From e399356ed17baf7b50da393a3f13682b01bd14a9 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 2 Feb 2015 15:04:01 +0100 Subject: drop .original files from the current code base --- .../programs/Xserver/GL/glx/render2.c.NX.original | 271 -- .../programs/Xserver/GL/glx/render2.c.X.original | 271 -- .../Xserver/GL/glx/render2swap.c.NX.original | 393 -- .../Xserver/GL/glx/render2swap.c.X.original | 393 -- .../Xserver/GL/mesa/X/Imakefile.NX.original | 93 - .../Xserver/GL/mesa/X/Imakefile.X.original | 93 - .../Xserver/GL/mesa/X/xf86glx.c.NX.original | 952 ---- .../Xserver/GL/mesa/X/xf86glx.c.X.original | 914 ---- .../Xserver/GL/mesa/main/Imakefile.NX.original | 61 - .../Xserver/GL/mesa/main/Imakefile.X.original | 61 - nx-X11/programs/Xserver/Imakefile.NX.original | 1579 ------ nx-X11/programs/Xserver/Imakefile.X.original | 1242 ----- nx-X11/programs/Xserver/Xext/Imakefile.NX.original | 226 - nx-X11/programs/Xserver/Xext/Imakefile.X.original | 200 - .../programs/Xserver/Xext/security.c.NX.original | 2245 --------- nx-X11/programs/Xserver/Xext/security.c.X.original | 2008 -------- nx-X11/programs/Xserver/dix/dixfonts.c.NX.original | 2215 --------- nx-X11/programs/Xserver/dix/dixfonts.c.X.original | 2150 --------- nx-X11/programs/Xserver/dix/pixmap.c.NX.original | 152 - nx-X11/programs/Xserver/dix/pixmap.c.X.original | 145 - nx-X11/programs/Xserver/fb/Imakefile.NX.original | 194 - nx-X11/programs/Xserver/fb/Imakefile.X.original | 188 - nx-X11/programs/Xserver/fb/fbtrap.c.NX.original | 242 - nx-X11/programs/Xserver/fb/fbtrap.c.X.original | 239 - .../Xserver/hw/nxagent/NXdispatch.c.NX.original | 4716 ------------------ .../Xserver/hw/nxagent/NXdispatch.c.XF86.original | 4110 ---------------- .../Xserver/hw/nxagent/NXdixfonts.c.NX.original | 2883 ----------- .../Xserver/hw/nxagent/NXdixfonts.c.XF86.original | 2223 --------- .../Xserver/hw/nxagent/NXevents.c.NX.original | 4797 ------------------- .../Xserver/hw/nxagent/NXevents.c.XF86.original | 4637 ------------------ .../Xserver/hw/nxagent/NXextension.c.NX.original | 528 -- .../Xserver/hw/nxagent/NXextension.c.XF86.original | 486 -- .../Xserver/hw/nxagent/NXglxext.c.NX.original | 550 --- .../Xserver/hw/nxagent/NXglxext.c.XF86.original | 489 -- .../Xserver/hw/nxagent/NXglyph.c.NX.original | 511 -- .../Xserver/hw/nxagent/NXglyph.c.XF86.original | 416 -- .../Xserver/hw/nxagent/NXglyphcurs.c.NX.original | 252 - .../Xserver/hw/nxagent/NXglyphcurs.c.XF86.original | 197 - .../Xserver/hw/nxagent/NXglyphstr.h.NX.original | 161 - .../Xserver/hw/nxagent/NXglyphstr.h.XF86.original | 127 - .../Xserver/hw/nxagent/NXmiexpose.c.NX.original | 938 ---- .../Xserver/hw/nxagent/NXmiexpose.c.XF86.original | 873 ---- .../Xserver/hw/nxagent/NXmiglyph.c.NX.original | 322 -- .../Xserver/hw/nxagent/NXmiglyph.c.XF86.original | 239 - .../Xserver/hw/nxagent/NXmitrap.c.NX.original | 204 - .../Xserver/hw/nxagent/NXmitrap.c.XF86.original | 196 - .../Xserver/hw/nxagent/NXmiwindow.c.NX.original | 1205 ----- .../Xserver/hw/nxagent/NXmiwindow.c.XF86.original | 1176 ----- .../Xserver/hw/nxagent/NXpicture.c.NX.original | 1512 ------ .../Xserver/hw/nxagent/NXpicture.c.XF86.original | 1305 ----- .../Xserver/hw/nxagent/NXpicturestr.h.NX.original | 533 --- .../hw/nxagent/NXpicturestr.h.XF86.original | 501 -- .../Xserver/hw/nxagent/NXproperty.c.NX.original | 921 ---- .../Xserver/hw/nxagent/NXproperty.c.XF86.original | 736 --- .../Xserver/hw/nxagent/NXrender.c.NX.original | 3048 ------------ .../Xserver/hw/nxagent/NXrender.c.XF86.original | 2584 ---------- .../Xserver/hw/nxagent/NXresource.c.NX.original | 1103 ----- .../Xserver/hw/nxagent/NXresource.c.XF86.original | 975 ---- .../Xserver/hw/nxagent/NXshm.c.NX.original | 1425 ------ .../Xserver/hw/nxagent/NXshm.c.XF86.original | 1257 ----- .../Xserver/hw/nxagent/NXwindow.c.NX.original | 4179 ---------------- .../Xserver/hw/nxagent/NXwindow.c.XF86.original | 3947 --------------- .../Xserver/hw/nxagent/NXxvdisp.c.NX.original | 2277 --------- .../Xserver/hw/nxagent/NXxvdisp.c.XF86.original | 2214 --------- .../Xserver/hw/nxagent/X/NXdamage.c.NX.original | 2073 -------- .../Xserver/hw/nxagent/X/NXdamage.c.X.original | 1966 -------- .../Xserver/hw/nxagent/X/NXdispatch.c.NX.original | 4679 ------------------ .../Xserver/hw/nxagent/X/NXdispatch.c.X.original | 4035 ---------------- .../Xserver/hw/nxagent/X/NXdixfonts.c.NX.original | 2804 ----------- .../Xserver/hw/nxagent/X/NXdixfonts.c.X.original | 2150 --------- .../Xserver/hw/nxagent/X/NXevents.c.NX.original | 5044 -------------------- .../Xserver/hw/nxagent/X/NXevents.c.X.original | 4670 ------------------ .../Xserver/hw/nxagent/X/NXextension.c.NX.original | 508 -- .../Xserver/hw/nxagent/X/NXextension.c.X.original | 474 -- .../Xserver/hw/nxagent/X/NXglxext.c.NX.original | 575 --- .../Xserver/hw/nxagent/X/NXglxext.c.X.original | 505 -- .../Xserver/hw/nxagent/X/NXglyph.c.NX.original | 581 --- .../Xserver/hw/nxagent/X/NXglyph.c.X.original | 488 -- .../Xserver/hw/nxagent/X/NXglyphcurs.c.NX.original | 241 - .../Xserver/hw/nxagent/X/NXglyphcurs.c.X.original | 194 - .../Xserver/hw/nxagent/X/NXglyphstr.h.NX.original | 174 - .../Xserver/hw/nxagent/X/NXglyphstr.h.X.original | 148 - .../Xserver/hw/nxagent/X/NXmiexpose.c.NX.original | 979 ---- .../Xserver/hw/nxagent/X/NXmiexpose.c.X.original | 905 ---- .../Xserver/hw/nxagent/X/NXmiglyph.c.NX.original | 318 -- .../Xserver/hw/nxagent/X/NXmiglyph.c.X.original | 243 - .../Xserver/hw/nxagent/X/NXmitrap.c.NX.original | 233 - .../Xserver/hw/nxagent/X/NXmitrap.c.X.original | 190 - .../Xserver/hw/nxagent/X/NXmiwindow.c.NX.original | 1222 ----- .../Xserver/hw/nxagent/X/NXmiwindow.c.X.original | 1184 ----- .../Xserver/hw/nxagent/X/NXpicture.c.NX.original | 2270 --------- .../Xserver/hw/nxagent/X/NXpicture.c.X.original | 1864 -------- .../hw/nxagent/X/NXpicturestr.h.NX.original | 678 --- .../Xserver/hw/nxagent/X/NXpicturestr.h.X.original | 654 --- .../Xserver/hw/nxagent/X/NXproperty.c.NX.original | 992 ---- .../Xserver/hw/nxagent/X/NXproperty.c.X.original | 729 --- .../Xserver/hw/nxagent/X/NXrender.c.NX.original | 3861 --------------- .../Xserver/hw/nxagent/X/NXrender.c.X.original | 3316 ------------- .../Xserver/hw/nxagent/X/NXresource.c.NX.original | 1250 ----- .../Xserver/hw/nxagent/X/NXresource.c.X.original | 954 ---- .../Xserver/hw/nxagent/X/NXshm.c.NX.original | 1498 ------ .../Xserver/hw/nxagent/X/NXshm.c.X.original | 1310 ----- .../Xserver/hw/nxagent/X/NXwindow.c.NX.original | 4167 ---------------- .../Xserver/hw/nxagent/X/NXwindow.c.X.original | 3853 --------------- .../Xserver/hw/nxagent/X/NXxvdisp.c.NX.original | 2286 --------- .../Xserver/hw/nxagent/X/NXxvdisp.c.X.original | 2217 --------- .../Xserver/include/dixstruct.h.NX.original | 236 - .../Xserver/include/dixstruct.h.X.original | 233 - nx-X11/programs/Xserver/mi/Imakefile.NX.original | 128 - nx-X11/programs/Xserver/mi/Imakefile.X.original | 94 - nx-X11/programs/Xserver/os/Imakefile.NX.original | 235 - nx-X11/programs/Xserver/os/Imakefile.X.original | 200 - nx-X11/programs/Xserver/os/WaitFor.c.NX.original | 882 ---- nx-X11/programs/Xserver/os/WaitFor.c.X.original | 701 --- nx-X11/programs/Xserver/os/auth.c.NX.original | 608 --- nx-X11/programs/Xserver/os/auth.c.X.original | 400 -- .../programs/Xserver/os/connection.c.NX.original | 1424 ------ nx-X11/programs/Xserver/os/connection.c.X.original | 1385 ------ nx-X11/programs/Xserver/os/log.c.NX.original | 716 --- nx-X11/programs/Xserver/os/log.c.X.original | 633 --- nx-X11/programs/Xserver/os/oscolor.c.NX.original | 483 -- nx-X11/programs/Xserver/os/oscolor.c.X.original | 303 -- nx-X11/programs/Xserver/os/utils.c.NX.original | 2440 ---------- nx-X11/programs/Xserver/os/utils.c.X.original | 2296 --------- nx-X11/programs/Xserver/os/xdmcp.c.NX.original | 1710 ------- nx-X11/programs/Xserver/os/xdmcp.c.X.original | 1681 ------- nx-X11/programs/Xserver/os/xprintf.c.NX.original | 163 - nx-X11/programs/Xserver/os/xprintf.c.X.original | 104 - nx-X11/programs/Xserver/randr.X.original/Imakefile | 18 - nx-X11/programs/Xserver/randr.X.original/mirandr.c | 102 - nx-X11/programs/Xserver/randr.X.original/randr.c | 1319 ----- .../programs/Xserver/randr.X.original/randrstr.h | 142 - .../programs/Xserver/randr/Imakefile.NX.original | 36 - nx-X11/programs/Xserver/randr/Imakefile.X.original | 0 .../Xserver/randr/panoramiXproto.h.NX.original | 192 - .../Xserver/randr/panoramiXproto.h.X.original | 0 nx-X11/programs/Xserver/randr/randr.c.NX.original | 521 -- nx-X11/programs/Xserver/randr/randr.c.X.original | 487 -- nx-X11/programs/Xserver/randr/randr.h.NX.original | 141 - nx-X11/programs/Xserver/randr/randr.h.X.original | 0 .../Xserver/randr/randrproto.h.NX.original | 655 --- .../programs/Xserver/randr/randrproto.h.X.original | 0 .../programs/Xserver/randr/registry.h.NX.original | 64 - .../programs/Xserver/randr/registry.h.X.original | 0 nx-X11/programs/Xserver/randr/rrcrtc.c.NX.original | 984 ---- nx-X11/programs/Xserver/randr/rrcrtc.c.X.original | 960 ---- .../programs/Xserver/randr/rrdispatch.c.X.original | 214 - nx-X11/programs/Xserver/randr/rrmode.c.NX.original | 420 -- nx-X11/programs/Xserver/randr/rrmode.c.X.original | 398 -- .../programs/Xserver/randr/rrscreen.c.NX.original | 1030 ---- .../programs/Xserver/randr/rrscreen.c.X.original | 981 ---- .../Xserver/randr/rrxinerama.c.NX.original | 490 -- .../programs/Xserver/randr/rrxinerama.c.X.original | 454 -- .../Xserver/render/renderedge.c.NX.original | 202 - .../Xserver/render/renderedge.c.X.original | 201 - .../programs/Xserver/xfixes/cursor.c.NX.original | 754 --- nx-X11/programs/Xserver/xfixes/cursor.c.X.original | 753 --- .../programs/Xserver/xfixes/select.c.NX.original | 281 -- nx-X11/programs/Xserver/xfixes/select.c.X.original | 279 -- nx-X11/programs/Xserver/xkb/Imakefile.NX.original | 106 - nx-X11/programs/Xserver/xkb/Imakefile.X.original | 102 - .../programs/Xserver/xkb/ddxKillSrv.c.NX.original | 69 - .../programs/Xserver/xkb/ddxKillSrv.c.X.original | 61 - nx-X11/programs/Xserver/xkb/ddxLoad.c.NX.original | 970 ---- nx-X11/programs/Xserver/xkb/ddxLoad.c.X.original | 604 --- nx-X11/programs/Xserver/xkb/xkbDflts.h.NX.original | 524 -- nx-X11/programs/Xserver/xkb/xkbDflts.h.X.original | 513 -- 167 files changed, 177844 deletions(-) delete mode 100644 nx-X11/programs/Xserver/GL/glx/render2.c.NX.original delete mode 100644 nx-X11/programs/Xserver/GL/glx/render2.c.X.original delete mode 100644 nx-X11/programs/Xserver/GL/glx/render2swap.c.NX.original delete mode 100644 nx-X11/programs/Xserver/GL/glx/render2swap.c.X.original delete mode 100644 nx-X11/programs/Xserver/GL/mesa/X/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/GL/mesa/X/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.NX.original delete mode 100644 nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.X.original delete mode 100644 nx-X11/programs/Xserver/GL/mesa/main/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/GL/mesa/main/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/Xext/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/Xext/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/Xext/security.c.NX.original delete mode 100644 nx-X11/programs/Xserver/Xext/security.c.X.original delete mode 100644 nx-X11/programs/Xserver/dix/dixfonts.c.NX.original delete mode 100644 nx-X11/programs/Xserver/dix/dixfonts.c.X.original delete mode 100644 nx-X11/programs/Xserver/dix/pixmap.c.NX.original delete mode 100644 nx-X11/programs/Xserver/dix/pixmap.c.X.original delete mode 100644 nx-X11/programs/Xserver/fb/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/fb/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/fb/fbtrap.c.NX.original delete mode 100644 nx-X11/programs/Xserver/fb/fbtrap.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXevents.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXevents.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXextension.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXextension.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXrender.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXrender.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXresource.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXresource.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXshm.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXshm.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.XF86.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.X.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.NX.original delete mode 100644 nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.X.original delete mode 100644 nx-X11/programs/Xserver/include/dixstruct.h.NX.original delete mode 100644 nx-X11/programs/Xserver/include/dixstruct.h.X.original delete mode 100644 nx-X11/programs/Xserver/mi/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/mi/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/os/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/os/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/os/WaitFor.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/WaitFor.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/auth.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/auth.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/connection.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/connection.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/log.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/log.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/oscolor.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/oscolor.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/utils.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/utils.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/xdmcp.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/xdmcp.c.X.original delete mode 100644 nx-X11/programs/Xserver/os/xprintf.c.NX.original delete mode 100644 nx-X11/programs/Xserver/os/xprintf.c.X.original delete mode 100644 nx-X11/programs/Xserver/randr.X.original/Imakefile delete mode 100644 nx-X11/programs/Xserver/randr.X.original/mirandr.c delete mode 100644 nx-X11/programs/Xserver/randr.X.original/randr.c delete mode 100644 nx-X11/programs/Xserver/randr.X.original/randrstr.h delete mode 100644 nx-X11/programs/Xserver/randr/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/randr/panoramiXproto.h.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/panoramiXproto.h.X.original delete mode 100644 nx-X11/programs/Xserver/randr/randr.c.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/randr.c.X.original delete mode 100644 nx-X11/programs/Xserver/randr/randr.h.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/randr.h.X.original delete mode 100644 nx-X11/programs/Xserver/randr/randrproto.h.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/randrproto.h.X.original delete mode 100644 nx-X11/programs/Xserver/randr/registry.h.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/registry.h.X.original delete mode 100644 nx-X11/programs/Xserver/randr/rrcrtc.c.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/rrcrtc.c.X.original delete mode 100644 nx-X11/programs/Xserver/randr/rrdispatch.c.X.original delete mode 100644 nx-X11/programs/Xserver/randr/rrmode.c.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/rrmode.c.X.original delete mode 100644 nx-X11/programs/Xserver/randr/rrscreen.c.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/rrscreen.c.X.original delete mode 100644 nx-X11/programs/Xserver/randr/rrxinerama.c.NX.original delete mode 100644 nx-X11/programs/Xserver/randr/rrxinerama.c.X.original delete mode 100644 nx-X11/programs/Xserver/render/renderedge.c.NX.original delete mode 100644 nx-X11/programs/Xserver/render/renderedge.c.X.original delete mode 100755 nx-X11/programs/Xserver/xfixes/cursor.c.NX.original delete mode 100755 nx-X11/programs/Xserver/xfixes/cursor.c.X.original delete mode 100755 nx-X11/programs/Xserver/xfixes/select.c.NX.original delete mode 100755 nx-X11/programs/Xserver/xfixes/select.c.X.original delete mode 100644 nx-X11/programs/Xserver/xkb/Imakefile.NX.original delete mode 100644 nx-X11/programs/Xserver/xkb/Imakefile.X.original delete mode 100644 nx-X11/programs/Xserver/xkb/ddxKillSrv.c.NX.original delete mode 100644 nx-X11/programs/Xserver/xkb/ddxKillSrv.c.X.original delete mode 100644 nx-X11/programs/Xserver/xkb/ddxLoad.c.NX.original delete mode 100644 nx-X11/programs/Xserver/xkb/ddxLoad.c.X.original delete mode 100644 nx-X11/programs/Xserver/xkb/xkbDflts.h.NX.original delete mode 100644 nx-X11/programs/Xserver/xkb/xkbDflts.h.X.original (limited to 'nx-X11/programs/Xserver') diff --git a/nx-X11/programs/Xserver/GL/glx/render2.c.NX.original b/nx-X11/programs/Xserver/GL/glx/render2.c.NX.original deleted file mode 100644 index f4491b276..000000000 --- a/nx-X11/programs/Xserver/GL/glx/render2.c.NX.original +++ /dev/null @@ -1,271 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/glx/render2.c,v 1.8 2004/02/03 23:04:08 alanh Exp $ */ -/* -** License Applicability. Except to the extent portions of this file are -** made subject to an alternative license as permitted in the SGI Free -** Software License B, Version 1.1 (the "License"), the contents of this -** file are subject only to the provisions of the License. You may not use -** this file except in compliance with the License. You may obtain a copy -** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 -** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: -** -** http://oss.sgi.com/projects/FreeB -** -** Note that, as provided in the License, the Software is distributed on an -** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS -** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND -** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A -** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. -** -** Original Code. The Original Code is: OpenGL Sample Implementation, -** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, -** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. -** Copyright in any portions created by third parties is as indicated -** elsewhere herein. All Rights Reserved. -** -** Additional Notice Provisions: The application programming interfaces -** established by SGI in conjunction with the Original Code are The -** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released -** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version -** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X -** Window System(R) (Version 1.3), released October 19, 1998. This software -** was created using the OpenGL(R) version 1.2.1 Sample Implementation -** published by SGI, but has not been independently verified as being -** compliant with the OpenGL(R) version 1.2.1 Specification. -** -*/ - -/* #define NEED_REPLIES */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "unpack.h" -#include "g_disptab.h" -#include "g_disptab_EXT.h" -#include "indirect_size.h" - -void __glXDisp_Map1f(GLbyte *pc) -{ - GLint order, k; - GLfloat u1, u2, *points; - GLenum target; - - target = *(GLenum *)(pc + 0); - order = *(GLint *)(pc + 12); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - points = (GLfloat *)(pc + 16); - k = __glMap1f_size(target); - - glMap1f(target, u1, u2, k, order, points); -} - -void __glXDisp_Map2f(GLbyte *pc) -{ - GLint uorder, vorder, ustride, vstride, k; - GLfloat u1, u2, v1, v2, *points; - GLenum target; - - target = *(GLenum *)(pc + 0); - uorder = *(GLint *)(pc + 12); - vorder = *(GLint *)(pc + 24); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - v1 = *(GLfloat *)(pc + 16); - v2 = *(GLfloat *)(pc + 20); - points = (GLfloat *)(pc + 28); - - k = __glMap2f_size(target); - ustride = vorder * k; - vstride = k; - - glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDisp_Map1d(GLbyte *pc) -{ - GLint order, k; -#ifdef __GLX_ALIGN64 - GLint compsize; -#endif - GLenum target; - GLdouble u1, u2, *points; - - target = *(GLenum*) (pc + 16); - order = *(GLint*) (pc + 20); - k = __glMap1d_size(target); - -#ifdef __GLX_ALIGN64 - if (order < 0 || k < 0) { - compsize = 0; - } else { - compsize = order * k; - } -#endif - - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - pc += 24; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap1d(target, u1, u2, k, order, points); -} - -void __glXDisp_Map2d(GLbyte *pc) -{ - GLdouble u1, u2, v1, v2, *points; - GLint uorder, vorder, ustride, vstride, k; -#ifdef __GLX_ALIGN64 - GLint compsize; -#endif - GLenum target; - - target = *(GLenum *)(pc + 32); - uorder = *(GLint *)(pc + 36); - vorder = *(GLint *)(pc + 40); - k = __glMap2d_size(target); - -#ifdef __GLX_ALIGN64 - if (vorder < 0 || uorder < 0 || k < 0) { - compsize = 0; - } else { - compsize = uorder * vorder * k; - } -#endif - - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - __GLX_GET_DOUBLE(v1,pc+16); - __GLX_GET_DOUBLE(v2,pc+24); - pc += 44; - - ustride = vorder * k; - vstride = k; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDisp_CallLists(GLbyte *pc) -{ - GLenum type; - GLsizei n; - - type = *(GLenum *)(pc + 4); - n = *(GLsizei *)(pc + 0); - glCallLists(n, type, pc + 8); -} - -void __glXDisp_DrawArrays(GLbyte *pc) -{ - __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc; - __GLXdispatchDrawArraysComponentHeader *compHeader; - GLint numVertexes = hdr->numVertexes; - GLint numComponents = hdr->numComponents; - GLenum primType = hdr->primType; - GLint stride = 0; - int i; - - pc += sizeof(__GLXdispatchDrawArraysHeader); - compHeader = (__GLXdispatchDrawArraysComponentHeader *)pc; - - /* compute stride (same for all component arrays) */ - for (i = 0; i < numComponents; i++) { - GLenum datatype = compHeader[i].datatype; - GLint numVals = compHeader[i].numVals; - - stride += __GLX_PAD(numVals * __glXTypeSize(datatype)); - } - - pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader); - - /* set up component arrays */ - for (i = 0; i < numComponents; i++) { - GLenum datatype = compHeader[i].datatype; - GLint numVals = compHeader[i].numVals; - GLenum component = compHeader[i].component; - - switch (component) { - case GL_VERTEX_ARRAY: - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(numVals, datatype, stride, pc); - break; - case GL_NORMAL_ARRAY: - glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(datatype, stride, pc); - break; - case GL_COLOR_ARRAY: - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(numVals, datatype, stride, pc); - break; - case GL_INDEX_ARRAY: - glEnableClientState(GL_INDEX_ARRAY); - glIndexPointer(datatype, stride, pc); - break; - case GL_TEXTURE_COORD_ARRAY: - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(numVals, datatype, stride, pc); - break; - case GL_EDGE_FLAG_ARRAY: - glEnableClientState(GL_EDGE_FLAG_ARRAY); - glEdgeFlagPointer(stride, (const GLboolean *)pc); - break; - case GL_SECONDARY_COLOR_ARRAY: - glEnableClientState(GL_SECONDARY_COLOR_ARRAY); - glSecondaryColorPointer(numVals, datatype, stride, pc); - break; - case GL_FOG_COORD_ARRAY: - glEnableClientState(GL_FOG_COORD_ARRAY); - glFogCoordPointer(datatype, stride, pc); - break; - default: - break; - } - - pc += __GLX_PAD(numVals * __glXTypeSize(datatype)); - } - - glDrawArrays(primType, 0, numVertexes); - - /* turn off anything we might have turned on */ - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_INDEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_EDGE_FLAG_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - glDisableClientState(GL_FOG_COORD_ARRAY); -} - -void __glXDisp_DrawArraysEXT(GLbyte *pc) -{ - __glXDisp_DrawArrays(pc); -} diff --git a/nx-X11/programs/Xserver/GL/glx/render2.c.X.original b/nx-X11/programs/Xserver/GL/glx/render2.c.X.original deleted file mode 100644 index 39d0c132a..000000000 --- a/nx-X11/programs/Xserver/GL/glx/render2.c.X.original +++ /dev/null @@ -1,271 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/glx/render2.c,v 1.8 2004/02/03 23:04:08 alanh Exp $ */ -/* -** License Applicability. Except to the extent portions of this file are -** made subject to an alternative license as permitted in the SGI Free -** Software License B, Version 1.1 (the "License"), the contents of this -** file are subject only to the provisions of the License. You may not use -** this file except in compliance with the License. You may obtain a copy -** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 -** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: -** -** http://oss.sgi.com/projects/FreeB -** -** Note that, as provided in the License, the Software is distributed on an -** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS -** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND -** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A -** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. -** -** Original Code. The Original Code is: OpenGL Sample Implementation, -** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, -** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. -** Copyright in any portions created by third parties is as indicated -** elsewhere herein. All Rights Reserved. -** -** Additional Notice Provisions: The application programming interfaces -** established by SGI in conjunction with the Original Code are The -** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released -** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version -** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X -** Window System(R) (Version 1.3), released October 19, 1998. This software -** was created using the OpenGL(R) version 1.2.1 Sample Implementation -** published by SGI, but has not been independently verified as being -** compliant with the OpenGL(R) version 1.2.1 Specification. -** -*/ - -/* #define NEED_REPLIES */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "unpack.h" -#include "g_disptab.h" -#include "g_disptab_EXT.h" - - -void __glXDisp_Map1f(GLbyte *pc) -{ - GLint order, k; - GLfloat u1, u2, *points; - GLenum target; - - target = *(GLenum *)(pc + 0); - order = *(GLint *)(pc + 12); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - points = (GLfloat *)(pc + 16); - k = __glMap1f_size(target); - - glMap1f(target, u1, u2, k, order, points); -} - -void __glXDisp_Map2f(GLbyte *pc) -{ - GLint uorder, vorder, ustride, vstride, k; - GLfloat u1, u2, v1, v2, *points; - GLenum target; - - target = *(GLenum *)(pc + 0); - uorder = *(GLint *)(pc + 12); - vorder = *(GLint *)(pc + 24); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - v1 = *(GLfloat *)(pc + 16); - v2 = *(GLfloat *)(pc + 20); - points = (GLfloat *)(pc + 28); - - k = __glMap2f_size(target); - ustride = vorder * k; - vstride = k; - - glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDisp_Map1d(GLbyte *pc) -{ - GLint order, k; -#ifdef __GLX_ALIGN64 - GLint compsize; -#endif - GLenum target; - GLdouble u1, u2, *points; - - target = *(GLenum*) (pc + 16); - order = *(GLint*) (pc + 20); - k = __glMap1d_size(target); - -#ifdef __GLX_ALIGN64 - if (order < 0 || k < 0) { - compsize = 0; - } else { - compsize = order * k; - } -#endif - - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - pc += 24; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap1d(target, u1, u2, k, order, points); -} - -void __glXDisp_Map2d(GLbyte *pc) -{ - GLdouble u1, u2, v1, v2, *points; - GLint uorder, vorder, ustride, vstride, k; -#ifdef __GLX_ALIGN64 - GLint compsize; -#endif - GLenum target; - - target = *(GLenum *)(pc + 32); - uorder = *(GLint *)(pc + 36); - vorder = *(GLint *)(pc + 40); - k = __glMap2d_size(target); - -#ifdef __GLX_ALIGN64 - if (vorder < 0 || uorder < 0 || k < 0) { - compsize = 0; - } else { - compsize = uorder * vorder * k; - } -#endif - - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - __GLX_GET_DOUBLE(v1,pc+16); - __GLX_GET_DOUBLE(v2,pc+24); - pc += 44; - - ustride = vorder * k; - vstride = k; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDisp_CallLists(GLbyte *pc) -{ - GLenum type; - GLsizei n; - - type = *(GLenum *)(pc + 4); - n = *(GLsizei *)(pc + 0); - glCallLists(n, type, pc + 8); -} - -void __glXDisp_DrawArrays(GLbyte *pc) -{ - __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc; - __GLXdispatchDrawArraysComponentHeader *compHeader; - GLint numVertexes = hdr->numVertexes; - GLint numComponents = hdr->numComponents; - GLenum primType = hdr->primType; - GLint stride = 0; - int i; - - pc += sizeof(__GLXdispatchDrawArraysHeader); - compHeader = (__GLXdispatchDrawArraysComponentHeader *)pc; - - /* compute stride (same for all component arrays) */ - for (i = 0; i < numComponents; i++) { - GLenum datatype = compHeader[i].datatype; - GLint numVals = compHeader[i].numVals; - - stride += __GLX_PAD(numVals * __glXTypeSize(datatype)); - } - - pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader); - - /* set up component arrays */ - for (i = 0; i < numComponents; i++) { - GLenum datatype = compHeader[i].datatype; - GLint numVals = compHeader[i].numVals; - GLenum component = compHeader[i].component; - - switch (component) { - case GL_VERTEX_ARRAY: - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(numVals, datatype, stride, pc); - break; - case GL_NORMAL_ARRAY: - glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(datatype, stride, pc); - break; - case GL_COLOR_ARRAY: - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(numVals, datatype, stride, pc); - break; - case GL_INDEX_ARRAY: - glEnableClientState(GL_INDEX_ARRAY); - glIndexPointer(datatype, stride, pc); - break; - case GL_TEXTURE_COORD_ARRAY: - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(numVals, datatype, stride, pc); - break; - case GL_EDGE_FLAG_ARRAY: - glEnableClientState(GL_EDGE_FLAG_ARRAY); - glEdgeFlagPointer(stride, (const GLboolean *)pc); - break; - case GL_SECONDARY_COLOR_ARRAY: - glEnableClientState(GL_SECONDARY_COLOR_ARRAY); - glSecondaryColorPointer(numVals, datatype, stride, pc); - break; - case GL_FOG_COORD_ARRAY: - glEnableClientState(GL_FOG_COORD_ARRAY); - glFogCoordPointer(datatype, stride, pc); - break; - default: - break; - } - - pc += __GLX_PAD(numVals * __glXTypeSize(datatype)); - } - - glDrawArrays(primType, 0, numVertexes); - - /* turn off anything we might have turned on */ - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_INDEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_EDGE_FLAG_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - glDisableClientState(GL_FOG_COORD_ARRAY); -} - -void __glXDisp_DrawArraysEXT(GLbyte *pc) -{ - __glXDisp_DrawArrays(pc); -} diff --git a/nx-X11/programs/Xserver/GL/glx/render2swap.c.NX.original b/nx-X11/programs/Xserver/GL/glx/render2swap.c.NX.original deleted file mode 100644 index 0225970cb..000000000 --- a/nx-X11/programs/Xserver/GL/glx/render2swap.c.NX.original +++ /dev/null @@ -1,393 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/glx/render2swap.c,v 1.6 2002/01/14 22:47:08 tsi Exp $ */ -/* -** License Applicability. Except to the extent portions of this file are -** made subject to an alternative license as permitted in the SGI Free -** Software License B, Version 1.1 (the "License"), the contents of this -** file are subject only to the provisions of the License. You may not use -** this file except in compliance with the License. You may obtain a copy -** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 -** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: -** -** http://oss.sgi.com/projects/FreeB -** -** Note that, as provided in the License, the Software is distributed on an -** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS -** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND -** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A -** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. -** -** Original Code. The Original Code is: OpenGL Sample Implementation, -** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, -** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. -** Copyright in any portions created by third parties is as indicated -** elsewhere herein. All Rights Reserved. -** -** Additional Notice Provisions: The application programming interfaces -** established by SGI in conjunction with the Original Code are The -** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released -** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version -** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X -** Window System(R) (Version 1.3), released October 19, 1998. This software -** was created using the OpenGL(R) version 1.2.1 Sample Implementation -** published by SGI, but has not been independently verified as being -** compliant with the OpenGL(R) version 1.2.1 Specification. -** -*/ - -/* #define NEED_REPLIES */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "glxserver.h" -#include "unpack.h" -#include "g_disptab.h" -#include "g_disptab_EXT.h" -#include "indirect_size.h" - -void __glXDispSwap_Map1f(GLbyte *pc) -{ - GLint order, k; - GLfloat u1, u2, *points; - GLenum target; - GLint compsize; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_INT(pc + 0); - __GLX_SWAP_INT(pc + 12); - __GLX_SWAP_FLOAT(pc + 4); - __GLX_SWAP_FLOAT(pc + 8); - - target = *(GLenum *)(pc + 0); - order = *(GLint *)(pc + 12); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - points = (GLfloat *)(pc + 16); - k = __glMap1f_size(target); - - if (order <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = order * k; - } - __GLX_SWAP_FLOAT_ARRAY(points, compsize); - - glMap1f(target, u1, u2, k, order, points); -} - -void __glXDispSwap_Map2f(GLbyte *pc) -{ - GLint uorder, vorder, ustride, vstride, k; - GLfloat u1, u2, v1, v2, *points; - GLenum target; - GLint compsize; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_INT(pc + 0); - __GLX_SWAP_INT(pc + 12); - __GLX_SWAP_INT(pc + 24); - __GLX_SWAP_FLOAT(pc + 4); - __GLX_SWAP_FLOAT(pc + 8); - __GLX_SWAP_FLOAT(pc + 16); - __GLX_SWAP_FLOAT(pc + 20); - - target = *(GLenum *)(pc + 0); - uorder = *(GLint *)(pc + 12); - vorder = *(GLint *)(pc + 24); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - v1 = *(GLfloat *)(pc + 16); - v2 = *(GLfloat *)(pc + 20); - points = (GLfloat *)(pc + 28); - - k = __glMap2f_size(target); - ustride = vorder * k; - vstride = k; - - if (vorder <= 0 || uorder <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = uorder * vorder * k; - } - __GLX_SWAP_FLOAT_ARRAY(points, compsize); - - glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDispSwap_Map1d(GLbyte *pc) -{ - GLint order, k, compsize; - GLenum target; - GLdouble u1, u2, *points; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_DOUBLE(pc + 0); - __GLX_SWAP_DOUBLE(pc + 8); - __GLX_SWAP_INT(pc + 16); - __GLX_SWAP_INT(pc + 20); - - target = *(GLenum*) (pc + 16); - order = *(GLint*) (pc + 20); - k = __glMap1d_size(target); - if (order <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = order * k; - } - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - __GLX_SWAP_DOUBLE_ARRAY(pc+24, compsize); - pc += 24; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap1d(target, u1, u2, k, order, points); -} - -void __glXDispSwap_Map2d(GLbyte *pc) -{ - GLdouble u1, u2, v1, v2, *points; - GLint uorder, vorder, ustride, vstride, k, compsize; - GLenum target; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_DOUBLE(pc + 0); - __GLX_SWAP_DOUBLE(pc + 8); - __GLX_SWAP_DOUBLE(pc + 16); - __GLX_SWAP_DOUBLE(pc + 24); - __GLX_SWAP_INT(pc + 32); - __GLX_SWAP_INT(pc + 36); - __GLX_SWAP_INT(pc + 40); - - target = *(GLenum *)(pc + 32); - uorder = *(GLint *)(pc + 36); - vorder = *(GLint *)(pc + 40); - k = __glMap2d_size(target); - if (vorder <= 0 || uorder <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = uorder * vorder * k; - } - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - __GLX_GET_DOUBLE(v1,pc+16); - __GLX_GET_DOUBLE(v2,pc+24); - __GLX_SWAP_DOUBLE_ARRAY(pc+44, compsize); - pc += 44; - ustride = vorder * k; - vstride = k; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDispSwap_CallLists(GLbyte *pc) -{ - GLenum type; - GLsizei n; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_INT(pc + 4); - __GLX_SWAP_INT(pc + 0); - type = *(GLenum *)(pc + 4); - n = *(GLsizei *)(pc + 0); - - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_2_BYTES: - case GL_3_BYTES: - case GL_4_BYTES: - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - __GLX_SWAP_SHORT_ARRAY(pc+8, n); - break; - case GL_INT: - case GL_UNSIGNED_INT: - __GLX_SWAP_INT_ARRAY(pc+8, n); - break; - case GL_FLOAT: - __GLX_SWAP_FLOAT_ARRAY(pc+8, n); - break; - } - - glCallLists(n, type, pc+8); -} - -static void swapArray(GLint numVals, GLenum datatype, - GLint stride, GLint numVertexes, GLbyte *pc) -{ - int i,j; - __GLX_DECLARE_SWAP_VARIABLES; - - switch (datatype) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - /* don't need to swap */ - return; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - for (i=0; inumVertexes; - GLint numComponents = hdr->numComponents; - GLenum primType = hdr->primType; - GLint stride = 0; - int i; - __GLX_DECLARE_SWAP_VARIABLES; - - __GLX_SWAP_INT(&numVertexes); - __GLX_SWAP_INT(&numComponents); - __GLX_SWAP_INT(&primType); - - pc += sizeof(__GLXdispatchDrawArraysHeader); - compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc; - - /* compute stride (same for all component arrays) */ - for (i=0; i -#endif - -#include "glxserver.h" -#include "unpack.h" -#include "g_disptab.h" -#include "g_disptab_EXT.h" - - -void __glXDispSwap_Map1f(GLbyte *pc) -{ - GLint order, k; - GLfloat u1, u2, *points; - GLenum target; - GLint compsize; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_INT(pc + 0); - __GLX_SWAP_INT(pc + 12); - __GLX_SWAP_FLOAT(pc + 4); - __GLX_SWAP_FLOAT(pc + 8); - - target = *(GLenum *)(pc + 0); - order = *(GLint *)(pc + 12); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - points = (GLfloat *)(pc + 16); - k = __glMap1f_size(target); - - if (order <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = order * k; - } - __GLX_SWAP_FLOAT_ARRAY(points, compsize); - - glMap1f(target, u1, u2, k, order, points); -} - -void __glXDispSwap_Map2f(GLbyte *pc) -{ - GLint uorder, vorder, ustride, vstride, k; - GLfloat u1, u2, v1, v2, *points; - GLenum target; - GLint compsize; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_INT(pc + 0); - __GLX_SWAP_INT(pc + 12); - __GLX_SWAP_INT(pc + 24); - __GLX_SWAP_FLOAT(pc + 4); - __GLX_SWAP_FLOAT(pc + 8); - __GLX_SWAP_FLOAT(pc + 16); - __GLX_SWAP_FLOAT(pc + 20); - - target = *(GLenum *)(pc + 0); - uorder = *(GLint *)(pc + 12); - vorder = *(GLint *)(pc + 24); - u1 = *(GLfloat *)(pc + 4); - u2 = *(GLfloat *)(pc + 8); - v1 = *(GLfloat *)(pc + 16); - v2 = *(GLfloat *)(pc + 20); - points = (GLfloat *)(pc + 28); - - k = __glMap2f_size(target); - ustride = vorder * k; - vstride = k; - - if (vorder <= 0 || uorder <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = uorder * vorder * k; - } - __GLX_SWAP_FLOAT_ARRAY(points, compsize); - - glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDispSwap_Map1d(GLbyte *pc) -{ - GLint order, k, compsize; - GLenum target; - GLdouble u1, u2, *points; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_DOUBLE(pc + 0); - __GLX_SWAP_DOUBLE(pc + 8); - __GLX_SWAP_INT(pc + 16); - __GLX_SWAP_INT(pc + 20); - - target = *(GLenum*) (pc + 16); - order = *(GLint*) (pc + 20); - k = __glMap1d_size(target); - if (order <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = order * k; - } - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - __GLX_SWAP_DOUBLE_ARRAY(pc+24, compsize); - pc += 24; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap1d(target, u1, u2, k, order, points); -} - -void __glXDispSwap_Map2d(GLbyte *pc) -{ - GLdouble u1, u2, v1, v2, *points; - GLint uorder, vorder, ustride, vstride, k, compsize; - GLenum target; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_DOUBLE(pc + 0); - __GLX_SWAP_DOUBLE(pc + 8); - __GLX_SWAP_DOUBLE(pc + 16); - __GLX_SWAP_DOUBLE(pc + 24); - __GLX_SWAP_INT(pc + 32); - __GLX_SWAP_INT(pc + 36); - __GLX_SWAP_INT(pc + 40); - - target = *(GLenum *)(pc + 32); - uorder = *(GLint *)(pc + 36); - vorder = *(GLint *)(pc + 40); - k = __glMap2d_size(target); - if (vorder <= 0 || uorder <= 0 || k < 0) { - /* Erroneous command. */ - compsize = 0; - } else { - compsize = uorder * vorder * k; - } - __GLX_GET_DOUBLE(u1,pc); - __GLX_GET_DOUBLE(u2,pc+8); - __GLX_GET_DOUBLE(v1,pc+16); - __GLX_GET_DOUBLE(v2,pc+24); - __GLX_SWAP_DOUBLE_ARRAY(pc+44, compsize); - pc += 44; - ustride = vorder * k; - vstride = k; - -#ifdef __GLX_ALIGN64 - if (((unsigned long)pc) & 7) { - /* - ** Copy the doubles up 4 bytes, trashing the command but aligning - ** the data in the process - */ - __GLX_MEM_COPY(pc-4, pc, compsize*8); - points = (GLdouble*) (pc - 4); - } else { - points = (GLdouble*) pc; - } -#else - points = (GLdouble*) pc; -#endif - glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points); -} - -void __glXDispSwap_CallLists(GLbyte *pc) -{ - GLenum type; - GLsizei n; - __GLX_DECLARE_SWAP_VARIABLES; - __GLX_DECLARE_SWAP_ARRAY_VARIABLES; - - __GLX_SWAP_INT(pc + 4); - __GLX_SWAP_INT(pc + 0); - type = *(GLenum *)(pc + 4); - n = *(GLsizei *)(pc + 0); - - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_2_BYTES: - case GL_3_BYTES: - case GL_4_BYTES: - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - __GLX_SWAP_SHORT_ARRAY(pc+8, n); - break; - case GL_INT: - case GL_UNSIGNED_INT: - __GLX_SWAP_INT_ARRAY(pc+8, n); - break; - case GL_FLOAT: - __GLX_SWAP_FLOAT_ARRAY(pc+8, n); - break; - } - - glCallLists(n, type, pc+8); -} - -static void swapArray(GLint numVals, GLenum datatype, - GLint stride, GLint numVertexes, GLbyte *pc) -{ - int i,j; - __GLX_DECLARE_SWAP_VARIABLES; - - switch (datatype) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - /* don't need to swap */ - return; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - for (i=0; inumVertexes; - GLint numComponents = hdr->numComponents; - GLenum primType = hdr->primType; - GLint stride = 0; - int i; - __GLX_DECLARE_SWAP_VARIABLES; - - __GLX_SWAP_INT(&numVertexes); - __GLX_SWAP_INT(&numComponents); - __GLX_SWAP_INT(&primType); - - pc += sizeof(__GLXdispatchDrawArraysHeader); - compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc; - - /* compute stride (same for all component arrays) */ - for (i=0; i - -#define NeedAllMesaSrc -#define NeedToLinkMesaSrc -#define MesaXBuildDir /**/ -#define MesaInXServer -#if !defined(IHaveModules) || !BuildModuleInSubdir -#include "../../../../../lib/GL/mesa/drivers/x11/Imakefile.inc" -#else -#include "../../../../../../lib/GL/mesa/drivers/x11/Imakefile.inc" -#endif - - -LinkSourceFile(compsize.c,$(MESASRCDIR)/src/glx/x11) - - DRIVER_SRCS = $(XMESA_SRCS) - DRIVER_OBJS = $(XMESA_OBJS) - - COMMON_SRCS = driverfuncs.c - COMMON_OBJS = driverfuncs.o - -#ifndef XFree86Version - -/* This appears to be the quickest way to build a non-XFree86 server */ -GLXSRV_DEFINES = -DXFree86Server - -#endif - - GLX_SRCS = xf86glx.c xf86glx_util.c compsize.c - GLX_OBJS = xf86glx.o xf86glx_util.o compsize.o - - SRCS = $(DRIVER_SRCS) $(GLX_SRCS) $(COMMON_SRCS) - OBJS = $(DRIVER_OBJS) $(GLX_OBJS) $(COMMON_OBJS) - - INCLUDES = -I$(SERVERSRC)/GL/mesa/X -I$(XINCLUDESRC) \ - -I$(EXTINCSRC) \ - -I$(MESASRCDIR)/src/mesa \ - -I$(MESASRCDIR)/src/mesa/main \ - -I$(MESASRCDIR)/src/mesa/glapi \ - -I$(MESASRCDIR)/src/mesa/shader \ - -I$(MESASRCDIR)/src -I$(MESASRCDIR)/src/mesa/drivers/x11 \ - -I$(MESASRCDIR)/include \ - -I$(LIBSRC)/GL/glx -I$(LIBSRC)/GL/include \ - -I$(SERVERSRC)/include -I$(SERVERSRC)/GL/include \ - -I$(SERVERSRC)/GL/glx \ - -I$(XF86OSSRC) \ - -I$(DRMSRCDIR)/shared-core - - DEFINES = $(GLX_DEFINES) $(GLXSRV_DEFINES) -DNXAGENT_SERVER /*-DUSE_X86_ASM*/ /*-DUSE_SPARC_ASM*/ - -#ifdef IHaveModules -ModuleObjectRule() -#else -NormalLibraryObjectRule() -#endif - -SubdirLibraryRule($(OBJS)) - -LintLibraryTarget(dri,$(SRCS)) -NormalLintTarget($(SRCS)) - -DependTarget() - -#ifdef IHaveSubdirs -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - -#if defined(IHaveModules) && BuildModuleInSubdir -LinkSourceFile(xf86glx.c,..) -LinkSourceFile(xf86glx_util.c,..) -#endif - -#ifndef MesaDrvSrcDir -#define MesaDrvSrcDir $(MESASRCDIR)/src/mesa/drivers/dri -#endif - -MESADRVSRCDIR = MesaDrvSrcDir - - -LinkSourceFile(driverfuncs.c, $(MESADRVSRCDIR)/../common) -LinkSourceFile(driverfuncs.h, $(MESADRVSRCDIR)/../common) diff --git a/nx-X11/programs/Xserver/GL/mesa/X/Imakefile.X.original b/nx-X11/programs/Xserver/GL/mesa/X/Imakefile.X.original deleted file mode 100644 index 57fb7ff36..000000000 --- a/nx-X11/programs/Xserver/GL/mesa/X/Imakefile.X.original +++ /dev/null @@ -1,93 +0,0 @@ -XCOMM $XFree86: xc/programs/Xserver/GL/mesa/src/X/Imakefile,v 1.16 2002/11/22 22:56:01 tsi Exp $ - -#if DoLoadableServer -#if !BuildModuleInSubdir -#define IHaveModules -#elif !defined(IHaveModules) -#define IHaveSubdirs -SUBDIRS = module -#endif -#endif - -#include - -#define NeedAllMesaSrc -#define NeedToLinkMesaSrc -#define MesaXBuildDir /**/ -#define MesaInXServer -#if !defined(IHaveModules) || !BuildModuleInSubdir -#include "../../../../../lib/GL/mesa/drivers/x11/Imakefile.inc" -#else -#include "../../../../../../lib/GL/mesa/drivers/x11/Imakefile.inc" -#endif - - -LinkSourceFile(compsize.c,$(MESASRCDIR)/src/glx/x11) - - DRIVER_SRCS = $(XMESA_SRCS) - DRIVER_OBJS = $(XMESA_OBJS) - - COMMON_SRCS = driverfuncs.c - COMMON_OBJS = driverfuncs.o - -#ifndef XFree86Version - -/* This appears to be the quickest way to build a non-XFree86 server */ -GLXSRV_DEFINES = -DXFree86Server - -#endif - - GLX_SRCS = xf86glx.c xf86glx_util.c compsize.c - GLX_OBJS = xf86glx.o xf86glx_util.o compsize.o - - SRCS = $(DRIVER_SRCS) $(GLX_SRCS) $(COMMON_SRCS) - OBJS = $(DRIVER_OBJS) $(GLX_OBJS) $(COMMON_OBJS) - - INCLUDES = -I$(SERVERSRC)/GL/mesa/X -I$(XINCLUDESRC) \ - -I$(EXTINCSRC) \ - -I$(MESASRCDIR)/src/mesa \ - -I$(MESASRCDIR)/src/mesa/main \ - -I$(MESASRCDIR)/src/mesa/glapi \ - -I$(MESASRCDIR)/src/mesa/shader \ - -I$(MESASRCDIR)/src -I$(MESASRCDIR)/src/mesa/drivers/x11 \ - -I$(MESASRCDIR)/include \ - -I$(LIBSRC)/GL/glx -I$(LIBSRC)/GL/include \ - -I$(SERVERSRC)/include -I$(SERVERSRC)/GL/include \ - -I$(SERVERSRC)/GL/glx \ - -I$(XF86OSSRC) \ - -I$(DRMSRCDIR)/shared-core - - DEFINES = $(GLX_DEFINES) $(GLXSRV_DEFINES) /*-DUSE_X86_ASM*/ /*-DUSE_SPARC_ASM*/ - -#ifdef IHaveModules -ModuleObjectRule() -#else -NormalLibraryObjectRule() -#endif - -SubdirLibraryRule($(OBJS)) - -LintLibraryTarget(dri,$(SRCS)) -NormalLintTarget($(SRCS)) - -DependTarget() - -#ifdef IHaveSubdirs -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - -#if defined(IHaveModules) && BuildModuleInSubdir -LinkSourceFile(xf86glx.c,..) -LinkSourceFile(xf86glx_util.c,..) -#endif - -#ifndef MesaDrvSrcDir -#define MesaDrvSrcDir $(MESASRCDIR)/src/mesa/drivers/dri -#endif - -MESADRVSRCDIR = MesaDrvSrcDir - - -LinkSourceFile(driverfuncs.c, $(MESADRVSRCDIR)/../common) -LinkSourceFile(driverfuncs.h, $(MESADRVSRCDIR)/../common) diff --git a/nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.NX.original b/nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.NX.original deleted file mode 100644 index 19b5be637..000000000 --- a/nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.NX.original +++ /dev/null @@ -1,952 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/mesa/src/X/xf86glx.c,v 1.19 2003/07/16 01:38:27 dawes Exp $ */ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin - * Brian E. Paul - * - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "xf86glxint.h" -#include "context.h" -#include "xmesaP.h" -#include -#include "context.h" - -/* - * This define is for the glcore.h header file. - * If you add it here, then make sure you also add it in - * ../../../glx/Imakefile. - */ -#if 0 -#define DEBUG -#include -#undef DEBUG -#else -#include -#endif - -#include "glcontextmodes.h" - -#ifdef NXAGENT_SERVER -#include "../main/WSDrawBuffer.h" -#endif - -/* - * This structure is statically allocated in the __glXScreens[] - * structure. This struct is not used anywhere other than in - * __glXScreenInit to initialize each of the active screens - * (__glXActiveScreens[]). Several of the fields must be initialized by - * the screenProbe routine before they are copied to the active screens - * struct. In particular, the contextCreate, pGlxVisual, numVisuals, - * and numUsableVisuals fields must be initialized. - */ -static __GLXscreenInfo __glDDXScreenInfo = { - __MESA_screenProbe, /* Must be generic and handle all screens */ - __MESA_createContext, /* Substitute screen's createContext routine */ - __MESA_createBuffer, /* Substitute screen's createBuffer routine */ - NULL, /* Set up modes in probe */ - NULL, /* Set up pVisualPriv in probe */ - 0, /* Set up numVisuals in probe */ - 0, /* Set up numUsableVisuals in probe */ - NULL, /* GLextensions is overwritten by __glXScreenInit */ - "Vendor String", /* GLXvendor is overwritten by __glXScreenInit */ - "Version String", /* GLXversion is overwritten by __glXScreenInit */ - "Extensions String", /* GLXextensions is overwritten by __glXScreenInit */ - NULL /* WrappedPositionWindow is overwritten */ -}; - -#ifdef NXAGENT_SERVER -WSDrawBufferPtr pWSDrawBuffer = NULL; - -void AddWSDrawBuffer(GLframebuffer *mesa_buffer) -{ - WSDrawBufferPtr prevWSDB; - WSDrawBufferPtr newWSDB; - WSDrawBufferPtr p; - - prevWSDB = NULL; - newWSDB = NULL; - p = pWSDrawBuffer; - while (p != NULL) { - prevWSDB = p; - if (prevWSDB -> DrawBuffer == mesa_buffer) { - return; - } - p = p -> next; - } - newWSDB = malloc(sizeof(WSDrawBufferRec)); - newWSDB -> DrawBuffer = mesa_buffer; - newWSDB -> next = NULL; - - if (pWSDrawBuffer == NULL) - pWSDrawBuffer = newWSDB; - else - prevWSDB -> next = newWSDB; -} -#endif - -void *__glXglDDXScreenInfo(void) { - return &__glDDXScreenInfo; -} - -static __GLXextensionInfo __glDDXExtensionInfo = { - GL_CORE_MESA, - __MESA_resetExtension, - __MESA_initVisuals, - __MESA_setVisualConfigs -}; - -void *__glXglDDXExtensionInfo(void) { - return &__glDDXExtensionInfo; -} - -static __MESA_screen MESAScreens[MAXSCREENS]; -static __GLcontext *MESA_CC = NULL; - -static int numConfigs = 0; -static __GLXvisualConfig *visualConfigs = NULL; -static void **visualPrivates = NULL; - - -static int count_bits(unsigned int n) -{ - int bits = 0; - - while (n > 0) { - if (n & 1) bits++; - n >>= 1; - } - return bits; -} - - -static XMesaVisual find_mesa_visual(int screen, VisualID vid) -{ - __MESA_screen * const pMScr = &MESAScreens[screen]; - const __GLcontextModes *modes; - unsigned i = 0; - - for ( modes = pMScr->modes ; modes != NULL ; modes = modes->next ) { - if ( modes->visualID == vid ) { - break; - } - - i++; - } - - return (modes != NULL) ? pMScr->xm_vis[i] : NULL; -} - - -/* - * In the case the driver defines no GLX visuals we'll use these. - * Note that for TrueColor and DirectColor visuals, bufferSize is the - * sum of redSize, greenSize, blueSize and alphaSize, which may be larger - * than the nplanes/rootDepth of the server's X11 visuals - */ -#define NUM_FALLBACK_CONFIGS 5 -static __GLXvisualConfig FallbackConfigs[NUM_FALLBACK_CONFIGS] = { - /* [0] = RGB, double buffered, Z */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 0, /* rgba sizes */ - -1, -1, -1, 0, /* rgba masks */ - 0, 0, 0, 0, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 0, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [1] = RGB, double buffered, Z, stencil, accum */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 0, /* rgba sizes */ - -1, -1, -1, 0, /* rgba masks */ - 16, 16, 16, 0, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 8, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [2] = RGB+Alpha, double buffered, Z, stencil, accum */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 8, /* rgba sizes */ - -1, -1, -1, -1, /* rgba masks */ - 16, 16, 16, 16, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 8, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [3] = RGB+Alpha, single buffered, Z, stencil, accum */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 8, /* rgba sizes */ - -1, -1, -1, -1, /* rgba masks */ - 16, 16, 16, 16, /* rgba accum sizes */ - False, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 8, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [4] = CI, double buffered, Z */ - { - -1, /* vid */ - -1, /* class */ - False, /* rgba? (false = color index) */ - -1, -1, -1, 0, /* rgba sizes */ - -1, -1, -1, 0, /* rgba masks */ - 0, 0, 0, 0, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 0, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, -}; - - -static Bool init_visuals(int *nvisualp, VisualPtr *visualp, - VisualID *defaultVisp, - int ndepth, DepthPtr pdepth, - int rootDepth) -{ - int numRGBconfigs; - int numCIconfigs; - int numVisuals = *nvisualp; - int numNewVisuals; - int numNewConfigs; - VisualPtr pVisual = *visualp; - VisualPtr pVisualNew = NULL; - VisualID *orig_vid = NULL; - __GLcontextModes *modes; - __GLXvisualConfig *pNewVisualConfigs = NULL; - void **glXVisualPriv; - void **pNewVisualPriv; - int found_default; - int i, j, k; - - if (numConfigs > 0) - numNewConfigs = numConfigs; - else - numNewConfigs = NUM_FALLBACK_CONFIGS; - - /* Alloc space for the list of new GLX visuals */ - pNewVisualConfigs = (__GLXvisualConfig *) - __glXMalloc(numNewConfigs * sizeof(__GLXvisualConfig)); - if (!pNewVisualConfigs) { - return FALSE; - } - - /* Alloc space for the list of new GLX visual privates */ - pNewVisualPriv = (void **) __glXMalloc(numNewConfigs * sizeof(void *)); - if (!pNewVisualPriv) { - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* - ** If SetVisualConfigs was not called, then use default GLX - ** visual configs. - */ - if (numConfigs == 0) { - memcpy(pNewVisualConfigs, FallbackConfigs, - NUM_FALLBACK_CONFIGS * sizeof(__GLXvisualConfig)); - memset(pNewVisualPriv, 0, NUM_FALLBACK_CONFIGS * sizeof(void *)); - } - else { - /* copy driver's visual config info */ - for (i = 0; i < numConfigs; i++) { - pNewVisualConfigs[i] = visualConfigs[i]; - pNewVisualPriv[i] = visualPrivates[i]; - } - } - - /* Count the number of RGB and CI visual configs */ - numRGBconfigs = 0; - numCIconfigs = 0; - for (i = 0; i < numNewConfigs; i++) { - if (pNewVisualConfigs[i].rgba) - numRGBconfigs++; - else - numCIconfigs++; - } - - /* Count the total number of visuals to compute */ - numNewVisuals = 0; - for (i = 0; i < numVisuals; i++) { - numNewVisuals += - (pVisual[i].class == TrueColor || pVisual[i].class == DirectColor) - ? numRGBconfigs : numCIconfigs; - } - - /* Reset variables for use with the next screen/driver's visual configs */ - visualConfigs = NULL; - numConfigs = 0; - - /* Alloc temp space for the list of orig VisualIDs for each new visual */ - orig_vid = (VisualID *)__glXMalloc(numNewVisuals * sizeof(VisualID)); - if (!orig_vid) { - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Alloc space for the list of glXVisuals */ - modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLcontextModes)); - if (modes == NULL) { - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Alloc space for the list of glXVisualPrivates */ - glXVisualPriv = (void **)__glXMalloc(numNewVisuals * sizeof(void *)); - if (!glXVisualPriv) { - _gl_context_modes_destroy( modes ); - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Alloc space for the new list of the X server's visuals */ - pVisualNew = (VisualPtr)__glXMalloc(numNewVisuals * sizeof(VisualRec)); - if (!pVisualNew) { - __glXFree(glXVisualPriv); - _gl_context_modes_destroy( modes ); - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Initialize the new visuals */ - found_default = FALSE; - MESAScreens[screenInfo.numScreens-1].modes = modes; - for (i = j = 0; i < numVisuals; i++) { - int is_rgb = (pVisual[i].class == TrueColor || - pVisual[i].class == DirectColor); - - for (k = 0; k < numNewConfigs; k++) { - if (pNewVisualConfigs[k].rgba != is_rgb) - continue; - - assert( modes != NULL ); - - /* Initialize the new visual */ - pVisualNew[j] = pVisual[i]; - pVisualNew[j].vid = FakeClientID(0); - - /* Check for the default visual */ - if (!found_default && pVisual[i].vid == *defaultVisp) { - *defaultVisp = pVisualNew[j].vid; - found_default = TRUE; - } - - /* Save the old VisualID */ - orig_vid[j] = pVisual[i].vid; - - /* Initialize the glXVisual */ - _gl_copy_visual_to_context_mode( modes, & pNewVisualConfigs[k] ); - modes->visualID = pVisualNew[j].vid; - - /* - * If the class is -1, then assume the X visual information - * is identical to what GLX needs, and take them from the X - * visual. NOTE: if class != -1, then all other fields MUST - * be initialized. - */ - if (modes->visualType == GLX_NONE) { - modes->visualType = _gl_convert_from_x_visual_type( pVisual[i].class ); - modes->redBits = count_bits(pVisual[i].redMask); - modes->greenBits = count_bits(pVisual[i].greenMask); - modes->blueBits = count_bits(pVisual[i].blueMask); - modes->alphaBits = modes->alphaBits; - modes->redMask = pVisual[i].redMask; - modes->greenMask = pVisual[i].greenMask; - modes->blueMask = pVisual[i].blueMask; - modes->alphaMask = modes->alphaMask; - modes->rgbBits = (is_rgb) - ? (modes->redBits + modes->greenBits + - modes->blueBits + modes->alphaBits) - : rootDepth; - } - - /* Save the device-dependent private for this visual */ - glXVisualPriv[j] = pNewVisualPriv[k]; - - j++; - modes = modes->next; - } - } - - assert(j <= numNewVisuals); - - /* Save the GLX visuals in the screen structure */ - MESAScreens[screenInfo.numScreens-1].num_vis = numNewVisuals; - MESAScreens[screenInfo.numScreens-1].private = glXVisualPriv; - - /* Set up depth's VisualIDs */ - for (i = 0; i < ndepth; i++) { - int numVids = 0; - VisualID *pVids = NULL; - int k, n = 0; - - /* Count the new number of VisualIDs at this depth */ - for (j = 0; j < pdepth[i].numVids; j++) - for (k = 0; k < numNewVisuals; k++) - if (pdepth[i].vids[j] == orig_vid[k]) - numVids++; - - /* Allocate a new list of VisualIDs for this depth */ - pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID)); - - /* Initialize the new list of VisualIDs for this depth */ - for (j = 0; j < pdepth[i].numVids; j++) - for (k = 0; k < numNewVisuals; k++) - if (pdepth[i].vids[j] == orig_vid[k]) - pVids[n++] = pVisualNew[k].vid; - - /* Update this depth's list of VisualIDs */ - __glXFree(pdepth[i].vids); - pdepth[i].vids = pVids; - pdepth[i].numVids = numVids; - } - - /* Update the X server's visuals */ - *nvisualp = numNewVisuals; - *visualp = pVisualNew; - - /* Free the old list of the X server's visuals */ - __glXFree(pVisual); - - /* Clean up temporary allocations */ - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - - /* Free the private list created by DDX HW driver */ - if (visualPrivates) - xfree(visualPrivates); - visualPrivates = NULL; - - return TRUE; -} - -void __MESA_setVisualConfigs(int nconfigs, __GLXvisualConfig *configs, - void **privates) -{ - numConfigs = nconfigs; - visualConfigs = configs; - visualPrivates = privates; -} - -Bool __MESA_initVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, int *rootDepthp, - VisualID *defaultVisp, unsigned long sizes, - int bitsPerRGB) -{ - /* - * Setup the visuals supported by this particular screen. - */ - return init_visuals(nvisualp, visualp, defaultVisp, - *ndepthp, *depthp, *rootDepthp); -} - -static void fixup_visuals(int screen) -{ - ScreenPtr pScreen = screenInfo.screens[screen]; - __MESA_screen *pMScr = &MESAScreens[screen]; - int j; - __GLcontextModes *modes; - - for ( modes = pMScr->modes ; modes != NULL ; modes = modes->next ) { - const int vis_class = _gl_convert_to_x_visual_type( modes->visualType ); - const int nplanes = (modes->rgbBits - modes->alphaBits); - const VisualPtr pVis = pScreen->visuals; - - /* Find a visual that matches the GLX visual's class and size */ - for (j = 0; j < pScreen->numVisuals; j++) { - if (pVis[j].class == vis_class && - pVis[j].nplanes == nplanes) { - - /* Fixup the masks */ - modes->redMask = pVis[j].redMask; - modes->greenMask = pVis[j].greenMask; - modes->blueMask = pVis[j].blueMask; - - /* Recalc the sizes */ - modes->redBits = count_bits(modes->redMask); - modes->greenBits = count_bits(modes->greenMask); - modes->blueBits = count_bits(modes->blueMask); - } - } - } -} - -static void init_screen_visuals(int screen) -{ - ScreenPtr pScreen = screenInfo.screens[screen]; - __GLcontextModes *modes; - XMesaVisual *pXMesaVisual; - int *used; - int i, j; - - /* Alloc space for the list of XMesa visuals */ - pXMesaVisual = (XMesaVisual *)__glXMalloc(MESAScreens[screen].num_vis * - sizeof(XMesaVisual)); - __glXMemset(pXMesaVisual, 0, - MESAScreens[screen].num_vis * sizeof(XMesaVisual)); - - /* FIXME: Change 'used' to be a array of bits (rather than of ints), - * FIXME: create a stack array of 8 or 16 bytes. If 'numVisuals' is less - * FIXME: than 64 or 128 the stack array can be used instead of calling - * FIXME: __glXMalloc / __glXFree. If nothing else, convert 'used' to - * FIXME: array of bytes instead of ints! - */ - used = (int *)__glXMalloc(pScreen->numVisuals * sizeof(int)); - __glXMemset(used, 0, pScreen->numVisuals * sizeof(int)); - - i = 0; - for ( modes = MESAScreens[screen].modes - ; modes != NULL - ; modes = modes->next ) { - const int vis_class = _gl_convert_to_x_visual_type( modes->visualType ); - const int nplanes = (modes->rgbBits - modes->alphaBits); - const VisualPtr pVis = pScreen->visuals; - - for (j = 0; j < pScreen->numVisuals; j++) { - if (pVis[j].class == vis_class && - pVis[j].nplanes == nplanes && - pVis[j].redMask == modes->redMask && - pVis[j].greenMask == modes->greenMask && - pVis[j].blueMask == modes->blueMask && - !used[j]) { - - /* Create the XMesa visual */ - pXMesaVisual[i] = - XMesaCreateVisual(pScreen, - pVis, - modes->rgbMode, - (modes->alphaBits > 0), - modes->doubleBufferMode, - modes->stereoMode, - GL_TRUE, /* ximage_flag */ - modes->depthBits, - modes->stencilBits, - modes->accumRedBits, - modes->accumGreenBits, - modes->accumBlueBits, - modes->accumAlphaBits, - modes->samples, - modes->level, - modes->visualRating); - /* Set the VisualID */ - modes->visualID = pVis[j].vid; - - /* Mark this visual used */ - used[j] = 1; - break; - } - } - - if ( j == pScreen->numVisuals ) { - ErrorF("No matching visual for __GLcontextMode with " - "visual class = %d (%d), nplanes = %u\n", - vis_class, - modes->visualType, - (modes->rgbBits - modes->alphaBits) ); - } - else if ( modes->visualID == -1 ) { - FatalError( "Matching visual found, but visualID still -1!\n" ); - } - - i++; - } - - __glXFree(used); - - MESAScreens[screen].xm_vis = pXMesaVisual; -} - -Bool __MESA_screenProbe(int screen) -{ - /* - * Set up the current screen's visuals. - */ - __glDDXScreenInfo.modes = MESAScreens[screen].modes; - __glDDXScreenInfo.pVisualPriv = MESAScreens[screen].private; - __glDDXScreenInfo.numVisuals = - __glDDXScreenInfo.numUsableVisuals = MESAScreens[screen].num_vis; - - /* - * Set the current screen's createContext routine. This could be - * wrapped by a DDX GLX context creation routine. - */ - __glDDXScreenInfo.createContext = __MESA_createContext; - - /* - * The ordering of the rgb compenents might have been changed by the - * driver after mi initialized them. - */ - fixup_visuals(screen); - - /* - * Find the GLX visuals that are supported by this screen and create - * XMesa's visuals. - */ - init_screen_visuals(screen); - - return TRUE; -} - -extern void __MESA_resetExtension(void) -{ - int i, j; - - XMesaReset(); - - for (i = 0; i < screenInfo.numScreens; i++) { - for (j = 0; j < MESAScreens[i].num_vis; j++) { - if (MESAScreens[i].xm_vis[j]) { - XMesaDestroyVisual(MESAScreens[i].xm_vis[j]); - MESAScreens[i].xm_vis[j] = NULL; - } - } - _gl_context_modes_destroy( MESAScreens[i].modes ); - MESAScreens[i].modes = NULL; - __glXFree(MESAScreens[i].private); - MESAScreens[i].private = NULL; - __glXFree(MESAScreens[i].xm_vis); - MESAScreens[i].xm_vis = NULL; - MESAScreens[i].num_vis = 0; - } - __glDDXScreenInfo.modes = NULL; - MESA_CC = NULL; -} - -void __MESA_createBuffer(__GLXdrawablePrivate *glxPriv) -{ - DrawablePtr pDraw = glxPriv->pDraw; - XMesaVisual xm_vis = find_mesa_visual(pDraw->pScreen->myNum, - glxPriv->modes->visualID); - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - __MESA_buffer buf; - - if (xm_vis == NULL) { - ErrorF("find_mesa_visual returned NULL for visualID = 0x%04x\n", - glxPriv->modes->visualID); - } - buf = (__MESA_buffer)__glXMalloc(sizeof(struct __MESA_bufferRec)); - - /* Create Mesa's buffers */ - if (glxPriv->type == DRAWABLE_WINDOW) { - buf->xm_buf = (void *)XMesaCreateWindowBuffer(xm_vis, - (WindowPtr)pDraw); - } else { - buf->xm_buf = (void *)XMesaCreatePixmapBuffer(xm_vis, - (PixmapPtr)pDraw, 0); - } - - /* Wrap the front buffer's resize routine */ - buf->fbresize = glPriv->frontBuffer.resize; - glPriv->frontBuffer.resize = __MESA_resizeBuffers; - - /* Wrap the swap buffers routine */ - buf->fbswap = glxPriv->swapBuffers; - glxPriv->swapBuffers = __MESA_swapBuffers; - - /* Save Mesa's private buffer structure */ - glPriv->private = (void *)buf; - glPriv->freePrivate = __MESA_destroyBuffer; -} - -GLboolean __MESA_resizeBuffers(__GLdrawableBuffer *buffer, - GLint x, GLint y, - GLuint width, GLuint height, - __GLdrawablePrivate *glPriv, - GLuint bufferMask) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - - if (buf->xm_buf) - XMesaResizeBuffers(buf->xm_buf); - - return (*buf->fbresize)(buffer, x, y, width, height, glPriv, bufferMask); -} - -GLboolean __MESA_swapBuffers(__GLXdrawablePrivate *glxPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glxPriv->glPriv.private; - - /* - ** Do not call the wrapped swap buffers routine since Mesa has - ** already done the swap. - */ - XMesaSwapBuffers(buf->xm_buf); - - return GL_TRUE; -} - -void __MESA_destroyBuffer(__GLdrawablePrivate *glPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - __GLXdrawablePrivate *glxPriv = (__GLXdrawablePrivate *)glPriv->other; - -#ifdef NXAGENT_SERVER - AddWSDrawBuffer(& (buf -> xm_buf -> mesa_buffer) ); -#endif - - /* Destroy Mesa's buffers */ - if (buf->xm_buf) - XMesaDestroyBuffer(buf->xm_buf); - - /* Unwrap these routines */ - glxPriv->swapBuffers = buf->fbswap; - glPriv->frontBuffer.resize = buf->fbresize; - - __glXFree(glPriv->private); - glPriv->private = NULL; -} - -__GLinterface *__MESA_createContext(__GLimports *imports, - __GLcontextModes *modes, - __GLinterface *shareGC) -{ - __GLcontext *gl_ctx = NULL; - __GLcontext *m_share = NULL; - __GLXcontext *glxc = (__GLXcontext *)imports->other; - XMesaVisual xm_vis; - - if (shareGC) - m_share = (__GLcontext *)shareGC; - - xm_vis = find_mesa_visual(glxc->pScreen->myNum, glxc->modes->visualID); - if (xm_vis) { - XMesaContext xmshare = m_share ? m_share->DriverCtx : 0; - XMesaContext xmctx = XMesaCreateContext(xm_vis, xmshare); - gl_ctx = xmctx ? &xmctx->mesa : 0; - } - else { - ErrorF("find_mesa_visual returned NULL for visualID = 0x%04x\n", - glxc->modes->visualID); - } - - - if (!gl_ctx) - return NULL; - - gl_ctx->imports = *imports; - gl_ctx->exports.destroyContext = __MESA_destroyContext; - gl_ctx->exports.loseCurrent = __MESA_loseCurrent; - gl_ctx->exports.makeCurrent = __MESA_makeCurrent; - gl_ctx->exports.shareContext = __MESA_shareContext; - gl_ctx->exports.copyContext = __MESA_copyContext; - gl_ctx->exports.forceCurrent = __MESA_forceCurrent; - gl_ctx->exports.notifyResize = __MESA_notifyResize; - gl_ctx->exports.notifyDestroy = __MESA_notifyDestroy; - gl_ctx->exports.notifySwapBuffers = __MESA_notifySwapBuffers; - gl_ctx->exports.dispatchExec = __MESA_dispatchExec; - gl_ctx->exports.beginDispatchOverride = __MESA_beginDispatchOverride; - gl_ctx->exports.endDispatchOverride = __MESA_endDispatchOverride; - - return (__GLinterface *)gl_ctx; -} - -GLboolean __MESA_destroyContext(__GLcontext *gc) -{ - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - XMesaDestroyContext( xmesa ); - return GL_TRUE; -} - -GLboolean __MESA_loseCurrent(__GLcontext *gc) -{ - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - MESA_CC = NULL; - __glXLastContext = NULL; - return XMesaLoseCurrent(xmesa); -} - -GLboolean __MESA_makeCurrent(__GLcontext *gc) -{ - __GLdrawablePrivate *drawPriv = gc->imports.getDrawablePrivate( gc ); - __MESA_buffer drawBuf = (__MESA_buffer)drawPriv->private; - __GLdrawablePrivate *readPriv = gc->imports.getReadablePrivate( gc ); - __MESA_buffer readBuf = (__MESA_buffer)readPriv->private; - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - - MESA_CC = gc; - return XMesaMakeCurrent2(xmesa, drawBuf->xm_buf, readBuf->xm_buf); -} - -GLboolean __MESA_shareContext(__GLcontext *gc, __GLcontext *gcShare) -{ - /* NOT_DONE */ - /* XXX I don't see where/how this could ever be called */ - ErrorF("__MESA_shareContext\n"); - return GL_FALSE; -} - -GLboolean __MESA_copyContext(__GLcontext *dst, const __GLcontext *src, - GLuint mask) -{ - XMesaContext xm_dst = (XMesaContext) dst->DriverCtx; - const XMesaContext xm_src = (const XMesaContext) src->DriverCtx; - _mesa_copy_context(&xm_src->mesa, &xm_dst->mesa, mask); - return GL_TRUE; -} - -GLboolean __MESA_forceCurrent(__GLcontext *gc) -{ - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - MESA_CC = gc; - return XMesaForceCurrent(xmesa); -} - -GLboolean __MESA_notifyResize(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifyResize\n"); - return GL_FALSE; -} - -void __MESA_notifyDestroy(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifyDestroy\n"); - return; -} - -void __MESA_notifySwapBuffers(__GLcontext *gc) -{ - _mesa_notifySwapBuffers(gc); -} - -struct __GLdispatchStateRec *__MESA_dispatchExec(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_dispatchExec\n"); - return NULL; -} - -void __MESA_beginDispatchOverride(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_beginDispatchOverride\n"); - return; -} - -void __MESA_endDispatchOverride(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_endDispatchOverride\n"); - return; -} - - -/* - * Server-side GLX uses these functions which are normally defined - * in the OpenGL SI. - */ - -GLuint __glFloorLog2(GLuint val) -{ - int c = 0; - - while (val > 1) { - c++; - val >>= 1; - } - return c; -} - diff --git a/nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.X.original b/nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.X.original deleted file mode 100644 index 5dd4e7c37..000000000 --- a/nx-X11/programs/Xserver/GL/mesa/X/xf86glx.c.X.original +++ /dev/null @@ -1,914 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/mesa/src/X/xf86glx.c,v 1.19 2003/07/16 01:38:27 dawes Exp $ */ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin - * Brian E. Paul - * - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "xf86glxint.h" -#include "context.h" -#include "xmesaP.h" -#include -#include "context.h" - -/* - * This define is for the glcore.h header file. - * If you add it here, then make sure you also add it in - * ../../../glx/Imakefile. - */ -#if 0 -#define DEBUG -#include -#undef DEBUG -#else -#include -#endif - -#include "glcontextmodes.h" - -/* - * This structure is statically allocated in the __glXScreens[] - * structure. This struct is not used anywhere other than in - * __glXScreenInit to initialize each of the active screens - * (__glXActiveScreens[]). Several of the fields must be initialized by - * the screenProbe routine before they are copied to the active screens - * struct. In particular, the contextCreate, pGlxVisual, numVisuals, - * and numUsableVisuals fields must be initialized. - */ -static __GLXscreenInfo __glDDXScreenInfo = { - __MESA_screenProbe, /* Must be generic and handle all screens */ - __MESA_createContext, /* Substitute screen's createContext routine */ - __MESA_createBuffer, /* Substitute screen's createBuffer routine */ - NULL, /* Set up modes in probe */ - NULL, /* Set up pVisualPriv in probe */ - 0, /* Set up numVisuals in probe */ - 0, /* Set up numUsableVisuals in probe */ - NULL, /* GLextensions is overwritten by __glXScreenInit */ - "Vendor String", /* GLXvendor is overwritten by __glXScreenInit */ - "Version String", /* GLXversion is overwritten by __glXScreenInit */ - "Extensions String", /* GLXextensions is overwritten by __glXScreenInit */ - NULL /* WrappedPositionWindow is overwritten */ -}; - -void *__glXglDDXScreenInfo(void) { - return &__glDDXScreenInfo; -} - -static __GLXextensionInfo __glDDXExtensionInfo = { - GL_CORE_MESA, - __MESA_resetExtension, - __MESA_initVisuals, - __MESA_setVisualConfigs -}; - -void *__glXglDDXExtensionInfo(void) { - return &__glDDXExtensionInfo; -} - -static __MESA_screen MESAScreens[MAXSCREENS]; -static __GLcontext *MESA_CC = NULL; - -static int numConfigs = 0; -static __GLXvisualConfig *visualConfigs = NULL; -static void **visualPrivates = NULL; - - -static int count_bits(unsigned int n) -{ - int bits = 0; - - while (n > 0) { - if (n & 1) bits++; - n >>= 1; - } - return bits; -} - - -static XMesaVisual find_mesa_visual(int screen, VisualID vid) -{ - __MESA_screen * const pMScr = &MESAScreens[screen]; - const __GLcontextModes *modes; - unsigned i = 0; - - for ( modes = pMScr->modes ; modes != NULL ; modes = modes->next ) { - if ( modes->visualID == vid ) { - break; - } - - i++; - } - - return (modes != NULL) ? pMScr->xm_vis[i] : NULL; -} - - -/* - * In the case the driver defines no GLX visuals we'll use these. - * Note that for TrueColor and DirectColor visuals, bufferSize is the - * sum of redSize, greenSize, blueSize and alphaSize, which may be larger - * than the nplanes/rootDepth of the server's X11 visuals - */ -#define NUM_FALLBACK_CONFIGS 5 -static __GLXvisualConfig FallbackConfigs[NUM_FALLBACK_CONFIGS] = { - /* [0] = RGB, double buffered, Z */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 0, /* rgba sizes */ - -1, -1, -1, 0, /* rgba masks */ - 0, 0, 0, 0, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 0, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [1] = RGB, double buffered, Z, stencil, accum */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 0, /* rgba sizes */ - -1, -1, -1, 0, /* rgba masks */ - 16, 16, 16, 0, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 8, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [2] = RGB+Alpha, double buffered, Z, stencil, accum */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 8, /* rgba sizes */ - -1, -1, -1, -1, /* rgba masks */ - 16, 16, 16, 16, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 8, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [3] = RGB+Alpha, single buffered, Z, stencil, accum */ - { - -1, /* vid */ - -1, /* class */ - True, /* rgba */ - -1, -1, -1, 8, /* rgba sizes */ - -1, -1, -1, -1, /* rgba masks */ - 16, 16, 16, 16, /* rgba accum sizes */ - False, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 8, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, - /* [4] = CI, double buffered, Z */ - { - -1, /* vid */ - -1, /* class */ - False, /* rgba? (false = color index) */ - -1, -1, -1, 0, /* rgba sizes */ - -1, -1, -1, 0, /* rgba masks */ - 0, 0, 0, 0, /* rgba accum sizes */ - True, /* doubleBuffer */ - False, /* stereo */ - -1, /* bufferSize */ - 16, /* depthSize */ - 0, /* stencilSize */ - 0, /* auxBuffers */ - 0, /* level */ - GLX_NONE, /* visualRating */ - GLX_NONE, /* transparentPixel */ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ - 0 /* transparentIndex */ - }, -}; - - -static Bool init_visuals(int *nvisualp, VisualPtr *visualp, - VisualID *defaultVisp, - int ndepth, DepthPtr pdepth, - int rootDepth) -{ - int numRGBconfigs; - int numCIconfigs; - int numVisuals = *nvisualp; - int numNewVisuals; - int numNewConfigs; - VisualPtr pVisual = *visualp; - VisualPtr pVisualNew = NULL; - VisualID *orig_vid = NULL; - __GLcontextModes *modes; - __GLXvisualConfig *pNewVisualConfigs = NULL; - void **glXVisualPriv; - void **pNewVisualPriv; - int found_default; - int i, j, k; - - if (numConfigs > 0) - numNewConfigs = numConfigs; - else - numNewConfigs = NUM_FALLBACK_CONFIGS; - - /* Alloc space for the list of new GLX visuals */ - pNewVisualConfigs = (__GLXvisualConfig *) - __glXMalloc(numNewConfigs * sizeof(__GLXvisualConfig)); - if (!pNewVisualConfigs) { - return FALSE; - } - - /* Alloc space for the list of new GLX visual privates */ - pNewVisualPriv = (void **) __glXMalloc(numNewConfigs * sizeof(void *)); - if (!pNewVisualPriv) { - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* - ** If SetVisualConfigs was not called, then use default GLX - ** visual configs. - */ - if (numConfigs == 0) { - memcpy(pNewVisualConfigs, FallbackConfigs, - NUM_FALLBACK_CONFIGS * sizeof(__GLXvisualConfig)); - memset(pNewVisualPriv, 0, NUM_FALLBACK_CONFIGS * sizeof(void *)); - } - else { - /* copy driver's visual config info */ - for (i = 0; i < numConfigs; i++) { - pNewVisualConfigs[i] = visualConfigs[i]; - pNewVisualPriv[i] = visualPrivates[i]; - } - } - - /* Count the number of RGB and CI visual configs */ - numRGBconfigs = 0; - numCIconfigs = 0; - for (i = 0; i < numNewConfigs; i++) { - if (pNewVisualConfigs[i].rgba) - numRGBconfigs++; - else - numCIconfigs++; - } - - /* Count the total number of visuals to compute */ - numNewVisuals = 0; - for (i = 0; i < numVisuals; i++) { - numNewVisuals += - (pVisual[i].class == TrueColor || pVisual[i].class == DirectColor) - ? numRGBconfigs : numCIconfigs; - } - - /* Reset variables for use with the next screen/driver's visual configs */ - visualConfigs = NULL; - numConfigs = 0; - - /* Alloc temp space for the list of orig VisualIDs for each new visual */ - orig_vid = (VisualID *)__glXMalloc(numNewVisuals * sizeof(VisualID)); - if (!orig_vid) { - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Alloc space for the list of glXVisuals */ - modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLcontextModes)); - if (modes == NULL) { - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Alloc space for the list of glXVisualPrivates */ - glXVisualPriv = (void **)__glXMalloc(numNewVisuals * sizeof(void *)); - if (!glXVisualPriv) { - _gl_context_modes_destroy( modes ); - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Alloc space for the new list of the X server's visuals */ - pVisualNew = (VisualPtr)__glXMalloc(numNewVisuals * sizeof(VisualRec)); - if (!pVisualNew) { - __glXFree(glXVisualPriv); - _gl_context_modes_destroy( modes ); - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - return FALSE; - } - - /* Initialize the new visuals */ - found_default = FALSE; - MESAScreens[screenInfo.numScreens-1].modes = modes; - for (i = j = 0; i < numVisuals; i++) { - int is_rgb = (pVisual[i].class == TrueColor || - pVisual[i].class == DirectColor); - - for (k = 0; k < numNewConfigs; k++) { - if (pNewVisualConfigs[k].rgba != is_rgb) - continue; - - assert( modes != NULL ); - - /* Initialize the new visual */ - pVisualNew[j] = pVisual[i]; - pVisualNew[j].vid = FakeClientID(0); - - /* Check for the default visual */ - if (!found_default && pVisual[i].vid == *defaultVisp) { - *defaultVisp = pVisualNew[j].vid; - found_default = TRUE; - } - - /* Save the old VisualID */ - orig_vid[j] = pVisual[i].vid; - - /* Initialize the glXVisual */ - _gl_copy_visual_to_context_mode( modes, & pNewVisualConfigs[k] ); - modes->visualID = pVisualNew[j].vid; - - /* - * If the class is -1, then assume the X visual information - * is identical to what GLX needs, and take them from the X - * visual. NOTE: if class != -1, then all other fields MUST - * be initialized. - */ - if (modes->visualType == GLX_NONE) { - modes->visualType = _gl_convert_from_x_visual_type( pVisual[i].class ); - modes->redBits = count_bits(pVisual[i].redMask); - modes->greenBits = count_bits(pVisual[i].greenMask); - modes->blueBits = count_bits(pVisual[i].blueMask); - modes->alphaBits = modes->alphaBits; - modes->redMask = pVisual[i].redMask; - modes->greenMask = pVisual[i].greenMask; - modes->blueMask = pVisual[i].blueMask; - modes->alphaMask = modes->alphaMask; - modes->rgbBits = (is_rgb) - ? (modes->redBits + modes->greenBits + - modes->blueBits + modes->alphaBits) - : rootDepth; - } - - /* Save the device-dependent private for this visual */ - glXVisualPriv[j] = pNewVisualPriv[k]; - - j++; - modes = modes->next; - } - } - - assert(j <= numNewVisuals); - - /* Save the GLX visuals in the screen structure */ - MESAScreens[screenInfo.numScreens-1].num_vis = numNewVisuals; - MESAScreens[screenInfo.numScreens-1].private = glXVisualPriv; - - /* Set up depth's VisualIDs */ - for (i = 0; i < ndepth; i++) { - int numVids = 0; - VisualID *pVids = NULL; - int k, n = 0; - - /* Count the new number of VisualIDs at this depth */ - for (j = 0; j < pdepth[i].numVids; j++) - for (k = 0; k < numNewVisuals; k++) - if (pdepth[i].vids[j] == orig_vid[k]) - numVids++; - - /* Allocate a new list of VisualIDs for this depth */ - pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID)); - - /* Initialize the new list of VisualIDs for this depth */ - for (j = 0; j < pdepth[i].numVids; j++) - for (k = 0; k < numNewVisuals; k++) - if (pdepth[i].vids[j] == orig_vid[k]) - pVids[n++] = pVisualNew[k].vid; - - /* Update this depth's list of VisualIDs */ - __glXFree(pdepth[i].vids); - pdepth[i].vids = pVids; - pdepth[i].numVids = numVids; - } - - /* Update the X server's visuals */ - *nvisualp = numNewVisuals; - *visualp = pVisualNew; - - /* Free the old list of the X server's visuals */ - __glXFree(pVisual); - - /* Clean up temporary allocations */ - __glXFree(orig_vid); - __glXFree(pNewVisualPriv); - __glXFree(pNewVisualConfigs); - - /* Free the private list created by DDX HW driver */ - if (visualPrivates) - xfree(visualPrivates); - visualPrivates = NULL; - - return TRUE; -} - -void __MESA_setVisualConfigs(int nconfigs, __GLXvisualConfig *configs, - void **privates) -{ - numConfigs = nconfigs; - visualConfigs = configs; - visualPrivates = privates; -} - -Bool __MESA_initVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, int *rootDepthp, - VisualID *defaultVisp, unsigned long sizes, - int bitsPerRGB) -{ - /* - * Setup the visuals supported by this particular screen. - */ - return init_visuals(nvisualp, visualp, defaultVisp, - *ndepthp, *depthp, *rootDepthp); -} - -static void fixup_visuals(int screen) -{ - ScreenPtr pScreen = screenInfo.screens[screen]; - __MESA_screen *pMScr = &MESAScreens[screen]; - int j; - __GLcontextModes *modes; - - for ( modes = pMScr->modes ; modes != NULL ; modes = modes->next ) { - const int vis_class = _gl_convert_to_x_visual_type( modes->visualType ); - const int nplanes = (modes->rgbBits - modes->alphaBits); - const VisualPtr pVis = pScreen->visuals; - - /* Find a visual that matches the GLX visual's class and size */ - for (j = 0; j < pScreen->numVisuals; j++) { - if (pVis[j].class == vis_class && - pVis[j].nplanes == nplanes) { - - /* Fixup the masks */ - modes->redMask = pVis[j].redMask; - modes->greenMask = pVis[j].greenMask; - modes->blueMask = pVis[j].blueMask; - - /* Recalc the sizes */ - modes->redBits = count_bits(modes->redMask); - modes->greenBits = count_bits(modes->greenMask); - modes->blueBits = count_bits(modes->blueMask); - } - } - } -} - -static void init_screen_visuals(int screen) -{ - ScreenPtr pScreen = screenInfo.screens[screen]; - __GLcontextModes *modes; - XMesaVisual *pXMesaVisual; - int *used; - int i, j; - - /* Alloc space for the list of XMesa visuals */ - pXMesaVisual = (XMesaVisual *)__glXMalloc(MESAScreens[screen].num_vis * - sizeof(XMesaVisual)); - __glXMemset(pXMesaVisual, 0, - MESAScreens[screen].num_vis * sizeof(XMesaVisual)); - - /* FIXME: Change 'used' to be a array of bits (rather than of ints), - * FIXME: create a stack array of 8 or 16 bytes. If 'numVisuals' is less - * FIXME: than 64 or 128 the stack array can be used instead of calling - * FIXME: __glXMalloc / __glXFree. If nothing else, convert 'used' to - * FIXME: array of bytes instead of ints! - */ - used = (int *)__glXMalloc(pScreen->numVisuals * sizeof(int)); - __glXMemset(used, 0, pScreen->numVisuals * sizeof(int)); - - i = 0; - for ( modes = MESAScreens[screen].modes - ; modes != NULL - ; modes = modes->next ) { - const int vis_class = _gl_convert_to_x_visual_type( modes->visualType ); - const int nplanes = (modes->rgbBits - modes->alphaBits); - const VisualPtr pVis = pScreen->visuals; - - for (j = 0; j < pScreen->numVisuals; j++) { - if (pVis[j].class == vis_class && - pVis[j].nplanes == nplanes && - pVis[j].redMask == modes->redMask && - pVis[j].greenMask == modes->greenMask && - pVis[j].blueMask == modes->blueMask && - !used[j]) { - - /* Create the XMesa visual */ - pXMesaVisual[i] = - XMesaCreateVisual(pScreen, - pVis, - modes->rgbMode, - (modes->alphaBits > 0), - modes->doubleBufferMode, - modes->stereoMode, - GL_TRUE, /* ximage_flag */ - modes->depthBits, - modes->stencilBits, - modes->accumRedBits, - modes->accumGreenBits, - modes->accumBlueBits, - modes->accumAlphaBits, - modes->samples, - modes->level, - modes->visualRating); - /* Set the VisualID */ - modes->visualID = pVis[j].vid; - - /* Mark this visual used */ - used[j] = 1; - break; - } - } - - if ( j == pScreen->numVisuals ) { - ErrorF("No matching visual for __GLcontextMode with " - "visual class = %d (%d), nplanes = %u\n", - vis_class, - modes->visualType, - (modes->rgbBits - modes->alphaBits) ); - } - else if ( modes->visualID == -1 ) { - FatalError( "Matching visual found, but visualID still -1!\n" ); - } - - i++; - } - - __glXFree(used); - - MESAScreens[screen].xm_vis = pXMesaVisual; -} - -Bool __MESA_screenProbe(int screen) -{ - /* - * Set up the current screen's visuals. - */ - __glDDXScreenInfo.modes = MESAScreens[screen].modes; - __glDDXScreenInfo.pVisualPriv = MESAScreens[screen].private; - __glDDXScreenInfo.numVisuals = - __glDDXScreenInfo.numUsableVisuals = MESAScreens[screen].num_vis; - - /* - * Set the current screen's createContext routine. This could be - * wrapped by a DDX GLX context creation routine. - */ - __glDDXScreenInfo.createContext = __MESA_createContext; - - /* - * The ordering of the rgb compenents might have been changed by the - * driver after mi initialized them. - */ - fixup_visuals(screen); - - /* - * Find the GLX visuals that are supported by this screen and create - * XMesa's visuals. - */ - init_screen_visuals(screen); - - return TRUE; -} - -extern void __MESA_resetExtension(void) -{ - int i, j; - - XMesaReset(); - - for (i = 0; i < screenInfo.numScreens; i++) { - for (j = 0; j < MESAScreens[i].num_vis; j++) { - if (MESAScreens[i].xm_vis[j]) { - XMesaDestroyVisual(MESAScreens[i].xm_vis[j]); - MESAScreens[i].xm_vis[j] = NULL; - } - } - _gl_context_modes_destroy( MESAScreens[i].modes ); - MESAScreens[i].modes = NULL; - __glXFree(MESAScreens[i].private); - MESAScreens[i].private = NULL; - __glXFree(MESAScreens[i].xm_vis); - MESAScreens[i].xm_vis = NULL; - MESAScreens[i].num_vis = 0; - } - __glDDXScreenInfo.modes = NULL; - MESA_CC = NULL; -} - -void __MESA_createBuffer(__GLXdrawablePrivate *glxPriv) -{ - DrawablePtr pDraw = glxPriv->pDraw; - XMesaVisual xm_vis = find_mesa_visual(pDraw->pScreen->myNum, - glxPriv->modes->visualID); - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - __MESA_buffer buf; - - if (xm_vis == NULL) { - ErrorF("find_mesa_visual returned NULL for visualID = 0x%04x\n", - glxPriv->modes->visualID); - } - buf = (__MESA_buffer)__glXMalloc(sizeof(struct __MESA_bufferRec)); - - /* Create Mesa's buffers */ - if (glxPriv->type == DRAWABLE_WINDOW) { - buf->xm_buf = (void *)XMesaCreateWindowBuffer(xm_vis, - (WindowPtr)pDraw); - } else { - buf->xm_buf = (void *)XMesaCreatePixmapBuffer(xm_vis, - (PixmapPtr)pDraw, 0); - } - - /* Wrap the front buffer's resize routine */ - buf->fbresize = glPriv->frontBuffer.resize; - glPriv->frontBuffer.resize = __MESA_resizeBuffers; - - /* Wrap the swap buffers routine */ - buf->fbswap = glxPriv->swapBuffers; - glxPriv->swapBuffers = __MESA_swapBuffers; - - /* Save Mesa's private buffer structure */ - glPriv->private = (void *)buf; - glPriv->freePrivate = __MESA_destroyBuffer; -} - -GLboolean __MESA_resizeBuffers(__GLdrawableBuffer *buffer, - GLint x, GLint y, - GLuint width, GLuint height, - __GLdrawablePrivate *glPriv, - GLuint bufferMask) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - - if (buf->xm_buf) - XMesaResizeBuffers(buf->xm_buf); - - return (*buf->fbresize)(buffer, x, y, width, height, glPriv, bufferMask); -} - -GLboolean __MESA_swapBuffers(__GLXdrawablePrivate *glxPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glxPriv->glPriv.private; - - /* - ** Do not call the wrapped swap buffers routine since Mesa has - ** already done the swap. - */ - XMesaSwapBuffers(buf->xm_buf); - - return GL_TRUE; -} - -void __MESA_destroyBuffer(__GLdrawablePrivate *glPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - __GLXdrawablePrivate *glxPriv = (__GLXdrawablePrivate *)glPriv->other; - - /* Destroy Mesa's buffers */ - if (buf->xm_buf) - XMesaDestroyBuffer(buf->xm_buf); - - /* Unwrap these routines */ - glxPriv->swapBuffers = buf->fbswap; - glPriv->frontBuffer.resize = buf->fbresize; - - __glXFree(glPriv->private); - glPriv->private = NULL; -} - -__GLinterface *__MESA_createContext(__GLimports *imports, - __GLcontextModes *modes, - __GLinterface *shareGC) -{ - __GLcontext *gl_ctx = NULL; - __GLcontext *m_share = NULL; - __GLXcontext *glxc = (__GLXcontext *)imports->other; - XMesaVisual xm_vis; - - if (shareGC) - m_share = (__GLcontext *)shareGC; - - xm_vis = find_mesa_visual(glxc->pScreen->myNum, glxc->modes->visualID); - if (xm_vis) { - XMesaContext xmshare = m_share ? m_share->DriverCtx : 0; - XMesaContext xmctx = XMesaCreateContext(xm_vis, xmshare); - gl_ctx = xmctx ? &xmctx->mesa : 0; - } - else { - ErrorF("find_mesa_visual returned NULL for visualID = 0x%04x\n", - glxc->modes->visualID); - } - - - if (!gl_ctx) - return NULL; - - gl_ctx->imports = *imports; - gl_ctx->exports.destroyContext = __MESA_destroyContext; - gl_ctx->exports.loseCurrent = __MESA_loseCurrent; - gl_ctx->exports.makeCurrent = __MESA_makeCurrent; - gl_ctx->exports.shareContext = __MESA_shareContext; - gl_ctx->exports.copyContext = __MESA_copyContext; - gl_ctx->exports.forceCurrent = __MESA_forceCurrent; - gl_ctx->exports.notifyResize = __MESA_notifyResize; - gl_ctx->exports.notifyDestroy = __MESA_notifyDestroy; - gl_ctx->exports.notifySwapBuffers = __MESA_notifySwapBuffers; - gl_ctx->exports.dispatchExec = __MESA_dispatchExec; - gl_ctx->exports.beginDispatchOverride = __MESA_beginDispatchOverride; - gl_ctx->exports.endDispatchOverride = __MESA_endDispatchOverride; - - return (__GLinterface *)gl_ctx; -} - -GLboolean __MESA_destroyContext(__GLcontext *gc) -{ - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - XMesaDestroyContext( xmesa ); - return GL_TRUE; -} - -GLboolean __MESA_loseCurrent(__GLcontext *gc) -{ - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - MESA_CC = NULL; - __glXLastContext = NULL; - return XMesaLoseCurrent(xmesa); -} - -GLboolean __MESA_makeCurrent(__GLcontext *gc) -{ - __GLdrawablePrivate *drawPriv = gc->imports.getDrawablePrivate( gc ); - __MESA_buffer drawBuf = (__MESA_buffer)drawPriv->private; - __GLdrawablePrivate *readPriv = gc->imports.getReadablePrivate( gc ); - __MESA_buffer readBuf = (__MESA_buffer)readPriv->private; - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - - MESA_CC = gc; - return XMesaMakeCurrent2(xmesa, drawBuf->xm_buf, readBuf->xm_buf); -} - -GLboolean __MESA_shareContext(__GLcontext *gc, __GLcontext *gcShare) -{ - /* NOT_DONE */ - /* XXX I don't see where/how this could ever be called */ - ErrorF("__MESA_shareContext\n"); - return GL_FALSE; -} - -GLboolean __MESA_copyContext(__GLcontext *dst, const __GLcontext *src, - GLuint mask) -{ - XMesaContext xm_dst = (XMesaContext) dst->DriverCtx; - const XMesaContext xm_src = (const XMesaContext) src->DriverCtx; - _mesa_copy_context(&xm_src->mesa, &xm_dst->mesa, mask); - return GL_TRUE; -} - -GLboolean __MESA_forceCurrent(__GLcontext *gc) -{ - XMesaContext xmesa = (XMesaContext) gc->DriverCtx; - MESA_CC = gc; - return XMesaForceCurrent(xmesa); -} - -GLboolean __MESA_notifyResize(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifyResize\n"); - return GL_FALSE; -} - -void __MESA_notifyDestroy(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifyDestroy\n"); - return; -} - -void __MESA_notifySwapBuffers(__GLcontext *gc) -{ - _mesa_notifySwapBuffers(gc); -} - -struct __GLdispatchStateRec *__MESA_dispatchExec(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_dispatchExec\n"); - return NULL; -} - -void __MESA_beginDispatchOverride(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_beginDispatchOverride\n"); - return; -} - -void __MESA_endDispatchOverride(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_endDispatchOverride\n"); - return; -} - - -/* - * Server-side GLX uses these functions which are normally defined - * in the OpenGL SI. - */ - -GLuint __glFloorLog2(GLuint val) -{ - int c = 0; - - while (val > 1) { - c++; - val >>= 1; - } - return c; -} - diff --git a/nx-X11/programs/Xserver/GL/mesa/main/Imakefile.NX.original b/nx-X11/programs/Xserver/GL/mesa/main/Imakefile.NX.original deleted file mode 100644 index 6287b92de..000000000 --- a/nx-X11/programs/Xserver/GL/mesa/main/Imakefile.NX.original +++ /dev/null @@ -1,61 +0,0 @@ -XCOMM $XdotOrg: xc/programs/Xserver/GL/mesa/main/Imakefile,v 1.2 2004/08/19 07:34:43 kem Exp $ -XCOMM $XFree86: xc/programs/Xserver/GL/mesa/src/math/Imakefile,v 1.8 2002/11/22 22:56:01 tsi Exp $ - -#if DoLoadableServer -#if !BuildModuleInSubdir -#define IHaveModules -#elif !defined(IHaveModules) -#define IHaveSubdirs -SUBDIRS = module -#endif -#endif - -/* Large PIC tables needed for Solaris/SPARC builds */ -#if defined(SunArchitecture) && defined(SparcArchitecture) && defined(LargePositionIndependentCFlags) - PICFLAGS = LargePositionIndependentCFlags -#endif - -#include - -#define NeedAllMesaSrc -#define NeedToLinkMesaSrc -#define MesaBuildDir /**/ -#if !defined(IHaveModules) || !BuildModuleInSubdir -#include "../../../../../lib/GL/mesa/main/Imakefile.inc" -#else -#include "../../../../../../lib/GL/mesa/main/Imakefile.inc" -#endif - - SRCS = $(COREMESABASESRCS) - OBJS = $(COREMESABASEOBJS) - - INCLUDES = -I$(MESASRCDIR)/src/mesa \ - -I$(MESASRCDIR)/src/mesa/main \ - -I$(MESASRCDIR)/src/mesa/shader \ - -I$(MESASRCDIR)/src/mesa/glapi \ - -I$(MESASRCDIR)/include \ - -I$(SERVERSRC)/include -I$(XINCLUDESRC) \ - -I$(SERVERSRC)/GL/include -I$(SERVERSRC)/GL/glx \ - -I$(LIBSRC)/GL/include \ - -I$(XF86SRC) -I$(INCLUDESRC) - - DEFINES = $(GLX_DEFINES) -DNXAGENT_SERVER /*-DUSE_X86_ASM*/ /*-DUSE_SPARC_ASM*/ - -#ifdef IHaveModules -ModuleObjectRule() -#else -NormalLibraryObjectRule() -#endif - -SubdirLibraryRule($(OBJS)) - -LintLibraryTarget(dri,$(SRCS)) -NormalLintTarget($(SRCS)) - -DependTarget() - -#ifdef IHaveSubdirs -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - diff --git a/nx-X11/programs/Xserver/GL/mesa/main/Imakefile.X.original b/nx-X11/programs/Xserver/GL/mesa/main/Imakefile.X.original deleted file mode 100644 index 463812236..000000000 --- a/nx-X11/programs/Xserver/GL/mesa/main/Imakefile.X.original +++ /dev/null @@ -1,61 +0,0 @@ -XCOMM $XdotOrg: xc/programs/Xserver/GL/mesa/main/Imakefile,v 1.2 2004/08/19 07:34:43 kem Exp $ -XCOMM $XFree86: xc/programs/Xserver/GL/mesa/src/math/Imakefile,v 1.8 2002/11/22 22:56:01 tsi Exp $ - -#if DoLoadableServer -#if !BuildModuleInSubdir -#define IHaveModules -#elif !defined(IHaveModules) -#define IHaveSubdirs -SUBDIRS = module -#endif -#endif - -/* Large PIC tables needed for Solaris/SPARC builds */ -#if defined(SunArchitecture) && defined(SparcArchitecture) && defined(LargePositionIndependentCFlags) - PICFLAGS = LargePositionIndependentCFlags -#endif - -#include - -#define NeedAllMesaSrc -#define NeedToLinkMesaSrc -#define MesaBuildDir /**/ -#if !defined(IHaveModules) || !BuildModuleInSubdir -#include "../../../../../lib/GL/mesa/main/Imakefile.inc" -#else -#include "../../../../../../lib/GL/mesa/main/Imakefile.inc" -#endif - - SRCS = $(COREMESABASESRCS) - OBJS = $(COREMESABASEOBJS) - - INCLUDES = -I$(MESASRCDIR)/src/mesa \ - -I$(MESASRCDIR)/src/mesa/main \ - -I$(MESASRCDIR)/src/mesa/shader \ - -I$(MESASRCDIR)/src/mesa/glapi \ - -I$(MESASRCDIR)/include \ - -I$(SERVERSRC)/include -I$(XINCLUDESRC) \ - -I$(SERVERSRC)/GL/include -I$(SERVERSRC)/GL/glx \ - -I$(LIBSRC)/GL/include \ - -I$(XF86SRC) -I$(INCLUDESRC) - - DEFINES = $(GLX_DEFINES) /*-DUSE_X86_ASM*/ /*-DUSE_SPARC_ASM*/ - -#ifdef IHaveModules -ModuleObjectRule() -#else -NormalLibraryObjectRule() -#endif - -SubdirLibraryRule($(OBJS)) - -LintLibraryTarget(dri,$(SRCS)) -NormalLintTarget($(SRCS)) - -DependTarget() - -#ifdef IHaveSubdirs -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - diff --git a/nx-X11/programs/Xserver/Imakefile.NX.original b/nx-X11/programs/Xserver/Imakefile.NX.original deleted file mode 100644 index 6bf7801e7..000000000 --- a/nx-X11/programs/Xserver/Imakefile.NX.original +++ /dev/null @@ -1,1579 +0,0 @@ -XCOMM $XdotOrg: xc/programs/Xserver/Imakefile,v 1.37 2005/11/18 18:15:23 ajax Exp $ -XCOMM $Xorg: Imakefile,v 1.4 2001/03/14 18:42:02 pookie Exp $ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * Server Master Makefile - */ -XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.296 2003/11/23 06:47:00 torrey Exp $ - -#ifndef InstallXserverSetUID -#define InstallXserverSetUID NO -#endif -#define InstallServerSetUID InstallXserverSetUID - -#include - -/* On most systems the linker requires the libraries in dependency order. - But we have no real order because there are cycles. We fix this by adding - some libraries twice on the commandline. dependLib will add the - dependency library to the commandline if the link order is important */ -#if 1 /* This is currently enabled for all systems */ -#define dependLib(x) x -#else -#define dependLib(x) -#endif - -#if (defined (XFree86Version) || defined(XorgVersion)) -/* Do not strip server binaries */ -INSTPGMFLAGS = -#endif - -#define PreFbLibs $(DIX) $(OS) $(XPDDX) -#define PreFbLibsNoFont $(DIX) $(OS) -#define BarePostFbLibs $(MFB) $(XPFBLIBS) $(MI) -#define PostFbLibs BarePostFbLibs $(EXTENSIONS) -#define NoMfbBarePostFbLibs $(XPFBLIBS) $(MI) -#if !BuildXinerama -#define NoMfbPostFbLibs NoMfbBarePostFbLibs $(EXTENSIONS) -#else -#define NoMfbPostFbLibs $(EXTENSIONS) NoMfbBarePostFbLibs $(EXTENSIONS) -#endif - -#define MFBBareLibs PreFbLibs BarePostFbLibs -#define NoMFBBareLibs PreFbLibs NoMfbBarePostFbLibs -#define MFBLibs PreFbLibs PostFbLibs -#define NoMFBLibs PreFbLibs NoMfbPostFbLibs -#define CFBLibs PreFbLibs $(CFB) PostFbLibs -#define CFB4Libs PreFbLibs $(CFB4) PostFbLibs -#define CFB8Libs PreFbLibs $(CFB8) PostFbLibs -#define CFB16Libs PreFbLibs $(CFB16) PostFbLibs -#define CFB24Libs PreFbLibs $(CFB24) PostFbLibs -#define CFB32Libs PreFbLibs $(CFB32) PostFbLibs - -#define NoMFBCFBLibs PreFbLibs $(CFB) NoMfbPostFbLibs -#define NoMFBCFB8Libs PreFbLibs $(CFB8) NoMfbPostFbLibs -#define FbPostFbLibs $(FB) NoMfbPostFbLibs -#define FBLibs PreFbLibs FbPostFbLibs - -#define MiExtLibs $(SHADOW) - -#define AllFBLibs PreFbLibs $(FB) $(CFB) PostFbLibs - -#if BuildGlxExt -# if BuildXF86DRI && ((defined(XF86Server) && XF86Server) \ - || (defined(XorgServer) && XorgServer)) - DRILIB = GL/dri/ModuleLibraryTargetName(dri) -# else - DRILIB = -# endif -# if GlxUseSGISI - GLXLIB = GL/glx/ModuleLibraryTargetName(glx) \ - GL/sgi-si/ModuleLibraryTargetName(GLcore) \ - $(DRILIB) -# else -# if defined(GlxUseWindows) && GlxUseWindows - XWin_GL.exe.GLXLIB = GL/glx/ModuleLibraryTargetName(glx_stdcall) \ - GL/windows/ModuleLibraryTargetName(GLcore) -# endif /* GlxUseWindows */ -# if defined(Win32Architecture) && defined(GlxUseWindows) && GlxUseWindows - GLXLIB = GL/glx/ModuleLibraryTargetName(glx_stdcall) \ - GL/windows/ModuleLibraryTargetName(GLcore) -# elif DoLoadableServer - GLXLIB = GL/glx/ModuleLibraryTargetName(glx) \ - GL/mesa/GLcore/ModuleLibraryTargetName(GLcore) -# else - GLXLIB = GL/glx/ModuleLibraryTargetName(glx) \ - GL/mesa/GLcore/ModuleLibraryTargetName(GLcore) \ - $(DRILIB) -# endif -# endif - GLXDIR = GL -# if defined(cygwinArchitecture) && defined(GlxUseWindows) && GlxUseWindows - GLXEXT = $(if $($@.GLXLIB),$($@.GLXLIB), $(GLXLIB)) -# else - GLXEXT = $(GLXLIB) -# endif -#endif - -#if BuildXInputExt - XINPUTEXT = Xi/LibraryTargetName(xinput) - XIDIR = Xi -#endif -#if BuildXKB - XKBEXT = xkb/LibraryTargetName(xkb) dependLib($(OS)) - XKBDIR = xkb -#if (defined(XFree86Version) || defined(XorgVersion)) - XF86XKBOBJS = xkb/xf86KillSrv.o xkb/xf86VT.o xkb/xf86Private.o -#endif -#endif -#if BuildLBX - LBXEXT = lbx/LibraryTargetName(lbx) \ - $(TOP)/lib/lbxutil/LibraryTargetName(lbxutil) - LBXDIRS = lbx -#endif -#if BuildDBE - DBEEXT = dbe/LibraryTargetName(dbe) -#endif -#if BuildDBE || BuildDBElib - DBEDIR = dbe -#endif -#if BuildRECORD - RECORDEXT = record/LibraryTargetName(record) -#endif -#if BuildRECORD || BuildRECORDlib - RECORDDIR = record -#endif -#if BuildXTrap - XTRAPEXT = XTrap/LibraryTargetName(xtrap) - XTRAPDIR = XTrap -#endif -#ifdef SiteExtensionLibs - SITEEXTS = SiteExtensionLibs -#endif -#ifdef SiteExtensionDirs - SITEEXTDIRS = SiteExtensionDirs -#endif -#if DoLoadableServer && HasDlopen - LIBDL = DlLibrary -#endif - LIBREGEX = RegexLibrary - -#if DoLoadableServer - LIBCWRAPPER = os/libcwrapper.o -#endif - -#if BuildXprint - -XPCONFIGDIR = XpConfig - -#ifndef XpRasterDDX -#define XpRasterDDX YES -#endif -#ifndef XpColorPclDDX -#define XpColorPclDDX YES -#endif -#ifndef XpMonoPclDDX -#define XpMonoPclDDX NO -#endif -#ifndef XpPostScriptDDX -#define XpPostScriptDDX YES -#endif - -#if XpRasterDDX -XPRASTLIB = Xprint/raster/LibraryTargetName(raster) -#endif -#if XpColorPclDDX -XPPCLLIB = Xprint/pcl/LibraryTargetName(pcl) -#endif -#if XpMonoPclDDX -XPMPCLLIB = Xprint/pcl-mono/LibraryTargetName(pcl) -#endif -#if XpPostScriptDDX -XPPSLIB = Xprint/ps/LibraryTargetName(ps) -#endif - -XPDDXLIBS = Xprint/LibraryTargetName(printer) \ - $(XPRASTLIB) $(XPPCLLIB) $(XPMPCLLIB) $(XPPSLIB) -XPDDXFBLIBS = $(MFB) $(CFB32) -#if !PrintOnlyServer - XPFBLIBS = $(XPDDXFBLIBS) - XPDDX = $(XPDDXLIBS) -#endif - XPDDXDIR = Xprint -#endif -#if !BuildXprint || PrintOnlyServer -XPFBLIBS = dix/LibraryTargetName(xpstubs) -#endif - -#if BuildRender - RENDERDIR = render - RENDERLIB = $(RENDERDIR)/librender.a -#endif -#if BuildRandR - RANDRDIR = randr - RANDRLIB = $(RANDRDIR)/librandr.a -#endif -#if BuildXfixes - FIXESDIR = xfixes - FIXESLIB = $(FIXESDIR)/libxfixes.a -#endif -#if BuildDamage - DAMAGEDIR = damageext - DAMAGELIB = $(DAMAGEDIR)/libdamage.a -#endif -#if BuildComposite - CWDIR = miext/cw - COMPOSITEDIR = composite - COMPOSITELIB = $(COMPOSITEDIR)/libcomposite.a -#if DoLoadableServer - CW = miext/cw/ModuleLibraryTargetName(cw) -#else - CW = miext/cw/LibraryTargetName(cw) -#endif -#endif -#if DoLoadableServer - EXTENSIONS = $(COMPOSITELIB) $(DAMAGELIB) $(DAMAGE) $(FIXESLIB) $(CW) \ - $(OTHEREXTS) $(RANDRLIB) $(RENDERLIB) - LOADABLEEXTS = $(MISCEXT) $(DBEEXT) $(RECORDEXT) $(GLXEXT) $(XTRAPEXT) - MISCEXT = Xext/LibraryTargetName(ext) - OTHEREXTS = Xext/LibraryTargetName(exts) $(XKBEXT) $(XINPUTEXT) \ - $(LBXEXT) $(SITEEXTS) -#else - EXTENSIONS = $(COMPOSITELIB) $(DAMAGELIB) $(DAMAGE) $(FIXESLIB) $(CW) \ - $(OTHEREXTS) $(GLXEXT) $(RANDRLIB) $(RENDERLIB) - OTHEREXTS = Xext/LibraryTargetName(ext) $(XKBEXT) $(XINPUTEXT) \ - $(LBXEXT) $(DBEEXT) $(RECORDEXT) $(SITEEXTS) $(XTRAPEXT) -#endif - EXTDIRS = Xext $(XKBDIR) $(XIDIR) $(GLXDIR) \ - $(LBXDIRS) $(DBEDIR) $(RECORDDIR) $(SITEEXTDIRS) \ - $(RANDRDIR) $(RENDERDIR) $(XTRAPDIR) $(XPCONFIGDIR) \ - $(FIXESDIR) $(DAMAGEDIR) $(CWDIR) $(COMPOSITEDIR) -#if BuildLBX || GzipFontCompression - ZLIB = GzipLibrary -#endif - OS = os/LibraryTargetName(os) $(DEPXAUTHLIB) $(DEPXDMCPLIB) - BSDEMUL = $(DEPXBSDLIB) -#if DoLoadableServer - MFB = mfb/ModuleLibraryTargetName(mfb) - FB = fb/ModuleLibraryTargetName(fb) -#if XF8_32Wid - CFB = cfb/ModuleLibraryTargetName(cfb) \ - cfb16/ModuleLibraryTargetName(cfb16) \ - cfb24/ModuleLibraryTargetName(cfb24) \ - cfb32/ModuleLibraryTargetName(cfb32) -#else - CFB = cfb/ModuleLibraryTargetName(cfb) \ - cfb16/ModuleLibraryTargetName(cfb16) \ - cfb32/ModuleLibraryTargetName(cfb32) -#endif - CFB8 = cfb/ModuleLibraryTargetName(cfb) - CFB4 = cfb/ModuleLibraryTargetName(cfb) \ - cfb4/ModuleLibraryTargetName(cfb4) - CFB16 = cfb/ModuleLibraryTargetName(cfb) \ - cfb16/ModuleLibraryTargetName(cfb16) - CFB24 = cfb/ModuleLibraryTargetName(cfb) \ - cfb24/ModuleLibraryTargetName(cfb24) - CFB32 = cfb/ModuleLibraryTargetName(cfb) \ - cfb32/ModuleLibraryTargetName(cfb32) - DAMAGE = miext/damage/ModuleLibraryTargetName(damage) - SHADOW = miext/shadow/ModuleLibraryTargetName(shadow) - LAYER = miext/layer/ModuleLibraryTargetName(layer) -#else - MFB = mfb/LibraryTargetName(mfb) - FB = fb/LibraryTargetName(fb) -#if XF8_32Wid - CFB = cfb16/LibraryTargetName(cfb16) \ - cfb24/LibraryTargetName(cfb24) \ - cfb32/LibraryTargetName(cfb32) \ - cfb/LibraryTargetName(cfb) -#else - CFB = cfb16/LibraryTargetName(cfb16) \ - cfb32/LibraryTargetName(cfb32) \ - cfb/LibraryTargetName(cfb) -#endif - CFB8 = cfb/LibraryTargetName(cfb) - CFB4 = cfb4/LibraryTargetName(cfb4) \ - cfb/LibraryTargetName(cfb) - CFB16 = cfb16/LibraryTargetName(cfb16) \ - cfb/LibraryTargetName(cfb) - CFB24 = cfb24/LibraryTargetName(cfb24) \ - cfb/LibraryTargetName(cfb) - CFB32 = cfb32/LibraryTargetName(cfb32) \ - cfb/LibraryTargetName(cfb) - DAMAGE = miext/damage/LibraryTargetName(damage) - SHADOW = miext/shadow/LibraryTargetName(shadow) - LAYER = miext/layer/LibraryTargetName(layer) -#endif -#if !HasFfs && (defined(mingwArchitecture) || defined(cygwinArchitecture)) - /* Order of libraries is important when linking in mingw or - * cygwin. libmi.a requires ffs from libdix.a. So it is added - * after libmi.a on the commandline */ - MI = mi/LibraryTargetName(mi) $(DIX) -#else - MI = mi/LibraryTargetName(mi) -#endif - MIINITEXTOBJ = mi/miinitext.o - DIX = dix/LibraryTargetName(dix) - FONTBASE = $(FONTLIBSRC)/fontbase.o \ - $(FONTLIBSRC)/LibraryTargetName(fontbase) -#if XserverStaticFontLib - FONT = $(FONTLIBSRC)/LibraryTargetName(Xfont) $(FREETYPE2LIB) -#else - FONT = $(LDPRELIB) $(XFONTLIB) $(FREETYPE2LIB) -#endif - FONTLIBS = $(FONT) $(XPFBLIBS) -#if UsbMouseSupport -#if !HasLibUsb - USB = $(XF86OSSRC)/bsd/libusb/LibraryTargetName(usb) -#else - USB = UsbHidLib -#endif -#endif -#ifdef ServerExtraSysLibs - EXTRASYSLIBS = ServerExtraSysLibs -#endif -#if HasPam && HasPamMisc - PAMLIBS = PamLibraries PamMiscLibraries -#endif -#if !(SystemV4 || defined(SGIArchitecture) || UseRgbTxt) - DBMLIBS = DBMLibrary -#endif - SYSLIBS = $(ZLIB) MathLibrary Krb5Libraries $(DBMLIBS) $(USB) \ - $(PAMLIBS) $(EXTRASYSLIBS) -#if !HasCbrt - CBRT = mi/LibraryTargetName(cbrt) -#endif - STDDIRS = include dix os mi $(XPDDXDIR) $(EXTDIRS) - FBDIR = fb - MFBDIR = mfb - CFB4DIR = cfb4 - CFB8DIR = cfb - CFB16DIR = cfb16 - CFB24DIR = cfb24 - CFB32DIR = cfb32 - AFBDIR = afb - -XCOMM -XCOMM This turns off the default rule for compiling .c files because -XCOMM this makefile does not really know how to build it. This is really -XCOMM just a hack because of the Sun version of make and nfs. -XCOMM -.c.o: - -.s.o: - -/* Build rule blocks, add one for each server - * - * If a server needs mfb, its build block should have a line like: - * MFBSUBDIR = mfb - * Similarly, its build block should have: - * CFB4SUBDIR = cfb4 (if the server needs 4 bit cfb) - * CFB8SUBDIR = cfb (8 bit cfb) - * CFB16SUBDIR = cfb16 (16 bit cfb) - * CFB24SUBDIR = cfb24 (24 bit cfb) - * CFB32SUBDIR = cfb32 (32 bit cfb) - * - * If a server does not need all of the above components, simply - * omit the relevant lines from the build block. - * - * If these guidelines are followed, a make at the top of the server - * tree should result in each subdirectory being built only once, - * even if multiple servers that share subdirectories are being built. - */ - -#if defined(XdecServer) && XdecServer -XCOMM -XCOMM Digital MIPS based WS server (ultrix 4.2 and beyond) -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -DECWSDDXDIR = hw/dec/ws -DECDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DECWSDDXDIR) $(DEPDIRS) -DECOBJS = hw/dec/ws/init.o hw/dec/ws/sdepthinit.o -DECLIBS = hw/dec/ws/LibraryTargetName(dec) CFB8Libs -ServerTarget(Xdec,$(DECDIRS),$(DECOBJS), \ - $(DECLIBS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xdec -#endif -#endif /* XdecServer */ - - -#if defined(XdecMultiDepthServer) && XdecMultiDepthServer -XCOMM -XCOMM Digital MIPS based WS server (ultrix 4.2 and beyond) -XCOMM Supports 8, 12, and 24 bit pixmaps -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB24SUBDIR = cfb24 -CFB32SUBDIR = cfb32 -DECWSDDXDIR = hw/dec/ws -DECDIRS1 = $(STDDIRS) $(MFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(DECWSDDXDIR) $(DEPDIRS) -DECOBJS1 = hw/dec/ws/init.o hw/dec/ws/mdepthinit.o -DECLIBS1 = hw/dec/ws/LibraryTargetName(dec) CFBLibs -ServerTarget(Xdec_md,$(DECDIRS1),$(DECOBJS1), \ - $(DECLIBS1),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xdec_md -#endif -#endif /* XdecMultiDepthServer */ - - -#if defined(XsunServer) && XsunServer -XCOMM -XCOMM Sun server -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -SUNDDXDIR = hw/sun -#if DoLoadableServer -SUNOBJS = hw/sun/sunInit.o hw/sun/sunInitExt.o hw/sun/stubs.o -#elif (defined(XF86Server) && XF86Server) \ - || (defined(XorgServer) && XorgServer) -SUNOBJS = hw/sun/sunInit.o hw/sun/stubs.o -#else -SUNOBJS = hw/sun/sunInit.o -#endif -SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(SUNDDXDIR) $(DEPDIRS) -SUNLIBS = hw/sun/LibraryTargetName(sun) CFB8Libs -SUNSYSLIBS = $(FONTLIBS) $(WIDECHARSYSLIB) $(SYSLIBS) -SetUIDServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS), \ - $(LIBCWRAPPER) $(SUNLIBS) $(LOADABLEEXTS),$(SUNSYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xsun -#endif -#endif /* XsunServer */ - - -#if defined(Xsun24Server) && Xsun24Server -XCOMM -XCOMM Sun multiple pixmap depth (8, 12, 24) server -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB24SUBDIR = cfb24 -CFB32SUBDIR = cfb32 -SUNDDXDIR = hw/sun -SUN24DIRS = $(STDDIRS) $(MFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(SUNDDXDIR) $(DEPDIRS) -#if DoLoadableServer -SUN24OBJS = hw/sun/sunInitMulti.o hw/sun/sunInitExt.o hw/sun/stubs.o -#elif defined(XF86Server) && XF86Server \ - || (defined(XorgServer) && XorgServer) -SUN24OBJS = hw/sun/sunInitMulti.o hw/sun/stubs.o -#else -SUN24OBJS = hw/sun/sunInitMulti.o -#endif -SUN24LIBS = hw/sun/LibraryTargetName(sun) CFBLibs -SetUIDServerTarget(Xsun24,$(SUN24DIRS),$(SUN24OBJS), \ - $(LIBCWRAPPER) $(SUN24LIBS) $(LOADABLEEXTS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xsun24 -#endif -#endif /* Xsun24Server */ - - -#if defined(XsunMonoServer) && XsunMonoServer -XCOMM -XCOMM Sun monochrome server -XCOMM -MFBSUBDIR = mfb -SUNDDXDIR = hw/sun -SUNMDIRS = $(STDDIRS) $(MFBDIR) $(SUNDDXDIR) $(DEPDIRS) -#if defined(XF86Server) && XF86Server \ - || (defined(XorgServer) && XorgServer) -SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o hw/sun/stubs.o -#else -SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o -#endif -SUNMLIBS = hw/sun/LibraryTargetName(sun) MFBBareLibs $(EXTENSIONS) -SetUIDServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS), \ - $(LIBCWRAPPER) $(SUNMLIBS) $(LOADABLEEXTS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall XsunMono -#endif -#endif /* XsunMonoServer */ - - -#if defined(XsunLynxServer) && XsunLynxServer -XCOMM -XCOMM Sun server for LynxOS microSPARC 2.4.0 -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -LYNXDDXDIR = hw/sunLynx -SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(LYNXDDXDIR) $(DEPDIRS) -SUNOBJS = hw/sunLynx/sunLyInit.o -SUNLIBS = hw/sunLynx/libsun.a CFB8Libs -ServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS), \ - $(SUNLIBS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xsun -#endif -#endif /* XsunLynxServer */ - - -#if defined(XsunLynxMonoServer) && XsunLynxMonoServer -XCOMM -XCOMM Sun monochrome server for LynxOS microSPARC 2.4.0 -XCOMM -MFBSUBDIR = mfb -LYNXDDXDIR = hw/sunLynx -SUNMDIRS = $(STDDIRS) $(MFBDIR) $(LYNXDDXDIR) $(DEPDIRS) -SUNMOBJS = hw/sunLynx/sunInitMono.o hw/sunLynx/sunInExMono.o -SUNMLIBS = hw/sunLynx/libsun.a MFBBareLibs $(OTHEREXTS) -ServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS), \ - $(SUNMLIBS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall XsunMono -#endif -#endif /* XsunLynxMonoServer */ - - -#if HasParallelMake -XCOMM -XCOMM force non-parallel build of XF86 servers to prevent MUTEX overrides -XCOMM -#if defined(XF86Server) && XF86Server -XF86SERVER = XFree86 -#endif -#if defined(XorgServer) && XorgServer -XF86SERVER = Xorg -#endif -#if defined(XnestServer) && XnestServer -XNEST = Xnext -#endif -#if defined(XVirtualFramebufferServer) && XVirtualFramebufferServer -XVFB = Xvfb -#endif -#if XdmxServer -XDMX = Xdmx -#endif -#if defined(XWinServer) && XWinServer && !MakeDllModules -XWIN = XWin -#endif -#if defined(NXAgentServer) && NXAgentServer -NXAGENT = nxagent -#endif -#if defined(NXWinServer) && NXWinServer && !MakeDllModules -NXWIN = NXWin -#endif -#if (defined(XF86Server) && XF86Server) || \ - (defined(XorgServer) && XorgServer) || \ - (defined(XnestServer) && XnestServer) || \ - (defined(NXAgentServer) && NXAgentServer) || \ - (defined(XVirtualFramebufferServer) && XVirtualFramebufferServer) || \ - (defined(XdmxServer) && XdmxServer) || \ - (!MakeDllModules && defined(XWinServer) && XWinServer) || \ - (!MakeDllModules && defined(NXWinServer) && NXWinServer) -MakeMutex($(XF86SERVER) $(XNEST) $(XVFB) $(XWIN) $(NXAGENT) $(NXWIN)) -#endif -MakeMutex($(STDDIRS) mfb fb cfb cfb16 cfb24 cfb32) -#endif - - -#if defined(XF86Server) && XF86Server -XCOMM -XCOMM XFree86 Server -XCOMM -FBSUBDIR = fb -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB24SUBDIR = cfb24 -CFB32SUBDIR = cfb32 -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -LAYERDIR = miext/layer -#ifdef OS2Architecture -SERVERDEFFILE = XFree86.def -XNESTDEFFILE = Xnest.def -XVFBDEFFILE = Xvfb.def -#endif -#if XF86AFB -AFBSUBDIR = afb -#endif -XFREE86DDXDIR = hw/xfree86 -XF86SERVERSUBDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(AFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(SHADOWDIR) $(LAYERDIR) $(XFREE86DDXDIR) $(DEPDIRS) \ - $(MIDAMAGEDIR) -XF86INIT = $(XF86COMSRC)/xf86Init.o $(XF86COMSRC)/xf86IniExt.o -XF86COMLIB = $(XF86COMSRC)/LibraryTargetName(xf86) -XF86PARSLIB= $(XF86PARSERSRC)/LibraryTargetName(xf86config) -XF86OSLIB = $(XF86OSSRC)/LibraryTargetName(xf86_os) -#if XF86XAA -XF86XAALIB = $(XF86SRC)/xaa/LibraryTargetName(xaa) -#endif -#if XF86EXA -XF86EXALIB = $(XF86SRC)/exa/LibraryTargetName(exa) -#endif -#if XF86VgaHw -XF86VGAHWLIB = $(XF86SRC)/vgahw/LibraryTargetName(vgahw) -#endif -#if XF86FBDevHw -XF86FBDEVHWLIB = $(XF86SRC)/fbdevhw/LibraryTargetName(fbdevhw) -#endif -#if XF1Bpp || XF4Bpp -XF1BPPLIB = $(XF86SRC)/xf1bpp/LibraryTargetName(xf1bpp) -#endif -#if XF4Bpp -XF4BPPLIB = $(XF86SRC)/xf4bpp/LibraryTargetName(xf4bpp) -#endif -#if XF8_32Wid -XF8_32WIDLIB = $(XF86SRC)/xf8_32wid/LibraryTargetName(xf8_32wid) -#endif -#if XF8_32Bpp -XF8_32BPPLIB = $(XF86SRC)/xf8_32bpp/LibraryTargetName(xf8_32bpp) -#endif -#if XF8_16Bpp -XF8_16BPPLIB = $(XF86SRC)/xf8_16bpp/LibraryTargetName(xf8_16bpp) -#endif -#if XFShadowFB -XFSHADOWFBLIB = $(XF86SRC)/shadowfb/LibraryTargetName(shadowfb) -#endif -#if XF86AFB -AFBLIB = afb/LibraryTargetName(afb) -#endif -XF86DRIVERLIB = $(XF86SRC)/drivers/LibraryTargetName(driver) -#if XF86Ramdac -XF86RAMDACLIB = $(XF86SRC)/ramdac/LibraryTargetName(ramdac) -#endif -#if XF86I2C -XF86I2CLIB = $(XF86SRC)/i2c/LibraryTargetName(i2c) -#endif -#if XF86DDC -XF86DDCLIB = $(XF86SRC)/ddc/LibraryTargetName(ddc) -#endif -#if XF86VBE -XF86VBELIB = $(XF86SRC)/vbe/LibraryTargetName(vbe) -#endif -#if XF86RAC -XF86RACLIB = $(XF86SRC)/rac/LibraryTargetName(rac) -#endif -#if XF86INT10_BUILD > X86EMU_GENERIC -XF86INT10LIB = $(XF86OSSRC)/LibraryTargetName(int10) -#else -XF86INT10LIB = $(XF86SRC)/int10/LibraryTargetName(int10) -#endif -#if UseMemLeak -MEMDEBUGLIB = $(TOP)/util/memleak/LibraryTargetName(memleak) -#endif -XF86IDRIVERLIB = $(XF86SRC)/input/LibraryTargetName(idriver) -#if !DoLoadableServer -XF86DRVOBJS = $(XF86SRC)/drivers/drvConf.o -XF86DRVLIBS = $(XF86DRIVERLIB) $(XF86RAMDACLIB) $(XF86DDCLIB) $(XF86I2CLIB) \ - $(XF86XAALIB) $(XF86EXALIB) $(XF86VGAHWLIB) $(XF86FBDEVHWLIB) \ - $(XF8_32WIDLIB) $(XF8_32BPPLIB) \ - $(XF8_16BPPLIB) \ - $(XF4BPPLIB) $(XF1BPPLIB) $(XFSHADOWFBLIB) $(AFBLIB) -XF86IDRVOBJS = $(XF86SRC)/input/drvConf.o -XF86IDRVLIBS = $(XF86IDRIVERLIB) -XF86SCANLIB = $(XF86SRC)/scanpci/LibraryTargetName(scanpci) -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) $(XF86RACLIB) \ - $(XF86PARSLIB) $(XF86VBELIB) $(XF86OSLIB) $(XF86INT10LIB) -#else -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) \ - $(XF86PARSLIB) $(XF86OSLIB) -#endif -#if DoLoadableServer -XF86LOADERLIB = $(XF86SRC)/loader/LibraryTargetName(loader) -XF86MAINLIBS = PreFbLibsNoFont \ - $(FONTBASE) $(OTHEREXTS) $(XF86COMLIB) \ - NoMfbPostFbLibs -XF86SERVERSYSLIBS = $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) -#else -XF86MAINLIBS = MiExtLibs AllFBLibs $(XF86COMLIB) $(MI) -XF86SERVERSYSLIBS = $(FONTLIBS) $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) \ - $(XF86DDCLIB) -#endif -XF86SERVEROBJS = $(XF86XKBOBJS) $(XF86DRVOBJS) $(XF86IDRVOBJS) -#if HasParallelMake -MakeMutex($(XF86SERVERSUBDIRS) $(XF86SERVERLIBS) $(XF86SERVERSYSLIBS)) -#endif -#if ForceServerRemake -$(XF86SERVERLIBS) $(XF86SERVERSYSLIBS):: $(XF86SERVERSUBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -SetUIDServerTarget(XFree86,$(XF86SERVERSUBDIRS),$(XF86SERVEROBJS) $(SERVERDEFFILE), \ - $(XF86SERVERLIBS),$(XF86SERVERSYSLIBS)) -#if DoLoadableServer -ServerDriverSDKTarget(XFree86) -#endif -#ifndef ServerToInstall -#define ServerToInstall XFree86 -#endif -#endif /* XF86Server */ - -#if defined(XorgServer) && XorgServer -XCOMM -XCOMM Xorg Server -XCOMM -FBSUBDIR = fb -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -#if XF8_32Wid -CFB24SUBDIR = cfb24 -#endif -CFB32SUBDIR = cfb32 -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -LAYERDIR = miext/layer -#ifdef OS2Architecture -SERVERDEFFILE = Xorg.def -XNESTDEFFILE = Xnest.def -XVFBDEFFILE = Xvfb.def -#endif -#if XF86AFB -AFBSUBDIR = afb -#endif -XFREE86DDXDIR = hw/xfree86 -XF86SERVERSUBDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(AFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(SHADOWDIR) $(LAYERDIR) $(XFREE86DDXDIR) $(DEPDIRS) \ - $(MIDAMAGEDIR) -XF86INIT = $(XF86COMSRC)/xf86Init.o $(XF86COMSRC)/xf86IniExt.o -XF86COMLIB = $(XF86COMSRC)/LibraryTargetName(xf86) -XF86PARSLIB= $(XF86PARSERSRC)/LibraryTargetName(xf86config) -XF86OSLIB = $(XF86OSSRC)/LibraryTargetName(xf86_os) -#if XF86XAA -XF86XAALIB = $(XF86SRC)/xaa/LibraryTargetName(xaa) -#endif -#if XF86EXA -XF86EXALIB = $(XF86SRC)/exa/LibraryTargetName(exa) -#endif -#if XF86VgaHw -XF86VGAHWLIB = $(XF86SRC)/vgahw/LibraryTargetName(vgahw) -#endif -#if XF86FBDevHw -XF86FBDEVHWLIB = $(XF86SRC)/fbdevhw/LibraryTargetName(fbdevhw) -#endif -#if XF1Bpp || XF4Bpp -XF1BPPLIB = $(XF86SRC)/xf1bpp/LibraryTargetName(xf1bpp) -#endif -#if XF4Bpp -XF4BPPLIB = $(XF86SRC)/xf4bpp/LibraryTargetName(xf4bpp) -#endif -#if XF8_32Wid -XF8_32WIDLIB = $(XF86SRC)/xf8_32wid/LibraryTargetName(xf8_32wid) -#endif -#if XF8_32Bpp -XF8_32BPPLIB = $(XF86SRC)/xf8_32bpp/LibraryTargetName(xf8_32bpp) -#endif -#if XF8_16Bpp -XF8_16BPPLIB = $(XF86SRC)/xf8_16bpp/LibraryTargetName(xf8_16bpp) -#endif -#if XFShadowFB -XFSHADOWFBLIB = $(XF86SRC)/shadowfb/LibraryTargetName(shadowfb) -#endif -#if XF86AFB -AFBLIB = afb/LibraryTargetName(afb) -#endif -XF86DRIVERLIB = $(XF86SRC)/drivers/LibraryTargetName(driver) -#if XF86Ramdac -XF86RAMDACLIB = $(XF86SRC)/ramdac/LibraryTargetName(ramdac) -#endif -#if XF86I2C -XF86I2CLIB = $(XF86SRC)/i2c/LibraryTargetName(i2c) -#endif -#if XF86DDC -XF86DDCLIB = $(XF86SRC)/ddc/LibraryTargetName(ddc) -#endif -#if XF86VBE -XF86VBELIB = $(XF86SRC)/vbe/LibraryTargetName(vbe) -#endif -#if XF86RAC -XF86RACLIB = $(XF86SRC)/rac/LibraryTargetName(rac) -#endif -#if XF86INT10_BUILD > X86EMU_GENERIC -XF86INT10LIB = $(XF86OSSRC)/LibraryTargetName(int10) -#else -XF86INT10LIB = $(XF86SRC)/int10/LibraryTargetName(int10) -#endif -#if UseMemLeak -MEMDEBUGLIB = $(TOP)/util/memleak/LibraryTargetName(memleak) -#endif -XF86IDRIVERLIB = $(XF86SRC)/input/LibraryTargetName(idriver) -#if !DoLoadableServer -XF86DRVOBJS = $(XF86SRC)/drivers/drvConf.o -XF86DRVLIBS = $(XF86DRIVERLIB) $(XF86RAMDACLIB) $(XF86DDCLIB) $(XF86I2CLIB) \ - $(XF86XAALIB) $(XF86EXALIB) $(XF86VGAHWLIB) $(XF86FBDEVHWLIB) \ - $(XF8_32WIDLIB) $(XF8_32BPPLIB) \ - $(XF8_16BPPLIB) \ - $(XF4BPPLIB) $(XF1BPPLIB) $(XFSHADOWFBLIB) $(AFBLIB) -XF86IDRVOBJS = $(XF86SRC)/input/drvConf.o -XF86IDRVLIBS = $(XF86IDRIVERLIB) -XF86SCANLIB = $(XF86SRC)/scanpci/LibraryTargetName(scanpci) -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) $(XF86RACLIB) \ - $(XF86PARSLIB) $(XF86VBELIB) $(XF86OSLIB) $(XF86INT10LIB) -#else -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) \ - $(XF86PARSLIB) $(XF86OSLIB) -#endif -#if DoLoadableServer -XF86LOADERLIB = $(XF86SRC)/loader/LibraryTargetName(loader) -XF86MAINLIBS = PreFbLibsNoFont \ - $(FONTBASE) $(OTHEREXTS) $(XF86COMLIB) \ - NoMfbPostFbLibs -XF86SERVERSYSLIBS = $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) -#else -XF86MAINLIBS = MiExtLibs AllFBLibs $(XF86COMLIB) $(MI) -XF86SERVERSYSLIBS = $(FONTLIBS) $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) \ - $(XF86DDCLIB) -#endif -XF86SERVEROBJS = $(XF86XKBOBJS) $(XF86DRVOBJS) $(XF86IDRVOBJS) -#if HasParallelMake -MakeMutex($(XF86SERVERSUBDIRS) $(XF86SERVERLIBS) $(XF86SERVERSYSLIBS)) -#endif -#if ForceServerRemake -$(XF86SERVERLIBS) $(XF86SERVERSYSLIBS):: $(XF86SERVERSUBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -SetUIDServerTarget(Xorg,$(XF86SERVERSUBDIRS),$(XF86SERVEROBJS) $(SERVERDEFFILE), \ - $(XF86SERVERLIBS),$(XF86SERVERSYSLIBS)) -#if DoLoadableServer -ServerDriverSDKTarget(Xorg) -#endif -#ifndef ServerToInstall -#define ServerToInstall Xorg -#endif -#endif /* XorgServer */ - -#if defined(XprtServer) && XprtServer -XCOMM -XCOMM Print Server -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB32SUBDIR = cfb32 -MIDAMAGEDIR = miext/damage -XPSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB32DIR) $(DEPDIRS) \ - $(MIDAMAGEDIR) -XPOBJS = Xprint/ddxInit.o Xprint/dpmsstubs.o Xprint/miinitext.o -#if PrintOnlyServer -XPLIBS = PreFbLibs $(XPDDXLIBS) $(XPDDXFBLIBS) PostFbLibs -#else -XPLIBS = PreFbLibs PostFbLibs -#endif -#if (defined(SunArchitecture) || defined(SparcArchitecture)) && \ - defined(SVR4Architecture) -XPSYSLIBS = $(FONTLIBS) $(CBRT) $(SYSLIBS) $(XONLYLIB) -lw -#else -XPSYSLIBS = $(FONTLIBS) $(CBRT) $(SYSLIBS) $(XONLYLIB) -#endif -#if HasParallelMake -MakeMutex($(XPSUBDIRS) $(XPOBJS) $(XPLIBS) $(XPSYSLIBS)) -#endif -#if ForceServerRemake -$(XPOBJS) $(XPLIBS) $(XPSYSLIBS):: $(XPSUBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xprt,$(XPSUBDIRS),$(XPOBJS), \ - $(LIBCWRAPPER) $(XPLIBS) $(LOADABLEEXTS),$(XPSYSLIBS)) -#endif /* XprtServer */ - -#if defined(XnestServer) && XnestServer -XCOMM -XCOMM Server with Xlib-based ddx -XCOMM -#ifndef Win32Architecture -XNESTDDXDIR = hw/xnest -#else -XNESTDDXDIR = hw -#endif -#if BuildDPMS -XNESTDPMSSTUBOBJS = $(XNESTDDXDIR)/dpmsstubs.o -#endif -XNESTDIRS = $(STDDIRS) $(XNESTDDXDIR) $(DEPDIRS) -#if !defined(LynxOSArchitecture) && \ - !defined(Win32Architecture) && \ - !defined(QNX4Architecture) -XNESTOBJS = hw/xnest/miinitext.o $(XNESTDPMSSTUBOBJS) -#else -XNESTOBJS = hw/xnest/miinitext.o dix/main.o $(XNESTDPMSSTUBOBJS) -#endif -XNEST = hw/xnest/LibraryTargetName(xnest) -XNESTLIBS = PreFbLibs $(XNEST) NoMfbPostFbLibs $(XNEST) -XNESTSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XLIB) $(SYSLIBS) -#if HasParallelMake -MakeMutex($(XNESTDIRS) $(XNESTOBJS) $(XNESTLIBS) $(XNESTSYSLIBS)) -#endif -#if ForceServerRemake -$(XNESTOBJS) $(XNESTLIBS) $(XNESTSYSLIBS):: $(XNESTDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xnest,$(XNESTDIRS),$(XNESTOBJS) $(XNESTDEFFILE), \ - $(LIBCWRAPPER) $(XNESTLIBS) $(LOADABLEEXTS),$(XNESTSYSLIBS)) -#endif /* XnestServer */ - -#if defined(NXAgentServer) && NXAgentServer -XCOMM -XCOMM Nested server with NXlib-based ddx and compressed transport. -XCOMM -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -FBDIR = fb -#ifndef Win32Architecture -NXAGENTDDXDIR = hw/nxagent -#else -NXAGENTDDXDIR = hw -#endif - -NXAGENTDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(MIDAMAGEDIR) $(NXAGENTDDXDIR) $(DEPDIRS) - -#if defined(SunArchitecture) || \ - defined(SparcArchitecture) -NXAGENTOBJS = hw/nxagent/miinitext.o \ - hw/nxagent/NXwindow.o \ - hw/nxagent/NXevents.o \ - hw/nxagent/NXproperty.o \ - hw/nxagent/NXdixfonts.o \ - hw/nxagent/NXglyphcurs.o \ - hw/nxagent/NXdispatch.o \ - hw/nxagent/NXrender.o \ - hw/nxagent/NXglyph.o \ - hw/nxagent/NXpicture.o \ - hw/nxagent/NXextension.o \ - hw/nxagent/NXglxext.o \ - hw/nxagent/NXmiglyph.o \ - hw/nxagent/NXmiexpose.o \ - hw/nxagent/NXresource.o \ - hw/nxagent/NXmiwindow.o \ - hw/nxagent/NXdamage.o -#elif !defined(LynxOSArchitecture) && \ - !defined(Win32Architecture) && \ - !defined(QNX4Architecture) -NXAGENTOBJS = hw/nxagent/miinitext.o \ - hw/nxagent/NXwindow.o \ - hw/nxagent/NXevents.o \ - hw/nxagent/NXproperty.o \ - hw/nxagent/NXdixfonts.o \ - hw/nxagent/NXglyphcurs.o \ - hw/nxagent/NXdispatch.o \ - hw/nxagent/NXrender.o \ - hw/nxagent/NXglyph.o \ - hw/nxagent/NXpicture.o \ - hw/nxagent/NXextension.o \ - hw/nxagent/NXglxext.o \ - hw/nxagent/NXxvdisp.o \ - hw/nxagent/NXmiglyph.o \ - hw/nxagent/NXmiexpose.o \ - hw/nxagent/NXresource.o \ - hw/nxagent/NXmiwindow.o \ - hw/nxagent/NXdamage.o -#else -NXAGENTOBJS = hw/nxagent/miinitext.o \ - hw/nxagent/NXwindow.o \ - hw/nxagent/NXevents.o \ - hw/nxagent/NXproperty.o \ - hw/nxagent/NXdixfonts.o \ - hw/nxagent/NXglyphcurs.o \ - hw/nxagent/NXdispatch.o \ - hw/nxagent/NXrender.o \ - hw/nxagent/NXglyph.o \ - hw/nxagent/NXpicture.o \ - hw/nxagent/NXextension.o \ - hw/nxagent/NXglxext.o \ - hw/nxagent/NXxvdisp.o \ - hw/nxagent/NXmiglyph.o \ - hw/nxagent/NXmiexpose.o \ - hw/nxagent/NXresource.o \ - hw/nxagent/NXmiwindow.o \ - hw/nxagent/NXdamage.o \ - dix/main.o -#endif - -XPMLIB = -lXpm -NXAGENT = hw/nxagent/LibraryTargetName(nxagent) -NXAGENTLIBS = PreFbLibs $(NXAGENT) FbPostFbLibs $(NXAGENT) $(MI) -NXAGENTSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XLIB) $(SYSLIBS) $(XPMLIB) -#if HasParallelMake -MakeMutex($(NXAGENTDIRS) $(NXAGENTOBJS) $(NXAGENTLIBS) $(NXAGENTSYSLIBS)) -#endif -#if ForceServerRemake -$(NXAGENTOBJS) $(NXAGENTLIBS) $(NXAGENTSYSLIBS):: $(NXAGENTDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -#if NXLibraries -/* - * We need this as the linker will try to locate dependencies of X11 and Xext. - */ - -#if defined(SunArchitecture) -NXAGENTNXLIBS = -L ../../../nxcomp -L ../../../nxcompext -L ../../../nxcompshad \ - -lXcomp -lXcompext -lXcompshad -lrt -L/usr/sfw/lib -lXrender -lXfixes \ - -L../../../nx-X11/exports/lib -lXtst -lXdamage -lXrandr -lXcomposite -#elif defined(cygwinArchitecture) -NXAGENTNXLIBS = -L ../../../nxcomp -L ../../../nxcompext \ - -lXcomp -lXcompext -lXrender -lX11 -lXext -lXcomposite -lXfixes \ - -L ../../../nxcompshad -lXcompshad -L../../../nx-X11/exports/lib -lXtst -#else -NXAGENTNXLIBS = -L ../../../nxcomp -L ../../../nxcompext -L ../../../nxcompshad \ - -lXcomp -lXcompext -lXcompshad -lXrender -lX11 -lXext -lXfixes \ - -L../../../nx-X11/exports/lib -lXtst -lXdamage -lXrandr -lXcomposite -#endif - -#endif - -#ifdef cygwinArchitecture -NX_XSHADOWLIBNAME = cygXcompshad.dll -#else -NX_XSHADOWLIBNAME = libXcompshad.so -#endif - -NX_XSHADOWLIBDIR = $(XTOP)/../nxcompshad -NX_XSHADOWLIBTARGET = $(NX_XSHADOWLIBDIR)/$(NX_XSHADOWLIBNAME) -NX_XSHADOWCONFIGTARGET = $(NX_XSHADOWLIBDIR)/config.status - -$(NX_XSHADOWCONFIGTARGET): - cd $(NX_XSHADOWLIBDIR) && \ - ./configure - -#ifdef SunArchitecture -$(NX_XSHADOWLIBTARGET): $(NX_XSHADOWCONFIGTARGET) - cd $(NX_XSHADOWLIBDIR) && \ - gmake -#else -$(NX_XSHADOWLIBTARGET): $(NX_XSHADOWCONFIGTARGET) - cd $(NX_XSHADOWLIBDIR) && \ - make -#endif - -ServerTarget(nxagent,$(NX_XSHADOWLIBTARGET) $(NXAGENTDIRS),$(NXAGENTOBJS), \ - $(LIBCWRAPPER) $(NXAGENTLIBS) $(LOADABLEEXTS),$(NXAGENTSYSLIBS) $(NXAGENTNXLIBS)) - -/* - * Hard coded target to build a static nxagent server. - */ -nxagent_static: nxagent - if [ -f nxagent_static ]; then set -x; \ - $(MV) nxagent_static nxagent_static.bak; \ - else exit 0; fi - $(CCLINK) -o nxagent_static -static $(LDOPTIONS) $(NXAGENTOBJS) \ - $(LIBCWRAPPER) $(NXAGENTLIBS) $(LOADABLEEXTS) $(LDLIBS) \ - $(NXAGENTSYSLIBS) $(EXTRA_LOAD_FLAGS) - -/* - * Hard coded target to build a static nxagent server except for libX11 and libXext. - */ -nxagent_static_nolibs: nxagent - if [ -f nxagent_static_nolibs ]; then set -x; \ - $(MV) nxagent__static_nolibs nxagent_static_nolibs.bak; \ - else exit 0; fi - $(CCLINK) -o nxagent_static_nolibs -Wl,-Bstatic $(LDOPTIONS) $(NXAGENTOBJS) \ - $(NXAGENTLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER) $(LDLIBS) $(FONTLIBS) \ - $(LDPRELIBS) $(SYSLIBS) -Wl,-Bdynamic -lXext -lX11 $(EXTRA_LOAD_FLAGS) -#endif /* NXAgentServer */ - -#if defined(XnonServer) && XnonServer -XCOMM -XCOMM non server, just compile sources for build test -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB32SUBDIR = cfb32 -#if HasParallelMake -MakeMutex($(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB32DIR) $(DEPDIRS)) -#endif -Xnon: $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB32DIR) $(DEPDIRS) -#endif /* XnonServer */ - - -#if defined(XVirtualFramebufferServer) && XVirtualFramebufferServer -XCOMM -XCOMM server with Virtual (malloced) framebuffer -XCOMM -MFBSUBDIR = mfb -FBSUBDIR = fb -#if defined(Win32Architecture) -XVFBDDXDIR = hw -#else -XVFBDDXDIR = hw/vfb -#endif -XVFBDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(XVFBDDXDIR) $(DEPDIRS) -#ifndef Win32Architecture -#if BuildDPMS -XVFBDPMSSTUBOBJS = $(XVFBDDXDIR)/dpmsstubs.o -#endif -XVFBOBJS = $(XVFBDDXDIR)/stubs.o $(XVFBDDXDIR)/miinitext.o $(XVFBDPMSSTUBOBJS) -#else -XVFBOBJS = dix/main.o hw/vfb/stubs.o hw/vfb/miinitext.o -#endif -XVFB = $(XVFBDDXDIR)/LibraryTargetName(vfb) -XVFBLIBS = PreFbLibs $(XVFB) $(FB) PostFbLibs $(MI) -XVFBSYSLIBS = $(FONTLIBS) $(SYSLIBS) -#if HasParallelMake -MakeMutex($(XVFBDIRS) $(XVFBOBJS) $(XVFB) $(XVFBLIBS) $(XVFBSYSLIBS)) -#endif -#if ForceServerRemake -$(XVFBOBJS) $(XVFB) $(XVFBLIBS) $(XVFBSYSLIBS):: $(XVFBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xvfb,$(XVFBDIRS),$(XVFBOBJS) $(XVFBDEFFILE), \ - $(LIBCWRAPPER) $(XVFBLIBS) $(LOADABLEEXTS),$(XVFBSYSLIBS)) -#endif /* XVirtualFramebufferServer */ - -#if defined(XdmxServer) && XdmxServer -XCOMM -XCOMM distribued multihead Server -XCOMM -#ifndef Win32Architecture -XDMXDDXDIR = hw/dmx -#else -XDMXDDXDIR = hw -#endif -FBDIR = fb -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -XDMXDIRS = $(STDDIRS) $(XDMXDDXDIR) $(SHADOWDIR) $(DEPDIRS) $(FBDIR) $(MIDAMAGEDIR) -#if BuildGlxExt -#if BuildXinerama -GLXPROXY_EXTRAOBJS = hw/dmx/panoramiX.o -#endif -GLXPROXYLIB = hw/dmx/glxProxy/LibraryTargetName(glxProxy) -#endif -#if !defined(LynxOSArchitecture) && \ - !defined(Win32Architecture) && \ - !defined(QNX4Architecture) -XDMXOBJS = hw/dmx/miinitext.o $(GLXPROXY_EXTRAOBJS) -#else -XDMXOBJS = hw/dmx/miinitext.o $(GLXPROXY_EXTRAOBJS) dix/main.o -#endif -XDMX = hw/dmx/LibraryTargetName(dmx) \ - hw/dmx/input/LibraryTargetName(dmxinput) \ - hw/dmx/config/LibraryTargetName(dmxconfig) \ - $(GLXPROXYLIB) -XDMXLIBS = PreFbLibs $(XDMX) MiExtLibs FbPostFbLibs $(XDMX) -#if BuildRender -XDMXRENDERLIB = $(XRENDERLIB) -#endif -XDMXSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XILIB) $(XLIB) $(SYSLIBS) $(XMULIB) $(XDMXRENDERLIB) -#if HasParallelMake -MakeMutex($(XDMXDIRS) $(XDMXOBJS) $(XDMXLIBS) $(XDMXSYSLIBS)) -#endif -#if ForceServerRemake -$(XDMXOBJS) $(XDMXLIBS) $(XDMXSYSLIBS):: $(XDMXDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xdmx,$(XDMXDIRS),$(XDMXOBJS), \ - $(LIBCWRAPPER) $(XDMXLIBS) $(LOADABLEEXTS),$(XDMXSYSLIBS)) -#endif /* XdmxServer */ - -#if defined(XWinServer) && XWinServer -XCOMM -XCOMM X Server for MS Windows -XCOMM -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -#if BuildXWinLayer -LAYERDIR = miext/layer -XWINLAYERLIB = $(LAYER) -#else -LAYERDIR = -XWINLAYERLIB = -#endif -#if BuildXWinMultiWindowExtWM -ROOTLESSDIR = miext/rootless -ROOTLESSLIB = $(ROOTLESSDIR)/LibraryTargetName(rootless) \ - $(ROOTLESSDIR)/safeAlpha/LibraryTargetName(safeAlpha) \ - $(ROOTLESSDIR)/accel/LibraryTargetName(rlAccel) -#else -ROOTLESSDIR = -ROOTLESSLIB = -#endif -XWINDDXDIR = hw/xwin -#if BuildXWinXF86Config -XWINPARSERDIR = hw/xfree86/parser -XWINPARSERLIB = $(XWINPARSERDIR)/LibraryTargetName(xf86config) -#else -XWINPARSERDIR = -XWINPARSERLIB = -#endif -#if defined(GlxUseWindows) && GlxUseWindows -XWINOPENGLLIB = -lopengl32 -#else -XWINOPENGLLIB = -#endif - -XWINLIB = $(XWINDDXDIR)/LibraryTargetName(XWin) -XWINDIRS = $(STDDIRS) $(FBDIR) $(SHADOWDIR) $(LAYERDIR) $(XWINDDXDIR) \ - $(DEPDIRS) $(XWINPARSERDIR) $(ROOTLESSDIR) $(MIDAMAGEDIR) -XWINOBJS = $(XWINDDXDIR)/stubs.o $(XWINDDXDIR)/XWin.res -XWINLIBS = PreFbLibs $(XWINLIB) FbPostFbLibs $(XWINLIB) $(XWINLAYERLIB) \ - $(SHADOW) $(XWINPARSERLIB) $(ROOTLESSLIB) $(OS) -#if BuildXWinMultiWindow || BuildXWinClipboard -XWINX11 = $(XONLYLIB) -# if defined(Win32Architecture) -PTHREADLIB = -lpthreadGC2 -# endif -#endif -#if defined(Win32Architecture) -# if defined(GlxUseWindows) && GlxUseWindows -XWINGL32 = -lopengl32 -# endif -XWINW32 = -lgdi32 -lwsock32 $(XWINGL32) $(PTHREADLIB) -#else -XWINW32 = -lgdi32 -#endif -XWINSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XWINX11) $(SYSLIBS) $(XWINW32) - -EXTRA_LDOPTIONS = -e _mainCRTStartup - -#if HasParallelMake -MakeMutex($(XWINDIRS) $(XWINOBJS) $(XWINLIB) $(XWINLIBS) $(XWINSYSLIBS)) -#endif - -#if ForceServerRemake -$(XWINOBJS) $(XWINLIB) $(XWINLIBS) $(XWINSYSLIBS):: $(XWINDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif - -#ifdef mingwArchitecture -XWINSERVERNAME=Xming -XWINGLSERVERNAME=XmingGL -#else -XWINSERVERNAME=XWin -XWINGLSERVERNAME=XWin_GL -#endif -ServerTarget($(XWINSERVERNAME),$(XWINDIRS),$(XWINOBJS), \ - $(LIBCWRAPPER) $(XWINLIBS) $(LOADABLEEXTS),$(XWINSYSLIBS)) -#if defined(cygwinArchitecture) && defined(GlxUseWindows) && GlxUseWindows -ServerTarget($(XWINGLSERVERNAME),$(XWINDIRS),$(XWINOBJS), \ - $(LIBCWRAPPER) $(XWINLIBS) $(LOADABLEEXTS),$(XWINSYSLIBS) \ - $(XWINOPENGLLIB)) -#endif - -#ifndef ServerToInstall -# define ServerToInstall $(XWINSERVERNAME) -#endif - -#endif /* XWinServer */ - - -#if defined(NXWinServer) && NXWinServer -XCOMM -XCOMM X Server for MS Windows -XCOMM -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -#if BuildXWinLayer -LAYERDIR = miext/layer -XWINLAYERLIB = $(LAYER) -#else -LAYERDIR = -XWINLAYERLIB = -#endif -#if BuildXWinMultiWindowExtWM -ROOTLESSDIR = miext/rootless -ROOTLESSLIB = $(ROOTLESSDIR)/LibraryTargetName(rootless) \ - $(ROOTLESSDIR)/safeAlpha/LibraryTargetName(safeAlpha) \ - $(ROOTLESSDIR)/accel/LibraryTargetName(rlAccel) -#else -ROOTLESSDIR = -ROOTLESSLIB = -#endif -NXWINDDXDIR = hw/nxwin -#if BuildXWinXF86Config -XWINPARSERDIR = hw/xfree86/parser -XWINPARSERLIB = $(XWINPARSERDIR)/LibraryTargetName(xf86config) -#else -XWINPARSERDIR = -XWINPARSERLIB = -#endif -#if defined(GlxUseWindows) && GlxUseWindows -XWINOPENGLLIB = -lopengl32 -#else -XWINOPENGLLIB = -#endif - -NXWINLIB = $(NXWINDDXDIR)/LibraryTargetName(NXWin) -NXWINDIRS = $(STDDIRS) $(FBDIR) $(SHADOWDIR) $(LAYERDIR) $(NXWINDDXDIR) \ - $(DEPDIRS) $(XWINPARSERDIR) $(ROOTLESSDIR) $(MIDAMAGEDIR) -NXWINOBJS = $(NXWINDDXDIR)/stubs.o $(NXWINDDXDIR)/NXWin.res -NXWINLIBS = PreFbLibs $(NXWINLIB) FbPostFbLibs $(NXWINLIB) $(XWINLAYERLIB) \ - $(SHADOW) $(XWINPARSERLIB) $(ROOTLESSLIB) $(OS) -#if BuildXWinMultiWindow || BuildXWinClipboard -XWINX11 = $(XONLYLIB) -# if defined(Win32Architecture) -PTHREADLIB = -lpthreadGC -# endif -#endif -#if defined(Win32Architecture) -# if defined(GlxUseWindows) && GlxUseWindows -XWINGL32 = -lopengl32 -# endif -XWINW32 = -lgdi32 -lwsock32 $(XWINGL32) $(PTHREADLIB) -#else -XWINW32 = -lgdi32 -#endif -NXWINSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XWINX11) $(SYSLIBS) $(XWINW32) - -NXWINNXLIBS = -L../../../nxcomp -lXcomp - -/* - * These flags cause NXWin.exe to be a Windows executable, which - * prevents NXWin.exe from opening a Command Prompt window when it is - * started. However, the flags also prevent NXWin.exe from outputting - * its status and error message to a Command Prompt; thus, one most - * implement a method to redirect status and error messages to a file - * before enabling these flags. - */ -EXTRA_LDOPTIONS = -e _mainCRTStartup - -#if HasParallelMake -MakeMutex($(NXWINDIRS) $(NXWINOBJS) $(NXWINLIB) $(NXWINLIBS) $(NXWINSYSLIBS) $(NXWINNXLIBS)) -#endif - -#if ForceServerRemake -$(NXWINOBJS) $(NXWINLIB) $(NXWINLIBS) $(NXWINSYSLIBS) $(NXWINNXLIBS):: $(NXWINDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif - -#ifdef mingwArchitecture -NXWINSERVERNAME=NXming -NXWINGLSERVERNAME=NXmingGL -#else -NXWINSERVERNAME=NXWin -NXWINGLSERVERNAME=NXWin_GL -#endif -ServerTarget($(NXWINSERVERNAME),$(NXWINDIRS),$(NXWINOBJS), \ - $(LIBCWRAPPER) $(NXWINLIBS) $(LOADABLEEXTS),$(NXWINSYSLIBS) $(NXWINNXLIBS)) -#if defined(cygwinArchitecture) && defined(GlxUseWindows) && GlxUseWindows -ServerTarget($(NXWINGLSERVERNAME),$(NXWINDIRS),$(NXWINOBJS), \ - $(LIBCWRAPPER) $(NXWINLIBS) $(LOADABLEEXTS),$(NXWINSYSLIBS) $(NXWINNXLIBS)\ - $(XWINOPENGLLIB)) -#endif - -#ifndef ServerToInstall -# define ServerToInstall $(NXWINSERVERNAME) -#endif - -#endif /* NXWinServer */ - -#if 0 -#if defined(NXWinServer) && NXWinServer -XCOMM -XCOMM X Server for MS Windows -XCOMM -FBDIR = fb -SHADOWDIR = miext/shadow -LAYERDIR = miext/layer -NXWINDDXDIR = hw/nxwin -XWINPARSERDIR = hw/xfree86/parser -XWINPARSERLIB = $(XWINPARSERDIR)/LibraryTargetName(xf86config) -NXWINLIB = $(NXWINDDXDIR)/LibraryTargetName(nxwin) -NXWINDIRS = $(STDDIRS) $(FBDIR) $(SHADOWDIR) $(LAYERDIR) $(NXWINDDXDIR) \ - $(DEPDIRS) $(XWINPARSERDIR) -#NXWINOBJS = $(NXWINDDXDIR)/stubs.o $(NXWINDDXDIR)/NX.res \ - $(NXWINDDXDIR)/NXwindow.o \ - $(NXWINDDXDIR)/NXdispatch.o $(NXWINDDXDIR)/NXproperty.o \ - $(NXWINDDXDIR)/NXevents.o -NXWINOBJS = $(NXWINDDXDIR)/stubs.o $(NXWINDDXDIR)/NX.res -NXWINLIBS = PreFbLibs $(NXWINLIB) FbPostFbLibs $(LAYER) $(SHADOW) \ - $(XWINPARSERLIB) -NXWINSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XLIB) $(SYSLIBS) -lgdi32 -lddraw -NXWINNXLIBS = -L../../../nxcomp -lXcomp - -/* - * These flags cause NXWin.exe to be a Windows executable, which - * prevents NXWin.exe from opening a Command Prompt window when it is - * started. However, the flags also prevent NXWin.exe from outputting - * its status and error message to a Command Prompt; thus, one most - * implement a method to redirect status and error messages to a file - * before enabling these flags. - */ -EXTRA_LDOPTIONS = -mwindows -e _mainCRTStartup - -#if HasParallelMake -MakeMutex($(NXWINDIRS) $(NXWINOBJS) $(NXWINLIB) $(NXWINLIBS) $(NXWINSYSLIBS) $(NXWINNXLIBS)) -#endif - -#if ForceServerRemake -$(NXWINOBJS) $(NXWINLIB) $(NXWINLIBS) $(NXWINSYSLIBS) $(NXWINNXLIBS):: $(NXWINDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif - -ServerTarget(NXWin,$(NXWINDIRS),$(NXWINOBJS), \ - $(NXWINLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER),$(NXWINSYSLIBS) $(NXWINNXLIBS)) - -#ifndef ServerToInstall -#define ServerToInstall NXWin -#endif - -#endif /* NXWinServer */ -#endif - -#ifdef DarwinArchitecture -/* - * To allow building even when building the client-side libraries is turned - * off, libraries in ProjectRoot are listed as dependencies for some targets. - * This causes problems unless we tell make where to find these dependencies. - */ -VPATH = $(BUILDLIBDIR):$(USRLIBDIR) -#endif - -#if defined(XDarwinServer) && XDarwinServer -XCOMM -XCOMM X Darwin server for Mac OS X / Darwin -XCOMM -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -ROOTLESSDIR = miext/rootless -DARWINDDXDIR = hw/darwin -DARWINDIRS = $(STDDIRS) $(FBDIR) $(SHADOWDIR) $(DARWINDDXDIR) $(DEPDIRS) -DARWINOBJS = $(DARWINDDXDIR)/miinitext.o -DARWINLIBS = PreFbLibs $(DARWINDDXDIR)/LibraryTargetName(darwin) -DARWINEXTLIBS = MiExtLibs FbPostFbLibs $(DARWINDDXDIR)/LibraryTargetName(darwin) -DARWINSYSLIBS = $(FONTLIBS) $(SYSLIBS) -framework IOKit -IOKITLIB = $(DARWINDDXDIR)/iokit/LibraryTargetName(iokit) - -/* - * IOKit X server - */ -SetUIDServerTarget(XDarwin,$(DARWINDIRS),$(DARWINOBJS), \ - $(DARWINLIBS) $(IOKITLIB) $(DARWINEXTLIBS),$(DARWINSYSLIBS)) - -#if DarwinQuartzSupport - -QUARTZDIR = $(DARWINDDXDIR)/quartz -QUARTZLIB = $(QUARTZDIR)/LibraryTargetName(XQuartz) -QUARTZSYSLIBS = -framework ApplicationServices -framework Cocoa \ - -framework CoreAudio -framework Carbon -ObjC -ROOTLESSLIB = $(ROOTLESSDIR)/LibraryTargetName(rootless) \ - $(ROOTLESSDIR)/safeAlpha/LibraryTargetName(safeAlpha) \ - $(ROOTLESSDIR)/accel/LibraryTargetName(rlAccel) -XPLUGINLIB = XpluginLibrary - -#if NothingOutsideProjectRoot -XDARWINAPPDIR = $(BINDIR)/XDarwin.app/Contents -#else -XDARWINAPPDIR = /Applications/XDarwin.app/Contents -#endif - -/* - * Quartz X server (installed in its application bundle) - */ -SetUIDServerTarget(XDarwinApp,$(DARWINDIRS),$(DARWINOBJS), \ - $(DARWINLIBS) $(QUARTZLIB) $(DARWINEXTLIBS), \ - $(DARWINSYSLIBS) $(QUARTZSYSLIBS) -u _miDCInitialize) - -install:: - $(MKDIRHIER) $(DESTDIR)$(XDARWINAPPDIR)/MacOS - $(MV) $(DESTDIR)$(BINDIR)/XDarwinApp \ - $(DESTDIR)$(XDARWINAPPDIR)/MacOS/XDarwin - -(cd $(DESTDIR)$(BINDIR); $(RM) XDarwinQuartz; \ - $(LN) $(XDARWINAPPDIR)/MacOS/XDarwin XDarwinQuartz) - -/* - * Display mode bundles for Quartz - * (installed in their own bundles inside XDarwin's) - */ -#if HasXplugin -XPRDIRS = $(QUARTZDIR)/xpr $(ROOTLESSDIR) $(ROOTLESSDIR)/safeAlpha -XPRLIBS = $(QUARTZDIR)/xpr/LibraryTargetName(xpr) $(ROOTLESSLIB) - -BundleProgramTarget(xpr,XDarwinApp,$(XPRDIRS),$(QUARTZDIR)/xpr/xprScreen.o, \ - $(XPRLIBS),-framework ApplicationServices \ - $(XPLUGINLIB),$(XDARWINAPPDIR)/Resources) -#endif - -CRDIRS = $(QUARTZDIR)/cr $(ROOTLESSDIR) $(ROOTLESSDIR)/safeAlpha -CRLIBS = $(QUARTZDIR)/cr/LibraryTargetName(cr) $(ROOTLESSLIB) - -BundleProgramTarget(cr,XDarwinApp,$(CRDIRS),$(QUARTZDIR)/cr/crScreen.o, \ - $(CRLIBS),-framework ApplicationServices -framework Cocoa \ - -framework Carbon -ObjC,$(XDARWINAPPDIR)/Resources) - -FSDIRS = $(QUARTZDIR)/fullscreen $(SHADOWDIR) -FSLIBS = $(QUARTZDIR)/fullscreen/LibraryTargetName(fullscreen) $(SHADOW) - -BundleProgramTarget(fullscreen,XDarwinApp,$(FSDIRS), \ - $(QUARTZDIR)/fullscreen/fullscreen.o,$(FSLIBS), \ - -framework ApplicationServices,$(XDARWINAPPDIR)/Resources) - -/* - * GLX bundles for Quartz - * (installed in their own bundles inside XDarwin's) - */ -BundleProgramTarget(glxAGL,XDarwinApp,GL,GL/glx/glxext.o,GL/glx/libglx.a \ - GL/apple/libAGLcore.a, \ - -framework AGL -framework OpenGL,$(XDARWINAPPDIR)/Resources) - -#if BuildAppleDRI -BundleProgramTarget(glxCGL,XDarwinApp,GL,GL/glx/glxext.o,GL/glx/libglx.a \ - GL/apple/libCGLcore.a, \ - -framework OpenGL $(XPLUGINLIB),$(XDARWINAPPDIR)/Resources) -#endif - -BundleProgramTarget(glxMesa,XDarwinApp,GL,GL/glx/glxext.o,GL/glx/libglx.a \ - GL/mesa/GLcore/libGLcore.a,NullParameter,$(XDARWINAPPDIR)/Resources) - -#else /* !DarwinQuartzSupport */ - -#define ServerToInstall XDarwin - -#endif /* DarwinQuartzSupport */ - -#endif /* XDarwinServer */ - - -CFBSUBDIRS = $(CFB8SUBDIR) $(CFB16SUBDIR) $(CFB24SUBDIR) $(CFB32SUBDIR) -MIEXTDIRS = $(SHADOWDIR) $(LAYERDIR) $(ROOTLESSDIR) $(MIDAMAGEDIR) -IPLANDIRS = $(IPLAN2P2DIR) $(IPLAN2P4DIR) $(IPLAN2P8DIR) -DDXDIRS = $(DECWSDDXDIR) $(SUNDDXDIR) $(LYNXDDXDIR) \ - $(HPDDXDIR) $(XFREE86DDXDIR) $(XWINDDXDIR) $(DARWINDDXDIR) \ - $(XVFBDDXDIR) $(XNESTDDXDIR) $(XDMXDDXDIR) $(NXAGENTDDXDIR) $(NXWINDDXDIR) -SUBDIRS = $(STDDIRS) $(MFBSUBDIR) $(CFBSUBDIRS) \ - $(IPLANDIRS) $(ILBMDIR) $(AFBSUBDIR) \ - $(DDXDIRS) $(FBSUBDIR) $(KDRIVEDIRS) $(MIEXTDIRS) - -#if defined(ServerToInstall) && !defined(OS2Architecture) -install:: - -(cd $(DESTDIR)$(BINDIR); $(RM) X; $(LN) ServerToInstall X) -#endif - -#define IHaveSubdirs - -DependSubdirs($(SUBDIRS)) -MakeLintLibSubdirs($(SUBDIRS)) -LintSubdirs($(SUBDIRS)) - -ForceSubdirs($(DEPDIRS) $(SUBDIRS)) - -DEFAULTFONTPATH = DefaultFontPath -EXTRAMANDEFS = -D__default_font_path__="`echo $(DEFAULTFONTPATH) | sed -e 's/,/, /g'`" - -InstallManPage(Xserver,$(MANDIR)) - -#if MakeDllModules && DoLoadableServer && \ - (defined(SunArchitecture) && defined(SVR4Architecture)) -XCOMM Hackery for building dlopen-able .so modules on Solaris - -AllTarget(linker-deps) - -LINKER_DEPS_DIRS = $(SUBDIRS) $(FONTLIBSRC) - -XCOMM After everything is built, run through and generate linker dependencies -linker-deps: - RunPerlScript($(XF86SRC)/os-support/sunos/find_deps.pl,-R ProjectRoot $(LINKER_DEPS_DIRS)) - for i in $(LINKER_DEPS_DIRS) ; do \ - echo "relinking with dependency flags in $(CURRENT_DIR)/$$i..."; \ - MakeNamedTargetSubdir($$i,NullParameter,all) ; \ - done -#endif diff --git a/nx-X11/programs/Xserver/Imakefile.X.original b/nx-X11/programs/Xserver/Imakefile.X.original deleted file mode 100644 index 58471ca7f..000000000 --- a/nx-X11/programs/Xserver/Imakefile.X.original +++ /dev/null @@ -1,1242 +0,0 @@ -XCOMM $XdotOrg: xc/programs/Xserver/Imakefile,v 1.37 2005/11/18 18:15:23 ajax Exp $ -XCOMM $Xorg: Imakefile,v 1.4 2001/03/14 18:42:02 pookie Exp $ -/* - * Server Master Makefile - */ -XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.296 2003/11/23 06:47:00 torrey Exp $ - -#ifndef InstallXserverSetUID -#define InstallXserverSetUID NO -#endif -#define InstallServerSetUID InstallXserverSetUID - -#include - -/* On most systems the linker requires the libraries in dependency order. - But we have no real order because there are cycles. We fix this by adding - some libraries twice on the commandline. dependLib will add the - dependency library to the commandline if the link order is important */ -#if 1 /* This is currently enabled for all systems */ -#define dependLib(x) x -#else -#define dependLib(x) -#endif - -#if (defined (XFree86Version) || defined(XorgVersion)) -/* Do not strip server binaries */ -INSTPGMFLAGS = -#endif - -#define PreFbLibs $(DIX) $(OS) $(XPDDX) -#define PreFbLibsNoFont $(DIX) $(OS) -#define BarePostFbLibs $(MFB) $(XPFBLIBS) $(MI) -#define PostFbLibs BarePostFbLibs $(EXTENSIONS) -#define NoMfbBarePostFbLibs $(XPFBLIBS) $(MI) -#if !BuildXinerama -#define NoMfbPostFbLibs NoMfbBarePostFbLibs $(EXTENSIONS) -#else -#define NoMfbPostFbLibs $(EXTENSIONS) NoMfbBarePostFbLibs $(EXTENSIONS) -#endif - -#define MFBBareLibs PreFbLibs BarePostFbLibs -#define NoMFBBareLibs PreFbLibs NoMfbBarePostFbLibs -#define MFBLibs PreFbLibs PostFbLibs -#define NoMFBLibs PreFbLibs NoMfbPostFbLibs -#define CFBLibs PreFbLibs $(CFB) PostFbLibs -#define CFB4Libs PreFbLibs $(CFB4) PostFbLibs -#define CFB8Libs PreFbLibs $(CFB8) PostFbLibs -#define CFB16Libs PreFbLibs $(CFB16) PostFbLibs -#define CFB24Libs PreFbLibs $(CFB24) PostFbLibs -#define CFB32Libs PreFbLibs $(CFB32) PostFbLibs - -#define NoMFBCFBLibs PreFbLibs $(CFB) NoMfbPostFbLibs -#define NoMFBCFB8Libs PreFbLibs $(CFB8) NoMfbPostFbLibs -#define FbPostFbLibs $(FB) NoMfbPostFbLibs -#define FBLibs PreFbLibs FbPostFbLibs - -#define MiExtLibs $(SHADOW) - -#define AllFBLibs PreFbLibs $(FB) $(CFB) PostFbLibs - -#if BuildGlxExt -# if BuildXF86DRI && ((defined(XF86Server) && XF86Server) \ - || (defined(XorgServer) && XorgServer)) - DRILIB = GL/dri/ModuleLibraryTargetName(dri) -# else - DRILIB = -# endif -# if GlxUseSGISI - GLXLIB = GL/glx/ModuleLibraryTargetName(glx) \ - GL/sgi-si/ModuleLibraryTargetName(GLcore) \ - $(DRILIB) -# else -# if defined(GlxUseWindows) && GlxUseWindows - XWin_GL.exe.GLXLIB = GL/glx/ModuleLibraryTargetName(glx_stdcall) \ - GL/windows/ModuleLibraryTargetName(GLcore) -# endif /* GlxUseWindows */ -# if defined(Win32Architecture) && defined(GlxUseWindows) && GlxUseWindows - GLXLIB = GL/glx/ModuleLibraryTargetName(glx_stdcall) \ - GL/windows/ModuleLibraryTargetName(GLcore) -# elif DoLoadableServer - GLXLIB = GL/glx/ModuleLibraryTargetName(glx) \ - GL/mesa/GLcore/ModuleLibraryTargetName(GLcore) -# else - GLXLIB = GL/glx/ModuleLibraryTargetName(glx) \ - GL/mesa/GLcore/ModuleLibraryTargetName(GLcore) \ - $(DRILIB) -# endif -# endif - GLXDIR = GL -# if defined(cygwinArchitecture) && defined(GlxUseWindows) && GlxUseWindows - GLXEXT = $(if $($@.GLXLIB),$($@.GLXLIB), $(GLXLIB)) -# else - GLXEXT = $(GLXLIB) -# endif -#endif - -#if BuildXInputExt - XINPUTEXT = Xi/LibraryTargetName(xinput) - XIDIR = Xi -#endif -#if BuildXKB - XKBEXT = xkb/LibraryTargetName(xkb) dependLib($(OS)) - XKBDIR = xkb -#if (defined(XFree86Version) || defined(XorgVersion)) - XF86XKBOBJS = xkb/xf86KillSrv.o xkb/xf86VT.o xkb/xf86Private.o -#endif -#endif -#if BuildLBX - LBXEXT = lbx/LibraryTargetName(lbx) \ - $(TOP)/lib/lbxutil/LibraryTargetName(lbxutil) - LBXDIRS = lbx -#endif -#if BuildDBE - DBEEXT = dbe/LibraryTargetName(dbe) -#endif -#if BuildDBE || BuildDBElib - DBEDIR = dbe -#endif -#if BuildRECORD - RECORDEXT = record/LibraryTargetName(record) -#endif -#if BuildRECORD || BuildRECORDlib - RECORDDIR = record -#endif -#if BuildXTrap - XTRAPEXT = XTrap/LibraryTargetName(xtrap) - XTRAPDIR = XTrap -#endif -#ifdef SiteExtensionLibs - SITEEXTS = SiteExtensionLibs -#endif -#ifdef SiteExtensionDirs - SITEEXTDIRS = SiteExtensionDirs -#endif -#if DoLoadableServer && HasDlopen - LIBDL = DlLibrary -#endif - LIBREGEX = RegexLibrary - -#if DoLoadableServer - LIBCWRAPPER = os/libcwrapper.o -#endif - -#if BuildXprint - -XPCONFIGDIR = XpConfig - -#ifndef XpRasterDDX -#define XpRasterDDX YES -#endif -#ifndef XpColorPclDDX -#define XpColorPclDDX YES -#endif -#ifndef XpMonoPclDDX -#define XpMonoPclDDX NO -#endif -#ifndef XpPostScriptDDX -#define XpPostScriptDDX YES -#endif - -#if XpRasterDDX -XPRASTLIB = Xprint/raster/LibraryTargetName(raster) -#endif -#if XpColorPclDDX -XPPCLLIB = Xprint/pcl/LibraryTargetName(pcl) -#endif -#if XpMonoPclDDX -XPMPCLLIB = Xprint/pcl-mono/LibraryTargetName(pcl) -#endif -#if XpPostScriptDDX -XPPSLIB = Xprint/ps/LibraryTargetName(ps) -#endif - -XPDDXLIBS = Xprint/LibraryTargetName(printer) \ - $(XPRASTLIB) $(XPPCLLIB) $(XPMPCLLIB) $(XPPSLIB) -XPDDXFBLIBS = $(MFB) $(CFB32) -#if !PrintOnlyServer - XPFBLIBS = $(XPDDXFBLIBS) - XPDDX = $(XPDDXLIBS) -#endif - XPDDXDIR = Xprint -#endif -#if !BuildXprint || PrintOnlyServer -XPFBLIBS = dix/LibraryTargetName(xpstubs) -#endif - -#if BuildRender - RENDERDIR = render - RENDERLIB = $(RENDERDIR)/librender.a -#endif -#if BuildRandR - RANDRDIR = randr - RANDRLIB = $(RANDRDIR)/librandr.a -#endif -#if BuildXfixes - FIXESDIR = xfixes - FIXESLIB = $(FIXESDIR)/libxfixes.a -#endif -#if BuildDamage - DAMAGEDIR = damageext - DAMAGELIB = $(DAMAGEDIR)/libdamage.a -#endif -#if BuildComposite - CWDIR = miext/cw - COMPOSITEDIR = composite - COMPOSITELIB = $(COMPOSITEDIR)/libcomposite.a -#if DoLoadableServer - CW = miext/cw/ModuleLibraryTargetName(cw) -#else - CW = miext/cw/LibraryTargetName(cw) -#endif -#endif -#if DoLoadableServer - EXTENSIONS = $(COMPOSITELIB) $(DAMAGELIB) $(DAMAGE) $(FIXESLIB) $(CW) \ - $(OTHEREXTS) $(RANDRLIB) $(RENDERLIB) - LOADABLEEXTS = $(MISCEXT) $(DBEEXT) $(RECORDEXT) $(GLXEXT) $(XTRAPEXT) - MISCEXT = Xext/LibraryTargetName(ext) - OTHEREXTS = Xext/LibraryTargetName(exts) $(XKBEXT) $(XINPUTEXT) \ - $(LBXEXT) $(SITEEXTS) -#else - EXTENSIONS = $(COMPOSITELIB) $(DAMAGELIB) $(DAMAGE) $(FIXESLIB) $(CW) \ - $(OTHEREXTS) $(GLXEXT) $(RANDRLIB) $(RENDERLIB) - OTHEREXTS = Xext/LibraryTargetName(ext) $(XKBEXT) $(XINPUTEXT) \ - $(LBXEXT) $(DBEEXT) $(RECORDEXT) $(SITEEXTS) $(XTRAPEXT) -#endif - EXTDIRS = Xext $(XKBDIR) $(XIDIR) $(GLXDIR) \ - $(LBXDIRS) $(DBEDIR) $(RECORDDIR) $(SITEEXTDIRS) \ - $(RANDRDIR) $(RENDERDIR) $(XTRAPDIR) $(XPCONFIGDIR) \ - $(FIXESDIR) $(DAMAGEDIR) $(CWDIR) $(COMPOSITEDIR) -#if BuildLBX || GzipFontCompression - ZLIB = GzipLibrary -#endif - OS = os/LibraryTargetName(os) - BSDEMUL = $(DEPXBSDLIB) -#if DoLoadableServer - MFB = mfb/ModuleLibraryTargetName(mfb) - FB = fb/ModuleLibraryTargetName(fb) -#if XF8_32Wid - CFB = cfb/ModuleLibraryTargetName(cfb) \ - cfb16/ModuleLibraryTargetName(cfb16) \ - cfb24/ModuleLibraryTargetName(cfb24) \ - cfb32/ModuleLibraryTargetName(cfb32) -#else - CFB = cfb/ModuleLibraryTargetName(cfb) \ - cfb16/ModuleLibraryTargetName(cfb16) \ - cfb32/ModuleLibraryTargetName(cfb32) -#endif - CFB8 = cfb/ModuleLibraryTargetName(cfb) - CFB4 = cfb/ModuleLibraryTargetName(cfb) \ - cfb4/ModuleLibraryTargetName(cfb4) - CFB16 = cfb/ModuleLibraryTargetName(cfb) \ - cfb16/ModuleLibraryTargetName(cfb16) - CFB24 = cfb/ModuleLibraryTargetName(cfb) \ - cfb24/ModuleLibraryTargetName(cfb24) - CFB32 = cfb/ModuleLibraryTargetName(cfb) \ - cfb32/ModuleLibraryTargetName(cfb32) - DAMAGE = miext/damage/ModuleLibraryTargetName(damage) - SHADOW = miext/shadow/ModuleLibraryTargetName(shadow) - LAYER = miext/layer/ModuleLibraryTargetName(layer) -#else - MFB = mfb/LibraryTargetName(mfb) - FB = fb/LibraryTargetName(fb) -#if XF8_32Wid - CFB = cfb16/LibraryTargetName(cfb16) \ - cfb24/LibraryTargetName(cfb24) \ - cfb32/LibraryTargetName(cfb32) \ - cfb/LibraryTargetName(cfb) -#else - CFB = cfb16/LibraryTargetName(cfb16) \ - cfb32/LibraryTargetName(cfb32) \ - cfb/LibraryTargetName(cfb) -#endif - CFB8 = cfb/LibraryTargetName(cfb) - CFB4 = cfb4/LibraryTargetName(cfb4) \ - cfb/LibraryTargetName(cfb) - CFB16 = cfb16/LibraryTargetName(cfb16) \ - cfb/LibraryTargetName(cfb) - CFB24 = cfb24/LibraryTargetName(cfb24) \ - cfb/LibraryTargetName(cfb) - CFB32 = cfb32/LibraryTargetName(cfb32) \ - cfb/LibraryTargetName(cfb) - DAMAGE = miext/damage/LibraryTargetName(damage) - SHADOW = miext/shadow/LibraryTargetName(shadow) - LAYER = miext/layer/LibraryTargetName(layer) -#endif -#if !HasFfs && (defined(mingwArchitecture) || defined(cygwinArchitecture)) - /* Order of libraries is important when linking in mingw or - * cygwin. libmi.a requires ffs from libdix.a. So it is added - * after libmi.a on the commandline */ - MI = mi/LibraryTargetName(mi) $(DIX) -#else - MI = mi/LibraryTargetName(mi) -#endif - MIINITEXTOBJ = mi/miinitext.o - DIX = dix/LibraryTargetName(dix) - FONTBASE = $(FONTLIBSRC)/fontbase.o \ - $(FONTLIBSRC)/LibraryTargetName(fontbase) -#if XserverStaticFontLib - FONT = $(FONTLIBSRC)/LibraryTargetName(Xfont) $(FREETYPE2LIB) -#else - FONT = $(LDPRELIB) $(XFONTLIB) $(FREETYPE2LIB) -#endif - FONTLIBS = $(FONT) $(XPFBLIBS) -#if UsbMouseSupport -#if !HasLibUsb - USB = $(XF86OSSRC)/bsd/libusb/LibraryTargetName(usb) -#else - USB = UsbHidLib -#endif -#endif -#ifdef ServerExtraSysLibs - EXTRASYSLIBS = ServerExtraSysLibs -#endif -#if HasPam && HasPamMisc - PAMLIBS = PamLibraries PamMiscLibraries -#endif -#if !(SystemV4 || defined(SGIArchitecture) || UseRgbTxt) - DBMLIBS = DBMLibrary -#endif - SYSLIBS = $(ZLIB) MathLibrary Krb5Libraries $(DBMLIBS) $(USB) \ - $(PAMLIBS) $(XAUTHLIB) $(XDMCPLIB) $(EXTRASYSLIBS) -#if !HasCbrt - CBRT = mi/LibraryTargetName(cbrt) -#endif - STDDIRS = include dix os mi $(XPDDXDIR) $(EXTDIRS) - FBDIR = fb - MFBDIR = mfb - CFB4DIR = cfb4 - CFB8DIR = cfb - CFB16DIR = cfb16 - CFB24DIR = cfb24 - CFB32DIR = cfb32 - AFBDIR = afb - -XCOMM -XCOMM This turns off the default rule for compiling .c files because -XCOMM this makefile does not really know how to build it. This is really -XCOMM just a hack because of the Sun version of make and nfs. -XCOMM -.c.o: - -.s.o: - -/* Build rule blocks, add one for each server - * - * If a server needs mfb, its build block should have a line like: - * MFBSUBDIR = mfb - * Similarly, its build block should have: - * CFB4SUBDIR = cfb4 (if the server needs 4 bit cfb) - * CFB8SUBDIR = cfb (8 bit cfb) - * CFB16SUBDIR = cfb16 (16 bit cfb) - * CFB24SUBDIR = cfb24 (24 bit cfb) - * CFB32SUBDIR = cfb32 (32 bit cfb) - * - * If a server does not need all of the above components, simply - * omit the relevant lines from the build block. - * - * If these guidelines are followed, a make at the top of the server - * tree should result in each subdirectory being built only once, - * even if multiple servers that share subdirectories are being built. - */ - -#if defined(XdecServer) && XdecServer -XCOMM -XCOMM Digital MIPS based WS server (ultrix 4.2 and beyond) -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -DECWSDDXDIR = hw/dec/ws -DECDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DECWSDDXDIR) $(DEPDIRS) -DECOBJS = hw/dec/ws/init.o hw/dec/ws/sdepthinit.o -DECLIBS = hw/dec/ws/LibraryTargetName(dec) CFB8Libs -ServerTarget(Xdec,$(DECDIRS),$(DECOBJS), \ - $(DECLIBS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xdec -#endif -#endif /* XdecServer */ - - -#if defined(XdecMultiDepthServer) && XdecMultiDepthServer -XCOMM -XCOMM Digital MIPS based WS server (ultrix 4.2 and beyond) -XCOMM Supports 8, 12, and 24 bit pixmaps -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB24SUBDIR = cfb24 -CFB32SUBDIR = cfb32 -DECWSDDXDIR = hw/dec/ws -DECDIRS1 = $(STDDIRS) $(MFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(DECWSDDXDIR) $(DEPDIRS) -DECOBJS1 = hw/dec/ws/init.o hw/dec/ws/mdepthinit.o -DECLIBS1 = hw/dec/ws/LibraryTargetName(dec) CFBLibs -ServerTarget(Xdec_md,$(DECDIRS1),$(DECOBJS1), \ - $(DECLIBS1),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xdec_md -#endif -#endif /* XdecMultiDepthServer */ - - -#if defined(XsunServer) && XsunServer -XCOMM -XCOMM Sun server -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -SUNDDXDIR = hw/sun -#if DoLoadableServer -SUNOBJS = hw/sun/sunInit.o hw/sun/sunInitExt.o hw/sun/stubs.o -#elif (defined(XF86Server) && XF86Server) \ - || (defined(XorgServer) && XorgServer) -SUNOBJS = hw/sun/sunInit.o hw/sun/stubs.o -#else -SUNOBJS = hw/sun/sunInit.o -#endif -SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(SUNDDXDIR) $(DEPDIRS) -SUNLIBS = hw/sun/LibraryTargetName(sun) CFB8Libs -SUNSYSLIBS = $(FONTLIBS) $(WIDECHARSYSLIB) $(SYSLIBS) -SetUIDServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS), \ - $(LIBCWRAPPER) $(SUNLIBS) $(LOADABLEEXTS),$(SUNSYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xsun -#endif -#endif /* XsunServer */ - - -#if defined(Xsun24Server) && Xsun24Server -XCOMM -XCOMM Sun multiple pixmap depth (8, 12, 24) server -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB24SUBDIR = cfb24 -CFB32SUBDIR = cfb32 -SUNDDXDIR = hw/sun -SUN24DIRS = $(STDDIRS) $(MFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(SUNDDXDIR) $(DEPDIRS) -#if DoLoadableServer -SUN24OBJS = hw/sun/sunInitMulti.o hw/sun/sunInitExt.o hw/sun/stubs.o -#elif defined(XF86Server) && XF86Server \ - || (defined(XorgServer) && XorgServer) -SUN24OBJS = hw/sun/sunInitMulti.o hw/sun/stubs.o -#else -SUN24OBJS = hw/sun/sunInitMulti.o -#endif -SUN24LIBS = hw/sun/LibraryTargetName(sun) CFBLibs -SetUIDServerTarget(Xsun24,$(SUN24DIRS),$(SUN24OBJS), \ - $(LIBCWRAPPER) $(SUN24LIBS) $(LOADABLEEXTS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xsun24 -#endif -#endif /* Xsun24Server */ - - -#if defined(XsunMonoServer) && XsunMonoServer -XCOMM -XCOMM Sun monochrome server -XCOMM -MFBSUBDIR = mfb -SUNDDXDIR = hw/sun -SUNMDIRS = $(STDDIRS) $(MFBDIR) $(SUNDDXDIR) $(DEPDIRS) -#if defined(XF86Server) && XF86Server \ - || (defined(XorgServer) && XorgServer) -SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o hw/sun/stubs.o -#else -SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o -#endif -SUNMLIBS = hw/sun/LibraryTargetName(sun) MFBBareLibs $(EXTENSIONS) -SetUIDServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS), \ - $(LIBCWRAPPER) $(SUNMLIBS) $(LOADABLEEXTS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall XsunMono -#endif -#endif /* XsunMonoServer */ - - -#if defined(XsunLynxServer) && XsunLynxServer -XCOMM -XCOMM Sun server for LynxOS microSPARC 2.4.0 -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -LYNXDDXDIR = hw/sunLynx -SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(LYNXDDXDIR) $(DEPDIRS) -SUNOBJS = hw/sunLynx/sunLyInit.o -SUNLIBS = hw/sunLynx/libsun.a CFB8Libs -ServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS), \ - $(SUNLIBS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall Xsun -#endif -#endif /* XsunLynxServer */ - - -#if defined(XsunLynxMonoServer) && XsunLynxMonoServer -XCOMM -XCOMM Sun monochrome server for LynxOS microSPARC 2.4.0 -XCOMM -MFBSUBDIR = mfb -LYNXDDXDIR = hw/sunLynx -SUNMDIRS = $(STDDIRS) $(MFBDIR) $(LYNXDDXDIR) $(DEPDIRS) -SUNMOBJS = hw/sunLynx/sunInitMono.o hw/sunLynx/sunInExMono.o -SUNMLIBS = hw/sunLynx/libsun.a MFBBareLibs $(OTHEREXTS) -ServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS), \ - $(SUNMLIBS),$(FONTLIBS) $(SYSLIBS)) -#ifndef ServerToInstall -#define ServerToInstall XsunMono -#endif -#endif /* XsunLynxMonoServer */ - - -#if HasParallelMake -XCOMM -XCOMM force non-parallel build of XF86 servers to prevent MUTEX overrides -XCOMM -#if defined(XF86Server) && XF86Server -XF86SERVER = XFree86 -#endif -#if defined(XorgServer) && XorgServer -XF86SERVER = Xorg -#endif -#if defined(XnestServer) && XnestServer -XNEST = Xnext -#endif -#if defined(XVirtualFramebufferServer) && XVirtualFramebufferServer -XVFB = Xvfb -#endif -#if XdmxServer -XDMX = Xdmx -#endif -#if defined(XWinServer) && XWinServer && !MakeDllModules -XWIN = XWin -#endif -#if (defined(XF86Server) && XF86Server) || \ - (defined(XorgServer) && XorgServer) || \ - (defined(XnestServer) && XnestServer) || \ - (defined(XVirtualFramebufferServer) && XVirtualFramebufferServer) || \ - (defined(XdmxServer) && XdmxServer) || \ - (!MakeDllModules && defined(XWinServer) && XWinServer) -MakeMutex($(XF86SERVER) $(XNEST) $(XVFB) $(XWIN)) -#endif -MakeMutex($(STDDIRS) mfb fb cfb cfb16 cfb24 cfb32) -#endif - - -#if defined(XF86Server) && XF86Server -XCOMM -XCOMM XFree86 Server -XCOMM -FBSUBDIR = fb -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB24SUBDIR = cfb24 -CFB32SUBDIR = cfb32 -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -LAYERDIR = miext/layer -#ifdef OS2Architecture -SERVERDEFFILE = XFree86.def -XNESTDEFFILE = Xnest.def -XVFBDEFFILE = Xvfb.def -#endif -#if XF86AFB -AFBSUBDIR = afb -#endif -XFREE86DDXDIR = hw/xfree86 -XF86SERVERSUBDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(AFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(SHADOWDIR) $(LAYERDIR) $(XFREE86DDXDIR) $(DEPDIRS) \ - $(MIDAMAGEDIR) -XF86INIT = $(XF86COMSRC)/xf86Init.o $(XF86COMSRC)/xf86IniExt.o -XF86COMLIB = $(XF86COMSRC)/LibraryTargetName(xf86) -XF86PARSLIB= $(XF86PARSERSRC)/LibraryTargetName(xf86config) -XF86OSLIB = $(XF86OSSRC)/LibraryTargetName(xf86_os) -#if XF86XAA -XF86XAALIB = $(XF86SRC)/xaa/LibraryTargetName(xaa) -#endif -#if XF86EXA -XF86EXALIB = $(XF86SRC)/exa/LibraryTargetName(exa) -#endif -#if XF86VgaHw -XF86VGAHWLIB = $(XF86SRC)/vgahw/LibraryTargetName(vgahw) -#endif -#if XF86FBDevHw -XF86FBDEVHWLIB = $(XF86SRC)/fbdevhw/LibraryTargetName(fbdevhw) -#endif -#if XF1Bpp || XF4Bpp -XF1BPPLIB = $(XF86SRC)/xf1bpp/LibraryTargetName(xf1bpp) -#endif -#if XF4Bpp -XF4BPPLIB = $(XF86SRC)/xf4bpp/LibraryTargetName(xf4bpp) -#endif -#if XF8_32Wid -XF8_32WIDLIB = $(XF86SRC)/xf8_32wid/LibraryTargetName(xf8_32wid) -#endif -#if XF8_32Bpp -XF8_32BPPLIB = $(XF86SRC)/xf8_32bpp/LibraryTargetName(xf8_32bpp) -#endif -#if XF8_16Bpp -XF8_16BPPLIB = $(XF86SRC)/xf8_16bpp/LibraryTargetName(xf8_16bpp) -#endif -#if XFShadowFB -XFSHADOWFBLIB = $(XF86SRC)/shadowfb/LibraryTargetName(shadowfb) -#endif -#if XF86AFB -AFBLIB = afb/LibraryTargetName(afb) -#endif -XF86DRIVERLIB = $(XF86SRC)/drivers/LibraryTargetName(driver) -#if XF86Ramdac -XF86RAMDACLIB = $(XF86SRC)/ramdac/LibraryTargetName(ramdac) -#endif -#if XF86I2C -XF86I2CLIB = $(XF86SRC)/i2c/LibraryTargetName(i2c) -#endif -#if XF86DDC -XF86DDCLIB = $(XF86SRC)/ddc/LibraryTargetName(ddc) -#endif -#if XF86VBE -XF86VBELIB = $(XF86SRC)/vbe/LibraryTargetName(vbe) -#endif -#if XF86RAC -XF86RACLIB = $(XF86SRC)/rac/LibraryTargetName(rac) -#endif -#if XF86INT10_BUILD > X86EMU_GENERIC -XF86INT10LIB = $(XF86OSSRC)/LibraryTargetName(int10) -#else -XF86INT10LIB = $(XF86SRC)/int10/LibraryTargetName(int10) -#endif -#if UseMemLeak -MEMDEBUGLIB = $(TOP)/util/memleak/LibraryTargetName(memleak) -#endif -XF86IDRIVERLIB = $(XF86SRC)/input/LibraryTargetName(idriver) -#if !DoLoadableServer -XF86DRVOBJS = $(XF86SRC)/drivers/drvConf.o -XF86DRVLIBS = $(XF86DRIVERLIB) $(XF86RAMDACLIB) $(XF86DDCLIB) $(XF86I2CLIB) \ - $(XF86XAALIB) $(XF86EXALIB) $(XF86VGAHWLIB) $(XF86FBDEVHWLIB) \ - $(XF8_32WIDLIB) $(XF8_32BPPLIB) \ - $(XF8_16BPPLIB) \ - $(XF4BPPLIB) $(XF1BPPLIB) $(XFSHADOWFBLIB) $(AFBLIB) -XF86IDRVOBJS = $(XF86SRC)/input/drvConf.o -XF86IDRVLIBS = $(XF86IDRIVERLIB) -XF86SCANLIB = $(XF86SRC)/scanpci/LibraryTargetName(scanpci) -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) $(XF86RACLIB) \ - $(XF86PARSLIB) $(XF86VBELIB) $(XF86OSLIB) $(XF86INT10LIB) -#else -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) \ - $(XF86PARSLIB) $(XF86OSLIB) -#endif -#if DoLoadableServer -XF86LOADERLIB = $(XF86SRC)/loader/LibraryTargetName(loader) -XF86MAINLIBS = PreFbLibsNoFont \ - $(FONTBASE) $(OTHEREXTS) $(XF86COMLIB) \ - NoMfbPostFbLibs -XF86SERVERSYSLIBS = $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) -#else -XF86MAINLIBS = MiExtLibs AllFBLibs $(XF86COMLIB) $(MI) -XF86SERVERSYSLIBS = $(FONTLIBS) $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) \ - $(XF86DDCLIB) -#endif -XF86SERVEROBJS = $(XF86XKBOBJS) $(XF86DRVOBJS) $(XF86IDRVOBJS) -#if HasParallelMake -MakeMutex($(XF86SERVERSUBDIRS) $(XF86SERVERLIBS) $(XF86SERVERSYSLIBS)) -#endif -#if ForceServerRemake -$(XF86SERVERLIBS) $(XF86SERVERSYSLIBS):: $(XF86SERVERSUBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -SetUIDServerTarget(XFree86,$(XF86SERVERSUBDIRS),$(XF86SERVEROBJS) $(SERVERDEFFILE), \ - $(XF86SERVERLIBS),$(XF86SERVERSYSLIBS)) -#if DoLoadableServer -ServerDriverSDKTarget(XFree86) -#endif -#ifndef ServerToInstall -#define ServerToInstall XFree86 -#endif -#endif /* XF86Server */ - -#if defined(XorgServer) && XorgServer -XCOMM -XCOMM Xorg Server -XCOMM -FBSUBDIR = fb -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -#if XF8_32Wid -CFB24SUBDIR = cfb24 -#endif -CFB32SUBDIR = cfb32 -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -LAYERDIR = miext/layer -#ifdef OS2Architecture -SERVERDEFFILE = Xorg.def -XNESTDEFFILE = Xnest.def -XVFBDEFFILE = Xvfb.def -#endif -#if XF86AFB -AFBSUBDIR = afb -#endif -XFREE86DDXDIR = hw/xfree86 -XF86SERVERSUBDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(AFBDIR) \ - $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \ - $(SHADOWDIR) $(LAYERDIR) $(XFREE86DDXDIR) $(DEPDIRS) \ - $(MIDAMAGEDIR) -XF86INIT = $(XF86COMSRC)/xf86Init.o $(XF86COMSRC)/xf86IniExt.o -XF86COMLIB = $(XF86COMSRC)/LibraryTargetName(xf86) -XF86PARSLIB= $(XF86PARSERSRC)/LibraryTargetName(xf86config) -XF86OSLIB = $(XF86OSSRC)/LibraryTargetName(xf86_os) -#if XF86XAA -XF86XAALIB = $(XF86SRC)/xaa/LibraryTargetName(xaa) -#endif -#if XF86EXA -XF86EXALIB = $(XF86SRC)/exa/LibraryTargetName(exa) -#endif -#if XF86VgaHw -XF86VGAHWLIB = $(XF86SRC)/vgahw/LibraryTargetName(vgahw) -#endif -#if XF86FBDevHw -XF86FBDEVHWLIB = $(XF86SRC)/fbdevhw/LibraryTargetName(fbdevhw) -#endif -#if XF1Bpp || XF4Bpp -XF1BPPLIB = $(XF86SRC)/xf1bpp/LibraryTargetName(xf1bpp) -#endif -#if XF4Bpp -XF4BPPLIB = $(XF86SRC)/xf4bpp/LibraryTargetName(xf4bpp) -#endif -#if XF8_32Wid -XF8_32WIDLIB = $(XF86SRC)/xf8_32wid/LibraryTargetName(xf8_32wid) -#endif -#if XF8_32Bpp -XF8_32BPPLIB = $(XF86SRC)/xf8_32bpp/LibraryTargetName(xf8_32bpp) -#endif -#if XF8_16Bpp -XF8_16BPPLIB = $(XF86SRC)/xf8_16bpp/LibraryTargetName(xf8_16bpp) -#endif -#if XFShadowFB -XFSHADOWFBLIB = $(XF86SRC)/shadowfb/LibraryTargetName(shadowfb) -#endif -#if XF86AFB -AFBLIB = afb/LibraryTargetName(afb) -#endif -XF86DRIVERLIB = $(XF86SRC)/drivers/LibraryTargetName(driver) -#if XF86Ramdac -XF86RAMDACLIB = $(XF86SRC)/ramdac/LibraryTargetName(ramdac) -#endif -#if XF86I2C -XF86I2CLIB = $(XF86SRC)/i2c/LibraryTargetName(i2c) -#endif -#if XF86DDC -XF86DDCLIB = $(XF86SRC)/ddc/LibraryTargetName(ddc) -#endif -#if XF86VBE -XF86VBELIB = $(XF86SRC)/vbe/LibraryTargetName(vbe) -#endif -#if XF86RAC -XF86RACLIB = $(XF86SRC)/rac/LibraryTargetName(rac) -#endif -#if XF86INT10_BUILD > X86EMU_GENERIC -XF86INT10LIB = $(XF86OSSRC)/LibraryTargetName(int10) -#else -XF86INT10LIB = $(XF86SRC)/int10/LibraryTargetName(int10) -#endif -#if UseMemLeak -MEMDEBUGLIB = $(TOP)/util/memleak/LibraryTargetName(memleak) -#endif -XF86IDRIVERLIB = $(XF86SRC)/input/LibraryTargetName(idriver) -#if !DoLoadableServer -XF86DRVOBJS = $(XF86SRC)/drivers/drvConf.o -XF86DRVLIBS = $(XF86DRIVERLIB) $(XF86RAMDACLIB) $(XF86DDCLIB) $(XF86I2CLIB) \ - $(XF86XAALIB) $(XF86EXALIB) $(XF86VGAHWLIB) $(XF86FBDEVHWLIB) \ - $(XF8_32WIDLIB) $(XF8_32BPPLIB) \ - $(XF8_16BPPLIB) \ - $(XF4BPPLIB) $(XF1BPPLIB) $(XFSHADOWFBLIB) $(AFBLIB) -XF86IDRVOBJS = $(XF86SRC)/input/drvConf.o -XF86IDRVLIBS = $(XF86IDRIVERLIB) -XF86SCANLIB = $(XF86SRC)/scanpci/LibraryTargetName(scanpci) -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) $(XF86RACLIB) \ - $(XF86PARSLIB) $(XF86VBELIB) $(XF86OSLIB) $(XF86INT10LIB) -#else -XF86LIBS = $(MEMDEBUGLIB) $(XF86INIT) $(XF86COMLIB) \ - $(XF86PARSLIB) $(XF86OSLIB) -#endif -#if DoLoadableServer -XF86LOADERLIB = $(XF86SRC)/loader/LibraryTargetName(loader) -XF86MAINLIBS = PreFbLibsNoFont \ - $(FONTBASE) $(OTHEREXTS) $(XF86COMLIB) \ - NoMfbPostFbLibs -XF86SERVERSYSLIBS = $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) -#else -XF86MAINLIBS = MiExtLibs AllFBLibs $(XF86COMLIB) $(MI) -XF86SERVERSYSLIBS = $(FONTLIBS) $(SYSLIBS) $(LIBDL) $(LIBREGEX) -XF86SERVERLIBS = $(XF86DRVLIBS) $(XF86IDRVLIBS) $(XF86LIBS) $(XF86LOADERLIB) \ - $(XF86COMLIB) $(XF86MAINLIBS) $(XF86SCANLIB) $(XF86OSLIB) \ - $(XF86DDCLIB) -#endif -XF86SERVEROBJS = $(XF86XKBOBJS) $(XF86DRVOBJS) $(XF86IDRVOBJS) -#if HasParallelMake -MakeMutex($(XF86SERVERSUBDIRS) $(XF86SERVERLIBS) $(XF86SERVERSYSLIBS)) -#endif -#if ForceServerRemake -$(XF86SERVERLIBS) $(XF86SERVERSYSLIBS):: $(XF86SERVERSUBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -SetUIDServerTarget(Xorg,$(XF86SERVERSUBDIRS),$(XF86SERVEROBJS) $(SERVERDEFFILE), \ - $(XF86SERVERLIBS),$(XF86SERVERSYSLIBS)) -#if DoLoadableServer -ServerDriverSDKTarget(Xorg) -#endif -#ifndef ServerToInstall -#define ServerToInstall Xorg -#endif -#endif /* XorgServer */ - -#if defined(XprtServer) && XprtServer -XCOMM -XCOMM Print Server -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB32SUBDIR = cfb32 -MIDAMAGEDIR = miext/damage -XPSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB32DIR) $(DEPDIRS) \ - $(MIDAMAGEDIR) -XPOBJS = Xprint/ddxInit.o Xprint/dpmsstubs.o Xprint/miinitext.o -#if PrintOnlyServer -XPLIBS = PreFbLibs $(XPDDXLIBS) $(XPDDXFBLIBS) PostFbLibs -#else -XPLIBS = PreFbLibs PostFbLibs -#endif -#if (defined(SunArchitecture) || defined(SparcArchitecture)) && \ - defined(SVR4Architecture) -XPSYSLIBS = $(FONTLIBS) $(CBRT) $(SYSLIBS) $(XONLYLIB) -lw -#else -XPSYSLIBS = $(FONTLIBS) $(CBRT) $(SYSLIBS) $(XONLYLIB) -#endif -#if HasParallelMake -MakeMutex($(XPSUBDIRS) $(XPOBJS) $(XPLIBS) $(XPSYSLIBS)) -#endif -#if ForceServerRemake -$(XPOBJS) $(XPLIBS) $(XPSYSLIBS):: $(XPSUBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xprt,$(XPSUBDIRS),$(XPOBJS), \ - $(LIBCWRAPPER) $(XPLIBS) $(LOADABLEEXTS),$(XPSYSLIBS)) -#endif /* XprtServer */ - -#if defined(XnestServer) && XnestServer -XCOMM -XCOMM Server with Xlib-based ddx -XCOMM -#ifndef Win32Architecture -XNESTDDXDIR = hw/xnest -#else -XNESTDDXDIR = hw -#endif -#if BuildDPMS -XNESTDPMSSTUBOBJS = $(XNESTDDXDIR)/dpmsstubs.o -#endif -XNESTDIRS = $(STDDIRS) $(XNESTDDXDIR) $(DEPDIRS) -#if !defined(LynxOSArchitecture) && \ - !defined(Win32Architecture) && \ - !defined(QNX4Architecture) -XNESTOBJS = hw/xnest/miinitext.o $(XNESTDPMSSTUBOBJS) -#else -XNESTOBJS = hw/xnest/miinitext.o dix/main.o $(XNESTDPMSSTUBOBJS) -#endif -XNEST = hw/xnest/LibraryTargetName(xnest) -XNESTLIBS = PreFbLibs $(XNEST) NoMfbPostFbLibs $(XNEST) -XNESTSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XLIB) $(SYSLIBS) -#if HasParallelMake -MakeMutex($(XNESTDIRS) $(XNESTOBJS) $(XNESTLIBS) $(XNESTSYSLIBS)) -#endif -#if ForceServerRemake -$(XNESTOBJS) $(XNESTLIBS) $(XNESTSYSLIBS):: $(XNESTDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xnest,$(XNESTDIRS),$(XNESTOBJS) $(XNESTDEFFILE), \ - $(LIBCWRAPPER) $(XNESTLIBS) $(LOADABLEEXTS),$(XNESTSYSLIBS)) -#endif /* XnestServer */ - - -#if defined(XnonServer) && XnonServer -XCOMM -XCOMM non server, just compile sources for build test -XCOMM -MFBSUBDIR = mfb -CFB8SUBDIR = cfb -CFB16SUBDIR = cfb16 -CFB32SUBDIR = cfb32 -#if HasParallelMake -MakeMutex($(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB32DIR) $(DEPDIRS)) -#endif -Xnon: $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB32DIR) $(DEPDIRS) -#endif /* XnonServer */ - - -#if defined(XVirtualFramebufferServer) && XVirtualFramebufferServer -XCOMM -XCOMM server with Virtual (malloced) framebuffer -XCOMM -MFBSUBDIR = mfb -FBSUBDIR = fb -#if defined(Win32Architecture) -XVFBDDXDIR = hw -#else -XVFBDDXDIR = hw/vfb -#endif -XVFBDIRS = $(STDDIRS) $(MFBDIR) $(FBDIR) $(XVFBDDXDIR) $(DEPDIRS) -#ifndef Win32Architecture -#if BuildDPMS -XVFBDPMSSTUBOBJS = $(XVFBDDXDIR)/dpmsstubs.o -#endif -XVFBOBJS = $(XVFBDDXDIR)/stubs.o $(XVFBDDXDIR)/miinitext.o $(XVFBDPMSSTUBOBJS) -#else -XVFBOBJS = dix/main.o hw/vfb/stubs.o hw/vfb/miinitext.o -#endif -XVFB = $(XVFBDDXDIR)/LibraryTargetName(vfb) -XVFBLIBS = PreFbLibs $(XVFB) $(FB) PostFbLibs $(MI) -XVFBSYSLIBS = $(FONTLIBS) $(SYSLIBS) -#if HasParallelMake -MakeMutex($(XVFBDIRS) $(XVFBOBJS) $(XVFB) $(XVFBLIBS) $(XVFBSYSLIBS)) -#endif -#if ForceServerRemake -$(XVFBOBJS) $(XVFB) $(XVFBLIBS) $(XVFBSYSLIBS):: $(XVFBDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xvfb,$(XVFBDIRS),$(XVFBOBJS) $(XVFBDEFFILE), \ - $(LIBCWRAPPER) $(XVFBLIBS) $(LOADABLEEXTS),$(XVFBSYSLIBS)) -#endif /* XVirtualFramebufferServer */ - -#if defined(XdmxServer) && XdmxServer -XCOMM -XCOMM distribued multihead Server -XCOMM -#ifndef Win32Architecture -XDMXDDXDIR = hw/dmx -#else -XDMXDDXDIR = hw -#endif -FBDIR = fb -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -XDMXDIRS = $(STDDIRS) $(XDMXDDXDIR) $(SHADOWDIR) $(DEPDIRS) $(FBDIR) $(MIDAMAGEDIR) -#if BuildGlxExt -#if BuildXinerama -GLXPROXY_EXTRAOBJS = hw/dmx/panoramiX.o -#endif -GLXPROXYLIB = hw/dmx/glxProxy/LibraryTargetName(glxProxy) -#endif -#if !defined(LynxOSArchitecture) && \ - !defined(Win32Architecture) && \ - !defined(QNX4Architecture) -XDMXOBJS = hw/dmx/miinitext.o $(GLXPROXY_EXTRAOBJS) -#else -XDMXOBJS = hw/dmx/miinitext.o $(GLXPROXY_EXTRAOBJS) dix/main.o -#endif -XDMX = hw/dmx/LibraryTargetName(dmx) \ - hw/dmx/input/LibraryTargetName(dmxinput) \ - hw/dmx/config/LibraryTargetName(dmxconfig) \ - $(GLXPROXYLIB) -XDMXLIBS = PreFbLibs $(XDMX) MiExtLibs FbPostFbLibs $(XDMX) -#if BuildRender -XDMXRENDERLIB = $(XRENDERLIB) -#endif -XDMXSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XILIB) $(XLIB) $(SYSLIBS) $(XMULIB) $(XDMXRENDERLIB) -#if HasParallelMake -MakeMutex($(XDMXDIRS) $(XDMXOBJS) $(XDMXLIBS) $(XDMXSYSLIBS)) -#endif -#if ForceServerRemake -$(XDMXOBJS) $(XDMXLIBS) $(XDMXSYSLIBS):: $(XDMXDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif -ServerTarget(Xdmx,$(XDMXDIRS),$(XDMXOBJS), \ - $(LIBCWRAPPER) $(XDMXLIBS) $(LOADABLEEXTS),$(XDMXSYSLIBS)) -#endif /* XdmxServer */ - -#if defined(XWinServer) && XWinServer -XCOMM -XCOMM X Server for MS Windows -XCOMM -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -#if BuildXWinLayer -LAYERDIR = miext/layer -XWINLAYERLIB = $(LAYER) -#else -LAYERDIR = -XWINLAYERLIB = -#endif -#if BuildXWinMultiWindowExtWM -ROOTLESSDIR = miext/rootless -ROOTLESSLIB = $(ROOTLESSDIR)/LibraryTargetName(rootless) \ - $(ROOTLESSDIR)/safeAlpha/LibraryTargetName(safeAlpha) \ - $(ROOTLESSDIR)/accel/LibraryTargetName(rlAccel) -#else -ROOTLESSDIR = -ROOTLESSLIB = -#endif -XWINDDXDIR = hw/xwin -#if BuildXWinXF86Config -XWINPARSERDIR = hw/xfree86/parser -XWINPARSERLIB = $(XWINPARSERDIR)/LibraryTargetName(xf86config) -#else -XWINPARSERDIR = -XWINPARSERLIB = -#endif -#if defined(GlxUseWindows) && GlxUseWindows -XWINOPENGLLIB = -lopengl32 -#else -XWINOPENGLLIB = -#endif - -XWINLIB = $(XWINDDXDIR)/LibraryTargetName(XWin) -XWINDIRS = $(STDDIRS) $(FBDIR) $(SHADOWDIR) $(LAYERDIR) $(XWINDDXDIR) \ - $(DEPDIRS) $(XWINPARSERDIR) $(ROOTLESSDIR) $(MIDAMAGEDIR) -XWINOBJS = $(XWINDDXDIR)/stubs.o $(XWINDDXDIR)/XWin.res -XWINLIBS = PreFbLibs $(XWINLIB) FbPostFbLibs $(XWINLIB) $(XWINLAYERLIB) \ - $(SHADOW) $(XWINPARSERLIB) $(ROOTLESSLIB) $(OS) -#if BuildXWinMultiWindow || BuildXWinClipboard -XWINX11 = $(XONLYLIB) -# if defined(Win32Architecture) -PTHREADLIB = -lpthreadGC2 -# endif -#endif -#if defined(Win32Architecture) -# if defined(GlxUseWindows) && GlxUseWindows -XWINGL32 = -lopengl32 -# endif -XWINW32 = -lgdi32 -lwsock32 $(XWINGL32) $(PTHREADLIB) -#else -XWINW32 = -lgdi32 -#endif -XWINSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XWINX11) $(SYSLIBS) $(XWINW32) - -EXTRA_LDOPTIONS = -e _mainCRTStartup - -#if HasParallelMake -MakeMutex($(XWINDIRS) $(XWINOBJS) $(XWINLIB) $(XWINLIBS) $(XWINSYSLIBS)) -#endif - -#if ForceServerRemake -$(XWINOBJS) $(XWINLIB) $(XWINLIBS) $(XWINSYSLIBS):: $(XWINDIRS) - @if [ -f $@ ]; then touch $@ >/dev/null 2>&1 || exit 0; fi -#endif - -#ifdef mingwArchitecture -XWINSERVERNAME=Xming -XWINGLSERVERNAME=XmingGL -#else -XWINSERVERNAME=XWin -XWINGLSERVERNAME=XWin_GL -#endif -ServerTarget($(XWINSERVERNAME),$(XWINDIRS),$(XWINOBJS), \ - $(LIBCWRAPPER) $(XWINLIBS) $(LOADABLEEXTS),$(XWINSYSLIBS)) -#if defined(cygwinArchitecture) && defined(GlxUseWindows) && GlxUseWindows -ServerTarget($(XWINGLSERVERNAME),$(XWINDIRS),$(XWINOBJS), \ - $(LIBCWRAPPER) $(XWINLIBS) $(LOADABLEEXTS),$(XWINSYSLIBS) \ - $(XWINOPENGLLIB)) -#endif - -#ifndef ServerToInstall -# define ServerToInstall $(XWINSERVERNAME) -#endif - -#endif /* XWinServer */ - - -#ifdef DarwinArchitecture -/* - * To allow building even when building the client-side libraries is turned - * off, libraries in ProjectRoot are listed as dependencies for some targets. - * This causes problems unless we tell make where to find these dependencies. - */ -VPATH = $(BUILDLIBDIR):$(USRLIBDIR) -#endif - -#if defined(XDarwinServer) && XDarwinServer -XCOMM -XCOMM X Darwin server for Mac OS X / Darwin -XCOMM -FBSUBDIR = fb -MIDAMAGEDIR = miext/damage -SHADOWDIR = miext/shadow -ROOTLESSDIR = miext/rootless -DARWINDDXDIR = hw/darwin -DARWINDIRS = $(STDDIRS) $(FBDIR) $(SHADOWDIR) $(DARWINDDXDIR) $(DEPDIRS) -DARWINOBJS = $(DARWINDDXDIR)/miinitext.o -DARWINLIBS = PreFbLibs $(DARWINDDXDIR)/LibraryTargetName(darwin) -DARWINEXTLIBS = MiExtLibs FbPostFbLibs $(DARWINDDXDIR)/LibraryTargetName(darwin) -DARWINSYSLIBS = $(FONTLIBS) $(SYSLIBS) -framework IOKit -IOKITLIB = $(DARWINDDXDIR)/iokit/LibraryTargetName(iokit) - -/* - * IOKit X server - */ -SetUIDServerTarget(XDarwin,$(DARWINDIRS),$(DARWINOBJS), \ - $(DARWINLIBS) $(IOKITLIB) $(DARWINEXTLIBS),$(DARWINSYSLIBS)) - -#if DarwinQuartzSupport - -QUARTZDIR = $(DARWINDDXDIR)/quartz -QUARTZLIB = $(QUARTZDIR)/LibraryTargetName(XQuartz) -QUARTZSYSLIBS = -framework ApplicationServices -framework Cocoa \ - -framework CoreAudio -framework Carbon -ObjC -ROOTLESSLIB = $(ROOTLESSDIR)/LibraryTargetName(rootless) \ - $(ROOTLESSDIR)/safeAlpha/LibraryTargetName(safeAlpha) \ - $(ROOTLESSDIR)/accel/LibraryTargetName(rlAccel) -XPLUGINLIB = XpluginLibrary - -#if NothingOutsideProjectRoot -XDARWINAPPDIR = $(BINDIR)/XDarwin.app/Contents -#else -XDARWINAPPDIR = /Applications/XDarwin.app/Contents -#endif - -/* - * Quartz X server (installed in its application bundle) - */ -SetUIDServerTarget(XDarwinApp,$(DARWINDIRS),$(DARWINOBJS), \ - $(DARWINLIBS) $(QUARTZLIB) $(DARWINEXTLIBS), \ - $(DARWINSYSLIBS) $(QUARTZSYSLIBS) -u _miDCInitialize) - -install:: - $(MKDIRHIER) $(DESTDIR)$(XDARWINAPPDIR)/MacOS - $(MV) $(DESTDIR)$(BINDIR)/XDarwinApp \ - $(DESTDIR)$(XDARWINAPPDIR)/MacOS/XDarwin - -(cd $(DESTDIR)$(BINDIR); $(RM) XDarwinQuartz; \ - $(LN) $(XDARWINAPPDIR)/MacOS/XDarwin XDarwinQuartz) - -/* - * Display mode bundles for Quartz - * (installed in their own bundles inside XDarwin's) - */ -#if HasXplugin -XPRDIRS = $(QUARTZDIR)/xpr $(ROOTLESSDIR) $(ROOTLESSDIR)/safeAlpha -XPRLIBS = $(QUARTZDIR)/xpr/LibraryTargetName(xpr) $(ROOTLESSLIB) - -BundleProgramTarget(xpr,XDarwinApp,$(XPRDIRS),$(QUARTZDIR)/xpr/xprScreen.o, \ - $(XPRLIBS),-framework ApplicationServices \ - $(XPLUGINLIB),$(XDARWINAPPDIR)/Resources) -#endif - -CRDIRS = $(QUARTZDIR)/cr $(ROOTLESSDIR) $(ROOTLESSDIR)/safeAlpha -CRLIBS = $(QUARTZDIR)/cr/LibraryTargetName(cr) $(ROOTLESSLIB) - -BundleProgramTarget(cr,XDarwinApp,$(CRDIRS),$(QUARTZDIR)/cr/crScreen.o, \ - $(CRLIBS),-framework ApplicationServices -framework Cocoa \ - -framework Carbon -ObjC,$(XDARWINAPPDIR)/Resources) - -FSDIRS = $(QUARTZDIR)/fullscreen $(SHADOWDIR) -FSLIBS = $(QUARTZDIR)/fullscreen/LibraryTargetName(fullscreen) $(SHADOW) - -BundleProgramTarget(fullscreen,XDarwinApp,$(FSDIRS), \ - $(QUARTZDIR)/fullscreen/fullscreen.o,$(FSLIBS), \ - -framework ApplicationServices,$(XDARWINAPPDIR)/Resources) - -/* - * GLX bundles for Quartz - * (installed in their own bundles inside XDarwin's) - */ -BundleProgramTarget(glxAGL,XDarwinApp,GL,GL/glx/glxext.o,GL/glx/libglx.a \ - GL/apple/libAGLcore.a, \ - -framework AGL -framework OpenGL,$(XDARWINAPPDIR)/Resources) - -#if BuildAppleDRI -BundleProgramTarget(glxCGL,XDarwinApp,GL,GL/glx/glxext.o,GL/glx/libglx.a \ - GL/apple/libCGLcore.a, \ - -framework OpenGL $(XPLUGINLIB),$(XDARWINAPPDIR)/Resources) -#endif - -BundleProgramTarget(glxMesa,XDarwinApp,GL,GL/glx/glxext.o,GL/glx/libglx.a \ - GL/mesa/GLcore/libGLcore.a,NullParameter,$(XDARWINAPPDIR)/Resources) - -#else /* !DarwinQuartzSupport */ - -#define ServerToInstall XDarwin - -#endif /* DarwinQuartzSupport */ - -#endif /* XDarwinServer */ - - -CFBSUBDIRS = $(CFB8SUBDIR) $(CFB16SUBDIR) $(CFB24SUBDIR) $(CFB32SUBDIR) -MIEXTDIRS = $(SHADOWDIR) $(LAYERDIR) $(ROOTLESSDIR) $(MIDAMAGEDIR) -IPLANDIRS = $(IPLAN2P2DIR) $(IPLAN2P4DIR) $(IPLAN2P8DIR) -DDXDIRS = $(DECWSDDXDIR) $(SUNDDXDIR) $(LYNXDDXDIR) \ - $(HPDDXDIR) $(XFREE86DDXDIR) $(XWINDDXDIR) $(DARWINDDXDIR) \ - $(XVFBDDXDIR) $(XNESTDDXDIR) $(XDMXDDXDIR) -SUBDIRS = $(STDDIRS) $(MFBSUBDIR) $(CFBSUBDIRS) \ - $(IPLANDIRS) $(ILBMDIR) $(AFBSUBDIR) \ - $(DDXDIRS) $(FBSUBDIR) $(KDRIVEDIRS) $(MIEXTDIRS) - -#if defined(ServerToInstall) && !defined(OS2Architecture) -install:: - -(cd $(DESTDIR)$(BINDIR); $(RM) X; $(LN) ServerToInstall X) -#endif - -#define IHaveSubdirs - -DependSubdirs($(SUBDIRS)) -MakeLintLibSubdirs($(SUBDIRS)) -LintSubdirs($(SUBDIRS)) - -ForceSubdirs($(DEPDIRS) $(SUBDIRS)) - -DEFAULTFONTPATH = DefaultFontPath -EXTRAMANDEFS = -D__default_font_path__="`echo $(DEFAULTFONTPATH) | sed -e 's/,/, /g'`" - -InstallManPage(Xserver,$(MANDIR)) - -#if MakeDllModules && DoLoadableServer && \ - (defined(SunArchitecture) && defined(SVR4Architecture)) -XCOMM Hackery for building dlopen-able .so modules on Solaris - -AllTarget(linker-deps) - -LINKER_DEPS_DIRS = $(SUBDIRS) $(FONTLIBSRC) - -XCOMM After everything is built, run through and generate linker dependencies -linker-deps: - RunPerlScript($(XF86SRC)/os-support/sunos/find_deps.pl,-R ProjectRoot $(LINKER_DEPS_DIRS)) - for i in $(LINKER_DEPS_DIRS) ; do \ - echo "relinking with dependency flags in $(CURRENT_DIR)/$$i..."; \ - MakeNamedTargetSubdir($$i,NullParameter,all) ; \ - done -#endif diff --git a/nx-X11/programs/Xserver/Xext/Imakefile.NX.original b/nx-X11/programs/Xserver/Xext/Imakefile.NX.original deleted file mode 100644 index b75f8913b..000000000 --- a/nx-X11/programs/Xserver/Xext/Imakefile.NX.original +++ /dev/null @@ -1,226 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/Xext/Imakefile,v 1.9 2005/04/24 01:10:12 gisburn Exp $ */ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:47:55 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/Xext/Imakefile,v 3.43 2003/04/21 18:56:48 sven Exp $ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#include - -#if DoLoadableServer -#define IHaveSubdirs -SUBDIRS = extmod -#endif - -#if BuildEVI -#ifdef SGIArchitectureNotTog - EVISRCS = EVI.c sgiEVI.c - EVIOBJS = EVI.o sgiEVI.o -#else - EVISRCS = EVI.c sampleEVI.c - EVIOBJS = EVI.o sampleEVI.o -#endif -#endif -#if HasShm - SHMSRCS = shm.c - SHMOBJS = shm.o -#endif - -#if BuildMultibuffer - MULTIBUFSRC = mbuf.c - MULTIBUFOBJ = mbuf.o -#endif - -#if BuildScreenSaverExt - SCRNSAVSRC = saver.c - SCRNSAVOBJ = saver.o -#endif - -#if BuildXF86VidModeExt && \ - ((defined(XF86Server) && XF86Server) || \ - (defined(XorgServer) && XorgServer)) - VIDMODESRCS = xf86vmode.c - VIDMODEOBJS = xf86vmode.o -#endif - -#if BuildXF86MiscExt && \ - ((defined(XF86Server) && XF86Server) || \ - (defined(XorgServer) && XorgServer)) -XF86MISCSRCS = xf86misc.c -XF86MISCOBJS = xf86misc.o -#endif - -#if BuildXF86BigfontExt -XF86BIGFSRCS = xf86bigfont.c -XF86BIGFOBJS = xf86bigfont.o -#if HasShm - SHM_DEFINES = -DHAS_SHM -#endif -#endif - -#if BuildXF86DGA - XF86DGASRCS = xf86dga.c xf86dga2.c - XF86DGAOBJS = xf86dga.o xf86dga2.o -#if HasShm - XVMCSHM_DEFINES = -DHAS_XVMCSHM -#endif -#endif - -#if BuildXvExt - XVSRCS = xvmain.c xvdisp.c xvmc.c - XVOBJS = xvmain.o xvdisp.o xvmc.o -#endif - -#if BuildXResExt - XRESSRCS = xres.c - XRESOBJS = xres.o -#endif - -#if BuildAppgroup - APPGROUPSRCS = appgroup.c - APPGROUPOBJS = appgroup.o -#endif -#if BuildXCSecurity - SECURITYSRCS = security.c - SECURITYOBJS = security.o - SERVERCONFIGDIR = ServerConfigDir - POLICYFILEDEF = -DDEFAULTPOLICYFILE=\"$(SERVERCONFIGDIR)/SecurityPolicy\" -#endif -#if BuildCup - CUPSRCS = cup.c - CUPOBJS = cup.o -#endif -#if BuildXinerama - PNRXSRCS = panoramiX.c panoramiXSwap.c panoramiXprocs.c - PNRXOBJS = panoramiX.o panoramiXSwap.o panoramiXprocs.o - PNRXINCLUDES = -I$(FONTINCSRC) -I../mi -I../render -#endif -#if XdmxServer - DMXSRCS = dmx.c - DMXOBJS = dmx.o - DMXINCLUDES = -I../hw/dmx -#endif -#if BuildDPMS - DPMSSRCS = dpms.c - DPMSOBJS = dpms.o -#endif - -#if BuildFontCache - FONTCACHESRCS = fontcache.c - FONTCACHEOBJS = fontcache.o -#if 0 - FONTCACHEINCLUDES = -I$(XF86SRC)/os-support -#endif -#endif - -#if BuildXevie - XEVIESRCS = xevie.c - XEVIEOBJS = xevie.o -#endif - -#if BuildXprint - XPRINTSRCS = xprint.c - XPRINTOBJS = xprint.o -#endif - - SRCS = shape.c $(SHMSRCS) $(MULTIBUFSRC) \ - mitmisc.c xtest.c xtest1di.c xtest1dd.c sleepuntil.c \ - bigreq.c sync.c $(SCRNSAVSRC) xcmisc.c $(VIDMODESRCS) \ - $(XF86MISCSRCS) $(XF86BIGFSRCS) $(XF86DGASRCS) $(SECURITYSRCS) \ - $(APPGROUPSRCS) $(XPRINTSRCS) $(CUPSRCS) $(PNRXSRCS) $(DPMSSRCS) \ - $(XEVIESRCS) \ - $(EVISRCS) $(XVSRCS) $(FONTCACHESRCS) $(XRESSRCS) $(DMXSRCS) - - OBJS = shape.o $(SHMOBJS) $(MULTIBUFOBJ) \ - mitmisc.o xtest.o xtest1di.o xtest1dd.o sleepuntil.o \ - bigreq.o sync.o $(SCRNSAVOBJ) xcmisc.o $(VIDMODEOBJS) \ - $(XF86MISCOBJS) $(XF86BIGFOBJS) $(XF86DGAOBJS) $(SECURITYOBJS) \ - $(APPGROUPOBJS) $(XPRINTOBJS) $(CUPOBJS) $(PNRXOBJS) $(DPMSOBJS) \ - $(XEVIEOBJS) \ - $(EVIOBJS) $(XVOBJS) $(FONTCACHEOBJS) $(XRESOBJS) $(DMXOBJS) - - SOBJS = $(SHMOBJS) $(APPGROUPOBJS) $(SECURITYOBJS) $(XPRINTOBJS) \ - shape.o xtest.o xtest1di.o xtest1dd.o sleepuntil.o $(PNRXOBJS) \ - $(XEVIEOBJS) \ - $(XF86BIGFOBJS) - -#if defined(NXAgentServer) && NXAgentServer -NX_DEFINES = -DNXAGENT_SERVER -#endif - - -#if (defined(XFree86Version) || defined(XorgVersion)) -/* XXX Check if this can be eliminated */ -XF86INCLUDES = -I$(XF86COMSRC) -#endif - INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \ - $(PNRXINCLUDES) $(XF86INCLUDES) -I$(FONTINCSRC) \ - $(FONTCACHEINCLUDES) $(DMXINCLUDES) - LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln - -#if defined(NXAgentServer) && NXAgentServer - DEFINES = $(EXT_DEFINES) $(XVMCSHM_DEFINES) $(NX_DEFINES) -#else - DEFINES = $(EXT_DEFINES) $(XVMCSHM_DEFINES) -#endif - -NormalLibraryObjectRule() - -/* - * A hack to work around an optimization problem with gcc 2.95.2 - */ -#if BuildXF86VidModeExt && defined(GccOptBug295) -SpecialCObjectRule(xf86vmode,NullParameter,-O0) -#endif - -NormalLibraryTarget(ext,$(OBJS)) -LintLibraryTarget(ext,$(SRCS)) -NormalLintTarget($(SRCS)) - -#if DoLoadableServer -NormalLibraryTarget(exts,$(SOBJS)) -#endif - -#if BuildXF86BigfontExt -SpecialCObjectRule(xf86bigfont,$(ICONFIGFILES),$(SHM_DEFINES)) -#endif -#if BuildXCSecurity -SpecialCObjectRule(security,$(ICONFIGFILES),$(POLICYFILEDEF)) -#endif - -LinkConfDirectory(xserver,.,xserver,.) - -LinkSourceFile(modinit.h,extmod) - -#if BuildXCSecurity && InstallSecurityConfig -InstallNonExecFile(SecurityPolicy,$(SERVERCONFIGDIR)) -#endif - -DependTarget() - -#if DoLoadableServer -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - -InstallDriverSDKNonExecFile(dgaproc.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(xvdix.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(xvmcext.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/Xext/Imakefile.X.original b/nx-X11/programs/Xserver/Xext/Imakefile.X.original deleted file mode 100644 index f2753b3f4..000000000 --- a/nx-X11/programs/Xserver/Xext/Imakefile.X.original +++ /dev/null @@ -1,200 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/Xext/Imakefile,v 1.9 2005/04/24 01:10:12 gisburn Exp $ */ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:47:55 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/Xext/Imakefile,v 3.43 2003/04/21 18:56:48 sven Exp $ - -#include - -#if DoLoadableServer -#define IHaveSubdirs -SUBDIRS = extmod -#endif - -#if BuildEVI -#ifdef SGIArchitectureNotTog - EVISRCS = EVI.c sgiEVI.c - EVIOBJS = EVI.o sgiEVI.o -#else - EVISRCS = EVI.c sampleEVI.c - EVIOBJS = EVI.o sampleEVI.o -#endif -#endif -#if HasShm - SHMSRCS = shm.c - SHMOBJS = shm.o -#endif - -#if BuildMultibuffer - MULTIBUFSRC = mbuf.c - MULTIBUFOBJ = mbuf.o -#endif - -#if BuildScreenSaverExt - SCRNSAVSRC = saver.c - SCRNSAVOBJ = saver.o -#endif - -#if BuildXF86VidModeExt && \ - ((defined(XF86Server) && XF86Server) || \ - (defined(XorgServer) && XorgServer)) - VIDMODESRCS = xf86vmode.c - VIDMODEOBJS = xf86vmode.o -#endif - -#if BuildXF86MiscExt && \ - ((defined(XF86Server) && XF86Server) || \ - (defined(XorgServer) && XorgServer)) -XF86MISCSRCS = xf86misc.c -XF86MISCOBJS = xf86misc.o -#endif - -#if BuildXF86BigfontExt -XF86BIGFSRCS = xf86bigfont.c -XF86BIGFOBJS = xf86bigfont.o -#if HasShm - SHM_DEFINES = -DHAS_SHM -#endif -#endif - -#if BuildXF86DGA - XF86DGASRCS = xf86dga.c xf86dga2.c - XF86DGAOBJS = xf86dga.o xf86dga2.o -#if HasShm - XVMCSHM_DEFINES = -DHAS_XVMCSHM -#endif -#endif - -#if BuildXvExt - XVSRCS = xvmain.c xvdisp.c xvmc.c - XVOBJS = xvmain.o xvdisp.o xvmc.o -#endif - -#if BuildXResExt - XRESSRCS = xres.c - XRESOBJS = xres.o -#endif - -#if BuildAppgroup - APPGROUPSRCS = appgroup.c - APPGROUPOBJS = appgroup.o -#endif -#if BuildXCSecurity - SECURITYSRCS = security.c - SECURITYOBJS = security.o - SERVERCONFIGDIR = ServerConfigDir - POLICYFILEDEF = -DDEFAULTPOLICYFILE=\"$(SERVERCONFIGDIR)/SecurityPolicy\" -#endif -#if BuildCup - CUPSRCS = cup.c - CUPOBJS = cup.o -#endif -#if BuildXinerama - PNRXSRCS = panoramiX.c panoramiXSwap.c panoramiXprocs.c - PNRXOBJS = panoramiX.o panoramiXSwap.o panoramiXprocs.o - PNRXINCLUDES = -I$(FONTINCSRC) -I../mi -I../render -#endif -#if XdmxServer - DMXSRCS = dmx.c - DMXOBJS = dmx.o - DMXINCLUDES = -I../hw/dmx -#endif -#if BuildDPMS - DPMSSRCS = dpms.c - DPMSOBJS = dpms.o -#endif - -#if BuildFontCache - FONTCACHESRCS = fontcache.c - FONTCACHEOBJS = fontcache.o -#if 0 - FONTCACHEINCLUDES = -I$(XF86SRC)/os-support -#endif -#endif - -#if BuildXevie - XEVIESRCS = xevie.c - XEVIEOBJS = xevie.o -#endif - -#if BuildXprint - XPRINTSRCS = xprint.c - XPRINTOBJS = xprint.o -#endif - - SRCS = shape.c $(SHMSRCS) $(MULTIBUFSRC) \ - mitmisc.c xtest.c xtest1di.c xtest1dd.c sleepuntil.c \ - bigreq.c sync.c $(SCRNSAVSRC) xcmisc.c $(VIDMODESRCS) \ - $(XF86MISCSRCS) $(XF86BIGFSRCS) $(XF86DGASRCS) $(SECURITYSRCS) \ - $(APPGROUPSRCS) $(XPRINTSRCS) $(CUPSRCS) $(PNRXSRCS) $(DPMSSRCS) \ - $(XEVIESRCS) \ - $(EVISRCS) $(XVSRCS) $(FONTCACHESRCS) $(XRESSRCS) $(DMXSRCS) - - OBJS = shape.o $(SHMOBJS) $(MULTIBUFOBJ) \ - mitmisc.o xtest.o xtest1di.o xtest1dd.o sleepuntil.o \ - bigreq.o sync.o $(SCRNSAVOBJ) xcmisc.o $(VIDMODEOBJS) \ - $(XF86MISCOBJS) $(XF86BIGFOBJS) $(XF86DGAOBJS) $(SECURITYOBJS) \ - $(APPGROUPOBJS) $(XPRINTOBJS) $(CUPOBJS) $(PNRXOBJS) $(DPMSOBJS) \ - $(XEVIEOBJS) \ - $(EVIOBJS) $(XVOBJS) $(FONTCACHEOBJS) $(XRESOBJS) $(DMXOBJS) - - SOBJS = $(SHMOBJS) $(APPGROUPOBJS) $(SECURITYOBJS) $(XPRINTOBJS) \ - shape.o xtest.o xtest1di.o xtest1dd.o sleepuntil.o $(PNRXOBJS) \ - $(XEVIEOBJS) \ - $(XF86BIGFOBJS) - -#if (defined(XFree86Version) || defined(XorgVersion)) -/* XXX Check if this can be eliminated */ -XF86INCLUDES = -I$(XF86COMSRC) -#endif - INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \ - $(PNRXINCLUDES) $(XF86INCLUDES) -I$(FONTINCSRC) \ - $(FONTCACHEINCLUDES) $(DMXINCLUDES) - LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln - - DEFINES = $(EXT_DEFINES) $(XVMCSHM_DEFINES) - -NormalLibraryObjectRule() - -/* - * A hack to work around an optimization problem with gcc 2.95.2 - */ -#if BuildXF86VidModeExt && defined(GccOptBug295) -SpecialCObjectRule(xf86vmode,NullParameter,-O0) -#endif - -NormalLibraryTarget(ext,$(OBJS)) -LintLibraryTarget(ext,$(SRCS)) -NormalLintTarget($(SRCS)) - -#if DoLoadableServer -NormalLibraryTarget(exts,$(SOBJS)) -#endif - -#if BuildXF86BigfontExt -SpecialCObjectRule(xf86bigfont,$(ICONFIGFILES),$(SHM_DEFINES)) -#endif -#if BuildXCSecurity -SpecialCObjectRule(security,$(ICONFIGFILES),$(POLICYFILEDEF)) -#endif - -LinkConfDirectory(xserver,.,xserver,.) - -LinkSourceFile(modinit.h,extmod) - -#if BuildXCSecurity && InstallSecurityConfig -InstallNonExecFile(SecurityPolicy,$(SERVERCONFIGDIR)) -#endif - -DependTarget() - -#if DoLoadableServer -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - -InstallDriverSDKNonExecFile(dgaproc.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(xvdix.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(xvmcext.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/Xext/security.c.NX.original b/nx-X11/programs/Xserver/Xext/security.c.NX.original deleted file mode 100644 index 2139425b4..000000000 --- a/nx-X11/programs/Xserver/Xext/security.c.NX.original +++ /dev/null @@ -1,2245 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/Xext/security.c,v 1.5 2005/07/03 07:01:04 daniels Exp $ */ -/* $Xorg: security.c,v 1.4 2001/02/09 02:04:32 xorgcvs Exp $ */ -/* - -Copyright 1996, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -*/ -/* $XFree86: xc/programs/Xserver/Xext/security.c,v 1.16tsi Exp $ */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "dixstruct.h" -#include "extnsionst.h" -#include "windowstr.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "colormapst.h" -#include "propertyst.h" -#define _SECURITY_SERVER -#include -#include -#include -#ifdef LBX -#define _XLBX_SERVER_ -#include -extern unsigned char LbxReqCode; -#endif -#ifdef XAPPGROUP -#include -#endif -#include /* for file reading operations */ -#include /* for XA_STRING */ - -#ifdef NXAGENT_SERVER - -#include -#include -#include -#include - -#endif - -#ifndef DEFAULTPOLICYFILE -# define DEFAULTPOLICYFILE NULL -#endif - -#ifdef NXAGENT_SERVER - -#define NX_ALTERNATIVEPOLICYFILE "/usr/lib/xserver/SecurityPolicy" - -#endif - -#if defined(WIN32) || defined(__CYGWIN__) -#include -#undef index -#endif - -/* - * Set here the required NX log level. - */ - -#ifdef NXAGENT_SERVER - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -#endif - -#ifdef NXAGENT_SERVER - -static char _NXPolicyFilePath[1024]; - -#endif - -#include "modinit.h" - -static int SecurityErrorBase; /* first Security error number */ -static int SecurityEventBase; /* first Security event number */ - -CallbackListPtr SecurityValidateGroupCallback = NULL; /* see security.h */ - -RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */ - -static RESTYPE RTEventClient; - -/* Proc vectors for untrusted clients, swapped and unswapped versions. - * These are the same as the normal proc vectors except that extensions - * that haven't declared themselves secure will have ProcBadRequest plugged - * in for their major opcode dispatcher. This prevents untrusted clients - * from guessing extension major opcodes and using the extension even though - * the extension can't be listed or queried. - */ -int (*UntrustedProcVector[256])( - ClientPtr /*client*/ -); -int (*SwappedUntrustedProcVector[256])( - ClientPtr /*client*/ -); - -#ifdef NXAGENT_SERVER - -/* - * This function returns the SecurityPolicy - * file full path. This path is referred by - * SecurityPolicyFile variable (generally it - * contains the hardcoded path at compile time). - * If the path does not exist, the function will - * try a set of well known paths. - */ - -const char *_NXGetPolicyFilePath(const char *path) -{ - - struct stat SecurityPolicyStat; - - /* - * Check the policy file path only once. - */ - - if (*_NXPolicyFilePath != '\0') - { - return _NXPolicyFilePath; - } - - if (stat(path, &SecurityPolicyStat) == 0) - { - if (strlen(path) + 1 > 1024) - { - #ifdef WARNING - fprintf(stderr, "_NXGetPolicyFilePath: WARNING! Maximum length of SecurityPolicy file path exceeded.\n"); - #endif - - goto _NXGetPolicyFilePathError; - } - - strcpy(_NXPolicyFilePath, path); - - #ifdef TEST - fprintf(stderr, "_NXGetPolicyFilePath: Using SecurityPolicy file path [%s].\n", - _NXPolicyFilePath); - #endif - - return _NXPolicyFilePath; - } - - if (stat(DEFAULTPOLICYFILE, &SecurityPolicyStat) == 0) - { - if (strlen(DEFAULTPOLICYFILE) + 1 > 1024) - { - #ifdef WARNING - fprintf(stderr, "_NXGetPolicyFilePath: WARNING! Maximum length of SecurityPolicy file path exceeded.\n"); - #endif - - goto _NXGetPolicyFilePathError; - } - - strcpy(_NXPolicyFilePath, DEFAULTPOLICYFILE); - - #ifdef TEST - fprintf(stderr, "_NXGetPolicyFilePath: Using SecurityPolicy file path [%s].\n", - _NXPolicyFilePath); - #endif - - return _NXPolicyFilePath; - } - - if (stat(NX_ALTERNATIVEPOLICYFILE, &SecurityPolicyStat) == 0) - { - if (strlen(NX_ALTERNATIVEPOLICYFILE) + 1 > 1024) - { - #ifdef WARNING - fprintf(stderr, "_NXGetPolicyFilePath: WARNING! Maximum length of SecurityPolicy file path exceeded.\n"); - #endif - - goto _NXGetPolicyFilePathError; - } - - strcpy(_NXPolicyFilePath, NX_ALTERNATIVEPOLICYFILE); - - #ifdef TEST - fprintf(stderr, "_NXGetPolicyFilePath: Using SecurityPolicy file path [%s].\n", - _NXPolicyFilePath); - #endif - - return _NXPolicyFilePath; - } - -_NXGetPolicyFilePathError: - - if (strlen(path) + 1 > 1024) - { - #ifdef WARNING - fprintf(stderr, "_NXGetPolicyFilePath: WARNING! Maximum length of SecurityPolicy file exceeded.\n"); - #endif - } - - strcpy(_NXPolicyFilePath, path); - - #ifdef TEST - fprintf(stderr, "_NXGetPolicyFilePath: Using default SecurityPolicy file path [%s].\n", - _NXPolicyFilePath); - #endif - - return _NXPolicyFilePath; -} - -#endif - -/* SecurityAudit - * - * Arguments: - * format is the formatting string to be used to interpret the - * remaining arguments. - * - * Returns: nothing. - * - * Side Effects: - * Writes the message to the log file if security logging is on. - */ - -void -SecurityAudit(char *format, ...) -{ - va_list args; - - if (auditTrailLevel < SECURITY_AUDIT_LEVEL) - return; - va_start(args, format); - VAuditF(format, args); - va_end(args); -} /* SecurityAudit */ - -#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) - -/* SecurityDeleteAuthorization - * - * Arguments: - * value is the authorization to delete. - * id is its resource ID. - * - * Returns: Success. - * - * Side Effects: - * Frees everything associated with the authorization. - */ - -static int -SecurityDeleteAuthorization( - pointer value, - XID id) -{ - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value; - unsigned short name_len, data_len; - char *name, *data; - int status; - int i; - OtherClientsPtr pEventClient; - - /* Remove the auth using the os layer auth manager */ - - status = AuthorizationFromID(pAuth->id, &name_len, &name, - &data_len, &data); - assert(status); - status = RemoveAuthorization(name_len, name, data_len, data); - assert(status); - (void)status; - - /* free the auth timer if there is one */ - - if (pAuth->timer) TimerFree(pAuth->timer); - - /* send revoke events */ - - while ((pEventClient = pAuth->eventClients)) - { - /* send revocation event event */ - ClientPtr client = rClient(pEventClient); - - if (!client->clientGone) - { - xSecurityAuthorizationRevokedEvent are; - are.type = SecurityEventBase + XSecurityAuthorizationRevoked; - are.sequenceNumber = client->sequence; - are.authId = pAuth->id; - WriteEventsToClient(client, 1, (xEvent *)&are); - } - FreeResource(pEventClient->resource, RT_NONE); - } - - /* kill all clients using this auth */ - - for (i = 1; iauthId == pAuth->id)) - CloseDownClient(clients[i]); - } - - SecurityAudit("revoked authorization ID %d\n", pAuth->id); - xfree(pAuth); - return Success; - -} /* SecurityDeleteAuthorization */ - - -/* resource delete function for RTEventClient */ -static int -SecurityDeleteAuthorizationEventClient( - pointer value, - XID id) -{ - OtherClientsPtr pEventClient, prev = NULL; - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value; - - for (pEventClient = pAuth->eventClients; - pEventClient; - pEventClient = pEventClient->next) - { - if (pEventClient->resource == id) - { - if (prev) - prev->next = pEventClient->next; - else - pAuth->eventClients = pEventClient->next; - xfree(pEventClient); - return(Success); - } - prev = pEventClient; - } - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} /* SecurityDeleteAuthorizationEventClient */ - - -/* SecurityComputeAuthorizationTimeout - * - * Arguments: - * pAuth is the authorization for which we are computing the timeout - * seconds is the number of seconds we want to wait - * - * Returns: - * the number of milliseconds that the auth timer should be set to - * - * Side Effects: - * Sets pAuth->secondsRemaining to any "overflow" amount of time - * that didn't fit in 32 bits worth of milliseconds - */ - -static CARD32 -SecurityComputeAuthorizationTimeout( - SecurityAuthorizationPtr pAuth, - unsigned int seconds) -{ - /* maxSecs is the number of full seconds that can be expressed in - * 32 bits worth of milliseconds - */ - CARD32 maxSecs = (CARD32)(~0) / (CARD32)MILLI_PER_SECOND; - - if (seconds > maxSecs) - { /* only come here if we want to wait more than 49 days */ - pAuth->secondsRemaining = seconds - maxSecs; - return maxSecs * MILLI_PER_SECOND; - } - else - { /* by far the common case */ - pAuth->secondsRemaining = 0; - return seconds * MILLI_PER_SECOND; - } -} /* SecurityStartAuthorizationTimer */ - -/* SecurityAuthorizationExpired - * - * This function is passed as an argument to TimerSet and gets called from - * the timer manager in the os layer when its time is up. - * - * Arguments: - * timer is the timer for this authorization. - * time is the current time. - * pval is the authorization whose time is up. - * - * Returns: - * A new time delay in milliseconds if the timer should wait some - * more, else zero. - * - * Side Effects: - * Frees the authorization resource if the timeout period is really - * over, otherwise recomputes pAuth->secondsRemaining. - */ - -static CARD32 -SecurityAuthorizationExpired( - OsTimerPtr timer, - CARD32 time, - pointer pval) -{ - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)pval; - - assert(pAuth->timer == timer); - - if (pAuth->secondsRemaining) - { - return SecurityComputeAuthorizationTimeout(pAuth, - pAuth->secondsRemaining); - } - else - { - FreeResource(pAuth->id, RT_NONE); - return 0; - } -} /* SecurityAuthorizationExpired */ - -/* SecurityStartAuthorizationTimer - * - * Arguments: - * pAuth is the authorization whose timer should be started. - * - * Returns: nothing. - * - * Side Effects: - * A timer is started, set to expire after the timeout period for - * this authorization. When it expires, the function - * SecurityAuthorizationExpired will be called. - */ - -static void -SecurityStartAuthorizationTimer( - SecurityAuthorizationPtr pAuth) -{ - pAuth->timer = TimerSet(pAuth->timer, 0, - SecurityComputeAuthorizationTimeout(pAuth, pAuth->timeout), - SecurityAuthorizationExpired, pAuth); -} /* SecurityStartAuthorizationTimer */ - - -/* Proc functions all take a client argument, execute the request in - * client->requestBuffer, and return a protocol error status. - */ - -static int -ProcSecurityQueryVersion( - ClientPtr client) -{ - /* REQUEST(xSecurityQueryVersionReq); */ - xSecurityQueryVersionReply rep; - - /* paranoia: this "can't happen" because this extension is hidden - * from untrusted clients, but just in case... - */ - if (client->trustLevel != XSecurityClientTrusted) - return BadRequest; - - REQUEST_SIZE_MATCH(xSecurityQueryVersionReq); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.majorVersion = SECURITY_MAJOR_VERSION; - rep.minorVersion = SECURITY_MINOR_VERSION; - if(client->swapped) - { - register char n; - swaps(&rep.sequenceNumber, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - } - (void)WriteToClient(client, SIZEOF(xSecurityQueryVersionReply), - (char *)&rep); - return (client->noClientException); -} /* ProcSecurityQueryVersion */ - - -static int -SecurityEventSelectForAuthorization( - SecurityAuthorizationPtr pAuth, - ClientPtr client, - Mask mask) -{ - OtherClients *pEventClient; - - for (pEventClient = pAuth->eventClients; - pEventClient; - pEventClient = pEventClient->next) - { - if (SameClient(pEventClient, client)) - { - if (mask == 0) - FreeResource(pEventClient->resource, RT_NONE); - else - pEventClient->mask = mask; - return Success; - } - } - - pEventClient = (OtherClients *) xalloc(sizeof(OtherClients)); - if (!pEventClient) - return BadAlloc; - pEventClient->mask = mask; - pEventClient->resource = FakeClientID(client->index); - pEventClient->next = pAuth->eventClients; - if (!AddResource(pEventClient->resource, RTEventClient, - (pointer)pAuth)) - { - xfree(pEventClient); - return BadAlloc; - } - pAuth->eventClients = pEventClient; - - return Success; -} /* SecurityEventSelectForAuthorization */ - - -static int -ProcSecurityGenerateAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityGenerateAuthorizationReq); - int len; /* request length in CARD32s*/ - Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */ - SecurityAuthorizationPtr pAuth = NULL; /* auth we are creating */ - int err; /* error to return from this function */ - XID authId; /* authorization ID assigned by os layer */ - xSecurityGenerateAuthorizationReply rep; /* reply struct */ - unsigned int trustLevel; /* trust level of new auth */ - XID group; /* group of new auth */ - CARD32 timeout; /* timeout of new auth */ - CARD32 *values; /* list of supplied attributes */ - char *protoname; /* auth proto name sent in request */ - char *protodata; /* auth proto data sent in request */ - unsigned int authdata_len; /* # bytes of generated auth data */ - char *pAuthdata; /* generated auth data */ - Mask eventMask; /* what events on this auth does client want */ - - /* paranoia: this "can't happen" because this extension is hidden - * from untrusted clients, but just in case... - */ - if (client->trustLevel != XSecurityClientTrusted) - return BadRequest; - - /* check request length */ - - REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq); - len = SIZEOF(xSecurityGenerateAuthorizationReq) >> 2; - len += (stuff->nbytesAuthProto + (unsigned)3) >> 2; - len += (stuff->nbytesAuthData + (unsigned)3) >> 2; - values = ((CARD32 *)stuff) + len; - len += Ones(stuff->valueMask); - if (client->req_len != len) - return BadLength; - - /* check valuemask */ - if (stuff->valueMask & ~XSecurityAllAuthorizationAttributes) - { - client->errorValue = stuff->valueMask; - return BadValue; - } - - /* check timeout */ - timeout = 60; - if (stuff->valueMask & XSecurityTimeout) - { - timeout = *values++; - } - - /* check trustLevel */ - trustLevel = XSecurityClientUntrusted; - if (stuff->valueMask & XSecurityTrustLevel) - { - trustLevel = *values++; - if (trustLevel != XSecurityClientTrusted && - trustLevel != XSecurityClientUntrusted) - { - client->errorValue = trustLevel; - return BadValue; - } - } - - /* check group */ - group = None; - if (stuff->valueMask & XSecurityGroup) - { - group = *values++; - if (SecurityValidateGroupCallback) - { - SecurityValidateGroupInfoRec vgi; - vgi.group = group; - vgi.valid = FALSE; - CallCallbacks(&SecurityValidateGroupCallback, (pointer)&vgi); - - /* if nobody said they recognized it, it's an error */ - - if (!vgi.valid) - { - client->errorValue = group; - return BadValue; - } - } - } - - /* check event mask */ - eventMask = 0; - if (stuff->valueMask & XSecurityEventMask) - { - eventMask = *values++; - if (eventMask & ~XSecurityAllEventMasks) - { - client->errorValue = eventMask; - return BadValue; - } - } - - protoname = (char *)&stuff[1]; - protodata = protoname + ((stuff->nbytesAuthProto + (unsigned)3) >> 2); - - /* call os layer to generate the authorization */ - - authId = GenerateAuthorization(stuff->nbytesAuthProto, protoname, - stuff->nbytesAuthData, protodata, - &authdata_len, &pAuthdata); - if ((XID) ~0L == authId) - { - err = SecurityErrorBase + XSecurityBadAuthorizationProtocol; - goto bailout; - } - - /* now that we've added the auth, remember to remove it if we have to - * abort the request for some reason (like allocation failure) - */ - removeAuth = TRUE; - - /* associate additional information with this auth ID */ - - pAuth = (SecurityAuthorizationPtr)xalloc(sizeof(SecurityAuthorizationRec)); - if (!pAuth) - { - err = BadAlloc; - goto bailout; - } - - /* fill in the auth fields */ - - pAuth->id = authId; - pAuth->timeout = timeout; - pAuth->group = group; - pAuth->trustLevel = trustLevel; - pAuth->refcnt = 0; /* the auth was just created; nobody's using it yet */ - pAuth->secondsRemaining = 0; - pAuth->timer = NULL; - pAuth->eventClients = NULL; - - /* handle event selection */ - if (eventMask) - { - err = SecurityEventSelectForAuthorization(pAuth, client, eventMask); - if (err != Success) - goto bailout; - } - - if (!AddResource(authId, SecurityAuthorizationResType, pAuth)) - { - err = BadAlloc; - goto bailout; - } - - /* start the timer ticking */ - - if (pAuth->timeout != 0) - SecurityStartAuthorizationTimer(pAuth); - - /* tell client the auth id and data */ - - rep.type = X_Reply; - rep.length = (authdata_len + 3) >> 2; - rep.sequenceNumber = client->sequence; - rep.authId = authId; - rep.dataLength = authdata_len; - - if (client->swapped) - { - register char n; - swapl(&rep.length, n); - swaps(&rep.sequenceNumber, n); - swapl(&rep.authId, n); - swaps(&rep.dataLength, n); - } - - WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply), - (char *)&rep); - WriteToClient(client, authdata_len, pAuthdata); - - SecurityAudit("client %d generated authorization %d trust %d timeout %d group %d events %d\n", - client->index, pAuth->id, pAuth->trustLevel, pAuth->timeout, - pAuth->group, eventMask); - - /* the request succeeded; don't call RemoveAuthorization or free pAuth */ - - removeAuth = FALSE; - pAuth = NULL; - err = client->noClientException; - -bailout: - if (removeAuth) - RemoveAuthorization(stuff->nbytesAuthProto, protoname, - authdata_len, pAuthdata); - if (pAuth) xfree(pAuth); - return err; - -} /* ProcSecurityGenerateAuthorization */ - -static int -ProcSecurityRevokeAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityRevokeAuthorizationReq); - SecurityAuthorizationPtr pAuth; - - /* paranoia: this "can't happen" because this extension is hidden - * from untrusted clients, but just in case... - */ - if (client->trustLevel != XSecurityClientTrusted) - return BadRequest; - - REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq); - - pAuth = (SecurityAuthorizationPtr)SecurityLookupIDByType(client, - stuff->authId, SecurityAuthorizationResType, SecurityDestroyAccess); - if (!pAuth) - return SecurityErrorBase + XSecurityBadAuthorization; - - FreeResource(stuff->authId, RT_NONE); - return Success; -} /* ProcSecurityRevokeAuthorization */ - - -static int -ProcSecurityDispatch( - ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) - { - case X_SecurityQueryVersion: - return ProcSecurityQueryVersion(client); - case X_SecurityGenerateAuthorization: - return ProcSecurityGenerateAuthorization(client); - case X_SecurityRevokeAuthorization: - return ProcSecurityRevokeAuthorization(client); - default: - return BadRequest; - } -} /* ProcSecurityDispatch */ - -static int -SProcSecurityQueryVersion( - ClientPtr client) -{ - REQUEST(xSecurityQueryVersionReq); - register char n; - - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xSecurityQueryVersionReq); - swaps(&stuff->majorVersion, n); - swaps(&stuff->minorVersion,n); - return ProcSecurityQueryVersion(client); -} /* SProcSecurityQueryVersion */ - - -static int -SProcSecurityGenerateAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityGenerateAuthorizationReq); - register char n; - CARD32 *values; - unsigned long nvalues; - int values_offset; - - swaps(&stuff->length, n); - REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq); - swaps(&stuff->nbytesAuthProto, n); - swaps(&stuff->nbytesAuthData, n); - swapl(&stuff->valueMask, n); - values_offset = ((stuff->nbytesAuthProto + (unsigned)3) >> 2) + - ((stuff->nbytesAuthData + (unsigned)3) >> 2); - if (values_offset > - stuff->length - (sz_xSecurityGenerateAuthorizationReq >> 2)) - return BadLength; - values = (CARD32 *)(&stuff[1]) + values_offset; - nvalues = (((CARD32 *)stuff) + stuff->length) - values; - SwapLongs(values, nvalues); - return ProcSecurityGenerateAuthorization(client); -} /* SProcSecurityGenerateAuthorization */ - - -static int -SProcSecurityRevokeAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityRevokeAuthorizationReq); - register char n; - - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq); - swapl(&stuff->authId, n); - return ProcSecurityRevokeAuthorization(client); -} /* SProcSecurityRevokeAuthorization */ - - -static int -SProcSecurityDispatch( - ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) - { - case X_SecurityQueryVersion: - return SProcSecurityQueryVersion(client); - case X_SecurityGenerateAuthorization: - return SProcSecurityGenerateAuthorization(client); - case X_SecurityRevokeAuthorization: - return SProcSecurityRevokeAuthorization(client); - default: - return BadRequest; - } -} /* SProcSecurityDispatch */ - -static void -SwapSecurityAuthorizationRevokedEvent( - xSecurityAuthorizationRevokedEvent *from, - xSecurityAuthorizationRevokedEvent *to) -{ - to->type = from->type; - to->detail = from->detail; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->authId, to->authId); -} - -/* SecurityDetermineEventPropogationLimits - * - * This is a helper function for SecurityCheckDeviceAccess. - * - * Arguments: - * dev is the device for which the starting and stopping windows for - * event propogation should be determined. - * The values pointed to by ppWin and ppStopWin are not used. - * - * Returns: - * ppWin is filled in with a pointer to the window at which event - * propogation for the given device should start given the current - * state of the server (pointer position, window layout, etc.) - * ppStopWin is filled in with the window at which event propogation - * should stop; events should not go to ppStopWin. - * - * Side Effects: none. - */ - -static void -SecurityDetermineEventPropogationLimits( - DeviceIntPtr dev, - WindowPtr *ppWin, - WindowPtr *ppStopWin) -{ - WindowPtr pFocusWin = dev->focus ? dev->focus->win : NoneWin; - - if (pFocusWin == NoneWin) - { /* no focus -- events don't go anywhere */ - *ppWin = *ppStopWin = NULL; - return; - } - - if (pFocusWin == PointerRootWin) - { /* focus follows the pointer */ - *ppWin = GetSpriteWindow(); - *ppStopWin = NULL; /* propogate all the way to the root */ - } - else - { /* a real window is set for the focus */ - WindowPtr pSpriteWin = GetSpriteWindow(); - *ppStopWin = pFocusWin->parent; /* don't go past the focus window */ - - /* if the pointer is in a subwindow of the focus window, start - * at that subwindow, else start at the focus window itself - */ - if (IsParent(pFocusWin, pSpriteWin)) - *ppWin = pSpriteWin; - else *ppWin = pFocusWin; - } -} /* SecurityDetermineEventPropogationLimits */ - - -/* SecurityCheckDeviceAccess - * - * Arguments: - * client is the client attempting to access a device. - * dev is the device being accessed. - * fromRequest is TRUE if the device access is a direct result of - * the client executing some request and FALSE if it is a - * result of the server trying to send an event (e.g. KeymapNotify) - * to the client. - * Returns: - * TRUE if the device access should be allowed, else FALSE. - * - * Side Effects: - * An audit message is generated if access is denied. - */ - -Bool -SecurityCheckDeviceAccess(client, dev, fromRequest) - ClientPtr client; - DeviceIntPtr dev; - Bool fromRequest; -{ - WindowPtr pWin, pStopWin; - Bool untrusted_got_event; - Bool found_event_window; - Mask eventmask; - int reqtype = 0; - - /* trusted clients always allowed to do anything */ - if (client->trustLevel == XSecurityClientTrusted) - return TRUE; - - /* device security other than keyboard is not implemented yet */ - if (dev != inputInfo.keyboard) - return TRUE; - - /* some untrusted client wants access */ - - if (fromRequest) - { - reqtype = ((xReq *)client->requestBuffer)->reqType; - switch (reqtype) - { - /* never allow these */ - case X_ChangeKeyboardMapping: - case X_ChangeKeyboardControl: - case X_SetModifierMapping: - SecurityAudit("client %d attempted request %d\n", - client->index, reqtype); - return FALSE; - default: - break; - } - } - - untrusted_got_event = FALSE; - found_event_window = FALSE; - - if (dev->grab) - { - untrusted_got_event = - ((rClient(dev->grab))->trustLevel != XSecurityClientTrusted); - } - else - { - SecurityDetermineEventPropogationLimits(dev, &pWin, &pStopWin); - - eventmask = KeyPressMask | KeyReleaseMask; - while ( (pWin != pStopWin) && !found_event_window) - { - OtherClients *other; - - if (pWin->eventMask & eventmask) - { - found_event_window = TRUE; - client = wClient(pWin); - if (client->trustLevel != XSecurityClientTrusted) - { - untrusted_got_event = TRUE; - } - } - if (wOtherEventMasks(pWin) & eventmask) - { - found_event_window = TRUE; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & eventmask) - { - client = rClient(other); - if (client->trustLevel != XSecurityClientTrusted) - { - untrusted_got_event = TRUE; - break; - } - } - } - } - if (wDontPropagateMask(pWin) & eventmask) - break; - pWin = pWin->parent; - } /* while propogating the event */ - } - - /* allow access by untrusted clients only if an event would have gone - * to an untrusted client - */ - - if (!untrusted_got_event) - { - char *devname = dev->name; - if (!devname) devname = "unnamed"; - if (fromRequest) - SecurityAudit("client %d attempted request %d device %d (%s)\n", - client->index, reqtype, dev->id, devname); - else - SecurityAudit("client %d attempted to access device %d (%s)\n", - client->index, dev->id, devname); - } - return untrusted_got_event; -} /* SecurityCheckDeviceAccess */ - - - -/* SecurityAuditResourceIDAccess - * - * Arguments: - * client is the client doing the resource access. - * id is the resource id. - * - * Returns: NULL - * - * Side Effects: - * An audit message is generated with details of the denied - * resource access. - */ - -static pointer -SecurityAuditResourceIDAccess( - ClientPtr client, - XID id) -{ - int cid = CLIENT_ID(id); - int reqtype = ((xReq *)client->requestBuffer)->reqType; - switch (reqtype) - { - case X_ChangeProperty: - case X_DeleteProperty: - case X_GetProperty: - { - xChangePropertyReq *req = - (xChangePropertyReq *)client->requestBuffer; - int propertyatom = req->property; - char *propertyname = NameForAtom(propertyatom); - - SecurityAudit("client %d attempted request %d with window 0x%x property %s of client %d\n", - client->index, reqtype, id, propertyname, cid); - break; - } - default: - { - SecurityAudit("client %d attempted request %d with resource 0x%x of client %d\n", - client->index, reqtype, id, cid); - break; - } - } - return NULL; -} /* SecurityAuditResourceIDAccess */ - - -/* SecurityCheckResourceIDAccess - * - * This function gets plugged into client->CheckAccess and is called from - * SecurityLookupIDByType/Class to determine if the client can access the - * resource. - * - * Arguments: - * client is the client doing the resource access. - * id is the resource id. - * rtype is its type or class. - * access_mode represents the intended use of the resource; see - * resource.h. - * rval is a pointer to the resource structure for this resource. - * - * Returns: - * If access is granted, the value of rval that was passed in, else NULL. - * - * Side Effects: - * Disallowed resource accesses are audited. - */ - -static pointer -SecurityCheckResourceIDAccess( - ClientPtr client, - XID id, - RESTYPE rtype, - Mask access_mode, - pointer rval) -{ - int cid = CLIENT_ID(id); - int reqtype = ((xReq *)client->requestBuffer)->reqType; - - if (SecurityUnknownAccess == access_mode) - return rval; /* for compatibility, we have to allow access */ - - switch (reqtype) - { /* these are always allowed */ - case X_QueryTree: - case X_TranslateCoords: - case X_GetGeometry: - /* property access is controlled in SecurityCheckPropertyAccess */ - case X_GetProperty: - case X_ChangeProperty: - case X_DeleteProperty: - case X_RotateProperties: - case X_ListProperties: - return rval; - default: - break; - } - - if (cid != 0) - { /* not a server-owned resource */ - /* - * The following 'if' restricts clients to only access resources at - * the same trustLevel. Since there are currently only two trust levels, - * and trusted clients never call this function, this degenerates into - * saying that untrusted clients can only access resources of other - * untrusted clients. One way to add the notion of groups would be to - * allow values other than Trusted (0) and Untrusted (1) for this field. - * Clients at the same trust level would be able to use each other's - * resources, but not those of clients at other trust levels. I haven't - * tried it, but this probably mostly works already. The obvious - * competing alternative for grouping clients for security purposes is to - * use app groups. dpw - */ - if (client->trustLevel == clients[cid]->trustLevel -#ifdef XAPPGROUP - || (RT_COLORMAP == rtype && - XagDefaultColormap (client) == (Colormap) id) -#endif - ) - return rval; - else - return SecurityAuditResourceIDAccess(client, id); - } - else /* server-owned resource - probably a default colormap or root window */ - { - if (RT_WINDOW == rtype || RC_DRAWABLE == rtype) - { - switch (reqtype) - { /* the following operations are allowed on root windows */ - case X_CreatePixmap: - case X_CreateGC: - case X_CreateWindow: - case X_CreateColormap: - case X_ListProperties: - case X_GrabPointer: - case X_UngrabButton: - case X_QueryBestSize: - case X_GetWindowAttributes: - break; - case X_SendEvent: - { /* see if it is an event specified by the ICCCM */ - xSendEventReq *req = (xSendEventReq *) - (client->requestBuffer); - if (req->propagate == xTrue - || - (req->eventMask != ColormapChangeMask && - req->eventMask != StructureNotifyMask && - req->eventMask != - (SubstructureRedirectMask|SubstructureNotifyMask) - ) - || - (req->event.u.u.type != UnmapNotify && - req->event.u.u.type != ConfigureRequest && - req->event.u.u.type != ClientMessage - ) - ) - { /* not an ICCCM event */ - return SecurityAuditResourceIDAccess(client, id); - } - break; - } /* case X_SendEvent on root */ - - case X_ChangeWindowAttributes: - { /* Allow selection of PropertyNotify and StructureNotify - * events on the root. - */ - xChangeWindowAttributesReq *req = - (xChangeWindowAttributesReq *)(client->requestBuffer); - if (req->valueMask == CWEventMask) - { - CARD32 value = *((CARD32 *)(req + 1)); - if ( (value & - ~(PropertyChangeMask|StructureNotifyMask)) == 0) - break; - } - return SecurityAuditResourceIDAccess(client, id); - } /* case X_ChangeWindowAttributes on root */ - - default: - { -#ifdef LBX - /* XXX really need per extension dispatching */ - if (reqtype == LbxReqCode) { - switch (((xReq *)client->requestBuffer)->data) { - case X_LbxGetProperty: - case X_LbxChangeProperty: - return rval; - default: - break; - } - } -#endif - /* others not allowed */ - return SecurityAuditResourceIDAccess(client, id); - } - } - } /* end server-owned window or drawable */ - else if (SecurityAuthorizationResType == rtype) - { - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)rval; - if (pAuth->trustLevel != client->trustLevel) - return SecurityAuditResourceIDAccess(client, id); - } - else if (RT_COLORMAP != rtype) - { /* don't allow anything else besides colormaps */ - return SecurityAuditResourceIDAccess(client, id); - } - } - return rval; -} /* SecurityCheckResourceIDAccess */ - - -/* SecurityClientStateCallback - * - * Arguments: - * pcbl is &ClientStateCallback. - * nullata is NULL. - * calldata is a pointer to a NewClientInfoRec (include/dixstruct.h) - * which contains information about client state changes. - * - * Returns: nothing. - * - * Side Effects: - * - * If a new client is connecting, its authorization ID is copied to - * client->authID. If this is a generated authorization, its reference - * count is bumped, its timer is cancelled if it was running, and its - * trustlevel is copied to client->trustLevel. - * - * If a client is disconnecting and the client was using a generated - * authorization, the authorization's reference count is decremented, and - * if it is now zero, the timer for this authorization is started. - */ - -static void -SecurityClientStateCallback( - CallbackListPtr *pcbl, - pointer nulldata, - pointer calldata) -{ - NewClientInfoRec *pci = (NewClientInfoRec *)calldata; - ClientPtr client = pci->client; - - switch (client->clientState) - { - case ClientStateRunning: - { - XID authId = AuthorizationIDOfClient(client); - SecurityAuthorizationPtr pAuth; - - client->authId = authId; - pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId, - SecurityAuthorizationResType); - if (pAuth) - { /* it is a generated authorization */ - pAuth->refcnt++; - if (pAuth->refcnt == 1) - { - if (pAuth->timer) TimerCancel(pAuth->timer); - } - client->trustLevel = pAuth->trustLevel; - if (client->trustLevel != XSecurityClientTrusted) - { - client->CheckAccess = SecurityCheckResourceIDAccess; - client->requestVector = client->swapped ? - SwappedUntrustedProcVector : UntrustedProcVector; - } - } - break; - } - case ClientStateGone: - case ClientStateRetained: /* client disconnected */ - { - XID authId = client->authId; - SecurityAuthorizationPtr pAuth; - - pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId, - SecurityAuthorizationResType); - if (pAuth) - { /* it is a generated authorization */ - pAuth->refcnt--; - if (pAuth->refcnt == 0) - { - SecurityStartAuthorizationTimer(pAuth); - } - } - break; - } - default: break; - } -} /* SecurityClientStateCallback */ - -#ifdef LBX -Bool -SecuritySameLevel(client, authId) - ClientPtr client; - XID authId; -{ - SecurityAuthorizationPtr pAuth; - - pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId, - SecurityAuthorizationResType); - if (pAuth) - return client->trustLevel == pAuth->trustLevel; - return client->trustLevel == XSecurityClientTrusted; -} -#endif - -/* SecurityCensorImage - * - * Called after pScreen->GetImage to prevent pieces or trusted windows from - * being returned in image data from an untrusted window. - * - * Arguments: - * client is the client doing the GetImage. - * pVisibleRegion is the visible region of the window. - * widthBytesLine is the width in bytes of one horizontal line in pBuf. - * pDraw is the source window. - * x, y, w, h is the rectangle of image data from pDraw in pBuf. - * format is the format of the image data in pBuf: ZPixmap or XYPixmap. - * pBuf is the image data. - * - * Returns: nothing. - * - * Side Effects: - * Any part of the rectangle (x, y, w, h) that is outside the visible - * region of the window will be destroyed (overwritten) in pBuf. - */ -void -SecurityCensorImage(client, pVisibleRegion, widthBytesLine, pDraw, x, y, w, h, - format, pBuf) - ClientPtr client; - RegionPtr pVisibleRegion; - long widthBytesLine; - DrawablePtr pDraw; - int x, y, w, h; - unsigned int format; - char * pBuf; -{ - ScreenPtr pScreen = pDraw->pScreen; - RegionRec imageRegion; /* region representing x,y,w,h */ - RegionRec censorRegion; /* region to obliterate */ - BoxRec imageBox; - int nRects; - - imageBox.x1 = x; - imageBox.y1 = y; - imageBox.x2 = x + w; - imageBox.y2 = y + h; - REGION_INIT(pScreen, &imageRegion, &imageBox, 1); - REGION_NULL(pScreen, &censorRegion); - - /* censorRegion = imageRegion - visibleRegion */ - REGION_SUBTRACT(pScreen, &censorRegion, &imageRegion, pVisibleRegion); - nRects = REGION_NUM_RECTS(&censorRegion); - if (nRects > 0) - { /* we have something to censor */ - GCPtr pScratchGC = NULL; - PixmapPtr pPix = NULL; - xRectangle *pRects = NULL; - Bool failed = FALSE; - int depth = 1; - int bitsPerPixel = 1; - int i; - BoxPtr pBox; - - /* convert region to list-of-rectangles for PolyFillRect */ - - pRects = (xRectangle *)ALLOCATE_LOCAL(nRects * sizeof(xRectangle *)); - if (!pRects) - { - failed = TRUE; - goto failSafe; - } - for (pBox = REGION_RECTS(&censorRegion), i = 0; - i < nRects; - i++, pBox++) - { - pRects[i].x = pBox->x1; - pRects[i].y = pBox->y1 - imageBox.y1; - pRects[i].width = pBox->x2 - pBox->x1; - pRects[i].height = pBox->y2 - pBox->y1; - } - - /* use pBuf as a fake pixmap */ - - if (format == ZPixmap) - { - depth = pDraw->depth; - bitsPerPixel = pDraw->bitsPerPixel; - } - - pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h, - depth, bitsPerPixel, - widthBytesLine, (pointer)pBuf); - if (!pPix) - { - failed = TRUE; - goto failSafe; - } - - pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen); - if (!pScratchGC) - { - failed = TRUE; - goto failSafe; - } - - ValidateGC(&pPix->drawable, pScratchGC); - (* pScratchGC->ops->PolyFillRect)(&pPix->drawable, - pScratchGC, nRects, pRects); - - failSafe: - if (failed) - { - /* Censoring was not completed above. To be safe, wipe out - * all the image data so that nothing trusted gets out. - */ - bzero(pBuf, (int)(widthBytesLine * h)); - } - if (pRects) DEALLOCATE_LOCAL(pRects); - if (pScratchGC) FreeScratchGC(pScratchGC); - if (pPix) FreeScratchPixmapHeader(pPix); - } - REGION_UNINIT(pScreen, &imageRegion); - REGION_UNINIT(pScreen, &censorRegion); -} /* SecurityCensorImage */ - -/**********************************************************************/ - -typedef struct _PropertyAccessRec { - ATOM name; - ATOM mustHaveProperty; - char *mustHaveValue; - char windowRestriction; -#define SecurityAnyWindow 0 -#define SecurityRootWindow 1 -#define SecurityWindowWithProperty 2 - char readAction; - char writeAction; - char destroyAction; - struct _PropertyAccessRec *next; -} PropertyAccessRec, *PropertyAccessPtr; - -static PropertyAccessPtr PropertyAccessList = NULL; -static char SecurityDefaultAction = SecurityErrorOperation; -static char *SecurityPolicyFile = DEFAULTPOLICYFILE; -static ATOM SecurityMaxPropertyName = 0; - -static char *SecurityKeywords[] = { -#define SecurityKeywordComment 0 - "#", -#define SecurityKeywordProperty 1 - "property", -#define SecurityKeywordSitePolicy 2 - "sitepolicy", -#define SecurityKeywordRoot 3 - "root", -#define SecurityKeywordAny 4 - "any" -}; - -#define NUMKEYWORDS (sizeof(SecurityKeywords) / sizeof(char *)) - -#undef PROPDEBUG -/*#define PROPDEBUG 1*/ - -static void -SecurityFreePropertyAccessList(void) -{ - while (PropertyAccessList) - { - PropertyAccessPtr freeit = PropertyAccessList; - PropertyAccessList = PropertyAccessList->next; - xfree(freeit); - } -} /* SecurityFreePropertyAccessList */ - -#ifndef __UNIXOS2__ -#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') ) -#else -#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') ) -#endif - -static char * -SecuritySkipWhitespace( - char *p) -{ - while (SecurityIsWhitespace(*p)) - p++; - return p; -} /* SecuritySkipWhitespace */ - - -static char * -SecurityParseString( - char **rest) -{ - char *startOfString; - char *s = *rest; - char endChar = 0; - - s = SecuritySkipWhitespace(s); - - if (*s == '"' || *s == '\'') - { - endChar = *s++; - startOfString = s; - while (*s && (*s != endChar)) - s++; - } - else - { - startOfString = s; - while (*s && !SecurityIsWhitespace(*s)) - s++; - } - if (*s) - { - *s = '\0'; - *rest = s + 1; - return startOfString; - } - else - { - *rest = s; - return (endChar) ? NULL : startOfString; - } -} /* SecurityParseString */ - - -static int -SecurityParseKeyword( - char **p) -{ - int i; - char *s = *p; - s = SecuritySkipWhitespace(s); - for (i = 0; i < NUMKEYWORDS; i++) - { - int len = strlen(SecurityKeywords[i]); - if (strncmp(s, SecurityKeywords[i], len) == 0) - { - *p = s + len; - return (i); - } - } - *p = s; - return -1; -} /* SecurityParseKeyword */ - - -static Bool -SecurityParsePropertyAccessRule( - char *p) -{ - char *propname; - char c; - char action = SecurityDefaultAction; - char readAction, writeAction, destroyAction; - PropertyAccessPtr pacl, prev, cur; - char *mustHaveProperty = NULL; - char *mustHaveValue = NULL; - Bool invalid; - char windowRestriction; - int size; - int keyword; - - /* get property name */ - propname = SecurityParseString(&p); - if (!propname || (strlen(propname) == 0)) - return FALSE; - - /* get window on which property must reside for rule to apply */ - - keyword = SecurityParseKeyword(&p); - if (keyword == SecurityKeywordRoot) - windowRestriction = SecurityRootWindow; - else if (keyword == SecurityKeywordAny) - windowRestriction = SecurityAnyWindow; - else /* not root or any, must be a property name */ - { - mustHaveProperty = SecurityParseString(&p); - if (!mustHaveProperty || (strlen(mustHaveProperty) == 0)) - return FALSE; - windowRestriction = SecurityWindowWithProperty; - p = SecuritySkipWhitespace(p); - if (*p == '=') - { /* property value is specified too */ - p++; /* skip over '=' */ - mustHaveValue = SecurityParseString(&p); - if (!mustHaveValue) - return FALSE; - } - } - - /* get operations and actions */ - - invalid = FALSE; - readAction = writeAction = destroyAction = SecurityDefaultAction; - while ( (c = *p++) && !invalid) - { - switch (c) - { - case 'i': action = SecurityIgnoreOperation; break; - case 'a': action = SecurityAllowOperation; break; - case 'e': action = SecurityErrorOperation; break; - - case 'r': readAction = action; break; - case 'w': writeAction = action; break; - case 'd': destroyAction = action; break; - - default : - if (!SecurityIsWhitespace(c)) - invalid = TRUE; - break; - } - } - if (invalid) - return FALSE; - - /* We've successfully collected all the information needed for this - * property access rule. Now record it in a PropertyAccessRec. - */ - size = sizeof(PropertyAccessRec); - - /* If there is a property value string, allocate space for it - * right after the PropertyAccessRec. - */ - if (mustHaveValue) - size += strlen(mustHaveValue) + 1; - pacl = (PropertyAccessPtr)Xalloc(size); - if (!pacl) - return FALSE; - - pacl->name = MakeAtom(propname, strlen(propname), TRUE); - if (pacl->name == BAD_RESOURCE) - { - Xfree(pacl); - return FALSE; - } - if (mustHaveProperty) - { - pacl->mustHaveProperty = MakeAtom(mustHaveProperty, - strlen(mustHaveProperty), TRUE); - if (pacl->mustHaveProperty == BAD_RESOURCE) - { - Xfree(pacl); - return FALSE; - } - } - else - pacl->mustHaveProperty = 0; - - if (mustHaveValue) - { - pacl->mustHaveValue = (char *)(pacl + 1); - strcpy(pacl->mustHaveValue, mustHaveValue); - } - else - pacl->mustHaveValue = NULL; - - SecurityMaxPropertyName = max(SecurityMaxPropertyName, pacl->name); - - pacl->windowRestriction = windowRestriction; - pacl->readAction = readAction; - pacl->writeAction = writeAction; - pacl->destroyAction = destroyAction; - - /* link the new rule into the list of rules in order of increasing - * property name (atom) value to make searching easier - */ - - for (prev = NULL, cur = PropertyAccessList; - cur && cur->name <= pacl->name; - prev = cur, cur = cur->next) - ; - if (!prev) - { - pacl->next = cur; - PropertyAccessList = pacl; - } - else - { - prev->next = pacl; - pacl->next = cur; - } - return TRUE; -} /* SecurityParsePropertyAccessRule */ - -static char **SecurityPolicyStrings = NULL; -static int nSecurityPolicyStrings = 0; - -static Bool -SecurityParseSitePolicy( - char *p) -{ - char *policyStr = SecurityParseString(&p); - char *copyPolicyStr; - char **newStrings; - - if (!policyStr) - return FALSE; - - copyPolicyStr = (char *)Xalloc(strlen(policyStr) + 1); - if (!copyPolicyStr) - return TRUE; - strcpy(copyPolicyStr, policyStr); - newStrings = (char **)Xrealloc(SecurityPolicyStrings, - sizeof (char *) * (nSecurityPolicyStrings + 1)); - if (!newStrings) - { - Xfree(copyPolicyStr); - return TRUE; - } - - SecurityPolicyStrings = newStrings; - SecurityPolicyStrings[nSecurityPolicyStrings++] = copyPolicyStr; - - return TRUE; - -} /* SecurityParseSitePolicy */ - - -char ** -SecurityGetSitePolicyStrings(n) - int *n; -{ - *n = nSecurityPolicyStrings; - return SecurityPolicyStrings; -} /* SecurityGetSitePolicyStrings */ - -static void -SecurityFreeSitePolicyStrings(void) -{ - if (SecurityPolicyStrings) - { - assert(nSecurityPolicyStrings); - while (nSecurityPolicyStrings--) - { - Xfree(SecurityPolicyStrings[nSecurityPolicyStrings]); - } - Xfree(SecurityPolicyStrings); - SecurityPolicyStrings = NULL; - nSecurityPolicyStrings = 0; - } -} /* SecurityFreeSitePolicyStrings */ - - -static void -SecurityLoadPropertyAccessList(void) -{ - FILE *f; - int lineNumber = 0; - - SecurityMaxPropertyName = 0; - -#ifdef NXAGENT_SERVER - - if (!_NXGetPolicyFilePath(SecurityPolicyFile)) - { - return; - } - -#else - - if (!SecurityPolicyFile) - return; - -#endif - -#ifndef __UNIXOS2__ - -#ifdef NXAGENT_SERVER - - f = Fopen(_NXGetPolicyFilePath(SecurityPolicyFile), "r"); - -#else - - f = Fopen(SecurityPolicyFile, "r"); - -#endif - -#else - -#ifdef NXAGENT_SERVER - - f = Fopen((char*)__XOS2RedirRoot( _NXGetPolicyFilePath(SecurityPolicyFile)), "r"); - -#else - - f = Fopen((char*)__XOS2RedirRoot(SecurityPolicyFile), "r"); - -#endif - -#endif - - if (!f) - { -#ifdef NXAGENT_SERVER - - ErrorF("error opening security policy file %s\n", - _NXGetPolicyFilePath(SecurityPolicyFile)); - -#else - - ErrorF("error opening security policy file %s\n", - SecurityPolicyFile); - -#endif - - return; - } - - while (!feof(f)) - { - char buf[200]; - Bool validLine; - char *p; - - if (!(p = fgets(buf, sizeof(buf), f))) - break; - lineNumber++; - - /* if first line, check version number */ - if (lineNumber == 1) - { - char *v = SecurityParseString(&p); - if (strcmp(v, SECURITY_POLICY_FILE_VERSION) != 0) - { - -#ifdef NXAGENT_SERVER - - ErrorF("%s: invalid security policy file version, ignoring file\n", - _NXGetPolicyFilePath(SecurityPolicyFile)); - -#else - - ErrorF("%s: invalid security policy file version, ignoring file\n", - SecurityPolicyFile); - -#endif - - break; - } - validLine = TRUE; - } - else - { - switch (SecurityParseKeyword(&p)) - { - case SecurityKeywordComment: - validLine = TRUE; - break; - - case SecurityKeywordProperty: - validLine = SecurityParsePropertyAccessRule(p); - break; - - case SecurityKeywordSitePolicy: - validLine = SecurityParseSitePolicy(p); - break; - - default: - validLine = (*p == '\0'); /* blank lines OK, others not */ - break; - } - } - -#ifdef NXAGENT_SERVER - - if (!validLine) - { - ErrorF("Line %d of %s invalid, ignoring\n", - lineNumber, _NXGetPolicyFilePath(SecurityPolicyFile)); - } - -#else - - if (!validLine) - ErrorF("Line %d of %s invalid, ignoring\n", - lineNumber, SecurityPolicyFile); - -#endif - - } /* end while more input */ - -#ifdef PROPDEBUG - { - PropertyAccessPtr pacl; - char *op = "aie"; - for (pacl = PropertyAccessList; pacl; pacl = pacl->next) - { - ErrorF("property %s ", NameForAtom(pacl->name)); - switch (pacl->windowRestriction) - { - case SecurityAnyWindow: ErrorF("any "); break; - case SecurityRootWindow: ErrorF("root "); break; - case SecurityWindowWithProperty: - { - ErrorF("%s ", NameForAtom(pacl->mustHaveProperty)); - if (pacl->mustHaveValue) - ErrorF(" = \"%s\" ", pacl->mustHaveValue); - - } - break; - } - ErrorF("%cr %cw %cd\n", op[pacl->readAction], - op[pacl->writeAction], op[pacl->destroyAction]); - } - } -#endif /* PROPDEBUG */ - - Fclose(f); -} /* SecurityLoadPropertyAccessList */ - - -static Bool -SecurityMatchString( - char *ws, - char *cs) -{ - while (*ws && *cs) - { - if (*ws == '*') - { - Bool match = FALSE; - ws++; - while (!(match = SecurityMatchString(ws, cs)) && *cs) - { - cs++; - } - return match; - } - else if (*ws == *cs) - { - ws++; - cs++; - } - else break; - } - return ( ( (*ws == '\0') || ((*ws == '*') && *(ws+1) == '\0') ) - && (*cs == '\0') ); -} /* SecurityMatchString */ - -#ifdef PROPDEBUG -#include -#include -#endif - - -char -SecurityCheckPropertyAccess(client, pWin, propertyName, access_mode) - ClientPtr client; - WindowPtr pWin; - ATOM propertyName; - Mask access_mode; -{ - PropertyAccessPtr pacl; - char action = SecurityDefaultAction; - - /* if client trusted or window untrusted, allow operation */ - - if ( (client->trustLevel == XSecurityClientTrusted) || - (wClient(pWin)->trustLevel != XSecurityClientTrusted) ) - return SecurityAllowOperation; - -#ifdef PROPDEBUG - /* For testing, it's more convenient if the property rules file gets - * reloaded whenever it changes, so we can rapidly try things without - * having to reset the server. - */ - { - struct stat buf; - static time_t lastmod = 0; - -#ifdef NXAGENT_SERVER - - int ret = stat(_NXGetPolicyFilePath(SecurityPolicyFile), &buf); - -#else - - int ret = stat(SecurityPolicyFile , &buf); - -#endif - - if ( (ret == 0) && (buf.st_mtime > lastmod) ) - { - ErrorF("reloading property rules\n"); - SecurityFreePropertyAccessList(); - SecurityLoadPropertyAccessList(); - lastmod = buf.st_mtime; - } - } -#endif - - /* If the property atom is bigger than any atoms on the list, - * we know we won't find it, so don't even bother looking. - */ - if (propertyName <= SecurityMaxPropertyName) - { - /* untrusted client operating on trusted window; see if it's allowed */ - - for (pacl = PropertyAccessList; pacl; pacl = pacl->next) - { - if (pacl->name < propertyName) - continue; - if (pacl->name > propertyName) - break; - - /* pacl->name == propertyName, so see if it applies to this window */ - - switch (pacl->windowRestriction) - { - case SecurityAnyWindow: /* always applies */ - break; - - case SecurityRootWindow: - { - /* if not a root window, this rule doesn't apply */ - if (pWin->parent) - continue; - } - break; - - case SecurityWindowWithProperty: - { - PropertyPtr pProp = wUserProps (pWin); - Bool match = FALSE; - char *p; - char *pEndData; - - while (pProp) - { - if (pProp->propertyName == pacl->mustHaveProperty) - break; - pProp = pProp->next; - } - if (!pProp) - continue; - if (!pacl->mustHaveValue) - break; - if (pProp->type != XA_STRING || pProp->format != 8) - continue; - - p = pProp->data; - pEndData = ((char *)pProp->data) + pProp->size; - while (!match && p < pEndData) - { - if (SecurityMatchString(pacl->mustHaveValue, p)) - match = TRUE; - else - { /* skip to the next string */ - while (*p++ && p < pEndData) - ; - } - } - if (!match) - continue; - } - break; /* end case SecurityWindowWithProperty */ - } /* end switch on windowRestriction */ - - /* If we get here, the property access rule pacl applies. - * If pacl doesn't apply, something above should have - * executed a continue, which will skip the follwing code. - */ - action = SecurityAllowOperation; - if (access_mode & SecurityReadAccess) - action = max(action, pacl->readAction); - if (access_mode & SecurityWriteAccess) - action = max(action, pacl->writeAction); - if (access_mode & SecurityDestroyAccess) - action = max(action, pacl->destroyAction); - break; - } /* end for each pacl */ - } /* end if propertyName <= SecurityMaxPropertyName */ - - if (SecurityAllowOperation != action) - { /* audit the access violation */ - int cid = CLIENT_ID(pWin->drawable.id); - int reqtype = ((xReq *)client->requestBuffer)->reqType; - char *actionstr = (SecurityIgnoreOperation == action) ? - "ignored" : "error"; - SecurityAudit("client %d attempted request %d with window 0x%x property %s (atom 0x%x) of client %d, %s\n", - client->index, reqtype, pWin->drawable.id, - NameForAtom(propertyName), propertyName, cid, actionstr); - } - return action; -} /* SecurityCheckPropertyAccess */ - - -/* SecurityResetProc - * - * Arguments: - * extEntry is the extension information for the security extension. - * - * Returns: nothing. - * - * Side Effects: - * Performs any cleanup needed by Security at server shutdown time. - */ - -static void -SecurityResetProc( - ExtensionEntry *extEntry) -{ - SecurityFreePropertyAccessList(); - SecurityFreeSitePolicyStrings(); -} /* SecurityResetProc */ - - -int -XSecurityOptions(argc, argv, i) - int argc; - char **argv; - int i; -{ - if (strcmp(argv[i], "-sp") == 0) - { - if (i < argc) - SecurityPolicyFile = argv[++i]; - return (i + 1); - } - return (i); -} /* XSecurityOptions */ - - - -/* SecurityExtensionInit - * - * Arguments: none. - * - * Returns: nothing. - * - * Side Effects: - * Enables the Security extension if possible. - */ - -void -SecurityExtensionInit(INITARGS) -{ - ExtensionEntry *extEntry; - int i; - - SecurityAuthorizationResType = - CreateNewResourceType(SecurityDeleteAuthorization); - - RTEventClient = CreateNewResourceType( - SecurityDeleteAuthorizationEventClient); - - if (!SecurityAuthorizationResType || !RTEventClient) - return; - - RTEventClient |= RC_NEVERRETAIN; - - if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL)) - return; - - extEntry = AddExtension(SECURITY_EXTENSION_NAME, - XSecurityNumberEvents, XSecurityNumberErrors, - ProcSecurityDispatch, SProcSecurityDispatch, - SecurityResetProc, StandardMinorOpcode); - - SecurityErrorBase = extEntry->errorBase; - SecurityEventBase = extEntry->eventBase; - - EventSwapVector[SecurityEventBase + XSecurityAuthorizationRevoked] = - (EventSwapPtr)SwapSecurityAuthorizationRevokedEvent; - - /* initialize untrusted proc vectors */ - - for (i = 0; i < 128; i++) - { - UntrustedProcVector[i] = ProcVector[i]; - SwappedUntrustedProcVector[i] = SwappedProcVector[i]; - } - - /* make sure insecure extensions are not allowed */ - - for (i = 128; i < 256; i++) - { - if (!UntrustedProcVector[i]) - { - UntrustedProcVector[i] = ProcBadRequest; - SwappedUntrustedProcVector[i] = ProcBadRequest; - } - } - - SecurityLoadPropertyAccessList(); - -} /* SecurityExtensionInit */ diff --git a/nx-X11/programs/Xserver/Xext/security.c.X.original b/nx-X11/programs/Xserver/Xext/security.c.X.original deleted file mode 100644 index c6a516733..000000000 --- a/nx-X11/programs/Xserver/Xext/security.c.X.original +++ /dev/null @@ -1,2008 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/Xext/security.c,v 1.5 2005/07/03 07:01:04 daniels Exp $ */ -/* $Xorg: security.c,v 1.4 2001/02/09 02:04:32 xorgcvs Exp $ */ -/* - -Copyright 1996, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -*/ -/* $XFree86: xc/programs/Xserver/Xext/security.c,v 1.16tsi Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "dixstruct.h" -#include "extnsionst.h" -#include "windowstr.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "colormapst.h" -#include "propertyst.h" -#define _SECURITY_SERVER -#include -#include -#include -#ifdef LBX -#define _XLBX_SERVER_ -#include -extern unsigned char LbxReqCode; -#endif -#ifdef XAPPGROUP -#include -#endif -#include /* for file reading operations */ -#include /* for XA_STRING */ - -#ifndef DEFAULTPOLICYFILE -# define DEFAULTPOLICYFILE NULL -#endif -#if defined(WIN32) || defined(__CYGWIN__) -#include -#undef index -#endif - -#include "modinit.h" - -static int SecurityErrorBase; /* first Security error number */ -static int SecurityEventBase; /* first Security event number */ - -CallbackListPtr SecurityValidateGroupCallback = NULL; /* see security.h */ - -RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */ - -static RESTYPE RTEventClient; - -/* Proc vectors for untrusted clients, swapped and unswapped versions. - * These are the same as the normal proc vectors except that extensions - * that haven't declared themselves secure will have ProcBadRequest plugged - * in for their major opcode dispatcher. This prevents untrusted clients - * from guessing extension major opcodes and using the extension even though - * the extension can't be listed or queried. - */ -int (*UntrustedProcVector[256])( - ClientPtr /*client*/ -); -int (*SwappedUntrustedProcVector[256])( - ClientPtr /*client*/ -); - -/* SecurityAudit - * - * Arguments: - * format is the formatting string to be used to interpret the - * remaining arguments. - * - * Returns: nothing. - * - * Side Effects: - * Writes the message to the log file if security logging is on. - */ - -void -SecurityAudit(char *format, ...) -{ - va_list args; - - if (auditTrailLevel < SECURITY_AUDIT_LEVEL) - return; - va_start(args, format); - VAuditF(format, args); - va_end(args); -} /* SecurityAudit */ - -#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) - -/* SecurityDeleteAuthorization - * - * Arguments: - * value is the authorization to delete. - * id is its resource ID. - * - * Returns: Success. - * - * Side Effects: - * Frees everything associated with the authorization. - */ - -static int -SecurityDeleteAuthorization( - pointer value, - XID id) -{ - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value; - unsigned short name_len, data_len; - char *name, *data; - int status; - int i; - OtherClientsPtr pEventClient; - - /* Remove the auth using the os layer auth manager */ - - status = AuthorizationFromID(pAuth->id, &name_len, &name, - &data_len, &data); - assert(status); - status = RemoveAuthorization(name_len, name, data_len, data); - assert(status); - (void)status; - - /* free the auth timer if there is one */ - - if (pAuth->timer) TimerFree(pAuth->timer); - - /* send revoke events */ - - while ((pEventClient = pAuth->eventClients)) - { - /* send revocation event event */ - ClientPtr client = rClient(pEventClient); - - if (!client->clientGone) - { - xSecurityAuthorizationRevokedEvent are; - are.type = SecurityEventBase + XSecurityAuthorizationRevoked; - are.sequenceNumber = client->sequence; - are.authId = pAuth->id; - WriteEventsToClient(client, 1, (xEvent *)&are); - } - FreeResource(pEventClient->resource, RT_NONE); - } - - /* kill all clients using this auth */ - - for (i = 1; iauthId == pAuth->id)) - CloseDownClient(clients[i]); - } - - SecurityAudit("revoked authorization ID %d\n", pAuth->id); - xfree(pAuth); - return Success; - -} /* SecurityDeleteAuthorization */ - - -/* resource delete function for RTEventClient */ -static int -SecurityDeleteAuthorizationEventClient( - pointer value, - XID id) -{ - OtherClientsPtr pEventClient, prev = NULL; - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value; - - for (pEventClient = pAuth->eventClients; - pEventClient; - pEventClient = pEventClient->next) - { - if (pEventClient->resource == id) - { - if (prev) - prev->next = pEventClient->next; - else - pAuth->eventClients = pEventClient->next; - xfree(pEventClient); - return(Success); - } - prev = pEventClient; - } - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} /* SecurityDeleteAuthorizationEventClient */ - - -/* SecurityComputeAuthorizationTimeout - * - * Arguments: - * pAuth is the authorization for which we are computing the timeout - * seconds is the number of seconds we want to wait - * - * Returns: - * the number of milliseconds that the auth timer should be set to - * - * Side Effects: - * Sets pAuth->secondsRemaining to any "overflow" amount of time - * that didn't fit in 32 bits worth of milliseconds - */ - -static CARD32 -SecurityComputeAuthorizationTimeout( - SecurityAuthorizationPtr pAuth, - unsigned int seconds) -{ - /* maxSecs is the number of full seconds that can be expressed in - * 32 bits worth of milliseconds - */ - CARD32 maxSecs = (CARD32)(~0) / (CARD32)MILLI_PER_SECOND; - - if (seconds > maxSecs) - { /* only come here if we want to wait more than 49 days */ - pAuth->secondsRemaining = seconds - maxSecs; - return maxSecs * MILLI_PER_SECOND; - } - else - { /* by far the common case */ - pAuth->secondsRemaining = 0; - return seconds * MILLI_PER_SECOND; - } -} /* SecurityStartAuthorizationTimer */ - -/* SecurityAuthorizationExpired - * - * This function is passed as an argument to TimerSet and gets called from - * the timer manager in the os layer when its time is up. - * - * Arguments: - * timer is the timer for this authorization. - * time is the current time. - * pval is the authorization whose time is up. - * - * Returns: - * A new time delay in milliseconds if the timer should wait some - * more, else zero. - * - * Side Effects: - * Frees the authorization resource if the timeout period is really - * over, otherwise recomputes pAuth->secondsRemaining. - */ - -static CARD32 -SecurityAuthorizationExpired( - OsTimerPtr timer, - CARD32 time, - pointer pval) -{ - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)pval; - - assert(pAuth->timer == timer); - - if (pAuth->secondsRemaining) - { - return SecurityComputeAuthorizationTimeout(pAuth, - pAuth->secondsRemaining); - } - else - { - FreeResource(pAuth->id, RT_NONE); - return 0; - } -} /* SecurityAuthorizationExpired */ - -/* SecurityStartAuthorizationTimer - * - * Arguments: - * pAuth is the authorization whose timer should be started. - * - * Returns: nothing. - * - * Side Effects: - * A timer is started, set to expire after the timeout period for - * this authorization. When it expires, the function - * SecurityAuthorizationExpired will be called. - */ - -static void -SecurityStartAuthorizationTimer( - SecurityAuthorizationPtr pAuth) -{ - pAuth->timer = TimerSet(pAuth->timer, 0, - SecurityComputeAuthorizationTimeout(pAuth, pAuth->timeout), - SecurityAuthorizationExpired, pAuth); -} /* SecurityStartAuthorizationTimer */ - - -/* Proc functions all take a client argument, execute the request in - * client->requestBuffer, and return a protocol error status. - */ - -static int -ProcSecurityQueryVersion( - ClientPtr client) -{ - /* REQUEST(xSecurityQueryVersionReq); */ - xSecurityQueryVersionReply rep; - - /* paranoia: this "can't happen" because this extension is hidden - * from untrusted clients, but just in case... - */ - if (client->trustLevel != XSecurityClientTrusted) - return BadRequest; - - REQUEST_SIZE_MATCH(xSecurityQueryVersionReq); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.majorVersion = SECURITY_MAJOR_VERSION; - rep.minorVersion = SECURITY_MINOR_VERSION; - if(client->swapped) - { - register char n; - swaps(&rep.sequenceNumber, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - } - (void)WriteToClient(client, SIZEOF(xSecurityQueryVersionReply), - (char *)&rep); - return (client->noClientException); -} /* ProcSecurityQueryVersion */ - - -static int -SecurityEventSelectForAuthorization( - SecurityAuthorizationPtr pAuth, - ClientPtr client, - Mask mask) -{ - OtherClients *pEventClient; - - for (pEventClient = pAuth->eventClients; - pEventClient; - pEventClient = pEventClient->next) - { - if (SameClient(pEventClient, client)) - { - if (mask == 0) - FreeResource(pEventClient->resource, RT_NONE); - else - pEventClient->mask = mask; - return Success; - } - } - - pEventClient = (OtherClients *) xalloc(sizeof(OtherClients)); - if (!pEventClient) - return BadAlloc; - pEventClient->mask = mask; - pEventClient->resource = FakeClientID(client->index); - pEventClient->next = pAuth->eventClients; - if (!AddResource(pEventClient->resource, RTEventClient, - (pointer)pAuth)) - { - xfree(pEventClient); - return BadAlloc; - } - pAuth->eventClients = pEventClient; - - return Success; -} /* SecurityEventSelectForAuthorization */ - - -static int -ProcSecurityGenerateAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityGenerateAuthorizationReq); - int len; /* request length in CARD32s*/ - Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */ - SecurityAuthorizationPtr pAuth = NULL; /* auth we are creating */ - int err; /* error to return from this function */ - XID authId; /* authorization ID assigned by os layer */ - xSecurityGenerateAuthorizationReply rep; /* reply struct */ - unsigned int trustLevel; /* trust level of new auth */ - XID group; /* group of new auth */ - CARD32 timeout; /* timeout of new auth */ - CARD32 *values; /* list of supplied attributes */ - char *protoname; /* auth proto name sent in request */ - char *protodata; /* auth proto data sent in request */ - unsigned int authdata_len; /* # bytes of generated auth data */ - char *pAuthdata; /* generated auth data */ - Mask eventMask; /* what events on this auth does client want */ - - /* paranoia: this "can't happen" because this extension is hidden - * from untrusted clients, but just in case... - */ - if (client->trustLevel != XSecurityClientTrusted) - return BadRequest; - - /* check request length */ - - REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq); - len = SIZEOF(xSecurityGenerateAuthorizationReq) >> 2; - len += (stuff->nbytesAuthProto + (unsigned)3) >> 2; - len += (stuff->nbytesAuthData + (unsigned)3) >> 2; - values = ((CARD32 *)stuff) + len; - len += Ones(stuff->valueMask); - if (client->req_len != len) - return BadLength; - - /* check valuemask */ - if (stuff->valueMask & ~XSecurityAllAuthorizationAttributes) - { - client->errorValue = stuff->valueMask; - return BadValue; - } - - /* check timeout */ - timeout = 60; - if (stuff->valueMask & XSecurityTimeout) - { - timeout = *values++; - } - - /* check trustLevel */ - trustLevel = XSecurityClientUntrusted; - if (stuff->valueMask & XSecurityTrustLevel) - { - trustLevel = *values++; - if (trustLevel != XSecurityClientTrusted && - trustLevel != XSecurityClientUntrusted) - { - client->errorValue = trustLevel; - return BadValue; - } - } - - /* check group */ - group = None; - if (stuff->valueMask & XSecurityGroup) - { - group = *values++; - if (SecurityValidateGroupCallback) - { - SecurityValidateGroupInfoRec vgi; - vgi.group = group; - vgi.valid = FALSE; - CallCallbacks(&SecurityValidateGroupCallback, (pointer)&vgi); - - /* if nobody said they recognized it, it's an error */ - - if (!vgi.valid) - { - client->errorValue = group; - return BadValue; - } - } - } - - /* check event mask */ - eventMask = 0; - if (stuff->valueMask & XSecurityEventMask) - { - eventMask = *values++; - if (eventMask & ~XSecurityAllEventMasks) - { - client->errorValue = eventMask; - return BadValue; - } - } - - protoname = (char *)&stuff[1]; - protodata = protoname + ((stuff->nbytesAuthProto + (unsigned)3) >> 2); - - /* call os layer to generate the authorization */ - - authId = GenerateAuthorization(stuff->nbytesAuthProto, protoname, - stuff->nbytesAuthData, protodata, - &authdata_len, &pAuthdata); - if ((XID) ~0L == authId) - { - err = SecurityErrorBase + XSecurityBadAuthorizationProtocol; - goto bailout; - } - - /* now that we've added the auth, remember to remove it if we have to - * abort the request for some reason (like allocation failure) - */ - removeAuth = TRUE; - - /* associate additional information with this auth ID */ - - pAuth = (SecurityAuthorizationPtr)xalloc(sizeof(SecurityAuthorizationRec)); - if (!pAuth) - { - err = BadAlloc; - goto bailout; - } - - /* fill in the auth fields */ - - pAuth->id = authId; - pAuth->timeout = timeout; - pAuth->group = group; - pAuth->trustLevel = trustLevel; - pAuth->refcnt = 0; /* the auth was just created; nobody's using it yet */ - pAuth->secondsRemaining = 0; - pAuth->timer = NULL; - pAuth->eventClients = NULL; - - /* handle event selection */ - if (eventMask) - { - err = SecurityEventSelectForAuthorization(pAuth, client, eventMask); - if (err != Success) - goto bailout; - } - - if (!AddResource(authId, SecurityAuthorizationResType, pAuth)) - { - err = BadAlloc; - goto bailout; - } - - /* start the timer ticking */ - - if (pAuth->timeout != 0) - SecurityStartAuthorizationTimer(pAuth); - - /* tell client the auth id and data */ - - rep.type = X_Reply; - rep.length = (authdata_len + 3) >> 2; - rep.sequenceNumber = client->sequence; - rep.authId = authId; - rep.dataLength = authdata_len; - - if (client->swapped) - { - register char n; - swapl(&rep.length, n); - swaps(&rep.sequenceNumber, n); - swapl(&rep.authId, n); - swaps(&rep.dataLength, n); - } - - WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply), - (char *)&rep); - WriteToClient(client, authdata_len, pAuthdata); - - SecurityAudit("client %d generated authorization %d trust %d timeout %d group %d events %d\n", - client->index, pAuth->id, pAuth->trustLevel, pAuth->timeout, - pAuth->group, eventMask); - - /* the request succeeded; don't call RemoveAuthorization or free pAuth */ - - removeAuth = FALSE; - pAuth = NULL; - err = client->noClientException; - -bailout: - if (removeAuth) - RemoveAuthorization(stuff->nbytesAuthProto, protoname, - authdata_len, pAuthdata); - if (pAuth) xfree(pAuth); - return err; - -} /* ProcSecurityGenerateAuthorization */ - -static int -ProcSecurityRevokeAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityRevokeAuthorizationReq); - SecurityAuthorizationPtr pAuth; - - /* paranoia: this "can't happen" because this extension is hidden - * from untrusted clients, but just in case... - */ - if (client->trustLevel != XSecurityClientTrusted) - return BadRequest; - - REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq); - - pAuth = (SecurityAuthorizationPtr)SecurityLookupIDByType(client, - stuff->authId, SecurityAuthorizationResType, SecurityDestroyAccess); - if (!pAuth) - return SecurityErrorBase + XSecurityBadAuthorization; - - FreeResource(stuff->authId, RT_NONE); - return Success; -} /* ProcSecurityRevokeAuthorization */ - - -static int -ProcSecurityDispatch( - ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) - { - case X_SecurityQueryVersion: - return ProcSecurityQueryVersion(client); - case X_SecurityGenerateAuthorization: - return ProcSecurityGenerateAuthorization(client); - case X_SecurityRevokeAuthorization: - return ProcSecurityRevokeAuthorization(client); - default: - return BadRequest; - } -} /* ProcSecurityDispatch */ - -static int -SProcSecurityQueryVersion( - ClientPtr client) -{ - REQUEST(xSecurityQueryVersionReq); - register char n; - - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xSecurityQueryVersionReq); - swaps(&stuff->majorVersion, n); - swaps(&stuff->minorVersion,n); - return ProcSecurityQueryVersion(client); -} /* SProcSecurityQueryVersion */ - - -static int -SProcSecurityGenerateAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityGenerateAuthorizationReq); - register char n; - CARD32 *values; - unsigned long nvalues; - int values_offset; - - swaps(&stuff->length, n); - REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq); - swaps(&stuff->nbytesAuthProto, n); - swaps(&stuff->nbytesAuthData, n); - swapl(&stuff->valueMask, n); - values_offset = ((stuff->nbytesAuthProto + (unsigned)3) >> 2) + - ((stuff->nbytesAuthData + (unsigned)3) >> 2); - if (values_offset > - stuff->length - (sz_xSecurityGenerateAuthorizationReq >> 2)) - return BadLength; - values = (CARD32 *)(&stuff[1]) + values_offset; - nvalues = (((CARD32 *)stuff) + stuff->length) - values; - SwapLongs(values, nvalues); - return ProcSecurityGenerateAuthorization(client); -} /* SProcSecurityGenerateAuthorization */ - - -static int -SProcSecurityRevokeAuthorization( - ClientPtr client) -{ - REQUEST(xSecurityRevokeAuthorizationReq); - register char n; - - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq); - swapl(&stuff->authId, n); - return ProcSecurityRevokeAuthorization(client); -} /* SProcSecurityRevokeAuthorization */ - - -static int -SProcSecurityDispatch( - ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) - { - case X_SecurityQueryVersion: - return SProcSecurityQueryVersion(client); - case X_SecurityGenerateAuthorization: - return SProcSecurityGenerateAuthorization(client); - case X_SecurityRevokeAuthorization: - return SProcSecurityRevokeAuthorization(client); - default: - return BadRequest; - } -} /* SProcSecurityDispatch */ - -static void -SwapSecurityAuthorizationRevokedEvent( - xSecurityAuthorizationRevokedEvent *from, - xSecurityAuthorizationRevokedEvent *to) -{ - to->type = from->type; - to->detail = from->detail; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->authId, to->authId); -} - -/* SecurityDetermineEventPropogationLimits - * - * This is a helper function for SecurityCheckDeviceAccess. - * - * Arguments: - * dev is the device for which the starting and stopping windows for - * event propogation should be determined. - * The values pointed to by ppWin and ppStopWin are not used. - * - * Returns: - * ppWin is filled in with a pointer to the window at which event - * propogation for the given device should start given the current - * state of the server (pointer position, window layout, etc.) - * ppStopWin is filled in with the window at which event propogation - * should stop; events should not go to ppStopWin. - * - * Side Effects: none. - */ - -static void -SecurityDetermineEventPropogationLimits( - DeviceIntPtr dev, - WindowPtr *ppWin, - WindowPtr *ppStopWin) -{ - WindowPtr pFocusWin = dev->focus ? dev->focus->win : NoneWin; - - if (pFocusWin == NoneWin) - { /* no focus -- events don't go anywhere */ - *ppWin = *ppStopWin = NULL; - return; - } - - if (pFocusWin == PointerRootWin) - { /* focus follows the pointer */ - *ppWin = GetSpriteWindow(); - *ppStopWin = NULL; /* propogate all the way to the root */ - } - else - { /* a real window is set for the focus */ - WindowPtr pSpriteWin = GetSpriteWindow(); - *ppStopWin = pFocusWin->parent; /* don't go past the focus window */ - - /* if the pointer is in a subwindow of the focus window, start - * at that subwindow, else start at the focus window itself - */ - if (IsParent(pFocusWin, pSpriteWin)) - *ppWin = pSpriteWin; - else *ppWin = pFocusWin; - } -} /* SecurityDetermineEventPropogationLimits */ - - -/* SecurityCheckDeviceAccess - * - * Arguments: - * client is the client attempting to access a device. - * dev is the device being accessed. - * fromRequest is TRUE if the device access is a direct result of - * the client executing some request and FALSE if it is a - * result of the server trying to send an event (e.g. KeymapNotify) - * to the client. - * Returns: - * TRUE if the device access should be allowed, else FALSE. - * - * Side Effects: - * An audit message is generated if access is denied. - */ - -Bool -SecurityCheckDeviceAccess(client, dev, fromRequest) - ClientPtr client; - DeviceIntPtr dev; - Bool fromRequest; -{ - WindowPtr pWin, pStopWin; - Bool untrusted_got_event; - Bool found_event_window; - Mask eventmask; - int reqtype = 0; - - /* trusted clients always allowed to do anything */ - if (client->trustLevel == XSecurityClientTrusted) - return TRUE; - - /* device security other than keyboard is not implemented yet */ - if (dev != inputInfo.keyboard) - return TRUE; - - /* some untrusted client wants access */ - - if (fromRequest) - { - reqtype = ((xReq *)client->requestBuffer)->reqType; - switch (reqtype) - { - /* never allow these */ - case X_ChangeKeyboardMapping: - case X_ChangeKeyboardControl: - case X_SetModifierMapping: - SecurityAudit("client %d attempted request %d\n", - client->index, reqtype); - return FALSE; - default: - break; - } - } - - untrusted_got_event = FALSE; - found_event_window = FALSE; - - if (dev->grab) - { - untrusted_got_event = - ((rClient(dev->grab))->trustLevel != XSecurityClientTrusted); - } - else - { - SecurityDetermineEventPropogationLimits(dev, &pWin, &pStopWin); - - eventmask = KeyPressMask | KeyReleaseMask; - while ( (pWin != pStopWin) && !found_event_window) - { - OtherClients *other; - - if (pWin->eventMask & eventmask) - { - found_event_window = TRUE; - client = wClient(pWin); - if (client->trustLevel != XSecurityClientTrusted) - { - untrusted_got_event = TRUE; - } - } - if (wOtherEventMasks(pWin) & eventmask) - { - found_event_window = TRUE; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & eventmask) - { - client = rClient(other); - if (client->trustLevel != XSecurityClientTrusted) - { - untrusted_got_event = TRUE; - break; - } - } - } - } - if (wDontPropagateMask(pWin) & eventmask) - break; - pWin = pWin->parent; - } /* while propogating the event */ - } - - /* allow access by untrusted clients only if an event would have gone - * to an untrusted client - */ - - if (!untrusted_got_event) - { - char *devname = dev->name; - if (!devname) devname = "unnamed"; - if (fromRequest) - SecurityAudit("client %d attempted request %d device %d (%s)\n", - client->index, reqtype, dev->id, devname); - else - SecurityAudit("client %d attempted to access device %d (%s)\n", - client->index, dev->id, devname); - } - return untrusted_got_event; -} /* SecurityCheckDeviceAccess */ - - - -/* SecurityAuditResourceIDAccess - * - * Arguments: - * client is the client doing the resource access. - * id is the resource id. - * - * Returns: NULL - * - * Side Effects: - * An audit message is generated with details of the denied - * resource access. - */ - -static pointer -SecurityAuditResourceIDAccess( - ClientPtr client, - XID id) -{ - int cid = CLIENT_ID(id); - int reqtype = ((xReq *)client->requestBuffer)->reqType; - switch (reqtype) - { - case X_ChangeProperty: - case X_DeleteProperty: - case X_GetProperty: - { - xChangePropertyReq *req = - (xChangePropertyReq *)client->requestBuffer; - int propertyatom = req->property; - char *propertyname = NameForAtom(propertyatom); - - SecurityAudit("client %d attempted request %d with window 0x%x property %s of client %d\n", - client->index, reqtype, id, propertyname, cid); - break; - } - default: - { - SecurityAudit("client %d attempted request %d with resource 0x%x of client %d\n", - client->index, reqtype, id, cid); - break; - } - } - return NULL; -} /* SecurityAuditResourceIDAccess */ - - -/* SecurityCheckResourceIDAccess - * - * This function gets plugged into client->CheckAccess and is called from - * SecurityLookupIDByType/Class to determine if the client can access the - * resource. - * - * Arguments: - * client is the client doing the resource access. - * id is the resource id. - * rtype is its type or class. - * access_mode represents the intended use of the resource; see - * resource.h. - * rval is a pointer to the resource structure for this resource. - * - * Returns: - * If access is granted, the value of rval that was passed in, else NULL. - * - * Side Effects: - * Disallowed resource accesses are audited. - */ - -static pointer -SecurityCheckResourceIDAccess( - ClientPtr client, - XID id, - RESTYPE rtype, - Mask access_mode, - pointer rval) -{ - int cid = CLIENT_ID(id); - int reqtype = ((xReq *)client->requestBuffer)->reqType; - - if (SecurityUnknownAccess == access_mode) - return rval; /* for compatibility, we have to allow access */ - - switch (reqtype) - { /* these are always allowed */ - case X_QueryTree: - case X_TranslateCoords: - case X_GetGeometry: - /* property access is controlled in SecurityCheckPropertyAccess */ - case X_GetProperty: - case X_ChangeProperty: - case X_DeleteProperty: - case X_RotateProperties: - case X_ListProperties: - return rval; - default: - break; - } - - if (cid != 0) - { /* not a server-owned resource */ - /* - * The following 'if' restricts clients to only access resources at - * the same trustLevel. Since there are currently only two trust levels, - * and trusted clients never call this function, this degenerates into - * saying that untrusted clients can only access resources of other - * untrusted clients. One way to add the notion of groups would be to - * allow values other than Trusted (0) and Untrusted (1) for this field. - * Clients at the same trust level would be able to use each other's - * resources, but not those of clients at other trust levels. I haven't - * tried it, but this probably mostly works already. The obvious - * competing alternative for grouping clients for security purposes is to - * use app groups. dpw - */ - if (client->trustLevel == clients[cid]->trustLevel -#ifdef XAPPGROUP - || (RT_COLORMAP == rtype && - XagDefaultColormap (client) == (Colormap) id) -#endif - ) - return rval; - else - return SecurityAuditResourceIDAccess(client, id); - } - else /* server-owned resource - probably a default colormap or root window */ - { - if (RT_WINDOW == rtype || RC_DRAWABLE == rtype) - { - switch (reqtype) - { /* the following operations are allowed on root windows */ - case X_CreatePixmap: - case X_CreateGC: - case X_CreateWindow: - case X_CreateColormap: - case X_ListProperties: - case X_GrabPointer: - case X_UngrabButton: - case X_QueryBestSize: - case X_GetWindowAttributes: - break; - case X_SendEvent: - { /* see if it is an event specified by the ICCCM */ - xSendEventReq *req = (xSendEventReq *) - (client->requestBuffer); - if (req->propagate == xTrue - || - (req->eventMask != ColormapChangeMask && - req->eventMask != StructureNotifyMask && - req->eventMask != - (SubstructureRedirectMask|SubstructureNotifyMask) - ) - || - (req->event.u.u.type != UnmapNotify && - req->event.u.u.type != ConfigureRequest && - req->event.u.u.type != ClientMessage - ) - ) - { /* not an ICCCM event */ - return SecurityAuditResourceIDAccess(client, id); - } - break; - } /* case X_SendEvent on root */ - - case X_ChangeWindowAttributes: - { /* Allow selection of PropertyNotify and StructureNotify - * events on the root. - */ - xChangeWindowAttributesReq *req = - (xChangeWindowAttributesReq *)(client->requestBuffer); - if (req->valueMask == CWEventMask) - { - CARD32 value = *((CARD32 *)(req + 1)); - if ( (value & - ~(PropertyChangeMask|StructureNotifyMask)) == 0) - break; - } - return SecurityAuditResourceIDAccess(client, id); - } /* case X_ChangeWindowAttributes on root */ - - default: - { -#ifdef LBX - /* XXX really need per extension dispatching */ - if (reqtype == LbxReqCode) { - switch (((xReq *)client->requestBuffer)->data) { - case X_LbxGetProperty: - case X_LbxChangeProperty: - return rval; - default: - break; - } - } -#endif - /* others not allowed */ - return SecurityAuditResourceIDAccess(client, id); - } - } - } /* end server-owned window or drawable */ - else if (SecurityAuthorizationResType == rtype) - { - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)rval; - if (pAuth->trustLevel != client->trustLevel) - return SecurityAuditResourceIDAccess(client, id); - } - else if (RT_COLORMAP != rtype) - { /* don't allow anything else besides colormaps */ - return SecurityAuditResourceIDAccess(client, id); - } - } - return rval; -} /* SecurityCheckResourceIDAccess */ - - -/* SecurityClientStateCallback - * - * Arguments: - * pcbl is &ClientStateCallback. - * nullata is NULL. - * calldata is a pointer to a NewClientInfoRec (include/dixstruct.h) - * which contains information about client state changes. - * - * Returns: nothing. - * - * Side Effects: - * - * If a new client is connecting, its authorization ID is copied to - * client->authID. If this is a generated authorization, its reference - * count is bumped, its timer is cancelled if it was running, and its - * trustlevel is copied to client->trustLevel. - * - * If a client is disconnecting and the client was using a generated - * authorization, the authorization's reference count is decremented, and - * if it is now zero, the timer for this authorization is started. - */ - -static void -SecurityClientStateCallback( - CallbackListPtr *pcbl, - pointer nulldata, - pointer calldata) -{ - NewClientInfoRec *pci = (NewClientInfoRec *)calldata; - ClientPtr client = pci->client; - - switch (client->clientState) - { - case ClientStateRunning: - { - XID authId = AuthorizationIDOfClient(client); - SecurityAuthorizationPtr pAuth; - - client->authId = authId; - pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId, - SecurityAuthorizationResType); - if (pAuth) - { /* it is a generated authorization */ - pAuth->refcnt++; - if (pAuth->refcnt == 1) - { - if (pAuth->timer) TimerCancel(pAuth->timer); - } - client->trustLevel = pAuth->trustLevel; - if (client->trustLevel != XSecurityClientTrusted) - { - client->CheckAccess = SecurityCheckResourceIDAccess; - client->requestVector = client->swapped ? - SwappedUntrustedProcVector : UntrustedProcVector; - } - } - break; - } - case ClientStateGone: - case ClientStateRetained: /* client disconnected */ - { - XID authId = client->authId; - SecurityAuthorizationPtr pAuth; - - pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId, - SecurityAuthorizationResType); - if (pAuth) - { /* it is a generated authorization */ - pAuth->refcnt--; - if (pAuth->refcnt == 0) - { - SecurityStartAuthorizationTimer(pAuth); - } - } - break; - } - default: break; - } -} /* SecurityClientStateCallback */ - -#ifdef LBX -Bool -SecuritySameLevel(client, authId) - ClientPtr client; - XID authId; -{ - SecurityAuthorizationPtr pAuth; - - pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId, - SecurityAuthorizationResType); - if (pAuth) - return client->trustLevel == pAuth->trustLevel; - return client->trustLevel == XSecurityClientTrusted; -} -#endif - -/* SecurityCensorImage - * - * Called after pScreen->GetImage to prevent pieces or trusted windows from - * being returned in image data from an untrusted window. - * - * Arguments: - * client is the client doing the GetImage. - * pVisibleRegion is the visible region of the window. - * widthBytesLine is the width in bytes of one horizontal line in pBuf. - * pDraw is the source window. - * x, y, w, h is the rectangle of image data from pDraw in pBuf. - * format is the format of the image data in pBuf: ZPixmap or XYPixmap. - * pBuf is the image data. - * - * Returns: nothing. - * - * Side Effects: - * Any part of the rectangle (x, y, w, h) that is outside the visible - * region of the window will be destroyed (overwritten) in pBuf. - */ -void -SecurityCensorImage(client, pVisibleRegion, widthBytesLine, pDraw, x, y, w, h, - format, pBuf) - ClientPtr client; - RegionPtr pVisibleRegion; - long widthBytesLine; - DrawablePtr pDraw; - int x, y, w, h; - unsigned int format; - char * pBuf; -{ - ScreenPtr pScreen = pDraw->pScreen; - RegionRec imageRegion; /* region representing x,y,w,h */ - RegionRec censorRegion; /* region to obliterate */ - BoxRec imageBox; - int nRects; - - imageBox.x1 = x; - imageBox.y1 = y; - imageBox.x2 = x + w; - imageBox.y2 = y + h; - REGION_INIT(pScreen, &imageRegion, &imageBox, 1); - REGION_NULL(pScreen, &censorRegion); - - /* censorRegion = imageRegion - visibleRegion */ - REGION_SUBTRACT(pScreen, &censorRegion, &imageRegion, pVisibleRegion); - nRects = REGION_NUM_RECTS(&censorRegion); - if (nRects > 0) - { /* we have something to censor */ - GCPtr pScratchGC = NULL; - PixmapPtr pPix = NULL; - xRectangle *pRects = NULL; - Bool failed = FALSE; - int depth = 1; - int bitsPerPixel = 1; - int i; - BoxPtr pBox; - - /* convert region to list-of-rectangles for PolyFillRect */ - - pRects = (xRectangle *)ALLOCATE_LOCAL(nRects * sizeof(xRectangle *)); - if (!pRects) - { - failed = TRUE; - goto failSafe; - } - for (pBox = REGION_RECTS(&censorRegion), i = 0; - i < nRects; - i++, pBox++) - { - pRects[i].x = pBox->x1; - pRects[i].y = pBox->y1 - imageBox.y1; - pRects[i].width = pBox->x2 - pBox->x1; - pRects[i].height = pBox->y2 - pBox->y1; - } - - /* use pBuf as a fake pixmap */ - - if (format == ZPixmap) - { - depth = pDraw->depth; - bitsPerPixel = pDraw->bitsPerPixel; - } - - pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h, - depth, bitsPerPixel, - widthBytesLine, (pointer)pBuf); - if (!pPix) - { - failed = TRUE; - goto failSafe; - } - - pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen); - if (!pScratchGC) - { - failed = TRUE; - goto failSafe; - } - - ValidateGC(&pPix->drawable, pScratchGC); - (* pScratchGC->ops->PolyFillRect)(&pPix->drawable, - pScratchGC, nRects, pRects); - - failSafe: - if (failed) - { - /* Censoring was not completed above. To be safe, wipe out - * all the image data so that nothing trusted gets out. - */ - bzero(pBuf, (int)(widthBytesLine * h)); - } - if (pRects) DEALLOCATE_LOCAL(pRects); - if (pScratchGC) FreeScratchGC(pScratchGC); - if (pPix) FreeScratchPixmapHeader(pPix); - } - REGION_UNINIT(pScreen, &imageRegion); - REGION_UNINIT(pScreen, &censorRegion); -} /* SecurityCensorImage */ - -/**********************************************************************/ - -typedef struct _PropertyAccessRec { - ATOM name; - ATOM mustHaveProperty; - char *mustHaveValue; - char windowRestriction; -#define SecurityAnyWindow 0 -#define SecurityRootWindow 1 -#define SecurityWindowWithProperty 2 - char readAction; - char writeAction; - char destroyAction; - struct _PropertyAccessRec *next; -} PropertyAccessRec, *PropertyAccessPtr; - -static PropertyAccessPtr PropertyAccessList = NULL; -static char SecurityDefaultAction = SecurityErrorOperation; -static char *SecurityPolicyFile = DEFAULTPOLICYFILE; -static ATOM SecurityMaxPropertyName = 0; - -static char *SecurityKeywords[] = { -#define SecurityKeywordComment 0 - "#", -#define SecurityKeywordProperty 1 - "property", -#define SecurityKeywordSitePolicy 2 - "sitepolicy", -#define SecurityKeywordRoot 3 - "root", -#define SecurityKeywordAny 4 - "any" -}; - -#define NUMKEYWORDS (sizeof(SecurityKeywords) / sizeof(char *)) - -#undef PROPDEBUG -/*#define PROPDEBUG 1*/ - -static void -SecurityFreePropertyAccessList(void) -{ - while (PropertyAccessList) - { - PropertyAccessPtr freeit = PropertyAccessList; - PropertyAccessList = PropertyAccessList->next; - xfree(freeit); - } -} /* SecurityFreePropertyAccessList */ - -#ifndef __UNIXOS2__ -#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') ) -#else -#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') ) -#endif - -static char * -SecuritySkipWhitespace( - char *p) -{ - while (SecurityIsWhitespace(*p)) - p++; - return p; -} /* SecuritySkipWhitespace */ - - -static char * -SecurityParseString( - char **rest) -{ - char *startOfString; - char *s = *rest; - char endChar = 0; - - s = SecuritySkipWhitespace(s); - - if (*s == '"' || *s == '\'') - { - endChar = *s++; - startOfString = s; - while (*s && (*s != endChar)) - s++; - } - else - { - startOfString = s; - while (*s && !SecurityIsWhitespace(*s)) - s++; - } - if (*s) - { - *s = '\0'; - *rest = s + 1; - return startOfString; - } - else - { - *rest = s; - return (endChar) ? NULL : startOfString; - } -} /* SecurityParseString */ - - -static int -SecurityParseKeyword( - char **p) -{ - int i; - char *s = *p; - s = SecuritySkipWhitespace(s); - for (i = 0; i < NUMKEYWORDS; i++) - { - int len = strlen(SecurityKeywords[i]); - if (strncmp(s, SecurityKeywords[i], len) == 0) - { - *p = s + len; - return (i); - } - } - *p = s; - return -1; -} /* SecurityParseKeyword */ - - -static Bool -SecurityParsePropertyAccessRule( - char *p) -{ - char *propname; - char c; - char action = SecurityDefaultAction; - char readAction, writeAction, destroyAction; - PropertyAccessPtr pacl, prev, cur; - char *mustHaveProperty = NULL; - char *mustHaveValue = NULL; - Bool invalid; - char windowRestriction; - int size; - int keyword; - - /* get property name */ - propname = SecurityParseString(&p); - if (!propname || (strlen(propname) == 0)) - return FALSE; - - /* get window on which property must reside for rule to apply */ - - keyword = SecurityParseKeyword(&p); - if (keyword == SecurityKeywordRoot) - windowRestriction = SecurityRootWindow; - else if (keyword == SecurityKeywordAny) - windowRestriction = SecurityAnyWindow; - else /* not root or any, must be a property name */ - { - mustHaveProperty = SecurityParseString(&p); - if (!mustHaveProperty || (strlen(mustHaveProperty) == 0)) - return FALSE; - windowRestriction = SecurityWindowWithProperty; - p = SecuritySkipWhitespace(p); - if (*p == '=') - { /* property value is specified too */ - p++; /* skip over '=' */ - mustHaveValue = SecurityParseString(&p); - if (!mustHaveValue) - return FALSE; - } - } - - /* get operations and actions */ - - invalid = FALSE; - readAction = writeAction = destroyAction = SecurityDefaultAction; - while ( (c = *p++) && !invalid) - { - switch (c) - { - case 'i': action = SecurityIgnoreOperation; break; - case 'a': action = SecurityAllowOperation; break; - case 'e': action = SecurityErrorOperation; break; - - case 'r': readAction = action; break; - case 'w': writeAction = action; break; - case 'd': destroyAction = action; break; - - default : - if (!SecurityIsWhitespace(c)) - invalid = TRUE; - break; - } - } - if (invalid) - return FALSE; - - /* We've successfully collected all the information needed for this - * property access rule. Now record it in a PropertyAccessRec. - */ - size = sizeof(PropertyAccessRec); - - /* If there is a property value string, allocate space for it - * right after the PropertyAccessRec. - */ - if (mustHaveValue) - size += strlen(mustHaveValue) + 1; - pacl = (PropertyAccessPtr)Xalloc(size); - if (!pacl) - return FALSE; - - pacl->name = MakeAtom(propname, strlen(propname), TRUE); - if (pacl->name == BAD_RESOURCE) - { - Xfree(pacl); - return FALSE; - } - if (mustHaveProperty) - { - pacl->mustHaveProperty = MakeAtom(mustHaveProperty, - strlen(mustHaveProperty), TRUE); - if (pacl->mustHaveProperty == BAD_RESOURCE) - { - Xfree(pacl); - return FALSE; - } - } - else - pacl->mustHaveProperty = 0; - - if (mustHaveValue) - { - pacl->mustHaveValue = (char *)(pacl + 1); - strcpy(pacl->mustHaveValue, mustHaveValue); - } - else - pacl->mustHaveValue = NULL; - - SecurityMaxPropertyName = max(SecurityMaxPropertyName, pacl->name); - - pacl->windowRestriction = windowRestriction; - pacl->readAction = readAction; - pacl->writeAction = writeAction; - pacl->destroyAction = destroyAction; - - /* link the new rule into the list of rules in order of increasing - * property name (atom) value to make searching easier - */ - - for (prev = NULL, cur = PropertyAccessList; - cur && cur->name <= pacl->name; - prev = cur, cur = cur->next) - ; - if (!prev) - { - pacl->next = cur; - PropertyAccessList = pacl; - } - else - { - prev->next = pacl; - pacl->next = cur; - } - return TRUE; -} /* SecurityParsePropertyAccessRule */ - -static char **SecurityPolicyStrings = NULL; -static int nSecurityPolicyStrings = 0; - -static Bool -SecurityParseSitePolicy( - char *p) -{ - char *policyStr = SecurityParseString(&p); - char *copyPolicyStr; - char **newStrings; - - if (!policyStr) - return FALSE; - - copyPolicyStr = (char *)Xalloc(strlen(policyStr) + 1); - if (!copyPolicyStr) - return TRUE; - strcpy(copyPolicyStr, policyStr); - newStrings = (char **)Xrealloc(SecurityPolicyStrings, - sizeof (char *) * (nSecurityPolicyStrings + 1)); - if (!newStrings) - { - Xfree(copyPolicyStr); - return TRUE; - } - - SecurityPolicyStrings = newStrings; - SecurityPolicyStrings[nSecurityPolicyStrings++] = copyPolicyStr; - - return TRUE; - -} /* SecurityParseSitePolicy */ - - -char ** -SecurityGetSitePolicyStrings(n) - int *n; -{ - *n = nSecurityPolicyStrings; - return SecurityPolicyStrings; -} /* SecurityGetSitePolicyStrings */ - -static void -SecurityFreeSitePolicyStrings(void) -{ - if (SecurityPolicyStrings) - { - assert(nSecurityPolicyStrings); - while (nSecurityPolicyStrings--) - { - Xfree(SecurityPolicyStrings[nSecurityPolicyStrings]); - } - Xfree(SecurityPolicyStrings); - SecurityPolicyStrings = NULL; - nSecurityPolicyStrings = 0; - } -} /* SecurityFreeSitePolicyStrings */ - - -static void -SecurityLoadPropertyAccessList(void) -{ - FILE *f; - int lineNumber = 0; - - SecurityMaxPropertyName = 0; - - if (!SecurityPolicyFile) - return; - -#ifndef __UNIXOS2__ - f = Fopen(SecurityPolicyFile, "r"); -#else - f = Fopen((char*)__XOS2RedirRoot(SecurityPolicyFile), "r"); -#endif - if (!f) - { - ErrorF("error opening security policy file %s\n", - SecurityPolicyFile); - return; - } - - while (!feof(f)) - { - char buf[200]; - Bool validLine; - char *p; - - if (!(p = fgets(buf, sizeof(buf), f))) - break; - lineNumber++; - - /* if first line, check version number */ - if (lineNumber == 1) - { - char *v = SecurityParseString(&p); - if (strcmp(v, SECURITY_POLICY_FILE_VERSION) != 0) - { - ErrorF("%s: invalid security policy file version, ignoring file\n", - SecurityPolicyFile); - break; - } - validLine = TRUE; - } - else - { - switch (SecurityParseKeyword(&p)) - { - case SecurityKeywordComment: - validLine = TRUE; - break; - - case SecurityKeywordProperty: - validLine = SecurityParsePropertyAccessRule(p); - break; - - case SecurityKeywordSitePolicy: - validLine = SecurityParseSitePolicy(p); - break; - - default: - validLine = (*p == '\0'); /* blank lines OK, others not */ - break; - } - } - - if (!validLine) - ErrorF("Line %d of %s invalid, ignoring\n", - lineNumber, SecurityPolicyFile); - } /* end while more input */ - -#ifdef PROPDEBUG - { - PropertyAccessPtr pacl; - char *op = "aie"; - for (pacl = PropertyAccessList; pacl; pacl = pacl->next) - { - ErrorF("property %s ", NameForAtom(pacl->name)); - switch (pacl->windowRestriction) - { - case SecurityAnyWindow: ErrorF("any "); break; - case SecurityRootWindow: ErrorF("root "); break; - case SecurityWindowWithProperty: - { - ErrorF("%s ", NameForAtom(pacl->mustHaveProperty)); - if (pacl->mustHaveValue) - ErrorF(" = \"%s\" ", pacl->mustHaveValue); - - } - break; - } - ErrorF("%cr %cw %cd\n", op[pacl->readAction], - op[pacl->writeAction], op[pacl->destroyAction]); - } - } -#endif /* PROPDEBUG */ - - Fclose(f); -} /* SecurityLoadPropertyAccessList */ - - -static Bool -SecurityMatchString( - char *ws, - char *cs) -{ - while (*ws && *cs) - { - if (*ws == '*') - { - Bool match = FALSE; - ws++; - while (!(match = SecurityMatchString(ws, cs)) && *cs) - { - cs++; - } - return match; - } - else if (*ws == *cs) - { - ws++; - cs++; - } - else break; - } - return ( ( (*ws == '\0') || ((*ws == '*') && *(ws+1) == '\0') ) - && (*cs == '\0') ); -} /* SecurityMatchString */ - -#ifdef PROPDEBUG -#include -#include -#endif - - -char -SecurityCheckPropertyAccess(client, pWin, propertyName, access_mode) - ClientPtr client; - WindowPtr pWin; - ATOM propertyName; - Mask access_mode; -{ - PropertyAccessPtr pacl; - char action = SecurityDefaultAction; - - /* if client trusted or window untrusted, allow operation */ - - if ( (client->trustLevel == XSecurityClientTrusted) || - (wClient(pWin)->trustLevel != XSecurityClientTrusted) ) - return SecurityAllowOperation; - -#ifdef PROPDEBUG - /* For testing, it's more convenient if the property rules file gets - * reloaded whenever it changes, so we can rapidly try things without - * having to reset the server. - */ - { - struct stat buf; - static time_t lastmod = 0; - int ret = stat(SecurityPolicyFile , &buf); - if ( (ret == 0) && (buf.st_mtime > lastmod) ) - { - ErrorF("reloading property rules\n"); - SecurityFreePropertyAccessList(); - SecurityLoadPropertyAccessList(); - lastmod = buf.st_mtime; - } - } -#endif - - /* If the property atom is bigger than any atoms on the list, - * we know we won't find it, so don't even bother looking. - */ - if (propertyName <= SecurityMaxPropertyName) - { - /* untrusted client operating on trusted window; see if it's allowed */ - - for (pacl = PropertyAccessList; pacl; pacl = pacl->next) - { - if (pacl->name < propertyName) - continue; - if (pacl->name > propertyName) - break; - - /* pacl->name == propertyName, so see if it applies to this window */ - - switch (pacl->windowRestriction) - { - case SecurityAnyWindow: /* always applies */ - break; - - case SecurityRootWindow: - { - /* if not a root window, this rule doesn't apply */ - if (pWin->parent) - continue; - } - break; - - case SecurityWindowWithProperty: - { - PropertyPtr pProp = wUserProps (pWin); - Bool match = FALSE; - char *p; - char *pEndData; - - while (pProp) - { - if (pProp->propertyName == pacl->mustHaveProperty) - break; - pProp = pProp->next; - } - if (!pProp) - continue; - if (!pacl->mustHaveValue) - break; - if (pProp->type != XA_STRING || pProp->format != 8) - continue; - - p = pProp->data; - pEndData = ((char *)pProp->data) + pProp->size; - while (!match && p < pEndData) - { - if (SecurityMatchString(pacl->mustHaveValue, p)) - match = TRUE; - else - { /* skip to the next string */ - while (*p++ && p < pEndData) - ; - } - } - if (!match) - continue; - } - break; /* end case SecurityWindowWithProperty */ - } /* end switch on windowRestriction */ - - /* If we get here, the property access rule pacl applies. - * If pacl doesn't apply, something above should have - * executed a continue, which will skip the follwing code. - */ - action = SecurityAllowOperation; - if (access_mode & SecurityReadAccess) - action = max(action, pacl->readAction); - if (access_mode & SecurityWriteAccess) - action = max(action, pacl->writeAction); - if (access_mode & SecurityDestroyAccess) - action = max(action, pacl->destroyAction); - break; - } /* end for each pacl */ - } /* end if propertyName <= SecurityMaxPropertyName */ - - if (SecurityAllowOperation != action) - { /* audit the access violation */ - int cid = CLIENT_ID(pWin->drawable.id); - int reqtype = ((xReq *)client->requestBuffer)->reqType; - char *actionstr = (SecurityIgnoreOperation == action) ? - "ignored" : "error"; - SecurityAudit("client %d attempted request %d with window 0x%x property %s (atom 0x%x) of client %d, %s\n", - client->index, reqtype, pWin->drawable.id, - NameForAtom(propertyName), propertyName, cid, actionstr); - } - return action; -} /* SecurityCheckPropertyAccess */ - - -/* SecurityResetProc - * - * Arguments: - * extEntry is the extension information for the security extension. - * - * Returns: nothing. - * - * Side Effects: - * Performs any cleanup needed by Security at server shutdown time. - */ - -static void -SecurityResetProc( - ExtensionEntry *extEntry) -{ - SecurityFreePropertyAccessList(); - SecurityFreeSitePolicyStrings(); -} /* SecurityResetProc */ - - -int -XSecurityOptions(argc, argv, i) - int argc; - char **argv; - int i; -{ - if (strcmp(argv[i], "-sp") == 0) - { - if (i < argc) - SecurityPolicyFile = argv[++i]; - return (i + 1); - } - return (i); -} /* XSecurityOptions */ - - - -/* SecurityExtensionInit - * - * Arguments: none. - * - * Returns: nothing. - * - * Side Effects: - * Enables the Security extension if possible. - */ - -void -SecurityExtensionInit(INITARGS) -{ - ExtensionEntry *extEntry; - int i; - - SecurityAuthorizationResType = - CreateNewResourceType(SecurityDeleteAuthorization); - - RTEventClient = CreateNewResourceType( - SecurityDeleteAuthorizationEventClient); - - if (!SecurityAuthorizationResType || !RTEventClient) - return; - - RTEventClient |= RC_NEVERRETAIN; - - if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL)) - return; - - extEntry = AddExtension(SECURITY_EXTENSION_NAME, - XSecurityNumberEvents, XSecurityNumberErrors, - ProcSecurityDispatch, SProcSecurityDispatch, - SecurityResetProc, StandardMinorOpcode); - - SecurityErrorBase = extEntry->errorBase; - SecurityEventBase = extEntry->eventBase; - - EventSwapVector[SecurityEventBase + XSecurityAuthorizationRevoked] = - (EventSwapPtr)SwapSecurityAuthorizationRevokedEvent; - - /* initialize untrusted proc vectors */ - - for (i = 0; i < 128; i++) - { - UntrustedProcVector[i] = ProcVector[i]; - SwappedUntrustedProcVector[i] = SwappedProcVector[i]; - } - - /* make sure insecure extensions are not allowed */ - - for (i = 128; i < 256; i++) - { - if (!UntrustedProcVector[i]) - { - UntrustedProcVector[i] = ProcBadRequest; - SwappedUntrustedProcVector[i] = ProcBadRequest; - } - } - - SecurityLoadPropertyAccessList(); - -} /* SecurityExtensionInit */ diff --git a/nx-X11/programs/Xserver/dix/dixfonts.c.NX.original b/nx-X11/programs/Xserver/dix/dixfonts.c.NX.original deleted file mode 100644 index b66fe23bd..000000000 --- a/nx-X11/programs/Xserver/dix/dixfonts.c.NX.original +++ /dev/null @@ -1,2215 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/dix/dixfonts.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */ -/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.28 2003/11/08 02:02:03 dawes Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* The panoramix components contained the following notice */ -/* -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ -/* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */ - -#define NEED_REPLIES -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "cursorstr.h" -#include "misc.h" -#include "opaque.h" -#include "dixfontstr.h" -#include "closestr.h" - -#ifdef DEBUG -#include -#endif - -#ifdef NX_TRANS_SOCKET - -char _NXFontPath[1024]; - -/* - * Override the default font path and make - * it configurable at run time, based on - * the NX_FONT environment. - */ - -static const char *_NXGetFontPath(const char *path) -{ - const char *fontEnv; - - /* - * Check the environment only once. - */ - - if (*_NXFontPath != '\0') - { - return _NXFontPath; - } - - fontEnv = getenv("NX_FONT"); - - if (fontEnv != NULL && *fontEnv != '\0') - { - if (strlen(fontEnv) + 1 > 1024) - { -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: WARNING! Maximum length of font path exceeded.\n"); -#endif - goto _NXGetFontPathError; - } - - strcpy(_NXFontPath, fontEnv); - -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: Using NX font path [%s].\n", _NXFontPath); -#endif - - return _NXFontPath; - } - -_NXGetFontPathError: - - strcpy(_NXFontPath, path); - -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: Using default font path [%s].\n", _NXFontPath); -#endif - - return _NXFontPath; -} - -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#endif - -#ifdef LBX -#include "lbxserve.h" -#endif - -#ifdef XF86BIGFONT -#define _XF86BIGFONT_SERVER_ -#include -#endif - -#define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics - -extern pointer fosNaturalParams; -extern FontPtr defaultFont; - -static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; -FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; - -static unsigned char *font_path_string; - -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; -static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; -static FontPatternCachePtr patternCache; - -int -FontToXError(err) - int err; -{ - switch (err) { - case Successful: - return Success; - case AllocError: - return BadAlloc; - case BadFontName: - return BadName; - case BadFontPath: - case BadFontFormat: /* is there something better? */ - case BadCharRange: - return BadValue; - default: - return err; - } -} - - -/* - * adding RT_FONT prevents conflict with default cursor font - */ -Bool -SetDefaultFont(char *defaultfontname) -{ - int err; - FontPtr pf; - XID fid; - - fid = FakeClientID(0); - err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); - if (err != Success) - return FALSE; - pf = (FontPtr) LookupIDByType(fid, RT_FONT); - if (pf == (FontPtr) NULL) - return FALSE; - defaultFont = pf; - return TRUE; -} - -/* - * note that the font wakeup queue is not refcounted. this is because - * an fpe needs to be added when it's inited, and removed when it's finally - * freed, in order to handle any data that isn't requested, like FS events. - * - * since the only thing that should call these routines is the renderer's - * init_fpe() and free_fpe(), there shouldn't be any problem in using - * freed data. - */ -void -QueueFontWakeup(FontPathElementPtr fpe) -{ - int i; - FontPathElementPtr *new; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - -#ifdef DEBUG - fprintf(stderr, "re-queueing fpe wakeup\n"); -#endif - - return; - } - } - if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - xrealloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; - } - slept_fpes[num_slept_fpes] = fpe; - num_slept_fpes++; -} - -void -RemoveFontWakeup(FontPathElementPtr fpe) -{ - int i, - j; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } - } -} - -void -FontWakeup(pointer data, int count, pointer LastSelectMask) -{ - int i; - FontPathElementPtr fpe; - - if (count < 0) - return; - /* wake up any fpe's that may be waiting for information */ - for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); - } -} - -/* XXX -- these two funcs may want to be broken into macros */ -static void -UseFPE(FontPathElementPtr fpe) -{ - fpe->refcount++; -} - -static void -FreeFPE (FontPathElementPtr fpe) -{ - fpe->refcount--; - if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); - } -} - -static Bool -doOpenFont(ClientPtr client, OFclosurePtr c) -{ - FontPtr pfont = NullFont; - FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; - /* - * Decide at runtime what FontFormat to use. - */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - -#if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | -#endif - -#if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | -#endif - -#if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | -#endif - -#if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | -#endif - - BitmapFormatScanlineUnit8; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) - break; - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); - } - return TRUE; - } - break; - } - - if (err != Successful) - goto bail; - if (!pfont) { - err = BadFontName; - goto bail; - } - /* check values for firstCol, lastCol, firstRow, and lastRow */ - if (pfont->info.firstCol > pfont->info.lastCol || - pfont->info.firstRow > pfont->info.lastRow || - pfont->info.lastCol - pfont->info.firstCol > 255) { - err = AllocError; - goto bail; - } - if (!pfont->fpe) - pfont->fpe = fpe; - pfont->refcnt++; - if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - if (!(*pScr->RealizeFont) (pScr, pfont)) - { - CloseFont (pfont, (Font) 0); - err = AllocError; - goto bail; - } - } - } - } - if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; - } - if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen, - pfont); -bail: - if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); - } - if (c->slept) - ClientWakeup(c->client); - for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); - } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); - return TRUE; -} - -int -OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontname) -{ - OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - c = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!c) - return BadAlloc; - c->fontname = (char *) xalloc(lenfname); - c->origFontName = pfontname; - c->origFontNameLen = lenfname; - if (!c->fontname) { - xfree(c); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); - return BadAlloc; - } - memmove(c->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->fontid = fid; - c->current_fpe = 0; - c->num_fpes = num_fpes; - c->fnamelen = lenfname; - c->slept = FALSE; - c->flags = flags; - c->non_cachable_font = cached; - - (void) doOpenFont(client, c); - return Success; -} - -/** - * Decrement font's ref count, and free storage if ref count equals zero - * - * \param value must conform to DeleteType - */ -int -CloseFont(pointer value, XID fid) -{ - int nscr; - ScreenPtr pscr; - FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; - - if (pfont == NullFont) - return (Success); - if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; -#ifdef LBX - LbxFreeFontTag(pfont); -#endif -#ifdef XF86BIGFONT - XF86BigfontFreeFontShm(pfont); -#endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); - } - return (Success); -} - - -/***====================================================================***/ - -/** - * Sets up pReply as the correct QueryFontReply for pFont with the first - * nProtoCCIStructs char infos. - * - * \param pReply caller must allocate this storage - */ -void -QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs) -{ - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; - - /* pr->length set in dispatch */ - pReply->minCharOrByte2 = pFont->info.firstCol; - pReply->defaultChar = pFont->info.defaultCh; - pReply->maxCharOrByte2 = pFont->info.lastCol; - pReply->drawDirection = pFont->info.drawDirection; - pReply->allCharsExist = pFont->info.allExist; - pReply->minByte1 = pFont->info.firstRow; - pReply->maxByte1 = pFont->info.lastRow; - pReply->fontAscent = pFont->info.fontAscent; - pReply->fontDescent = pFont->info.fontDescent; - - pReply->minBounds = pFont->info.ink_minbounds; - pReply->maxBounds = pFont->info.ink_maxbounds; - - pReply->nFontProps = pFont->info.nprops; - pReply->nCharInfos = nProtoCCIStructs; - - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - } - - ninfos = 0; - ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); - prCI = (xCharInfo *) (prFP); - for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } - } - return; -} - -static Bool -doListFontsAndAliases(ClientPtr client, LFclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ - if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; - } - -finish: - - names = c->names; - nnames = names->nnames; - client = c->client; - stringLens = 0; - for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - - reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; - reply.nFonts = nnames; - reply.sequenceNumber = client->sequence; - - bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2); - - if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; - } - /* - * since WriteToClient long word aligns things, copy to temp buffer and - * write all at once - */ - for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } - } - nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); - (void) WriteToClient(client, stringLens + nnames, bufferStart); - DEALLOCATE_LOCAL(bufferStart); - -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); - return TRUE; -} - -int -ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, - unsigned max_names) -{ - int i; - LFclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - return BadAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - return BadAlloc; - } - c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - return BadAlloc; - } - memmove( c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsAndAliases(client, c); - return Success; -} - -int -doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; - xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; - xListFontsWithInfoReply finalReply; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; - if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; - } - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - c->reply = reply; - c->length = length; - } - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: - length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); - finalReply.type = X_Reply; - finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; - WriteSwappedDataToClient(client, length, &finalReply); -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - xfree(c); - return TRUE; -} - -int -StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, - int max_names) -{ - int i; - LFWIclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFWIclosurePtr) xalloc(sizeof *c))) - goto badAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - xfree(c); - goto badAlloc; - } - memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->reply = 0; - c->length = 0; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->savedNumFonts = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsWithInfo(client, c); - return Success; -badAlloc: - return BadAlloc; -} - -#define TextEltHeader 2 -#define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; -#define clearGCmask (GCClipMask) - -int -doPolyText(ClientPtr client, register PTclosurePtr c) -{ - register FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; - int err = Success, lgerr; /* err is in X error, not font error, space */ - enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; - FontPathElementPtr fpe; - GC *origGC = NULL; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (c->slept) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } - - client_state = c->slept ? SLEEPING : NEVER_SLEPT; - - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - oldfid = fid; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - client->errorValue = fid; - err = BadFont; - /* restore pFont and fid for step 4 (described below) */ - pFont = oldpFont; - fid = oldfid; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGC( c->pGC, GCFont, &fid); - ValidateGC(c->pDraw, c->pGC); - if (c->reqType == X_PolyText8) - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; - else - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16; - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!c->slept) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - len = c->endReq - c->pElt; - c->data = (unsigned char *)xalloc(len); - if (!c->data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(c->data, c->pElt, len); - c->pElt = c->data; - c->endReq = c->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, c->pElt + TextEltHeader); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGC(origGC, GCFont, &fid); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; - if (err != Success && c->client != serverClient) { -#ifdef PANORAMIX - if (noPanoramiXExtension || !c->pGC->pScreen->myNum) -#endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, - unsigned char *endReq, int xorg, int yorg, int reqType, XID did) -{ - PTclosureRec local_closure; - - local_closure.pElt = pElt; - local_closure.endReq = endReq; - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_PolyText8) - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8; - local_closure.itemSize = 1; - } - else - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16; - local_closure.itemSize = 2; - } - local_closure.pGC = pGC; - local_closure.did = did; - local_closure.err = Success; - local_closure.slept = FALSE; - - (void) doPolyText(client, &local_closure); - return Success; -} - - -#undef TextEltHeader -#undef FontShiftSize - -int -doImageText(ClientPtr client, register ITclosurePtr c) -{ - int err = Success, lgerr; /* err is in X error, not font error, space */ - FontPathElementPtr fpe; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); - if (lgerr == Suspended) - { - if (!c->slept) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = (unsigned char *)xalloc(c->nChars * c->itemSize); - if (!data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * c->itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, c->data); - } - -bail: - - if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, - unsigned char *data, int xorg, int yorg, int reqType, XID did) -{ - ITclosureRec local_closure; - - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.pGC = pGC; - local_closure.nChars = nChars; - local_closure.data = data; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_ImageText8) - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8; - local_closure.itemSize = 1; - } - else - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16; - local_closure.itemSize = 2; - } - local_closure.did = did; - local_closure.slept = FALSE; - - (void) doImageText(client, &local_closure); - return Success; -} - - -/* does the necessary magic to figure out the fpe type */ -static int -DetermineFPEType(char *pathname) -{ - int i; - - for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; - } - return -1; -} - - -static void -FreeFontPath(FontPathElementPtr *list, int n, Bool force) -{ - int i; - - for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n", - list[i]->name_length, list[i]->name, - list[i]->refcount, found); - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); - } - xfree((char *) list); -} - -static FontPathElementPtr -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) -{ - FontPathElementPtr fpe; - int i; - - for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; - } - return (FontPathElementPtr) 0; -} - - -static int -SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) -{ - int i, err = 0; - int valid_paths = 0; - unsigned int len; - unsigned char *cp = paths; - FontPathElementPtr fpe = NULL, *fplist; - - fplist = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * npaths); - if (!fplist) { - *bad = 0; - return BadAlloc; - } - for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF ("Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = (char *) xalloc(len + 1); - if (!fpe->name) - { - xfree(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - if (persist) - { - ErrorF("Could not init font path element %s, removing from list!\n", - fpe->name); - } - xfree (fpe->name); - xfree (fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; - } - - FreeFontPath(font_path_elements, num_fpes, FALSE); - font_path_elements = fplist; - if (patternCache) - EmptyFontPatternCache(patternCache); - num_fpes = valid_paths; - - return Success; -bail: - *bad = i; - while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); - xfree(fplist); - return FontToXError(err); -} - -/* XXX -- do we need to pass error down to each renderer? */ -int -SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error) -{ - int err = Success; - - if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - err = SetFontPathElements(npaths, paths, error, FALSE); - } - return err; -} - -int -SetDefaultFontPath(char *path) -{ - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; - - /* get enough for string, plus values -- use up commas */ -#ifdef NX_TRANS_SOCKET - len = strlen(_NXGetFontPath(path)) + 1; -#else - len = strlen(path) + 1; -#endif - nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len); - if (!newpath) - return BadAlloc; -#ifdef NX_TRANS_SOCKET - pp = (unsigned char *) _NXGetFontPath(path); -#else - pp = (unsigned char *) path; -#endif - cp++; - while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } - } - *nump = (unsigned char) size; - - err = SetFontPathElements(num, newpath, &bad, TRUE); - - DEALLOCATE_LOCAL(newpath); - - return err; -} - -unsigned char * -GetFontPath(int *count, int *length) -{ - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; - - len = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; - } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); - if (!font_path_string) - return NULL; - - c = font_path_string; - *length = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; - } - *count = num_fpes; - return font_path_string; -} - -int -LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size, unsigned char *data) -{ - if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); - else - return Successful; -} - -void -DeleteClientFontStuff(ClientPtr client) -{ - int i; - FontPathElementPtr fpe; - - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } -} - -void -InitFonts () -{ - patternCache = MakeFontPatternCache(); - -#ifndef KDRIVESERVER - if (screenInfo.numScreens > screenInfo.numVideoScreens) { - PrinterFontRegisterFpeFunctions(); - FontFileCheckRegisterFpeFunctions(); - check_fs_register_fpe_functions(); - } else -#endif - { -#ifdef KDRIVESERVER - BuiltinRegisterFpeFunctions(); -#endif - FontFileRegisterFpeFunctions(); -#ifndef NOFONTSERVERACCESS - fs_register_fpe_functions(); -#endif - } -} - -int -GetDefaultPointSize () -{ - return 120; -} - - -FontResolutionPtr -GetClientResolutions (int *num) -{ - if (requestingClient && requestingClient->fontResFunc != NULL && - !requestingClient->clientGone) - { - return (*requestingClient->fontResFunc)(requestingClient, num); - } - else { - static struct _FontResolution res; - ScreenPtr pScreen; - - pScreen = screenInfo.screens[0]; - res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; - /* - * XXX - we'll want this as long as bitmap instances are prevalent - so that we can match them from scalable fonts - */ - if (res.x_resolution < 88) - res.x_resolution = 75; - else - res.x_resolution = 100; - res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; - if (res.y_resolution < 88) - res.y_resolution = 75; - else - res.y_resolution = 100; - res.point_size = 120; - *num = 1; - return &res; - } -} - -/* - * returns the type index of the new fpe - * - * should be called (only once!) by each type of fpe when initialized - */ - -int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) -{ - FPEFunctions *new; - - /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); - if (!new) - return -1; - fpe_functions = new; - - fpe_functions[num_fpe_types].name_check = name_func; - fpe_functions[num_fpe_types].open_font = open_func; - fpe_functions[num_fpe_types].close_font = close_func; - fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; - fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; - fpe_functions[num_fpe_types].init_fpe = init_func; - fpe_functions[num_fpe_types].free_fpe = free_func; - fpe_functions[num_fpe_types].reset_fpe = reset_func; - fpe_functions[num_fpe_types].client_died = client_died; - fpe_functions[num_fpe_types].load_glyphs = load_glyphs; - fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; - fpe_functions[num_fpe_types].set_path_hook = set_path_func; - - return num_fpe_types++; -} - -void -FreeFonts() -{ - if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; - } - FreeFontPath(font_path_elements, num_fpes, TRUE); - font_path_elements = 0; - num_fpes = 0; - xfree(fpe_functions); - num_fpe_types = 0; - fpe_functions = (FPEFunctions *) 0; -} - -/* convenience functions for FS interface */ - -FontPtr -find_old_font(XID id) -{ - return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE, - SecurityUnknownAccess); -} - -Font -GetNewFontClientID() -{ - return FakeClientID(0); -} - -int -StoreFontClientFont(FontPtr pfont, Font id) -{ - return AddResource(id, RT_NONE, (pointer) pfont); -} - -void -DeleteFontClientID(Font id) -{ - FreeResource(id, RT_NONE); -} - -int -client_auth_generation(ClientPtr client) -{ - return 0; -} - -static int fs_handlers_installed = 0; -static unsigned int last_server_gen; - -int -init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler) -{ - /* if server has reset, make sure the b&w handlers are reinstalled */ - if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; - } - if (fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "adding FS b & w handlers\n"); -#endif - - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; - } - QueueFontWakeup(fpe); - return Successful; -} - -void -remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler, Bool all) -{ - if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "removing FS b & w handlers\n"); -#endif - - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } - } - RemoveFontWakeup(fpe); -} - -#ifdef DEBUG -#define GLWIDTHBYTESPADDED(bits,nbytes) \ - ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ - :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ - :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ - :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ - : 0) - -#define GLYPH_SIZE(ch, nbytes) \ - GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \ - (ch)->metrics.leftSideBearing, (nbytes)) -void -dump_char_ascii(CharInfoPtr cip) -{ - int r, - l; - int bpr; - int byte; - static unsigned maskTab[] = { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - bpr = GLYPH_SIZE(cip, 4); - for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) { - pointer row = (pointer) cip->bits + r * bpr; - - byte = 0; - for (l = 0; l <= (cip->metrics.rightSideBearing - - cip->metrics.leftSideBearing); l++) { - if (maskTab[l & 7] & row[l >> 3]) - putchar('X'); - else - putchar('.'); - } - putchar('\n'); - } -} - -#endif diff --git a/nx-X11/programs/Xserver/dix/dixfonts.c.X.original b/nx-X11/programs/Xserver/dix/dixfonts.c.X.original deleted file mode 100644 index 2c5874e8d..000000000 --- a/nx-X11/programs/Xserver/dix/dixfonts.c.X.original +++ /dev/null @@ -1,2150 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/dix/dixfonts.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */ -/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.28 2003/11/08 02:02:03 dawes Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* The panoramix components contained the following notice */ -/* -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ -/* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */ - -#define NEED_REPLIES -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "cursorstr.h" -#include "misc.h" -#include "opaque.h" -#include "dixfontstr.h" -#include "closestr.h" - -#ifdef DEBUG -#include -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#endif - -#ifdef LBX -#include "lbxserve.h" -#endif - -#ifdef XF86BIGFONT -#define _XF86BIGFONT_SERVER_ -#include -#endif - -#define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics - -extern pointer fosNaturalParams; -extern FontPtr defaultFont; - -static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; -FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; - -static unsigned char *font_path_string; - -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; -static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; -static FontPatternCachePtr patternCache; - -int -FontToXError(err) - int err; -{ - switch (err) { - case Successful: - return Success; - case AllocError: - return BadAlloc; - case BadFontName: - return BadName; - case BadFontPath: - case BadFontFormat: /* is there something better? */ - case BadCharRange: - return BadValue; - default: - return err; - } -} - - -/* - * adding RT_FONT prevents conflict with default cursor font - */ -Bool -SetDefaultFont(char *defaultfontname) -{ - int err; - FontPtr pf; - XID fid; - - fid = FakeClientID(0); - err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); - if (err != Success) - return FALSE; - pf = (FontPtr) LookupIDByType(fid, RT_FONT); - if (pf == (FontPtr) NULL) - return FALSE; - defaultFont = pf; - return TRUE; -} - -/* - * note that the font wakeup queue is not refcounted. this is because - * an fpe needs to be added when it's inited, and removed when it's finally - * freed, in order to handle any data that isn't requested, like FS events. - * - * since the only thing that should call these routines is the renderer's - * init_fpe() and free_fpe(), there shouldn't be any problem in using - * freed data. - */ -void -QueueFontWakeup(FontPathElementPtr fpe) -{ - int i; - FontPathElementPtr *new; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - -#ifdef DEBUG - fprintf(stderr, "re-queueing fpe wakeup\n"); -#endif - - return; - } - } - if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - xrealloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; - } - slept_fpes[num_slept_fpes] = fpe; - num_slept_fpes++; -} - -void -RemoveFontWakeup(FontPathElementPtr fpe) -{ - int i, - j; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } - } -} - -void -FontWakeup(pointer data, int count, pointer LastSelectMask) -{ - int i; - FontPathElementPtr fpe; - - if (count < 0) - return; - /* wake up any fpe's that may be waiting for information */ - for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); - } -} - -/* XXX -- these two funcs may want to be broken into macros */ -static void -UseFPE(FontPathElementPtr fpe) -{ - fpe->refcount++; -} - -static void -FreeFPE (FontPathElementPtr fpe) -{ - fpe->refcount--; - if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); - } -} - -static Bool -doOpenFont(ClientPtr client, OFclosurePtr c) -{ - FontPtr pfont = NullFont; - FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; - /* - * Decide at runtime what FontFormat to use. - */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - -#if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | -#endif - -#if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | -#endif - -#if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | -#endif - -#if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | -#endif - - BitmapFormatScanlineUnit8; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) - break; - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); - } - return TRUE; - } - break; - } - - if (err != Successful) - goto bail; - if (!pfont) { - err = BadFontName; - goto bail; - } - /* check values for firstCol, lastCol, firstRow, and lastRow */ - if (pfont->info.firstCol > pfont->info.lastCol || - pfont->info.firstRow > pfont->info.lastRow || - pfont->info.lastCol - pfont->info.firstCol > 255) { - err = AllocError; - goto bail; - } - if (!pfont->fpe) - pfont->fpe = fpe; - pfont->refcnt++; - if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - if (!(*pScr->RealizeFont) (pScr, pfont)) - { - CloseFont (pfont, (Font) 0); - err = AllocError; - goto bail; - } - } - } - } - if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; - } - if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen, - pfont); -bail: - if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); - } - if (c->slept) - ClientWakeup(c->client); - for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); - } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); - return TRUE; -} - -int -OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontname) -{ - OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - c = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!c) - return BadAlloc; - c->fontname = (char *) xalloc(lenfname); - c->origFontName = pfontname; - c->origFontNameLen = lenfname; - if (!c->fontname) { - xfree(c); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); - return BadAlloc; - } - memmove(c->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->fontid = fid; - c->current_fpe = 0; - c->num_fpes = num_fpes; - c->fnamelen = lenfname; - c->slept = FALSE; - c->flags = flags; - c->non_cachable_font = cached; - - (void) doOpenFont(client, c); - return Success; -} - -/** - * Decrement font's ref count, and free storage if ref count equals zero - * - * \param value must conform to DeleteType - */ -int -CloseFont(pointer value, XID fid) -{ - int nscr; - ScreenPtr pscr; - FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; - - if (pfont == NullFont) - return (Success); - if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; -#ifdef LBX - LbxFreeFontTag(pfont); -#endif -#ifdef XF86BIGFONT - XF86BigfontFreeFontShm(pfont); -#endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); - } - return (Success); -} - - -/***====================================================================***/ - -/** - * Sets up pReply as the correct QueryFontReply for pFont with the first - * nProtoCCIStructs char infos. - * - * \param pReply caller must allocate this storage - */ -void -QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs) -{ - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; - - /* pr->length set in dispatch */ - pReply->minCharOrByte2 = pFont->info.firstCol; - pReply->defaultChar = pFont->info.defaultCh; - pReply->maxCharOrByte2 = pFont->info.lastCol; - pReply->drawDirection = pFont->info.drawDirection; - pReply->allCharsExist = pFont->info.allExist; - pReply->minByte1 = pFont->info.firstRow; - pReply->maxByte1 = pFont->info.lastRow; - pReply->fontAscent = pFont->info.fontAscent; - pReply->fontDescent = pFont->info.fontDescent; - - pReply->minBounds = pFont->info.ink_minbounds; - pReply->maxBounds = pFont->info.ink_maxbounds; - - pReply->nFontProps = pFont->info.nprops; - pReply->nCharInfos = nProtoCCIStructs; - - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - } - - ninfos = 0; - ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); - prCI = (xCharInfo *) (prFP); - for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } - } - return; -} - -static Bool -doListFontsAndAliases(ClientPtr client, LFclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ - if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; - } - -finish: - - names = c->names; - nnames = names->nnames; - client = c->client; - stringLens = 0; - for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - - reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; - reply.nFonts = nnames; - reply.sequenceNumber = client->sequence; - - bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2); - - if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; - } - /* - * since WriteToClient long word aligns things, copy to temp buffer and - * write all at once - */ - for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } - } - nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); - (void) WriteToClient(client, stringLens + nnames, bufferStart); - DEALLOCATE_LOCAL(bufferStart); - -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); - return TRUE; -} - -int -ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, - unsigned max_names) -{ - int i; - LFclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - return BadAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - return BadAlloc; - } - c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - return BadAlloc; - } - memmove( c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsAndAliases(client, c); - return Success; -} - -int -doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; - xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; - xListFontsWithInfoReply finalReply; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; - if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; - } - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - c->reply = reply; - c->length = length; - } - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: - length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); - finalReply.type = X_Reply; - finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; - WriteSwappedDataToClient(client, length, &finalReply); -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - xfree(c); - return TRUE; -} - -int -StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, - int max_names) -{ - int i; - LFWIclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFWIclosurePtr) xalloc(sizeof *c))) - goto badAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - xfree(c); - goto badAlloc; - } - memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->reply = 0; - c->length = 0; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->savedNumFonts = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsWithInfo(client, c); - return Success; -badAlloc: - return BadAlloc; -} - -#define TextEltHeader 2 -#define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; -#define clearGCmask (GCClipMask) - -int -doPolyText(ClientPtr client, register PTclosurePtr c) -{ - register FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; - int err = Success, lgerr; /* err is in X error, not font error, space */ - enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; - FontPathElementPtr fpe; - GC *origGC = NULL; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (c->slept) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } - - client_state = c->slept ? SLEEPING : NEVER_SLEPT; - - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - oldfid = fid; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - client->errorValue = fid; - err = BadFont; - /* restore pFont and fid for step 4 (described below) */ - pFont = oldpFont; - fid = oldfid; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGC( c->pGC, GCFont, &fid); - ValidateGC(c->pDraw, c->pGC); - if (c->reqType == X_PolyText8) - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; - else - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16; - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!c->slept) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - len = c->endReq - c->pElt; - c->data = (unsigned char *)xalloc(len); - if (!c->data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(c->data, c->pElt, len); - c->pElt = c->data; - c->endReq = c->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, c->pElt + TextEltHeader); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGC(origGC, GCFont, &fid); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; - if (err != Success && c->client != serverClient) { -#ifdef PANORAMIX - if (noPanoramiXExtension || !c->pGC->pScreen->myNum) -#endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, - unsigned char *endReq, int xorg, int yorg, int reqType, XID did) -{ - PTclosureRec local_closure; - - local_closure.pElt = pElt; - local_closure.endReq = endReq; - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_PolyText8) - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8; - local_closure.itemSize = 1; - } - else - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16; - local_closure.itemSize = 2; - } - local_closure.pGC = pGC; - local_closure.did = did; - local_closure.err = Success; - local_closure.slept = FALSE; - - (void) doPolyText(client, &local_closure); - return Success; -} - - -#undef TextEltHeader -#undef FontShiftSize - -int -doImageText(ClientPtr client, register ITclosurePtr c) -{ - int err = Success, lgerr; /* err is in X error, not font error, space */ - FontPathElementPtr fpe; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); - if (lgerr == Suspended) - { - if (!c->slept) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = (unsigned char *)xalloc(c->nChars * c->itemSize); - if (!data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * c->itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, c->data); - } - -bail: - - if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, - unsigned char *data, int xorg, int yorg, int reqType, XID did) -{ - ITclosureRec local_closure; - - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.pGC = pGC; - local_closure.nChars = nChars; - local_closure.data = data; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_ImageText8) - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8; - local_closure.itemSize = 1; - } - else - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16; - local_closure.itemSize = 2; - } - local_closure.did = did; - local_closure.slept = FALSE; - - (void) doImageText(client, &local_closure); - return Success; -} - - -/* does the necessary magic to figure out the fpe type */ -static int -DetermineFPEType(char *pathname) -{ - int i; - - for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; - } - return -1; -} - - -static void -FreeFontPath(FontPathElementPtr *list, int n, Bool force) -{ - int i; - - for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n", - list[i]->name_length, list[i]->name, - list[i]->refcount, found); - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); - } - xfree((char *) list); -} - -static FontPathElementPtr -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) -{ - FontPathElementPtr fpe; - int i; - - for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; - } - return (FontPathElementPtr) 0; -} - - -static int -SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) -{ - int i, err = 0; - int valid_paths = 0; - unsigned int len; - unsigned char *cp = paths; - FontPathElementPtr fpe = NULL, *fplist; - - fplist = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * npaths); - if (!fplist) { - *bad = 0; - return BadAlloc; - } - for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF ("Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = (char *) xalloc(len + 1); - if (!fpe->name) - { - xfree(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - if (persist) - { - ErrorF("Could not init font path element %s, removing from list!\n", - fpe->name); - } - xfree (fpe->name); - xfree (fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; - } - - FreeFontPath(font_path_elements, num_fpes, FALSE); - font_path_elements = fplist; - if (patternCache) - EmptyFontPatternCache(patternCache); - num_fpes = valid_paths; - - return Success; -bail: - *bad = i; - while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); - xfree(fplist); - return FontToXError(err); -} - -/* XXX -- do we need to pass error down to each renderer? */ -int -SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error) -{ - int err = Success; - - if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - err = SetFontPathElements(npaths, paths, error, FALSE); - } - return err; -} - -int -SetDefaultFontPath(char *path) -{ - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; - - /* get enough for string, plus values -- use up commas */ - len = strlen(path) + 1; - nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len); - if (!newpath) - return BadAlloc; - pp = (unsigned char *) path; - cp++; - while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } - } - *nump = (unsigned char) size; - - err = SetFontPathElements(num, newpath, &bad, TRUE); - - DEALLOCATE_LOCAL(newpath); - - return err; -} - -unsigned char * -GetFontPath(int *count, int *length) -{ - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; - - len = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; - } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); - if (!font_path_string) - return NULL; - - c = font_path_string; - *length = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; - } - *count = num_fpes; - return font_path_string; -} - -int -LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size, unsigned char *data) -{ - if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); - else - return Successful; -} - -void -DeleteClientFontStuff(ClientPtr client) -{ - int i; - FontPathElementPtr fpe; - - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } -} - -void -InitFonts () -{ - patternCache = MakeFontPatternCache(); - -#ifndef KDRIVESERVER - if (screenInfo.numScreens > screenInfo.numVideoScreens) { - PrinterFontRegisterFpeFunctions(); - FontFileCheckRegisterFpeFunctions(); - check_fs_register_fpe_functions(); - } else -#endif - { -#ifdef KDRIVESERVER - BuiltinRegisterFpeFunctions(); -#endif - FontFileRegisterFpeFunctions(); -#ifndef NOFONTSERVERACCESS - fs_register_fpe_functions(); -#endif - } -} - -int -GetDefaultPointSize () -{ - return 120; -} - - -FontResolutionPtr -GetClientResolutions (int *num) -{ - if (requestingClient && requestingClient->fontResFunc != NULL && - !requestingClient->clientGone) - { - return (*requestingClient->fontResFunc)(requestingClient, num); - } - else { - static struct _FontResolution res; - ScreenPtr pScreen; - - pScreen = screenInfo.screens[0]; - res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; - /* - * XXX - we'll want this as long as bitmap instances are prevalent - so that we can match them from scalable fonts - */ - if (res.x_resolution < 88) - res.x_resolution = 75; - else - res.x_resolution = 100; - res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; - if (res.y_resolution < 88) - res.y_resolution = 75; - else - res.y_resolution = 100; - res.point_size = 120; - *num = 1; - return &res; - } -} - -/* - * returns the type index of the new fpe - * - * should be called (only once!) by each type of fpe when initialized - */ - -int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) -{ - FPEFunctions *new; - - /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); - if (!new) - return -1; - fpe_functions = new; - - fpe_functions[num_fpe_types].name_check = name_func; - fpe_functions[num_fpe_types].open_font = open_func; - fpe_functions[num_fpe_types].close_font = close_func; - fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; - fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; - fpe_functions[num_fpe_types].init_fpe = init_func; - fpe_functions[num_fpe_types].free_fpe = free_func; - fpe_functions[num_fpe_types].reset_fpe = reset_func; - fpe_functions[num_fpe_types].client_died = client_died; - fpe_functions[num_fpe_types].load_glyphs = load_glyphs; - fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; - fpe_functions[num_fpe_types].set_path_hook = set_path_func; - - return num_fpe_types++; -} - -void -FreeFonts() -{ - if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; - } - FreeFontPath(font_path_elements, num_fpes, TRUE); - font_path_elements = 0; - num_fpes = 0; - xfree(fpe_functions); - num_fpe_types = 0; - fpe_functions = (FPEFunctions *) 0; -} - -/* convenience functions for FS interface */ - -FontPtr -find_old_font(XID id) -{ - return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE, - SecurityUnknownAccess); -} - -Font -GetNewFontClientID() -{ - return FakeClientID(0); -} - -int -StoreFontClientFont(FontPtr pfont, Font id) -{ - return AddResource(id, RT_NONE, (pointer) pfont); -} - -void -DeleteFontClientID(Font id) -{ - FreeResource(id, RT_NONE); -} - -int -client_auth_generation(ClientPtr client) -{ - return 0; -} - -static int fs_handlers_installed = 0; -static unsigned int last_server_gen; - -int -init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler) -{ - /* if server has reset, make sure the b&w handlers are reinstalled */ - if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; - } - if (fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "adding FS b & w handlers\n"); -#endif - - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; - } - QueueFontWakeup(fpe); - return Successful; -} - -void -remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler, Bool all) -{ - if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "removing FS b & w handlers\n"); -#endif - - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } - } - RemoveFontWakeup(fpe); -} - -#ifdef DEBUG -#define GLWIDTHBYTESPADDED(bits,nbytes) \ - ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ - :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ - :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ - :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ - : 0) - -#define GLYPH_SIZE(ch, nbytes) \ - GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \ - (ch)->metrics.leftSideBearing, (nbytes)) -void -dump_char_ascii(CharInfoPtr cip) -{ - int r, - l; - int bpr; - int byte; - static unsigned maskTab[] = { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - bpr = GLYPH_SIZE(cip, 4); - for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) { - pointer row = (pointer) cip->bits + r * bpr; - - byte = 0; - for (l = 0; l <= (cip->metrics.rightSideBearing - - cip->metrics.leftSideBearing); l++) { - if (maskTab[l & 7] & row[l >> 3]) - putchar('X'); - else - putchar('.'); - } - putchar('\n'); - } -} - -#endif diff --git a/nx-X11/programs/Xserver/dix/pixmap.c.NX.original b/nx-X11/programs/Xserver/dix/pixmap.c.NX.original deleted file mode 100644 index 4be7d03ce..000000000 --- a/nx-X11/programs/Xserver/dix/pixmap.c.NX.original +++ /dev/null @@ -1,152 +0,0 @@ -/* $Xorg: pixmap.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ -/* - -Copyright 1993, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ -/* $XFree86: xc/programs/Xserver/dix/pixmap.c,v 3.4 2001/01/17 22:36:44 dawes Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "scrnintstr.h" -#include "misc.h" -#include "os.h" -#include "windowstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "site.h" - - -/* - * Scratch pixmap management and device independent pixmap allocation - * function. - */ - - -/* callable by ddx */ -PixmapPtr -GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth, - int bitsPerPixel, int devKind, pointer pPixData) -{ - PixmapPtr pPixmap = pScreen->pScratchPixmap; - - if (pPixmap) - pScreen->pScratchPixmap = NULL; - else - /* width and height of 0 means don't allocate any pixmap data */ - pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth); - - if (pPixmap) { - if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - bitsPerPixel, devKind, pPixData)) - return pPixmap; - (*pScreen->DestroyPixmap)(pPixmap); - } - return NullPixmap; -} - - -/* callable by ddx */ -void -FreeScratchPixmapHeader(PixmapPtr pPixmap) -{ - if (pPixmap) - { - ScreenPtr pScreen = pPixmap->drawable.pScreen; - - pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */ - if (pScreen->pScratchPixmap) - (*pScreen->DestroyPixmap)(pPixmap); - else - pScreen->pScratchPixmap = pPixmap; - } -} - - -Bool -CreateScratchPixmapsForScreen(int scrnum) -{ - /* let it be created on first use */ - screenInfo.screens[scrnum]->pScratchPixmap = NULL; - return TRUE; -} - - -void -FreeScratchPixmapsForScreen(int scrnum) -{ - FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap); -} - - -/* callable by ddx */ -PixmapPtr -AllocatePixmap(ScreenPtr pScreen, int pixDataSize) -{ - PixmapPtr pPixmap; -#ifdef PIXPRIV - char *ptr; - DevUnion *ppriv; - unsigned *sizes; - unsigned size; - int i; - - if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize) - return NullPixmap; - - /* - * FIXME: Allocate 4 bytes at the end of each pixmap. This - * is a quick workaround intended to fix a problem reported - * by Valgrind due to fbBlt() writing just after the end of - * the pixmap buffer. This may be a RENDER bug. - */ - - pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize + 4); - if (!pPixmap) - return NullPixmap; - ppriv = (DevUnion *)(pPixmap + 1); - pPixmap->devPrivates = ppriv; - sizes = pScreen->PixmapPrivateSizes; - ptr = (char *)(ppriv + pScreen->PixmapPrivateLen); - for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ((size = *sizes) != 0) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } -#else - pPixmap = (PixmapPtr)xalloc(sizeof(PixmapRec) + pixDataSize); -#endif - return pPixmap; -} diff --git a/nx-X11/programs/Xserver/dix/pixmap.c.X.original b/nx-X11/programs/Xserver/dix/pixmap.c.X.original deleted file mode 100644 index 78ce2a8c6..000000000 --- a/nx-X11/programs/Xserver/dix/pixmap.c.X.original +++ /dev/null @@ -1,145 +0,0 @@ -/* $Xorg: pixmap.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ -/* - -Copyright 1993, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ -/* $XFree86: xc/programs/Xserver/dix/pixmap.c,v 3.4 2001/01/17 22:36:44 dawes Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "scrnintstr.h" -#include "misc.h" -#include "os.h" -#include "windowstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "site.h" - - -/* - * Scratch pixmap management and device independent pixmap allocation - * function. - */ - - -/* callable by ddx */ -PixmapPtr -GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth, - int bitsPerPixel, int devKind, pointer pPixData) -{ - PixmapPtr pPixmap = pScreen->pScratchPixmap; - - if (pPixmap) - pScreen->pScratchPixmap = NULL; - else - /* width and height of 0 means don't allocate any pixmap data */ - pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth); - - if (pPixmap) { - if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - bitsPerPixel, devKind, pPixData)) - return pPixmap; - (*pScreen->DestroyPixmap)(pPixmap); - } - return NullPixmap; -} - - -/* callable by ddx */ -void -FreeScratchPixmapHeader(PixmapPtr pPixmap) -{ - if (pPixmap) - { - ScreenPtr pScreen = pPixmap->drawable.pScreen; - - pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */ - if (pScreen->pScratchPixmap) - (*pScreen->DestroyPixmap)(pPixmap); - else - pScreen->pScratchPixmap = pPixmap; - } -} - - -Bool -CreateScratchPixmapsForScreen(int scrnum) -{ - /* let it be created on first use */ - screenInfo.screens[scrnum]->pScratchPixmap = NULL; - return TRUE; -} - - -void -FreeScratchPixmapsForScreen(int scrnum) -{ - FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap); -} - - -/* callable by ddx */ -PixmapPtr -AllocatePixmap(ScreenPtr pScreen, int pixDataSize) -{ - PixmapPtr pPixmap; -#ifdef PIXPRIV - char *ptr; - DevUnion *ppriv; - unsigned *sizes; - unsigned size; - int i; - - if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize) - return NullPixmap; - - pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize); - if (!pPixmap) - return NullPixmap; - ppriv = (DevUnion *)(pPixmap + 1); - pPixmap->devPrivates = ppriv; - sizes = pScreen->PixmapPrivateSizes; - ptr = (char *)(ppriv + pScreen->PixmapPrivateLen); - for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ((size = *sizes) != 0) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } -#else - pPixmap = (PixmapPtr)xalloc(sizeof(PixmapRec) + pixDataSize); -#endif - return pPixmap; -} diff --git a/nx-X11/programs/Xserver/fb/Imakefile.NX.original b/nx-X11/programs/Xserver/fb/Imakefile.NX.original deleted file mode 100644 index cb560e7a0..000000000 --- a/nx-X11/programs/Xserver/fb/Imakefile.NX.original +++ /dev/null @@ -1,194 +0,0 @@ -XCOMM $XFree86: xc/programs/Xserver/fb/Imakefile,v 1.16 2002/05/31 16:12:17 dawes Exp $ -XCOMM -XCOMM -XCOMM Id: Imakefile,v 1.1 1999/11/02 03:54:44 keithp Exp $ - -/* - * The X.org 6.8.99.16 snapshot fails to compile with GCC 4. - * Temporarily disable the MMX features until the bug is - * fixed. - * -#if defined(HasGcc34) && HasGcc34 -MMXOPTIONS= -mmmx -msse -Winline --param inline-unit-growth=10000 \ - --param large-function-growth=10000 -DUSE_MMX -USEMMXOPTIONS= -DUSE_MMX -#if defined(i386Architecture) || defined(AMD64Architecture) -SpecialCObjectRule(fbmmx,fbmmx.c,$(MMXOPTIONS)) -SpecialCObjectRule(fbpict,fbpict.c,$(USEMMXOPTIONS)) -SpecialCObjectRule(fbfill,fbfill.c,$(USEMMXOPTIONS)) -SpecialCObjectRule(fbcopy,fbcopy.c,$(USEMMXOPTIONS)) -#endif - -#endif - */ - -#if DoLoadableServer -#if !BuildModuleInSubdir -#define IHaveModules -#elif !defined(IHaveModules) -#define IHaveSubdirs -SUBDIRS = module -#endif -#endif - -#include - -#ifdef FbNoPixelAddrCode -DEFINES=-DFBNOPIXADDR -DFBNO24BIT -#endif - -#if defined(IHaveModules) -XFMODSRC = fbmodule.c -XFMODOBJ = fbmodule.o -#endif - -#if BuildRender -RENDERSRC = fbcompose.c -RENDEROBJ = fbcompose.o -#endif - -SRCS = $(XFMODSRC) \ - fballpriv.c \ - fbbits.c \ - fbblt.c \ - fbbltone.c \ - fbbstore.c \ - fbcmap.c \ - $(RENDERSRC) \ - fbcopy.c \ - fbedge.c \ - fbfill.c \ - fbfillrect.c \ - fbfillsp.c \ - fbgc.c \ - fbgetsp.c \ - fbglyph.c \ - fbimage.c \ - fbline.c \ - fboverlay.c \ - fbpixmap.c \ - fbpoint.c \ - fbpush.c \ - fbscreen.c \ - fbseg.c \ - fbsetsp.c \ - fbsolid.c \ - fbstipple.c \ - fbtile.c \ - fbtrap.c \ - fbutil.c \ - fbwindow.c \ - fb24_32.c \ - fbpict.c \ - fbmmx.c \ - fbpseudocolor.c - -OBJS = $(XFMODOBJ) \ - fbarc.o \ - fballpriv.o \ - fbbits.o \ - fbblt.o \ - fbbltone.o \ - fbbstore.o \ - fbcmap.o \ - $(RENDEROBJ) \ - fbcopy.o \ - fbedge.o \ - fbfill.o \ - fbfillrect.o \ - fbfillsp.o \ - fbgc.o \ - fbgetsp.o \ - fbglyph.o \ - fbimage.o \ - fbline.o \ - fboverlay.o \ - fbpixmap.o \ - fbpoint.o \ - fbpush.o \ - fbscreen.o \ - fbseg.o \ - fbsetsp.o \ - fbsolid.o \ - fbstipple.o \ - fbtile.o \ - fbtrap.o \ - fbutil.o \ - fbwindow.o \ - fb24_32.o \ - fbpict.o \ - fbmmx.o \ - fbpseudocolor.o - - INCLUDES = -I$(SERVERSRC)/fb -I$(SERVERSRC)/mi -I$(SERVERSRC)/include \ - -I$(XINCLUDESRC) \ - -I$(FONTINCSRC) -I$(XF86SRC)/common $(EXTRAINCLUDES) \ - -I$(SERVERSRC)/render -I$(EXTINCSRC) -I$(SERVERSRC)/Xext - LINTLIBS = $(SERVERSRC)/dix/llib-ldix.ln $(SERVERSRC)/os/llib-los.ln \ - $(SERVERSRC)/mi/llib-lmi.ln - -#ifdef IHaveModules -ModuleObjectRule() -LibraryModuleTarget(fb,$(OBJS)) -#else -NormalLibraryObjectRule() -NormalLibraryTarget(fb,$(OBJS)) -#endif - -LintLibraryTarget(fb,$(SRCS)) - -NormalLintTarget($(SRCS)) - -#ifdef IHaveModules -InstallLibraryModule(fb,$(MODULEDIR),.) -#endif - -DependTarget() - -#ifdef IHaveSubdirs -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - -#ifdef LinkDirectory -LinkSourceFile(fb24_32.c,LinkDirectory) -LinkSourceFile(fballpriv.c,LinkDirectory) -LinkSourceFile(fbarc.c,LinkDirectory) -LinkSourceFile(fbbits.c,LinkDirectory) -LinkSourceFile(fbblt.c,LinkDirectory) -LinkSourceFile(fbbltone.c,LinkDirectory) -LinkSourceFile(fbbstore.c,LinkDirectory) -LinkSourceFile(fbcmap.c,LinkDirectory) -#if BuildRender -LinkSourceFile(fbcompose.c,LinkDirectory) -#endif -LinkSourceFile(fbcopy.c,LinkDirectory) -LinkSourceFile(fbfill.c,LinkDirectory) -LinkSourceFile(fbfillrect.c,LinkDirectory) -LinkSourceFile(fbfillsp.c,LinkDirectory) -LinkSourceFile(fbgc.c,LinkDirectory) -LinkSourceFile(fbgetsp.c,LinkDirectory) -LinkSourceFile(fbglyph.c,LinkDirectory) -LinkSourceFile(fbimage.c,LinkDirectory) -LinkSourceFile(fbline.c,LinkDirectory) -LinkSourceFile(fbmodule.c,LinkDirectory) -LinkSourceFile(fboverlay.c,LinkDirectory) -LinkSourceFile(fbpict.c,LinkDirectory) -LinkSourceFile(fbpixmap.c,LinkDirectory) -LinkSourceFile(fbpoint.c,LinkDirectory) -LinkSourceFile(fbpush.c,LinkDirectory) -LinkSourceFile(fbscreen.c,LinkDirectory) -LinkSourceFile(fbseg.c,LinkDirectory) -LinkSourceFile(fbsetsp.c,LinkDirectory) -LinkSourceFile(fbsolid.c,LinkDirectory) -LinkSourceFile(fbstipple.c,LinkDirectory) -LinkSourceFile(fbtile.c,LinkDirectory) -LinkSourceFile(fbtrap.c,LinkDirectory) -LinkSourceFile(fbutil.c,LinkDirectory) -LinkSourceFile(fbwindow.c,LinkDirectory) -LinkSourceFile(fbmmx.c,LinkDirectory) -#endif - -InstallDriverSDKLibraryModule(fb,$(DRIVERSDKMODULEDIR),.) -InstallDriverSDKNonExecFile(fb.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(fbrop.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/fb/Imakefile.X.original b/nx-X11/programs/Xserver/fb/Imakefile.X.original deleted file mode 100644 index df867016a..000000000 --- a/nx-X11/programs/Xserver/fb/Imakefile.X.original +++ /dev/null @@ -1,188 +0,0 @@ -XCOMM $XFree86: xc/programs/Xserver/fb/Imakefile,v 1.16 2002/05/31 16:12:17 dawes Exp $ -XCOMM -XCOMM -XCOMM Id: Imakefile,v 1.1 1999/11/02 03:54:44 keithp Exp $ - -#if defined(HasGcc34) && HasGcc34 -MMXOPTIONS= -mmmx -msse -Winline --param inline-unit-growth=10000 \ - --param large-function-growth=10000 -DUSE_MMX -USEMMXOPTIONS= -DUSE_MMX -#if defined(i386Architecture) || defined(AMD64Architecture) -SpecialCObjectRule(fbmmx,fbmmx.c,$(MMXOPTIONS)) -SpecialCObjectRule(fbpict,fbpict.c,$(USEMMXOPTIONS)) -SpecialCObjectRule(fbfill,fbfill.c,$(USEMMXOPTIONS)) -SpecialCObjectRule(fbcopy,fbcopy.c,$(USEMMXOPTIONS)) -#endif - -#endif - -#if DoLoadableServer -#if !BuildModuleInSubdir -#define IHaveModules -#elif !defined(IHaveModules) -#define IHaveSubdirs -SUBDIRS = module -#endif -#endif - -#include - -#ifdef FbNoPixelAddrCode -DEFINES=-DFBNOPIXADDR -DFBNO24BIT -#endif - -#if defined(IHaveModules) -XFMODSRC = fbmodule.c -XFMODOBJ = fbmodule.o -#endif - -#if BuildRender -RENDERSRC = fbcompose.c -RENDEROBJ = fbcompose.o -#endif - -SRCS = $(XFMODSRC) \ - fballpriv.c \ - fbbits.c \ - fbblt.c \ - fbbltone.c \ - fbbstore.c \ - fbcmap.c \ - $(RENDERSRC) \ - fbcopy.c \ - fbedge.c \ - fbfill.c \ - fbfillrect.c \ - fbfillsp.c \ - fbgc.c \ - fbgetsp.c \ - fbglyph.c \ - fbimage.c \ - fbline.c \ - fboverlay.c \ - fbpixmap.c \ - fbpoint.c \ - fbpush.c \ - fbscreen.c \ - fbseg.c \ - fbsetsp.c \ - fbsolid.c \ - fbstipple.c \ - fbtile.c \ - fbtrap.c \ - fbutil.c \ - fbwindow.c \ - fb24_32.c \ - fbpict.c \ - fbmmx.c \ - fbpseudocolor.c - -OBJS = $(XFMODOBJ) \ - fbarc.o \ - fballpriv.o \ - fbbits.o \ - fbblt.o \ - fbbltone.o \ - fbbstore.o \ - fbcmap.o \ - $(RENDEROBJ) \ - fbcopy.o \ - fbedge.o \ - fbfill.o \ - fbfillrect.o \ - fbfillsp.o \ - fbgc.o \ - fbgetsp.o \ - fbglyph.o \ - fbimage.o \ - fbline.o \ - fboverlay.o \ - fbpixmap.o \ - fbpoint.o \ - fbpush.o \ - fbscreen.o \ - fbseg.o \ - fbsetsp.o \ - fbsolid.o \ - fbstipple.o \ - fbtile.o \ - fbtrap.o \ - fbutil.o \ - fbwindow.o \ - fb24_32.o \ - fbpict.o \ - fbmmx.o \ - fbpseudocolor.o - - INCLUDES = -I$(SERVERSRC)/fb -I$(SERVERSRC)/mi -I$(SERVERSRC)/include \ - -I$(XINCLUDESRC) \ - -I$(FONTINCSRC) -I$(XF86SRC)/common $(EXTRAINCLUDES) \ - -I$(SERVERSRC)/render -I$(EXTINCSRC) -I$(SERVERSRC)/Xext - LINTLIBS = $(SERVERSRC)/dix/llib-ldix.ln $(SERVERSRC)/os/llib-los.ln \ - $(SERVERSRC)/mi/llib-lmi.ln - -#ifdef IHaveModules -ModuleObjectRule() -LibraryModuleTarget(fb,$(OBJS)) -#else -NormalLibraryObjectRule() -NormalLibraryTarget(fb,$(OBJS)) -#endif - -LintLibraryTarget(fb,$(SRCS)) - -NormalLintTarget($(SRCS)) - -#ifdef IHaveModules -InstallLibraryModule(fb,$(MODULEDIR),.) -#endif - -DependTarget() - -#ifdef IHaveSubdirs -MakeSubdirs($(SUBDIRS)) -DependSubdirs($(SUBDIRS)) -#endif - -#ifdef LinkDirectory -LinkSourceFile(fb24_32.c,LinkDirectory) -LinkSourceFile(fballpriv.c,LinkDirectory) -LinkSourceFile(fbarc.c,LinkDirectory) -LinkSourceFile(fbbits.c,LinkDirectory) -LinkSourceFile(fbblt.c,LinkDirectory) -LinkSourceFile(fbbltone.c,LinkDirectory) -LinkSourceFile(fbbstore.c,LinkDirectory) -LinkSourceFile(fbcmap.c,LinkDirectory) -#if BuildRender -LinkSourceFile(fbcompose.c,LinkDirectory) -#endif -LinkSourceFile(fbcopy.c,LinkDirectory) -LinkSourceFile(fbfill.c,LinkDirectory) -LinkSourceFile(fbfillrect.c,LinkDirectory) -LinkSourceFile(fbfillsp.c,LinkDirectory) -LinkSourceFile(fbgc.c,LinkDirectory) -LinkSourceFile(fbgetsp.c,LinkDirectory) -LinkSourceFile(fbglyph.c,LinkDirectory) -LinkSourceFile(fbimage.c,LinkDirectory) -LinkSourceFile(fbline.c,LinkDirectory) -LinkSourceFile(fbmodule.c,LinkDirectory) -LinkSourceFile(fboverlay.c,LinkDirectory) -LinkSourceFile(fbpict.c,LinkDirectory) -LinkSourceFile(fbpixmap.c,LinkDirectory) -LinkSourceFile(fbpoint.c,LinkDirectory) -LinkSourceFile(fbpush.c,LinkDirectory) -LinkSourceFile(fbscreen.c,LinkDirectory) -LinkSourceFile(fbseg.c,LinkDirectory) -LinkSourceFile(fbsetsp.c,LinkDirectory) -LinkSourceFile(fbsolid.c,LinkDirectory) -LinkSourceFile(fbstipple.c,LinkDirectory) -LinkSourceFile(fbtile.c,LinkDirectory) -LinkSourceFile(fbtrap.c,LinkDirectory) -LinkSourceFile(fbutil.c,LinkDirectory) -LinkSourceFile(fbwindow.c,LinkDirectory) -LinkSourceFile(fbmmx.c,LinkDirectory) -#endif - -InstallDriverSDKLibraryModule(fb,$(DRIVERSDKMODULEDIR),.) -InstallDriverSDKNonExecFile(fb.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(fbrop.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/fb/fbtrap.c.NX.original b/nx-X11/programs/Xserver/fb/fbtrap.c.NX.original deleted file mode 100644 index 1940bc209..000000000 --- a/nx-X11/programs/Xserver/fb/fbtrap.c.NX.original +++ /dev/null @@ -1,242 +0,0 @@ -/* - * $Id: fbtrap.c,v 1.5 2005/07/03 07:01:23 daniels Exp $ - * - * Copyright © 2004 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "fb.h" - -#ifdef RENDER - -#include "picturestr.h" -#include "mipict.h" -#include "renderedge.h" -#include "fbpict.h" - -void -fbAddTraps (PicturePtr pPicture, - INT16 x_off, - INT16 y_off, - int ntrap, - xTrap *traps) -{ - FbBits *buf; - int bpp; - int width; - int stride; - int height; - int pxoff, pyoff; - - xFixed x_off_fixed; - xFixed y_off_fixed; - RenderEdge l, r; - xFixed t, b; - - fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); - - width = pPicture->pDrawable->width; - height = pPicture->pDrawable->height; - x_off += pxoff; - y_off += pyoff; - - x_off_fixed = IntToxFixed(y_off); - y_off_fixed = IntToxFixed(y_off); - - while (ntrap--) - { - t = traps->top.y + y_off_fixed; - if (t < 0) - t = 0; - t = RenderSampleCeilY (t, bpp); - - b = traps->bot.y + y_off_fixed; - if (xFixedToInt (b) >= height) - b = IntToxFixed (height) - 1; - b = RenderSampleFloorY (b, bpp); - - if (b >= t) - { - /* initialize edge walkers */ - RenderEdgeInit (&l, bpp, t, - traps->top.l + x_off_fixed, - traps->top.y + y_off_fixed, - traps->bot.l + x_off_fixed, - traps->bot.y + y_off_fixed); - - RenderEdgeInit (&r, bpp, t, - traps->top.r + x_off_fixed, - traps->top.y + y_off_fixed, - traps->bot.r + x_off_fixed, - traps->bot.y + y_off_fixed); - - fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); - } - traps++; - } -} - -void -fbRasterizeTrapezoid (PicturePtr pPicture, - xTrapezoid *trap, - int x_off, - int y_off) -{ - FbBits *buf; - int bpp; - int width; - int stride; - int height; - int pxoff, pyoff; - - xFixed x_off_fixed; - xFixed y_off_fixed; - RenderEdge l, r; - xFixed t, b; - - if (!xTrapezoidValid (trap)) - return; - - fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); - - width = pPicture->pDrawable->width; - height = pPicture->pDrawable->height; - x_off += pxoff; - y_off += pyoff; - - x_off_fixed = IntToxFixed(x_off); - y_off_fixed = IntToxFixed(y_off); - t = trap->top + y_off_fixed; - if (t < 0) - t = 0; - t = RenderSampleCeilY (t, bpp); - - b = trap->bottom + y_off_fixed; - if (xFixedToInt (b) >= height) - b = IntToxFixed (height) - 1; - b = RenderSampleFloorY (b, bpp); - - if (b >= t) - { - /* initialize edge walkers */ - RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off); - RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off); - - fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); - } -} - -static int -_GreaterY (xPointFixed *a, xPointFixed *b) -{ - if (a->y == b->y) - return a->x > b->x; - return a->y > b->y; -} - -/* - * Note that the definition of this function is a bit odd because - * of the X coordinate space (y increasing downwards). - */ -static int -_Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b) -{ - xPointFixed ad, bd; - - ad.x = a->x - ref->x; - ad.y = a->y - ref->y; - bd.x = b->x - ref->x; - bd.y = b->y - ref->y; - - return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0; -} - -/* FIXME -- this could be made more efficient */ -void -fbAddTriangles (PicturePtr pPicture, - INT16 x_off, - INT16 y_off, - int ntri, - xTriangle *tris) -{ - xPointFixed *top, *left, *right, *tmp; - xTrapezoid trap; - - for (; ntri; ntri--, tris++) - { - top = &tris->p1; - left = &tris->p2; - right = &tris->p3; - if (_GreaterY (top, left)) { - tmp = left; left = top; top = tmp; - } - if (_GreaterY (top, right)) { - tmp = right; right = top; top = tmp; - } - if (_Clockwise (top, right, left)) { - tmp = right; right = left; left = tmp; - } - - /* - * Two cases: - * - * + + - * / \ / \ - * / \ / \ - * / + + \ - * / -- -- \ - * / -- -- \ - * / --- --- \ - * +-- --+ - */ - - trap.top = top->y; - trap.left.p1 = *top; - trap.left.p2 = *left; - trap.right.p1 = *top; - trap.right.p2 = *right; - if (right->y < left->y) - trap.bottom = right->y; - else - trap.bottom = left->y; - fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); - if (right->y < left->y) - { - trap.top = right->y; - trap.bottom = left->y; - trap.right.p1 = *right; - trap.right.p2 = *left; - } - else - { - trap.top = left->y; - trap.bottom = right->y; - trap.left.p1 = *left; - trap.left.p2 = *right; - } - fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); - } -} - -#endif /* RENDER */ diff --git a/nx-X11/programs/Xserver/fb/fbtrap.c.X.original b/nx-X11/programs/Xserver/fb/fbtrap.c.X.original deleted file mode 100644 index 39483d8cd..000000000 --- a/nx-X11/programs/Xserver/fb/fbtrap.c.X.original +++ /dev/null @@ -1,239 +0,0 @@ -/* - * $Id: fbtrap.c,v 1.5 2005/07/03 07:01:23 daniels Exp $ - * - * Copyright © 2004 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "fb.h" - -#ifdef RENDER - -#include "picturestr.h" -#include "mipict.h" -#include "renderedge.h" -#include "fbpict.h" - -void -fbAddTraps (PicturePtr pPicture, - INT16 x_off, - INT16 y_off, - int ntrap, - xTrap *traps) -{ - FbBits *buf; - int bpp; - int width; - int stride; - int height; - int pxoff, pyoff; - - xFixed x_off_fixed; - xFixed y_off_fixed; - RenderEdge l, r; - xFixed t, b; - - fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); - - width = pPicture->pDrawable->width; - height = pPicture->pDrawable->height; - x_off += pxoff; - y_off += pyoff; - - x_off_fixed = IntToxFixed(y_off); - y_off_fixed = IntToxFixed(y_off); - - while (ntrap--) - { - t = traps->top.y + y_off_fixed; - if (t < 0) - t = 0; - t = RenderSampleCeilY (t, bpp); - - b = traps->bot.y + y_off_fixed; - if (xFixedToInt (b) >= height) - b = IntToxFixed (height) - 1; - b = RenderSampleFloorY (b, bpp); - - if (b >= t) - { - /* initialize edge walkers */ - RenderEdgeInit (&l, bpp, t, - traps->top.l + x_off_fixed, - traps->top.y + y_off_fixed, - traps->bot.l + x_off_fixed, - traps->bot.y + y_off_fixed); - - RenderEdgeInit (&r, bpp, t, - traps->top.r + x_off_fixed, - traps->top.y + y_off_fixed, - traps->bot.r + x_off_fixed, - traps->bot.y + y_off_fixed); - - fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); - } - traps++; - } -} - -void -fbRasterizeTrapezoid (PicturePtr pPicture, - xTrapezoid *trap, - int x_off, - int y_off) -{ - FbBits *buf; - int bpp; - int width; - int stride; - int height; - int pxoff, pyoff; - - xFixed x_off_fixed; - xFixed y_off_fixed; - RenderEdge l, r; - xFixed t, b; - - fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); - - width = pPicture->pDrawable->width; - height = pPicture->pDrawable->height; - x_off += pxoff; - y_off += pyoff; - - x_off_fixed = IntToxFixed(x_off); - y_off_fixed = IntToxFixed(y_off); - t = trap->top + y_off_fixed; - if (t < 0) - t = 0; - t = RenderSampleCeilY (t, bpp); - - b = trap->bottom + y_off_fixed; - if (xFixedToInt (b) >= height) - b = IntToxFixed (height) - 1; - b = RenderSampleFloorY (b, bpp); - - if (b >= t) - { - /* initialize edge walkers */ - RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off); - RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off); - - fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); - } -} - -static int -_GreaterY (xPointFixed *a, xPointFixed *b) -{ - if (a->y == b->y) - return a->x > b->x; - return a->y > b->y; -} - -/* - * Note that the definition of this function is a bit odd because - * of the X coordinate space (y increasing downwards). - */ -static int -_Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b) -{ - xPointFixed ad, bd; - - ad.x = a->x - ref->x; - ad.y = a->y - ref->y; - bd.x = b->x - ref->x; - bd.y = b->y - ref->y; - - return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0; -} - -/* FIXME -- this could be made more efficient */ -void -fbAddTriangles (PicturePtr pPicture, - INT16 x_off, - INT16 y_off, - int ntri, - xTriangle *tris) -{ - xPointFixed *top, *left, *right, *tmp; - xTrapezoid trap; - - for (; ntri; ntri--, tris++) - { - top = &tris->p1; - left = &tris->p2; - right = &tris->p3; - if (_GreaterY (top, left)) { - tmp = left; left = top; top = tmp; - } - if (_GreaterY (top, right)) { - tmp = right; right = top; top = tmp; - } - if (_Clockwise (top, right, left)) { - tmp = right; right = left; left = tmp; - } - - /* - * Two cases: - * - * + + - * / \ / \ - * / \ / \ - * / + + \ - * / -- -- \ - * / -- -- \ - * / --- --- \ - * +-- --+ - */ - - trap.top = top->y; - trap.left.p1 = *top; - trap.left.p2 = *left; - trap.right.p1 = *top; - trap.right.p2 = *right; - if (right->y < left->y) - trap.bottom = right->y; - else - trap.bottom = left->y; - fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); - if (right->y < left->y) - { - trap.top = right->y; - trap.bottom = left->y; - trap.right.p1 = *right; - trap.right.p2 = *left; - } - else - { - trap.top = left->y; - trap.bottom = right->y; - trap.left.p1 = *left; - trap.left.p2 = *right; - } - fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); - } -} - -#endif /* RENDER */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.NX.original deleted file mode 100644 index 4f59b8098..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.NX.original +++ /dev/null @@ -1,4716 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXdispatch.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ -/************************************************************ - -Copyright 1987, 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/**************************************************************** -* * -* Copyright (c) Digital Equipment Corporation, 1991, 1997 * -* * -* All Rights Reserved. Unpublished rights reserved under * -* the copyright laws of the United States. * -* * -* The software contained on this media is proprietary to * -* and embodies the confidential technology of Digital * -* Equipment Corporation. Possession, use, duplication or * -* dissemination of the software and media is authorized only * -* pursuant to a valid written license from Digital Equipment * -* Corporation. * -* * -* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * -* by the U.S. Government is subject to restrictions as set * -* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * -* or in FAR 52.227-19, as applicable. * -* * -*****************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.29 2003/01/12 02:44:26 dawes Exp $ */ - -#ifdef PANORAMIX_DEBUG -#include -int ProcInitialConnection(); -#endif - -#ifdef __sun -#define False 0 -#define True 1 -#endif - -#define GC XlibGC -#include -#undef GC - -#include "windowstr.h" -#include "fontstruct.h" -#include "dixfontstr.h" -#include "gcstruct.h" -#include "selection.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "opaque.h" -#include "input.h" -#include "servermd.h" -#include "extnsionst.h" -#include "dixfont.h" -#include "../../dix/dispatch.h" -#include "swaprep.h" -#include "swapreq.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif -#ifdef XAPPGROUP -#include "Xagsrv.h" -#endif -#ifdef XKB -#define XKB_IN_SERVER -#include "inputstr.h" -#include "XKBsrv.h" -#endif - -#include "Atoms.h" -#include "Splash.h" -#include "Client.h" -#include "Clipboard.h" -#include "Reconnect.h" -#include "Millis.h" -#include "Font.h" -#include "Shadow.h" -#include "Handlers.h" - -const int nxagentMaxFontNames = 10000; - -char dispatchExceptionAtReset = DE_RESET; - -/* - * This allows the agent to exit if no - * client is connected within a timeout. -*/ - -int nxagentClients = 0; - -void nxagentWaitDisplay(void); - -void nxagentListRemoteFonts(const char *, int); - -unsigned int nxagentWMtimeout = 0; -Bool nxagentWMPassed = 0; - -/* - * Timeouts based on screen saver time. - */ - -int nxagentAutoDisconnectTimeout = 0; - -#ifdef LBX -#include "../../lbx/lbxserve.h" -#endif - -#include "Xatom.h" - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef WATCH - -/* - * Log begin and end of the important handlers. - */ - -#undef BLOCKS - -#ifdef WATCH -#include "unistd.h" -#endif - -#ifdef TEST -#include "Literals.h" -#endif - -#define mskcnt ((MAXCLIENTS + 31) / 32) -#define BITMASK(i) (1U << ((i) & 31)) -#define MASKIDX(i) ((i) >> 5) -#define MASKWORD(buf, i) buf[MASKIDX(i)] -#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) -#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) -#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) - -extern xConnSetupPrefix connSetupPrefix; -extern char *ConnectionInfo; - -Selection *CurrentSelections; -int NumCurrentSelections; - -extern WindowPtr nxagentViewportFrameLeft; -extern WindowPtr nxagentViewportFrameRight; -extern WindowPtr nxagentViewportFrameAbove; -extern WindowPtr nxagentViewportFrameBelow; - -#define IsViewportFrame(pWin) ((pWin) == nxagentViewportFrameLeft || \ - (pWin) == nxagentViewportFrameRight || \ - (pWin) == nxagentViewportFrameAbove || \ - (pWin) == nxagentViewportFrameBelow) - -extern int nxagentMaxAllowedResets; - -extern int nxagentFindClientResource(int, RESTYPE, pointer); - -static ClientPtr grabClient; -#define GrabNone 0 -#define GrabActive 1 -#define GrabKickout 2 -static int grabState = GrabNone; -static long grabWaiters[mskcnt]; -CallbackListPtr ServerGrabCallback = NULL; -HWEventQueuePtr checkForInput[2]; -extern int connBlockScreenStart; - -static void KillAllClients( -#if NeedFunctionPrototypes - void -#endif -); - -static void DeleteClientFromAnySelections( -#if NeedFunctionPrototypes - ClientPtr /*client*/ -#endif -); - -static int nextFreeClientID; /* always MIN free client ID */ - -static int nClients; /* number of authorized clients */ - -CallbackListPtr ClientStateCallback; -char dispatchException = 0; -char isItTimeToYield; - -/* Various of the DIX function interfaces were not designed to allow - * the client->errorValue to be set on BadValue and other errors. - * Rather than changing interfaces and breaking untold code we introduce - * a new global that dispatch can use. - */ -XID clientErrorValue; /* XXX this is a kludge */ - -#define SAME_SCREENS(a, b) (\ - (a.pScreen == b.pScreen)) - -void -SetInputCheck(c0, c1) - HWEventQueuePtr c0, c1; -{ - checkForInput[0] = c0; - checkForInput[1] = c1; -} - -void -UpdateCurrentTime() -{ - TimeStamp systime; - - /* To avoid time running backwards, we must call GetTimeInMillis before - * calling ProcessInputEvents. - */ - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] != *checkForInput[1]) - ProcessInputEvents(); - if (CompareTimeStamps(systime, currentTime) == LATER) - currentTime = systime; -} - -/* Like UpdateCurrentTime, but can't call ProcessInputEvents */ -void -UpdateCurrentTimeIf() -{ - TimeStamp systime; - - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] == *checkForInput[1]) - currentTime = systime; -} - -void -InitSelections() -{ - if (CurrentSelections) - xfree(CurrentSelections); - CurrentSelections = (Selection *)NULL; - NumCurrentSelections = 0; - -#ifdef NXAGENT_CLIPBOARD - { - Selection *newsels; - newsels = (Selection *)xalloc(2 * sizeof(Selection)); - if (!newsels) - return; - NumCurrentSelections += 2; - CurrentSelections = newsels; - - CurrentSelections[0].selection = XA_PRIMARY; - CurrentSelections[0].lastTimeChanged = ClientTimeToServerTime(0); - CurrentSelections[0].window = WindowTable[0]->drawable.id; - CurrentSelections[0].pWin = NULL; - CurrentSelections[0].client = NullClient; - - CurrentSelections[1].selection = MakeAtom("CLIPBOARD", 9, 1); - CurrentSelections[1].lastTimeChanged = ClientTimeToServerTime(0); - CurrentSelections[1].window = WindowTable[0]->drawable.id; - CurrentSelections[1].pWin = NULL; - CurrentSelections[1].client = NullClient; - } -#endif - -} - -void -FlushClientCaches(id) - XID id; -{ - int i; - register ClientPtr client; - - client = clients[CLIENT_ID(id)]; - if (client == NullClient) - return ; - for (i=0; ilastDrawableID == id) - { - client->lastDrawableID = WindowTable[0]->drawable.id; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - } - else if (client->lastGCID == id) - { - client->lastGCID = INVALID; - client->lastGC = (GCPtr)NULL; - } - } - } -} -#ifdef SMART_SCHEDULE - -#undef SMART_DEBUG - -#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */ -#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */ - -/* - * Disable the SmartScheduler as it doesn't - * seem to work for us. - */ - -Bool SmartScheduleDisable = True; - -long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE; -long SmartScheduleTime; -ClientPtr SmartLastClient; -int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1]; -int SmartScheduleClient(int *clientReady, int nready); - -#ifdef SMART_DEBUG -long SmartLastPrint; -#endif - -void Dispatch(void); -void InitProcVectors(void); - -int -SmartScheduleClient (int *clientReady, int nready) -{ - ClientPtr pClient; - int i; - int client; - int bestPrio, best = 0; - int bestRobin, robin; - long now = SmartScheduleTime; - long idle; - - bestPrio = -0x7fffffff; - bestRobin = 0; - idle = 2 * SmartScheduleSlice; - for (i = 0; i < nready; i++) - { - client = clientReady[i]; - pClient = clients[client]; - /* Praise clients which are idle */ - if ((now - pClient->smart_check_tick) >= idle) - { - if (pClient->smart_priority < 0) - pClient->smart_priority++; - } - pClient->smart_check_tick = now; - - /* check priority to select best client */ - robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff; - if (pClient->smart_priority > bestPrio || - (pClient->smart_priority == bestPrio && robin > bestRobin)) - { - bestPrio = pClient->smart_priority; - bestRobin = robin; - best = client; - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - fprintf (stderr, " %2d: %3d", client, pClient->smart_priority); -#endif - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - { - fprintf (stderr, " use %2d\n", best); - SmartLastPrint = now; - } -#endif - pClient = clients[best]; - SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index; - /* - * Set current client pointer - */ - if (SmartLastClient != pClient) - { - pClient->smart_start_tick = now; - SmartLastClient = pClient; - } - /* - * Adjust slice - */ - if (nready == 1) - { - /* - * If it's been a long time since another client - * has run, bump the slice up to get maximal - * performance from a single client - */ - if ((now - pClient->smart_start_tick) > 1000 && - SmartScheduleSlice < SmartScheduleMaxSlice) - { - SmartScheduleSlice += SmartScheduleInterval; - } - } - else - { - SmartScheduleSlice = SmartScheduleInterval; - } - return best; -} -#endif - -#define MAJOROP ((xReq *)client->requestBuffer)->reqType - -void -Dispatch(void) -{ - register int *clientReady; /* array of request ready clients */ - register int result; - register ClientPtr client; - register int nready; - register HWEventQueuePtr* icheck = checkForInput; -#ifdef SMART_SCHEDULE - int start_tick; -#endif - - unsigned long currentDispatch = 0; - - nextFreeClientID = 1; - InitSelections(); - nClients = 0; - - /* - * The agent initialization was successfully - * completed. We can now handle our clients. - */ - - if (serverGeneration > nxagentMaxAllowedResets) - { - fprintf(stderr, "Session: Session started at '%s'.\n", GetTimeAsString()); - - nxagentSessionState = SESSION_UP; - } - -#ifdef NXAGENT_ONSTART - - /* - * Set NX_WM property (used by NX client to identify - * the agent's window) three seconds since the first - * client connects. - */ - - nxagentWMtimeout = GetTimeInMillis() + 3000; - -#endif - - clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients); - if (!clientReady) - return; - - #ifdef WATCH - - fprintf(stderr, "Dispatch: Watchpoint 12.\n"); - -/* -Reply Total Cached Bits In Bits Out Bits/Reply Ratio -------- ----- ------ ------- -------- ---------- ----- -#3 1 352 bits (0 KB) -> 236 bits (0 KB) -> 352/1 -> 236/1 = 1.492:1 -#14 1 256 bits (0 KB) -> 101 bits (0 KB) -> 256/1 -> 101/1 = 2.535:1 -#16 1 256 bits (0 KB) -> 26 bits (0 KB) -> 256/1 -> 26/1 = 9.846:1 -#20 2 2 12256 bits (1 KB) -> 56 bits (0 KB) -> 6128/1 -> 28/1 = 218.857:1 -#43 1 256 bits (0 KB) -> 45 bits (0 KB) -> 256/1 -> 45/1 = 5.689:1 -#47 2 2 42304 bits (5 KB) -> 49 bits (0 KB) -> 21152/1 -> 24/1 = 863.347:1 -#98 1 256 bits (0 KB) -> 34 bits (0 KB) -> 256/1 -> 34/1 = 7.529:1 -*/ - - sleep(30); - - #endif - - #ifdef TEST - fprintf(stderr, "Dispatch: Value of dispatchException is [%x].\n", - dispatchException); - - fprintf(stderr, "Dispatch: Value of dispatchExceptionAtReset is [%x].\n", - dispatchExceptionAtReset); - #endif - - if (!(dispatchException & DE_TERMINATE)) - dispatchException = 0; - - while (!dispatchException) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } - - /* - * Ensure we remove the splash after the timeout. - * Initializing clientReady[0] to -1 will tell - * WaitForSomething() to yield control after the - * timeout set in clientReady[1]. - */ - - clientReady[0] = 0; - - if (nxagentSplashWindow != None || (nxagentOption(Xdmcp) == 1 && nxagentXdmcpUp == 0)) - { - #ifdef TEST - fprintf(stderr, "******Dispatch: Requesting a timeout of [%d] Ms.\n", - NXAGENT_WAKEUP); - #endif - - clientReady[0] = -1; - clientReady[1] = NXAGENT_WAKEUP; - } - - #ifdef BLOCKS - fprintf(stderr, "[End dispatch]\n"); - #endif - - nready = WaitForSomething(clientReady); - - #ifdef BLOCKS - fprintf(stderr, "[Begin dispatch]\n"); - #endif - - #ifdef TEST - fprintf(stderr, "******Dispatch: Running with [%d] clients ready.\n", - nready); - #endif - - #ifdef NXAGENT_ONSTART - - currentDispatch = GetTimeInMillis(); - - /* - * If the timeout is expired set the - * selection informing the NX client - * that the agent is ready. - */ - - if (!nxagentWMPassed && (nxagentWMtimeout < currentDispatch)) - { - nxagentRemoveSplashWindow(NULL); - } - - nxagentClients = nClients; - - #endif - -#ifdef SMART_SCHEDULE - if (nready && !SmartScheduleDisable) - { - clientReady[0] = SmartScheduleClient (clientReady, nready); - nready = 1; - } -#endif - /***************** - * Handle events in round robin fashion, doing input between - * each round - *****************/ - - while (!dispatchException && (--nready >= 0)) - { - client = clients[clientReady[nready]]; - if (! client) - { - /* KillClient can cause this to happen */ - continue; - } - /* GrabServer activation can cause this to be true */ - if (grabState == GrabKickout) - { - grabState = GrabActive; - break; - } - isItTimeToYield = FALSE; - - requestingClient = client; -#ifdef SMART_SCHEDULE - start_tick = SmartScheduleTime; -#endif - while (!isItTimeToYield) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } -#ifdef SMART_SCHEDULE - if (!SmartScheduleDisable && - (SmartScheduleTime - start_tick) >= SmartScheduleSlice) - { - /* Penalize clients which consume ticks */ - if (client->smart_priority > SMART_MIN_PRIORITY) - client->smart_priority--; - break; - } -#endif - /* now, finally, deal with client requests */ - - #ifdef TEST - fprintf(stderr, "******Dispatch: Reading request from client [%d].\n", - client->index); - #endif - - result = ReadRequestFromClient(client); - if (result <= 0) - { - if (result < 0) - CloseDownClient(client); - break; - } -#ifdef NXAGENT_SERVER - - #ifdef TEST - - else - { - if (MAJOROP > 127) - { - fprintf(stderr, "******Dispatch: Read [Extension] request OPCODE#%d MINOR#%d " - "size [%d] client [%d].\n", MAJOROP, *((char *) client->requestBuffer + 1), - client->req_len << 2, client->index); - } - else - { - fprintf(stderr, "******Dispatch: Read [%s] request OPCODE#%d size [%d] client [%d].\n", - nxagentRequestLiteral[MAJOROP], MAJOROP, client->req_len << 2, - client->index); - } - } - - #endif -#endif - - client->sequence++; -#ifdef DEBUG - if (client->requestLogIndex == MAX_REQUEST_LOG) - client->requestLogIndex = 0; - client->requestLog[client->requestLogIndex] = MAJOROP; - client->requestLogIndex++; -#endif - if (result > (MAX_BIG_REQUEST_SIZE << 2)) - result = BadLength; - else -#ifdef NXAGENT_SERVER - { - result = (* client->requestVector[MAJOROP])(client); - - #ifdef TEST - - if (MAJOROP > 127) - { - fprintf(stderr, "******Dispatch: Handled [Extension] request OPCODE#%d MINOR#%d " - "size [%d] client [%d] result [%d].\n", MAJOROP, - *((char *) client->requestBuffer + 1), client->req_len << 2, - client->index, result); - } - else - { - fprintf(stderr, "******Dispatch: Handled [%s] request OPCODE#%d size [%d] client [%d] " - "result [%d].\n", nxagentRequestLiteral[MAJOROP], MAJOROP, - client->req_len << 2, client->index, result); - } - - #endif - - /* - * Can set isItTimeToYield to force - * the dispatcher to pay attention - * to another client. - */ - - nxagentDispatchHandler(client, client->req_len << 2, 0); - } -#else - result = (* client->requestVector[MAJOROP])(client); -#endif - - if (result != Success) - { - if (client->noClientException != Success) - CloseDownClient(client); - else - SendErrorToClient(client, MAJOROP, - MinorOpcodeOfRequest(client), - client->errorValue, result); - break; - } - } - FlushAllOutput(); -#ifdef SMART_SCHEDULE - client = clients[clientReady[nready]]; - if (client) - client->smart_stop_tick = SmartScheduleTime; -#endif - requestingClient = NULL; - } - dispatchException &= ~DE_PRIORITYCHANGE; - } - - if ((dispatchException & DE_RESET) && - (serverGeneration > nxagentMaxAllowedResets)) - { - dispatchException &= ~DE_RESET; - dispatchException |= DE_TERMINATE; - - fprintf(stderr, "Info: Reached threshold of maximum allowed resets.\n"); - } - - nxagentResetAtomMap(); - - if (serverGeneration > nxagentMaxAllowedResets) - { - /* - * The session is terminating. Force an I/O - * error on the display and wait until the - * NX transport is gone. - */ - - fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString()); - - nxagentWaitDisplay(); - - fprintf(stderr, "Session: Session terminated at '%s'.\n", GetTimeAsString()); - } - - if (nxagentOption(Shadow)) - { - NXShadowDestroy(); - } - - KillAllClients(); - DEALLOCATE_LOCAL(clientReady); - dispatchException &= ~DE_RESET; -} - -#undef MAJOROP - -/*ARGSUSED*/ -int -ProcBadRequest(client) - ClientPtr client; -{ - return (BadRequest); -} - -int -ProcCreateWindow(client) - register ClientPtr client; -{ - register WindowPtr pParent, pWin; - REQUEST(xCreateWindowReq); - int result; - int len; - - REQUEST_AT_LEAST_SIZE(xCreateWindowReq); - - LEGAL_NEW_RESOURCE(stuff->wid, client); - if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess))) - return BadWindow; - len = client->req_len - (sizeof(xCreateWindowReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - pWin = CreateWindow(stuff->wid, pParent, stuff->x, - stuff->y, stuff->width, stuff->height, - stuff->borderWidth, stuff->class, - stuff->mask, (XID *) &stuff[1], - (int)stuff->depth, - client, stuff->visual, &result); - if (pWin) - { - Mask mask = pWin->eventMask; - - pWin->eventMask = 0; /* subterfuge in case AddResource fails */ - if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin)) - return BadAlloc; - pWin->eventMask = mask; - } - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcChangeWindowAttributes(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xChangeWindowAttributesReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2); - if (len != Ones(stuff->valueMask)) - return BadLength; - result = ChangeWindowAttributes(pWin, - stuff->valueMask, - (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcGetWindowAttributes(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - xGetWindowAttributesReply wa; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - GetWindowAttributes(pWin, client, &wa); - WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa); - return(client->noClientException); -} - -int -ProcDestroyWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - if (pWin->parent) - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcDestroySubwindows(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - DestroySubwindows(pWin, client); - return(client->noClientException); -} - -int -ProcChangeSaveSet(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xChangeSaveSetReq); - register int result; - - REQUEST_SIZE_MATCH(xChangeSaveSetReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) - return BadMatch; - if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete)) - { - result = AlterSaveSetForClient(client, pWin, stuff->mode); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->mode; - return( BadValue ); - } -} - -int -ProcReparentWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin, pParent; - REQUEST(xReparentWindowReq); - register int result; - - REQUEST_SIZE_MATCH(xReparentWindowReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - - if (!nxagentWMPassed) - { - nxagentRemoveSplashWindow(pWin); - } - - pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess); - if (!pParent) - return(BadWindow); - if (SAME_SCREENS(pWin->drawable, pParent->drawable)) - { - if ((pWin->backgroundState == ParentRelative) && - (pParent->drawable.depth != pWin->drawable.depth)) - return BadMatch; - if ((pWin->drawable.class != InputOnly) && - (pParent->drawable.class == InputOnly)) - return BadMatch; - result = ReparentWindow(pWin, pParent, - (short)stuff->x, (short)stuff->y, client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - return (BadMatch); -} - -int -ProcMapWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapWindow(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcMapSubwindows(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapSubwindows(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcUnmapWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapWindow(pWin, FALSE); - /* update cache to say it is mapped */ - - return(client->noClientException); -} - -int -ProcUnmapSubwindows(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapSubwindows(pWin); - return(client->noClientException); -} - -int -ProcConfigureWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xConfigureWindowReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xConfigureWindowReq) >> 2); - if (Ones((Mask)stuff->mask) != len) - return BadLength; - result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], - client); - - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcCirculateWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xCirculateWindowReq); - - REQUEST_SIZE_MATCH(xCirculateWindowReq); - if ((stuff->direction != RaiseLowest) && - (stuff->direction != LowerHighest)) - { - client->errorValue = stuff->direction; - return BadValue; - } - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - CirculateWindow(pWin, (int)stuff->direction, client); - return(client->noClientException); -} - -int -GetGeometry(client, rep) - register ClientPtr client; - xGetGeometryReply *rep; -{ - register DrawablePtr pDraw; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess); - rep->type = X_Reply; - rep->length = 0; - rep->sequenceNumber = client->sequence; - rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - rep->depth = pDraw->depth; - rep->width = pDraw->width; - rep->height = pDraw->height; - - /* XXX - Because the pixmap-implementation of the multibuffer extension - * may have the buffer-id's drawable resource value be a pointer - * to the buffer's window instead of the buffer itself - * (this happens if the buffer is the displayed buffer), - * we also have to check that the id matches before we can - * truly say that it is a DRAWABLE_WINDOW. - */ - - if ((pDraw->type == UNDRAWABLE_WINDOW) || - ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id))) - { - register WindowPtr pWin = (WindowPtr)pDraw; - rep->x = pWin->origin.x - wBorderWidth (pWin); - rep->y = pWin->origin.y - wBorderWidth (pWin); - rep->borderWidth = pWin->borderWidth; - } - else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */ - { - rep->x = rep->y = rep->borderWidth = 0; - } - - return Success; -} - - -int -ProcGetGeometry(client) - register ClientPtr client; -{ - xGetGeometryReply rep; - int status; - - if ((status = GetGeometry(client, &rep)) != Success) - return status; - - WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); - return(client->noClientException); -} - - -int -ProcQueryTree(client) - register ClientPtr client; -{ - xQueryTreeReply reply; - int numChildren = 0; - register WindowPtr pChild, pWin, pHead; - Window *childIDs = (Window *)NULL; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - reply.type = X_Reply; - reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - reply.sequenceNumber = client->sequence; - if (pWin->parent) - reply.parent = pWin->parent->drawable.id; - else - reply.parent = (Window)None; - pHead = RealChildHead(pWin); - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (!IsViewportFrame(pChild)) - { - numChildren++; - } - } - if (numChildren) - { - int curChild = 0; - - childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window)); - if (!childIDs) - return BadAlloc; - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (!IsViewportFrame(pChild)) - { - childIDs[curChild++] = pChild->drawable.id; - } - } - } - - reply.nChildren = numChildren; - reply.length = (numChildren * sizeof(Window)) >> 2; - - WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply); - if (numChildren) - { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs); - DEALLOCATE_LOCAL(childIDs); - } - - return(client->noClientException); -} - -int -ProcInternAtom(client) - register ClientPtr client; -{ - Atom atom; - char *tchar; - REQUEST(xInternAtomReq); - - REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes); - if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse)) - { - client->errorValue = stuff->onlyIfExists; - return(BadValue); - } - tchar = (char *) &stuff[1]; - atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists); - if (atom != BAD_RESOURCE) - { - xInternAtomReply reply; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.atom = atom; - WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); - return(client->noClientException); - } - else - return (BadAlloc); -} - -int -ProcGetAtomName(client) - register ClientPtr client; -{ - char *str; - xGetAtomNameReply reply; - int len; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if ( (str = NameForAtom(stuff->id)) ) - { - len = strlen(str); - reply.type = X_Reply; - reply.length = (len + 3) >> 2; - reply.sequenceNumber = client->sequence; - reply.nameLength = len; - WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); - (void)WriteToClient(client, len, str); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -#ifdef K5AUTH -extern int k5_bad(); -#endif - -int -ProcSetSelectionOwner(client) - register ClientPtr client; -{ - WindowPtr pWin; - TimeStamp time; - REQUEST(xSetSelectionOwnerReq); - - REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); - UpdateCurrentTime(); - time = ClientTimeToServerTime(stuff->time); - - /* If the client's time stamp is in the future relative to the server's - time stamp, do not set the selection, just return success. */ - if (CompareTimeStamps(time, currentTime) == LATER) - return Success; - if (stuff->window != None) - { - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - } - else - pWin = (WindowPtr)None; - if (ValidAtom(stuff->selection)) - { - int i = 0; - - /* - * First, see if the selection is already set... - */ - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) - i++; - if (i < NumCurrentSelections) - { - xEvent event; - - /* If the timestamp in client's request is in the past relative - to the time stamp indicating the last time the owner of the - selection was set, do not set the selection, just return - success. */ - if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged) - == EARLIER) - return Success; - if (CurrentSelections[i].client && - (!pWin || (CurrentSelections[i].client != client))) - { - event.u.u.type = SelectionClear; - event.u.selectionClear.time = time.milliseconds; - event.u.selectionClear.window = CurrentSelections[i].window; - event.u.selectionClear.atom = CurrentSelections[i].selection; - (void) TryClientEvents (CurrentSelections[i].client, &event, 1, - NoEventMask, NoEventMask /* CantBeFiltered */, - NullGrab); - } - } - else - { - /* - * It doesn't exist, so add it... - */ - Selection *newsels; - - if (i == 0) - newsels = (Selection *)xalloc(sizeof(Selection)); - else - newsels = (Selection *)xrealloc(CurrentSelections, - (NumCurrentSelections + 1) * sizeof(Selection)); - if (!newsels) - return BadAlloc; - NumCurrentSelections++; - CurrentSelections = newsels; - CurrentSelections[i].selection = stuff->selection; - } - CurrentSelections[i].lastTimeChanged = time; - CurrentSelections[i].window = stuff->window; - CurrentSelections[i].pWin = pWin; - CurrentSelections[i].client = (pWin ? client : NullClient); - -#ifdef NXAGENT_CLIPBOARD - if ((CurrentSelections[i].pWin != NULL) && - (nxagentOption(Clipboard) != ClipboardNone) && - ((CurrentSelections[i].selection == XA_PRIMARY) || - (CurrentSelections[i].selection == MakeAtom("CLIPBOARD", 9, 0)))) - { - nxagentSetSelectionOwner(&CurrentSelections[i]); - } -#endif - return (client->noClientException); - } - else - { - client->errorValue = stuff->selection; - return (BadAtom); - } -} - -int -ProcGetSelectionOwner(client) - register ClientPtr client; -{ - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if (ValidAtom(stuff->id)) - { - int i; - xGetSelectionOwnerReply reply; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->id) i++; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - if (i < NumCurrentSelections) - reply.owner = CurrentSelections[i].window; - else - reply.owner = None; - WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -int -ProcConvertSelection(client) - register ClientPtr client; -{ - Bool paramsOkay; - xEvent event; - WindowPtr pWin; - REQUEST(xConvertSelectionReq); - - REQUEST_SIZE_MATCH(xConvertSelectionReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - -#ifdef NXAGENT_CLIPBOARD - if (((stuff->selection == XA_PRIMARY) || - (stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) && - nxagentOption(Clipboard) != ClipboardNone) - { - int i = 0; - - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - - if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None)) - { - if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor, - stuff->property, stuff->target, stuff->time)) - { - return (client->noClientException); - } - } - } -#endif - - paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target)); - if (stuff->property != None) - paramsOkay &= ValidAtom(stuff->property); - if (paramsOkay) - { - int i; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - if ((i < NumCurrentSelections) && - (CurrentSelections[i].window != None) && (CurrentSelections[i].client != NullClient) -#ifdef XCSECURITY - && (!client->CheckAccess || - (* client->CheckAccess)(client, CurrentSelections[i].window, - RT_WINDOW, SecurityReadAccess, - CurrentSelections[i].pWin)) -#endif - ) - { - event.u.u.type = SelectionRequest; - event.u.selectionRequest.time = stuff->time; - event.u.selectionRequest.owner = - CurrentSelections[i].window; - event.u.selectionRequest.requestor = stuff->requestor; - event.u.selectionRequest.selection = stuff->selection; - event.u.selectionRequest.target = stuff->target; - event.u.selectionRequest.property = stuff->property; - if (TryClientEvents( - CurrentSelections[i].client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab)) - return (client->noClientException); - } - event.u.u.type = SelectionNotify; - event.u.selectionNotify.time = stuff->time; - event.u.selectionNotify.requestor = stuff->requestor; - event.u.selectionNotify.selection = stuff->selection; - event.u.selectionNotify.target = stuff->target; - event.u.selectionNotify.property = None; - (void) TryClientEvents(client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab); - return (client->noClientException); - } - else - { - client->errorValue = stuff->property; - return (BadAtom); - } -} - -int -ProcGrabServer(client) - register ClientPtr client; -{ - REQUEST_SIZE_MATCH(xReq); - if (grabState != GrabNone && client != grabClient) - { - ResetCurrentRequest(client); - client->sequence--; - BITSET(grabWaiters, client->index); - IgnoreClient(client); - return(client->noClientException); - } - OnlyListenToOneClient(client); - grabState = GrabKickout; - grabClient = client; - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_GRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } - - return(client->noClientException); -} - -static void -#if NeedFunctionPrototypes -UngrabServer(ClientPtr client) -#else -UngrabServer(client) - ClientPtr client; -#endif -{ - int i; - - grabState = GrabNone; - ListenToAllClients(); - for (i = mskcnt; --i >= 0 && !grabWaiters[i]; ) - ; - if (i >= 0) - { - i <<= 5; - while (!GETBIT(grabWaiters, i)) - i++; - BITCLEAR(grabWaiters, i); - AttendClient(clients[i]); - } - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_UNGRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } -} - -int -ProcUngrabServer(client) - register ClientPtr client; -{ - REQUEST_SIZE_MATCH(xReq); - UngrabServer(client); - return(client->noClientException); -} - -int -ProcTranslateCoords(client) - register ClientPtr client; -{ - REQUEST(xTranslateCoordsReq); - - register WindowPtr pWin, pDst; - xTranslateCoordsReply rep; - - REQUEST_SIZE_MATCH(xTranslateCoordsReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client, - SecurityReadAccess); - if (!pDst) - return(BadWindow); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) - { - rep.sameScreen = xFalse; - rep.child = None; - rep.dstX = rep.dstY = 0; - } - else - { - INT16 x, y; - rep.sameScreen = xTrue; - rep.child = None; - /* computing absolute coordinates -- adjust to destination later */ - x = pWin->drawable.x + stuff->srcX; - y = pWin->drawable.y + stuff->srcY; - pWin = pDst->firstChild; - while (pWin) - { -#ifdef SHAPE - BoxRec box; -#endif - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth (pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - &pWin->borderSize, x, y, &box)) -#endif - ) - { - rep.child = pWin->drawable.id; - pWin = (WindowPtr) NULL; - } - else - pWin = pWin->nextSib; - } - /* adjust to destination coordinates */ - rep.dstX = x - pDst->drawable.x; - rep.dstY = y - pDst->drawable.y; - } - WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep); - return(client->noClientException); -} - -int -ProcOpenFont(client) - register ClientPtr client; -{ - int err; - char fontReq[256]; - REQUEST(xOpenFontReq); - - REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes); - client->errorValue = stuff->fid; - LEGAL_NEW_RESOURCE(stuff->fid, client); - - memcpy(fontReq,(char *)&stuff[1],(stuff->nbytes<256)?stuff->nbytes:255); - fontReq[stuff->nbytes]=0; - if (strchr(fontReq,'*') || strchr(fontReq,'?')) - { - extern int nxOpenFont(ClientPtr, XID, Mask, unsigned, char*); -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Dispatch: ProcOpenFont try to find a common font with font pattern=%s\n",fontReq); -#endif - nxagentListRemoteFonts(fontReq, nxagentMaxFontNames); - err = nxOpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - } - else - err = OpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcCloseFont(client) - register ClientPtr client; -{ - FontPtr pFont; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityDestroyAccess); - if (pFont != (FontPtr)NULL) - { - #ifdef NXAGENT_SERVER - - /* - * When a client closes a font the resource - * should not be lost if the reference counter - * is not 0, otherwise the server will not be - * able to find this font looping through the - * resources. - */ - - if (pFont -> refcnt > 0) - { - if (nxagentFindClientResource(serverClient -> index, RT_NX_FONT, pFont) == 0) - { - #ifdef TEST - fprintf(stderr, "ProcCloseFont: Switching resource for font at [%p].\n", - (void *) pFont); - #endif - - nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index); - - AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont); - - } - #ifdef TEST - else - { - fprintf(stderr, "ProcCloseFont: Found duplicated font at [%p], " - "resource switching skipped.\n", (void *) pFont); - } - #endif - } - - #endif - - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadFont); - } -} - -int -ProcQueryFont(client) - register ClientPtr client; -{ - xQueryFontReply *reply; - FontPtr pFont; - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - client->errorValue = stuff->id; /* EITHER font or gc */ - - pFont = NULL; - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - /* can't use VERIFY_GC because it might return BadGC */ - pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->id; - return(BadFont); /* procotol spec says only error is BadFont */ - } - pFont = pGC->font; - } - -/* test -{ - Atom name_atom, value_atom; - int nprops; - FontPropPtr props; - int i; - char *name; - - name_atom = MakeAtom("FONT", 4, True); - value_atom = 0L; - - nprops = pFont->info.nprops; - props = pFont->info.props; - - for (i = 0; i < nprops; i++) - if (props[i].name == name_atom) { - value_atom = props[i].value; - break; - } - - if (!value_atom) return (BadFont); - - name = (char *)NameForAtom(value_atom); - fprintf(stderr, "QueryFont: font name [%s]\n",name); -} - end test */ - - { - xCharInfo *pmax = FONTINKMAX(pFont); - xCharInfo *pmin = FONTINKMIN(pFont); - int nprotoxcistructs; - int rlength; - - nprotoxcistructs = ( - pmax->rightSideBearing == pmin->rightSideBearing && - pmax->leftSideBearing == pmin->leftSideBearing && - pmax->descent == pmin->descent && - pmax->ascent == pmin->ascent && - pmax->characterWidth == pmin->characterWidth) ? - 0 : N2dChars(pFont); - - rlength = sizeof(xQueryFontReply) + - FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) + - nprotoxcistructs * sizeof(xCharInfo); - reply = NULL; - reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength); - if(!reply) - { - return(BadAlloc); - } - - reply->type = X_Reply; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->sequenceNumber = client->sequence; - QueryFont( pFont, reply, nprotoxcistructs); - - WriteReplyToClient(client, rlength, reply); - DEALLOCATE_LOCAL(reply); - return(client->noClientException); - } -} - -int -ProcQueryTextExtents(client) - register ClientPtr client; -{ - REQUEST(xQueryTextExtentsReq); - xQueryTextExtentsReply reply; - FontPtr pFont; - GC *pGC; - ExtentInfoRec info; - unsigned long length; - - REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); - - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->fid; - return(BadFont); - } - pFont = pGC->font; - } - length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2); - length = length << 1; - if (stuff->oddLength) - { - if (length == 0) - return(BadLength); - length--; - } - if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info)) - return(BadAlloc); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.drawDirection = info.drawDirection; - reply.fontAscent = info.fontAscent; - reply.fontDescent = info.fontDescent; - reply.overallAscent = info.overallAscent; - reply.overallDescent = info.overallDescent; - reply.overallWidth = info.overallWidth; - reply.overallLeft = info.overallLeft; - reply.overallRight = info.overallRight; - WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply); - return(client->noClientException); -} - -int -ProcListFonts(client) - register ClientPtr client; -{ - char tmp[256]; - - REQUEST(xListFontsReq); - - REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes); - memcpy(tmp,(unsigned char *) &stuff[1],(stuff->nbytes<256)?stuff->nbytes:255); - tmp[stuff->nbytes]=0; - -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Dispatch: ListFont request with pattern %s max_names=%d\n",tmp,stuff->maxNames); -#endif - nxagentListRemoteFonts(tmp, stuff -> maxNames < nxagentMaxFontNames ? nxagentMaxFontNames : stuff->maxNames); - return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, - stuff->maxNames); -} - -int -ProcListFontsWithInfo(client) - register ClientPtr client; -{ - char tmp[256]; - REQUEST(xListFontsWithInfoReq); - - REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes); - - memcpy(tmp,(unsigned char *) &stuff[1],(stuff->nbytes<256)?stuff->nbytes:255); - tmp[stuff->nbytes]=0; -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Dispatch: ListFont with info request with pattern %s max_names=%d\n",tmp,stuff->maxNames); -#endif - nxagentListRemoteFonts(tmp, stuff -> maxNames < nxagentMaxFontNames ? nxagentMaxFontNames :stuff->maxNames); - - return StartListFontsWithInfo(client, stuff->nbytes, - (unsigned char *) &stuff[1], stuff->maxNames); -} - -/*ARGSUSED*/ -int -dixDestroyPixmap(value, pid) - pointer value; /* must conform to DeleteType */ - XID pid; -{ - PixmapPtr pPixmap = (PixmapPtr)value; - return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); -} - -int -ProcCreatePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - REQUEST(xCreatePixmapReq); - DepthPtr pDepth; - register int i; - - REQUEST_SIZE_MATCH(xCreatePixmapReq); - client->errorValue = stuff->pid; - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap) - (pDraw->pScreen, stuff->width, - stuff->height, stuff->depth); - if (pMap) - { - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - return(client->noClientException); - } - return (BadAlloc); -} - -int -ProcFreePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP, - SecurityDestroyAccess); - if (pMap) - { - #ifdef NXAGENT_SERVER - - /* - * When a client releases a pixmap the resource - * should not be lost if the reference counter - * is not 0, otherwise the server will not be - * able to find this pixmap looping through the - * resources. - */ - - if (pMap -> refcnt > 0) - { - if (nxagentFindClientResource(serverClient -> index, RT_NX_PIXMAP, pMap) == 0) - { - #ifdef TEST - fprintf(stderr, "ProcFreePixmap: Switching resource for pixmap at [%p].\n", - (void *) pMap); - #endif - - nxagentPixmapPriv(pMap) -> mid = FakeClientID(serverClient -> index); - - AddResource(nxagentPixmapPriv(pMap) -> mid, RT_NX_PIXMAP, pMap); - } - #ifdef TEST - else - { - fprintf(stderr, "ProcFreePixmap: Found duplicated pixmap at [%p], " - "resource switching skipped.\n", (void *) pMap); - } - #endif - } - - #endif - - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadPixmap); - } -} - -int -ProcCreateGC(client) - register ClientPtr client; -{ - int error; - GC *pGC; - register DrawablePtr pDraw; - unsigned len; - REQUEST(xCreateGCReq); - - REQUEST_AT_LEAST_SIZE(xCreateGCReq); - client->errorValue = stuff->gc; - LEGAL_NEW_RESOURCE(stuff->gc, client); - SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - len = client->req_len - (sizeof(xCreateGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - pGC = (GC *)CreateGC(pDraw, stuff->mask, - (XID *) &stuff[1], &error); - if (error != Success) - return error; - if (!AddResource(stuff->gc, RT_GC, (pointer)pGC)) - return (BadAlloc); - return(client->noClientException); -} - -int -ProcChangeGC(client) - register ClientPtr client; -{ - GC *pGC; - REQUEST(xChangeGCReq); - int result; - unsigned len; - - REQUEST_AT_LEAST_SIZE(xChangeGCReq); - SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess); - len = client->req_len - (sizeof(xChangeGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - - result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcCopyGC(client) - register ClientPtr client; -{ - register GC *dstGC; - register GC *pGC; - int result; - REQUEST(xCopyGCReq); - - REQUEST_SIZE_MATCH(xCopyGCReq); - SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess); - SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess); - if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth)) - return (BadMatch); - result = CopyGC(pGC, dstGC, stuff->mask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetDashes(client) - register ClientPtr client; -{ - register GC *pGC; - int result; - REQUEST(xSetDashesReq); - - REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes); - if (stuff->nDashes == 0) - { - client->errorValue = 0; - return BadValue; - } - - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes, - (unsigned char *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetClipRectangles(client) - register ClientPtr client; -{ - int nr; - int result; - register GC *pGC; - REQUEST(xSetClipRectanglesReq); - - REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq); - if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && - (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) - { - client->errorValue = stuff->ordering; - return BadValue; - } - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq); - if (nr & 4) - return(BadLength); - nr >>= 3; - result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *)&stuff[1], (int)stuff->ordering); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcFreeGC(client) - register ClientPtr client; -{ - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess); - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcClearToBackground(client) - register ClientPtr client; -{ - REQUEST(xClearAreaReq); - register WindowPtr pWin; - - REQUEST_SIZE_MATCH(xClearAreaReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (pWin->drawable.class == InputOnly) - { - client->errorValue = stuff->window; - return (BadMatch); - } - if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) - { - client->errorValue = stuff->exposures; - return(BadValue); - } - (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y, - stuff->width, stuff->height, - (Bool)stuff->exposures); - return(client->noClientException); -} - -int -ProcCopyArea(client) - register ClientPtr client; -{ - register DrawablePtr pDst; - register DrawablePtr pSrc; - register GC *pGC; - REQUEST(xCopyAreaReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyAreaReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client, - SecurityReadAccess); - if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - pSrc = pDst; - - SET_DBE_SRCBUF(pSrc, stuff->srcDrawable); - - pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY); - if (pGC->graphicsExposures) - { - (*pDst->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); - if (pRgn) - REGION_DESTROY(pDst->pScreen, pRgn); - } - - return(client->noClientException); -} - -int -ProcCopyPlane(client) - register ClientPtr client; -{ - register DrawablePtr psrcDraw, pdstDraw; - register GC *pGC; - REQUEST(xCopyPlaneReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyPlaneReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client, - SecurityReadAccess); - if (pdstDraw->pScreen != psrcDraw->pScreen) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - psrcDraw = pdstDraw; - - SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable); - - /* Check to see if stuff->bitPlane has exactly ONE good bit set */ - if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || - (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) - { - client->errorValue = stuff->bitPlane; - return(BadValue); - } - - pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY, stuff->bitPlane); - if (pGC->graphicsExposures) - { - (*pdstDraw->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); - if (pRgn) - REGION_DESTROY(pdstDraw->pScreen, pRgn); - } - return(client->noClientException); -} - -int -ProcPolyPoint(client) - register ClientPtr client; -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyPointReq); - - REQUEST_AT_LEAST_SIZE(xPolyPointReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2; - if (npoint) - { - (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, - (xPoint *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcPolyLine(client) - register ClientPtr client; -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyLineReq); - - REQUEST_AT_LEAST_SIZE(xPolyLineReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2; - if (npoint > 1) - { - (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, - (DDXPointPtr) &stuff[1]); - } - return(client->noClientException); -} - -int -ProcPolySegment(client) - register ClientPtr client; -{ - int nsegs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolySegmentReq); - - REQUEST_AT_LEAST_SIZE(xPolySegmentReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); - if (nsegs & 4) - return(BadLength); - nsegs >>= 3; - if (nsegs) - { - (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcPolyRectangle (client) - register ClientPtr client; -{ - int nrects; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); - if (nrects & 4) - return(BadLength); - nrects >>= 3; - if (nrects) - { - (*pGC->ops->PolyRectangle)(pDraw, pGC, - nrects, (xRectangle *) &stuff[1]); - } - return(client->noClientException); -} - -int -ProcPolyArc(client) - register ClientPtr client; -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - { - (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcFillPoly(client) - register ClientPtr client; -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xFillPolyReq); - - REQUEST_AT_LEAST_SIZE(xFillPolyReq); - if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) && - (stuff->shape != Convex)) - { - client->errorValue = stuff->shape; - return BadValue; - } - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2; - if (things) - { - (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, - stuff->coordMode, things, - (DDXPointPtr) &stuff[1]); - } - return(client->noClientException); -} - -int -ProcPolyFillRectangle(client) - register ClientPtr client; -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); - if (things & 4) - return(BadLength); - things >>= 3; - - if (things) - { - (*pGC->ops->PolyFillRect) (pDraw, pGC, things, - (xRectangle *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcPolyFillArc(client) - register ClientPtr client; -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - { - (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); - } - return (client->noClientException); -} - -#ifdef MATCH_CLIENT_ENDIAN - -int -ServerOrder (void) -{ - int whichbyte = 1; - - if (*((char *) &whichbyte)) - return LSBFirst; - return MSBFirst; -} - -#define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder()) - -void -ReformatImage (char *base, int nbytes, int bpp, int order) -{ - switch (bpp) { - case 1: /* yuck */ - if (BITMAP_BIT_ORDER != order) - BitOrderInvert ((unsigned char *) base, nbytes); -#if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8 - ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order); -#endif - break; - case 4: - break; /* yuck */ - case 8: - break; - case 16: - if (IMAGE_BYTE_ORDER != order) - TwoByteSwap ((unsigned char *) base, nbytes); - break; - case 32: - if (IMAGE_BYTE_ORDER != order) - FourByteSwap ((unsigned char *) base, nbytes); - break; - } -} -#else -#define ReformatImage(b,n,bpp,o) -#endif - -/* 64-bit server notes: the protocol restricts padding of images to - * 8-, 16-, or 32-bits. We would like to have 64-bits for the server - * to use internally. Removes need for internal alignment checking. - * All of the PutImage functions could be changed individually, but - * as currently written, they call other routines which require things - * to be 64-bit padded on scanlines, so we changed things here. - * If an image would be padded differently for 64- versus 32-, then - * copy each scanline to a 64-bit padded scanline. - * Also, we need to make sure that the image is aligned on a 64-bit - * boundary, even if the scanlines are padded to our satisfaction. - */ -int -ProcPutImage(client) - register ClientPtr client; -{ - register GC *pGC; - register DrawablePtr pDraw; - long length; /* length of scanline server padded */ - long lengthProto; /* length of scanline protocol padded */ - char *tmpImage; - REQUEST(xPutImageReq); - - REQUEST_AT_LEAST_SIZE(xPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - if (stuff->format == XYBitmap) - { - if ((stuff->depth != 1) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - } - else if (stuff->format == XYPixmap) - { - if ((pDraw->depth != stuff->depth) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0)) - return BadMatch; - length = PixmapBytePad(stuff->width, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - tmpImage = (char *)&stuff[1]; - lengthProto = length; - - if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) + - (sizeof(xPutImageReq) >> 2)) != client->req_len) - return BadLength; - - ReformatImage (tmpImage, lengthProto * stuff->height, - stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1, - ClientOrder(client)); - - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY, - stuff->width, stuff->height, - stuff->leftPad, stuff->format, tmpImage); - - return (client->noClientException); -} - - -int -DoGetImage(client, format, drawable, x, y, width, height, planemask, im_return) - register ClientPtr client; - Drawable drawable; - int format; - int x, y, width, height; - Mask planemask; - xGetImageReply **im_return; -{ - register DrawablePtr pDraw; - int nlines, linesPerBuf; - register int linesDone; - long widthBytesLine, length; - Mask plane = 0; - char *pBuf; - xGetImageReply xgi; - RegionPtr pVisibleRegion = NULL; - - if ((format != XYPixmap) && (format != ZPixmap)) - { - client->errorValue = format; - return(BadValue); - } - SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess); - if(pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + x < 0 || - pDraw->x + x + width > pDraw->pScreen->width || - pDraw->y + y < 0 || - pDraw->y + y + height > pDraw->pScreen->height || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual (((WindowPtr) pDraw)); - } - else - { - if(x < 0 || - x+width > (int)pDraw->width || - y < 0 || - y+height > (int)pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - - SET_DBE_SRCBUF(pDraw, drawable); - - xgi.type = X_Reply; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(format == ZPixmap) - { - widthBytesLine = PixmapBytePad(width, pDraw->depth); - length = widthBytesLine * height; - - } - else - { - widthBytesLine = BitmapBytePad(width); - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = widthBytesLine * height * - Ones(planemask & (plane | (plane - 1))); - - } - - xgi.length = length; - - if (im_return) { - pBuf = (char *)xalloc(sz_xGetImageReply + length); - if (!pBuf) - return (BadAlloc); - if (widthBytesLine == 0) - linesPerBuf = 0; - else - linesPerBuf = height; - *im_return = (xGetImageReply *)pBuf; - *(xGetImageReply *)pBuf = xgi; - pBuf += sz_xGetImageReply; - } else { - xgi.length = (xgi.length + 3) >> 2; - if (widthBytesLine == 0 || height == 0) - linesPerBuf = 0; - else if (widthBytesLine >= IMAGE_BUFSIZE) - linesPerBuf = 1; - else - { - linesPerBuf = IMAGE_BUFSIZE / widthBytesLine; - if (linesPerBuf > height) - linesPerBuf = height; - } - length = linesPerBuf * widthBytesLine; - if (linesPerBuf < height) - { - /* we have to make sure intermediate buffers don't need padding */ - while ((linesPerBuf > 1) && - (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))) - { - linesPerBuf--; - length -= widthBytesLine; - } - while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)) - { - linesPerBuf++; - length += widthBytesLine; - } - } - if(!(pBuf = (char *) ALLOCATE_LOCAL(length))) - return (BadAlloc); - WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); - } - -#ifdef XCSECURITY - if (client->trustLevel != XSecurityClientTrusted && - pDraw->type == DRAWABLE_WINDOW) - { - pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw); - if (pVisibleRegion) - { - REGION_TRANSLATE(pScreen, pVisibleRegion, -pDraw->x, -pDraw->y); - } - } -#endif - - if (linesPerBuf == 0) - { - /* nothing to do */ - } - else if (format == ZPixmap) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - planemask, - (pointer) pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note that this is NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (!im_return) - { - ReformatImage (pBuf, (int)(nlines * widthBytesLine), - BitsPerPixel (pDraw->depth), - ClientOrder(client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - else /* XYPixmap */ - { - for (; plane; plane >>= 1) - { - if (planemask & plane) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - plane, - (pointer)pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, - widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note: NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (im_return) { - pBuf += nlines * widthBytesLine; - } else { - ReformatImage (pBuf, - (int)(nlines * widthBytesLine), - 1, - ClientOrder (client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - } - } -#ifdef XCSECURITY - if (pVisibleRegion) - REGION_DESTROY(pScreen, pVisibleRegion); -#endif - if (!im_return) - DEALLOCATE_LOCAL(pBuf); - return (client->noClientException); -} - -int -ProcGetImage(client) - register ClientPtr client; -{ - REQUEST(xGetImageReq); - - REQUEST_SIZE_MATCH(xGetImageReq); - - return DoGetImage(client, stuff->format, stuff->drawable, - stuff->x, stuff->y, - (int)stuff->width, (int)stuff->height, - stuff->planeMask, (xGetImageReply **)NULL); -} - -int -ProcPolyText(client) - register ClientPtr client; -{ - int err; - REQUEST(xPolyTextReq); - DrawablePtr pDraw; - GC *pGC; - - REQUEST_AT_LEAST_SIZE(xPolyTextReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = PolyText(client, - pDraw, - pGC, - (unsigned char *)&stuff[1], - ((unsigned char *) stuff) + (client->req_len << 2), - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText8(client) - register ClientPtr client; -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText16(client) - register ClientPtr client; -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - - -int -ProcCreateColormap(client) - register ClientPtr client; -{ - VisualPtr pVisual; - ColormapPtr pmap; - Colormap mid; - register WindowPtr pWin; - ScreenPtr pScreen; - REQUEST(xCreateColormapReq); - int i, result; - - REQUEST_SIZE_MATCH(xCreateColormapReq); - - if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) - { - client->errorValue = stuff->alloc; - return(BadValue); - } - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pScreen = pWin->drawable.pScreen; - for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid != stuff->visual) - continue; - result = CreateColormap(mid, pScreen, pVisual, &pmap, - (int)stuff->alloc, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - client->errorValue = stuff->visual; - return(BadValue); -} - -int -ProcFreeColormap(client) - register ClientPtr client; -{ - ColormapPtr pmap; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP, - SecurityDestroyAccess); - if (pmap) - { - /* Freeing a default colormap is a no-op */ - if (!(pmap->flags & IsDefault)) - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - - -int -ProcCopyColormapAndFree(client) - register ClientPtr client; -{ - Colormap mid; - ColormapPtr pSrcMap; - REQUEST(xCopyColormapAndFreeReq); - int result; - - REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client, stuff->srcCmap, - RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) ) - { - result = CopyColormapAndFree(mid, pSrcMap, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->srcCmap; - return(BadColor); - } -} - -int -ProcInstallColormap(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - (*(pcmp->pScreen->InstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcUninstallColormap(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - if(pcmp->mid != pcmp->pScreen->defColormap) - (*(pcmp->pScreen->UninstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcListInstalledColormaps(client) - register ClientPtr client; -{ - xListInstalledColormapsReply *preply; - int nummaps; - WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - - if (!pWin) - return(BadWindow); - - preply = (xListInstalledColormapsReply *) - ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) + - pWin->drawable.pScreen->maxInstalledCmaps * - sizeof(Colormap)); - if(!preply) - return(BadAlloc); - - preply->type = X_Reply; - preply->sequenceNumber = client->sequence; - nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pWin->drawable.pScreen, (Colormap *)&preply[1]); - preply->nColormaps = nummaps; - preply->length = nummaps; - WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); - DEALLOCATE_LOCAL(preply); - return(client->noClientException); -} - -int -ProcAllocColor(client) - register ClientPtr client; -{ - ColormapPtr pmap; - int retval; - xAllocColorReply acr; - REQUEST(xAllocColorReq); - - REQUEST_SIZE_MATCH(xAllocColorReq); - pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pmap) - { -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pmap, (xReq *) stuff)) - return Success; -#endif - acr.type = X_Reply; - acr.length = 0; - acr.sequenceNumber = client->sequence; - acr.red = stuff->red; - acr.green = stuff->green; - acr.blue = stuff->blue; - acr.pixel = 0; - if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, - &acr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return (retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pmap->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); - return (client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocNamedColor (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xAllocNamedColorReq); - - REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int retval; - - xAllocNamedColorReply ancr; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocNamedColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - ancr.type = X_Reply; - ancr.length = 0; - ancr.sequenceNumber = client->sequence; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) - { - ancr.screenRed = ancr.exactRed; - ancr.screenGreen = ancr.exactGreen; - ancr.screenBlue = ancr.exactBlue; - ancr.pixel = 0; - if( (retval = AllocColor(pcmp, - &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue, - &ancr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr); - return (client->noClientException); - } - else - return(BadName); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorCells (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xAllocColorCellsReq); - - REQUEST_SIZE_MATCH(xAllocColorCellsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorCellsReply accr; - int npixels, nmasks, retval; - long length; - Pixel *ppixels, *pmasks; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorCells request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - nmasks = stuff->planes; - length = ((long)npixels + (long)nmasks) * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - pmasks = ppixels + npixels; - - if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, - (Bool)stuff->contiguous, ppixels, pmasks)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - accr.type = X_Reply; - accr.length = length >> 2; - accr.sequenceNumber = client->sequence; - accr.nPixels = npixels; - accr.nMasks = nmasks; - WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorPlanes(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xAllocColorPlanesReq); - - REQUEST_SIZE_MATCH(xAllocColorPlanesReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorPlanesReply acpr; - int npixels, retval; - long length; - Pixel *ppixels; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorPlanes request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - acpr.type = X_Reply; - acpr.sequenceNumber = client->sequence; - acpr.nPixels = npixels; - length = (long)npixels * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - if( (retval = AllocColorPlanes(client->index, pcmp, npixels, - (int)stuff->red, (int)stuff->green, (int)stuff->blue, - (Bool)stuff->contiguous, ppixels, - &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - acpr.length = length >> 2; -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcFreeColors (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xFreeColorsReq); - - REQUEST_AT_LEAST_SIZE(xFreeColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - if(pcmp->flags & AllAllocated) - return(BadAccess); - count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2; - retval = FreeColors(pcmp, client->index, count, - (Pixel *)&stuff[1], (Pixel)stuff->planeMask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreColors (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xStoreColorsReq); - - REQUEST_AT_LEAST_SIZE(xStoreColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - count = (client->req_len << 2) - sizeof(xStoreColorsReq); - if (count % sizeof(xColorItem)) - return(BadLength); - count /= sizeof(xColorItem); - retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreNamedColor (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xStoreNamedColorReq); - - REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xColorItem def; - int retval; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], - stuff->nbytes, &def.red, &def.green, &def.blue)) - { - def.flags = stuff->flags; - def.pixel = stuff->pixel; - retval = StoreColors(pcmp, 1, &def); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcQueryColors(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xQueryColorsReq); - - REQUEST_AT_LEAST_SIZE(xQueryColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - int count, retval; - xrgb *prgbs; - xQueryColorsReply qcr; - - count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2; - prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb)); - if(!prgbs && count) - return(BadAlloc); - if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) ) - { - if (prgbs) DEALLOCATE_LOCAL(prgbs); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return (retval); - } - } - qcr.type = X_Reply; - qcr.length = (count * sizeof(xrgb)) >> 2; - qcr.sequenceNumber = client->sequence; - qcr.nColors = count; - WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); - if (count) - { - client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; - WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); - } - if (prgbs) DEALLOCATE_LOCAL(prgbs); - return(client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcLookupColor(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xLookupColorReq); - - REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - xLookupColorReply lcr; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) - { - lcr.type = X_Reply; - lcr.length = 0; - lcr.sequenceNumber = client->sequence; - lcr.screenRed = lcr.exactRed; - lcr.screenGreen = lcr.exactGreen; - lcr.screenBlue = lcr.exactBlue; - (*pcmp->pScreen->ResolveColor)(&lcr.screenRed, - &lcr.screenGreen, - &lcr.screenBlue, - pcmp->pVisual); - WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); - return(client->noClientException); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcCreateCursor( client) - register ClientPtr client; -{ - CursorPtr pCursor; - - register PixmapPtr src; - register PixmapPtr msk; - unsigned char * srcbits; - unsigned char * mskbits; - unsigned short width, height; - long n; - CursorMetricRec cm; - - - REQUEST(xCreateCursorReq); - - REQUEST_SIZE_MATCH(xCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source, - RT_PIXMAP, SecurityReadAccess); - msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask, - RT_PIXMAP, SecurityReadAccess); - if ( src == (PixmapPtr)NULL) - { - client->errorValue = stuff->source; - return (BadPixmap); - } - if ( msk == (PixmapPtr)NULL) - { - if (stuff->mask != None) - { - client->errorValue = stuff->mask; - return (BadPixmap); - } - } - else if ( src->drawable.width != msk->drawable.width - || src->drawable.height != msk->drawable.height - || src->drawable.depth != 1 - || msk->drawable.depth != 1) - return (BadMatch); - - width = src->drawable.width; - height = src->drawable.height; - - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - - n = BitmapBytePad(width)*height; - srcbits = (unsigned char *)xalloc(n); - if (!srcbits) - return (BadAlloc); - mskbits = (unsigned char *)xalloc(n); - if (!mskbits) - { - xfree(srcbits); - return (BadAlloc); - } - - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)srcbits, n); - (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height, - XYPixmap, 1, (pointer)srcbits); - if ( msk == (PixmapPtr)NULL) - { - register unsigned char *bits = mskbits; - while (--n >= 0) - *bits++ = ~0; - } - else - { - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)mskbits, n); - (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width, - height, XYPixmap, 1, (pointer)mskbits); - } - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - pCursor = AllocCursor( srcbits, mskbits, &cm, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue); - - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - { - #ifdef TEST - fprintf(stderr, "ProcCreateCursor: Created cursor at [%p].\n", (void *) pCursor); - #endif - - return (client->noClientException); - } - - return BadAlloc; -} - -int -ProcCreateGlyphCursor( client) - register ClientPtr client; -{ - CursorPtr pCursor; - int res; - - REQUEST(xCreateGlyphCursorReq); - - REQUEST_SIZE_MATCH(xCreateGlyphCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - res = AllocGlyphCursor(stuff->source, stuff->sourceChar, - stuff->mask, stuff->maskChar, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client); - if (res != Success) - return res; - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - - -int -ProcFreeCursor(client) - register ClientPtr client; -{ - CursorPtr pCursor; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id, - RT_CURSOR, SecurityDestroyAccess); - if (pCursor) - { - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadCursor); - } -} - -int -ProcQueryBestSize (client) - register ClientPtr client; -{ - xQueryBestSizeReply reply; - register DrawablePtr pDraw; - ScreenPtr pScreen; - REQUEST(xQueryBestSizeReq); - - REQUEST_SIZE_MATCH(xQueryBestSizeReq); - if ((stuff->class != CursorShape) && - (stuff->class != TileShape) && - (stuff->class != StippleShape)) - { - client->errorValue = stuff->class; - return(BadValue); - } - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW) - return (BadMatch); - pScreen = pDraw->pScreen; - (* pScreen->QueryBestSize)(stuff->class, &stuff->width, - &stuff->height, pScreen); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.width = stuff->width; - reply.height = stuff->height; - WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply); - return (client->noClientException); -} - - -int -ProcSetScreenSaver (client) - register ClientPtr client; -{ - int blankingOption, exposureOption; - REQUEST(xSetScreenSaverReq); - - REQUEST_SIZE_MATCH(xSetScreenSaverReq); - blankingOption = stuff->preferBlank; - if ((blankingOption != DontPreferBlanking) && - (blankingOption != PreferBlanking) && - (blankingOption != DefaultBlanking)) - { - client->errorValue = blankingOption; - return BadValue; - } - exposureOption = stuff->allowExpose; - if ((exposureOption != DontAllowExposures) && - (exposureOption != AllowExposures) && - (exposureOption != DefaultExposures)) - { - client->errorValue = exposureOption; - return BadValue; - } - if (stuff->timeout < -1) - { - client->errorValue = stuff->timeout; - return BadValue; - } - if (stuff->interval < -1) - { - client->errorValue = stuff->interval; - return BadValue; - } - - /* - * The NX agent uses the screen saver procedure - * to monitor the user activities and launch its - * handlers (like timeout feature), so we can't - * always allow the clients to change our values. - */ - - #ifdef TEST - fprintf(stderr, "ProcSetScreenSaver: Called with timeout [%d] interval [%d] Blanking [%d] Exposure [%d].\n", - stuff -> timeout, stuff -> interval, blankingOption, exposureOption); - #endif - - if (nxagentOption(Timeout) == 0) - { - if (blankingOption == DefaultBlanking) - { - ScreenSaverBlanking = defaultScreenSaverBlanking; - } - else - { - ScreenSaverBlanking = blankingOption; - } - - if (exposureOption == DefaultExposures) - { - ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; - } - else - { - ScreenSaverAllowExposures = exposureOption; - } - - if (stuff->timeout >= 0) - { - ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND; - } - else - { - ScreenSaverTime = defaultScreenSaverTime; - } - - if (stuff->interval >= 0) - { - ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND; - } - else - { - ScreenSaverInterval = defaultScreenSaverInterval; - } - } - - #ifdef TEST - - else - { - fprintf(stderr, "ProcSetScreenSaver: Keeping auto-disconnect timeout set to [%d] seconds.\n", - nxagentOption(Timeout)); - } - - #endif - - return (client->noClientException); -} - -int -ProcGetScreenSaver(client) - register ClientPtr client; -{ - xGetScreenSaverReply rep; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.timeout = ScreenSaverTime / MILLI_PER_SECOND; - rep.interval = ScreenSaverInterval / MILLI_PER_SECOND; - rep.preferBlanking = ScreenSaverBlanking; - rep.allowExposures = ScreenSaverAllowExposures; - WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep); - return (client->noClientException); -} - -int -ProcChangeHosts(client) - register ClientPtr client; -{ - REQUEST(xChangeHostsReq); - int result; - - REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength); - - if(stuff->mode == HostInsert) - result = AddHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else if (stuff->mode == HostDelete) - result = RemoveHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else - { - client->errorValue = stuff->mode; - return BadValue; - } - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcListHosts(client) - register ClientPtr client; -{ - xListHostsReply reply; - int len, nHosts, result; - pointer pdata; - /* REQUEST(xListHostsReq); */ - - REQUEST_SIZE_MATCH(xListHostsReq); -#ifdef XCSECURITY - /* untrusted clients can't list hosts */ - if (client->trustLevel != XSecurityClientTrusted) - { - SecurityAudit("client %d attempted to list hosts\n", client->index); - return BadAccess; - } -#endif - result = GetHosts(&pdata, &nHosts, &len, &reply.enabled); - if (result != Success) - return(result); - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.nHosts = nHosts; - reply.length = len >> 2; - WriteReplyToClient(client, sizeof(xListHostsReply), &reply); - if (nHosts) - { - client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; - WriteSwappedDataToClient(client, len, pdata); - } - xfree(pdata); - return (client->noClientException); -} - -int -ProcChangeAccessControl(client) - register ClientPtr client; -{ - int result; - REQUEST(xSetAccessControlReq); - - REQUEST_SIZE_MATCH(xSetAccessControlReq); - if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) - { - client->errorValue = stuff->mode; - return BadValue; - } - result = ChangeAccessControl(client, stuff->mode == EnableAccess); - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcKillClient(client) - register ClientPtr client; -{ - REQUEST(xResourceReq); - ClientPtr killclient; - - REQUEST_SIZE_MATCH(xResourceReq); - if (stuff->id == AllTemporary) - { - CloseDownRetainedResources(); - return (client->noClientException); - } - - if ((killclient = LookupClient(stuff->id, client))) - { - CloseDownClient(killclient); - /* if an LBX proxy gets killed, isItTimeToYield will be set */ - if (isItTimeToYield || (client == killclient)) - { - /* force yield and return Success, so that Dispatch() - * doesn't try to touch client - */ - isItTimeToYield = TRUE; - return (Success); - } - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadValue); - } -} - -int -ProcSetFontPath(client) - register ClientPtr client; -{ - unsigned char *ptr; - unsigned long nbytes, total; - long nfonts; - int n, result; - int error; - REQUEST(xSetFontPathReq); - - REQUEST_AT_LEAST_SIZE(xSetFontPathReq); - - nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq); - total = nbytes; - ptr = (unsigned char *)&stuff[1]; - nfonts = stuff->nFonts; - while (--nfonts >= 0) - { - if ((total == 0) || (total < (n = (*ptr + 1)))) - return(BadLength); - total -= n; - ptr += n; - } - if (total >= 4) - return(BadLength); - result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1], - &error); - if (!result) - { - result = client->noClientException; - client->errorValue = error; - } - return (result); -} - -int -ProcGetFontPath(client) - register ClientPtr client; -{ - xGetFontPathReply reply; - int stringLens, numpaths; - unsigned char *bufferStart; - /* REQUEST (xReq); */ - - REQUEST_SIZE_MATCH(xReq); - bufferStart = GetFontPath(&numpaths, &stringLens); - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = (stringLens + numpaths + 3) >> 2; - reply.nPaths = numpaths; - - WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); - if (stringLens || numpaths) - (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart); - return(client->noClientException); -} - -int -ProcChangeCloseDownMode(client) - register ClientPtr client; -{ - REQUEST(xSetCloseDownModeReq); - - REQUEST_SIZE_MATCH(xSetCloseDownModeReq); - if ((stuff->mode == AllTemporary) || - (stuff->mode == RetainPermanent) || - (stuff->mode == RetainTemporary)) - { - client->closeDownMode = stuff->mode; - return (client->noClientException); - } - else - { - client->errorValue = stuff->mode; - return (BadValue); - } -} - -int ProcForceScreenSaver(client) - register ClientPtr client; -{ - REQUEST(xForceScreenSaverReq); - - REQUEST_SIZE_MATCH(xForceScreenSaverReq); - - if ((stuff->mode != ScreenSaverReset) && - (stuff->mode != ScreenSaverActive)) - { - client->errorValue = stuff->mode; - return BadValue; - } - - /* - * The NX agent uses the screen saver procedure - * to monitor the user activities and launch its - * handlers (like timeout feature), so we can't - * always allow the clients to force the screen - * saver handler execution. - */ - - if (nxagentOption(Timeout) == 0) - { - SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode); - } - - #ifdef TEST - - else - { - fprintf(stderr, "ProcForceScreenSaver: Ignoring the client request with mode [%d].\n", - stuff -> mode); - } - - #endif - - return client->noClientException; -} - -int ProcNoOperation(client) - register ClientPtr client; -{ - REQUEST_AT_LEAST_SIZE(xReq); - - /* noop -- don't do anything */ - return(client->noClientException); -} - -void -InitProcVectors(void) -{ - int i; - for (i = 0; i<256; i++) - { - if(!ProcVector[i]) - { - ProcVector[i] = SwappedProcVector[i] = ProcBadRequest; - ReplySwapVector[i] = ReplyNotSwappd; - } -#ifdef K5AUTH - if (!k5_Vector[i]) - { - k5_Vector[i] = k5_bad; - } -#endif - } - for(i = LASTEvent; i < 128; i++) - { - EventSwapVector[i] = NotImplemented; - } - -} - -/********************** - * CloseDownClient - * - * Client can either mark his resources destroy or retain. If retained and - * then killed again, the client is really destroyed. - *********************/ - -void -CloseDownClient(client) - register ClientPtr client; -{ - Bool really_close_down = client->clientGone || - client->closeDownMode == DestroyAll; - - /* - * There must be a better way to hook a - * call-back function to be called any - * time a client is going to be closed. - */ - - nxagentClearClipboard(client, NULL); - - /* - * Need to reset the karma counter and - * get rid of the pending sync replies. - */ - - nxagentWakeupByReset(client); - - /* - * Check if the client - * is a shadow nxagent. - */ - - nxagentCheckIfShadowAgent(client); - - if (!client->clientGone) - { - /* ungrab server if grabbing client dies */ - if (grabState != GrabNone && grabClient == client) - { - UngrabServer(client); - } - BITCLEAR(grabWaiters, client->index); - DeleteClientFromAnySelections(client); - ReleaseActiveGrabs(client); - DeleteClientFontStuff(client); - if (!really_close_down) - { - /* This frees resources that should never be retained - * no matter what the close down mode is. Actually we - * could do this unconditionally, but it's probably - * better not to traverse all the client's resources - * twice (once here, once a few lines down in - * FreeClientResources) in the common case of - * really_close_down == TRUE. - */ - FreeClientNeverRetainResources(client); - client->clientState = ClientStateRetained; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - } - client->clientGone = TRUE; /* so events aren't sent to client */ - if (ClientIsAsleep(client)) - ClientSignal (client); - ProcessWorkQueueZombies(); -#ifdef LBX - ProcessQTagZombies(); -#endif - CloseDownConnection(client); - - /* If the client made it to the Running stage, nClients has - * been incremented on its behalf, so we need to decrement it - * now. If it hasn't gotten to Running, nClients has *not* - * been incremented, so *don't* decrement it. - */ - if (client->clientState != ClientStateInitial && - client->clientState != ClientStateAuthenticating ) - { - --nClients; - } - } - - if (really_close_down) - { - if (client->clientState == ClientStateRunning && nClients == 0) - dispatchException |= dispatchExceptionAtReset; - - client->clientState = ClientStateGone; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - FreeClientResources(client); - if (client->index < nextFreeClientID) - nextFreeClientID = client->index; - clients[client->index] = NullClient; -#ifdef SMART_SCHEDULE - SmartLastClient = NullClient; -#endif - xfree(client); - - while (!clients[currentMaxClients-1]) - currentMaxClients--; - } -} - -static void -KillAllClients() -{ - int i; - for (i=1; icloseDownMode = DestroyAll; - CloseDownClient(clients[i]); - } -} - -/********************* - * CloseDownRetainedResources - * - * Find all clients that are gone and have terminated in RetainTemporary - * and destroy their resources. - *********************/ - -void -CloseDownRetainedResources() -{ - register int i; - register ClientPtr client; - - for (i=1; icloseDownMode == RetainTemporary) - && (client->clientGone)) - CloseDownClient(client); - } -} - -void InitClient(client, i, ospriv) - ClientPtr client; - int i; - pointer ospriv; -{ - client->index = i; - client->sequence = 0; - client->clientAsMask = ((Mask)i) << CLIENTOFFSET; - client->clientGone = FALSE; - if (i) - { - client->closeDownMode = DestroyAll; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - client->lastDrawableID = WindowTable[0]->drawable.id; - } - else - { - client->closeDownMode = RetainPermanent; - client->lastDrawable = (DrawablePtr)NULL; - client->lastDrawableID = INVALID; - } - client->lastGC = (GCPtr) NULL; - client->lastGCID = INVALID; - client->numSaved = 0; - client->saveSet = (pointer *)NULL; - client->noClientException = Success; -#ifdef LOG_DEBUG - client->requestLogIndex = 0; -#endif - client->requestVector = InitialVector; - client->osPrivate = ospriv; - client->swapped = FALSE; - client->big_requests = FALSE; - client->priority = 0; - client->clientState = ClientStateInitial; -#ifdef XKB - if (!noXkbExtension) { - client->xkbClientFlags = 0; - client->mapNotifyMask = 0; - QueryMinMaxKeyCodes(&client->minKC,&client->maxKC); - } -#endif - client->replyBytesRemaining = 0; -#ifdef LBX - client->readRequest = StandardReadRequestFromClient; -#endif -#ifdef XCSECURITY - client->trustLevel = XSecurityClientTrusted; - client->CheckAccess = NULL; - client->authId = 0; -#endif -#ifdef XAPPGROUP - client->appgroup = NULL; -#endif - client->fontResFunc = NULL; -#ifdef SMART_SCHEDULE - client->smart_priority = 0; - client->smart_start_tick = SmartScheduleTime; - client->smart_stop_tick = SmartScheduleTime; - client->smart_check_tick = SmartScheduleTime; -#endif -} - -extern int clientPrivateLen; -extern unsigned *clientPrivateSizes; -extern unsigned totalClientSize; - -int -InitClientPrivates(client) - ClientPtr client; -{ - register char *ptr; - DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - if (totalClientSize == sizeof(ClientRec)) - ppriv = (DevUnion *)NULL; - else if (client->index) - ppriv = (DevUnion *)(client + 1); - else - { - ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec)); - if (!ppriv) - return 0; - } - client->devPrivates = ppriv; - sizes = clientPrivateSizes; - ptr = (char *)(ppriv + clientPrivateLen); - for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - - /* - * Initialize the private members. - */ - - nxagentInitClientPrivates(client); - - return 1; -} - -/************************ - * int NextAvailableClient(ospriv) - * - * OS dependent portion can't assign client id's because of CloseDownModes. - * Returns NULL if there are no free clients. - *************************/ - -ClientPtr -NextAvailableClient(ospriv) - pointer ospriv; -{ - register int i; - register ClientPtr client; - xReq data; - - i = nextFreeClientID; - if (i == MAXCLIENTS) - return (ClientPtr)NULL; - clients[i] = client = (ClientPtr)xalloc(totalClientSize); - if (!client) - return (ClientPtr)NULL; - InitClient(client, i, ospriv); - InitClientPrivates(client); - if (!InitClientResources(client)) - { - xfree(client); - return (ClientPtr)NULL; - } - data.reqType = 1; - data.length = (sz_xReq + sz_xConnClientPrefix) >> 2; - if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) - { - FreeClientResources(client); - xfree(client); - return (ClientPtr)NULL; - } - if (i == currentMaxClients) - currentMaxClients++; - while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID]) - nextFreeClientID++; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return(client); -} - -int -ProcInitialConnection(client) - register ClientPtr client; -{ - REQUEST(xReq); - register xConnClientPrefix *prefix; - int whichbyte = 1; - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B')) - return (client->noClientException = -1); - if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) - { - client->swapped = TRUE; - SwapConnClientPrefix(prefix); - } - stuff->reqType = 2; - stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) + - ((prefix->nbytesAuthString + (unsigned)3) >> 2); - if (client->swapped) - { - swaps(&stuff->length, whichbyte); - } - ResetCurrentRequest(client); - return (client->noClientException); -} - -#ifdef LBX -void -IncrementClientCount() -{ - nClients++; -} -#endif - -int -SendConnSetup(client, reason) - register ClientPtr client; - char *reason; -{ - register xWindowRoot *root; - register int i; - int numScreens; - char* lConnectionInfo; - xConnSetupPrefix* lconnSetupPrefix; - - if (reason) - { - xConnSetupPrefix csp; - - csp.success = xFalse; - csp.lengthReason = strlen(reason); - csp.length = (csp.lengthReason + (unsigned)3) >> 2; - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (client->swapped) - WriteSConnSetupPrefix(client, &csp); - else - (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); - (void)WriteToClient(client, (int)csp.lengthReason, reason); - return (client->noClientException = -1); - } - - numScreens = screenInfo.numScreens; - lConnectionInfo = ConnectionInfo; - lconnSetupPrefix = &connSetupPrefix; - - /* We're about to start speaking X protocol back to the client by - * sending the connection setup info. This means the authorization - * step is complete, and we can count the client as an - * authorized one. - */ - nClients++; - - client->requestVector = client->swapped ? SwappedProcVector : ProcVector; - client->sequence = 0; -#ifdef XAPPGROUP - XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens); -#endif - ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask; - ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK; -#ifdef MATCH_CLIENT_ENDIAN - ((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client); - ((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client); -#endif - /* fill in the "currentInputMask" */ - root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart); -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#endif - - for (i=0; icurrentInputMask = WindowTable[i]->eventMask | - wOtherEventMasks (WindowTable[i]); - pDepth = (xDepth *)(root + 1); - for (j = 0; j < root->nDepths; j++) - { - pDepth = (xDepth *)(((char *)(pDepth + 1)) + - pDepth->nVisuals * sizeof(xVisualType)); - } - root = (xWindowRoot *)pDepth; - } - - if (client->swapped) - { - WriteSConnSetupPrefix(client, lconnSetupPrefix); - WriteSConnectionInfo(client, - (unsigned long)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - else - { - (void)WriteToClient(client, sizeof(xConnSetupPrefix), - (char *) lconnSetupPrefix); - (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - client->clientState = ClientStateRunning; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = lconnSetupPrefix; - clientinfo.setup = (xConnSetup *)lConnectionInfo; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return (client->noClientException); -} - -int -ProcEstablishConnection(client) - register ClientPtr client; -{ - char *reason, *auth_proto, *auth_string; - register xConnClientPrefix *prefix; - REQUEST(xReq); - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - auth_proto = (char *)prefix + sz_xConnClientPrefix; - auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3); - if ((prefix->majorVersion != X_PROTOCOL) || - (prefix->minorVersion != X_PROTOCOL_REVISION)) - reason = "Protocol version mismatch"; - else - reason = ClientAuthorized(client, - (unsigned short)prefix->nbytesAuthProto, - auth_proto, - (unsigned short)prefix->nbytesAuthString, - auth_string); - /* - * If Kerberos is being used for this client, the clientState - * will be set to ClientStateAuthenticating at this point. - * More messages need to be exchanged among the X server, Kerberos - * server, and client to figure out if everyone is authorized. - * So we don't want to send the connection setup info yet, since - * the auth step isn't really done. - */ - if (client->clientState == ClientStateCheckingSecurity) - client->clientState = ClientStateCheckedSecurity; - else if (client->clientState != ClientStateAuthenticating) - return(SendConnSetup(client, reason)); - return(client->noClientException); -} - -void -SendErrorToClient(client, majorCode, minorCode, resId, errorCode) - ClientPtr client; - unsigned int majorCode; - unsigned int minorCode; - XID resId; - int errorCode; -{ - xError rep; - - rep.type = X_Error; - rep.sequenceNumber = client->sequence; - rep.errorCode = errorCode; - rep.majorCode = majorCode; - rep.minorCode = minorCode; - rep.resourceID = resId; - - WriteEventsToClient (client, 1, (xEvent *)&rep); -} - -void -DeleteWindowFromAnySelections(pWin) - WindowPtr pWin; -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].pWin == pWin) - { - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -static void -DeleteClientFromAnySelections(client) - ClientPtr client; -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].client == client) - { - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -void -MarkClientException(client) - ClientPtr client; -{ - client->noClientException = -1; -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.XF86.original deleted file mode 100644 index a385a8b09..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c.XF86.original +++ /dev/null @@ -1,4110 +0,0 @@ -/* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ -/************************************************************ - -Copyright 1987, 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/**************************************************************** -* * -* Copyright (c) Digital Equipment Corporation, 1991, 1997 * -* * -* All Rights Reserved. Unpublished rights reserved under * -* the copyright laws of the United States. * -* * -* The software contained on this media is proprietary to * -* and embodies the confidential technology of Digital * -* Equipment Corporation. Possession, use, duplication or * -* dissemination of the software and media is authorized only * -* pursuant to a valid written license from Digital Equipment * -* Corporation. * -* * -* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * -* by the U.S. Government is subject to restrictions as set * -* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * -* or in FAR 52.227-19, as applicable. * -* * -*****************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.29 2003/01/12 02:44:26 dawes Exp $ */ - -#ifdef PANORAMIX_DEBUG -#include -int ProcInitialConnection(); -#endif - -#include "windowstr.h" -#include "fontstruct.h" -#include "dixfontstr.h" -#include "gcstruct.h" -#include "selection.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "opaque.h" -#include "input.h" -#include "servermd.h" -#include "extnsionst.h" -#include "dixfont.h" -#include "dispatch.h" -#include "swaprep.h" -#include "swapreq.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif -#ifdef XAPPGROUP -#include "Xagsrv.h" -#endif -#ifdef XKB -#define XKB_IN_SERVER -#include "inputstr.h" -#include "XKBsrv.h" -#endif -#ifdef LBX -#include "lbxserve.h" -#endif - -#define mskcnt ((MAXCLIENTS + 31) / 32) -#define BITMASK(i) (1U << ((i) & 31)) -#define MASKIDX(i) ((i) >> 5) -#define MASKWORD(buf, i) buf[MASKIDX(i)] -#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) -#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) -#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) - -extern xConnSetupPrefix connSetupPrefix; -extern char *ConnectionInfo; - -Selection *CurrentSelections; -int NumCurrentSelections; - -static ClientPtr grabClient; -#define GrabNone 0 -#define GrabActive 1 -#define GrabKickout 2 -static int grabState = GrabNone; -static long grabWaiters[mskcnt]; -CallbackListPtr ServerGrabCallback = NULL; -HWEventQueuePtr checkForInput[2]; -extern int connBlockScreenStart; - -static void KillAllClients( -#if NeedFunctionPrototypes - void -#endif -); - -static void DeleteClientFromAnySelections( -#if NeedFunctionPrototypes - ClientPtr /*client*/ -#endif -); - -static int nextFreeClientID; /* always MIN free client ID */ - -static int nClients; /* number of authorized clients */ - -CallbackListPtr ClientStateCallback; -char dispatchException = 0; -char isItTimeToYield; - -/* Various of the DIX function interfaces were not designed to allow - * the client->errorValue to be set on BadValue and other errors. - * Rather than changing interfaces and breaking untold code we introduce - * a new global that dispatch can use. - */ -XID clientErrorValue; /* XXX this is a kludge */ - -#define SAME_SCREENS(a, b) (\ - (a.pScreen == b.pScreen)) - -void -SetInputCheck(c0, c1) - HWEventQueuePtr c0, c1; -{ - checkForInput[0] = c0; - checkForInput[1] = c1; -} - -void -UpdateCurrentTime() -{ - TimeStamp systime; - - /* To avoid time running backwards, we must call GetTimeInMillis before - * calling ProcessInputEvents. - */ - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] != *checkForInput[1]) - ProcessInputEvents(); - if (CompareTimeStamps(systime, currentTime) == LATER) - currentTime = systime; -} - -/* Like UpdateCurrentTime, but can't call ProcessInputEvents */ -void -UpdateCurrentTimeIf() -{ - TimeStamp systime; - - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] == *checkForInput[1]) - currentTime = systime; -} - -void -InitSelections() -{ - if (CurrentSelections) - xfree(CurrentSelections); - CurrentSelections = (Selection *)NULL; - NumCurrentSelections = 0; -} - -void -FlushClientCaches(id) - XID id; -{ - int i; - register ClientPtr client; - - client = clients[CLIENT_ID(id)]; - if (client == NullClient) - return ; - for (i=0; ilastDrawableID == id) - { - client->lastDrawableID = WindowTable[0]->drawable.id; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - } - else if (client->lastGCID == id) - { - client->lastGCID = INVALID; - client->lastGC = (GCPtr)NULL; - } - } - } -} -#ifdef SMART_SCHEDULE - -#undef SMART_DEBUG - -#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */ -#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */ - -Bool SmartScheduleDisable; -long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE; -long SmartScheduleTime; -ClientPtr SmartLastClient; -int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1]; -int SmartScheduleClient(int *clientReady, int nready); - -#ifdef SMART_DEBUG -long SmartLastPrint; -#endif - -void Dispatch(void); -void InitProcVectors(void); - -int -SmartScheduleClient (int *clientReady, int nready) -{ - ClientPtr pClient; - int i; - int client; - int bestPrio, best = 0; - int bestRobin, robin; - long now = SmartScheduleTime; - long idle; - - bestPrio = -0x7fffffff; - bestRobin = 0; - idle = 2 * SmartScheduleSlice; - for (i = 0; i < nready; i++) - { - client = clientReady[i]; - pClient = clients[client]; - /* Praise clients which are idle */ - if ((now - pClient->smart_check_tick) >= idle) - { - if (pClient->smart_priority < 0) - pClient->smart_priority++; - } - pClient->smart_check_tick = now; - - /* check priority to select best client */ - robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff; - if (pClient->smart_priority > bestPrio || - (pClient->smart_priority == bestPrio && robin > bestRobin)) - { - bestPrio = pClient->smart_priority; - bestRobin = robin; - best = client; - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - fprintf (stderr, " %2d: %3d", client, pClient->smart_priority); -#endif - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - { - fprintf (stderr, " use %2d\n", best); - SmartLastPrint = now; - } -#endif - pClient = clients[best]; - SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index; - /* - * Set current client pointer - */ - if (SmartLastClient != pClient) - { - pClient->smart_start_tick = now; - SmartLastClient = pClient; - } - /* - * Adjust slice - */ - if (nready == 1) - { - /* - * If it's been a long time since another client - * has run, bump the slice up to get maximal - * performance from a single client - */ - if ((now - pClient->smart_start_tick) > 1000 && - SmartScheduleSlice < SmartScheduleMaxSlice) - { - SmartScheduleSlice += SmartScheduleInterval; - } - } - else - { - SmartScheduleSlice = SmartScheduleInterval; - } - return best; -} -#endif - -#define MAJOROP ((xReq *)client->requestBuffer)->reqType - -void -Dispatch(void) -{ - register int *clientReady; /* array of request ready clients */ - register int result; - register ClientPtr client; - register int nready; - register HWEventQueuePtr* icheck = checkForInput; -#ifdef SMART_SCHEDULE - int start_tick; -#endif - - #ifdef __DARWIN__ - extern char dispatchExceptionAtReset; - #endif - - nextFreeClientID = 1; - InitSelections(); - nClients = 0; - - clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients); - if (!clientReady) - return; - - while (!dispatchException) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } - - nready = WaitForSomething(clientReady); - -#ifdef SMART_SCHEDULE - if (nready && !SmartScheduleDisable) - { - clientReady[0] = SmartScheduleClient (clientReady, nready); - nready = 1; - } -#endif - /***************** - * Handle events in round robin fashion, doing input between - * each round - *****************/ - - while (!dispatchException && (--nready >= 0)) - { - client = clients[clientReady[nready]]; - if (! client) - { - /* KillClient can cause this to happen */ - continue; - } - /* GrabServer activation can cause this to be true */ - if (grabState == GrabKickout) - { - grabState = GrabActive; - break; - } - isItTimeToYield = FALSE; - - requestingClient = client; -#ifdef SMART_SCHEDULE - start_tick = SmartScheduleTime; -#endif - while (!isItTimeToYield) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } -#ifdef SMART_SCHEDULE - if (!SmartScheduleDisable && - (SmartScheduleTime - start_tick) >= SmartScheduleSlice) - { - /* Penalize clients which consume ticks */ - if (client->smart_priority > SMART_MIN_PRIORITY) - client->smart_priority--; - break; - } -#endif - /* now, finally, deal with client requests */ - - result = ReadRequestFromClient(client); - if (result <= 0) - { - if (result < 0) - CloseDownClient(client); - break; - } - - client->sequence++; -#ifdef DEBUG - if (client->requestLogIndex == MAX_REQUEST_LOG) - client->requestLogIndex = 0; - client->requestLog[client->requestLogIndex] = MAJOROP; - client->requestLogIndex++; -#endif - if (result > (MAX_BIG_REQUEST_SIZE << 2)) - result = BadLength; - else - result = (* client->requestVector[MAJOROP])(client); - - if (result != Success) - { - if (client->noClientException != Success) - CloseDownClient(client); - else - SendErrorToClient(client, MAJOROP, - MinorOpcodeOfRequest(client), - client->errorValue, result); - break; - } - } - FlushAllOutput(); -#ifdef SMART_SCHEDULE - client = clients[clientReady[nready]]; - if (client) - client->smart_stop_tick = SmartScheduleTime; -#endif - requestingClient = NULL; - } - dispatchException &= ~DE_PRIORITYCHANGE; - - /* - * On Darwin we found that the it is not possible - * to get the correct keyboard layout unless it is - * set on the local machine, before the NX session - * is started, by using xmodmap. As we set the key- - * board locally, we must prevent the X server to - * reset, otherwise we would loose any local confi- - * guration. The code below is aimed at this. Note - * also that a statically compiled version of xmod- - * map is included in the MacOS/X package. - */ - - #ifdef __DARWIN__ - - if (dispatchException & DE_RESET ) - { - dispatchException &= ~DE_RESET; - - dispatchExceptionAtReset = DE_TERMINATE; - } - - #endif /* __DARWIN__ */ - - } - KillAllClients(); - DEALLOCATE_LOCAL(clientReady); - dispatchException &= ~DE_RESET; -} - -#undef MAJOROP - -/*ARGSUSED*/ -int -ProcBadRequest(client) - ClientPtr client; -{ - return (BadRequest); -} - -int -ProcCreateWindow(client) - register ClientPtr client; -{ - register WindowPtr pParent, pWin; - REQUEST(xCreateWindowReq); - int result; - int len; - - REQUEST_AT_LEAST_SIZE(xCreateWindowReq); - - LEGAL_NEW_RESOURCE(stuff->wid, client); - if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess))) - return BadWindow; - len = client->req_len - (sizeof(xCreateWindowReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - pWin = CreateWindow(stuff->wid, pParent, stuff->x, - stuff->y, stuff->width, stuff->height, - stuff->borderWidth, stuff->class, - stuff->mask, (XID *) &stuff[1], - (int)stuff->depth, - client, stuff->visual, &result); - if (pWin) - { - Mask mask = pWin->eventMask; - - pWin->eventMask = 0; /* subterfuge in case AddResource fails */ - if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin)) - return BadAlloc; - pWin->eventMask = mask; - } - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcChangeWindowAttributes(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xChangeWindowAttributesReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2); - if (len != Ones(stuff->valueMask)) - return BadLength; - result = ChangeWindowAttributes(pWin, - stuff->valueMask, - (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcGetWindowAttributes(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - xGetWindowAttributesReply wa; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - GetWindowAttributes(pWin, client, &wa); - WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa); - return(client->noClientException); -} - -int -ProcDestroyWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - if (pWin->parent) - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcDestroySubwindows(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - DestroySubwindows(pWin, client); - return(client->noClientException); -} - -int -ProcChangeSaveSet(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xChangeSaveSetReq); - register int result; - - REQUEST_SIZE_MATCH(xChangeSaveSetReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) - return BadMatch; - if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete)) - { - result = AlterSaveSetForClient(client, pWin, stuff->mode); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->mode; - return( BadValue ); - } -} - -int -ProcReparentWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin, pParent; - REQUEST(xReparentWindowReq); - register int result; - - REQUEST_SIZE_MATCH(xReparentWindowReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess); - if (!pParent) - return(BadWindow); - if (SAME_SCREENS(pWin->drawable, pParent->drawable)) - { - if ((pWin->backgroundState == ParentRelative) && - (pParent->drawable.depth != pWin->drawable.depth)) - return BadMatch; - if ((pWin->drawable.class != InputOnly) && - (pParent->drawable.class == InputOnly)) - return BadMatch; - result = ReparentWindow(pWin, pParent, - (short)stuff->x, (short)stuff->y, client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - return (BadMatch); -} - -int -ProcMapWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapWindow(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcMapSubwindows(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapSubwindows(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcUnmapWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapWindow(pWin, FALSE); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcUnmapSubwindows(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapSubwindows(pWin); - return(client->noClientException); -} - -int -ProcConfigureWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xConfigureWindowReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xConfigureWindowReq) >> 2); - if (Ones((Mask)stuff->mask) != len) - return BadLength; - result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcCirculateWindow(client) - register ClientPtr client; -{ - register WindowPtr pWin; - REQUEST(xCirculateWindowReq); - - REQUEST_SIZE_MATCH(xCirculateWindowReq); - if ((stuff->direction != RaiseLowest) && - (stuff->direction != LowerHighest)) - { - client->errorValue = stuff->direction; - return BadValue; - } - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - CirculateWindow(pWin, (int)stuff->direction, client); - return(client->noClientException); -} - -int -GetGeometry(client, rep) - register ClientPtr client; - xGetGeometryReply *rep; -{ - register DrawablePtr pDraw; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess); - rep->type = X_Reply; - rep->length = 0; - rep->sequenceNumber = client->sequence; - rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - rep->depth = pDraw->depth; - rep->width = pDraw->width; - rep->height = pDraw->height; - - /* XXX - Because the pixmap-implementation of the multibuffer extension - * may have the buffer-id's drawable resource value be a pointer - * to the buffer's window instead of the buffer itself - * (this happens if the buffer is the displayed buffer), - * we also have to check that the id matches before we can - * truly say that it is a DRAWABLE_WINDOW. - */ - - if ((pDraw->type == UNDRAWABLE_WINDOW) || - ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id))) - { - register WindowPtr pWin = (WindowPtr)pDraw; - rep->x = pWin->origin.x - wBorderWidth (pWin); - rep->y = pWin->origin.y - wBorderWidth (pWin); - rep->borderWidth = pWin->borderWidth; - } - else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */ - { - rep->x = rep->y = rep->borderWidth = 0; - } - - return Success; -} - - -int -ProcGetGeometry(client) - register ClientPtr client; -{ - xGetGeometryReply rep; - int status; - - if ((status = GetGeometry(client, &rep)) != Success) - return status; - - WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); - return(client->noClientException); -} - - -int -ProcQueryTree(client) - register ClientPtr client; -{ - xQueryTreeReply reply; - int numChildren = 0; - register WindowPtr pChild, pWin, pHead; - Window *childIDs = (Window *)NULL; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - reply.type = X_Reply; - reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - reply.sequenceNumber = client->sequence; - if (pWin->parent) - reply.parent = pWin->parent->drawable.id; - else - reply.parent = (Window)None; - pHead = RealChildHead(pWin); - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - numChildren++; - if (numChildren) - { - int curChild = 0; - - childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window)); - if (!childIDs) - return BadAlloc; - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - childIDs[curChild++] = pChild->drawable.id; - } - - reply.nChildren = numChildren; - reply.length = (numChildren * sizeof(Window)) >> 2; - - WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply); - if (numChildren) - { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs); - DEALLOCATE_LOCAL(childIDs); - } - - return(client->noClientException); -} - -int -ProcInternAtom(client) - register ClientPtr client; -{ - Atom atom; - char *tchar; - REQUEST(xInternAtomReq); - - REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes); - if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse)) - { - client->errorValue = stuff->onlyIfExists; - return(BadValue); - } - tchar = (char *) &stuff[1]; - atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists); - if (atom != BAD_RESOURCE) - { - xInternAtomReply reply; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.atom = atom; - WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); - return(client->noClientException); - } - else - return (BadAlloc); -} - -int -ProcGetAtomName(client) - register ClientPtr client; -{ - char *str; - xGetAtomNameReply reply; - int len; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if ( (str = NameForAtom(stuff->id)) ) - { - len = strlen(str); - reply.type = X_Reply; - reply.length = (len + 3) >> 2; - reply.sequenceNumber = client->sequence; - reply.nameLength = len; - WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); - (void)WriteToClient(client, len, str); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -#ifdef K5AUTH -extern int k5_bad(); -#endif - -int -ProcSetSelectionOwner(client) - register ClientPtr client; -{ - WindowPtr pWin; - TimeStamp time; - REQUEST(xSetSelectionOwnerReq); - - REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); - UpdateCurrentTime(); - time = ClientTimeToServerTime(stuff->time); - - /* If the client's time stamp is in the future relative to the server's - time stamp, do not set the selection, just return success. */ - if (CompareTimeStamps(time, currentTime) == LATER) - return Success; - if (stuff->window != None) - { - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - } - else - pWin = (WindowPtr)None; - if (ValidAtom(stuff->selection)) - { - int i = 0; - - /* - * First, see if the selection is already set... - */ - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) - i++; - if (i < NumCurrentSelections) - { - xEvent event; - - /* If the timestamp in client's request is in the past relative - to the time stamp indicating the last time the owner of the - selection was set, do not set the selection, just return - success. */ - if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged) - == EARLIER) - return Success; - if (CurrentSelections[i].client && - (!pWin || (CurrentSelections[i].client != client))) - { - event.u.u.type = SelectionClear; - event.u.selectionClear.time = time.milliseconds; - event.u.selectionClear.window = CurrentSelections[i].window; - event.u.selectionClear.atom = CurrentSelections[i].selection; - (void) TryClientEvents (CurrentSelections[i].client, &event, 1, - NoEventMask, NoEventMask /* CantBeFiltered */, - NullGrab); - } - } - else - { - /* - * It doesn't exist, so add it... - */ - Selection *newsels; - - if (i == 0) - newsels = (Selection *)xalloc(sizeof(Selection)); - else - newsels = (Selection *)xrealloc(CurrentSelections, - (NumCurrentSelections + 1) * sizeof(Selection)); - if (!newsels) - return BadAlloc; - NumCurrentSelections++; - CurrentSelections = newsels; - CurrentSelections[i].selection = stuff->selection; - } - CurrentSelections[i].lastTimeChanged = time; - CurrentSelections[i].window = stuff->window; - CurrentSelections[i].pWin = pWin; - CurrentSelections[i].client = (pWin ? client : NullClient); - return (client->noClientException); - } - else - { - client->errorValue = stuff->selection; - return (BadAtom); - } -} - -int -ProcGetSelectionOwner(client) - register ClientPtr client; -{ - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if (ValidAtom(stuff->id)) - { - int i; - xGetSelectionOwnerReply reply; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->id) i++; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - if (i < NumCurrentSelections) - reply.owner = CurrentSelections[i].window; - else - reply.owner = None; - WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -int -ProcConvertSelection(client) - register ClientPtr client; -{ - Bool paramsOkay; - xEvent event; - WindowPtr pWin; - REQUEST(xConvertSelectionReq); - - REQUEST_SIZE_MATCH(xConvertSelectionReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target)); - if (stuff->property != None) - paramsOkay &= ValidAtom(stuff->property); - if (paramsOkay) - { - int i; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - if ((i < NumCurrentSelections) && - (CurrentSelections[i].window != None) -#ifdef XCSECURITY - && (!client->CheckAccess || - (* client->CheckAccess)(client, CurrentSelections[i].window, - RT_WINDOW, SecurityReadAccess, - CurrentSelections[i].pWin)) -#endif - ) - { - event.u.u.type = SelectionRequest; - event.u.selectionRequest.time = stuff->time; - event.u.selectionRequest.owner = - CurrentSelections[i].window; - event.u.selectionRequest.requestor = stuff->requestor; - event.u.selectionRequest.selection = stuff->selection; - event.u.selectionRequest.target = stuff->target; - event.u.selectionRequest.property = stuff->property; - if (TryClientEvents( - CurrentSelections[i].client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab)) - return (client->noClientException); - } - event.u.u.type = SelectionNotify; - event.u.selectionNotify.time = stuff->time; - event.u.selectionNotify.requestor = stuff->requestor; - event.u.selectionNotify.selection = stuff->selection; - event.u.selectionNotify.target = stuff->target; - event.u.selectionNotify.property = None; - (void) TryClientEvents(client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab); - return (client->noClientException); - } - else - { - client->errorValue = stuff->property; - return (BadAtom); - } -} - -int -ProcGrabServer(client) - register ClientPtr client; -{ - REQUEST_SIZE_MATCH(xReq); - if (grabState != GrabNone && client != grabClient) - { - ResetCurrentRequest(client); - client->sequence--; - BITSET(grabWaiters, client->index); - IgnoreClient(client); - return(client->noClientException); - } - OnlyListenToOneClient(client); - grabState = GrabKickout; - grabClient = client; - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_GRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } - - return(client->noClientException); -} - -static void -#if NeedFunctionPrototypes -UngrabServer(ClientPtr client) -#else -UngrabServer(client) - ClientPtr client; -#endif -{ - int i; - - grabState = GrabNone; - ListenToAllClients(); - for (i = mskcnt; --i >= 0 && !grabWaiters[i]; ) - ; - if (i >= 0) - { - i <<= 5; - while (!GETBIT(grabWaiters, i)) - i++; - BITCLEAR(grabWaiters, i); - AttendClient(clients[i]); - } - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_UNGRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } -} - -int -ProcUngrabServer(client) - register ClientPtr client; -{ - REQUEST_SIZE_MATCH(xReq); - UngrabServer(client); - return(client->noClientException); -} - -int -ProcTranslateCoords(client) - register ClientPtr client; -{ - REQUEST(xTranslateCoordsReq); - - register WindowPtr pWin, pDst; - xTranslateCoordsReply rep; - - REQUEST_SIZE_MATCH(xTranslateCoordsReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client, - SecurityReadAccess); - if (!pDst) - return(BadWindow); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) - { - rep.sameScreen = xFalse; - rep.child = None; - rep.dstX = rep.dstY = 0; - } - else - { - INT16 x, y; - rep.sameScreen = xTrue; - rep.child = None; - /* computing absolute coordinates -- adjust to destination later */ - x = pWin->drawable.x + stuff->srcX; - y = pWin->drawable.y + stuff->srcY; - pWin = pDst->firstChild; - while (pWin) - { -#ifdef SHAPE - BoxRec box; -#endif - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth (pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - &pWin->borderSize, x, y, &box)) -#endif - ) - { - rep.child = pWin->drawable.id; - pWin = (WindowPtr) NULL; - } - else - pWin = pWin->nextSib; - } - /* adjust to destination coordinates */ - rep.dstX = x - pDst->drawable.x; - rep.dstY = y - pDst->drawable.y; - } - WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep); - return(client->noClientException); -} - -int -ProcOpenFont(client) - register ClientPtr client; -{ - int err; - REQUEST(xOpenFontReq); - - REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes); - client->errorValue = stuff->fid; - LEGAL_NEW_RESOURCE(stuff->fid, client); - err = OpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcCloseFont(client) - register ClientPtr client; -{ - FontPtr pFont; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityDestroyAccess); - if ( pFont != (FontPtr)NULL) /* id was valid */ - { - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadFont); - } -} - -int -ProcQueryFont(client) - register ClientPtr client; -{ - xQueryFontReply *reply; - FontPtr pFont; - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - client->errorValue = stuff->id; /* EITHER font or gc */ - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - /* can't use VERIFY_GC because it might return BadGC */ - pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->id; - return(BadFont); /* procotol spec says only error is BadFont */ - } - pFont = pGC->font; - } - - { - xCharInfo *pmax = FONTINKMAX(pFont); - xCharInfo *pmin = FONTINKMIN(pFont); - int nprotoxcistructs; - int rlength; - - nprotoxcistructs = ( - pmax->rightSideBearing == pmin->rightSideBearing && - pmax->leftSideBearing == pmin->leftSideBearing && - pmax->descent == pmin->descent && - pmax->ascent == pmin->ascent && - pmax->characterWidth == pmin->characterWidth) ? - 0 : N2dChars(pFont); - - rlength = sizeof(xQueryFontReply) + - FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) + - nprotoxcistructs * sizeof(xCharInfo); - reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength); - if(!reply) - { - return(BadAlloc); - } - - reply->type = X_Reply; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->sequenceNumber = client->sequence; - QueryFont( pFont, reply, nprotoxcistructs); - - WriteReplyToClient(client, rlength, reply); - DEALLOCATE_LOCAL(reply); - return(client->noClientException); - } -} - -int -ProcQueryTextExtents(client) - register ClientPtr client; -{ - REQUEST(xQueryTextExtentsReq); - xQueryTextExtentsReply reply; - FontPtr pFont; - GC *pGC; - ExtentInfoRec info; - unsigned long length; - - REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); - - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->fid; - return(BadFont); - } - pFont = pGC->font; - } - length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2); - length = length << 1; - if (stuff->oddLength) - { - if (length == 0) - return(BadLength); - length--; - } - if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info)) - return(BadAlloc); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.drawDirection = info.drawDirection; - reply.fontAscent = info.fontAscent; - reply.fontDescent = info.fontDescent; - reply.overallAscent = info.overallAscent; - reply.overallDescent = info.overallDescent; - reply.overallWidth = info.overallWidth; - reply.overallLeft = info.overallLeft; - reply.overallRight = info.overallRight; - WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply); - return(client->noClientException); -} - -int -ProcListFonts(client) - register ClientPtr client; -{ - REQUEST(xListFontsReq); - - REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes); - - return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, - stuff->maxNames); -} - -int -ProcListFontsWithInfo(client) - register ClientPtr client; -{ - REQUEST(xListFontsWithInfoReq); - - REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes); - - return StartListFontsWithInfo(client, stuff->nbytes, - (unsigned char *) &stuff[1], stuff->maxNames); -} - -/*ARGSUSED*/ -int -dixDestroyPixmap(value, pid) - pointer value; /* must conform to DeleteType */ - XID pid; -{ - PixmapPtr pPixmap = (PixmapPtr)value; - return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); -} - -int -ProcCreatePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - REQUEST(xCreatePixmapReq); - DepthPtr pDepth; - register int i; - - REQUEST_SIZE_MATCH(xCreatePixmapReq); - client->errorValue = stuff->pid; - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap) - (pDraw->pScreen, stuff->width, - stuff->height, stuff->depth); - if (pMap) - { - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - return(client->noClientException); - } - return (BadAlloc); -} - -int -ProcFreePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP, - SecurityDestroyAccess); - if (pMap) - { - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadPixmap); - } -} - -int -ProcCreateGC(client) - register ClientPtr client; -{ - int error; - GC *pGC; - register DrawablePtr pDraw; - unsigned len; - REQUEST(xCreateGCReq); - - REQUEST_AT_LEAST_SIZE(xCreateGCReq); - client->errorValue = stuff->gc; - LEGAL_NEW_RESOURCE(stuff->gc, client); - SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - len = client->req_len - (sizeof(xCreateGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - pGC = (GC *)CreateGC(pDraw, stuff->mask, - (XID *) &stuff[1], &error); - if (error != Success) - return error; - if (!AddResource(stuff->gc, RT_GC, (pointer)pGC)) - return (BadAlloc); - return(client->noClientException); -} - -int -ProcChangeGC(client) - register ClientPtr client; -{ - GC *pGC; - REQUEST(xChangeGCReq); - int result; - unsigned len; - - REQUEST_AT_LEAST_SIZE(xChangeGCReq); - SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess); - len = client->req_len - (sizeof(xChangeGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - - result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcCopyGC(client) - register ClientPtr client; -{ - register GC *dstGC; - register GC *pGC; - int result; - REQUEST(xCopyGCReq); - - REQUEST_SIZE_MATCH(xCopyGCReq); - SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess); - SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess); - if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth)) - return (BadMatch); - result = CopyGC(pGC, dstGC, stuff->mask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetDashes(client) - register ClientPtr client; -{ - register GC *pGC; - int result; - REQUEST(xSetDashesReq); - - REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes); - if (stuff->nDashes == 0) - { - client->errorValue = 0; - return BadValue; - } - - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes, - (unsigned char *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetClipRectangles(client) - register ClientPtr client; -{ - int nr; - int result; - register GC *pGC; - REQUEST(xSetClipRectanglesReq); - - REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq); - if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && - (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) - { - client->errorValue = stuff->ordering; - return BadValue; - } - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq); - if (nr & 4) - return(BadLength); - nr >>= 3; - result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *)&stuff[1], (int)stuff->ordering); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcFreeGC(client) - register ClientPtr client; -{ - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess); - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcClearToBackground(client) - register ClientPtr client; -{ - REQUEST(xClearAreaReq); - register WindowPtr pWin; - - REQUEST_SIZE_MATCH(xClearAreaReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (pWin->drawable.class == InputOnly) - { - client->errorValue = stuff->window; - return (BadMatch); - } - if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) - { - client->errorValue = stuff->exposures; - return(BadValue); - } - (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y, - stuff->width, stuff->height, - (Bool)stuff->exposures); - return(client->noClientException); -} - -int -ProcCopyArea(client) - register ClientPtr client; -{ - register DrawablePtr pDst; - register DrawablePtr pSrc; - register GC *pGC; - REQUEST(xCopyAreaReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyAreaReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client, - SecurityReadAccess); - if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - pSrc = pDst; - - SET_DBE_SRCBUF(pSrc, stuff->srcDrawable); - - pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY); - if (pGC->graphicsExposures) - { - (*pDst->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); - if (pRgn) - REGION_DESTROY(pDst->pScreen, pRgn); - } - - return(client->noClientException); -} - -int -ProcCopyPlane(client) - register ClientPtr client; -{ - register DrawablePtr psrcDraw, pdstDraw; - register GC *pGC; - REQUEST(xCopyPlaneReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyPlaneReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client, - SecurityReadAccess); - if (pdstDraw->pScreen != psrcDraw->pScreen) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - psrcDraw = pdstDraw; - - SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable); - - /* Check to see if stuff->bitPlane has exactly ONE good bit set */ - if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || - (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) - { - client->errorValue = stuff->bitPlane; - return(BadValue); - } - - pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY, stuff->bitPlane); - if (pGC->graphicsExposures) - { - (*pdstDraw->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); - if (pRgn) - REGION_DESTROY(pdstDraw->pScreen, pRgn); - } - return(client->noClientException); -} - -int -ProcPolyPoint(client) - register ClientPtr client; -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyPointReq); - - REQUEST_AT_LEAST_SIZE(xPolyPointReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2; - if (npoint) - (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, - (xPoint *) &stuff[1]); - return (client->noClientException); -} - -int -ProcPolyLine(client) - register ClientPtr client; -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyLineReq); - - REQUEST_AT_LEAST_SIZE(xPolyLineReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2; - if (npoint > 1) - (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, - (DDXPointPtr) &stuff[1]); - return(client->noClientException); -} - -int -ProcPolySegment(client) - register ClientPtr client; -{ - int nsegs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolySegmentReq); - - REQUEST_AT_LEAST_SIZE(xPolySegmentReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); - if (nsegs & 4) - return(BadLength); - nsegs >>= 3; - if (nsegs) - (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]); - return (client->noClientException); -} - -int -ProcPolyRectangle (client) - register ClientPtr client; -{ - int nrects; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); - if (nrects & 4) - return(BadLength); - nrects >>= 3; - if (nrects) - (*pGC->ops->PolyRectangle)(pDraw, pGC, - nrects, (xRectangle *) &stuff[1]); - return(client->noClientException); -} - -int -ProcPolyArc(client) - register ClientPtr client; -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]); - return (client->noClientException); -} - -int -ProcFillPoly(client) - register ClientPtr client; -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xFillPolyReq); - - REQUEST_AT_LEAST_SIZE(xFillPolyReq); - if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) && - (stuff->shape != Convex)) - { - client->errorValue = stuff->shape; - return BadValue; - } - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2; - if (things) - (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, - stuff->coordMode, things, - (DDXPointPtr) &stuff[1]); - return(client->noClientException); -} - -int -ProcPolyFillRectangle(client) - register ClientPtr client; -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); - if (things & 4) - return(BadLength); - things >>= 3; - - if (things) - (*pGC->ops->PolyFillRect) (pDraw, pGC, things, - (xRectangle *) &stuff[1]); - return (client->noClientException); -} - -int -ProcPolyFillArc(client) - register ClientPtr client; -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); - return (client->noClientException); -} - -#ifdef MATCH_CLIENT_ENDIAN - -int -ServerOrder (void) -{ - int whichbyte = 1; - - if (*((char *) &whichbyte)) - return LSBFirst; - return MSBFirst; -} - -#define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder()) - -void -ReformatImage (char *base, int nbytes, int bpp, int order) -{ - switch (bpp) { - case 1: /* yuck */ - if (BITMAP_BIT_ORDER != order) - BitOrderInvert ((unsigned char *) base, nbytes); -#if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8 - ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order); -#endif - break; - case 4: - break; /* yuck */ - case 8: - break; - case 16: - if (IMAGE_BYTE_ORDER != order) - TwoByteSwap ((unsigned char *) base, nbytes); - break; - case 32: - if (IMAGE_BYTE_ORDER != order) - FourByteSwap ((unsigned char *) base, nbytes); - break; - } -} -#else -#define ReformatImage(b,n,bpp,o) -#endif - -/* 64-bit server notes: the protocol restricts padding of images to - * 8-, 16-, or 32-bits. We would like to have 64-bits for the server - * to use internally. Removes need for internal alignment checking. - * All of the PutImage functions could be changed individually, but - * as currently written, they call other routines which require things - * to be 64-bit padded on scanlines, so we changed things here. - * If an image would be padded differently for 64- versus 32-, then - * copy each scanline to a 64-bit padded scanline. - * Also, we need to make sure that the image is aligned on a 64-bit - * boundary, even if the scanlines are padded to our satisfaction. - */ -int -ProcPutImage(client) - register ClientPtr client; -{ - register GC *pGC; - register DrawablePtr pDraw; - long length; /* length of scanline server padded */ - long lengthProto; /* length of scanline protocol padded */ - char *tmpImage; - REQUEST(xPutImageReq); - - REQUEST_AT_LEAST_SIZE(xPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - if (stuff->format == XYBitmap) - { - if ((stuff->depth != 1) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - } - else if (stuff->format == XYPixmap) - { - if ((pDraw->depth != stuff->depth) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0)) - return BadMatch; - length = PixmapBytePad(stuff->width, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - tmpImage = (char *)&stuff[1]; - lengthProto = length; - - if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) + - (sizeof(xPutImageReq) >> 2)) != client->req_len) - return BadLength; - - ReformatImage (tmpImage, lengthProto * stuff->height, - stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1, - ClientOrder(client)); - - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY, - stuff->width, stuff->height, - stuff->leftPad, stuff->format, tmpImage); - - return (client->noClientException); -} - - -int -DoGetImage(client, format, drawable, x, y, width, height, planemask, im_return) - register ClientPtr client; - Drawable drawable; - int format; - int x, y, width, height; - Mask planemask; - xGetImageReply **im_return; -{ - register DrawablePtr pDraw; - int nlines, linesPerBuf; - register int linesDone; - long widthBytesLine, length; - Mask plane = 0; - char *pBuf; - xGetImageReply xgi; - RegionPtr pVisibleRegion = NULL; - - if ((format != XYPixmap) && (format != ZPixmap)) - { - client->errorValue = format; - return(BadValue); - } - SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess); - if(pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + x < 0 || - pDraw->x + x + width > pDraw->pScreen->width || - pDraw->y + y < 0 || - pDraw->y + y + height > pDraw->pScreen->height || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual (((WindowPtr) pDraw)); - } - else - { - if(x < 0 || - x+width > (int)pDraw->width || - y < 0 || - y+height > (int)pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - - SET_DBE_SRCBUF(pDraw, drawable); - - xgi.type = X_Reply; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(format == ZPixmap) - { - widthBytesLine = PixmapBytePad(width, pDraw->depth); - length = widthBytesLine * height; - - } - else - { - widthBytesLine = BitmapBytePad(width); - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = widthBytesLine * height * - Ones(planemask & (plane | (plane - 1))); - - } - - xgi.length = length; - - if (im_return) { - pBuf = (char *)xalloc(sz_xGetImageReply + length); - if (!pBuf) - return (BadAlloc); - if (widthBytesLine == 0) - linesPerBuf = 0; - else - linesPerBuf = height; - *im_return = (xGetImageReply *)pBuf; - *(xGetImageReply *)pBuf = xgi; - pBuf += sz_xGetImageReply; - } else { - xgi.length = (xgi.length + 3) >> 2; - if (widthBytesLine == 0 || height == 0) - linesPerBuf = 0; - else if (widthBytesLine >= IMAGE_BUFSIZE) - linesPerBuf = 1; - else - { - linesPerBuf = IMAGE_BUFSIZE / widthBytesLine; - if (linesPerBuf > height) - linesPerBuf = height; - } - length = linesPerBuf * widthBytesLine; - if (linesPerBuf < height) - { - /* we have to make sure intermediate buffers don't need padding */ - while ((linesPerBuf > 1) && - (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))) - { - linesPerBuf--; - length -= widthBytesLine; - } - while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)) - { - linesPerBuf++; - length += widthBytesLine; - } - } - if(!(pBuf = (char *) ALLOCATE_LOCAL(length))) - return (BadAlloc); - WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); - } - -#ifdef XCSECURITY - if (client->trustLevel != XSecurityClientTrusted && - pDraw->type == DRAWABLE_WINDOW) - { - pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw); - if (pVisibleRegion) - { - REGION_TRANSLATE(pScreen, pVisibleRegion, -pDraw->x, -pDraw->y); - } - } -#endif - - if (linesPerBuf == 0) - { - /* nothing to do */ - } - else if (format == ZPixmap) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - planemask, - (pointer) pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note that this is NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (!im_return) - { - ReformatImage (pBuf, (int)(nlines * widthBytesLine), - BitsPerPixel (pDraw->depth), - ClientOrder(client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - else /* XYPixmap */ - { - for (; plane; plane >>= 1) - { - if (planemask & plane) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - plane, - (pointer)pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, - widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note: NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (im_return) { - pBuf += nlines * widthBytesLine; - } else { - ReformatImage (pBuf, - (int)(nlines * widthBytesLine), - 1, - ClientOrder (client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - } - } -#ifdef XCSECURITY - if (pVisibleRegion) - REGION_DESTROY(pScreen, pVisibleRegion); -#endif - if (!im_return) - DEALLOCATE_LOCAL(pBuf); - return (client->noClientException); -} - -int -ProcGetImage(client) - register ClientPtr client; -{ - REQUEST(xGetImageReq); - - REQUEST_SIZE_MATCH(xGetImageReq); - - return DoGetImage(client, stuff->format, stuff->drawable, - stuff->x, stuff->y, - (int)stuff->width, (int)stuff->height, - stuff->planeMask, (xGetImageReply **)NULL); -} - -int -ProcPolyText(client) - register ClientPtr client; -{ - int err; - REQUEST(xPolyTextReq); - DrawablePtr pDraw; - GC *pGC; - - REQUEST_AT_LEAST_SIZE(xPolyTextReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = PolyText(client, - pDraw, - pGC, - (unsigned char *)&stuff[1], - ((unsigned char *) stuff) + (client->req_len << 2), - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText8(client) - register ClientPtr client; -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText16(client) - register ClientPtr client; -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - - -int -ProcCreateColormap(client) - register ClientPtr client; -{ - VisualPtr pVisual; - ColormapPtr pmap; - Colormap mid; - register WindowPtr pWin; - ScreenPtr pScreen; - REQUEST(xCreateColormapReq); - int i, result; - - REQUEST_SIZE_MATCH(xCreateColormapReq); - - if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) - { - client->errorValue = stuff->alloc; - return(BadValue); - } - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pScreen = pWin->drawable.pScreen; - for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid != stuff->visual) - continue; - result = CreateColormap(mid, pScreen, pVisual, &pmap, - (int)stuff->alloc, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - client->errorValue = stuff->visual; - return(BadValue); -} - -int -ProcFreeColormap(client) - register ClientPtr client; -{ - ColormapPtr pmap; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP, - SecurityDestroyAccess); - if (pmap) - { - /* Freeing a default colormap is a no-op */ - if (!(pmap->flags & IsDefault)) - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - - -int -ProcCopyColormapAndFree(client) - register ClientPtr client; -{ - Colormap mid; - ColormapPtr pSrcMap; - REQUEST(xCopyColormapAndFreeReq); - int result; - - REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client, stuff->srcCmap, - RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) ) - { - result = CopyColormapAndFree(mid, pSrcMap, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->srcCmap; - return(BadColor); - } -} - -int -ProcInstallColormap(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - (*(pcmp->pScreen->InstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcUninstallColormap(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - if(pcmp->mid != pcmp->pScreen->defColormap) - (*(pcmp->pScreen->UninstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcListInstalledColormaps(client) - register ClientPtr client; -{ - xListInstalledColormapsReply *preply; - int nummaps; - WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - - if (!pWin) - return(BadWindow); - - preply = (xListInstalledColormapsReply *) - ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) + - pWin->drawable.pScreen->maxInstalledCmaps * - sizeof(Colormap)); - if(!preply) - return(BadAlloc); - - preply->type = X_Reply; - preply->sequenceNumber = client->sequence; - nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pWin->drawable.pScreen, (Colormap *)&preply[1]); - preply->nColormaps = nummaps; - preply->length = nummaps; - WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); - DEALLOCATE_LOCAL(preply); - return(client->noClientException); -} - -int -ProcAllocColor(client) - register ClientPtr client; -{ - ColormapPtr pmap; - int retval; - xAllocColorReply acr; - REQUEST(xAllocColorReq); - - REQUEST_SIZE_MATCH(xAllocColorReq); - pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pmap) - { -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pmap, (xReq *) stuff)) - return Success; -#endif - acr.type = X_Reply; - acr.length = 0; - acr.sequenceNumber = client->sequence; - acr.red = stuff->red; - acr.green = stuff->green; - acr.blue = stuff->blue; - acr.pixel = 0; - if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, - &acr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return (retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pmap->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); - return (client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocNamedColor (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xAllocNamedColorReq); - - REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int retval; - - xAllocNamedColorReply ancr; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocNamedColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - ancr.type = X_Reply; - ancr.length = 0; - ancr.sequenceNumber = client->sequence; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) - { - ancr.screenRed = ancr.exactRed; - ancr.screenGreen = ancr.exactGreen; - ancr.screenBlue = ancr.exactBlue; - ancr.pixel = 0; - if( (retval = AllocColor(pcmp, - &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue, - &ancr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr); - return (client->noClientException); - } - else - return(BadName); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorCells (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xAllocColorCellsReq); - - REQUEST_SIZE_MATCH(xAllocColorCellsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorCellsReply accr; - int npixels, nmasks, retval; - long length; - Pixel *ppixels, *pmasks; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorCells request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - nmasks = stuff->planes; - length = ((long)npixels + (long)nmasks) * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - pmasks = ppixels + npixels; - - if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, - (Bool)stuff->contiguous, ppixels, pmasks)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - accr.type = X_Reply; - accr.length = length >> 2; - accr.sequenceNumber = client->sequence; - accr.nPixels = npixels; - accr.nMasks = nmasks; - WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorPlanes(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xAllocColorPlanesReq); - - REQUEST_SIZE_MATCH(xAllocColorPlanesReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorPlanesReply acpr; - int npixels, retval; - long length; - Pixel *ppixels; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorPlanes request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - acpr.type = X_Reply; - acpr.sequenceNumber = client->sequence; - acpr.nPixels = npixels; - length = (long)npixels * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - if( (retval = AllocColorPlanes(client->index, pcmp, npixels, - (int)stuff->red, (int)stuff->green, (int)stuff->blue, - (Bool)stuff->contiguous, ppixels, - &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - acpr.length = length >> 2; -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcFreeColors (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xFreeColorsReq); - - REQUEST_AT_LEAST_SIZE(xFreeColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - if(pcmp->flags & AllAllocated) - return(BadAccess); - count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2; - retval = FreeColors(pcmp, client->index, count, - (Pixel *)&stuff[1], (Pixel)stuff->planeMask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreColors (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xStoreColorsReq); - - REQUEST_AT_LEAST_SIZE(xStoreColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - count = (client->req_len << 2) - sizeof(xStoreColorsReq); - if (count % sizeof(xColorItem)) - return(BadLength); - count /= sizeof(xColorItem); - retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreNamedColor (client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xStoreNamedColorReq); - - REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xColorItem def; - int retval; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], - stuff->nbytes, &def.red, &def.green, &def.blue)) - { - def.flags = stuff->flags; - def.pixel = stuff->pixel; - retval = StoreColors(pcmp, 1, &def); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcQueryColors(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xQueryColorsReq); - - REQUEST_AT_LEAST_SIZE(xQueryColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - int count, retval; - xrgb *prgbs; - xQueryColorsReply qcr; - - count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2; - prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb)); - if(!prgbs && count) - return(BadAlloc); - if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) ) - { - if (prgbs) DEALLOCATE_LOCAL(prgbs); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return (retval); - } - } - qcr.type = X_Reply; - qcr.length = (count * sizeof(xrgb)) >> 2; - qcr.sequenceNumber = client->sequence; - qcr.nColors = count; - WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); - if (count) - { - client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; - WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); - } - if (prgbs) DEALLOCATE_LOCAL(prgbs); - return(client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcLookupColor(client) - register ClientPtr client; -{ - ColormapPtr pcmp; - REQUEST(xLookupColorReq); - - REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - xLookupColorReply lcr; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) - { - lcr.type = X_Reply; - lcr.length = 0; - lcr.sequenceNumber = client->sequence; - lcr.screenRed = lcr.exactRed; - lcr.screenGreen = lcr.exactGreen; - lcr.screenBlue = lcr.exactBlue; - (*pcmp->pScreen->ResolveColor)(&lcr.screenRed, - &lcr.screenGreen, - &lcr.screenBlue, - pcmp->pVisual); - WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); - return(client->noClientException); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcCreateCursor( client) - register ClientPtr client; -{ - CursorPtr pCursor; - - register PixmapPtr src; - register PixmapPtr msk; - unsigned char * srcbits; - unsigned char * mskbits; - unsigned short width, height; - long n; - CursorMetricRec cm; - - - REQUEST(xCreateCursorReq); - - REQUEST_SIZE_MATCH(xCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source, - RT_PIXMAP, SecurityReadAccess); - msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask, - RT_PIXMAP, SecurityReadAccess); - if ( src == (PixmapPtr)NULL) - { - client->errorValue = stuff->source; - return (BadPixmap); - } - if ( msk == (PixmapPtr)NULL) - { - if (stuff->mask != None) - { - client->errorValue = stuff->mask; - return (BadPixmap); - } - } - else if ( src->drawable.width != msk->drawable.width - || src->drawable.height != msk->drawable.height - || src->drawable.depth != 1 - || msk->drawable.depth != 1) - return (BadMatch); - - width = src->drawable.width; - height = src->drawable.height; - - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - - n = BitmapBytePad(width)*height; - srcbits = (unsigned char *)xalloc(n); - if (!srcbits) - return (BadAlloc); - mskbits = (unsigned char *)xalloc(n); - if (!mskbits) - { - xfree(srcbits); - return (BadAlloc); - } - - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)srcbits, n); - (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height, - XYPixmap, 1, (pointer)srcbits); - if ( msk == (PixmapPtr)NULL) - { - register unsigned char *bits = mskbits; - while (--n >= 0) - *bits++ = ~0; - } - else - { - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)mskbits, n); - (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width, - height, XYPixmap, 1, (pointer)mskbits); - } - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - pCursor = AllocCursor( srcbits, mskbits, &cm, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue); - - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; -} - -int -ProcCreateGlyphCursor( client) - register ClientPtr client; -{ - CursorPtr pCursor; - int res; - - REQUEST(xCreateGlyphCursorReq); - - REQUEST_SIZE_MATCH(xCreateGlyphCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - res = AllocGlyphCursor(stuff->source, stuff->sourceChar, - stuff->mask, stuff->maskChar, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client); - if (res != Success) - return res; - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - - -int -ProcFreeCursor(client) - register ClientPtr client; -{ - CursorPtr pCursor; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id, - RT_CURSOR, SecurityDestroyAccess); - if (pCursor) - { - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadCursor); - } -} - -int -ProcQueryBestSize (client) - register ClientPtr client; -{ - xQueryBestSizeReply reply; - register DrawablePtr pDraw; - ScreenPtr pScreen; - REQUEST(xQueryBestSizeReq); - - REQUEST_SIZE_MATCH(xQueryBestSizeReq); - if ((stuff->class != CursorShape) && - (stuff->class != TileShape) && - (stuff->class != StippleShape)) - { - client->errorValue = stuff->class; - return(BadValue); - } - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW) - return (BadMatch); - pScreen = pDraw->pScreen; - (* pScreen->QueryBestSize)(stuff->class, &stuff->width, - &stuff->height, pScreen); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.width = stuff->width; - reply.height = stuff->height; - WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply); - return (client->noClientException); -} - - -int -ProcSetScreenSaver (client) - register ClientPtr client; -{ - int blankingOption, exposureOption; - REQUEST(xSetScreenSaverReq); - - REQUEST_SIZE_MATCH(xSetScreenSaverReq); - blankingOption = stuff->preferBlank; - if ((blankingOption != DontPreferBlanking) && - (blankingOption != PreferBlanking) && - (blankingOption != DefaultBlanking)) - { - client->errorValue = blankingOption; - return BadValue; - } - exposureOption = stuff->allowExpose; - if ((exposureOption != DontAllowExposures) && - (exposureOption != AllowExposures) && - (exposureOption != DefaultExposures)) - { - client->errorValue = exposureOption; - return BadValue; - } - if (stuff->timeout < -1) - { - client->errorValue = stuff->timeout; - return BadValue; - } - if (stuff->interval < -1) - { - client->errorValue = stuff->interval; - return BadValue; - } - - if (blankingOption == DefaultBlanking) - ScreenSaverBlanking = defaultScreenSaverBlanking; - else - ScreenSaverBlanking = blankingOption; - if (exposureOption == DefaultExposures) - ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; - else - ScreenSaverAllowExposures = exposureOption; - - if (stuff->timeout >= 0) - ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND; - else - ScreenSaverTime = defaultScreenSaverTime; - if (stuff->interval >= 0) - ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND; - else - ScreenSaverInterval = defaultScreenSaverInterval; - return (client->noClientException); -} - -int -ProcGetScreenSaver(client) - register ClientPtr client; -{ - xGetScreenSaverReply rep; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.timeout = ScreenSaverTime / MILLI_PER_SECOND; - rep.interval = ScreenSaverInterval / MILLI_PER_SECOND; - rep.preferBlanking = ScreenSaverBlanking; - rep.allowExposures = ScreenSaverAllowExposures; - WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep); - return (client->noClientException); -} - -int -ProcChangeHosts(client) - register ClientPtr client; -{ - REQUEST(xChangeHostsReq); - int result; - - REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength); - - if(stuff->mode == HostInsert) - result = AddHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else if (stuff->mode == HostDelete) - result = RemoveHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else - { - client->errorValue = stuff->mode; - return BadValue; - } - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcListHosts(client) - register ClientPtr client; -{ - xListHostsReply reply; - int len, nHosts, result; - pointer pdata; - /* REQUEST(xListHostsReq); */ - - REQUEST_SIZE_MATCH(xListHostsReq); -#ifdef XCSECURITY - /* untrusted clients can't list hosts */ - if (client->trustLevel != XSecurityClientTrusted) - { - SecurityAudit("client %d attempted to list hosts\n", client->index); - return BadAccess; - } -#endif - result = GetHosts(&pdata, &nHosts, &len, &reply.enabled); - if (result != Success) - return(result); - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.nHosts = nHosts; - reply.length = len >> 2; - WriteReplyToClient(client, sizeof(xListHostsReply), &reply); - if (nHosts) - { - client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; - WriteSwappedDataToClient(client, len, pdata); - } - xfree(pdata); - return (client->noClientException); -} - -int -ProcChangeAccessControl(client) - register ClientPtr client; -{ - int result; - REQUEST(xSetAccessControlReq); - - REQUEST_SIZE_MATCH(xSetAccessControlReq); - if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) - { - client->errorValue = stuff->mode; - return BadValue; - } - result = ChangeAccessControl(client, stuff->mode == EnableAccess); - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcKillClient(client) - register ClientPtr client; -{ - REQUEST(xResourceReq); - ClientPtr killclient; - - REQUEST_SIZE_MATCH(xResourceReq); - if (stuff->id == AllTemporary) - { - CloseDownRetainedResources(); - return (client->noClientException); - } - - if ((killclient = LookupClient(stuff->id, client))) - { - CloseDownClient(killclient); - /* if an LBX proxy gets killed, isItTimeToYield will be set */ - if (isItTimeToYield || (client == killclient)) - { - /* force yield and return Success, so that Dispatch() - * doesn't try to touch client - */ - isItTimeToYield = TRUE; - return (Success); - } - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadValue); - } -} - -int -ProcSetFontPath(client) - register ClientPtr client; -{ - unsigned char *ptr; - unsigned long nbytes, total; - long nfonts; - int n, result; - int error; - REQUEST(xSetFontPathReq); - - REQUEST_AT_LEAST_SIZE(xSetFontPathReq); - - nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq); - total = nbytes; - ptr = (unsigned char *)&stuff[1]; - nfonts = stuff->nFonts; - while (--nfonts >= 0) - { - if ((total == 0) || (total < (n = (*ptr + 1)))) - return(BadLength); - total -= n; - ptr += n; - } - if (total >= 4) - return(BadLength); - result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1], - &error); - if (!result) - { - result = client->noClientException; - client->errorValue = error; - } - return (result); -} - -int -ProcGetFontPath(client) - register ClientPtr client; -{ - xGetFontPathReply reply; - int stringLens, numpaths; - unsigned char *bufferStart; - /* REQUEST (xReq); */ - - REQUEST_SIZE_MATCH(xReq); - bufferStart = GetFontPath(&numpaths, &stringLens); - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = (stringLens + numpaths + 3) >> 2; - reply.nPaths = numpaths; - - WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); - if (stringLens || numpaths) - (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart); - return(client->noClientException); -} - -int -ProcChangeCloseDownMode(client) - register ClientPtr client; -{ - REQUEST(xSetCloseDownModeReq); - - REQUEST_SIZE_MATCH(xSetCloseDownModeReq); - if ((stuff->mode == AllTemporary) || - (stuff->mode == RetainPermanent) || - (stuff->mode == RetainTemporary)) - { - client->closeDownMode = stuff->mode; - return (client->noClientException); - } - else - { - client->errorValue = stuff->mode; - return (BadValue); - } -} - -int ProcForceScreenSaver(client) - register ClientPtr client; -{ - REQUEST(xForceScreenSaverReq); - - REQUEST_SIZE_MATCH(xForceScreenSaverReq); - - if ((stuff->mode != ScreenSaverReset) && - (stuff->mode != ScreenSaverActive)) - { - client->errorValue = stuff->mode; - return BadValue; - } - SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode); - return client->noClientException; -} - -int ProcNoOperation(client) - register ClientPtr client; -{ - REQUEST_AT_LEAST_SIZE(xReq); - - /* noop -- don't do anything */ - return(client->noClientException); -} - -void -InitProcVectors(void) -{ - int i; - for (i = 0; i<256; i++) - { - if(!ProcVector[i]) - { - ProcVector[i] = SwappedProcVector[i] = ProcBadRequest; - ReplySwapVector[i] = ReplyNotSwappd; - } -#ifdef K5AUTH - if (!k5_Vector[i]) - { - k5_Vector[i] = k5_bad; - } -#endif - } - for(i = LASTEvent; i < 128; i++) - { - EventSwapVector[i] = NotImplemented; - } - -} - -/********************** - * CloseDownClient - * - * Client can either mark his resources destroy or retain. If retained and - * then killed again, the client is really destroyed. - *********************/ - -char dispatchExceptionAtReset = DE_RESET; - -void -CloseDownClient(client) - register ClientPtr client; -{ - Bool really_close_down = client->clientGone || - client->closeDownMode == DestroyAll; - - if (!client->clientGone) - { - /* ungrab server if grabbing client dies */ - if (grabState != GrabNone && grabClient == client) - { - UngrabServer(client); - } - BITCLEAR(grabWaiters, client->index); - DeleteClientFromAnySelections(client); - ReleaseActiveGrabs(client); - DeleteClientFontStuff(client); - if (!really_close_down) - { - /* This frees resources that should never be retained - * no matter what the close down mode is. Actually we - * could do this unconditionally, but it's probably - * better not to traverse all the client's resources - * twice (once here, once a few lines down in - * FreeClientResources) in the common case of - * really_close_down == TRUE. - */ - FreeClientNeverRetainResources(client); - client->clientState = ClientStateRetained; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - } - client->clientGone = TRUE; /* so events aren't sent to client */ - if (ClientIsAsleep(client)) - ClientSignal (client); - ProcessWorkQueueZombies(); -#ifdef LBX - ProcessQTagZombies(); -#endif - CloseDownConnection(client); - - /* If the client made it to the Running stage, nClients has - * been incremented on its behalf, so we need to decrement it - * now. If it hasn't gotten to Running, nClients has *not* - * been incremented, so *don't* decrement it. - */ - if (client->clientState != ClientStateInitial && - client->clientState != ClientStateAuthenticating ) - { - --nClients; - } - } - - if (really_close_down) - { - if (client->clientState == ClientStateRunning && nClients == 0) - dispatchException |= dispatchExceptionAtReset; - - client->clientState = ClientStateGone; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - FreeClientResources(client); - if (client->index < nextFreeClientID) - nextFreeClientID = client->index; - clients[client->index] = NullClient; -#ifdef SMART_SCHEDULE - SmartLastClient = NullClient; -#endif - xfree(client); - - while (!clients[currentMaxClients-1]) - currentMaxClients--; - } -} - -static void -KillAllClients() -{ - int i; - for (i=1; icloseDownMode = DestroyAll; - CloseDownClient(clients[i]); - } -} - -/********************* - * CloseDownRetainedResources - * - * Find all clients that are gone and have terminated in RetainTemporary - * and destroy their resources. - *********************/ - -void -CloseDownRetainedResources() -{ - register int i; - register ClientPtr client; - - for (i=1; icloseDownMode == RetainTemporary) - && (client->clientGone)) - CloseDownClient(client); - } -} - -void InitClient(client, i, ospriv) - ClientPtr client; - int i; - pointer ospriv; -{ - client->index = i; - client->sequence = 0; - client->clientAsMask = ((Mask)i) << CLIENTOFFSET; - client->clientGone = FALSE; - if (i) - { - client->closeDownMode = DestroyAll; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - client->lastDrawableID = WindowTable[0]->drawable.id; - } - else - { - client->closeDownMode = RetainPermanent; - client->lastDrawable = (DrawablePtr)NULL; - client->lastDrawableID = INVALID; - } - client->lastGC = (GCPtr) NULL; - client->lastGCID = INVALID; - client->numSaved = 0; - client->saveSet = (pointer *)NULL; - client->noClientException = Success; -#ifdef DEBUG - client->requestLogIndex = 0; -#endif - client->requestVector = InitialVector; - client->osPrivate = ospriv; - client->swapped = FALSE; - client->big_requests = FALSE; - client->priority = 0; - client->clientState = ClientStateInitial; -#ifdef XKB - if (!noXkbExtension) { - client->xkbClientFlags = 0; - client->mapNotifyMask = 0; - QueryMinMaxKeyCodes(&client->minKC,&client->maxKC); - } -#endif - client->replyBytesRemaining = 0; -#ifdef LBX - client->readRequest = StandardReadRequestFromClient; -#endif -#ifdef XCSECURITY - client->trustLevel = XSecurityClientTrusted; - client->CheckAccess = NULL; - client->authId = 0; -#endif -#ifdef XAPPGROUP - client->appgroup = NULL; -#endif - client->fontResFunc = NULL; -#ifdef SMART_SCHEDULE - client->smart_priority = 0; - client->smart_start_tick = SmartScheduleTime; - client->smart_stop_tick = SmartScheduleTime; - client->smart_check_tick = SmartScheduleTime; -#endif -} - -extern int clientPrivateLen; -extern unsigned *clientPrivateSizes; -extern unsigned totalClientSize; - -int -InitClientPrivates(client) - ClientPtr client; -{ - register char *ptr; - DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - if (totalClientSize == sizeof(ClientRec)) - ppriv = (DevUnion *)NULL; - else if (client->index) - ppriv = (DevUnion *)(client + 1); - else - { - ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec)); - if (!ppriv) - return 0; - } - client->devPrivates = ppriv; - sizes = clientPrivateSizes; - ptr = (char *)(ppriv + clientPrivateLen); - for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - return 1; -} - -/************************ - * int NextAvailableClient(ospriv) - * - * OS dependent portion can't assign client id's because of CloseDownModes. - * Returns NULL if there are no free clients. - *************************/ - -ClientPtr -NextAvailableClient(ospriv) - pointer ospriv; -{ - register int i; - register ClientPtr client; - xReq data; - - i = nextFreeClientID; - if (i == MAXCLIENTS) - return (ClientPtr)NULL; - clients[i] = client = (ClientPtr)xalloc(totalClientSize); - if (!client) - return (ClientPtr)NULL; - InitClient(client, i, ospriv); - InitClientPrivates(client); - if (!InitClientResources(client)) - { - xfree(client); - return (ClientPtr)NULL; - } - data.reqType = 1; - data.length = (sz_xReq + sz_xConnClientPrefix) >> 2; - if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) - { - FreeClientResources(client); - xfree(client); - return (ClientPtr)NULL; - } - if (i == currentMaxClients) - currentMaxClients++; - while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID]) - nextFreeClientID++; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return(client); -} - -int -ProcInitialConnection(client) - register ClientPtr client; -{ - REQUEST(xReq); - register xConnClientPrefix *prefix; - int whichbyte = 1; - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B')) - return (client->noClientException = -1); - if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) - { - client->swapped = TRUE; - SwapConnClientPrefix(prefix); - } - stuff->reqType = 2; - stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) + - ((prefix->nbytesAuthString + (unsigned)3) >> 2); - if (client->swapped) - { - swaps(&stuff->length, whichbyte); - } - ResetCurrentRequest(client); - return (client->noClientException); -} - -#ifdef LBX -void -IncrementClientCount() -{ - nClients++; -} -#endif - -int -SendConnSetup(client, reason) - register ClientPtr client; - char *reason; -{ - register xWindowRoot *root; - register int i; - int numScreens; - char* lConnectionInfo; - xConnSetupPrefix* lconnSetupPrefix; - - if (reason) - { - xConnSetupPrefix csp; - - csp.success = xFalse; - csp.lengthReason = strlen(reason); - csp.length = (csp.lengthReason + (unsigned)3) >> 2; - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (client->swapped) - WriteSConnSetupPrefix(client, &csp); - else - (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); - (void)WriteToClient(client, (int)csp.lengthReason, reason); - return (client->noClientException = -1); - } - - numScreens = screenInfo.numScreens; - lConnectionInfo = ConnectionInfo; - lconnSetupPrefix = &connSetupPrefix; - - /* We're about to start speaking X protocol back to the client by - * sending the connection setup info. This means the authorization - * step is complete, and we can count the client as an - * authorized one. - */ - nClients++; - - client->requestVector = client->swapped ? SwappedProcVector : ProcVector; - client->sequence = 0; -#ifdef XAPPGROUP - XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens); -#endif - ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask; - ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK; -#ifdef MATCH_CLIENT_ENDIAN - ((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client); - ((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client); -#endif - /* fill in the "currentInputMask" */ - root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart); -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#endif - - for (i=0; icurrentInputMask = WindowTable[i]->eventMask | - wOtherEventMasks (WindowTable[i]); - pDepth = (xDepth *)(root + 1); - for (j = 0; j < root->nDepths; j++) - { - pDepth = (xDepth *)(((char *)(pDepth + 1)) + - pDepth->nVisuals * sizeof(xVisualType)); - } - root = (xWindowRoot *)pDepth; - } - - if (client->swapped) - { - WriteSConnSetupPrefix(client, lconnSetupPrefix); - WriteSConnectionInfo(client, - (unsigned long)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - else - { - (void)WriteToClient(client, sizeof(xConnSetupPrefix), - (char *) lconnSetupPrefix); - (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - client->clientState = ClientStateRunning; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = lconnSetupPrefix; - clientinfo.setup = (xConnSetup *)lConnectionInfo; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return (client->noClientException); -} - -int -ProcEstablishConnection(client) - register ClientPtr client; -{ - char *reason, *auth_proto, *auth_string; - register xConnClientPrefix *prefix; - REQUEST(xReq); - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - auth_proto = (char *)prefix + sz_xConnClientPrefix; - auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3); - if ((prefix->majorVersion != X_PROTOCOL) || - (prefix->minorVersion != X_PROTOCOL_REVISION)) - reason = "Protocol version mismatch"; - else - reason = ClientAuthorized(client, - (unsigned short)prefix->nbytesAuthProto, - auth_proto, - (unsigned short)prefix->nbytesAuthString, - auth_string); - /* - * If Kerberos is being used for this client, the clientState - * will be set to ClientStateAuthenticating at this point. - * More messages need to be exchanged among the X server, Kerberos - * server, and client to figure out if everyone is authorized. - * So we don't want to send the connection setup info yet, since - * the auth step isn't really done. - */ - if (client->clientState == ClientStateCheckingSecurity) - client->clientState = ClientStateCheckedSecurity; - else if (client->clientState != ClientStateAuthenticating) - return(SendConnSetup(client, reason)); - return(client->noClientException); -} - -void -SendErrorToClient(client, majorCode, minorCode, resId, errorCode) - ClientPtr client; - unsigned int majorCode; - unsigned int minorCode; - XID resId; - int errorCode; -{ - xError rep; - - rep.type = X_Error; - rep.sequenceNumber = client->sequence; - rep.errorCode = errorCode; - rep.majorCode = majorCode; - rep.minorCode = minorCode; - rep.resourceID = resId; - - WriteEventsToClient (client, 1, (xEvent *)&rep); -} - -void -DeleteWindowFromAnySelections(pWin) - WindowPtr pWin; -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].pWin == pWin) - { - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -static void -DeleteClientFromAnySelections(client) - ClientPtr client; -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].client == client) - { - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -void -MarkClientException(client) - ClientPtr client; -{ - client->noClientException = -1; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.NX.original deleted file mode 100644 index 1cccfd972..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.NX.original +++ /dev/null @@ -1,2883 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXdixfonts.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.27 2003/02/15 03:47:05 dawes Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */ - -#define NEED_REPLIES -#include "X.h" -#include "Xmd.h" -#include "Xproto.h" -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "cursorstr.h" -#include "misc.h" -#include "opaque.h" -#include "dixfontstr.h" -#include "closestr.h" - -/* -#define NXAGENT_DEBUG -*/ - -#ifdef DEBUG -#include -#endif - -#include "Agent.h" -#include "Font.h" - -#ifndef NX_TRANS_SOCKET - -#define NX_TRANS_SOCKET - -#endif - -#ifdef NX_TRANS_SOCKET - -char _NXFontPath[1024]; - -/* - * Override the default font path and make - * it configurable at run time, based on - * the NX_FONT environment. - */ - -static const char *_NXGetFontPath(const char *path) -{ - const char *fontEnv; - - /* - * Check the environment only once. - */ - - if (*_NXFontPath != '\0') - { - return _NXFontPath; - } - - fontEnv = getenv("NX_FONT"); - - if (fontEnv != NULL && *fontEnv != '\0') - { - if (strlen(fontEnv) + 1 > 1024) - { -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: WARNING! Maximum length of font path exceeded.\n"); -#endif - goto _NXGetFontPathError; - } - - strcpy(_NXFontPath, fontEnv); - -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: Using NX font path [%s].\n", _NXFontPath); -#endif - - return _NXFontPath; - } - -_NXGetFontPathError: - - strcpy(_NXFontPath, path); - -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: Using default font path [%s].\n", _NXFontPath); -#endif - - return _NXFontPath; -} - -#endif - -#ifdef PANORAMIX -#include "../../Xext/panoramiX.h" -#include "../../Xext/panoramiXsrv.h" -#endif - -#ifdef LBX -#include "lbxserve.h" -#endif - -#ifdef XF86BIGFONT -#define _XF86BIGFONT_SERVER_ -#include "xf86bigfont.h" -#endif - -#define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics - -extern pointer fosNaturalParams; -extern FontPtr defaultFont; - -static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; -FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; - -static unsigned char *font_path_string; - -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; -static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; -static FontPatternCachePtr patternCache; - -int -FontToXError(err) - int err; -{ - switch (err) { - case Successful: - return Success; - case AllocError: - return BadAlloc; - case BadFontName: - return BadName; - case BadFontPath: - case BadFontFormat: /* is there something better? */ - case BadCharRange: - return BadValue; - default: - return err; - } -} - - -/* - * adding RT_FONT prevents conflict with default cursor font - */ -Bool -SetDefaultFont(defaultfontname) - char *defaultfontname; -{ - int err; - FontPtr pf; - XID fid; - - fid = FakeClientID(0); - err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); - if (err != Success) - return FALSE; - pf = (FontPtr) LookupIDByType(fid, RT_FONT); - if (pf == (FontPtr) NULL) - return FALSE; - defaultFont = pf; - return TRUE; -} - -/* - * note that the font wakeup queue is not refcounted. this is because - * an fpe needs to be added when it's inited, and removed when it's finally - * freed, in order to handle any data that isn't requested, like FS events. - * - * since the only thing that should call these routines is the renderer's - * init_fpe() and free_fpe(), there shouldn't be any problem in using - * freed data. - */ -void -QueueFontWakeup(fpe) - FontPathElementPtr fpe; -{ - int i; - FontPathElementPtr *new; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - -#ifdef DEBUG - fprintf(stderr, "re-queueing fpe wakeup\n"); -#endif - - return; - } - } - if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - xrealloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; - } - slept_fpes[num_slept_fpes] = fpe; - num_slept_fpes++; -} - -void -RemoveFontWakeup(fpe) - FontPathElementPtr fpe; -{ - int i, - j; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } - } -} - -/* ARGSUSED */ -void -FontWakeup(data, count, LastSelectMask) - pointer data; - int count; - pointer LastSelectMask; -{ - int i; - FontPathElementPtr fpe; - - if (count < 0) - return; - /* wake up any fpe's that may be waiting for information */ - for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); - } -} - -/* XXX -- these two funcs may want to be broken into macros */ -static void -#if NeedFunctionPrototypes -UseFPE(FontPathElementPtr fpe) -#else -UseFPE(fpe) - FontPathElementPtr fpe; -#endif -{ - fpe->refcount++; -} - -static void -#if NeedFunctionPrototypes -FreeFPE (FontPathElementPtr fpe) -#else -FreeFPE (fpe) - FontPathElementPtr fpe; -#endif -{ - fpe->refcount--; - if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); - } -} - -static Bool -#if NeedFunctionPrototypes -doOpenFont(ClientPtr client, OFclosurePtr c) -#else -doOpenFont(client, c) - ClientPtr client; - OFclosurePtr c; -#endif -{ - FontPtr pfont = NullFont; - FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; - char nxagentOrigFontName[256]; - int nxagentOrigFontNameLen; - - /* - * Decide at runtime what FontFormat to use. - */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - -#if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | -#endif - -#if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | -#endif - -#if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | -#endif - -#if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | -#endif - - BitmapFormatScanlineUnit8; - - - nxagentOrigFontNameLen = (c -> origFontNameLen < 256) ? c -> origFontNameLen : 255; - - memcpy(nxagentOrigFontName, c -> origFontName, nxagentOrigFontNameLen); - - nxagentOrigFontName[nxagentOrigFontNameLen] = 0; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) - break; - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doOpenFont: client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - break; - } - - if (err != Successful) - goto bail; - if (!pfont) { - err = BadFontName; - goto bail; - } - if (!pfont->fpe) - pfont->fpe = fpe; - pfont->refcnt++; - if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - - /* NXAGENT uses useless screen pointer to pass the original font name - * to realizeFont, could be a source of problems in the future. - */ - - if (!(*pScr->RealizeFont) ((ScreenPtr)nxagentOrigFontName, pfont)) - { - CloseFont (pfont, (Font) 0); - err=BadFontName; - goto bail; - } - } - } - } - if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; - } - if( nxagentFontPriv(pfont) -> mirrorID == 0 ) - { - extern RESTYPE RT_NX_FONT; - - nxagentFontPriv(pfont) -> mirrorID = FakeClientID(0); - if (!AddResource(nxagentFontPriv(pfont) -> mirrorID, RT_NX_FONT, (pointer) pfont)) { - FreeResource(c->fontid, RT_NONE); - err = AllocError; - goto bail; - } - } - if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, nxagentOrigFontName, nxagentOrigFontNameLen, - pfont); -bail: - if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); - } - if (c->slept) - { - ClientWakeup(c->client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doOpenFont: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); - } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); - return TRUE; -} - -int -OpenFont(client, fid, flags, lenfname, pfontname) - ClientPtr client; - XID fid; - Mask flags; - unsigned lenfname; - char *pfontname; -{ - OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - c = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!c) - return BadAlloc; - c->fontname = (char *) xalloc(lenfname); - c->origFontName = pfontname; - c->origFontNameLen = lenfname; - if (!c->fontname) { - xfree(c); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); - return BadAlloc; - } - memmove(c->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->fontid = fid; - c->current_fpe = 0; - c->num_fpes = num_fpes; - c->fnamelen = lenfname; - c->slept = FALSE; - c->flags = flags; - c->non_cachable_font = cached; - - (void) doOpenFont(client, c); - return Success; -} - -/* - * Decrement font's ref count, and free storage if ref count equals zero - */ -/*ARGSUSED*/ -int -CloseFont(value, fid) - pointer value; /* must conform to DeleteType */ - XID fid; -{ - int nscr; - ScreenPtr pscr; - FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; - - if (pfont == NullFont) - return (Success); - if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; -#ifdef LBX - LbxFreeFontTag(pfont); -#endif -#ifdef XF86BIGFONT - { - extern void XF86BigfontFreeFontShm(FontPtr); - XF86BigfontFreeFontShm(pfont); - } -#endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); - } - return (Success); -} - - -/***====================================================================***/ - - /* - * \ Sets up pReply as the correct QueryFontReply for pFont with the first - * nProtoCCIStructs char infos. \ - */ - -void -QueryFont(pFont, pReply, nProtoCCIStructs) - FontPtr pFont; - xQueryFontReply *pReply; /* caller must allocate this storage */ - int nProtoCCIStructs; -{ - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; - - /* pr->length set in dispatch */ - pReply->minCharOrByte2 = pFont->info.firstCol; - pReply->defaultChar = pFont->info.defaultCh; - pReply->maxCharOrByte2 = pFont->info.lastCol; - pReply->drawDirection = pFont->info.drawDirection; - pReply->allCharsExist = pFont->info.allExist; - pReply->minByte1 = pFont->info.firstRow; - pReply->maxByte1 = pFont->info.lastRow; - pReply->fontAscent = pFont->info.fontAscent; - pReply->fontDescent = pFont->info.fontDescent; - - pReply->minBounds = pFont->info.ink_minbounds; - pReply->maxBounds = pFont->info.ink_maxbounds; - - pReply->nFontProps = pFont->info.nprops; - pReply->nCharInfos = nProtoCCIStructs; - - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - } - - ninfos = 0; - ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); - prCI = (xCharInfo *) (prFP); - for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } - } - return; -} - -static Bool -#if NeedFunctionPrototypes -doListFontsAndAliases(ClientPtr client, LFclosurePtr c) -#else -doListFontsAndAliases(client, c) - ClientPtr client; - LFclosurePtr c; -#endif -{ - FontPathElementPtr fpe; - int err = Successful; - FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont (1): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont (2): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont (3): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ - if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; - } - -finish: - - names = c->names; - nnames = names->nnames; - client = c->client; - stringLens = 0; - for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - - reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; - reply.nFonts = nnames; - reply.sequenceNumber = client->sequence; - - bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2); - - if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; - } - /* - * since WriteToClient long word aligns things, copy to temp buffer and - * write all at once - */ - for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - { - /* dirty hack: don't list to client fonts not existing on the remote side */ - char tmp[256]; - - memcpy(tmp, names->names[i], names->length[i]); - tmp[ names->length[i] ] = 0; - - if (nxagentFontLookUp(tmp) == 0) - { -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "doListFontsAndAliases:\n"); - fprintf(stderr, " removing font: %s \n", tmp); -#endif - reply.nFonts--; - stringLens -= names->length[i]; - continue; - } - } - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } - } - nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); - (void) WriteToClient(client, stringLens + nnames, bufferStart); - DEALLOCATE_LOCAL(bufferStart); - -bail: - if (c->slept) - { - ClientWakeup(client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); - return TRUE; -} - -int -ListFonts(client, pattern, length, max_names) - ClientPtr client; - unsigned char *pattern; - unsigned int length; - unsigned int max_names; -{ - int i; - LFclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - return BadAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - return BadAlloc; - } - c->names = MakeFontNamesRecord(max_names < nxagentMaxFontNames ? max_names : nxagentMaxFontNames); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - return BadAlloc; - } - memmove( c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsAndAliases(client, c); - return Success; -} - -int -doListFontsWithInfo(client, c) - ClientPtr client; - LFWIclosurePtr c; -{ - FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; - xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; - xListFontsWithInfoReply finalReply; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; - if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFontWinfo (1): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFontWinfo (2): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - c->savedName = (char *) pFontInfo; - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - - if (nxagentFontLookUp(name) == 0) - { -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "doListFontsAndAliases (with info):\n"); - fprintf(stderr, " removing font: %s \n", name); -#endif - continue; - } - - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - c->reply = reply; - c->length = length; - } - reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: - length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); - finalReply.type = X_Reply; - finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; - WriteSwappedDataToClient(client, length, &finalReply); -bail: - if (c->slept) - { - ClientWakeup(client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFontWinfo: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - xfree(c); - return TRUE; -} - -int -StartListFontsWithInfo(client, length, pattern, max_names) - ClientPtr client; - int length; - unsigned char *pattern; - int max_names; -{ - int i; - LFWIclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFWIclosurePtr) xalloc(sizeof *c))) - goto badAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - xfree(c); - goto badAlloc; - } - memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->reply = 0; - c->length = 0; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->savedNumFonts = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - doListFontsWithInfo(client, c); - return Success; -badAlloc: - return BadAlloc; -} - -#define TextEltHeader 2 -#define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; -#define clearGCmask (GCClipMask) - -int -doPolyText(client, c) - ClientPtr client; - register PTclosurePtr c; -{ - register FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; - int err = Success, lgerr; /* err is in X error, not font error, space */ - enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; - FontPathElementPtr fpe; - GC *origGC = NULL; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (c->slept) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } - - client_state = c->slept ? SLEEPING : NEVER_SLEPT; - - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - oldfid = fid; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - client->errorValue = fid; - err = BadFont; - /* restore pFont and fid for step 4 (described below) */ - pFont = oldpFont; - fid = oldfid; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGC( c->pGC, GCFont, &fid); - ValidateGC(c->pDraw, c->pGC); - if (c->reqType == X_PolyText8) - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; - else - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16; - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!c->slept) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - len = c->endReq - c->pElt; - c->data = (unsigned char *)xalloc(len); - if (!c->data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(c->data, c->pElt, len); - c->pElt = c->data; - c->endReq = c->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - - pGC->tileIsPixel = TRUE; - pGC->tile.pixel = 0; - pGC->stipple = NullPixmap; - - if ((err = CopyGC(c->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doPolyText (1): client [%lx] sleeping.\n", client); -#endif - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, c->pElt + TextEltHeader); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGC(origGC, GCFont, &fid); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; - if (err != Success && c->client != serverClient) { -#ifdef PANORAMIX - if (noPanoramiXExtension || !c->pGC->pScreen->myNum) -#endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doPolytext: client [%lx] wakeup.\n", client); -#endif - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -PolyText(client, pDraw, pGC, pElt, endReq, xorg, yorg, reqType, did) - ClientPtr client; - DrawablePtr pDraw; - GC *pGC; - unsigned char *pElt; - unsigned char *endReq; - int xorg; - int yorg; - int reqType; - XID did; -{ - PTclosureRec local_closure; - - local_closure.pElt = pElt; - local_closure.endReq = endReq; - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_PolyText8) - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8; - local_closure.itemSize = 1; - } - else - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16; - local_closure.itemSize = 2; - } - local_closure.pGC = pGC; - local_closure.did = did; - local_closure.err = Success; - local_closure.slept = FALSE; - - (void) doPolyText(client, &local_closure); - return Success; -} - - -#undef TextEltHeader -#undef FontShiftSize - -int -doImageText(client, c) - ClientPtr client; - register ITclosurePtr c; -{ - int err = Success, lgerr; /* err is in X error, not font error, space */ - FontPathElementPtr fpe; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); - if (lgerr == Suspended) - { - if (!c->slept) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = (unsigned char *)xalloc(c->nChars * c->itemSize); - if (!data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * c->itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - - pGC->tileIsPixel = TRUE; - pGC->tile.pixel = 0; - pGC->stipple = NullPixmap; - - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doImageText (1): client [%lx] sleeping.\n", client); -#endif - - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, c->data); - } - -bail: - - if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doImageText: client [%lx] wakeup.\n", client); -#endif - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -ImageText(client, pDraw, pGC, nChars, data, xorg, yorg, reqType, did) - ClientPtr client; - DrawablePtr pDraw; - GC *pGC; - int nChars; - unsigned char *data; - int xorg; - int yorg; - int reqType; - XID did; -{ - ITclosureRec local_closure; - - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.pGC = pGC; - local_closure.nChars = nChars; - local_closure.data = data; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_ImageText8) - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8; - local_closure.itemSize = 1; - } - else - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16; - local_closure.itemSize = 2; - } - local_closure.did = did; - local_closure.slept = FALSE; - - (void) doImageText(client, &local_closure); - return Success; -} - - -/* does the necessary magic to figure out the fpe type */ -static int -#if NeedFunctionPrototypes -DetermineFPEType(char *pathname) -#else -DetermineFPEType(pathname) - char *pathname; -#endif -{ - int i; - - for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; - } - return -1; -} - - -static void -#if NeedFunctionPrototypes -FreeFontPath(FontPathElementPtr *list, int n, Bool force) -#else -FreeFontPath(list, n, force) - FontPathElementPtr *list; - Bool force; - int n; -#endif -{ - int i; - - for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n", - list[i]->name_length, list[i]->name, - list[i]->refcount, found); - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); - } - xfree((char *) list); -} - -static FontPathElementPtr -#if NeedFunctionPrototypes -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) -#else -find_existing_fpe(list, num, name, len) - FontPathElementPtr *list; - int num; - unsigned char *name; - int len; -#endif -{ - FontPathElementPtr fpe; - int i; - - for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; - } - return (FontPathElementPtr) 0; -} - - -static int -#if NeedFunctionPrototypes -SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) -#else -SetFontPathElements(npaths, paths, bad, persist) - int npaths; - unsigned char *paths; - int *bad; - Bool persist; -#endif -{ - int i, err = 0; - int valid_paths = 0; - unsigned int len; - unsigned char *cp = paths; - FontPathElementPtr fpe = NULL, *fplist; - - fplist = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * npaths); - if (!fplist) { - *bad = 0; - return BadAlloc; - } - for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF ("Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = (char *) xalloc(len + 1); - if (!fpe->name) - { - xfree(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - if (persist) - { - ErrorF("Could not init font path element %s, removing from list!\n", - fpe->name); - } - xfree (fpe->name); - xfree (fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; - } - - FreeFontPath(font_path_elements, num_fpes, FALSE); - font_path_elements = fplist; - if (patternCache) - EmptyFontPatternCache(patternCache); - num_fpes = valid_paths; - - return Success; -bail: - *bad = i; - while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); - xfree(fplist); - return FontToXError(err); -} - -/* XXX -- do we need to pass error down to each renderer? */ -int -SetFontPath(client, npaths, paths, error) - ClientPtr client; - int npaths; - unsigned char *paths; - int *error; -{ - int err = Success; - - if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - err = SetFontPathElements(npaths, paths, error, FALSE); - } - return err; -} - -int -SetDefaultFontPath(path) - char *path; -{ - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; - - /* get enough for string, plus values -- use up commas */ -#ifdef NX_TRANS_SOCKET - len = strlen(_NXGetFontPath(path)) + 1; -#else - len = strlen(path) + 1; -#endif - nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len); - if (!newpath) - return BadAlloc; -#ifdef NX_TRANS_SOCKET - pp = (unsigned char *) _NXGetFontPath(path); -#else - pp = (unsigned char *) path; -#endif - cp++; - while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } - } - *nump = (unsigned char) size; - - err = SetFontPathElements(num, newpath, &bad, TRUE); - - DEALLOCATE_LOCAL(newpath); - - return err; -} - -unsigned char * -GetFontPath(count, length) - int *count; - int *length; -{ - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; - - len = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; - } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); - if (!font_path_string) - return NULL; - - c = font_path_string; - *length = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; - } - *count = num_fpes; - return font_path_string; -} - -int -LoadGlyphs(client, pfont, nchars, item_size, data) - ClientPtr client; - FontPtr pfont; - unsigned nchars; - int item_size; - unsigned char *data; -{ - if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); - else - return Successful; -} - -void -DeleteClientFontStuff(client) - ClientPtr client; -{ - int i; - FontPathElementPtr fpe; - - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } -} - -void -InitFonts () -{ - patternCache = MakeFontPatternCache(); - -#ifndef KDRIVESERVER - if (screenInfo.numScreens > screenInfo.numVideoScreens) { - PrinterFontRegisterFpeFunctions(); - FontFileCheckRegisterFpeFunctions(); - check_fs_register_fpe_functions(); - } else -#endif - { -#ifdef KDRIVESERVER - BuiltinRegisterFpeFunctions(); -#endif - FontFileRegisterFpeFunctions(); -#ifndef NOFONTSERVERACCESS - fs_register_fpe_functions(); -#endif - } -} - -int -GetDefaultPointSize () -{ - return 120; -} - - -FontResolutionPtr -GetClientResolutions (num) - int *num; -{ - if (requestingClient && requestingClient->fontResFunc != NULL && - !requestingClient->clientGone) - { - return (*requestingClient->fontResFunc)(requestingClient, num); - } - else { - static struct _FontResolution res; - ScreenPtr pScreen; - - pScreen = screenInfo.screens[0]; - res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; - /* - * XXX - we'll want this as long as bitmap instances are prevalent - so that we can match them from scalable fonts - */ - if (res.x_resolution < 88) - res.x_resolution = 75; - else - res.x_resolution = 100; - res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; - if (res.y_resolution < 88) - res.y_resolution = 75; - else - res.y_resolution = 100; - res.point_size = 120; - *num = 1; - return &res; - } -} - -/* - * returns the type index of the new fpe - * - * should be called (only once!) by each type of fpe when initialized - */ - -int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) -{ - FPEFunctions *new; - - /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); - if (!new) - return -1; - fpe_functions = new; - - fpe_functions[num_fpe_types].name_check = name_func; - fpe_functions[num_fpe_types].open_font = open_func; - fpe_functions[num_fpe_types].close_font = close_func; - fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; - fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; - fpe_functions[num_fpe_types].init_fpe = init_func; - fpe_functions[num_fpe_types].free_fpe = free_func; - fpe_functions[num_fpe_types].reset_fpe = reset_func; - fpe_functions[num_fpe_types].client_died = client_died; - fpe_functions[num_fpe_types].load_glyphs = load_glyphs; - fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; - fpe_functions[num_fpe_types].set_path_hook = set_path_func; - - return num_fpe_types++; -} - -void -FreeFonts() -{ - if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; - } - FreeFontPath(font_path_elements, num_fpes, TRUE); - font_path_elements = 0; - num_fpes = 0; - xfree(fpe_functions); - num_fpe_types = 0; - fpe_functions = (FPEFunctions *) 0; -} - -/* convenience functions for FS interface */ - -FontPtr -find_old_font(id) - XID id; -{ - return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE, - SecurityUnknownAccess); -} - -Font -GetNewFontClientID() -{ - return FakeClientID(0); -} - -int -StoreFontClientFont(pfont, id) - FontPtr pfont; - Font id; -{ - return AddResource(id, RT_NONE, (pointer) pfont); -} - -void -DeleteFontClientID(id) - Font id; -{ - FreeResource(id, RT_NONE); -} - -int -client_auth_generation(client) - ClientPtr client; -{ - return 0; -} - -static int fs_handlers_installed = 0; -static unsigned int last_server_gen; - -int -init_fs_handlers(fpe, block_handler) - FontPathElementPtr fpe; - BlockHandlerProcPtr block_handler; -{ - /* if server has reset, make sure the b&w handlers are reinstalled */ - if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; - } - if (fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "adding FS b & w handlers\n"); -#endif - - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; - } - QueueFontWakeup(fpe); - return Successful; -} - -void -remove_fs_handlers(fpe, block_handler, all) - FontPathElementPtr fpe; - BlockHandlerProcPtr block_handler; - Bool all; -{ - if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "removing FS b & w handlers\n"); -#endif - - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } - } - RemoveFontWakeup(fpe); -} - -#ifdef DEBUG -#define GLWIDTHBYTESPADDED(bits,nbytes) \ - ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ - :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ - :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ - :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ - : 0) - -#define GLYPH_SIZE(ch, nbytes) \ - GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \ - (ch)->metrics.leftSideBearing, (nbytes)) -dump_char_ascii(cip) - CharInfoPtr cip; -{ - int r, - l; - int bpr; - int byte; - static unsigned maskTab[] = { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - bpr = GLYPH_SIZE(cip, 4); - for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) { - pointer row = (pointer) cip->bits + r * bpr; - - byte = 0; - for (l = 0; l <= (cip->metrics.rightSideBearing - - cip->metrics.leftSideBearing); l++) { - if (maskTab[l & 7] & row[l >> 3]) - putchar('X'); - else - putchar('.'); - } - putchar('\n'); - } -} - -#endif - - -typedef struct -{ - LFclosurePtr c; - OFclosurePtr oc; -} nxFs,*nxFsPtr; - -static Bool -#if NeedFunctionPrototypes -nxdoListFontsAndAliases(ClientPtr client, nxFsPtr fss) -#else -nxdoListFontsAndAliases(client, fss) - ClientPtr client; - nxFsPtr fss; -#endif -{ - LFclosurePtr c=fss->c; - OFclosurePtr oc=fss->oc; - FontPathElementPtr fpe; - int err = Successful; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int i; - int aliascount = 0; - char tmp[256]; - tmp[0]=0; - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)nxdoListFontsAndAliases, - (pointer) fss); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont (1): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)nxdoListFontsAndAliases, - (pointer) fss); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont (2): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)nxdoListFontsAndAliases, - (pointer) fss); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont (3): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - { - memmove(resolved, tmpname, resolvedlen); - resolved[resolvedlen] = '\0'; - } - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - { - memcpy(tmp,c->savedName,c->savedNameLen>255?255:c->savedNameLen); - tmp[c->savedNameLen>255?256:c->savedNameLen]=0; - if (nxagentFontLookUp(tmp)) - break; - else tmp[0]=0; - } - } - else - { - memcpy(tmp,name,namelen>255?255:namelen); - tmp[namelen>255?256:namelen]=0; - if (nxagentFontLookUp(tmp)) - break; - else tmp[0]=0; - } - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - { - memmove(c->savedName, name, namelen); - c->savedName[namelen] = '\0'; - } - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ -bail: -finish: - if (strlen(tmp)) - { -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "nxListFont changed (0) font to %s\n",tmp); -#endif - memcpy(oc->fontname, tmp, strlen(tmp)); - oc->fnamelen = strlen(tmp); - - oc->origFontName = oc->fontname; - oc->origFontNameLen = oc->fnamelen; - - } - else - { - for (i = 0; i < c->names->nnames; i++) - { - if (c->names->length[i] > 255) - continue; - else - { - memcpy(tmp, c->names->names[i], c->names->length[i]); - tmp[ c->names->length[i] ] = 0; - if (nxagentFontLookUp(tmp) == 0) - continue; - memcpy(oc->fontname, tmp, strlen(tmp)); - oc->fnamelen = strlen(tmp); - - oc->origFontName = oc->fontname; - oc->origFontNameLen = oc->fnamelen; - -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "nxListFont changed (1) font to %s\n",tmp); -#endif - break; - } - } - } - - if (c->slept) - { - ClientWakeup(client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(c->names); - xfree(c); - xfree(fss); - if (resolved) xfree(resolved); - - return doOpenFont(client, oc); -} - -int -nxOpenFont(client, fid, flags, lenfname, pfontname) - ClientPtr client; - XID fid; - Mask flags; - unsigned lenfname; - char *pfontname; -{ - nxFsPtr fss; - LFclosurePtr c; - OFclosurePtr oc; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - if (!(fss = (nxFsPtr) xalloc(sizeof(nxFs)))) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - { - xfree(fss); - return BadAlloc; - } - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - xfree(fss); - return BadAlloc; - } - c->names = MakeFontNamesRecord(100); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - xfree(fss); - return BadAlloc; - } - memmove( c->current.pattern, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = lenfname; - c->current.current_fpe = 0; - c->current.max_names = nxagentMaxFontNames; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - - oc = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!oc) - { - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - xfree(c); - xfree(fss); - return BadAlloc; - } - oc->fontname = (char *) xalloc(256);/* I don't want to deal with future reallocs errors */ - oc->origFontName = pfontname; - oc->origFontNameLen = lenfname; - if (!oc->fontname) { - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - xfree(c); - xfree(oc); - xfree(fss); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - oc->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!oc->fpe_list) { - xfree(oc->fontname); - xfree(oc); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - xfree(c); - xfree(fss); - return BadAlloc; - } - memmove(oc->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - oc->fpe_list[i] = font_path_elements[i]; - UseFPE(oc->fpe_list[i]); - } - oc->client = client; - oc->fontid = fid; - oc->current_fpe = 0; - oc->num_fpes = num_fpes; - oc->fnamelen = lenfname; - oc->slept = FALSE; - oc->flags = flags; - oc->non_cachable_font = cached; - fss->c=c; - fss->oc=oc; - nxdoListFontsAndAliases(client, fss); - return Success; -} - - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.XF86.original deleted file mode 100644 index 5386c908b..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c.XF86.original +++ /dev/null @@ -1,2223 +0,0 @@ -/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.27 2003/02/15 03:47:05 dawes Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */ - -#define NEED_REPLIES -#include "X.h" -#include "Xmd.h" -#include "Xproto.h" -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "cursorstr.h" -#include "misc.h" -#include "opaque.h" -#include "dixfontstr.h" -#include "closestr.h" - -#ifdef DEBUG -#include -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#endif - -#ifdef LBX -#include "lbxserve.h" -#endif - -#ifdef XF86BIGFONT -#define _XF86BIGFONT_SERVER_ -#include "xf86bigfont.h" -#endif - -#define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics - -extern pointer fosNaturalParams; -extern FontPtr defaultFont; - -static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; -FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; - -static unsigned char *font_path_string; - -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; -static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; -static FontPatternCachePtr patternCache; - -int -FontToXError(err) - int err; -{ - switch (err) { - case Successful: - return Success; - case AllocError: - return BadAlloc; - case BadFontName: - return BadName; - case BadFontPath: - case BadFontFormat: /* is there something better? */ - case BadCharRange: - return BadValue; - default: - return err; - } -} - - -/* - * adding RT_FONT prevents conflict with default cursor font - */ -Bool -SetDefaultFont(defaultfontname) - char *defaultfontname; -{ - int err; - FontPtr pf; - XID fid; - - fid = FakeClientID(0); - err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); - if (err != Success) - return FALSE; - pf = (FontPtr) LookupIDByType(fid, RT_FONT); - if (pf == (FontPtr) NULL) - return FALSE; - defaultFont = pf; - return TRUE; -} - -/* - * note that the font wakeup queue is not refcounted. this is because - * an fpe needs to be added when it's inited, and removed when it's finally - * freed, in order to handle any data that isn't requested, like FS events. - * - * since the only thing that should call these routines is the renderer's - * init_fpe() and free_fpe(), there shouldn't be any problem in using - * freed data. - */ -void -QueueFontWakeup(fpe) - FontPathElementPtr fpe; -{ - int i; - FontPathElementPtr *new; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - -#ifdef DEBUG - fprintf(stderr, "re-queueing fpe wakeup\n"); -#endif - - return; - } - } - if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - xrealloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; - } - slept_fpes[num_slept_fpes] = fpe; - num_slept_fpes++; -} - -void -RemoveFontWakeup(fpe) - FontPathElementPtr fpe; -{ - int i, - j; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } - } -} - -/* ARGSUSED */ -void -FontWakeup(data, count, LastSelectMask) - pointer data; - int count; - pointer LastSelectMask; -{ - int i; - FontPathElementPtr fpe; - - if (count < 0) - return; - /* wake up any fpe's that may be waiting for information */ - for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); - } -} - -/* XXX -- these two funcs may want to be broken into macros */ -static void -#if NeedFunctionPrototypes -UseFPE(FontPathElementPtr fpe) -#else -UseFPE(fpe) - FontPathElementPtr fpe; -#endif -{ - fpe->refcount++; -} - -static void -#if NeedFunctionPrototypes -FreeFPE (FontPathElementPtr fpe) -#else -FreeFPE (fpe) - FontPathElementPtr fpe; -#endif -{ - fpe->refcount--; - if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); - } -} - -static Bool -#if NeedFunctionPrototypes -doOpenFont(ClientPtr client, OFclosurePtr c) -#else -doOpenFont(client, c) - ClientPtr client; - OFclosurePtr c; -#endif -{ - FontPtr pfont = NullFont; - FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; - /* - * Decide at runtime what FontFormat to use. - */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - -#if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | -#endif - -#if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | -#endif - -#if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | -#endif - -#if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | -#endif - - BitmapFormatScanlineUnit8; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) - break; - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); - } - return TRUE; - } - break; - } - - if (err != Successful) - goto bail; - if (!pfont) { - err = BadFontName; - goto bail; - } - if (!pfont->fpe) - pfont->fpe = fpe; - pfont->refcnt++; - if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - if (!(*pScr->RealizeFont) (pScr, pfont)) - { - CloseFont (pfont, (Font) 0); - err = AllocError; - goto bail; - } - } - } - } - if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; - } - if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen, - pfont); -bail: - if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); - } - if (c->slept) - ClientWakeup(c->client); - for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); - } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); - return TRUE; -} - -int -OpenFont(client, fid, flags, lenfname, pfontname) - ClientPtr client; - XID fid; - Mask flags; - unsigned lenfname; - char *pfontname; -{ - OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - c = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!c) - return BadAlloc; - c->fontname = (char *) xalloc(lenfname); - c->origFontName = pfontname; - c->origFontNameLen = lenfname; - if (!c->fontname) { - xfree(c); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); - return BadAlloc; - } - memmove(c->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->fontid = fid; - c->current_fpe = 0; - c->num_fpes = num_fpes; - c->fnamelen = lenfname; - c->slept = FALSE; - c->flags = flags; - c->non_cachable_font = cached; - - (void) doOpenFont(client, c); - return Success; -} - -/* - * Decrement font's ref count, and free storage if ref count equals zero - */ -/*ARGSUSED*/ -int -CloseFont(value, fid) - pointer value; /* must conform to DeleteType */ - XID fid; -{ - int nscr; - ScreenPtr pscr; - FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; - - if (pfont == NullFont) - return (Success); - if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; -#ifdef LBX - LbxFreeFontTag(pfont); -#endif -#ifdef XF86BIGFONT - XF86BigfontFreeFontShm(pfont); -#endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); - } - return (Success); -} - - -/***====================================================================***/ - - /* - * \ Sets up pReply as the correct QueryFontReply for pFont with the first - * nProtoCCIStructs char infos. \ - */ - -void -QueryFont(pFont, pReply, nProtoCCIStructs) - FontPtr pFont; - xQueryFontReply *pReply; /* caller must allocate this storage */ - int nProtoCCIStructs; -{ - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; - - /* pr->length set in dispatch */ - pReply->minCharOrByte2 = pFont->info.firstCol; - pReply->defaultChar = pFont->info.defaultCh; - pReply->maxCharOrByte2 = pFont->info.lastCol; - pReply->drawDirection = pFont->info.drawDirection; - pReply->allCharsExist = pFont->info.allExist; - pReply->minByte1 = pFont->info.firstRow; - pReply->maxByte1 = pFont->info.lastRow; - pReply->fontAscent = pFont->info.fontAscent; - pReply->fontDescent = pFont->info.fontDescent; - - pReply->minBounds = pFont->info.ink_minbounds; - pReply->maxBounds = pFont->info.ink_maxbounds; - - pReply->nFontProps = pFont->info.nprops; - pReply->nCharInfos = nProtoCCIStructs; - - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - } - - ninfos = 0; - ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); - prCI = (xCharInfo *) (prFP); - for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } - } - return; -} - -static Bool -#if NeedFunctionPrototypes -doListFontsAndAliases(ClientPtr client, LFclosurePtr c) -#else -doListFontsAndAliases(client, c) - ClientPtr client; - LFclosurePtr c; -#endif -{ - FontPathElementPtr fpe; - int err = Successful; - FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ - if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; - } - -finish: - - names = c->names; - nnames = names->nnames; - client = c->client; - stringLens = 0; - for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - - reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; - reply.nFonts = nnames; - reply.sequenceNumber = client->sequence; - - bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2); - - if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; - } - /* - * since WriteToClient long word aligns things, copy to temp buffer and - * write all at once - */ - for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } - } - nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); - (void) WriteToClient(client, stringLens + nnames, bufferStart); - DEALLOCATE_LOCAL(bufferStart); - -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); - return TRUE; -} - -int -ListFonts(client, pattern, length, max_names) - ClientPtr client; - unsigned char *pattern; - unsigned int length; - unsigned int max_names; -{ - int i; - LFclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - return BadAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - return BadAlloc; - } - c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - return BadAlloc; - } - memmove( c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsAndAliases(client, c); - return Success; -} - -int -doListFontsWithInfo(client, c) - ClientPtr client; - LFWIclosurePtr c; -{ - FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; - xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; - xListFontsWithInfoReply finalReply; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; - if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; - } - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - c->savedName = (char *) pFontInfo; - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - c->reply = reply; - c->length = length; - } - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: - length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); - finalReply.type = X_Reply; - finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; - WriteSwappedDataToClient(client, length, &finalReply); -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - xfree(c); - return TRUE; -} - -int -StartListFontsWithInfo(client, length, pattern, max_names) - ClientPtr client; - int length; - unsigned char *pattern; - int max_names; -{ - int i; - LFWIclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFWIclosurePtr) xalloc(sizeof *c))) - goto badAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - xfree(c); - goto badAlloc; - } - memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->reply = 0; - c->length = 0; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->savedNumFonts = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - doListFontsWithInfo(client, c); - return Success; -badAlloc: - return BadAlloc; -} - -#define TextEltHeader 2 -#define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; -#define clearGCmask (GCClipMask) - -int -doPolyText(client, c) - ClientPtr client; - register PTclosurePtr c; -{ - register FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; - int err = Success, lgerr; /* err is in X error, not font error, space */ - enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; - FontPathElementPtr fpe; - GC *origGC = NULL; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (c->slept) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } - - client_state = c->slept ? SLEEPING : NEVER_SLEPT; - - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - oldfid = fid; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - client->errorValue = fid; - err = BadFont; - /* restore pFont and fid for step 4 (described below) */ - pFont = oldpFont; - fid = oldfid; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGC( c->pGC, GCFont, &fid); - ValidateGC(c->pDraw, c->pGC); - if (c->reqType == X_PolyText8) - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; - else - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16; - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!c->slept) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - len = c->endReq - c->pElt; - c->data = (unsigned char *)xalloc(len); - if (!c->data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(c->data, c->pElt, len); - c->pElt = c->data; - c->endReq = c->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, c->pElt + TextEltHeader); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGC(origGC, GCFont, &fid); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; - if (err != Success && c->client != serverClient) { -#ifdef PANORAMIX - if (noPanoramiXExtension || !c->pGC->pScreen->myNum) -#endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -PolyText(client, pDraw, pGC, pElt, endReq, xorg, yorg, reqType, did) - ClientPtr client; - DrawablePtr pDraw; - GC *pGC; - unsigned char *pElt; - unsigned char *endReq; - int xorg; - int yorg; - int reqType; - XID did; -{ - PTclosureRec local_closure; - - local_closure.pElt = pElt; - local_closure.endReq = endReq; - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_PolyText8) - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8; - local_closure.itemSize = 1; - } - else - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16; - local_closure.itemSize = 2; - } - local_closure.pGC = pGC; - local_closure.did = did; - local_closure.err = Success; - local_closure.slept = FALSE; - - (void) doPolyText(client, &local_closure); - return Success; -} - - -#undef TextEltHeader -#undef FontShiftSize - -int -doImageText(client, c) - ClientPtr client; - register ITclosurePtr c; -{ - int err = Success, lgerr; /* err is in X error, not font error, space */ - FontPathElementPtr fpe; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); - if (lgerr == Suspended) - { - if (!c->slept) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = (unsigned char *)xalloc(c->nChars * c->itemSize); - if (!data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * c->itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, c->data); - } - -bail: - - if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -ImageText(client, pDraw, pGC, nChars, data, xorg, yorg, reqType, did) - ClientPtr client; - DrawablePtr pDraw; - GC *pGC; - int nChars; - unsigned char *data; - int xorg; - int yorg; - int reqType; - XID did; -{ - ITclosureRec local_closure; - - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.pGC = pGC; - local_closure.nChars = nChars; - local_closure.data = data; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_ImageText8) - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8; - local_closure.itemSize = 1; - } - else - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16; - local_closure.itemSize = 2; - } - local_closure.did = did; - local_closure.slept = FALSE; - - (void) doImageText(client, &local_closure); - return Success; -} - - -/* does the necessary magic to figure out the fpe type */ -static int -#if NeedFunctionPrototypes -DetermineFPEType(char *pathname) -#else -DetermineFPEType(pathname) - char *pathname; -#endif -{ - int i; - - for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; - } - return -1; -} - - -static void -#if NeedFunctionPrototypes -FreeFontPath(FontPathElementPtr *list, int n, Bool force) -#else -FreeFontPath(list, n, force) - FontPathElementPtr *list; - Bool force; - int n; -#endif -{ - int i; - - for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n", - list[i]->name_length, list[i]->name, - list[i]->refcount, found); - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); - } - xfree((char *) list); -} - -static FontPathElementPtr -#if NeedFunctionPrototypes -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) -#else -find_existing_fpe(list, num, name, len) - FontPathElementPtr *list; - int num; - unsigned char *name; - int len; -#endif -{ - FontPathElementPtr fpe; - int i; - - for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; - } - return (FontPathElementPtr) 0; -} - - -static int -#if NeedFunctionPrototypes -SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) -#else -SetFontPathElements(npaths, paths, bad, persist) - int npaths; - unsigned char *paths; - int *bad; - Bool persist; -#endif -{ - int i, err = 0; - int valid_paths = 0; - unsigned int len; - unsigned char *cp = paths; - FontPathElementPtr fpe = NULL, *fplist; - - fplist = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * npaths); - if (!fplist) { - *bad = 0; - return BadAlloc; - } - for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF ("Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = (char *) xalloc(len + 1); - if (!fpe->name) - { - xfree(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - if (persist) - { - ErrorF("Could not init font path element %s, removing from list!\n", - fpe->name); - } - xfree (fpe->name); - xfree (fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; - } - - FreeFontPath(font_path_elements, num_fpes, FALSE); - font_path_elements = fplist; - if (patternCache) - EmptyFontPatternCache(patternCache); - num_fpes = valid_paths; - - return Success; -bail: - *bad = i; - while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); - xfree(fplist); - return FontToXError(err); -} - -/* XXX -- do we need to pass error down to each renderer? */ -int -SetFontPath(client, npaths, paths, error) - ClientPtr client; - int npaths; - unsigned char *paths; - int *error; -{ - int err = Success; - - if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - err = SetFontPathElements(npaths, paths, error, FALSE); - } - return err; -} - -int -SetDefaultFontPath(path) - char *path; -{ - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; - - /* get enough for string, plus values -- use up commas */ - len = strlen(path) + 1; - nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len); - if (!newpath) - return BadAlloc; - pp = (unsigned char *) path; - cp++; - while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } - } - *nump = (unsigned char) size; - - err = SetFontPathElements(num, newpath, &bad, TRUE); - - DEALLOCATE_LOCAL(newpath); - - return err; -} - -unsigned char * -GetFontPath(count, length) - int *count; - int *length; -{ - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; - - len = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; - } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); - if (!font_path_string) - return NULL; - - c = font_path_string; - *length = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; - } - *count = num_fpes; - return font_path_string; -} - -int -LoadGlyphs(client, pfont, nchars, item_size, data) - ClientPtr client; - FontPtr pfont; - unsigned nchars; - int item_size; - unsigned char *data; -{ - if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); - else - return Successful; -} - -void -DeleteClientFontStuff(client) - ClientPtr client; -{ - int i; - FontPathElementPtr fpe; - - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } -} - -void -InitFonts () -{ - patternCache = MakeFontPatternCache(); - -#ifndef KDRIVESERVER - if (screenInfo.numScreens > screenInfo.numVideoScreens) { - PrinterFontRegisterFpeFunctions(); - FontFileCheckRegisterFpeFunctions(); - check_fs_register_fpe_functions(); - } else -#endif - { -#ifdef KDRIVESERVER - BuiltinRegisterFpeFunctions(); -#endif - FontFileRegisterFpeFunctions(); -#ifndef NOFONTSERVERACCESS - fs_register_fpe_functions(); -#endif - } -} - -int -GetDefaultPointSize () -{ - return 120; -} - - -FontResolutionPtr -GetClientResolutions (num) - int *num; -{ - if (requestingClient && requestingClient->fontResFunc != NULL && - !requestingClient->clientGone) - { - return (*requestingClient->fontResFunc)(requestingClient, num); - } - else { - static struct _FontResolution res; - ScreenPtr pScreen; - - pScreen = screenInfo.screens[0]; - res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; - /* - * XXX - we'll want this as long as bitmap instances are prevalent - so that we can match them from scalable fonts - */ - if (res.x_resolution < 88) - res.x_resolution = 75; - else - res.x_resolution = 100; - res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; - if (res.y_resolution < 88) - res.y_resolution = 75; - else - res.y_resolution = 100; - res.point_size = 120; - *num = 1; - return &res; - } -} - -/* - * returns the type index of the new fpe - * - * should be called (only once!) by each type of fpe when initialized - */ - -int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) -{ - FPEFunctions *new; - - /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); - if (!new) - return -1; - fpe_functions = new; - - fpe_functions[num_fpe_types].name_check = name_func; - fpe_functions[num_fpe_types].open_font = open_func; - fpe_functions[num_fpe_types].close_font = close_func; - fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; - fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; - fpe_functions[num_fpe_types].init_fpe = init_func; - fpe_functions[num_fpe_types].free_fpe = free_func; - fpe_functions[num_fpe_types].reset_fpe = reset_func; - fpe_functions[num_fpe_types].client_died = client_died; - fpe_functions[num_fpe_types].load_glyphs = load_glyphs; - fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; - fpe_functions[num_fpe_types].set_path_hook = set_path_func; - - return num_fpe_types++; -} - -void -FreeFonts() -{ - if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; - } - FreeFontPath(font_path_elements, num_fpes, TRUE); - font_path_elements = 0; - num_fpes = 0; - xfree(fpe_functions); - num_fpe_types = 0; - fpe_functions = (FPEFunctions *) 0; -} - -/* convenience functions for FS interface */ - -FontPtr -find_old_font(id) - XID id; -{ - return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE, - SecurityUnknownAccess); -} - -Font -GetNewFontClientID() -{ - return FakeClientID(0); -} - -int -StoreFontClientFont(pfont, id) - FontPtr pfont; - Font id; -{ - return AddResource(id, RT_NONE, (pointer) pfont); -} - -void -DeleteFontClientID(id) - Font id; -{ - FreeResource(id, RT_NONE); -} - -int -client_auth_generation(client) - ClientPtr client; -{ - return 0; -} - -static int fs_handlers_installed = 0; -static unsigned int last_server_gen; - -int -init_fs_handlers(fpe, block_handler) - FontPathElementPtr fpe; - BlockHandlerProcPtr block_handler; -{ - /* if server has reset, make sure the b&w handlers are reinstalled */ - if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; - } - if (fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "adding FS b & w handlers\n"); -#endif - - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; - } - QueueFontWakeup(fpe); - return Successful; -} - -void -remove_fs_handlers(fpe, block_handler, all) - FontPathElementPtr fpe; - BlockHandlerProcPtr block_handler; - Bool all; -{ - if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "removing FS b & w handlers\n"); -#endif - - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } - } - RemoveFontWakeup(fpe); -} - -#ifdef DEBUG -#define GLWIDTHBYTESPADDED(bits,nbytes) \ - ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ - :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ - :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ - :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ - : 0) - -#define GLYPH_SIZE(ch, nbytes) \ - GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \ - (ch)->metrics.leftSideBearing, (nbytes)) -dump_char_ascii(cip) - CharInfoPtr cip; -{ - int r, - l; - int bpr; - int byte; - static unsigned maskTab[] = { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - bpr = GLYPH_SIZE(cip, 4); - for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) { - pointer row = (pointer) cip->bits + r * bpr; - - byte = 0; - for (l = 0; l <= (cip->metrics.rightSideBearing - - cip->metrics.leftSideBearing); l++) { - if (maskTab[l & 7] & row[l >> 3]) - putchar('X'); - else - putchar('.'); - } - putchar('\n'); - } -} - -#endif diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXevents.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXevents.c.NX.original deleted file mode 100644 index f697cf3ca..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXevents.c.NX.original +++ /dev/null @@ -1,4797 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXevents.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/events.c,v 3.46 2002/09/17 01:15:09 dawes Exp $ */ -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/**************************************************************** -* * -* Copyright (c) Digital Equipment Corporation, 1991, 1997 * -* * -* All Rights Reserved. Unpublished rights reserved under * -* the copyright laws of the United States. * -* * -* The software contained on this media is proprietary to * -* and embodies the confidential technology of Digital * -* Equipment Corporation. Possession, use, duplication or * -* dissemination of the software and media is authorized only * -* pursuant to a valid written license from Digital Equipment * -* Corporation. * -* * -* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * -* by the U.S. Government is subject to restrictions as set * -* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * -* or in FAR 52.227-19, as applicable. * -* * -*****************************************************************/ - -/* $Xorg: events.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "X.h" -#include "Xlib.h" -#include "misc.h" -#include "resource.h" -#define NEED_EVENTS -#define NEED_REPLIES -#include "Xproto.h" -#include "windowstr.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "cursorstr.h" - -#include "dixstruct.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include "globals.h" - -#ifdef XKB -#include "XKBsrv.h" -#if NeedFunctionPrototypes -extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); -#else -extern Bool XkbFilterEvents(); -#endif -#endif - -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif - -#include "XIproto.h" -#include "exevents.h" -#include "extnsionst.h" - -#include "dixevents.h" -#include "dixgrabs.h" -#include "../../dix/dispatch.h" - -#include "NXlib.h" - -#include "Events.h" -#include "Windows.h" - -extern Display *nxagentDisplay; - -extern WindowPtr nxagentLastEnteredWindow; - -#define EXTENSION_EVENT_BASE 64 - -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ -#define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask ) -#define AllButtonsMask ( \ - Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) -#define MotionMask ( \ - PointerMotionMask | Button1MotionMask | \ - Button2MotionMask | Button3MotionMask | Button4MotionMask | \ - Button5MotionMask | ButtonMotionMask ) -#define PropagateMask ( \ - KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \ - MotionMask ) -#define PointerGrabMask ( \ - ButtonPressMask | ButtonReleaseMask | \ - EnterWindowMask | LeaveWindowMask | \ - PointerMotionHintMask | KeymapStateMask | \ - MotionMask ) -#define AllModifiersMask ( \ - ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \ - Mod3Mask | Mod4Mask | Mod5Mask ) -#define AllEventMasks (lastEventMask|(lastEventMask-1)) -/* - * The following relies on the fact that the ButtonMotionMasks are equal - * to the corresponding ButtonMasks from the current modifier/button state. - */ -#define Motion_Filter(class) (PointerMotionMask | \ - (class)->state | (class)->motionMask) - - -#define WID(w) ((w) ? ((w)->drawable.id) : 0) - -#define XE_KBPTR (xE->u.keyButtonPointer) - - -#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) - -CallbackListPtr EventCallback; -CallbackListPtr DeviceEventCallback; - -#define DNPMCOUNT 8 - -Mask DontPropagateMasks[DNPMCOUNT]; -static int DontPropagateRefCnts[DNPMCOUNT]; - -#ifdef DEBUG -static debug_events = 0; -#endif -InputInfo inputInfo; - -static struct { - QdEventPtr pending, *pendtail; - DeviceIntPtr replayDev; /* kludgy rock to put flag for */ - WindowPtr replayWin; /* ComputeFreezes */ - Bool playingEvents; - TimeStamp time; -} syncEvents; - -/* - * The window trace information is used to avoid having to compute all the - * windows between the root and the current pointer window each time a button - * or key goes down. The grabs on each of those windows must be checked. - */ -static WindowPtr *spriteTrace = (WindowPtr *)NULL; -#define ROOT spriteTrace[0] -static int spriteTraceSize = 0; -static int spriteTraceGood; - -typedef struct { - int x, y; - ScreenPtr pScreen; -} HotSpot; - -static struct { - CursorPtr current; - BoxRec hotLimits; /* logical constraints of hot spot */ - Bool confined; /* confined to screen */ -#if defined(SHAPE) || defined(PANORAMIX) - RegionPtr hotShape; /* additional logical shape constraint */ -#endif - BoxRec physLimits; /* physical constraints of hot spot */ - WindowPtr win; /* window of logical position */ - HotSpot hot; /* logical pointer position */ - HotSpot hotPhys; /* physical pointer position */ -#ifdef PANORAMIX - ScreenPtr screen; /* all others are in Screen 0 coordinates */ - RegionRec Reg1; /* Region 1 for confining motion */ - RegionRec Reg2; /* Region 2 for confining virtual motion */ - WindowPtr windows[MAXSCREENS]; - WindowPtr confineWin; /* confine window */ -#endif -} sprite; /* info about the cursor sprite */ - -static void DoEnterLeaveEvents( -#if NeedFunctionPrototypes - WindowPtr /*fromWin*/, - WindowPtr /*toWin*/, - int /*mode*/ -#endif -); - -static WindowPtr XYToWindow( -#if NeedFunctionPrototypes - int /*x*/, - int /*y*/ -#endif -); - -extern int lastEvent; - -static Mask lastEventMask; - -#ifdef XINPUT -extern int DeviceMotionNotify; -#endif - -#define CantBeFiltered NoEventMask -static Mask filters[128] = -{ - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ - EnterWindowMask, /* EnterNotify */ - LeaveWindowMask, /* LeaveNotify */ - FocusChangeMask, /* FocusIn */ - FocusChangeMask, /* FocusOut */ - KeymapStateMask, /* KeymapNotify */ - ExposureMask, /* Expose */ - CantBeFiltered, /* GraphicsExpose */ - CantBeFiltered, /* NoExpose */ - VisibilityChangeMask, /* VisibilityNotify */ - SubstructureNotifyMask, /* CreateNotify */ - StructureAndSubMask, /* DestroyNotify */ - StructureAndSubMask, /* UnmapNotify */ - StructureAndSubMask, /* MapNotify */ - SubstructureRedirectMask, /* MapRequest */ - StructureAndSubMask, /* ReparentNotify */ - StructureAndSubMask, /* ConfigureNotify */ - SubstructureRedirectMask, /* ConfigureRequest */ - StructureAndSubMask, /* GravityNotify */ - ResizeRedirectMask, /* ResizeRequest */ - StructureAndSubMask, /* CirculateNotify */ - SubstructureRedirectMask, /* CirculateRequest */ - PropertyChangeMask, /* PropertyNotify */ - CantBeFiltered, /* SelectionClear */ - CantBeFiltered, /* SelectionRequest */ - CantBeFiltered, /* SelectionNotify */ - ColormapChangeMask, /* ColormapNotify */ - CantBeFiltered, /* ClientMessage */ - CantBeFiltered /* MappingNotify */ -}; - -static CARD8 criticalEvents[32] = -{ - 0x7c /* key and button events */ -}; - -#ifdef PANORAMIX - -static void ConfineToShape(RegionPtr shape, int *px, int *py); -static void SyntheticMotion(int x, int y); -static void PostNewCursor(void); - -static Bool -XineramaSetCursorPosition( - int x, - int y, - Bool generateEvent -){ - ScreenPtr pScreen; - BoxRec box; - int i; - - /* x,y are in Screen 0 coordinates. We need to decide what Screen - to send the message too and what the coordinates relative to - that screen are. */ - - pScreen = sprite.screen; - x += panoramiXdataPtr[0].x; - y += panoramiXdataPtr[0].y; - - if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum], - x, y, &box)) - { - FOR_NSCREENS(i) - { - if(i == pScreen->myNum) - continue; - if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i], x, y, &box)) - { - pScreen = screenInfo.screens[i]; - break; - } - } - } - - sprite.screen = pScreen; - sprite.hotPhys.x = x - panoramiXdataPtr[0].x; - sprite.hotPhys.y = y - panoramiXdataPtr[0].y; - x -= panoramiXdataPtr[pScreen->myNum].x; - y -= panoramiXdataPtr[pScreen->myNum].y; - - return (*pScreen->SetCursorPosition)(pScreen, x, y, generateEvent); -} - - -static void -XineramaConstrainCursor(void) -{ - ScreenPtr pScreen = sprite.screen; - BoxRec newBox = sprite.physLimits; - - /* Translate the constraining box to the screen - the sprite is actually on */ - newBox.x1 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.x2 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.y1 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - newBox.y2 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - - (* pScreen->ConstrainCursor)(pScreen, &newBox); -} - -static void -XineramaCheckPhysLimits( - CursorPtr cursor, - Bool generateEvents -){ - HotSpot new; - - if (!cursor) - return; - - new = sprite.hotPhys; - - /* I don't care what the DDX has to say about it */ - sprite.physLimits = sprite.hotLimits; - - /* constrain the pointer to those limits */ - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) /* more work if the shape is a mess */ - ConfineToShape(sprite.hotShape, &new.x, &new.y); - - if((new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - XineramaSetCursorPosition (new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } - - /* Tell DDX what the limits are */ - XineramaConstrainCursor(); -} - - -static Bool -XineramaSetWindowPntrs(WindowPtr pWin) -{ - if(pWin == WindowTable[0]) { - memcpy(sprite.windows, WindowTable, - PanoramiXNumScreens*sizeof(WindowPtr)); - } else { - PanoramiXRes *win; - int i; - - win = (PanoramiXRes*)LookupIDByType(pWin->drawable.id, XRT_WINDOW); - - if(!win) - return FALSE; - - for(i = 0; i < PanoramiXNumScreens; i++) { - sprite.windows[i] = LookupIDByType(win->info[i].id, RT_WINDOW); - if(!sprite.windows[i]) /* window is being unmapped */ - return FALSE; - } - } - return TRUE; -} - -static void -XineramaCheckVirtualMotion( - QdEventPtr qe, - WindowPtr pWin -){ - - if (qe) - { - sprite.hot.pScreen = qe->pScreen; /* should always be Screen 0 */ - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - int x, y, off_x, off_y, i; - BoxRec lims; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg2, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg2, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg2, &sprite.Reg2, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - lims = *REGION_EXTENTS(sprite.screen, &sprite.Reg2); - - if (sprite.hot.x < lims.x1) - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) - sprite.hot.y = lims.y2 - 1; - - if (REGION_NUM_RECTS(&sprite.Reg2) > 1) - ConfineToShape(&sprite.Reg2, &sprite.hot.x, &sprite.hot.y); - - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } -} - - -static Bool -XineramaCheckMotion(xEvent *xE) -{ - WindowPtr prevSpriteWin = sprite.win; - - if (xE && !syncEvents.playingEvents) - { - /* Motion events entering DIX get translated to Screen 0 - coordinates. Replayed events have already been - translated since they've entered DIX before */ - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; - - sprite.hot.x = XE_KBPTR.rootX; - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) - sprite.hot.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); - - sprite.hotPhys = sprite.hot; - if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - (sprite.hotPhys.y != XE_KBPTR.rootY)) - { - XineramaSetCursorPosition( - sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - } - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); - - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - - -static void -XineramaConfineCursorToWindow(WindowPtr pWin, Bool generateEvents) -{ - - if (syncEvents.playingEvents) - { - XineramaCheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - int x, y, off_x, off_y, i; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg1, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg1, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg1, &sprite.Reg1, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - sprite.hotLimits = *REGION_EXTENTS(sprite.screen, &sprite.Reg1); - - if(REGION_NUM_RECTS(&sprite.Reg1) > 1) - sprite.hotShape = &sprite.Reg1; - else - sprite.hotShape = NullRegion; - - sprite.confined = FALSE; - sprite.confineWin = (pWin == WindowTable[0]) ? NullWindow : pWin; - - XineramaCheckPhysLimits(sprite.current, generateEvents); - } -} - - -static void -XineramaChangeToCursor(CursorPtr cursor) -{ - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - XineramaCheckPhysLimits(cursor, FALSE); - (*sprite.screen->DisplayCursor)(sprite.screen, cursor); - sprite.current = cursor; - } -} - - -#endif /* PANORAMIX */ - -void -SetMaskForEvent(mask, event) - Mask mask; - int event; -{ - if ((event < LASTEvent) || (event >= 128)) - FatalError("SetMaskForEvent: bogus event number"); - filters[event] = mask; -} - -void -SetCriticalEvent(event) - int event; -{ - if (event >= 128) - FatalError("SetCriticalEvent: bogus event number"); - criticalEvents[event >> 3] |= 1 << (event & 7); -} - -static void -#if NeedFunctionPrototypes -SyntheticMotion(int x, int y) -#else -SyntheticMotion(x, y) - int x, y; -#endif -{ - xEvent xE; - -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - x += panoramiXdataPtr[0].x - panoramiXdataPtr[sprite.screen->myNum].x; - y += panoramiXdataPtr[0].y - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; - if (syncEvents.playingEvents) - xE.u.keyButtonPointer.time = syncEvents.time.milliseconds; - else - xE.u.keyButtonPointer.time = currentTime.milliseconds; - xE.u.u.type = MotionNotify; - (*inputInfo.pointer->public.processInputProc)(&xE, inputInfo.pointer, 1); -} - -#ifdef SHAPE -static void -#if NeedFunctionPrototypes -ConfineToShape(RegionPtr shape, int *px, int *py) -#else -ConfineToShape(shape, px, py) - RegionPtr shape; - int *px, *py; -#endif -{ - BoxRec box; - int x = *px, y = *py; - int incx = 1, incy = 1; - - if (POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)) - return; - box = *REGION_EXTENTS(sprite.hot.pScreen, shape); - /* this is rather crude */ - do { - x += incx; - if (x >= box.x2) - { - incx = -1; - x = *px - 1; - } - else if (x < box.x1) - { - incx = 1; - x = *px; - y += incy; - if (y >= box.y2) - { - incy = -1; - y = *py - 1; - } - else if (y < box.y1) - return; /* should never get here! */ - } - } while (!POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)); - *px = x; - *py = y; -} -#endif - -static void -#if NeedFunctionPrototypes -CheckPhysLimits( - CursorPtr cursor, - Bool generateEvents, - Bool confineToScreen, - ScreenPtr pScreen) -#else -CheckPhysLimits(cursor, generateEvents, confineToScreen, pScreen) - CursorPtr cursor; - Bool generateEvents; - Bool confineToScreen; - ScreenPtr pScreen; -#endif -{ - HotSpot new; - - if (!cursor) - return; - new = sprite.hotPhys; - if (pScreen) - new.pScreen = pScreen; - else - pScreen = new.pScreen; - (*pScreen->CursorLimits) (pScreen, cursor, &sprite.hotLimits, - &sprite.physLimits); - sprite.confined = confineToScreen; - (* pScreen->ConstrainCursor)(pScreen, &sprite.physLimits); - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &new.x, &new.y); -#endif - if ((pScreen != sprite.hotPhys.pScreen) || - (new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - if (pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys = new; - (*pScreen->SetCursorPosition) (pScreen, new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } -} - -static void -#if NeedFunctionPrototypes -CheckVirtualMotion( - register QdEventPtr qe, - register WindowPtr pWin) -#else -CheckVirtualMotion(qe, pWin) - register QdEventPtr qe; - register WindowPtr pWin; -#endif -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaCheckVirtualMotion(qe, pWin); - return; - } -#endif - if (qe) - { - sprite.hot.pScreen = qe->pScreen; - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - BoxRec lims; - - if (sprite.hot.pScreen != pWin->drawable.pScreen) - { - sprite.hot.pScreen = pWin->drawable.pScreen; - sprite.hot.x = sprite.hot.y = 0; - } - lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize); - if (sprite.hot.x < lims.x1) - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) - sprite.hot.y = lims.y2 - 1; -#ifdef SHAPE - if (wBoundingShape(pWin)) - ConfineToShape(&pWin->borderSize, &sprite.hot.x, &sprite.hot.y); -#endif - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } - ROOT = WindowTable[sprite.hot.pScreen->myNum]; -} - -static void -ConfineCursorToWindow(WindowPtr pWin, Bool generateEvents, Bool confineToScreen) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaConfineCursorToWindow(pWin, generateEvents); - return; - } -#endif - - if (syncEvents.playingEvents) - { - CheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - sprite.hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize); -#ifdef SHAPE - sprite.hotShape = wBoundingShape(pWin) ? &pWin->borderSize - : NullRegion; -#endif - CheckPhysLimits(sprite.current, generateEvents, confineToScreen, - pScreen); - } -} - -Bool -PointerConfinedToScreen() -{ - return sprite.confined; -} - -static void -#if NeedFunctionPrototypes -ChangeToCursor(CursorPtr cursor) -#else -ChangeToCursor(cursor) - CursorPtr cursor; -#endif -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaChangeToCursor(cursor); - return; - } -#endif - - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - CheckPhysLimits(cursor, FALSE, sprite.confined, - (ScreenPtr)NULL); - (*sprite.hotPhys.pScreen->DisplayCursor) (sprite.hotPhys.pScreen, - cursor); - sprite.current = cursor; - } -} - -/* returns true if b is a descendent of a */ -Bool -IsParent(a, b) - register WindowPtr a, b; -{ - for (b = b->parent; b; b = b->parent) - if (b == a) return TRUE; - return FALSE; -} - -static void -#if NeedFunctionPrototypes -PostNewCursor(void) -#else -PostNewCursor() -#endif -{ - register WindowPtr win; - register GrabPtr grab = inputInfo.pointer->grab; - - if (syncEvents.playingEvents) - return; - if (grab) - { - if (grab->cursor) - { - ChangeToCursor(grab->cursor); - return; - } - if (IsParent(grab->window, sprite.win)) - win = sprite.win; - else - win = grab->window; - } - else - win = sprite.win; - for (; win; win = win->parent) - if (win->optional && win->optional->cursor != NullCursor) - { - ChangeToCursor(win->optional->cursor); - return; - } -} - -WindowPtr -GetCurrentRootWindow() -{ - return ROOT; -} - -WindowPtr -GetSpriteWindow() -{ - return sprite.win; -} - -CursorPtr -GetSpriteCursor() -{ - return sprite.current; -} - -void -GetSpritePosition(px, py) - int *px, *py; -{ - *px = sprite.hotPhys.x; - *py = sprite.hotPhys.y; -} - -#ifdef PANORAMIX -int -XineramaGetCursorScreen() -{ - if(!noPanoramiXExtension) { - return sprite.screen->myNum; - } else { - return 0; - } -} -#endif /* PANORAMIX */ - -#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */ - -static void -#if NeedFunctionPrototypes -MonthChangedOrBadTime(register xEvent *xE) -#else -MonthChangedOrBadTime(xE) - register xEvent *xE; -#endif -{ - /* If the ddx/OS is careless about not processing timestamped events from - * different sources in sorted order, then it's possible for time to go - * backwards when it should not. Here we ensure a decent time. - */ - if ((currentTime.milliseconds - XE_KBPTR.time) > TIMESLOP) - currentTime.months++; - else - XE_KBPTR.time = currentTime.milliseconds; -} - -#define NoticeTime(xE) { \ - if ((xE)->u.keyButtonPointer.time < currentTime.milliseconds) \ - MonthChangedOrBadTime(xE); \ - currentTime.milliseconds = (xE)->u.keyButtonPointer.time; \ - lastDeviceEventTime = currentTime; } - -void -NoticeEventTime(xE) - register xEvent *xE; -{ - if (!syncEvents.playingEvents) - NoticeTime(xE); -} - -/************************************************************************** - * The following procedures deal with synchronous events * - **************************************************************************/ - -void -EnqueueEvent(xE, device, count) - xEvent *xE; - DeviceIntPtr device; - int count; -{ - register QdEventPtr tail = *syncEvents.pendtail; - register QdEventPtr qe; - xEvent *qxE; - - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* The RECORD spec says that the root window field of motion events - * must be valid. At this point, it hasn't been filled in yet, so - * we do it here. The long expression below is necessary to get - * the current root window; the apparently reasonable alternative - * GetCurrentRootWindow()->drawable.id doesn't give you the right - * answer on the first motion event after a screen change because - * the data that GetCurrentRootWindow relies on hasn't been - * updated yet. - */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - if (xE->u.u.type == MotionNotify) - { -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; - } -#endif - sprite.hotPhys.x = XE_KBPTR.rootX; - sprite.hotPhys.y = XE_KBPTR.rootY; - /* do motion compression */ - if (tail && - (tail->event->u.u.type == MotionNotify) && - (tail->pScreen == sprite.hotPhys.pScreen)) - { - tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x; - tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y; - tail->event->u.keyButtonPointer.time = XE_KBPTR.time; - tail->months = currentTime.months; - return; - } - } - qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + (count * sizeof(xEvent))); - if (!qe) - return; - qe->next = (QdEventPtr)NULL; - qe->device = device; - qe->pScreen = sprite.hotPhys.pScreen; - qe->months = currentTime.months; - qe->event = (xEvent *)(qe + 1); - qe->evcount = count; - for (qxE = qe->event; --count >= 0; qxE++, xE++) - *qxE = *xE; - if (tail) - syncEvents.pendtail = &tail->next; - *syncEvents.pendtail = qe; -} - -static void -#if NeedFunctionPrototypes -PlayReleasedEvents(void) -#else -PlayReleasedEvents() -#endif -{ - register QdEventPtr *prev, qe; - register DeviceIntPtr dev; - - prev = &syncEvents.pending; - while ( (qe = *prev) ) - { - if (!qe->device->sync.frozen) - { - *prev = qe->next; - if (*syncEvents.pendtail == *prev) - syncEvents.pendtail = prev; - if (qe->event->u.u.type == MotionNotify) - CheckVirtualMotion(qe, NullWindow); - syncEvents.time.months = qe->months; - syncEvents.time.milliseconds = qe->event->u.keyButtonPointer.time; -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - qe->event->u.keyButtonPointer.rootX += - panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x; - qe->event->u.keyButtonPointer.rootY += - panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - (*qe->device->public.processInputProc)(qe->event, qe->device, - qe->evcount); - xfree(qe); - for (dev = inputInfo.devices; dev && dev->sync.frozen; dev = dev->next) - ; - if (!dev) - break; - /* Playing the event may have unfrozen another device. */ - /* So to play it safe, restart at the head of the queue */ - prev = &syncEvents.pending; - } - else - prev = &qe->next; - } -} - -static void -#if NeedFunctionPrototypes -FreezeThaw(register DeviceIntPtr dev, Bool frozen) -#else -FreezeThaw(dev, frozen) - register DeviceIntPtr dev; - Bool frozen; -#endif -{ - dev->sync.frozen = frozen; - if (frozen) - dev->public.processInputProc = dev->public.enqueueInputProc; - else - dev->public.processInputProc = dev->public.realInputProc; -} - -void -ComputeFreezes() -{ - register DeviceIntPtr replayDev = syncEvents.replayDev; - register int i; - WindowPtr w; - register xEvent *xE; - int count; - GrabPtr grab; - register DeviceIntPtr dev; - - for (dev = inputInfo.devices; dev; dev = dev->next) - FreezeThaw(dev, dev->sync.other || (dev->sync.state >= FROZEN)); - if (syncEvents.playingEvents || (!replayDev && !syncEvents.pending)) - return; - syncEvents.playingEvents = TRUE; - if (replayDev) - { - xE = replayDev->sync.event; - count = replayDev->sync.evcount; - syncEvents.replayDev = (DeviceIntPtr)NULL; - - w = XYToWindow( XE_KBPTR.rootX, XE_KBPTR.rootY); - for (i = 0; i < spriteTraceGood; i++) - { - if (syncEvents.replayWin == spriteTrace[i]) - { - if (!CheckDeviceGrabs(replayDev, xE, i+1, count)) { - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, - replayDev, count); - } - goto playmore; - } - } - /* must not still be in the same stack */ - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, replayDev, count); - } -playmore: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!dev->sync.frozen) - { - PlayReleasedEvents(); - break; - } - } - syncEvents.playingEvents = FALSE; - /* the following may have been skipped during replay, so do it now */ - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); - PostNewCursor(); -} - -#ifdef RANDR -void -ScreenRestructured (ScreenPtr pScreen) -{ - GrabPtr grab; - - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); -} -#endif - -void -CheckGrabForSyncs(thisDev, thisMode, otherMode) - register DeviceIntPtr thisDev; - Bool thisMode, otherMode; -{ - register GrabPtr grab = thisDev->grab; - register DeviceIntPtr dev; - - if (thisMode == GrabModeSync) - thisDev->sync.state = FROZEN_NO_EVENT; - else - { /* free both if same client owns both */ - thisDev->sync.state = THAWED; - if (thisDev->sync.other && - (CLIENT_BITS(thisDev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - thisDev->sync.other = NullGrab; - } - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev != thisDev) - { - if (otherMode == GrabModeSync) - dev->sync.other = grab; - else - { /* free both if same client owns both */ - if (dev->sync.other && - (CLIENT_BITS(dev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - dev->sync.other = NullGrab; - } - } - } - ComputeFreezes(); -} - -void -ActivatePointerGrab(mouse, grab, time, autoGrab) - register GrabPtr grab; - register DeviceIntPtr mouse; - TimeStamp time; - Bool autoGrab; -{ - WindowPtr oldWin = (mouse->grab) ? mouse->grab->window - : sprite.win; - - if (grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, FALSE, TRUE); - } - DoEnterLeaveEvents(oldWin, grab->window, NotifyGrab); - mouse->valuator->motionHintWindow = NullWindow; - if (syncEvents.playingEvents) - mouse->grabTime = syncEvents.time; - else - mouse->grabTime = time; - if (grab->cursor) - grab->cursor->refcnt++; - mouse->activeGrab = *grab; - mouse->grab = &mouse->activeGrab; - mouse->fromPassiveGrab = autoGrab; - PostNewCursor(); - CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); - - #ifdef NXAGENT_SERVER - - /* - * If grab is synchronous, events are delivered to clients only if they send - * an AllowEvent request. If mode field in AllowEvent request is SyncPointer, the - * delivered event is saved in a queue and replayed later, when grab is released. - * We should export sync grab to X as async in order to avoid events to be - * queued twice, in the agent and in the X server. This solution have a drawback: - * replayed events are not delivered to that application that are not clients of - * the agent. - * A different solution could be to make the grab asynchronous in the agent and - * to export it as synchronous. But this seems to be less safe. - * - * To make internal grab asynchronous, change previous line as follows. - * - * if (nxagentOption(Rootless)) - * { - * CheckGrabForSyncs(mouse, GrabModeAsync, (Bool)grab->keyboardMode); - * } - * else - * { - * CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); - * } - */ - - if (nxagentOption(Rootless) == 1) - { - /* - * FIXME: We should use the correct value - * for the cursor. Temporarily we set it - * to None. - */ - - int resource = nxagentWaitForResource(NXGetCollectGrabPointerResource, - nxagentCollectGrabPointerPredicate); - - NXCollectGrabPointer(nxagentDisplay, resource, nxagentWindow(grab -> window), - 1, grab -> eventMask & PointerGrabMask, - GrabModeAsync, GrabModeAsync, (grab -> confineTo) ? - nxagentWindow(grab -> confineTo) : None, - None, CurrentTime); - } - - #endif -} - -void -DeactivatePointerGrab(mouse) - register DeviceIntPtr mouse; -{ - register GrabPtr grab = mouse->grab; - register DeviceIntPtr dev; - - mouse->valuator->motionHintWindow = NullWindow; - mouse->grab = NullGrab; - mouse->sync.state = NOT_GRABBED; - mouse->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoEnterLeaveEvents(grab->window, sprite.win, NotifyUngrab); - if (grab->confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - PostNewCursor(); - if (grab->cursor) - FreeCursor(grab->cursor, (Cursor)0); - ComputeFreezes(); - - #ifdef NXAGENT_SERVER - - if (nxagentOption(Rootless) == 1) - { - XUngrabPointer(nxagentDisplay, CurrentTime); - - if (sprite.win == ROOT) - { - mouse -> button -> state &= - ~(Button1Mask | Button2Mask | Button3Mask | - Button4Mask | Button5Mask); - } - } - - #endif -} - -void -ActivateKeyboardGrab(keybd, grab, time, passive) - register DeviceIntPtr keybd; - GrabPtr grab; - TimeStamp time; - Bool passive; -{ - WindowPtr oldWin; - - if (keybd->grab) - oldWin = keybd->grab->window; - else if (keybd->focus) - oldWin = keybd->focus->win; - else - oldWin = sprite.win; - if (oldWin == FollowKeyboardWin) - oldWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab); - if (syncEvents.playingEvents) - keybd->grabTime = syncEvents.time; - else - keybd->grabTime = time; - keybd->activeGrab = *grab; - keybd->grab = &keybd->activeGrab; - keybd->fromPassiveGrab = passive; - CheckGrabForSyncs(keybd, (Bool)grab->keyboardMode, (Bool)grab->pointerMode); -} - -void -DeactivateKeyboardGrab(keybd) - register DeviceIntPtr keybd; -{ - register GrabPtr grab = keybd->grab; - register DeviceIntPtr dev; - register WindowPtr focusWin = keybd->focus ? keybd->focus->win - : sprite.win; - - if (focusWin == FollowKeyboardWin) - focusWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - keybd->grab = NullGrab; - keybd->sync.state = NOT_GRABBED; - keybd->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab); - ComputeFreezes(); -} - -void -AllowSome(client, time, thisDev, newState) - ClientPtr client; - TimeStamp time; - register DeviceIntPtr thisDev; - int newState; -{ - Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced; - TimeStamp grabTime; - register DeviceIntPtr dev; - - thisGrabbed = thisDev->grab && SameClient(thisDev->grab, client); - thisSynced = FALSE; - otherGrabbed = FALSE; - othersFrozen = TRUE; - grabTime = thisDev->grabTime; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - { - if (!(thisGrabbed || otherGrabbed) || - (CompareTimeStamps(dev->grabTime, grabTime) == LATER)) - grabTime = dev->grabTime; - otherGrabbed = TRUE; - if (thisDev->sync.other == dev->grab) - thisSynced = TRUE; - if (dev->sync.state < FROZEN) - othersFrozen = FALSE; - } - else if (!dev->sync.other || !SameClient(dev->sync.other, client)) - othersFrozen = FALSE; - } - if (!((thisGrabbed && thisDev->sync.state >= FROZEN) || thisSynced)) - return; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, grabTime) == EARLIER)) - return; - switch (newState) - { - case THAWED: /* Async */ - if (thisGrabbed) - thisDev->sync.state = THAWED; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - break; - case FREEZE_NEXT_EVENT: /* Sync */ - if (thisGrabbed) - { - thisDev->sync.state = FREEZE_NEXT_EVENT; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - } - break; - case THAWED_BOTH: /* AsyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case FREEZE_BOTH_NEXT_EVENT: /* SyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = FREEZE_BOTH_NEXT_EVENT; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case NOT_GRABBED: /* Replay */ - if (thisGrabbed && thisDev->sync.state == FROZEN_WITH_EVENT) - { - if (thisSynced) - thisDev->sync.other = NullGrab; - syncEvents.replayDev = thisDev; - syncEvents.replayWin = thisDev->grab->window; - (*thisDev->DeactivateGrab)(thisDev); - syncEvents.replayDev = (DeviceIntPtr)NULL; - } - break; - case THAW_OTHERS: /* AsyncOthers */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - } -} - -int -ProcAllowEvents(client) - register ClientPtr client; -{ - TimeStamp time; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - REQUEST(xAllowEventsReq); - - REQUEST_SIZE_MATCH(xAllowEventsReq); - time = ClientTimeToServerTime(stuff->time); - switch (stuff->mode) - { - case ReplayPointer: - AllowSome(client, time, mouse, NOT_GRABBED); - break; - case SyncPointer: - AllowSome(client, time, mouse, FREEZE_NEXT_EVENT); - break; - case AsyncPointer: - AllowSome(client, time, mouse, THAWED); - break; - case ReplayKeyboard: - AllowSome(client, time, keybd, NOT_GRABBED); - break; - case SyncKeyboard: - AllowSome(client, time, keybd, FREEZE_NEXT_EVENT); - break; - case AsyncKeyboard: - AllowSome(client, time, keybd, THAWED); - break; - case SyncBoth: - AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT); - break; - case AsyncBoth: - AllowSome(client, time, keybd, THAWED_BOTH); - break; - default: - client->errorValue = stuff->mode; - return BadValue; - } - - /* - * This is not necessary if we export grab to X as asynchronous. - * - * if (nxagentOption(Rootless) && stuff -> mode != ReplayKeyboard && - * stuff -> mode != SyncKeyboard && stuff -> mode != AsyncKeyboard) - * { - * XAllowEvents(nxagentDisplay, stuff -> mode, CurrentTime); - * } - */ - - return Success; -} - -void -ReleaseActiveGrabs(client) - ClientPtr client; -{ - register DeviceIntPtr dev; - Bool done; - - /* XXX CloseDownClient should remove passive grabs before - * releasing active grabs. - */ - do { - done = TRUE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - { - (*dev->DeactivateGrab)(dev); - done = FALSE; - } - } - } while (!done); -} - -/************************************************************************** - * The following procedures deal with delivering events * - **************************************************************************/ - -int -TryClientEvents (client, pEvents, count, mask, filter, grab) - ClientPtr client; - GrabPtr grab; - xEvent *pEvents; - int count; - Mask mask, filter; -{ - int i; - int type; - -#ifdef DEBUG - if (debug_events) ErrorF( - "Event([%d, %d], mask=0x%x), client=%d", - pEvents->u.u.type, pEvents->u.u.detail, mask, client->index); -#endif - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) - return -1; /* don't send, but notify caller */ - type = pEvents->u.u.type; - if (type == MotionNotify) - { - if (mask & PointerMotionHintMask) - { - if (WID(inputInfo.pointer->valuator->motionHintWindow) == - pEvents->u.keyButtonPointer.event) - { -#ifdef DEBUG - if (debug_events) ErrorF("\n"); - fprintf(stderr,"motionHintWindow == keyButtonPointer.event\n"); -#endif - return 1; /* don't send, but pretend we did */ - } - pEvents->u.u.detail = NotifyHint; - } - else - { - pEvents->u.u.detail = NotifyNormal; - } - } -#ifdef XINPUT - else - { - if ((type == DeviceMotionNotify) && - MaybeSendDeviceMotionNotifyHint - ((deviceKeyButtonPointer*)pEvents, mask) != 0) - return 1; - } -#endif - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } - - if (BitIsOn(criticalEvents, type)) - { -#ifdef SMART_SCHEDULE - if (client->smart_priority < SMART_MAX_PRIORITY) - client->smart_priority++; -#endif - SetCriticalOutputPending(); - } - - WriteEventsToClient(client, count, pEvents); -#ifdef DEBUG - if (debug_events) ErrorF( " delivered\n"); -#endif - return 1; - } - else - { -#ifdef DEBUG - if (debug_events) ErrorF("\n"); -#endif - return 0; - } -} - -int -DeliverEventsToWindow(pWin, pEvents, count, filter, grab, mskidx) - register WindowPtr pWin; - GrabPtr grab; - xEvent *pEvents; - int count; - Mask filter; - int mskidx; -{ - int deliveries = 0, nondeliveries = 0; - int attempt; - register InputClients *other; - ClientPtr client = NullClient; - Mask deliveryMask = 0; /* If a grab occurs due to a button press, then - this mask is the mask of the grab. */ - int type = pEvents->u.u.type; - - /* CantBeFiltered means only window owner gets the event */ - if ((filter == CantBeFiltered) || !(type & EXTENSION_EVENT_BASE)) - { - /* if nobody ever wants to see this event, skip some work */ - if (filter != CantBeFiltered && - !((wOtherEventMasks(pWin)|pWin->eventMask) & filter)) - return 0; - if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = wClient(pWin); - deliveryMask = pWin->eventMask; - } else - nondeliveries--; - } - } - if (filter != CantBeFiltered) - { - if (type & EXTENSION_EVENT_BASE) - { - OtherInputMasks *inputMasks; - - inputMasks = wOtherInputMasks(pWin); - if (!inputMasks || - !(inputMasks->inputEvents[mskidx] & filter)) - return 0; - other = inputMasks->inputClients; - } - else - other = (InputClients *)wOtherClients(pWin); - for (; other; other = other->next) - { - if ( (attempt = TryClientEvents(rClient(other), pEvents, count, - other->mask[mskidx], filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = rClient(other); - deliveryMask = other->mask[mskidx]; - } else - nondeliveries--; - } - } - } - if ((type == ButtonPress) && deliveries && (!grab)) - { - GrabRec tempGrab; - - tempGrab.device = inputInfo.pointer; - tempGrab.resource = client->clientAsMask; - tempGrab.window = pWin; - tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE; - tempGrab.eventMask = deliveryMask; - tempGrab.keyboardMode = GrabModeAsync; - tempGrab.pointerMode = GrabModeAsync; - tempGrab.confineTo = NullWindow; - tempGrab.cursor = NullCursor; - (*inputInfo.pointer->ActivateGrab)(inputInfo.pointer, &tempGrab, - currentTime, TRUE); - } - else if ((type == MotionNotify) && deliveries) - inputInfo.pointer->valuator->motionHintWindow = pWin; -#ifdef XINPUT - else - { - if (((type == DeviceMotionNotify) || (type == DeviceButtonPress)) && - deliveries) - CheckDeviceGrabAndHintWindow (pWin, type, - (deviceKeyButtonPointer*) pEvents, - grab, client, deliveryMask); - } -#endif - if (deliveries) - return deliveries; - return nondeliveries; -} - -/* If the event goes to dontClient, don't send it and return 0. if - send works, return 1 or if send didn't work, return 2. - Only works for core events. -*/ - -#ifdef PANORAMIX -static int -XineramaTryClientEventsResult( - ClientPtr client, - GrabPtr grab, - Mask mask, - Mask filter -){ - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) return -1; - else return 1; - } - return 0; -} -#endif - -int -MaybeDeliverEventsToClient(pWin, pEvents, count, filter, dontClient) - register WindowPtr pWin; - xEvent *pEvents; - int count; - Mask filter; - ClientPtr dontClient; -{ - register OtherClients *other; - - - if (pWin->eventMask & filter) - { - if (wClient(pWin) == dontClient) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - wClient(pWin), NullGrab, pWin->eventMask, filter); -#endif - return TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, NullGrab); - } - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & filter) - { - if (SameClient(other, dontClient)) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - rClient(other), NullGrab, other->mask, filter); -#endif - return TryClientEvents(rClient(other), pEvents, count, - other->mask, filter, NullGrab); - } - } - return 2; -} - -static void -#if NeedFunctionPrototypes -FixUpEventFromWindow( - xEvent *xE, - WindowPtr pWin, - Window child, - Bool calcChild) -#else -FixUpEventFromWindow(xE, pWin, child, calcChild) - xEvent *xE; - WindowPtr pWin; - Window child; - Bool calcChild; -#endif -{ - if (calcChild) - { - WindowPtr w=spriteTrace[spriteTraceGood-1]; - /* If the search ends up past the root should the child field be - set to none or should the value in the argument be passed - through. It probably doesn't matter since everyone calls - this function with child == None anyway. */ - - while (w) - { - /* If the source window is same as event window, child should be - none. Don't bother going all all the way back to the root. */ - - if (w == pWin) - { - child = None; - break; - } - - if (w->parent == pWin) - { - child = w->drawable.id; - break; - } - w = w->parent; - } - } - XE_KBPTR.root = ROOT->drawable.id; - XE_KBPTR.event = pWin->drawable.id; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - XE_KBPTR.sameScreen = xTrue; - XE_KBPTR.child = child; - XE_KBPTR.eventX = - XE_KBPTR.rootX - pWin->drawable.x; - XE_KBPTR.eventY = - XE_KBPTR.rootY - pWin->drawable.y; - } - else - { - XE_KBPTR.sameScreen = xFalse; - XE_KBPTR.child = None; - XE_KBPTR.eventX = 0; - XE_KBPTR.eventY = 0; - } -} - -int -DeliverDeviceEvents(pWin, xE, grab, stopAt, dev, count) - register WindowPtr pWin, stopAt; - register xEvent *xE; - GrabPtr grab; - DeviceIntPtr dev; - int count; -{ - Window child = None; - int type = xE->u.u.type; - Mask filter = filters[type]; - int deliveries = 0; - - if (type & EXTENSION_EVENT_BASE) - { - register OtherInputMasks *inputMasks; - int mskidx = dev->id; - - inputMasks = wOtherInputMasks(pWin); - if (inputMasks && !(filter & inputMasks->deliverableEvents[mskidx])) - return 0; - while (pWin) - { - if (inputMasks && (inputMasks->inputEvents[mskidx] & filter)) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, mskidx); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (inputMasks && - (filter & inputMasks->dontPropagateMask[mskidx]))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - if (pWin) - inputMasks = wOtherInputMasks(pWin); - } - } - else - { - if (!(filter & pWin->deliverableEvents)) - return 0; - while (pWin) - { - if ((wOtherEventMasks(pWin)|pWin->eventMask) & filter) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, 0); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (filter & wDontPropagateMask(pWin))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - } - } - return 0; -} - -/* not useful for events that propagate up the tree or extension events */ -int -DeliverEvents(pWin, xE, count, otherParent) - register WindowPtr pWin, otherParent; - register xEvent *xE; - int count; -{ - Mask filter; - int deliveries; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return count; -#endif - - if (!count) - return 0; - filter = filters[xE->u.u.type]; - if ((filter & SubstructureNotifyMask) && (xE->u.u.type != CreateNotify)) - xE->u.destroyNotify.event = pWin->drawable.id; - if (filter != StructureAndSubMask) - return DeliverEventsToWindow(pWin, xE, count, filter, NullGrab, 0); - deliveries = DeliverEventsToWindow(pWin, xE, count, StructureNotifyMask, - NullGrab, 0); - if (pWin->parent) - { - xE->u.destroyNotify.event = pWin->parent->drawable.id; - deliveries += DeliverEventsToWindow(pWin->parent, xE, count, - SubstructureNotifyMask, NullGrab, - 0); - if (xE->u.u.type == ReparentNotify) - { - xE->u.destroyNotify.event = otherParent->drawable.id; - deliveries += DeliverEventsToWindow(otherParent, xE, count, - SubstructureNotifyMask, - NullGrab, 0); - } - } - return deliveries; -} - - -static Bool -PointInBorderSize(WindowPtr pWin, int x, int y) -{ - BoxRec box; - - if(POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderSize, x, y, &box)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(POINT_IN_REGION(sprite.screen, - &sprite.windows[i]->borderSize, - x + panoramiXdataPtr[0].x - panoramiXdataPtr[i].x, - y + panoramiXdataPtr[0].y - panoramiXdataPtr[i].y, - &box)) - return TRUE; - } - } -#endif - return FALSE; -} - -static WindowPtr -#if NeedFunctionPrototypes -XYToWindow(int x, int y) -#else -XYToWindow(x, y) - int x, y; -#endif -{ - register WindowPtr pWin; - - spriteTraceGood = 1; /* root window still there */ - - if (nxagentOption(Rootless)) - { - if (nxagentLastEnteredWindow == NULL) - { - return ROOT; - } - - pWin = ROOT->lastChild; - - while (pWin && pWin != ROOT->firstChild && pWin != nxagentLastEnteredWindow) - { - pWin = pWin->prevSib; - } - } - else - { - pWin = ROOT->firstChild; - } - - while (pWin) - { - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth(pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) -#endif - ) - { - if (spriteTraceGood >= spriteTraceSize) - { - spriteTraceSize += 10; - Must_have_memory = TRUE; /* XXX */ - spriteTrace = (WindowPtr *)xrealloc( - spriteTrace, spriteTraceSize*sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - spriteTrace[spriteTraceGood++] = pWin; - pWin = pWin->firstChild; - } - else - pWin = pWin->nextSib; - } - return spriteTrace[spriteTraceGood-1]; -} - -static Bool -#if NeedFunctionPrototypes -CheckMotion(xEvent *xE) -#else -CheckMotion(xE) - xEvent *xE; -#endif -{ - WindowPtr prevSpriteWin = sprite.win; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaCheckMotion(xE); -#endif - - if (xE && !syncEvents.playingEvents) - { - if (sprite.hot.pScreen != sprite.hotPhys.pScreen) - { - sprite.hot.pScreen = sprite.hotPhys.pScreen; - ROOT = WindowTable[sprite.hot.pScreen->myNum]; - } - sprite.hot.x = XE_KBPTR.rootX; - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) - sprite.hot.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); -#endif - sprite.hotPhys = sprite.hot; - - /* - * This code force cursor position to be inside the - * root window of the agent. We can't view a reason - * to do this and it interacts in an undesirable way - * with toggling fullscreen. - * - * if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - * (sprite.hotPhys.y != XE_KBPTR.rootY)) - * { - * (*sprite.hotPhys.pScreen->SetCursorPosition)( - * sprite.hotPhys.pScreen, - * sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - * } - */ - - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); -#ifdef notyet - if (!(sprite.win->deliverableEvents & - Motion_Filter(inputInfo.pointer->button)) - !syncEvents.playingEvents) - { - /* XXX Do PointerNonInterestBox here */ - } -#endif - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - -void -WindowsRestructured() -{ - (void) CheckMotion((xEvent *)NULL); -} - -void -DefineInitialRootWindow(win) - register WindowPtr win; -{ - register ScreenPtr pScreen = win->drawable.pScreen; - extern void nxagentInitViewportFrame(ScreenPtr, WindowPtr); - extern int nxagentShadowInit(ScreenPtr, WindowPtr); - - sprite.hotPhys.pScreen = pScreen; - sprite.hotPhys.x = pScreen->width / 2; - sprite.hotPhys.y = pScreen->height / 2; - sprite.hot = sprite.hotPhys; - sprite.hotLimits.x2 = pScreen->width; - sprite.hotLimits.y2 = pScreen->height; - sprite.win = win; - sprite.current = wCursor (win); - spriteTraceGood = 1; - ROOT = win; - (*pScreen->CursorLimits) ( - pScreen, sprite.current, &sprite.hotLimits, &sprite.physLimits); - sprite.confined = FALSE; - (*pScreen->ConstrainCursor) (pScreen, &sprite.physLimits); - (*pScreen->SetCursorPosition) (pScreen, sprite.hot.x, sprite.hot.y, FALSE); - (*pScreen->DisplayCursor) (pScreen, sprite.current); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotLimits.x1 = -panoramiXdataPtr[0].x; - sprite.hotLimits.y1 = -panoramiXdataPtr[0].y; - sprite.hotLimits.x2 = PanoramiXPixWidth - panoramiXdataPtr[0].x; - sprite.hotLimits.y2 = PanoramiXPixHeight - panoramiXdataPtr[0].y; - sprite.physLimits = sprite.hotLimits; - sprite.confineWin = NullWindow; - sprite.screen = pScreen; - /* gotta UNINIT these someplace */ - REGION_INIT(pScreen, &sprite.Reg1, NullBox, 1); - REGION_INIT(pScreen, &sprite.Reg2, NullBox, 1); - } -#endif - - nxagentInitViewportFrame(pScreen, win); - - if (nxagentOption(Shadow)) - { - if (nxagentShadowInit(pScreen, win) == -1) - { - GiveUp(0); - } - } -} - -/* - * This does not take any shortcuts, and even ignores its argument, since - * it does not happen very often, and one has to walk up the tree since - * this might be a newly instantiated cursor for an intermediate window - * between the one the pointer is in and the one that the last cursor was - * instantiated from. - */ -/*ARGSUSED*/ -void -WindowHasNewCursor(pWin) - WindowPtr pWin; -{ - PostNewCursor(); -} - -void -NewCurrentScreen(newScreen, x, y) - ScreenPtr newScreen; - int x,y; -{ - sprite.hotPhys.x = x; - sprite.hotPhys.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotPhys.x += panoramiXdataPtr[newScreen->myNum].x - - panoramiXdataPtr[0].x; - sprite.hotPhys.y += panoramiXdataPtr[newScreen->myNum].y - - panoramiXdataPtr[0].y; - if (newScreen != sprite.screen) { - sprite.screen = newScreen; - /* Make sure we tell the DDX to update its copy of the screen */ - if(sprite.confineWin) - XineramaConfineCursorToWindow(sprite.confineWin, TRUE); - else - XineramaConfineCursorToWindow(WindowTable[0], TRUE); - /* if the pointer wasn't confined, the DDX won't get - told of the pointer warp so we reposition it here */ - if(!syncEvents.playingEvents) - (*sprite.screen->SetCursorPosition)(sprite.screen, - sprite.hotPhys.x + panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x, - sprite.hotPhys.y + panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y, FALSE); - } - } else -#endif - if (newScreen != sprite.hotPhys.pScreen) - ConfineCursorToWindow(WindowTable[newScreen->myNum], TRUE, FALSE); -} - -#ifdef PANORAMIX - -static Bool -XineramaPointInWindowIsVisible( - WindowPtr pWin, - int x, - int y -) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - BoxRec box; - int i, xoff, yoff; - - if (!pWin->realized) return FALSE; - - if (POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) - return TRUE; - - if(!XineramaSetWindowPntrs(pWin)) return FALSE; - - xoff = x + panoramiXdataPtr[0].x; - yoff = y + panoramiXdataPtr[0].y; - - for(i = 1; i < PanoramiXNumScreens; i++) { - pWin = sprite.windows[i]; - pScreen = pWin->drawable.pScreen; - x = xoff - panoramiXdataPtr[i].x; - y = yoff - panoramiXdataPtr[i].y; - - if(POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) - return TRUE; - - } - - return FALSE; -} - -static int -XineramaWarpPointer(ClientPtr client) -{ - WindowPtr dest = NULL; - int x, y; - - REQUEST(xWarpPointerReq); - - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if(source == WindowTable[0]) { - winX -= panoramiXdataPtr[0].x; - winY -= panoramiXdataPtr[0].y; - } - if (x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !XineramaPointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) { - x = dest->drawable.x; - y = dest->drawable.y; - if(dest == WindowTable[0]) { - x -= panoramiXdataPtr[0].x; - y -= panoramiXdataPtr[0].y; - } - } - - x += stuff->dstX; - y += stuff->dstY; - - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); - - XineramaSetCursorPosition(x, y, TRUE); - - return Success; -} - -#endif - - -int -ProcWarpPointer(client) - ClientPtr client; -{ - WindowPtr dest = NULL; - int x, y; - ScreenPtr newScreen; - - REQUEST(xWarpPointerReq); - - REQUEST_SIZE_MATCH(xWarpPointerReq); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaWarpPointer(client); -#endif - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if (source->drawable.pScreen != sprite.hotPhys.pScreen || - x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !PointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) - { - x = dest->drawable.x; - y = dest->drawable.y; - newScreen = dest->drawable.pScreen; - } else - newScreen = sprite.hotPhys.pScreen; - - x += stuff->dstX; - y += stuff->dstY; - - if (x < 0) - x = 0; - else if (x >= newScreen->width) - x = newScreen->width - 1; - if (y < 0) - y = 0; - else if (y >= newScreen->height) - y = newScreen->height - 1; - - if (newScreen == sprite.hotPhys.pScreen) - { - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; -#if defined(SHAPE) - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); -#endif - (*newScreen->SetCursorPosition)(newScreen, x, y, TRUE); - } - else if (!PointerConfinedToScreen()) - { - NewCurrentScreen(newScreen, x, y); - } - return Success; -} - -static Bool -BorderSizeNotEmpty(WindowPtr pWin) -{ - if(REGION_NOTEMPTY(sprite.hotPhys.pScreen, &pWin->borderSize)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(REGION_NOTEMPTY(sprite.screen, &sprite.windows[i]->borderSize)) - return TRUE; - } - } -#endif - return FALSE; -} - -/* "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a - passive grab set on the window to be activated. */ - -static Bool -#if NeedFunctionPrototypes -CheckPassiveGrabsOnWindow( - WindowPtr pWin, - register DeviceIntPtr device, - register xEvent *xE, - int count) -#else -CheckPassiveGrabsOnWindow(pWin, device, xE, count) - WindowPtr pWin; - register DeviceIntPtr device; - register xEvent *xE; - int count; -#endif -{ - register GrabPtr grab = wPassiveGrabs(pWin); - GrabRec tempGrab; - register xEvent *dxE; - - if (!grab) - return FALSE; - tempGrab.window = pWin; - tempGrab.device = device; - tempGrab.type = xE->u.u.type; - tempGrab.detail.exact = xE->u.u.detail; - tempGrab.detail.pMask = NULL; - tempGrab.modifiersDetail.pMask = NULL; - for (; grab; grab = grab->next) - { -#ifdef XKB - DeviceIntPtr gdev; - XkbSrvInfoPtr xkbi; - - gdev= grab->modifierDevice; - xkbi= gdev->key->xkbInfo; -#endif - tempGrab.modifierDevice = grab->modifierDevice; - if (device == grab->modifierDevice && - (xE->u.u.type == KeyPress -#ifdef XINPUT - || xE->u.u.type == DeviceKeyPress -#endif - )) - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension?gdev->key->prev_state:xkbi->state.grab_mods); -#else - grab->modifierDevice->key->prev_state; -#endif - else - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension ? gdev->key->state : xkbi->state.grab_mods); -#else - grab->modifierDevice->key->state; -#endif - if (GrabMatchesSecond(&tempGrab, grab) && - (!grab->confineTo || - (grab->confineTo->realized && - BorderSizeNotEmpty(grab->confineTo)))) - { -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(wClient(pWin), device, FALSE)) - return FALSE; -#endif -#ifdef XKB - if (!noXkbExtension) { - XE_KBPTR.state &= 0x1f00; - XE_KBPTR.state |= - tempGrab.modifiersDetail.exact&(~0x1f00); - } -#endif - (*device->ActivateGrab)(device, grab, currentTime, TRUE); - - FixUpEventFromWindow(xE, grab->window, None, TRUE); - - (void) TryClientEvents(rClient(grab), xE, count, - filters[xE->u.u.type], - filters[xE->u.u.type], grab); - - if (device->sync.state == FROZEN_NO_EVENT) - { - if (device->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - device->sync.event = (xEvent *)xrealloc(device->sync.event, - count* - sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - device->sync.evcount = count; - for (dxE = device->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - device->sync.state = FROZEN_WITH_EVENT; - } - return TRUE; - } - } - return FALSE; -} - -/* -"CheckDeviceGrabs" handles both keyboard and pointer events that may cause -a passive grab to be activated. If the event is a keyboard event, the -ancestors of the focus window are traced down and tried to see if they have -any passive grabs to be activated. If the focus window itself is reached and -it's descendants contain they pointer, the ancestors of the window that the -pointer is in are then traced down starting at the focus window, otherwise no -grabs are activated. If the event is a pointer event, the ancestors of the -window that the pointer is in are traced down starting at the root until -CheckPassiveGrabs causes a passive grab to activate or all the windows are -tried. PRH -*/ - -Bool -CheckDeviceGrabs(device, xE, checkFirst, count) - register DeviceIntPtr device; - register xEvent *xE; - int checkFirst; - int count; -{ - register int i; - register WindowPtr pWin = NULL; - register FocusClassPtr focus = device->focus; - - if ((xE->u.u.type == ButtonPress -#ifdef XINPUT - || xE->u.u.type == DeviceButtonPress -#endif - ) && device->button->buttonsDown != 1) - return FALSE; - - i = checkFirst; - - if (focus) - { - for (; i < focus->traceGood; i++) - { - pWin = focus->trace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - if ((focus->win == NoneWin) || - (i >= spriteTraceGood) || - ((i > checkFirst) && (pWin != spriteTrace[i-1]))) - return FALSE; - } - - for (; i < spriteTraceGood; i++) - { - pWin = spriteTrace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - return FALSE; -} - -void -DeliverFocusedEvent(keybd, xE, window, count) - xEvent *xE; - DeviceIntPtr keybd; - WindowPtr window; - int count; -{ - WindowPtr focus = keybd->focus->win; - int mskidx = 0; - - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - if (!focus) - return; - if (focus == PointerRootWin) - { - DeliverDeviceEvents(window, xE, NullGrab, NullWindow, keybd, count); - return; - } - if ((focus == window) || IsParent(focus, window)) - { - if (DeliverDeviceEvents(window, xE, NullGrab, focus, keybd, count)) - return; - } - /* just deliver it to the focus window */ - FixUpEventFromWindow(xE, focus, None, FALSE); - if (xE->u.u.type & EXTENSION_EVENT_BASE) - mskidx = keybd->id; - (void)DeliverEventsToWindow(focus, xE, count, filters[xE->u.u.type], - NullGrab, mskidx); -} - -void -DeliverGrabbedEvent(xE, thisDev, deactivateGrab, count) - register xEvent *xE; - register DeviceIntPtr thisDev; - Bool deactivateGrab; - int count; -{ - register GrabPtr grab = thisDev->grab; - int deliveries = 0; - register DeviceIntPtr dev; - register xEvent *dxE; - - if (grab->ownerEvents) - { - WindowPtr focus; - - if (thisDev->focus) - { - focus = thisDev->focus->win; - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - } - else - focus = PointerRootWin; - if (focus == PointerRootWin) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, NullWindow, - thisDev, count); - else if (focus && (focus == sprite.win || IsParent(focus, sprite.win))) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, focus, - thisDev, count); - else if (focus) - deliveries = DeliverDeviceEvents(focus, xE, grab, focus, - thisDev, count); - } - if (!deliveries) - { - FixUpEventFromWindow(xE, grab->window, None, TRUE); - deliveries = TryClientEvents(rClient(grab), xE, count, - (Mask)grab->eventMask, - filters[xE->u.u.type], grab); - if (deliveries && (xE->u.u.type == MotionNotify -#ifdef XINPUT - || xE->u.u.type == DeviceMotionNotify -#endif - )) - thisDev->valuator->motionHintWindow = grab->window; - } - if (deliveries && !deactivateGrab && (xE->u.u.type != MotionNotify -#ifdef XINPUT - && xE->u.u.type != DeviceMotionNotify -#endif - )) - switch (thisDev->sync.state) - { - case FREEZE_BOTH_NEXT_EVENT: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - FreezeThaw(dev, TRUE); - if ((dev->sync.state == FREEZE_BOTH_NEXT_EVENT) && - (CLIENT_BITS(dev->grab->resource) == - CLIENT_BITS(thisDev->grab->resource))) - dev->sync.state = FROZEN_NO_EVENT; - else - dev->sync.other = thisDev->grab; - } - /* fall through */ - case FREEZE_NEXT_EVENT: - thisDev->sync.state = FROZEN_WITH_EVENT; - FreezeThaw(thisDev, TRUE); - if (thisDev->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - thisDev->sync.event = (xEvent *)xrealloc(thisDev->sync.event, - count*sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - thisDev->sync.evcount = count; - for (dxE = thisDev->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - break; - } -} - -void -#ifdef XKB -CoreProcessKeyboardEvent (xE, keybd, count) -#else -ProcessKeyboardEvent (xE, keybd, count) -#endif - register xEvent *xE; - register DeviceIntPtr keybd; - int count; -{ - int key, bit; - register BYTE *kptr; - register int i; - register CARD8 modifiers; - register CARD16 mask; - GrabPtr grab = keybd->grab; - Bool deactivateGrab = FALSE; - register KeyClassPtr keyc = keybd->key; - - if (!syncEvents.playingEvents) - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } - XE_KBPTR.state = (keyc->state | inputInfo.pointer->button->state); - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - modifiers = keyc->modifierMap[key]; -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("CoreProcessKbdEvent: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - if (*kptr & bit) /* allow ddx to generate multiple downs */ - { - if (!modifiers) - { - xE->u.u.type = KeyRelease; - (*keybd->public.processInputProc)(xE, keybd, count); - xE->u.u.type = KeyPress; - /* release can have side effects, don't fall through */ - (*keybd->public.processInputProc)(xE, keybd, count); - } - return; - } - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr |= bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) - { - /* This key affects modifier "i" */ - keyc->modifierKeyCount[i]++; - keyc->state |= mask; - modifiers &= ~mask; - } - } - if (!grab && CheckDeviceGrabs(keybd, xE, 0, count)) - { - keybd->activatingKey = key; - return; - } - break; - case KeyRelease: - if (!(*kptr & bit)) /* guard against duplicates */ - return; - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr &= ~bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) { - /* This key affects modifier "i" */ - if (--keyc->modifierKeyCount[i] <= 0) { - keyc->state &= ~mask; - keyc->modifierKeyCount[i] = 0; - } - modifiers &= ~mask; - } - } - if (keybd->fromPassiveGrab && (key == keybd->activatingKey)) - deactivateGrab = TRUE; - break; - default: - FatalError("Impossible keyboard event"); - } - if (grab) - DeliverGrabbedEvent(xE, keybd, deactivateGrab, count); - else - DeliverFocusedEvent(keybd, xE, sprite.win, count); - if (deactivateGrab) - (*keybd->DeactivateGrab)(keybd); -} - -#ifdef XKB -/* This function is used to set the key pressed or key released state - - this is only used when the pressing of keys does not cause - CoreProcessKeyEvent to be called, as in for example Mouse Keys. -*/ -void -FixKeyState (xE, keybd) - register xEvent *xE; - register DeviceIntPtr keybd; -{ - int key, bit; - register BYTE *kptr; - register KeyClassPtr keyc = keybd->key; - - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("FixKeyState: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - *kptr |= bit; - break; - case KeyRelease: - *kptr &= ~bit; - break; - default: - FatalError("Impossible keyboard event"); - } -} -#endif - -void -#ifdef XKB -CoreProcessPointerEvent (xE, mouse, count) -#else -ProcessPointerEvent (xE, mouse, count) -#endif - register xEvent *xE; - register DeviceIntPtr mouse; - int count; -{ - register GrabPtr grab = mouse->grab; - Bool deactivateGrab = FALSE; - register ButtonClassPtr butc = mouse->button; -#ifdef XKB - XkbSrvInfoPtr xkbi; - - xkbi = inputInfo.keyboard->key->xkbInfo; -#endif - - if (!syncEvents.playingEvents) - NoticeTime(xE) - XE_KBPTR.state = (butc->state | ( -#ifdef XKB - (noXkbExtension ? - inputInfo.keyboard->key->state : - xkbi->state.grab_mods) -#else - inputInfo.keyboard->key->state -#endif - )); - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* see comment in EnqueueEvents regarding the next three lines */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } - if (xE->u.u.type != MotionNotify) - { - register int key; - register BYTE *kptr; - int bit; - - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - - key = xE->u.u.detail; - kptr = &butc->down[key >> 3]; - bit = 1 << (key & 7); - switch (xE->u.u.type) - { - case ButtonPress: - mouse->valuator->motionHintWindow = NullWindow; - if (!(*kptr & bit)) - butc->buttonsDown++; - butc->motionMask = ButtonMotionMask; - *kptr |= bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - if (xE->u.u.detail == 0) - return; - if (xE->u.u.detail <= 5) - butc->state |= (Button1Mask >> 1) << xE->u.u.detail; - filters[MotionNotify] = Motion_Filter(butc); - if (!grab) - if (CheckDeviceGrabs(mouse, xE, 0, count)) - return; - break; - case ButtonRelease: - mouse->valuator->motionHintWindow = NullWindow; - if (*kptr & bit) - --butc->buttonsDown; - if (!butc->buttonsDown) - butc->motionMask = 0; - *kptr &= ~bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - if (xE->u.u.detail == 0) - return; - if (xE->u.u.detail <= 5) - butc->state &= ~((Button1Mask >> 1) << xE->u.u.detail); - filters[MotionNotify] = Motion_Filter(butc); - if (!butc->state && mouse->fromPassiveGrab) - deactivateGrab = TRUE; - break; - default: - FatalError("bogus pointer event from ddx"); - } - } - else if (!CheckMotion(xE)) - return; - if (grab) - DeliverGrabbedEvent(xE, mouse, deactivateGrab, count); - else - DeliverDeviceEvents(sprite.win, xE, NullGrab, NullWindow, - mouse, count); - if (deactivateGrab) - (*mouse->DeactivateGrab)(mouse); -} - -#define AtMostOneClient \ - (SubstructureRedirectMask | ResizeRedirectMask | ButtonPressMask) - -void -RecalculateDeliverableEvents(pWin) - register WindowPtr pWin; -{ - register OtherClients *others; - register WindowPtr pChild; - - pChild = pWin; - while (1) - { - if (pChild->optional) - { - pChild->optional->otherEventMasks = 0; - for (others = wOtherClients(pChild); others; others = others->next) - { - pChild->optional->otherEventMasks |= others->mask; - } - } - pChild->deliverableEvents = pChild->eventMask| - wOtherEventMasks(pChild); - if (pChild->parent) - pChild->deliverableEvents |= - (pChild->parent->deliverableEvents & - ~wDontPropagateMask(pChild) & PropagateMask); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -int -OtherClientGone(value, id) - pointer value; /* must conform to DeleteType */ - XID id; -{ - register OtherClientsPtr other, prev; - register WindowPtr pWin = (WindowPtr)value; - - prev = 0; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->resource == id) - { - if (prev) - prev->next = other->next; - else - { - if (!(pWin->optional->otherClients = other->next)) - CheckWindowOptionalNeed (pWin); - } - xfree(other); - RecalculateDeliverableEvents(pWin); - return(Success); - } - prev = other; - } - FatalError("client not on event list"); - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} - -int -EventSelectForWindow(pWin, client, mask) - register WindowPtr pWin; - register ClientPtr client; - Mask mask; -{ - Mask check; - OtherClients * others; - - if (mask & ~AllEventMasks) - { - client->errorValue = mask; - return BadValue; - } - check = (mask & AtMostOneClient); - if (check & (pWin->eventMask|wOtherEventMasks(pWin))) - { /* It is illegal for two different - clients to select on any of the - events for AtMostOneClient. However, - it is OK, for some client to - continue selecting on one of those - events. */ - if ((wClient(pWin) != client) && (check & pWin->eventMask)) - return BadAccess; - for (others = wOtherClients (pWin); others; others = others->next) - { - if (!SameClient(others, client) && (check & others->mask)) - return BadAccess; - } - } - if (wClient (pWin) == client) - { - check = pWin->eventMask; -#ifdef SGIMISC - pWin->eventMask = - (mask & ~SGIMiscSpecialDestroyMask) | (pWin->eventMask & SGIMiscSpecialDestroyMask); -#else - pWin->eventMask = mask; -#endif - } - else - { - for (others = wOtherClients (pWin); others; others = others->next) - { - if (SameClient(others, client)) - { - check = others->mask; -#ifdef SGIMISC - mask = (mask & ~SGIMiscSpecialDestroyMask) | (others->mask & SGIMiscSpecialDestroyMask); -#endif - if (mask == 0) - { - FreeResource(others->resource, RT_NONE); - return Success; - } - else - others->mask = mask; - goto maskSet; - } - } - check = 0; - if (!pWin->optional && !MakeWindowOptional (pWin)) - return BadAlloc; - others = (OtherClients *) xalloc(sizeof(OtherClients)); - if (!others) - return BadAlloc; - others->mask = mask; - others->resource = FakeClientID(client->index); - others->next = pWin->optional->otherClients; - pWin->optional->otherClients = others; - if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer)pWin)) - return BadAlloc; - } -maskSet: - if ((inputInfo.pointer->valuator->motionHintWindow == pWin) && - (mask & PointerMotionHintMask) && - !(check & PointerMotionHintMask) && - !inputInfo.pointer->grab) - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - RecalculateDeliverableEvents(pWin); - return Success; -} - -/*ARGSUSED*/ -int -EventSuppressForWindow(pWin, client, mask, checkOptional) - register WindowPtr pWin; - register ClientPtr client; - Mask mask; - Bool *checkOptional; -{ - register int i, free; - - if ((mask & ~PropagateMask) && !permitOldBugs) - { - client->errorValue = mask; - return BadValue; - } - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - if (!mask) - i = 0; - else - { - for (i = DNPMCOUNT, free = 0; --i > 0; ) - { - if (!DontPropagateRefCnts[i]) - free = i; - else if (mask == DontPropagateMasks[i]) - break; - } - if (!i && free) - { - i = free; - DontPropagateMasks[i] = mask; - } - } - if (i || !mask) - { - pWin->dontPropagate = i; - if (i) - DontPropagateRefCnts[i]++; - if (pWin->optional) - { - pWin->optional->dontPropagateMask = mask; - *checkOptional = TRUE; - } - } - else - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]++; - return BadAlloc; - } - pWin->dontPropagate = 0; - pWin->optional->dontPropagateMask = mask; - } - RecalculateDeliverableEvents(pWin); - return Success; -} - -static WindowPtr -#if NeedFunctionPrototypes -CommonAncestor( - register WindowPtr a, - register WindowPtr b) -#else -CommonAncestor(a, b) - register WindowPtr a, b; -#endif -{ - for (b = b->parent; b; b = b->parent) - if (IsParent(b, a)) return b; - return NullWindow; -} - -static void -#if NeedFunctionPrototypes -EnterLeaveEvent( - int type, - int mode, - int detail, - register WindowPtr pWin, - Window child) -#else -EnterLeaveEvent(type, mode, detail, pWin, child) - int type, mode, detail; - register WindowPtr pWin; - Window child; -#endif -{ - xEvent event; - register DeviceIntPtr keybd = inputInfo.keyboard; - WindowPtr focus; - register DeviceIntPtr mouse = inputInfo.pointer; - register GrabPtr grab = mouse->grab; - Mask mask; - - if ((pWin == mouse->valuator->motionHintWindow) && - (detail != NotifyInferior)) - mouse->valuator->motionHintWindow = NullWindow; - if (grab) - { - mask = (pWin == grab->window) ? grab->eventMask : 0; - if (grab->ownerEvents) - mask |= EventMaskForClient(pWin, rClient(grab)); - } - else - { - mask = pWin->eventMask | wOtherEventMasks(pWin); - } - if (mask & filters[type]) - { - event.u.u.type = type; - event.u.u.detail = detail; - event.u.enterLeave.time = currentTime.milliseconds; - event.u.enterLeave.rootX = sprite.hot.x; - event.u.enterLeave.rootY = sprite.hot.y; - /* Counts on the same initial structure of crossing & button events! */ - FixUpEventFromWindow(&event, pWin, None, FALSE); - /* Enter/Leave events always set child */ - event.u.enterLeave.child = child; - event.u.enterLeave.flags = event.u.keyButtonPointer.sameScreen ? - ELFlagSameScreen : 0; -#ifdef XKB - if (!noXkbExtension) { - event.u.enterLeave.state = mouse->button->state & 0x1f00; - event.u.enterLeave.state |= - XkbGrabStateFromRec(&keybd->key->xkbInfo->state); - } else -#endif - event.u.enterLeave.state = keybd->key->state | mouse->button->state; - event.u.enterLeave.mode = mode; - focus = keybd->focus->win; - if ((focus != NoneWin) && - ((pWin == focus) || (focus == PointerRootWin) || - IsParent(focus, pWin))) - event.u.enterLeave.flags |= ELFlagFocus; - if (grab) - (void)TryClientEvents(rClient(grab), &event, 1, mask, - filters[type], grab); - else - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], - NullGrab, 0); - } - if ((type == EnterNotify) && (mask & KeymapStateMask)) - { - xKeymapEvent ke; - -#ifdef XCSECURITY - ClientPtr client = grab ? rClient(grab) - : clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, keybd, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31); - ke.type = KeymapNotify; - if (grab) - (void)TryClientEvents(rClient(grab), (xEvent *)&ke, 1, mask, - KeymapStateMask, grab); - else - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - -static void -#if NeedFunctionPrototypes -EnterNotifies(WindowPtr ancestor, WindowPtr child, int mode, int detail) -#else -EnterNotifies(ancestor, child, mode, detail) - WindowPtr ancestor, child; - int mode, detail; -#endif -{ - WindowPtr parent = child->parent; - - if (ancestor == parent) - return; - EnterNotifies(ancestor, parent, mode, detail); - EnterLeaveEvent(EnterNotify, mode, detail, parent, child->drawable.id); -} - -static void -#if NeedFunctionPrototypes -LeaveNotifies(WindowPtr child, WindowPtr ancestor, int mode, int detail) -#else -LeaveNotifies(child, ancestor, mode, detail) - WindowPtr child, ancestor; - int detail, mode; -#endif -{ - register WindowPtr pWin; - - if (ancestor == child) - return; - for (pWin = child->parent; pWin != ancestor; pWin = pWin->parent) - { - EnterLeaveEvent(LeaveNotify, mode, detail, pWin, child->drawable.id); - child = pWin; - } -} - -static void -#if NeedFunctionPrototypes -DoEnterLeaveEvents(WindowPtr fromWin, WindowPtr toWin, int mode) -#else -DoEnterLeaveEvents(fromWin, toWin, mode) - WindowPtr fromWin, toWin; - int mode; -#endif -{ - if (fromWin == toWin) - return; - if (IsParent(fromWin, toWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyInferior, fromWin, None); - EnterNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyAncestor, toWin, None); - } - else if (IsParent(toWin, fromWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyAncestor, fromWin, None); - LeaveNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyInferior, toWin, None); - } - else - { /* neither fromWin nor toWin is descendent of the other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - EnterLeaveEvent(LeaveNotify, mode, NotifyNonlinear, fromWin, None); - LeaveNotifies(fromWin, common, mode, NotifyNonlinearVirtual); - EnterNotifies(common, toWin, mode, NotifyNonlinearVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyNonlinear, toWin, None); - } -} - -static void -#if NeedFunctionPrototypes -FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, register WindowPtr pWin) -#else -FocusEvent(dev, type, mode, detail, pWin) - DeviceIntPtr dev; - int type, mode, detail; - register WindowPtr pWin; -#endif -{ - xEvent event; - -#ifdef XINPUT - if (dev != inputInfo.keyboard) - { - DeviceFocusEvent(dev, type, mode, detail, pWin); - return; - } -#endif - event.u.focus.mode = mode; - event.u.u.type = type; - event.u.u.detail = detail; - event.u.focus.window = pWin->drawable.id; - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], NullGrab, - 0); - if ((type == FocusIn) && - ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) - { - xKeymapEvent ke; -#ifdef XCSECURITY - ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, dev, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31); - ke.type = KeymapNotify; - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - - /* - * recursive because it is easier - * no-op if child not descended from ancestor - */ -static Bool -#if NeedFunctionPrototypes -FocusInEvents( - DeviceIntPtr dev, - WindowPtr ancestor, WindowPtr child, WindowPtr skipChild, - int mode, int detail, - Bool doAncestor) -#else -FocusInEvents(dev, ancestor, child, skipChild, mode, detail, doAncestor) - DeviceIntPtr dev; - WindowPtr ancestor, child, skipChild; - int mode, detail; - Bool doAncestor; -#endif -{ - if (child == NullWindow) - return ancestor == NullWindow; - if (ancestor == child) - { - if (doAncestor) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - if (FocusInEvents(dev, ancestor, child->parent, skipChild, mode, detail, - doAncestor)) - { - if (child != skipChild) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - return FALSE; -} - -/* dies horribly if ancestor is not an ancestor of child */ -static void -#if NeedFunctionPrototypes -FocusOutEvents( - DeviceIntPtr dev, - WindowPtr child, WindowPtr ancestor, - int mode, int detail, - Bool doAncestor) -#else -FocusOutEvents(dev, child, ancestor, mode, detail, doAncestor) - DeviceIntPtr dev; - WindowPtr child, ancestor; - int mode; - int detail; - Bool doAncestor; -#endif -{ - register WindowPtr pWin; - - for (pWin = child; pWin != ancestor; pWin = pWin->parent) - FocusEvent(dev, FocusOut, mode, detail, pWin); - if (doAncestor) - FocusEvent(dev, FocusOut, mode, detail, ancestor); -} - -void -DoFocusEvents(dev, fromWin, toWin, mode) - DeviceIntPtr dev; - WindowPtr fromWin, toWin; - int mode; -{ - int out, in; /* for holding details for to/from - PointerRoot/None */ - int i; - - if (fromWin == toWin) - return; - out = (fromWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - in = (toWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - /* wrong values if neither, but then not referenced */ - - if ((toWin == NullWindow) || (toWin == PointerRootWin)) - { - if ((fromWin == NullWindow) || (fromWin == PointerRootWin)) - { - if (fromWin == PointerRootWin) - FocusOutEvents(dev, sprite.win, ROOT, mode, NotifyPointer, - TRUE); - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusOut, mode, out, WindowTable[0]); - else -#endif - for (i=0; iparent, NullWindow, mode, - NotifyNonlinearVirtual, FALSE); - } - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusIn, mode, in, WindowTable[0]); - else -#endif - for (i=0; iparent != NullWindow) - (void)FocusInEvents(dev, ROOT, toWin, toWin, mode, - NotifyNonlinearVirtual, TRUE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, mode, - NotifyPointer, FALSE); - } - else - { - if (IsParent(toWin, fromWin)) - { - FocusEvent(dev, FocusOut, mode, NotifyAncestor, fromWin); - FocusOutEvents(dev, fromWin->parent, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyInferior, toWin); - if ((IsParent(toWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(fromWin, sprite.win)) && - (!IsParent(sprite.win, fromWin))) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - else - if (IsParent(fromWin, toWin)) - { - if ((IsParent(fromWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(toWin, sprite.win)) && - (!IsParent(sprite.win, toWin))) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyInferior, fromWin); - (void)FocusInEvents(dev, fromWin, toWin, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyAncestor, toWin); - } - else - { - /* neither fromWin or toWin is child of other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - if (IsParent(fromWin, sprite.win)) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyNonlinear, fromWin); - if (fromWin->parent != NullWindow) - FocusOutEvents(dev, fromWin->parent, common, mode, - NotifyNonlinearVirtual, FALSE); - if (toWin->parent != NullWindow) - (void)FocusInEvents(dev, common, toWin, toWin, mode, - NotifyNonlinearVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - } - } -} - -int -#if NeedFunctionPrototypes -SetInputFocus( - ClientPtr client, - DeviceIntPtr dev, - Window focusID, - CARD8 revertTo, - Time ctime, - Bool followOK) -#else -SetInputFocus(client, dev, focusID, revertTo, ctime, followOK) - ClientPtr client; - DeviceIntPtr dev; - Window focusID; - CARD8 revertTo; - Time ctime; - Bool followOK; -#endif -{ - register FocusClassPtr focus; - register WindowPtr focusWin; - int mode; - TimeStamp time; - - UpdateCurrentTime(); - if ((revertTo != RevertToParent) && - (revertTo != RevertToPointerRoot) && - (revertTo != RevertToNone) && - ((revertTo != RevertToFollowKeyboard) || !followOK)) - { - client->errorValue = revertTo; - return BadValue; - } - time = ClientTimeToServerTime(ctime); - if ((focusID == None) || (focusID == PointerRoot)) - focusWin = (WindowPtr)(long)focusID; - else if ((focusID == FollowKeyboard) && followOK) - focusWin = inputInfo.keyboard->focus->win; - else if (!(focusWin = SecurityLookupWindow(focusID, client, - SecurityReadAccess))) - return BadWindow; - else - { - /* It is a match error to try to set the input focus to an - unviewable window. */ - - if(!focusWin->realized) - return(BadMatch); - } - focus = dev->focus; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, focus->time) == EARLIER)) - return Success; - mode = (dev->grab) ? NotifyWhileGrabbed : NotifyNormal; - if (focus->win == FollowKeyboardWin) - DoFocusEvents(dev, inputInfo.keyboard->focus->win, focusWin, mode); - else - DoFocusEvents(dev, focus->win, focusWin, mode); - focus->time = time; - focus->revert = revertTo; - if (focusID == FollowKeyboard) - focus->win = FollowKeyboardWin; - else - focus->win = focusWin; - if ((focusWin == NoneWin) || (focusWin == PointerRootWin)) - focus->traceGood = 0; - else - { - int depth = 0; - register WindowPtr pWin; - - for (pWin = focusWin; pWin; pWin = pWin->parent) depth++; - if (depth > focus->traceSize) - { - focus->traceSize = depth+1; - Must_have_memory = TRUE; /* XXX */ - focus->trace = (WindowPtr *)xrealloc(focus->trace, - focus->traceSize * - sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - focus->traceGood = depth; - for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) - focus->trace[depth] = pWin; - } - return Success; -} - -int -ProcSetInputFocus(client) - ClientPtr client; -{ - REQUEST(xSetInputFocusReq); - - REQUEST_SIZE_MATCH(xSetInputFocusReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - return Success; -#endif - return SetInputFocus(client, inputInfo.keyboard, stuff->focus, - stuff->revertTo, stuff->time, FALSE); -} - -int -ProcGetInputFocus(client) - ClientPtr client; -{ - xGetInputFocusReply rep; - /* REQUEST(xReq); */ - FocusClassPtr focus = inputInfo.keyboard->focus; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (focus->win == NoneWin) - rep.focus = None; - else if (focus->win == PointerRootWin) - rep.focus = PointerRoot; - else rep.focus = focus->win->drawable.id; - rep.revertTo = focus->revert; - WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep); - return Success; -} - -int -ProcGrabPointer(client) - ClientPtr client; -{ - xGrabPointerReply rep; - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - WindowPtr pWin, confineTo; - CursorPtr cursor, oldCursor; - REQUEST(xGrabPointerReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xGrabPointerReq); - UpdateCurrentTime(); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else - { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - /* at this point, some sort of reply is guaranteed. */ - time = ClientTimeToServerTime(stuff->time); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - grab = device->grab; - if ((grab) && !SameClient(grab, client)) - rep.status = AlreadyGrabbed; - else if ((!pWin->realized) || - (confineTo && - !(confineTo->realized && BorderSizeNotEmpty(confineTo)))) - rep.status = GrabNotViewable; - else if (device->sync.frozen && - device->sync.other && !SameClient(device->sync.other, client)) - rep.status = GrabFrozen; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - rep.status = GrabInvalidTime; - else - { - GrabRec tempGrab; - - oldCursor = NullCursor; - if (grab) - { - if (grab->confineTo && !confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - oldCursor = grab->cursor; - } - tempGrab.cursor = cursor; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = stuff->ownerEvents; - tempGrab.eventMask = stuff->eventMask; - tempGrab.confineTo = confineTo; - tempGrab.window = pWin; - tempGrab.keyboardMode = stuff->keyboardMode; - tempGrab.pointerMode = stuff->pointerMode; - tempGrab.device = device; - (*device->ActivateGrab)(device, &tempGrab, time, FALSE); - if (oldCursor) - FreeCursor (oldCursor, (Cursor)0); - rep.status = GrabSuccess; - } - WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep); - return Success; -} - -int -ProcChangeActivePointerGrab(client) - ClientPtr client; -{ - DeviceIntPtr device = inputInfo.pointer; - register GrabPtr grab = device->grab; - CursorPtr newCursor, oldCursor; - REQUEST(xChangeActivePointerGrabReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq); - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - if (stuff->cursor == None) - newCursor = NullCursor; - else - { - newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!newCursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - if (!grab) - return Success; - if (!SameClient(grab, client)) - return Success; - time = ClientTimeToServerTime(stuff->time); - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - return Success; - oldCursor = grab->cursor; - grab->cursor = newCursor; - if (newCursor) - newCursor->refcnt++; - PostNewCursor(); - if (oldCursor) - FreeCursor(oldCursor, (Cursor)0); - grab->eventMask = stuff->eventMask; - return Success; -} - -int -ProcUngrabPointer(client) - ClientPtr client; -{ - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->DeactivateGrab)(device); - return Success; -} - -int -GrabDevice(client, dev, this_mode, other_mode, grabWindow, ownerEvents, ctime, - mask, status) - register ClientPtr client; - register DeviceIntPtr dev; - unsigned this_mode; - unsigned other_mode; - Window grabWindow; - unsigned ownerEvents; - Time ctime; - Mask mask; - CARD8 *status; -{ - register WindowPtr pWin; - register GrabPtr grab; - TimeStamp time; - - UpdateCurrentTime(); - if ((this_mode != GrabModeSync) && (this_mode != GrabModeAsync)) - { - client->errorValue = this_mode; - return BadValue; - } - if ((other_mode != GrabModeSync) && (other_mode != GrabModeAsync)) - { - client->errorValue = other_mode; - return BadValue; - } - if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) - { - client->errorValue = ownerEvents; - return BadValue; - } - pWin = SecurityLookupWindow(grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - time = ClientTimeToServerTime(ctime); - grab = dev->grab; - if (grab && !SameClient(grab, client)) - *status = AlreadyGrabbed; - else if (!pWin->realized) - *status = GrabNotViewable; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, dev->grabTime) == EARLIER)) - *status = GrabInvalidTime; - else if (dev->sync.frozen && - dev->sync.other && !SameClient(dev->sync.other, client)) - *status = GrabFrozen; - else - { - GrabRec tempGrab; - - tempGrab.window = pWin; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = ownerEvents; - tempGrab.keyboardMode = this_mode; - tempGrab.pointerMode = other_mode; - tempGrab.eventMask = mask; - tempGrab.device = dev; - (*dev->ActivateGrab)(dev, &tempGrab, time, FALSE); - *status = GrabSuccess; - } - return Success; -} - -int -ProcGrabKeyboard(client) - ClientPtr client; -{ - xGrabKeyboardReply rep; - REQUEST(xGrabKeyboardReq); - int result; - - REQUEST_SIZE_MATCH(xGrabKeyboardReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - { - result = Success; - rep.status = AlreadyGrabbed; - } - else -#endif - result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode, - stuff->pointerMode, stuff->grabWindow, - stuff->ownerEvents, stuff->time, - KeyPressMask | KeyReleaseMask, &rep.status); - if (result != Success) - return result; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep); - return Success; -} - -int -ProcUngrabKeyboard(client) - ClientPtr client; -{ - DeviceIntPtr device = inputInfo.keyboard; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->DeactivateGrab)(device); - return Success; -} - -int -ProcQueryPointer(client) - ClientPtr client; -{ - xQueryPointerReply rep; - WindowPtr pWin, t; - REQUEST(xResourceReq); - DeviceIntPtr mouse = inputInfo.pointer; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = SecurityLookupWindow(stuff->id, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (mouse->valuator->motionHintWindow) - MaybeStopHint(mouse, client); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.mask = mouse->button->state | inputInfo.keyboard->key->state; - rep.length = 0; - rep.root = (ROOT)->drawable.id; - rep.rootX = sprite.hot.x; - rep.rootY = sprite.hot.y; - rep.child = None; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - rep.sameScreen = xTrue; - rep.winX = sprite.hot.x - pWin->drawable.x; - rep.winY = sprite.hot.y - pWin->drawable.y; - for (t = sprite.win; t; t = t->parent) - if (t->parent == pWin) - { - rep.child = t->drawable.id; - break; - } - } - else - { - rep.sameScreen = xFalse; - rep.winX = 0; - rep.winY = 0; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - rep.rootX += panoramiXdataPtr[0].x; - rep.rootY += panoramiXdataPtr[0].y; - if(stuff->id == rep.root) { - rep.winX += panoramiXdataPtr[0].x; - rep.winY += panoramiXdataPtr[0].y; - } - } -#endif - - WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep); - - return(Success); -} - -void -InitEvents() -{ - int i; - - sprite.hot.pScreen = sprite.hotPhys.pScreen = (ScreenPtr)NULL; - inputInfo.numDevices = 0; - inputInfo.devices = (DeviceIntPtr)NULL; - inputInfo.off_devices = (DeviceIntPtr)NULL; - inputInfo.keyboard = (DeviceIntPtr)NULL; - inputInfo.pointer = (DeviceIntPtr)NULL; - if (spriteTraceSize == 0) - { - spriteTraceSize = 32; - spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr)); - if (!spriteTrace) - FatalError("failed to allocate spriteTrace"); - } - spriteTraceGood = 0; - lastEventMask = OwnerGrabButtonMask; - filters[MotionNotify] = PointerMotionMask; - sprite.win = NullWindow; - sprite.current = NullCursor; - sprite.hotLimits.x1 = 0; - sprite.hotLimits.y1 = 0; - sprite.hotLimits.x2 = 0; - sprite.hotLimits.y2 = 0; - sprite.confined = FALSE; - syncEvents.replayDev = (DeviceIntPtr)NULL; - syncEvents.replayWin = NullWindow; - while (syncEvents.pending) - { - QdEventPtr next = syncEvents.pending->next; - xfree(syncEvents.pending); - syncEvents.pending = next; - } - syncEvents.pendtail = &syncEvents.pending; - syncEvents.playingEvents = FALSE; - syncEvents.time.months = 0; - syncEvents.time.milliseconds = 0; /* hardly matters */ - currentTime.months = 0; - currentTime.milliseconds = GetTimeInMillis(); - lastDeviceEventTime = currentTime; - for (i = 0; i < DNPMCOUNT; i++) - { - DontPropagateMasks[i] = 0; - DontPropagateRefCnts[i] = 0; - } -} - -void -CloseDownEvents(void) -{ - xfree(spriteTrace); - spriteTrace = NULL; - spriteTraceSize = 0; -} - -int -ProcSendEvent(client) - ClientPtr client; -{ - WindowPtr pWin; - WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */ - REQUEST(xSendEventReq); - - REQUEST_SIZE_MATCH(xSendEventReq); - - /* The client's event type must be a core event type or one defined by an - extension. */ - - -#ifdef NXAGENT_CLIPBOARD - - if (stuff -> event.u.u.type == SelectionNotify) - { - extern int nxagentSendNotify(xEvent*); - if (nxagentSendNotify(&stuff->event) == 1) - return Success; - } -#endif - - if ( ! ((stuff->event.u.u.type > X_Reply && - stuff->event.u.u.type < LASTEvent) || - (stuff->event.u.u.type >= EXTENSION_EVENT_BASE && - stuff->event.u.u.type < (unsigned)lastEvent))) - { - client->errorValue = stuff->event.u.u.type; - return BadValue; - } - if (stuff->event.u.u.type == ClientMessage && - stuff->event.u.u.detail != 8 && - stuff->event.u.u.detail != 16 && - stuff->event.u.u.detail != 32 && - !permitOldBugs) - { - client->errorValue = stuff->event.u.u.detail; - return BadValue; - } - if ((stuff->eventMask & ~AllEventMasks) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - - if (stuff->destination == PointerWindow) - pWin = sprite.win; - else if (stuff->destination == InputFocus) - { - WindowPtr inputFocus = inputInfo.keyboard->focus->win; - - if (inputFocus == NoneWin) - return Success; - - /* If the input focus is PointerRootWin, send the event to where - the pointer is if possible, then perhaps propogate up to root. */ - if (inputFocus == PointerRootWin) - inputFocus = ROOT; - - if (IsParent(inputFocus, sprite.win)) - { - effectiveFocus = inputFocus; - pWin = sprite.win; - } - else - effectiveFocus = pWin = inputFocus; - } - else - pWin = SecurityLookupWindow(stuff->destination, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue)) - { - client->errorValue = stuff->propagate; - return BadValue; - } - stuff->event.u.u.type |= 0x80; - if (stuff->propagate) - { - for (;pWin; pWin = pWin->parent) - { - if (DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0)) - return Success; - if (pWin == effectiveFocus) - return Success; - stuff->eventMask &= ~wDontPropagateMask(pWin); - if (!stuff->eventMask) - break; - } - } - else - (void)DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0); - return Success; -} - -int -ProcUngrabKey(client) - ClientPtr client; -{ - REQUEST(xUngrabKeyReq); - WindowPtr pWin; - GrabRec tempGrab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xUngrabKeyReq); - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - tempGrab.resource = client->clientAsMask; - tempGrab.device = keybd; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = KeyPress; - tempGrab.detail.exact = stuff->key; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -int -ProcGrabKey(client) - ClientPtr client; -{ - WindowPtr pWin; - REQUEST(xGrabKeyReq); - GrabPtr grab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xGrabKeyReq); - if ((stuff->ownerEvents != xTrue) && (stuff->ownerEvents != xFalse)) - { - client->errorValue = stuff->ownerEvents; - return(BadValue); - } - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - grab = CreateGrab(client->index, keybd, pWin, - (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents, - (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode, - keybd, stuff->modifiers, KeyPress, stuff->key, - NullWindow, NullCursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - - -int -ProcGrabButton(client) - ClientPtr client; -{ - WindowPtr pWin, confineTo; - REQUEST(xGrabButtonReq); - CursorPtr cursor; - GrabPtr grab; - - REQUEST_SIZE_MATCH(xGrabButtonReq); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - - - grab = CreateGrab(client->index, inputInfo.pointer, pWin, - permitOldBugs ? (Mask)(stuff->eventMask | - ButtonPressMask | ButtonReleaseMask) : - (Mask)stuff->eventMask, - (Bool)stuff->ownerEvents, (Bool) stuff->keyboardMode, - (Bool)stuff->pointerMode, inputInfo.keyboard, stuff->modifiers, - ButtonPress, stuff->button, confineTo, cursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - -int -ProcUngrabButton(client) - ClientPtr client; -{ - REQUEST(xUngrabButtonReq); - WindowPtr pWin; - GrabRec tempGrab; - - REQUEST_SIZE_MATCH(xUngrabButtonReq); - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - tempGrab.resource = client->clientAsMask; - tempGrab.device = inputInfo.pointer; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = ButtonPress; - tempGrab.detail.exact = stuff->button; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -void -DeleteWindowFromAnyEvents(pWin, freeResources) - WindowPtr pWin; - Bool freeResources; -{ - WindowPtr parent; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - FocusClassPtr focus = keybd->focus; - OtherClientsPtr oc; - GrabPtr passive; - - - /* Deactivate any grabs performed on this window, before making any - input focus changes. */ - - if (mouse->grab && - ((mouse->grab->window == pWin) || (mouse->grab->confineTo == pWin))) - (*mouse->DeactivateGrab)(mouse); - - /* Deactivating a keyboard grab should cause focus events. */ - - if (keybd->grab && (keybd->grab->window == pWin)) - (*keybd->DeactivateGrab)(keybd); - - /* If the focus window is a root window (ie. has no parent) then don't - delete the focus from it. */ - - if ((pWin == focus->win) && (pWin->parent != NullWindow)) - { - int focusEventMode = NotifyNormal; - - /* If a grab is in progress, then alter the mode of focus events. */ - - if (keybd->grab) - focusEventMode = NotifyWhileGrabbed; - - switch (focus->revert) - { - case RevertToNone: - DoFocusEvents(keybd, pWin, NoneWin, focusEventMode); - focus->win = NoneWin; - focus->traceGood = 0; - break; - case RevertToParent: - parent = pWin; - do - { - parent = parent->parent; - focus->traceGood--; - } while (!parent->realized -/* This would be a good protocol change -- windows being reparented - during SaveSet processing would cause the focus to revert to the - nearest enclosing window which will survive the death of the exiting - client, instead of ending up reverting to a dying window and thence - to None - */ -#ifdef NOTDEF - || clients[CLIENT_ID(parent->drawable.id)]->clientGone -#endif - ); - DoFocusEvents(keybd, pWin, parent, focusEventMode); - focus->win = parent; - focus->revert = RevertToNone; - break; - case RevertToPointerRoot: - DoFocusEvents(keybd, pWin, PointerRootWin, focusEventMode); - focus->win = PointerRootWin; - focus->traceGood = 0; - break; - } - } - - if (mouse->valuator->motionHintWindow == pWin) - mouse->valuator->motionHintWindow = NullWindow; - - if (freeResources) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - while ( (oc = wOtherClients(pWin)) ) - FreeResource(oc->resource, RT_NONE); - while ( (passive = wPassiveGrabs(pWin)) ) - FreeResource(passive->resource, RT_NONE); - } -#ifdef XINPUT - DeleteWindowFromAnyExtEvents(pWin, freeResources); -#endif -} - -/* Call this whenever some window at or below pWin has changed geometry */ - -/*ARGSUSED*/ -void -CheckCursorConfinement(pWin) - WindowPtr pWin; -{ - GrabPtr grab = inputInfo.pointer->grab; - WindowPtr confineTo; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) return; -#endif - - if (grab && (confineTo = grab->confineTo)) - { - if (!BorderSizeNotEmpty(confineTo)) - (*inputInfo.pointer->DeactivateGrab)(inputInfo.pointer); - else if ((pWin == confineTo) || IsParent(pWin, confineTo)) - ConfineCursorToWindow(confineTo, TRUE, TRUE); - } -} - -Mask -EventMaskForClient(pWin, client) - WindowPtr pWin; - ClientPtr client; -{ - register OtherClientsPtr other; - - if (wClient (pWin) == client) - return pWin->eventMask; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (SameClient(other, client)) - return other->mask; - } - return 0; -} - -int -ProcRecolorCursor(client) - ClientPtr client; -{ - CursorPtr pCursor; - int nscr; - ScreenPtr pscr; - Bool displayed; - REQUEST(xRecolorCursorReq); - - REQUEST_SIZE_MATCH(xRecolorCursorReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityWriteAccess); - if ( !pCursor) - { - client->errorValue = stuff->cursor; - return (BadCursor); - } - - pCursor->foreRed = stuff->foreRed; - pCursor->foreGreen = stuff->foreGreen; - pCursor->foreBlue = stuff->foreBlue; - - pCursor->backRed = stuff->backRed; - pCursor->backGreen = stuff->backGreen; - pCursor->backBlue = stuff->backBlue; - - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { - pscr = screenInfo.screens[nscr]; -#ifdef PANORAMIX - if(!noPanoramiXExtension) - displayed = (pscr == sprite.screen); - else -#endif - displayed = (pscr == sprite.hotPhys.pScreen); - ( *pscr->RecolorCursor)(pscr, pCursor, - (pCursor == sprite.current) && displayed); - } - return (Success); -} - -void -WriteEventsToClient(pClient, count, events) - ClientPtr pClient; - int count; - xEvent *events; -{ -#ifdef PANORAMIX - xEvent eventCopy; -#endif - xEvent eventTo, *eventFrom; - int i; - -#ifdef XKB - if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events))) - return; -#endif - -#ifdef PANORAMIX - if(!noPanoramiXExtension && - (panoramiXdataPtr[0].x || panoramiXdataPtr[0].y)) - { - switch(events->u.u.type) { - case MotionNotify: - case ButtonPress: - case ButtonRelease: - case KeyPress: - case KeyRelease: - case EnterNotify: - case LeaveNotify: - /* - When multiple clients want the same event DeliverEventsToWindow - passes the same event structure multiple times so we can't - modify the one passed to us - */ - count = 1; /* should always be 1 */ - memcpy(&eventCopy, events, sizeof(xEvent)); - eventCopy.u.keyButtonPointer.rootX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.rootY += panoramiXdataPtr[0].y; - if(eventCopy.u.keyButtonPointer.event == - eventCopy.u.keyButtonPointer.root) - { - eventCopy.u.keyButtonPointer.eventX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.eventY += panoramiXdataPtr[0].y; - } - events = &eventCopy; - break; - default: break; - } - } -#endif - - if (EventCallback) - { - EventInfoRec eventinfo; - eventinfo.client = pClient; - eventinfo.events = events; - eventinfo.count = count; - CallCallbacks(&EventCallback, (pointer)&eventinfo); - } - if(pClient->swapped) - { - for(i = 0; i < count; i++) - { - eventFrom = &events[i]; - /* Remember to strip off the leading bit of type in case - this event was sent with "SendEvent." */ - (*EventSwapVector[eventFrom->u.u.type & 0177]) - (eventFrom, &eventTo); - (void)WriteToClient(pClient, sizeof(xEvent), (char *)&eventTo); - } - } - else - { - (void)WriteToClient(pClient, count * sizeof(xEvent), (char *) events); - } -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXevents.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXevents.c.XF86.original deleted file mode 100644 index ce8e53f92..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXevents.c.XF86.original +++ /dev/null @@ -1,4637 +0,0 @@ -/* $XFree86: xc/programs/Xserver/dix/events.c,v 3.46 2002/09/17 01:15:09 dawes Exp $ */ -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/**************************************************************** -* * -* Copyright (c) Digital Equipment Corporation, 1991, 1997 * -* * -* All Rights Reserved. Unpublished rights reserved under * -* the copyright laws of the United States. * -* * -* The software contained on this media is proprietary to * -* and embodies the confidential technology of Digital * -* Equipment Corporation. Possession, use, duplication or * -* dissemination of the software and media is authorized only * -* pursuant to a valid written license from Digital Equipment * -* Corporation. * -* * -* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * -* by the U.S. Government is subject to restrictions as set * -* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * -* or in FAR 52.227-19, as applicable. * -* * -*****************************************************************/ - -/* $Xorg: events.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "X.h" -#include "misc.h" -#include "resource.h" -#define NEED_EVENTS -#define NEED_REPLIES -#include "Xproto.h" -#include "windowstr.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "cursorstr.h" - -#include "dixstruct.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include "globals.h" - -#ifdef XKB -#include "XKBsrv.h" -#if NeedFunctionPrototypes -extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); -#else -extern Bool XkbFilterEvents(); -#endif -#endif - -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif - -#include "XIproto.h" -#include "exevents.h" -#include "extnsionst.h" - -#include "dixevents.h" -#include "dixgrabs.h" -#include "dispatch.h" - -#define EXTENSION_EVENT_BASE 64 - -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ -#define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask ) -#define AllButtonsMask ( \ - Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) -#define MotionMask ( \ - PointerMotionMask | Button1MotionMask | \ - Button2MotionMask | Button3MotionMask | Button4MotionMask | \ - Button5MotionMask | ButtonMotionMask ) -#define PropagateMask ( \ - KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \ - MotionMask ) -#define PointerGrabMask ( \ - ButtonPressMask | ButtonReleaseMask | \ - EnterWindowMask | LeaveWindowMask | \ - PointerMotionHintMask | KeymapStateMask | \ - MotionMask ) -#define AllModifiersMask ( \ - ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \ - Mod3Mask | Mod4Mask | Mod5Mask ) -#define AllEventMasks (lastEventMask|(lastEventMask-1)) -/* - * The following relies on the fact that the ButtonMotionMasks are equal - * to the corresponding ButtonMasks from the current modifier/button state. - */ -#define Motion_Filter(class) (PointerMotionMask | \ - (class)->state | (class)->motionMask) - - -#define WID(w) ((w) ? ((w)->drawable.id) : 0) - -#define XE_KBPTR (xE->u.keyButtonPointer) - - -#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) - -CallbackListPtr EventCallback; -CallbackListPtr DeviceEventCallback; - -#define DNPMCOUNT 8 - -Mask DontPropagateMasks[DNPMCOUNT]; -static int DontPropagateRefCnts[DNPMCOUNT]; - -#ifdef DEBUG -static debug_events = 0; -#endif -InputInfo inputInfo; - -static struct { - QdEventPtr pending, *pendtail; - DeviceIntPtr replayDev; /* kludgy rock to put flag for */ - WindowPtr replayWin; /* ComputeFreezes */ - Bool playingEvents; - TimeStamp time; -} syncEvents; - -/* - * The window trace information is used to avoid having to compute all the - * windows between the root and the current pointer window each time a button - * or key goes down. The grabs on each of those windows must be checked. - */ -static WindowPtr *spriteTrace = (WindowPtr *)NULL; -#define ROOT spriteTrace[0] -static int spriteTraceSize = 0; -static int spriteTraceGood; - -typedef struct { - int x, y; - ScreenPtr pScreen; -} HotSpot; - -static struct { - CursorPtr current; - BoxRec hotLimits; /* logical constraints of hot spot */ - Bool confined; /* confined to screen */ -#if defined(SHAPE) || defined(PANORAMIX) - RegionPtr hotShape; /* additional logical shape constraint */ -#endif - BoxRec physLimits; /* physical constraints of hot spot */ - WindowPtr win; /* window of logical position */ - HotSpot hot; /* logical pointer position */ - HotSpot hotPhys; /* physical pointer position */ -#ifdef PANORAMIX - ScreenPtr screen; /* all others are in Screen 0 coordinates */ - RegionRec Reg1; /* Region 1 for confining motion */ - RegionRec Reg2; /* Region 2 for confining virtual motion */ - WindowPtr windows[MAXSCREENS]; - WindowPtr confineWin; /* confine window */ -#endif -} sprite; /* info about the cursor sprite */ - -static void DoEnterLeaveEvents( -#if NeedFunctionPrototypes - WindowPtr /*fromWin*/, - WindowPtr /*toWin*/, - int /*mode*/ -#endif -); - -static WindowPtr XYToWindow( -#if NeedFunctionPrototypes - int /*x*/, - int /*y*/ -#endif -); - -extern int lastEvent; - -static Mask lastEventMask; - -#ifdef XINPUT -extern int DeviceMotionNotify; -#endif - -#define CantBeFiltered NoEventMask -static Mask filters[128] = -{ - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ - EnterWindowMask, /* EnterNotify */ - LeaveWindowMask, /* LeaveNotify */ - FocusChangeMask, /* FocusIn */ - FocusChangeMask, /* FocusOut */ - KeymapStateMask, /* KeymapNotify */ - ExposureMask, /* Expose */ - CantBeFiltered, /* GraphicsExpose */ - CantBeFiltered, /* NoExpose */ - VisibilityChangeMask, /* VisibilityNotify */ - SubstructureNotifyMask, /* CreateNotify */ - StructureAndSubMask, /* DestroyNotify */ - StructureAndSubMask, /* UnmapNotify */ - StructureAndSubMask, /* MapNotify */ - SubstructureRedirectMask, /* MapRequest */ - StructureAndSubMask, /* ReparentNotify */ - StructureAndSubMask, /* ConfigureNotify */ - SubstructureRedirectMask, /* ConfigureRequest */ - StructureAndSubMask, /* GravityNotify */ - ResizeRedirectMask, /* ResizeRequest */ - StructureAndSubMask, /* CirculateNotify */ - SubstructureRedirectMask, /* CirculateRequest */ - PropertyChangeMask, /* PropertyNotify */ - CantBeFiltered, /* SelectionClear */ - CantBeFiltered, /* SelectionRequest */ - CantBeFiltered, /* SelectionNotify */ - ColormapChangeMask, /* ColormapNotify */ - CantBeFiltered, /* ClientMessage */ - CantBeFiltered /* MappingNotify */ -}; - -static CARD8 criticalEvents[32] = -{ - 0x7c /* key and button events */ -}; - -#ifdef PANORAMIX - -static void ConfineToShape(RegionPtr shape, int *px, int *py); -static void SyntheticMotion(int x, int y); -static void PostNewCursor(void); - -static Bool -XineramaSetCursorPosition( - int x, - int y, - Bool generateEvent -){ - ScreenPtr pScreen; - BoxRec box; - int i; - - /* x,y are in Screen 0 coordinates. We need to decide what Screen - to send the message too and what the coordinates relative to - that screen are. */ - - pScreen = sprite.screen; - x += panoramiXdataPtr[0].x; - y += panoramiXdataPtr[0].y; - - if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum], - x, y, &box)) - { - FOR_NSCREENS(i) - { - if(i == pScreen->myNum) - continue; - if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i], x, y, &box)) - { - pScreen = screenInfo.screens[i]; - break; - } - } - } - - sprite.screen = pScreen; - sprite.hotPhys.x = x - panoramiXdataPtr[0].x; - sprite.hotPhys.y = y - panoramiXdataPtr[0].y; - x -= panoramiXdataPtr[pScreen->myNum].x; - y -= panoramiXdataPtr[pScreen->myNum].y; - - return (*pScreen->SetCursorPosition)(pScreen, x, y, generateEvent); -} - - -static void -XineramaConstrainCursor(void) -{ - ScreenPtr pScreen = sprite.screen; - BoxRec newBox = sprite.physLimits; - - /* Translate the constraining box to the screen - the sprite is actually on */ - newBox.x1 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.x2 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.y1 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - newBox.y2 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - - (* pScreen->ConstrainCursor)(pScreen, &newBox); -} - -static void -XineramaCheckPhysLimits( - CursorPtr cursor, - Bool generateEvents -){ - HotSpot new; - - if (!cursor) - return; - - new = sprite.hotPhys; - - /* I don't care what the DDX has to say about it */ - sprite.physLimits = sprite.hotLimits; - - /* constrain the pointer to those limits */ - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) /* more work if the shape is a mess */ - ConfineToShape(sprite.hotShape, &new.x, &new.y); - - if((new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - XineramaSetCursorPosition (new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } - - /* Tell DDX what the limits are */ - XineramaConstrainCursor(); -} - - -static Bool -XineramaSetWindowPntrs(WindowPtr pWin) -{ - if(pWin == WindowTable[0]) { - memcpy(sprite.windows, WindowTable, - PanoramiXNumScreens*sizeof(WindowPtr)); - } else { - PanoramiXRes *win; - int i; - - win = (PanoramiXRes*)LookupIDByType(pWin->drawable.id, XRT_WINDOW); - - if(!win) - return FALSE; - - for(i = 0; i < PanoramiXNumScreens; i++) { - sprite.windows[i] = LookupIDByType(win->info[i].id, RT_WINDOW); - if(!sprite.windows[i]) /* window is being unmapped */ - return FALSE; - } - } - return TRUE; -} - -static void -XineramaCheckVirtualMotion( - QdEventPtr qe, - WindowPtr pWin -){ - - if (qe) - { - sprite.hot.pScreen = qe->pScreen; /* should always be Screen 0 */ - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - int x, y, off_x, off_y, i; - BoxRec lims; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg2, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg2, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg2, &sprite.Reg2, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - lims = *REGION_EXTENTS(sprite.screen, &sprite.Reg2); - - if (sprite.hot.x < lims.x1) - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) - sprite.hot.y = lims.y2 - 1; - - if (REGION_NUM_RECTS(&sprite.Reg2) > 1) - ConfineToShape(&sprite.Reg2, &sprite.hot.x, &sprite.hot.y); - - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } -} - - -static Bool -XineramaCheckMotion(xEvent *xE) -{ - WindowPtr prevSpriteWin = sprite.win; - - if (xE && !syncEvents.playingEvents) - { - /* Motion events entering DIX get translated to Screen 0 - coordinates. Replayed events have already been - translated since they've entered DIX before */ - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; - - sprite.hot.x = XE_KBPTR.rootX; - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) - sprite.hot.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); - - sprite.hotPhys = sprite.hot; - if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - (sprite.hotPhys.y != XE_KBPTR.rootY)) - { - XineramaSetCursorPosition( - sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - } - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); - - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - - -static void -XineramaConfineCursorToWindow(WindowPtr pWin, Bool generateEvents) -{ - - if (syncEvents.playingEvents) - { - XineramaCheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - int x, y, off_x, off_y, i; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg1, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg1, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg1, &sprite.Reg1, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - sprite.hotLimits = *REGION_EXTENTS(sprite.screen, &sprite.Reg1); - - if(REGION_NUM_RECTS(&sprite.Reg1) > 1) - sprite.hotShape = &sprite.Reg1; - else - sprite.hotShape = NullRegion; - - sprite.confined = FALSE; - sprite.confineWin = (pWin == WindowTable[0]) ? NullWindow : pWin; - - XineramaCheckPhysLimits(sprite.current, generateEvents); - } -} - - -static void -XineramaChangeToCursor(CursorPtr cursor) -{ - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - XineramaCheckPhysLimits(cursor, FALSE); - (*sprite.screen->DisplayCursor)(sprite.screen, cursor); - sprite.current = cursor; - } -} - - -#endif /* PANORAMIX */ - -void -SetMaskForEvent(mask, event) - Mask mask; - int event; -{ - if ((event < LASTEvent) || (event >= 128)) - FatalError("SetMaskForEvent: bogus event number"); - filters[event] = mask; -} - -void -SetCriticalEvent(event) - int event; -{ - if (event >= 128) - FatalError("SetCriticalEvent: bogus event number"); - criticalEvents[event >> 3] |= 1 << (event & 7); -} - -static void -#if NeedFunctionPrototypes -SyntheticMotion(int x, int y) -#else -SyntheticMotion(x, y) - int x, y; -#endif -{ - xEvent xE; - -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - x += panoramiXdataPtr[0].x - panoramiXdataPtr[sprite.screen->myNum].x; - y += panoramiXdataPtr[0].y - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; - if (syncEvents.playingEvents) - xE.u.keyButtonPointer.time = syncEvents.time.milliseconds; - else - xE.u.keyButtonPointer.time = currentTime.milliseconds; - xE.u.u.type = MotionNotify; - (*inputInfo.pointer->public.processInputProc)(&xE, inputInfo.pointer, 1); -} - -#ifdef SHAPE -static void -#if NeedFunctionPrototypes -ConfineToShape(RegionPtr shape, int *px, int *py) -#else -ConfineToShape(shape, px, py) - RegionPtr shape; - int *px, *py; -#endif -{ - BoxRec box; - int x = *px, y = *py; - int incx = 1, incy = 1; - - if (POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)) - return; - box = *REGION_EXTENTS(sprite.hot.pScreen, shape); - /* this is rather crude */ - do { - x += incx; - if (x >= box.x2) - { - incx = -1; - x = *px - 1; - } - else if (x < box.x1) - { - incx = 1; - x = *px; - y += incy; - if (y >= box.y2) - { - incy = -1; - y = *py - 1; - } - else if (y < box.y1) - return; /* should never get here! */ - } - } while (!POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)); - *px = x; - *py = y; -} -#endif - -static void -#if NeedFunctionPrototypes -CheckPhysLimits( - CursorPtr cursor, - Bool generateEvents, - Bool confineToScreen, - ScreenPtr pScreen) -#else -CheckPhysLimits(cursor, generateEvents, confineToScreen, pScreen) - CursorPtr cursor; - Bool generateEvents; - Bool confineToScreen; - ScreenPtr pScreen; -#endif -{ - HotSpot new; - - if (!cursor) - return; - new = sprite.hotPhys; - if (pScreen) - new.pScreen = pScreen; - else - pScreen = new.pScreen; - (*pScreen->CursorLimits) (pScreen, cursor, &sprite.hotLimits, - &sprite.physLimits); - sprite.confined = confineToScreen; - (* pScreen->ConstrainCursor)(pScreen, &sprite.physLimits); - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &new.x, &new.y); -#endif - if ((pScreen != sprite.hotPhys.pScreen) || - (new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - if (pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys = new; - (*pScreen->SetCursorPosition) (pScreen, new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } -} - -static void -#if NeedFunctionPrototypes -CheckVirtualMotion( - register QdEventPtr qe, - register WindowPtr pWin) -#else -CheckVirtualMotion(qe, pWin) - register QdEventPtr qe; - register WindowPtr pWin; -#endif -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaCheckVirtualMotion(qe, pWin); - return; - } -#endif - if (qe) - { - sprite.hot.pScreen = qe->pScreen; - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - BoxRec lims; - - if (sprite.hot.pScreen != pWin->drawable.pScreen) - { - sprite.hot.pScreen = pWin->drawable.pScreen; - sprite.hot.x = sprite.hot.y = 0; - } - lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize); - if (sprite.hot.x < lims.x1) - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) - sprite.hot.y = lims.y2 - 1; -#ifdef SHAPE - if (wBoundingShape(pWin)) - ConfineToShape(&pWin->borderSize, &sprite.hot.x, &sprite.hot.y); -#endif - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } - ROOT = WindowTable[sprite.hot.pScreen->myNum]; -} - -static void -ConfineCursorToWindow(WindowPtr pWin, Bool generateEvents, Bool confineToScreen) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaConfineCursorToWindow(pWin, generateEvents); - return; - } -#endif - - if (syncEvents.playingEvents) - { - CheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - sprite.hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize); -#ifdef SHAPE - sprite.hotShape = wBoundingShape(pWin) ? &pWin->borderSize - : NullRegion; -#endif - CheckPhysLimits(sprite.current, generateEvents, confineToScreen, - pScreen); - } -} - -Bool -PointerConfinedToScreen() -{ - return sprite.confined; -} - -static void -#if NeedFunctionPrototypes -ChangeToCursor(CursorPtr cursor) -#else -ChangeToCursor(cursor) - CursorPtr cursor; -#endif -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaChangeToCursor(cursor); - return; - } -#endif - - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - CheckPhysLimits(cursor, FALSE, sprite.confined, - (ScreenPtr)NULL); - (*sprite.hotPhys.pScreen->DisplayCursor) (sprite.hotPhys.pScreen, - cursor); - sprite.current = cursor; - } -} - -/* returns true if b is a descendent of a */ -Bool -IsParent(a, b) - register WindowPtr a, b; -{ - for (b = b->parent; b; b = b->parent) - if (b == a) return TRUE; - return FALSE; -} - -static void -#if NeedFunctionPrototypes -PostNewCursor(void) -#else -PostNewCursor() -#endif -{ - register WindowPtr win; - register GrabPtr grab = inputInfo.pointer->grab; - - if (syncEvents.playingEvents) - return; - if (grab) - { - if (grab->cursor) - { - ChangeToCursor(grab->cursor); - return; - } - if (IsParent(grab->window, sprite.win)) - win = sprite.win; - else - win = grab->window; - } - else - win = sprite.win; - for (; win; win = win->parent) - if (win->optional && win->optional->cursor != NullCursor) - { - ChangeToCursor(win->optional->cursor); - return; - } -} - -WindowPtr -GetCurrentRootWindow() -{ - return ROOT; -} - -WindowPtr -GetSpriteWindow() -{ - return sprite.win; -} - -CursorPtr -GetSpriteCursor() -{ - return sprite.current; -} - -void -GetSpritePosition(px, py) - int *px, *py; -{ - *px = sprite.hotPhys.x; - *py = sprite.hotPhys.y; -} - -#ifdef PANORAMIX -int -XineramaGetCursorScreen() -{ - if(!noPanoramiXExtension) { - return sprite.screen->myNum; - } else { - return 0; - } -} -#endif /* PANORAMIX */ - -#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */ - -static void -#if NeedFunctionPrototypes -MonthChangedOrBadTime(register xEvent *xE) -#else -MonthChangedOrBadTime(xE) - register xEvent *xE; -#endif -{ - /* If the ddx/OS is careless about not processing timestamped events from - * different sources in sorted order, then it's possible for time to go - * backwards when it should not. Here we ensure a decent time. - */ - if ((currentTime.milliseconds - XE_KBPTR.time) > TIMESLOP) - currentTime.months++; - else - XE_KBPTR.time = currentTime.milliseconds; -} - -#define NoticeTime(xE) { \ - if ((xE)->u.keyButtonPointer.time < currentTime.milliseconds) \ - MonthChangedOrBadTime(xE); \ - currentTime.milliseconds = (xE)->u.keyButtonPointer.time; \ - lastDeviceEventTime = currentTime; } - -void -NoticeEventTime(xE) - register xEvent *xE; -{ - if (!syncEvents.playingEvents) - NoticeTime(xE); -} - -/************************************************************************** - * The following procedures deal with synchronous events * - **************************************************************************/ - -void -EnqueueEvent(xE, device, count) - xEvent *xE; - DeviceIntPtr device; - int count; -{ - register QdEventPtr tail = *syncEvents.pendtail; - register QdEventPtr qe; - xEvent *qxE; - - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* The RECORD spec says that the root window field of motion events - * must be valid. At this point, it hasn't been filled in yet, so - * we do it here. The long expression below is necessary to get - * the current root window; the apparently reasonable alternative - * GetCurrentRootWindow()->drawable.id doesn't give you the right - * answer on the first motion event after a screen change because - * the data that GetCurrentRootWindow relies on hasn't been - * updated yet. - */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - if (xE->u.u.type == MotionNotify) - { -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; - } -#endif - sprite.hotPhys.x = XE_KBPTR.rootX; - sprite.hotPhys.y = XE_KBPTR.rootY; - /* do motion compression */ - if (tail && - (tail->event->u.u.type == MotionNotify) && - (tail->pScreen == sprite.hotPhys.pScreen)) - { - tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x; - tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y; - tail->event->u.keyButtonPointer.time = XE_KBPTR.time; - tail->months = currentTime.months; - return; - } - } - qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + (count * sizeof(xEvent))); - if (!qe) - return; - qe->next = (QdEventPtr)NULL; - qe->device = device; - qe->pScreen = sprite.hotPhys.pScreen; - qe->months = currentTime.months; - qe->event = (xEvent *)(qe + 1); - qe->evcount = count; - for (qxE = qe->event; --count >= 0; qxE++, xE++) - *qxE = *xE; - if (tail) - syncEvents.pendtail = &tail->next; - *syncEvents.pendtail = qe; -} - -static void -#if NeedFunctionPrototypes -PlayReleasedEvents(void) -#else -PlayReleasedEvents() -#endif -{ - register QdEventPtr *prev, qe; - register DeviceIntPtr dev; - - prev = &syncEvents.pending; - while ( (qe = *prev) ) - { - if (!qe->device->sync.frozen) - { - *prev = qe->next; - if (*syncEvents.pendtail == *prev) - syncEvents.pendtail = prev; - if (qe->event->u.u.type == MotionNotify) - CheckVirtualMotion(qe, NullWindow); - syncEvents.time.months = qe->months; - syncEvents.time.milliseconds = qe->event->u.keyButtonPointer.time; -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - qe->event->u.keyButtonPointer.rootX += - panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x; - qe->event->u.keyButtonPointer.rootY += - panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - (*qe->device->public.processInputProc)(qe->event, qe->device, - qe->evcount); - xfree(qe); - for (dev = inputInfo.devices; dev && dev->sync.frozen; dev = dev->next) - ; - if (!dev) - break; - /* Playing the event may have unfrozen another device. */ - /* So to play it safe, restart at the head of the queue */ - prev = &syncEvents.pending; - } - else - prev = &qe->next; - } -} - -static void -#if NeedFunctionPrototypes -FreezeThaw(register DeviceIntPtr dev, Bool frozen) -#else -FreezeThaw(dev, frozen) - register DeviceIntPtr dev; - Bool frozen; -#endif -{ - dev->sync.frozen = frozen; - if (frozen) - dev->public.processInputProc = dev->public.enqueueInputProc; - else - dev->public.processInputProc = dev->public.realInputProc; -} - -void -ComputeFreezes() -{ - register DeviceIntPtr replayDev = syncEvents.replayDev; - register int i; - WindowPtr w; - register xEvent *xE; - int count; - GrabPtr grab; - register DeviceIntPtr dev; - - for (dev = inputInfo.devices; dev; dev = dev->next) - FreezeThaw(dev, dev->sync.other || (dev->sync.state >= FROZEN)); - if (syncEvents.playingEvents || (!replayDev && !syncEvents.pending)) - return; - syncEvents.playingEvents = TRUE; - if (replayDev) - { - xE = replayDev->sync.event; - count = replayDev->sync.evcount; - syncEvents.replayDev = (DeviceIntPtr)NULL; - - w = XYToWindow( XE_KBPTR.rootX, XE_KBPTR.rootY); - for (i = 0; i < spriteTraceGood; i++) - { - if (syncEvents.replayWin == spriteTrace[i]) - { - if (!CheckDeviceGrabs(replayDev, xE, i+1, count)) { - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, - replayDev, count); - } - goto playmore; - } - } - /* must not still be in the same stack */ - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, replayDev, count); - } -playmore: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!dev->sync.frozen) - { - PlayReleasedEvents(); - break; - } - } - syncEvents.playingEvents = FALSE; - /* the following may have been skipped during replay, so do it now */ - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); - PostNewCursor(); -} - -#ifdef RANDR -void -ScreenRestructured (ScreenPtr pScreen) -{ - GrabPtr grab; - - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); -} -#endif - -void -CheckGrabForSyncs(thisDev, thisMode, otherMode) - register DeviceIntPtr thisDev; - Bool thisMode, otherMode; -{ - register GrabPtr grab = thisDev->grab; - register DeviceIntPtr dev; - - if (thisMode == GrabModeSync) - thisDev->sync.state = FROZEN_NO_EVENT; - else - { /* free both if same client owns both */ - thisDev->sync.state = THAWED; - if (thisDev->sync.other && - (CLIENT_BITS(thisDev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - thisDev->sync.other = NullGrab; - } - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev != thisDev) - { - if (otherMode == GrabModeSync) - dev->sync.other = grab; - else - { /* free both if same client owns both */ - if (dev->sync.other && - (CLIENT_BITS(dev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - dev->sync.other = NullGrab; - } - } - } - ComputeFreezes(); -} - -void -ActivatePointerGrab(mouse, grab, time, autoGrab) - register GrabPtr grab; - register DeviceIntPtr mouse; - TimeStamp time; - Bool autoGrab; -{ - WindowPtr oldWin = (mouse->grab) ? mouse->grab->window - : sprite.win; - - if (grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, FALSE, TRUE); - } - DoEnterLeaveEvents(oldWin, grab->window, NotifyGrab); - mouse->valuator->motionHintWindow = NullWindow; - if (syncEvents.playingEvents) - mouse->grabTime = syncEvents.time; - else - mouse->grabTime = time; - if (grab->cursor) - grab->cursor->refcnt++; - mouse->activeGrab = *grab; - mouse->grab = &mouse->activeGrab; - mouse->fromPassiveGrab = autoGrab; - PostNewCursor(); - CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); -} - -void -DeactivatePointerGrab(mouse) - register DeviceIntPtr mouse; -{ - register GrabPtr grab = mouse->grab; - register DeviceIntPtr dev; - - mouse->valuator->motionHintWindow = NullWindow; - mouse->grab = NullGrab; - mouse->sync.state = NOT_GRABBED; - mouse->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoEnterLeaveEvents(grab->window, sprite.win, NotifyUngrab); - if (grab->confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - PostNewCursor(); - if (grab->cursor) - FreeCursor(grab->cursor, (Cursor)0); - ComputeFreezes(); -} - -void -ActivateKeyboardGrab(keybd, grab, time, passive) - register DeviceIntPtr keybd; - GrabPtr grab; - TimeStamp time; - Bool passive; -{ - WindowPtr oldWin; - - if (keybd->grab) - oldWin = keybd->grab->window; - else if (keybd->focus) - oldWin = keybd->focus->win; - else - oldWin = sprite.win; - if (oldWin == FollowKeyboardWin) - oldWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab); - if (syncEvents.playingEvents) - keybd->grabTime = syncEvents.time; - else - keybd->grabTime = time; - keybd->activeGrab = *grab; - keybd->grab = &keybd->activeGrab; - keybd->fromPassiveGrab = passive; - CheckGrabForSyncs(keybd, (Bool)grab->keyboardMode, (Bool)grab->pointerMode); -} - -void -DeactivateKeyboardGrab(keybd) - register DeviceIntPtr keybd; -{ - register GrabPtr grab = keybd->grab; - register DeviceIntPtr dev; - register WindowPtr focusWin = keybd->focus ? keybd->focus->win - : sprite.win; - - if (focusWin == FollowKeyboardWin) - focusWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - keybd->grab = NullGrab; - keybd->sync.state = NOT_GRABBED; - keybd->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab); - ComputeFreezes(); -} - -void -AllowSome(client, time, thisDev, newState) - ClientPtr client; - TimeStamp time; - register DeviceIntPtr thisDev; - int newState; -{ - Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced; - TimeStamp grabTime; - register DeviceIntPtr dev; - - thisGrabbed = thisDev->grab && SameClient(thisDev->grab, client); - thisSynced = FALSE; - otherGrabbed = FALSE; - othersFrozen = TRUE; - grabTime = thisDev->grabTime; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - { - if (!(thisGrabbed || otherGrabbed) || - (CompareTimeStamps(dev->grabTime, grabTime) == LATER)) - grabTime = dev->grabTime; - otherGrabbed = TRUE; - if (thisDev->sync.other == dev->grab) - thisSynced = TRUE; - if (dev->sync.state < FROZEN) - othersFrozen = FALSE; - } - else if (!dev->sync.other || !SameClient(dev->sync.other, client)) - othersFrozen = FALSE; - } - if (!((thisGrabbed && thisDev->sync.state >= FROZEN) || thisSynced)) - return; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, grabTime) == EARLIER)) - return; - switch (newState) - { - case THAWED: /* Async */ - if (thisGrabbed) - thisDev->sync.state = THAWED; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - break; - case FREEZE_NEXT_EVENT: /* Sync */ - if (thisGrabbed) - { - thisDev->sync.state = FREEZE_NEXT_EVENT; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - } - break; - case THAWED_BOTH: /* AsyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case FREEZE_BOTH_NEXT_EVENT: /* SyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = FREEZE_BOTH_NEXT_EVENT; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case NOT_GRABBED: /* Replay */ - if (thisGrabbed && thisDev->sync.state == FROZEN_WITH_EVENT) - { - if (thisSynced) - thisDev->sync.other = NullGrab; - syncEvents.replayDev = thisDev; - syncEvents.replayWin = thisDev->grab->window; - (*thisDev->DeactivateGrab)(thisDev); - syncEvents.replayDev = (DeviceIntPtr)NULL; - } - break; - case THAW_OTHERS: /* AsyncOthers */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - } -} - -int -ProcAllowEvents(client) - register ClientPtr client; -{ - TimeStamp time; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - REQUEST(xAllowEventsReq); - - REQUEST_SIZE_MATCH(xAllowEventsReq); - time = ClientTimeToServerTime(stuff->time); - switch (stuff->mode) - { - case ReplayPointer: - AllowSome(client, time, mouse, NOT_GRABBED); - break; - case SyncPointer: - AllowSome(client, time, mouse, FREEZE_NEXT_EVENT); - break; - case AsyncPointer: - AllowSome(client, time, mouse, THAWED); - break; - case ReplayKeyboard: - AllowSome(client, time, keybd, NOT_GRABBED); - break; - case SyncKeyboard: - AllowSome(client, time, keybd, FREEZE_NEXT_EVENT); - break; - case AsyncKeyboard: - AllowSome(client, time, keybd, THAWED); - break; - case SyncBoth: - AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT); - break; - case AsyncBoth: - AllowSome(client, time, keybd, THAWED_BOTH); - break; - default: - client->errorValue = stuff->mode; - return BadValue; - } - return Success; -} - -void -ReleaseActiveGrabs(client) - ClientPtr client; -{ - register DeviceIntPtr dev; - Bool done; - - /* XXX CloseDownClient should remove passive grabs before - * releasing active grabs. - */ - do { - done = TRUE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - { - (*dev->DeactivateGrab)(dev); - done = FALSE; - } - } - } while (!done); -} - -/************************************************************************** - * The following procedures deal with delivering events * - **************************************************************************/ - -int -TryClientEvents (client, pEvents, count, mask, filter, grab) - ClientPtr client; - GrabPtr grab; - xEvent *pEvents; - int count; - Mask mask, filter; -{ - int i; - int type; - -#ifdef DEBUG - if (debug_events) ErrorF( - "Event([%d, %d], mask=0x%x), client=%d", - pEvents->u.u.type, pEvents->u.u.detail, mask, client->index); -#endif - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) - return -1; /* don't send, but notify caller */ - type = pEvents->u.u.type; - if (type == MotionNotify) - { - if (mask & PointerMotionHintMask) - { - if (WID(inputInfo.pointer->valuator->motionHintWindow) == - pEvents->u.keyButtonPointer.event) - { -#ifdef DEBUG - if (debug_events) ErrorF("\n"); - fprintf(stderr,"motionHintWindow == keyButtonPointer.event\n"); -#endif - return 1; /* don't send, but pretend we did */ - } - pEvents->u.u.detail = NotifyHint; - } - else - { - pEvents->u.u.detail = NotifyNormal; - } - } -#ifdef XINPUT - else - { - if ((type == DeviceMotionNotify) && - MaybeSendDeviceMotionNotifyHint - ((deviceKeyButtonPointer*)pEvents, mask) != 0) - return 1; - } -#endif - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } - - if (BitIsOn(criticalEvents, type)) - { -#ifdef SMART_SCHEDULE - if (client->smart_priority < SMART_MAX_PRIORITY) - client->smart_priority++; -#endif - SetCriticalOutputPending(); - } - - WriteEventsToClient(client, count, pEvents); -#ifdef DEBUG - if (debug_events) ErrorF( " delivered\n"); -#endif - return 1; - } - else - { -#ifdef DEBUG - if (debug_events) ErrorF("\n"); -#endif - return 0; - } -} - -int -DeliverEventsToWindow(pWin, pEvents, count, filter, grab, mskidx) - register WindowPtr pWin; - GrabPtr grab; - xEvent *pEvents; - int count; - Mask filter; - int mskidx; -{ - int deliveries = 0, nondeliveries = 0; - int attempt; - register InputClients *other; - ClientPtr client = NullClient; - Mask deliveryMask = 0; /* If a grab occurs due to a button press, then - this mask is the mask of the grab. */ - int type = pEvents->u.u.type; - - /* CantBeFiltered means only window owner gets the event */ - if ((filter == CantBeFiltered) || !(type & EXTENSION_EVENT_BASE)) - { - /* if nobody ever wants to see this event, skip some work */ - if (filter != CantBeFiltered && - !((wOtherEventMasks(pWin)|pWin->eventMask) & filter)) - return 0; - if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = wClient(pWin); - deliveryMask = pWin->eventMask; - } else - nondeliveries--; - } - } - if (filter != CantBeFiltered) - { - if (type & EXTENSION_EVENT_BASE) - { - OtherInputMasks *inputMasks; - - inputMasks = wOtherInputMasks(pWin); - if (!inputMasks || - !(inputMasks->inputEvents[mskidx] & filter)) - return 0; - other = inputMasks->inputClients; - } - else - other = (InputClients *)wOtherClients(pWin); - for (; other; other = other->next) - { - if ( (attempt = TryClientEvents(rClient(other), pEvents, count, - other->mask[mskidx], filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = rClient(other); - deliveryMask = other->mask[mskidx]; - } else - nondeliveries--; - } - } - } - if ((type == ButtonPress) && deliveries && (!grab)) - { - GrabRec tempGrab; - - tempGrab.device = inputInfo.pointer; - tempGrab.resource = client->clientAsMask; - tempGrab.window = pWin; - tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE; - tempGrab.eventMask = deliveryMask; - tempGrab.keyboardMode = GrabModeAsync; - tempGrab.pointerMode = GrabModeAsync; - tempGrab.confineTo = NullWindow; - tempGrab.cursor = NullCursor; - (*inputInfo.pointer->ActivateGrab)(inputInfo.pointer, &tempGrab, - currentTime, TRUE); - } - else if ((type == MotionNotify) && deliveries) - inputInfo.pointer->valuator->motionHintWindow = pWin; -#ifdef XINPUT - else - { - if (((type == DeviceMotionNotify) || (type == DeviceButtonPress)) && - deliveries) - CheckDeviceGrabAndHintWindow (pWin, type, - (deviceKeyButtonPointer*) pEvents, - grab, client, deliveryMask); - } -#endif - if (deliveries) - return deliveries; - return nondeliveries; -} - -/* If the event goes to dontClient, don't send it and return 0. if - send works, return 1 or if send didn't work, return 2. - Only works for core events. -*/ - -#ifdef PANORAMIX -static int -XineramaTryClientEventsResult( - ClientPtr client, - GrabPtr grab, - Mask mask, - Mask filter -){ - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) return -1; - else return 1; - } - return 0; -} -#endif - -int -MaybeDeliverEventsToClient(pWin, pEvents, count, filter, dontClient) - register WindowPtr pWin; - xEvent *pEvents; - int count; - Mask filter; - ClientPtr dontClient; -{ - register OtherClients *other; - - - if (pWin->eventMask & filter) - { - if (wClient(pWin) == dontClient) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - wClient(pWin), NullGrab, pWin->eventMask, filter); -#endif - return TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, NullGrab); - } - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & filter) - { - if (SameClient(other, dontClient)) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - rClient(other), NullGrab, other->mask, filter); -#endif - return TryClientEvents(rClient(other), pEvents, count, - other->mask, filter, NullGrab); - } - } - return 2; -} - -static void -#if NeedFunctionPrototypes -FixUpEventFromWindow( - xEvent *xE, - WindowPtr pWin, - Window child, - Bool calcChild) -#else -FixUpEventFromWindow(xE, pWin, child, calcChild) - xEvent *xE; - WindowPtr pWin; - Window child; - Bool calcChild; -#endif -{ - if (calcChild) - { - WindowPtr w=spriteTrace[spriteTraceGood-1]; - /* If the search ends up past the root should the child field be - set to none or should the value in the argument be passed - through. It probably doesn't matter since everyone calls - this function with child == None anyway. */ - - while (w) - { - /* If the source window is same as event window, child should be - none. Don't bother going all all the way back to the root. */ - - if (w == pWin) - { - child = None; - break; - } - - if (w->parent == pWin) - { - child = w->drawable.id; - break; - } - w = w->parent; - } - } - XE_KBPTR.root = ROOT->drawable.id; - XE_KBPTR.event = pWin->drawable.id; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - XE_KBPTR.sameScreen = xTrue; - XE_KBPTR.child = child; - XE_KBPTR.eventX = - XE_KBPTR.rootX - pWin->drawable.x; - XE_KBPTR.eventY = - XE_KBPTR.rootY - pWin->drawable.y; - } - else - { - XE_KBPTR.sameScreen = xFalse; - XE_KBPTR.child = None; - XE_KBPTR.eventX = 0; - XE_KBPTR.eventY = 0; - } -} - -int -DeliverDeviceEvents(pWin, xE, grab, stopAt, dev, count) - register WindowPtr pWin, stopAt; - register xEvent *xE; - GrabPtr grab; - DeviceIntPtr dev; - int count; -{ - Window child = None; - int type = xE->u.u.type; - Mask filter = filters[type]; - int deliveries = 0; - - if (type & EXTENSION_EVENT_BASE) - { - register OtherInputMasks *inputMasks; - int mskidx = dev->id; - - inputMasks = wOtherInputMasks(pWin); - if (inputMasks && !(filter & inputMasks->deliverableEvents[mskidx])) - return 0; - while (pWin) - { - if (inputMasks && (inputMasks->inputEvents[mskidx] & filter)) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, mskidx); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (inputMasks && - (filter & inputMasks->dontPropagateMask[mskidx]))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - if (pWin) - inputMasks = wOtherInputMasks(pWin); - } - } - else - { - if (!(filter & pWin->deliverableEvents)) - return 0; - while (pWin) - { - if ((wOtherEventMasks(pWin)|pWin->eventMask) & filter) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, 0); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (filter & wDontPropagateMask(pWin))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - } - } - return 0; -} - -/* not useful for events that propagate up the tree or extension events */ -int -DeliverEvents(pWin, xE, count, otherParent) - register WindowPtr pWin, otherParent; - register xEvent *xE; - int count; -{ - Mask filter; - int deliveries; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return count; -#endif - - if (!count) - return 0; - filter = filters[xE->u.u.type]; - if ((filter & SubstructureNotifyMask) && (xE->u.u.type != CreateNotify)) - xE->u.destroyNotify.event = pWin->drawable.id; - if (filter != StructureAndSubMask) - return DeliverEventsToWindow(pWin, xE, count, filter, NullGrab, 0); - deliveries = DeliverEventsToWindow(pWin, xE, count, StructureNotifyMask, - NullGrab, 0); - if (pWin->parent) - { - xE->u.destroyNotify.event = pWin->parent->drawable.id; - deliveries += DeliverEventsToWindow(pWin->parent, xE, count, - SubstructureNotifyMask, NullGrab, - 0); - if (xE->u.u.type == ReparentNotify) - { - xE->u.destroyNotify.event = otherParent->drawable.id; - deliveries += DeliverEventsToWindow(otherParent, xE, count, - SubstructureNotifyMask, - NullGrab, 0); - } - } - return deliveries; -} - - -static Bool -PointInBorderSize(WindowPtr pWin, int x, int y) -{ - BoxRec box; - - if(POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderSize, x, y, &box)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(POINT_IN_REGION(sprite.screen, - &sprite.windows[i]->borderSize, - x + panoramiXdataPtr[0].x - panoramiXdataPtr[i].x, - y + panoramiXdataPtr[0].y - panoramiXdataPtr[i].y, - &box)) - return TRUE; - } - } -#endif - return FALSE; -} - -static WindowPtr -#if NeedFunctionPrototypes -XYToWindow(int x, int y) -#else -XYToWindow(x, y) - int x, y; -#endif -{ - register WindowPtr pWin; - - spriteTraceGood = 1; /* root window still there */ - pWin = ROOT->firstChild; - while (pWin) - { - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth(pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) -#endif - ) - { - if (spriteTraceGood >= spriteTraceSize) - { - spriteTraceSize += 10; - Must_have_memory = TRUE; /* XXX */ - spriteTrace = (WindowPtr *)xrealloc( - spriteTrace, spriteTraceSize*sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - spriteTrace[spriteTraceGood++] = pWin; - pWin = pWin->firstChild; - } - else - pWin = pWin->nextSib; - } - return spriteTrace[spriteTraceGood-1]; -} - -static Bool -#if NeedFunctionPrototypes -CheckMotion(xEvent *xE) -#else -CheckMotion(xE) - xEvent *xE; -#endif -{ - WindowPtr prevSpriteWin = sprite.win; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaCheckMotion(xE); -#endif - - if (xE && !syncEvents.playingEvents) - { - if (sprite.hot.pScreen != sprite.hotPhys.pScreen) - { - sprite.hot.pScreen = sprite.hotPhys.pScreen; - ROOT = WindowTable[sprite.hot.pScreen->myNum]; - } - sprite.hot.x = XE_KBPTR.rootX; - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) - sprite.hot.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); -#endif - sprite.hotPhys = sprite.hot; - if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - (sprite.hotPhys.y != XE_KBPTR.rootY)) - { - (*sprite.hotPhys.pScreen->SetCursorPosition)( - sprite.hotPhys.pScreen, - sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - } - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); -#ifdef notyet - if (!(sprite.win->deliverableEvents & - Motion_Filter(inputInfo.pointer->button)) - !syncEvents.playingEvents) - { - /* XXX Do PointerNonInterestBox here */ - } -#endif - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - -void -WindowsRestructured() -{ - (void) CheckMotion((xEvent *)NULL); -} - -void -DefineInitialRootWindow(win) - register WindowPtr win; -{ - register ScreenPtr pScreen = win->drawable.pScreen; - - sprite.hotPhys.pScreen = pScreen; - sprite.hotPhys.x = pScreen->width / 2; - sprite.hotPhys.y = pScreen->height / 2; - sprite.hot = sprite.hotPhys; - sprite.hotLimits.x2 = pScreen->width; - sprite.hotLimits.y2 = pScreen->height; - sprite.win = win; - sprite.current = wCursor (win); - spriteTraceGood = 1; - ROOT = win; - (*pScreen->CursorLimits) ( - pScreen, sprite.current, &sprite.hotLimits, &sprite.physLimits); - sprite.confined = FALSE; - (*pScreen->ConstrainCursor) (pScreen, &sprite.physLimits); - (*pScreen->SetCursorPosition) (pScreen, sprite.hot.x, sprite.hot.y, FALSE); - (*pScreen->DisplayCursor) (pScreen, sprite.current); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotLimits.x1 = -panoramiXdataPtr[0].x; - sprite.hotLimits.y1 = -panoramiXdataPtr[0].y; - sprite.hotLimits.x2 = PanoramiXPixWidth - panoramiXdataPtr[0].x; - sprite.hotLimits.y2 = PanoramiXPixHeight - panoramiXdataPtr[0].y; - sprite.physLimits = sprite.hotLimits; - sprite.confineWin = NullWindow; - sprite.screen = pScreen; - /* gotta UNINIT these someplace */ - REGION_INIT(pScreen, &sprite.Reg1, NullBox, 1); - REGION_INIT(pScreen, &sprite.Reg2, NullBox, 1); - } -#endif -} - -/* - * This does not take any shortcuts, and even ignores its argument, since - * it does not happen very often, and one has to walk up the tree since - * this might be a newly instantiated cursor for an intermediate window - * between the one the pointer is in and the one that the last cursor was - * instantiated from. - */ -/*ARGSUSED*/ -void -WindowHasNewCursor(pWin) - WindowPtr pWin; -{ - PostNewCursor(); -} - -void -NewCurrentScreen(newScreen, x, y) - ScreenPtr newScreen; - int x,y; -{ - sprite.hotPhys.x = x; - sprite.hotPhys.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotPhys.x += panoramiXdataPtr[newScreen->myNum].x - - panoramiXdataPtr[0].x; - sprite.hotPhys.y += panoramiXdataPtr[newScreen->myNum].y - - panoramiXdataPtr[0].y; - if (newScreen != sprite.screen) { - sprite.screen = newScreen; - /* Make sure we tell the DDX to update its copy of the screen */ - if(sprite.confineWin) - XineramaConfineCursorToWindow(sprite.confineWin, TRUE); - else - XineramaConfineCursorToWindow(WindowTable[0], TRUE); - /* if the pointer wasn't confined, the DDX won't get - told of the pointer warp so we reposition it here */ - if(!syncEvents.playingEvents) - (*sprite.screen->SetCursorPosition)(sprite.screen, - sprite.hotPhys.x + panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x, - sprite.hotPhys.y + panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y, FALSE); - } - } else -#endif - if (newScreen != sprite.hotPhys.pScreen) - ConfineCursorToWindow(WindowTable[newScreen->myNum], TRUE, FALSE); -} - -#ifdef PANORAMIX - -static Bool -XineramaPointInWindowIsVisible( - WindowPtr pWin, - int x, - int y -) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - BoxRec box; - int i, xoff, yoff; - - if (!pWin->realized) return FALSE; - - if (POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) - return TRUE; - - if(!XineramaSetWindowPntrs(pWin)) return FALSE; - - xoff = x + panoramiXdataPtr[0].x; - yoff = y + panoramiXdataPtr[0].y; - - for(i = 1; i < PanoramiXNumScreens; i++) { - pWin = sprite.windows[i]; - pScreen = pWin->drawable.pScreen; - x = xoff - panoramiXdataPtr[i].x; - y = yoff - panoramiXdataPtr[i].y; - - if(POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) - return TRUE; - - } - - return FALSE; -} - -static int -XineramaWarpPointer(ClientPtr client) -{ - WindowPtr dest = NULL; - int x, y; - - REQUEST(xWarpPointerReq); - - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if(source == WindowTable[0]) { - winX -= panoramiXdataPtr[0].x; - winY -= panoramiXdataPtr[0].y; - } - if (x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !XineramaPointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) { - x = dest->drawable.x; - y = dest->drawable.y; - if(dest == WindowTable[0]) { - x -= panoramiXdataPtr[0].x; - y -= panoramiXdataPtr[0].y; - } - } - - x += stuff->dstX; - y += stuff->dstY; - - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); - - XineramaSetCursorPosition(x, y, TRUE); - - return Success; -} - -#endif - - -int -ProcWarpPointer(client) - ClientPtr client; -{ - WindowPtr dest = NULL; - int x, y; - ScreenPtr newScreen; - - REQUEST(xWarpPointerReq); - - REQUEST_SIZE_MATCH(xWarpPointerReq); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaWarpPointer(client); -#endif - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if (source->drawable.pScreen != sprite.hotPhys.pScreen || - x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !PointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) - { - x = dest->drawable.x; - y = dest->drawable.y; - newScreen = dest->drawable.pScreen; - } else - newScreen = sprite.hotPhys.pScreen; - - x += stuff->dstX; - y += stuff->dstY; - - if (x < 0) - x = 0; - else if (x >= newScreen->width) - x = newScreen->width - 1; - if (y < 0) - y = 0; - else if (y >= newScreen->height) - y = newScreen->height - 1; - - if (newScreen == sprite.hotPhys.pScreen) - { - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; -#if defined(SHAPE) - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); -#endif - (*newScreen->SetCursorPosition)(newScreen, x, y, TRUE); - } - else if (!PointerConfinedToScreen()) - { - NewCurrentScreen(newScreen, x, y); - } - return Success; -} - -static Bool -BorderSizeNotEmpty(WindowPtr pWin) -{ - if(REGION_NOTEMPTY(sprite.hotPhys.pScreen, &pWin->borderSize)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(REGION_NOTEMPTY(sprite.screen, &sprite.windows[i]->borderSize)) - return TRUE; - } - } -#endif - return FALSE; -} - -/* "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a - passive grab set on the window to be activated. */ - -static Bool -#if NeedFunctionPrototypes -CheckPassiveGrabsOnWindow( - WindowPtr pWin, - register DeviceIntPtr device, - register xEvent *xE, - int count) -#else -CheckPassiveGrabsOnWindow(pWin, device, xE, count) - WindowPtr pWin; - register DeviceIntPtr device; - register xEvent *xE; - int count; -#endif -{ - register GrabPtr grab = wPassiveGrabs(pWin); - GrabRec tempGrab; - register xEvent *dxE; - - if (!grab) - return FALSE; - tempGrab.window = pWin; - tempGrab.device = device; - tempGrab.type = xE->u.u.type; - tempGrab.detail.exact = xE->u.u.detail; - tempGrab.detail.pMask = NULL; - tempGrab.modifiersDetail.pMask = NULL; - for (; grab; grab = grab->next) - { -#ifdef XKB - DeviceIntPtr gdev; - XkbSrvInfoPtr xkbi; - - gdev= grab->modifierDevice; - xkbi= gdev->key->xkbInfo; -#endif - tempGrab.modifierDevice = grab->modifierDevice; - if (device == grab->modifierDevice && - (xE->u.u.type == KeyPress -#ifdef XINPUT - || xE->u.u.type == DeviceKeyPress -#endif - )) - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension?gdev->key->prev_state:xkbi->state.grab_mods); -#else - grab->modifierDevice->key->prev_state; -#endif - else - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension ? gdev->key->state : xkbi->state.grab_mods); -#else - grab->modifierDevice->key->state; -#endif - if (GrabMatchesSecond(&tempGrab, grab) && - (!grab->confineTo || - (grab->confineTo->realized && - BorderSizeNotEmpty(grab->confineTo)))) - { -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(wClient(pWin), device, FALSE)) - return FALSE; -#endif -#ifdef XKB - if (!noXkbExtension) { - XE_KBPTR.state &= 0x1f00; - XE_KBPTR.state |= - tempGrab.modifiersDetail.exact&(~0x1f00); - } -#endif - (*device->ActivateGrab)(device, grab, currentTime, TRUE); - - FixUpEventFromWindow(xE, grab->window, None, TRUE); - - (void) TryClientEvents(rClient(grab), xE, count, - filters[xE->u.u.type], - filters[xE->u.u.type], grab); - - if (device->sync.state == FROZEN_NO_EVENT) - { - if (device->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - device->sync.event = (xEvent *)xrealloc(device->sync.event, - count* - sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - device->sync.evcount = count; - for (dxE = device->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - device->sync.state = FROZEN_WITH_EVENT; - } - return TRUE; - } - } - return FALSE; -} - -/* -"CheckDeviceGrabs" handles both keyboard and pointer events that may cause -a passive grab to be activated. If the event is a keyboard event, the -ancestors of the focus window are traced down and tried to see if they have -any passive grabs to be activated. If the focus window itself is reached and -it's descendants contain they pointer, the ancestors of the window that the -pointer is in are then traced down starting at the focus window, otherwise no -grabs are activated. If the event is a pointer event, the ancestors of the -window that the pointer is in are traced down starting at the root until -CheckPassiveGrabs causes a passive grab to activate or all the windows are -tried. PRH -*/ - -Bool -CheckDeviceGrabs(device, xE, checkFirst, count) - register DeviceIntPtr device; - register xEvent *xE; - int checkFirst; - int count; -{ - register int i; - register WindowPtr pWin = NULL; - register FocusClassPtr focus = device->focus; - - if ((xE->u.u.type == ButtonPress -#ifdef XINPUT - || xE->u.u.type == DeviceButtonPress -#endif - ) && device->button->buttonsDown != 1) - return FALSE; - - i = checkFirst; - - if (focus) - { - for (; i < focus->traceGood; i++) - { - pWin = focus->trace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - if ((focus->win == NoneWin) || - (i >= spriteTraceGood) || - ((i > checkFirst) && (pWin != spriteTrace[i-1]))) - return FALSE; - } - - for (; i < spriteTraceGood; i++) - { - pWin = spriteTrace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - return FALSE; -} - -void -DeliverFocusedEvent(keybd, xE, window, count) - xEvent *xE; - DeviceIntPtr keybd; - WindowPtr window; - int count; -{ - WindowPtr focus = keybd->focus->win; - int mskidx = 0; - - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - if (!focus) - return; - if (focus == PointerRootWin) - { - DeliverDeviceEvents(window, xE, NullGrab, NullWindow, keybd, count); - return; - } - if ((focus == window) || IsParent(focus, window)) - { - if (DeliverDeviceEvents(window, xE, NullGrab, focus, keybd, count)) - return; - } - /* just deliver it to the focus window */ - FixUpEventFromWindow(xE, focus, None, FALSE); - if (xE->u.u.type & EXTENSION_EVENT_BASE) - mskidx = keybd->id; - (void)DeliverEventsToWindow(focus, xE, count, filters[xE->u.u.type], - NullGrab, mskidx); -} - -void -DeliverGrabbedEvent(xE, thisDev, deactivateGrab, count) - register xEvent *xE; - register DeviceIntPtr thisDev; - Bool deactivateGrab; - int count; -{ - register GrabPtr grab = thisDev->grab; - int deliveries = 0; - register DeviceIntPtr dev; - register xEvent *dxE; - - if (grab->ownerEvents) - { - WindowPtr focus; - - if (thisDev->focus) - { - focus = thisDev->focus->win; - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - } - else - focus = PointerRootWin; - if (focus == PointerRootWin) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, NullWindow, - thisDev, count); - else if (focus && (focus == sprite.win || IsParent(focus, sprite.win))) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, focus, - thisDev, count); - else if (focus) - deliveries = DeliverDeviceEvents(focus, xE, grab, focus, - thisDev, count); - } - if (!deliveries) - { - FixUpEventFromWindow(xE, grab->window, None, TRUE); - deliveries = TryClientEvents(rClient(grab), xE, count, - (Mask)grab->eventMask, - filters[xE->u.u.type], grab); - if (deliveries && (xE->u.u.type == MotionNotify -#ifdef XINPUT - || xE->u.u.type == DeviceMotionNotify -#endif - )) - thisDev->valuator->motionHintWindow = grab->window; - } - if (deliveries && !deactivateGrab && (xE->u.u.type != MotionNotify -#ifdef XINPUT - && xE->u.u.type != DeviceMotionNotify -#endif - )) - switch (thisDev->sync.state) - { - case FREEZE_BOTH_NEXT_EVENT: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - FreezeThaw(dev, TRUE); - if ((dev->sync.state == FREEZE_BOTH_NEXT_EVENT) && - (CLIENT_BITS(dev->grab->resource) == - CLIENT_BITS(thisDev->grab->resource))) - dev->sync.state = FROZEN_NO_EVENT; - else - dev->sync.other = thisDev->grab; - } - /* fall through */ - case FREEZE_NEXT_EVENT: - thisDev->sync.state = FROZEN_WITH_EVENT; - FreezeThaw(thisDev, TRUE); - if (thisDev->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - thisDev->sync.event = (xEvent *)xrealloc(thisDev->sync.event, - count*sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - thisDev->sync.evcount = count; - for (dxE = thisDev->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - break; - } -} - -void -#ifdef XKB -CoreProcessKeyboardEvent (xE, keybd, count) -#else -ProcessKeyboardEvent (xE, keybd, count) -#endif - register xEvent *xE; - register DeviceIntPtr keybd; - int count; -{ - int key, bit; - register BYTE *kptr; - register int i; - register CARD8 modifiers; - register CARD16 mask; - GrabPtr grab = keybd->grab; - Bool deactivateGrab = FALSE; - register KeyClassPtr keyc = keybd->key; - - if (!syncEvents.playingEvents) - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } - XE_KBPTR.state = (keyc->state | inputInfo.pointer->button->state); - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - modifiers = keyc->modifierMap[key]; -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("CoreProcessKbdEvent: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - if (*kptr & bit) /* allow ddx to generate multiple downs */ - { - if (!modifiers) - { - xE->u.u.type = KeyRelease; - (*keybd->public.processInputProc)(xE, keybd, count); - xE->u.u.type = KeyPress; - /* release can have side effects, don't fall through */ - (*keybd->public.processInputProc)(xE, keybd, count); - } - return; - } - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr |= bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) - { - /* This key affects modifier "i" */ - keyc->modifierKeyCount[i]++; - keyc->state |= mask; - modifiers &= ~mask; - } - } - if (!grab && CheckDeviceGrabs(keybd, xE, 0, count)) - { - keybd->activatingKey = key; - return; - } - break; - case KeyRelease: - if (!(*kptr & bit)) /* guard against duplicates */ - return; - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr &= ~bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) { - /* This key affects modifier "i" */ - if (--keyc->modifierKeyCount[i] <= 0) { - keyc->state &= ~mask; - keyc->modifierKeyCount[i] = 0; - } - modifiers &= ~mask; - } - } - if (keybd->fromPassiveGrab && (key == keybd->activatingKey)) - deactivateGrab = TRUE; - break; - default: - FatalError("Impossible keyboard event"); - } - if (grab) - DeliverGrabbedEvent(xE, keybd, deactivateGrab, count); - else - DeliverFocusedEvent(keybd, xE, sprite.win, count); - if (deactivateGrab) - (*keybd->DeactivateGrab)(keybd); -} - -#ifdef XKB -/* This function is used to set the key pressed or key released state - - this is only used when the pressing of keys does not cause - CoreProcessKeyEvent to be called, as in for example Mouse Keys. -*/ -void -FixKeyState (xE, keybd) - register xEvent *xE; - register DeviceIntPtr keybd; -{ - int key, bit; - register BYTE *kptr; - register KeyClassPtr keyc = keybd->key; - - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("FixKeyState: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - *kptr |= bit; - break; - case KeyRelease: - *kptr &= ~bit; - break; - default: - FatalError("Impossible keyboard event"); - } -} -#endif - -void -#ifdef XKB -CoreProcessPointerEvent (xE, mouse, count) -#else -ProcessPointerEvent (xE, mouse, count) -#endif - register xEvent *xE; - register DeviceIntPtr mouse; - int count; -{ - register GrabPtr grab = mouse->grab; - Bool deactivateGrab = FALSE; - register ButtonClassPtr butc = mouse->button; -#ifdef XKB - XkbSrvInfoPtr xkbi= inputInfo.keyboard->key->xkbInfo; -#endif - - if (!syncEvents.playingEvents) - NoticeTime(xE) - XE_KBPTR.state = (butc->state | ( -#ifdef XKB - (noXkbExtension ? - inputInfo.keyboard->key->state : - xkbi->state.grab_mods) -#else - inputInfo.keyboard->key->state -#endif - )); - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* see comment in EnqueueEvents regarding the next three lines */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } - if (xE->u.u.type != MotionNotify) - { - register int key; - register BYTE *kptr; - int bit; - - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - - key = xE->u.u.detail; - kptr = &butc->down[key >> 3]; - bit = 1 << (key & 7); - switch (xE->u.u.type) - { - case ButtonPress: - mouse->valuator->motionHintWindow = NullWindow; - if (!(*kptr & bit)) - butc->buttonsDown++; - butc->motionMask = ButtonMotionMask; - *kptr |= bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - if (xE->u.u.detail == 0) - return; - if (xE->u.u.detail <= 5) - butc->state |= (Button1Mask >> 1) << xE->u.u.detail; - filters[MotionNotify] = Motion_Filter(butc); - if (!grab) - if (CheckDeviceGrabs(mouse, xE, 0, count)) - return; - break; - case ButtonRelease: - mouse->valuator->motionHintWindow = NullWindow; - if (*kptr & bit) - --butc->buttonsDown; - if (!butc->buttonsDown) - butc->motionMask = 0; - *kptr &= ~bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - if (xE->u.u.detail == 0) - return; - if (xE->u.u.detail <= 5) - butc->state &= ~((Button1Mask >> 1) << xE->u.u.detail); - filters[MotionNotify] = Motion_Filter(butc); - if (!butc->state && mouse->fromPassiveGrab) - deactivateGrab = TRUE; - break; - default: - FatalError("bogus pointer event from ddx"); - } - } - else if (!CheckMotion(xE)) - return; - if (grab) - DeliverGrabbedEvent(xE, mouse, deactivateGrab, count); - else - DeliverDeviceEvents(sprite.win, xE, NullGrab, NullWindow, - mouse, count); - if (deactivateGrab) - (*mouse->DeactivateGrab)(mouse); -} - -#define AtMostOneClient \ - (SubstructureRedirectMask | ResizeRedirectMask | ButtonPressMask) - -void -RecalculateDeliverableEvents(pWin) - register WindowPtr pWin; -{ - register OtherClients *others; - register WindowPtr pChild; - - pChild = pWin; - while (1) - { - if (pChild->optional) - { - pChild->optional->otherEventMasks = 0; - for (others = wOtherClients(pChild); others; others = others->next) - { - pChild->optional->otherEventMasks |= others->mask; - } - } - pChild->deliverableEvents = pChild->eventMask| - wOtherEventMasks(pChild); - if (pChild->parent) - pChild->deliverableEvents |= - (pChild->parent->deliverableEvents & - ~wDontPropagateMask(pChild) & PropagateMask); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -int -OtherClientGone(value, id) - pointer value; /* must conform to DeleteType */ - XID id; -{ - register OtherClientsPtr other, prev; - register WindowPtr pWin = (WindowPtr)value; - - prev = 0; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->resource == id) - { - if (prev) - prev->next = other->next; - else - { - if (!(pWin->optional->otherClients = other->next)) - CheckWindowOptionalNeed (pWin); - } - xfree(other); - RecalculateDeliverableEvents(pWin); - return(Success); - } - prev = other; - } - FatalError("client not on event list"); - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} - -int -EventSelectForWindow(pWin, client, mask) - register WindowPtr pWin; - register ClientPtr client; - Mask mask; -{ - Mask check; - OtherClients * others; - - if (mask & ~AllEventMasks) - { - client->errorValue = mask; - return BadValue; - } - check = (mask & AtMostOneClient); - if (check & (pWin->eventMask|wOtherEventMasks(pWin))) - { /* It is illegal for two different - clients to select on any of the - events for AtMostOneClient. However, - it is OK, for some client to - continue selecting on one of those - events. */ - if ((wClient(pWin) != client) && (check & pWin->eventMask)) - return BadAccess; - for (others = wOtherClients (pWin); others; others = others->next) - { - if (!SameClient(others, client) && (check & others->mask)) - return BadAccess; - } - } - if (wClient (pWin) == client) - { - check = pWin->eventMask; -#ifdef SGIMISC - pWin->eventMask = - (mask & ~SGIMiscSpecialDestroyMask) | (pWin->eventMask & SGIMiscSpecialDestroyMask); -#else - pWin->eventMask = mask; -#endif - } - else - { - for (others = wOtherClients (pWin); others; others = others->next) - { - if (SameClient(others, client)) - { - check = others->mask; -#ifdef SGIMISC - mask = (mask & ~SGIMiscSpecialDestroyMask) | (others->mask & SGIMiscSpecialDestroyMask); -#endif - if (mask == 0) - { - FreeResource(others->resource, RT_NONE); - return Success; - } - else - others->mask = mask; - goto maskSet; - } - } - check = 0; - if (!pWin->optional && !MakeWindowOptional (pWin)) - return BadAlloc; - others = (OtherClients *) xalloc(sizeof(OtherClients)); - if (!others) - return BadAlloc; - others->mask = mask; - others->resource = FakeClientID(client->index); - others->next = pWin->optional->otherClients; - pWin->optional->otherClients = others; - if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer)pWin)) - return BadAlloc; - } -maskSet: - if ((inputInfo.pointer->valuator->motionHintWindow == pWin) && - (mask & PointerMotionHintMask) && - !(check & PointerMotionHintMask) && - !inputInfo.pointer->grab) - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - RecalculateDeliverableEvents(pWin); - return Success; -} - -/*ARGSUSED*/ -int -EventSuppressForWindow(pWin, client, mask, checkOptional) - register WindowPtr pWin; - register ClientPtr client; - Mask mask; - Bool *checkOptional; -{ - register int i, free; - - if ((mask & ~PropagateMask) && !permitOldBugs) - { - client->errorValue = mask; - return BadValue; - } - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - if (!mask) - i = 0; - else - { - for (i = DNPMCOUNT, free = 0; --i > 0; ) - { - if (!DontPropagateRefCnts[i]) - free = i; - else if (mask == DontPropagateMasks[i]) - break; - } - if (!i && free) - { - i = free; - DontPropagateMasks[i] = mask; - } - } - if (i || !mask) - { - pWin->dontPropagate = i; - if (i) - DontPropagateRefCnts[i]++; - if (pWin->optional) - { - pWin->optional->dontPropagateMask = mask; - *checkOptional = TRUE; - } - } - else - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]++; - return BadAlloc; - } - pWin->dontPropagate = 0; - pWin->optional->dontPropagateMask = mask; - } - RecalculateDeliverableEvents(pWin); - return Success; -} - -static WindowPtr -#if NeedFunctionPrototypes -CommonAncestor( - register WindowPtr a, - register WindowPtr b) -#else -CommonAncestor(a, b) - register WindowPtr a, b; -#endif -{ - for (b = b->parent; b; b = b->parent) - if (IsParent(b, a)) return b; - return NullWindow; -} - -static void -#if NeedFunctionPrototypes -EnterLeaveEvent( - int type, - int mode, - int detail, - register WindowPtr pWin, - Window child) -#else -EnterLeaveEvent(type, mode, detail, pWin, child) - int type, mode, detail; - register WindowPtr pWin; - Window child; -#endif -{ - xEvent event; - register DeviceIntPtr keybd = inputInfo.keyboard; - WindowPtr focus; - register DeviceIntPtr mouse = inputInfo.pointer; - register GrabPtr grab = mouse->grab; - Mask mask; - - if ((pWin == mouse->valuator->motionHintWindow) && - (detail != NotifyInferior)) - mouse->valuator->motionHintWindow = NullWindow; - if (grab) - { - mask = (pWin == grab->window) ? grab->eventMask : 0; - if (grab->ownerEvents) - mask |= EventMaskForClient(pWin, rClient(grab)); - } - else - { - mask = pWin->eventMask | wOtherEventMasks(pWin); - } - if (mask & filters[type]) - { - event.u.u.type = type; - event.u.u.detail = detail; - event.u.enterLeave.time = currentTime.milliseconds; - event.u.enterLeave.rootX = sprite.hot.x; - event.u.enterLeave.rootY = sprite.hot.y; - /* Counts on the same initial structure of crossing & button events! */ - FixUpEventFromWindow(&event, pWin, None, FALSE); - /* Enter/Leave events always set child */ - event.u.enterLeave.child = child; - event.u.enterLeave.flags = event.u.keyButtonPointer.sameScreen ? - ELFlagSameScreen : 0; -#ifdef XKB - if (!noXkbExtension) { - event.u.enterLeave.state = mouse->button->state & 0x1f00; - event.u.enterLeave.state |= - XkbGrabStateFromRec(&keybd->key->xkbInfo->state); - } else -#endif - event.u.enterLeave.state = keybd->key->state | mouse->button->state; - event.u.enterLeave.mode = mode; - focus = keybd->focus->win; - if ((focus != NoneWin) && - ((pWin == focus) || (focus == PointerRootWin) || - IsParent(focus, pWin))) - event.u.enterLeave.flags |= ELFlagFocus; - if (grab) - (void)TryClientEvents(rClient(grab), &event, 1, mask, - filters[type], grab); - else - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], - NullGrab, 0); - } - if ((type == EnterNotify) && (mask & KeymapStateMask)) - { - xKeymapEvent ke; - -#ifdef XCSECURITY - ClientPtr client = grab ? rClient(grab) - : clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, keybd, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31); - ke.type = KeymapNotify; - if (grab) - (void)TryClientEvents(rClient(grab), (xEvent *)&ke, 1, mask, - KeymapStateMask, grab); - else - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - -static void -#if NeedFunctionPrototypes -EnterNotifies(WindowPtr ancestor, WindowPtr child, int mode, int detail) -#else -EnterNotifies(ancestor, child, mode, detail) - WindowPtr ancestor, child; - int mode, detail; -#endif -{ - WindowPtr parent = child->parent; - - if (ancestor == parent) - return; - EnterNotifies(ancestor, parent, mode, detail); - EnterLeaveEvent(EnterNotify, mode, detail, parent, child->drawable.id); -} - -static void -#if NeedFunctionPrototypes -LeaveNotifies(WindowPtr child, WindowPtr ancestor, int mode, int detail) -#else -LeaveNotifies(child, ancestor, mode, detail) - WindowPtr child, ancestor; - int detail, mode; -#endif -{ - register WindowPtr pWin; - - if (ancestor == child) - return; - for (pWin = child->parent; pWin != ancestor; pWin = pWin->parent) - { - EnterLeaveEvent(LeaveNotify, mode, detail, pWin, child->drawable.id); - child = pWin; - } -} - -static void -#if NeedFunctionPrototypes -DoEnterLeaveEvents(WindowPtr fromWin, WindowPtr toWin, int mode) -#else -DoEnterLeaveEvents(fromWin, toWin, mode) - WindowPtr fromWin, toWin; - int mode; -#endif -{ - if (fromWin == toWin) - return; - if (IsParent(fromWin, toWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyInferior, fromWin, None); - EnterNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyAncestor, toWin, None); - } - else if (IsParent(toWin, fromWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyAncestor, fromWin, None); - LeaveNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyInferior, toWin, None); - } - else - { /* neither fromWin nor toWin is descendent of the other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - EnterLeaveEvent(LeaveNotify, mode, NotifyNonlinear, fromWin, None); - LeaveNotifies(fromWin, common, mode, NotifyNonlinearVirtual); - EnterNotifies(common, toWin, mode, NotifyNonlinearVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyNonlinear, toWin, None); - } -} - -static void -#if NeedFunctionPrototypes -FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, register WindowPtr pWin) -#else -FocusEvent(dev, type, mode, detail, pWin) - DeviceIntPtr dev; - int type, mode, detail; - register WindowPtr pWin; -#endif -{ - xEvent event; - -#ifdef XINPUT - if (dev != inputInfo.keyboard) - { - DeviceFocusEvent(dev, type, mode, detail, pWin); - return; - } -#endif - event.u.focus.mode = mode; - event.u.u.type = type; - event.u.u.detail = detail; - event.u.focus.window = pWin->drawable.id; - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], NullGrab, - 0); - if ((type == FocusIn) && - ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) - { - xKeymapEvent ke; -#ifdef XCSECURITY - ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, dev, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31); - ke.type = KeymapNotify; - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - - /* - * recursive because it is easier - * no-op if child not descended from ancestor - */ -static Bool -#if NeedFunctionPrototypes -FocusInEvents( - DeviceIntPtr dev, - WindowPtr ancestor, WindowPtr child, WindowPtr skipChild, - int mode, int detail, - Bool doAncestor) -#else -FocusInEvents(dev, ancestor, child, skipChild, mode, detail, doAncestor) - DeviceIntPtr dev; - WindowPtr ancestor, child, skipChild; - int mode, detail; - Bool doAncestor; -#endif -{ - if (child == NullWindow) - return ancestor == NullWindow; - if (ancestor == child) - { - if (doAncestor) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - if (FocusInEvents(dev, ancestor, child->parent, skipChild, mode, detail, - doAncestor)) - { - if (child != skipChild) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - return FALSE; -} - -/* dies horribly if ancestor is not an ancestor of child */ -static void -#if NeedFunctionPrototypes -FocusOutEvents( - DeviceIntPtr dev, - WindowPtr child, WindowPtr ancestor, - int mode, int detail, - Bool doAncestor) -#else -FocusOutEvents(dev, child, ancestor, mode, detail, doAncestor) - DeviceIntPtr dev; - WindowPtr child, ancestor; - int mode; - int detail; - Bool doAncestor; -#endif -{ - register WindowPtr pWin; - - for (pWin = child; pWin != ancestor; pWin = pWin->parent) - FocusEvent(dev, FocusOut, mode, detail, pWin); - if (doAncestor) - FocusEvent(dev, FocusOut, mode, detail, ancestor); -} - -void -DoFocusEvents(dev, fromWin, toWin, mode) - DeviceIntPtr dev; - WindowPtr fromWin, toWin; - int mode; -{ - int out, in; /* for holding details for to/from - PointerRoot/None */ - int i; - - if (fromWin == toWin) - return; - out = (fromWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - in = (toWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - /* wrong values if neither, but then not referenced */ - - if ((toWin == NullWindow) || (toWin == PointerRootWin)) - { - if ((fromWin == NullWindow) || (fromWin == PointerRootWin)) - { - if (fromWin == PointerRootWin) - FocusOutEvents(dev, sprite.win, ROOT, mode, NotifyPointer, - TRUE); - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusOut, mode, out, WindowTable[0]); - else -#endif - for (i=0; iparent, NullWindow, mode, - NotifyNonlinearVirtual, FALSE); - } - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusIn, mode, in, WindowTable[0]); - else -#endif - for (i=0; iparent != NullWindow) - (void)FocusInEvents(dev, ROOT, toWin, toWin, mode, - NotifyNonlinearVirtual, TRUE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, mode, - NotifyPointer, FALSE); - } - else - { - if (IsParent(toWin, fromWin)) - { - FocusEvent(dev, FocusOut, mode, NotifyAncestor, fromWin); - FocusOutEvents(dev, fromWin->parent, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyInferior, toWin); - if ((IsParent(toWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(fromWin, sprite.win)) && - (!IsParent(sprite.win, fromWin))) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - else - if (IsParent(fromWin, toWin)) - { - if ((IsParent(fromWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(toWin, sprite.win)) && - (!IsParent(sprite.win, toWin))) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyInferior, fromWin); - (void)FocusInEvents(dev, fromWin, toWin, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyAncestor, toWin); - } - else - { - /* neither fromWin or toWin is child of other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - if (IsParent(fromWin, sprite.win)) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyNonlinear, fromWin); - if (fromWin->parent != NullWindow) - FocusOutEvents(dev, fromWin->parent, common, mode, - NotifyNonlinearVirtual, FALSE); - if (toWin->parent != NullWindow) - (void)FocusInEvents(dev, common, toWin, toWin, mode, - NotifyNonlinearVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - } - } -} - -int -#if NeedFunctionPrototypes -SetInputFocus( - ClientPtr client, - DeviceIntPtr dev, - Window focusID, - CARD8 revertTo, - Time ctime, - Bool followOK) -#else -SetInputFocus(client, dev, focusID, revertTo, ctime, followOK) - ClientPtr client; - DeviceIntPtr dev; - Window focusID; - CARD8 revertTo; - Time ctime; - Bool followOK; -#endif -{ - register FocusClassPtr focus; - register WindowPtr focusWin; - int mode; - TimeStamp time; - - UpdateCurrentTime(); - if ((revertTo != RevertToParent) && - (revertTo != RevertToPointerRoot) && - (revertTo != RevertToNone) && - ((revertTo != RevertToFollowKeyboard) || !followOK)) - { - client->errorValue = revertTo; - return BadValue; - } - time = ClientTimeToServerTime(ctime); - if ((focusID == None) || (focusID == PointerRoot)) - focusWin = (WindowPtr)(long)focusID; - else if ((focusID == FollowKeyboard) && followOK) - focusWin = inputInfo.keyboard->focus->win; - else if (!(focusWin = SecurityLookupWindow(focusID, client, - SecurityReadAccess))) - return BadWindow; - else - { - /* It is a match error to try to set the input focus to an - unviewable window. */ - - if(!focusWin->realized) - return(BadMatch); - } - focus = dev->focus; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, focus->time) == EARLIER)) - return Success; - mode = (dev->grab) ? NotifyWhileGrabbed : NotifyNormal; - if (focus->win == FollowKeyboardWin) - DoFocusEvents(dev, inputInfo.keyboard->focus->win, focusWin, mode); - else - DoFocusEvents(dev, focus->win, focusWin, mode); - focus->time = time; - focus->revert = revertTo; - if (focusID == FollowKeyboard) - focus->win = FollowKeyboardWin; - else - focus->win = focusWin; - if ((focusWin == NoneWin) || (focusWin == PointerRootWin)) - focus->traceGood = 0; - else - { - int depth = 0; - register WindowPtr pWin; - - for (pWin = focusWin; pWin; pWin = pWin->parent) depth++; - if (depth > focus->traceSize) - { - focus->traceSize = depth+1; - Must_have_memory = TRUE; /* XXX */ - focus->trace = (WindowPtr *)xrealloc(focus->trace, - focus->traceSize * - sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - focus->traceGood = depth; - for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) - focus->trace[depth] = pWin; - } - return Success; -} - -int -ProcSetInputFocus(client) - ClientPtr client; -{ - REQUEST(xSetInputFocusReq); - - REQUEST_SIZE_MATCH(xSetInputFocusReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - return Success; -#endif - return SetInputFocus(client, inputInfo.keyboard, stuff->focus, - stuff->revertTo, stuff->time, FALSE); -} - -int -ProcGetInputFocus(client) - ClientPtr client; -{ - xGetInputFocusReply rep; - /* REQUEST(xReq); */ - FocusClassPtr focus = inputInfo.keyboard->focus; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (focus->win == NoneWin) - rep.focus = None; - else if (focus->win == PointerRootWin) - rep.focus = PointerRoot; - else rep.focus = focus->win->drawable.id; - rep.revertTo = focus->revert; - WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep); - return Success; -} - -int -ProcGrabPointer(client) - ClientPtr client; -{ - xGrabPointerReply rep; - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - WindowPtr pWin, confineTo; - CursorPtr cursor, oldCursor; - REQUEST(xGrabPointerReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xGrabPointerReq); - UpdateCurrentTime(); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else - { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - /* at this point, some sort of reply is guaranteed. */ - time = ClientTimeToServerTime(stuff->time); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - grab = device->grab; - if ((grab) && !SameClient(grab, client)) - rep.status = AlreadyGrabbed; - else if ((!pWin->realized) || - (confineTo && - !(confineTo->realized && BorderSizeNotEmpty(confineTo)))) - rep.status = GrabNotViewable; - else if (device->sync.frozen && - device->sync.other && !SameClient(device->sync.other, client)) - rep.status = GrabFrozen; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - rep.status = GrabInvalidTime; - else - { - GrabRec tempGrab; - - oldCursor = NullCursor; - if (grab) - { - if (grab->confineTo && !confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - oldCursor = grab->cursor; - } - tempGrab.cursor = cursor; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = stuff->ownerEvents; - tempGrab.eventMask = stuff->eventMask; - tempGrab.confineTo = confineTo; - tempGrab.window = pWin; - tempGrab.keyboardMode = stuff->keyboardMode; - tempGrab.pointerMode = stuff->pointerMode; - tempGrab.device = device; - (*device->ActivateGrab)(device, &tempGrab, time, FALSE); - if (oldCursor) - FreeCursor (oldCursor, (Cursor)0); - rep.status = GrabSuccess; - } - WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep); - return Success; -} - -int -ProcChangeActivePointerGrab(client) - ClientPtr client; -{ - DeviceIntPtr device = inputInfo.pointer; - register GrabPtr grab = device->grab; - CursorPtr newCursor, oldCursor; - REQUEST(xChangeActivePointerGrabReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq); - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - if (stuff->cursor == None) - newCursor = NullCursor; - else - { - newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!newCursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - if (!grab) - return Success; - if (!SameClient(grab, client)) - return Success; - time = ClientTimeToServerTime(stuff->time); - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - return Success; - oldCursor = grab->cursor; - grab->cursor = newCursor; - if (newCursor) - newCursor->refcnt++; - PostNewCursor(); - if (oldCursor) - FreeCursor(oldCursor, (Cursor)0); - grab->eventMask = stuff->eventMask; - return Success; -} - -int -ProcUngrabPointer(client) - ClientPtr client; -{ - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->DeactivateGrab)(device); - return Success; -} - -int -GrabDevice(client, dev, this_mode, other_mode, grabWindow, ownerEvents, ctime, - mask, status) - register ClientPtr client; - register DeviceIntPtr dev; - unsigned this_mode; - unsigned other_mode; - Window grabWindow; - unsigned ownerEvents; - Time ctime; - Mask mask; - CARD8 *status; -{ - register WindowPtr pWin; - register GrabPtr grab; - TimeStamp time; - - UpdateCurrentTime(); - if ((this_mode != GrabModeSync) && (this_mode != GrabModeAsync)) - { - client->errorValue = this_mode; - return BadValue; - } - if ((other_mode != GrabModeSync) && (other_mode != GrabModeAsync)) - { - client->errorValue = other_mode; - return BadValue; - } - if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) - { - client->errorValue = ownerEvents; - return BadValue; - } - pWin = SecurityLookupWindow(grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - time = ClientTimeToServerTime(ctime); - grab = dev->grab; - if (grab && !SameClient(grab, client)) - *status = AlreadyGrabbed; - else if (!pWin->realized) - *status = GrabNotViewable; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, dev->grabTime) == EARLIER)) - *status = GrabInvalidTime; - else if (dev->sync.frozen && - dev->sync.other && !SameClient(dev->sync.other, client)) - *status = GrabFrozen; - else - { - GrabRec tempGrab; - - tempGrab.window = pWin; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = ownerEvents; - tempGrab.keyboardMode = this_mode; - tempGrab.pointerMode = other_mode; - tempGrab.eventMask = mask; - tempGrab.device = dev; - (*dev->ActivateGrab)(dev, &tempGrab, time, FALSE); - *status = GrabSuccess; - } - return Success; -} - -int -ProcGrabKeyboard(client) - ClientPtr client; -{ - xGrabKeyboardReply rep; - REQUEST(xGrabKeyboardReq); - int result; - - REQUEST_SIZE_MATCH(xGrabKeyboardReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - { - result = Success; - rep.status = AlreadyGrabbed; - } - else -#endif - result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode, - stuff->pointerMode, stuff->grabWindow, - stuff->ownerEvents, stuff->time, - KeyPressMask | KeyReleaseMask, &rep.status); - if (result != Success) - return result; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep); - return Success; -} - -int -ProcUngrabKeyboard(client) - ClientPtr client; -{ - DeviceIntPtr device = inputInfo.keyboard; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->DeactivateGrab)(device); - return Success; -} - -int -ProcQueryPointer(client) - ClientPtr client; -{ - xQueryPointerReply rep; - WindowPtr pWin, t; - REQUEST(xResourceReq); - DeviceIntPtr mouse = inputInfo.pointer; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = SecurityLookupWindow(stuff->id, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (mouse->valuator->motionHintWindow) - MaybeStopHint(mouse, client); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.mask = mouse->button->state | inputInfo.keyboard->key->state; - rep.length = 0; - rep.root = (ROOT)->drawable.id; - rep.rootX = sprite.hot.x; - rep.rootY = sprite.hot.y; - rep.child = None; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - rep.sameScreen = xTrue; - rep.winX = sprite.hot.x - pWin->drawable.x; - rep.winY = sprite.hot.y - pWin->drawable.y; - for (t = sprite.win; t; t = t->parent) - if (t->parent == pWin) - { - rep.child = t->drawable.id; - break; - } - } - else - { - rep.sameScreen = xFalse; - rep.winX = 0; - rep.winY = 0; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - rep.rootX += panoramiXdataPtr[0].x; - rep.rootY += panoramiXdataPtr[0].y; - if(stuff->id == rep.root) { - rep.winX += panoramiXdataPtr[0].x; - rep.winY += panoramiXdataPtr[0].y; - } - } -#endif - - WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep); - - return(Success); -} - -void -InitEvents() -{ - int i; - - sprite.hot.pScreen = sprite.hotPhys.pScreen = (ScreenPtr)NULL; - inputInfo.numDevices = 0; - inputInfo.devices = (DeviceIntPtr)NULL; - inputInfo.off_devices = (DeviceIntPtr)NULL; - inputInfo.keyboard = (DeviceIntPtr)NULL; - inputInfo.pointer = (DeviceIntPtr)NULL; - if (spriteTraceSize == 0) - { - spriteTraceSize = 32; - spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr)); - if (!spriteTrace) - FatalError("failed to allocate spriteTrace"); - } - spriteTraceGood = 0; - lastEventMask = OwnerGrabButtonMask; - filters[MotionNotify] = PointerMotionMask; - sprite.win = NullWindow; - sprite.current = NullCursor; - sprite.hotLimits.x1 = 0; - sprite.hotLimits.y1 = 0; - sprite.hotLimits.x2 = 0; - sprite.hotLimits.y2 = 0; - sprite.confined = FALSE; - syncEvents.replayDev = (DeviceIntPtr)NULL; - syncEvents.replayWin = NullWindow; - while (syncEvents.pending) - { - QdEventPtr next = syncEvents.pending->next; - xfree(syncEvents.pending); - syncEvents.pending = next; - } - syncEvents.pendtail = &syncEvents.pending; - syncEvents.playingEvents = FALSE; - syncEvents.time.months = 0; - syncEvents.time.milliseconds = 0; /* hardly matters */ - currentTime.months = 0; - currentTime.milliseconds = GetTimeInMillis(); - lastDeviceEventTime = currentTime; - for (i = 0; i < DNPMCOUNT; i++) - { - DontPropagateMasks[i] = 0; - DontPropagateRefCnts[i] = 0; - } -} - -void -CloseDownEvents(void) -{ - xfree(spriteTrace); - spriteTrace = NULL; - spriteTraceSize = 0; -} - -int -ProcSendEvent(client) - ClientPtr client; -{ - WindowPtr pWin; - WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */ - REQUEST(xSendEventReq); - - REQUEST_SIZE_MATCH(xSendEventReq); - - /* The client's event type must be a core event type or one defined by an - extension. */ - - if ( ! ((stuff->event.u.u.type > X_Reply && - stuff->event.u.u.type < LASTEvent) || - (stuff->event.u.u.type >= EXTENSION_EVENT_BASE && - stuff->event.u.u.type < (unsigned)lastEvent))) - { - client->errorValue = stuff->event.u.u.type; - return BadValue; - } - if (stuff->event.u.u.type == ClientMessage && - stuff->event.u.u.detail != 8 && - stuff->event.u.u.detail != 16 && - stuff->event.u.u.detail != 32 && - !permitOldBugs) - { - client->errorValue = stuff->event.u.u.detail; - return BadValue; - } - if ((stuff->eventMask & ~AllEventMasks) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - - if (stuff->destination == PointerWindow) - pWin = sprite.win; - else if (stuff->destination == InputFocus) - { - WindowPtr inputFocus = inputInfo.keyboard->focus->win; - - if (inputFocus == NoneWin) - return Success; - - /* If the input focus is PointerRootWin, send the event to where - the pointer is if possible, then perhaps propogate up to root. */ - if (inputFocus == PointerRootWin) - inputFocus = ROOT; - - if (IsParent(inputFocus, sprite.win)) - { - effectiveFocus = inputFocus; - pWin = sprite.win; - } - else - effectiveFocus = pWin = inputFocus; - } - else - pWin = SecurityLookupWindow(stuff->destination, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue)) - { - client->errorValue = stuff->propagate; - return BadValue; - } - stuff->event.u.u.type |= 0x80; - if (stuff->propagate) - { - for (;pWin; pWin = pWin->parent) - { - if (DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0)) - return Success; - if (pWin == effectiveFocus) - return Success; - stuff->eventMask &= ~wDontPropagateMask(pWin); - if (!stuff->eventMask) - break; - } - } - else - (void)DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0); - return Success; -} - -int -ProcUngrabKey(client) - ClientPtr client; -{ - REQUEST(xUngrabKeyReq); - WindowPtr pWin; - GrabRec tempGrab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xUngrabKeyReq); - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - tempGrab.resource = client->clientAsMask; - tempGrab.device = keybd; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = KeyPress; - tempGrab.detail.exact = stuff->key; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -int -ProcGrabKey(client) - ClientPtr client; -{ - WindowPtr pWin; - REQUEST(xGrabKeyReq); - GrabPtr grab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xGrabKeyReq); - if ((stuff->ownerEvents != xTrue) && (stuff->ownerEvents != xFalse)) - { - client->errorValue = stuff->ownerEvents; - return(BadValue); - } - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - grab = CreateGrab(client->index, keybd, pWin, - (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents, - (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode, - keybd, stuff->modifiers, KeyPress, stuff->key, - NullWindow, NullCursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - - -int -ProcGrabButton(client) - ClientPtr client; -{ - WindowPtr pWin, confineTo; - REQUEST(xGrabButtonReq); - CursorPtr cursor; - GrabPtr grab; - - REQUEST_SIZE_MATCH(xGrabButtonReq); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - - - grab = CreateGrab(client->index, inputInfo.pointer, pWin, - permitOldBugs ? (Mask)(stuff->eventMask | - ButtonPressMask | ButtonReleaseMask) : - (Mask)stuff->eventMask, - (Bool)stuff->ownerEvents, (Bool) stuff->keyboardMode, - (Bool)stuff->pointerMode, inputInfo.keyboard, stuff->modifiers, - ButtonPress, stuff->button, confineTo, cursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - -int -ProcUngrabButton(client) - ClientPtr client; -{ - REQUEST(xUngrabButtonReq); - WindowPtr pWin; - GrabRec tempGrab; - - REQUEST_SIZE_MATCH(xUngrabButtonReq); - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - tempGrab.resource = client->clientAsMask; - tempGrab.device = inputInfo.pointer; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = ButtonPress; - tempGrab.detail.exact = stuff->button; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -void -DeleteWindowFromAnyEvents(pWin, freeResources) - WindowPtr pWin; - Bool freeResources; -{ - WindowPtr parent; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - FocusClassPtr focus = keybd->focus; - OtherClientsPtr oc; - GrabPtr passive; - - - /* Deactivate any grabs performed on this window, before making any - input focus changes. */ - - if (mouse->grab && - ((mouse->grab->window == pWin) || (mouse->grab->confineTo == pWin))) - (*mouse->DeactivateGrab)(mouse); - - /* Deactivating a keyboard grab should cause focus events. */ - - if (keybd->grab && (keybd->grab->window == pWin)) - (*keybd->DeactivateGrab)(keybd); - - /* If the focus window is a root window (ie. has no parent) then don't - delete the focus from it. */ - - if ((pWin == focus->win) && (pWin->parent != NullWindow)) - { - int focusEventMode = NotifyNormal; - - /* If a grab is in progress, then alter the mode of focus events. */ - - if (keybd->grab) - focusEventMode = NotifyWhileGrabbed; - - switch (focus->revert) - { - case RevertToNone: - DoFocusEvents(keybd, pWin, NoneWin, focusEventMode); - focus->win = NoneWin; - focus->traceGood = 0; - break; - case RevertToParent: - parent = pWin; - do - { - parent = parent->parent; - focus->traceGood--; - } while (!parent->realized -/* This would be a good protocol change -- windows being reparented - during SaveSet processing would cause the focus to revert to the - nearest enclosing window which will survive the death of the exiting - client, instead of ending up reverting to a dying window and thence - to None - */ -#ifdef NOTDEF - || clients[CLIENT_ID(parent->drawable.id)]->clientGone -#endif - ); - DoFocusEvents(keybd, pWin, parent, focusEventMode); - focus->win = parent; - focus->revert = RevertToNone; - break; - case RevertToPointerRoot: - DoFocusEvents(keybd, pWin, PointerRootWin, focusEventMode); - focus->win = PointerRootWin; - focus->traceGood = 0; - break; - } - } - - if (mouse->valuator->motionHintWindow == pWin) - mouse->valuator->motionHintWindow = NullWindow; - - if (freeResources) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - while ( (oc = wOtherClients(pWin)) ) - FreeResource(oc->resource, RT_NONE); - while ( (passive = wPassiveGrabs(pWin)) ) - FreeResource(passive->resource, RT_NONE); - } -#ifdef XINPUT - DeleteWindowFromAnyExtEvents(pWin, freeResources); -#endif -} - -/* Call this whenever some window at or below pWin has changed geometry */ - -/*ARGSUSED*/ -void -CheckCursorConfinement(pWin) - WindowPtr pWin; -{ - GrabPtr grab = inputInfo.pointer->grab; - WindowPtr confineTo; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) return; -#endif - - if (grab && (confineTo = grab->confineTo)) - { - if (!BorderSizeNotEmpty(confineTo)) - (*inputInfo.pointer->DeactivateGrab)(inputInfo.pointer); - else if ((pWin == confineTo) || IsParent(pWin, confineTo)) - ConfineCursorToWindow(confineTo, TRUE, TRUE); - } -} - -Mask -EventMaskForClient(pWin, client) - WindowPtr pWin; - ClientPtr client; -{ - register OtherClientsPtr other; - - if (wClient (pWin) == client) - return pWin->eventMask; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (SameClient(other, client)) - return other->mask; - } - return 0; -} - -int -ProcRecolorCursor(client) - ClientPtr client; -{ - CursorPtr pCursor; - int nscr; - ScreenPtr pscr; - Bool displayed; - REQUEST(xRecolorCursorReq); - - REQUEST_SIZE_MATCH(xRecolorCursorReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityWriteAccess); - if ( !pCursor) - { - client->errorValue = stuff->cursor; - return (BadCursor); - } - - pCursor->foreRed = stuff->foreRed; - pCursor->foreGreen = stuff->foreGreen; - pCursor->foreBlue = stuff->foreBlue; - - pCursor->backRed = stuff->backRed; - pCursor->backGreen = stuff->backGreen; - pCursor->backBlue = stuff->backBlue; - - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { - pscr = screenInfo.screens[nscr]; -#ifdef PANORAMIX - if(!noPanoramiXExtension) - displayed = (pscr == sprite.screen); - else -#endif - displayed = (pscr == sprite.hotPhys.pScreen); - ( *pscr->RecolorCursor)(pscr, pCursor, - (pCursor == sprite.current) && displayed); - } - return (Success); -} - -void -WriteEventsToClient(pClient, count, events) - ClientPtr pClient; - int count; - xEvent *events; -{ -#ifdef PANORAMIX - xEvent eventCopy; -#endif - xEvent eventTo, *eventFrom; - int i; - -#ifdef XKB - if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events))) - return; -#endif - -#ifdef PANORAMIX - if(!noPanoramiXExtension && - (panoramiXdataPtr[0].x || panoramiXdataPtr[0].y)) - { - switch(events->u.u.type) { - case MotionNotify: - case ButtonPress: - case ButtonRelease: - case KeyPress: - case KeyRelease: - case EnterNotify: - case LeaveNotify: - /* - When multiple clients want the same event DeliverEventsToWindow - passes the same event structure multiple times so we can't - modify the one passed to us - */ - count = 1; /* should always be 1 */ - memcpy(&eventCopy, events, sizeof(xEvent)); - eventCopy.u.keyButtonPointer.rootX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.rootY += panoramiXdataPtr[0].y; - if(eventCopy.u.keyButtonPointer.event == - eventCopy.u.keyButtonPointer.root) - { - eventCopy.u.keyButtonPointer.eventX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.eventY += panoramiXdataPtr[0].y; - } - events = &eventCopy; - break; - default: break; - } - } -#endif - - if (EventCallback) - { - EventInfoRec eventinfo; - eventinfo.client = pClient; - eventinfo.events = events; - eventinfo.count = count; - CallCallbacks(&EventCallback, (pointer)&eventinfo); - } - if(pClient->swapped) - { - for(i = 0; i < count; i++) - { - eventFrom = &events[i]; - /* Remember to strip off the leading bit of type in case - this event was sent with "SendEvent." */ - (*EventSwapVector[eventFrom->u.u.type & 0177]) - (eventFrom, &eventTo); - (void)WriteToClient(pClient, sizeof(xEvent), (char *)&eventTo); - } - } - else - { - (void)WriteToClient(pClient, count * sizeof(xEvent), (char *) events); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXextension.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXextension.c.NX.original deleted file mode 100644 index 1d86bf870..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXextension.c.NX.original +++ /dev/null @@ -1,528 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXextension.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/extension.c,v 3.12 2002/02/19 11:09:22 alanh Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: extension.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "X.h" -#define NEED_EVENTS -#define NEED_REPLIES -#include "Xproto.h" -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "gcstruct.h" -#include "scrnintstr.h" -#include "../../dix/dispatch.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif -#ifdef LBX -#include "lbxserve.h" -#endif - -#include "Trap.h" - -#define EXTENSION_BASE 128 -#define EXTENSION_EVENT_BASE 64 -#define LAST_EVENT 128 -#define LAST_ERROR 255 - -ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS]; - -static ExtensionEntry **extensions = (ExtensionEntry **)NULL; - -int lastEvent = EXTENSION_EVENT_BASE; -static int lastError = FirstExtensionError; -static unsigned int NumExtensions = 0; - -ExtensionEntry * -AddExtension(char *name, int NumEvents, int NumErrors, - int (*MainProc)(ClientPtr c1), - int (*SwappedMainProc)(ClientPtr c2), - void (*CloseDownProc)(ExtensionEntry *e), - unsigned short (*MinorOpcodeProc)(ClientPtr c3)) -{ - int i; - register ExtensionEntry *ext, **newexts; - - if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc) - return((ExtensionEntry *) NULL); - if ((lastEvent + NumEvents > LAST_EVENT) || - (unsigned)(lastError + NumErrors > LAST_ERROR)) - return((ExtensionEntry *) NULL); - - ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry)); - if (!ext) - return((ExtensionEntry *) NULL); - ext->name = (char *)xalloc(strlen(name) + 1); - ext->num_aliases = 0; - ext->aliases = (char **)NULL; - if (!ext->name) - { - xfree(ext); - return((ExtensionEntry *) NULL); - } - strcpy(ext->name, name); - i = NumExtensions; - newexts = (ExtensionEntry **) xrealloc(extensions, - (i + 1) * sizeof(ExtensionEntry *)); - if (!newexts) - { - xfree(ext->name); - xfree(ext); - return((ExtensionEntry *) NULL); - } - NumExtensions++; - extensions = newexts; - extensions[i] = ext; - ext->index = i; - ext->base = i + EXTENSION_BASE; - ext->CloseDown = CloseDownProc; - ext->MinorOpcode = MinorOpcodeProc; - ProcVector[i + EXTENSION_BASE] = MainProc; - SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc; - if (NumEvents) - { - ext->eventBase = lastEvent; - ext->eventLast = lastEvent + NumEvents; - lastEvent += NumEvents; - } - else - { - ext->eventBase = 0; - ext->eventLast = 0; - } - if (NumErrors) - { - ext->errorBase = lastError; - ext->errorLast = lastError + NumErrors; - lastError += NumErrors; - } - else - { - ext->errorBase = 0; - ext->errorLast = 0; - } -#ifdef XCSECURITY - ext->secure = FALSE; -#endif - -#ifdef LBX - (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase); -#endif - return(ext); -} - -Bool AddExtensionAlias(alias, ext) - char *alias; - ExtensionEntry *ext; -{ - char *name; - char **aliases; - - aliases = (char **)xrealloc(ext->aliases, - (ext->num_aliases + 1) * sizeof(char *)); - if (!aliases) - return FALSE; - ext->aliases = aliases; - name = (char *)xalloc(strlen(alias) + 1); - if (!name) - return FALSE; - strcpy(name, alias); - ext->aliases[ext->num_aliases] = name; - ext->num_aliases++; -#ifdef LBX - return LbxAddExtensionAlias(ext->index, alias); -#else - return TRUE; -#endif -} - -static int -FindExtension(char *extname, int len) -{ - int i, j; - - for (i=0; iname) == len) && - !strncmp(extname, extensions[i]->name, len)) - break; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - if ((strlen(extensions[i]->aliases[j]) == len) && - !strncmp(extname, extensions[i]->aliases[j], len)) - break; - } - if (j >= 0) break; - } - return ((i == NumExtensions) ? -1 : i); -} - -/* - * CheckExtension returns the extensions[] entry for the requested - * extension name. Maybe this could just return a Bool instead? - */ -ExtensionEntry * -CheckExtension(const char *extname) -{ - int n; - - n = FindExtension((char*)extname, strlen(extname)); - if (n != -1) - return extensions[n]; - else - return NULL; -} - -void -DeclareExtensionSecurity(extname, secure) - char *extname; - Bool secure; -{ -#ifdef XCSECURITY - int i = FindExtension(extname, strlen(extname)); - if (i >= 0) - { - int majorop = extensions[i]->base; - extensions[i]->secure = secure; - if (secure) - { - UntrustedProcVector[majorop] = ProcVector[majorop]; - SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop]; - } - else - { - UntrustedProcVector[majorop] = ProcBadRequest; - SwappedUntrustedProcVector[majorop] = ProcBadRequest; - } - } -#endif -#ifdef LBX - LbxDeclareExtensionSecurity(extname, secure); -#endif -} - -unsigned short -StandardMinorOpcode(client) - ClientPtr client; -{ - return ((xReq *)client->requestBuffer)->data; -} - -unsigned short -MinorOpcodeOfRequest(client) - ClientPtr client; -{ - unsigned char major; - - major = ((xReq *)client->requestBuffer)->reqType; - if (major < EXTENSION_BASE) - return 0; - major -= EXTENSION_BASE; - if (major >= NumExtensions) - return 0; - return (*extensions[major]->MinorOpcode)(client); -} - -void -CloseDownExtensions() -{ - register int i,j; - -#ifdef LBX - LbxCloseDownExtensions(); -#endif - - for (i = NumExtensions - 1; i >= 0; i--) - { - (* extensions[i]->CloseDown)(extensions[i]); - NumExtensions = i; - xfree(extensions[i]->name); - for (j = extensions[i]->num_aliases; --j >= 0;) - xfree(extensions[i]->aliases[j]); - xfree(extensions[i]->aliases); - xfree(extensions[i]); - } - xfree(extensions); - extensions = (ExtensionEntry **)NULL; - lastEvent = EXTENSION_EVENT_BASE; - lastError = FirstExtensionError; - for (i=0; inum) - { - spentry->num--; - xfree(spentry->procList[spentry->num].name); - } - xfree(spentry->procList); - spentry->procList = (ProcEntryPtr)NULL; - } -} - - -int -ProcQueryExtension(client) - ClientPtr client; -{ - xQueryExtensionReply reply; - int i; - REQUEST(xQueryExtensionReq); - - REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes); - - reply.type = X_Reply; - reply.length = 0; - reply.major_opcode = 0; - reply.sequenceNumber = client->sequence; - - if ( ! NumExtensions ) - reply.present = xFalse; - else - { - i = FindExtension((char *)&stuff[1], stuff->nbytes); - if (i < 0 - - /* - * Hide RENDER if our implementation - * is faulty. - */ - - || (nxagentRenderTrap && strcmp(extensions[i]->name, "RENDER") == 0) -#ifdef XCSECURITY - /* don't show insecure extensions to untrusted clients */ - || (client->trustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) -#endif - ) - reply.present = xFalse; - else - { - reply.present = xTrue; - reply.major_opcode = extensions[i]->base; - reply.first_event = extensions[i]->eventBase; - reply.first_error = extensions[i]->errorBase; - } - } - WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply); - return(client->noClientException); -} - -int -ProcListExtensions(client) - ClientPtr client; -{ - xListExtensionsReply reply; - char *bufptr, *buffer; - int total_length = 0; - - REQUEST_SIZE_MATCH(xReq); - - reply.type = X_Reply; - reply.nExtensions = 0; - reply.length = 0; - reply.sequenceNumber = client->sequence; - buffer = NULL; - - if ( NumExtensions ) - { - register int i, j; - - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - /* - * Hide RENDER if our implementation - * is faulty. - */ - - if (nxagentRenderTrap && strcmp(extensions[i]->name, "RENDER") == 0) - continue; - - total_length += strlen(extensions[i]->name) + 1; - reply.nExtensions += 1 + extensions[i]->num_aliases; - for (j = extensions[i]->num_aliases; --j >= 0;) - total_length += strlen(extensions[i]->aliases[j]) + 1; - } - reply.length = (total_length + 3) >> 2; - buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length); - if (!buffer) - return(BadAlloc); - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - *bufptr++ = len = strlen(extensions[i]->name); - memmove(bufptr, extensions[i]->name, len); - bufptr += len; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - *bufptr++ = len = strlen(extensions[i]->aliases[j]); - memmove(bufptr, extensions[i]->aliases[j], len); - bufptr += len; - } - } - } - WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply); - if (reply.length) - { - WriteToClient(client, total_length, buffer); - DEALLOCATE_LOCAL(buffer); - } - return(client->noClientException); -} - - -ExtensionLookupProc -LookupProc(name, pGC) - char *name; - GCPtr pGC; -{ - register int i; - register ScreenProcEntry *spentry; - spentry = &AuxillaryScreenProcs[pGC->pScreen->myNum]; - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - return(spentry->procList[i].proc); - } - return (ExtensionLookupProc)NULL; -} - -Bool -RegisterProc(name, pGC, proc) - char *name; - GC *pGC; - ExtensionLookupProc proc; -{ - return RegisterScreenProc(name, pGC->pScreen, proc); -} - -Bool -RegisterScreenProc(name, pScreen, proc) - char *name; - ScreenPtr pScreen; - ExtensionLookupProc proc; -{ - register ScreenProcEntry *spentry; - register ProcEntryPtr procEntry = (ProcEntryPtr)NULL; - char *newname; - int i; - - spentry = &AuxillaryScreenProcs[pScreen->myNum]; - /* first replace duplicates */ - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - { - procEntry = &spentry->procList[i]; - break; - } - } - if (procEntry) - procEntry->proc = proc; - else - { - newname = (char *)xalloc(strlen(name)+1); - if (!newname) - return FALSE; - procEntry = (ProcEntryPtr) - xrealloc(spentry->procList, - sizeof(ProcEntryRec) * (spentry->num+1)); - if (!procEntry) - { - xfree(newname); - return FALSE; - } - spentry->procList = procEntry; - procEntry += spentry->num; - procEntry->name = newname; - strcpy(newname, name); - procEntry->proc = proc; - spentry->num++; - } - return TRUE; -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXextension.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXextension.c.XF86.original deleted file mode 100644 index 36f053f02..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXextension.c.XF86.original +++ /dev/null @@ -1,486 +0,0 @@ -/* $XFree86: xc/programs/Xserver/dix/extension.c,v 3.12 2002/02/19 11:09:22 alanh Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: extension.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "X.h" -#define NEED_EVENTS -#define NEED_REPLIES -#include "Xproto.h" -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "gcstruct.h" -#include "scrnintstr.h" -#include "dispatch.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif -#ifdef LBX -#include "lbxserve.h" -#endif - -#define EXTENSION_BASE 128 -#define EXTENSION_EVENT_BASE 64 -#define LAST_EVENT 128 -#define LAST_ERROR 255 - -ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS]; - -static ExtensionEntry **extensions = (ExtensionEntry **)NULL; - -int lastEvent = EXTENSION_EVENT_BASE; -static int lastError = FirstExtensionError; -static unsigned int NumExtensions = 0; - -ExtensionEntry * -AddExtension(char *name, int NumEvents, int NumErrors, - int (*MainProc)(ClientPtr c1), - int (*SwappedMainProc)(ClientPtr c2), - void (*CloseDownProc)(ExtensionEntry *e), - unsigned short (*MinorOpcodeProc)(ClientPtr c3)) -{ - int i; - register ExtensionEntry *ext, **newexts; - - if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc) - return((ExtensionEntry *) NULL); - if ((lastEvent + NumEvents > LAST_EVENT) || - (unsigned)(lastError + NumErrors > LAST_ERROR)) - return((ExtensionEntry *) NULL); - - ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry)); - if (!ext) - return((ExtensionEntry *) NULL); - ext->name = (char *)xalloc(strlen(name) + 1); - ext->num_aliases = 0; - ext->aliases = (char **)NULL; - if (!ext->name) - { - xfree(ext); - return((ExtensionEntry *) NULL); - } - strcpy(ext->name, name); - i = NumExtensions; - newexts = (ExtensionEntry **) xrealloc(extensions, - (i + 1) * sizeof(ExtensionEntry *)); - if (!newexts) - { - xfree(ext->name); - xfree(ext); - return((ExtensionEntry *) NULL); - } - NumExtensions++; - extensions = newexts; - extensions[i] = ext; - ext->index = i; - ext->base = i + EXTENSION_BASE; - ext->CloseDown = CloseDownProc; - ext->MinorOpcode = MinorOpcodeProc; - ProcVector[i + EXTENSION_BASE] = MainProc; - SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc; - if (NumEvents) - { - ext->eventBase = lastEvent; - ext->eventLast = lastEvent + NumEvents; - lastEvent += NumEvents; - } - else - { - ext->eventBase = 0; - ext->eventLast = 0; - } - if (NumErrors) - { - ext->errorBase = lastError; - ext->errorLast = lastError + NumErrors; - lastError += NumErrors; - } - else - { - ext->errorBase = 0; - ext->errorLast = 0; - } -#ifdef XCSECURITY - ext->secure = FALSE; -#endif - -#ifdef LBX - (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase); -#endif - return(ext); -} - -Bool AddExtensionAlias(alias, ext) - char *alias; - ExtensionEntry *ext; -{ - char *name; - char **aliases; - - aliases = (char **)xrealloc(ext->aliases, - (ext->num_aliases + 1) * sizeof(char *)); - if (!aliases) - return FALSE; - ext->aliases = aliases; - name = (char *)xalloc(strlen(alias) + 1); - if (!name) - return FALSE; - strcpy(name, alias); - ext->aliases[ext->num_aliases] = name; - ext->num_aliases++; -#ifdef LBX - return LbxAddExtensionAlias(ext->index, alias); -#else - return TRUE; -#endif -} - -static int -FindExtension(char *extname, int len) -{ - int i, j; - - for (i=0; iname) == len) && - !strncmp(extname, extensions[i]->name, len)) - break; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - if ((strlen(extensions[i]->aliases[j]) == len) && - !strncmp(extname, extensions[i]->aliases[j], len)) - break; - } - if (j >= 0) break; - } - return ((i == NumExtensions) ? -1 : i); -} - -/* - * CheckExtension returns the extensions[] entry for the requested - * extension name. Maybe this could just return a Bool instead? - */ -ExtensionEntry * -CheckExtension(const char *extname) -{ - int n; - - n = FindExtension((char*)extname, strlen(extname)); - if (n != -1) - return extensions[n]; - else - return NULL; -} - -void -DeclareExtensionSecurity(extname, secure) - char *extname; - Bool secure; -{ -#ifdef XCSECURITY - int i = FindExtension(extname, strlen(extname)); - if (i >= 0) - { - int majorop = extensions[i]->base; - extensions[i]->secure = secure; - if (secure) - { - UntrustedProcVector[majorop] = ProcVector[majorop]; - SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop]; - } - else - { - UntrustedProcVector[majorop] = ProcBadRequest; - SwappedUntrustedProcVector[majorop] = ProcBadRequest; - } - } -#endif -#ifdef LBX - LbxDeclareExtensionSecurity(extname, secure); -#endif -} - -unsigned short -StandardMinorOpcode(client) - ClientPtr client; -{ - return ((xReq *)client->requestBuffer)->data; -} - -unsigned short -MinorOpcodeOfRequest(client) - ClientPtr client; -{ - unsigned char major; - - major = ((xReq *)client->requestBuffer)->reqType; - if (major < EXTENSION_BASE) - return 0; - major -= EXTENSION_BASE; - if (major >= NumExtensions) - return 0; - return (*extensions[major]->MinorOpcode)(client); -} - -void -CloseDownExtensions() -{ - register int i,j; - -#ifdef LBX - LbxCloseDownExtensions(); -#endif - - for (i = NumExtensions - 1; i >= 0; i--) - { - (* extensions[i]->CloseDown)(extensions[i]); - NumExtensions = i; - xfree(extensions[i]->name); - for (j = extensions[i]->num_aliases; --j >= 0;) - xfree(extensions[i]->aliases[j]); - xfree(extensions[i]->aliases); - xfree(extensions[i]); - } - xfree(extensions); - extensions = (ExtensionEntry **)NULL; - lastEvent = EXTENSION_EVENT_BASE; - lastError = FirstExtensionError; - for (i=0; inum) - { - spentry->num--; - xfree(spentry->procList[spentry->num].name); - } - xfree(spentry->procList); - spentry->procList = (ProcEntryPtr)NULL; - } -} - - -int -ProcQueryExtension(client) - ClientPtr client; -{ - xQueryExtensionReply reply; - int i; - REQUEST(xQueryExtensionReq); - - REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes); - - reply.type = X_Reply; - reply.length = 0; - reply.major_opcode = 0; - reply.sequenceNumber = client->sequence; - - if ( ! NumExtensions ) - reply.present = xFalse; - else - { - i = FindExtension((char *)&stuff[1], stuff->nbytes); - if (i < 0 -#ifdef XCSECURITY - /* don't show insecure extensions to untrusted clients */ - || (client->trustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) -#endif - ) - reply.present = xFalse; - else - { - reply.present = xTrue; - reply.major_opcode = extensions[i]->base; - reply.first_event = extensions[i]->eventBase; - reply.first_error = extensions[i]->errorBase; - } - } - WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply); - return(client->noClientException); -} - -int -ProcListExtensions(client) - ClientPtr client; -{ - xListExtensionsReply reply; - char *bufptr, *buffer; - int total_length = 0; - - REQUEST_SIZE_MATCH(xReq); - - reply.type = X_Reply; - reply.nExtensions = 0; - reply.length = 0; - reply.sequenceNumber = client->sequence; - buffer = NULL; - - if ( NumExtensions ) - { - register int i, j; - - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - total_length += strlen(extensions[i]->name) + 1; - reply.nExtensions += 1 + extensions[i]->num_aliases; - for (j = extensions[i]->num_aliases; --j >= 0;) - total_length += strlen(extensions[i]->aliases[j]) + 1; - } - reply.length = (total_length + 3) >> 2; - buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length); - if (!buffer) - return(BadAlloc); - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - *bufptr++ = len = strlen(extensions[i]->name); - memmove(bufptr, extensions[i]->name, len); - bufptr += len; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - *bufptr++ = len = strlen(extensions[i]->aliases[j]); - memmove(bufptr, extensions[i]->aliases[j], len); - bufptr += len; - } - } - } - WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply); - if (reply.length) - { - WriteToClient(client, total_length, buffer); - DEALLOCATE_LOCAL(buffer); - } - return(client->noClientException); -} - - -ExtensionLookupProc -LookupProc(name, pGC) - char *name; - GCPtr pGC; -{ - register int i; - register ScreenProcEntry *spentry; - spentry = &AuxillaryScreenProcs[pGC->pScreen->myNum]; - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - return(spentry->procList[i].proc); - } - return (ExtensionLookupProc)NULL; -} - -Bool -RegisterProc(name, pGC, proc) - char *name; - GC *pGC; - ExtensionLookupProc proc; -{ - return RegisterScreenProc(name, pGC->pScreen, proc); -} - -Bool -RegisterScreenProc(name, pScreen, proc) - char *name; - ScreenPtr pScreen; - ExtensionLookupProc proc; -{ - register ScreenProcEntry *spentry; - register ProcEntryPtr procEntry = (ProcEntryPtr)NULL; - char *newname; - int i; - - spentry = &AuxillaryScreenProcs[pScreen->myNum]; - /* first replace duplicates */ - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - { - procEntry = &spentry->procList[i]; - break; - } - } - if (procEntry) - procEntry->proc = proc; - else - { - newname = (char *)xalloc(strlen(name)+1); - if (!newname) - return FALSE; - procEntry = (ProcEntryPtr) - xrealloc(spentry->procList, - sizeof(ProcEntryRec) * (spentry->num+1)); - if (!procEntry) - { - xfree(newname); - return FALSE; - } - spentry->procList = procEntry; - procEntry += spentry->num; - procEntry->name = newname; - strcpy(newname, name); - procEntry->proc = proc; - spentry->num++; - } - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.NX.original deleted file mode 100644 index fe2f4aa6c..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.NX.original +++ /dev/null @@ -1,550 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXglxext.c" - -#else - -/* $XFree86: xc/programs/Xserver/GL/glx/glxext.c,v 1.8 2001/08/23 18:25:40 alanh Exp $ -** The contents of this file are subject to the GLX Public License Version 1.0 -** (the "License"). You may not use this file except in compliance with the -** License. You may obtain a copy of the License at Silicon Graphics, Inc., -** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043 -** or at http://www.sgi.com/software/opensource/glx/license.html. -** -** Software distributed under the License is distributed on an "AS IS" -** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY -** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR -** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific -** language governing rights and limitations under the License. -** -** The Original Software is GLX version 1.2 source code, released February, -** 1999. The developer of the Original Software is Silicon Graphics, Inc. -** Those portions of the Subject Software created by Silicon Graphics, Inc. -** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved. -** -*/ - -#define NEED_REPLIES -#include "glxserver.h" -#include -#include -#include -#include "g_disptab.h" -#include "unpack.h" -#include "glxutil.h" -#include "glxext.h" -#include "micmap.h" - -#include "Trap.h" - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -extern __GLXextensionInfo __glDDXExtensionInfo; - -__GLXextensionInfo *__glXExt = &__glDDXExtensionInfo; - -/* -** Forward declarations. -*/ -static int __glXSwapDispatch(ClientPtr); -static int __glXDispatch(ClientPtr); - -/* -** Called when the extension is reset. -*/ -static void ResetExtension(ExtensionEntry* extEntry) -{ - __glXFlushContextCache(); - (*__glXExt->resetExtension)(); - __glXScreenReset(); -} - -/* -** Initialize the per-client context storage. -*/ -static void ResetClientState(int clientIndex) -{ - __GLXclientState *cl = __glXClients[clientIndex]; - - if (cl->returnBuf) __glXFree(cl->returnBuf); - if (cl->largeCmdBuf) __glXFree(cl->largeCmdBuf); - if (cl->currentContexts) __glXFree(cl->currentContexts); - __glXMemset(cl, 0, sizeof(__GLXclientState)); - /* - ** By default, assume that the client supports - ** GLX major version 1 minor version 0 protocol. - */ - cl->GLClientmajorVersion = 1; - cl->GLClientminorVersion = 0; - if (cl->GLClientextensions) __glXFree(cl->GLClientextensions); - -} - -/* -** Reset state used to keep track of large (multi-request) commands. -*/ -void __glXResetLargeCommandStatus(__GLXclientState *cl) -{ - cl->largeCmdBytesSoFar = 0; - cl->largeCmdBytesTotal = 0; - cl->largeCmdRequestsSoFar = 0; - cl->largeCmdRequestsTotal = 0; -} - -/* -** This procedure is called when the client who created the context goes -** away OR when glXDestroyContext is called. In either case, all we do is -** flag that the ID is no longer valid, and (maybe) free the context. -** use. -*/ -static int ContextGone(__GLXcontext* cx, XID id) -{ - cx->idExists = GL_FALSE; - if (!cx->isCurrent) { - __glXFreeContext(cx); - } - - return True; -} - -/* -** Free a client's state. -*/ -static int ClientGone(int clientIndex, XID id) -{ - __GLXcontext *cx; - __GLXclientState *cl = __glXClients[clientIndex]; - int i; - - if (cl) { - /* - ** Free all the contexts that are current for this client. - */ - for (i=0; i < cl->numCurrentContexts; i++) { - cx = cl->currentContexts[i]; - if (cx) { - __glXDeassociateContext(cx, cx->glxPriv); - cx->isCurrent = GL_FALSE; - if (!cx->idExists) { - __glXFreeContext(cx); - } - } - } - /* - ** Re-initialize the client state structure. Don't free it because - ** we'll probably get another client with this index and use the struct - ** again. There is a maximum of MAXCLIENTS of these structures. - */ - ResetClientState(clientIndex); - } - - return True; -} - -/* -** Free a GLX Pixmap. -*/ -static int PixmapGone(__GLXpixmap *pGlxPixmap, XID id) -{ - PixmapPtr pPixmap = (PixmapPtr) pGlxPixmap->pDraw; - - pGlxPixmap->idExists = False; - if (!pGlxPixmap->refcnt) { - /* - ** The DestroyPixmap routine should decrement the refcount and free - ** only if it's zero. - */ - (*pGlxPixmap->pScreen->DestroyPixmap)(pPixmap); - __glXFree(pGlxPixmap); - } - - return True; -} - -/* -** Free a context. -*/ -GLboolean __glXFreeContext(__GLXcontext *cx) -{ - if (cx->idExists || cx->isCurrent) return GL_FALSE; - - if (!cx->isDirect) { - if ((*cx->gc->exports.destroyContext)((__GLcontext *)cx->gc) == GL_FALSE) { - return GL_FALSE; - } - } - if (cx->feedbackBuf) __glXFree(cx->feedbackBuf); - if (cx->selectBuf) __glXFree(cx->selectBuf); - __glXFree(cx); - if (cx == __glXLastContext) { - __glXFlushContextCache(); - } - - return GL_TRUE; -} - -/************************************************************************/ - -/* -** These routines can be used to check whether a particular GL command -** has caused an error. Specifically, we use them to check whether a -** given query has caused an error, in which case a zero-length data -** reply is sent to the client. -*/ - -static GLboolean errorOccured = GL_FALSE; - -/* -** The GL was will call this routine if an error occurs. -*/ -void __glXErrorCallBack(__GLinterface *gc, GLenum code) -{ - errorOccured = GL_TRUE; -} - -/* -** Clear the error flag before calling the GL command. -*/ -void __glXClearErrorOccured(void) -{ - errorOccured = GL_FALSE; -} - -/* -** Check if the GL command caused an error. -*/ -GLboolean __glXErrorOccured(void) -{ - return errorOccured; -} - -/************************************************************************/ - -/* -** Initialize the GLX extension. -*/ -void GlxExtensionInit(void) -{ - ExtensionEntry *extEntry; - int i; - -#ifdef X11R5 - __glXContextRes = CreateNewResourceType(ContextGone); - __glXClientRes = CreateNewResourceType(ClientGone); - __glXPixmapRes = CreateNewResourceType(PixmapGone); -#else - __glXContextRes = CreateNewResourceType((DeleteType)ContextGone); - __glXClientRes = CreateNewResourceType((DeleteType)ClientGone); - __glXPixmapRes = CreateNewResourceType((DeleteType)PixmapGone); -#endif - - /* - ** Add extension to server extensions. - */ - extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS, - __GLX_NUMBER_ERRORS, __glXDispatch, - __glXSwapDispatch, ResetExtension, - StandardMinorOpcode); - if (!extEntry) { - FatalError("__glXExtensionInit: AddExtensions failed\n"); - return; - } - if (!AddExtensionAlias(GLX_EXTENSION_ALIAS, extEntry)) { - ErrorF("__glXExtensionInit: AddExtensionAlias failed\n"); - return; - } - - __glXBadContext = extEntry->errorBase + GLXBadContext; - __glXBadContextState = extEntry->errorBase + GLXBadContextState; - __glXBadDrawable = extEntry->errorBase + GLXBadDrawable; - __glXBadPixmap = extEntry->errorBase + GLXBadPixmap; - __glXBadContextTag = extEntry->errorBase + GLXBadContextTag; - __glXBadCurrentWindow = extEntry->errorBase + GLXBadCurrentWindow; - __glXBadRenderRequest = extEntry->errorBase + GLXBadRenderRequest; - __glXBadLargeRequest = extEntry->errorBase + GLXBadLargeRequest; - __glXUnsupportedPrivateRequest = extEntry->errorBase + - GLXUnsupportedPrivateRequest; - - /* - ** Initialize table of client state. There is never a client 0. - */ - for (i=1; i <= MAXCLIENTS; i++) { - __glXClients[i] = 0; - } - - /* - ** Initialize screen specific data. - */ - __glXScreenInit(screenInfo.numScreens); -} - -/************************************************************************/ - -Bool __glXCoreType(void) -{ - return __glXExt->type; -} - -/************************************************************************/ - -void GlxSetVisualConfigs(int nconfigs, - __GLXvisualConfig *configs, void **privates) -{ - (*__glXExt->setVisualConfigs)(nconfigs, configs, privates); -} - -static miInitVisualsProcPtr saveInitVisualsProc; - -Bool GlxInitVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, - int *rootDepthp, VisualID *defaultVisp, - unsigned long sizes, int bitsPerRGB, - int preferredVis) -{ - Bool ret; - - if (saveInitVisualsProc) { - ret = saveInitVisualsProc(visualp, depthp, nvisualp, ndepthp, - rootDepthp, defaultVisp, sizes, bitsPerRGB, - preferredVis); - if (!ret) - return False; - } - (*__glXExt->initVisuals)(visualp, depthp, nvisualp, ndepthp, rootDepthp, - defaultVisp, sizes, bitsPerRGB); - return True; -} - -void -GlxWrapInitVisuals(miInitVisualsProcPtr *initVisProc) -{ - saveInitVisualsProc = *initVisProc; - *initVisProc = GlxInitVisuals; -} - -/************************************************************************/ - -void __glXFlushContextCache(void) -{ - __glXLastContext = 0; -} - -/* -** Make a context the current one for the GL (in this implementation, there -** is only one instance of the GL, and we use it to serve all GL clients by -** switching it between different contexts). While we are at it, look up -** a context by its tag and return its (__GLXcontext *). -*/ -__GLXcontext *__glXForceCurrent(__GLXclientState *cl, GLXContextTag tag, - int *error) -{ - __GLXcontext *cx; - - /* - ** See if the context tag is legal; it is managed by the extension, - ** so if it's invalid, we have an implementation error. - */ - cx = (__GLXcontext *) __glXLookupContextByTag(cl, tag); - if (!cx) { - cl->client->errorValue = tag; - *error = __glXBadContextTag; - return 0; - } - - if (!cx->isDirect) { - if (cx->glxPriv == NULL) { - /* - ** The drawable has vanished. It must be a window, because only - ** windows can be destroyed from under us; GLX pixmaps are - ** refcounted and don't go away until no one is using them. - */ - *error = __glXBadCurrentWindow; - return 0; - } - } - - if (cx == __glXLastContext) { - /* No need to re-bind */ - return cx; - } - - /* Make this context the current one for the GL. */ - if (!cx->isDirect) { - if (!(*cx->gc->exports.forceCurrent)((__GLcontext *)cx->gc)) { - /* Bind failed, and set the error code. Bummer */ - cl->client->errorValue = cx->id; - *error = __glXBadContextState; - return 0; - } - } - __glXLastContext = cx; - return cx; -} - -/************************************************************************/ - -/* -** Top level dispatcher; all commands are executed from here down. -*/ -static int __glXDispatch(ClientPtr client) -{ - int result; - - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** If we're expecting a glXRenderLarge request, this better be one. - */ - if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) { - client->errorValue = stuff->glxCode; - return __glXBadLargeRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSingleTable[opcode]; - - /* - * Report upstream that we are - * dispatching a GLX operation. - */ - - nxagentGlxTrap = 1; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Going to dispatch GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - result = (*proc)(cl, (GLbyte *) stuff); - - nxagentGlxTrap = 0; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Dispatched GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - return result; -} - -static int __glXSwapDispatch(ClientPtr client) -{ - int result; - - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSwapSingleTable[opcode]; - - /* - * Report upstream that we are - * dispatching a GLX operation. - */ - - nxagentGlxTrap = 1; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Going to dispatch GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - result = (*proc)(cl, (GLbyte *) stuff); - - nxagentGlxTrap = 0; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Dispatched GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - return result; -} - -int __glXNoSuchSingleOpcode(__GLXclientState *cl, GLbyte *pc) -{ - return BadRequest; -} - -void __glXNoSuchRenderOpcode(GLbyte *pc) -{ - return; -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.XF86.original deleted file mode 100644 index 95a9c2e6e..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglxext.c.XF86.original +++ /dev/null @@ -1,489 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/glx/glxext.c,v 1.8 2001/08/23 18:25:40 alanh Exp $ -** The contents of this file are subject to the GLX Public License Version 1.0 -** (the "License"). You may not use this file except in compliance with the -** License. You may obtain a copy of the License at Silicon Graphics, Inc., -** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043 -** or at http://www.sgi.com/software/opensource/glx/license.html. -** -** Software distributed under the License is distributed on an "AS IS" -** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY -** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR -** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific -** language governing rights and limitations under the License. -** -** The Original Software is GLX version 1.2 source code, released February, -** 1999. The developer of the Original Software is Silicon Graphics, Inc. -** Those portions of the Subject Software created by Silicon Graphics, Inc. -** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved. -** -*/ - -#define NEED_REPLIES -#include "glxserver.h" -#include -#include -#include -#include "g_disptab.h" -#include "unpack.h" -#include "glxutil.h" -#include "glxext.h" -#include "micmap.h" - - -extern __GLXextensionInfo __glDDXExtensionInfo; - -__GLXextensionInfo *__glXExt = &__glDDXExtensionInfo; - -/* -** Forward declarations. -*/ -static int __glXSwapDispatch(ClientPtr); -static int __glXDispatch(ClientPtr); - -/* -** Called when the extension is reset. -*/ -static void ResetExtension(ExtensionEntry* extEntry) -{ - __glXFlushContextCache(); - (*__glXExt->resetExtension)(); - __glXScreenReset(); -} - -/* -** Initialize the per-client context storage. -*/ -static void ResetClientState(int clientIndex) -{ - __GLXclientState *cl = __glXClients[clientIndex]; - - if (cl->returnBuf) __glXFree(cl->returnBuf); - if (cl->largeCmdBuf) __glXFree(cl->largeCmdBuf); - if (cl->currentContexts) __glXFree(cl->currentContexts); - __glXMemset(cl, 0, sizeof(__GLXclientState)); - /* - ** By default, assume that the client supports - ** GLX major version 1 minor version 0 protocol. - */ - cl->GLClientmajorVersion = 1; - cl->GLClientminorVersion = 0; - if (cl->GLClientextensions) __glXFree(cl->GLClientextensions); - -} - -/* -** Reset state used to keep track of large (multi-request) commands. -*/ -void __glXResetLargeCommandStatus(__GLXclientState *cl) -{ - cl->largeCmdBytesSoFar = 0; - cl->largeCmdBytesTotal = 0; - cl->largeCmdRequestsSoFar = 0; - cl->largeCmdRequestsTotal = 0; -} - -/* -** This procedure is called when the client who created the context goes -** away OR when glXDestroyContext is called. In either case, all we do is -** flag that the ID is no longer valid, and (maybe) free the context. -** use. -*/ -static int ContextGone(__GLXcontext* cx, XID id) -{ - cx->idExists = GL_FALSE; - if (!cx->isCurrent) { - __glXFreeContext(cx); - } - - return True; -} - -/* -** Free a client's state. -*/ -static int ClientGone(int clientIndex, XID id) -{ - __GLXcontext *cx; - __GLXclientState *cl = __glXClients[clientIndex]; - int i; - - if (cl) { - /* - ** Free all the contexts that are current for this client. - */ - for (i=0; i < cl->numCurrentContexts; i++) { - cx = cl->currentContexts[i]; - if (cx) { - __glXDeassociateContext(cx, cx->glxPriv); - cx->isCurrent = GL_FALSE; - if (!cx->idExists) { - __glXFreeContext(cx); - } - } - } - /* - ** Re-initialize the client state structure. Don't free it because - ** we'll probably get another client with this index and use the struct - ** again. There is a maximum of MAXCLIENTS of these structures. - */ - ResetClientState(clientIndex); - } - - return True; -} - -/* -** Free a GLX Pixmap. -*/ -static int PixmapGone(__GLXpixmap *pGlxPixmap, XID id) -{ - PixmapPtr pPixmap = (PixmapPtr) pGlxPixmap->pDraw; - - pGlxPixmap->idExists = False; - if (!pGlxPixmap->refcnt) { - /* - ** The DestroyPixmap routine should decrement the refcount and free - ** only if it's zero. - */ - (*pGlxPixmap->pScreen->DestroyPixmap)(pPixmap); - __glXFree(pGlxPixmap); - } - - return True; -} - -/* -** Free a context. -*/ -GLboolean __glXFreeContext(__GLXcontext *cx) -{ - if (cx->idExists || cx->isCurrent) return GL_FALSE; - - if (!cx->isDirect) { - if ((*cx->gc->exports.destroyContext)((__GLcontext *)cx->gc) == GL_FALSE) { - return GL_FALSE; - } - } - if (cx->feedbackBuf) __glXFree(cx->feedbackBuf); - if (cx->selectBuf) __glXFree(cx->selectBuf); - __glXFree(cx); - if (cx == __glXLastContext) { - __glXFlushContextCache(); - } - - return GL_TRUE; -} - -/************************************************************************/ - -/* -** These routines can be used to check whether a particular GL command -** has caused an error. Specifically, we use them to check whether a -** given query has caused an error, in which case a zero-length data -** reply is sent to the client. -*/ - -static GLboolean errorOccured = GL_FALSE; - -/* -** The GL was will call this routine if an error occurs. -*/ -void __glXErrorCallBack(__GLinterface *gc, GLenum code) -{ - errorOccured = GL_TRUE; -} - -/* -** Clear the error flag before calling the GL command. -*/ -void __glXClearErrorOccured(void) -{ - errorOccured = GL_FALSE; -} - -/* -** Check if the GL command caused an error. -*/ -GLboolean __glXErrorOccured(void) -{ - return errorOccured; -} - -/************************************************************************/ - -/* -** Initialize the GLX extension. -*/ -void GlxExtensionInit(void) -{ - ExtensionEntry *extEntry; - int i; - -#ifdef X11R5 - __glXContextRes = CreateNewResourceType(ContextGone); - __glXClientRes = CreateNewResourceType(ClientGone); - __glXPixmapRes = CreateNewResourceType(PixmapGone); -#else - __glXContextRes = CreateNewResourceType((DeleteType)ContextGone); - __glXClientRes = CreateNewResourceType((DeleteType)ClientGone); - __glXPixmapRes = CreateNewResourceType((DeleteType)PixmapGone); -#endif - - /* - ** Add extension to server extensions. - */ - extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS, - __GLX_NUMBER_ERRORS, __glXDispatch, - __glXSwapDispatch, ResetExtension, - StandardMinorOpcode); - if (!extEntry) { - FatalError("__glXExtensionInit: AddExtensions failed\n"); - return; - } - if (!AddExtensionAlias(GLX_EXTENSION_ALIAS, extEntry)) { - ErrorF("__glXExtensionInit: AddExtensionAlias failed\n"); - return; - } - - __glXBadContext = extEntry->errorBase + GLXBadContext; - __glXBadContextState = extEntry->errorBase + GLXBadContextState; - __glXBadDrawable = extEntry->errorBase + GLXBadDrawable; - __glXBadPixmap = extEntry->errorBase + GLXBadPixmap; - __glXBadContextTag = extEntry->errorBase + GLXBadContextTag; - __glXBadCurrentWindow = extEntry->errorBase + GLXBadCurrentWindow; - __glXBadRenderRequest = extEntry->errorBase + GLXBadRenderRequest; - __glXBadLargeRequest = extEntry->errorBase + GLXBadLargeRequest; - __glXUnsupportedPrivateRequest = extEntry->errorBase + - GLXUnsupportedPrivateRequest; - - /* - ** Initialize table of client state. There is never a client 0. - */ - for (i=1; i <= MAXCLIENTS; i++) { - __glXClients[i] = 0; - } - - /* - ** Initialize screen specific data. - */ - __glXScreenInit(screenInfo.numScreens); -} - -/************************************************************************/ - -Bool __glXCoreType(void) -{ - return __glXExt->type; -} - -/************************************************************************/ - -void GlxSetVisualConfigs(int nconfigs, - __GLXvisualConfig *configs, void **privates) -{ - (*__glXExt->setVisualConfigs)(nconfigs, configs, privates); -} - -static miInitVisualsProcPtr saveInitVisualsProc; - -Bool GlxInitVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, - int *rootDepthp, VisualID *defaultVisp, - unsigned long sizes, int bitsPerRGB, - int preferredVis) -{ - Bool ret; - - if (saveInitVisualsProc) { - ret = saveInitVisualsProc(visualp, depthp, nvisualp, ndepthp, - rootDepthp, defaultVisp, sizes, bitsPerRGB, - preferredVis); - if (!ret) - return False; - } - (*__glXExt->initVisuals)(visualp, depthp, nvisualp, ndepthp, rootDepthp, - defaultVisp, sizes, bitsPerRGB); - return True; -} - -void -GlxWrapInitVisuals(miInitVisualsProcPtr *initVisProc) -{ - saveInitVisualsProc = *initVisProc; - *initVisProc = GlxInitVisuals; -} - -/************************************************************************/ - -void __glXFlushContextCache(void) -{ - __glXLastContext = 0; -} - -/* -** Make a context the current one for the GL (in this implementation, there -** is only one instance of the GL, and we use it to serve all GL clients by -** switching it between different contexts). While we are at it, look up -** a context by its tag and return its (__GLXcontext *). -*/ -__GLXcontext *__glXForceCurrent(__GLXclientState *cl, GLXContextTag tag, - int *error) -{ - __GLXcontext *cx; - - /* - ** See if the context tag is legal; it is managed by the extension, - ** so if it's invalid, we have an implementation error. - */ - cx = (__GLXcontext *) __glXLookupContextByTag(cl, tag); - if (!cx) { - cl->client->errorValue = tag; - *error = __glXBadContextTag; - return 0; - } - - if (!cx->isDirect) { - if (cx->glxPriv == NULL) { - /* - ** The drawable has vanished. It must be a window, because only - ** windows can be destroyed from under us; GLX pixmaps are - ** refcounted and don't go away until no one is using them. - */ - *error = __glXBadCurrentWindow; - return 0; - } - } - - if (cx == __glXLastContext) { - /* No need to re-bind */ - return cx; - } - - /* Make this context the current one for the GL. */ - if (!cx->isDirect) { - if (!(*cx->gc->exports.forceCurrent)((__GLcontext *)cx->gc)) { - /* Bind failed, and set the error code. Bummer */ - cl->client->errorValue = cx->id; - *error = __glXBadContextState; - return 0; - } - } - __glXLastContext = cx; - return cx; -} - -/************************************************************************/ - -/* -** Top level dispatcher; all commands are executed from here down. -*/ -static int __glXDispatch(ClientPtr client) -{ - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** If we're expecting a glXRenderLarge request, this better be one. - */ - if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) { - client->errorValue = stuff->glxCode; - return __glXBadLargeRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSingleTable[opcode]; - return (*proc)(cl, (GLbyte *) stuff); -} - -static int __glXSwapDispatch(ClientPtr client) -{ - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSwapSingleTable[opcode]; - return (*proc)(cl, (GLbyte *) stuff); -} - -int __glXNoSuchSingleOpcode(__GLXclientState *cl, GLbyte *pc) -{ - return BadRequest; -} - -void __glXNoSuchRenderOpcode(GLbyte *pc) -{ - return; -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.NX.original deleted file mode 100644 index 22483b3fd..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.NX.original +++ /dev/null @@ -1,511 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXglyph.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/glyph.c,v 1.6 2001/10/28 03:34:19 tsi Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" - -#ifdef NXAGENT_SERVER - -#include "NXpicturestr.h" -#include "NXglyphstr.h" -#include "Render.h" - -#define PANIC -#define WARNING -#undef DEBUG -#undef TEST - -#endif - -/* - * From Knuth -- a good choice for hash/rehash values is p, p-2 where - * p and p-2 are both prime. These tables are sized to have an extra 10% - * free to avoid exponential performance degradation as the hash table fills - */ -static GlyphHashSetRec glyphHashSets[] = { - { 32, 43, 41 }, - { 64, 73, 71 }, - { 128, 151, 149 }, - { 256, 283, 281 }, - { 512, 571, 569 }, - { 1024, 1153, 1151 }, - { 2048, 2269, 2267 }, - { 4096, 4519, 4517 }, - { 8192, 9013, 9011 }, - { 16384, 18043, 18041 }, - { 32768, 36109, 36107 }, - { 65536, 72091, 72089 }, - { 131072, 144409, 144407 }, - { 262144, 288361, 288359 }, - { 524288, 576883, 576881 }, - { 1048576, 1153459, 1153457 }, - { 2097152, 2307163, 2307161 }, - { 4194304, 4613893, 4613891 }, - { 8388608, 9227641, 9227639 }, - { 16777216, 18455029, 18455027 }, - { 33554432, 36911011, 36911009 }, - { 67108864, 73819861, 73819859 }, - { 134217728, 147639589, 147639587 }, - { 268435456, 295279081, 295279079 }, - { 536870912, 590559793, 590559791 } -}; - -#define NGLYPHHASHSETS (sizeof(glyphHashSets)/sizeof(glyphHashSets[0])) - -const CARD8 glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 }; - -GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled) -{ - int i; - - for (i = 0; i < NGLYPHHASHSETS; i++) - if (glyphHashSets[i].entries >= filled) - return &glyphHashSets[i]; - return 0; -} - -Bool -GlyphInit (ScreenPtr pScreen) -{ - return TRUE; -} - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare) -{ - CARD32 elt, step, s; - GlyphPtr glyph; - GlyphRefPtr table, gr, del; - CARD32 tableSize = hash->hashSet->size; - - table = hash->table; - elt = signature % tableSize; - step = 0; - del = 0; - for (;;) - { - gr = &table[elt]; - s = gr->signature; - glyph = gr->glyph; - if (!glyph) - { - if (del) - gr = del; - break; - } - if (glyph == DeletedGlyph) - { - if (!del) - del = gr; - else if (gr == del) - break; - } - else if (s == signature && - (!match || - memcmp (&compare->info, &glyph->info, compare->size) == 0)) - { - break; - } - if (!step) - { - step = signature % hash->hashSet->rehash; - if (!step) - step = 1; - } - elt += step; - if (elt >= tableSize) - elt -= tableSize; - } - return gr; -} - -CARD32 -HashGlyph (GlyphPtr glyph) -{ - CARD32 *bits = (CARD32 *) &(glyph->info); - CARD32 hash; - int n = glyph->size / sizeof (CARD32); - - hash = 0; - while (n--) - hash ^= *bits++; - return hash; -} - -#ifdef CHECK_DUPLICATES -void -DuplicateRef (GlyphPtr glyph, char *where) -{ - ErrorF ("Duplicate Glyph 0x%x from %s\n", glyph, where); -} - -void -CheckDuplicates (GlyphHashPtr hash, char *where) -{ - GlyphPtr g; - int i, j; - - for (i = 0; i < hash->hashSet->size; i++) - { - g = hash->table[i].glyph; - if (!g || g == DeletedGlyph) - continue; - for (j = i + 1; j < hash->hashSet->size; j++) - if (hash->table[j].glyph == g) - DuplicateRef (g, where); - } -} -#else -#define CheckDuplicates(a,b) -#define DuplicateRef(a,b) -#endif - -void -FreeGlyph (GlyphPtr glyph, int format) -{ - CheckDuplicates (&globalGlyphs[format], "FreeGlyph"); - if (--glyph->refcnt == 0) - { - GlyphRefPtr gr; - int i; - int first; - - first = -1; - for (i = 0; i < globalGlyphs[format].hashSet->size; i++) - if (globalGlyphs[format].table[i].glyph == glyph) - { - if (first != -1) - DuplicateRef (glyph, "FreeGlyph check"); - first = i; - } - - gr = FindGlyphRef (&globalGlyphs[format], - HashGlyph (glyph), TRUE, glyph); - if (gr - globalGlyphs[format].table != first) - DuplicateRef (glyph, "Found wrong one"); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - gr->signature = 0; - globalGlyphs[format].tableEntries--; - } - xfree (glyph); - } -} - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) -{ - GlyphRefPtr gr; - CARD32 hash; - - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph top global"); - /* Locate existing matching glyph */ - hash = HashGlyph (glyph); - gr = FindGlyphRef (&globalGlyphs[glyphSet->fdepth], hash, TRUE, glyph); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - xfree (glyph); - glyph = gr->glyph; - } - else - { - gr->glyph = glyph; - gr->signature = hash; - globalGlyphs[glyphSet->fdepth].tableEntries++; - } - - /* Insert/replace glyphset value */ - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - ++glyph->refcnt; - if (gr->glyph && gr->glyph != DeletedGlyph) - FreeGlyph (gr->glyph, glyphSet->fdepth); - else - glyphSet->hash.tableEntries++; - gr->glyph = glyph; - gr->signature = id; - - #ifdef NXAGENT_SERVER - - gr -> corruptedGlyph = 1; - - #endif - - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph bottom"); -} - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphRefPtr gr; - GlyphPtr glyph; - - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - glyph = gr->glyph; - if (glyph && glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - glyphSet->hash.tableEntries--; - FreeGlyph (glyph, glyphSet->fdepth); - return TRUE; - } - return FALSE; -} - -#ifdef NXAGENT_SERVER - -GlyphPtr FindGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphRefPtr gr; - GlyphPtr glyph; - - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - glyph = gr -> glyph; - - if (glyph == DeletedGlyph) - { - glyph = 0; - } - else if (gr -> corruptedGlyph == 1) - { - #ifdef DEBUG - fprintf(stderr, "FindGlyphRef: Going to synchronize the glyph [%p] for glyphset [%p].\n", - (void *) glyph, (void *) glyphSet); - #endif - - nxagentAddGlyphs(glyphSet, &id, &(glyph -> info), 1, - (CARD8*)(glyph + 1), glyph -> size - sizeof(xGlyphInfo)); - } - - return glyph; -} - -#else - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphPtr glyph; - - glyph = FindGlyphRef (&glyphSet->hash, id, FALSE, 0)->glyph; - if (glyph == DeletedGlyph) - glyph = 0; - return glyph; -} - -#endif - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int fdepth) -{ - int size; - GlyphPtr glyph; - - size = gi->height * PixmapBytePad (gi->width, glyphDepths[fdepth]); - glyph = (GlyphPtr) xalloc (size + sizeof (GlyphRec)); - if (!glyph) - return 0; - glyph->refcnt = 0; - glyph->size = size + sizeof (xGlyphInfo); - glyph->info = *gi; - return glyph; -} - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet) -{ - hash->table = (GlyphRefPtr) xalloc (hashSet->size * sizeof (GlyphRefRec)); - if (!hash->table) - return FALSE; - memset (hash->table, 0, hashSet->size * sizeof (GlyphRefRec)); - hash->hashSet = hashSet; - hash->tableEntries = 0; - return TRUE; -} - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global) -{ - CARD32 tableEntries; - GlyphHashSetPtr hashSet; - GlyphHashRec newHash; - GlyphRefPtr gr; - GlyphPtr glyph; - int i; - int oldSize; - CARD32 s; - - #ifdef NXAGENT_SERVER - - CARD32 c; - - #endif - - tableEntries = hash->tableEntries + change; - hashSet = FindGlyphHashSet (tableEntries); - if (hashSet == hash->hashSet) - return TRUE; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash top"); - if (!AllocateGlyphHash (&newHash, hashSet)) - return FALSE; - if (hash->table) - { - oldSize = hash->hashSet->size; - for (i = 0; i < oldSize; i++) - { - glyph = hash->table[i].glyph; - if (glyph && glyph != DeletedGlyph) - { - s = hash->table[i].signature; - - #ifdef NXAGENT_SERVER - - c = hash->table[i].corruptedGlyph; - - #endif - - gr = FindGlyphRef (&newHash, s, global, glyph); - gr->signature = s; - gr->glyph = glyph; - - #ifdef NXAGENT_SERVER - - gr -> corruptedGlyph = c; - - #endif - - ++newHash.tableEntries; - } - } - xfree (hash->table); - } - *hash = newHash; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash bottom"); - return TRUE; -} - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change) -{ - return (ResizeGlyphHash (&glyphSet->hash, change, FALSE) && - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], change, TRUE)); -} - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format) -{ - GlyphSetPtr glyphSet; - - if (!globalGlyphs[fdepth].hashSet) - { - if (!AllocateGlyphHash (&globalGlyphs[fdepth], &glyphHashSets[0])) - return FALSE; - } - glyphSet = xalloc (sizeof (GlyphSetRec)); - if (!glyphSet) - return FALSE; - if (!AllocateGlyphHash (&glyphSet->hash, &glyphHashSets[0])) - { - xfree (glyphSet); - return FALSE; - } - glyphSet->refcnt = 1; - glyphSet->fdepth = fdepth; - glyphSet->format = format; - return glyphSet; -} - -int -FreeGlyphSet (pointer value, - XID gid) -{ - GlyphSetPtr glyphSet = (GlyphSetPtr) value; - - if (--glyphSet->refcnt == 0) - { - CARD32 i, tableSize = glyphSet->hash.hashSet->size; - GlyphRefPtr table = glyphSet->hash.table; - GlyphPtr glyph; - - for (i = 0; i < tableSize; i++) - { - glyph = table[i].glyph; - if (glyph && glyph != DeletedGlyph) - FreeGlyph (glyph, glyphSet->fdepth); - } - if (!globalGlyphs[glyphSet->fdepth].tableEntries) - { - xfree (globalGlyphs[glyphSet->fdepth].table); - globalGlyphs[glyphSet->fdepth].table = 0; - globalGlyphs[glyphSet->fdepth].hashSet = 0; - } - else - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE); - xfree (table); - xfree (glyphSet); - } - return Success; -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.XF86.original deleted file mode 100644 index b4f08c223..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c.XF86.original +++ /dev/null @@ -1,416 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/glyph.c,v 1.6 2001/10/28 03:34:19 tsi Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "picturestr.h" -#include "glyphstr.h" - -/* - * From Knuth -- a good choice for hash/rehash values is p, p-2 where - * p and p-2 are both prime. These tables are sized to have an extra 10% - * free to avoid exponential performance degradation as the hash table fills - */ -static GlyphHashSetRec glyphHashSets[] = { - { 32, 43, 41 }, - { 64, 73, 71 }, - { 128, 151, 149 }, - { 256, 283, 281 }, - { 512, 571, 569 }, - { 1024, 1153, 1151 }, - { 2048, 2269, 2267 }, - { 4096, 4519, 4517 }, - { 8192, 9013, 9011 }, - { 16384, 18043, 18041 }, - { 32768, 36109, 36107 }, - { 65536, 72091, 72089 }, - { 131072, 144409, 144407 }, - { 262144, 288361, 288359 }, - { 524288, 576883, 576881 }, - { 1048576, 1153459, 1153457 }, - { 2097152, 2307163, 2307161 }, - { 4194304, 4613893, 4613891 }, - { 8388608, 9227641, 9227639 }, - { 16777216, 18455029, 18455027 }, - { 33554432, 36911011, 36911009 }, - { 67108864, 73819861, 73819859 }, - { 134217728, 147639589, 147639587 }, - { 268435456, 295279081, 295279079 }, - { 536870912, 590559793, 590559791 } -}; - -#define NGLYPHHASHSETS (sizeof(glyphHashSets)/sizeof(glyphHashSets[0])) - -const CARD8 glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 }; - -GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled) -{ - int i; - - for (i = 0; i < NGLYPHHASHSETS; i++) - if (glyphHashSets[i].entries >= filled) - return &glyphHashSets[i]; - return 0; -} - -Bool -GlyphInit (ScreenPtr pScreen) -{ - return TRUE; -} - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare) -{ - CARD32 elt, step, s; - GlyphPtr glyph; - GlyphRefPtr table, gr, del; - CARD32 tableSize = hash->hashSet->size; - - table = hash->table; - elt = signature % tableSize; - step = 0; - del = 0; - for (;;) - { - gr = &table[elt]; - s = gr->signature; - glyph = gr->glyph; - if (!glyph) - { - if (del) - gr = del; - break; - } - if (glyph == DeletedGlyph) - { - if (!del) - del = gr; - else if (gr == del) - break; - } - else if (s == signature && - (!match || - memcmp (&compare->info, &glyph->info, compare->size) == 0)) - { - break; - } - if (!step) - { - step = signature % hash->hashSet->rehash; - if (!step) - step = 1; - } - elt += step; - if (elt >= tableSize) - elt -= tableSize; - } - return gr; -} - -CARD32 -HashGlyph (GlyphPtr glyph) -{ - CARD32 *bits = (CARD32 *) &(glyph->info); - CARD32 hash; - int n = glyph->size / sizeof (CARD32); - - hash = 0; - while (n--) - hash ^= *bits++; - return hash; -} - -#ifdef CHECK_DUPLICATES -void -DuplicateRef (GlyphPtr glyph, char *where) -{ - ErrorF ("Duplicate Glyph 0x%x from %s\n", glyph, where); -} - -void -CheckDuplicates (GlyphHashPtr hash, char *where) -{ - GlyphPtr g; - int i, j; - - for (i = 0; i < hash->hashSet->size; i++) - { - g = hash->table[i].glyph; - if (!g || g == DeletedGlyph) - continue; - for (j = i + 1; j < hash->hashSet->size; j++) - if (hash->table[j].glyph == g) - DuplicateRef (g, where); - } -} -#else -#define CheckDuplicates(a,b) -#define DuplicateRef(a,b) -#endif - -void -FreeGlyph (GlyphPtr glyph, int format) -{ - CheckDuplicates (&globalGlyphs[format], "FreeGlyph"); - if (--glyph->refcnt == 0) - { - GlyphRefPtr gr; - int i; - int first; - - first = -1; - for (i = 0; i < globalGlyphs[format].hashSet->size; i++) - if (globalGlyphs[format].table[i].glyph == glyph) - { - if (first != -1) - DuplicateRef (glyph, "FreeGlyph check"); - first = i; - } - - gr = FindGlyphRef (&globalGlyphs[format], - HashGlyph (glyph), TRUE, glyph); - if (gr - globalGlyphs[format].table != first) - DuplicateRef (glyph, "Found wrong one"); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - gr->signature = 0; - globalGlyphs[format].tableEntries--; - } - xfree (glyph); - } -} - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) -{ - GlyphRefPtr gr; - CARD32 hash; - - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph top global"); - /* Locate existing matching glyph */ - hash = HashGlyph (glyph); - gr = FindGlyphRef (&globalGlyphs[glyphSet->fdepth], hash, TRUE, glyph); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - xfree (glyph); - glyph = gr->glyph; - } - else - { - gr->glyph = glyph; - gr->signature = hash; - globalGlyphs[glyphSet->fdepth].tableEntries++; - } - - /* Insert/replace glyphset value */ - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - ++glyph->refcnt; - if (gr->glyph && gr->glyph != DeletedGlyph) - FreeGlyph (gr->glyph, glyphSet->fdepth); - else - glyphSet->hash.tableEntries++; - gr->glyph = glyph; - gr->signature = id; - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph bottom"); -} - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphRefPtr gr; - GlyphPtr glyph; - - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - glyph = gr->glyph; - if (glyph && glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - glyphSet->hash.tableEntries--; - FreeGlyph (glyph, glyphSet->fdepth); - return TRUE; - } - return FALSE; -} - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphPtr glyph; - - glyph = FindGlyphRef (&glyphSet->hash, id, FALSE, 0)->glyph; - if (glyph == DeletedGlyph) - glyph = 0; - return glyph; -} - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int fdepth) -{ - int size; - GlyphPtr glyph; - - size = gi->height * PixmapBytePad (gi->width, glyphDepths[fdepth]); - glyph = (GlyphPtr) xalloc (size + sizeof (GlyphRec)); - if (!glyph) - return 0; - glyph->refcnt = 0; - glyph->size = size + sizeof (xGlyphInfo); - glyph->info = *gi; - return glyph; -} - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet) -{ - hash->table = (GlyphRefPtr) xalloc (hashSet->size * sizeof (GlyphRefRec)); - if (!hash->table) - return FALSE; - memset (hash->table, 0, hashSet->size * sizeof (GlyphRefRec)); - hash->hashSet = hashSet; - hash->tableEntries = 0; - return TRUE; -} - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global) -{ - CARD32 tableEntries; - GlyphHashSetPtr hashSet; - GlyphHashRec newHash; - GlyphRefPtr gr; - GlyphPtr glyph; - int i; - int oldSize; - CARD32 s; - - tableEntries = hash->tableEntries + change; - hashSet = FindGlyphHashSet (tableEntries); - if (hashSet == hash->hashSet) - return TRUE; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash top"); - if (!AllocateGlyphHash (&newHash, hashSet)) - return FALSE; - if (hash->table) - { - oldSize = hash->hashSet->size; - for (i = 0; i < oldSize; i++) - { - glyph = hash->table[i].glyph; - if (glyph && glyph != DeletedGlyph) - { - s = hash->table[i].signature; - gr = FindGlyphRef (&newHash, s, global, glyph); - gr->signature = s; - gr->glyph = glyph; - ++newHash.tableEntries; - } - } - xfree (hash->table); - } - *hash = newHash; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash bottom"); - return TRUE; -} - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change) -{ - return (ResizeGlyphHash (&glyphSet->hash, change, FALSE) && - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], change, TRUE)); -} - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format) -{ - GlyphSetPtr glyphSet; - - if (!globalGlyphs[fdepth].hashSet) - { - if (!AllocateGlyphHash (&globalGlyphs[fdepth], &glyphHashSets[0])) - return FALSE; - } - glyphSet = xalloc (sizeof (GlyphSetRec)); - if (!glyphSet) - return FALSE; - if (!AllocateGlyphHash (&glyphSet->hash, &glyphHashSets[0])) - { - xfree (glyphSet); - return FALSE; - } - glyphSet->refcnt = 1; - glyphSet->fdepth = fdepth; - glyphSet->format = format; - return glyphSet; -} - -int -FreeGlyphSet (pointer value, - XID gid) -{ - GlyphSetPtr glyphSet = (GlyphSetPtr) value; - - if (--glyphSet->refcnt == 0) - { - CARD32 i, tableSize = glyphSet->hash.hashSet->size; - GlyphRefPtr table = glyphSet->hash.table; - GlyphPtr glyph; - - for (i = 0; i < tableSize; i++) - { - glyph = table[i].glyph; - if (glyph && glyph != DeletedGlyph) - FreeGlyph (glyph, glyphSet->fdepth); - } - if (!globalGlyphs[glyphSet->fdepth].tableEntries) - { - xfree (globalGlyphs[glyphSet->fdepth].table); - globalGlyphs[glyphSet->fdepth].table = 0; - globalGlyphs[glyphSet->fdepth].hashSet = 0; - } - else - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE); - xfree (table); - xfree (glyphSet); - } - return Success; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.NX.original deleted file mode 100644 index 9212bf438..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.NX.original +++ /dev/null @@ -1,252 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXglyphcurs.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* $Xorg: glyphcurs.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "misc.h" -#include "fontstruct.h" -#include "dixfontstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "resource.h" -#include "dix.h" -#include "cursorstr.h" -#include "opaque.h" -#include "servermd.h" - -#include "../../fb/fb.h" -#include "Pixmaps.h" - -#ifndef True -#define True 1 -#endif - -/* - get the bits out of the font in a portable way. to avoid -dealing with padding and such-like, we draw the glyph into -a bitmap, then read the bits out with GetImage, which -uses server-natural format. - since all screens return the same bitmap format, we'll just use -the first one we find. - the character origin lines up with the hotspot in the -cursor metrics. -*/ - -int -ServerBitsFromGlyph(pfont, ch, cm, ppbits) - FontPtr pfont; - unsigned int ch; - register CursorMetricPtr cm; - unsigned char **ppbits; -{ - register ScreenPtr pScreen; - register GCPtr pGC; - xRectangle rect; - PixmapPtr ppix; - long nby; - char *pbits; - ChangeGCVal gcval[3]; - unsigned char char2b[2]; - - /* turn glyph index into a protocol-format char2b */ - char2b[0] = (unsigned char)(ch >> 8); - char2b[1] = (unsigned char)(ch & 0xff); - - pScreen = screenInfo.screens[0]; - nby = BitmapBytePad(cm->width) * (long)cm->height; - pbits = (char *)xalloc(nby); - if (!pbits) - return BadAlloc; - /* zeroing the (pad) bits seems to help some ddx cursor handling */ - bzero(pbits, nby); - - ppix = fbCreatePixmap(pScreen, cm->width, cm->height, 1); - pGC = GetScratchGC(1, pScreen); - if (!ppix || !pGC) - { - if (ppix) - fbDestroyPixmap(ppix); - if (pGC) - FreeScratchGC(pGC); - xfree(pbits); - return BadAlloc; - } - - #ifdef TEST - fprintf(stderr, "ServerBitsFromGlyph: Created virtual pixmap at [%p] with width [%d] height [%d] depth [%d].\n", - (void *) ppix, cm->width, cm->height, 1); - #endif - - nxagentPixmapPriv(ppix) -> id = 0; - nxagentPixmapPriv(ppix) -> mid = 0; - nxagentPixmapPriv(ppix) -> isVirtual = True; - nxagentPixmapPriv(ppix) -> pRealPixmap = NULL; - nxagentPixmapPriv(ppix) -> pVirtualPixmap = NULL; - - rect.x = 0; - rect.y = 0; - rect.width = cm->width; - rect.height = cm->height; - - pGC->stateChanges |= GCFunction | GCForeground | GCFont; - pGC->alu = GXcopy; - - pGC->fgPixel = 0; - - pfont->refcnt++; - - if (pGC->font) - CloseFont(pGC->font, (Font)0); - - pGC->font = pfont; - - ValidateGC((DrawablePtr)ppix, pGC); - fbPolyFillRect((DrawablePtr)ppix, pGC, 1, &rect); - - /* draw the glyph */ - gcval[0].val = 1; - pGC->fgPixel = 1; - - pGC->stateChanges |= GCForeground; - - ValidateGC((DrawablePtr)ppix, pGC); - miPolyText16((DrawablePtr)ppix, pGC, (int)cm->xhot, (int)cm->yhot, (int)1, (unsigned short*)char2b); - fbGetImage((DrawablePtr)ppix, 0, 0, cm->width, cm->height, - XYPixmap, 1, pbits); - *ppbits = (unsigned char *)pbits; - FreeScratchGC(pGC); - fbDestroyPixmap(ppix); - - #ifdef TEST - fprintf(stderr, "ServerBitsFromGlyph: Destroyed virtual pixmap at [%p].\n", - (void *) ppix); - #endif - - return Success; -} - - -Bool -CursorMetricsFromGlyph( pfont, ch, cm) - register FontPtr pfont; - unsigned ch; - register CursorMetricPtr cm; -{ - CharInfoPtr pci; - unsigned long nglyphs; - CARD8 chs[2]; - FontEncoding encoding; - - chs[0] = ch >> 8; - chs[1] = ch; - encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; - if (encoding == Linear16Bit) - { - if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) - return FALSE; - } - else - { - if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) - return FALSE; - if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) - return FALSE; - } - (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); - if (nglyphs == 0) - return FALSE; - cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; - cm->height = pci->metrics.descent + pci->metrics.ascent; - if (pci->metrics.leftSideBearing > 0) - { - cm->width += pci->metrics.leftSideBearing; - cm->xhot = 0; - } - else - { - cm->xhot = -pci->metrics.leftSideBearing; - if (pci->metrics.rightSideBearing < 0) - cm->width -= pci->metrics.rightSideBearing; - } - if (pci->metrics.ascent < 0) - { - cm->height -= pci->metrics.ascent; - cm->yhot = 0; - } - else - { - cm->yhot = pci->metrics.ascent; - if (pci->metrics.descent < 0) - cm->height -= pci->metrics.descent; - } - return TRUE; -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.XF86.original deleted file mode 100644 index 630e98fa3..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c.XF86.original +++ /dev/null @@ -1,197 +0,0 @@ -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* $Xorg: glyphcurs.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "misc.h" -#include "fontstruct.h" -#include "dixfontstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "resource.h" -#include "dix.h" -#include "cursorstr.h" -#include "opaque.h" -#include "servermd.h" - - -/* - get the bits out of the font in a portable way. to avoid -dealing with padding and such-like, we draw the glyph into -a bitmap, then read the bits out with GetImage, which -uses server-natural format. - since all screens return the same bitmap format, we'll just use -the first one we find. - the character origin lines up with the hotspot in the -cursor metrics. -*/ - -int -ServerBitsFromGlyph(pfont, ch, cm, ppbits) - FontPtr pfont; - unsigned int ch; - register CursorMetricPtr cm; - unsigned char **ppbits; -{ - register ScreenPtr pScreen; - register GCPtr pGC; - xRectangle rect; - PixmapPtr ppix; - long nby; - char *pbits; - ChangeGCVal gcval[3]; - unsigned char char2b[2]; - - /* turn glyph index into a protocol-format char2b */ - char2b[0] = (unsigned char)(ch >> 8); - char2b[1] = (unsigned char)(ch & 0xff); - - pScreen = screenInfo.screens[0]; - nby = BitmapBytePad(cm->width) * (long)cm->height; - pbits = (char *)xalloc(nby); - if (!pbits) - return BadAlloc; - /* zeroing the (pad) bits seems to help some ddx cursor handling */ - bzero(pbits, nby); - - ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width, - cm->height, 1); - pGC = GetScratchGC(1, pScreen); - if (!ppix || !pGC) - { - if (ppix) - (*pScreen->DestroyPixmap)(ppix); - if (pGC) - FreeScratchGC(pGC); - xfree(pbits); - return BadAlloc; - } - - rect.x = 0; - rect.y = 0; - rect.width = cm->width; - rect.height = cm->height; - - /* fill the pixmap with 0 */ - gcval[0].val = GXcopy; - gcval[1].val = 0; - gcval[2].ptr = (pointer)pfont; - dixChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, - NULL, gcval); - ValidateGC((DrawablePtr)ppix, pGC); - (*pGC->ops->PolyFillRect)((DrawablePtr)ppix, pGC, 1, &rect); - - /* draw the glyph */ - gcval[0].val = 1; - dixChangeGC(NullClient, pGC, GCForeground, NULL, gcval); - ValidateGC((DrawablePtr)ppix, pGC); - (*pGC->ops->PolyText16)((DrawablePtr)ppix, pGC, cm->xhot, cm->yhot, - 1, (unsigned short *)char2b); - (*pScreen->GetImage)((DrawablePtr)ppix, 0, 0, cm->width, cm->height, - XYPixmap, 1, pbits); - *ppbits = (unsigned char *)pbits; - FreeScratchGC(pGC); - (*pScreen->DestroyPixmap)(ppix); - return Success; -} - - -Bool -CursorMetricsFromGlyph( pfont, ch, cm) - register FontPtr pfont; - unsigned ch; - register CursorMetricPtr cm; -{ - CharInfoPtr pci; - unsigned long nglyphs; - CARD8 chs[2]; - FontEncoding encoding; - - chs[0] = ch >> 8; - chs[1] = ch; - encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; - if (encoding == Linear16Bit) - { - if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) - return FALSE; - } - else - { - if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) - return FALSE; - if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) - return FALSE; - } - (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); - if (nglyphs == 0) - return FALSE; - cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; - cm->height = pci->metrics.descent + pci->metrics.ascent; - if (pci->metrics.leftSideBearing > 0) - { - cm->width += pci->metrics.leftSideBearing; - cm->xhot = 0; - } - else - { - cm->xhot = -pci->metrics.leftSideBearing; - if (pci->metrics.rightSideBearing < 0) - cm->width -= pci->metrics.rightSideBearing; - } - if (pci->metrics.ascent < 0) - { - cm->height -= pci->metrics.ascent; - cm->yhot = 0; - } - else - { - cm->yhot = pci->metrics.ascent; - if (pci->metrics.descent < 0) - cm->height -= pci->metrics.descent; - } - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.NX.original deleted file mode 100644 index 0f122be4a..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.NX.original +++ /dev/null @@ -1,161 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXglyphstr.h" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/glyphstr.h,v 1.4 2001/01/21 21:19:39 tsi Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -/* - * This must keep the same symbol as the original glyphstr.h - * or symbols will be redefined. The code here adds a field - * to _GlyphSet. This should be done by defining a new type - * and casting when appropriate. - */ - -#ifndef _GLYPHSTR_H_ -#define _GLYPHSTR_H_ - -#include "renderproto.h" -#include "../../render/picture.h" -#include "screenint.h" - -#define GlyphFormat1 0 -#define GlyphFormat4 1 -#define GlyphFormat8 2 -#define GlyphFormat16 3 -#define GlyphFormat32 4 -#define GlyphFormatNum 5 - -typedef struct _Glyph { - CARD32 refcnt; - CARD32 size; /* info + bitmap */ - xGlyphInfo info; - /* bits follow */ -} GlyphRec, *GlyphPtr; - -typedef struct _GlyphRef { - CARD32 signature; - GlyphPtr glyph; - CARD16 corruptedGlyph; -} GlyphRefRec, *GlyphRefPtr; - -#define DeletedGlyph ((GlyphPtr) 1) - -typedef struct _GlyphHashSet { - CARD32 entries; - CARD32 size; - CARD32 rehash; -} GlyphHashSetRec, *GlyphHashSetPtr; - -typedef struct _GlyphHash { - GlyphRefPtr table; - GlyphHashSetPtr hashSet; - CARD32 tableEntries; -} GlyphHashRec, *GlyphHashPtr; - -typedef struct _GlyphSet { - CARD32 refcnt; - PictFormatPtr format; - int fdepth; - GlyphHashRec hash; - CARD32 remoteID; -} GlyphSetRec, *GlyphSetPtr; - -typedef struct _GlyphList { - INT16 xOff; - INT16 yOff; - CARD8 len; - PictFormatPtr format; -} GlyphListRec, *GlyphListPtr; - -extern GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled); - -Bool -GlyphInit (ScreenPtr pScreen); - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare); - -CARD32 -HashGlyph (GlyphPtr glyph); - -void -FreeGlyph (GlyphPtr glyph, int format); - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id); - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int format); - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet); - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global); - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change); - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format); - -int -FreeGlyphSet (pointer value, - XID gid); - - - -#endif /* _GLYPHSTR_H_ */ - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.XF86.original deleted file mode 100644 index 99f55e3eb..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyphstr.h.XF86.original +++ /dev/null @@ -1,127 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/glyphstr.h,v 1.4 2001/01/21 21:19:39 tsi Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifndef _GLYPHSTR_H_ -#define _GLYPHSTR_H_ - -#include "renderproto.h" -#include "picture.h" -#include "screenint.h" - -#define GlyphFormat1 0 -#define GlyphFormat4 1 -#define GlyphFormat8 2 -#define GlyphFormat16 3 -#define GlyphFormat32 4 -#define GlyphFormatNum 5 - -typedef struct _Glyph { - CARD32 refcnt; - CARD32 size; /* info + bitmap */ - xGlyphInfo info; - /* bits follow */ -} GlyphRec, *GlyphPtr; - -typedef struct _GlyphRef { - CARD32 signature; - GlyphPtr glyph; -} GlyphRefRec, *GlyphRefPtr; - -#define DeletedGlyph ((GlyphPtr) 1) - -typedef struct _GlyphHashSet { - CARD32 entries; - CARD32 size; - CARD32 rehash; -} GlyphHashSetRec, *GlyphHashSetPtr; - -typedef struct _GlyphHash { - GlyphRefPtr table; - GlyphHashSetPtr hashSet; - CARD32 tableEntries; -} GlyphHashRec, *GlyphHashPtr; - -typedef struct _GlyphSet { - CARD32 refcnt; - PictFormatPtr format; - int fdepth; - GlyphHashRec hash; -} GlyphSetRec, *GlyphSetPtr; - -typedef struct _GlyphList { - INT16 xOff; - INT16 yOff; - CARD8 len; - PictFormatPtr format; -} GlyphListRec, *GlyphListPtr; - -extern GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled); - -Bool -GlyphInit (ScreenPtr pScreen); - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare); - -CARD32 -HashGlyph (GlyphPtr glyph); - -void -FreeGlyph (GlyphPtr glyph, int format); - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id); - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int format); - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet); - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global); - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change); - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format); - -int -FreeGlyphSet (pointer value, - XID gid); - - - -#endif /* _GLYPHSTR_H_ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.NX.original deleted file mode 100644 index bd068170c..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.NX.original +++ /dev/null @@ -1,938 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXmiexpose.c" - -#else - -/* $XFree86: xc/programs/Xserver/mi/miexpose.c,v 3.9 2001/12/14 20:00:22 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ - -/* $Xorg: miexpose.c,v 1.4 2001/02/09 02:05:20 xorgcvs Exp $ */ - -#include "X.h" -#define NEED_EVENTS -#include "Xproto.h" -#include "Xprotostr.h" - -#include "misc.h" -#include "regionstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "windowstr.h" -#include "pixmap.h" -#include "input.h" - -#include "dixstruct.h" -#include "mi.h" -#include "Xmd.h" - -#include "globals.h" - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -/* - machine-independent graphics exposure code. any device that uses -the region package can call this. -*/ - -#ifdef NXAGENT_SERVER - -#include "Windows.h" - -#endif - -#ifndef RECTLIMIT -#define RECTLIMIT 25 /* pick a number, any number > 8 */ -#endif - -/* miHandleExposures - generate a region for exposures for areas that were copied from obscured or -non-existent areas to non-obscured areas of the destination. Paint the -background for the region, if the destination is a window. - -NOTE: - this should generally be called, even if graphicsExposures is false, -because this is where bits get recovered from backing store. - -NOTE: - added argument 'plane' is used to indicate how exposures from backing -store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea -should be used, else a CopyPlane of the indicated plane will be used. The -exposing is done by the backing store's GraphicsExpose function, of course. - -*/ - -RegionPtr -miHandleExposures(pSrcDrawable, pDstDrawable, - pGC, srcx, srcy, width, height, dstx, dsty, plane) - register DrawablePtr pSrcDrawable; - register DrawablePtr pDstDrawable; - GCPtr pGC; - int srcx, srcy; - int width, height; - int dstx, dsty; - unsigned long plane; -{ - register ScreenPtr pscr; - RegionPtr prgnSrcClip; /* drawable-relative source clip */ - RegionRec rgnSrcRec; - RegionPtr prgnDstClip; /* drawable-relative dest clip */ - RegionRec rgnDstRec; - BoxRec srcBox; /* unclipped source */ - RegionRec rgnExposed; /* exposed region, calculated source- - relative, made dst relative to - intersect with visible parts of - dest and send events to client, - and then screen relative to paint - the window background - */ - WindowPtr pSrcWin; - BoxRec expBox; - Bool extents; - -#ifdef NXAGENT_SERVER - - /* - * Set the elements reported by the compiler - * as uninitialized. - */ - - expBox.x1 = 0; - expBox.y1 = 0; - expBox.x2 = 0; - expBox.y2 = 0; - -#endif - - /* This prevents warning about pscr not being used. */ - pGC->pScreen = pscr = pGC->pScreen; - - /* avoid work if we can */ - if (!pGC->graphicsExposures && - (pDstDrawable->type == DRAWABLE_PIXMAP) && - ((pSrcDrawable->type == DRAWABLE_PIXMAP) || - (((WindowPtr)pSrcDrawable)->backStorage == NULL))) - return NULL; - - srcBox.x1 = srcx; - srcBox.y1 = srcy; - srcBox.x2 = srcx+width; - srcBox.y2 = srcy+height; - - if (pSrcDrawable->type != DRAWABLE_PIXMAP) - { - BoxRec TsrcBox; - - TsrcBox.x1 = srcx + pSrcDrawable->x; - TsrcBox.y1 = srcy + pSrcDrawable->y; - TsrcBox.x2 = TsrcBox.x1 + width; - TsrcBox.y2 = TsrcBox.y1 + height; - pSrcWin = (WindowPtr) pSrcDrawable; - if (pGC->subWindowMode == IncludeInferiors) - { - prgnSrcClip = NotClippedByChildren (pSrcWin); - if ((RECT_IN_REGION(pscr, prgnSrcClip, &TsrcBox)) == rgnIN) - { - REGION_DESTROY(pscr, prgnSrcClip); - return NULL; - } - } - else - { - if ((RECT_IN_REGION(pscr, &pSrcWin->clipList, &TsrcBox)) == rgnIN) - return NULL; - prgnSrcClip = &rgnSrcRec; - REGION_INIT(pscr, prgnSrcClip, NullBox, 0); - REGION_COPY(pscr, prgnSrcClip, &pSrcWin->clipList); - } - REGION_TRANSLATE(pscr, prgnSrcClip, - -pSrcDrawable->x, -pSrcDrawable->y); - } - else - { - BoxRec box; - - if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) && - (srcBox.x2 <= pSrcDrawable->width) && - (srcBox.y2 <= pSrcDrawable->height)) - return NULL; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pSrcDrawable->width; - box.y2 = pSrcDrawable->height; - prgnSrcClip = &rgnSrcRec; - REGION_INIT(pscr, prgnSrcClip, &box, 1); - pSrcWin = (WindowPtr)NULL; - } - - if (pDstDrawable == pSrcDrawable) - { - prgnDstClip = prgnSrcClip; - } - else if (pDstDrawable->type != DRAWABLE_PIXMAP) - { - if (pGC->subWindowMode == IncludeInferiors) - { - prgnDstClip = NotClippedByChildren((WindowPtr)pDstDrawable); - } - else - { - prgnDstClip = &rgnDstRec; - REGION_INIT(pscr, prgnDstClip, NullBox, 0); - REGION_COPY(pscr, prgnDstClip, - &((WindowPtr)pDstDrawable)->clipList); - } - REGION_TRANSLATE(pscr, prgnDstClip, - -pDstDrawable->x, -pDstDrawable->y); - } - else - { - BoxRec box; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pDstDrawable->width; - box.y2 = pDstDrawable->height; - prgnDstClip = &rgnDstRec; - REGION_INIT(pscr, prgnDstClip, &box, 1); - } - - /* drawable-relative source region */ - REGION_INIT(pscr, &rgnExposed, &srcBox, 1); - - /* now get the hidden parts of the source box*/ - REGION_SUBTRACT(pscr, &rgnExposed, &rgnExposed, prgnSrcClip); - - if (pSrcWin && pSrcWin->backStorage) - { - /* - * Copy any areas from the source backing store. Modifies - * rgnExposed. - */ - (* pSrcWin->drawable.pScreen->ExposeCopy) ((WindowPtr)pSrcDrawable, - pDstDrawable, - pGC, - &rgnExposed, - srcx, srcy, - dstx, dsty, - plane); - } - - /* move them over the destination */ - REGION_TRANSLATE(pscr, &rgnExposed, dstx-srcx, dsty-srcy); - - /* intersect with visible areas of dest */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, prgnDstClip); - - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-) - * for windows. - */ - extents = pGC->graphicsExposures && - (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) && - (pDstDrawable->type != DRAWABLE_PIXMAP); -#ifdef SHAPE - if (pSrcWin) - { - RegionPtr region; - if (!(region = wClipShape (pSrcWin))) - region = wBoundingShape (pSrcWin); - /* - * If you try to CopyArea the extents of a shaped window, compacting the - * exposed region will undo all our work! - */ - if (extents && pSrcWin && region && - (RECT_IN_REGION(pscr, region, &srcBox) != rgnIN)) - extents = FALSE; - } -#endif - if (extents) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - expBox = *REGION_EXTENTS(pscr, &rgnExposed); - REGION_RESET(pscr, &rgnExposed, &expBox); - /* need to clear out new areas of backing store */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - expBox.x1, - expBox.y1, - expBox.x2 - expBox.x1, - expBox.y2 - expBox.y1, - FALSE); - } - if ((pDstDrawable->type != DRAWABLE_PIXMAP) && - (((WindowPtr)pDstDrawable)->backgroundState != None)) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - /* make the exposed area screen-relative */ - REGION_TRANSLATE(pscr, &rgnExposed, - pDstDrawable->x, pDstDrawable->y); - - if (extents) - { - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, &pWin->clipList); - } - (*pWin->drawable.pScreen->PaintWindowBackground)( - (WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND); - - if (extents) - { - REGION_RESET(pscr, &rgnExposed, &expBox); - } - else - REGION_TRANSLATE(pscr, &rgnExposed, - -pDstDrawable->x, -pDstDrawable->y); - } - if (prgnDstClip == &rgnDstRec) - { - REGION_UNINIT(pscr, prgnDstClip); - } - else if (prgnDstClip != prgnSrcClip) - { - REGION_DESTROY(pscr, prgnDstClip); - } - - if (prgnSrcClip == &rgnSrcRec) - { - REGION_UNINIT(pscr, prgnSrcClip); - } - else - { - REGION_DESTROY(pscr, prgnSrcClip); - } - - if (pGC->graphicsExposures) - { - /* don't look */ - RegionPtr exposed = REGION_CREATE(pscr, NullBox, 0); - *exposed = rgnExposed; - return exposed; - } - else - { - REGION_UNINIT(pscr, &rgnExposed); - return NULL; - } -} - -/* send GraphicsExpose events, or a NoExpose event, based on the region */ - -void -miSendGraphicsExpose (client, pRgn, drawable, major, minor) - ClientPtr client; - RegionPtr pRgn; - XID drawable; - int major; - int minor; -{ - if (pRgn && !REGION_NIL(pRgn)) - { - xEvent *pEvent; - register xEvent *pe; - register BoxPtr pBox; - register int i; - int numRects; - - numRects = REGION_NUM_RECTS(pRgn); - pBox = REGION_RECTS(pRgn); - if(!(pEvent = (xEvent *)ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - pe = pEvent; - - for (i=1; i<=numRects; i++, pe++, pBox++) - { - pe->u.u.type = GraphicsExpose; - pe->u.graphicsExposure.drawable = drawable; - pe->u.graphicsExposure.x = pBox->x1; - pe->u.graphicsExposure.y = pBox->y1; - pe->u.graphicsExposure.width = pBox->x2 - pBox->x1; - pe->u.graphicsExposure.height = pBox->y2 - pBox->y1; - pe->u.graphicsExposure.count = numRects - i; - pe->u.graphicsExposure.majorEvent = major; - pe->u.graphicsExposure.minorEvent = minor; - } - TryClientEvents(client, pEvent, numRects, - (Mask)0, NoEventMask, NullGrab); - DEALLOCATE_LOCAL(pEvent); - } - else - { - xEvent event; - event.u.u.type = NoExpose; - event.u.noExposure.drawable = drawable; - event.u.noExposure.majorEvent = major; - event.u.noExposure.minorEvent = minor; - TryClientEvents(client, &event, 1, - (Mask)0, NoEventMask, NullGrab); - } -} - - -void -miSendExposures(pWin, pRgn, dx, dy) - WindowPtr pWin; - RegionPtr pRgn; - register int dx, dy; -{ - register BoxPtr pBox; - int numRects; - register xEvent *pEvent, *pe; - register int i; - - pBox = REGION_RECTS(pRgn); - numRects = REGION_NUM_RECTS(pRgn); - if(!(pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - - for (i=numRects, pe = pEvent; --i >= 0; pe++, pBox++) - { - pe->u.u.type = Expose; - pe->u.expose.window = pWin->drawable.id; - pe->u.expose.x = pBox->x1 - dx; - pe->u.expose.y = pBox->y1 - dy; - pe->u.expose.width = pBox->x2 - pBox->x1; - pe->u.expose.height = pBox->y2 - pBox->y1; - pe->u.expose.count = i; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - int scrnum = pWin->drawable.pScreen->myNum; - int x = 0, y = 0; - XID realWin = 0; - - if(!pWin->parent) { - x = panoramiXdataPtr[scrnum].x; - y = panoramiXdataPtr[scrnum].y; - pWin = WindowTable[0]; - realWin = pWin->drawable.id; - } else if (scrnum) { - PanoramiXRes *win; - win = PanoramiXFindIDByScrnum(XRT_WINDOW, - pWin->drawable.id, scrnum); - if(!win) { - DEALLOCATE_LOCAL(pEvent); - return; - } - realWin = win->info[0].id; - pWin = LookupIDByType(realWin, RT_WINDOW); - } - if(x || y || scrnum) - for (i = 0; i < numRects; i++) { - pEvent[i].u.expose.window = realWin; - pEvent[i].u.expose.x += x; - pEvent[i].u.expose.y += y; - } - } -#endif - - DeliverEvents(pWin, pEvent, numRects, NullWindow); - - DEALLOCATE_LOCAL(pEvent); -} - -void -miWindowExposures(pWin, prgn, other_exposed) - WindowPtr pWin; - register RegionPtr prgn, other_exposed; -{ -#ifdef NXAGENT_SERVER - - int total; - -#endif - RegionPtr exposures = prgn; - if (pWin->backStorage && prgn) - /* - * in some cases, backing store will cause a different - * region to be exposed than needs to be repainted - * (like when a window is mapped). RestoreAreas is - * allowed to return a region other than prgn, - * in which case this routine will free the resultant - * region. If exposures is null, then no events will - * be sent to the client; if prgn is empty - * no areas will be repainted. - */ - exposures = (*pWin->drawable.pScreen->RestoreAreas)(pWin, prgn); - if ((prgn && !REGION_NIL(prgn)) || - (exposures && !REGION_NIL(exposures)) || other_exposed) - { - RegionRec expRec; - int clientInterested; - - /* - * Restore from backing-store FIRST. - */ - clientInterested = (pWin->eventMask|wOtherEventMasks(pWin)) & ExposureMask; - if (other_exposed) - { - if (exposures) - { - REGION_UNION(pWin->drawable.pScreen, other_exposed, - exposures, - other_exposed); - if (exposures != prgn) - REGION_DESTROY(pWin->drawable.pScreen, exposures); - } - exposures = other_exposed; - } -#ifdef NXAGENT_SERVER - - /* - * If the number of rectangles is greater - * than 4, let the function decide. - */ - - total = REGION_NUM_RECTS(exposures); - - if (clientInterested && exposures && (total > RECTLIMIT || - (total > 4 && nxagentExtentsPredicate(total) == 1))) -#else - if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT)) -#endif - { - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-). - */ - BoxRec box; - - box = *REGION_EXTENTS( pWin->drawable.pScreen, exposures); - if (exposures == prgn) { - exposures = &expRec; - REGION_INIT( pWin->drawable.pScreen, exposures, &box, 1); - REGION_RESET( pWin->drawable.pScreen, prgn, &box); - } else { - REGION_RESET( pWin->drawable.pScreen, exposures, &box); - REGION_UNION( pWin->drawable.pScreen, prgn, prgn, exposures); - } - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT( pWin->drawable.pScreen, prgn, prgn, &pWin->clipList); - /* need to clear out new areas of backing store, too */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - box.x1 - pWin->drawable.x, - box.y1 - pWin->drawable.y, - box.x2 - box.x1, - box.y2 - box.y1, - FALSE); - } - if (prgn && !REGION_NIL(prgn)) - (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, prgn, PW_BACKGROUND); - if (clientInterested && exposures && !REGION_NIL(exposures)) - miSendExposures(pWin, exposures, - pWin->drawable.x, pWin->drawable.y); - if (exposures == &expRec) - { - REGION_UNINIT( pWin->drawable.pScreen, exposures); - } - else if (exposures && exposures != prgn && exposures != other_exposed) - REGION_DESTROY( pWin->drawable.pScreen, exposures); - if (prgn) - REGION_EMPTY( pWin->drawable.pScreen, prgn); - } - else if (exposures && exposures != prgn) - REGION_DESTROY( pWin->drawable.pScreen, exposures); -} - - -/* - this code is highly unlikely. it is not haile selassie. - - there is some hair here. we can't just use the window's -clip region as it is, because if we are painting the border, -the border is not in the client area and so we will be excluded -when we validate the GC, and if we are painting a parent-relative -background, the area we want to paint is in some other window. -since we trust the code calling us to tell us to paint only areas -that are really ours, we will temporarily give the window a -clipList the size of the whole screen and an origin at (0,0). -this more or less assumes that ddX code will do translation -based on the window's absolute position, and that ValidateGC will -look at clipList, and that no other fields from the -window will be used. it's not possible to just draw -in the root because it may be a different depth. - -to get the tile to align correctly we set the GC's tile origin to -be the (x,y) of the window's upper left corner, after which we -get the right bits when drawing into the root. - -because the clip_mask is being set to None, we may call DoChangeGC with -fPointer set true, thus we no longer need to install the background or -border tile in the resource table. -*/ - -static RESTYPE ResType = 0; -static int numGCs = 0; -static GCPtr screenContext[MAXSCREENS]; - -/*ARGSUSED*/ -static int -tossGC ( - pointer value, - XID id) -{ - GCPtr pGC = (GCPtr)value; - screenContext[pGC->pScreen->myNum] = (GCPtr)NULL; - FreeGC (pGC, id); - numGCs--; - if (!numGCs) - ResType = 0; - - return 0; -} - - -void -miPaintWindow(pWin, prgn, what) -register WindowPtr pWin; -RegionPtr prgn; -int what; -{ - int status; - - Bool usingScratchGC = FALSE; - WindowPtr pRoot; - -#define FUNCTION 0 -#define FOREGROUND 1 -#define TILE 2 -#define FILLSTYLE 3 -#define ABSX 4 -#define ABSY 5 -#define CLIPMASK 6 -#define SUBWINDOW 7 -#define COUNT_BITS 8 - - ChangeGCVal gcval[7]; - ChangeGCVal newValues [COUNT_BITS]; - - BITS32 gcmask, index, mask; - RegionRec prgnWin; - DDXPointRec oldCorner; - BoxRec box; - WindowPtr pBgWin; - GCPtr pGC; - register int i; - register BoxPtr pbox; - register ScreenPtr pScreen = pWin->drawable.pScreen; - register xRectangle *prect; - int numRects; - -#ifdef NXAGENT_SERVER - - /* - * Set the elements reported by the compiler - * as uninitialized. - */ - - prgnWin.extents.x1 = 0; - prgnWin.extents.y1 = 0; - prgnWin.extents.x2 = 0; - prgnWin.extents.y2 = 0; - - prgnWin.data = NULL; - - oldCorner.x = 0; - oldCorner.y = 0; - -#endif - - gcmask = 0; - - if (what == PW_BACKGROUND) - { - switch (pWin->backgroundState) { - case None: - return; - case ParentRelative: - (*pWin->parent->drawable.pScreen->PaintWindowBackground)(pWin->parent, prgn, what); - return; - case BackgroundPixel: - newValues[FOREGROUND].val = pWin->background.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - break; - case BackgroundPixmap: - newValues[TILE].ptr = (pointer)pWin->background.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - break; - } - } - else - { - if (pWin->borderIsPixel) - { - newValues[FOREGROUND].val = pWin->border.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - } - else - { - newValues[TILE].ptr = (pointer)pWin->border.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - } - } - - prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(prgn) * - sizeof(xRectangle)); - if (!prect) - return; - - newValues[FUNCTION].val = GXcopy; - gcmask |= GCFunction | GCClipMask; - - i = pScreen->myNum; - pRoot = WindowTable[i]; - - pBgWin = pWin; - if (what == PW_BORDER) - { - while (pBgWin->backgroundState == ParentRelative) - pBgWin = pBgWin->parent; - } - - if ((pWin->drawable.depth != pRoot->drawable.depth) || - (pWin->drawable.bitsPerPixel != pRoot->drawable.bitsPerPixel)) - { - usingScratchGC = TRUE; - pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen); - if (!pGC) - { - DEALLOCATE_LOCAL(prect); - return; - } - /* - * mash the clip list so we can paint the border by - * mangling the window in place, pretending it - * spans the entire screen - */ - if (what == PW_BORDER) - { - prgnWin = pWin->clipList; - oldCorner.x = pWin->drawable.x; - oldCorner.y = pWin->drawable.y; - pWin->drawable.x = pWin->drawable.y = 0; - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - } - else - { - newValues[ABSX].val = 0; - newValues[ABSY].val = 0; - } - } else { - /* - * draw the background to the root window - */ - if (screenContext[i] == (GCPtr)NULL) - { - if (!ResType && !(ResType = CreateNewResourceType(tossGC))) - return; - screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0, - (XID *)NULL, &status); - if (!screenContext[i]) - return; - numGCs++; - if (!AddResource(FakeClientID(0), ResType, - (pointer)screenContext[i])) - return; - } - pGC = screenContext[i]; - newValues[SUBWINDOW].val = IncludeInferiors; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - gcmask |= GCSubwindowMode; - pWin = pRoot; - } - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack); - - mask = gcmask; - gcmask = 0; - i = 0; - while (mask) { - index = lowbit (mask); - mask &= ~index; - switch (index) { - case GCFunction: - if (pGC->alu != newValues[FUNCTION].val) { - gcmask |= index; - gcval[i++].val = newValues[FUNCTION].val; - } - break; - case GCTileStipXOrigin: - if ( pGC->patOrg.x != newValues[ABSX].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSX].val; - } - break; - case GCTileStipYOrigin: - if ( pGC->patOrg.y != newValues[ABSY].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSY].val; - } - break; - case GCClipMask: - if ( pGC->clientClipType != CT_NONE) { - gcmask |= index; - gcval[i++].val = CT_NONE; - } - break; - case GCSubwindowMode: - if ( pGC->subWindowMode != newValues[SUBWINDOW].val) { - gcmask |= index; - gcval[i++].val = newValues[SUBWINDOW].val; - } - break; - case GCTile: - if (pGC->tileIsPixel || pGC->tile.pixmap != newValues[TILE].ptr) - { - gcmask |= index; - gcval[i++].ptr = newValues[TILE].ptr; - } - break; - case GCFillStyle: - if ( pGC->fillStyle != newValues[FILLSTYLE].val) { - gcmask |= index; - gcval[i++].val = newValues[FILLSTYLE].val; - } - break; - case GCForeground: - if ( pGC->fgPixel != newValues[FOREGROUND].val) { - gcmask |= index; - gcval[i++].val = newValues[FOREGROUND].val; - } - break; - } - } - - if (gcmask) - dixChangeGC(NullClient, pGC, gcmask, NULL, gcval); - - if (pWin->drawable.serialNumber != pGC->serialNumber) - ValidateGC((DrawablePtr)pWin, pGC); - - numRects = REGION_NUM_RECTS(prgn); - pbox = REGION_RECTS(prgn); - for (i= numRects; --i >= 0; pbox++, prect++) - { - prect->x = pbox->x1 - pWin->drawable.x; - prect->y = pbox->y1 - pWin->drawable.y; - prect->width = pbox->x2 - pbox->x1; - prect->height = pbox->y2 - pbox->y1; - } - prect -= numRects; - (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect); - DEALLOCATE_LOCAL(prect); - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing); - - if (usingScratchGC) - { - if (what == PW_BORDER) - { - REGION_UNINIT(pScreen, &pWin->clipList); - pWin->clipList = prgnWin; - pWin->drawable.x = oldCorner.x; - pWin->drawable.y = oldCorner.y; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - FreeScratchGC(pGC); - } -} - - -/* MICLEARDRAWABLE -- sets the entire drawable to the background color of - * the GC. Useful when we have a scratch drawable and need to initialize - * it. */ -void -miClearDrawable(pDraw, pGC) - DrawablePtr pDraw; - GCPtr pGC; -{ - XID fg = pGC->fgPixel; - XID bg = pGC->bgPixel; - xRectangle rect; - - rect.x = 0; - rect.y = 0; - rect.width = pDraw->width; - rect.height = pDraw->height; - DoChangeGC(pGC, GCForeground, &bg, 0); - ValidateGC(pDraw, pGC); - (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect); - DoChangeGC(pGC, GCForeground, &fg, 0); - ValidateGC(pDraw, pGC); -} - -#endif /* NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.XF86.original deleted file mode 100644 index ca896b9e0..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c.XF86.original +++ /dev/null @@ -1,873 +0,0 @@ -/* $XFree86: xc/programs/Xserver/mi/miexpose.c,v 3.9 2001/12/14 20:00:22 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ - -/* $Xorg: miexpose.c,v 1.4 2001/02/09 02:05:20 xorgcvs Exp $ */ - -#include "X.h" -#define NEED_EVENTS -#include "Xproto.h" -#include "Xprotostr.h" - -#include "misc.h" -#include "regionstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "windowstr.h" -#include "pixmap.h" -#include "input.h" - -#include "dixstruct.h" -#include "mi.h" -#include "Xmd.h" - -#include "globals.h" - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -/* - machine-independent graphics exposure code. any device that uses -the region package can call this. -*/ - -#ifndef RECTLIMIT -#define RECTLIMIT 25 /* pick a number, any number > 8 */ -#endif - -/* miHandleExposures - generate a region for exposures for areas that were copied from obscured or -non-existent areas to non-obscured areas of the destination. Paint the -background for the region, if the destination is a window. - -NOTE: - this should generally be called, even if graphicsExposures is false, -because this is where bits get recovered from backing store. - -NOTE: - added argument 'plane' is used to indicate how exposures from backing -store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea -should be used, else a CopyPlane of the indicated plane will be used. The -exposing is done by the backing store's GraphicsExpose function, of course. - -*/ - -RegionPtr -miHandleExposures(pSrcDrawable, pDstDrawable, - pGC, srcx, srcy, width, height, dstx, dsty, plane) - register DrawablePtr pSrcDrawable; - register DrawablePtr pDstDrawable; - GCPtr pGC; - int srcx, srcy; - int width, height; - int dstx, dsty; - unsigned long plane; -{ - register ScreenPtr pscr; - RegionPtr prgnSrcClip; /* drawable-relative source clip */ - RegionRec rgnSrcRec; - RegionPtr prgnDstClip; /* drawable-relative dest clip */ - RegionRec rgnDstRec; - BoxRec srcBox; /* unclipped source */ - RegionRec rgnExposed; /* exposed region, calculated source- - relative, made dst relative to - intersect with visible parts of - dest and send events to client, - and then screen relative to paint - the window background - */ - WindowPtr pSrcWin; - BoxRec expBox; - Bool extents; - - /* This prevents warning about pscr not being used. */ - pGC->pScreen = pscr = pGC->pScreen; - - /* avoid work if we can */ - if (!pGC->graphicsExposures && - (pDstDrawable->type == DRAWABLE_PIXMAP) && - ((pSrcDrawable->type == DRAWABLE_PIXMAP) || - (((WindowPtr)pSrcDrawable)->backStorage == NULL))) - return NULL; - - srcBox.x1 = srcx; - srcBox.y1 = srcy; - srcBox.x2 = srcx+width; - srcBox.y2 = srcy+height; - - if (pSrcDrawable->type != DRAWABLE_PIXMAP) - { - BoxRec TsrcBox; - - TsrcBox.x1 = srcx + pSrcDrawable->x; - TsrcBox.y1 = srcy + pSrcDrawable->y; - TsrcBox.x2 = TsrcBox.x1 + width; - TsrcBox.y2 = TsrcBox.y1 + height; - pSrcWin = (WindowPtr) pSrcDrawable; - if (pGC->subWindowMode == IncludeInferiors) - { - prgnSrcClip = NotClippedByChildren (pSrcWin); - if ((RECT_IN_REGION(pscr, prgnSrcClip, &TsrcBox)) == rgnIN) - { - REGION_DESTROY(pscr, prgnSrcClip); - return NULL; - } - } - else - { - if ((RECT_IN_REGION(pscr, &pSrcWin->clipList, &TsrcBox)) == rgnIN) - return NULL; - prgnSrcClip = &rgnSrcRec; - REGION_INIT(pscr, prgnSrcClip, NullBox, 0); - REGION_COPY(pscr, prgnSrcClip, &pSrcWin->clipList); - } - REGION_TRANSLATE(pscr, prgnSrcClip, - -pSrcDrawable->x, -pSrcDrawable->y); - } - else - { - BoxRec box; - - if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) && - (srcBox.x2 <= pSrcDrawable->width) && - (srcBox.y2 <= pSrcDrawable->height)) - return NULL; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pSrcDrawable->width; - box.y2 = pSrcDrawable->height; - prgnSrcClip = &rgnSrcRec; - REGION_INIT(pscr, prgnSrcClip, &box, 1); - pSrcWin = (WindowPtr)NULL; - } - - if (pDstDrawable == pSrcDrawable) - { - prgnDstClip = prgnSrcClip; - } - else if (pDstDrawable->type != DRAWABLE_PIXMAP) - { - if (pGC->subWindowMode == IncludeInferiors) - { - prgnDstClip = NotClippedByChildren((WindowPtr)pDstDrawable); - } - else - { - prgnDstClip = &rgnDstRec; - REGION_INIT(pscr, prgnDstClip, NullBox, 0); - REGION_COPY(pscr, prgnDstClip, - &((WindowPtr)pDstDrawable)->clipList); - } - REGION_TRANSLATE(pscr, prgnDstClip, - -pDstDrawable->x, -pDstDrawable->y); - } - else - { - BoxRec box; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pDstDrawable->width; - box.y2 = pDstDrawable->height; - prgnDstClip = &rgnDstRec; - REGION_INIT(pscr, prgnDstClip, &box, 1); - } - - /* drawable-relative source region */ - REGION_INIT(pscr, &rgnExposed, &srcBox, 1); - - /* now get the hidden parts of the source box*/ - REGION_SUBTRACT(pscr, &rgnExposed, &rgnExposed, prgnSrcClip); - - if (pSrcWin && pSrcWin->backStorage) - { - /* - * Copy any areas from the source backing store. Modifies - * rgnExposed. - */ - (* pSrcWin->drawable.pScreen->ExposeCopy) ((WindowPtr)pSrcDrawable, - pDstDrawable, - pGC, - &rgnExposed, - srcx, srcy, - dstx, dsty, - plane); - } - - /* move them over the destination */ - REGION_TRANSLATE(pscr, &rgnExposed, dstx-srcx, dsty-srcy); - - /* intersect with visible areas of dest */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, prgnDstClip); - - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-) - * for windows. - */ - extents = pGC->graphicsExposures && - (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) && - (pDstDrawable->type != DRAWABLE_PIXMAP); -#ifdef SHAPE - if (pSrcWin) - { - RegionPtr region; - if (!(region = wClipShape (pSrcWin))) - region = wBoundingShape (pSrcWin); - /* - * If you try to CopyArea the extents of a shaped window, compacting the - * exposed region will undo all our work! - */ - if (extents && pSrcWin && region && - (RECT_IN_REGION(pscr, region, &srcBox) != rgnIN)) - extents = FALSE; - } -#endif - if (extents) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - expBox = *REGION_EXTENTS(pscr, &rgnExposed); - REGION_RESET(pscr, &rgnExposed, &expBox); - /* need to clear out new areas of backing store */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - expBox.x1, - expBox.y1, - expBox.x2 - expBox.x1, - expBox.y2 - expBox.y1, - FALSE); - } - if ((pDstDrawable->type != DRAWABLE_PIXMAP) && - (((WindowPtr)pDstDrawable)->backgroundState != None)) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - /* make the exposed area screen-relative */ - REGION_TRANSLATE(pscr, &rgnExposed, - pDstDrawable->x, pDstDrawable->y); - - if (extents) - { - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, &pWin->clipList); - } - (*pWin->drawable.pScreen->PaintWindowBackground)( - (WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND); - - if (extents) - { - REGION_RESET(pscr, &rgnExposed, &expBox); - } - else - REGION_TRANSLATE(pscr, &rgnExposed, - -pDstDrawable->x, -pDstDrawable->y); - } - if (prgnDstClip == &rgnDstRec) - { - REGION_UNINIT(pscr, prgnDstClip); - } - else if (prgnDstClip != prgnSrcClip) - { - REGION_DESTROY(pscr, prgnDstClip); - } - - if (prgnSrcClip == &rgnSrcRec) - { - REGION_UNINIT(pscr, prgnSrcClip); - } - else - { - REGION_DESTROY(pscr, prgnSrcClip); - } - - if (pGC->graphicsExposures) - { - /* don't look */ - RegionPtr exposed = REGION_CREATE(pscr, NullBox, 0); - *exposed = rgnExposed; - return exposed; - } - else - { - REGION_UNINIT(pscr, &rgnExposed); - return NULL; - } -} - -/* send GraphicsExpose events, or a NoExpose event, based on the region */ - -void -miSendGraphicsExpose (client, pRgn, drawable, major, minor) - ClientPtr client; - RegionPtr pRgn; - XID drawable; - int major; - int minor; -{ - if (pRgn && !REGION_NIL(pRgn)) - { - xEvent *pEvent; - register xEvent *pe; - register BoxPtr pBox; - register int i; - int numRects; - - numRects = REGION_NUM_RECTS(pRgn); - pBox = REGION_RECTS(pRgn); - if(!(pEvent = (xEvent *)ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - pe = pEvent; - - for (i=1; i<=numRects; i++, pe++, pBox++) - { - pe->u.u.type = GraphicsExpose; - pe->u.graphicsExposure.drawable = drawable; - pe->u.graphicsExposure.x = pBox->x1; - pe->u.graphicsExposure.y = pBox->y1; - pe->u.graphicsExposure.width = pBox->x2 - pBox->x1; - pe->u.graphicsExposure.height = pBox->y2 - pBox->y1; - pe->u.graphicsExposure.count = numRects - i; - pe->u.graphicsExposure.majorEvent = major; - pe->u.graphicsExposure.minorEvent = minor; - } - TryClientEvents(client, pEvent, numRects, - (Mask)0, NoEventMask, NullGrab); - DEALLOCATE_LOCAL(pEvent); - } - else - { - xEvent event; - event.u.u.type = NoExpose; - event.u.noExposure.drawable = drawable; - event.u.noExposure.majorEvent = major; - event.u.noExposure.minorEvent = minor; - TryClientEvents(client, &event, 1, - (Mask)0, NoEventMask, NullGrab); - } -} - - -void -miSendExposures(pWin, pRgn, dx, dy) - WindowPtr pWin; - RegionPtr pRgn; - register int dx, dy; -{ - register BoxPtr pBox; - int numRects; - register xEvent *pEvent, *pe; - register int i; - - pBox = REGION_RECTS(pRgn); - numRects = REGION_NUM_RECTS(pRgn); - if(!(pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - - for (i=numRects, pe = pEvent; --i >= 0; pe++, pBox++) - { - pe->u.u.type = Expose; - pe->u.expose.window = pWin->drawable.id; - pe->u.expose.x = pBox->x1 - dx; - pe->u.expose.y = pBox->y1 - dy; - pe->u.expose.width = pBox->x2 - pBox->x1; - pe->u.expose.height = pBox->y2 - pBox->y1; - pe->u.expose.count = i; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - int scrnum = pWin->drawable.pScreen->myNum; - int x = 0, y = 0; - XID realWin = 0; - - if(!pWin->parent) { - x = panoramiXdataPtr[scrnum].x; - y = panoramiXdataPtr[scrnum].y; - pWin = WindowTable[0]; - realWin = pWin->drawable.id; - } else if (scrnum) { - PanoramiXRes *win; - win = PanoramiXFindIDByScrnum(XRT_WINDOW, - pWin->drawable.id, scrnum); - if(!win) { - DEALLOCATE_LOCAL(pEvent); - return; - } - realWin = win->info[0].id; - pWin = LookupIDByType(realWin, RT_WINDOW); - } - if(x || y || scrnum) - for (i = 0; i < numRects; i++) { - pEvent[i].u.expose.window = realWin; - pEvent[i].u.expose.x += x; - pEvent[i].u.expose.y += y; - } - } -#endif - - DeliverEvents(pWin, pEvent, numRects, NullWindow); - - DEALLOCATE_LOCAL(pEvent); -} - -void -miWindowExposures(pWin, prgn, other_exposed) - WindowPtr pWin; - register RegionPtr prgn, other_exposed; -{ - RegionPtr exposures = prgn; - if (pWin->backStorage && prgn) - /* - * in some cases, backing store will cause a different - * region to be exposed than needs to be repainted - * (like when a window is mapped). RestoreAreas is - * allowed to return a region other than prgn, - * in which case this routine will free the resultant - * region. If exposures is null, then no events will - * be sent to the client; if prgn is empty - * no areas will be repainted. - */ - exposures = (*pWin->drawable.pScreen->RestoreAreas)(pWin, prgn); - if ((prgn && !REGION_NIL(prgn)) || - (exposures && !REGION_NIL(exposures)) || other_exposed) - { - RegionRec expRec; - int clientInterested; - - /* - * Restore from backing-store FIRST. - */ - clientInterested = (pWin->eventMask|wOtherEventMasks(pWin)) & ExposureMask; - if (other_exposed) - { - if (exposures) - { - REGION_UNION(pWin->drawable.pScreen, other_exposed, - exposures, - other_exposed); - if (exposures != prgn) - REGION_DESTROY(pWin->drawable.pScreen, exposures); - } - exposures = other_exposed; - } - if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT)) - { - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-). - */ - BoxRec box; - - box = *REGION_EXTENTS( pWin->drawable.pScreen, exposures); - if (exposures == prgn) { - exposures = &expRec; - REGION_INIT( pWin->drawable.pScreen, exposures, &box, 1); - REGION_RESET( pWin->drawable.pScreen, prgn, &box); - } else { - REGION_RESET( pWin->drawable.pScreen, exposures, &box); - REGION_UNION( pWin->drawable.pScreen, prgn, prgn, exposures); - } - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT( pWin->drawable.pScreen, prgn, prgn, &pWin->clipList); - /* need to clear out new areas of backing store, too */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - box.x1 - pWin->drawable.x, - box.y1 - pWin->drawable.y, - box.x2 - box.x1, - box.y2 - box.y1, - FALSE); - } - if (prgn && !REGION_NIL(prgn)) - (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, prgn, PW_BACKGROUND); - if (clientInterested && exposures && !REGION_NIL(exposures)) - miSendExposures(pWin, exposures, - pWin->drawable.x, pWin->drawable.y); - if (exposures == &expRec) - { - REGION_UNINIT( pWin->drawable.pScreen, exposures); - } - else if (exposures && exposures != prgn && exposures != other_exposed) - REGION_DESTROY( pWin->drawable.pScreen, exposures); - if (prgn) - REGION_EMPTY( pWin->drawable.pScreen, prgn); - } - else if (exposures && exposures != prgn) - REGION_DESTROY( pWin->drawable.pScreen, exposures); -} - - -/* - this code is highly unlikely. it is not haile selassie. - - there is some hair here. we can't just use the window's -clip region as it is, because if we are painting the border, -the border is not in the client area and so we will be excluded -when we validate the GC, and if we are painting a parent-relative -background, the area we want to paint is in some other window. -since we trust the code calling us to tell us to paint only areas -that are really ours, we will temporarily give the window a -clipList the size of the whole screen and an origin at (0,0). -this more or less assumes that ddX code will do translation -based on the window's absolute position, and that ValidateGC will -look at clipList, and that no other fields from the -window will be used. it's not possible to just draw -in the root because it may be a different depth. - -to get the tile to align correctly we set the GC's tile origin to -be the (x,y) of the window's upper left corner, after which we -get the right bits when drawing into the root. - -because the clip_mask is being set to None, we may call DoChangeGC with -fPointer set true, thus we no longer need to install the background or -border tile in the resource table. -*/ - -static RESTYPE ResType = 0; -static int numGCs = 0; -static GCPtr screenContext[MAXSCREENS]; - -/*ARGSUSED*/ -static int -tossGC ( - pointer value, - XID id) -{ - GCPtr pGC = (GCPtr)value; - screenContext[pGC->pScreen->myNum] = (GCPtr)NULL; - FreeGC (pGC, id); - numGCs--; - if (!numGCs) - ResType = 0; - - return 0; -} - - -void -miPaintWindow(pWin, prgn, what) -register WindowPtr pWin; -RegionPtr prgn; -int what; -{ - int status; - - Bool usingScratchGC = FALSE; - WindowPtr pRoot; - -#define FUNCTION 0 -#define FOREGROUND 1 -#define TILE 2 -#define FILLSTYLE 3 -#define ABSX 4 -#define ABSY 5 -#define CLIPMASK 6 -#define SUBWINDOW 7 -#define COUNT_BITS 8 - - ChangeGCVal gcval[7]; - ChangeGCVal newValues [COUNT_BITS]; - - BITS32 gcmask, index, mask; - RegionRec prgnWin; - DDXPointRec oldCorner; - BoxRec box; - WindowPtr pBgWin; - GCPtr pGC; - register int i; - register BoxPtr pbox; - register ScreenPtr pScreen = pWin->drawable.pScreen; - register xRectangle *prect; - int numRects; - - gcmask = 0; - - if (what == PW_BACKGROUND) - { - switch (pWin->backgroundState) { - case None: - return; - case ParentRelative: - (*pWin->parent->drawable.pScreen->PaintWindowBackground)(pWin->parent, prgn, what); - return; - case BackgroundPixel: - newValues[FOREGROUND].val = pWin->background.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - break; - case BackgroundPixmap: - newValues[TILE].ptr = (pointer)pWin->background.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - break; - } - } - else - { - if (pWin->borderIsPixel) - { - newValues[FOREGROUND].val = pWin->border.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - } - else - { - newValues[TILE].ptr = (pointer)pWin->border.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - } - } - - prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(prgn) * - sizeof(xRectangle)); - if (!prect) - return; - - newValues[FUNCTION].val = GXcopy; - gcmask |= GCFunction | GCClipMask; - - i = pScreen->myNum; - pRoot = WindowTable[i]; - - pBgWin = pWin; - if (what == PW_BORDER) - { - while (pBgWin->backgroundState == ParentRelative) - pBgWin = pBgWin->parent; - } - - if ((pWin->drawable.depth != pRoot->drawable.depth) || - (pWin->drawable.bitsPerPixel != pRoot->drawable.bitsPerPixel)) - { - usingScratchGC = TRUE; - pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen); - if (!pGC) - { - DEALLOCATE_LOCAL(prect); - return; - } - /* - * mash the clip list so we can paint the border by - * mangling the window in place, pretending it - * spans the entire screen - */ - if (what == PW_BORDER) - { - prgnWin = pWin->clipList; - oldCorner.x = pWin->drawable.x; - oldCorner.y = pWin->drawable.y; - pWin->drawable.x = pWin->drawable.y = 0; - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - } - else - { - newValues[ABSX].val = 0; - newValues[ABSY].val = 0; - } - } else { - /* - * draw the background to the root window - */ - if (screenContext[i] == (GCPtr)NULL) - { - if (!ResType && !(ResType = CreateNewResourceType(tossGC))) - return; - screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0, - (XID *)NULL, &status); - if (!screenContext[i]) - return; - numGCs++; - if (!AddResource(FakeClientID(0), ResType, - (pointer)screenContext[i])) - return; - } - pGC = screenContext[i]; - newValues[SUBWINDOW].val = IncludeInferiors; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - gcmask |= GCSubwindowMode; - pWin = pRoot; - } - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack); - - mask = gcmask; - gcmask = 0; - i = 0; - while (mask) { - index = lowbit (mask); - mask &= ~index; - switch (index) { - case GCFunction: - if (pGC->alu != newValues[FUNCTION].val) { - gcmask |= index; - gcval[i++].val = newValues[FUNCTION].val; - } - break; - case GCTileStipXOrigin: - if ( pGC->patOrg.x != newValues[ABSX].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSX].val; - } - break; - case GCTileStipYOrigin: - if ( pGC->patOrg.y != newValues[ABSY].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSY].val; - } - break; - case GCClipMask: - if ( pGC->clientClipType != CT_NONE) { - gcmask |= index; - gcval[i++].val = CT_NONE; - } - break; - case GCSubwindowMode: - if ( pGC->subWindowMode != newValues[SUBWINDOW].val) { - gcmask |= index; - gcval[i++].val = newValues[SUBWINDOW].val; - } - break; - case GCTile: - if (pGC->tileIsPixel || pGC->tile.pixmap != newValues[TILE].ptr) - { - gcmask |= index; - gcval[i++].ptr = newValues[TILE].ptr; - } - break; - case GCFillStyle: - if ( pGC->fillStyle != newValues[FILLSTYLE].val) { - gcmask |= index; - gcval[i++].val = newValues[FILLSTYLE].val; - } - break; - case GCForeground: - if ( pGC->fgPixel != newValues[FOREGROUND].val) { - gcmask |= index; - gcval[i++].val = newValues[FOREGROUND].val; - } - break; - } - } - - if (gcmask) - dixChangeGC(NullClient, pGC, gcmask, NULL, gcval); - - if (pWin->drawable.serialNumber != pGC->serialNumber) - ValidateGC((DrawablePtr)pWin, pGC); - - numRects = REGION_NUM_RECTS(prgn); - pbox = REGION_RECTS(prgn); - for (i= numRects; --i >= 0; pbox++, prect++) - { - prect->x = pbox->x1 - pWin->drawable.x; - prect->y = pbox->y1 - pWin->drawable.y; - prect->width = pbox->x2 - pbox->x1; - prect->height = pbox->y2 - pbox->y1; - } - prect -= numRects; - (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect); - DEALLOCATE_LOCAL(prect); - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing); - - if (usingScratchGC) - { - if (what == PW_BORDER) - { - REGION_UNINIT(pScreen, &pWin->clipList); - pWin->clipList = prgnWin; - pWin->drawable.x = oldCorner.x; - pWin->drawable.y = oldCorner.y; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - FreeScratchGC(pGC); - } -} - - -/* MICLEARDRAWABLE -- sets the entire drawable to the background color of - * the GC. Useful when we have a scratch drawable and need to initialize - * it. */ -void -miClearDrawable(pDraw, pGC) - DrawablePtr pDraw; - GCPtr pGC; -{ - XID fg = pGC->fgPixel; - XID bg = pGC->bgPixel; - xRectangle rect; - - rect.x = 0; - rect.y = 0; - rect.width = pDraw->width; - rect.height = pDraw->height; - DoChangeGC(pGC, GCForeground, &bg, 0); - ValidateGC(pDraw, pGC); - (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect); - DoChangeGC(pGC, GCForeground, &fg, 0); - ValidateGC(pDraw, pGC); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.NX.original deleted file mode 100644 index 09901ba9c..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.NX.original +++ /dev/null @@ -1,322 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXmiglyph.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/miglyph.c,v 1.6 2000/12/05 03:13:31 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -#ifdef NXAGENT_SERVER - -#include "Render.h" - -#endif - -void -miGlyphExtents (int nlist, - GlyphListPtr list, - GlyphPtr *glyphs, - BoxPtr extents) -{ - int x1, x2, y1, y2; - int n; - GlyphPtr glyph; - int x, y; - - x = 0; - y = 0; - extents->x1 = MAXSHORT; - extents->x2 = MINSHORT; - extents->y1 = MAXSHORT; - extents->y2 = MINSHORT; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - list++; - while (n--) - { - glyph = *glyphs++; - x1 = x - glyph->info.x; - if (x1 < MINSHORT) - x1 = MINSHORT; - y1 = y - glyph->info.y; - if (y1 < MINSHORT) - y1 = MINSHORT; - x2 = x1 + glyph->info.width; - if (x2 > MAXSHORT) - x2 = MAXSHORT; - y2 = y1 + glyph->info.height; - if (y2 > MAXSHORT) - y2 = MAXSHORT; - if (x1 < extents->x1) - extents->x1 = x1; - if (x2 > extents->x2) - extents->x2 = x2; - if (y1 < extents->y1) - extents->y1 = y1; - if (y2 > extents->y2) - extents->y2 = y2; - x += glyph->info.xOff; - y += glyph->info.yOff; - } - } -} - -#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0) - -void -miGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr list, - GlyphPtr *glyphs) -{ - PixmapPtr pPixmap = 0; - PicturePtr pPicture; - PixmapPtr pMaskPixmap = 0; - PicturePtr pMask; - ScreenPtr pScreen = pDst->pDrawable->pScreen; - int width = 0, height = 0; - int x, y; - int xDst = list->xOff, yDst = list->yOff; - int n; - GlyphPtr glyph; - int error; - BoxRec extents; - CARD32 component_alpha; - - #ifdef NXAGENT_SERVER - - /* - * Get rid of the warning. - */ - - extents.x1 = 0; - extents.y1 = 0; - - #endif - - if (maskFormat) - { - GCPtr pGC; - xRectangle rect; - - #ifdef NXAGENT_SERVER - - if (nxagentGlyphsExtents != NullBox) - { - memcpy(&extents, nxagentGlyphsExtents, sizeof(BoxRec)); - } - else - { - nxagentGlyphsExtents = (BoxPtr) xalloc(sizeof(BoxRec)); - - miGlyphExtents (nlist, list, glyphs, &extents); - - memcpy(nxagentGlyphsExtents, &extents, sizeof(BoxRec)); - } - - #else - - miGlyphExtents (nlist, list, glyphs, &extents); - - #endif - - if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1) - return; - width = extents.x2 - extents.x1; - height = extents.y2 - extents.y1; - pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, maskFormat->depth); - - if (!pMaskPixmap) - return; - - component_alpha = NeedsComponent(maskFormat->format); - pMask = CreatePicture (0, &pMaskPixmap->drawable, - maskFormat, CPComponentAlpha, &component_alpha, - serverClient, &error); - - if (!pMask) - { - (*pScreen->DestroyPixmap) (pMaskPixmap); - return; - } - pGC = GetScratchGC (pMaskPixmap->drawable.depth, pScreen); - ValidateGC (&pMaskPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect) (&pMaskPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - x = -extents.x1; - y = -extents.y1; - } - else - { - pMask = pDst; - x = 0; - y = 0; - } - pPicture = 0; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - - while (n--) - { - glyph = *glyphs++; - if (!pPicture) - { - pPixmap = GetScratchPixmapHeader (pScreen, glyph->info.width, glyph->info.height, - list->format->depth, - list->format->depth, - 0, (pointer) (glyph + 1)); - if (!pPixmap) - return; - component_alpha = NeedsComponent(list->format->format); - pPicture = CreatePicture (0, &pPixmap->drawable, list->format, - CPComponentAlpha, &component_alpha, - serverClient, &error); - if (!pPicture) - { - FreeScratchPixmapHeader (pPixmap); - return; - } - } - (*pScreen->ModifyPixmapHeader) (pPixmap, - glyph->info.width, glyph->info.height, - 0, 0, -1, (pointer) (glyph + 1)); - - #ifdef NXAGENT_SERVER - - /* - * The following line fixes a problem with glyphs that appeared - * as clipped. It was a side effect due the validate function - * "ValidatePicture" that makes a check on the Drawable serial - * number instead of the picture serial number, failing thus - * the clip mask update. - */ - - pPicture->pDrawable->serialNumber = NEXT_SERIAL_NUMBER; - - #endif - - pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - if (maskFormat) - { - CompositePicture (PictOpAdd, - pPicture, - None, - pMask, - 0, 0, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - else - { - CompositePicture (op, - pSrc, - pPicture, - pDst, - xSrc + (x - glyph->info.x) - xDst, - ySrc + (y - glyph->info.y) - yDst, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - x += glyph->info.xOff; - y += glyph->info.yOff; - } - - list++; - if (pPicture) - { - FreeScratchPixmapHeader (pPixmap); - FreePicture ((pointer) pPicture, 0); - pPicture = 0; - pPixmap = 0; - } - } - if (maskFormat) - { - x = extents.x1; - y = extents.y1; - CompositePicture (op, - pSrc, - pMask, - pDst, - xSrc + x - xDst, - ySrc + y - yDst, - 0, 0, - x, y, - width, height); - - FreePicture ((pointer) pMask, (XID) 0); - (*pScreen->DestroyPixmap) (pMaskPixmap); - } - -} - -#endif /* NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.XF86.original deleted file mode 100644 index 00b6764d6..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmiglyph.c.XF86.original +++ /dev/null @@ -1,239 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/miglyph.c,v 1.6 2000/12/05 03:13:31 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -void -miGlyphExtents (int nlist, - GlyphListPtr list, - GlyphPtr *glyphs, - BoxPtr extents) -{ - int x1, x2, y1, y2; - int n; - GlyphPtr glyph; - int x, y; - - x = 0; - y = 0; - extents->x1 = MAXSHORT; - extents->x2 = MINSHORT; - extents->y1 = MAXSHORT; - extents->y2 = MINSHORT; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - list++; - while (n--) - { - glyph = *glyphs++; - x1 = x - glyph->info.x; - if (x1 < MINSHORT) - x1 = MINSHORT; - y1 = y - glyph->info.y; - if (y1 < MINSHORT) - y1 = MINSHORT; - x2 = x1 + glyph->info.width; - if (x2 > MAXSHORT) - x2 = MAXSHORT; - y2 = y1 + glyph->info.height; - if (y2 > MAXSHORT) - y2 = MAXSHORT; - if (x1 < extents->x1) - extents->x1 = x1; - if (x2 > extents->x2) - extents->x2 = x2; - if (y1 < extents->y1) - extents->y1 = y1; - if (y2 > extents->y2) - extents->y2 = y2; - x += glyph->info.xOff; - y += glyph->info.yOff; - } - } -} - -#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0) - -void -miGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr list, - GlyphPtr *glyphs) -{ - PixmapPtr pPixmap = 0; - PicturePtr pPicture; - PixmapPtr pMaskPixmap = 0; - PicturePtr pMask; - ScreenPtr pScreen = pDst->pDrawable->pScreen; - int width = 0, height = 0; - int x, y; - int xDst = list->xOff, yDst = list->yOff; - int n; - GlyphPtr glyph; - int error; - BoxRec extents; - CARD32 component_alpha; - - if (maskFormat) - { - GCPtr pGC; - xRectangle rect; - - miGlyphExtents (nlist, list, glyphs, &extents); - - if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1) - return; - width = extents.x2 - extents.x1; - height = extents.y2 - extents.y1; - pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, maskFormat->depth); - if (!pMaskPixmap) - return; - component_alpha = NeedsComponent(maskFormat->format); - pMask = CreatePicture (0, &pMaskPixmap->drawable, - maskFormat, CPComponentAlpha, &component_alpha, - serverClient, &error); - if (!pMask) - { - (*pScreen->DestroyPixmap) (pMaskPixmap); - return; - } - pGC = GetScratchGC (pMaskPixmap->drawable.depth, pScreen); - ValidateGC (&pMaskPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect) (&pMaskPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - x = -extents.x1; - y = -extents.y1; - } - else - { - pMask = pDst; - x = 0; - y = 0; - } - pPicture = 0; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - while (n--) - { - glyph = *glyphs++; - if (!pPicture) - { - pPixmap = GetScratchPixmapHeader (pScreen, glyph->info.width, glyph->info.height, - list->format->depth, - list->format->depth, - 0, (pointer) (glyph + 1)); - if (!pPixmap) - return; - component_alpha = NeedsComponent(list->format->format); - pPicture = CreatePicture (0, &pPixmap->drawable, list->format, - CPComponentAlpha, &component_alpha, - serverClient, &error); - if (!pPicture) - { - FreeScratchPixmapHeader (pPixmap); - return; - } - } - (*pScreen->ModifyPixmapHeader) (pPixmap, - glyph->info.width, glyph->info.height, - 0, 0, -1, (pointer) (glyph + 1)); - pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - if (maskFormat) - { - CompositePicture (PictOpAdd, - pPicture, - None, - pMask, - 0, 0, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - else - { - CompositePicture (op, - pSrc, - pPicture, - pDst, - xSrc + (x - glyph->info.x) - xDst, - ySrc + (y - glyph->info.y) - yDst, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - x += glyph->info.xOff; - y += glyph->info.yOff; - } - list++; - if (pPicture) - { - FreeScratchPixmapHeader (pPixmap); - FreePicture ((pointer) pPicture, 0); - pPicture = 0; - pPixmap = 0; - } - } - if (maskFormat) - { - x = extents.x1; - y = extents.y1; - CompositePicture (op, - pSrc, - pMask, - pDst, - xSrc + x - xDst, - ySrc + y - yDst, - 0, 0, - x, y, - width, height); - FreePicture ((pointer) pMask, (XID) 0); - (*pScreen->DestroyPixmap) (pMaskPixmap); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.NX.original deleted file mode 100644 index 7d0a99572..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.NX.original +++ /dev/null @@ -1,204 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXmitrap.c" - -#else - -/* - * $XFree86: xc/programs/Xserver/render/mitrap.c,v 1.9 2002/11/05 23:39:16 keithp Exp $ - * - * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "servermd.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -PicturePtr -miCreateAlphaPicture (ScreenPtr pScreen, - PicturePtr pDst, - PictFormatPtr pPictFormat, - CARD16 width, - CARD16 height) -{ - PixmapPtr pPixmap; - PicturePtr pPicture; - GCPtr pGC; - int error; - xRectangle rect; - - if (width > 32767 || height > 32767) - return 0; - - if (!pPictFormat) - { - if (pDst->polyEdge == PolyEdgeSharp) - pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1); - else - pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8); - if (!pPictFormat) - return 0; - } - - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, - pPictFormat->depth); - if (!pPixmap) - return 0; - pGC = GetScratchGC (pPixmap->drawable.depth, pScreen); - if (!pGC) - { - (*pScreen->DestroyPixmap) (pPixmap); - return 0; - } - ValidateGC (&pPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect)(&pPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat, - 0, 0, serverClient, &error); - (*pScreen->DestroyPixmap) (pPixmap); - return pPicture; -} - -static xFixed -miLineFixedX (xLineFixed *l, xFixed y, Bool ceil) -{ - xFixed dx = l->p2.x - l->p1.x; - xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx; - xFixed dy = l->p2.y - l->p1.y; - if (ceil) - ex += (dy - 1); - return l->p1.x + (xFixed) (ex / dy); -} - -void -miTrapezoidBounds (int ntrap, xTrapezoid *traps, BoxPtr box) -{ - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - for (; ntrap; ntrap--, traps++) - { - INT16 x1, y1, x2, y2; - - if (!xTrapezoidValid(traps)) - continue; - y1 = xFixedToInt (traps->top); - if (y1 < box->y1) - box->y1 = y1; - - y2 = xFixedToInt (xFixedCeil (traps->bottom)); - if (y2 > box->y2) - box->y2 = y2; - - x1 = xFixedToInt (min (miLineFixedX (&traps->left, traps->top, FALSE), - miLineFixedX (&traps->left, traps->bottom, FALSE))); - if (x1 < box->x1) - box->x1 = x1; - - x2 = xFixedToInt (xFixedCeil (max (miLineFixedX (&traps->right, traps->top, TRUE), - miLineFixedX (&traps->right, traps->bottom, TRUE)))); - if (x2 > box->x2) - box->x2 = x2; - } -} - -void -miTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture = 0; - BoxRec bounds; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = traps[0].left.p1.x >> 16; - yDst = traps[0].left.p1.y >> 16; - - if (maskFormat) - { - miTrapezoidBounds (ntrap, traps, &bounds); - if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - return; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - return; - } - for (; ntrap; ntrap--, traps++) - { - if (!xTrapezoidValid(traps)) - continue; - if (!maskFormat) - { - miTrapezoidBounds (1, traps, &bounds); - if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - continue; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - continue; - } - (*ps->RasterizeTrapezoid) (pPicture, traps, - -bounds.x1, -bounds.y1); - if (!maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - } - if (maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } -} - -#endif /* NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.XF86.original deleted file mode 100644 index 7f592ccd4..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmitrap.c.XF86.original +++ /dev/null @@ -1,196 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/mitrap.c,v 1.9 2002/11/05 23:39:16 keithp Exp $ - * - * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "servermd.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -PicturePtr -miCreateAlphaPicture (ScreenPtr pScreen, - PicturePtr pDst, - PictFormatPtr pPictFormat, - CARD16 width, - CARD16 height) -{ - PixmapPtr pPixmap; - PicturePtr pPicture; - GCPtr pGC; - int error; - xRectangle rect; - - if (width > 32767 || height > 32767) - return 0; - - if (!pPictFormat) - { - if (pDst->polyEdge == PolyEdgeSharp) - pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1); - else - pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8); - if (!pPictFormat) - return 0; - } - - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, - pPictFormat->depth); - if (!pPixmap) - return 0; - pGC = GetScratchGC (pPixmap->drawable.depth, pScreen); - if (!pGC) - { - (*pScreen->DestroyPixmap) (pPixmap); - return 0; - } - ValidateGC (&pPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect)(&pPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat, - 0, 0, serverClient, &error); - (*pScreen->DestroyPixmap) (pPixmap); - return pPicture; -} - -static xFixed -miLineFixedX (xLineFixed *l, xFixed y, Bool ceil) -{ - xFixed dx = l->p2.x - l->p1.x; - xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx; - xFixed dy = l->p2.y - l->p1.y; - if (ceil) - ex += (dy - 1); - return l->p1.x + (xFixed) (ex / dy); -} - -void -miTrapezoidBounds (int ntrap, xTrapezoid *traps, BoxPtr box) -{ - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - for (; ntrap; ntrap--, traps++) - { - INT16 x1, y1, x2, y2; - - if (!xTrapezoidValid(traps)) - continue; - y1 = xFixedToInt (traps->top); - if (y1 < box->y1) - box->y1 = y1; - - y2 = xFixedToInt (xFixedCeil (traps->bottom)); - if (y2 > box->y2) - box->y2 = y2; - - x1 = xFixedToInt (min (miLineFixedX (&traps->left, traps->top, FALSE), - miLineFixedX (&traps->left, traps->bottom, FALSE))); - if (x1 < box->x1) - box->x1 = x1; - - x2 = xFixedToInt (xFixedCeil (max (miLineFixedX (&traps->right, traps->top, TRUE), - miLineFixedX (&traps->right, traps->bottom, TRUE)))); - if (x2 > box->x2) - box->x2 = x2; - } -} - -void -miTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture = 0; - BoxRec bounds; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = traps[0].left.p1.x >> 16; - yDst = traps[0].left.p1.y >> 16; - - if (maskFormat) - { - miTrapezoidBounds (ntrap, traps, &bounds); - if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - return; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - return; - } - for (; ntrap; ntrap--, traps++) - { - if (!xTrapezoidValid(traps)) - continue; - if (!maskFormat) - { - miTrapezoidBounds (1, traps, &bounds); - if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - continue; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - continue; - } - (*ps->RasterizeTrapezoid) (pPicture, traps, - -bounds.x1, -bounds.y1); - if (!maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - } - if (maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.NX.original deleted file mode 100644 index ea2e7df28..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.NX.original +++ /dev/null @@ -1,1205 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXmiwindow.c" - -#else - -/* $XFree86: xc/programs/Xserver/mi/miwindow.c,v 1.7 2001/12/14 20:00:28 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: miwindow.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ -#include "X.h" -#include "miscstruct.h" -#include "region.h" -#include "mi.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" - -void -miClearToBackground(pWin, x, y, w, h, generateExposures) - WindowPtr pWin; - int x,y; - int w,h; - Bool generateExposures; -{ - BoxRec box; - RegionRec reg; - RegionPtr pBSReg = NullRegion; - ScreenPtr pScreen; - BoxPtr extents; - int x1, y1, x2, y2; - - /* compute everything using ints to avoid overflow */ - - x1 = pWin->drawable.x + x; - y1 = pWin->drawable.y + y; - if (w) - x2 = x1 + (int) w; - else - x2 = x1 + (int) pWin->drawable.width - (int) x; - if (h) - y2 = y1 + h; - else - y2 = y1 + (int) pWin->drawable.height - (int) y; - - extents = &pWin->clipList.extents; - - /* clip the resulting rectangle to the window clipList extents. This - * makes sure that the result will fit in a box, given that the - * screen is < 32768 on a side. - */ - - if (x1 < extents->x1) - x1 = extents->x1; - if (x2 > extents->x2) - x2 = extents->x2; - if (y1 < extents->y1) - y1 = extents->y1; - if (y2 > extents->y2) - y2 = extents->y2; - - if (x2 <= x1 || y2 <= y1) - { - x2 = x1 = 0; - y2 = y1 = 0; - } - - box.x1 = x1; - box.x2 = x2; - box.y1 = y1; - box.y2 = y2; - - pScreen = pWin->drawable.pScreen; - REGION_INIT(pScreen, ®, &box, 1); - if (pWin->backStorage) - { - /* - * If the window has backing-store on, call through the - * ClearToBackground vector to handle the special semantics - * (i.e. things backing store is to be cleared out and - * an Expose event is to be generated for those areas in backing - * store if generateExposures is TRUE). - */ - pBSReg = (* pScreen->ClearBackingStore)(pWin, x, y, w, h, - generateExposures); - } - - REGION_INTERSECT(pScreen, ®, ®, &pWin->clipList); - if (generateExposures) - (*pScreen->WindowExposures)(pWin, ®, pBSReg); - else if (pWin->backgroundState != None) - (*pScreen->PaintWindowBackground)(pWin, ®, PW_BACKGROUND); - REGION_UNINIT(pScreen, ®); - if (pBSReg) - REGION_DESTROY(pScreen, pBSReg); -} - -/* - * For SaveUnders using backing-store. The idea is that when a window is mapped - * with saveUnder set TRUE, any windows it obscures will have its backing - * store turned on setting the DIXsaveUnder bit, - * The backing-store code must be written to allow for this - */ - -/*- - *----------------------------------------------------------------------- - * miCheckSubSaveUnder -- - * Check all the inferiors of a window for coverage by saveUnder - * windows. Called from ChangeSaveUnder and CheckSaveUnder. - * This code is very inefficient. - * - * Results: - * TRUE if any windows need to have backing-store removed. - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -static Bool -miCheckSubSaveUnder( - register WindowPtr pParent, /* Parent to check */ - WindowPtr pFirst, /* first reconfigured window */ - RegionPtr pRegion) /* Initial area obscured by saveUnder */ -{ - register WindowPtr pChild; /* Current child */ - register ScreenPtr pScreen; /* Screen to use */ - RegionRec SubRegion; /* Area of children obscured */ - Bool res = FALSE; /* result */ - Bool subInited=FALSE;/* SubRegion initialized */ - - pScreen = pParent->drawable.pScreen; - if ( (pChild = pParent->firstChild) ) - { - /* - * build region above first changed window - */ - - for (; pChild != pFirst; pChild = pChild->nextSib) - if (pChild->viewable && pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - - /* - * check region below and including first changed window - */ - - for (; pChild; pChild = pChild->nextSib) - { - if (pChild->viewable) - { - /* - * don't save under nephew/niece windows; - * use a separate region - */ - - if (pChild->firstChild) - { - if (!subInited) - { - REGION_INIT(pScreen, &SubRegion, NullBox, 0); - subInited = TRUE; - } - REGION_COPY(pScreen, &SubRegion, pRegion); - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - &SubRegion); - } - else - { - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - pRegion); - } - - if (pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - } - } - - if (subInited) - REGION_UNINIT(pScreen, &SubRegion); - } - - /* - * Check the state of this window. DIX save unders are - * enabled for viewable windows with some client expressing - * exposure interest and which intersect the save under region - */ - - if (pParent->viewable && - ((pParent->eventMask | wOtherEventMasks(pParent)) & ExposureMask) && - REGION_NOTEMPTY(pScreen, &pParent->borderSize) && - RECT_IN_REGION(pScreen, pRegion, REGION_EXTENTS(pScreen, - &pParent->borderSize)) != rgnOUT) - { - if (!pParent->DIXsaveUnder) - { - pParent->DIXsaveUnder = TRUE; - (*pScreen->ChangeWindowAttributes) (pParent, CWBackingStore); - } - } - else - { - if (pParent->DIXsaveUnder) - { - res = TRUE; - pParent->DIXsaveUnder = FALSE; - } - } - return res; -} - - -/*- - *----------------------------------------------------------------------- - * miChangeSaveUnder -- - * Change the save-under state of a tree of windows. Called when - * a window with saveUnder TRUE is mapped/unmapped/reconfigured. - * - * Results: - * TRUE if any windows need to have backing-store removed (which - * means that PostChangeSaveUnder needs to be called later to - * finish the job). - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -Bool -miChangeSaveUnder(pWin, first) - register WindowPtr pWin; - WindowPtr first; /* First window to check. - * Used when pWin was restacked */ -{ - RegionRec rgn; /* Area obscured by saveUnder windows */ - register ScreenPtr pScreen; - Bool res; - - if (!deltaSaveUndersViewable && !numSaveUndersViewable) - return FALSE; - numSaveUndersViewable += deltaSaveUndersViewable; - deltaSaveUndersViewable = 0; - pScreen = pWin->drawable.pScreen; - REGION_INIT(pScreen, &rgn, NullBox, 1); - res = miCheckSubSaveUnder (pWin->parent, - pWin->saveUnder ? first : pWin->nextSib, - &rgn); - REGION_UNINIT(pScreen, &rgn); - return res; -} - -/*- - *----------------------------------------------------------------------- - * miPostChangeSaveUnder -- - * Actually turn backing-store off for those windows that no longer - * need to have it on. - * - * Results: - * None. - * - * Side Effects: - * Backing-store and SAVE_UNDER_CHANGE_BIT are turned off for those - * windows affected. - * - *----------------------------------------------------------------------- - */ -void -miPostChangeSaveUnder(pWin, pFirst) - WindowPtr pWin; - WindowPtr pFirst; -{ - register WindowPtr pParent, pChild; - ChangeWindowAttributesProcPtr ChangeWindowAttributes; - - if (!(pParent = pWin->parent)) - return; - ChangeWindowAttributes = pParent->drawable.pScreen->ChangeWindowAttributes; - if (!pParent->DIXsaveUnder && - (pParent->backingStore == NotUseful) && pParent->backStorage) - (*ChangeWindowAttributes)(pParent, CWBackingStore); - if (!(pChild = pFirst)) - return; - while (1) - { - if (!pChild->DIXsaveUnder && - (pChild->backingStore == NotUseful) && pChild->backStorage) - (*ChangeWindowAttributes)(pChild, CWBackingStore); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib) - { - pChild = pChild->parent; - if (pChild == pParent) - return; - } - pChild = pChild->nextSib; - } -} - -void -miMarkWindow(pWin) - register WindowPtr pWin; -{ - register ValidatePtr val; - - if (pWin->valdata) - return; - val = (ValidatePtr)xnfalloc(sizeof(ValidateRec)); - val->before.oldAbsCorner.x = pWin->drawable.x; - val->before.oldAbsCorner.y = pWin->drawable.y; - val->before.borderVisible = NullRegion; - val->before.resized = FALSE; - pWin->valdata = val; -} - -Bool -miMarkOverlappedWindows(pWin, pFirst, ppLayerWin) - WindowPtr pWin; - WindowPtr pFirst; - WindowPtr *ppLayerWin; -{ - register BoxPtr box; - register WindowPtr pChild, pLast; - Bool anyMarked = FALSE; - MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow; - ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - - /* single layered systems are easy */ - if (ppLayerWin) *ppLayerWin = pWin; - - if (pWin == pFirst) - { - /* Blindly mark pWin and all of its inferiors. This is a slight - * overkill if there are mapped windows that outside pWin's border, - * but it's better than wasting time on RectIn checks. - */ - pChild = pWin; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - (* MarkWindow)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - anyMarked = TRUE; - pFirst = pFirst->nextSib; - } - if ( (pChild = pFirst) ) - { - box = REGION_EXTENTS(pChild->drawable.pScreen, &pWin->borderSize); - pLast = pChild->parent->lastChild; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - if (RECT_IN_REGION(pScreen, &pChild->borderSize, box)) - { - (* MarkWindow)(pChild); - anyMarked = TRUE; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - } - while (!pChild->nextSib && (pChild != pLast)) - pChild = pChild->parent; - if (pChild == pLast) - break; - pChild = pChild->nextSib; - } - } - if (anyMarked) - (* MarkWindow)(pWin->parent); - return anyMarked; -} - -/***** - * miHandleValidateExposures(pWin) - * starting at pWin, draw background in any windows that have exposure - * regions, translate the regions, restore any backing store, - * and then send any regions still exposed to the client - *****/ -void -miHandleValidateExposures(pWin) - WindowPtr pWin; -{ - register WindowPtr pChild; - register ValidatePtr val; - ScreenPtr pScreen; - WindowExposuresProcPtr WindowExposures; - - pScreen = pWin->drawable.pScreen; - - pChild = pWin; - WindowExposures = pChild->drawable.pScreen->WindowExposures; - while (1) - { - if ( (val = pChild->valdata) ) - { - if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed)) - (*pChild->drawable.pScreen->PaintWindowBorder)(pChild, - &val->after.borderExposed, - PW_BORDER); - REGION_UNINIT(pScreen, &val->after.borderExposed); - (*WindowExposures)(pChild, &val->after.exposed, NullRegion); - REGION_UNINIT(pScreen, &val->after.exposed); - xfree(val); - pChild->valdata = (ValidatePtr)NULL; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -void -miMoveWindow(pWin, x, y, pNextSib, kind) - register WindowPtr pWin; - int x,y; - WindowPtr pNextSib; - VTKind kind; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - short bw; - RegionPtr oldRegion = NULL; - DDXPointRec oldpt; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr windowToValidate; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be moved */ - if (!(pParent = pWin->parent)) - return ; - pScreen = pWin->drawable.pScreen; - bw = wBorderWidth (pWin); - - oldpt.x = pWin->drawable.x; - oldpt.y = pWin->drawable.y; - if (WasViewable) - { - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->borderClip); - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - } - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - x = pWin->drawable.x = pParent->drawable.x + x + (int)bw; - y = pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - SetWinSize (pWin); - SetBorderSize (pWin); - - (*pScreen->PositionWindow)(pWin, x, y); - - windowToValidate = MoveWindowInStack(pWin, pNextSib); - - ResizeChildrenWinSize(pWin, x - oldpt.x, y - oldpt.y, 0, 0); - - if (WasViewable) - { - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, windowToValidate, (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, pLayerWin, (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, windowToValidate); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind); - (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion); - REGION_DESTROY(pScreen, oldRegion); - /* XXX need to retile border if ParentRelative origin */ - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, windowToValidate); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - - -/* - * pValid is a region of the screen which has been - * successfully copied -- recomputed exposed regions for affected windows - */ - -static int -miRecomputeExposures ( - register WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - register ScreenPtr pScreen; - RegionPtr pValid = (RegionPtr)value; - - if (pWin->valdata) - { - pScreen = pWin->drawable.pScreen; - /* - * compute exposed regions of this window - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->clipList, pValid); - /* - * compute exposed regions of the border - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->borderClip, &pWin->winSize); - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->valdata->after.borderExposed, pValid); - return WT_WALKCHILDREN; - } - return WT_NOMATCH; -} - -void -miSlideAndSizeWindow(pWin, x, y, w, h, pSib) - register WindowPtr pWin; - int x,y; - unsigned int w, h; - WindowPtr pSib; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - unsigned short width = pWin->drawable.width, - height = pWin->drawable.height; - short oldx = pWin->drawable.x, - oldy = pWin->drawable.y; - int bw = wBorderWidth (pWin); - short dw, dh; - DDXPointRec oldpt; - RegionPtr oldRegion = NULL; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr pFirstChange; - register WindowPtr pChild; - RegionPtr gravitate[StaticGravity + 1]; - register unsigned g; - int nx, ny; /* destination x,y */ - int newx, newy; /* new inner window position */ - RegionPtr pRegion = NULL; - RegionPtr destClip; /* portions of destination already written */ - RegionPtr oldWinClip = NULL; /* old clip list for window */ - RegionPtr borderVisible = NullRegion; /* visible area of the border */ - RegionPtr bsExposed = NullRegion; /* backing store exposures */ - Bool shrunk = FALSE; /* shrunk in an inner dimension */ - Bool moved = FALSE; /* window position changed */ -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be resized */ - if (!(pParent = pWin->parent)) - return ; - - pScreen = pWin->drawable.pScreen; - newx = pParent->drawable.x + x + bw; - newy = pParent->drawable.y + y + bw; - if (WasViewable) - { - anyMarked = FALSE; - /* - * save the visible region of the window - */ - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->winSize); - - /* - * categorize child windows into regions to be moved - */ - for (g = 0; g <= StaticGravity; g++) - gravitate[g] = (RegionPtr) NULL; - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - g = pChild->winGravity; - if (g != UnmapGravity) - { - if (!gravitate[g]) - gravitate[g] = REGION_CREATE(pScreen, NullBox, 1); - REGION_UNION(pScreen, gravitate[g], - gravitate[g], &pChild->borderClip); - } - else - { - UnmapWindow(pChild, TRUE); - anyMarked = TRUE; - } - } - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - - oldWinClip = NULL; - if (pWin->bitGravity != ForgetGravity) - { - oldWinClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldWinClip, &pWin->clipList); - } - /* - * if the window is changing size, borderExposed - * can't be computed correctly without some help. - */ - if (pWin->drawable.height > h || pWin->drawable.width > w) - shrunk = TRUE; - - if (newx != oldx || newy != oldy) - moved = TRUE; - - if ((pWin->drawable.height != h || pWin->drawable.width != w) && - HasBorder (pWin)) - { - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - /* for tiled borders, we punt and draw the whole thing */ - if (pWin->borderIsPixel || !moved) - { - if (shrunk || moved) - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, - &pWin->winSize); - else - REGION_COPY(pScreen, borderVisible, - &pWin->borderClip); - } - } - } - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.height = h; - pWin->drawable.width = w; - - x = pWin->drawable.x = newx; - y = pWin->drawable.y = newy; - - SetWinSize (pWin); - SetBorderSize (pWin); - - dw = (int)w - (int)width; - dh = (int)h - (int)height; - ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh); - - /* let the hardware adjust background and border pixmaps, if any */ - (*pScreen->PositionWindow)(pWin, x, y); - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - pRegion = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->backStorage) - REGION_COPY(pScreen, pRegion, &pWin->clipList); - - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - - if (pWin->valdata) - { - pWin->valdata->before.resized = TRUE; - pWin->valdata->before.borderVisible = borderVisible; - } - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, VTOther); - /* - * the entire window is trashed unless bitGravity - * recovers portions of it - */ - REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList); - } - - GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny); - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pRegion = &pWin->clipList; /* a convenient empty region */ - if (pWin->bitGravity == ForgetGravity) - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, NullRegion, oldx, oldy); - else - { - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, nx - x, ny - y, pRegion, oldx, oldy); - } - } - - if (WasViewable) - { - /* avoid the border */ - if (HasBorder (pWin)) - { - int offx, offy, dx, dy; - - /* kruft to avoid double translates for each gravity */ - offx = 0; - offy = 0; - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - /* align winSize to gravitate[g]. - * winSize is in new coordinates, - * gravitate[g] is still in old coordinates */ - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - dx = (oldx - nx) - offx; - dy = (oldy - ny) - offy; - if (dx || dy) - { - REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy); - offx += dx; - offy += dy; - } - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], - &pWin->winSize); - } - /* get winSize back where it belongs */ - if (offx || offy) - REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy); - } - /* - * add screen bits to the appropriate bucket - */ - - if (oldWinClip) - { - /* - * clip to new clipList - */ - REGION_COPY(pScreen, pRegion, oldWinClip); - REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy); - REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList); - /* - * don't step on any gravity bits which will be copied after this - * region. Note -- this assumes that the regions will be copied - * in gravity order. - */ - for (g = pWin->bitGravity + 1; g <= StaticGravity; g++) - { - if (gravitate[g]) - REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip, - gravitate[g]); - } - REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny); - g = pWin->bitGravity; - if (!gravitate[g]) - gravitate[g] = oldWinClip; - else - { - REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip); - REGION_DESTROY(pScreen, oldWinClip); - } - } - - /* - * move the bits on the screen - */ - - destClip = NULL; - - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - oldpt.x = oldx + (x - nx); - oldpt.y = oldy + (y - ny); - - /* Note that gravitate[g] is *translated* by CopyWindow */ - - /* only copy the remaining useful bits */ - - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], oldRegion); - - /* clip to not overwrite already copied areas */ - - if (destClip) { - REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y); - REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip); - REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y); - } - - /* and move those bits */ - - if (oldpt.x != x || oldpt.y != y) - (*pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, gravitate[g]); - - /* remove any overwritten bits from the remaining useful bits */ - - REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]); - - /* - * recompute exposed regions of child windows - */ - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->winGravity != g) - continue; - REGION_INTERSECT(pScreen, pRegion, - &pChild->borderClip, gravitate[g]); - TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion); - } - - /* - * remove the successfully copied regions of the - * window from its exposed region - */ - - if (g == pWin->bitGravity) - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->valdata->after.exposed, gravitate[g]); - if (!destClip) - destClip = gravitate[g]; - else - { - REGION_UNION(pScreen, destClip, destClip, gravitate[g]); - REGION_DESTROY(pScreen, gravitate[g]); - } - } - - REGION_DESTROY(pScreen, oldRegion); - REGION_DESTROY(pScreen, pRegion); - if (destClip) - REGION_DESTROY(pScreen, destClip); - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, - VTOther); - } - else if (bsExposed) - { - (*pScreen->WindowExposures) (pWin, NullRegion, bsExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (pWin->realized) - WindowsRestructured (); -} - -WindowPtr -miGetLayerWindow(pWin) - WindowPtr pWin; -{ - return pWin->firstChild; -} - -#ifdef SHAPE -/****** - * - * miSetShape - * The border/window shape has changed. Recompute winSize/borderSize - * and send appropriate exposure events - */ - -void -miSetShape(pWin) - register WindowPtr pWin; -{ - Bool WasViewable = (Bool)(pWin->viewable); - register ScreenPtr pScreen = pWin->drawable.pScreen; - Bool anyMarked = FALSE; - RegionPtr pOldClip = NULL, bsExposed; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - if (pWin->valdata) - { - if (HasBorder (pWin)) - { - RegionPtr borderVisible; - - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - pWin->valdata->before.resized = TRUE; - } - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - if (WasViewable) - { - if (pWin->backStorage) - { - pOldClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, pOldClip, &pWin->clipList); - } - - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pOldClip = &pWin->clipList; /* a convenient empty region */ - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, pOldClip, - pWin->drawable.x, pWin->drawable.y); -#ifdef NXAGENT_SERVER - - /* - * We got a few, rare, segfaults here after having - * started using the backing store. It may be a - * different bug but miChangeSaveUnder() calls mi- - * CheckSubSaveUnder() that, in turn, can change - * the backing store attribute of the window. This - * means that we may try to destroy the region - * even if it was not created at the beginning of - * this function as, at the time, the backing store - * was off. miCheckSubSaveUnder() appear to get a - * pointer to the parent, so maybe doesn't change - * the attribute of the window itself. This is to - * be better investigated. - */ - - if (WasViewable && pOldClip) - REGION_DESTROY(pScreen, pOldClip); -#else - if (WasViewable) - REGION_DESTROY(pScreen, pOldClip); -#endif - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - } - if (WasViewable) - { - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - if (pWin->realized) - WindowsRestructured (); - CheckCursorConfinement(pWin); -} -#endif - -/* Keeps the same inside(!) origin */ - -void -miChangeBorderWidth(pWin, width) - register WindowPtr pWin; - unsigned int width; -{ - WindowPtr pParent; - int oldwidth; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - Bool WasViewable = (Bool)(pWin->viewable); - Bool HadBorder; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - oldwidth = wBorderWidth (pWin); - if (oldwidth == width) - return; - HadBorder = HasBorder(pWin); - pScreen = pWin->drawable.pScreen; - pParent = pWin->parent; - if (WasViewable && width < oldwidth) - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - - pWin->borderWidth = width; - SetBorderSize (pWin); - - if (WasViewable) - { - if (width > oldwidth) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - /* - * save the old border visible region to correctly compute - * borderExposed. - */ - if (pWin->valdata && HadBorder) - { - RegionPtr borderVisible; - borderVisible = REGION_CREATE(pScreen, NULL, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTOther); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, - VTOther); - } - if (pWin->realized) - WindowsRestructured (); -} - -void -miMarkUnrealizedWindow(pChild, pWin, fromConfigure) - WindowPtr pChild; - WindowPtr pWin; - Bool fromConfigure; -{ - if ((pChild != pWin) || fromConfigure) - { - REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList); - if (pChild->drawable.pScreen->ClipNotify) - (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0); - REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip); - } -} - -void -miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth) -{ - ScreenPtr pScreen; - WindowPtr pChild; - - pScreen = pWin->drawable.pScreen; - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->drawable.depth == depth) - REGION_UNION(pScreen, pReg, pReg, &pChild->borderClip); - - if (pChild->firstChild) - miSegregateChildren(pChild, pReg, depth); - } -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.XF86.original deleted file mode 100644 index fbced41c6..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXmiwindow.c.XF86.original +++ /dev/null @@ -1,1176 +0,0 @@ -/* $XFree86: xc/programs/Xserver/mi/miwindow.c,v 1.7 2001/12/14 20:00:28 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: miwindow.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ -#include "X.h" -#include "miscstruct.h" -#include "region.h" -#include "mi.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" - -void -miClearToBackground(pWin, x, y, w, h, generateExposures) - WindowPtr pWin; - int x,y; - int w,h; - Bool generateExposures; -{ - BoxRec box; - RegionRec reg; - RegionPtr pBSReg = NullRegion; - ScreenPtr pScreen; - BoxPtr extents; - int x1, y1, x2, y2; - - /* compute everything using ints to avoid overflow */ - - x1 = pWin->drawable.x + x; - y1 = pWin->drawable.y + y; - if (w) - x2 = x1 + (int) w; - else - x2 = x1 + (int) pWin->drawable.width - (int) x; - if (h) - y2 = y1 + h; - else - y2 = y1 + (int) pWin->drawable.height - (int) y; - - extents = &pWin->clipList.extents; - - /* clip the resulting rectangle to the window clipList extents. This - * makes sure that the result will fit in a box, given that the - * screen is < 32768 on a side. - */ - - if (x1 < extents->x1) - x1 = extents->x1; - if (x2 > extents->x2) - x2 = extents->x2; - if (y1 < extents->y1) - y1 = extents->y1; - if (y2 > extents->y2) - y2 = extents->y2; - - if (x2 <= x1 || y2 <= y1) - { - x2 = x1 = 0; - y2 = y1 = 0; - } - - box.x1 = x1; - box.x2 = x2; - box.y1 = y1; - box.y2 = y2; - - pScreen = pWin->drawable.pScreen; - REGION_INIT(pScreen, ®, &box, 1); - if (pWin->backStorage) - { - /* - * If the window has backing-store on, call through the - * ClearToBackground vector to handle the special semantics - * (i.e. things backing store is to be cleared out and - * an Expose event is to be generated for those areas in backing - * store if generateExposures is TRUE). - */ - pBSReg = (* pScreen->ClearBackingStore)(pWin, x, y, w, h, - generateExposures); - } - - REGION_INTERSECT(pScreen, ®, ®, &pWin->clipList); - if (generateExposures) - (*pScreen->WindowExposures)(pWin, ®, pBSReg); - else if (pWin->backgroundState != None) - (*pScreen->PaintWindowBackground)(pWin, ®, PW_BACKGROUND); - REGION_UNINIT(pScreen, ®); - if (pBSReg) - REGION_DESTROY(pScreen, pBSReg); -} - -/* - * For SaveUnders using backing-store. The idea is that when a window is mapped - * with saveUnder set TRUE, any windows it obscures will have its backing - * store turned on setting the DIXsaveUnder bit, - * The backing-store code must be written to allow for this - */ - -/*- - *----------------------------------------------------------------------- - * miCheckSubSaveUnder -- - * Check all the inferiors of a window for coverage by saveUnder - * windows. Called from ChangeSaveUnder and CheckSaveUnder. - * This code is very inefficient. - * - * Results: - * TRUE if any windows need to have backing-store removed. - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -static Bool -miCheckSubSaveUnder( - register WindowPtr pParent, /* Parent to check */ - WindowPtr pFirst, /* first reconfigured window */ - RegionPtr pRegion) /* Initial area obscured by saveUnder */ -{ - register WindowPtr pChild; /* Current child */ - register ScreenPtr pScreen; /* Screen to use */ - RegionRec SubRegion; /* Area of children obscured */ - Bool res = FALSE; /* result */ - Bool subInited=FALSE;/* SubRegion initialized */ - - pScreen = pParent->drawable.pScreen; - if ( (pChild = pParent->firstChild) ) - { - /* - * build region above first changed window - */ - - for (; pChild != pFirst; pChild = pChild->nextSib) - if (pChild->viewable && pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - - /* - * check region below and including first changed window - */ - - for (; pChild; pChild = pChild->nextSib) - { - if (pChild->viewable) - { - /* - * don't save under nephew/niece windows; - * use a separate region - */ - - if (pChild->firstChild) - { - if (!subInited) - { - REGION_INIT(pScreen, &SubRegion, NullBox, 0); - subInited = TRUE; - } - REGION_COPY(pScreen, &SubRegion, pRegion); - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - &SubRegion); - } - else - { - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - pRegion); - } - - if (pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - } - } - - if (subInited) - REGION_UNINIT(pScreen, &SubRegion); - } - - /* - * Check the state of this window. DIX save unders are - * enabled for viewable windows with some client expressing - * exposure interest and which intersect the save under region - */ - - if (pParent->viewable && - ((pParent->eventMask | wOtherEventMasks(pParent)) & ExposureMask) && - REGION_NOTEMPTY(pScreen, &pParent->borderSize) && - RECT_IN_REGION(pScreen, pRegion, REGION_EXTENTS(pScreen, - &pParent->borderSize)) != rgnOUT) - { - if (!pParent->DIXsaveUnder) - { - pParent->DIXsaveUnder = TRUE; - (*pScreen->ChangeWindowAttributes) (pParent, CWBackingStore); - } - } - else - { - if (pParent->DIXsaveUnder) - { - res = TRUE; - pParent->DIXsaveUnder = FALSE; - } - } - return res; -} - - -/*- - *----------------------------------------------------------------------- - * miChangeSaveUnder -- - * Change the save-under state of a tree of windows. Called when - * a window with saveUnder TRUE is mapped/unmapped/reconfigured. - * - * Results: - * TRUE if any windows need to have backing-store removed (which - * means that PostChangeSaveUnder needs to be called later to - * finish the job). - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -Bool -miChangeSaveUnder(pWin, first) - register WindowPtr pWin; - WindowPtr first; /* First window to check. - * Used when pWin was restacked */ -{ - RegionRec rgn; /* Area obscured by saveUnder windows */ - register ScreenPtr pScreen; - Bool res; - - if (!deltaSaveUndersViewable && !numSaveUndersViewable) - return FALSE; - numSaveUndersViewable += deltaSaveUndersViewable; - deltaSaveUndersViewable = 0; - pScreen = pWin->drawable.pScreen; - REGION_INIT(pScreen, &rgn, NullBox, 1); - res = miCheckSubSaveUnder (pWin->parent, - pWin->saveUnder ? first : pWin->nextSib, - &rgn); - REGION_UNINIT(pScreen, &rgn); - return res; -} - -/*- - *----------------------------------------------------------------------- - * miPostChangeSaveUnder -- - * Actually turn backing-store off for those windows that no longer - * need to have it on. - * - * Results: - * None. - * - * Side Effects: - * Backing-store and SAVE_UNDER_CHANGE_BIT are turned off for those - * windows affected. - * - *----------------------------------------------------------------------- - */ -void -miPostChangeSaveUnder(pWin, pFirst) - WindowPtr pWin; - WindowPtr pFirst; -{ - register WindowPtr pParent, pChild; - ChangeWindowAttributesProcPtr ChangeWindowAttributes; - - if (!(pParent = pWin->parent)) - return; - ChangeWindowAttributes = pParent->drawable.pScreen->ChangeWindowAttributes; - if (!pParent->DIXsaveUnder && - (pParent->backingStore == NotUseful) && pParent->backStorage) - (*ChangeWindowAttributes)(pParent, CWBackingStore); - if (!(pChild = pFirst)) - return; - while (1) - { - if (!pChild->DIXsaveUnder && - (pChild->backingStore == NotUseful) && pChild->backStorage) - (*ChangeWindowAttributes)(pChild, CWBackingStore); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib) - { - pChild = pChild->parent; - if (pChild == pParent) - return; - } - pChild = pChild->nextSib; - } -} - -void -miMarkWindow(pWin) - register WindowPtr pWin; -{ - register ValidatePtr val; - - if (pWin->valdata) - return; - val = (ValidatePtr)xnfalloc(sizeof(ValidateRec)); - val->before.oldAbsCorner.x = pWin->drawable.x; - val->before.oldAbsCorner.y = pWin->drawable.y; - val->before.borderVisible = NullRegion; - val->before.resized = FALSE; - pWin->valdata = val; -} - -Bool -miMarkOverlappedWindows(pWin, pFirst, ppLayerWin) - WindowPtr pWin; - WindowPtr pFirst; - WindowPtr *ppLayerWin; -{ - register BoxPtr box; - register WindowPtr pChild, pLast; - Bool anyMarked = FALSE; - MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow; - ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - - /* single layered systems are easy */ - if (ppLayerWin) *ppLayerWin = pWin; - - if (pWin == pFirst) - { - /* Blindly mark pWin and all of its inferiors. This is a slight - * overkill if there are mapped windows that outside pWin's border, - * but it's better than wasting time on RectIn checks. - */ - pChild = pWin; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - (* MarkWindow)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - anyMarked = TRUE; - pFirst = pFirst->nextSib; - } - if ( (pChild = pFirst) ) - { - box = REGION_EXTENTS(pChild->drawable.pScreen, &pWin->borderSize); - pLast = pChild->parent->lastChild; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - if (RECT_IN_REGION(pScreen, &pChild->borderSize, box)) - { - (* MarkWindow)(pChild); - anyMarked = TRUE; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - } - while (!pChild->nextSib && (pChild != pLast)) - pChild = pChild->parent; - if (pChild == pLast) - break; - pChild = pChild->nextSib; - } - } - if (anyMarked) - (* MarkWindow)(pWin->parent); - return anyMarked; -} - -/***** - * miHandleValidateExposures(pWin) - * starting at pWin, draw background in any windows that have exposure - * regions, translate the regions, restore any backing store, - * and then send any regions still exposed to the client - *****/ -void -miHandleValidateExposures(pWin) - WindowPtr pWin; -{ - register WindowPtr pChild; - register ValidatePtr val; - ScreenPtr pScreen; - WindowExposuresProcPtr WindowExposures; - - pScreen = pWin->drawable.pScreen; - - pChild = pWin; - WindowExposures = pChild->drawable.pScreen->WindowExposures; - while (1) - { - if ( (val = pChild->valdata) ) - { - if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed)) - (*pChild->drawable.pScreen->PaintWindowBorder)(pChild, - &val->after.borderExposed, - PW_BORDER); - REGION_UNINIT(pScreen, &val->after.borderExposed); - (*WindowExposures)(pChild, &val->after.exposed, NullRegion); - REGION_UNINIT(pScreen, &val->after.exposed); - xfree(val); - pChild->valdata = (ValidatePtr)NULL; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -void -miMoveWindow(pWin, x, y, pNextSib, kind) - register WindowPtr pWin; - int x,y; - WindowPtr pNextSib; - VTKind kind; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - short bw; - RegionPtr oldRegion = NULL; - DDXPointRec oldpt; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr windowToValidate; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be moved */ - if (!(pParent = pWin->parent)) - return ; - pScreen = pWin->drawable.pScreen; - bw = wBorderWidth (pWin); - - oldpt.x = pWin->drawable.x; - oldpt.y = pWin->drawable.y; - if (WasViewable) - { - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->borderClip); - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - } - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - x = pWin->drawable.x = pParent->drawable.x + x + (int)bw; - y = pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - SetWinSize (pWin); - SetBorderSize (pWin); - - (*pScreen->PositionWindow)(pWin, x, y); - - windowToValidate = MoveWindowInStack(pWin, pNextSib); - - ResizeChildrenWinSize(pWin, x - oldpt.x, y - oldpt.y, 0, 0); - - if (WasViewable) - { - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, windowToValidate, (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, pLayerWin, (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, windowToValidate); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind); - (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion); - REGION_DESTROY(pScreen, oldRegion); - /* XXX need to retile border if ParentRelative origin */ - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, windowToValidate); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - - -/* - * pValid is a region of the screen which has been - * successfully copied -- recomputed exposed regions for affected windows - */ - -static int -miRecomputeExposures ( - register WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - register ScreenPtr pScreen; - RegionPtr pValid = (RegionPtr)value; - - if (pWin->valdata) - { - pScreen = pWin->drawable.pScreen; - /* - * compute exposed regions of this window - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->clipList, pValid); - /* - * compute exposed regions of the border - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->borderClip, &pWin->winSize); - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->valdata->after.borderExposed, pValid); - return WT_WALKCHILDREN; - } - return WT_NOMATCH; -} - -void -miSlideAndSizeWindow(pWin, x, y, w, h, pSib) - register WindowPtr pWin; - int x,y; - unsigned int w, h; - WindowPtr pSib; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - unsigned short width = pWin->drawable.width, - height = pWin->drawable.height; - short oldx = pWin->drawable.x, - oldy = pWin->drawable.y; - int bw = wBorderWidth (pWin); - short dw, dh; - DDXPointRec oldpt; - RegionPtr oldRegion = NULL; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr pFirstChange; - register WindowPtr pChild; - RegionPtr gravitate[StaticGravity + 1]; - register unsigned g; - int nx, ny; /* destination x,y */ - int newx, newy; /* new inner window position */ - RegionPtr pRegion = NULL; - RegionPtr destClip; /* portions of destination already written */ - RegionPtr oldWinClip = NULL; /* old clip list for window */ - RegionPtr borderVisible = NullRegion; /* visible area of the border */ - RegionPtr bsExposed = NullRegion; /* backing store exposures */ - Bool shrunk = FALSE; /* shrunk in an inner dimension */ - Bool moved = FALSE; /* window position changed */ -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be resized */ - if (!(pParent = pWin->parent)) - return ; - - pScreen = pWin->drawable.pScreen; - newx = pParent->drawable.x + x + bw; - newy = pParent->drawable.y + y + bw; - if (WasViewable) - { - anyMarked = FALSE; - /* - * save the visible region of the window - */ - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->winSize); - - /* - * categorize child windows into regions to be moved - */ - for (g = 0; g <= StaticGravity; g++) - gravitate[g] = (RegionPtr) NULL; - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - g = pChild->winGravity; - if (g != UnmapGravity) - { - if (!gravitate[g]) - gravitate[g] = REGION_CREATE(pScreen, NullBox, 1); - REGION_UNION(pScreen, gravitate[g], - gravitate[g], &pChild->borderClip); - } - else - { - UnmapWindow(pChild, TRUE); - anyMarked = TRUE; - } - } - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - - oldWinClip = NULL; - if (pWin->bitGravity != ForgetGravity) - { - oldWinClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldWinClip, &pWin->clipList); - } - /* - * if the window is changing size, borderExposed - * can't be computed correctly without some help. - */ - if (pWin->drawable.height > h || pWin->drawable.width > w) - shrunk = TRUE; - - if (newx != oldx || newy != oldy) - moved = TRUE; - - if ((pWin->drawable.height != h || pWin->drawable.width != w) && - HasBorder (pWin)) - { - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - /* for tiled borders, we punt and draw the whole thing */ - if (pWin->borderIsPixel || !moved) - { - if (shrunk || moved) - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, - &pWin->winSize); - else - REGION_COPY(pScreen, borderVisible, - &pWin->borderClip); - } - } - } - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.height = h; - pWin->drawable.width = w; - - x = pWin->drawable.x = newx; - y = pWin->drawable.y = newy; - - SetWinSize (pWin); - SetBorderSize (pWin); - - dw = (int)w - (int)width; - dh = (int)h - (int)height; - ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh); - - /* let the hardware adjust background and border pixmaps, if any */ - (*pScreen->PositionWindow)(pWin, x, y); - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - pRegion = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->backStorage) - REGION_COPY(pScreen, pRegion, &pWin->clipList); - - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - - if (pWin->valdata) - { - pWin->valdata->before.resized = TRUE; - pWin->valdata->before.borderVisible = borderVisible; - } - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, VTOther); - /* - * the entire window is trashed unless bitGravity - * recovers portions of it - */ - REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList); - } - - GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny); - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pRegion = &pWin->clipList; /* a convenient empty region */ - if (pWin->bitGravity == ForgetGravity) - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, NullRegion, oldx, oldy); - else - { - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, nx - x, ny - y, pRegion, oldx, oldy); - } - } - - if (WasViewable) - { - /* avoid the border */ - if (HasBorder (pWin)) - { - int offx, offy, dx, dy; - - /* kruft to avoid double translates for each gravity */ - offx = 0; - offy = 0; - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - /* align winSize to gravitate[g]. - * winSize is in new coordinates, - * gravitate[g] is still in old coordinates */ - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - dx = (oldx - nx) - offx; - dy = (oldy - ny) - offy; - if (dx || dy) - { - REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy); - offx += dx; - offy += dy; - } - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], - &pWin->winSize); - } - /* get winSize back where it belongs */ - if (offx || offy) - REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy); - } - /* - * add screen bits to the appropriate bucket - */ - - if (oldWinClip) - { - /* - * clip to new clipList - */ - REGION_COPY(pScreen, pRegion, oldWinClip); - REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy); - REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList); - /* - * don't step on any gravity bits which will be copied after this - * region. Note -- this assumes that the regions will be copied - * in gravity order. - */ - for (g = pWin->bitGravity + 1; g <= StaticGravity; g++) - { - if (gravitate[g]) - REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip, - gravitate[g]); - } - REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny); - g = pWin->bitGravity; - if (!gravitate[g]) - gravitate[g] = oldWinClip; - else - { - REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip); - REGION_DESTROY(pScreen, oldWinClip); - } - } - - /* - * move the bits on the screen - */ - - destClip = NULL; - - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - oldpt.x = oldx + (x - nx); - oldpt.y = oldy + (y - ny); - - /* Note that gravitate[g] is *translated* by CopyWindow */ - - /* only copy the remaining useful bits */ - - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], oldRegion); - - /* clip to not overwrite already copied areas */ - - if (destClip) { - REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y); - REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip); - REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y); - } - - /* and move those bits */ - - if (oldpt.x != x || oldpt.y != y) - (*pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, gravitate[g]); - - /* remove any overwritten bits from the remaining useful bits */ - - REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]); - - /* - * recompute exposed regions of child windows - */ - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->winGravity != g) - continue; - REGION_INTERSECT(pScreen, pRegion, - &pChild->borderClip, gravitate[g]); - TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion); - } - - /* - * remove the successfully copied regions of the - * window from its exposed region - */ - - if (g == pWin->bitGravity) - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->valdata->after.exposed, gravitate[g]); - if (!destClip) - destClip = gravitate[g]; - else - { - REGION_UNION(pScreen, destClip, destClip, gravitate[g]); - REGION_DESTROY(pScreen, gravitate[g]); - } - } - - REGION_DESTROY(pScreen, oldRegion); - REGION_DESTROY(pScreen, pRegion); - if (destClip) - REGION_DESTROY(pScreen, destClip); - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, - VTOther); - } - else if (bsExposed) - { - (*pScreen->WindowExposures) (pWin, NullRegion, bsExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (pWin->realized) - WindowsRestructured (); -} - -WindowPtr -miGetLayerWindow(pWin) - WindowPtr pWin; -{ - return pWin->firstChild; -} - -#ifdef SHAPE -/****** - * - * miSetShape - * The border/window shape has changed. Recompute winSize/borderSize - * and send appropriate exposure events - */ - -void -miSetShape(pWin) - register WindowPtr pWin; -{ - Bool WasViewable = (Bool)(pWin->viewable); - register ScreenPtr pScreen = pWin->drawable.pScreen; - Bool anyMarked = FALSE; - RegionPtr pOldClip = NULL, bsExposed; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - if (pWin->valdata) - { - if (HasBorder (pWin)) - { - RegionPtr borderVisible; - - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - pWin->valdata->before.resized = TRUE; - } - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - if (WasViewable) - { - if (pWin->backStorage) - { - pOldClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, pOldClip, &pWin->clipList); - } - - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pOldClip = &pWin->clipList; /* a convenient empty region */ - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, pOldClip, - pWin->drawable.x, pWin->drawable.y); - if (WasViewable) - REGION_DESTROY(pScreen, pOldClip); - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - } - if (WasViewable) - { - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - if (pWin->realized) - WindowsRestructured (); - CheckCursorConfinement(pWin); -} -#endif - -/* Keeps the same inside(!) origin */ - -void -miChangeBorderWidth(pWin, width) - register WindowPtr pWin; - unsigned int width; -{ - WindowPtr pParent; - int oldwidth; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - Bool WasViewable = (Bool)(pWin->viewable); - Bool HadBorder; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - oldwidth = wBorderWidth (pWin); - if (oldwidth == width) - return; - HadBorder = HasBorder(pWin); - pScreen = pWin->drawable.pScreen; - pParent = pWin->parent; - if (WasViewable && width < oldwidth) - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - - pWin->borderWidth = width; - SetBorderSize (pWin); - - if (WasViewable) - { - if (width > oldwidth) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - /* - * save the old border visible region to correctly compute - * borderExposed. - */ - if (pWin->valdata && HadBorder) - { - RegionPtr borderVisible; - borderVisible = REGION_CREATE(pScreen, NULL, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTOther); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, - VTOther); - } - if (pWin->realized) - WindowsRestructured (); -} - -void -miMarkUnrealizedWindow(pChild, pWin, fromConfigure) - WindowPtr pChild; - WindowPtr pWin; - Bool fromConfigure; -{ - if ((pChild != pWin) || fromConfigure) - { - REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList); - if (pChild->drawable.pScreen->ClipNotify) - (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0); - REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip); - } -} - -void -miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth) -{ - ScreenPtr pScreen; - WindowPtr pChild; - - pScreen = pWin->drawable.pScreen; - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->drawable.depth == depth) - REGION_UNION(pScreen, pReg, pReg, &pChild->borderClip); - - if (pChild->firstChild) - miSegregateChildren(pChild, pReg, depth); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.NX.original deleted file mode 100644 index d32cdb6c4..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.NX.original +++ /dev/null @@ -1,1512 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXpicture.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/picture.c,v 1.30 2003/01/26 16:40:43 eich Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "NXpicturestr.h" - -#include "Screen.h" -#include "Pixmaps.h" -#include "Drawable.h" - -void *nxagentMatchingFormats(PictFormatPtr pForm); - -int PictureScreenPrivateIndex = -1; -int PictureWindowPrivateIndex; -int PictureGeneration; -RESTYPE PictureType; -RESTYPE PictFormatType; -RESTYPE GlyphSetType; -int PictureCmapPolicy = PictureCmapPolicyDefault; - -Bool -PictureDestroyWindow (WindowPtr pWindow) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - - while ((pPicture = GetPictureWindow(pWindow))) - { - SetPictureWindow(pWindow, pPicture->pNext); - if (pPicture->id) - FreeResource (pPicture->id, PictureType); - FreePicture ((pointer) pPicture, pPicture->id); - } - pScreen->DestroyWindow = ps->DestroyWindow; - ret = (*pScreen->DestroyWindow) (pWindow); - ps->DestroyWindow = pScreen->DestroyWindow; - pScreen->DestroyWindow = PictureDestroyWindow; - return ret; -} - -Bool -PictureCloseScreen (int index, ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - int n; - - pScreen->CloseScreen = ps->CloseScreen; - ret = (*pScreen->CloseScreen) (index, pScreen); - PictureResetFilters (pScreen); - for (n = 0; n < ps->nformats; n++) - if (ps->formats[n].type == PictTypeIndexed) - (*ps->CloseIndexed) (pScreen, &ps->formats[n]); - SetPictureScreen(pScreen, 0); - xfree (ps->formats); - xfree (ps); - return ret; -} - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef) -{ - ScreenPtr pScreen = pColormap->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - pScreen->StoreColors = ps->StoreColors; - (*pScreen->StoreColors) (pColormap, ndef, pdef); - ps->StoreColors = pScreen->StoreColors; - pScreen->StoreColors = PictureStoreColors; - - if (pColormap->class == PseudoColor || pColormap->class == GrayScale) - { - PictFormatPtr format = ps->formats; - int nformats = ps->nformats; - - while (nformats--) - { - if (format->type == PictTypeIndexed && - format->index.pColormap == pColormap) - { - (*ps->UpdateIndexed) (pScreen, format, ndef, pdef); - break; - } - format++; - } - } -} - -static int -visualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - int d, v; - DepthPtr pDepth; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - for (v = 0; v < pDepth->numVids; v++) - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - return 0; -} - -typedef struct _formatInit { - CARD32 format; - CARD8 depth; -} FormatInitRec, *FormatInitPtr; - -static int -addFormat (FormatInitRec formats[256], - int nformat, - CARD32 format, - CARD8 depth) -{ - int n; - - for (n = 0; n < nformat; n++) - if (formats[n].format == format && formats[n].depth == depth) - return nformat; - formats[nformat].format = format; - formats[nformat].depth = depth; - return ++nformat; -} - -#define Mask(n) ((n) == 32 ? 0xffffffff : ((1 << (n))-1)) - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp) -{ -#ifdef NXAGENT_SERVER - int nformats, f, n; -#else - int nformats, f; -#endif - PictFormatPtr pFormats; - FormatInitRec formats[1024]; - CARD32 format; - CARD8 depth; - VisualPtr pVisual; - int v; - int bpp; - int type; - int r, g, b; - int d; - DepthPtr pDepth; - - nformats = 0; - /* formats required by protocol */ - formats[nformats].format = PICT_a1; - formats[nformats].depth = 1; - nformats++; - formats[nformats].format = PICT_a8; - formats[nformats].depth = 8; - nformats++; - formats[nformats].format = PICT_a4; - formats[nformats].depth = 4; - nformats++; - formats[nformats].format = PICT_a8r8g8b8; - formats[nformats].depth = 32; - nformats++; - formats[nformats].format = PICT_x8r8g8b8; - formats[nformats].depth = 32; - nformats++; - - /* now look through the depths and visuals adding other formats */ - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = &pScreen->visuals[v]; - depth = visualDepth (pScreen, pVisual); - if (!depth) - continue; - bpp = BitsPerPixel (depth); - switch (pVisual->class) { - case DirectColor: - case TrueColor: - r = Ones (pVisual->redMask); - g = Ones (pVisual->greenMask); - b = Ones (pVisual->blueMask); - type = PICT_TYPE_OTHER; - /* - * Current rendering code supports only two direct formats, - * fields must be packed together at the bottom of the pixel - * and must be either RGB or BGR - */ - if (pVisual->offsetBlue == 0 && - pVisual->offsetGreen == b && - pVisual->offsetRed == b + g) - { - type = PICT_TYPE_ARGB; - } - else if (pVisual->offsetRed == 0 && - pVisual->offsetGreen == r && - pVisual->offsetBlue == r + g) - { - type = PICT_TYPE_ABGR; - } - if (type != PICT_TYPE_OTHER) - { - format = PICT_FORMAT(bpp, type, 0, r, g, b); - nformats = addFormat (formats, nformats, format, depth); - } - break; - case StaticColor: - case PseudoColor: - format = PICT_VISFORMAT (bpp, PICT_TYPE_COLOR, v); - nformats = addFormat (formats, nformats, format, depth); - break; - case StaticGray: - case GrayScale: - format = PICT_VISFORMAT (bpp, PICT_TYPE_GRAY, v); - nformats = addFormat (formats, nformats, format, depth); - break; - } - } - /* - * Walk supported depths and add useful Direct formats - */ - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - bpp = BitsPerPixel (pDepth->depth); - format = 0; - switch (bpp) { - case 16: - /* depth 12 formats */ - if (pDepth->depth >= 12) - { - nformats = addFormat (formats, nformats, - PICT_x4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x4b4g4r4, pDepth->depth); - } - /* depth 15 formats */ - if (pDepth->depth >= 15) - { - nformats = addFormat (formats, nformats, - PICT_x1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x1b5g5r5, pDepth->depth); - } - /* depth 16 formats */ - if (pDepth->depth >= 16) - { - nformats = addFormat (formats, nformats, - PICT_a1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a1b5g5r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_r5g6b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b5g6r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4b4g4r4, pDepth->depth); - } - break; - case 24: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b8g8r8, pDepth->depth); - } - break; - case 32: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_x8r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x8b8g8r8, pDepth->depth); - } - break; - } - } - - - pFormats = (PictFormatPtr) xalloc (nformats * sizeof (PictFormatRec)); - if (!pFormats) - return 0; - memset (pFormats, '\0', nformats * sizeof (PictFormatRec)); -#ifdef NXAGENT_SERVER - for (f = 0, n = 0; n < nformats; n++) - { - pFormats[f].id = FakeClientID (0); - pFormats[f].depth = formats[n].depth; - format = formats[n].format; - pFormats[f].format = format; -#else - for (f = 0; f < nformats; f++) - { - pFormats[f].id = FakeClientID (0); - pFormats[f].depth = formats[f].depth; - format = formats[f].format; - pFormats[f].format = format; -#endif - switch (PICT_FORMAT_TYPE(format)) { - case PICT_TYPE_ARGB: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_R(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = (PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_B(format); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = 0; - break; - - case PICT_TYPE_ABGR: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_B(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = (PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_R(format); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = 0; - break; - - case PICT_TYPE_A: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alpha = 0; - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - - /* remaining fields already set to zero */ - break; - - case PICT_TYPE_COLOR: - case PICT_TYPE_GRAY: - pFormats[f].type = PictTypeIndexed; - pFormats[f].index.pVisual = &pScreen->visuals[PICT_FORMAT_VIS(format)]; - break; - } - -#ifdef NXAGENT_SERVER - if (nxagentMatchingFormats(&pFormats[f]) != NULL) - { - f++; - } - else - { - memset(&pFormats[f], '\0', sizeof(PictFormatRec)); - } - } - *nformatp = f; -#else - } - *nformatp = nformats; -#endif - return pFormats; -} - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return FALSE; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->type == PictTypeIndexed && !format->index.pColormap) - { - if (format->index.pVisual->vid == pScreen->rootVisual) - format->index.pColormap = (ColormapPtr) LookupIDByType(pScreen->defColormap, - RT_COLORMAP); - else - { - if (CreateColormap (FakeClientID (0), pScreen, - format->index.pVisual, - &format->index.pColormap, AllocNone, - 0) != Success) - { - return FALSE; - } - } - if (!(*ps->InitIndexed) (pScreen, format)) - return FALSE; - } - format++; - } - return TRUE; -} - -Bool -PictureFinishInit (void) -{ - int s; - - for (s = 0; s < screenInfo.numScreens; s++) - { - if (!PictureInitIndexedFormats (screenInfo.screens[s])) - return FALSE; - (void) AnimCurInit (screenInfo.screens[s]); - } - - return TRUE; -} - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return FALSE; - ps->subpixel = subpixel; - return TRUE; - -} - -int -PictureGetSubpixelOrder (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return SubPixelUnknown; - return ps->subpixel; -} - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - int type; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - switch (pVisual->class) { - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - type = PictTypeIndexed; - break; - case TrueColor: - type = PictTypeDirect; - break; - case DirectColor: - default: - return 0; - } - while (nformat--) - { - if (format->depth == depth && format->type == type) - { - if (type == PictTypeIndexed) - { - if (format->index.pVisual == pVisual) - return format; - } - else - { - if (format->direct.redMask << format->direct.red == - pVisual->redMask && - format->direct.greenMask << format->direct.green == - pVisual->greenMask && - format->direct.blueMask << format->direct.blue == - pVisual->blueMask) - { - return format; - } - } - } - format++; - } - return 0; -} - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 f) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->depth == depth && format->format == (f & 0xffffff)) - return format; - format++; - } - return 0; -} - -int -PictureParseCmapPolicy (const char *name) -{ - if ( strcmp (name, "default" ) == 0) - return PictureCmapPolicyDefault; - else if ( strcmp (name, "mono" ) == 0) - return PictureCmapPolicyMono; - else if ( strcmp (name, "gray" ) == 0) - return PictureCmapPolicyGray; - else if ( strcmp (name, "color" ) == 0) - return PictureCmapPolicyColor; - else if ( strcmp (name, "all" ) == 0) - return PictureCmapPolicyAll; - else - return PictureCmapPolicyInvalid; -} - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats) -{ - PictureScreenPtr ps; - int n; - CARD32 type, a, r, g, b; - - if (PictureGeneration != serverGeneration) - { - PictureType = CreateNewResourceType (FreePicture); - if (!PictureType) - return FALSE; - PictFormatType = CreateNewResourceType (FreePictFormat); - if (!PictFormatType) - return FALSE; - GlyphSetType = CreateNewResourceType (FreeGlyphSet); - if (!GlyphSetType) - return FALSE; - PictureScreenPrivateIndex = AllocateScreenPrivateIndex(); - if (PictureScreenPrivateIndex < 0) - return FALSE; - PictureWindowPrivateIndex = AllocateWindowPrivateIndex(); - PictureGeneration = serverGeneration; -#ifdef XResExtension - RegisterResourceName (PictureType, "PICTURE"); - RegisterResourceName (PictFormatType, "PICTFORMAT"); - RegisterResourceName (GlyphSetType, "GLYPHSET"); -#endif - } - if (!AllocateWindowPrivate (pScreen, PictureWindowPrivateIndex, 0)) - return FALSE; - - if (!formats) - { - formats = PictureCreateDefaultFormats (pScreen, &nformats); - if (!formats) - return FALSE; - } - for (n = 0; n < nformats; n++) - { - if (!AddResource (formats[n].id, PictFormatType, (pointer) (formats+n))) - { - xfree (formats); - return FALSE; - } - if (formats[n].type == PictTypeIndexed) - { - if ((formats[n].index.pVisual->class | DynamicClass) == PseudoColor) - type = PICT_TYPE_COLOR; - else - type = PICT_TYPE_GRAY; - a = r = g = b = 0; - } - else - { - if ((formats[n].direct.redMask| - formats[n].direct.blueMask| - formats[n].direct.greenMask) == 0) - type = PICT_TYPE_A; - else if (formats[n].direct.red > formats[n].direct.blue) - type = PICT_TYPE_ARGB; - else - type = PICT_TYPE_ABGR; - a = Ones (formats[n].direct.alphaMask); - r = Ones (formats[n].direct.redMask); - g = Ones (formats[n].direct.greenMask); - b = Ones (formats[n].direct.blueMask); - } - formats[n].format = PICT_FORMAT(0,type,a,r,g,b); - } - ps = (PictureScreenPtr) xalloc (sizeof (PictureScreenRec)); - if (!ps) - { - xfree (formats); - return FALSE; - } - SetPictureScreen(pScreen, ps); - if (!GlyphInit (pScreen)) - { - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - ps->totalPictureSize = sizeof (PictureRec); - ps->PicturePrivateSizes = 0; - ps->PicturePrivateLen = 0; - - ps->formats = formats; - ps->fallback = formats; - ps->nformats = nformats; - - ps->filters = 0; - ps->nfilters = 0; - ps->filterAliases = 0; - ps->nfilterAliases = 0; - - ps->subpixel = SubPixelUnknown; - - ps->CloseScreen = pScreen->CloseScreen; - ps->DestroyWindow = pScreen->DestroyWindow; - ps->StoreColors = pScreen->StoreColors; - pScreen->DestroyWindow = PictureDestroyWindow; - pScreen->CloseScreen = PictureCloseScreen; - pScreen->StoreColors = PictureStoreColors; - - if (!PictureSetDefaultFilters (pScreen)) - { - PictureResetFilters (pScreen); - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - return TRUE; -} - -void -SetPictureToDefaults (PicturePtr pPicture) -{ - pPicture->refcnt = 1; - pPicture->repeat = 0; - pPicture->graphicsExposures = FALSE; - pPicture->subWindowMode = ClipByChildren; - pPicture->polyEdge = PolyEdgeSharp; - pPicture->polyMode = PolyModePrecise; - pPicture->freeCompClip = FALSE; - pPicture->clientClipType = CT_NONE; - pPicture->componentAlpha = FALSE; - - pPicture->alphaMap = 0; - pPicture->alphaOrigin.x = 0; - pPicture->alphaOrigin.y = 0; - - pPicture->clipOrigin.x = 0; - pPicture->clipOrigin.y = 0; - pPicture->clientClip = 0; - - pPicture->transform = 0; - - pPicture->dither = None; - pPicture->filter = PictureGetFilterId (FilterNearest, -1, TRUE); - pPicture->filter_params = 0; - pPicture->filter_nparams = 0; - - pPicture->serialNumber = GC_CHANGE_SERIAL_BIT; - pPicture->stateChanges = (1 << (CPLastBit+1)) - 1; -} - -PicturePtr -AllocatePicture (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture; - char *ptr; - DevUnion *ppriv; - unsigned int *sizes; - unsigned int size; - int i; - - pPicture = (PicturePtr) xalloc (ps->totalPictureSize); - if (!pPicture) - return 0; - ppriv = (DevUnion *)(pPicture + 1); - pPicture->devPrivates = ppriv; - sizes = ps->PicturePrivateSizes; - ptr = (char *)(ppriv + ps->PicturePrivateLen); - for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - return pPicture; -} - -/* - * Let picture always point to the virtual pixmap. - * For sure this is not the best way to deal with - * the virtual frame-buffer. - */ - -#define NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask vmask, - XID *vlist, - ClientPtr client, - int *error) -{ - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen); - - pPicture = AllocatePicture (pDrawable->pScreen); - if (!pPicture) - { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pDrawable = pDrawable; - pPicture->pFormat = pFormat; - pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24); - if (pDrawable->type == DRAWABLE_PIXMAP) - { - #ifdef NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - - pPicture->pDrawable = nxagentVirtualDrawable(pDrawable); - - #endif - - ++((PixmapPtr)pDrawable)->refcnt; - pPicture->pNext = 0; - } - else - { - pPicture->pNext = GetPictureWindow(((WindowPtr) pDrawable)); - SetPictureWindow(((WindowPtr) pDrawable), pPicture); - } - - SetPictureToDefaults (pPicture); - - if (vmask) - *error = ChangePicture (pPicture, vmask, vlist, 0, client); - else - *error = Success; - if (*error == Success) - *error = (*ps->CreatePicture) (pPicture); - if (*error != Success) - { - FreePicture (pPicture, (XID) 0); - pPicture = 0; - } - return pPicture; -} - -#define NEXT_VAL(_type) (vlist ? (_type) *vlist++ : (_type) ulist++->val) - -#define NEXT_PTR(_type) ((_type) ulist++->ptr) - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - BITS32 index2; - int error = 0; - BITS32 maskQ; - - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - maskQ = vmask; - while (vmask && !error) - { - index2 = (BITS32) lowbit (vmask); - vmask &= ~index2; - pPicture->stateChanges |= index2; - switch (index2) - { - case CPRepeat: - { - unsigned int newr; - newr = NEXT_VAL(unsigned int); - if (newr <= xTrue) - pPicture->repeat = newr; - else - { - client->errorValue = newr; - error = BadValue; - } - } - break; - case CPAlphaMap: - { - PicturePtr pAlpha; - - if (vlist) - { - Picture pid = NEXT_VAL(Picture); - - if (pid == None) - pAlpha = 0; - else - { - pAlpha = (PicturePtr) SecurityLookupIDByType(client, - pid, - PictureType, - SecurityWriteAccess|SecurityReadAccess); - if (!pAlpha) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - if (pAlpha->pDrawable->type != DRAWABLE_PIXMAP) - { - client->errorValue = pid; - error = BadMatch; - break; - } - } - } - else - pAlpha = NEXT_PTR(PicturePtr); - if (!error) - { - if (pAlpha && pAlpha->pDrawable->type == DRAWABLE_PIXMAP) - pAlpha->refcnt++; - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - pPicture->alphaMap = pAlpha; - } - } - break; - case CPAlphaXOrigin: - pPicture->alphaOrigin.x = NEXT_VAL(INT16); - break; - case CPAlphaYOrigin: - pPicture->alphaOrigin.y = NEXT_VAL(INT16); - break; - case CPClipXOrigin: - pPicture->clipOrigin.x = NEXT_VAL(INT16); - break; - case CPClipYOrigin: - pPicture->clipOrigin.y = NEXT_VAL(INT16); - break; - case CPClipMask: - { - Pixmap pid; - PixmapPtr pPixmap; - int clipType; - - if (vlist) - { - pid = NEXT_VAL(Pixmap); - if (pid == None) - { - clipType = CT_NONE; - pPixmap = NullPixmap; - } - else - { - clipType = CT_PIXMAP; - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, - pid, - RT_PIXMAP, - SecurityReadAccess); - if (!pPixmap) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - } - } - else - { - pPixmap = NEXT_PTR(PixmapPtr); - if (pPixmap) - clipType = CT_PIXMAP; - else - clipType = CT_NONE; - } - - if (pPixmap) - { - if ((pPixmap->drawable.depth != 1) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - break; - } - else - { - clipType = CT_PIXMAP; - pPixmap->refcnt++; - } - } - error = (*ps->ChangePictureClip)(pPicture, clipType, - (pointer)pPixmap, 0); - break; - } - case CPGraphicsExposure: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe <= xTrue) - pPicture->graphicsExposures = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPSubwindowMode: - { - unsigned int news; - news = NEXT_VAL(unsigned int); - if (news == ClipByChildren || news == IncludeInferiors) - pPicture->subWindowMode = news; - else - { - client->errorValue = news; - error = BadValue; - } - } - break; - case CPPolyEdge: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe == PolyEdgeSharp || newe == PolyEdgeSmooth) - pPicture->polyEdge = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPPolyMode: - { - unsigned int newm; - newm = NEXT_VAL(unsigned int); - if (newm == PolyModePrecise || newm == PolyModeImprecise) - pPicture->polyMode = newm; - else - { - client->errorValue = newm; - error = BadValue; - } - } - break; - case CPDither: - pPicture->dither = NEXT_VAL(Atom); - break; - case CPComponentAlpha: - { - unsigned int newca; - - newca = NEXT_VAL (unsigned int); - if (newca <= xTrue) - pPicture->componentAlpha = newca; - else - { - client->errorValue = newca; - error = BadValue; - } - } - break; - default: - client->errorValue = maskQ; - error = BadValue; - break; - } - } - (*ps->ChangePicture) (pPicture, maskQ); - return error; -} - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - RegionPtr clientClip; - int result; - - clientClip = RECTS_TO_REGION(pScreen, - nRect, rects, CT_UNSORTED); - if (!clientClip) - return BadAlloc; - result =(*ps->ChangePictureClip) (pPicture, CT_REGION, - (pointer) clientClip, 0); - if (result == Success) - { - pPicture->clipOrigin.x = xOrigin; - pPicture->clipOrigin.y = yOrigin; - pPicture->stateChanges |= CPClipXOrigin|CPClipYOrigin|CPClipMask; - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - } - return result; -} - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform) -{ - static const PictTransform identity = { { - { xFixed1, 0x00000, 0x00000 }, - { 0x00000, xFixed1, 0x00000 }, - { 0x00000, 0x00000, xFixed1 }, - } }; - - if (transform && memcmp (transform, &identity, sizeof (PictTransform)) == 0) - transform = 0; - - if (transform) - { - if (!pPicture->transform) - { - pPicture->transform = (PictTransform *) xalloc (sizeof (PictTransform)); - if (!pPicture->transform) - return BadAlloc; - } - *pPicture->transform = *transform; - } - else - { - if (pPicture->transform) - { - xfree (pPicture->transform); - pPicture->transform = 0; - } - } - return Success; -} - -static void -ValidateOnePicture (PicturePtr pPicture) -{ - if (pPicture->serialNumber != pPicture->pDrawable->serialNumber) - { - PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen); - - (*ps->ValidatePicture) (pPicture, pPicture->stateChanges); - pPicture->stateChanges = 0; - pPicture->serialNumber = pPicture->pDrawable->serialNumber; - } -} - -void -ValidatePicture(PicturePtr pPicture) -{ - ValidateOnePicture (pPicture); - if (pPicture->alphaMap) - ValidateOnePicture (pPicture->alphaMap); -} - -int -FreePicture (pointer value, - XID pid) -{ - PicturePtr pPicture = (PicturePtr) value; - - if (--pPicture->refcnt == 0) - { - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - (*ps->DestroyPicture) (pPicture); - (*ps->DestroyPictureClip) (pPicture); - if (pPicture->transform) - xfree (pPicture->transform); - if (pPicture->pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pPicture->pDrawable; - PicturePtr *pPrev; - - for (pPrev = (PicturePtr *) &((pWindow)->devPrivates[PictureWindowPrivateIndex].ptr); - *pPrev; - pPrev = &(*pPrev)->pNext) - { - if (*pPrev == pPicture) - { - *pPrev = pPicture->pNext; - break; - } - } - } - else if (pPicture->pDrawable->type == DRAWABLE_PIXMAP) - { - (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable); - } - xfree (pPicture); - } - return Success; -} - -int -FreePictFormat (pointer pPictFormat, - XID pid) -{ - return Success; -} - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - if (pMask) - ValidatePicture (pMask); - ValidatePicture (pDst); - (*ps->Composite) (op, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height); -} - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - - #ifdef TEST - fprintf(stderr, "CompositeGlyphs: Going to composite glyphs with " - "source at [%p] and destination at [%p].\n", - (void *) pSrc, (void *) pDst); - #endif - - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, lists, glyphs); -} - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pDst); - (*ps->CompositeRects) (op, pDst, color, nRect, rects); -} - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Trapezoids) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps); -} - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntriangles, triangles); -} - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriStrip) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriFan) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -typedef xFixed_32_32 xFixed_48_16; - -#define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff) -#define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31)) - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector) -{ - PictVector result; - int i, j; - xFixed_32_32 partial; - xFixed_48_16 v; - - for (j = 0; j < 3; j++) - { - v = 0; - for (i = 0; i < 3; i++) - { - partial = ((xFixed_48_16) transform->matrix[j][i] * - (xFixed_48_16) vector->vector[i]); - v += partial >> 16; - } - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - result.vector[j] = (xFixed) v; - } - if (!result.vector[2]) - return FALSE; - for (j = 0; j < 2; j++) - { - partial = (xFixed_48_16) result.vector[j] << 16; - v = partial / result.vector[2]; - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - vector->vector[j] = (xFixed) v; - } - vector->vector[2] = xFixed1; - return TRUE; -} - -#ifndef True -# define True 1 -#endif - -#ifndef False -# define False 0 -#endif - -void nxagentReconnectPictFormat(void*, XID, void*); - -Bool nxagentReconnectAllPictFormat(void *p) -{ - PictFormatPtr formats_old, formats; - int nformats, nformats_old; - Bool success = True; - Bool matched; - int i, n; - CARD32 type, a, r, g, b; - - #ifdef DEBUG - fprintf(stderr, "nxagentReconnectAllPictFormat\n"); - #endif - - formats_old = GetPictureScreen(nxagentDefaultScreen) -> formats; - nformats_old = GetPictureScreen(nxagentDefaultScreen) -> nformats; - - /* - * TODO: We could copy PictureCreateDefaultFormats, - * in order not to waste ID with FakeClientID(). - */ - formats = PictureCreateDefaultFormats (nxagentDefaultScreen, &nformats); - - if (!formats) - return FALSE; - - for (n = 0; n < nformats; n++) - { - if (formats[n].type == PictTypeIndexed) - { - if ((formats[n].index.pVisual->class | DynamicClass) == PseudoColor) - type = PICT_TYPE_COLOR; - else - type = PICT_TYPE_GRAY; - a = r = g = b = 0; - } - else - { - if ((formats[n].direct.redMask| - formats[n].direct.blueMask| - formats[n].direct.greenMask) == 0) - type = PICT_TYPE_A; - else if (formats[n].direct.red > formats[n].direct.blue) - type = PICT_TYPE_ARGB; - else - type = PICT_TYPE_ABGR; - a = Ones (formats[n].direct.alphaMask); - r = Ones (formats[n].direct.redMask); - g = Ones (formats[n].direct.greenMask); - b = Ones (formats[n].direct.blueMask); - } - formats[n].format = PICT_FORMAT(0,type,a,r,g,b); - } - - for (n = 0; n < nformats_old; n++) - { - for (i = 0, matched = False; (!matched) && (i < nformats); i++) - { - if (formats_old[n].format == formats[i].format && - formats_old[n].type == formats[i].type && - formats_old[n].direct.red == formats[i].direct.red && - formats_old[n].direct.green == formats[i].direct.green && - formats_old[n].direct.blue == formats[i].direct.blue && - formats_old[n].direct.redMask == formats[i].direct.redMask && - formats_old[n].direct.greenMask == formats[i].direct.greenMask && - formats_old[n].direct.blueMask == formats[i].direct.blueMask && - formats_old[n].direct.alpha == formats[i].direct.alpha && - formats_old[n].direct.alphaMask == formats[i].direct.alphaMask) - { - /* - * Regard depth 16 and 15 as were the same, if all other values match. - */ - - if ((formats_old[n].depth == formats[i].depth) || - ((formats_old[n].depth == 15 || formats_old[n].depth == 16) && - (formats[i].depth == 15 || formats[i].depth == 16))) - { - matched = True; - } - } - } - if (!matched) - return False; - } - xfree(formats); - - /* TODO: Perhaps do i have to do PictureFinishInit ?. */ - /* TODO: We have to check for new Render protocol version. */ - - for (i = 0; (i < MAXCLIENTS) && (success); i++) - { - if (clients[i]) - { - FindClientResourcesByType(clients[i], PictFormatType, nxagentReconnectPictFormat, &success); - } - } - - return success; -} - -/* - * It seem we don't have nothing - * to do for reconnect PictureFormat. - */ - -void nxagentReconnectPictFormat(void *p0, XID x1, void *p2) -{ - PictFormatPtr pFormat; - Bool *pBool; - - pFormat = (PictFormatPtr)p0; - pBool = (Bool*)p2; - - #ifdef DEBUG - fprintf(stderr, "nxagentReconnectPictFormat.\n"); - #endif -} - - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.XF86.original deleted file mode 100644 index b2ef69bdf..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c.XF86.original +++ /dev/null @@ -1,1305 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/picture.c,v 1.30 2003/01/26 16:40:43 eich Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "picturestr.h" - -int PictureScreenPrivateIndex = -1; -int PictureWindowPrivateIndex; -int PictureGeneration; -RESTYPE PictureType; -RESTYPE PictFormatType; -RESTYPE GlyphSetType; -int PictureCmapPolicy = PictureCmapPolicyDefault; - -Bool -PictureDestroyWindow (WindowPtr pWindow) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - - while ((pPicture = GetPictureWindow(pWindow))) - { - SetPictureWindow(pWindow, pPicture->pNext); - if (pPicture->id) - FreeResource (pPicture->id, PictureType); - FreePicture ((pointer) pPicture, pPicture->id); - } - pScreen->DestroyWindow = ps->DestroyWindow; - ret = (*pScreen->DestroyWindow) (pWindow); - ps->DestroyWindow = pScreen->DestroyWindow; - pScreen->DestroyWindow = PictureDestroyWindow; - return ret; -} - -Bool -PictureCloseScreen (int index, ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - int n; - - pScreen->CloseScreen = ps->CloseScreen; - ret = (*pScreen->CloseScreen) (index, pScreen); - PictureResetFilters (pScreen); - for (n = 0; n < ps->nformats; n++) - if (ps->formats[n].type == PictTypeIndexed) - (*ps->CloseIndexed) (pScreen, &ps->formats[n]); - SetPictureScreen(pScreen, 0); - xfree (ps->formats); - xfree (ps); - return ret; -} - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef) -{ - ScreenPtr pScreen = pColormap->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - pScreen->StoreColors = ps->StoreColors; - (*pScreen->StoreColors) (pColormap, ndef, pdef); - ps->StoreColors = pScreen->StoreColors; - pScreen->StoreColors = PictureStoreColors; - - if (pColormap->class == PseudoColor || pColormap->class == GrayScale) - { - PictFormatPtr format = ps->formats; - int nformats = ps->nformats; - - while (nformats--) - { - if (format->type == PictTypeIndexed && - format->index.pColormap == pColormap) - { - (*ps->UpdateIndexed) (pScreen, format, ndef, pdef); - break; - } - format++; - } - } -} - -static int -visualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - int d, v; - DepthPtr pDepth; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - for (v = 0; v < pDepth->numVids; v++) - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - return 0; -} - -typedef struct _formatInit { - CARD32 format; - CARD8 depth; -} FormatInitRec, *FormatInitPtr; - -static int -addFormat (FormatInitRec formats[256], - int nformat, - CARD32 format, - CARD8 depth) -{ - int n; - - for (n = 0; n < nformat; n++) - if (formats[n].format == format && formats[n].depth == depth) - return nformat; - formats[nformat].format = format; - formats[nformat].depth = depth; - return ++nformat; -} - -#define Mask(n) ((n) == 32 ? 0xffffffff : ((1 << (n))-1)) - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp) -{ - int nformats, f; - PictFormatPtr pFormats; - FormatInitRec formats[1024]; - CARD32 format; - CARD8 depth; - VisualPtr pVisual; - int v; - int bpp; - int type; - int r, g, b; - int d; - DepthPtr pDepth; - - nformats = 0; - /* formats required by protocol */ - formats[nformats].format = PICT_a1; - formats[nformats].depth = 1; - nformats++; - formats[nformats].format = PICT_a8; - formats[nformats].depth = 8; - nformats++; - formats[nformats].format = PICT_a4; - formats[nformats].depth = 4; - nformats++; - formats[nformats].format = PICT_a8r8g8b8; - formats[nformats].depth = 32; - nformats++; - formats[nformats].format = PICT_x8r8g8b8; - formats[nformats].depth = 32; - nformats++; - - /* now look through the depths and visuals adding other formats */ - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = &pScreen->visuals[v]; - depth = visualDepth (pScreen, pVisual); - if (!depth) - continue; - bpp = BitsPerPixel (depth); - switch (pVisual->class) { - case DirectColor: - case TrueColor: - r = Ones (pVisual->redMask); - g = Ones (pVisual->greenMask); - b = Ones (pVisual->blueMask); - type = PICT_TYPE_OTHER; - /* - * Current rendering code supports only two direct formats, - * fields must be packed together at the bottom of the pixel - * and must be either RGB or BGR - */ - if (pVisual->offsetBlue == 0 && - pVisual->offsetGreen == b && - pVisual->offsetRed == b + g) - { - type = PICT_TYPE_ARGB; - } - else if (pVisual->offsetRed == 0 && - pVisual->offsetGreen == r && - pVisual->offsetBlue == r + g) - { - type = PICT_TYPE_ABGR; - } - if (type != PICT_TYPE_OTHER) - { - format = PICT_FORMAT(bpp, type, 0, r, g, b); - nformats = addFormat (formats, nformats, format, depth); - } - break; - case StaticColor: - case PseudoColor: - format = PICT_VISFORMAT (bpp, PICT_TYPE_COLOR, v); - nformats = addFormat (formats, nformats, format, depth); - break; - case StaticGray: - case GrayScale: - format = PICT_VISFORMAT (bpp, PICT_TYPE_GRAY, v); - nformats = addFormat (formats, nformats, format, depth); - break; - } - } - /* - * Walk supported depths and add useful Direct formats - */ - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - bpp = BitsPerPixel (pDepth->depth); - format = 0; - switch (bpp) { - case 16: - /* depth 12 formats */ - if (pDepth->depth >= 12) - { - nformats = addFormat (formats, nformats, - PICT_x4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x4b4g4r4, pDepth->depth); - } - /* depth 15 formats */ - if (pDepth->depth >= 15) - { - nformats = addFormat (formats, nformats, - PICT_x1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x1b5g5r5, pDepth->depth); - } - /* depth 16 formats */ - if (pDepth->depth >= 16) - { - nformats = addFormat (formats, nformats, - PICT_a1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a1b5g5r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_r5g6b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b5g6r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4b4g4r4, pDepth->depth); - } - break; - case 24: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b8g8r8, pDepth->depth); - } - break; - case 32: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_x8r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x8b8g8r8, pDepth->depth); - } - break; - } - } - - - pFormats = (PictFormatPtr) xalloc (nformats * sizeof (PictFormatRec)); - if (!pFormats) - return 0; - memset (pFormats, '\0', nformats * sizeof (PictFormatRec)); - for (f = 0; f < nformats; f++) - { - pFormats[f].id = FakeClientID (0); - pFormats[f].depth = formats[f].depth; - format = formats[f].format; - pFormats[f].format = format; - switch (PICT_FORMAT_TYPE(format)) { - case PICT_TYPE_ARGB: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_R(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = (PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_B(format); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = 0; - break; - - case PICT_TYPE_ABGR: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_B(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = (PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_R(format); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = 0; - break; - - case PICT_TYPE_A: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alpha = 0; - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - - /* remaining fields already set to zero */ - break; - - case PICT_TYPE_COLOR: - case PICT_TYPE_GRAY: - pFormats[f].type = PictTypeIndexed; - pFormats[f].index.pVisual = &pScreen->visuals[PICT_FORMAT_VIS(format)]; - break; - } - } - *nformatp = nformats; - return pFormats; -} - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return FALSE; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->type == PictTypeIndexed && !format->index.pColormap) - { - if (format->index.pVisual->vid == pScreen->rootVisual) - format->index.pColormap = (ColormapPtr) LookupIDByType(pScreen->defColormap, - RT_COLORMAP); - else - { - if (CreateColormap (FakeClientID (0), pScreen, - format->index.pVisual, - &format->index.pColormap, AllocNone, - 0) != Success) - { - return FALSE; - } - } - if (!(*ps->InitIndexed) (pScreen, format)) - return FALSE; - } - format++; - } - return TRUE; -} - -Bool -PictureFinishInit (void) -{ - int s; - - for (s = 0; s < screenInfo.numScreens; s++) - { - if (!PictureInitIndexedFormats (screenInfo.screens[s])) - return FALSE; - (void) AnimCurInit (screenInfo.screens[s]); - } - - return TRUE; -} - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return FALSE; - ps->subpixel = subpixel; - return TRUE; - -} - -int -PictureGetSubpixelOrder (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return SubPixelUnknown; - return ps->subpixel; -} - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - int type; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - switch (pVisual->class) { - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - type = PictTypeIndexed; - break; - case TrueColor: - type = PictTypeDirect; - break; - case DirectColor: - default: - return 0; - } - while (nformat--) - { - if (format->depth == depth && format->type == type) - { - if (type == PictTypeIndexed) - { - if (format->index.pVisual == pVisual) - return format; - } - else - { - if (format->direct.redMask << format->direct.red == - pVisual->redMask && - format->direct.greenMask << format->direct.green == - pVisual->greenMask && - format->direct.blueMask << format->direct.blue == - pVisual->blueMask) - { - return format; - } - } - } - format++; - } - return 0; -} - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 f) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->depth == depth && format->format == (f & 0xffffff)) - return format; - format++; - } - return 0; -} - -int -PictureParseCmapPolicy (const char *name) -{ - if ( strcmp (name, "default" ) == 0) - return PictureCmapPolicyDefault; - else if ( strcmp (name, "mono" ) == 0) - return PictureCmapPolicyMono; - else if ( strcmp (name, "gray" ) == 0) - return PictureCmapPolicyGray; - else if ( strcmp (name, "color" ) == 0) - return PictureCmapPolicyColor; - else if ( strcmp (name, "all" ) == 0) - return PictureCmapPolicyAll; - else - return PictureCmapPolicyInvalid; -} - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats) -{ - PictureScreenPtr ps; - int n; - CARD32 type, a, r, g, b; - - if (PictureGeneration != serverGeneration) - { - PictureType = CreateNewResourceType (FreePicture); - if (!PictureType) - return FALSE; - PictFormatType = CreateNewResourceType (FreePictFormat); - if (!PictFormatType) - return FALSE; - GlyphSetType = CreateNewResourceType (FreeGlyphSet); - if (!GlyphSetType) - return FALSE; - PictureScreenPrivateIndex = AllocateScreenPrivateIndex(); - if (PictureScreenPrivateIndex < 0) - return FALSE; - PictureWindowPrivateIndex = AllocateWindowPrivateIndex(); - PictureGeneration = serverGeneration; -#ifdef XResExtension - RegisterResourceName (PictureType, "PICTURE"); - RegisterResourceName (PictFormatType, "PICTFORMAT"); - RegisterResourceName (GlyphSetType, "GLYPHSET"); -#endif - } - if (!AllocateWindowPrivate (pScreen, PictureWindowPrivateIndex, 0)) - return FALSE; - - if (!formats) - { - formats = PictureCreateDefaultFormats (pScreen, &nformats); - if (!formats) - return FALSE; - } - for (n = 0; n < nformats; n++) - { - if (!AddResource (formats[n].id, PictFormatType, (pointer) (formats+n))) - { - xfree (formats); - return FALSE; - } - if (formats[n].type == PictTypeIndexed) - { - if ((formats[n].index.pVisual->class | DynamicClass) == PseudoColor) - type = PICT_TYPE_COLOR; - else - type = PICT_TYPE_GRAY; - a = r = g = b = 0; - } - else - { - if ((formats[n].direct.redMask| - formats[n].direct.blueMask| - formats[n].direct.greenMask) == 0) - type = PICT_TYPE_A; - else if (formats[n].direct.red > formats[n].direct.blue) - type = PICT_TYPE_ARGB; - else - type = PICT_TYPE_ABGR; - a = Ones (formats[n].direct.alphaMask); - r = Ones (formats[n].direct.redMask); - g = Ones (formats[n].direct.greenMask); - b = Ones (formats[n].direct.blueMask); - } - formats[n].format = PICT_FORMAT(0,type,a,r,g,b); - } - ps = (PictureScreenPtr) xalloc (sizeof (PictureScreenRec)); - if (!ps) - { - xfree (formats); - return FALSE; - } - SetPictureScreen(pScreen, ps); - if (!GlyphInit (pScreen)) - { - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - ps->totalPictureSize = sizeof (PictureRec); - ps->PicturePrivateSizes = 0; - ps->PicturePrivateLen = 0; - - ps->formats = formats; - ps->fallback = formats; - ps->nformats = nformats; - - ps->filters = 0; - ps->nfilters = 0; - ps->filterAliases = 0; - ps->nfilterAliases = 0; - - ps->subpixel = SubPixelUnknown; - - ps->CloseScreen = pScreen->CloseScreen; - ps->DestroyWindow = pScreen->DestroyWindow; - ps->StoreColors = pScreen->StoreColors; - pScreen->DestroyWindow = PictureDestroyWindow; - pScreen->CloseScreen = PictureCloseScreen; - pScreen->StoreColors = PictureStoreColors; - - if (!PictureSetDefaultFilters (pScreen)) - { - PictureResetFilters (pScreen); - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - return TRUE; -} - -void -SetPictureToDefaults (PicturePtr pPicture) -{ - pPicture->refcnt = 1; - pPicture->repeat = 0; - pPicture->graphicsExposures = FALSE; - pPicture->subWindowMode = ClipByChildren; - pPicture->polyEdge = PolyEdgeSharp; - pPicture->polyMode = PolyModePrecise; - pPicture->freeCompClip = FALSE; - pPicture->clientClipType = CT_NONE; - pPicture->componentAlpha = FALSE; - - pPicture->alphaMap = 0; - pPicture->alphaOrigin.x = 0; - pPicture->alphaOrigin.y = 0; - - pPicture->clipOrigin.x = 0; - pPicture->clipOrigin.y = 0; - pPicture->clientClip = 0; - - pPicture->transform = 0; - - pPicture->dither = None; - pPicture->filter = PictureGetFilterId (FilterNearest, -1, TRUE); - pPicture->filter_params = 0; - pPicture->filter_nparams = 0; - - pPicture->serialNumber = GC_CHANGE_SERIAL_BIT; - pPicture->stateChanges = (1 << (CPLastBit+1)) - 1; -} - -PicturePtr -AllocatePicture (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture; - char *ptr; - DevUnion *ppriv; - unsigned int *sizes; - unsigned int size; - int i; - - pPicture = (PicturePtr) xalloc (ps->totalPictureSize); - if (!pPicture) - return 0; - ppriv = (DevUnion *)(pPicture + 1); - pPicture->devPrivates = ppriv; - sizes = ps->PicturePrivateSizes; - ptr = (char *)(ppriv + ps->PicturePrivateLen); - for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - return pPicture; -} - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask vmask, - XID *vlist, - ClientPtr client, - int *error) -{ - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen); - - pPicture = AllocatePicture (pDrawable->pScreen); - if (!pPicture) - { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pDrawable = pDrawable; - pPicture->pFormat = pFormat; - pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24); - if (pDrawable->type == DRAWABLE_PIXMAP) - { - ++((PixmapPtr)pDrawable)->refcnt; - pPicture->pNext = 0; - } - else - { - pPicture->pNext = GetPictureWindow(((WindowPtr) pDrawable)); - SetPictureWindow(((WindowPtr) pDrawable), pPicture); - } - - SetPictureToDefaults (pPicture); - - if (vmask) - *error = ChangePicture (pPicture, vmask, vlist, 0, client); - else - *error = Success; - if (*error == Success) - *error = (*ps->CreatePicture) (pPicture); - if (*error != Success) - { - FreePicture (pPicture, (XID) 0); - pPicture = 0; - } - return pPicture; -} - -#define NEXT_VAL(_type) (vlist ? (_type) *vlist++ : (_type) ulist++->val) - -#define NEXT_PTR(_type) ((_type) ulist++->ptr) - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - BITS32 index2; - int error = 0; - BITS32 maskQ; - - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - maskQ = vmask; - while (vmask && !error) - { - index2 = (BITS32) lowbit (vmask); - vmask &= ~index2; - pPicture->stateChanges |= index2; - switch (index2) - { - case CPRepeat: - { - unsigned int newr; - newr = NEXT_VAL(unsigned int); - if (newr <= xTrue) - pPicture->repeat = newr; - else - { - client->errorValue = newr; - error = BadValue; - } - } - break; - case CPAlphaMap: - { - PicturePtr pAlpha; - - if (vlist) - { - Picture pid = NEXT_VAL(Picture); - - if (pid == None) - pAlpha = 0; - else - { - pAlpha = (PicturePtr) SecurityLookupIDByType(client, - pid, - PictureType, - SecurityWriteAccess|SecurityReadAccess); - if (!pAlpha) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - if (pAlpha->pDrawable->type != DRAWABLE_PIXMAP) - { - client->errorValue = pid; - error = BadMatch; - break; - } - } - } - else - pAlpha = NEXT_PTR(PicturePtr); - if (!error) - { - if (pAlpha && pAlpha->pDrawable->type == DRAWABLE_PIXMAP) - pAlpha->refcnt++; - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - pPicture->alphaMap = pAlpha; - } - } - break; - case CPAlphaXOrigin: - pPicture->alphaOrigin.x = NEXT_VAL(INT16); - break; - case CPAlphaYOrigin: - pPicture->alphaOrigin.y = NEXT_VAL(INT16); - break; - case CPClipXOrigin: - pPicture->clipOrigin.x = NEXT_VAL(INT16); - break; - case CPClipYOrigin: - pPicture->clipOrigin.y = NEXT_VAL(INT16); - break; - case CPClipMask: - { - Pixmap pid; - PixmapPtr pPixmap; - int clipType; - - if (vlist) - { - pid = NEXT_VAL(Pixmap); - if (pid == None) - { - clipType = CT_NONE; - pPixmap = NullPixmap; - } - else - { - clipType = CT_PIXMAP; - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, - pid, - RT_PIXMAP, - SecurityReadAccess); - if (!pPixmap) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - } - } - else - { - pPixmap = NEXT_PTR(PixmapPtr); - if (pPixmap) - clipType = CT_PIXMAP; - else - clipType = CT_NONE; - } - - if (pPixmap) - { - if ((pPixmap->drawable.depth != 1) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - break; - } - else - { - clipType = CT_PIXMAP; - pPixmap->refcnt++; - } - } - error = (*ps->ChangePictureClip)(pPicture, clipType, - (pointer)pPixmap, 0); - break; - } - case CPGraphicsExposure: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe <= xTrue) - pPicture->graphicsExposures = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPSubwindowMode: - { - unsigned int news; - news = NEXT_VAL(unsigned int); - if (news == ClipByChildren || news == IncludeInferiors) - pPicture->subWindowMode = news; - else - { - client->errorValue = news; - error = BadValue; - } - } - break; - case CPPolyEdge: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe == PolyEdgeSharp || newe == PolyEdgeSmooth) - pPicture->polyEdge = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPPolyMode: - { - unsigned int newm; - newm = NEXT_VAL(unsigned int); - if (newm == PolyModePrecise || newm == PolyModeImprecise) - pPicture->polyMode = newm; - else - { - client->errorValue = newm; - error = BadValue; - } - } - break; - case CPDither: - pPicture->dither = NEXT_VAL(Atom); - break; - case CPComponentAlpha: - { - unsigned int newca; - - newca = NEXT_VAL (unsigned int); - if (newca <= xTrue) - pPicture->componentAlpha = newca; - else - { - client->errorValue = newca; - error = BadValue; - } - } - break; - default: - client->errorValue = maskQ; - error = BadValue; - break; - } - } - (*ps->ChangePicture) (pPicture, maskQ); - return error; -} - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - RegionPtr clientClip; - int result; - - clientClip = RECTS_TO_REGION(pScreen, - nRect, rects, CT_UNSORTED); - if (!clientClip) - return BadAlloc; - result =(*ps->ChangePictureClip) (pPicture, CT_REGION, - (pointer) clientClip, 0); - if (result == Success) - { - pPicture->clipOrigin.x = xOrigin; - pPicture->clipOrigin.y = yOrigin; - pPicture->stateChanges |= CPClipXOrigin|CPClipYOrigin|CPClipMask; - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - } - return result; -} - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform) -{ - static const PictTransform identity = { { - { xFixed1, 0x00000, 0x00000 }, - { 0x00000, xFixed1, 0x00000 }, - { 0x00000, 0x00000, xFixed1 }, - } }; - - if (transform && memcmp (transform, &identity, sizeof (PictTransform)) == 0) - transform = 0; - - if (transform) - { - if (!pPicture->transform) - { - pPicture->transform = (PictTransform *) xalloc (sizeof (PictTransform)); - if (!pPicture->transform) - return BadAlloc; - } - *pPicture->transform = *transform; - } - else - { - if (pPicture->transform) - { - xfree (pPicture->transform); - pPicture->transform = 0; - } - } - return Success; -} - -static void -ValidateOnePicture (PicturePtr pPicture) -{ - if (pPicture->serialNumber != pPicture->pDrawable->serialNumber) - { - PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen); - - (*ps->ValidatePicture) (pPicture, pPicture->stateChanges); - pPicture->stateChanges = 0; - pPicture->serialNumber = pPicture->pDrawable->serialNumber; - } -} - -void -ValidatePicture(PicturePtr pPicture) -{ - ValidateOnePicture (pPicture); - if (pPicture->alphaMap) - ValidateOnePicture (pPicture->alphaMap); -} - -int -FreePicture (pointer value, - XID pid) -{ - PicturePtr pPicture = (PicturePtr) value; - - if (--pPicture->refcnt == 0) - { - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - (*ps->DestroyPicture) (pPicture); - (*ps->DestroyPictureClip) (pPicture); - if (pPicture->transform) - xfree (pPicture->transform); - if (pPicture->pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pPicture->pDrawable; - PicturePtr *pPrev; - - for (pPrev = (PicturePtr *) &((pWindow)->devPrivates[PictureWindowPrivateIndex].ptr); - *pPrev; - pPrev = &(*pPrev)->pNext) - { - if (*pPrev == pPicture) - { - *pPrev = pPicture->pNext; - break; - } - } - } - else if (pPicture->pDrawable->type == DRAWABLE_PIXMAP) - { - (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable); - } - xfree (pPicture); - } - return Success; -} - -int -FreePictFormat (pointer pPictFormat, - XID pid) -{ - return Success; -} - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - if (pMask) - ValidatePicture (pMask); - ValidatePicture (pDst); - (*ps->Composite) (op, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height); -} - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, lists, glyphs); -} - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pDst); - (*ps->CompositeRects) (op, pDst, color, nRect, rects); -} - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Trapezoids) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps); -} - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntriangles, triangles); -} - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriStrip) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriFan) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -typedef xFixed_32_32 xFixed_48_16; - -#define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff) -#define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31)) - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector) -{ - PictVector result; - int i, j; - xFixed_32_32 partial; - xFixed_48_16 v; - - for (j = 0; j < 3; j++) - { - v = 0; - for (i = 0; i < 3; i++) - { - partial = ((xFixed_48_16) transform->matrix[j][i] * - (xFixed_48_16) vector->vector[i]); - v += partial >> 16; - } - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - result.vector[j] = (xFixed) v; - } - if (!result.vector[2]) - return FALSE; - for (j = 0; j < 2; j++) - { - partial = (xFixed_48_16) result.vector[j] << 16; - v = partial / result.vector[2]; - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - vector->vector[j] = (xFixed) v; - } - vector->vector[2] = xFixed1; - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.NX.original deleted file mode 100644 index 91eab0125..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.NX.original +++ /dev/null @@ -1,533 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXpicturestr.h" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/picturestr.h,v 1.22 2002/11/23 02:38:15 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -/* - * This must keep the same symbol as the original - * picturestr.h or symbols will be redefined. We - * should define a new types and cast when appro- - * priate. - */ - -#ifndef _PICTURESTR_H_ -#define _PICTURESTR_H_ - -#include "NXglyphstr.h" -#include "scrnintstr.h" -#include "resource.h" - -typedef struct _DirectFormat { - CARD16 red, redMask; - CARD16 green, greenMask; - CARD16 blue, blueMask; - CARD16 alpha, alphaMask; -} DirectFormatRec; - -typedef struct _IndexFormat { - VisualPtr pVisual; - ColormapPtr pColormap; - int nvalues; - xIndexValue *pValues; - void *devPrivate; -} IndexFormatRec; - -typedef struct _PictFormat { - CARD32 id; - CARD32 format; /* except bpp */ - unsigned char type; - unsigned char depth; - DirectFormatRec direct; - IndexFormatRec index; -} PictFormatRec; - -typedef struct _PictVector { - xFixed vector[3]; -} PictVector, *PictVectorPtr; - -typedef struct _PictTransform { - xFixed matrix[3][3]; -} PictTransform, *PictTransformPtr; - -typedef struct _Picture { - DrawablePtr pDrawable; - PictFormatPtr pFormat; - CARD32 format; /* PICT_FORMAT */ - int refcnt; - CARD32 id; - PicturePtr pNext; /* chain on same drawable */ - - unsigned int repeat : 1; - unsigned int graphicsExposures : 1; - unsigned int subWindowMode : 1; - unsigned int polyEdge : 1; - unsigned int polyMode : 1; - unsigned int freeCompClip : 1; - unsigned int clientClipType : 2; - unsigned int componentAlpha : 1; - unsigned int unused : 23; - - PicturePtr alphaMap; - DDXPointRec alphaOrigin; - - DDXPointRec clipOrigin; - pointer clientClip; - - Atom dither; - - unsigned long stateChanges; - unsigned long serialNumber; - - RegionPtr pCompositeClip; - - DevUnion *devPrivates; - - PictTransform *transform; - - int filter; - xFixed *filter_params; - int filter_nparams; -} PictureRec; - -typedef struct { - char *name; - xFixed *params; - int nparams; - int id; -} PictFilterRec, *PictFilterPtr; - -#define PictFilterNearest 0 -#define PictFilterBilinear 1 - -#define PictFilterFast 2 -#define PictFilterGood 3 -#define PictFilterBest 4 - -typedef struct { - char *alias; - int alias_id; - int filter_id; -} PictFilterAliasRec, *PictFilterAliasPtr; - -typedef int (*CreatePictureProcPtr) (PicturePtr pPicture); -typedef void (*DestroyPictureProcPtr) (PicturePtr pPicture); -typedef int (*ChangePictureClipProcPtr) (PicturePtr pPicture, - int clipType, - pointer value, - int n); -typedef void (*DestroyPictureClipProcPtr)(PicturePtr pPicture); - -typedef int (*ChangePictureTransformProcPtr) (PicturePtr pPicture, - PictTransform *transform); - -typedef int (*ChangePictureFilterProcPtr) (PicturePtr pPicture, - int filter, - xFixed *params, - int nparams); - -typedef void (*DestroyPictureFilterProcPtr) (PicturePtr pPicture); - -typedef void (*ChangePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*ValidatePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*CompositeProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -typedef void (*GlyphsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlists, - GlyphListPtr lists, - GlyphPtr *glyphs); - -typedef void (*CompositeRectsProcPtr) (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -typedef void (*RasterizeTrapezoidProcPtr)(PicturePtr pMask, - xTrapezoid *trap, - int x_off, - int y_off); - -typedef void (*TrapezoidsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -typedef void (*TrianglesProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntri, - xTriangle *tris); - -typedef void (*TriStripProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef void (*TriFanProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef Bool (*InitIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*CloseIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*UpdateIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat, - int ndef, - xColorItem *pdef); - -typedef struct _PictureScreen { - int totalPictureSize; - unsigned int *PicturePrivateSizes; - int PicturePrivateLen; - - PictFormatPtr formats; - PictFormatPtr fallback; - int nformats; - - CreatePictureProcPtr CreatePicture; - DestroyPictureProcPtr DestroyPicture; - ChangePictureClipProcPtr ChangePictureClip; - DestroyPictureClipProcPtr DestroyPictureClip; - - ChangePictureProcPtr ChangePicture; - ValidatePictureProcPtr ValidatePicture; - - CompositeProcPtr Composite; - GlyphsProcPtr Glyphs; - CompositeRectsProcPtr CompositeRects; - - DestroyWindowProcPtr DestroyWindow; - CloseScreenProcPtr CloseScreen; - - StoreColorsProcPtr StoreColors; - - InitIndexedProcPtr InitIndexed; - CloseIndexedProcPtr CloseIndexed; - UpdateIndexedProcPtr UpdateIndexed; - - int subpixel; - - PictFilterPtr filters; - int nfilters; - PictFilterAliasPtr filterAliases; - int nfilterAliases; - - ChangePictureTransformProcPtr ChangePictureTransform; - ChangePictureFilterProcPtr ChangePictureFilter; - DestroyPictureFilterProcPtr DestroyPictureFilter; - - TrapezoidsProcPtr Trapezoids; - TrianglesProcPtr Triangles; - TriStripProcPtr TriStrip; - TriFanProcPtr TriFan; - - RasterizeTrapezoidProcPtr RasterizeTrapezoid; -} PictureScreenRec, *PictureScreenPtr; - -extern int PictureScreenPrivateIndex; -extern int PictureWindowPrivateIndex; -extern RESTYPE PictureType; -extern RESTYPE PictFormatType; -extern RESTYPE GlyphSetType; - -#define GetPictureScreen(s) ((PictureScreenPtr) ((s)->devPrivates[PictureScreenPrivateIndex].ptr)) -#define GetPictureScreenIfSet(s) ((PictureScreenPrivateIndex != -1) ? GetPictureScreen(s) : NULL) -#define SetPictureScreen(s,p) ((s)->devPrivates[PictureScreenPrivateIndex].ptr = (pointer) (p)) -#define GetPictureWindow(w) ((PicturePtr) ((w)->devPrivates[PictureWindowPrivateIndex].ptr)) -#define SetPictureWindow(w,p) ((w)->devPrivates[PictureWindowPrivateIndex].ptr = (pointer) (p)) - -#define VERIFY_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, PictureType, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -Bool -PictureDestroyWindow (WindowPtr pWindow); - -Bool -PictureCloseScreen (int Index, ScreenPtr pScreen); - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef); - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen); - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel); - -int -PictureGetSubpixelOrder (ScreenPtr pScreen); - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp); - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual); - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 format); - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); - -int -PictureGetFilterId (char *filter, int len, Bool makeit); - -char * -PictureGetFilterName (int id); - -int -PictureAddFilter (ScreenPtr pScreen, char *filter, xFixed *params, int nparams); - -Bool -PictureSetFilterAlias (ScreenPtr pScreen, char *filter, char *alias); - -Bool -PictureSetDefaultFilters (ScreenPtr pScreen); - -void -PictureResetFilters (ScreenPtr pScreen); - -PictFilterPtr -PictureFindFilter (ScreenPtr pScreen, char *name, int len); - -int -SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams); - -Bool -PictureFinishInit (void); - -void -SetPictureToDefaults (PicturePtr pPicture); - -PicturePtr -AllocatePicture (ScreenPtr pScreen); - -#if 0 -Bool -miPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); -#endif - - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask mask, - XID *list, - ClientPtr client, - int *error); - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client); - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects); - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform); - -void -ValidatePicture(PicturePtr pPicture); - -int -FreePicture (pointer pPicture, - XID pid); - -int -FreePictFormat (pointer pPictFormat, - XID pid); - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs); - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles); - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector); - -void RenderExtensionInit (void); - -Bool -AnimCurInit (ScreenPtr pScreen); - -int -AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor); - -#ifdef PANORAMIX -void PanoramiXRenderInit (void); -void PanoramiXRenderReset (void); -#endif - -#endif /* _PICTURESTR_H_ */ - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.XF86.original deleted file mode 100644 index cb5ea0ac9..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicturestr.h.XF86.original +++ /dev/null @@ -1,501 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/picturestr.h,v 1.22 2002/11/23 02:38:15 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifndef _PICTURESTR_H_ -#define _PICTURESTR_H_ - -#include "glyphstr.h" -#include "scrnintstr.h" -#include "resource.h" - -typedef struct _DirectFormat { - CARD16 red, redMask; - CARD16 green, greenMask; - CARD16 blue, blueMask; - CARD16 alpha, alphaMask; -} DirectFormatRec; - -typedef struct _IndexFormat { - VisualPtr pVisual; - ColormapPtr pColormap; - int nvalues; - xIndexValue *pValues; - void *devPrivate; -} IndexFormatRec; - -typedef struct _PictFormat { - CARD32 id; - CARD32 format; /* except bpp */ - unsigned char type; - unsigned char depth; - DirectFormatRec direct; - IndexFormatRec index; -} PictFormatRec; - -typedef struct _PictVector { - xFixed vector[3]; -} PictVector, *PictVectorPtr; - -typedef struct _PictTransform { - xFixed matrix[3][3]; -} PictTransform, *PictTransformPtr; - -typedef struct _Picture { - DrawablePtr pDrawable; - PictFormatPtr pFormat; - CARD32 format; /* PICT_FORMAT */ - int refcnt; - CARD32 id; - PicturePtr pNext; /* chain on same drawable */ - - unsigned int repeat : 1; - unsigned int graphicsExposures : 1; - unsigned int subWindowMode : 1; - unsigned int polyEdge : 1; - unsigned int polyMode : 1; - unsigned int freeCompClip : 1; - unsigned int clientClipType : 2; - unsigned int componentAlpha : 1; - unsigned int unused : 23; - - PicturePtr alphaMap; - DDXPointRec alphaOrigin; - - DDXPointRec clipOrigin; - pointer clientClip; - - Atom dither; - - unsigned long stateChanges; - unsigned long serialNumber; - - RegionPtr pCompositeClip; - - DevUnion *devPrivates; - - PictTransform *transform; - - int filter; - xFixed *filter_params; - int filter_nparams; -} PictureRec; - -typedef struct { - char *name; - xFixed *params; - int nparams; - int id; -} PictFilterRec, *PictFilterPtr; - -#define PictFilterNearest 0 -#define PictFilterBilinear 1 - -#define PictFilterFast 2 -#define PictFilterGood 3 -#define PictFilterBest 4 - -typedef struct { - char *alias; - int alias_id; - int filter_id; -} PictFilterAliasRec, *PictFilterAliasPtr; - -typedef int (*CreatePictureProcPtr) (PicturePtr pPicture); -typedef void (*DestroyPictureProcPtr) (PicturePtr pPicture); -typedef int (*ChangePictureClipProcPtr) (PicturePtr pPicture, - int clipType, - pointer value, - int n); -typedef void (*DestroyPictureClipProcPtr)(PicturePtr pPicture); - -typedef int (*ChangePictureTransformProcPtr) (PicturePtr pPicture, - PictTransform *transform); - -typedef int (*ChangePictureFilterProcPtr) (PicturePtr pPicture, - int filter, - xFixed *params, - int nparams); - -typedef void (*DestroyPictureFilterProcPtr) (PicturePtr pPicture); - -typedef void (*ChangePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*ValidatePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*CompositeProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -typedef void (*GlyphsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlists, - GlyphListPtr lists, - GlyphPtr *glyphs); - -typedef void (*CompositeRectsProcPtr) (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -typedef void (*RasterizeTrapezoidProcPtr)(PicturePtr pMask, - xTrapezoid *trap, - int x_off, - int y_off); - -typedef void (*TrapezoidsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -typedef void (*TrianglesProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntri, - xTriangle *tris); - -typedef void (*TriStripProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef void (*TriFanProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef Bool (*InitIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*CloseIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*UpdateIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat, - int ndef, - xColorItem *pdef); - -typedef struct _PictureScreen { - int totalPictureSize; - unsigned int *PicturePrivateSizes; - int PicturePrivateLen; - - PictFormatPtr formats; - PictFormatPtr fallback; - int nformats; - - CreatePictureProcPtr CreatePicture; - DestroyPictureProcPtr DestroyPicture; - ChangePictureClipProcPtr ChangePictureClip; - DestroyPictureClipProcPtr DestroyPictureClip; - - ChangePictureProcPtr ChangePicture; - ValidatePictureProcPtr ValidatePicture; - - CompositeProcPtr Composite; - GlyphsProcPtr Glyphs; - CompositeRectsProcPtr CompositeRects; - - DestroyWindowProcPtr DestroyWindow; - CloseScreenProcPtr CloseScreen; - - StoreColorsProcPtr StoreColors; - - InitIndexedProcPtr InitIndexed; - CloseIndexedProcPtr CloseIndexed; - UpdateIndexedProcPtr UpdateIndexed; - - int subpixel; - - PictFilterPtr filters; - int nfilters; - PictFilterAliasPtr filterAliases; - int nfilterAliases; - - ChangePictureTransformProcPtr ChangePictureTransform; - ChangePictureFilterProcPtr ChangePictureFilter; - DestroyPictureFilterProcPtr DestroyPictureFilter; - - TrapezoidsProcPtr Trapezoids; - TrianglesProcPtr Triangles; - TriStripProcPtr TriStrip; - TriFanProcPtr TriFan; - - RasterizeTrapezoidProcPtr RasterizeTrapezoid; -} PictureScreenRec, *PictureScreenPtr; - -extern int PictureScreenPrivateIndex; -extern int PictureWindowPrivateIndex; -extern RESTYPE PictureType; -extern RESTYPE PictFormatType; -extern RESTYPE GlyphSetType; - -#define GetPictureScreen(s) ((PictureScreenPtr) ((s)->devPrivates[PictureScreenPrivateIndex].ptr)) -#define GetPictureScreenIfSet(s) ((PictureScreenPrivateIndex != -1) ? GetPictureScreen(s) : NULL) -#define SetPictureScreen(s,p) ((s)->devPrivates[PictureScreenPrivateIndex].ptr = (pointer) (p)) -#define GetPictureWindow(w) ((PicturePtr) ((w)->devPrivates[PictureWindowPrivateIndex].ptr)) -#define SetPictureWindow(w,p) ((w)->devPrivates[PictureWindowPrivateIndex].ptr = (pointer) (p)) - -#define VERIFY_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, PictureType, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -Bool -PictureDestroyWindow (WindowPtr pWindow); - -Bool -PictureCloseScreen (int Index, ScreenPtr pScreen); - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef); - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen); - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel); - -int -PictureGetSubpixelOrder (ScreenPtr pScreen); - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp); - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual); - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 format); - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); - -int -PictureGetFilterId (char *filter, int len, Bool makeit); - -char * -PictureGetFilterName (int id); - -int -PictureAddFilter (ScreenPtr pScreen, char *filter, xFixed *params, int nparams); - -Bool -PictureSetFilterAlias (ScreenPtr pScreen, char *filter, char *alias); - -Bool -PictureSetDefaultFilters (ScreenPtr pScreen); - -void -PictureResetFilters (ScreenPtr pScreen); - -PictFilterPtr -PictureFindFilter (ScreenPtr pScreen, char *name, int len); - -int -SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams); - -Bool -PictureFinishInit (void); - -void -SetPictureToDefaults (PicturePtr pPicture); - -PicturePtr -AllocatePicture (ScreenPtr pScreen); - -#if 0 -Bool -miPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); -#endif - - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask mask, - XID *list, - ClientPtr client, - int *error); - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client); - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects); - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform); - -void -ValidatePicture(PicturePtr pPicture); - -int -FreePicture (pointer pPicture, - XID pid); - -int -FreePictFormat (pointer pPictFormat, - XID pid); - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs); - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles); - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector); - -void RenderExtensionInit (void); - -Bool -AnimCurInit (ScreenPtr pScreen); - -int -AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor); - -#ifdef PANORAMIX -void PanoramiXRenderInit (void); -void PanoramiXRenderReset (void); -#endif - -#endif /* _PICTURESTR_H_ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.NX.original deleted file mode 100644 index 20a6bd6dc..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.NX.original +++ /dev/null @@ -1,921 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXproperty.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/property.c,v 3.12 2002/02/19 11:09:22 alanh Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: property.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "X.h" -#define NEED_REPLIES -#define NEED_EVENTS -#include "Xproto.h" -#include "windowstr.h" -#include "propertyst.h" -#include "dixstruct.h" -#include "../../dix/dispatch.h" -#include "swaprep.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif -#ifdef LBX -#include "lbxserve.h" -#include "lbxtags.h" -#endif - -#include "Options.h" -#include "Rootless.h" -#include "Client.h" - -#if defined(LBX) || defined(LBX_COMPAT) -int fWriteToClient(client, len, buf) - ClientPtr client; - int len; - char *buf; -{ - return WriteToClient(client, len, buf); -} -#endif - -/***************************************************************** - * Property Stuff - * - * ChangeProperty, DeleteProperty, GetProperties, - * ListProperties - * - * Properties below to windows. A allocate slots each time - * a property is added. No fancy searching done. - * - *****************************************************************/ - -#ifdef notdef -static void -PrintPropertys(pWin) - WindowPtr pWin; -{ - PropertyPtr pProp; - register int j; - - pProp = pWin->userProps; - while (pProp) - { - ErrorF( "%x %x\n", pProp->propertyName, pProp->type); - ErrorF("property format: %d\n", pProp->format); - ErrorF("property data: \n"); - for (j=0; j<(pProp->format/8)*pProp->size; j++) - ErrorF("%c\n", pProp->data[j]); - pProp = pProp->next; - } -} -#endif - -int -ProcRotateProperties(client) - ClientPtr client; -{ - int i, j, delta; - REQUEST(xRotatePropertiesReq); - WindowPtr pWin; - register Atom * atoms; - PropertyPtr * props; /* array of pointer */ - PropertyPtr pProp; - xEvent event; - - REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2); - UpdateCurrentTime(); - pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!stuff->nAtoms) - return(Success); - atoms = (Atom *) & stuff[1]; - props = (PropertyPtr *)ALLOCATE_LOCAL(stuff->nAtoms * sizeof(PropertyPtr)); - if (!props) - return(BadAlloc); - for (i = 0; i < stuff->nAtoms; i++) - { -#ifdef XCSECURITY - char action = SecurityCheckPropertyAccess(client, pWin, atoms[i], - SecurityReadAccess|SecurityWriteAccess); -#endif - if (!ValidAtom(atoms[i]) -#ifdef XCSECURITY - || (SecurityErrorOperation == action) -#endif - ) - { - DEALLOCATE_LOCAL(props); - client->errorValue = atoms[i]; - return BadAtom; - } -#ifdef XCSECURITY - if (SecurityIgnoreOperation == action) - { - DEALLOCATE_LOCAL(props); - return Success; - } -#endif - for (j = i + 1; j < stuff->nAtoms; j++) - if (atoms[j] == atoms[i]) - { - DEALLOCATE_LOCAL(props); - return BadMatch; - } - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == atoms[i]) - goto found; - pProp = pProp->next; - } - DEALLOCATE_LOCAL(props); - return BadMatch; -found: - props[i] = pProp; - } - delta = stuff->nPositions; - - /* If the rotation is a complete 360 degrees, then moving the properties - around and generating PropertyNotify events should be skipped. */ - - if ( (stuff->nAtoms != 0) && (abs(delta) % stuff->nAtoms) != 0 ) - { - while (delta < 0) /* faster if abs value is small */ - delta += stuff->nAtoms; - for (i = 0; i < stuff->nAtoms; i++) - { - /* Generate a PropertyNotify event for each property whose value - is changed in the order in which they appear in the request. */ - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = props[i]->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - - props[i]->propertyName = atoms[(i + delta) % stuff->nAtoms]; - } - } - DEALLOCATE_LOCAL(props); - return Success; -} - -int -ProcChangeProperty(client) - ClientPtr client; -{ - WindowPtr pWin; - char format, mode; - unsigned long len; - int sizeInBytes; - int totalSize; - int err; - REQUEST(xChangePropertyReq); - - REQUEST_AT_LEAST_SIZE(xChangePropertyReq); - UpdateCurrentTime(); - format = stuff->format; - mode = stuff->mode; - if ((mode != PropModeReplace) && (mode != PropModeAppend) && - (mode != PropModePrepend)) - { - client->errorValue = mode; - return BadValue; - } - if ((format != 8) && (format != 16) && (format != 32)) - { - client->errorValue = format; - return BadValue; - } - len = stuff->nUnits; - if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2)) - return BadLength; - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize); - -#ifdef NXAGENT_CLIPBOARD - { - extern WindowPtr nxagentGetClipboardWindow(Atom, WindowPtr); - - pWin = nxagentGetClipboardWindow(stuff->property, NULL); - } - - if (pWin == NULL) -#endif - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if (!ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - -#ifdef XCSECURITY - switch (SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityWriteAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom; - case SecurityIgnoreOperation: - return Success; - } -#endif - -#ifdef NXAGENT_ARTSD - { - /* Do not process MCOPGLOBALS property changes, - they are already set reflecting the server side settings. - Just return success. - */ - extern Atom mcop_local_atom; - if (stuff->property == mcop_local_atom) - return client->noClientException; - } -#endif - -#ifdef LBX - err = LbxChangeWindowProperty(client, pWin, stuff->property, stuff->type, - (int)format, (int)mode, len, TRUE, (pointer)&stuff[1], TRUE, NULL); -#else - err = ChangeWindowProperty(pWin, stuff->property, stuff->type, (int)format, - (int)mode, len, (pointer)&stuff[1], TRUE); -#endif - if (err != Success) - return err; - else - { - if (nxagentOption(Rootless) == 1) - { - nxagentExportProperty(pWin, stuff->property, stuff->type, (int) format, - (int) mode, len, (pointer) &stuff[1]); - } - - nxagentGuessClientHint(client, stuff->property, (char *) &stuff[1]); - - nxagentGuessShadowHint(client, stuff->property); - - return client->noClientException; - } -} - -int -ChangeWindowProperty(pWin, property, type, format, mode, len, value, sendevent) - WindowPtr pWin; - Atom property, type; - int format, mode; - unsigned long len; - pointer value; - Bool sendevent; -{ -#ifdef LBX - return LbxChangeWindowProperty(NULL, pWin, property, type, - format, mode, len, TRUE, value, - sendevent, NULL); -#else - PropertyPtr pProp; - xEvent event; - int sizeInBytes; - int totalSize; - pointer data; - - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - - /* first see if property already exists */ - - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == property) - break; - pProp = pProp->next; - } - if (!pProp) /* just add to list */ - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - return(BadAlloc); - pProp = (PropertyPtr)xalloc(sizeof(PropertyRec)); - if (!pProp) - return(BadAlloc); - data = (pointer)xalloc(totalSize); - if (!data && len) - { - xfree(pProp); - return(BadAlloc); - } - pProp->propertyName = property; - pProp->type = type; - pProp->format = format; - pProp->data = data; - if (len) - memmove((char *)data, (char *)value, totalSize); - pProp->size = len; - pProp->next = pWin->optional->userProps; - pWin->optional->userProps = pProp; - } - else - { - /* To append or prepend to a property the request format and type - must match those of the already defined property. The - existing format and type are irrelevant when using the mode - "PropModeReplace" since they will be written over. */ - - if ((format != pProp->format) && (mode != PropModeReplace)) - return(BadMatch); - if ((pProp->type != type) && (mode != PropModeReplace)) - return(BadMatch); - if (mode == PropModeReplace) - { - if (totalSize != pProp->size * (pProp->format >> 3)) - { - data = (pointer)xrealloc(pProp->data, totalSize); - if (!data && len) - return(BadAlloc); - pProp->data = data; - } - if (len) - memmove((char *)pProp->data, (char *)value, totalSize); - pProp->size = len; - pProp->type = type; - pProp->format = format; - } - else if (len == 0) - { - /* do nothing */ - } - else if (mode == PropModeAppend) - { - data = (pointer)xrealloc(pProp->data, - sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - pProp->data = data; - memmove(&((char *)data)[pProp->size * sizeInBytes], - (char *)value, - totalSize); - pProp->size += len; - } - else if (mode == PropModePrepend) - { - data = (pointer)xalloc(sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - memmove(&((char *)data)[totalSize], (char *)pProp->data, - (int)(pProp->size * sizeInBytes)); - memmove((char *)data, (char *)value, totalSize); - xfree(pProp->data); - pProp->data = data; - pProp->size += len; - } - } - if (sendevent) - { - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - return(Success); -#endif -} - -int -DeleteProperty(pWin, propName) - WindowPtr pWin; - Atom propName; -{ - PropertyPtr pProp, prevProp; - xEvent event; - - if (!(pProp = wUserProps (pWin))) - return(Success); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == propName) - break; - prevProp = pProp; - pProp = pProp->next; - } - if (pProp) - { - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - { - prevProp->next = pProp->next; - } -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - xfree(pProp->data); - xfree(pProp); - } - return(Success); -} - -void -DeleteAllWindowProperties(pWin) - WindowPtr pWin; -{ - PropertyPtr pProp, pNextProp; - xEvent event; - - pProp = wUserProps (pWin); - while (pProp) - { -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - pNextProp = pProp->next; - xfree(pProp->data); - xfree(pProp); - pProp = pNextProp; - } -} - -static int -NullPropertyReply(client, propertyType, format, reply) - ClientPtr client; - ATOM propertyType; - int format; - xGetPropertyReply *reply; -{ - reply->nItems = 0; - reply->length = 0; - reply->bytesAfter = 0; - reply->propertyType = propertyType; - reply->format = format; - WriteReplyToClient(client, sizeof(xGenericReply), reply); - return(client->noClientException); -} - -/***************** - * GetProperty - * If type Any is specified, returns the property from the specified - * window regardless of its type. If a type is specified, returns the - * property only if its type equals the specified type. - * If delete is True and a property is returned, the property is also - * deleted from the window and a PropertyNotify event is generated on the - * window. - *****************/ - -int -ProcGetProperty(client) - ClientPtr client; -{ - PropertyPtr pProp, prevProp; - unsigned long n, len, ind; - WindowPtr pWin; - xGetPropertyReply reply; - REQUEST(xGetPropertyReq); - - REQUEST_SIZE_MATCH(xGetPropertyReq); - if (stuff->delete) - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) - { - client->errorValue = stuff->delete; - return(BadValue); - } - if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - - pProp = wUserProps (pWin); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == stuff->property) - break; - prevProp = pProp; - pProp = pProp->next; - } - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - if (!pProp) - return NullPropertyReply(client, None, 0, &reply); - -#ifdef XCSECURITY - { - Mask access_mode = SecurityReadAccess; - - if (stuff->delete) - access_mode |= SecurityDestroyAccess; - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - access_mode)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return NullPropertyReply(client, pProp->type, pProp->format, - &reply); - } - } -#endif - /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((stuff->type != pProp->type) && - (stuff->type != AnyPropertyType)) - ) - { - reply.bytesAfter = pProp->size; - reply.format = pProp->format; - reply.length = 0; - reply.nItems = 0; - reply.propertyType = pProp->type; - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - return(Success); - } -#ifdef LBX - /* make sure we have the current value */ - if (pProp->tag_id && pProp->owner_pid) { - LbxStallPropRequest(client, pProp); - return client->noClientException; - } -#endif - -/* - * Return type, format, value to client - */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = stuff->longOffset << 2; - - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ - - if (n < ind) - { - client->errorValue = stuff->longOffset; - return BadValue; - } - - len = min(n - ind, 4 * stuff->longLength); - - reply.bytesAfter = n - (ind + len); - reply.format = pProp->format; - reply.length = (len + 3) >> 2; - reply.nItems = len / (pProp->format / 8 ); - reply.propertyType = pProp->type; - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* send the event */ - xEvent event; - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - if (len) - { - switch (reply.format) { - case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break; - case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break; - default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break; - } - WriteSwappedDataToClient(client, len, - (char *)pProp->data + ind); - } - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* delete the Property */ -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - prevProp->next = pProp->next; - xfree(pProp->data); - xfree(pProp); - } - return(client->noClientException); -} - -#ifdef NXAGENT_CLIPBOARD -/* GetWindowProperty clipboard use only */ -int -GetWindowProperty(pWin, property, longOffset, longLength, delete, - type, actualType, format, nItems, bytesAfter, propData ) - WindowPtr pWin; - Atom property; - long longOffset; - long longLength; - Bool delete; - Atom type; - Atom *actualType; - int *format; - unsigned long *nItems; - unsigned long *bytesAfter; - unsigned char **propData; -{ - PropertyPtr pProp, prevProp; - unsigned long n, len, ind; - - if (!pWin) - return BadWindow; - - - if (!ValidAtom(property)) - { - return(BadAtom); - } - if ((type != AnyPropertyType) && !ValidAtom(type)) - { - return(BadAtom); - } - - pProp = wUserProps (pWin); - prevProp = (PropertyPtr)NULL; - - while (pProp) - { - if (pProp->propertyName == property) - break; - prevProp = pProp; - pProp = pProp->next; - } - - - if (!pProp) - return (BadAtom); - - /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((type != pProp->type) && - (type != AnyPropertyType)) - ) - { - *bytesAfter = pProp->size; - *format = pProp->format; - *nItems = 0; - *actualType = pProp->type; - return(Success); - } - -/* - * Return type, format, value to client - */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = longOffset << 2; - - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ - - if (n < ind) - { - return BadValue; - } - - len = min(n - ind, 4 * longLength); - - *bytesAfter = n - (ind + len); - *format = pProp->format; - *nItems = len / (pProp->format / 8 ); - *actualType = pProp->type; - - if (delete && (*bytesAfter == 0)) - { /* send the event */ - xEvent event; - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - - if (len) - { - *propData = (unsigned char *)(pProp->data) + ind; - } - - if (delete && (*bytesAfter == 0)) - { /* delete the Property */ -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - prevProp->next = pProp->next; - xfree(pProp->data); - xfree(pProp); - } - return(Success); -} -#endif - -int -ProcListProperties(client) - ClientPtr client; -{ - Atom *pAtoms = NULL, *temppAtoms; - xListPropertiesReply xlpr; - int numProps = 0; - WindowPtr pWin; - PropertyPtr pProp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pProp = wUserProps (pWin); - while (pProp) - { - pProp = pProp->next; - numProps++; - } - if (numProps) - if(!(pAtoms = (Atom *)ALLOCATE_LOCAL(numProps * sizeof(Atom)))) - return(BadAlloc); - - xlpr.type = X_Reply; - xlpr.nProperties = numProps; - xlpr.length = (numProps * sizeof(Atom)) >> 2; - xlpr.sequenceNumber = client->sequence; - pProp = wUserProps (pWin); - temppAtoms = pAtoms; - while (pProp) - { - *temppAtoms++ = pProp->propertyName; - pProp = pProp->next; - } - WriteReplyToClient(client, sizeof(xGenericReply), &xlpr); - if (numProps) - { - client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write; - WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); - DEALLOCATE_LOCAL(pAtoms); - } - return(client->noClientException); -} - -int -ProcDeleteProperty(client) - register ClientPtr client; -{ - WindowPtr pWin; - REQUEST(xDeletePropertyReq); - int result; - - REQUEST_SIZE_MATCH(xDeletePropertyReq); - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return (BadAtom); - } - -#ifdef XCSECURITY - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityDestroyAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return Success; - } -#endif - - result = DeleteProperty(pWin, stuff->property); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.XF86.original deleted file mode 100644 index ba12faffe..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c.XF86.original +++ /dev/null @@ -1,736 +0,0 @@ -/* $XFree86: xc/programs/Xserver/dix/property.c,v 3.12 2002/02/19 11:09:22 alanh Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: property.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#include "X.h" -#define NEED_REPLIES -#define NEED_EVENTS -#include "Xproto.h" -#include "windowstr.h" -#include "propertyst.h" -#include "dixstruct.h" -#include "dispatch.h" -#include "swaprep.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif -#ifdef LBX -#include "lbxserve.h" -#include "lbxtags.h" -#endif - -#if defined(LBX) || defined(LBX_COMPAT) -int fWriteToClient(ClientPtr client, int len, char *buf) -{ - return WriteToClient(client, len, buf); -} -#endif - -/***************************************************************** - * Property Stuff - * - * ChangeProperty, DeleteProperty, GetProperties, - * ListProperties - * - * Properties below to windows. A allocate slots each time - * a property is added. No fancy searching done. - * - *****************************************************************/ - -#ifdef notdef -static void -PrintPropertys(pWin) - WindowPtr pWin; -{ - PropertyPtr pProp; - register int j; - - pProp = pWin->userProps; - while (pProp) - { - ErrorF( "%x %x\n", pProp->propertyName, pProp->type); - ErrorF("property format: %d\n", pProp->format); - ErrorF("property data: \n"); - for (j=0; j<(pProp->format/8)*pProp->size; j++) - ErrorF("%c\n", pProp->data[j]); - pProp = pProp->next; - } -} -#endif - -int -ProcRotateProperties(client) - ClientPtr client; -{ - int i, j, delta; - REQUEST(xRotatePropertiesReq); - WindowPtr pWin; - register Atom * atoms; - PropertyPtr * props; /* array of pointer */ - PropertyPtr pProp; - xEvent event; - - REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2); - UpdateCurrentTime(); - pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!stuff->nAtoms) - return(Success); - atoms = (Atom *) & stuff[1]; - props = (PropertyPtr *)ALLOCATE_LOCAL(stuff->nAtoms * sizeof(PropertyPtr)); - if (!props) - return(BadAlloc); - for (i = 0; i < stuff->nAtoms; i++) - { -#ifdef XCSECURITY - char action = SecurityCheckPropertyAccess(client, pWin, atoms[i], - SecurityReadAccess|SecurityWriteAccess); -#endif - if (!ValidAtom(atoms[i]) -#ifdef XCSECURITY - || (SecurityErrorOperation == action) -#endif - ) - { - DEALLOCATE_LOCAL(props); - client->errorValue = atoms[i]; - return BadAtom; - } -#ifdef XCSECURITY - if (SecurityIgnoreOperation == action) - { - DEALLOCATE_LOCAL(props); - return Success; - } -#endif - for (j = i + 1; j < stuff->nAtoms; j++) - if (atoms[j] == atoms[i]) - { - DEALLOCATE_LOCAL(props); - return BadMatch; - } - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == atoms[i]) - goto found; - pProp = pProp->next; - } - DEALLOCATE_LOCAL(props); - return BadMatch; -found: - props[i] = pProp; - } - delta = stuff->nPositions; - - /* If the rotation is a complete 360 degrees, then moving the properties - around and generating PropertyNotify events should be skipped. */ - - if ( (stuff->nAtoms != 0) && (abs(delta) % stuff->nAtoms) != 0 ) - { - while (delta < 0) /* faster if abs value is small */ - delta += stuff->nAtoms; - for (i = 0; i < stuff->nAtoms; i++) - { - /* Generate a PropertyNotify event for each property whose value - is changed in the order in which they appear in the request. */ - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = props[i]->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - - props[i]->propertyName = atoms[(i + delta) % stuff->nAtoms]; - } - } - DEALLOCATE_LOCAL(props); - return Success; -} - -int -ProcChangeProperty(client) - ClientPtr client; -{ - WindowPtr pWin; - char format, mode; - unsigned long len; - int sizeInBytes; - int totalSize; - int err; - REQUEST(xChangePropertyReq); - - REQUEST_AT_LEAST_SIZE(xChangePropertyReq); - UpdateCurrentTime(); - format = stuff->format; - mode = stuff->mode; - if ((mode != PropModeReplace) && (mode != PropModeAppend) && - (mode != PropModePrepend)) - { - client->errorValue = mode; - return BadValue; - } - if ((format != 8) && (format != 16) && (format != 32)) - { - client->errorValue = format; - return BadValue; - } - len = stuff->nUnits; - if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2)) - return BadLength; - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize); - - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if (!ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - -#ifdef XCSECURITY - switch (SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityWriteAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom; - case SecurityIgnoreOperation: - return Success; - } -#endif - -#ifdef LBX - err = LbxChangeWindowProperty(client, pWin, stuff->property, stuff->type, - (int)format, (int)mode, len, TRUE, (pointer)&stuff[1], TRUE, NULL); -#else - err = ChangeWindowProperty(pWin, stuff->property, stuff->type, (int)format, - (int)mode, len, (pointer)&stuff[1], TRUE); -#endif - if (err != Success) - return err; - else - return client->noClientException; -} - -int -ChangeWindowProperty(pWin, property, type, format, mode, len, value, sendevent) - WindowPtr pWin; - Atom property, type; - int format, mode; - unsigned long len; - pointer value; - Bool sendevent; -{ -#ifdef LBX - return LbxChangeWindowProperty(NULL, pWin, property, type, - format, mode, len, TRUE, value, - sendevent, NULL); -#else - PropertyPtr pProp; - xEvent event; - int sizeInBytes; - int totalSize; - pointer data; - - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - - /* first see if property already exists */ - - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == property) - break; - pProp = pProp->next; - } - if (!pProp) /* just add to list */ - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - return(BadAlloc); - pProp = (PropertyPtr)xalloc(sizeof(PropertyRec)); - if (!pProp) - return(BadAlloc); - data = (pointer)xalloc(totalSize); - if (!data && len) - { - xfree(pProp); - return(BadAlloc); - } - pProp->propertyName = property; - pProp->type = type; - pProp->format = format; - pProp->data = data; - if (len) - memmove((char *)data, (char *)value, totalSize); - pProp->size = len; - pProp->next = pWin->optional->userProps; - pWin->optional->userProps = pProp; - } - else - { - /* To append or prepend to a property the request format and type - must match those of the already defined property. The - existing format and type are irrelevant when using the mode - "PropModeReplace" since they will be written over. */ - - if ((format != pProp->format) && (mode != PropModeReplace)) - return(BadMatch); - if ((pProp->type != type) && (mode != PropModeReplace)) - return(BadMatch); - if (mode == PropModeReplace) - { - if (totalSize != pProp->size * (pProp->format >> 3)) - { - data = (pointer)xrealloc(pProp->data, totalSize); - if (!data && len) - return(BadAlloc); - pProp->data = data; - } - if (len) - memmove((char *)pProp->data, (char *)value, totalSize); - pProp->size = len; - pProp->type = type; - pProp->format = format; - } - else if (len == 0) - { - /* do nothing */ - } - else if (mode == PropModeAppend) - { - data = (pointer)xrealloc(pProp->data, - sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - pProp->data = data; - memmove(&((char *)data)[pProp->size * sizeInBytes], - (char *)value, - totalSize); - pProp->size += len; - } - else if (mode == PropModePrepend) - { - data = (pointer)xalloc(sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - memmove(&((char *)data)[totalSize], (char *)pProp->data, - (int)(pProp->size * sizeInBytes)); - memmove((char *)data, (char *)value, totalSize); - xfree(pProp->data); - pProp->data = data; - pProp->size += len; - } - } - if (sendevent) - { - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - return(Success); -#endif -} - -int -DeleteProperty(pWin, propName) - WindowPtr pWin; - Atom propName; -{ - PropertyPtr pProp, prevProp; - xEvent event; - - if (!(pProp = wUserProps (pWin))) - return(Success); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == propName) - break; - prevProp = pProp; - pProp = pProp->next; - } - if (pProp) - { - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - { - prevProp->next = pProp->next; - } -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - xfree(pProp->data); - xfree(pProp); - } - return(Success); -} - -void -DeleteAllWindowProperties(pWin) - WindowPtr pWin; -{ - PropertyPtr pProp, pNextProp; - xEvent event; - - pProp = wUserProps (pWin); - while (pProp) - { -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - pNextProp = pProp->next; - xfree(pProp->data); - xfree(pProp); - pProp = pNextProp; - } -} - -static int -NullPropertyReply(client, propertyType, format, reply) - ClientPtr client; - ATOM propertyType; - int format; - xGetPropertyReply *reply; -{ - reply->nItems = 0; - reply->length = 0; - reply->bytesAfter = 0; - reply->propertyType = propertyType; - reply->format = format; - WriteReplyToClient(client, sizeof(xGenericReply), reply); - return(client->noClientException); -} - -/***************** - * GetProperty - * If type Any is specified, returns the property from the specified - * window regardless of its type. If a type is specified, returns the - * property only if its type equals the specified type. - * If delete is True and a property is returned, the property is also - * deleted from the window and a PropertyNotify event is generated on the - * window. - *****************/ - -int -ProcGetProperty(client) - ClientPtr client; -{ - PropertyPtr pProp, prevProp; - unsigned long n, len, ind; - WindowPtr pWin; - xGetPropertyReply reply; - REQUEST(xGetPropertyReq); - - REQUEST_SIZE_MATCH(xGetPropertyReq); - if (stuff->delete) - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) - { - client->errorValue = stuff->delete; - return(BadValue); - } - if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - - pProp = wUserProps (pWin); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == stuff->property) - break; - prevProp = pProp; - pProp = pProp->next; - } - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - if (!pProp) - return NullPropertyReply(client, None, 0, &reply); - -#ifdef XCSECURITY - { - Mask access_mode = SecurityReadAccess; - - if (stuff->delete) - access_mode |= SecurityDestroyAccess; - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - access_mode)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return NullPropertyReply(client, pProp->type, pProp->format, - &reply); - } - } -#endif - /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((stuff->type != pProp->type) && - (stuff->type != AnyPropertyType)) - ) - { - reply.bytesAfter = pProp->size; - reply.format = pProp->format; - reply.length = 0; - reply.nItems = 0; - reply.propertyType = pProp->type; - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - return(Success); - } -#ifdef LBX - /* make sure we have the current value */ - if (pProp->tag_id && pProp->owner_pid) { - LbxStallPropRequest(client, pProp); - return client->noClientException; - } -#endif - -/* - * Return type, format, value to client - */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = stuff->longOffset << 2; - - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ - - if (n < ind) - { - client->errorValue = stuff->longOffset; - return BadValue; - } - - len = min(n - ind, 4 * stuff->longLength); - - reply.bytesAfter = n - (ind + len); - reply.format = pProp->format; - reply.length = (len + 3) >> 2; - reply.nItems = len / (pProp->format / 8 ); - reply.propertyType = pProp->type; - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* send the event */ - xEvent event; - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - if (len) - { - switch (reply.format) { - case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break; - case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break; - default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break; - } - WriteSwappedDataToClient(client, len, - (char *)pProp->data + ind); - } - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* delete the Property */ -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - prevProp->next = pProp->next; - xfree(pProp->data); - xfree(pProp); - } - return(client->noClientException); -} - -int -ProcListProperties(client) - ClientPtr client; -{ - Atom *pAtoms = NULL, *temppAtoms; - xListPropertiesReply xlpr; - int numProps = 0; - WindowPtr pWin; - PropertyPtr pProp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pProp = wUserProps (pWin); - while (pProp) - { - pProp = pProp->next; - numProps++; - } - if (numProps) - if(!(pAtoms = (Atom *)ALLOCATE_LOCAL(numProps * sizeof(Atom)))) - return(BadAlloc); - - xlpr.type = X_Reply; - xlpr.nProperties = numProps; - xlpr.length = (numProps * sizeof(Atom)) >> 2; - xlpr.sequenceNumber = client->sequence; - pProp = wUserProps (pWin); - temppAtoms = pAtoms; - while (pProp) - { - *temppAtoms++ = pProp->propertyName; - pProp = pProp->next; - } - WriteReplyToClient(client, sizeof(xGenericReply), &xlpr); - if (numProps) - { - client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write; - WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); - DEALLOCATE_LOCAL(pAtoms); - } - return(client->noClientException); -} - -int -ProcDeleteProperty(client) - register ClientPtr client; -{ - WindowPtr pWin; - REQUEST(xDeletePropertyReq); - int result; - - REQUEST_SIZE_MATCH(xDeletePropertyReq); - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return (BadAtom); - } - -#ifdef XCSECURITY - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityDestroyAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return Success; - } -#endif - - result = DeleteProperty(pWin, stuff->property); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXrender.c.NX.original deleted file mode 100644 index 43607ac08..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c.NX.original +++ /dev/null @@ -1,3048 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXrender.c" - -#else - -/* - * $XFree86: xc/programs/Xserver/render/render.c,v 1.26 2003/02/14 18:15:21 dawes Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#define NEED_REPLIES -#define NEED_EVENTS -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "colormapst.h" -#include "extnsionst.h" -#include "servermd.h" -#include "render.h" -#include "renderproto.h" -#include "Xfuncproto.h" -#include "cursorstr.h" -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#include "NXpicturestr.h" -#include "NXglyphstr.h" - -#include "Trap.h" - -#include "Render.h" -#include "Pixmaps.h" -#include "Options.h" -#include "Screen.h" - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -/* - * From NXmiglyph.c. - */ - -void miGlyphExtents(int nlist, GlyphListPtr list, - GlyphPtr *glyphs, BoxPtr extents); - -/* - * Functions from Render.c. - */ - -int nxagentCursorSaveRenderInfo(ScreenPtr, CursorPtr); -void nxagentCursorPostSaveRenderInfo(CursorPtr, ScreenPtr, PicturePtr, int, int); -int nxagentRenderRealizeCursor(ScreenPtr, CursorPtr); -int nxagentCreatePicture(PicturePtr, Mask); -void nxagentDestroyPicture(PicturePtr pPicture); -void nxagentChangePicture(PicturePtr, Mask); -int nxagentChangePictureClip(PicturePtr, int, int, xRectangle *, int, int); -void nxagentComposite(CARD8, PicturePtr, PicturePtr, PicturePtr, INT16, INT16, - INT16, INT16, INT16, INT16, CARD16, CARD16); -void nxagentCompositeRects(CARD8, PicturePtr, xRenderColor *, int, xRectangle *); -void nxagentCreateGlyphSet(GlyphSetPtr glyphSet); -void nxagentReferenceGlyphSet(GlyphSetPtr glyphSet); -void nxagentFreeGlyphs(GlyphSetPtr glyphSet, CARD32 *gids, int nglyph); -void nxagentFreeGlyphSet(GlyphSetPtr glyphSet); -void nxagentSetPictureTransform(PicturePtr pPicture, pointer transform); -void nxagentSetPictureFilter(PicturePtr pPicture, char *filter, int name_size, - pointer params, int nparams); -void nxagentTrapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst, PictFormatPtr maskFormat, - INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid *traps); - -/* - * The void pointer is actually a XGlyphElt8. - */ - -void nxagentGlyphs(CARD8, PicturePtr, PicturePtr, PictFormatPtr, - INT16, INT16, int, void *, int, GlyphPtr *); - -static int ProcRenderQueryVersion (ClientPtr pClient); -static int ProcRenderQueryPictFormats (ClientPtr pClient); -static int ProcRenderQueryPictIndexValues (ClientPtr pClient); -static int ProcRenderQueryDithers (ClientPtr pClient); -static int ProcRenderCreatePicture (ClientPtr pClient); -static int ProcRenderChangePicture (ClientPtr pClient); -static int ProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int ProcRenderFreePicture (ClientPtr pClient); -static int ProcRenderComposite (ClientPtr pClient); -static int ProcRenderScale (ClientPtr pClient); -static int ProcRenderTrapezoids (ClientPtr pClient); -static int ProcRenderTriangles (ClientPtr pClient); -static int ProcRenderTriStrip (ClientPtr pClient); -static int ProcRenderTriFan (ClientPtr pClient); -static int ProcRenderColorTrapezoids (ClientPtr pClient); -static int ProcRenderColorTriangles (ClientPtr pClient); -static int ProcRenderTransform (ClientPtr pClient); -static int ProcRenderCreateGlyphSet (ClientPtr pClient); -static int ProcRenderReferenceGlyphSet (ClientPtr pClient); -static int ProcRenderFreeGlyphSet (ClientPtr pClient); -static int ProcRenderAddGlyphs (ClientPtr pClient); -static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int ProcRenderFreeGlyphs (ClientPtr pClient); -static int ProcRenderCompositeGlyphs (ClientPtr pClient); -static int ProcRenderFillRectangles (ClientPtr pClient); -static int ProcRenderCreateCursor (ClientPtr pClient); -static int ProcRenderSetPictureTransform (ClientPtr pClient); -static int ProcRenderQueryFilters (ClientPtr pClient); -static int ProcRenderSetPictureFilter (ClientPtr pClient); -static int ProcRenderCreateAnimCursor (ClientPtr pClient); - -static int ProcRenderDispatch (ClientPtr pClient); - -static int SProcRenderQueryVersion (ClientPtr pClient); -static int SProcRenderQueryPictFormats (ClientPtr pClient); -static int SProcRenderQueryPictIndexValues (ClientPtr pClient); -static int SProcRenderQueryDithers (ClientPtr pClient); -static int SProcRenderCreatePicture (ClientPtr pClient); -static int SProcRenderChangePicture (ClientPtr pClient); -static int SProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int SProcRenderFreePicture (ClientPtr pClient); -static int SProcRenderComposite (ClientPtr pClient); -static int SProcRenderScale (ClientPtr pClient); -static int SProcRenderTrapezoids (ClientPtr pClient); -static int SProcRenderTriangles (ClientPtr pClient); -static int SProcRenderTriStrip (ClientPtr pClient); -static int SProcRenderTriFan (ClientPtr pClient); -static int SProcRenderColorTrapezoids (ClientPtr pClient); -static int SProcRenderColorTriangles (ClientPtr pClient); -static int SProcRenderTransform (ClientPtr pClient); -static int SProcRenderCreateGlyphSet (ClientPtr pClient); -static int SProcRenderReferenceGlyphSet (ClientPtr pClient); -static int SProcRenderFreeGlyphSet (ClientPtr pClient); -static int SProcRenderAddGlyphs (ClientPtr pClient); -static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int SProcRenderFreeGlyphs (ClientPtr pClient); -static int SProcRenderCompositeGlyphs (ClientPtr pClient); -static int SProcRenderFillRectangles (ClientPtr pClient); -static int SProcRenderCreateCursor (ClientPtr pClient); -static int SProcRenderSetPictureTransform (ClientPtr pClient); -static int SProcRenderQueryFilters (ClientPtr pClient); -static int SProcRenderSetPictureFilter (ClientPtr pClient); -static int SProcRenderCreateAnimCursor (ClientPtr pClient); - -static int SProcRenderDispatch (ClientPtr pClient); - -int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = { - ProcRenderQueryVersion, - ProcRenderQueryPictFormats, - ProcRenderQueryPictIndexValues, - ProcRenderQueryDithers, - ProcRenderCreatePicture, - ProcRenderChangePicture, - ProcRenderSetPictureClipRectangles, - ProcRenderFreePicture, - ProcRenderComposite, - ProcRenderScale, - ProcRenderTrapezoids, - ProcRenderTriangles, - ProcRenderTriStrip, - ProcRenderTriFan, - ProcRenderColorTrapezoids, - ProcRenderColorTriangles, - ProcRenderTransform, - ProcRenderCreateGlyphSet, - ProcRenderReferenceGlyphSet, - ProcRenderFreeGlyphSet, - ProcRenderAddGlyphs, - ProcRenderAddGlyphsFromPicture, - ProcRenderFreeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderFillRectangles, - ProcRenderCreateCursor, - ProcRenderSetPictureTransform, - ProcRenderQueryFilters, - ProcRenderSetPictureFilter, - ProcRenderCreateAnimCursor, -}; - -int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = { - SProcRenderQueryVersion, - SProcRenderQueryPictFormats, - SProcRenderQueryPictIndexValues, - SProcRenderQueryDithers, - SProcRenderCreatePicture, - SProcRenderChangePicture, - SProcRenderSetPictureClipRectangles, - SProcRenderFreePicture, - SProcRenderComposite, - SProcRenderScale, - SProcRenderTrapezoids, - SProcRenderTriangles, - SProcRenderTriStrip, - SProcRenderTriFan, - SProcRenderColorTrapezoids, - SProcRenderColorTriangles, - SProcRenderTransform, - SProcRenderCreateGlyphSet, - SProcRenderReferenceGlyphSet, - SProcRenderFreeGlyphSet, - SProcRenderAddGlyphs, - SProcRenderAddGlyphsFromPicture, - SProcRenderFreeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderFillRectangles, - SProcRenderCreateCursor, - SProcRenderSetPictureTransform, - SProcRenderQueryFilters, - SProcRenderSetPictureFilter, - SProcRenderCreateAnimCursor, -}; - -static void -RenderResetProc (ExtensionEntry *extEntry); - -static CARD8 RenderReqCode; -int RenderErrBase; -int RenderClientPrivateIndex; - -typedef struct _RenderClient { - int major_version; - int minor_version; -} RenderClientRec, *RenderClientPtr; - -#define GetRenderClient(pClient) ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr) - -static void -RenderClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - RenderClientPtr pRenderClient = GetRenderClient (pClient); - - pRenderClient->major_version = 0; - pRenderClient->minor_version = 0; -} - -void -RenderExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (!PictureType) - return; - if (!PictureFinishInit ()) - return; - RenderClientPrivateIndex = AllocateClientPrivateIndex (); - if (!AllocateClientPrivate (RenderClientPrivateIndex, - sizeof (RenderClientRec))) - return; - if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0)) - return; - - extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors, - ProcRenderDispatch, SProcRenderDispatch, - RenderResetProc, StandardMinorOpcode); - if (!extEntry) - return; - RenderReqCode = (CARD8) extEntry->base; - RenderErrBase = extEntry->errorBase; -} - -static void -RenderResetProc (ExtensionEntry *extEntry) -{ -} - -static int -ProcRenderQueryVersion (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryVersionReply rep; - register int n; - REQUEST(xRenderQueryVersionReq); - - pRenderClient->major_version = stuff->majorVersion; - pRenderClient->minor_version = stuff->minorVersion; - - REQUEST_SIZE_MATCH(xRenderQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = nxagentRenderVersionMajor; - rep.minorVersion = nxagentRenderVersionMinor; - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.majorVersion, n); - swapl(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -#if 0 -static int -VisualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - DepthPtr pDepth; - int d, v; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - for (v = 0; v < pDepth->numVids; v++) - { - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - } - return 0; -} -#endif - -static VisualPtr -findVisual (ScreenPtr pScreen, VisualID vid) -{ - VisualPtr pVisual; - int v; - - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = pScreen->visuals + v; - if (pVisual->vid == vid) - return pVisual; - } - return 0; -} - -extern char *ConnectionInfo; - -static int -ProcRenderQueryPictFormats (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryPictFormatsReply *reply; - xPictScreen *pictScreen; - xPictDepth *pictDepth; - xPictVisual *pictVisual; - xPictFormInfo *pictForm; - CARD32 *pictSubpixel; - ScreenPtr pScreen; - VisualPtr pVisual; - DepthPtr pDepth; - int v, d; - PictureScreenPtr ps; - PictFormatPtr pFormat; - int nformat; - int ndepth; - int nvisual; - int rlength; - int s; - int n; - int numScreens; - int numSubpixel; - - extern int nxagentAlphaEnabled; -/* REQUEST(xRenderQueryPictFormatsReq); */ - - REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq); - -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#else - numScreens = screenInfo.numScreens; -#endif - ndepth = nformat = nvisual = 0; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - ++ndepth; - - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual)) - ++nvisual; - } - } - ps = GetPictureScreenIfSet(pScreen); - if (ps) - nformat += ps->nformats; - } - if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6) - numSubpixel = 0; - else - numSubpixel = numScreens; - - rlength = (sizeof (xRenderQueryPictFormatsReply) + - nformat * sizeof (xPictFormInfo) + - numScreens * sizeof (xPictScreen) + - ndepth * sizeof (xPictDepth) + - nvisual * sizeof (xPictVisual) + - numSubpixel * sizeof (CARD32)); - reply = (xRenderQueryPictFormatsReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numFormats = nformat; - reply->numScreens = numScreens; - reply->numDepths = ndepth; - reply->numVisuals = nvisual; - reply->numSubpixel = numSubpixel; - - pictForm = (xPictFormInfo *) (reply + 1); - - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (nformat = 0, pFormat = ps->formats; - nformat < ps->nformats; - nformat++, pFormat++) - { - pictForm->id = pFormat->id; - pictForm->type = pFormat->type; - pictForm->depth = pFormat->depth; - pictForm->direct.red = pFormat->direct.red; - pictForm->direct.redMask = pFormat->direct.redMask; - pictForm->direct.green = pFormat->direct.green; - pictForm->direct.greenMask = pFormat->direct.greenMask; - pictForm->direct.blue = pFormat->direct.blue; - pictForm->direct.blueMask = pFormat->direct.blueMask; - pictForm->direct.alpha = nxagentAlphaEnabled ? pFormat->direct.alpha : 0; - pictForm->direct.alphaMask = pFormat->direct.alphaMask; - if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap) - pictForm->colormap = pFormat->index.pColormap->mid; - else - pictForm->colormap = None; - if (client->swapped) - { - swapl (&pictForm->id, n); - swaps (&pictForm->direct.red, n); - swaps (&pictForm->direct.redMask, n); - swaps (&pictForm->direct.green, n); - swaps (&pictForm->direct.greenMask, n); - swaps (&pictForm->direct.blue, n); - swaps (&pictForm->direct.blueMask, n); - swaps (&pictForm->direct.alpha, n); - swaps (&pictForm->direct.alphaMask, n); - swapl (&pictForm->colormap, n); - } - pictForm++; - } - } - } - - pictScreen = (xPictScreen *) pictForm; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - pictDepth = (xPictDepth *) (pictScreen + 1); - ndepth = 0; - for (d = 0; d < pScreen->numDepths; d++) - { - pictVisual = (xPictVisual *) (pictDepth + 1); - pDepth = pScreen->allowedDepths + d; - - nvisual = 0; - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && (pFormat = PictureMatchVisual (pScreen, - pDepth->depth, - pVisual))) - { - pictVisual->visual = pVisual->vid; - pictVisual->format = pFormat->id; - if (client->swapped) - { - swapl (&pictVisual->visual, n); - swapl (&pictVisual->format, n); - } - pictVisual++; - nvisual++; - } - } - pictDepth->depth = pDepth->depth; - pictDepth->nPictVisuals = nvisual; - if (client->swapped) - { - swaps (&pictDepth->nPictVisuals, n); - } - ndepth++; - pictDepth = (xPictDepth *) pictVisual; - } - pictScreen->nDepth = ndepth; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - pictScreen->fallback = ps->fallback->id; - else - pictScreen->fallback = 0; - if (client->swapped) - { - swapl (&pictScreen->nDepth, n); - swapl (&pictScreen->fallback, n); - } - pictScreen = (xPictScreen *) pictDepth; - } - pictSubpixel = (CARD32 *) pictScreen; - - for (s = 0; s < numSubpixel; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - *pictSubpixel = ps->subpixel; - else - *pictSubpixel = SubPixelUnknown; - if (client->swapped) - { - swapl (pictSubpixel, n); - } - ++pictSubpixel; - } - - if (client->swapped) - { - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numFormats, n); - swapl (&reply->numScreens, n); - swapl (&reply->numDepths, n); - swapl (&reply->numVisuals, n); - swapl (&reply->numSubpixel, n); - } - WriteToClient(client, rlength, (char *) reply); - xfree (reply); - return client->noClientException; -} - -static int -ProcRenderQueryPictIndexValues (ClientPtr client) -{ - PictFormatPtr pFormat; - int num; - int rlength; - int i, n; - REQUEST(xRenderQueryPictIndexValuesReq); - xRenderQueryPictIndexValuesReply *reply; - xIndexValue *values; - - REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq); - - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->type != PictTypeIndexed) - { - client->errorValue = stuff->format; - return BadMatch; - } - num = pFormat->index.nvalues; - rlength = (sizeof (xRenderQueryPictIndexValuesReply) + - num * sizeof(xIndexValue)); - reply = (xRenderQueryPictIndexValuesReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numIndexValues = num; - - values = (xIndexValue *) (reply + 1); - - memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue)); - - if (client->swapped) - { - for (i = 0; i < num; i++) - { - swapl (&values[i].pixel, n); - swaps (&values[i].red, n); - swaps (&values[i].green, n); - swaps (&values[i].blue, n); - swaps (&values[i].alpha, n); - } - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numIndexValues, n); - } - - WriteToClient(client, rlength, (char *) reply); - xfree(reply); - return (client->noClientException); -} - -static int -ProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreatePicture (ClientPtr client) -{ - PicturePtr pPicture; - DrawablePtr pDrawable; - PictFormatPtr pFormat; - int len; - int error; - REQUEST(xRenderCreatePictureReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, - SecurityWriteAccess); - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->depth != pDrawable->depth) - return BadMatch; - len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - pPicture = CreatePicture (stuff->pid, - pDrawable, - pFormat, - stuff->mask, - (XID *) (stuff + 1), - client, - &error); - if (!pPicture) - return error; - nxagentCreatePicture(pPicture, stuff -> mask); - - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int -ProcRenderChangePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderChangePictureReq); - int len; - int error; - - REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - error = ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1), - (DevUnion *) 0, client); - - nxagentChangePicture(pPicture, stuff->mask); - - return error; -} - -static int -ProcRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - PicturePtr pPicture; - int nr; - int result; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - /* - * The original code used sizeof(xRenderChangePictureReq). - * This was harmless, as both structures have the same size. - * - * nr = (client->req_len << 2) - sizeof(xRenderChangePictureReq); - */ - nr = (client->req_len << 2) - sizeof(xRenderSetPictureClipRectanglesReq); - if (nr & 4) - return BadLength; - nr >>= 3; - result = SetPictureClipRects (pPicture, - stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *) &stuff[1]); - nxagentChangePictureClip (pPicture, - CT_NONE, - nr, - (xRectangle *) &stuff[1], - (int)stuff -> xOrigin, - (int)stuff -> yOrigin); - - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderFreePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - - nxagentDestroyPicture(pPicture); - - FreeResource (stuff->picture, RT_NONE); - return(client->noClientException); -} - -static Bool -PictOpValid (CARD8 op) -{ - if (/*PictOpMinimum <= op && */ op <= PictOpMaximum) - return TRUE; - if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum) - return TRUE; - if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum) - return TRUE; - return FALSE; -} - -/* - * Check if both pictures have drawables which are - * virtual pixmaps. See the corresponding define - * in NXpicture.c - */ - -#define NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - -#ifdef NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - -#define nxagentCompositePredicate(pSrc, pDst) TRUE - -#else - -/* - * This is still under development. The final - * goal is to let pictures point to the real - * pixmaps instead of pointing to virtuals. - */ - -int nxagentCompositePredicate(PicturePtr pSrc, PicturePtr pDst) -{ - PixmapPtr pPixmap1; - PixmapPtr pPixmap2; - - pPixmap1 = (pSrc -> pDrawable -> type == DRAWABLE_PIXMAP ? - ((PixmapPtr) pSrc -> pDrawable) : NULL); - - pPixmap2 = (pDst -> pDrawable -> type == DRAWABLE_PIXMAP ? - ((PixmapPtr) pDst -> pDrawable) : NULL); - - if (pPixmap1 == NULL || pPixmap2 == NULL) - { - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 0.\n"); - #endif - - return FALSE; - } - else - { - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 1.\n"); - #endif - - if (nxagentPixmapIsVirtual(pPixmap1) == 1 && - nxagentPixmapIsVirtual(pPixmap2) == 1) - { - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 2.\n"); - #endif - - return TRUE; - } - } - - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 3.\n"); - #endif - - return FALSE; -} - -#endif - -static int -ProcRenderComposite (ClientPtr client) -{ - PicturePtr pSrc, pMask, pDst; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_ALPHA (pMask, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen || - (pMask && pSrc->pDrawable->pScreen != pMask->pDrawable->pScreen)) - return BadMatch; - - ValidatePicture (pSrc); - if (pMask) - ValidatePicture (pMask); - ValidatePicture (pDst); - - #ifdef NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - - if (nxagentCompositePredicate(pSrc, pDst)) - { - #ifdef TEST - fprintf(stderr, "ProcRenderComposite: Going to composite with " - "source at [%p] mask at [%p] and destination at [%p].\n", - (void *) pSrc, (void *) pMask, (void *) pDst); - #endif - - CompositePicture (stuff->op, - pSrc, - pMask, - pDst, - stuff->xSrc, - stuff->ySrc, - stuff->xMask, - stuff->yMask, - stuff->xDst, - stuff->yDst, - stuff->width, - stuff->height); - } - - #else - - if (pSrc -> pDrawable -> type == DRAWABLE_PIXMAP && - pDst -> pDrawable -> type == DRAWABLE_PIXMAP && - (!pMask || pMask -> pDrawable -> type == DRAWABLE_PIXMAP)) - { - PixmapPtr pVirtualPixmapSrc; - PixmapPtr pVirtualPixmapDst; - PixmapPtr pVirtualPixmapMask; - - PicturePtr pVirtualPictureSrc; - PicturePtr pVirtualPictureDst; - PicturePtr pVirtualPictureMask; - - pVirtualPixmapSrc = (PixmapPtr) pSrc -> pDrawable; - pVirtualPictureSrc = nxagentPixmapPriv(pVirtualPixmapSrc) -> pPicture; - - pVirtualPixmapDst = (PixmapPtr) pDst -> pDrawable; - pVirtualPictureDst = nxagentPixmapPriv(pVirtualPixmapDst) -> pPicture; - - if (pMask) - { - pVirtualPixmapMask = (PixmapPtr) pMask -> pDrawable; - pVirtualPictureMask = nxagentPixmapPriv(pVirtualPixmapMask) -> pPicture; - } - else - { - pVirtualPixmapMask = NULL; - pVirtualPictureMask = NULL; - } - - if (pVirtualPictureSrc && pVirtualPictureDst) - { - #ifdef TEST - fprintf(stderr, "ProcRenderComposite: Going to composite with " - "source at [%p] mask at [%p] and destination at [%p].\n", - (void *) pVirtualPixmapSrc, (void *) pVirtualPixmapMask, - (void *) pVirtualPixmapDst); - #endif - - CompositePicture (stuff->op, - pVirtualPictureSrc, - pVirtualPictureMask, - pVirtualPictureDst, - stuff->xSrc, - stuff->ySrc, - stuff->xMask, - stuff->yMask, - stuff->xDst, - stuff->yDst, - stuff->width, - stuff->height); - } - } - - #endif - - nxagentComposite (stuff -> op, - pSrc, - pMask, - pDst, - stuff -> xSrc, - stuff -> ySrc, - stuff -> xMask, - stuff -> yMask, - stuff -> xDst, - stuff -> yDst, - stuff -> width, - stuff -> height); - - return Success; -} - -static int -ProcRenderScale (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTrapezoids (ClientPtr client) -{ - int ntraps; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); - if (ntraps % sizeof (xTrapezoid)) - return BadLength; - ntraps /= sizeof (xTrapezoid); - if (ntraps) - { - if (nxagentCompositePredicate(pSrc, pDst)) - { - CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntraps, (xTrapezoid *) &stuff[1]); - } - - nxagentTrapezoids (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntraps, (xTrapezoid *) &stuff[1]); - } - - return client->noClientException; -} - -static int -ProcRenderTriangles (ClientPtr client) -{ - int ntris; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq); - if (ntris % sizeof (xTriangle)) - return BadLength; - ntris /= sizeof (xTriangle); - if (ntris) - CompositeTriangles (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntris, (xTriangle *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriStrip (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriStrip (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriFan (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriFan (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreateGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - PictFormatPtr format; - int f; - REQUEST(xRenderCreateGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - format = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!format) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - switch (format->depth) { - case 1: - f = GlyphFormat1; - break; - case 4: - f = GlyphFormat4; - break; - case 8: - f = GlyphFormat8; - break; - case 16: - f = GlyphFormat16; - break; - case 32: - f = GlyphFormat32; - break; - default: - return BadMatch; - } - if (format->type != PictTypeDirect) - return BadMatch; - glyphSet = AllocateGlyphSet (f, format); - if (!glyphSet) - return BadAlloc; - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - - nxagentCreateGlyphSet(glyphSet); - - return Success; -} - -static int -ProcRenderReferenceGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderReferenceGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->existing, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->existing; - return RenderErrBase + BadGlyphSet; - } - glyphSet->refcnt++; - - nxagentReferenceGlyphSet(glyphSet); - - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - return client->noClientException; -} - -#define NLOCALDELTA 64 -#define NLOCALGLYPH 256 - -static int -ProcRenderFreeGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderFreeGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityDestroyAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - nxagentFreeGlyphSet(glyphSet); - - FreeResource (stuff->glyphset, RT_NONE); - return client->noClientException; -} - -typedef struct _GlyphNew { - Glyph id; - GlyphPtr glyph; -} GlyphNewRec, *GlyphNewPtr; - -static int -ProcRenderAddGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderAddGlyphsReq); - GlyphNewRec glyphsLocal[NLOCALGLYPH]; - GlyphNewPtr glyphsBase, glyphs; - GlyphPtr glyph = NULL; - int remain, nglyphs; - CARD32 *gids; - xGlyphInfo *gi; - CARD8 *bits; - int size; - int err = BadAlloc; - - int totSizeImages; - - REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - nglyphs = stuff->nglyphs; - if (nglyphs <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphNewPtr) ALLOCATE_LOCAL (nglyphs * sizeof (GlyphNewRec)); - if (!glyphsBase) - return BadAlloc; - } - - remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq); - - glyphs = glyphsBase; - - totSizeImages = 0; - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + nglyphs); - bits = (CARD8 *) (gi + nglyphs); - remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs; - - while (remain >= 0 && nglyphs) - { - glyph = AllocateGlyph (gi, glyphSet->fdepth); - if (!glyph) - { - err = BadAlloc; - goto bail; - } - - glyphs->glyph = glyph; - glyphs->id = *gids; - - size = glyph->size - sizeof (xGlyphInfo); - if (remain < size) - break; - memcpy ((CARD8 *) (glyph + 1), bits, size); - - if (size & 3) - size += 4 - (size & 3); - bits += size; - totSizeImages += size; - remain -= size; - gi++; - gids++; - glyphs++; - nglyphs--; - } - - if (nglyphs || remain) - { - err = BadLength; - goto bail; - } - nglyphs = stuff->nglyphs; - if (!ResizeGlyphSet (glyphSet, nglyphs)) - { - err = BadAlloc; - goto bail; - } - glyphs = glyphsBase; - while (nglyphs--) - AddGlyph (glyphSet, glyphs->glyph, glyphs->id); - - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - return client->noClientException; -bail: - while (glyphs != glyphsBase) - { - --glyphs; - xfree (glyphs->glyph); - } - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - return err; -} - -static int -ProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderFreeGlyphs (ClientPtr client) -{ - REQUEST(xRenderFreeGlyphsReq); - GlyphSetPtr glyphSet; - int nglyph; - CARD32 *gids; - CARD32 glyph; - - REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2; - gids = (CARD32 *) (stuff + 1); - - nxagentFreeGlyphs(glyphSet, gids, nglyph); - - while (nglyph-- > 0) - { - glyph = *gids++; - if (!DeleteGlyph (glyphSet, glyph)) - { - client->errorValue = glyph; - return RenderErrBase + BadGlyph; - } - } - return client->noClientException; -} - -typedef struct XGlyphElt8{ - GlyphSet glyphset; - _Xconst char *chars; - int nchars; - int xOff; - int yOff; -} XGlyphElt8; - -static int -ProcRenderCompositeGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - GlyphSet gs; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - GlyphListRec listsLocal[NLOCALDELTA]; - GlyphListPtr lists, listsBase; - GlyphPtr glyphsLocal[NLOCALGLYPH]; - Glyph glyph; - GlyphPtr *glyphs, *glyphsBase; - xGlyphElt *elt; - CARD8 *buffer, *end; - int nglyph; - int nlist; - int space; - int size; - int n; - - XGlyphElt8 *elements, *elementsBase; - - REQUEST(xRenderCompositeGlyphsReq); - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - nglyph = 0; - nlist = 0; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - buffer += 4; - } - else - { - nlist++; - nglyph += elt->len; - space = size * elt->len; - if (space & 3) - space += 4 - (space & 3); - buffer += space; - } - } - if (nglyph <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphPtr *) ALLOCATE_LOCAL (nglyph * sizeof (GlyphPtr)); - if (!glyphsBase) - return BadAlloc; - } - if (nlist <= NLOCALDELTA) - listsBase = listsLocal; - else - { - listsBase = (GlyphListPtr) ALLOCATE_LOCAL (nlist * sizeof (GlyphListRec)); - if (!listsBase) - return BadAlloc; - } - - elementsBase = xalloc(nlist * sizeof(XGlyphElt8)); - if (!elementsBase) - return BadAlloc; - - buffer = (CARD8 *) (stuff + 1); - glyphs = glyphsBase; - lists = listsBase; - elements = elementsBase; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - #ifdef DEBUG - fprintf(stderr, "ProcRenderCompositeGlyphs: Glyphset change with base size [%d].\n", - size); - #endif - - if (buffer + sizeof (GlyphSet) < end) - { - gs = *(GlyphSet *) buffer; - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - gs, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = gs; - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - return RenderErrBase + BadGlyphSet; - } - } - buffer += 4; - } - else - { - lists->xOff = elt->deltax; - lists->yOff = elt->deltay; - lists->format = glyphSet->format; - lists->len = 0; - elements -> glyphset = glyphSet -> remoteID; - elements -> chars = (char *) buffer; - elements -> nchars = elt->len; - elements -> xOff = elt->deltax; - elements -> yOff = elt->deltay; - n = elt->len; - while (n--) - { - if (buffer + size <= end) - { - switch (size) { - case 1: - glyph = *((CARD8 *)buffer); break; - case 2: - glyph = *((CARD16 *)buffer); break; - case 4: - default: - glyph = *((CARD32 *)buffer); break; - } - if ((*glyphs = FindGlyph (glyphSet, glyph))) - { - lists->len++; - glyphs++; - } - } - buffer += size; - } - space = size * elt->len; - if (space & 3) - buffer += 4 - (space & 3); - lists++; - elements++; - } - } - if (buffer > end) - return BadLength; - - /* - * We need to know the glyphs extents to synchronize - * the drawables involved in the composite text ope- - * ration. Also we need to synchronize only the back- - * ground of the text we are going to render, so the - * operations on the framebuffer must be executed - * after the X requests. - */ - - if (pFormat != NULL) - { - nxagentGlyphsExtents = (BoxPtr) xalloc(sizeof(BoxRec)); - - miGlyphExtents(nlist, listsBase, glyphsBase, nxagentGlyphsExtents); - } - - nxagentGlyphs(stuff -> op, - pSrc, - pDst, - pFormat, - stuff -> xSrc, - stuff -> ySrc, - nlist, - elementsBase, - size, - glyphsBase); - - if (nxagentCompositePredicate(pSrc, pDst) == 1) - { - #ifdef TEST - fprintf(stderr, "ProcRenderCompositeGlyphs: Going to composite glyphs with " - "source at [%p] and destination at [%p].\n", - (void *) pSrc, (void *) pDst); - #endif - - CompositeGlyphs(stuff -> op, - pSrc, - pDst, - pFormat, - stuff -> xSrc, - stuff -> ySrc, - nlist, - listsBase, - glyphsBase); - } - - if (nxagentGlyphsExtents != NullBox) - { - xfree(nxagentGlyphsExtents); - - nxagentGlyphsExtents = NullBox; - } - - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - - xfree(elementsBase); - - return client->noClientException; -} - -static int -ProcRenderFillRectangles (ClientPtr client) -{ - PicturePtr pDst; - int things; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq); - if (things & 4) - return(BadLength); - things >>= 3; - - CompositeRects (stuff->op, - pDst, - &stuff->color, - things, - (xRectangle *) &stuff[1]); - - ValidatePicture (pDst); - nxagentCompositeRects(stuff -> op, - pDst, - &stuff -> color, - things, - (xRectangle *) &stuff[1]); - - return client->noClientException; -} - -static void -SetBit (unsigned char *line, int x, int bit) -{ - unsigned char mask; - - if (screenInfo.bitmapBitOrder == LSBFirst) - mask = (1 << (x & 7)); - else - mask = (0x80 >> (x & 7)); - /* XXX assumes byte order is host byte order */ - line += (x >> 3); - if (bit) - *line |= mask; - else - *line &= ~mask; -} - -#define DITHER_DIM 2 - -static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = { - { 1, 3, }, - { 4, 2, }, -}; - -#define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1) - -static int -ProcRenderCreateCursor (ClientPtr client) -{ - REQUEST(xRenderCreateCursorReq); - PicturePtr pSrc; - ScreenPtr pScreen; - unsigned short width, height; - CARD32 *argbbits, *argb; - unsigned char *srcbits, *srcline; - unsigned char *mskbits, *mskline; - int stride; - int x, y; - int nbytes_mono; - CursorMetricRec cm; - CursorPtr pCursor; - CARD32 twocolor[3]; - int ncolor; - - RealizeCursorProcPtr saveRealizeCursor; - - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - pScreen = pSrc->pDrawable->pScreen; - width = pSrc->pDrawable->width; - height = pSrc->pDrawable->height; - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - argbbits = xalloc (width * height * sizeof (CARD32)); - if (!argbbits) - return (BadAlloc); - - stride = BitmapBytePad(width); - nbytes_mono = stride*height; - srcbits = (unsigned char *)xalloc(nbytes_mono); - if (!srcbits) - { - xfree (argbbits); - return (BadAlloc); - } - mskbits = (unsigned char *)xalloc(nbytes_mono); - if (!mskbits) - { - xfree(argbbits); - xfree(srcbits); - return (BadAlloc); - } - bzero ((char *) mskbits, nbytes_mono); - bzero ((char *) srcbits, nbytes_mono); - - if (pSrc->format == PICT_a8r8g8b8) - { - (*pScreen->GetImage) (pSrc->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - } - else - { - PixmapPtr pPixmap; - PicturePtr pPicture; - PictFormatPtr pFormat; - int error; - - pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8); - if (!pFormat) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadImplementation); - } - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32); - if (!pPixmap) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadAlloc); - } - pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0, - client, &error); - if (!pPicture) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return error; - } - (*pScreen->DestroyPixmap) (pPixmap); - CompositePicture (PictOpSrc, - pSrc, 0, pPicture, - 0, 0, 0, 0, 0, 0, width, height); - (*pScreen->GetImage) (pPicture->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - FreePicture (pPicture, 0); - } - /* - * Check whether the cursor can be directly supported by - * the core cursor code - */ - ncolor = 0; - argb = argbbits; - for (y = 0; ncolor <= 2 && y < height; y++) - { - for (x = 0; ncolor <= 2 && x < width; x++) - { - CARD32 p = *argb++; - CARD32 a = (p >> 24); - - if (a == 0) /* transparent */ - continue; - if (a == 0xff) /* opaque */ - { - int n; - for (n = 0; n < ncolor; n++) - if (p == twocolor[n]) - break; - if (n == ncolor) - twocolor[ncolor++] = p; - } - else - ncolor = 3; - } - } - - /* - * Convert argb image to two plane cursor - */ - srcline = srcbits; - mskline = mskbits; - argb = argbbits; - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - CARD32 p = *argb++; - - if (ncolor <= 2) - { - CARD32 a = ((p >> 24)); - - SetBit (mskline, x, a != 0); - SetBit (srcline, x, a != 0 && p == twocolor[0]); - } - else - { - CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255; - CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255; - CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)]; - /* Set mask from dithered alpha value */ - SetBit(mskline, x, a > d); - /* Set src from dithered intensity value */ - SetBit(srcline, x, a > d && i <= d); - } - } - srcline += stride; - mskline += stride; - } - /* - * Dither to white and black if the cursor has more than two colors - */ - if (ncolor > 2) - { - twocolor[0] = 0xff000000; - twocolor[1] = 0xffffffff; - } - else - { - xfree (argbbits); - argbbits = 0; - } - -#define GetByte(p,s) (((p) >> (s)) & 0xff) -#define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8)) - - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - - /* - * This cursor uses RENDER, so we make sure - * that it is allocated in a way that allows - * the mi and dix layers to handle it but we - * later create it on the server by mirror- - * ing the RENDER operation we got from the - * client. - */ - - saveRealizeCursor = pScreen -> RealizeCursor; - - pScreen -> RealizeCursor = nxagentCursorSaveRenderInfo; - - pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm, - GetColor(twocolor[0], 16), - GetColor(twocolor[0], 8), - GetColor(twocolor[0], 0), - GetColor(twocolor[1], 16), - GetColor(twocolor[1], 8), - GetColor(twocolor[1], 0)); - - pScreen -> RealizeCursor = saveRealizeCursor; - - /* - * Store into the private data members the - * information needed to recreate it at - * reconnection. This is done in two steps - * as in the first step we don't have the - * picture info. - */ - - if (pCursor == NULL) - { - return BadAlloc; - } - - nxagentCursorPostSaveRenderInfo(pCursor, pScreen, pSrc, stuff -> x, stuff -> y); - - nxagentRenderRealizeCursor(pScreen, pCursor); - - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; -} - -static int -ProcRenderSetPictureTransform (ClientPtr client) -{ - REQUEST(xRenderSetPictureTransformReq); - PicturePtr pPicture; - int result; - - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - result = SetPictureTransform (pPicture, (PictTransform *) &stuff->transform); - - nxagentSetPictureTransform(pPicture, &stuff->transform); - - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderQueryFilters (ClientPtr client) -{ - REQUEST (xRenderQueryFiltersReq); - DrawablePtr pDrawable; - xRenderQueryFiltersReply *reply; - int nbytesName; - int nnames; - ScreenPtr pScreen; - PictureScreenPtr ps; - int i, j; - int len; - int total_bytes; - INT16 *aliases; - char *names; - - REQUEST_SIZE_MATCH(xRenderQueryFiltersReq); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, SecurityReadAccess); - - pScreen = pDrawable->pScreen; - nbytesName = 0; - nnames = 0; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (i = 0; i < ps->nfilters; i++) - nbytesName += 1 + strlen (ps->filters[i].name); - for (i = 0; i < ps->nfilterAliases; i++) - nbytesName += 1 + strlen (ps->filterAliases[i].alias); - nnames = ps->nfilters + ps->nfilterAliases; - } - len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2); - total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2); - reply = (xRenderQueryFiltersReply *) xalloc (total_bytes); - if (!reply) - return BadAlloc; - aliases = (INT16 *) (reply + 1); - names = (char *) (aliases + ((nnames + 1) & ~1)); - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = len; - reply->numAliases = nnames; - reply->numFilters = nnames; - if (ps) - { - - /* fill in alias values */ - for (i = 0; i < ps->nfilters; i++) - aliases[i] = FilterAliasNone; - for (i = 0; i < ps->nfilterAliases; i++) - { - for (j = 0; j < ps->nfilters; j++) - if (ps->filterAliases[i].filter_id == ps->filters[j].id) - break; - if (j == ps->nfilters) - { - for (j = 0; j < ps->nfilterAliases; j++) - if (ps->filterAliases[i].filter_id == - ps->filterAliases[j].alias_id) - { - break; - } - if (j == ps->nfilterAliases) - j = FilterAliasNone; - else - j = j + ps->nfilters; - } - aliases[i + ps->nfilters] = j; - } - - /* fill in filter names */ - for (i = 0; i < ps->nfilters; i++) - { - j = strlen (ps->filters[i].name); - *names++ = j; - strncpy (names, ps->filters[i].name, j); - names += j; - } - - /* fill in filter alias names */ - for (i = 0; i < ps->nfilterAliases; i++) - { - j = strlen (ps->filterAliases[i].alias); - *names++ = j; - strncpy (names, ps->filterAliases[i].alias, j); - names += j; - } - } - - if (client->swapped) - { - register int n; - - for (i = 0; i < (int)reply->numAliases; i++) - { - swaps (&aliases[i], n); - } - swaps(&reply->sequenceNumber, n); - swapl(&reply->length, n); - swapl(&reply->numAliases, n); - swapl(&reply->numFilters, n); - } - WriteToClient(client, total_bytes, (char *) reply); - xfree (reply); - - return(client->noClientException); -} - -static int -ProcRenderSetPictureFilter (ClientPtr client) -{ - REQUEST (xRenderSetPictureFilterReq); - PicturePtr pPicture; - int result; - xFixed *params; - int nparams; - char *name; - - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - name = (char *) (stuff + 1); - params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3)); - nparams = ((xFixed *) stuff + client->req_len) - params; - result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams); - - nxagentSetPictureFilter(pPicture, name, stuff->nbytes, params, nparams); - - return result; -} - -static int -ProcRenderCreateAnimCursor (ClientPtr client) -{ - REQUEST(xRenderCreateAnimCursorReq); - CursorPtr *cursors; - CARD32 *deltas; - CursorPtr pCursor; - int ncursor; - xAnimCursorElt *elt; - int i; - int ret; - - REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - if (client->req_len & 1) - return BadLength; - ncursor = (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1; - cursors = xalloc (ncursor * (sizeof (CursorPtr) + sizeof (CARD32))); - if (!cursors) - return BadAlloc; - deltas = (CARD32 *) (cursors + ncursor); - elt = (xAnimCursorElt *) (stuff + 1); - for (i = 0; i < ncursor; i++) - { - cursors[i] = (CursorPtr)SecurityLookupIDByType(client, elt->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursors[i]) - { - xfree (cursors); - client->errorValue = elt->cursor; - return BadCursor; - } - deltas[i] = elt->delay; - elt++; - } - ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor); - xfree (cursors); - if (ret != Success) - return ret; - - for (i = 0; i < MAXSCREENS; i++) - { - pCursor -> devPriv[i] = NULL; - } - - if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - -static int -ProcRenderDispatch (ClientPtr client) -{ - int result; - - REQUEST(xReq); - - /* - * Let the client fail if we are - * hiding the RENDER extension. - */ - - if (nxagentRenderTrap) - { - return BadRequest; - } - - if (stuff->data < RenderNumberRequests) - { - /* - * Set the nxagentGCTrap flag while - * dispatching a render operation to - * avoid reentrancy in GCOps.c. - */ - - nxagentGCTrap = 1; - - result = (*ProcRenderVector[stuff->data]) (client); - - nxagentGCTrap = 0; - - return result; - } - else - return BadRequest; -} - -static int -SProcRenderQueryVersion (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryVersionReq); - - swaps(&stuff->length, n); - swapl(&stuff->majorVersion, n); - swapl(&stuff->minorVersion, n); - return (*ProcRenderVector[stuff->renderReqType])(client); -} - -static int -SProcRenderQueryPictFormats (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictFormatsReq); - swaps(&stuff->length, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryPictIndexValues (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictIndexValuesReq); - swaps(&stuff->length, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreatePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreatePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->drawable, n); - swapl(&stuff->format, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderChangePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderChangePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureClipRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureClipRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderComposite (ClientPtr client) -{ - register int n; - REQUEST(xRenderCompositeReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->mask, n); - swapl(&stuff->dst, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xMask, n); - swaps(&stuff->yMask, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderScale (ClientPtr client) -{ - register int n; - REQUEST(xRenderScaleReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->colorScale, n); - swapl(&stuff->alphaScale, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTrapezoids (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriStrip (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriStripReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriStripReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriFan (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriFanReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriFanReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreateGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderReferenceGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderReferenceGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->existing, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreeGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphs (ClientPtr client) -{ - register int n; - register unsigned int i; - CARD32 *gids; - void *end; - xGlyphInfo *gi; - REQUEST(xRenderAddGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - swapl(&stuff->nglyphs, n); - if (stuff->nglyphs & 0xe0000000) - return BadLength; - end = (CARD8 *) stuff + (client->req_len << 2); - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + stuff->nglyphs); - if ((char *) end - (char *) (gids + stuff->nglyphs) < 0) - return BadLength; - if ((char *) end - (char *) (gi + stuff->nglyphs) < 0) - return BadLength; - for (i = 0; i < stuff->nglyphs; i++) - { - swapl (&gids[i], n); - swaps (&gi[i].width, n); - swaps (&gi[i].height, n); - swaps (&gi[i].x, n); - swaps (&gi[i].y, n); - swaps (&gi[i].xOff, n); - swaps (&gi[i].yOff, n); - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderFreeGlyphs (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCompositeGlyphs (ClientPtr client) -{ - register int n; - xGlyphElt *elt; - CARD8 *buffer; - CARD8 *end; - int space; - int i; - int size; - - REQUEST(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->maskFormat, n); - swapl(&stuff->glyphset, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - swaps (&elt->deltax, n); - swaps (&elt->deltay, n); - - i = elt->len; - if (i == 0xff) - { - swapl (buffer, n); - buffer += 4; - } - else - { - space = size * i; - switch (size) { - case 1: - buffer += i; - break; - case 2: - while (i--) - { - swaps (buffer, n); - buffer += 2; - } - break; - case 4: - while (i--) - { - swapl (buffer, n); - buffer += 4; - } - break; - } - if (space & 3) - buffer += 4 - (space & 3); - } - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFillRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->dst, n); - swaps(&stuff->color.red, n); - swaps(&stuff->color.green, n); - swaps(&stuff->color.blue, n); - swaps(&stuff->color.alpha, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateCursor (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateCursorReq); - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - swapl(&stuff->src, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureTransform (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureTransformReq); - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->transform.matrix11, n); - swapl(&stuff->transform.matrix12, n); - swapl(&stuff->transform.matrix13, n); - swapl(&stuff->transform.matrix21, n); - swapl(&stuff->transform.matrix22, n); - swapl(&stuff->transform.matrix23, n); - swapl(&stuff->transform.matrix31, n); - swapl(&stuff->transform.matrix32, n); - swapl(&stuff->transform.matrix33, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryFilters (ClientPtr client) -{ - register int n; - REQUEST (xRenderQueryFiltersReq); - REQUEST_SIZE_MATCH (xRenderQueryFiltersReq); - - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureFilter (ClientPtr client) -{ - register int n; - REQUEST (xRenderSetPictureFilterReq); - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swaps(&stuff->nbytes, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateAnimCursor (ClientPtr client) -{ - register int n; - REQUEST (xRenderCreateAnimCursorReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderDispatch (ClientPtr client) -{ - int result; - - REQUEST(xReq); - - /* - * Let the client fail if we are - * hiding the RENDER extension. - */ - - if (nxagentRenderTrap) - { - return BadRequest; - } - - if (stuff->data < RenderNumberRequests) - { - /* - * Set the nxagentGCTrap flag while - * dispatching a render operation to - * avoid reentrancy in GCOps.c. - */ - - nxagentGCTrap = 1; - - result = (*SProcRenderVector[stuff->data]) (client); - - nxagentGCTrap = 0; - - return result; - } - else - return BadRequest; -} - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -#define VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, XRT_PICTURE, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_XIN_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr); - -unsigned long XRT_PICTURE; - -static int -PanoramiXRenderCreatePicture (ClientPtr client) -{ - REQUEST(xRenderCreatePictureReq); - PanoramiXRes *refDraw, *newPict; - int result = Success, j; - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - if(!(refDraw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - if(!(newPict = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - newPict->type = XRT_PICTURE; - newPict->info[0].id = stuff->pid; - - if (refDraw->type == XRT_WINDOW && - stuff->drawable == WindowTable[0]->drawable.id) - { - newPict->u.pict.root = TRUE; - } - else - newPict->u.pict.root = FALSE; - - for(j = 1; j < PanoramiXNumScreens; j++) - newPict->info[j].id = FakeClientID(client->index); - - FOR_NSCREENS_BACKWARD(j) { - stuff->pid = newPict->info[j].id; - stuff->drawable = refDraw->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client); - if(result != Success) break; - } - - if (result == Success) - AddResource(newPict->info[0].id, XRT_PICTURE, newPict); - else - xfree(newPict); - - return (result); -} - -static int -PanoramiXRenderChangePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderChangePictureReq); - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderFreePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - client->errorValue = stuff->picture; - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client); - if(result != Success) break; - } - - /* Since ProcRenderFreePicture is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - - return (result); -} - -static int -PanoramiXRenderComposite (ClientPtr client) -{ - PanoramiXRes *src, *msk, *dst; - int result = Success, j; - xRenderCompositeReq orig; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_ALPHA (msk, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - orig = *stuff; - - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - stuff->xDst = orig.xDst - panoramiXdataPtr[j].x; - stuff->yDst = orig.yDst - panoramiXdataPtr[j].y; - } - if (msk) - { - stuff->mask = msk->info[j].id; - if (msk->u.pict.root) - { - stuff->xMask = orig.xMask - panoramiXdataPtr[j].x; - stuff->yMask = orig.yMask - panoramiXdataPtr[j].y; - } - } - result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client); - if(result != Success) break; - } - - return result; -} - -static int -PanoramiXRenderCompositeGlyphs (ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderCompositeGlyphsReq); - xGlyphElt origElt, *elt; - INT16 xSrc, ySrc; - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) + - sizeof (xGlyphElt))) - { - elt = (xGlyphElt *) (stuff + 1); - origElt = *elt; - xSrc = stuff->xSrc; - ySrc = stuff->ySrc; - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - elt->deltax = origElt.deltax - panoramiXdataPtr[j].x; - elt->deltay = origElt.deltay - panoramiXdataPtr[j].y; - } - result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client); - if(result != Success) break; - } - } - - return result; -} - -static int -PanoramiXRenderFillRectangles (ClientPtr client) -{ - PanoramiXRes *dst; - int result = Success, j; - REQUEST(xRenderFillRectanglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq); - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) - { - memcpy (extra, stuff + 1, extra_len); - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) - { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xRectangle *rects = (xRectangle *) (stuff + 1); - int i = extra_len / sizeof (xRectangle); - - while (i--) - { - rects->x -= x_off; - rects->y -= y_off; - rects++; - } - } - } - stuff->dst = dst->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client); - if(result != Success) break; - } - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -void -PanoramiXRenderInit (void) -{ - int i; - - XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource); - for (i = 0; i < RenderNumberRequests; i++) - PanoramiXSaveRenderVector[i] = ProcRenderVector[i]; - /* - * Stuff in Xinerama aware request processing hooks - */ - ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture; - ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture; - ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles; - ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture; - ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite; - ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles; -} - -void -PanoramiXRenderReset (void) -{ - int i; - for (i = 0; i < RenderNumberRequests; i++) - ProcRenderVector[i] = PanoramiXSaveRenderVector[i]; -} - -#endif /* PANORAMIX */ - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXrender.c.XF86.original deleted file mode 100644 index a4f90ea77..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c.XF86.original +++ /dev/null @@ -1,2584 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/render.c,v 1.26 2003/02/14 18:15:21 dawes Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#define NEED_REPLIES -#define NEED_EVENTS -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "colormapst.h" -#include "extnsionst.h" -#include "servermd.h" -#include "render.h" -#include "renderproto.h" -#include "picturestr.h" -#include "glyphstr.h" -#include "Xfuncproto.h" -#include "cursorstr.h" -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -static int ProcRenderQueryVersion (ClientPtr pClient); -static int ProcRenderQueryPictFormats (ClientPtr pClient); -static int ProcRenderQueryPictIndexValues (ClientPtr pClient); -static int ProcRenderQueryDithers (ClientPtr pClient); -static int ProcRenderCreatePicture (ClientPtr pClient); -static int ProcRenderChangePicture (ClientPtr pClient); -static int ProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int ProcRenderFreePicture (ClientPtr pClient); -static int ProcRenderComposite (ClientPtr pClient); -static int ProcRenderScale (ClientPtr pClient); -static int ProcRenderTrapezoids (ClientPtr pClient); -static int ProcRenderTriangles (ClientPtr pClient); -static int ProcRenderTriStrip (ClientPtr pClient); -static int ProcRenderTriFan (ClientPtr pClient); -static int ProcRenderColorTrapezoids (ClientPtr pClient); -static int ProcRenderColorTriangles (ClientPtr pClient); -static int ProcRenderTransform (ClientPtr pClient); -static int ProcRenderCreateGlyphSet (ClientPtr pClient); -static int ProcRenderReferenceGlyphSet (ClientPtr pClient); -static int ProcRenderFreeGlyphSet (ClientPtr pClient); -static int ProcRenderAddGlyphs (ClientPtr pClient); -static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int ProcRenderFreeGlyphs (ClientPtr pClient); -static int ProcRenderCompositeGlyphs (ClientPtr pClient); -static int ProcRenderFillRectangles (ClientPtr pClient); -static int ProcRenderCreateCursor (ClientPtr pClient); -static int ProcRenderSetPictureTransform (ClientPtr pClient); -static int ProcRenderQueryFilters (ClientPtr pClient); -static int ProcRenderSetPictureFilter (ClientPtr pClient); -static int ProcRenderCreateAnimCursor (ClientPtr pClient); - -static int ProcRenderDispatch (ClientPtr pClient); - -static int SProcRenderQueryVersion (ClientPtr pClient); -static int SProcRenderQueryPictFormats (ClientPtr pClient); -static int SProcRenderQueryPictIndexValues (ClientPtr pClient); -static int SProcRenderQueryDithers (ClientPtr pClient); -static int SProcRenderCreatePicture (ClientPtr pClient); -static int SProcRenderChangePicture (ClientPtr pClient); -static int SProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int SProcRenderFreePicture (ClientPtr pClient); -static int SProcRenderComposite (ClientPtr pClient); -static int SProcRenderScale (ClientPtr pClient); -static int SProcRenderTrapezoids (ClientPtr pClient); -static int SProcRenderTriangles (ClientPtr pClient); -static int SProcRenderTriStrip (ClientPtr pClient); -static int SProcRenderTriFan (ClientPtr pClient); -static int SProcRenderColorTrapezoids (ClientPtr pClient); -static int SProcRenderColorTriangles (ClientPtr pClient); -static int SProcRenderTransform (ClientPtr pClient); -static int SProcRenderCreateGlyphSet (ClientPtr pClient); -static int SProcRenderReferenceGlyphSet (ClientPtr pClient); -static int SProcRenderFreeGlyphSet (ClientPtr pClient); -static int SProcRenderAddGlyphs (ClientPtr pClient); -static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int SProcRenderFreeGlyphs (ClientPtr pClient); -static int SProcRenderCompositeGlyphs (ClientPtr pClient); -static int SProcRenderFillRectangles (ClientPtr pClient); -static int SProcRenderCreateCursor (ClientPtr pClient); -static int SProcRenderSetPictureTransform (ClientPtr pClient); -static int SProcRenderQueryFilters (ClientPtr pClient); -static int SProcRenderSetPictureFilter (ClientPtr pClient); -static int SProcRenderCreateAnimCursor (ClientPtr pClient); - -static int SProcRenderDispatch (ClientPtr pClient); - -int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = { - ProcRenderQueryVersion, - ProcRenderQueryPictFormats, - ProcRenderQueryPictIndexValues, - ProcRenderQueryDithers, - ProcRenderCreatePicture, - ProcRenderChangePicture, - ProcRenderSetPictureClipRectangles, - ProcRenderFreePicture, - ProcRenderComposite, - ProcRenderScale, - ProcRenderTrapezoids, - ProcRenderTriangles, - ProcRenderTriStrip, - ProcRenderTriFan, - ProcRenderColorTrapezoids, - ProcRenderColorTriangles, - ProcRenderTransform, - ProcRenderCreateGlyphSet, - ProcRenderReferenceGlyphSet, - ProcRenderFreeGlyphSet, - ProcRenderAddGlyphs, - ProcRenderAddGlyphsFromPicture, - ProcRenderFreeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderFillRectangles, - ProcRenderCreateCursor, - ProcRenderSetPictureTransform, - ProcRenderQueryFilters, - ProcRenderSetPictureFilter, - ProcRenderCreateAnimCursor, -}; - -int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = { - SProcRenderQueryVersion, - SProcRenderQueryPictFormats, - SProcRenderQueryPictIndexValues, - SProcRenderQueryDithers, - SProcRenderCreatePicture, - SProcRenderChangePicture, - SProcRenderSetPictureClipRectangles, - SProcRenderFreePicture, - SProcRenderComposite, - SProcRenderScale, - SProcRenderTrapezoids, - SProcRenderTriangles, - SProcRenderTriStrip, - SProcRenderTriFan, - SProcRenderColorTrapezoids, - SProcRenderColorTriangles, - SProcRenderTransform, - SProcRenderCreateGlyphSet, - SProcRenderReferenceGlyphSet, - SProcRenderFreeGlyphSet, - SProcRenderAddGlyphs, - SProcRenderAddGlyphsFromPicture, - SProcRenderFreeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderFillRectangles, - SProcRenderCreateCursor, - SProcRenderSetPictureTransform, - SProcRenderQueryFilters, - SProcRenderSetPictureFilter, - SProcRenderCreateAnimCursor, -}; - -static void -RenderResetProc (ExtensionEntry *extEntry); - -static CARD8 RenderReqCode; -int RenderErrBase; -int RenderClientPrivateIndex; - -typedef struct _RenderClient { - int major_version; - int minor_version; -} RenderClientRec, *RenderClientPtr; - -#define GetRenderClient(pClient) ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr) - -static void -RenderClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - RenderClientPtr pRenderClient = GetRenderClient (pClient); - - pRenderClient->major_version = 0; - pRenderClient->minor_version = 0; -} - -void -RenderExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (!PictureType) - return; - if (!PictureFinishInit ()) - return; - RenderClientPrivateIndex = AllocateClientPrivateIndex (); - if (!AllocateClientPrivate (RenderClientPrivateIndex, - sizeof (RenderClientRec))) - return; - if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0)) - return; - - extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors, - ProcRenderDispatch, SProcRenderDispatch, - RenderResetProc, StandardMinorOpcode); - if (!extEntry) - return; - RenderReqCode = (CARD8) extEntry->base; - RenderErrBase = extEntry->errorBase; -} - -static void -RenderResetProc (ExtensionEntry *extEntry) -{ -} - -static int -ProcRenderQueryVersion (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryVersionReply rep; - register int n; - REQUEST(xRenderQueryVersionReq); - - pRenderClient->major_version = stuff->majorVersion; - pRenderClient->minor_version = stuff->minorVersion; - - REQUEST_SIZE_MATCH(xRenderQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = RENDER_MAJOR; - rep.minorVersion = RENDER_MINOR; - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.majorVersion, n); - swapl(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -#if 0 -static int -VisualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - DepthPtr pDepth; - int d, v; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - for (v = 0; v < pDepth->numVids; v++) - { - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - } - return 0; -} -#endif - -static VisualPtr -findVisual (ScreenPtr pScreen, VisualID vid) -{ - VisualPtr pVisual; - int v; - - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = pScreen->visuals + v; - if (pVisual->vid == vid) - return pVisual; - } - return 0; -} - -extern char *ConnectionInfo; - -static int -ProcRenderQueryPictFormats (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryPictFormatsReply *reply; - xPictScreen *pictScreen; - xPictDepth *pictDepth; - xPictVisual *pictVisual; - xPictFormInfo *pictForm; - CARD32 *pictSubpixel; - ScreenPtr pScreen; - VisualPtr pVisual; - DepthPtr pDepth; - int v, d; - PictureScreenPtr ps; - PictFormatPtr pFormat; - int nformat; - int ndepth; - int nvisual; - int rlength; - int s; - int n; - int numScreens; - int numSubpixel; -/* REQUEST(xRenderQueryPictFormatsReq); */ - - REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq); - -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#else - numScreens = screenInfo.numScreens; -#endif - ndepth = nformat = nvisual = 0; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - ++ndepth; - - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual)) - ++nvisual; - } - } - ps = GetPictureScreenIfSet(pScreen); - if (ps) - nformat += ps->nformats; - } - if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6) - numSubpixel = 0; - else - numSubpixel = numScreens; - - rlength = (sizeof (xRenderQueryPictFormatsReply) + - nformat * sizeof (xPictFormInfo) + - numScreens * sizeof (xPictScreen) + - ndepth * sizeof (xPictDepth) + - nvisual * sizeof (xPictVisual) + - numSubpixel * sizeof (CARD32)); - reply = (xRenderQueryPictFormatsReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numFormats = nformat; - reply->numScreens = numScreens; - reply->numDepths = ndepth; - reply->numVisuals = nvisual; - reply->numSubpixel = numSubpixel; - - pictForm = (xPictFormInfo *) (reply + 1); - - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (nformat = 0, pFormat = ps->formats; - nformat < ps->nformats; - nformat++, pFormat++) - { - pictForm->id = pFormat->id; - pictForm->type = pFormat->type; - pictForm->depth = pFormat->depth; - pictForm->direct.red = pFormat->direct.red; - pictForm->direct.redMask = pFormat->direct.redMask; - pictForm->direct.green = pFormat->direct.green; - pictForm->direct.greenMask = pFormat->direct.greenMask; - pictForm->direct.blue = pFormat->direct.blue; - pictForm->direct.blueMask = pFormat->direct.blueMask; - pictForm->direct.alpha = pFormat->direct.alpha; - pictForm->direct.alphaMask = pFormat->direct.alphaMask; - if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap) - pictForm->colormap = pFormat->index.pColormap->mid; - else - pictForm->colormap = None; - if (client->swapped) - { - swapl (&pictForm->id, n); - swaps (&pictForm->direct.red, n); - swaps (&pictForm->direct.redMask, n); - swaps (&pictForm->direct.green, n); - swaps (&pictForm->direct.greenMask, n); - swaps (&pictForm->direct.blue, n); - swaps (&pictForm->direct.blueMask, n); - swaps (&pictForm->direct.alpha, n); - swaps (&pictForm->direct.alphaMask, n); - swapl (&pictForm->colormap, n); - } - pictForm++; - } - } - } - - pictScreen = (xPictScreen *) pictForm; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - pictDepth = (xPictDepth *) (pictScreen + 1); - ndepth = 0; - for (d = 0; d < pScreen->numDepths; d++) - { - pictVisual = (xPictVisual *) (pictDepth + 1); - pDepth = pScreen->allowedDepths + d; - - nvisual = 0; - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && (pFormat = PictureMatchVisual (pScreen, - pDepth->depth, - pVisual))) - { - pictVisual->visual = pVisual->vid; - pictVisual->format = pFormat->id; - if (client->swapped) - { - swapl (&pictVisual->visual, n); - swapl (&pictVisual->format, n); - } - pictVisual++; - nvisual++; - } - } - pictDepth->depth = pDepth->depth; - pictDepth->nPictVisuals = nvisual; - if (client->swapped) - { - swaps (&pictDepth->nPictVisuals, n); - } - ndepth++; - pictDepth = (xPictDepth *) pictVisual; - } - pictScreen->nDepth = ndepth; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - pictScreen->fallback = ps->fallback->id; - else - pictScreen->fallback = 0; - if (client->swapped) - { - swapl (&pictScreen->nDepth, n); - swapl (&pictScreen->fallback, n); - } - pictScreen = (xPictScreen *) pictDepth; - } - pictSubpixel = (CARD32 *) pictScreen; - - for (s = 0; s < numSubpixel; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - *pictSubpixel = ps->subpixel; - else - *pictSubpixel = SubPixelUnknown; - if (client->swapped) - { - swapl (pictSubpixel, n); - } - ++pictSubpixel; - } - - if (client->swapped) - { - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numFormats, n); - swapl (&reply->numScreens, n); - swapl (&reply->numDepths, n); - swapl (&reply->numVisuals, n); - swapl (&reply->numSubpixel, n); - } - WriteToClient(client, rlength, (char *) reply); - xfree (reply); - return client->noClientException; -} - -static int -ProcRenderQueryPictIndexValues (ClientPtr client) -{ - PictFormatPtr pFormat; - int num; - int rlength; - int i, n; - REQUEST(xRenderQueryPictIndexValuesReq); - xRenderQueryPictIndexValuesReply *reply; - xIndexValue *values; - - REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq); - - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->type != PictTypeIndexed) - { - client->errorValue = stuff->format; - return BadMatch; - } - num = pFormat->index.nvalues; - rlength = (sizeof (xRenderQueryPictIndexValuesReply) + - num * sizeof(xIndexValue)); - reply = (xRenderQueryPictIndexValuesReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numIndexValues = num; - - values = (xIndexValue *) (reply + 1); - - memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue)); - - if (client->swapped) - { - for (i = 0; i < num; i++) - { - swapl (&values[i].pixel, n); - swaps (&values[i].red, n); - swaps (&values[i].green, n); - swaps (&values[i].blue, n); - swaps (&values[i].alpha, n); - } - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numIndexValues, n); - } - - WriteToClient(client, rlength, (char *) reply); - xfree(reply); - return (client->noClientException); -} - -static int -ProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreatePicture (ClientPtr client) -{ - PicturePtr pPicture; - DrawablePtr pDrawable; - PictFormatPtr pFormat; - int len; - int error; - REQUEST(xRenderCreatePictureReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, - SecurityWriteAccess); - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->depth != pDrawable->depth) - return BadMatch; - len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - pPicture = CreatePicture (stuff->pid, - pDrawable, - pFormat, - stuff->mask, - (XID *) (stuff + 1), - client, - &error); - if (!pPicture) - return error; - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int -ProcRenderChangePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderChangePictureReq); - int len; - - REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - return ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1), - (DevUnion *) 0, client); -} - -static int -ProcRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - PicturePtr pPicture; - int nr; - int result; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - nr = (client->req_len << 2) - sizeof(xRenderChangePictureReq); - if (nr & 4) - return BadLength; - nr >>= 3; - result = SetPictureClipRects (pPicture, - stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *) &stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderFreePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - FreeResource (stuff->picture, RT_NONE); - return(client->noClientException); -} - -static Bool -PictOpValid (CARD8 op) -{ - if (/*PictOpMinimum <= op && */ op <= PictOpMaximum) - return TRUE; - if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum) - return TRUE; - if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum) - return TRUE; - return FALSE; -} - -static int -ProcRenderComposite (ClientPtr client) -{ - PicturePtr pSrc, pMask, pDst; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_ALPHA (pMask, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen || - (pMask && pSrc->pDrawable->pScreen != pMask->pDrawable->pScreen)) - return BadMatch; - CompositePicture (stuff->op, - pSrc, - pMask, - pDst, - stuff->xSrc, - stuff->ySrc, - stuff->xMask, - stuff->yMask, - stuff->xDst, - stuff->yDst, - stuff->width, - stuff->height); - return Success; -} - -static int -ProcRenderScale (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTrapezoids (ClientPtr client) -{ - int ntraps; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); - if (ntraps % sizeof (xTrapezoid)) - return BadLength; - ntraps /= sizeof (xTrapezoid); - if (ntraps) - CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntraps, (xTrapezoid *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriangles (ClientPtr client) -{ - int ntris; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq); - if (ntris % sizeof (xTriangle)) - return BadLength; - ntris /= sizeof (xTriangle); - if (ntris) - CompositeTriangles (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntris, (xTriangle *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriStrip (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriStrip (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriFan (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriFan (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreateGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - PictFormatPtr format; - int f; - REQUEST(xRenderCreateGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - format = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!format) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - switch (format->depth) { - case 1: - f = GlyphFormat1; - break; - case 4: - f = GlyphFormat4; - break; - case 8: - f = GlyphFormat8; - break; - case 16: - f = GlyphFormat16; - break; - case 32: - f = GlyphFormat32; - break; - default: - return BadMatch; - } - if (format->type != PictTypeDirect) - return BadMatch; - glyphSet = AllocateGlyphSet (f, format); - if (!glyphSet) - return BadAlloc; - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - return Success; -} - -static int -ProcRenderReferenceGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderReferenceGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->existing, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->existing; - return RenderErrBase + BadGlyphSet; - } - glyphSet->refcnt++; - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - return client->noClientException; -} - -#define NLOCALDELTA 64 -#define NLOCALGLYPH 256 - -static int -ProcRenderFreeGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderFreeGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityDestroyAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - FreeResource (stuff->glyphset, RT_NONE); - return client->noClientException; -} - -typedef struct _GlyphNew { - Glyph id; - GlyphPtr glyph; -} GlyphNewRec, *GlyphNewPtr; - -static int -ProcRenderAddGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderAddGlyphsReq); - GlyphNewRec glyphsLocal[NLOCALGLYPH]; - GlyphNewPtr glyphsBase, glyphs; - GlyphPtr glyph; - int remain, nglyphs; - CARD32 *gids; - xGlyphInfo *gi; - CARD8 *bits; - int size; - int err = BadAlloc; - - REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - nglyphs = stuff->nglyphs; - if (nglyphs <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphNewPtr) ALLOCATE_LOCAL (nglyphs * sizeof (GlyphNewRec)); - if (!glyphsBase) - return BadAlloc; - } - - remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq); - - glyphs = glyphsBase; - - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + nglyphs); - bits = (CARD8 *) (gi + nglyphs); - remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs; - while (remain >= 0 && nglyphs) - { - glyph = AllocateGlyph (gi, glyphSet->fdepth); - if (!glyph) - { - err = BadAlloc; - goto bail; - } - - glyphs->glyph = glyph; - glyphs->id = *gids; - - size = glyph->size - sizeof (xGlyphInfo); - if (remain < size) - break; - memcpy ((CARD8 *) (glyph + 1), bits, size); - - if (size & 3) - size += 4 - (size & 3); - bits += size; - remain -= size; - gi++; - gids++; - glyphs++; - nglyphs--; - } - if (nglyphs || remain) - { - err = BadLength; - goto bail; - } - nglyphs = stuff->nglyphs; - if (!ResizeGlyphSet (glyphSet, nglyphs)) - { - err = BadAlloc; - goto bail; - } - glyphs = glyphsBase; - while (nglyphs--) - AddGlyph (glyphSet, glyphs->glyph, glyphs->id); - - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - return client->noClientException; -bail: - while (glyphs != glyphsBase) - { - --glyphs; - xfree (glyphs->glyph); - } - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - return err; -} - -static int -ProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderFreeGlyphs (ClientPtr client) -{ - REQUEST(xRenderFreeGlyphsReq); - GlyphSetPtr glyphSet; - int nglyph; - CARD32 *gids; - CARD32 glyph; - - REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2; - gids = (CARD32 *) (stuff + 1); - while (nglyph-- > 0) - { - glyph = *gids++; - if (!DeleteGlyph (glyphSet, glyph)) - { - client->errorValue = glyph; - return RenderErrBase + BadGlyph; - } - } - return client->noClientException; -} - -static int -ProcRenderCompositeGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - GlyphSet gs; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - GlyphListRec listsLocal[NLOCALDELTA]; - GlyphListPtr lists, listsBase; - GlyphPtr glyphsLocal[NLOCALGLYPH]; - Glyph glyph; - GlyphPtr *glyphs, *glyphsBase; - xGlyphElt *elt; - CARD8 *buffer, *end; - int nglyph; - int nlist; - int space; - int size; - int n; - - REQUEST(xRenderCompositeGlyphsReq); - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - nglyph = 0; - nlist = 0; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - buffer += 4; - } - else - { - nlist++; - nglyph += elt->len; - space = size * elt->len; - if (space & 3) - space += 4 - (space & 3); - buffer += space; - } - } - if (nglyph <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphPtr *) ALLOCATE_LOCAL (nglyph * sizeof (GlyphPtr)); - if (!glyphsBase) - return BadAlloc; - } - if (nlist <= NLOCALDELTA) - listsBase = listsLocal; - else - { - listsBase = (GlyphListPtr) ALLOCATE_LOCAL (nlist * sizeof (GlyphListRec)); - if (!listsBase) - return BadAlloc; - } - buffer = (CARD8 *) (stuff + 1); - glyphs = glyphsBase; - lists = listsBase; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - if (buffer + sizeof (GlyphSet) < end) - { - gs = *(GlyphSet *) buffer; - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - gs, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = gs; - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - return RenderErrBase + BadGlyphSet; - } - } - buffer += 4; - } - else - { - lists->xOff = elt->deltax; - lists->yOff = elt->deltay; - lists->format = glyphSet->format; - lists->len = 0; - n = elt->len; - while (n--) - { - if (buffer + size <= end) - { - switch (size) { - case 1: - glyph = *((CARD8 *)buffer); break; - case 2: - glyph = *((CARD16 *)buffer); break; - case 4: - default: - glyph = *((CARD32 *)buffer); break; - } - if ((*glyphs = FindGlyph (glyphSet, glyph))) - { - lists->len++; - glyphs++; - } - } - buffer += size; - } - space = size * elt->len; - if (space & 3) - buffer += 4 - (space & 3); - lists++; - } - } - if (buffer > end) - return BadLength; - - CompositeGlyphs (stuff->op, - pSrc, - pDst, - pFormat, - stuff->xSrc, - stuff->ySrc, - nlist, - listsBase, - glyphsBase); - - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - - return client->noClientException; -} - -static int -ProcRenderFillRectangles (ClientPtr client) -{ - PicturePtr pDst; - int things; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq); - if (things & 4) - return(BadLength); - things >>= 3; - - CompositeRects (stuff->op, - pDst, - &stuff->color, - things, - (xRectangle *) &stuff[1]); - - return client->noClientException; -} - -static void -SetBit (unsigned char *line, int x, int bit) -{ - unsigned char mask; - - if (screenInfo.bitmapBitOrder == LSBFirst) - mask = (1 << (x & 7)); - else - mask = (0x80 >> (x & 7)); - /* XXX assumes byte order is host byte order */ - line += (x >> 3); - if (bit) - *line |= mask; - else - *line &= ~mask; -} - -#define DITHER_DIM 2 - -static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = { - { 1, 3, }, - { 4, 2, }, -}; - -#define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1) - -static int -ProcRenderCreateCursor (ClientPtr client) -{ - REQUEST(xRenderCreateCursorReq); - PicturePtr pSrc; - ScreenPtr pScreen; - unsigned short width, height; - CARD32 *argbbits, *argb; - unsigned char *srcbits, *srcline; - unsigned char *mskbits, *mskline; - int stride; - int x, y; - int nbytes_mono; - CursorMetricRec cm; - CursorPtr pCursor; - CARD32 twocolor[3]; - int ncolor; - - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - pScreen = pSrc->pDrawable->pScreen; - width = pSrc->pDrawable->width; - height = pSrc->pDrawable->height; - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - argbbits = xalloc (width * height * sizeof (CARD32)); - if (!argbbits) - return (BadAlloc); - - stride = BitmapBytePad(width); - nbytes_mono = stride*height; - srcbits = (unsigned char *)xalloc(nbytes_mono); - if (!srcbits) - { - xfree (argbbits); - return (BadAlloc); - } - mskbits = (unsigned char *)xalloc(nbytes_mono); - if (!mskbits) - { - xfree(argbbits); - xfree(srcbits); - return (BadAlloc); - } - bzero ((char *) mskbits, nbytes_mono); - bzero ((char *) srcbits, nbytes_mono); - - if (pSrc->format == PICT_a8r8g8b8) - { - (*pScreen->GetImage) (pSrc->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - } - else - { - PixmapPtr pPixmap; - PicturePtr pPicture; - PictFormatPtr pFormat; - int error; - - pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8); - if (!pFormat) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadImplementation); - } - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32); - if (!pPixmap) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadAlloc); - } - pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0, - client, &error); - if (!pPicture); - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return error; - } - (*pScreen->DestroyPixmap) (pPixmap); - CompositePicture (PictOpSrc, - pSrc, 0, pPicture, - 0, 0, 0, 0, 0, 0, width, height); - (*pScreen->GetImage) (pPicture->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - FreePicture (pPicture, 0); - } - /* - * Check whether the cursor can be directly supported by - * the core cursor code - */ - ncolor = 0; - argb = argbbits; - for (y = 0; ncolor <= 2 && y < height; y++) - { - for (x = 0; ncolor <= 2 && x < width; x++) - { - CARD32 p = *argb++; - CARD32 a = (p >> 24); - - if (a == 0) /* transparent */ - continue; - if (a == 0xff) /* opaque */ - { - int n; - for (n = 0; n < ncolor; n++) - if (p == twocolor[n]) - break; - if (n == ncolor) - twocolor[ncolor++] = p; - } - else - ncolor = 3; - } - } - - /* - * Convert argb image to two plane cursor - */ - srcline = srcbits; - mskline = mskbits; - argb = argbbits; - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - CARD32 p = *argb++; - - if (ncolor <= 2) - { - CARD32 a = ((p >> 24)); - - SetBit (mskline, x, a != 0); - SetBit (srcline, x, a != 0 && p == twocolor[0]); - } - else - { - CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255; - CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255; - CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)]; - /* Set mask from dithered alpha value */ - SetBit(mskline, x, a > d); - /* Set src from dithered intensity value */ - SetBit(srcline, x, a > d && i <= d); - } - } - srcline += stride; - mskline += stride; - } - /* - * Dither to white and black if the cursor has more than two colors - */ - if (ncolor > 2) - { - twocolor[0] = 0xff000000; - twocolor[1] = 0xffffffff; - } - else - { - xfree (argbbits); - argbbits = 0; - } - -#define GetByte(p,s) (((p) >> (s)) & 0xff) -#define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8)) - - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm, - GetColor(twocolor[0], 16), - GetColor(twocolor[0], 8), - GetColor(twocolor[0], 0), - GetColor(twocolor[1], 16), - GetColor(twocolor[1], 8), - GetColor(twocolor[1], 0)); - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; -} - -static int -ProcRenderSetPictureTransform (ClientPtr client) -{ - REQUEST(xRenderSetPictureTransformReq); - PicturePtr pPicture; - int result; - - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - result = SetPictureTransform (pPicture, (PictTransform *) &stuff->transform); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderQueryFilters (ClientPtr client) -{ - REQUEST (xRenderQueryFiltersReq); - DrawablePtr pDrawable; - xRenderQueryFiltersReply *reply; - int nbytesName; - int nnames; - ScreenPtr pScreen; - PictureScreenPtr ps; - int i, j; - int len; - int total_bytes; - INT16 *aliases; - char *names; - - REQUEST_SIZE_MATCH(xRenderQueryFiltersReq); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, SecurityReadAccess); - - pScreen = pDrawable->pScreen; - nbytesName = 0; - nnames = 0; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (i = 0; i < ps->nfilters; i++) - nbytesName += 1 + strlen (ps->filters[i].name); - for (i = 0; i < ps->nfilterAliases; i++) - nbytesName += 1 + strlen (ps->filterAliases[i].alias); - nnames = ps->nfilters + ps->nfilterAliases; - } - len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2); - total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2); - reply = (xRenderQueryFiltersReply *) xalloc (total_bytes); - if (!reply) - return BadAlloc; - aliases = (INT16 *) (reply + 1); - names = (char *) (aliases + ((nnames + 1) & ~1)); - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = len; - reply->numAliases = nnames; - reply->numFilters = nnames; - if (ps) - { - - /* fill in alias values */ - for (i = 0; i < ps->nfilters; i++) - aliases[i] = FilterAliasNone; - for (i = 0; i < ps->nfilterAliases; i++) - { - for (j = 0; j < ps->nfilters; j++) - if (ps->filterAliases[i].filter_id == ps->filters[j].id) - break; - if (j == ps->nfilters) - { - for (j = 0; j < ps->nfilterAliases; j++) - if (ps->filterAliases[i].filter_id == - ps->filterAliases[j].alias_id) - { - break; - } - if (j == ps->nfilterAliases) - j = FilterAliasNone; - else - j = j + ps->nfilters; - } - aliases[i + ps->nfilters] = j; - } - - /* fill in filter names */ - for (i = 0; i < ps->nfilters; i++) - { - j = strlen (ps->filters[i].name); - *names++ = j; - strncpy (names, ps->filters[i].name, j); - names += j; - } - - /* fill in filter alias names */ - for (i = 0; i < ps->nfilterAliases; i++) - { - j = strlen (ps->filterAliases[i].alias); - *names++ = j; - strncpy (names, ps->filterAliases[i].alias, j); - names += j; - } - } - - if (client->swapped) - { - register int n; - - for (i = 0; i < reply->numAliases; i++) - { - swaps (&aliases[i], n); - } - swaps(&reply->sequenceNumber, n); - swapl(&reply->length, n); - swapl(&reply->numAliases, n); - swapl(&reply->numFilters, n); - } - WriteToClient(client, total_bytes, (char *) reply); - xfree (reply); - - return(client->noClientException); -} - -static int -ProcRenderSetPictureFilter (ClientPtr client) -{ - REQUEST (xRenderSetPictureFilterReq); - PicturePtr pPicture; - int result; - xFixed *params; - int nparams; - char *name; - - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - name = (char *) (stuff + 1); - params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3)); - nparams = ((xFixed *) stuff + client->req_len) - params; - result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams); - return result; -} - -static int -ProcRenderCreateAnimCursor (ClientPtr client) -{ - REQUEST(xRenderCreateAnimCursorReq); - CursorPtr *cursors; - CARD32 *deltas; - CursorPtr pCursor; - int ncursor; - xAnimCursorElt *elt; - int i; - int ret; - - REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - if (client->req_len & 1) - return BadLength; - ncursor = (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1; - cursors = xalloc (ncursor * (sizeof (CursorPtr) + sizeof (CARD32))); - if (!cursors) - return BadAlloc; - deltas = (CARD32 *) (cursors + ncursor); - elt = (xAnimCursorElt *) (stuff + 1); - for (i = 0; i < ncursor; i++) - { - cursors[i] = (CursorPtr)SecurityLookupIDByType(client, elt->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursors[i]) - { - xfree (cursors); - client->errorValue = elt->cursor; - return BadCursor; - } - deltas[i] = elt->delay; - elt++; - } - ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor); - xfree (cursors); - if (ret != Success) - return ret; - - if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - -static int -ProcRenderDispatch (ClientPtr client) -{ - REQUEST(xReq); - - if (stuff->data < RenderNumberRequests) - return (*ProcRenderVector[stuff->data]) (client); - else - return BadRequest; -} - -static int -SProcRenderQueryVersion (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryVersionReq); - - swaps(&stuff->length, n); - swapl(&stuff->majorVersion, n); - swapl(&stuff->minorVersion, n); - return (*ProcRenderVector[stuff->renderReqType])(client); -} - -static int -SProcRenderQueryPictFormats (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictFormatsReq); - swaps(&stuff->length, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryPictIndexValues (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictIndexValuesReq); - swaps(&stuff->length, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreatePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreatePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->drawable, n); - swapl(&stuff->format, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderChangePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderChangePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureClipRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureClipRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderComposite (ClientPtr client) -{ - register int n; - REQUEST(xRenderCompositeReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->mask, n); - swapl(&stuff->dst, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xMask, n); - swaps(&stuff->yMask, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderScale (ClientPtr client) -{ - register int n; - REQUEST(xRenderScaleReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->colorScale, n); - swapl(&stuff->alphaScale, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTrapezoids (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriStrip (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriStripReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriStripReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriFan (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriFanReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriFanReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreateGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderReferenceGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderReferenceGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->existing, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreeGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphs (ClientPtr client) -{ - register int n; - register int i; - CARD32 *gids; - void *end; - xGlyphInfo *gi; - REQUEST(xRenderAddGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - swapl(&stuff->nglyphs, n); - if (stuff->nglyphs & 0xe0000000) - return BadLength; - end = (CARD8 *) stuff + (client->req_len << 2); - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + stuff->nglyphs); - if ((char *) end - (char *) (gids + stuff->nglyphs) < 0) - return BadLength; - if ((char *) end - (char *) (gi + stuff->nglyphs) < 0) - return BadLength; - for (i = 0; i < stuff->nglyphs; i++) - { - swapl (&gids[i], n); - swaps (&gi[i].width, n); - swaps (&gi[i].height, n); - swaps (&gi[i].x, n); - swaps (&gi[i].y, n); - swaps (&gi[i].xOff, n); - swaps (&gi[i].yOff, n); - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderFreeGlyphs (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCompositeGlyphs (ClientPtr client) -{ - register int n; - xGlyphElt *elt; - CARD8 *buffer; - CARD8 *end; - int space; - int i; - int size; - - REQUEST(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->maskFormat, n); - swapl(&stuff->glyphset, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - swaps (&elt->deltax, n); - swaps (&elt->deltay, n); - - i = elt->len; - if (i == 0xff) - { - swapl (buffer, n); - buffer += 4; - } - else - { - space = size * i; - switch (size) { - case 1: - buffer += i; - break; - case 2: - while (i--) - { - swaps (buffer, n); - buffer += 2; - } - break; - case 4: - while (i--) - { - swapl (buffer, n); - buffer += 4; - } - break; - } - if (space & 3) - buffer += 4 - (space & 3); - } - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFillRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->dst, n); - swaps(&stuff->color.red, n); - swaps(&stuff->color.green, n); - swaps(&stuff->color.blue, n); - swaps(&stuff->color.alpha, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateCursor (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateCursorReq); - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - swapl(&stuff->src, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureTransform (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureTransformReq); - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->transform.matrix11, n); - swapl(&stuff->transform.matrix12, n); - swapl(&stuff->transform.matrix13, n); - swapl(&stuff->transform.matrix21, n); - swapl(&stuff->transform.matrix22, n); - swapl(&stuff->transform.matrix23, n); - swapl(&stuff->transform.matrix31, n); - swapl(&stuff->transform.matrix32, n); - swapl(&stuff->transform.matrix33, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryFilters (ClientPtr client) -{ - register int n; - REQUEST (xRenderQueryFiltersReq); - REQUEST_SIZE_MATCH (xRenderQueryFiltersReq); - - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureFilter (ClientPtr client) -{ - register int n; - REQUEST (xRenderSetPictureFilterReq); - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swaps(&stuff->nbytes, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateAnimCursor (ClientPtr client) -{ - register int n; - REQUEST (xRenderCreateAnimCursorReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderDispatch (ClientPtr client) -{ - REQUEST(xReq); - - if (stuff->data < RenderNumberRequests) - return (*SProcRenderVector[stuff->data]) (client); - else - return BadRequest; -} - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -#define VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, XRT_PICTURE, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_XIN_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr); - -unsigned long XRT_PICTURE; - -static int -PanoramiXRenderCreatePicture (ClientPtr client) -{ - REQUEST(xRenderCreatePictureReq); - PanoramiXRes *refDraw, *newPict; - int result = Success, j; - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - if(!(refDraw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - if(!(newPict = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - newPict->type = XRT_PICTURE; - newPict->info[0].id = stuff->pid; - - if (refDraw->type == XRT_WINDOW && - stuff->drawable == WindowTable[0]->drawable.id) - { - newPict->u.pict.root = TRUE; - } - else - newPict->u.pict.root = FALSE; - - for(j = 1; j < PanoramiXNumScreens; j++) - newPict->info[j].id = FakeClientID(client->index); - - FOR_NSCREENS_BACKWARD(j) { - stuff->pid = newPict->info[j].id; - stuff->drawable = refDraw->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client); - if(result != Success) break; - } - - if (result == Success) - AddResource(newPict->info[0].id, XRT_PICTURE, newPict); - else - xfree(newPict); - - return (result); -} - -static int -PanoramiXRenderChangePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderChangePictureReq); - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderFreePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - client->errorValue = stuff->picture; - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client); - if(result != Success) break; - } - - /* Since ProcRenderFreePicture is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - - return (result); -} - -static int -PanoramiXRenderComposite (ClientPtr client) -{ - PanoramiXRes *src, *msk, *dst; - int result = Success, j; - xRenderCompositeReq orig; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_ALPHA (msk, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - orig = *stuff; - - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - stuff->xDst = orig.xDst - panoramiXdataPtr[j].x; - stuff->yDst = orig.yDst - panoramiXdataPtr[j].y; - } - if (msk) - { - stuff->mask = msk->info[j].id; - if (msk->u.pict.root) - { - stuff->xMask = orig.xMask - panoramiXdataPtr[j].x; - stuff->yMask = orig.yMask - panoramiXdataPtr[j].y; - } - } - result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client); - if(result != Success) break; - } - - return result; -} - -static int -PanoramiXRenderCompositeGlyphs (ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderCompositeGlyphsReq); - xGlyphElt origElt, *elt; - INT16 xSrc, ySrc; - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) + - sizeof (xGlyphElt))) - { - elt = (xGlyphElt *) (stuff + 1); - origElt = *elt; - xSrc = stuff->xSrc; - ySrc = stuff->ySrc; - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - elt->deltax = origElt.deltax - panoramiXdataPtr[j].x; - elt->deltay = origElt.deltay - panoramiXdataPtr[j].y; - } - result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client); - if(result != Success) break; - } - } - - return result; -} - -static int -PanoramiXRenderFillRectangles (ClientPtr client) -{ - PanoramiXRes *dst; - int result = Success, j; - REQUEST(xRenderFillRectanglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq); - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) - { - memcpy (extra, stuff + 1, extra_len); - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) - { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xRectangle *rects = (xRectangle *) (stuff + 1); - int i = extra_len / sizeof (xRectangle); - - while (i--) - { - rects->x -= x_off; - rects->y -= y_off; - rects++; - } - } - } - stuff->dst = dst->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client); - if(result != Success) break; - } - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -void -PanoramiXRenderInit (void) -{ - int i; - - XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource); - for (i = 0; i < RenderNumberRequests; i++) - PanoramiXSaveRenderVector[i] = ProcRenderVector[i]; - /* - * Stuff in Xinerama aware request processing hooks - */ - ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture; - ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture; - ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles; - ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture; - ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite; - ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles; -} - -void -PanoramiXRenderReset (void) -{ - int i; - for (i = 0; i < RenderNumberRequests; i++) - ProcRenderVector[i] = PanoramiXSaveRenderVector[i]; -} - -#endif /* PANORAMIX */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXresource.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXresource.c.NX.original deleted file mode 100644 index 0c81c81ef..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXresource.c.NX.original +++ /dev/null @@ -1,1103 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXresource.c" - -#else - -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* $Xorg: resource.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ - - -/* $TOG: resource.c /main/41 1998/02/09 14:20:31 kaleb $ */ - -/* Routines to manage various kinds of resources: - * - * CreateNewResourceType, CreateNewResourceClass, InitClientResources, - * FakeClientID, AddResource, FreeResource, FreeClientResources, - * FreeAllResources, LookupIDByType, LookupIDByClass, GetXIDRange - */ - -/* - * A resource ID is a 32 bit quantity, the upper 2 bits of which are - * off-limits for client-visible resources. The next 8 bits are - * used as client ID, and the low 22 bits come from the client. - * A resource ID is "hashed" by extracting and xoring subfields - * (varying with the size of the hash table). - * - * It is sometimes necessary for the server to create an ID that looks - * like it belongs to a client. This ID, however, must not be one - * the client actually can create, or we have the potential for conflict. - * The 31st bit of the ID is reserved for the server's use for this - * purpose. By setting CLIENT_ID(id) to the client, the SERVER_BIT to - * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a - * resource "owned" by the client. - */ -/* $XFree86: xc/programs/Xserver/dix/resource.c,v 3.12 2002/03/06 21:13:38 mvojkovi Exp $ */ - -#define NEED_EVENTS -#include "X.h" -#include "misc.h" -#include "os.h" -#include "resource.h" -#include "dixstruct.h" -#include "opaque.h" -#include "windowstr.h" -#include "dixfont.h" -#include "colormap.h" -#include "inputstr.h" -#include "dixevents.h" -#include "dixgrabs.h" -#include "cursor.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include - -#ifdef NXAGENT_SERVER - -#include "Agent.h" -#include "Font.h" -#include "Pixmaps.h" -#include "GCs.h" - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -#endif - -static void RebuildTable( -#if NeedFunctionPrototypes - int /*client*/ -#endif -); - -#define SERVER_MINID 32 - -#define INITBUCKETS 64 -#define INITHASHSIZE 6 -#define MAXHASHSIZE 11 - -typedef struct _Resource { - struct _Resource *next; - XID id; - RESTYPE type; - pointer value; -} ResourceRec, *ResourcePtr; -#define NullResource ((ResourcePtr)NULL) - -typedef struct _ClientResource { - ResourcePtr *resources; - int elements; - int buckets; - int hashsize; /* log(2)(buckets) */ - XID fakeID; - XID endFakeID; - XID expectID; -} ClientResourceRec; - -RESTYPE lastResourceType; -static RESTYPE lastResourceClass; -RESTYPE TypeMask; - -static DeleteType *DeleteFuncs = (DeleteType *)NULL; - -#ifdef XResExtension - -Atom * ResourceNames = NULL; - -void RegisterResourceName (RESTYPE type, char *name) -{ - ResourceNames[type & TypeMask] = MakeAtom(name, strlen(name), TRUE); -} - -#endif - -RESTYPE -CreateNewResourceType(deleteFunc) - DeleteType deleteFunc; -{ - RESTYPE next = lastResourceType + 1; - DeleteType *funcs; - - if (next & lastResourceClass) - return 0; - funcs = (DeleteType *)xrealloc(DeleteFuncs, - (next + 1) * sizeof(DeleteType)); - if (!funcs) - return 0; - -#ifdef XResExtension - { - Atom *newnames; - newnames = xrealloc(ResourceNames, (next + 1) * sizeof(Atom)); - if(!newnames) - return 0; - ResourceNames = newnames; - ResourceNames[next] = 0; - } -#endif - - lastResourceType = next; - DeleteFuncs = funcs; - DeleteFuncs[next] = deleteFunc; - return next; -} - -RESTYPE -CreateNewResourceClass() -{ - RESTYPE next = lastResourceClass >> 1; - - if (next & lastResourceType) - return 0; - lastResourceClass = next; - TypeMask = next - 1; - return next; -} - -ClientResourceRec clientTable[MAXCLIENTS]; - -/***************** - * InitClientResources - * When a new client is created, call this to allocate space - * in resource table - *****************/ - -Bool -InitClientResources(client) - ClientPtr client; -{ - register int i, j; - - if (client == serverClient) - { - lastResourceType = RT_LASTPREDEF; - lastResourceClass = RC_LASTPREDEF; - TypeMask = RC_LASTPREDEF - 1; - if (DeleteFuncs) - xfree(DeleteFuncs); - DeleteFuncs = (DeleteType *)xalloc((lastResourceType + 1) * - sizeof(DeleteType)); - if (!DeleteFuncs) - return FALSE; - DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA; - DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow; - DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap; - DeleteFuncs[RT_GC & TypeMask] = FreeGC; - DeleteFuncs[RT_FONT & TypeMask] = CloseFont; - DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor; - DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap; - DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels; - DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone; - DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab; - -#ifdef XResExtension - if(ResourceNames) - xfree(ResourceNames); - ResourceNames = xalloc((lastResourceType + 1) * sizeof(Atom)); - if(!ResourceNames) - return FALSE; -#endif - } - clientTable[i = client->index].resources = - (ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr)); - if (!clientTable[i].resources) - return FALSE; - clientTable[i].buckets = INITBUCKETS; - clientTable[i].elements = 0; - clientTable[i].hashsize = INITHASHSIZE; - /* Many IDs allocated from the server client are visible to clients, - * so we don't use the SERVER_BIT for them, but we have to start - * past the magic value constants used in the protocol. For normal - * clients, we can start from zero, with SERVER_BIT set. - */ - clientTable[i].fakeID = client->clientAsMask | - (client->index ? SERVER_BIT : SERVER_MINID); - clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1; - clientTable[i].expectID = client->clientAsMask; - for (j=0; j>6) ^ (id>>12)))); - case 7: - return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13)))); - case 8: - return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16)))); - case 9: - return ((int)(0x1FF & (id ^ (id>>9)))); - case 10: - return ((int)(0x3FF & (id ^ (id>>10)))); - case 11: - return ((int)(0x7FF & (id ^ (id>>11)))); - } - return -1; -} - -static XID -#if NeedFunctionPrototypes -AvailableID( - register int client, - register XID id, - register XID maxid, - register XID goodid) -#else -AvailableID(client, id, maxid, goodid) - register int client; - register XID id, maxid, goodid; -#endif -{ - register ResourcePtr res; - - if ((goodid >= id) && (goodid <= maxid)) - return goodid; - for (; id <= maxid; id++) - { - res = clientTable[client].resources[Hash(client, id)]; - while (res && (res->id != id)) - res = res->next; - if (!res) - return id; - } - return 0; -} - -void -GetXIDRange(client, server, minp, maxp) - int client; - Bool server; - XID *minp, *maxp; -{ - register XID id, maxid; - register ResourcePtr *resp; - register ResourcePtr res; - register int i; - XID goodid; - - id = (Mask)client << CLIENTOFFSET; - if (server) - id |= client ? SERVER_BIT : SERVER_MINID; - maxid = id | RESOURCE_ID_MASK; - goodid = 0; - for (resp = clientTable[client].resources, i = clientTable[client].buckets; - --i >= 0;) - { - for (res = *resp++; res; res = res->next) - { - if ((res->id < id) || (res->id > maxid)) - continue; - if (((res->id - id) >= (maxid - res->id)) ? - (goodid = AvailableID(client, id, res->id - 1, goodid)) : - !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) - maxid = res->id - 1; - else - id = res->id + 1; - } - } - if (id > maxid) - id = maxid = 0; - *minp = id; - *maxp = maxid; -} - -/* GetXIDList is called by the XC-MISC extension's MiscGetXIDList function. - * This function tries to find count unused XIDs for the given client. It - * puts the IDs in the array pids and returns the number found, which should - * almost always be the number requested. - * - * The circumstances that lead to a call to this function are very rare. - * Xlib must run out of IDs while trying to generate a request that wants - * multiple ID's, like the Multi-buffering CreateImageBuffers request. - * - * No rocket science in the implementation; just iterate over all - * possible IDs for the given client and pick the first count IDs - * that aren't in use. A more efficient algorithm could probably be - * invented, but this will be used so rarely that this should suffice. - */ - -unsigned int -GetXIDList(pClient, count, pids) - ClientPtr pClient; - unsigned int count; - XID *pids; -{ - unsigned int found = 0; - XID id = pClient->clientAsMask; - XID maxid; - - maxid = id | RESOURCE_ID_MASK; - while ( (found < count) && (id <= maxid) ) - { - if (!LookupIDByClass(id, RC_ANY)) - { - pids[found++] = id; - } - id++; - } - return found; -} - -/* - * Return the next usable fake client ID. - * - * Normally this is just the next one in line, but if we've used the last - * in the range, we need to find a new range of safe IDs to avoid - * over-running another client. - */ - -XID -FakeClientID(client) - register int client; -{ - XID id, maxid; - - id = clientTable[client].fakeID++; - if (id != clientTable[client].endFakeID) - return id; - GetXIDRange(client, TRUE, &id, &maxid); - if (!id) { - if (!client) - FatalError("FakeClientID: server internal ids exhausted\n"); - MarkClientException(clients[client]); - id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3); - maxid = id | RESOURCE_ID_MASK; - } - clientTable[client].fakeID = id + 1; - clientTable[client].endFakeID = maxid + 1; - return id; -} - -#ifdef NXAGENT_SERVER - -int nxagentFindClientResource(int client, RESTYPE type, pointer value) -{ - ResourcePtr pResource; - ResourcePtr *resources; - - int i; - - for (i = 0; i < clientTable[client].buckets; i++) - { - resources = clientTable[client].resources; - - for (pResource = resources[i]; pResource; pResource = pResource -> next) - { - if (pResource -> type == type && pResource -> value == value) - { - #ifdef TEST - fprintf(stderr, "nxagentFindClientResource: Found resource [%p] type [%lu] " - "for client [%d].\n", (void *) value, - pResource -> type, client); - #endif - - return 1; - } - } - } - - return 0; -} - -int nxagentSwitchResourceType(int client, RESTYPE type, pointer value) -{ - ResourcePtr pResource; - ResourcePtr *resources; - - RESTYPE internalType = 0; - - int i; - - if (type == RT_PIXMAP) - { - internalType = RT_NX_PIXMAP; - } - else if (type == RT_GC) - { - internalType = RT_NX_GC; - } - else if (type == RT_FONT) - { - internalType = RT_NX_FONT; - } - else - { - return 0; - } - - if (client == serverClient -> index) - { - #ifdef TEST - fprintf(stderr, "nxagentSwitchResourceType: Requesting client is [%d]. Skipping the resource switch.\n", - client); - #endif - - return 0; - } - - for (i = 0; i < clientTable[serverClient -> index].buckets; i++) - { - resources = clientTable[serverClient -> index].resources; - - for (pResource = resources[i]; pResource; pResource = pResource -> next) - { - if (pResource -> type == internalType && - pResource -> value == value) - { - #ifdef TEST - fprintf(stderr, "nxagentSwitchResourceType: Changing resource [%p] type from [%lu] to " - "[%lu] for server client [%d].\n", (void *) value, - (unsigned long) pResource -> type, (unsigned long) type, serverClient -> index); - #endif - - FreeResource(pResource -> id, RT_NONE); - - return 1; - } - } - } - - return 0; -} - -#endif - -Bool -AddResource(id, type, value) - XID id; - RESTYPE type; - pointer value; -{ - int client; - register ClientResourceRec *rrec; - register ResourcePtr res, *head; - - client = CLIENT_ID(id); - rrec = &clientTable[client]; - if (!rrec->buckets) - { - ErrorF("AddResource(%x, %x, %x), client=%d \n", - id, type, (unsigned long)value, client); - FatalError("client not in use\n"); - } - -#ifdef NXAGENT_SERVER - - nxagentSwitchResourceType(client, type, value); - - #ifdef TEST - fprintf(stderr, "AddResource: Adding resource for client [%d] type [%lu] value [%p] id [%lu].\n", - client, (unsigned long) type, (void *) value, (unsigned long) id); - #endif - -#endif - - if ((rrec->elements >= 4*rrec->buckets) && - (rrec->hashsize < MAXHASHSIZE)) - RebuildTable(client); - head = &rrec->resources[Hash(client, id)]; - res = (ResourcePtr)xalloc(sizeof(ResourceRec)); - if (!res) - { - (*DeleteFuncs[type & TypeMask])(value, id); - return FALSE; - } - res->next = *head; - res->id = id; - res->type = type; - res->value = value; - *head = res; - rrec->elements++; - if (!(id & SERVER_BIT) && (id >= rrec->expectID)) - rrec->expectID = id + 1; - return TRUE; -} - -static void -RebuildTable(client) - int client; -{ - register int j; - register ResourcePtr res, next; - ResourcePtr **tails, *resources; - register ResourcePtr **tptr, *rptr; - - /* - * For now, preserve insertion order, since some ddx layers depend - * on resources being free in the opposite order they are added. - */ - - j = 2 * clientTable[client].buckets; - tails = (ResourcePtr **)ALLOCATE_LOCAL(j * sizeof(ResourcePtr *)); - if (!tails) - return; - resources = (ResourcePtr *)xalloc(j * sizeof(ResourcePtr)); - if (!resources) - { - DEALLOCATE_LOCAL(tails); - return; - } - for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) - { - *rptr = NullResource; - *tptr = rptr; - } - clientTable[client].hashsize++; - for (j = clientTable[client].buckets, - rptr = clientTable[client].resources; - --j >= 0; - rptr++) - { - for (res = *rptr; res; res = next) - { - next = res->next; - res->next = NullResource; - tptr = &tails[Hash(client, res->id)]; - **tptr = res; - *tptr = &res->next; - } - } - DEALLOCATE_LOCAL(tails); - clientTable[client].buckets *= 2; - xfree(clientTable[client].resources); - clientTable[client].resources = resources; -} - -void -FreeResource(id, skipDeleteFuncType) - XID id; - RESTYPE skipDeleteFuncType; -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - register int *eltptr; - int elements; - Bool gotOne = FALSE; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - eltptr = &clientTable[cid].elements; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id) - { - RESTYPE rtype = res->type; - *prev = res->next; - elements = --*eltptr; - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - if (rtype != skipDeleteFuncType) - (*DeleteFuncs[rtype & TypeMask])(res->value, res->id); - xfree(res); - if (*eltptr != elements) - prev = head; /* prev may no longer be valid */ - gotOne = TRUE; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } - if (!gotOne) - FatalError("Freeing resource id=%X which isn't there", id); -} - - -void -FreeResourceByType(id, type, skipFree) - XID id; - RESTYPE type; - Bool skipFree; -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id && res->type == type) - { - *prev = res->next; - if (type & RC_CACHED) - FlushClientCaches(res->id); - if (!skipFree) - (*DeleteFuncs[type & TypeMask])(res->value, res->id); - xfree(res); - break; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } -} - -/* - * Change the value associated with a resource id. Caller - * is responsible for "doing the right thing" with the old - * data - */ - -Bool -ChangeResourceValue (id, rtype, value) - XID id; - RESTYPE rtype; - pointer value; -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - res->value = value; - return TRUE; - } - } - return FALSE; -} - -/* Note: if func adds or deletes resources, then func can get called - * more than once for some resources. If func adds new resources, - * func might or might not get called for them. func cannot both - * add and delete an equal number of resources! - */ - -void -FindClientResourcesByType( - ClientPtr client, - RESTYPE type, - FindResType func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - if (!type || this->type == type) { - elements = *eltptr; - (*func)(this->value, this->id, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } - } -} - -void -FindAllClientResources( - ClientPtr client, - FindAllRes func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - elements = *eltptr; - (*func)(this->value, this->id, this->type, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } -} - - -pointer -LookupClientResourceComplex( - ClientPtr client, - RESTYPE type, - FindComplexResType func, - pointer cdata -){ - ResourcePtr *resources; - ResourcePtr this; - int i; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - for (i = 0; i < clientTable[client->index].buckets; i++) { - for (this = resources[i]; this; this = this->next) { - if (!type || this->type == type) { - if((*func)(this->value, this->id, cdata)) - return this->value; - } - } - } - return NULL; -} - - -void -FreeClientNeverRetainResources(ClientPtr client) -{ - ResourcePtr *resources; - ResourcePtr this; - ResourcePtr *prev; - int j; - - if (!client) - return; - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - prev = &resources[j]; - while ( (this = *prev) ) - { - RESTYPE rtype = this->type; - if (rtype & RC_NEVERRETAIN) - { - *prev = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - else - prev = &this->next; - } - } -} - -void -FreeClientResources(client) - ClientPtr client; -{ - register ResourcePtr *resources; - register ResourcePtr this; - int j; - - /* This routine shouldn't be called with a null client, but just in - case ... */ - - if (!client) - return; - - HandleSaveSet(client); - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - /* It may seem silly to update the head of this resource list as - we delete the members, since the entire list will be deleted any way, - but there are some resource deletion functions "FreeClientPixels" for - one which do a LookupID on another resource id (a Colormap id in this - case), so the resource list must be kept valid up to the point that - it is deleted, so every time we delete a resource, we must update the - head, just like in FreeResource. I hope that this doesn't slow down - mass deletion appreciably. PRH */ - - ResourcePtr *head; - - head = &resources[j]; - - for (this = *head; this; this = *head) - { - RESTYPE rtype = this->type; - *head = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - } - xfree(clientTable[client->index].resources); - clientTable[client->index].resources = NULL; - clientTable[client->index].buckets = 0; -} - -void -FreeAllResources() -{ - int i; - - for (i = currentMaxClients; --i >= 0; ) - { - if (clientTable[i].buckets) - FreeClientResources(clients[i]); - } -} - -Bool -LegalNewID(id, client) - XID id; - register ClientPtr client; -{ - -#ifdef PANORAMIX - XID minid, maxid; - - if (!noPanoramiXExtension) { - minid = client->clientAsMask | (client->index ? - SERVER_BIT : SERVER_MINID); - maxid = (clientTable[client->index].fakeID | RESOURCE_ID_MASK) + 1; - if ((id >= minid) && (id <= maxid)) - return TRUE; - } -#endif /* PANORAMIX */ - return ((client->clientAsMask == (id & ~RESOURCE_ID_MASK)) && - ((clientTable[client->index].expectID <= id) || - !LookupIDByClass(id, RC_ANY))); -} - -#ifdef XCSECURITY - -/* SecurityLookupIDByType and SecurityLookupIDByClass: - * These are the heart of the resource ID security system. They take - * two additional arguments compared to the old LookupID functions: - * the client doing the lookup, and the access mode (see resource.h). - * The resource is returned if it exists and the client is allowed access, - * else NULL is returned. - */ - -pointer -SecurityLookupIDByType(client, id, rtype, mode) - ClientPtr client; - XID id; - RESTYPE rtype; - Mask mode; -{ - int cid; - register ResourcePtr res; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert( (rtype & TypeMask) <= lastResourceType); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, rtype, mode, retval); - return retval; -} - - -pointer -SecurityLookupIDByClass(client, id, classes, mode) - ClientPtr client; - XID id; - RESTYPE classes; - Mask mode; -{ - int cid; - register ResourcePtr res = NULL; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert (classes >= lastResourceClass); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, res->type, mode, retval); - return retval; -} - -/* We can't replace the LookupIDByType and LookupIDByClass functions with - * macros because of compatibility with loadable servers. - */ - -pointer -LookupIDByType(id, rtype) - XID id; - RESTYPE rtype; -{ - return SecurityLookupIDByType(NullClient, id, rtype, - SecurityUnknownAccess); -} - -pointer -LookupIDByClass(id, classes) - XID id; - RESTYPE classes; -{ - return SecurityLookupIDByClass(NullClient, id, classes, - SecurityUnknownAccess); -} - -#else /* not XCSECURITY */ - -/* - * LookupIDByType returns the object with the given id and type, else NULL. - */ -pointer -LookupIDByType(id, rtype) - XID id; - RESTYPE rtype; -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - return res->value; - } - return (pointer)NULL; -} - -/* - * LookupIDByClass returns the object with the given id and any one of the - * given classes, else NULL. - */ -pointer -LookupIDByClass(id, classes) - XID id; - RESTYPE classes; -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - return res->value; - } - return (pointer)NULL; -} - -#endif /* XCSECURITY */ - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXresource.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXresource.c.XF86.original deleted file mode 100644 index d17586a77..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXresource.c.XF86.original +++ /dev/null @@ -1,975 +0,0 @@ -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* $Xorg: resource.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ - - -/* $TOG: resource.c /main/41 1998/02/09 14:20:31 kaleb $ */ - -/* Routines to manage various kinds of resources: - * - * CreateNewResourceType, CreateNewResourceClass, InitClientResources, - * FakeClientID, AddResource, FreeResource, FreeClientResources, - * FreeAllResources, LookupIDByType, LookupIDByClass, GetXIDRange - */ - -/* - * A resource ID is a 32 bit quantity, the upper 2 bits of which are - * off-limits for client-visible resources. The next 8 bits are - * used as client ID, and the low 22 bits come from the client. - * A resource ID is "hashed" by extracting and xoring subfields - * (varying with the size of the hash table). - * - * It is sometimes necessary for the server to create an ID that looks - * like it belongs to a client. This ID, however, must not be one - * the client actually can create, or we have the potential for conflict. - * The 31st bit of the ID is reserved for the server's use for this - * purpose. By setting CLIENT_ID(id) to the client, the SERVER_BIT to - * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a - * resource "owned" by the client. - */ -/* $XFree86: xc/programs/Xserver/dix/resource.c,v 3.12 2002/03/06 21:13:38 mvojkovi Exp $ */ - -#define NEED_EVENTS -#include "X.h" -#include "misc.h" -#include "os.h" -#include "resource.h" -#include "dixstruct.h" -#include "opaque.h" -#include "windowstr.h" -#include "dixfont.h" -#include "colormap.h" -#include "inputstr.h" -#include "dixevents.h" -#include "dixgrabs.h" -#include "cursor.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include - -static void RebuildTable( -#if NeedFunctionPrototypes - int /*client*/ -#endif -); - -#define SERVER_MINID 32 - -#define INITBUCKETS 64 -#define INITHASHSIZE 6 -#define MAXHASHSIZE 11 - -typedef struct _Resource { - struct _Resource *next; - XID id; - RESTYPE type; - pointer value; -} ResourceRec, *ResourcePtr; -#define NullResource ((ResourcePtr)NULL) - -typedef struct _ClientResource { - ResourcePtr *resources; - int elements; - int buckets; - int hashsize; /* log(2)(buckets) */ - XID fakeID; - XID endFakeID; - XID expectID; -} ClientResourceRec; - -RESTYPE lastResourceType; -static RESTYPE lastResourceClass; -RESTYPE TypeMask; - -static DeleteType *DeleteFuncs = (DeleteType *)NULL; - -#ifdef XResExtension - -Atom * ResourceNames = NULL; - -void RegisterResourceName (RESTYPE type, char *name) -{ - ResourceNames[type & TypeMask] = MakeAtom(name, strlen(name), TRUE); -} - -#endif - -RESTYPE -CreateNewResourceType(deleteFunc) - DeleteType deleteFunc; -{ - RESTYPE next = lastResourceType + 1; - DeleteType *funcs; - - if (next & lastResourceClass) - return 0; - funcs = (DeleteType *)xrealloc(DeleteFuncs, - (next + 1) * sizeof(DeleteType)); - if (!funcs) - return 0; - -#ifdef XResExtension - { - Atom *newnames; - newnames = xrealloc(ResourceNames, (next + 1) * sizeof(Atom)); - if(!newnames) - return 0; - ResourceNames = newnames; - ResourceNames[next] = 0; - } -#endif - - lastResourceType = next; - DeleteFuncs = funcs; - DeleteFuncs[next] = deleteFunc; - return next; -} - -RESTYPE -CreateNewResourceClass() -{ - RESTYPE next = lastResourceClass >> 1; - - if (next & lastResourceType) - return 0; - lastResourceClass = next; - TypeMask = next - 1; - return next; -} - -ClientResourceRec clientTable[MAXCLIENTS]; - -/***************** - * InitClientResources - * When a new client is created, call this to allocate space - * in resource table - *****************/ - -Bool -InitClientResources(client) - ClientPtr client; -{ - register int i, j; - - if (client == serverClient) - { - lastResourceType = RT_LASTPREDEF; - lastResourceClass = RC_LASTPREDEF; - TypeMask = RC_LASTPREDEF - 1; - if (DeleteFuncs) - xfree(DeleteFuncs); - DeleteFuncs = (DeleteType *)xalloc((lastResourceType + 1) * - sizeof(DeleteType)); - if (!DeleteFuncs) - return FALSE; - DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA; - DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow; - DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap; - DeleteFuncs[RT_GC & TypeMask] = FreeGC; - DeleteFuncs[RT_FONT & TypeMask] = CloseFont; - DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor; - DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap; - DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels; - DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone; - DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab; - -#ifdef XResExtension - if(ResourceNames) - xfree(ResourceNames); - ResourceNames = xalloc((lastResourceType + 1) * sizeof(Atom)); - if(!ResourceNames) - return FALSE; -#endif - } - clientTable[i = client->index].resources = - (ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr)); - if (!clientTable[i].resources) - return FALSE; - clientTable[i].buckets = INITBUCKETS; - clientTable[i].elements = 0; - clientTable[i].hashsize = INITHASHSIZE; - /* Many IDs allocated from the server client are visible to clients, - * so we don't use the SERVER_BIT for them, but we have to start - * past the magic value constants used in the protocol. For normal - * clients, we can start from zero, with SERVER_BIT set. - */ - clientTable[i].fakeID = client->clientAsMask | - (client->index ? SERVER_BIT : SERVER_MINID); - clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1; - clientTable[i].expectID = client->clientAsMask; - for (j=0; j>6) ^ (id>>12)))); - case 7: - return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13)))); - case 8: - return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16)))); - case 9: - return ((int)(0x1FF & (id ^ (id>>9)))); - case 10: - return ((int)(0x3FF & (id ^ (id>>10)))); - case 11: - return ((int)(0x7FF & (id ^ (id>>11)))); - } - return -1; -} - -static XID -#if NeedFunctionPrototypes -AvailableID( - register int client, - register XID id, - register XID maxid, - register XID goodid) -#else -AvailableID(client, id, maxid, goodid) - register int client; - register XID id, maxid, goodid; -#endif -{ - register ResourcePtr res; - - if ((goodid >= id) && (goodid <= maxid)) - return goodid; - for (; id <= maxid; id++) - { - res = clientTable[client].resources[Hash(client, id)]; - while (res && (res->id != id)) - res = res->next; - if (!res) - return id; - } - return 0; -} - -void -GetXIDRange(client, server, minp, maxp) - int client; - Bool server; - XID *minp, *maxp; -{ - register XID id, maxid; - register ResourcePtr *resp; - register ResourcePtr res; - register int i; - XID goodid; - - id = (Mask)client << CLIENTOFFSET; - if (server) - id |= client ? SERVER_BIT : SERVER_MINID; - maxid = id | RESOURCE_ID_MASK; - goodid = 0; - for (resp = clientTable[client].resources, i = clientTable[client].buckets; - --i >= 0;) - { - for (res = *resp++; res; res = res->next) - { - if ((res->id < id) || (res->id > maxid)) - continue; - if (((res->id - id) >= (maxid - res->id)) ? - (goodid = AvailableID(client, id, res->id - 1, goodid)) : - !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) - maxid = res->id - 1; - else - id = res->id + 1; - } - } - if (id > maxid) - id = maxid = 0; - *minp = id; - *maxp = maxid; -} - -/* GetXIDList is called by the XC-MISC extension's MiscGetXIDList function. - * This function tries to find count unused XIDs for the given client. It - * puts the IDs in the array pids and returns the number found, which should - * almost always be the number requested. - * - * The circumstances that lead to a call to this function are very rare. - * Xlib must run out of IDs while trying to generate a request that wants - * multiple ID's, like the Multi-buffering CreateImageBuffers request. - * - * No rocket science in the implementation; just iterate over all - * possible IDs for the given client and pick the first count IDs - * that aren't in use. A more efficient algorithm could probably be - * invented, but this will be used so rarely that this should suffice. - */ - -unsigned int -GetXIDList(pClient, count, pids) - ClientPtr pClient; - unsigned int count; - XID *pids; -{ - unsigned int found = 0; - XID id = pClient->clientAsMask; - XID maxid; - - maxid = id | RESOURCE_ID_MASK; - while ( (found < count) && (id <= maxid) ) - { - if (!LookupIDByClass(id, RC_ANY)) - { - pids[found++] = id; - } - id++; - } - return found; -} - -/* - * Return the next usable fake client ID. - * - * Normally this is just the next one in line, but if we've used the last - * in the range, we need to find a new range of safe IDs to avoid - * over-running another client. - */ - -XID -FakeClientID(client) - register int client; -{ - XID id, maxid; - - id = clientTable[client].fakeID++; - if (id != clientTable[client].endFakeID) - return id; - GetXIDRange(client, TRUE, &id, &maxid); - if (!id) { - if (!client) - FatalError("FakeClientID: server internal ids exhausted\n"); - MarkClientException(clients[client]); - id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3); - maxid = id | RESOURCE_ID_MASK; - } - clientTable[client].fakeID = id + 1; - clientTable[client].endFakeID = maxid + 1; - return id; -} - -Bool -AddResource(id, type, value) - XID id; - RESTYPE type; - pointer value; -{ - int client; - register ClientResourceRec *rrec; - register ResourcePtr res, *head; - - client = CLIENT_ID(id); - rrec = &clientTable[client]; - if (!rrec->buckets) - { - ErrorF("AddResource(%x, %x, %x), client=%d \n", - id, type, (unsigned long)value, client); - FatalError("client not in use\n"); - } - if ((rrec->elements >= 4*rrec->buckets) && - (rrec->hashsize < MAXHASHSIZE)) - RebuildTable(client); - head = &rrec->resources[Hash(client, id)]; - res = (ResourcePtr)xalloc(sizeof(ResourceRec)); - if (!res) - { - (*DeleteFuncs[type & TypeMask])(value, id); - return FALSE; - } - res->next = *head; - res->id = id; - res->type = type; - res->value = value; - *head = res; - rrec->elements++; - if (!(id & SERVER_BIT) && (id >= rrec->expectID)) - rrec->expectID = id + 1; - return TRUE; -} - -static void -RebuildTable(client) - int client; -{ - register int j; - register ResourcePtr res, next; - ResourcePtr **tails, *resources; - register ResourcePtr **tptr, *rptr; - - /* - * For now, preserve insertion order, since some ddx layers depend - * on resources being free in the opposite order they are added. - */ - - j = 2 * clientTable[client].buckets; - tails = (ResourcePtr **)ALLOCATE_LOCAL(j * sizeof(ResourcePtr *)); - if (!tails) - return; - resources = (ResourcePtr *)xalloc(j * sizeof(ResourcePtr)); - if (!resources) - { - DEALLOCATE_LOCAL(tails); - return; - } - for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) - { - *rptr = NullResource; - *tptr = rptr; - } - clientTable[client].hashsize++; - for (j = clientTable[client].buckets, - rptr = clientTable[client].resources; - --j >= 0; - rptr++) - { - for (res = *rptr; res; res = next) - { - next = res->next; - res->next = NullResource; - tptr = &tails[Hash(client, res->id)]; - **tptr = res; - *tptr = &res->next; - } - } - DEALLOCATE_LOCAL(tails); - clientTable[client].buckets *= 2; - xfree(clientTable[client].resources); - clientTable[client].resources = resources; -} - -void -FreeResource(id, skipDeleteFuncType) - XID id; - RESTYPE skipDeleteFuncType; -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - register int *eltptr; - int elements; - Bool gotOne = FALSE; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - eltptr = &clientTable[cid].elements; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id) - { - RESTYPE rtype = res->type; - *prev = res->next; - elements = --*eltptr; - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - if (rtype != skipDeleteFuncType) - (*DeleteFuncs[rtype & TypeMask])(res->value, res->id); - xfree(res); - if (*eltptr != elements) - prev = head; /* prev may no longer be valid */ - gotOne = TRUE; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } - if (!gotOne) - FatalError("Freeing resource id=%X which isn't there", id); -} - - -void -FreeResourceByType(id, type, skipFree) - XID id; - RESTYPE type; - Bool skipFree; -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id && res->type == type) - { - *prev = res->next; - if (type & RC_CACHED) - FlushClientCaches(res->id); - if (!skipFree) - (*DeleteFuncs[type & TypeMask])(res->value, res->id); - xfree(res); - break; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } -} - -/* - * Change the value associated with a resource id. Caller - * is responsible for "doing the right thing" with the old - * data - */ - -Bool -ChangeResourceValue (id, rtype, value) - XID id; - RESTYPE rtype; - pointer value; -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - res->value = value; - return TRUE; - } - } - return FALSE; -} - -/* Note: if func adds or deletes resources, then func can get called - * more than once for some resources. If func adds new resources, - * func might or might not get called for them. func cannot both - * add and delete an equal number of resources! - */ - -void -FindClientResourcesByType( - ClientPtr client, - RESTYPE type, - FindResType func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - if (!type || this->type == type) { - elements = *eltptr; - (*func)(this->value, this->id, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } - } -} - -void -FindAllClientResources( - ClientPtr client, - FindAllRes func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - elements = *eltptr; - (*func)(this->value, this->id, this->type, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } -} - - -pointer -LookupClientResourceComplex( - ClientPtr client, - RESTYPE type, - FindComplexResType func, - pointer cdata -){ - ResourcePtr *resources; - ResourcePtr this; - int i; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - for (i = 0; i < clientTable[client->index].buckets; i++) { - for (this = resources[i]; this; this = this->next) { - if (!type || this->type == type) { - if((*func)(this->value, this->id, cdata)) - return this->value; - } - } - } - return NULL; -} - - -void -FreeClientNeverRetainResources(ClientPtr client) -{ - ResourcePtr *resources; - ResourcePtr this; - ResourcePtr *prev; - int j; - - if (!client) - return; - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - prev = &resources[j]; - while ( (this = *prev) ) - { - RESTYPE rtype = this->type; - if (rtype & RC_NEVERRETAIN) - { - *prev = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - else - prev = &this->next; - } - } -} - -void -FreeClientResources(client) - ClientPtr client; -{ - register ResourcePtr *resources; - register ResourcePtr this; - int j; - - /* This routine shouldn't be called with a null client, but just in - case ... */ - - if (!client) - return; - - HandleSaveSet(client); - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - /* It may seem silly to update the head of this resource list as - we delete the members, since the entire list will be deleted any way, - but there are some resource deletion functions "FreeClientPixels" for - one which do a LookupID on another resource id (a Colormap id in this - case), so the resource list must be kept valid up to the point that - it is deleted, so every time we delete a resource, we must update the - head, just like in FreeResource. I hope that this doesn't slow down - mass deletion appreciably. PRH */ - - ResourcePtr *head; - - head = &resources[j]; - - for (this = *head; this; this = *head) - { - RESTYPE rtype = this->type; - *head = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - } - xfree(clientTable[client->index].resources); - clientTable[client->index].resources = NULL; - clientTable[client->index].buckets = 0; -} - -void -FreeAllResources() -{ - int i; - - for (i = currentMaxClients; --i >= 0; ) - { - if (clientTable[i].buckets) - FreeClientResources(clients[i]); - } -} - -Bool -LegalNewID(id, client) - XID id; - register ClientPtr client; -{ - -#ifdef PANORAMIX - XID minid, maxid; - - if (!noPanoramiXExtension) { - minid = client->clientAsMask | (client->index ? - SERVER_BIT : SERVER_MINID); - maxid = (clientTable[client->index].fakeID | RESOURCE_ID_MASK) + 1; - if ((id >= minid) && (id <= maxid)) - return TRUE; - } -#endif /* PANORAMIX */ - return ((client->clientAsMask == (id & ~RESOURCE_ID_MASK)) && - ((clientTable[client->index].expectID <= id) || - !LookupIDByClass(id, RC_ANY))); -} - -#ifdef XCSECURITY - -/* SecurityLookupIDByType and SecurityLookupIDByClass: - * These are the heart of the resource ID security system. They take - * two additional arguments compared to the old LookupID functions: - * the client doing the lookup, and the access mode (see resource.h). - * The resource is returned if it exists and the client is allowed access, - * else NULL is returned. - */ - -pointer -SecurityLookupIDByType(client, id, rtype, mode) - ClientPtr client; - XID id; - RESTYPE rtype; - Mask mode; -{ - int cid; - register ResourcePtr res; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert( (rtype & TypeMask) <= lastResourceType); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, rtype, mode, retval); - return retval; -} - - -pointer -SecurityLookupIDByClass(client, id, classes, mode) - ClientPtr client; - XID id; - RESTYPE classes; - Mask mode; -{ - int cid; - register ResourcePtr res = NULL; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert (classes >= lastResourceClass); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, res->type, mode, retval); - return retval; -} - -/* We can't replace the LookupIDByType and LookupIDByClass functions with - * macros because of compatibility with loadable servers. - */ - -pointer -LookupIDByType(id, rtype) - XID id; - RESTYPE rtype; -{ - return SecurityLookupIDByType(NullClient, id, rtype, - SecurityUnknownAccess); -} - -pointer -LookupIDByClass(id, classes) - XID id; - RESTYPE classes; -{ - return SecurityLookupIDByClass(NullClient, id, classes, - SecurityUnknownAccess); -} - -#else /* not XCSECURITY */ - -/* - * LookupIDByType returns the object with the given id and type, else NULL. - */ -pointer -LookupIDByType(id, rtype) - XID id; - RESTYPE rtype; -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - return res->value; - } - return (pointer)NULL; -} - -/* - * LookupIDByClass returns the object with the given id and any one of the - * given classes, else NULL. - */ -pointer -LookupIDByClass(id, classes) - XID id; - RESTYPE classes; -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - return res->value; - } - return (pointer)NULL; -} - -#endif /* XCSECURITY */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXshm.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXshm.c.NX.original deleted file mode 100644 index e70415a7d..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXshm.c.NX.original +++ /dev/null @@ -1,1425 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXshm.c" - -#else - -/* $XFree86: xc/programs/Xserver/Xext/shm.c,v 3.36 2002/04/03 19:51:11 herrb Exp $ */ -/************************************************************ - -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -********************************************************/ - -/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */ - -/* $Xorg: shm.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */ - -#include -#ifndef Lynx -#include -#include -#else -#include -#include -#endif -#include -#include -#define NEED_REPLIES -#define NEED_EVENTS -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "extnsionst.h" -#include "servermd.h" -#define _XSHM_SERVER_ -#include "shmstr.h" -#include "Xfuncproto.h" -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -#include "Trap.h" -#include "Agent.h" -#include "Drawable.h" -#include "Pixmaps.h" - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -extern void fbGetImage(DrawablePtr pDrw, int x, int y, int w, int h, - unsigned int format, unsigned long planeMask, char *d); - -extern void fbPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, - int x, int y, int w, int h, int leftPad, int format, - char *pImage); - -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -static void miShmPutImage(XSHM_PUT_IMAGE_ARGS); -static void fbShmPutImage(XSHM_PUT_IMAGE_ARGS); -static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS); -static int ShmDetachSegment( -#if NeedFunctionPrototypes - pointer /* value */, - XID /* shmseg */ -#endif - ); -static void ShmResetProc( -#if NeedFunctionPrototypes - ExtensionEntry * /* extEntry */ -#endif - ); -static void SShmCompletionEvent( -#if NeedFunctionPrototypes - xShmCompletionEvent * /* from */, - xShmCompletionEvent * /* to */ -#endif - ); - -static Bool ShmDestroyPixmap (PixmapPtr pPixmap); - -static DISPATCH_PROC(ProcShmAttach); -static DISPATCH_PROC(ProcShmCreatePixmap); -static DISPATCH_PROC(ProcShmDetach); -static DISPATCH_PROC(ProcShmDispatch); -static DISPATCH_PROC(ProcShmGetImage); -static DISPATCH_PROC(ProcShmPutImage); -static DISPATCH_PROC(ProcShmQueryVersion); -static DISPATCH_PROC(SProcShmAttach); -static DISPATCH_PROC(SProcShmCreatePixmap); -static DISPATCH_PROC(SProcShmDetach); -static DISPATCH_PROC(SProcShmDispatch); -static DISPATCH_PROC(SProcShmGetImage); -static DISPATCH_PROC(SProcShmPutImage); -static DISPATCH_PROC(SProcShmQueryVersion); - -static unsigned char ShmReqCode; -int ShmCompletionCode; -int BadShmSegCode; -RESTYPE ShmSegType; -static ShmDescPtr Shmsegs; -static Bool sharedPixmaps; -static int pixmapFormat; -static int shmPixFormat[MAXSCREENS]; -static ShmFuncsPtr shmFuncs[MAXSCREENS]; -static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS]; -#ifdef PIXPRIV -static int shmPixmapPrivate; -#endif -static ShmFuncs miFuncs = {NULL, miShmPutImage}; -static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage}; - -#define VERIFY_SHMSEG(shmseg,shmdesc,client) \ -{ \ - shmdesc = (ShmDescPtr)LookupIDByType(shmseg, ShmSegType); \ - if (!shmdesc) \ - { \ - client->errorValue = shmseg; \ - return BadShmSegCode; \ - } \ -} - -#define VERIFY_SHMPTR(shmseg,offset,needwrite,shmdesc,client) \ -{ \ - VERIFY_SHMSEG(shmseg, shmdesc, client); \ - if ((offset & 3) || (offset > shmdesc->size)) \ - { \ - client->errorValue = offset; \ - return BadValue; \ - } \ - if (needwrite && !shmdesc->writable) \ - return BadAccess; \ -} - -#define VERIFY_SHMSIZE(shmdesc,offset,len,client) \ -{ \ - if ((offset + len) > shmdesc->size) \ - { \ - return BadAccess; \ - } \ -} - - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) -#include - -static Bool badSysCall = FALSE; - -static void -SigSysHandler(signo) -int signo; -{ - badSysCall = TRUE; -} - -static Bool CheckForShmSyscall() -{ - void (*oldHandler)(); - int shmid = -1; - - /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */ - oldHandler = signal(SIGSYS, SigSysHandler); - - badSysCall = FALSE; - shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT); - /* Clean up */ - if (shmid != -1) - { - shmctl(shmid, IPC_RMID, (struct shmid_ds *)NULL); - } - signal(SIGSYS, oldHandler); - return(!badSysCall); -} -#endif - -void -ShmExtensionInit() -{ - ExtensionEntry *extEntry; - int i; - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) - if (!CheckForShmSyscall()) - { - ErrorF("MIT-SHM extension disabled due to lack of kernel support\n"); - return; - } -#endif - - if (nxagentOption(SharedMemory) == False) - { - return; - } - - sharedPixmaps = xFalse; - pixmapFormat = 0; - { - sharedPixmaps = nxagentOption(SharedPixmaps); - pixmapFormat = shmPixFormat[0]; - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!shmFuncs[i]) - { - #ifdef TEST - fprintf(stderr, "ShmExtensionInit: Registering shmFuncs as miFuncs.\n"); - #endif - shmFuncs[i] = &miFuncs; - } - if (!shmFuncs[i]->CreatePixmap) - sharedPixmaps = xFalse; - if (shmPixFormat[i] && (shmPixFormat[i] != pixmapFormat)) - { - sharedPixmaps = xFalse; - pixmapFormat = 0; - } - } - if (!pixmapFormat) - pixmapFormat = ZPixmap; - if (sharedPixmaps) - { - for (i = 0; i < screenInfo.numScreens; i++) - { - destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap; - screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap; - } -#ifdef PIXPRIV - shmPixmapPrivate = AllocatePixmapPrivateIndex(); - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!AllocatePixmapPrivate(screenInfo.screens[i], - shmPixmapPrivate, 0)) - return; - } -#endif - } - } - ShmSegType = CreateNewResourceType(ShmDetachSegment); - if (ShmSegType && - (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors, - ProcShmDispatch, SProcShmDispatch, - ShmResetProc, StandardMinorOpcode))) - { - ShmReqCode = (unsigned char)extEntry->base; - ShmCompletionCode = extEntry->eventBase; - BadShmSegCode = extEntry->errorBase; - EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent; - } -} - -/*ARGSUSED*/ -static void -ShmResetProc (extEntry) -ExtensionEntry *extEntry; -{ - int i; - - for (i = 0; i < MAXSCREENS; i++) - { - shmFuncs[i] = (ShmFuncsPtr)NULL; - shmPixFormat[i] = 0; - } -} - -void -ShmRegisterFuncs(pScreen, funcs) - ScreenPtr pScreen; - ShmFuncsPtr funcs; -{ - shmFuncs[pScreen->myNum] = funcs; -} - -void -ShmSetPixmapFormat(pScreen, format) - ScreenPtr pScreen; - int format; -{ - shmPixFormat[pScreen->myNum] = format; -} - -static Bool -ShmDestroyPixmap (PixmapPtr pPixmap) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - Bool ret; - if (pPixmap->refcnt == 1) - { - ShmDescPtr shmdesc; -#ifdef PIXPRIV - shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr; -#else - char *base = (char *) pPixmap->devPrivate.ptr; - - if (base != (pointer) (pPixmap + 1)) - { - for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) - { - if (shmdesc->addr <= base && base <= shmdesc->addr + shmdesc->size) - break; - } - } - else - shmdesc = 0; -#endif - if (shmdesc) - ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id); - } - - pScreen->DestroyPixmap = destroyPixmap[pScreen->myNum]; - ret = (*pScreen->DestroyPixmap) (pPixmap); - destroyPixmap[pScreen->myNum] = pScreen->DestroyPixmap; - pScreen->DestroyPixmap = ShmDestroyPixmap; - return ret; -} - -void -ShmRegisterFbFuncs(pScreen) - ScreenPtr pScreen; -{ - #ifdef TEST - fprintf(stderr, "ShmRegisterFbFuncs: Registering shmFuncs as fbFuncs.\n"); - #endif - shmFuncs[pScreen->myNum] = &fbFuncs; -} - -static int -ProcShmQueryVersion(client) - register ClientPtr client; -{ - xShmQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xShmQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.sharedPixmaps = sharedPixmaps; - rep.pixmapFormat = pixmapFormat; - rep.majorVersion = SHM_MAJOR_VERSION; - rep.minorVersion = SHM_MINOR_VERSION; - rep.uid = geteuid(); - rep.gid = getegid(); - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - swaps(&rep.uid, n); - swaps(&rep.gid, n); - } - WriteToClient(client, sizeof(xShmQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -/* - * Simulate the access() system call for a shared memory segement, - * using the credentials from the client if available - */ -static int -shm_access(ClientPtr client, struct ipc_perm *perm, int readonly) -{ - int uid, gid; - mode_t mask; - - if (LocalClientCred(client, &uid, &gid) != -1) { - - /* User id 0 always gets access */ - if (uid == 0) { - return 0; - } - /* Check the owner */ - if (perm->uid == uid || perm->cuid == uid) { - mask = S_IRUSR; - if (!readonly) { - mask |= S_IWUSR; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - /* Check the group */ - if (perm->gid == gid || perm->cgid == gid) { - mask = S_IRGRP; - if (!readonly) { - mask |= S_IWGRP; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - } - /* Otherwise, check everyone else */ - mask = S_IROTH; - if (!readonly) { - mask |= S_IWOTH; - } - return (perm->mode & mask) == mask ? 0 : -1; -} - -static int -ProcShmAttach(client) - register ClientPtr client; -{ - struct shmid_ds buf; - ShmDescPtr shmdesc; - REQUEST(xShmAttachReq); - - REQUEST_SIZE_MATCH(xShmAttachReq); - LEGAL_NEW_RESOURCE(stuff->shmseg, client); - if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) - { - client->errorValue = stuff->readOnly; - return(BadValue); - } - for (shmdesc = Shmsegs; - shmdesc && (shmdesc->shmid != stuff->shmid); - shmdesc = shmdesc->next) - ; - if (shmdesc) - { - if (!stuff->readOnly && !shmdesc->writable) - return BadAccess; - shmdesc->refcnt++; - } - else - { - shmdesc = (ShmDescPtr) xalloc(sizeof(ShmDescRec)); - if (!shmdesc) - return BadAlloc; - shmdesc->addr = shmat(stuff->shmid, 0, - stuff->readOnly ? SHM_RDONLY : 0); - if ((shmdesc->addr == ((char *)-1)) || - shmctl(stuff->shmid, IPC_STAT, &buf)) - { - xfree(shmdesc); - return BadAccess; - } - - /* The attach was performed with root privs. We must - * do manual checking of access rights for the credentials - * of the client */ - - if (shm_access(client, &(buf.shm_perm), stuff->readOnly) == -1) { - shmdt(shmdesc->addr); - xfree(shmdesc); - return BadAccess; - } - - shmdesc->shmid = stuff->shmid; - shmdesc->refcnt = 1; - shmdesc->writable = !stuff->readOnly; - shmdesc->size = buf.shm_segsz; - shmdesc->next = Shmsegs; - Shmsegs = shmdesc; - } - if (!AddResource(stuff->shmseg, ShmSegType, (pointer)shmdesc)) - return BadAlloc; - return(client->noClientException); -} - -/*ARGSUSED*/ -static int -ShmDetachSegment(value, shmseg) - pointer value; /* must conform to DeleteType */ - XID shmseg; -{ - ShmDescPtr shmdesc = (ShmDescPtr)value; - ShmDescPtr *prev; - - if (--shmdesc->refcnt) - return TRUE; - shmdt(shmdesc->addr); - for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next) - ; - *prev = shmdesc->next; - xfree(shmdesc); - return Success; -} - -static int -ProcShmDetach(client) - register ClientPtr client; -{ - ShmDescPtr shmdesc; - REQUEST(xShmDetachReq); - - REQUEST_SIZE_MATCH(xShmDetachReq); - VERIFY_SHMSEG(stuff->shmseg, shmdesc, client); - FreeResource(stuff->shmseg, RT_NONE); - return(client->noClientException); -} - -static void -miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - PixmapPtr pmap; - GCPtr putGC; - - nxagentShmTrap = 0; - putGC = GetScratchGC(depth, dst->pScreen); - if (!putGC) - { - nxagentShmTrap = 1; - return; - } - pmap = (*dst->pScreen->CreatePixmap)(dst->pScreen, sw, sh, depth); - if (!pmap) - { - nxagentShmTrap = 1; - FreeScratchGC(putGC); - return; - } - ValidateGC((DrawablePtr)pmap, putGC); - (*putGC->ops->PutImage)((DrawablePtr)pmap, putGC, depth, -sx, -sy, w, h, 0, - (format == XYPixmap) ? XYPixmap : ZPixmap, data); - FreeScratchGC(putGC); - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy); - (*pmap->drawable.pScreen->DestroyPixmap)(pmap); - nxagentShmTrap = 1; -} - -static void -fbShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - int length; - char *newdata; - extern int nxagentImageLength(int, int, int, int, int); - - #ifdef TEST - fprintf(stderr, "fbShmPutImage: Called with drawable at [%p] GC at [%p] data at [%p].\n", - (void *) dst, (void *) pGC, (void *) data); - #endif - - if ((format == ZPixmap) || (depth == 1)) - { - PixmapPtr pPixmap; - - pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth, - BitsPerPixel(depth), PixmapBytePad(w, depth), (pointer)data); - if (!pPixmap) - return; - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy); - - /* - * We updated the internal framebuffer, - * now we want to go on the real X. - */ - - #ifdef TEST - fprintf(stderr, "fbShmPutImage: Realizing the PutImage with depth [%d] " - " format [%d] w [%d] h [%d] sx [%d] sy [%d] sw [%d] " - " sh [%d] dx [%d].\n", depth, format, w, h, - sx, sy, sw, sh, dx); - #endif - - length = nxagentImageLength(sw, sh, format, 0, depth); - - if ((newdata = xalloc(length)) != NULL) - { - fbGetImage((DrawablePtr) pPixmap, sx, sy, sw, sh, format, AllPlanes, newdata); - (*pGC->ops->PutImage)(dst, pGC, depth, dx, dy, sw, sh, 0, format, newdata); - - xfree(newdata); - } - else - { - #ifdef WARNING - fprintf(stderr, "fbShmPutImage: WARNING! Data allocation failed.\n"); - #endif - } - - FreeScratchPixmapHeader(pPixmap); - } - else - { - #ifdef TEST - fprintf(stderr, "fbShmPutImage: Calling miShmPutImage().\n"); - #endif - miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, - data); - } -} - - -#ifdef PANORAMIX -static int -ProcPanoramiXShmPutImage(register ClientPtr client) -{ - int j, result = 0, orig_x, orig_y; - PanoramiXRes *draw, *gc; - Bool sendEvent, isRoot; - - REQUEST(xShmPutImageReq); - REQUEST_SIZE_MATCH(xShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - orig_x = stuff->dstX; - orig_y = stuff->dstY; - sendEvent = stuff->sendEvent; - stuff->sendEvent = 0; - FOR_NSCREENS(j) { - if(!j) stuff->sendEvent = sendEvent; - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->dstX = orig_x - panoramiXdataPtr[j].x; - stuff->dstY = orig_y - panoramiXdataPtr[j].y; - } - result = ProcShmPutImage(client); - if(result != client->noClientException) break; - } - return(result); -} - -static int -ProcPanoramiXShmGetImage(ClientPtr client) -{ - PanoramiXRes *draw; - DrawablePtr drawables[MAXSCREENS]; - DrawablePtr pDraw; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int i, x, y, w, h, format; - Mask plane = 0, planemask; - long lenPer = 0, length, widthBytesLine; - Bool isRoot; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { - client->errorValue = stuff->format; - return(BadValue); - } - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if (draw->type == XRT_PIXMAP) - return ProcShmGetImage(client); - - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - x = stuff->x; - y = stuff->y; - w = stuff->width; - h = stuff->height; - format = stuff->format; - planemask = stuff->planeMask; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - if(isRoot) { - if( /* check for being onscreen */ - x < 0 || x + w > PanoramiXPixWidth || - y < 0 || y + h > PanoramiXPixHeight ) - return(BadMatch); - } else { - if( /* check for being onscreen */ - panoramiXdataPtr[0].x + pDraw->x + x < 0 || - panoramiXdataPtr[0].x + pDraw->x + x + w > PanoramiXPixWidth || - panoramiXdataPtr[0].y + pDraw->y + y < 0 || - panoramiXdataPtr[0].y + pDraw->y + y + h > PanoramiXPixHeight || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height) - return(BadMatch); - } - - drawables[0] = pDraw; - for(i = 1; i < PanoramiXNumScreens; i++) - VERIFY_DRAWABLE(drawables[i], draw->info[i].id, client); - - xgi.visual = wVisual(((WindowPtr)pDraw)); - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - - if(format == ZPixmap) { - widthBytesLine = PixmapBytePad(w, pDraw->depth); - length = widthBytesLine * h; - } else { - widthBytesLine = PixmapBytePad(w, 1); - lenPer = widthBytesLine * h; - plane = ((Mask)1) << (pDraw->depth - 1); - length = lenPer * Ones(planemask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) {/* nothing to do */ } - else if (format == ZPixmap) { - XineramaGetImageData(drawables, x, y, w, h, format, planemask, - shmdesc->addr + stuff->offset, - widthBytesLine, isRoot); - } else { - - length = stuff->offset; - for (; plane; plane >>= 1) { - if (planemask & plane) { - XineramaGetImageData(drawables, x, y, w, h, - format, plane, shmdesc->addr + length, - widthBytesLine, isRoot); - length += lenPer; - } - } - } - - if (client->swapped) { - register int n; - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static int -ProcPanoramiXShmCreatePixmap(client) - register ClientPtr client; -{ - ScreenPtr pScreen = NULL; - PixmapPtr pMap = NULL; - DrawablePtr pDraw; - DepthPtr pDepth; - int i, j, result; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - PanoramiXRes *newPix; - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - VERIFY_SHMSIZE(shmdesc, stuff->offset, - PixmapBytePad(stuff->width, stuff->depth) * stuff->height, - client); - - if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - - newPix->type = XRT_PIXMAP; - newPix->u.pix.shared = TRUE; - newPix->info[0].id = stuff->pid; - for(j = 1; j < PanoramiXNumScreens; j++) - newPix->info[j].id = FakeClientID(client->index); - - result = (client->noClientException); - - FOR_NSCREENS(j) { - pScreen = screenInfo.screens[j]; - - pMap = (*shmFuncs[j]->CreatePixmap)(pScreen, - stuff->width, stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - - if (pMap) { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = newPix->info[j].id; - if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer)pMap)) { - (*pScreen->DestroyPixmap)(pMap); - result = BadAlloc; - break; - } - } else { - result = BadAlloc; - break; - } - } - - if(result == BadAlloc) { - while(j--) { - (*pScreen->DestroyPixmap)(pMap); - FreeResource(newPix->info[j].id, RT_NONE); - } - xfree(newPix); - } else - AddResource(stuff->pid, XRT_PIXMAP, newPix); - - return result; -} - -#endif - -static int -ProcShmPutImage(client) - register ClientPtr client; -{ - register GCPtr pGC; - register DrawablePtr pDraw; - long length; - ShmDescPtr shmdesc; - REQUEST(xShmPutImageReq); - - REQUEST_SIZE_MATCH(xShmPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client); - if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse)) - return BadValue; - if (stuff->format == XYBitmap) - { - if (stuff->depth != 1) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - } - else if (stuff->format == XYPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight, - client); - if (stuff->srcX > stuff->totalWidth) - { - client->errorValue = stuff->srcX; - return BadValue; - } - if (stuff->srcY > stuff->totalHeight) - { - client->errorValue = stuff->srcY; - return BadValue; - } - if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth) - { - client->errorValue = stuff->srcWidth; - return BadValue; - } - if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight) - { - client->errorValue = stuff->srcHeight; - return BadValue; - } - - #ifdef TEST - fprintf(stderr, "ProcShmPutImage: Format [%d] srcX [%d] srcY [%d], " - "totalWidth [%d] totalHeight [%d]\n", stuff->format, stuff->srcX, - stuff->srcY, stuff->totalWidth, stuff->totalHeight); - #endif - - #ifdef TEST - fprintf(stderr, "ProcShmPutImage: Calling (*shmFuncs[pDraw->pScreen->myNum]->PutImage)().\n"); - #endif - - (*shmFuncs[pDraw->pScreen->myNum]->PutImage)( - pDraw, pGC, stuff->depth, stuff->format, - stuff->totalWidth, stuff->totalHeight, - stuff->srcX, stuff->srcY, - stuff->srcWidth, stuff->srcHeight, - stuff->dstX, stuff->dstY, - shmdesc->addr + stuff->offset); - - if (stuff->sendEvent) - { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = X_ShmPutImage; - ev.majorEvent = ShmReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return (client->noClientException); -} - - - -static int -ProcShmGetImage(client) - register ClientPtr client; -{ - register DrawablePtr pDraw; - long lenPer = 0, length; - Mask plane = 0; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int n; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) - { - client->errorValue = stuff->format; - return(BadValue); - } - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + stuff->x < 0 || - pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width || - pDraw->y + stuff->y < 0 || - pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height || - /* check for being inside of border */ - stuff->x < - wBorderWidth((WindowPtr)pDraw) || - stuff->x + (int)stuff->width > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - stuff->y < -wBorderWidth((WindowPtr)pDraw) || - stuff->y + (int)stuff->height > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual(((WindowPtr)pDraw)); - } - else - { - if (stuff->x < 0 || - stuff->x+(int)stuff->width > pDraw->width || - stuff->y < 0 || - stuff->y+(int)stuff->height > pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(stuff->format == ZPixmap) - { - length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height; - } - else - { - lenPer = PixmapBytePad(stuff->width, 1) * stuff->height; - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) - { - /* nothing to do */ - } - else if (stuff->format == ZPixmap) - { - (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, stuff->planeMask, - shmdesc->addr + stuff->offset); - } - else - { - - length = stuff->offset; - for (; plane; plane >>= 1) - { - if (stuff->planeMask & plane) - { - (*pDraw->pScreen->GetImage)(pDraw, - stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, plane, - shmdesc->addr + length); - length += lenPer; - } - } - } - - if (client->swapped) { - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static PixmapPtr -fbShmCreatePixmap (pScreen, width, height, depth, addr) - ScreenPtr pScreen; - int width; - int height; - int depth; - char *addr; -{ - register PixmapPtr pPixmap; - - nxagentShmPixmapTrap = 1; - - pPixmap = (*pScreen->CreatePixmap)(pScreen, width, height, depth); - - if (!pPixmap) - { - nxagentShmPixmapTrap = 0; - - return NullPixmap; - } - - #ifdef TEST - fprintf(stderr,"fbShmCreatePixmap: Width [%d] Height [%d] Depth [%d]\n", width, height, depth); - #endif - - if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - BitsPerPixel(depth), PixmapBytePad(width, depth), (pointer)addr)) - { - #ifdef WARNING - fprintf(stderr,"fbShmCreatePixmap: Return Null Pixmap.\n"); - #endif - - (*pScreen->DestroyPixmap)(pPixmap); - - nxagentShmPixmapTrap = 0; - - return NullPixmap; - } - - nxagentShmPixmapTrap = 0; - - return pPixmap; -} - -static int -ProcShmCreatePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - DepthPtr pDepth; - register int i; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - VERIFY_SHMSIZE(shmdesc, stuff->offset, - PixmapBytePad(stuff->width, stuff->depth) * stuff->height, - client); - pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)( - pDraw->pScreen, stuff->width, - stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - if (pMap) - { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - { - return(client->noClientException); - } - } - return (BadAlloc); -} - -static int -ProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - - #ifdef TEST - fprintf(stderr, "ProcShmDispatch: Going to execute operation [%d] for client [%d].\n", - stuff -> data, client -> index); - #endif - - switch (stuff->data) - { - case X_ShmQueryVersion: - return ProcShmQueryVersion(client); - case X_ShmAttach: - return ProcShmAttach(client); - case X_ShmDetach: - return ProcShmDetach(client); - case X_ShmPutImage: - { - int result; - - #ifdef TEST - fprintf(stderr, "ProcShmDispatch: Going to execute ProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - nxagentShmTrap = 1; - -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - { - result = ProcPanoramiXShmPutImage(client); - - nxagentShmTrap = 0; - - return result; - } -#endif - - result = ProcShmPutImage(client); - - nxagentShmTrap = 0; - - #ifdef TEST - fprintf(stderr, "ProcShmDispatch: Returning from ProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - return result; - } - case X_ShmGetImage: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmGetImage(client); -#endif - return ProcShmGetImage(client); - case X_ShmCreatePixmap: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmCreatePixmap(client); -#endif - return ProcShmCreatePixmap(client); - default: - return BadRequest; - } -} - -static void -SShmCompletionEvent(from, to) - xShmCompletionEvent *from, *to; -{ - to->type = from->type; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->drawable, to->drawable); - cpswaps(from->minorEvent, to->minorEvent); - to->majorEvent = from->majorEvent; - cpswapl(from->shmseg, to->shmseg); - cpswapl(from->offset, to->offset); -} - -static int -SProcShmQueryVersion(client) - register ClientPtr client; -{ - register int n; - REQUEST(xShmQueryVersionReq); - - swaps(&stuff->length, n); - return ProcShmQueryVersion(client); -} - -static int -SProcShmAttach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmAttachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmAttachReq); - swapl(&stuff->shmseg, n); - swapl(&stuff->shmid, n); - return ProcShmAttach(client); -} - -static int -SProcShmDetach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmDetachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmDetachReq); - swapl(&stuff->shmseg, n); - return ProcShmDetach(client); -} - -static int -SProcShmPutImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmPutImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmPutImageReq); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->totalWidth, n); - swaps(&stuff->totalHeight, n); - swaps(&stuff->srcX, n); - swaps(&stuff->srcY, n); - swaps(&stuff->srcWidth, n); - swaps(&stuff->srcHeight, n); - swaps(&stuff->dstX, n); - swaps(&stuff->dstY, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmPutImage(client); -} - -static int -SProcShmGetImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmGetImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmGetImageReq); - swapl(&stuff->drawable, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->planeMask, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmGetImage(client); -} - -static int -SProcShmCreatePixmap(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmCreatePixmapReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - swapl(&stuff->drawable, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmCreatePixmap(client); -} - -static int -SProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - - #ifdef TEST - fprintf(stderr, "SProcShmDispatch: Going to execute operation [%d] for client [%d].\n", - stuff -> data, client -> index); - #endif - - switch (stuff->data) - { - case X_ShmQueryVersion: - return SProcShmQueryVersion(client); - case X_ShmAttach: - return SProcShmAttach(client); - case X_ShmDetach: - return SProcShmDetach(client); - case X_ShmPutImage: - { - int result; - - #ifdef TEST - fprintf(stderr, "SProcShmDispatch: Going to execute SProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - nxagentShmTrap = 1; - - result = SProcShmPutImage(client); - - nxagentShmTrap = 0; - - #ifdef TEST - fprintf(stderr, "SProcShmDispatch: Returning from SProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - return result; - } - case X_ShmGetImage: - return SProcShmGetImage(client); - case X_ShmCreatePixmap: - return SProcShmCreatePixmap(client); - default: - return BadRequest; - } -} - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXshm.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXshm.c.XF86.original deleted file mode 100644 index 3ba9ad2c1..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXshm.c.XF86.original +++ /dev/null @@ -1,1257 +0,0 @@ -/* $XFree86: xc/programs/Xserver/Xext/shm.c,v 3.36 2002/04/03 19:51:11 herrb Exp $ */ -/************************************************************ - -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -********************************************************/ - -/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */ - -/* $Xorg: shm.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */ - -#include -#ifndef Lynx -#include -#include -#else -#include -#include -#endif -#include -#include -#define NEED_REPLIES -#define NEED_EVENTS -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "extnsionst.h" -#include "servermd.h" -#define _XSHM_SERVER_ -#include "shmstr.h" -#include "Xfuncproto.h" -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -static void miShmPutImage(XSHM_PUT_IMAGE_ARGS); -static void fbShmPutImage(XSHM_PUT_IMAGE_ARGS); -static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS); -static int ShmDetachSegment( -#if NeedFunctionPrototypes - pointer /* value */, - XID /* shmseg */ -#endif - ); -static void ShmResetProc( -#if NeedFunctionPrototypes - ExtensionEntry * /* extEntry */ -#endif - ); -static void SShmCompletionEvent( -#if NeedFunctionPrototypes - xShmCompletionEvent * /* from */, - xShmCompletionEvent * /* to */ -#endif - ); - -static Bool ShmDestroyPixmap (PixmapPtr pPixmap); - -static DISPATCH_PROC(ProcShmAttach); -static DISPATCH_PROC(ProcShmCreatePixmap); -static DISPATCH_PROC(ProcShmDetach); -static DISPATCH_PROC(ProcShmDispatch); -static DISPATCH_PROC(ProcShmGetImage); -static DISPATCH_PROC(ProcShmPutImage); -static DISPATCH_PROC(ProcShmQueryVersion); -static DISPATCH_PROC(SProcShmAttach); -static DISPATCH_PROC(SProcShmCreatePixmap); -static DISPATCH_PROC(SProcShmDetach); -static DISPATCH_PROC(SProcShmDispatch); -static DISPATCH_PROC(SProcShmGetImage); -static DISPATCH_PROC(SProcShmPutImage); -static DISPATCH_PROC(SProcShmQueryVersion); - -static unsigned char ShmReqCode; -int ShmCompletionCode; -int BadShmSegCode; -RESTYPE ShmSegType; -static ShmDescPtr Shmsegs; -static Bool sharedPixmaps; -static int pixmapFormat; -static int shmPixFormat[MAXSCREENS]; -static ShmFuncsPtr shmFuncs[MAXSCREENS]; -static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS]; -#ifdef PIXPRIV -static int shmPixmapPrivate; -#endif -static ShmFuncs miFuncs = {NULL, miShmPutImage}; -static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage}; - -#define VERIFY_SHMSEG(shmseg,shmdesc,client) \ -{ \ - shmdesc = (ShmDescPtr)LookupIDByType(shmseg, ShmSegType); \ - if (!shmdesc) \ - { \ - client->errorValue = shmseg; \ - return BadShmSegCode; \ - } \ -} - -#define VERIFY_SHMPTR(shmseg,offset,needwrite,shmdesc,client) \ -{ \ - VERIFY_SHMSEG(shmseg, shmdesc, client); \ - if ((offset & 3) || (offset > shmdesc->size)) \ - { \ - client->errorValue = offset; \ - return BadValue; \ - } \ - if (needwrite && !shmdesc->writable) \ - return BadAccess; \ -} - -#define VERIFY_SHMSIZE(shmdesc,offset,len,client) \ -{ \ - if ((offset + len) > shmdesc->size) \ - { \ - return BadAccess; \ - } \ -} - - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) -#include - -static Bool badSysCall = FALSE; - -static void -SigSysHandler(signo) -int signo; -{ - badSysCall = TRUE; -} - -static Bool CheckForShmSyscall() -{ - void (*oldHandler)(); - int shmid = -1; - - /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */ - oldHandler = signal(SIGSYS, SigSysHandler); - - badSysCall = FALSE; - shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT); - /* Clean up */ - if (shmid != -1) - { - shmctl(shmid, IPC_RMID, (struct shmid_ds *)NULL); - } - signal(SIGSYS, oldHandler); - return(!badSysCall); -} -#endif - -void -ShmExtensionInit() -{ - ExtensionEntry *extEntry; - int i; - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - if (!CheckForShmSyscall()) - { - ErrorF("MIT-SHM extension disabled due to lack of kernel support\n"); - return; - } -#endif - - sharedPixmaps = xFalse; - pixmapFormat = 0; - { - sharedPixmaps = xTrue; - pixmapFormat = shmPixFormat[0]; - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!shmFuncs[i]) - shmFuncs[i] = &miFuncs; - if (!shmFuncs[i]->CreatePixmap) - sharedPixmaps = xFalse; - if (shmPixFormat[i] && (shmPixFormat[i] != pixmapFormat)) - { - sharedPixmaps = xFalse; - pixmapFormat = 0; - } - } - if (!pixmapFormat) - pixmapFormat = ZPixmap; - if (sharedPixmaps) - { - for (i = 0; i < screenInfo.numScreens; i++) - { - destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap; - screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap; - } -#ifdef PIXPRIV - shmPixmapPrivate = AllocatePixmapPrivateIndex(); - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!AllocatePixmapPrivate(screenInfo.screens[i], - shmPixmapPrivate, 0)) - return; - } -#endif - } - } - ShmSegType = CreateNewResourceType(ShmDetachSegment); - if (ShmSegType && - (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors, - ProcShmDispatch, SProcShmDispatch, - ShmResetProc, StandardMinorOpcode))) - { - ShmReqCode = (unsigned char)extEntry->base; - ShmCompletionCode = extEntry->eventBase; - BadShmSegCode = extEntry->errorBase; - EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent; - } -} - -/*ARGSUSED*/ -static void -ShmResetProc (extEntry) -ExtensionEntry *extEntry; -{ - int i; - - for (i = 0; i < MAXSCREENS; i++) - { - shmFuncs[i] = (ShmFuncsPtr)NULL; - shmPixFormat[i] = 0; - } -} - -void -ShmRegisterFuncs(pScreen, funcs) - ScreenPtr pScreen; - ShmFuncsPtr funcs; -{ - shmFuncs[pScreen->myNum] = funcs; -} - -void -ShmSetPixmapFormat(pScreen, format) - ScreenPtr pScreen; - int format; -{ - shmPixFormat[pScreen->myNum] = format; -} - -static Bool -ShmDestroyPixmap (PixmapPtr pPixmap) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - Bool ret; - if (pPixmap->refcnt == 1) - { - ShmDescPtr shmdesc; -#ifdef PIXPRIV - shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr; -#else - char *base = (char *) pPixmap->devPrivate.ptr; - - if (base != (pointer) (pPixmap + 1)) - { - for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) - { - if (shmdesc->addr <= base && base <= shmdesc->addr + shmdesc->size) - break; - } - } - else - shmdesc = 0; -#endif - if (shmdesc) - ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id); - } - - pScreen->DestroyPixmap = destroyPixmap[pScreen->myNum]; - ret = (*pScreen->DestroyPixmap) (pPixmap); - destroyPixmap[pScreen->myNum] = pScreen->DestroyPixmap; - pScreen->DestroyPixmap = ShmDestroyPixmap; - return ret; -} - -void -ShmRegisterFbFuncs(pScreen) - ScreenPtr pScreen; -{ - shmFuncs[pScreen->myNum] = &fbFuncs; -} - -static int -ProcShmQueryVersion(client) - register ClientPtr client; -{ - xShmQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xShmQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.sharedPixmaps = sharedPixmaps; - rep.pixmapFormat = pixmapFormat; - rep.majorVersion = SHM_MAJOR_VERSION; - rep.minorVersion = SHM_MINOR_VERSION; - rep.uid = geteuid(); - rep.gid = getegid(); - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - swaps(&rep.uid, n); - swaps(&rep.gid, n); - } - WriteToClient(client, sizeof(xShmQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -/* - * Simulate the access() system call for a shared memory segement, - * using the credentials from the client if available - */ -static int -shm_access(ClientPtr client, struct ipc_perm *perm, int readonly) -{ - int uid, gid; - mode_t mask; - - if (LocalClientCred(client, &uid, &gid) != -1) { - - /* User id 0 always gets access */ - if (uid == 0) { - return 0; - } - /* Check the owner */ - if (perm->uid == uid || perm->cuid == uid) { - mask = S_IRUSR; - if (!readonly) { - mask |= S_IWUSR; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - /* Check the group */ - if (perm->gid == gid || perm->cgid == gid) { - mask = S_IRGRP; - if (!readonly) { - mask |= S_IWGRP; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - } - /* Otherwise, check everyone else */ - mask = S_IROTH; - if (!readonly) { - mask |= S_IWOTH; - } - return (perm->mode & mask) == mask ? 0 : -1; -} - -static int -ProcShmAttach(client) - register ClientPtr client; -{ - struct shmid_ds buf; - ShmDescPtr shmdesc; - REQUEST(xShmAttachReq); - - REQUEST_SIZE_MATCH(xShmAttachReq); - LEGAL_NEW_RESOURCE(stuff->shmseg, client); - if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) - { - client->errorValue = stuff->readOnly; - return(BadValue); - } - for (shmdesc = Shmsegs; - shmdesc && (shmdesc->shmid != stuff->shmid); - shmdesc = shmdesc->next) - ; - if (shmdesc) - { - if (!stuff->readOnly && !shmdesc->writable) - return BadAccess; - shmdesc->refcnt++; - } - else - { - shmdesc = (ShmDescPtr) xalloc(sizeof(ShmDescRec)); - if (!shmdesc) - return BadAlloc; - shmdesc->addr = shmat(stuff->shmid, 0, - stuff->readOnly ? SHM_RDONLY : 0); - if ((shmdesc->addr == ((char *)-1)) || - shmctl(stuff->shmid, IPC_STAT, &buf)) - { - xfree(shmdesc); - return BadAccess; - } - - /* The attach was performed with root privs. We must - * do manual checking of access rights for the credentials - * of the client */ - - if (shm_access(client, &(buf.shm_perm), stuff->readOnly) == -1) { - shmdt(shmdesc->addr); - xfree(shmdesc); - return BadAccess; - } - - shmdesc->shmid = stuff->shmid; - shmdesc->refcnt = 1; - shmdesc->writable = !stuff->readOnly; - shmdesc->size = buf.shm_segsz; - shmdesc->next = Shmsegs; - Shmsegs = shmdesc; - } - if (!AddResource(stuff->shmseg, ShmSegType, (pointer)shmdesc)) - return BadAlloc; - return(client->noClientException); -} - -/*ARGSUSED*/ -static int -ShmDetachSegment(value, shmseg) - pointer value; /* must conform to DeleteType */ - XID shmseg; -{ - ShmDescPtr shmdesc = (ShmDescPtr)value; - ShmDescPtr *prev; - - if (--shmdesc->refcnt) - return TRUE; - shmdt(shmdesc->addr); - for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next) - ; - *prev = shmdesc->next; - xfree(shmdesc); - return Success; -} - -static int -ProcShmDetach(client) - register ClientPtr client; -{ - ShmDescPtr shmdesc; - REQUEST(xShmDetachReq); - - REQUEST_SIZE_MATCH(xShmDetachReq); - VERIFY_SHMSEG(stuff->shmseg, shmdesc, client); - FreeResource(stuff->shmseg, RT_NONE); - return(client->noClientException); -} - -static void -miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - PixmapPtr pmap; - GCPtr putGC; - - putGC = GetScratchGC(depth, dst->pScreen); - if (!putGC) - return; - pmap = (*dst->pScreen->CreatePixmap)(dst->pScreen, sw, sh, depth); - if (!pmap) - { - FreeScratchGC(putGC); - return; - } - ValidateGC((DrawablePtr)pmap, putGC); - (*putGC->ops->PutImage)((DrawablePtr)pmap, putGC, depth, -sx, -sy, w, h, 0, - (format == XYPixmap) ? XYPixmap : ZPixmap, data); - FreeScratchGC(putGC); - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy); - (*pmap->drawable.pScreen->DestroyPixmap)(pmap); -} - -static void -fbShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - if ((format == ZPixmap) || (depth == 1)) - { - PixmapPtr pPixmap; - - pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth, - BitsPerPixel(depth), PixmapBytePad(w, depth), (pointer)data); - if (!pPixmap) - return; - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy); - FreeScratchPixmapHeader(pPixmap); - } - else - miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, - data); -} - - -#ifdef PANORAMIX -static int -ProcPanoramiXShmPutImage(register ClientPtr client) -{ - int j, result = 0, orig_x, orig_y; - PanoramiXRes *draw, *gc; - Bool sendEvent, isRoot; - - REQUEST(xShmPutImageReq); - REQUEST_SIZE_MATCH(xShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - orig_x = stuff->dstX; - orig_y = stuff->dstY; - sendEvent = stuff->sendEvent; - stuff->sendEvent = 0; - FOR_NSCREENS(j) { - if(!j) stuff->sendEvent = sendEvent; - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->dstX = orig_x - panoramiXdataPtr[j].x; - stuff->dstY = orig_y - panoramiXdataPtr[j].y; - } - result = ProcShmPutImage(client); - if(result != client->noClientException) break; - } - return(result); -} - -static int -ProcPanoramiXShmGetImage(ClientPtr client) -{ - PanoramiXRes *draw; - DrawablePtr drawables[MAXSCREENS]; - DrawablePtr pDraw; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int i, x, y, w, h, format; - Mask plane = 0, planemask; - long lenPer = 0, length, widthBytesLine; - Bool isRoot; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { - client->errorValue = stuff->format; - return(BadValue); - } - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if (draw->type == XRT_PIXMAP) - return ProcShmGetImage(client); - - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - x = stuff->x; - y = stuff->y; - w = stuff->width; - h = stuff->height; - format = stuff->format; - planemask = stuff->planeMask; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - if(isRoot) { - if( /* check for being onscreen */ - x < 0 || x + w > PanoramiXPixWidth || - y < 0 || y + h > PanoramiXPixHeight ) - return(BadMatch); - } else { - if( /* check for being onscreen */ - panoramiXdataPtr[0].x + pDraw->x + x < 0 || - panoramiXdataPtr[0].x + pDraw->x + x + w > PanoramiXPixWidth || - panoramiXdataPtr[0].y + pDraw->y + y < 0 || - panoramiXdataPtr[0].y + pDraw->y + y + h > PanoramiXPixHeight || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height) - return(BadMatch); - } - - drawables[0] = pDraw; - for(i = 1; i < PanoramiXNumScreens; i++) - VERIFY_DRAWABLE(drawables[i], draw->info[i].id, client); - - xgi.visual = wVisual(((WindowPtr)pDraw)); - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - - if(format == ZPixmap) { - widthBytesLine = PixmapBytePad(w, pDraw->depth); - length = widthBytesLine * h; - } else { - widthBytesLine = PixmapBytePad(w, 1); - lenPer = widthBytesLine * h; - plane = ((Mask)1) << (pDraw->depth - 1); - length = lenPer * Ones(planemask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) {/* nothing to do */ } - else if (format == ZPixmap) { - XineramaGetImageData(drawables, x, y, w, h, format, planemask, - shmdesc->addr + stuff->offset, - widthBytesLine, isRoot); - } else { - - length = stuff->offset; - for (; plane; plane >>= 1) { - if (planemask & plane) { - XineramaGetImageData(drawables, x, y, w, h, - format, plane, shmdesc->addr + length, - widthBytesLine, isRoot); - length += lenPer; - } - } - } - - if (client->swapped) { - register int n; - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static int -ProcPanoramiXShmCreatePixmap(client) - register ClientPtr client; -{ - ScreenPtr pScreen = NULL; - PixmapPtr pMap = NULL; - DrawablePtr pDraw; - DepthPtr pDepth; - int i, j, result; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - PanoramiXRes *newPix; - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - VERIFY_SHMSIZE(shmdesc, stuff->offset, - PixmapBytePad(stuff->width, stuff->depth) * stuff->height, - client); - - if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - - newPix->type = XRT_PIXMAP; - newPix->u.pix.shared = TRUE; - newPix->info[0].id = stuff->pid; - for(j = 1; j < PanoramiXNumScreens; j++) - newPix->info[j].id = FakeClientID(client->index); - - result = (client->noClientException); - - FOR_NSCREENS(j) { - pScreen = screenInfo.screens[j]; - - pMap = (*shmFuncs[j]->CreatePixmap)(pScreen, - stuff->width, stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - - if (pMap) { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = newPix->info[j].id; - if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer)pMap)) { - (*pScreen->DestroyPixmap)(pMap); - result = BadAlloc; - break; - } - } else { - result = BadAlloc; - break; - } - } - - if(result == BadAlloc) { - while(j--) { - (*pScreen->DestroyPixmap)(pMap); - FreeResource(newPix->info[j].id, RT_NONE); - } - xfree(newPix); - } else - AddResource(stuff->pid, XRT_PIXMAP, newPix); - - return result; -} - -#endif - -static int -ProcShmPutImage(client) - register ClientPtr client; -{ - register GCPtr pGC; - register DrawablePtr pDraw; - long length; - ShmDescPtr shmdesc; - REQUEST(xShmPutImageReq); - - REQUEST_SIZE_MATCH(xShmPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client); - if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse)) - return BadValue; - if (stuff->format == XYBitmap) - { - if (stuff->depth != 1) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - } - else if (stuff->format == XYPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight, - client); - if (stuff->srcX > stuff->totalWidth) - { - client->errorValue = stuff->srcX; - return BadValue; - } - if (stuff->srcY > stuff->totalHeight) - { - client->errorValue = stuff->srcY; - return BadValue; - } - if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth) - { - client->errorValue = stuff->srcWidth; - return BadValue; - } - if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight) - { - client->errorValue = stuff->srcHeight; - return BadValue; - } - - if ((((stuff->format == ZPixmap) && (stuff->srcX == 0)) || - ((stuff->format != ZPixmap) && - (stuff->srcX < screenInfo.bitmapScanlinePad) && - ((stuff->format == XYBitmap) || - ((stuff->srcY == 0) && - (stuff->srcHeight == stuff->totalHeight))))) && - ((stuff->srcX + stuff->srcWidth) == stuff->totalWidth)) - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, - stuff->dstX, stuff->dstY, - stuff->totalWidth, stuff->srcHeight, - stuff->srcX, stuff->format, - shmdesc->addr + stuff->offset + - (stuff->srcY * length)); - else - (*shmFuncs[pDraw->pScreen->myNum]->PutImage)( - pDraw, pGC, stuff->depth, stuff->format, - stuff->totalWidth, stuff->totalHeight, - stuff->srcX, stuff->srcY, - stuff->srcWidth, stuff->srcHeight, - stuff->dstX, stuff->dstY, - shmdesc->addr + stuff->offset); - - if (stuff->sendEvent) - { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = X_ShmPutImage; - ev.majorEvent = ShmReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return (client->noClientException); -} - - - -static int -ProcShmGetImage(client) - register ClientPtr client; -{ - register DrawablePtr pDraw; - long lenPer = 0, length; - Mask plane = 0; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int n; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) - { - client->errorValue = stuff->format; - return(BadValue); - } - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + stuff->x < 0 || - pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width || - pDraw->y + stuff->y < 0 || - pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height || - /* check for being inside of border */ - stuff->x < - wBorderWidth((WindowPtr)pDraw) || - stuff->x + (int)stuff->width > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - stuff->y < -wBorderWidth((WindowPtr)pDraw) || - stuff->y + (int)stuff->height > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual(((WindowPtr)pDraw)); - } - else - { - if (stuff->x < 0 || - stuff->x+(int)stuff->width > pDraw->width || - stuff->y < 0 || - stuff->y+(int)stuff->height > pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(stuff->format == ZPixmap) - { - length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height; - } - else - { - lenPer = PixmapBytePad(stuff->width, 1) * stuff->height; - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) - { - /* nothing to do */ - } - else if (stuff->format == ZPixmap) - { - (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, stuff->planeMask, - shmdesc->addr + stuff->offset); - } - else - { - - length = stuff->offset; - for (; plane; plane >>= 1) - { - if (stuff->planeMask & plane) - { - (*pDraw->pScreen->GetImage)(pDraw, - stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, plane, - shmdesc->addr + length); - length += lenPer; - } - } - } - - if (client->swapped) { - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static PixmapPtr -fbShmCreatePixmap (pScreen, width, height, depth, addr) - ScreenPtr pScreen; - int width; - int height; - int depth; - char *addr; -{ - register PixmapPtr pPixmap; - - pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth); - if (!pPixmap) - return NullPixmap; - - if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - BitsPerPixel(depth), PixmapBytePad(width, depth), (pointer)addr)) { - (*pScreen->DestroyPixmap)(pPixmap); - return NullPixmap; - } - return pPixmap; -} - -static int -ProcShmCreatePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - DepthPtr pDepth; - register int i; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - VERIFY_SHMSIZE(shmdesc, stuff->offset, - PixmapBytePad(stuff->width, stuff->depth) * stuff->height, - client); - pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)( - pDraw->pScreen, stuff->width, - stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - if (pMap) - { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - { - return(client->noClientException); - } - } - return (BadAlloc); -} - -static int -ProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - switch (stuff->data) - { - case X_ShmQueryVersion: - return ProcShmQueryVersion(client); - case X_ShmAttach: - return ProcShmAttach(client); - case X_ShmDetach: - return ProcShmDetach(client); - case X_ShmPutImage: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmPutImage(client); -#endif - return ProcShmPutImage(client); - case X_ShmGetImage: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmGetImage(client); -#endif - return ProcShmGetImage(client); - case X_ShmCreatePixmap: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmCreatePixmap(client); -#endif - return ProcShmCreatePixmap(client); - default: - return BadRequest; - } -} - -static void -SShmCompletionEvent(from, to) - xShmCompletionEvent *from, *to; -{ - to->type = from->type; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->drawable, to->drawable); - cpswaps(from->minorEvent, to->minorEvent); - to->majorEvent = from->majorEvent; - cpswapl(from->shmseg, to->shmseg); - cpswapl(from->offset, to->offset); -} - -static int -SProcShmQueryVersion(client) - register ClientPtr client; -{ - register int n; - REQUEST(xShmQueryVersionReq); - - swaps(&stuff->length, n); - return ProcShmQueryVersion(client); -} - -static int -SProcShmAttach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmAttachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmAttachReq); - swapl(&stuff->shmseg, n); - swapl(&stuff->shmid, n); - return ProcShmAttach(client); -} - -static int -SProcShmDetach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmDetachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmDetachReq); - swapl(&stuff->shmseg, n); - return ProcShmDetach(client); -} - -static int -SProcShmPutImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmPutImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmPutImageReq); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->totalWidth, n); - swaps(&stuff->totalHeight, n); - swaps(&stuff->srcX, n); - swaps(&stuff->srcY, n); - swaps(&stuff->srcWidth, n); - swaps(&stuff->srcHeight, n); - swaps(&stuff->dstX, n); - swaps(&stuff->dstY, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmPutImage(client); -} - -static int -SProcShmGetImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmGetImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmGetImageReq); - swapl(&stuff->drawable, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->planeMask, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmGetImage(client); -} - -static int -SProcShmCreatePixmap(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmCreatePixmapReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - swapl(&stuff->drawable, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmCreatePixmap(client); -} - -static int -SProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - switch (stuff->data) - { - case X_ShmQueryVersion: - return SProcShmQueryVersion(client); - case X_ShmAttach: - return SProcShmAttach(client); - case X_ShmDetach: - return SProcShmDetach(client); - case X_ShmPutImage: - return SProcShmPutImage(client); - case X_ShmGetImage: - return SProcShmGetImage(client); - case X_ShmCreatePixmap: - return SProcShmCreatePixmap(client); - default: - return BadRequest; - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.NX.original deleted file mode 100644 index 95ecde951..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.NX.original +++ /dev/null @@ -1,4179 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#include "X/NXwindow.c" - -#else - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -*/ - -/**************************************************************** -* * -* Copyright (c) Digital Equipment Corporation, 1991, 1997 * -* * -* All Rights Reserved. Unpublished rights reserved under * -* the copyright laws of the United States. * -* * -* The software contained on this media is proprietary to * -* and embodies the confidential technology of Digital * -* Equipment Corporation. Possession, use, duplication or * -* dissemination of the software and media is authorized only * -* pursuant to a valid written license from Digital Equipment * -* Corporation. * -* * -* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * -* by the U.S. Government is subject to restrictions as set * -* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * -* or in FAR 52.227-19, as applicable. * -* * -*****************************************************************/ - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "selection.h" -#ifdef PANORAMIX -#include "../../Xext/panoramiX.h" -#include "../../Xext/panoramiXsrv.h" -#endif -#include "dixevents.h" -#include "globals.h" - -#ifdef XAPPGROUP -#include "Xagsrv.h" -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif - -#include "Screen.h" -#include "Options.h" -#include "Atoms.h" -#include "Clipboard.h" -#include "Splash.h" -#include "Rootless.h" -#include "Composite.h" -#include "Drawable.h" -#include "Colormap.h" - -#if defined(NEED_SCREEN_REGIONS) -#define REGION_PTR(pScreen,pWin) \ - register ScreenPtr pScreen = pWin->drawable.pScreen; -#else -#define REGION_PTR(pScreen,pWin) /* nothing */ -#endif - -extern Bool nxagentWMIsRunning; -extern Bool nxagentScreenTrap; - -/****** - * Window stuff for server - * - * CreateRootWindow, CreateWindow, ChangeWindowAttributes, - * GetWindowAttributes, DeleteWindow, DestroySubWindows, - * HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows, - * UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow, - * - ******/ - -int screenIsSaved = SCREEN_SAVER_OFF; - -ScreenSaverStuffRec savedScreenInfo[MAXSCREENS]; - -#if 0 -extern void DeleteWindowFromAnyEvents(); -extern Mask EventMaskForClient(); -extern void WindowHasNewCursor(); -extern void RecalculateDeliverableEvents(); -#endif - -static Bool TileScreenSaver( -#if NeedFunctionPrototypes - int /*i*/, - int /*kind*/ -#endif -); - - -#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \ - CWDontPropagate | CWOverrideRedirect | CWCursor ) - -#define BOXES_OVERLAP(b1, b2) \ - (!( ((b1)->x2 <= (b2)->x1) || \ - ( ((b1)->x1 >= (b2)->x2)) || \ - ( ((b1)->y2 <= (b2)->y1)) || \ - ( ((b1)->y1 >= (b2)->y2)) ) ) - -#define RedirectSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask) - -#define SubSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask) - -#define StrSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask) - -#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent)) - - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -int numSaveUndersViewable = 0; -int deltaSaveUndersViewable = 0; - -WindowPtr nxagentRootTileWindow; - -/* - * This block used the DEBUG symbol. - */ - -#ifdef WINDOW_TREE_DEBUG -/****** - * PrintWindowTree - * For debugging only - ******/ - -int -PrintChildren(p1, indent) - WindowPtr p1; - int indent; -{ - WindowPtr p2; - int i; - - while (p1) - { - p2 = p1->firstChild; - for (i=0; idrawable.id); - miPrintRegion(&p1->clipList); - PrintChildren(p2, indent+4); - p1 = p1->nextSib; - } -} - -PrintWindowTree() -{ - int i; - WindowPtr pWin, p1; - - for (i=0; iclipList); - p1 = pWin->firstChild; - PrintChildren(p1, 4); - } -} -#endif - -int -TraverseTree(pWin, func, data) - register WindowPtr pWin; - VisitWindowProcPtr func; - pointer data; -{ - register int result; - register WindowPtr pChild; - - if (!(pChild = pWin)) - return(WT_NOMATCH); - while (1) - { - result = (* func)(pChild, data); - if (result == WT_STOPWALKING) - return(WT_STOPWALKING); - if ((result == WT_WALKCHILDREN) && pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - return(WT_NOMATCH); -} - -/***** - * WalkTree - * Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on - * each window. If FUNC returns WT_WALKCHILDREN, traverse the children, - * if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING - * exit WalkTree. Does depth-first traverse. - *****/ - -int -WalkTree(pScreen, func, data) - ScreenPtr pScreen; - VisitWindowProcPtr func; - pointer data; -{ - return(TraverseTree(WindowTable[pScreen->myNum], func, data)); -} - -/* hack for forcing backing store on all windows */ -int defaultBackingStore = NotUseful; -/* hack to force no backing store */ -Bool disableBackingStore = FALSE; -Bool enableBackingStore = FALSE; -/* hack to force no save unders */ -Bool disableSaveUnders = FALSE; - -static void -#if NeedFunctionPrototypes -SetWindowToDefaults(register WindowPtr pWin) -#else -SetWindowToDefaults(pWin) - register WindowPtr pWin; -#endif -{ - pWin->prevSib = NullWindow; - pWin->firstChild = NullWindow; - pWin->lastChild = NullWindow; - - pWin->valdata = (ValidatePtr)NULL; - pWin->optional = (WindowOptPtr)NULL; - pWin->cursorIsNone = TRUE; - - pWin->backingStore = NotUseful; - pWin->DIXsaveUnder = FALSE; - pWin->backStorage = (pointer) NULL; - - pWin->mapped = FALSE; /* off */ - pWin->realized = FALSE; /* off */ - pWin->viewable = FALSE; - pWin->visibility = VisibilityNotViewable; - pWin->overrideRedirect = FALSE; - pWin->saveUnder = FALSE; - - pWin->bitGravity = ForgetGravity; - pWin->winGravity = NorthWestGravity; - - pWin->eventMask = 0; - pWin->deliverableEvents = 0; - pWin->dontPropagate = 0; - pWin->forcedBS = FALSE; -#ifdef NEED_DBE_BUF_BITS - pWin->srcBuffer = DBE_FRONT_BUFFER; - pWin->dstBuffer = DBE_FRONT_BUFFER; -#endif -} - -void nxagentClearSplash(WindowPtr pW) -{ - int w, h; - ScreenPtr pScreen; - - w = pW->drawable.width; - h = pW->drawable.height; - - pScreen = pW->drawable.pScreen; - - if (pW->backgroundState == BackgroundPixmap) - { - (*pScreen->DestroyPixmap)(pW->background.pixmap); - } - - pW->backgroundState = BackgroundPixel; - pW->background.pixel = nxagentLogoBlack; - - (*pScreen->ChangeWindowAttributes)(pW, CWBackPixmap|CWBackPixel); -} - -static void -#if NeedFunctionPrototypes -MakeRootTile(WindowPtr pWin) -#else -MakeRootTile(pWin) - WindowPtr pWin; -#endif -{ - nxagentRootTileWindow = pWin; -} - -WindowPtr -AllocateWindow(pScreen) - ScreenPtr pScreen; -{ - WindowPtr pWin; - register char *ptr; - register DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - pWin = (WindowPtr)xalloc(pScreen->totalWindowSize); - if (pWin) - { - ppriv = (DevUnion *)(pWin + 1); - pWin->devPrivates = ppriv; - sizes = pScreen->WindowPrivateSizes; - ptr = (char *)(ppriv + pScreen->WindowPrivateLen); - for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - } - return pWin; -} - -/***** - * CreateRootWindow - * Makes a window at initialization time for specified screen - *****/ - -Bool -CreateRootWindow(pScreen) - ScreenPtr pScreen; -{ - WindowPtr pWin; - BoxRec box; - PixmapFormatRec *format; - - pWin = AllocateWindow(pScreen); - if (!pWin) - return FALSE; - - savedScreenInfo[pScreen->myNum].pWindow = NULL; - savedScreenInfo[pScreen->myNum].wid = FakeClientID(0); - savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL; - screenIsSaved = SCREEN_SAVER_OFF; - - WindowTable[pScreen->myNum] = pWin; - - pWin->drawable.pScreen = pScreen; - pWin->drawable.type = DRAWABLE_WINDOW; - - pWin->drawable.depth = pScreen->rootDepth; - for (format = screenInfo.formats; - format->depth != pScreen->rootDepth; - format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->parent = NullWindow; - SetWindowToDefaults(pWin); - - pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec)); - if (!pWin->optional) - return FALSE; - - pWin->optional->dontPropagateMask = 0; - pWin->optional->otherEventMasks = 0; - pWin->optional->otherClients = NULL; - pWin->optional->passiveGrabs = NULL; - pWin->optional->userProps = NULL; - pWin->optional->backingBitPlanes = ~0L; - pWin->optional->backingPixel = 0; -#ifdef SHAPE - pWin->optional->boundingShape = NULL; - pWin->optional->clipShape = NULL; -#endif -#ifdef XINPUT - pWin->optional->inputMasks = NULL; -#endif - pWin->optional->colormap = pScreen->defColormap; - pWin->optional->visual = pScreen->rootVisual; - - pWin->nextSib = NullWindow; - - pWin->drawable.id = FakeClientID(0); - - pWin->origin.x = pWin->origin.y = 0; - pWin->drawable.height = pScreen->height; - pWin->drawable.width = pScreen->width; - pWin->drawable.x = pWin->drawable.y = 0; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - REGION_INIT(pScreen, &pWin->winSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderClip, &box, 1); - - pWin->drawable.class = InputOutput; - pWin->optional->visual = pScreen->rootVisual; - - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = pScreen->whitePixel; - - pWin->borderIsPixel = TRUE; - pWin->border.pixel = pScreen->blackPixel; - pWin->borderWidth = 0; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin)) - return FALSE; - - if (disableBackingStore) - { - pScreen -> backingStoreSupport = NotUseful; - } - - if (enableBackingStore) - { - pScreen -> backingStoreSupport = Always; - } - - pScreen->saveUnderSupport = False; - -#ifdef DO_SAVE_UNDERS - if ((pScreen->backingStoreSupport != NotUseful) && - (pScreen->saveUnderSupport == NotUseful)) - { - /* - * If the screen has backing-store but no save-unders, let the - * clients know we can support save-unders using backing-store. - */ - pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS; - } -#endif /* DO_SAVE_UNDERS */ - - if (disableSaveUnders) - pScreen->saveUnderSupport = NotUseful; - - return TRUE; -} - -void -InitRootWindow(pWin) - WindowPtr pWin; -{ - ScreenPtr pScreen; - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Called for window at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - if (nxagentOption(Rootless)) - { - #ifdef TEST - fprintf(stderr, "InitRootWindow: Assigned agent root to window at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - nxagentRootlessWindow = pWin; - } - - pScreen = pWin->drawable.pScreen; - - /* - * A root window is created for each screen by main - * and the pointer is saved in WindowTable as in the - * following snippet: - * - * for (i = 0; i < screenInfo.numScreens; i++) - * InitRootWindow(WindowTable[i]); - * - * Our root window on the real display was already - * created at the time the screen was opened, so it - * is unclear how this window (or the other window, - * if you prefer) fits in the big picture. - */ - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Going to create window as root at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - if (!(*pScreen->CreateWindow)(pWin)) - return; /* XXX */ - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Created window as root at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - (*pScreen->PositionWindow)(pWin, 0, 0); - - pWin->cursorIsNone = FALSE; - pWin->optional->cursor = rootCursor; - rootCursor->refcnt++; - pWin->backingStore = defaultBackingStore; - pWin->forcedBS = (defaultBackingStore != NotUseful); - - #ifdef NXAGENT_SPLASH - /* We SHOULD check for an error value here XXX */ - pWin -> background.pixel = pScreen -> blackPixel; - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixel|CWBorderPixel|CWCursor|CWBackingStore); - #else - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore); - #endif - - MakeRootTile(pWin); - - /* - * Map both the root and the default agent window. - */ - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Mapping default windows.\n"); - #endif - - nxagentInitAtoms(pWin); - - nxagentInitClipboard(pWin); - - nxagentMapDefaultWindows(); - - nxagentRedirectDefaultWindows(); - - #ifdef NXAGENT_ARTSD - { - char artsd_port[10]; - int nPort; - extern void nxagentPropagateArtsdProperties(ScreenPtr pScreen, char *port); - nPort = atoi(display) + 7000; - sprintf(artsd_port,"%d", nPort); - nxagentPropagateArtsdProperties(pScreen, artsd_port); - } - #endif -} - -/* Set the region to the intersection of the rectangle and the - * window's winSize. The window is typically the parent of the - * window from which the region came. - */ - -void -ClippedRegionFromBox(pWin, Rgn, x, y, w, h) - register WindowPtr pWin; - RegionPtr Rgn; - register int x, y; - int w, h; -{ - REGION_PTR(pScreen, pWin) - BoxRec box; - - box = *(REGION_EXTENTS(pScreen, &pWin->winSize)); - /* we do these calculations to avoid overflows */ - if (x > box.x1) - box.x1 = x; - if (y > box.y1) - box.y1 = y; - x += w; - if (x < box.x2) - box.x2 = x; - y += h; - if (y < box.y2) - box.y2 = y; - if (box.x1 > box.x2) - box.x2 = box.x1; - if (box.y1 > box.y2) - box.y2 = box.y1; - REGION_RESET(pScreen, Rgn, &box); - REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize); -} - -WindowPtr -RealChildHead(pWin) - register WindowPtr pWin; -{ - if (!pWin->parent && - (screenIsSaved == SCREEN_SAVER_ON) && - (HasSaverWindow (pWin->drawable.pScreen->myNum))) - return (pWin->firstChild); - else - return (NullWindow); -} - -/***** - * CreateWindow - * Makes a window in response to client request - *****/ - -WindowPtr -CreateWindow(wid, pParent, x, y, w, h, bw, class, vmask, vlist, - depth, client, visual, error) - Window wid; - register WindowPtr pParent; - int x,y; - unsigned int w, h, bw; - unsigned int class; - register Mask vmask; - XID *vlist; - int depth; - ClientPtr client; - VisualID visual; - int *error; -{ - register WindowPtr pWin; - WindowPtr pHead; - register ScreenPtr pScreen; - xEvent event; - int idepth, ivisual; - Bool fOK; - DepthPtr pDepth; - PixmapFormatRec *format; - register WindowOptPtr ancwopt; - - if (class == CopyFromParent) - class = pParent->drawable.class; - - if ((class != InputOutput) && (class != InputOnly)) - { - *error = BadValue; - client->errorValue = class; - return NullWindow; - } - - if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) - { - *error = BadMatch; - return NullWindow; - } - - if ((class == InputOnly) && ((bw != 0) || (depth != 0))) - { - *error = BadMatch; - return NullWindow; - } - - pScreen = pParent->drawable.pScreen; - if ((class == InputOutput) && (depth == 0)) - depth = pParent->drawable.depth; - ancwopt = pParent->optional; - if (!ancwopt) - ancwopt = FindWindowWithOptional(pParent)->optional; - if (visual == CopyFromParent) { -#ifdef XAPPGROUP - VisualID ag_visual; - - if (client->appgroup && !pParent->parent && - (ag_visual = XagRootVisual (client))) - visual = ag_visual; - else -#endif - visual = ancwopt->visual; - } - - /* Find out if the depth and visual are acceptable for this Screen */ - if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) - { - fOK = FALSE; - for(idepth = 0; idepth < pScreen->numDepths; idepth++) - { - pDepth = (DepthPtr) &pScreen->allowedDepths[idepth]; - if ((depth == pDepth->depth) || (depth == 0)) - { - for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) - { - if (visual == pDepth->vids[ivisual]) - { - fOK = TRUE; - break; - } - } - } - } - if (fOK == FALSE) - { - *error = BadMatch; - return NullWindow; - } - } - - if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) && - (class != InputOnly) && - (depth != pParent->drawable.depth)) - { - *error = BadMatch; - return NullWindow; - } - - if (((vmask & CWColormap) == 0) && - (class != InputOnly) && - ((visual != ancwopt->visual) || (ancwopt->colormap == None))) - { - *error = BadMatch; - return NullWindow; - } - - pWin = AllocateWindow(pScreen); - if (!pWin) - { - *error = BadAlloc; - return NullWindow; - } - pWin->drawable = pParent->drawable; - pWin->drawable.depth = depth; - if (depth == pParent->drawable.depth) - pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; - else - { - for (format = screenInfo.formats; format->depth != depth; format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - } - if (class == InputOnly) - pWin->drawable.type = (short) UNDRAWABLE_WINDOW; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->drawable.id = wid; - pWin->drawable.class = class; - - pWin->parent = pParent; - SetWindowToDefaults(pWin); - - if (visual != ancwopt->visual) - { - if (!MakeWindowOptional (pWin)) - { - xfree (pWin); - *error = BadAlloc; - return NullWindow; - } - pWin->optional->visual = visual; - pWin->optional->colormap = None; - } - - pWin->borderWidth = bw; -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows; - * they make it too easy to steal window contents - */ - if (client->trustLevel != XSecurityClientTrusted) - { - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = 0; - } - else -#endif - pWin->backgroundState = None; - - pWin->borderIsPixel = pParent->borderIsPixel; - pWin->border = pParent->border; - if (pWin->borderIsPixel == FALSE) - pWin->border.pixmap->refcnt++; - - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - pWin->drawable.width = w; - pWin->drawable.height = h; - pWin->drawable.x = pParent->drawable.x + x + (int)bw; - pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - /* set up clip list correctly for unobscured WindowPtr */ - REGION_INIT(pScreen, &pWin->clipList, NullBox, 1); - REGION_INIT(pScreen, &pWin->borderClip, NullBox, 1); - REGION_INIT(pScreen, &pWin->winSize, NullBox, 1); - REGION_INIT(pScreen, &pWin->borderSize, NullBox, 1); - - pHead = RealChildHead(pParent); - if (pHead) - { - pWin->nextSib = pHead->nextSib; - if (pHead->nextSib) - pHead->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pHead->nextSib = pWin; - pWin->prevSib = pHead; - } - else - { - pWin->nextSib = pParent->firstChild; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - /* We SHOULD check for an error value here XXX */ - if (!(*pScreen->CreateWindow)(pWin)) - { - *error = BadAlloc; - DeleteWindow(pWin, None); - return NullWindow; - } - /* We SHOULD check for an error value here XXX */ - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - - if (!(vmask & CWEventMask)) - RecalculateDeliverableEvents(pWin); - - if (vmask) - *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin)); - else - *error = Success; - - if (*error != Success) - { - DeleteWindow(pWin, None); - return NullWindow; - } - if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful)) - { - XID value = defaultBackingStore; - (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin)); - pWin->forcedBS = TRUE; - } - - if (SubSend(pParent)) - { - event.u.u.type = CreateNotify; - event.u.createNotify.window = wid; - event.u.createNotify.parent = pParent->drawable.id; - event.u.createNotify.x = x; - event.u.createNotify.y = y; - event.u.createNotify.width = w; - event.u.createNotify.height = h; - event.u.createNotify.borderWidth = bw; - event.u.createNotify.override = pWin->overrideRedirect; - DeliverEvents(pParent, &event, 1, NullWindow); - } - return pWin; -} - -static void -#if NeedFunctionPrototypes -FreeWindowResources(register WindowPtr pWin) -#else -FreeWindowResources(pWin) - register WindowPtr pWin; -#endif -{ - register ScreenPtr pScreen = pWin->drawable.pScreen; - - DeleteWindowFromAnySaveSet(pWin); - DeleteWindowFromAnySelections(pWin); - DeleteWindowFromAnyEvents(pWin, TRUE); - REGION_UNINIT(pScreen, &pWin->clipList); - REGION_UNINIT(pScreen, &pWin->winSize); - REGION_UNINIT(pScreen, &pWin->borderClip); - REGION_UNINIT(pScreen, &pWin->borderSize); -#ifdef SHAPE - if (wBoundingShape (pWin)) - REGION_DESTROY(pScreen, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_DESTROY(pScreen, wClipShape (pWin)); -#endif - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - - DeleteAllWindowProperties(pWin); - /* We SHOULD check for an error value here XXX */ - (*pScreen->DestroyWindow)(pWin); - DisposeWindowOptional (pWin); -} - -static void -#if NeedFunctionPrototypes -CrushTree(WindowPtr pWin) -#else -CrushTree(pWin) - WindowPtr pWin; -#endif -{ - register WindowPtr pChild, pSib, pParent; - UnrealizeWindowProcPtr UnrealizeWindow; - xEvent event; - - if (!(pChild = pWin->firstChild)) - return; - UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow; - while (1) - { - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (1) - { - pParent = pChild->parent; - if (SubStrSend(pChild, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pChild->drawable.id; - DeliverEvents(pChild, &event, 1, NullWindow); - } - FreeResource(pChild->drawable.id, RT_WINDOW); - pSib = pChild->nextSib; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder && pChild->viewable) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->realized) - { - pChild->realized = FALSE; - (*UnrealizeWindow)(pChild); - } - FreeWindowResources(pChild); - xfree(pChild); - if ( (pChild = pSib) ) - break; - pChild = pParent; - pChild->firstChild = NullWindow; - pChild->lastChild = NullWindow; - if (pChild == pWin) - return; - } - } -} - -/***** - * DeleteWindow - * Deletes child of window then window itself - * If wid is None, don't send any events - *****/ - -/*ARGSUSED*/ -int -DeleteWindow(value, wid) - pointer value; - XID wid; - { - register WindowPtr pParent; - register WindowPtr pWin = (WindowPtr)value; - xEvent event; - - UnmapWindow(pWin, FALSE); - - CrushTree(pWin); - - pParent = pWin->parent; - if (wid && pParent && SubStrSend(pWin, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pWin->drawable.id; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - FreeWindowResources(pWin); - if (pParent) - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - } - xfree(pWin); - - if (pWin -> optional && - pWin -> optional -> colormap && - pWin -> parent) - { - nxagentSetInstalledColormapWindows(pWin -> drawable.pScreen); - } - - return Success; -} - -/*ARGSUSED*/ -void -DestroySubwindows(pWin, client) - register WindowPtr pWin; - ClientPtr client; -{ - /* XXX - * The protocol is quite clear that each window should be - * destroyed in turn, however, unmapping all of the first - * eliminates most of the calls to ValidateTree. So, - * this implementation is incorrect in that all of the - * UnmapNotifies occur before all of the DestroyNotifies. - * If you care, simply delete the call to UnmapSubwindows. - */ - UnmapSubwindows(pWin); - while (pWin->lastChild) - FreeResource(pWin->lastChild->drawable.id, RT_NONE); -} - -#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \ - ButtonReleaseMask | PointerMotionMask) - -/***** - * ChangeWindowAttributes - * - * The value-mask specifies which attributes are to be changed; the - * value-list contains one value for each one bit in the mask, from least - * to most significant bit in the mask. - *****/ - -int -ChangeWindowAttributes(pWin, vmask, vlist, client) - register WindowPtr pWin; - Mask vmask; - XID *vlist; - ClientPtr client; -{ - register Mask index2; - register XID *pVlist; - PixmapPtr pPixmap; - Pixmap pixID; - CursorPtr pCursor, pOldCursor; - Cursor cursorID; - WindowPtr pChild; - Colormap cmap; - ColormapPtr pCmap; - xEvent xE; - int result; - register ScreenPtr pScreen; - Mask vmaskCopy = 0; - register Mask tmask; - unsigned int val; - int error; - Bool checkOptional = FALSE; - Bool borderRelative = FALSE; - WindowPtr pLayerWin; - - if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK))) - return BadMatch; - - error = Success; - pScreen = pWin->drawable.pScreen; - pVlist = vlist; - tmask = vmask; - while (tmask) - { - index2 = (Mask) lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBackPixmap: - pixID = (Pixmap )*pVlist; - pVlist++; - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pixID == None) - { -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows */ - if (client->trustLevel == XSecurityClientTrusted) - { -#endif - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = None; -#ifdef XCSECURITY - } - else - { /* didn't change the background to None, so don't tell ddx */ - index2 = 0; - } -#endif - } - else if (pixID == ParentRelative) - { - if (pWin->parent && - pWin->drawable.depth != pWin->parent->drawable.depth) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = ParentRelative; - borderRelative = TRUE; - /* Note that the parent's backgroundTile's refcnt is NOT - * incremented. */ - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap != (PixmapPtr) NULL) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixmap; - pWin->background.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBackPixel: - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = (CARD32 ) *pVlist; - /* background pixel overrides background pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBackPixmap; - pVlist++; - break; - case CWBorderPixmap: - pixID = (Pixmap ) *pVlist; - pVlist++; - if (pixID == CopyFromParent) - { - if (!pWin->parent || - (pWin->drawable.depth != pWin->parent->drawable.depth)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->border = pWin->parent->border; - if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE) - { - index2 = CWBorderPixel; - } - else - { - pWin->parent->border.pixmap->refcnt++; - } - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = FALSE; - pWin->border.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBorderPixel: - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = TRUE; - pWin->border.pixel = (CARD32) *pVlist; - /* border pixel overrides border pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBorderPixmap; - pVlist++; - break; - case CWBitGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->bitGravity = val; - break; - case CWWinGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->winGravity = val; - break; - case CWBackingStore: - val = (CARD8 )*pVlist; - pVlist++; - if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->backingStore = val; - - #ifdef TEST - fprintf(stderr, "ChangeWindowAttributes: Changed backing store value to %d for window at %p.\n", - val, (void*)pWin); - #endif - - pWin->forcedBS = FALSE; - break; - case CWBackingPlanes: - if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingBitPlanes = (CARD32) *pVlist; - if ((CARD32)*pVlist == (CARD32)~0L) - checkOptional = TRUE; - } - pVlist++; - break; - case CWBackingPixel: - if (pWin->optional || (CARD32) *pVlist) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingPixel = (CARD32) *pVlist; - if (!*pVlist) - checkOptional = TRUE; - } - pVlist++; - break; - case CWSaveUnder: - val = (BOOL) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } -#ifdef DO_SAVE_UNDERS - if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) && - DO_SAVE_UNDERS(pWin)) - { - /* - * Re-check all siblings and inferiors for obscurity or - * exposition (hee hee). - */ - if (pWin->saveUnder) - deltaSaveUndersViewable--; - else - deltaSaveUndersViewable++; - pWin->saveUnder = val; - - if (pWin->firstChild) - { - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pLayerWin->parent, - pWin->nextSib); - } - else - { - if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pWin, - pWin->nextSib); - } - } - else - { - /* If we're changing the saveUnder attribute of the root - * window, all we do is set pWin->saveUnder so that - * GetWindowAttributes returns the right value. We don't - * do the "normal" save-under processing (as above). - * Hope that doesn't cause any problems. - */ - pWin->saveUnder = val; - } -#else - pWin->saveUnder = val; -#endif /* DO_SAVE_UNDERS */ - break; - case CWEventMask: - /* - * TODO: Some applications like java bean shell - * don' t work if they cannot monitor the root - * window for Structure Redirect events. However - * this doesn't seem to be the best solution, since - * also an X server with a window manager running, - * doesn't allow to monitor for those events, but - * the java bean shell works flawlessy on this - * server. - * - * if (nxagentCheckIllegalRootMonitoring(pWin, (Mask)*pVlist)) - * { - * return BadAccess; - * } - */ - - result = EventSelectForWindow(pWin, client, (Mask )*pVlist); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWDontPropagate: - result = EventSuppressForWindow(pWin, client, (Mask )*pVlist, - &checkOptional); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWOverrideRedirect: - val = (BOOL ) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->overrideRedirect = val; - break; - case CWColormap: - cmap = (Colormap) *pVlist; - pVlist++; - if (cmap == CopyFromParent) - { -#ifdef XAPPGROUP - Colormap ag_colormap; - ClientPtr win_owner; - - /* - * win_owner == client for CreateWindow, other clients - * can ChangeWindowAttributes - */ - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - - if ( win_owner && win_owner->appgroup && - !pWin->parent->parent && - (ag_colormap = XagDefaultColormap (win_owner))) - cmap = ag_colormap; - else -#endif - if (pWin->parent && - (!pWin->optional || - pWin->optional->visual == wVisual (pWin->parent))) - { - cmap = wColormap (pWin->parent); - } - else - cmap = None; - } - if (cmap == None) - { - error = BadMatch; - goto PatchUp; - } - pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap, - RT_COLORMAP, SecurityReadAccess); - if (!pCmap) - { - error = BadColor; - client->errorValue = cmap; - goto PatchUp; - } - if (pCmap->pVisual->vid != wVisual (pWin) || - pCmap->pScreen != pScreen) - { - error = BadMatch; - goto PatchUp; - } - if (cmap != wColormap (pWin)) - { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && cmap == wColormap (pWin->parent)) - checkOptional = TRUE; - - /* - * propagate the original colormap to any children - * inheriting it - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pWin->optional->colormap = cmap; - - /* - * check on any children now matching the new colormap - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional->colormap == cmap) - CheckWindowOptionalNeed (pChild); - } - - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pWin->drawable.id; - xE.u.colormap.colormap = cmap; - xE.u.colormap.new = xTrue; - xE.u.colormap.state = IsMapInstalled(cmap, pWin); - DeliverEvents(pWin, &xE, 1, NullWindow); - } - break; - case CWCursor: - cursorID = (Cursor ) *pVlist; - pVlist++; - /* - * install the new - */ - if ( cursorID == None) - { - if (pWin == WindowTable[pWin->drawable.pScreen->myNum]) - pCursor = rootCursor; - else - pCursor = (CursorPtr) None; - } - else - { - pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID, - RT_CURSOR, SecurityReadAccess); - if (!pCursor) - { - error = BadCursor; - client->errorValue = cursorID; - goto PatchUp; - } - } - - if (pCursor != wCursor (pWin)) - { - /* - * patch up child windows so they don't lose cursors. - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !pChild->cursorIsNone && - !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pOldCursor = 0; - if (pCursor == (CursorPtr) None) - { - pWin->cursorIsNone = TRUE; - if (pWin->optional) - { - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = (CursorPtr) None; - checkOptional = TRUE; - } - } else { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && pCursor == wCursor (pWin->parent)) - checkOptional = TRUE; - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = pCursor; - pCursor->refcnt++; - pWin->cursorIsNone = FALSE; - /* - * check on any children now matching the new cursor - */ - - for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional && - (pChild->optional->cursor == pCursor)) - CheckWindowOptionalNeed (pChild); - } - } - - if (pWin->realized) - WindowHasNewCursor( pWin); - - /* Can't free cursor until here - old cursor - * is needed in WindowHasNewCursor - */ - if (pOldCursor) - FreeCursor (pOldCursor, (Cursor)0); - } - break; - default: - error = BadValue; - client->errorValue = vmask; - goto PatchUp; - } - vmaskCopy |= index2; - } -PatchUp: - if (checkOptional) - CheckWindowOptionalNeed (pWin); - - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy); - - /* - If the border contents have changed, redraw the border. - Note that this has to be done AFTER pScreen->ChangeWindowAttributes - for the tile to be rotated, and the correct function selected. - */ - if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative) - && pWin->viewable && HasBorder (pWin)) - { - RegionRec exposed; - - REGION_INIT(pScreen, &exposed, NullBox, 0); - REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize); - (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER); - REGION_UNINIT(pScreen, &exposed); - } - return error; -} - - -/***** - * GetWindowAttributes - * Notice that this is different than ChangeWindowAttributes - *****/ - -void -GetWindowAttributes(pWin, client, wa) - register WindowPtr pWin; - ClientPtr client; - xGetWindowAttributesReply *wa; -{ - wa->type = X_Reply; - wa->bitGravity = pWin->bitGravity; - wa->winGravity = pWin->winGravity; - if (pWin->forcedBS && pWin->backingStore != Always) - wa->backingStore = NotUseful; - else - wa->backingStore = pWin->backingStore; - wa->length = (sizeof(xGetWindowAttributesReply) - - sizeof(xGenericReply)) >> 2; - wa->sequenceNumber = client->sequence; - wa->backingBitPlanes = wBackingBitPlanes (pWin); - wa->backingPixel = wBackingPixel (pWin); - wa->saveUnder = (BOOL)pWin->saveUnder; - wa->override = pWin->overrideRedirect; - if (!pWin->mapped) - wa->mapState = IsUnmapped; - else if (pWin->realized) - wa->mapState = IsViewable; - else - wa->mapState = IsUnviewable; - - wa->colormap = wColormap (pWin); - wa->mapInstalled = (wa->colormap == None) ? xFalse - : IsMapInstalled(wa->colormap, pWin); - - wa->yourEventMask = EventMaskForClient(pWin, client); - wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin); - wa->doNotPropagateMask = wDontPropagateMask (pWin); - wa->class = pWin->drawable.class; - wa->visualID = wVisual (pWin); -} - - -WindowPtr -MoveWindowInStack(pWin, pNextSib) - register WindowPtr pWin, pNextSib; -{ - register WindowPtr pParent = pWin->parent; - WindowPtr pFirstChange = pWin; /* highest window where list changes */ - - if (pWin->nextSib != pNextSib) - { - WindowPtr pOldNextSib = pWin->nextSib; - - if (!pNextSib) /* move to bottom */ - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL - * and pWin->nextSib != pNextSib - * therefore pWin->nextSib != NULL */ - pFirstChange = pWin->nextSib; - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pParent->lastChild->nextSib = pWin; - pWin->prevSib = pParent->lastChild; - pWin->nextSib = NullWindow; - pParent->lastChild = pWin; - } - else if (pParent->firstChild == pNextSib) /* move to top */ - { - pFirstChange = pWin; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pParent->firstChild; - pWin->prevSib = (WindowPtr ) NULL; - pNextSib->prevSib = pWin; - pParent->firstChild = pWin; - } - else /* move in middle of list */ - { - WindowPtr pOldNext = pWin->nextSib; - - pFirstChange = NullWindow; - if (pParent->firstChild == pWin) - pFirstChange = pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) { - pFirstChange = pWin; - pParent->lastChild = pWin->prevSib; - } - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pNextSib; - pWin->prevSib = pNextSib->prevSib; - if (pNextSib->prevSib) - pNextSib->prevSib->nextSib = pWin; - pNextSib->prevSib = pWin; - if (!pFirstChange) { /* do we know it yet? */ - pFirstChange = pParent->firstChild; /* no, search from top */ - while ((pFirstChange != pWin) && (pFirstChange != pOldNext)) - pFirstChange = pFirstChange->nextSib; - } - } - if(pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib); - } - - return( pFirstChange ); -} - -RegionPtr -CreateUnclippedWinSize (pWin) - register WindowPtr pWin; -{ - RegionPtr pRgn; - BoxRec box; - - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + (int) pWin->drawable.width; - box.y2 = pWin->drawable.y + (int) pWin->drawable.height; - pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { - REGION_PTR(pScreen, pWin) - - REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y); - } -#endif - return pRgn; -} - -void -SetWinSize (pWin) - register WindowPtr pWin; -{ - ClippedRegionFromBox(pWin->parent, &pWin->winSize, - pWin->drawable.x, pWin->drawable.y, - (int)pWin->drawable.width, - (int)pWin->drawable.height); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { - REGION_PTR(pScreen, pWin) - - REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wClipShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x, - pWin->drawable.y); - } -#endif -} - -void -SetBorderSize (pWin) - register WindowPtr pWin; -{ - int bw; - - if (HasBorder (pWin)) { - bw = wBorderWidth (pWin); - ClippedRegionFromBox(pWin->parent, &pWin->borderSize, - pWin->drawable.x - bw, pWin->drawable.y - bw, - (int)(pWin->drawable.width + (bw<<1)), - (int)(pWin->drawable.height + (bw<<1))); -#ifdef SHAPE - if (wBoundingShape (pWin)) { - REGION_PTR(pScreen, pWin) - - REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x, - - pWin->drawable.y); - REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize, - wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x, - pWin->drawable.y); - REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize, - &pWin->winSize); - } -#endif - } else { - REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize, - &pWin->winSize); - } -} - -void -GravityTranslate (x, y, oldx, oldy, dw, dh, gravity, destx, desty) - register int x, y; /* new window position */ - int oldx, oldy; /* old window position */ - int dw, dh; - unsigned gravity; - register int *destx, *desty; /* position relative to gravity */ -{ - switch (gravity) { - case NorthGravity: - *destx = x + dw / 2; - *desty = y; - break; - case NorthEastGravity: - *destx = x + dw; - *desty = y; - break; - case WestGravity: - *destx = x; - *desty = y + dh / 2; - break; - case CenterGravity: - *destx = x + dw / 2; - *desty = y + dh / 2; - break; - case EastGravity: - *destx = x + dw; - *desty = y + dh / 2; - break; - case SouthWestGravity: - *destx = x; - *desty = y + dh; - break; - case SouthGravity: - *destx = x + dw / 2; - *desty = y + dh; - break; - case SouthEastGravity: - *destx = x + dw; - *desty = y + dh; - break; - case StaticGravity: - *destx = oldx; - *desty = oldy; - break; - default: - *destx = x; - *desty = y; - break; - } -} - -/* XXX need to retile border on each window with ParentRelative origin */ -void -ResizeChildrenWinSize(pWin, dx, dy, dw, dh) - register WindowPtr pWin; - int dx, dy, dw, dh; -{ - register ScreenPtr pScreen; - register WindowPtr pSib, pChild; - Bool resized = (dw || dh); - - pScreen = pWin->drawable.pScreen; - - for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) - { - if (resized && (pSib->winGravity > NorthWestGravity)) - { - int cwsx, cwsy; - - cwsx = pSib->origin.x; - cwsy = pSib->origin.y; - GravityTranslate (cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh, - pSib->winGravity, &cwsx, &cwsy); - if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) - { - xEvent event; - - event.u.u.type = GravityNotify; - event.u.gravity.window = pSib->drawable.id; - event.u.gravity.x = cwsx - wBorderWidth (pSib); - event.u.gravity.y = cwsy - wBorderWidth (pSib); - DeliverEvents (pSib, &event, 1, NullWindow); - pSib->origin.x = cwsx; - pSib->origin.y = cwsy; - } - } - pSib->drawable.x = pWin->drawable.x + pSib->origin.x; - pSib->drawable.y = pWin->drawable.y + pSib->origin.y; - SetWinSize (pSib); - SetBorderSize (pSib); - - /* - * Don't force X to move children. It will position them - * according with gravity. - * - * (*pScreen->PositionWindow)(pSib, pSib->drawable.x, pSib->drawable.y); - */ - - /* - * Update pSib privates, as this window is moved by X. - */ - - nxagentAddConfiguredWindow(pSib, CW_Update); - - if ( (pChild = pSib->firstChild) ) - { - while (1) - { - pChild->drawable.x = pChild->parent->drawable.x + - pChild->origin.x; - pChild->drawable.y = pChild->parent->drawable.y + - pChild->origin.y; - SetWinSize (pChild); - SetBorderSize (pChild); - - (*pScreen->PositionWindow)(pChild, pChild->drawable.x, - pChild->drawable.y); - - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pSib)) - pChild = pChild->parent; - if (pChild == pSib) - break; - pChild = pChild->nextSib; - } - } - } -} - -#define GET_INT16(m, f) \ - if (m & mask) \ - { \ - f = (INT16) *pVlist;\ - pVlist++; \ - } -#define GET_CARD16(m, f) \ - if (m & mask) \ - { \ - f = (CARD16) *pVlist;\ - pVlist++;\ - } - -#define GET_CARD8(m, f) \ - if (m & mask) \ - { \ - f = (CARD8) *pVlist;\ - pVlist++;\ - } - -#define ChangeMask ((Mask)(CWX | CWY | CWWidth | CWHeight)) - -#define IllegalInputOnlyConfigureMask (CWBorderWidth) - -/* - * IsSiblingAboveMe - * returns Above if pSib above pMe in stack or Below otherwise - */ - -static int -#if NeedFunctionPrototypes -IsSiblingAboveMe( - register WindowPtr pMe, - register WindowPtr pSib) -#else -IsSiblingAboveMe(pMe, pSib) - register WindowPtr pMe, pSib; -#endif -{ - register WindowPtr pWin; - - pWin = pMe->parent->firstChild; - while (pWin) - { - if (pWin == pSib) - return(Above); - else if (pWin == pMe) - return(Below); - pWin = pWin->nextSib; - } - return(Below); -} - -static BoxPtr -#if NeedFunctionPrototypes -WindowExtents( - register WindowPtr pWin, - register BoxPtr pBox) -#else -WindowExtents(pWin, pBox) - register WindowPtr pWin; - register BoxPtr pBox; -#endif -{ - pBox->x1 = pWin->drawable.x - wBorderWidth (pWin); - pBox->y1 = pWin->drawable.y - wBorderWidth (pWin); - pBox->x2 = pWin->drawable.x + (int)pWin->drawable.width - + wBorderWidth (pWin); - pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height - + wBorderWidth (pWin); - return(pBox); -} - -#ifdef SHAPE -#define IS_SHAPED(pWin) (wBoundingShape (pWin) != (RegionPtr) NULL) - -static RegionPtr -#if NeedFunctionPrototypes -MakeBoundingRegion ( - register WindowPtr pWin, - BoxPtr pBox) -#else -MakeBoundingRegion (pWin, pBox) - register WindowPtr pWin; - BoxPtr pBox; -#endif -{ - RegionPtr pRgn; - REGION_PTR(pScreen, pWin) - - pRgn = REGION_CREATE(pScreen, pBox, 1); - if (wBoundingShape (pWin)) { - REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x, - -pWin->origin.y); - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x, - pWin->origin.y); - } - return pRgn; -} - -static Bool -#if NeedFunctionPrototypes -ShapeOverlap ( - WindowPtr pWin, - BoxPtr pWinBox, - WindowPtr pSib, - BoxPtr pSibBox) -#else -ShapeOverlap (pWin, pWinBox, pSib, pSibBox) - WindowPtr pWin, pSib; - BoxPtr pWinBox, pSibBox; -#endif -{ - RegionPtr pWinRgn, pSibRgn; - register ScreenPtr pScreen; - Bool ret; - - if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib)) - return TRUE; - pScreen = pWin->drawable.pScreen; - pWinRgn = MakeBoundingRegion (pWin, pWinBox); - pSibRgn = MakeBoundingRegion (pSib, pSibBox); - REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn); - ret = REGION_NOTEMPTY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pSibRgn); - return ret; -} -#endif - -static Bool -#if NeedFunctionPrototypes -AnyWindowOverlapsMe( - WindowPtr pWin, - WindowPtr pHead, - register BoxPtr box) -#else -AnyWindowOverlapsMe(pWin, pHead, box) - WindowPtr pWin, pHead; - register BoxPtr box; -#endif -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -static Bool -#if NeedFunctionPrototypes -IOverlapAnyWindow( - WindowPtr pWin, - register BoxPtr box) -#else -IOverlapAnyWindow(pWin, box) - WindowPtr pWin; - register BoxPtr box; -#endif -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -/* - * WhereDoIGoInTheStack() - * Given pWin and pSib and the relationshipe smode, return - * the window that pWin should go ABOVE. - * If a pSib is specified: - * Above: pWin is placed just above pSib - * Below: pWin is placed just below pSib - * TopIf: if pSib occludes pWin, then pWin is placed - * at the top of the stack - * BottomIf: if pWin occludes pSib, then pWin is - * placed at the bottom of the stack - * Opposite: if pSib occludes pWin, then pWin is placed at the - * top of the stack, else if pWin occludes pSib, then - * pWin is placed at the bottom of the stack - * - * If pSib is NULL: - * Above: pWin is placed at the top of the stack - * Below: pWin is placed at the bottom of the stack - * TopIf: if any sibling occludes pWin, then pWin is placed at - * the top of the stack - * BottomIf: if pWin occludes any sibline, then pWin is placed at - * the bottom of the stack - * Opposite: if any sibling occludes pWin, then pWin is placed at - * the top of the stack, else if pWin occludes any - * sibling, then pWin is placed at the bottom of the stack - * - */ - -static WindowPtr -#if NeedFunctionPrototypes -WhereDoIGoInTheStack( - register WindowPtr pWin, - register WindowPtr pSib, - short x, - short y, - unsigned short w, - unsigned short h, - int smode) -#else -WhereDoIGoInTheStack(pWin, pSib, x, y, w, h, smode) - register WindowPtr pWin, pSib; - short x, y; - unsigned short w, h; - int smode; -#endif -{ - BoxRec box; - register ScreenPtr pScreen; - WindowPtr pHead, pFirst; - - if ((pWin == pWin->parent->firstChild) && - (pWin == pWin->parent->lastChild)) - return((WindowPtr ) NULL); - pHead = RealChildHead(pWin->parent); - pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild; - pScreen = pWin->drawable.pScreen; - box.x1 = x; - box.y1 = y; - box.x2 = x + (int)w; - box.y2 = y + (int)h; - switch (smode) - { - case Above: - if (pSib) - return(pSib); - else if (pWin == pFirst) - return(pWin->nextSib); - else - return(pFirst); - case Below: - if (pSib) - if (pSib->nextSib != pWin) - return(pSib->nextSib); - else - return(pWin->nextSib); - else - return NullWindow; - case TopIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Above) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return(pFirst); - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - return(pFirst); - else - return(pWin->nextSib); - case BottomIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Below) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return NullWindow; - else - return(pWin->nextSib); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return(pWin->nextSib); - case Opposite: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT) - { - if (IsSiblingAboveMe(pWin, pSib) == Above) - return(pFirst); - else - return NullWindow; - } - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - { - /* If I'm occluded, I can't possibly be the first child - * if (pWin == pWin->parent->firstChild) - * return pWin->nextSib; - */ - return(pFirst); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return pWin->nextSib; - default: - { - ErrorF("Internal error in ConfigureWindow, smode == %d\n",smode ); - return pWin->nextSib; - } - } -} - -static void -#if NeedFunctionPrototypes -ReflectStackChange( - register WindowPtr pWin, - register WindowPtr pSib, - VTKind kind) -#else -ReflectStackChange(pWin, pSib, kind) - register WindowPtr pWin, pSib; - VTKind kind; -#endif -{ -/* Note that pSib might be NULL */ - - Bool WasViewable = (Bool)pWin->viewable; - WindowPtr pParent; - Bool anyMarked; - WindowPtr pFirstChange; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - ScreenPtr pScreen = pWin->drawable.pScreen; - - /* if this is a root window, can't be restacked */ - if (!(pParent = pWin->parent)) - return ; - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - &pLayerWin); - if (pLayerWin != pWin) pFirstChange = pLayerWin; -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, kind); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pWin->drawable.pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - -/***** - * ConfigureWindow - *****/ - -int -ConfigureWindow(pWin, mask, vlist, client) - register WindowPtr pWin; - register Mask mask; - XID *vlist; - ClientPtr client; -{ -#define RESTACK_WIN 0 -#define MOVE_WIN 1 -#define RESIZE_WIN 2 -#define REBORDER_WIN 3 - register WindowPtr pSib = NullWindow; - register WindowPtr pParent = pWin->parent; - Window sibwid = 0; - Mask index2, tmask; - register XID *pVlist; - short x, y, beforeX, beforeY; - unsigned short w = pWin->drawable.width, - h = pWin->drawable.height, - bw = pWin->borderWidth; - int action, smode = Above; -#ifdef XAPPGROUP - ClientPtr win_owner; - ClientPtr ag_leader = NULL; -#endif - xEvent event; - - if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask)) - return(BadMatch); - - if ((mask & CWSibling) && !(mask & CWStackMode)) - return(BadMatch); - - pVlist = vlist; - - if (pParent) - { - x = pWin->drawable.x - pParent->drawable.x - (int)bw; - y = pWin->drawable.y - pParent->drawable.y - (int)bw; - } - else - { - x = pWin->drawable.x; - y = pWin->drawable.y; - } - beforeX = x; - beforeY = y; - action = RESTACK_WIN; - if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - action = MOVE_WIN; - } - /* or should be resized */ - else if (mask & (CWX | CWY | CWWidth | CWHeight)) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - GET_CARD16(CWWidth, w); - GET_CARD16 (CWHeight, h); - if (!w || !h) - { - client->errorValue = 0; - return BadValue; - } - action = RESIZE_WIN; - } - tmask = mask & ~ChangeMask; - while (tmask) - { - index2 = (Mask)lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBorderWidth: - GET_CARD16(CWBorderWidth, bw); - break; - case CWSibling: - sibwid = (Window ) *pVlist; - pVlist++; - pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid, - RT_WINDOW, SecurityReadAccess); - if (!pSib) - { - client->errorValue = sibwid; - return(BadWindow); - } - if (pSib->parent != pParent) - return(BadMatch); - if (pSib == pWin) - return(BadMatch); - break; - case CWStackMode: - GET_CARD8(CWStackMode, smode); - if ((smode != TopIf) && (smode != BottomIf) && - (smode != Opposite) && (smode != Above) && (smode != Below)) - { - client->errorValue = smode; - return(BadValue); - } - break; - default: - client->errorValue = mask; - return(BadValue); - } - } - /* root really can't be reconfigured, so just return */ - if (!pParent) - return Success; - - /* Figure out if the window should be moved. Doesnt - make the changes to the window if event sent */ - - #ifdef TEST - if (nxagentWindowTopLevel(pWin)) - { - - fprintf(stderr, "ConfigureWindow: pWin [%p] mask [%lu] client [%p]\n", - pWin, mask, client); - - fprintf(stderr, "ConfigureWindow: x [%d] y [%d] w [%d] h [%d] CWStackMode [%d] " - "smode [%d] pSib [%p]\n", - x, y, w, h, (mask & CWStackMode) ? 1 : 0, smode, pSib); - } - #endif - - if (nxagentOption(Rootless) && nxagentWindowTopLevel(pWin) && - pWin -> overrideRedirect == 0 && - nxagentScreenTrap == 0) - { - nxagentConfigureRootlessWindow(pWin, x, y, w, h, bw, pSib, smode, mask); - - return Success; - } - - if (mask & CWStackMode) - pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x, - pParent->drawable.y + y, - w + (bw << 1), h + (bw << 1), smode); - else - pSib = pWin->nextSib; - -#ifdef XAPPGROUP - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = ConfigureRequest; - event.u.configureRequest.window = pWin->drawable.id; - if (mask & CWSibling) - event.u.configureRequest.sibling = sibwid; - else - event.u.configureRequest.sibling = None; - if (mask & CWStackMode) - event.u.u.detail = smode; - else - event.u.u.detail = Above; - event.u.configureRequest.x = x; - event.u.configureRequest.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureRequest.x += panoramiXdataPtr[0].x; - event.u.configureRequest.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureRequest.width = w; - event.u.configureRequest.height = h; - event.u.configureRequest.borderWidth = bw; - event.u.configureRequest.valueMask = mask; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.configureRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.configureRequest.parent = pParent->drawable.id; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - if (action == RESIZE_WIN) - { - Bool size_change = (w != pWin->drawable.width) - || (h != pWin->drawable.height); - if (size_change && ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask)) - { - xEvent eventT; - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = w; - eventT.u.resizeRequest.height = h; - if (MaybeDeliverEventsToClient(pWin, &eventT, 1, - ResizeRedirectMask, client) == 1) - { - /* if event is delivered, leave the actual size alone. */ - w = pWin->drawable.width; - h = pWin->drawable.height; - size_change = FALSE; - } - } - if (!size_change) - { - if (mask & (CWX | CWY)) - action = MOVE_WIN; - else if (mask & (CWStackMode | CWBorderWidth)) - action = RESTACK_WIN; - else /* really nothing to do */ - return(Success) ; - } - } - - if (action == RESIZE_WIN) - /* we've already checked whether there's really a size change */ - goto ActuallyDoSomething; - if ((mask & CWX) && (x != beforeX)) - goto ActuallyDoSomething; - if ((mask & CWY) && (y != beforeY)) - goto ActuallyDoSomething; - if ((mask & CWBorderWidth) && (bw != wBorderWidth (pWin))) - goto ActuallyDoSomething; - if (mask & CWStackMode) - { - if (pWin->nextSib != pSib) - goto ActuallyDoSomething; - } - return(Success); - -ActuallyDoSomething: - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - if (pSib) - event.u.configureNotify.aboveSibling = pSib->drawable.id; - else - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = x; - event.u.configureNotify.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureNotify.x += panoramiXdataPtr[0].x; - event.u.configureNotify.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureNotify.width = w; - event.u.configureNotify.height = h; - event.u.configureNotify.borderWidth = bw; - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (mask & CWBorderWidth) - { - if (action == RESTACK_WIN) - { - action = MOVE_WIN; - pWin->borderWidth = bw; - } - else if ((action == MOVE_WIN) && - (beforeX + wBorderWidth (pWin) == x + (int)bw) && - (beforeY + wBorderWidth (pWin) == y + (int)bw)) - { - action = REBORDER_WIN; - (*pWin->drawable.pScreen->ChangeBorderWidth)(pWin, bw); - } - else - pWin->borderWidth = bw; - } - if (action == MOVE_WIN) - (*pWin->drawable.pScreen->MoveWindow)(pWin, x, y, pSib, - (mask & CWBorderWidth) ? VTOther : VTMove); - else if (action == RESIZE_WIN) - (*pWin->drawable.pScreen->ResizeWindow)(pWin, x, y, w, h, pSib); - else if (mask & CWStackMode) - ReflectStackChange(pWin, pSib, VTOther); - - if (action != RESTACK_WIN) - CheckCursorConfinement(pWin); - - nxagentFlushConfigureWindow(); - - return(Success); -#undef RESTACK_WIN -#undef MOVE_WIN -#undef RESIZE_WIN -#undef REBORDER_WIN -} - - -/****** - * - * CirculateWindow - * For RaiseLowest, raises the lowest mapped child (if any) that is - * obscured by another child to the top of the stack. For LowerHighest, - * lowers the highest mapped child (if any) that is obscuring another - * child to the bottom of the stack. Exposure processing is performed - * - ******/ - -int -CirculateWindow(pParent, direction, client) - WindowPtr pParent; - int direction; - ClientPtr client; -{ - register WindowPtr pWin, pHead, pFirst; - xEvent event; - BoxRec box; - - #ifdef TEST - fprintf(stderr, "CirculateWindow: pParent [%p] direction [%d] client [%p]\n", - pParent, direction, client); - #endif - - /* - * if (nxagentOption(Rootless) && nxagentWMIsRunning && - * nxagentWindowTopLevel(pWin) && pWin -> overrideRedirect == 0) - * { - * nxagentCirculateRootlessWindows(direction); - * return Success; - * } - */ - - pHead = RealChildHead(pParent); - pFirst = pHead ? pHead->nextSib : pParent->firstChild; - if (direction == RaiseLowest) - { - for (pWin = pParent->lastChild; - (pWin != pHead) && - !(pWin->mapped && - AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box))); - pWin = pWin->prevSib) ; - if (pWin == pHead) - return Success; - } - else - { - for (pWin = pFirst; - pWin && - !(pWin->mapped && - IOverlapAnyWindow(pWin, WindowExtents(pWin, &box))); - pWin = pWin->nextSib) ; - if (!pWin) - return Success; - } - - event.u.circulate.window = pWin->drawable.id; - event.u.circulate.parent = pParent->drawable.id; - event.u.circulate.event = pParent->drawable.id; - if (direction == RaiseLowest) - event.u.circulate.place = PlaceOnTop; - else - event.u.circulate.place = PlaceOnBottom; - - if (RedirectSend(pParent)) - { - event.u.u.type = CirculateRequest; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - event.u.u.type = CirculateNotify; - DeliverEvents(pWin, &event, 1, NullWindow); - ReflectStackChange(pWin, - (direction == RaiseLowest) ? pFirst : NullWindow, - VTStack); - - return(Success); -} - -static int -#if NeedFunctionPrototypes -CompareWIDs( - WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -#else -CompareWIDs(pWin, value) - WindowPtr pWin; - pointer value; /* must conform to VisitWindowProcPtr */ -#endif -{ - Window *wid = (Window *)value; - - if (pWin->drawable.id == *wid) - return(WT_STOPWALKING); - else - return(WT_WALKCHILDREN); -} - -/***** - * ReparentWindow - *****/ - -int -ReparentWindow(pWin, pParent, x, y, client) - register WindowPtr pWin, pParent; - int x,y; - ClientPtr client; -{ - WindowPtr pPrev, pPriorParent; - Bool WasMapped = (Bool)(pWin->mapped); - xEvent event; - int bw = wBorderWidth (pWin); - register ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING) - return(BadMatch); - if (!MakeWindowOptional(pWin)) - return(BadAlloc); - - if (WasMapped) - UnmapWindow(pWin, FALSE); - - event.u.u.type = ReparentNotify; - event.u.reparent.window = pWin->drawable.id; - event.u.reparent.parent = pParent->drawable.id; - event.u.reparent.x = x; - event.u.reparent.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pParent->parent) { - event.u.reparent.x += panoramiXdataPtr[0].x; - event.u.reparent.y += panoramiXdataPtr[0].y; - } -#endif - event.u.reparent.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, pParent); - - /* take out of sibling chain */ - - pPriorParent = pPrev = pWin->parent; - if (pPrev->firstChild == pWin) - pPrev->firstChild = pWin->nextSib; - if (pPrev->lastChild == pWin) - pPrev->lastChild = pWin->prevSib; - - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - - /* insert at begining of pParent */ - pWin->parent = pParent; - pPrev = RealChildHead(pParent); - - if (pWin->parent == WindowTable[0]) - { - nxagentSetTopLevelEventMask(pWin); - } - - if (pPrev) - { - pWin->nextSib = pPrev->nextSib; - if (pPrev->nextSib) - pPrev->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pPrev->nextSib = pWin; - pWin->prevSib = pPrev; - } - else - { - pWin->nextSib = pParent->firstChild; - pWin->prevSib = NullWindow; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.x = x + bw + pParent->drawable.x; - pWin->drawable.y = y + bw + pParent->drawable.y; - - /* clip to parent */ - SetWinSize (pWin); - SetBorderSize (pWin); - - if (pScreen->ReparentWindow) - (*pScreen->ReparentWindow)(pWin, pPriorParent); - - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - CheckWindowOptionalNeed(pWin); - - if (WasMapped) - MapWindow(pWin, client); - RecalculateDeliverableEvents(pWin); - return(Success); -} - -static void -#if NeedFunctionPrototypes -RealizeTree(WindowPtr pWin) -#else -RealizeTree(pWin) - WindowPtr pWin; -#endif -{ - register WindowPtr pChild; - RealizeWindowProcPtr Realize; - - Realize = pWin->drawable.pScreen->RealizeWindow; - pChild = pWin; - while (1) - { - if (pChild->mapped) - { - pChild->realized = TRUE; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable++; -#endif - pChild->viewable = (pChild->drawable.class == InputOutput); - (* Realize)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * MapWindow - * If some other client has selected SubStructureReDirect on the parent - * and override-redirect is xFalse, then a MapRequest event is generated, - * but the window remains unmapped. Otherwise, the window is mapped and a - * MapNotify event is generated. - *****/ - -int -MapWindow(pWin, client) - register WindowPtr pWin; - ClientPtr client; -{ - register ScreenPtr pScreen; - - register WindowPtr pParent; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - #ifdef TEST - if (nxagentWindowTopLevel(pWin)) - { - fprintf(stderr, "MapWindow: pWin [%p] client [%p]\n", pWin, client); - } - #endif - - if (pWin->mapped) - return(Success); - -#ifdef XCSECURITY - /* don't let an untrusted client map a child-of-trusted-window, InputOnly - * window; too easy to steal device input - */ - if ( (client->trustLevel != XSecurityClientTrusted) && - (pWin->drawable.class == InputOnly) && - (wClient(pWin->parent)->trustLevel == XSecurityClientTrusted) ) - return Success; -#endif - - pScreen = pWin->drawable.pScreen; - if ( (pParent = pWin->parent) ) - { - xEvent event; - Bool anyMarked; -#ifdef XAPPGROUP - ClientPtr win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ClientPtr ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.mapRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - pWin->mapped = TRUE; - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pParent->realized) - return(Success); - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - } - WindowsRestructured (); - } - else - { - RegionRec temp; - - pWin->mapped = TRUE; - pWin->realized = TRUE; /* for roots */ - pWin->viewable = pWin->drawable.class == InputOutput; - /* We SHOULD check for an error value here XXX */ - (*pScreen->RealizeWindow)(pWin); - if (pScreen->ClipNotify) - (*pScreen->ClipNotify) (pWin, 0, 0); - if (pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap); - REGION_INIT(pScreen, &temp, NullBox, 0); - REGION_COPY(pScreen, &temp, &pWin->clipList); - (*pScreen->WindowExposures) (pWin, &temp, NullRegion); - REGION_UNINIT(pScreen, &temp); - } - - nxagentFlushConfigureWindow(); - - return(Success); -} - - -/***** - * MapSubwindows - * Performs a MapWindow all unmapped children of the window, in top - * to bottom stacking order. - *****/ - -void -MapSubwindows(pParent, client) - register WindowPtr pParent; - ClientPtr client; -{ - register WindowPtr pWin; - WindowPtr pFirstMapped = NullWindow; -#ifdef DO_SAVE_UNDERS - WindowPtr pFirstSaveUndered = NullWindow; -#endif - register ScreenPtr pScreen; - register Mask parentRedirect; - register Mask parentNotify; - xEvent event; - Bool anyMarked; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - pScreen = pParent->drawable.pScreen; - parentRedirect = RedirectSend(pParent); - parentNotify = SubSend(pParent); - anyMarked = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (!pWin->mapped) - { - if (parentRedirect && !pWin->overrideRedirect) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - continue; - } - - pWin->mapped = TRUE; - if (parentNotify || StrSend(pWin)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pFirstMapped) - pFirstMapped = pWin; - if (pParent->realized) - { - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = TRUE; - } -#endif /* DO_SAVE_UNDERS */ - } - } - } - } - - if (pFirstMapped) - { - pLayerWin = (*pScreen->GetLayerWindow)(pParent); - if (pLayerWin->parent != pParent) { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pLayerWin, - pLayerWin, - (WindowPtr *)NULL); - pFirstMapped = pLayerWin; - } - if (anyMarked) - { -#ifdef DO_SAVE_UNDERS - if (pLayerWin->parent != pParent) - { - if (dosave || (DO_SAVE_UNDERS(pLayerWin))) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, - pLayerWin); - } - } - else if (dosave) - { - dosave = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (DO_SAVE_UNDERS(pWin)) - { - dosave |= (*pScreen->ChangeSaveUnder)(pWin, - pWin->nextSib); - if (dosave && !pFirstSaveUndered) - pFirstSaveUndered = pWin; - } - } - } -#endif /* DO_SAVE_UNDERS */ - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstMapped, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, - pFirstSaveUndered->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstMapped, - VTMap); - WindowsRestructured (); - } -} - -static void -#if NeedFunctionPrototypes -UnrealizeTree( - WindowPtr pWin, - Bool fromConfigure) -#else -UnrealizeTree(pWin, fromConfigure) - WindowPtr pWin; - Bool fromConfigure; -#endif -{ - register WindowPtr pChild; - UnrealizeWindowProcPtr Unrealize; - MarkUnrealizedWindowProcPtr MarkUnrealizedWindow; - - Unrealize = pWin->drawable.pScreen->UnrealizeWindow; - MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow; - pChild = pWin; - while (1) - { - if (pChild->realized) - { - pChild->realized = FALSE; - pChild->visibility = VisibilityNotViewable; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { - PanoramiXRes *win; - win = (PanoramiXRes*)LookupIDByType(pChild->drawable.id, - XRT_WINDOW); - if(win) - win->u.win.visibility = VisibilityNotViewable; - } -#endif - (* Unrealize)(pChild); - DeleteWindowFromAnyEvents(pChild, FALSE); - if (pChild->viewable) - { -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->backStorage) - (*pChild->drawable.pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - (* MarkUnrealizedWindow)(pChild, pWin, fromConfigure); - pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * UnmapWindow - * If the window is already unmapped, this request has no effect. - * Otherwise, the window is unmapped and an UnMapNotify event is - * generated. Cannot unmap a root window. - *****/ - -int -UnmapWindow(pWin, fromConfigure) - register WindowPtr pWin; - Bool fromConfigure; -{ - register WindowPtr pParent; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - ScreenPtr pScreen = pWin->drawable.pScreen; - WindowPtr pLayerWin = pWin; - - #ifdef TEST - if (nxagentWindowTopLevel(pWin)) - { - fprintf(stderr, "UnmapWindow: pWin [%p] fromConfigure [%d]\n", pWin, - fromConfigure); - } - #endif - - if ((!pWin->mapped) || (!(pParent = pWin->parent))) - return(Success); - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pWin->drawable.id; - event.u.unmapNotify.fromConfigure = fromConfigure; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (wasViewable && !fromConfigure) - { - pWin->valdata = UnmapValData; - (*pScreen->MarkOverlappedWindows)(pWin, pWin->nextSib, &pLayerWin); - (*pScreen->MarkWindow)(pLayerWin->parent); - } - pWin->mapped = FALSE; - if (wasRealized) - UnrealizeTree(pWin, fromConfigure); - if (wasViewable) - { - if (!fromConfigure) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pWin, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib) ) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); - } - } - pWin->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (!fromConfigure && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pWin, VTUnmap); - } - if (wasRealized && !fromConfigure) - WindowsRestructured (); - return(Success); -} - -/***** - * UnmapSubwindows - * Performs an UnmapWindow request with the specified mode on all mapped - * children of the window, in bottom to top stacking order. - *****/ - -void -UnmapSubwindows(pWin) - register WindowPtr pWin; -{ - register WindowPtr pChild, pHead; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - Bool anyMarked = FALSE; - Mask parentNotify; - WindowPtr pLayerWin = NULL; - ScreenPtr pScreen = pWin->drawable.pScreen; - - if (!pWin->firstChild) - return; - parentNotify = SubSend(pWin); - pHead = RealChildHead(pWin); - - if (wasViewable) - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (pChild->mapped) - { - if (parentNotify || StrSend(pChild)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pChild->drawable.id; - event.u.unmapNotify.fromConfigure = xFalse; - DeliverEvents(pChild, &event, 1, NullWindow); - } - if (pChild->viewable) - { - pChild->valdata = UnmapValData; - anyMarked = TRUE; - } - pChild->mapped = FALSE; - if (pChild->realized) - UnrealizeTree(pChild, FALSE); - if (wasViewable) - { -#ifdef DO_SAVE_UNDERS - pChild->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (pChild->backStorage) - (*pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - } - } - } - if (wasViewable) - { - if (anyMarked) - { - if (pLayerWin->parent == pWin) - (*pScreen->MarkWindow)(pWin); - else - { - WindowPtr ptmp; - (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - (*pScreen->MarkWindow)(pLayerWin->parent); - - /* Windows between pWin and pLayerWin may not have been marked */ - ptmp = pWin; - - while (ptmp != pLayerWin->parent) - { - (*pScreen->MarkWindow)(ptmp); - ptmp = ptmp->parent; - } - pHead = pWin->firstChild; - } - (*pScreen->ValidateTree)(pLayerWin->parent, pHead, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin)) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pHead, VTUnmap); - } - if (wasRealized) - WindowsRestructured (); -} - - -void -HandleSaveSet(client) - register ClientPtr client; -{ - register WindowPtr pParent, pWin; - register int j; - - for (j=0; jnumSaved; j++) - { - pWin = (WindowPtr)client->saveSet[j]; - pParent = pWin->parent; - while (pParent && (wClient (pParent) == client)) - pParent = pParent->parent; - if (pParent) - { - if (pParent != pWin->parent) - { - ReparentWindow(pWin, pParent, - pWin->drawable.x - wBorderWidth (pWin) - pParent->drawable.x, - pWin->drawable.y - wBorderWidth (pWin) - pParent->drawable.y, - client); - if(!pWin->realized && pWin->mapped) - pWin->mapped = FALSE; - } - MapWindow(pWin, client); - } - } - xfree(client->saveSet); - client->numSaved = 0; - client->saveSet = (pointer *)NULL; -} - -Bool -VisibleBoundingBoxFromPoint(pWin, x, y, box) - register WindowPtr pWin; - int x, y; /* in root */ - BoxPtr box; /* "return" value */ -{ - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->clipList, x, y, box)) - return(TRUE); - return(FALSE); -} - -Bool -PointInWindowIsVisible(pWin, x, y) - register WindowPtr pWin; - int x, y; /* in root */ -{ - BoxRec box; - - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip, - x, y, &box)) - return(TRUE); - return(FALSE); -} - - -RegionPtr -NotClippedByChildren(pWin) - register WindowPtr pWin; -{ - register ScreenPtr pScreen; - RegionPtr pReg; - - pScreen = pWin->drawable.pScreen; - pReg = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->parent || - screenIsSaved != SCREEN_SAVER_ON || - !HasSaverWindow (pWin->drawable.pScreen->myNum)) - { - REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize); - } - return(pReg); -} - -void -SendVisibilityNotify(pWin) - WindowPtr pWin; -{ - xEvent event; - unsigned int visibility = pWin->visibility; - -#ifdef PANORAMIX - /* This is not quite correct yet, but it's close */ - if(!noPanoramiXExtension) { - PanoramiXRes *win; - WindowPtr pWin2; - int i, Scrnum; - - Scrnum = pWin->drawable.pScreen->myNum; - - win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, Scrnum); - - if(!win || (win->u.win.visibility == visibility)) - return; - - switch(visibility) { - case VisibilityUnobscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility == VisibilityPartiallyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - case VisibilityPartiallyObscured: - if(Scrnum) { - pWin2 = (WindowPtr)LookupIDByType(win->info[0].id, RT_WINDOW); - if (pWin2) pWin = pWin2; - } - break; - case VisibilityFullyObscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility != VisibilityFullyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - } - - win->u.win.visibility = visibility; - } -#endif - - event.u.u.type = VisibilityNotify; - event.u.visibility.window = pWin->drawable.id; - event.u.visibility.state = visibility; - DeliverEvents(pWin, &event, 1, NullWindow); -} - - -#define RANDOM_WIDTH 32 - -#ifndef NOLOGOHACK -static void DrawLogo( -#if NeedFunctionPrototypes - WindowPtr /*pWin*/ -#endif -); -#endif - -void -SaveScreens(on, mode) - int on; - int mode; -{ - int i; - int what; - int type; - - if (on == SCREEN_SAVER_FORCER) - { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; - if (mode == ScreenSaverReset) - what = SCREEN_SAVER_OFF; - else - what = SCREEN_SAVER_ON; - type = what; - } - else - { - what = on; - type = what; - if (what == screenIsSaved) - type = SCREEN_SAVER_CYCLE; - } - for (i = 0; i < screenInfo.numScreens; i++) - { - if (on == SCREEN_SAVER_FORCER) - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], on); - if (savedScreenInfo[i].ExternalScreenSaver) - { - if (nxagentOption(Timeout) != 0) - { - #ifdef TEST - fprintf(stderr, "SaveScreens: An external screen-saver handler is installed. " - "Ignoring it to let the auto-disconnect feature work.\n"); - #endif - } - else - { - if ((*savedScreenInfo[i].ExternalScreenSaver) - (screenInfo.screens[i], type, on == SCREEN_SAVER_FORCER)) - continue; - } - } - if (type == screenIsSaved) - continue; - switch (type) { - case SCREEN_SAVER_OFF: - if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - what); - } - else if (HasSaverWindow (i)) - { - savedScreenInfo[i].pWindow = NullWindow; - FreeResource(savedScreenInfo[i].wid, RT_NONE); - } - break; - case SCREEN_SAVER_CYCLE: - if (savedScreenInfo[i].blanked == SCREEN_IS_TILED) - { - WindowPtr pWin = savedScreenInfo[i].pWindow; - /* make it look like screen saver is off, so that - * NotClippedByChildren will compute a clip list - * for the root window, so miPaintWindow works - */ - screenIsSaved = SCREEN_SAVER_OFF; -#ifndef NOLOGOHACK - if (logoScreenSaver) - (*pWin->drawable.pScreen->ClearToBackground)(pWin, 0, 0, 0, 0, FALSE); -#endif - (*pWin->drawable.pScreen->MoveWindow)(pWin, - (short)(-(rand() % RANDOM_WIDTH)), - (short)(-(rand() % RANDOM_WIDTH)), - pWin->nextSib, VTMove); -#ifndef NOLOGOHACK - if (logoScreenSaver) - DrawLogo(pWin); -#endif - screenIsSaved = SCREEN_SAVER_ON; - } - /* - * Call the DDX saver in case it wants to do something - * at cycle time - */ - else if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - type); - } - break; - case SCREEN_SAVER_ON: - if (ScreenSaverBlanking != DontPreferBlanking) - { - if ((* screenInfo.screens[i]->SaveScreen) - (screenInfo.screens[i], what)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLANKED; - continue; - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_BLACK)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLACK; - continue; - } - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_TILED)) - { - savedScreenInfo[i].blanked = SCREEN_IS_TILED; - } - else - savedScreenInfo[i].blanked = SCREEN_ISNT_SAVED; - break; - } - } - screenIsSaved = what; -} - -static Bool -#if NeedFunctionPrototypes -TileScreenSaver(int i, int kind) -#else -TileScreenSaver(i, kind) - int i; - int kind; -#endif -{ - int j; - int result; - XID attributes[3]; - Mask mask; - WindowPtr pWin; - CursorMetricRec cm; - unsigned char *srcbits, *mskbits; - CursorPtr cursor; - XID cursorID = 0; - int attri; - - mask = 0; - attri = 0; - switch (kind) { - case SCREEN_IS_TILED: - switch (WindowTable[i]->backgroundState) { - case BackgroundPixel: - attributes[attri++] = WindowTable[i]->background.pixel; - mask |= CWBackPixel; - break; - case BackgroundPixmap: - attributes[attri++] = None; - mask |= CWBackPixmap; - break; - default: - break; - } - break; - case SCREEN_IS_BLACK: - attributes[attri++] = WindowTable[i]->drawable.pScreen->blackPixel; - mask |= CWBackPixel; - break; - } - mask |= CWOverrideRedirect; - attributes[attri++] = xTrue; - - /* - * create a blank cursor - */ - - cm.width=16; - cm.height=16; - cm.xhot=8; - cm.yhot=8; - srcbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - mskbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - if (!srcbits || !mskbits) - { - xfree(srcbits); - xfree(mskbits); - cursor = 0; - } - else - { - for (j=0; jwidth + RANDOM_WIDTH, - (unsigned short)screenInfo.screens[i]->height + RANDOM_WIDTH, - 0, InputOutput, mask, attributes, 0, serverClient, - wVisual (WindowTable[i]), &result); - - if (cursor) - FreeResource (cursorID, RT_NONE); - - if (!pWin) - return FALSE; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, - (pointer)savedScreenInfo[i].pWindow)) - return FALSE; - - if (mask & CWBackPixmap) - { - MakeRootTile (pWin); - (*pWin->drawable.pScreen->ChangeWindowAttributes)(pWin, CWBackPixmap); - } - MapWindow(pWin, serverClient); -#ifndef NOLOGOHACK - if (kind == SCREEN_IS_TILED && logoScreenSaver) - DrawLogo(pWin); -#endif - return TRUE; -} - -/* - * FindWindowWithOptional - * - * search ancestors of the given window for an entry containing - * a WindowOpt structure. Assumptions: some parent will - * contain the structure. - */ - -WindowPtr -FindWindowWithOptional (w) - register WindowPtr w; -{ - do - w = w->parent; - while (!w->optional); - return w; -} - -/* - * CheckWindowOptionalNeed - * - * check each optional entry in the given window to see if - * the value is satisfied by the default rules. If so, - * release the optional record - */ - -void -CheckWindowOptionalNeed (w) - register WindowPtr w; -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (!w->parent) - return; - optional = w->optional; - if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate]) - return; - if (optional->otherEventMasks != 0) - return; - if (optional->otherClients != NULL) - return; - if (optional->passiveGrabs != NULL) - return; - if (optional->userProps != NULL) - return; - if (optional->backingBitPlanes != ~0L) - return; - if (optional->backingPixel != 0) - return; -#ifdef SHAPE - if (optional->boundingShape != NULL) - return; - if (optional->clipShape != NULL) - return; -#endif -#ifdef XINPUT - if (optional->inputMasks != NULL) - return; -#endif - parentOptional = FindWindowWithOptional(w)->optional; - if (optional->visual != parentOptional->visual) - return; - if (optional->cursor != None && - (optional->cursor != parentOptional->cursor || - w->parent->cursorIsNone)) - return; - if (optional->colormap != parentOptional->colormap) - return; - DisposeWindowOptional (w); -} - -/* - * MakeWindowOptional - * - * create an optional record and initialize it with the default - * values. - */ - -Bool -MakeWindowOptional (pWin) - register WindowPtr pWin; -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (pWin->optional) - return TRUE; - optional = (WindowOptPtr) xalloc (sizeof (WindowOptRec)); - if (!optional) - return FALSE; - optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; - optional->otherEventMasks = 0; - optional->otherClients = NULL; - optional->passiveGrabs = NULL; - optional->userProps = NULL; - optional->backingBitPlanes = ~0L; - optional->backingPixel = 0; -#ifdef SHAPE - optional->boundingShape = NULL; - optional->clipShape = NULL; -#endif -#ifdef XINPUT - optional->inputMasks = NULL; -#endif - parentOptional = FindWindowWithOptional(pWin)->optional; - optional->visual = parentOptional->visual; - if (!pWin->cursorIsNone) - { - optional->cursor = parentOptional->cursor; - optional->cursor->refcnt++; - } - else - { - optional->cursor = None; - } - optional->colormap = parentOptional->colormap; - pWin->optional = optional; - return TRUE; -} - -void -DisposeWindowOptional (pWin) - register WindowPtr pWin; -{ - if (!pWin->optional) - return; - /* - * everything is peachy. Delete the optional record - * and clean up - */ - /* - * TOG changed this code to: - * - * if (pWin->cursorIsNone == FALSE) - * FreeCursor (pWin->optional->cursor, (Cursor)0); - * pWin->cursorIsNone = TRUE; - * - * This is blatently wrong; windows without optionals can have - * two different cursor values, either None or sharing their - * parents cursor. This difference is controlled by the - * cursorIsNone value; when TRUE, the window has no cursor, - * when false, it shares its cursor with its parent; TOG - * made it impossible for a window to have a cursor without - * an optional record. - */ - if (pWin->optional->cursor) - { - FreeCursor (pWin->optional->cursor, (Cursor)0); - pWin->cursorIsNone = FALSE; - } - else - pWin->cursorIsNone = TRUE; -/* FIXME - There is an error when disposing ClientResources on Agent exit - this xfree is not valid in some window at exit -*/ - - xfree (pWin->optional); - pWin->optional = NULL; -} - -#ifndef NOLOGOHACK -static void -#if NeedFunctionPrototypes -DrawLogo(WindowPtr pWin) -#else -DrawLogo(pWin) - WindowPtr pWin; -#endif -{ - DrawablePtr pDraw; - ScreenPtr pScreen; - int x, y; - unsigned int width, height, size; - GC *pGC; - int thin, gap, d31; - DDXPointRec poly[4]; - ChangeGCVal fore[2], back[2]; - xrgb rgb[2]; - BITS32 fmask, bmask; - ColormapPtr cmap; - - pDraw = (DrawablePtr)pWin; - pScreen = pDraw->pScreen; - x = -pWin->origin.x; - y = -pWin->origin.y; - width = pScreen->width; - height = pScreen->height; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pGC) - return; - - if ((rand() % 100) <= 17) /* make the probability for white fairly low */ - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - if ((pWin->backgroundState == BackgroundPixel) && - (cmap = (ColormapPtr)LookupIDByType(wColormap (pWin), RT_COLORMAP))) { - Pixel querypixels[2]; - - querypixels[0] = fore[0].val; - querypixels[1] = pWin->background.pixel; - QueryColors(cmap, 2, querypixels, rgb); - if ((rgb[0].red == rgb[1].red) && - (rgb[0].green == rgb[1].green) && - (rgb[0].blue == rgb[1].blue)) { - if (fore[0].val == pScreen->blackPixel) - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - } - } - fore[1].val = FillSolid; - fmask = GCForeground|GCFillStyle; - if (pWin->backgroundState == BackgroundPixel) { - back[0].val = pWin->background.pixel; - back[1].val = FillSolid; - bmask = GCForeground|GCFillStyle; - } else { - back[0].val = 0; - back[1].val = 0; - dixChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin, - NULL, back); - back[0].val = FillTiled; - back[1].ptr = pWin->background.pixmap; - bmask = GCFillStyle|GCTile; - } - - /* should be the same as the reference function XmuDrawLogo() */ - - size = width; - if (height < width) - size = height; - size = RANDOM_WIDTH + rand() % (size - RANDOM_WIDTH); - size &= ~1; - x += rand() % (width - size); - y += rand() % (height - size); - -/* - * Draw what will be the thin strokes. - * - * ----- - * / / - * / / - * / / - * / / - * /____/ - * d - * - * Point d is 9/44 (~1/5) of the way across. - */ - - thin = (size / 11); - if (thin < 1) thin = 1; - gap = (thin+3) / 4; - d31 = thin + thin + gap; - poly[0].x = x + size; poly[0].y = y; - poly[1].x = x + size-d31; poly[1].y = y; - poly[2].x = x + 0; poly[2].y = y + size; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for lower thin stroke. - * - * ------ - * / / - * / __ / - * / / / - * / / / - * /__/__/ - */ - - poly[0].x = x + d31/2; poly[0].y = y + size; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)+(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for upper thin stroke. - * - * ------ - * / / / - * /--/ / - * / / - * / / - * /_____/ - */ - - poly[0].x = x + size - d31/2; poly[0].y = y; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)-(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + size - d31; poly[3].y = y; - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Draw thick stroke. - * Point b is 1/4 of the way across. - * - * b - * ----- - * \ \ - * \ \ - * \ \ - * \ \ - * \____\ - */ - - poly[0].x = x; poly[0].y = y; - poly[1].x = x + size/4; poly[1].y = y; - poly[2].x = x + size; poly[2].y = y + size; - poly[3].x = x + size - size/4; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase to create gap. - * - * / - * / - * / - * / - * / - */ - - poly[0].x = x + size- thin; poly[0].y = y; - poly[1].x = x + size-( thin+gap); poly[1].y = y; - poly[2].x = x + thin; poly[2].y = y + size; - poly[3].x = x + thin + gap; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - - FreeScratchGC(pGC); -} - -#endif - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.XF86.original deleted file mode 100644 index 30c0df032..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c.XF86.original +++ /dev/null @@ -1,3947 +0,0 @@ -/* $Xorg: window.c,v 1.4 2001/02/09 02:04:41 xorgcvs Exp $ */ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -*/ - -/* The panoramix components contained the following notice */ -/**************************************************************** -* * -* Copyright (c) Digital Equipment Corporation, 1991, 1997 * -* * -* All Rights Reserved. Unpublished rights reserved under * -* the copyright laws of the United States. * -* * -* The software contained on this media is proprietary to * -* and embodies the confidential technology of Digital * -* Equipment Corporation. Possession, use, duplication or * -* dissemination of the software and media is authorized only * -* pursuant to a valid written license from Digital Equipment * -* Corporation. * -* * -* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * -* by the U.S. Government is subject to restrictions as set * -* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * -* or in FAR 52.227-19, as applicable. * -* * -*****************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/window.c,v 3.32 2003/01/12 02:44:26 dawes Exp $ */ - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include "dixevents.h" -#include "globals.h" - -#ifdef XAPPGROUP -#include "Xagsrv.h" -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include "security.h" -#endif - -#if defined(NEED_SCREEN_REGIONS) -#define REGION_PTR(pScreen,pWin) \ - register ScreenPtr pScreen = pWin->drawable.pScreen; -#else -#define REGION_PTR(pScreen,pWin) /* nothing */ -#endif - -/****** - * Window stuff for server - * - * CreateRootWindow, CreateWindow, ChangeWindowAttributes, - * GetWindowAttributes, DeleteWindow, DestroySubWindows, - * HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows, - * UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow, - * - ******/ - -static unsigned char _back_lsb[4] = {0x88, 0x22, 0x44, 0x11}; -static unsigned char _back_msb[4] = {0x11, 0x44, 0x22, 0x88}; - -int screenIsSaved = SCREEN_SAVER_OFF; - -ScreenSaverStuffRec savedScreenInfo[MAXSCREENS]; - -#if 0 -extern void DeleteWindowFromAnyEvents(); -extern Mask EventMaskForClient(); -extern void WindowHasNewCursor(); -extern void RecalculateDeliverableEvents(); -#endif - -static Bool TileScreenSaver( -#if NeedFunctionPrototypes - int /*i*/, - int /*kind*/ -#endif -); - - -#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \ - CWDontPropagate | CWOverrideRedirect | CWCursor ) - -#define BOXES_OVERLAP(b1, b2) \ - (!( ((b1)->x2 <= (b2)->x1) || \ - ( ((b1)->x1 >= (b2)->x2)) || \ - ( ((b1)->y2 <= (b2)->y1)) || \ - ( ((b1)->y1 >= (b2)->y2)) ) ) - -#define RedirectSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask) - -#define SubSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask) - -#define StrSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask) - -#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent)) - - -int numSaveUndersViewable = 0; -int deltaSaveUndersViewable = 0; - -#ifdef DEBUG -/****** - * PrintWindowTree - * For debugging only - ******/ - -int -PrintChildren(p1, indent) - WindowPtr p1; - int indent; -{ - WindowPtr p2; - int i; - - while (p1) - { - p2 = p1->firstChild; - for (i=0; idrawable.id); - miPrintRegion(&p1->clipList); - PrintChildren(p2, indent+4); - p1 = p1->nextSib; - } -} - -PrintWindowTree() -{ - int i; - WindowPtr pWin, p1; - - for (i=0; iclipList); - p1 = pWin->firstChild; - PrintChildren(p1, 4); - } -} -#endif - -int -TraverseTree(pWin, func, data) - register WindowPtr pWin; - VisitWindowProcPtr func; - pointer data; -{ - register int result; - register WindowPtr pChild; - - if (!(pChild = pWin)) - return(WT_NOMATCH); - while (1) - { - result = (* func)(pChild, data); - if (result == WT_STOPWALKING) - return(WT_STOPWALKING); - if ((result == WT_WALKCHILDREN) && pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - return(WT_NOMATCH); -} - -/***** - * WalkTree - * Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on - * each window. If FUNC returns WT_WALKCHILDREN, traverse the children, - * if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING - * exit WalkTree. Does depth-first traverse. - *****/ - -int -WalkTree(pScreen, func, data) - ScreenPtr pScreen; - VisitWindowProcPtr func; - pointer data; -{ - return(TraverseTree(WindowTable[pScreen->myNum], func, data)); -} - -/* hack for forcing backing store on all windows */ -int defaultBackingStore = NotUseful; -/* hack to force no backing store */ -Bool disableBackingStore = FALSE; -Bool enableBackingStore = FALSE; -/* hack to force no save unders */ -Bool disableSaveUnders = FALSE; - -static void -#if NeedFunctionPrototypes -SetWindowToDefaults(register WindowPtr pWin) -#else -SetWindowToDefaults(pWin) - register WindowPtr pWin; -#endif -{ - pWin->prevSib = NullWindow; - pWin->firstChild = NullWindow; - pWin->lastChild = NullWindow; - - pWin->valdata = (ValidatePtr)NULL; - pWin->optional = (WindowOptPtr)NULL; - pWin->cursorIsNone = TRUE; - - pWin->backingStore = NotUseful; - pWin->DIXsaveUnder = FALSE; - pWin->backStorage = (pointer) NULL; - - pWin->mapped = FALSE; /* off */ - pWin->realized = FALSE; /* off */ - pWin->viewable = FALSE; - pWin->visibility = VisibilityNotViewable; - pWin->overrideRedirect = FALSE; - pWin->saveUnder = FALSE; - - pWin->bitGravity = ForgetGravity; - pWin->winGravity = NorthWestGravity; - - pWin->eventMask = 0; - pWin->deliverableEvents = 0; - pWin->dontPropagate = 0; - pWin->forcedBS = FALSE; -#ifdef NEED_DBE_BUF_BITS - pWin->srcBuffer = DBE_FRONT_BUFFER; - pWin->dstBuffer = DBE_FRONT_BUFFER; -#endif -} - -static void -#if NeedFunctionPrototypes -MakeRootTile(WindowPtr pWin) -#else -MakeRootTile(pWin) - WindowPtr pWin; -#endif -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - GCPtr pGC; - unsigned char back[128]; - int len = BitmapBytePad(sizeof(long)); - register unsigned char *from, *to; - register int i, j; - - pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4, - pScreen->rootDepth); - - pWin->backgroundState = BackgroundPixmap; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pWin->background.pixmap || !pGC) - FatalError("could not create root tile"); - - { - CARD32 attributes[2]; - - attributes[0] = pScreen->whitePixel; - attributes[1] = pScreen->blackPixel; - - (void)ChangeGC(pGC, GCForeground | GCBackground, attributes); - } - - ValidateGC((DrawablePtr)pWin->background.pixmap, pGC); - - from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb; - to = back; - - for (i = 4; i > 0; i--, from++) - for (j = len; j > 0; j--) - *to++ = *from; - - if (blackRoot) - bzero(back, sizeof(back)); - - (*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, pGC, 1, - 0, 0, len, 4, 0, XYBitmap, (char *)back); - - FreeScratchGC(pGC); - -} - -WindowPtr -AllocateWindow(pScreen) - ScreenPtr pScreen; -{ - WindowPtr pWin; - register char *ptr; - register DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - pWin = (WindowPtr)xalloc(pScreen->totalWindowSize); - if (pWin) - { - ppriv = (DevUnion *)(pWin + 1); - pWin->devPrivates = ppriv; - sizes = pScreen->WindowPrivateSizes; - ptr = (char *)(ppriv + pScreen->WindowPrivateLen); - for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - } - return pWin; -} - -/***** - * CreateRootWindow - * Makes a window at initialization time for specified screen - *****/ - -Bool -CreateRootWindow(pScreen) - ScreenPtr pScreen; -{ - WindowPtr pWin; - BoxRec box; - PixmapFormatRec *format; - - pWin = AllocateWindow(pScreen); - if (!pWin) - return FALSE; - - savedScreenInfo[pScreen->myNum].pWindow = NULL; - savedScreenInfo[pScreen->myNum].wid = FakeClientID(0); - savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL; - screenIsSaved = SCREEN_SAVER_OFF; - - WindowTable[pScreen->myNum] = pWin; - - pWin->drawable.pScreen = pScreen; - pWin->drawable.type = DRAWABLE_WINDOW; - - pWin->drawable.depth = pScreen->rootDepth; - for (format = screenInfo.formats; - format->depth != pScreen->rootDepth; - format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->parent = NullWindow; - SetWindowToDefaults(pWin); - - pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec)); - if (!pWin->optional) - return FALSE; - - pWin->optional->dontPropagateMask = 0; - pWin->optional->otherEventMasks = 0; - pWin->optional->otherClients = NULL; - pWin->optional->passiveGrabs = NULL; - pWin->optional->userProps = NULL; - pWin->optional->backingBitPlanes = ~0L; - pWin->optional->backingPixel = 0; -#ifdef SHAPE - pWin->optional->boundingShape = NULL; - pWin->optional->clipShape = NULL; -#endif -#ifdef XINPUT - pWin->optional->inputMasks = NULL; -#endif - pWin->optional->colormap = pScreen->defColormap; - pWin->optional->visual = pScreen->rootVisual; - - pWin->nextSib = NullWindow; - - pWin->drawable.id = FakeClientID(0); - - pWin->origin.x = pWin->origin.y = 0; - pWin->drawable.height = pScreen->height; - pWin->drawable.width = pScreen->width; - pWin->drawable.x = pWin->drawable.y = 0; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - REGION_INIT(pScreen, &pWin->winSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderClip, &box, 1); - - pWin->drawable.class = InputOutput; - pWin->optional->visual = pScreen->rootVisual; - - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = pScreen->whitePixel; - - pWin->borderIsPixel = TRUE; - pWin->border.pixel = pScreen->blackPixel; - pWin->borderWidth = 0; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin)) - return FALSE; - - if (disableBackingStore) - pScreen->backingStoreSupport = NotUseful; - if (enableBackingStore) - pScreen->backingStoreSupport = Always; - -#ifdef DO_SAVE_UNDERS - if ((pScreen->backingStoreSupport != NotUseful) && - (pScreen->saveUnderSupport == NotUseful)) - { - /* - * If the screen has backing-store but no save-unders, let the - * clients know we can support save-unders using backing-store. - */ - pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS; - } -#endif /* DO_SAVE_UNDERS */ - - if (disableSaveUnders) - pScreen->saveUnderSupport = NotUseful; - - return TRUE; -} - -void -InitRootWindow(pWin) - WindowPtr pWin; -{ - ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - if (!(*pScreen->CreateWindow)(pWin)) - return; /* XXX */ - (*pScreen->PositionWindow)(pWin, 0, 0); - - pWin->cursorIsNone = FALSE; - pWin->optional->cursor = rootCursor; - rootCursor->refcnt++; - MakeRootTile(pWin); - pWin->backingStore = defaultBackingStore; - pWin->forcedBS = (defaultBackingStore != NotUseful); - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore); - - MapWindow(pWin, serverClient); -} - -/* Set the region to the intersection of the rectangle and the - * window's winSize. The window is typically the parent of the - * window from which the region came. - */ - -void -ClippedRegionFromBox(pWin, Rgn, x, y, w, h) - register WindowPtr pWin; - RegionPtr Rgn; - register int x, y; - int w, h; -{ - REGION_PTR(pScreen, pWin) - BoxRec box; - - box = *(REGION_EXTENTS(pScreen, &pWin->winSize)); - /* we do these calculations to avoid overflows */ - if (x > box.x1) - box.x1 = x; - if (y > box.y1) - box.y1 = y; - x += w; - if (x < box.x2) - box.x2 = x; - y += h; - if (y < box.y2) - box.y2 = y; - if (box.x1 > box.x2) - box.x2 = box.x1; - if (box.y1 > box.y2) - box.y2 = box.y1; - REGION_RESET(pScreen, Rgn, &box); - REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize); -} - -WindowPtr -RealChildHead(pWin) - register WindowPtr pWin; -{ - if (!pWin->parent && - (screenIsSaved == SCREEN_SAVER_ON) && - (HasSaverWindow (pWin->drawable.pScreen->myNum))) - return (pWin->firstChild); - else - return (NullWindow); -} - -/***** - * CreateWindow - * Makes a window in response to client request - *****/ - -WindowPtr -CreateWindow(wid, pParent, x, y, w, h, bw, class, vmask, vlist, - depth, client, visual, error) - Window wid; - register WindowPtr pParent; - int x,y; - unsigned int w, h, bw; - unsigned int class; - register Mask vmask; - XID *vlist; - int depth; - ClientPtr client; - VisualID visual; - int *error; -{ - register WindowPtr pWin; - WindowPtr pHead; - register ScreenPtr pScreen; - xEvent event; - int idepth, ivisual; - Bool fOK; - DepthPtr pDepth; - PixmapFormatRec *format; - register WindowOptPtr ancwopt; - - if (class == CopyFromParent) - class = pParent->drawable.class; - - if ((class != InputOutput) && (class != InputOnly)) - { - *error = BadValue; - client->errorValue = class; - return NullWindow; - } - - if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) - { - *error = BadMatch; - return NullWindow; - } - - if ((class == InputOnly) && ((bw != 0) || (depth != 0))) - { - *error = BadMatch; - return NullWindow; - } - - pScreen = pParent->drawable.pScreen; - if ((class == InputOutput) && (depth == 0)) - depth = pParent->drawable.depth; - ancwopt = pParent->optional; - if (!ancwopt) - ancwopt = FindWindowWithOptional(pParent)->optional; - if (visual == CopyFromParent) { -#ifdef XAPPGROUP - VisualID ag_visual; - - if (client->appgroup && !pParent->parent && - (ag_visual = XagRootVisual (client))) - visual = ag_visual; - else -#endif - visual = ancwopt->visual; - } - - /* Find out if the depth and visual are acceptable for this Screen */ - if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) - { - fOK = FALSE; - for(idepth = 0; idepth < pScreen->numDepths; idepth++) - { - pDepth = (DepthPtr) &pScreen->allowedDepths[idepth]; - if ((depth == pDepth->depth) || (depth == 0)) - { - for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) - { - if (visual == pDepth->vids[ivisual]) - { - fOK = TRUE; - break; - } - } - } - } - if (fOK == FALSE) - { - *error = BadMatch; - return NullWindow; - } - } - - if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) && - (class != InputOnly) && - (depth != pParent->drawable.depth)) - { - *error = BadMatch; - return NullWindow; - } - - if (((vmask & CWColormap) == 0) && - (class != InputOnly) && - ((visual != ancwopt->visual) || (ancwopt->colormap == None))) - { - *error = BadMatch; - return NullWindow; - } - - pWin = AllocateWindow(pScreen); - if (!pWin) - { - *error = BadAlloc; - return NullWindow; - } - pWin->drawable = pParent->drawable; - pWin->drawable.depth = depth; - if (depth == pParent->drawable.depth) - pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; - else - { - for (format = screenInfo.formats; format->depth != depth; format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - } - if (class == InputOnly) - pWin->drawable.type = (short) UNDRAWABLE_WINDOW; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->drawable.id = wid; - pWin->drawable.class = class; - - pWin->parent = pParent; - SetWindowToDefaults(pWin); - - if (visual != ancwopt->visual) - { - if (!MakeWindowOptional (pWin)) - { - xfree (pWin); - *error = BadAlloc; - return NullWindow; - } - pWin->optional->visual = visual; - pWin->optional->colormap = None; - } - - pWin->borderWidth = bw; -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows; - * they make it too easy to steal window contents - */ - if (client->trustLevel != XSecurityClientTrusted) - { - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = 0; - } - else -#endif - pWin->backgroundState = None; - - pWin->borderIsPixel = pParent->borderIsPixel; - pWin->border = pParent->border; - if (pWin->borderIsPixel == FALSE) - pWin->border.pixmap->refcnt++; - - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - pWin->drawable.width = w; - pWin->drawable.height = h; - pWin->drawable.x = pParent->drawable.x + x + (int)bw; - pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - /* set up clip list correctly for unobscured WindowPtr */ - REGION_INIT(pScreen, &pWin->clipList, NullBox, 1); - REGION_INIT(pScreen, &pWin->borderClip, NullBox, 1); - REGION_INIT(pScreen, &pWin->winSize, NullBox, 1); - REGION_INIT(pScreen, &pWin->borderSize, NullBox, 1); - - pHead = RealChildHead(pParent); - if (pHead) - { - pWin->nextSib = pHead->nextSib; - if (pHead->nextSib) - pHead->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pHead->nextSib = pWin; - pWin->prevSib = pHead; - } - else - { - pWin->nextSib = pParent->firstChild; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - /* We SHOULD check for an error value here XXX */ - if (!(*pScreen->CreateWindow)(pWin)) - { - *error = BadAlloc; - DeleteWindow(pWin, None); - return NullWindow; - } - /* We SHOULD check for an error value here XXX */ - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - - if (!(vmask & CWEventMask)) - RecalculateDeliverableEvents(pWin); - - if (vmask) - *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin)); - else - *error = Success; - - if (*error != Success) - { - DeleteWindow(pWin, None); - return NullWindow; - } - if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful)) - { - XID value = defaultBackingStore; - (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin)); - pWin->forcedBS = TRUE; - } - - if (SubSend(pParent)) - { - event.u.u.type = CreateNotify; - event.u.createNotify.window = wid; - event.u.createNotify.parent = pParent->drawable.id; - event.u.createNotify.x = x; - event.u.createNotify.y = y; - event.u.createNotify.width = w; - event.u.createNotify.height = h; - event.u.createNotify.borderWidth = bw; - event.u.createNotify.override = pWin->overrideRedirect; - DeliverEvents(pParent, &event, 1, NullWindow); - } - return pWin; -} - -static void -#if NeedFunctionPrototypes -FreeWindowResources(register WindowPtr pWin) -#else -FreeWindowResources(pWin) - register WindowPtr pWin; -#endif -{ - register ScreenPtr pScreen = pWin->drawable.pScreen; - - DeleteWindowFromAnySaveSet(pWin); - DeleteWindowFromAnySelections(pWin); - DeleteWindowFromAnyEvents(pWin, TRUE); - REGION_UNINIT(pScreen, &pWin->clipList); - REGION_UNINIT(pScreen, &pWin->winSize); - REGION_UNINIT(pScreen, &pWin->borderClip); - REGION_UNINIT(pScreen, &pWin->borderSize); -#ifdef SHAPE - if (wBoundingShape (pWin)) - REGION_DESTROY(pScreen, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_DESTROY(pScreen, wClipShape (pWin)); -#endif - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - - DeleteAllWindowProperties(pWin); - /* We SHOULD check for an error value here XXX */ - (*pScreen->DestroyWindow)(pWin); - DisposeWindowOptional (pWin); -} - -static void -#if NeedFunctionPrototypes -CrushTree(WindowPtr pWin) -#else -CrushTree(pWin) - WindowPtr pWin; -#endif -{ - register WindowPtr pChild, pSib, pParent; - UnrealizeWindowProcPtr UnrealizeWindow; - xEvent event; - - if (!(pChild = pWin->firstChild)) - return; - UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow; - while (1) - { - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (1) - { - pParent = pChild->parent; - if (SubStrSend(pChild, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pChild->drawable.id; - DeliverEvents(pChild, &event, 1, NullWindow); - } - FreeResource(pChild->drawable.id, RT_WINDOW); - pSib = pChild->nextSib; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder && pChild->viewable) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->realized) - { - pChild->realized = FALSE; - (*UnrealizeWindow)(pChild); - } - FreeWindowResources(pChild); - xfree(pChild); - if ( (pChild = pSib) ) - break; - pChild = pParent; - pChild->firstChild = NullWindow; - pChild->lastChild = NullWindow; - if (pChild == pWin) - return; - } - } -} - -/***** - * DeleteWindow - * Deletes child of window then window itself - * If wid is None, don't send any events - *****/ - -/*ARGSUSED*/ -int -DeleteWindow(value, wid) - pointer value; - XID wid; - { - register WindowPtr pParent; - register WindowPtr pWin = (WindowPtr)value; - xEvent event; - - UnmapWindow(pWin, FALSE); - - CrushTree(pWin); - - pParent = pWin->parent; - if (wid && pParent && SubStrSend(pWin, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pWin->drawable.id; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - FreeWindowResources(pWin); - if (pParent) - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - } - xfree(pWin); - return Success; -} - -/*ARGSUSED*/ -void -DestroySubwindows(pWin, client) - register WindowPtr pWin; - ClientPtr client; -{ - /* XXX - * The protocol is quite clear that each window should be - * destroyed in turn, however, unmapping all of the first - * eliminates most of the calls to ValidateTree. So, - * this implementation is incorrect in that all of the - * UnmapNotifies occur before all of the DestroyNotifies. - * If you care, simply delete the call to UnmapSubwindows. - */ - UnmapSubwindows(pWin); - while (pWin->lastChild) - FreeResource(pWin->lastChild->drawable.id, RT_NONE); -} - -#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \ - ButtonReleaseMask | PointerMotionMask) - -/***** - * ChangeWindowAttributes - * - * The value-mask specifies which attributes are to be changed; the - * value-list contains one value for each one bit in the mask, from least - * to most significant bit in the mask. - *****/ - -int -ChangeWindowAttributes(pWin, vmask, vlist, client) - register WindowPtr pWin; - Mask vmask; - XID *vlist; - ClientPtr client; -{ - register Mask index2; - register XID *pVlist; - PixmapPtr pPixmap; - Pixmap pixID; - CursorPtr pCursor, pOldCursor; - Cursor cursorID; - WindowPtr pChild; - Colormap cmap; - ColormapPtr pCmap; - xEvent xE; - int result; - register ScreenPtr pScreen; - Mask vmaskCopy = 0; - register Mask tmask; - unsigned int val; - int error; - Bool checkOptional = FALSE; - Bool borderRelative = FALSE; - WindowPtr pLayerWin; - - if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK))) - return BadMatch; - - error = Success; - pScreen = pWin->drawable.pScreen; - pVlist = vlist; - tmask = vmask; - while (tmask) - { - index2 = (Mask) lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBackPixmap: - pixID = (Pixmap )*pVlist; - pVlist++; - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pixID == None) - { -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows */ - if (client->trustLevel == XSecurityClientTrusted) - { -#endif - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = None; -#ifdef XCSECURITY - } - else - { /* didn't change the background to None, so don't tell ddx */ - index2 = 0; - } -#endif - } - else if (pixID == ParentRelative) - { - if (pWin->parent && - pWin->drawable.depth != pWin->parent->drawable.depth) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = ParentRelative; - borderRelative = TRUE; - /* Note that the parent's backgroundTile's refcnt is NOT - * incremented. */ - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap != (PixmapPtr) NULL) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixmap; - pWin->background.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBackPixel: - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = (CARD32 ) *pVlist; - /* background pixel overrides background pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBackPixmap; - pVlist++; - break; - case CWBorderPixmap: - pixID = (Pixmap ) *pVlist; - pVlist++; - if (pixID == CopyFromParent) - { - if (!pWin->parent || - (pWin->drawable.depth != pWin->parent->drawable.depth)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->border = pWin->parent->border; - if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE) - { - index2 = CWBorderPixel; - } - else - { - pWin->parent->border.pixmap->refcnt++; - } - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = FALSE; - pWin->border.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBorderPixel: - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = TRUE; - pWin->border.pixel = (CARD32) *pVlist; - /* border pixel overrides border pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBorderPixmap; - pVlist++; - break; - case CWBitGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->bitGravity = val; - break; - case CWWinGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->winGravity = val; - break; - case CWBackingStore: - val = (CARD8 )*pVlist; - pVlist++; - if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->backingStore = val; - pWin->forcedBS = FALSE; - break; - case CWBackingPlanes: - if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingBitPlanes = (CARD32) *pVlist; - if ((CARD32)*pVlist == (CARD32)~0L) - checkOptional = TRUE; - } - pVlist++; - break; - case CWBackingPixel: - if (pWin->optional || (CARD32) *pVlist) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingPixel = (CARD32) *pVlist; - if (!*pVlist) - checkOptional = TRUE; - } - pVlist++; - break; - case CWSaveUnder: - val = (BOOL) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } -#ifdef DO_SAVE_UNDERS - if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) && - DO_SAVE_UNDERS(pWin)) - { - /* - * Re-check all siblings and inferiors for obscurity or - * exposition (hee hee). - */ - if (pWin->saveUnder) - deltaSaveUndersViewable--; - else - deltaSaveUndersViewable++; - pWin->saveUnder = val; - - if (pWin->firstChild) - { - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pLayerWin->parent, - pWin->nextSib); - } - else - { - if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pWin, - pWin->nextSib); - } - } - else - { - /* If we're changing the saveUnder attribute of the root - * window, all we do is set pWin->saveUnder so that - * GetWindowAttributes returns the right value. We don't - * do the "normal" save-under processing (as above). - * Hope that doesn't cause any problems. - */ - pWin->saveUnder = val; - } -#else - pWin->saveUnder = val; -#endif /* DO_SAVE_UNDERS */ - break; - case CWEventMask: - result = EventSelectForWindow(pWin, client, (Mask )*pVlist); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWDontPropagate: - result = EventSuppressForWindow(pWin, client, (Mask )*pVlist, - &checkOptional); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWOverrideRedirect: - val = (BOOL ) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->overrideRedirect = val; - break; - case CWColormap: - cmap = (Colormap) *pVlist; - pVlist++; - if (cmap == CopyFromParent) - { -#ifdef XAPPGROUP - Colormap ag_colormap; - ClientPtr win_owner; - - /* - * win_owner == client for CreateWindow, other clients - * can ChangeWindowAttributes - */ - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - - if ( win_owner && win_owner->appgroup && - !pWin->parent->parent && - (ag_colormap = XagDefaultColormap (win_owner))) - cmap = ag_colormap; - else -#endif - if (pWin->parent && - (!pWin->optional || - pWin->optional->visual == wVisual (pWin->parent))) - { - cmap = wColormap (pWin->parent); - } - else - cmap = None; - } - if (cmap == None) - { - error = BadMatch; - goto PatchUp; - } - pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap, - RT_COLORMAP, SecurityReadAccess); - if (!pCmap) - { - error = BadColor; - client->errorValue = cmap; - goto PatchUp; - } - if (pCmap->pVisual->vid != wVisual (pWin) || - pCmap->pScreen != pScreen) - { - error = BadMatch; - goto PatchUp; - } - if (cmap != wColormap (pWin)) - { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && cmap == wColormap (pWin->parent)) - checkOptional = TRUE; - - /* - * propagate the original colormap to any children - * inheriting it - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pWin->optional->colormap = cmap; - - /* - * check on any children now matching the new colormap - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional->colormap == cmap) - CheckWindowOptionalNeed (pChild); - } - - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pWin->drawable.id; - xE.u.colormap.colormap = cmap; - xE.u.colormap.new = xTrue; - xE.u.colormap.state = IsMapInstalled(cmap, pWin); - DeliverEvents(pWin, &xE, 1, NullWindow); - } - break; - case CWCursor: - cursorID = (Cursor ) *pVlist; - pVlist++; - /* - * install the new - */ - if ( cursorID == None) - { - if (pWin == WindowTable[pWin->drawable.pScreen->myNum]) - pCursor = rootCursor; - else - pCursor = (CursorPtr) None; - } - else - { - pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID, - RT_CURSOR, SecurityReadAccess); - if (!pCursor) - { - error = BadCursor; - client->errorValue = cursorID; - goto PatchUp; - } - } - - if (pCursor != wCursor (pWin)) - { - /* - * patch up child windows so they don't lose cursors. - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !pChild->cursorIsNone && - !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pOldCursor = 0; - if (pCursor == (CursorPtr) None) - { - pWin->cursorIsNone = TRUE; - if (pWin->optional) - { - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = (CursorPtr) None; - checkOptional = TRUE; - } - } else { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && pCursor == wCursor (pWin->parent)) - checkOptional = TRUE; - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = pCursor; - pCursor->refcnt++; - pWin->cursorIsNone = FALSE; - /* - * check on any children now matching the new cursor - */ - - for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional && - (pChild->optional->cursor == pCursor)) - CheckWindowOptionalNeed (pChild); - } - } - - if (pWin->realized) - WindowHasNewCursor( pWin); - - /* Can't free cursor until here - old cursor - * is needed in WindowHasNewCursor - */ - if (pOldCursor) - FreeCursor (pOldCursor, (Cursor)0); - } - break; - default: - error = BadValue; - client->errorValue = vmask; - goto PatchUp; - } - vmaskCopy |= index2; - } -PatchUp: - if (checkOptional) - CheckWindowOptionalNeed (pWin); - - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy); - - /* - If the border contents have changed, redraw the border. - Note that this has to be done AFTER pScreen->ChangeWindowAttributes - for the tile to be rotated, and the correct function selected. - */ - if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative) - && pWin->viewable && HasBorder (pWin)) - { - RegionRec exposed; - - REGION_INIT(pScreen, &exposed, NullBox, 0); - REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize); - (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER); - REGION_UNINIT(pScreen, &exposed); - } - return error; -} - - -/***** - * GetWindowAttributes - * Notice that this is different than ChangeWindowAttributes - *****/ - -void -GetWindowAttributes(pWin, client, wa) - register WindowPtr pWin; - ClientPtr client; - xGetWindowAttributesReply *wa; -{ - wa->type = X_Reply; - wa->bitGravity = pWin->bitGravity; - wa->winGravity = pWin->winGravity; - if (pWin->forcedBS && pWin->backingStore != Always) - wa->backingStore = NotUseful; - else - wa->backingStore = pWin->backingStore; - wa->length = (sizeof(xGetWindowAttributesReply) - - sizeof(xGenericReply)) >> 2; - wa->sequenceNumber = client->sequence; - wa->backingBitPlanes = wBackingBitPlanes (pWin); - wa->backingPixel = wBackingPixel (pWin); - wa->saveUnder = (BOOL)pWin->saveUnder; - wa->override = pWin->overrideRedirect; - if (!pWin->mapped) - wa->mapState = IsUnmapped; - else if (pWin->realized) - wa->mapState = IsViewable; - else - wa->mapState = IsUnviewable; - - wa->colormap = wColormap (pWin); - wa->mapInstalled = (wa->colormap == None) ? xFalse - : IsMapInstalled(wa->colormap, pWin); - - wa->yourEventMask = EventMaskForClient(pWin, client); - wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin); - wa->doNotPropagateMask = wDontPropagateMask (pWin); - wa->class = pWin->drawable.class; - wa->visualID = wVisual (pWin); -} - - -WindowPtr -MoveWindowInStack(pWin, pNextSib) - register WindowPtr pWin, pNextSib; -{ - register WindowPtr pParent = pWin->parent; - WindowPtr pFirstChange = pWin; /* highest window where list changes */ - - if (pWin->nextSib != pNextSib) - { - WindowPtr pOldNextSib = pWin->nextSib; - - if (!pNextSib) /* move to bottom */ - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL - * and pWin->nextSib != pNextSib - * therefore pWin->nextSib != NULL */ - pFirstChange = pWin->nextSib; - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pParent->lastChild->nextSib = pWin; - pWin->prevSib = pParent->lastChild; - pWin->nextSib = NullWindow; - pParent->lastChild = pWin; - } - else if (pParent->firstChild == pNextSib) /* move to top */ - { - pFirstChange = pWin; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pParent->firstChild; - pWin->prevSib = (WindowPtr ) NULL; - pNextSib->prevSib = pWin; - pParent->firstChild = pWin; - } - else /* move in middle of list */ - { - WindowPtr pOldNext = pWin->nextSib; - - pFirstChange = NullWindow; - if (pParent->firstChild == pWin) - pFirstChange = pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) { - pFirstChange = pWin; - pParent->lastChild = pWin->prevSib; - } - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pNextSib; - pWin->prevSib = pNextSib->prevSib; - if (pNextSib->prevSib) - pNextSib->prevSib->nextSib = pWin; - pNextSib->prevSib = pWin; - if (!pFirstChange) { /* do we know it yet? */ - pFirstChange = pParent->firstChild; /* no, search from top */ - while ((pFirstChange != pWin) && (pFirstChange != pOldNext)) - pFirstChange = pFirstChange->nextSib; - } - } - if(pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib); - } - - return( pFirstChange ); -} - -RegionPtr -CreateUnclippedWinSize (pWin) - register WindowPtr pWin; -{ - RegionPtr pRgn; - BoxRec box; - - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + (int) pWin->drawable.width; - box.y2 = pWin->drawable.y + (int) pWin->drawable.height; - pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { - REGION_PTR(pScreen, pWin) - - REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y); - } -#endif - return pRgn; -} - -void -SetWinSize (pWin) - register WindowPtr pWin; -{ - ClippedRegionFromBox(pWin->parent, &pWin->winSize, - pWin->drawable.x, pWin->drawable.y, - (int)pWin->drawable.width, - (int)pWin->drawable.height); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { - REGION_PTR(pScreen, pWin) - - REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wClipShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x, - pWin->drawable.y); - } -#endif -} - -void -SetBorderSize (pWin) - register WindowPtr pWin; -{ - int bw; - - if (HasBorder (pWin)) { - bw = wBorderWidth (pWin); - ClippedRegionFromBox(pWin->parent, &pWin->borderSize, - pWin->drawable.x - bw, pWin->drawable.y - bw, - (int)(pWin->drawable.width + (bw<<1)), - (int)(pWin->drawable.height + (bw<<1))); -#ifdef SHAPE - if (wBoundingShape (pWin)) { - REGION_PTR(pScreen, pWin) - - REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x, - - pWin->drawable.y); - REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize, - wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x, - pWin->drawable.y); - REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize, - &pWin->winSize); - } -#endif - } else { - REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize, - &pWin->winSize); - } -} - -void -GravityTranslate (x, y, oldx, oldy, dw, dh, gravity, destx, desty) - register int x, y; /* new window position */ - int oldx, oldy; /* old window position */ - int dw, dh; - unsigned gravity; - register int *destx, *desty; /* position relative to gravity */ -{ - switch (gravity) { - case NorthGravity: - *destx = x + dw / 2; - *desty = y; - break; - case NorthEastGravity: - *destx = x + dw; - *desty = y; - break; - case WestGravity: - *destx = x; - *desty = y + dh / 2; - break; - case CenterGravity: - *destx = x + dw / 2; - *desty = y + dh / 2; - break; - case EastGravity: - *destx = x + dw; - *desty = y + dh / 2; - break; - case SouthWestGravity: - *destx = x; - *desty = y + dh; - break; - case SouthGravity: - *destx = x + dw / 2; - *desty = y + dh; - break; - case SouthEastGravity: - *destx = x + dw; - *desty = y + dh; - break; - case StaticGravity: - *destx = oldx; - *desty = oldy; - break; - default: - *destx = x; - *desty = y; - break; - } -} - -/* XXX need to retile border on each window with ParentRelative origin */ -void -ResizeChildrenWinSize(pWin, dx, dy, dw, dh) - register WindowPtr pWin; - int dx, dy, dw, dh; -{ - register ScreenPtr pScreen; - register WindowPtr pSib, pChild; - Bool resized = (dw || dh); - - pScreen = pWin->drawable.pScreen; - - for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) - { - if (resized && (pSib->winGravity > NorthWestGravity)) - { - int cwsx, cwsy; - - cwsx = pSib->origin.x; - cwsy = pSib->origin.y; - GravityTranslate (cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh, - pSib->winGravity, &cwsx, &cwsy); - if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) - { - xEvent event; - - event.u.u.type = GravityNotify; - event.u.gravity.window = pSib->drawable.id; - event.u.gravity.x = cwsx - wBorderWidth (pSib); - event.u.gravity.y = cwsy - wBorderWidth (pSib); - DeliverEvents (pSib, &event, 1, NullWindow); - pSib->origin.x = cwsx; - pSib->origin.y = cwsy; - } - } - pSib->drawable.x = pWin->drawable.x + pSib->origin.x; - pSib->drawable.y = pWin->drawable.y + pSib->origin.y; - SetWinSize (pSib); - SetBorderSize (pSib); - (*pScreen->PositionWindow)(pSib, pSib->drawable.x, pSib->drawable.y); - - if ( (pChild = pSib->firstChild) ) - { - while (1) - { - pChild->drawable.x = pChild->parent->drawable.x + - pChild->origin.x; - pChild->drawable.y = pChild->parent->drawable.y + - pChild->origin.y; - SetWinSize (pChild); - SetBorderSize (pChild); - (*pScreen->PositionWindow)(pChild, - pChild->drawable.x, pChild->drawable.y); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pSib)) - pChild = pChild->parent; - if (pChild == pSib) - break; - pChild = pChild->nextSib; - } - } - } -} - -#define GET_INT16(m, f) \ - if (m & mask) \ - { \ - f = (INT16) *pVlist;\ - pVlist++; \ - } -#define GET_CARD16(m, f) \ - if (m & mask) \ - { \ - f = (CARD16) *pVlist;\ - pVlist++;\ - } - -#define GET_CARD8(m, f) \ - if (m & mask) \ - { \ - f = (CARD8) *pVlist;\ - pVlist++;\ - } - -#define ChangeMask ((Mask)(CWX | CWY | CWWidth | CWHeight)) - -#define IllegalInputOnlyConfigureMask (CWBorderWidth) - -/* - * IsSiblingAboveMe - * returns Above if pSib above pMe in stack or Below otherwise - */ - -static int -#if NeedFunctionPrototypes -IsSiblingAboveMe( - register WindowPtr pMe, - register WindowPtr pSib) -#else -IsSiblingAboveMe(pMe, pSib) - register WindowPtr pMe, pSib; -#endif -{ - register WindowPtr pWin; - - pWin = pMe->parent->firstChild; - while (pWin) - { - if (pWin == pSib) - return(Above); - else if (pWin == pMe) - return(Below); - pWin = pWin->nextSib; - } - return(Below); -} - -static BoxPtr -#if NeedFunctionPrototypes -WindowExtents( - register WindowPtr pWin, - register BoxPtr pBox) -#else -WindowExtents(pWin, pBox) - register WindowPtr pWin; - register BoxPtr pBox; -#endif -{ - pBox->x1 = pWin->drawable.x - wBorderWidth (pWin); - pBox->y1 = pWin->drawable.y - wBorderWidth (pWin); - pBox->x2 = pWin->drawable.x + (int)pWin->drawable.width - + wBorderWidth (pWin); - pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height - + wBorderWidth (pWin); - return(pBox); -} - -#ifdef SHAPE -#define IS_SHAPED(pWin) (wBoundingShape (pWin) != (RegionPtr) NULL) - -static RegionPtr -#if NeedFunctionPrototypes -MakeBoundingRegion ( - register WindowPtr pWin, - BoxPtr pBox) -#else -MakeBoundingRegion (pWin, pBox) - register WindowPtr pWin; - BoxPtr pBox; -#endif -{ - RegionPtr pRgn; - REGION_PTR(pScreen, pWin) - - pRgn = REGION_CREATE(pScreen, pBox, 1); - if (wBoundingShape (pWin)) { - REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x, - -pWin->origin.y); - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x, - pWin->origin.y); - } - return pRgn; -} - -static Bool -#if NeedFunctionPrototypes -ShapeOverlap ( - WindowPtr pWin, - BoxPtr pWinBox, - WindowPtr pSib, - BoxPtr pSibBox) -#else -ShapeOverlap (pWin, pWinBox, pSib, pSibBox) - WindowPtr pWin, pSib; - BoxPtr pWinBox, pSibBox; -#endif -{ - RegionPtr pWinRgn, pSibRgn; - register ScreenPtr pScreen; - Bool ret; - - if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib)) - return TRUE; - pScreen = pWin->drawable.pScreen; - pWinRgn = MakeBoundingRegion (pWin, pWinBox); - pSibRgn = MakeBoundingRegion (pSib, pSibBox); - REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn); - ret = REGION_NOTEMPTY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pSibRgn); - return ret; -} -#endif - -static Bool -#if NeedFunctionPrototypes -AnyWindowOverlapsMe( - WindowPtr pWin, - WindowPtr pHead, - register BoxPtr box) -#else -AnyWindowOverlapsMe(pWin, pHead, box) - WindowPtr pWin, pHead; - register BoxPtr box; -#endif -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -static Bool -#if NeedFunctionPrototypes -IOverlapAnyWindow( - WindowPtr pWin, - register BoxPtr box) -#else -IOverlapAnyWindow(pWin, box) - WindowPtr pWin; - register BoxPtr box; -#endif -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -/* - * WhereDoIGoInTheStack() - * Given pWin and pSib and the relationshipe smode, return - * the window that pWin should go ABOVE. - * If a pSib is specified: - * Above: pWin is placed just above pSib - * Below: pWin is placed just below pSib - * TopIf: if pSib occludes pWin, then pWin is placed - * at the top of the stack - * BottomIf: if pWin occludes pSib, then pWin is - * placed at the bottom of the stack - * Opposite: if pSib occludes pWin, then pWin is placed at the - * top of the stack, else if pWin occludes pSib, then - * pWin is placed at the bottom of the stack - * - * If pSib is NULL: - * Above: pWin is placed at the top of the stack - * Below: pWin is placed at the bottom of the stack - * TopIf: if any sibling occludes pWin, then pWin is placed at - * the top of the stack - * BottomIf: if pWin occludes any sibline, then pWin is placed at - * the bottom of the stack - * Opposite: if any sibling occludes pWin, then pWin is placed at - * the top of the stack, else if pWin occludes any - * sibling, then pWin is placed at the bottom of the stack - * - */ - -static WindowPtr -#if NeedFunctionPrototypes -WhereDoIGoInTheStack( - register WindowPtr pWin, - register WindowPtr pSib, - short x, - short y, - unsigned short w, - unsigned short h, - int smode) -#else -WhereDoIGoInTheStack(pWin, pSib, x, y, w, h, smode) - register WindowPtr pWin, pSib; - short x, y; - unsigned short w, h; - int smode; -#endif -{ - BoxRec box; - register ScreenPtr pScreen; - WindowPtr pHead, pFirst; - - if ((pWin == pWin->parent->firstChild) && - (pWin == pWin->parent->lastChild)) - return((WindowPtr ) NULL); - pHead = RealChildHead(pWin->parent); - pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild; - pScreen = pWin->drawable.pScreen; - box.x1 = x; - box.y1 = y; - box.x2 = x + (int)w; - box.y2 = y + (int)h; - switch (smode) - { - case Above: - if (pSib) - return(pSib); - else if (pWin == pFirst) - return(pWin->nextSib); - else - return(pFirst); - case Below: - if (pSib) - if (pSib->nextSib != pWin) - return(pSib->nextSib); - else - return(pWin->nextSib); - else - return NullWindow; - case TopIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Above) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return(pFirst); - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - return(pFirst); - else - return(pWin->nextSib); - case BottomIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Below) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return NullWindow; - else - return(pWin->nextSib); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return(pWin->nextSib); - case Opposite: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT) - { - if (IsSiblingAboveMe(pWin, pSib) == Above) - return(pFirst); - else - return NullWindow; - } - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - { - /* If I'm occluded, I can't possibly be the first child - * if (pWin == pWin->parent->firstChild) - * return pWin->nextSib; - */ - return(pFirst); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return pWin->nextSib; - default: - { - ErrorF("Internal error in ConfigureWindow, smode == %d\n",smode ); - return pWin->nextSib; - } - } -} - -static void -#if NeedFunctionPrototypes -ReflectStackChange( - register WindowPtr pWin, - register WindowPtr pSib, - VTKind kind) -#else -ReflectStackChange(pWin, pSib, kind) - register WindowPtr pWin, pSib; - VTKind kind; -#endif -{ -/* Note that pSib might be NULL */ - - Bool WasViewable = (Bool)pWin->viewable; - WindowPtr pParent; - Bool anyMarked; - WindowPtr pFirstChange; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - ScreenPtr pScreen = pWin->drawable.pScreen; - - /* if this is a root window, can't be restacked */ - if (!(pParent = pWin->parent)) - return ; - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - &pLayerWin); - if (pLayerWin != pWin) pFirstChange = pLayerWin; -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, kind); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pWin->drawable.pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - -/***** - * ConfigureWindow - *****/ - -int -ConfigureWindow(pWin, mask, vlist, client) - register WindowPtr pWin; - register Mask mask; - XID *vlist; - ClientPtr client; -{ -#define RESTACK_WIN 0 -#define MOVE_WIN 1 -#define RESIZE_WIN 2 -#define REBORDER_WIN 3 - register WindowPtr pSib = NullWindow; - register WindowPtr pParent = pWin->parent; - Window sibwid = 0; - Mask index2, tmask; - register XID *pVlist; - short x, y, beforeX, beforeY; - unsigned short w = pWin->drawable.width, - h = pWin->drawable.height, - bw = pWin->borderWidth; - int action, smode = Above; -#ifdef XAPPGROUP - ClientPtr win_owner; - ClientPtr ag_leader = NULL; -#endif - xEvent event; - - if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask)) - return(BadMatch); - - if ((mask & CWSibling) && !(mask & CWStackMode)) - return(BadMatch); - - pVlist = vlist; - - if (pParent) - { - x = pWin->drawable.x - pParent->drawable.x - (int)bw; - y = pWin->drawable.y - pParent->drawable.y - (int)bw; - } - else - { - x = pWin->drawable.x; - y = pWin->drawable.y; - } - beforeX = x; - beforeY = y; - action = RESTACK_WIN; - if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - action = MOVE_WIN; - } - /* or should be resized */ - else if (mask & (CWX | CWY | CWWidth | CWHeight)) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - GET_CARD16(CWWidth, w); - GET_CARD16 (CWHeight, h); - if (!w || !h) - { - client->errorValue = 0; - return BadValue; - } - action = RESIZE_WIN; - } - tmask = mask & ~ChangeMask; - while (tmask) - { - index2 = (Mask)lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBorderWidth: - GET_CARD16(CWBorderWidth, bw); - break; - case CWSibling: - sibwid = (Window ) *pVlist; - pVlist++; - pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid, - RT_WINDOW, SecurityReadAccess); - if (!pSib) - { - client->errorValue = sibwid; - return(BadWindow); - } - if (pSib->parent != pParent) - return(BadMatch); - if (pSib == pWin) - return(BadMatch); - break; - case CWStackMode: - GET_CARD8(CWStackMode, smode); - if ((smode != TopIf) && (smode != BottomIf) && - (smode != Opposite) && (smode != Above) && (smode != Below)) - { - client->errorValue = smode; - return(BadValue); - } - break; - default: - client->errorValue = mask; - return(BadValue); - } - } - /* root really can't be reconfigured, so just return */ - if (!pParent) - return Success; - - /* Figure out if the window should be moved. Doesnt - make the changes to the window if event sent */ - - if (mask & CWStackMode) - pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x, - pParent->drawable.y + y, - w + (bw << 1), h + (bw << 1), smode); - else - pSib = pWin->nextSib; - -#ifdef XAPPGROUP - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = ConfigureRequest; - event.u.configureRequest.window = pWin->drawable.id; - if (mask & CWSibling) - event.u.configureRequest.sibling = sibwid; - else - event.u.configureRequest.sibling = None; - if (mask & CWStackMode) - event.u.u.detail = smode; - else - event.u.u.detail = Above; - event.u.configureRequest.x = x; - event.u.configureRequest.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureRequest.x += panoramiXdataPtr[0].x; - event.u.configureRequest.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureRequest.width = w; - event.u.configureRequest.height = h; - event.u.configureRequest.borderWidth = bw; - event.u.configureRequest.valueMask = mask; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.configureRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.configureRequest.parent = pParent->drawable.id; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - if (action == RESIZE_WIN) - { - Bool size_change = (w != pWin->drawable.width) - || (h != pWin->drawable.height); - if (size_change && ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask)) - { - xEvent eventT; - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = w; - eventT.u.resizeRequest.height = h; - if (MaybeDeliverEventsToClient(pWin, &eventT, 1, - ResizeRedirectMask, client) == 1) - { - /* if event is delivered, leave the actual size alone. */ - w = pWin->drawable.width; - h = pWin->drawable.height; - size_change = FALSE; - } - } - if (!size_change) - { - if (mask & (CWX | CWY)) - action = MOVE_WIN; - else if (mask & (CWStackMode | CWBorderWidth)) - action = RESTACK_WIN; - else /* really nothing to do */ - return(Success) ; - } - } - - if (action == RESIZE_WIN) - /* we've already checked whether there's really a size change */ - goto ActuallyDoSomething; - if ((mask & CWX) && (x != beforeX)) - goto ActuallyDoSomething; - if ((mask & CWY) && (y != beforeY)) - goto ActuallyDoSomething; - if ((mask & CWBorderWidth) && (bw != wBorderWidth (pWin))) - goto ActuallyDoSomething; - if (mask & CWStackMode) - { - if (pWin->nextSib != pSib) - goto ActuallyDoSomething; - } - return(Success); - -ActuallyDoSomething: - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - if (pSib) - event.u.configureNotify.aboveSibling = pSib->drawable.id; - else - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = x; - event.u.configureNotify.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureNotify.x += panoramiXdataPtr[0].x; - event.u.configureNotify.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureNotify.width = w; - event.u.configureNotify.height = h; - event.u.configureNotify.borderWidth = bw; - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (mask & CWBorderWidth) - { - if (action == RESTACK_WIN) - { - action = MOVE_WIN; - pWin->borderWidth = bw; - } - else if ((action == MOVE_WIN) && - (beforeX + wBorderWidth (pWin) == x + (int)bw) && - (beforeY + wBorderWidth (pWin) == y + (int)bw)) - { - action = REBORDER_WIN; - (*pWin->drawable.pScreen->ChangeBorderWidth)(pWin, bw); - } - else - pWin->borderWidth = bw; - } - if (action == MOVE_WIN) - (*pWin->drawable.pScreen->MoveWindow)(pWin, x, y, pSib, - (mask & CWBorderWidth) ? VTOther : VTMove); - else if (action == RESIZE_WIN) - (*pWin->drawable.pScreen->ResizeWindow)(pWin, x, y, w, h, pSib); - else if (mask & CWStackMode) - ReflectStackChange(pWin, pSib, VTOther); - - if (action != RESTACK_WIN) - CheckCursorConfinement(pWin); - return(Success); -#undef RESTACK_WIN -#undef MOVE_WIN -#undef RESIZE_WIN -#undef REBORDER_WIN -} - - -/****** - * - * CirculateWindow - * For RaiseLowest, raises the lowest mapped child (if any) that is - * obscured by another child to the top of the stack. For LowerHighest, - * lowers the highest mapped child (if any) that is obscuring another - * child to the bottom of the stack. Exposure processing is performed - * - ******/ - -int -CirculateWindow(pParent, direction, client) - WindowPtr pParent; - int direction; - ClientPtr client; -{ - register WindowPtr pWin, pHead, pFirst; - xEvent event; - BoxRec box; - - pHead = RealChildHead(pParent); - pFirst = pHead ? pHead->nextSib : pParent->firstChild; - if (direction == RaiseLowest) - { - for (pWin = pParent->lastChild; - (pWin != pHead) && - !(pWin->mapped && - AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box))); - pWin = pWin->prevSib) ; - if (pWin == pHead) - return Success; - } - else - { - for (pWin = pFirst; - pWin && - !(pWin->mapped && - IOverlapAnyWindow(pWin, WindowExtents(pWin, &box))); - pWin = pWin->nextSib) ; - if (!pWin) - return Success; - } - - event.u.circulate.window = pWin->drawable.id; - event.u.circulate.parent = pParent->drawable.id; - event.u.circulate.event = pParent->drawable.id; - if (direction == RaiseLowest) - event.u.circulate.place = PlaceOnTop; - else - event.u.circulate.place = PlaceOnBottom; - - if (RedirectSend(pParent)) - { - event.u.u.type = CirculateRequest; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - event.u.u.type = CirculateNotify; - DeliverEvents(pWin, &event, 1, NullWindow); - ReflectStackChange(pWin, - (direction == RaiseLowest) ? pFirst : NullWindow, - VTStack); - - return(Success); -} - -static int -#if NeedFunctionPrototypes -CompareWIDs( - WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -#else -CompareWIDs(pWin, value) - WindowPtr pWin; - pointer value; /* must conform to VisitWindowProcPtr */ -#endif -{ - Window *wid = (Window *)value; - - if (pWin->drawable.id == *wid) - return(WT_STOPWALKING); - else - return(WT_WALKCHILDREN); -} - -/***** - * ReparentWindow - *****/ - -int -ReparentWindow(pWin, pParent, x, y, client) - register WindowPtr pWin, pParent; - int x,y; - ClientPtr client; -{ - WindowPtr pPrev, pPriorParent; - Bool WasMapped = (Bool)(pWin->mapped); - xEvent event; - int bw = wBorderWidth (pWin); - register ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING) - return(BadMatch); - if (!MakeWindowOptional(pWin)) - return(BadAlloc); - - if (WasMapped) - UnmapWindow(pWin, FALSE); - - event.u.u.type = ReparentNotify; - event.u.reparent.window = pWin->drawable.id; - event.u.reparent.parent = pParent->drawable.id; - event.u.reparent.x = x; - event.u.reparent.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pParent->parent) { - event.u.reparent.x += panoramiXdataPtr[0].x; - event.u.reparent.y += panoramiXdataPtr[0].y; - } -#endif - event.u.reparent.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, pParent); - - /* take out of sibling chain */ - - pPriorParent = pPrev = pWin->parent; - if (pPrev->firstChild == pWin) - pPrev->firstChild = pWin->nextSib; - if (pPrev->lastChild == pWin) - pPrev->lastChild = pWin->prevSib; - - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - - /* insert at begining of pParent */ - pWin->parent = pParent; - pPrev = RealChildHead(pParent); - if (pPrev) - { - pWin->nextSib = pPrev->nextSib; - if (pPrev->nextSib) - pPrev->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pPrev->nextSib = pWin; - pWin->prevSib = pPrev; - } - else - { - pWin->nextSib = pParent->firstChild; - pWin->prevSib = NullWindow; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.x = x + bw + pParent->drawable.x; - pWin->drawable.y = y + bw + pParent->drawable.y; - - /* clip to parent */ - SetWinSize (pWin); - SetBorderSize (pWin); - - if (pScreen->ReparentWindow) - (*pScreen->ReparentWindow)(pWin, pPriorParent); - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - CheckWindowOptionalNeed(pWin); - - if (WasMapped) - MapWindow(pWin, client); - RecalculateDeliverableEvents(pWin); - return(Success); -} - -static void -#if NeedFunctionPrototypes -RealizeTree(WindowPtr pWin) -#else -RealizeTree(pWin) - WindowPtr pWin; -#endif -{ - register WindowPtr pChild; - RealizeWindowProcPtr Realize; - - Realize = pWin->drawable.pScreen->RealizeWindow; - pChild = pWin; - while (1) - { - if (pChild->mapped) - { - pChild->realized = TRUE; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable++; -#endif - pChild->viewable = (pChild->drawable.class == InputOutput); - (* Realize)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * MapWindow - * If some other client has selected SubStructureReDirect on the parent - * and override-redirect is xFalse, then a MapRequest event is generated, - * but the window remains unmapped. Otherwise, the window is mapped and a - * MapNotify event is generated. - *****/ - -int -MapWindow(pWin, client) - register WindowPtr pWin; - ClientPtr client; -{ - register ScreenPtr pScreen; - - register WindowPtr pParent; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - if (pWin->mapped) - return(Success); - -#ifdef XCSECURITY - /* don't let an untrusted client map a child-of-trusted-window, InputOnly - * window; too easy to steal device input - */ - if ( (client->trustLevel != XSecurityClientTrusted) && - (pWin->drawable.class == InputOnly) && - (wClient(pWin->parent)->trustLevel == XSecurityClientTrusted) ) - return Success; -#endif - - pScreen = pWin->drawable.pScreen; - if ( (pParent = pWin->parent) ) - { - xEvent event; - Bool anyMarked; -#ifdef XAPPGROUP - ClientPtr win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ClientPtr ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.mapRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - pWin->mapped = TRUE; - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pParent->realized) - return(Success); - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - } - WindowsRestructured (); - } - else - { - RegionRec temp; - - pWin->mapped = TRUE; - pWin->realized = TRUE; /* for roots */ - pWin->viewable = pWin->drawable.class == InputOutput; - /* We SHOULD check for an error value here XXX */ - (*pScreen->RealizeWindow)(pWin); - if (pScreen->ClipNotify) - (*pScreen->ClipNotify) (pWin, 0, 0); - if (pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap); - REGION_INIT(pScreen, &temp, NullBox, 0); - REGION_COPY(pScreen, &temp, &pWin->clipList); - (*pScreen->WindowExposures) (pWin, &temp, NullRegion); - REGION_UNINIT(pScreen, &temp); - } - - return(Success); -} - - -/***** - * MapSubwindows - * Performs a MapWindow all unmapped children of the window, in top - * to bottom stacking order. - *****/ - -void -MapSubwindows(pParent, client) - register WindowPtr pParent; - ClientPtr client; -{ - register WindowPtr pWin; - WindowPtr pFirstMapped = NullWindow; -#ifdef DO_SAVE_UNDERS - WindowPtr pFirstSaveUndered = NullWindow; -#endif - register ScreenPtr pScreen; - register Mask parentRedirect; - register Mask parentNotify; - xEvent event; - Bool anyMarked; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - pScreen = pParent->drawable.pScreen; - parentRedirect = RedirectSend(pParent); - parentNotify = SubSend(pParent); - anyMarked = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (!pWin->mapped) - { - if (parentRedirect && !pWin->overrideRedirect) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - continue; - } - - pWin->mapped = TRUE; - if (parentNotify || StrSend(pWin)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pFirstMapped) - pFirstMapped = pWin; - if (pParent->realized) - { - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = TRUE; - } -#endif /* DO_SAVE_UNDERS */ - } - } - } - } - - if (pFirstMapped) - { - pLayerWin = (*pScreen->GetLayerWindow)(pParent); - if (pLayerWin->parent != pParent) { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pLayerWin, - pLayerWin, - (WindowPtr *)NULL); - pFirstMapped = pLayerWin; - } - if (anyMarked) - { -#ifdef DO_SAVE_UNDERS - if (pLayerWin->parent != pParent) - { - if (dosave || (DO_SAVE_UNDERS(pLayerWin))) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, - pLayerWin); - } - } - else if (dosave) - { - dosave = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (DO_SAVE_UNDERS(pWin)) - { - dosave |= (*pScreen->ChangeSaveUnder)(pWin, - pWin->nextSib); - if (dosave && !pFirstSaveUndered) - pFirstSaveUndered = pWin; - } - } - } -#endif /* DO_SAVE_UNDERS */ - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstMapped, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, - pFirstSaveUndered->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstMapped, - VTMap); - WindowsRestructured (); - } -} - -static void -#if NeedFunctionPrototypes -UnrealizeTree( - WindowPtr pWin, - Bool fromConfigure) -#else -UnrealizeTree(pWin, fromConfigure) - WindowPtr pWin; - Bool fromConfigure; -#endif -{ - register WindowPtr pChild; - UnrealizeWindowProcPtr Unrealize; - MarkUnrealizedWindowProcPtr MarkUnrealizedWindow; - - Unrealize = pWin->drawable.pScreen->UnrealizeWindow; - MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow; - pChild = pWin; - while (1) - { - if (pChild->realized) - { - pChild->realized = FALSE; - pChild->visibility = VisibilityNotViewable; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { - PanoramiXRes *win; - win = (PanoramiXRes*)LookupIDByType(pChild->drawable.id, - XRT_WINDOW); - if(win) - win->u.win.visibility = VisibilityNotViewable; - } -#endif - (* Unrealize)(pChild); - DeleteWindowFromAnyEvents(pChild, FALSE); - if (pChild->viewable) - { -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->backStorage) - (*pChild->drawable.pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - (* MarkUnrealizedWindow)(pChild, pWin, fromConfigure); - pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * UnmapWindow - * If the window is already unmapped, this request has no effect. - * Otherwise, the window is unmapped and an UnMapNotify event is - * generated. Cannot unmap a root window. - *****/ - -int -UnmapWindow(pWin, fromConfigure) - register WindowPtr pWin; - Bool fromConfigure; -{ - register WindowPtr pParent; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - ScreenPtr pScreen = pWin->drawable.pScreen; - WindowPtr pLayerWin = pWin; - - if ((!pWin->mapped) || (!(pParent = pWin->parent))) - return(Success); - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pWin->drawable.id; - event.u.unmapNotify.fromConfigure = fromConfigure; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (wasViewable && !fromConfigure) - { - pWin->valdata = UnmapValData; - (*pScreen->MarkOverlappedWindows)(pWin, pWin->nextSib, &pLayerWin); - (*pScreen->MarkWindow)(pLayerWin->parent); - } - pWin->mapped = FALSE; - if (wasRealized) - UnrealizeTree(pWin, fromConfigure); - if (wasViewable) - { - if (!fromConfigure) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pWin, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib) ) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); - } - } - pWin->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (!fromConfigure && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pWin, VTUnmap); - } - if (wasRealized && !fromConfigure) - WindowsRestructured (); - return(Success); -} - -/***** - * UnmapSubwindows - * Performs an UnmapWindow request with the specified mode on all mapped - * children of the window, in bottom to top stacking order. - *****/ - -void -UnmapSubwindows(pWin) - register WindowPtr pWin; -{ - register WindowPtr pChild, pHead; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - Bool anyMarked = FALSE; - Mask parentNotify; - WindowPtr pLayerWin = NULL; - ScreenPtr pScreen = pWin->drawable.pScreen; - - if (!pWin->firstChild) - return; - parentNotify = SubSend(pWin); - pHead = RealChildHead(pWin); - - if (wasViewable) - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (pChild->mapped) - { - if (parentNotify || StrSend(pChild)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pChild->drawable.id; - event.u.unmapNotify.fromConfigure = xFalse; - DeliverEvents(pChild, &event, 1, NullWindow); - } - if (pChild->viewable) - { - pChild->valdata = UnmapValData; - anyMarked = TRUE; - } - pChild->mapped = FALSE; - if (pChild->realized) - UnrealizeTree(pChild, FALSE); - if (wasViewable) - { -#ifdef DO_SAVE_UNDERS - pChild->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (pChild->backStorage) - (*pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - } - } - } - if (wasViewable) - { - if (anyMarked) - { - if (pLayerWin->parent == pWin) - (*pScreen->MarkWindow)(pWin); - else - { - WindowPtr ptmp; - (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - (*pScreen->MarkWindow)(pLayerWin->parent); - - /* Windows between pWin and pLayerWin may not have been marked */ - ptmp = pWin; - - while (ptmp != pLayerWin->parent) - { - (*pScreen->MarkWindow)(ptmp); - ptmp = ptmp->parent; - } - pHead = pWin->firstChild; - } - (*pScreen->ValidateTree)(pLayerWin->parent, pHead, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin)) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pHead, VTUnmap); - } - if (wasRealized) - WindowsRestructured (); -} - - -void -HandleSaveSet(client) - register ClientPtr client; -{ - register WindowPtr pParent, pWin; - register int j; - - for (j=0; jnumSaved; j++) - { - pWin = (WindowPtr)client->saveSet[j]; - pParent = pWin->parent; - while (pParent && (wClient (pParent) == client)) - pParent = pParent->parent; - if (pParent) - { - if (pParent != pWin->parent) - { - ReparentWindow(pWin, pParent, - pWin->drawable.x - wBorderWidth (pWin) - pParent->drawable.x, - pWin->drawable.y - wBorderWidth (pWin) - pParent->drawable.y, - client); - if(!pWin->realized && pWin->mapped) - pWin->mapped = FALSE; - } - MapWindow(pWin, client); - } - } - xfree(client->saveSet); - client->numSaved = 0; - client->saveSet = (pointer *)NULL; -} - -Bool -VisibleBoundingBoxFromPoint(pWin, x, y, box) - register WindowPtr pWin; - int x, y; /* in root */ - BoxPtr box; /* "return" value */ -{ - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->clipList, x, y, box)) - return(TRUE); - return(FALSE); -} - -Bool -PointInWindowIsVisible(pWin, x, y) - register WindowPtr pWin; - int x, y; /* in root */ -{ - BoxRec box; - - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip, - x, y, &box)) - return(TRUE); - return(FALSE); -} - - -RegionPtr -NotClippedByChildren(pWin) - register WindowPtr pWin; -{ - register ScreenPtr pScreen; - RegionPtr pReg; - - pScreen = pWin->drawable.pScreen; - pReg = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->parent || - screenIsSaved != SCREEN_SAVER_ON || - !HasSaverWindow (pWin->drawable.pScreen->myNum)) - { - REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize); - } - return(pReg); -} - -void -SendVisibilityNotify(pWin) - WindowPtr pWin; -{ - xEvent event; - unsigned int visibility = pWin->visibility; - -#ifdef PANORAMIX - /* This is not quite correct yet, but it's close */ - if(!noPanoramiXExtension) { - PanoramiXRes *win; - WindowPtr pWin2; - int i, Scrnum; - - Scrnum = pWin->drawable.pScreen->myNum; - - win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, Scrnum); - - if(!win || (win->u.win.visibility == visibility)) - return; - - switch(visibility) { - case VisibilityUnobscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility == VisibilityPartiallyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - case VisibilityPartiallyObscured: - if(Scrnum) { - pWin2 = (WindowPtr)LookupIDByType(win->info[0].id, RT_WINDOW); - if (pWin2) pWin = pWin2; - } - break; - case VisibilityFullyObscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility != VisibilityFullyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - } - - win->u.win.visibility = visibility; - } -#endif - - event.u.u.type = VisibilityNotify; - event.u.visibility.window = pWin->drawable.id; - event.u.visibility.state = visibility; - DeliverEvents(pWin, &event, 1, NullWindow); -} - - -#define RANDOM_WIDTH 32 - -#ifndef NOLOGOHACK -static void DrawLogo( -#if NeedFunctionPrototypes - WindowPtr /*pWin*/ -#endif -); -#endif - -void -SaveScreens(on, mode) - int on; - int mode; -{ - int i; - int what; - int type; - - if (on == SCREEN_SAVER_FORCER) - { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; - if (mode == ScreenSaverReset) - what = SCREEN_SAVER_OFF; - else - what = SCREEN_SAVER_ON; - type = what; - } - else - { - what = on; - type = what; - if (what == screenIsSaved) - type = SCREEN_SAVER_CYCLE; - } - for (i = 0; i < screenInfo.numScreens; i++) - { - if (on == SCREEN_SAVER_FORCER) - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], on); - if (savedScreenInfo[i].ExternalScreenSaver) - { - if ((*savedScreenInfo[i].ExternalScreenSaver) - (screenInfo.screens[i], type, on == SCREEN_SAVER_FORCER)) - continue; - } - if (type == screenIsSaved) - continue; - switch (type) { - case SCREEN_SAVER_OFF: - if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - what); - } - else if (HasSaverWindow (i)) - { - savedScreenInfo[i].pWindow = NullWindow; - FreeResource(savedScreenInfo[i].wid, RT_NONE); - } - break; - case SCREEN_SAVER_CYCLE: - if (savedScreenInfo[i].blanked == SCREEN_IS_TILED) - { - WindowPtr pWin = savedScreenInfo[i].pWindow; - /* make it look like screen saver is off, so that - * NotClippedByChildren will compute a clip list - * for the root window, so miPaintWindow works - */ - screenIsSaved = SCREEN_SAVER_OFF; -#ifndef NOLOGOHACK - if (logoScreenSaver) - (*pWin->drawable.pScreen->ClearToBackground)(pWin, 0, 0, 0, 0, FALSE); -#endif - (*pWin->drawable.pScreen->MoveWindow)(pWin, - (short)(-(rand() % RANDOM_WIDTH)), - (short)(-(rand() % RANDOM_WIDTH)), - pWin->nextSib, VTMove); -#ifndef NOLOGOHACK - if (logoScreenSaver) - DrawLogo(pWin); -#endif - screenIsSaved = SCREEN_SAVER_ON; - } - /* - * Call the DDX saver in case it wants to do something - * at cycle time - */ - else if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - type); - } - break; - case SCREEN_SAVER_ON: - if (ScreenSaverBlanking != DontPreferBlanking) - { - if ((* screenInfo.screens[i]->SaveScreen) - (screenInfo.screens[i], what)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLANKED; - continue; - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_BLACK)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLACK; - continue; - } - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_TILED)) - { - savedScreenInfo[i].blanked = SCREEN_IS_TILED; - } - else - savedScreenInfo[i].blanked = SCREEN_ISNT_SAVED; - break; - } - } - screenIsSaved = what; -} - -static Bool -#if NeedFunctionPrototypes -TileScreenSaver(int i, int kind) -#else -TileScreenSaver(i, kind) - int i; - int kind; -#endif -{ - int j; - int result; - XID attributes[3]; - Mask mask; - WindowPtr pWin; - CursorMetricRec cm; - unsigned char *srcbits, *mskbits; - CursorPtr cursor; - XID cursorID = 0; - int attri; - - mask = 0; - attri = 0; - switch (kind) { - case SCREEN_IS_TILED: - switch (WindowTable[i]->backgroundState) { - case BackgroundPixel: - attributes[attri++] = WindowTable[i]->background.pixel; - mask |= CWBackPixel; - break; - case BackgroundPixmap: - attributes[attri++] = None; - mask |= CWBackPixmap; - break; - default: - break; - } - break; - case SCREEN_IS_BLACK: - attributes[attri++] = WindowTable[i]->drawable.pScreen->blackPixel; - mask |= CWBackPixel; - break; - } - mask |= CWOverrideRedirect; - attributes[attri++] = xTrue; - - /* - * create a blank cursor - */ - - cm.width=16; - cm.height=16; - cm.xhot=8; - cm.yhot=8; - srcbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - mskbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - if (!srcbits || !mskbits) - { - xfree(srcbits); - xfree(mskbits); - cursor = 0; - } - else - { - for (j=0; jwidth + RANDOM_WIDTH, - (unsigned short)screenInfo.screens[i]->height + RANDOM_WIDTH, - 0, InputOutput, mask, attributes, 0, serverClient, - wVisual (WindowTable[i]), &result); - - if (cursor) - FreeResource (cursorID, RT_NONE); - - if (!pWin) - return FALSE; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, - (pointer)savedScreenInfo[i].pWindow)) - return FALSE; - - if (mask & CWBackPixmap) - { - MakeRootTile (pWin); - (*pWin->drawable.pScreen->ChangeWindowAttributes)(pWin, CWBackPixmap); - } - MapWindow(pWin, serverClient); -#ifndef NOLOGOHACK - if (kind == SCREEN_IS_TILED && logoScreenSaver) - DrawLogo(pWin); -#endif - return TRUE; -} - -/* - * FindWindowWithOptional - * - * search ancestors of the given window for an entry containing - * a WindowOpt structure. Assumptions: some parent will - * contain the structure. - */ - -WindowPtr -FindWindowWithOptional (w) - register WindowPtr w; -{ - do - w = w->parent; - while (!w->optional); - return w; -} - -/* - * CheckWindowOptionalNeed - * - * check each optional entry in the given window to see if - * the value is satisfied by the default rules. If so, - * release the optional record - */ - -void -CheckWindowOptionalNeed (w) - register WindowPtr w; -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (!w->parent) - return; - optional = w->optional; - if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate]) - return; - if (optional->otherEventMasks != 0) - return; - if (optional->otherClients != NULL) - return; - if (optional->passiveGrabs != NULL) - return; - if (optional->userProps != NULL) - return; - if (optional->backingBitPlanes != ~0L) - return; - if (optional->backingPixel != 0) - return; -#ifdef SHAPE - if (optional->boundingShape != NULL) - return; - if (optional->clipShape != NULL) - return; -#endif -#ifdef XINPUT - if (optional->inputMasks != NULL) - return; -#endif - parentOptional = FindWindowWithOptional(w)->optional; - if (optional->visual != parentOptional->visual) - return; - if (optional->cursor != None && - (optional->cursor != parentOptional->cursor || - w->parent->cursorIsNone)) - return; - if (optional->colormap != parentOptional->colormap) - return; - DisposeWindowOptional (w); -} - -/* - * MakeWindowOptional - * - * create an optional record and initialize it with the default - * values. - */ - -Bool -MakeWindowOptional (pWin) - register WindowPtr pWin; -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (pWin->optional) - return TRUE; - optional = (WindowOptPtr) xalloc (sizeof (WindowOptRec)); - if (!optional) - return FALSE; - optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; - optional->otherEventMasks = 0; - optional->otherClients = NULL; - optional->passiveGrabs = NULL; - optional->userProps = NULL; - optional->backingBitPlanes = ~0L; - optional->backingPixel = 0; -#ifdef SHAPE - optional->boundingShape = NULL; - optional->clipShape = NULL; -#endif -#ifdef XINPUT - optional->inputMasks = NULL; -#endif - parentOptional = FindWindowWithOptional(pWin)->optional; - optional->visual = parentOptional->visual; - if (!pWin->cursorIsNone) - { - optional->cursor = parentOptional->cursor; - optional->cursor->refcnt++; - } - else - { - optional->cursor = None; - } - optional->colormap = parentOptional->colormap; - pWin->optional = optional; - return TRUE; -} - -void -DisposeWindowOptional (pWin) - register WindowPtr pWin; -{ - if (!pWin->optional) - return; - /* - * everything is peachy. Delete the optional record - * and clean up - */ - /* - * TOG changed this code to: - * - * if (pWin->cursorIsNone == FALSE) - * FreeCursor (pWin->optional->cursor, (Cursor)0); - * pWin->cursorIsNone = TRUE; - * - * This is blatently wrong; windows without optionals can have - * two different cursor values, either None or sharing their - * parents cursor. This difference is controlled by the - * cursorIsNone value; when TRUE, the window has no cursor, - * when false, it shares its cursor with its parent; TOG - * made it impossible for a window to have a cursor without - * an optional record. - */ - if (pWin->optional->cursor) - { - FreeCursor (pWin->optional->cursor, (Cursor)0); - pWin->cursorIsNone = FALSE; - } - else - pWin->cursorIsNone = TRUE; - xfree (pWin->optional); - pWin->optional = NULL; -} - -#ifndef NOLOGOHACK -static void -#if NeedFunctionPrototypes -DrawLogo(WindowPtr pWin) -#else -DrawLogo(pWin) - WindowPtr pWin; -#endif -{ - DrawablePtr pDraw; - ScreenPtr pScreen; - int x, y; - unsigned int width, height, size; - GC *pGC; - int thin, gap, d31; - DDXPointRec poly[4]; - ChangeGCVal fore[2], back[2]; - xrgb rgb[2]; - BITS32 fmask, bmask; - ColormapPtr cmap; - - pDraw = (DrawablePtr)pWin; - pScreen = pDraw->pScreen; - x = -pWin->origin.x; - y = -pWin->origin.y; - width = pScreen->width; - height = pScreen->height; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pGC) - return; - - if ((rand() % 100) <= 17) /* make the probability for white fairly low */ - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - if ((pWin->backgroundState == BackgroundPixel) && - (cmap = (ColormapPtr)LookupIDByType(wColormap (pWin), RT_COLORMAP))) { - Pixel querypixels[2]; - - querypixels[0] = fore[0].val; - querypixels[1] = pWin->background.pixel; - QueryColors(cmap, 2, querypixels, rgb); - if ((rgb[0].red == rgb[1].red) && - (rgb[0].green == rgb[1].green) && - (rgb[0].blue == rgb[1].blue)) { - if (fore[0].val == pScreen->blackPixel) - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - } - } - fore[1].val = FillSolid; - fmask = GCForeground|GCFillStyle; - if (pWin->backgroundState == BackgroundPixel) { - back[0].val = pWin->background.pixel; - back[1].val = FillSolid; - bmask = GCForeground|GCFillStyle; - } else { - back[0].val = 0; - back[1].val = 0; - dixChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin, - NULL, back); - back[0].val = FillTiled; - back[1].ptr = pWin->background.pixmap; - bmask = GCFillStyle|GCTile; - } - - /* should be the same as the reference function XmuDrawLogo() */ - - size = width; - if (height < width) - size = height; - size = RANDOM_WIDTH + rand() % (size - RANDOM_WIDTH); - size &= ~1; - x += rand() % (width - size); - y += rand() % (height - size); - -/* - * Draw what will be the thin strokes. - * - * ----- - * / / - * / / - * / / - * / / - * /____/ - * d - * - * Point d is 9/44 (~1/5) of the way across. - */ - - thin = (size / 11); - if (thin < 1) thin = 1; - gap = (thin+3) / 4; - d31 = thin + thin + gap; - poly[0].x = x + size; poly[0].y = y; - poly[1].x = x + size-d31; poly[1].y = y; - poly[2].x = x + 0; poly[2].y = y + size; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for lower thin stroke. - * - * ------ - * / / - * / __ / - * / / / - * / / / - * /__/__/ - */ - - poly[0].x = x + d31/2; poly[0].y = y + size; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)+(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for upper thin stroke. - * - * ------ - * / / / - * /--/ / - * / / - * / / - * /_____/ - */ - - poly[0].x = x + size - d31/2; poly[0].y = y; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)-(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + size - d31; poly[3].y = y; - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Draw thick stroke. - * Point b is 1/4 of the way across. - * - * b - * ----- - * \ \ - * \ \ - * \ \ - * \ \ - * \____\ - */ - - poly[0].x = x; poly[0].y = y; - poly[1].x = x + size/4; poly[1].y = y; - poly[2].x = x + size; poly[2].y = y + size; - poly[3].x = x + size - size/4; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase to create gap. - * - * / - * / - * / - * / - * / - */ - - poly[0].x = x + size- thin; poly[0].y = y; - poly[1].x = x + size-( thin+gap); poly[1].y = y; - poly[2].x = x + thin; poly[2].y = y + size; - poly[3].x = x + thin + gap; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - - FreeScratchGC(pGC); -} - -#endif diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.NX.original deleted file mode 100644 index f3bfcf58a..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.NX.original +++ /dev/null @@ -1,2277 +0,0 @@ -#ifdef NXAGENT_UPGRADE - -#if !defined(__sun) && !defined(__CYGWIN__) - -#include "X/NXxvdisp.c" - -#endif - -#else - -/*********************************************************** -Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts, -and the Massachusetts Institute of Technology, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital or MIT not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $XFree86: xc/programs/Xserver/Xext/xvdisp.c,v 1.25 2001/11/18 23:55:48 mvojkovi Exp $ */ - -/* -** File: -** -** xvdisp.c --- Xv server extension dispatch module. -** -** Author: -** -** David Carver (Digital Workstation Engineering/Project Athena) -** -** Revisions: -** -** 11.06.91 Carver -** - changed SetPortControl to SetPortAttribute -** - changed GetPortControl to GetPortAttribute -** - changed QueryBestSize -** -** 15.05.91 Carver -** - version 2.0 upgrade -** -** 24.01.91 Carver -** - version 1.4 upgrade -** -*/ - -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "dixstruct.h" -#include "resource.h" -#include "opaque.h" - -#include "Xv.h" -#include "Xvproto.h" -#include "xvdix.h" -#ifdef MITSHM -#define _XSHM_SERVER_ -#include "shmstr.h" -#endif - -#include "Trap.h" - -#undef TEST -#undef DEBUG - -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -unsigned long XvXRTPort; - -#ifdef MITSHM -static int XineramaXvShmPutImage(ClientPtr); -#endif -static int XineramaXvPutImage(ClientPtr); -static int XineramaXvPutVideo(ClientPtr); -static int XineramaXvPutStill(ClientPtr); -static int XineramaXvSetPortAttribute(ClientPtr); -static int XineramaXvStopVideo(ClientPtr); -#endif - -/* INTERNAL */ - -static int ProcXvQueryExtension(ClientPtr); -static int ProcXvQueryAdaptors(ClientPtr); -static int ProcXvQueryEncodings(ClientPtr); -static int ProcXvPutVideo(ClientPtr); -static int ProcXvPutStill(ClientPtr); -static int ProcXvGetVideo(ClientPtr); -static int ProcXvGetStill(ClientPtr); -static int ProcXvGrabPort(ClientPtr); -static int ProcXvUngrabPort(ClientPtr); -static int ProcXvSelectVideoNotify(ClientPtr); -static int ProcXvSelectPortNotify(ClientPtr); -static int ProcXvStopVideo(ClientPtr); -static int ProcXvSetPortAttribute(ClientPtr); -static int ProcXvGetPortAttribute(ClientPtr); -static int ProcXvQueryBestSize(ClientPtr); -static int ProcXvQueryPortAttributes(ClientPtr); -static int ProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int ProcXvShmPutImage(ClientPtr); -#endif -static int ProcXvQueryImageAttributes(ClientPtr); -static int ProcXvListImageFormats(ClientPtr); - -static int SProcXvQueryExtension(ClientPtr); -static int SProcXvQueryAdaptors(ClientPtr); -static int SProcXvQueryEncodings(ClientPtr); -static int SProcXvPutVideo(ClientPtr); -static int SProcXvPutStill(ClientPtr); -static int SProcXvGetVideo(ClientPtr); -static int SProcXvGetStill(ClientPtr); -static int SProcXvGrabPort(ClientPtr); -static int SProcXvUngrabPort(ClientPtr); -static int SProcXvSelectVideoNotify(ClientPtr); -static int SProcXvSelectPortNotify(ClientPtr); -static int SProcXvStopVideo(ClientPtr); -static int SProcXvSetPortAttribute(ClientPtr); -static int SProcXvGetPortAttribute(ClientPtr); -static int SProcXvQueryBestSize(ClientPtr); -static int SProcXvQueryPortAttributes(ClientPtr); -static int SProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int SProcXvShmPutImage(ClientPtr); -#endif -static int SProcXvQueryImageAttributes(ClientPtr); -static int SProcXvListImageFormats(ClientPtr); - -static int SWriteQueryAdaptorsReply(ClientPtr, xvQueryAdaptorsReply *); -static int SWriteQueryExtensionReply(ClientPtr, xvQueryExtensionReply *); -static int SWriteQueryEncodingsReply(ClientPtr, xvQueryEncodingsReply *); -static int SWriteAdaptorInfo(ClientPtr, xvAdaptorInfo *); -static int SWriteEncodingInfo(ClientPtr, xvEncodingInfo *); -static int SWriteFormat(ClientPtr, xvFormat *); -static int SWriteAttributeInfo(ClientPtr, xvAttributeInfo *); -static int SWriteGrabPortReply(ClientPtr, xvGrabPortReply *); -static int SWriteGetPortAttributeReply(ClientPtr, xvGetPortAttributeReply *); -static int SWriteQueryBestSizeReply(ClientPtr, xvQueryBestSizeReply *); -static int SWriteQueryPortAttributesReply( - ClientPtr, xvQueryPortAttributesReply *); -static int SWriteQueryImageAttributesReply( - ClientPtr, xvQueryImageAttributesReply*); -static int SWriteListImageFormatsReply(ClientPtr, xvListImageFormatsReply*); -static int SWriteImageFormatInfo(ClientPtr, xvImageFormatInfo*); - -#define _WriteQueryAdaptorsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryAdaptorsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryAdaptorsReply, (char*)_d) - -#define _WriteQueryExtensionReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryExtensionReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryExtensionReply, (char*)_d) - -#define _WriteQueryEncodingsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryEncodingsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryEncodingsReply, (char*)_d) - -#define _WriteAdaptorInfo(_c,_d) \ - if ((_c)->swapped) SWriteAdaptorInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAdaptorInfo, (char*)_d) - -#define _WriteAttributeInfo(_c,_d) \ - if ((_c)->swapped) SWriteAttributeInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAttributeInfo, (char*)_d) - -#define _WriteEncodingInfo(_c,_d) \ - if ((_c)->swapped) SWriteEncodingInfo(_c, _d); \ - else WriteToClient(_c, sz_xvEncodingInfo, (char*)_d) - -#define _WriteFormat(_c,_d) \ - if ((_c)->swapped) SWriteFormat(_c, _d); \ - else WriteToClient(_c, sz_xvFormat, (char*)_d) - -#define _WriteGrabPortReply(_c,_d) \ - if ((_c)->swapped) SWriteGrabPortReply(_c, _d); \ - else WriteToClient(_c, sz_xvGrabPortReply, (char*)_d) - -#define _WriteGetPortAttributeReply(_c,_d) \ - if ((_c)->swapped) SWriteGetPortAttributeReply(_c, _d); \ - else WriteToClient(_c, sz_xvGetPortAttributeReply, (char*)_d) - -#define _WriteQueryBestSizeReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryBestSizeReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryBestSizeReply,(char*) _d) - -#define _WriteQueryPortAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryPortAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryPortAttributesReply,(char*) _d) - -#define _WriteQueryImageAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryImageAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryImageAttributesReply,(char*) _d) - -#define _WriteListImageFormatsReply(_c,_d) \ - if ((_c)->swapped) SWriteListImageFormatsReply(_c, _d); \ - else WriteToClient(_c, sz_xvListImageFormatsReply,(char*) _d) - -#define _WriteImageFormatInfo(_c,_d) \ - if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \ - else WriteToClient(_c, sz_xvImageFormatInfo, (char*)_d) - -#define _AllocatePort(_i,_p) \ - ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success - -/* -** ProcXvDispatch -** -** -** -*/ - -int -ProcXvDispatch(ClientPtr client) -{ - int result; - - REQUEST(xReq); - - UpdateCurrentTime(); - - /* - * Report upstream that we are - * dispatching a XVideo operation. - */ - - nxagentXvTrap = 1; - - #ifdef TEST - fprintf(stderr, "ProcXvDispatch: Going to dispatch XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - switch (stuff->data) - { - case xv_QueryExtension: result = (ProcXvQueryExtension(client)); break; - case xv_QueryAdaptors: result = (ProcXvQueryAdaptors(client)); break; - case xv_QueryEncodings: result = (ProcXvQueryEncodings(client)); break; - case xv_PutVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvPutVideo(client)); break; - else -#endif - result = (ProcXvPutVideo(client)); break; - case xv_PutStill: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvPutStill(client)); break - else -#endif - result = (ProcXvPutStill(client)); break; - case xv_GetVideo: result = (ProcXvGetVideo(client)); break; - case xv_GetStill: result = (ProcXvGetStill(client)); break; - case xv_GrabPort: result = (ProcXvGrabPort(client)); break; - case xv_UngrabPort: result = (ProcXvUngrabPort(client)); break; - case xv_SelectVideoNotify: result = (ProcXvSelectVideoNotify(client)); break; - case xv_SelectPortNotify: result = (ProcXvSelectPortNotify(client)); break; - case xv_StopVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvStopVideo(client)); break; - else -#endif - result = (ProcXvStopVideo(client)); break; - case xv_SetPortAttribute: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvSetPortAttribute(client)); break; - else -#endif - result = (ProcXvSetPortAttribute(client)); break; - case xv_GetPortAttribute: result = (ProcXvGetPortAttribute(client)); break; - case xv_QueryBestSize: result = (ProcXvQueryBestSize(client)); break; - case xv_QueryPortAttributes: result = (ProcXvQueryPortAttributes(client)); break; - case xv_PutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvPutImage(client)); break; - else -#endif - result = (ProcXvPutImage(client)); break; -#ifdef MITSHM - case xv_ShmPutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvShmPutImage(client)); break; - else -#endif - result = (ProcXvShmPutImage(client)); break; -#endif - case xv_QueryImageAttributes: result = (ProcXvQueryImageAttributes(client)); break; - case xv_ListImageFormats: result = (ProcXvListImageFormats(client)); break; - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - result = (BadImplementation); break; - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - result = (BadRequest); break; - } - } - - nxagentXvTrap = 0; - - #ifdef TEST - fprintf(stderr, "ProcXvDispatch: Dispatched XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - return result; -} - -int -SProcXvDispatch(ClientPtr client) -{ - int result; - - REQUEST(xReq); - - UpdateCurrentTime(); - - /* - * Report upstream that we are - * dispatching a XVideo operation. - */ - - nxagentXvTrap = 1; - - #ifdef TEST - fprintf(stderr, "SProcXvDispatch: Going to dispatch XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - switch (stuff->data) - { - case xv_QueryExtension: result = (SProcXvQueryExtension(client)); break; - case xv_QueryAdaptors: result = (SProcXvQueryAdaptors(client)); break; - case xv_QueryEncodings: result = (SProcXvQueryEncodings(client)); break; - case xv_PutVideo: result = (SProcXvPutVideo(client)); break; - case xv_PutStill: result = (SProcXvPutStill(client)); break; - case xv_GetVideo: result = (SProcXvGetVideo(client)); break; - case xv_GetStill: result = (SProcXvGetStill(client)); break; - case xv_GrabPort: result = (SProcXvGrabPort(client)); break; - case xv_UngrabPort: result = (SProcXvUngrabPort(client)); break; - case xv_SelectVideoNotify: result = (SProcXvSelectVideoNotify(client)); break; - case xv_SelectPortNotify: result = (SProcXvSelectPortNotify(client)); break; - case xv_StopVideo: result = (SProcXvStopVideo(client)); break; - case xv_SetPortAttribute: result = (SProcXvSetPortAttribute(client)); break; - case xv_GetPortAttribute: result = (SProcXvGetPortAttribute(client)); break; - case xv_QueryBestSize: result = (SProcXvQueryBestSize(client)); break; - case xv_QueryPortAttributes: result = (SProcXvQueryPortAttributes(client)); break; - case xv_PutImage: result = (SProcXvPutImage(client)); break; -#ifdef MITSHM - case xv_ShmPutImage: result = (SProcXvShmPutImage(client)); break; -#endif - case xv_QueryImageAttributes: result = (SProcXvQueryImageAttributes(client)); break; - case xv_ListImageFormats: result = (SProcXvListImageFormats(client)); break; - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - result = (BadImplementation); break; - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - result = (BadRequest); break; - } - } - - nxagentXvTrap = 0; - - #ifdef TEST - fprintf(stderr, "ProcXvDispatch: Dispatched XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - return result; -} - -static int -ProcXvQueryExtension(ClientPtr client) -{ - xvQueryExtensionReply rep; - /* REQUEST(xvQueryExtensionReq); */ - REQUEST_SIZE_MATCH(xvQueryExtensionReq); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.version = XvVersion; - rep.revision = XvRevision; - - _WriteQueryExtensionReply(client, &rep); - - return Success; - -} - -static int -ProcXvQueryAdaptors(ClientPtr client) -{ - xvFormat format; - xvAdaptorInfo ainfo; - xvQueryAdaptorsReply rep; - int totalSize; - int na; - XvAdaptorPtr pa; - int nf; - XvFormatPtr pf; - WindowPtr pWin; - ScreenPtr pScreen; - XvScreenPtr pxvs; - - REQUEST(xvQueryAdaptorsReq); - REQUEST_SIZE_MATCH(xvQueryAdaptorsReq); - - if(!(pWin = (WindowPtr)LookupWindow(stuff->window, client) )) - { - client->errorValue = stuff->window; - return (BadWindow); - } - - pScreen = pWin->drawable.pScreen; - pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - if (!pxvs) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = 0; - rep.length = 0; - - _WriteQueryAdaptorsReply(client, &rep); - - return Success; - } - - (* pxvs->ddQueryAdaptors)(pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = pxvs->nAdaptors; - - /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ - - totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; - - /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - totalSize += (strlen(pa->name) + 3) & ~3; - totalSize += pa->nFormats * sz_xvFormat; - pa++; - } - - rep.length = totalSize >> 2; - - _WriteQueryAdaptorsReply(client, &rep); - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - - ainfo.base_id = pa->base_id; - ainfo.num_ports = pa->nPorts; - ainfo.type = pa->type; - ainfo.name_size = strlen(pa->name); - ainfo.num_formats = pa->nFormats; - - _WriteAdaptorInfo(client, &ainfo); - - WriteToClient(client, ainfo.name_size, pa->name); - - nf = pa->nFormats; - pf = pa->pFormats; - while (nf--) - { - format.depth = pf->depth; - format.visual = pf->visual; - _WriteFormat(client, &format); - pf++; - } - - pa++; - - } - - return (client->noClientException); - -} - -static int -ProcXvQueryEncodings(ClientPtr client) -{ - xvEncodingInfo einfo; - xvQueryEncodingsReply rep; - int totalSize; - XvPortPtr pPort; - int ne; - XvEncodingPtr pe; - int status; - - REQUEST(xvQueryEncodingsReq); - REQUEST_SIZE_MATCH(xvQueryEncodingsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_encodings = pPort->pAdaptor->nEncodings; - - /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */ - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - totalSize = ne * sz_xvEncodingInfo; - while (ne--) - { - totalSize += (strlen(pe->name) + 3) & ~3; - pe++; - } - - rep.length = totalSize >> 2; - - _WriteQueryEncodingsReply(client, &rep); - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - while (ne--) - { - einfo.encoding = pe->id; - einfo.name_size = strlen(pe->name); - einfo.width = pe->width; - einfo.height = pe->height; - einfo.rate.numerator = pe->rate.numerator; - einfo.rate.denominator = pe->rate.denominator; - _WriteEncodingInfo(client, &einfo); - WriteToClient(client, einfo.name_size, pe->name); - pe++; - } - - return (client->noClientException); - -} - -static int -ProcXvPutVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutVideoReq); - REQUEST_SIZE_MATCH(xvPutVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvPutStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutStillReq); - REQUEST_SIZE_MATCH(xvPutStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetVideoReq); - REQUEST_SIZE_MATCH(xvGetVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetStillReq); - REQUEST_SIZE_MATCH(xvGetStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvSelectVideoNotify(ClientPtr client) -{ - register DrawablePtr pDraw; - REQUEST(xvSelectVideoNotifyReq); - REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq); - - if(!(pDraw = (DrawablePtr)LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadWindow); - } - - return XVCALL(diSelectVideoNotify)(client, pDraw, stuff->onoff); - -} - -static int -ProcXvSelectPortNotify(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSelectPortNotifyReq); - REQUEST_SIZE_MATCH(xvSelectPortNotifyReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diSelectPortNotify)(client, pPort, stuff->onoff); - -} - -static int -ProcXvGrabPort(ClientPtr client) -{ - int result, status; - XvPortPtr pPort; - xvGrabPortReply rep; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - status = XVCALL(diGrabPort)(client, pPort, stuff->time, &result); - - if (status != Success) - { - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.result = result; - - _WriteGrabPortReply(client, &rep); - - return Success; - -} - -static int -ProcXvUngrabPort(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diUngrabPort)(client, pPort, stuff->time); - -} - - -static int -ProcXvStopVideo(ClientPtr client) -{ - int status; - register DrawablePtr pDraw; - XvPortPtr pPort; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if(!(pDraw = LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadDrawable); - } - - return XVCALL(diStopVideo)(client, pPort, pDraw); - -} - -static int -ProcXvSetPortAttribute(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSetPortAttributeReq); - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diSetPortAttribute)(client, pPort, - stuff->attribute, stuff->value); - - if (status == BadMatch) - client->errorValue = stuff->attribute; - else - client->errorValue = stuff->value; - - return status; -} - -static int -ProcXvGetPortAttribute(ClientPtr client) -{ - INT32 value; - int status; - XvPortPtr pPort; - xvGetPortAttributeReply rep; - REQUEST(xvGetPortAttributeReq); - REQUEST_SIZE_MATCH(xvGetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diGetPortAttribute)(client, pPort, stuff->attribute, &value); - if (status != Success) - { - client->errorValue = stuff->attribute; - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.value = value; - - _WriteGetPortAttributeReply(client, &rep); - - return Success; -} - -static int -ProcXvQueryBestSize(ClientPtr client) -{ - int status; - unsigned int actual_width, actual_height; - XvPortPtr pPort; - xvQueryBestSizeReply rep; - REQUEST(xvQueryBestSizeReq); - REQUEST_SIZE_MATCH(xvQueryBestSizeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - - (* pPort->pAdaptor->ddQueryBestSize)(client, pPort, stuff->motion, - stuff->vid_w, stuff->vid_h, - stuff->drw_w, stuff->drw_h, - &actual_width, &actual_height); - - rep.actual_width = actual_width; - rep.actual_height = actual_height; - - _WriteQueryBestSizeReply(client, &rep); - - return Success; -} - - -static int -ProcXvQueryPortAttributes(ClientPtr client) -{ - int status, size, i; - XvPortPtr pPort; - XvAttributePtr pAtt; - xvQueryPortAttributesReply rep; - xvAttributeInfo Info; - REQUEST(xvQueryPortAttributesReq); - REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_attributes = pPort->pAdaptor->nAttributes; - rep.text_size = 0; - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L; - } - - rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size; - rep.length >>= 2; - - _WriteQueryPortAttributesReply(client, &rep); - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - size = strlen(pAtt->name) + 1; /* pass the NULL */ - Info.flags = pAtt->flags; - Info.min = pAtt->min_value; - Info.max = pAtt->max_value; - Info.size = (size + 3) & ~3L; - - _WriteAttributeInfo(client, &Info); - - WriteToClient(client, size, pAtt->name); - } - - return Success; -} - - - -static int -ProcXvPutImage(ClientPtr client) -{ - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, i, size; - CARD16 width, height; - - REQUEST(xvPutImageReq); - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - width = stuff->width; - height = stuff->height; - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - size += sizeof(xvPutImageReq); - size = (size + 3) >> 2; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - if(client->req_len < size) - return BadLength; - - return XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, - pImage, (unsigned char*)(&stuff[1]), FALSE, - stuff->width, stuff->height); -} - -#ifdef MITSHM -/* redefined here since it's not in any header file */ -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -extern RESTYPE ShmSegType; -extern int BadShmSegCode; -extern int ShmCompletionCode; - -static int -ProcXvShmPutImage(ClientPtr client) -{ - ShmDescPtr shmdesc; - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, size_needed, i; - CARD16 width, height; - - REQUEST(xvShmPutImageReq); - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - if(!(shmdesc = (ShmDescPtr)LookupIDByType(stuff->shmseg, ShmSegType))) - { - client->errorValue = stuff->shmseg; - return BadShmSegCode; - } - - width = stuff->width; - height = stuff->height; - size_needed = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - if((size_needed + stuff->offset) > shmdesc->size) - return BadAccess; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - status = XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, pImage, - (unsigned char *)shmdesc->addr + stuff->offset, - stuff->send_event, stuff->width, stuff->height); - - if((status == Success) && stuff->send_event) { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = xv_ShmPutImage; - ev.majorEvent = XvReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return status; -} -#endif - -#ifdef XvMCExtension -XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id); -#endif - -static int -ProcXvQueryImageAttributes(ClientPtr client) -{ - xvQueryImageAttributesReply rep; - int size, num_planes, i; - CARD16 width, height; - XvImagePtr pImage = NULL; - XvPortPtr pPort; - int *offsets; - int *pitches; - REQUEST(xvQueryImageAttributesReq); - - REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - -#ifdef XvMCExtension - if(!pImage) - pImage = XvMCFindXvImage(pPort, stuff->id); -#endif - - if(!pImage) - return BadMatch; - - num_planes = pImage->num_planes; - - if(!(offsets = xalloc(num_planes << 3))) - return BadAlloc; - pitches = offsets + num_planes; - - width = stuff->width; - height = stuff->height; - - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, pPort, pImage, - &width, &height, offsets, pitches); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = num_planes << 1; - rep.num_planes = num_planes; - rep.width = width; - rep.height = height; - rep.data_size = size; - - _WriteQueryImageAttributesReply(client, &rep); - if(client->swapped) - SwapLongs((CARD32*)offsets, rep.length); - WriteToClient(client, rep.length << 2, (char*)offsets); - - xfree(offsets); - - return Success; -} - -static int -ProcXvListImageFormats(ClientPtr client) -{ - XvPortPtr pPort; - XvImagePtr pImage; - int i; - xvListImageFormatsReply rep; - xvImageFormatInfo info; - REQUEST(xvListImageFormatsReq); - - REQUEST_SIZE_MATCH(xvListImageFormatsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_formats = pPort->pAdaptor->nImages; - rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2; - - _WriteListImageFormatsReply(client, &rep); - - pImage = pPort->pAdaptor->pImages; - - for(i = 0; i < rep.num_formats; i++, pImage++) { - info.id = pImage->id; - info.type = pImage->type; - info.byte_order = pImage->byte_order; - memcpy(&info.guid, pImage->guid, 16); - info.bpp = pImage->bits_per_pixel; - info.num_planes = pImage->num_planes; - info.depth = pImage->depth; - info.red_mask = pImage->red_mask; - info.green_mask = pImage->green_mask; - info.blue_mask = pImage->blue_mask; - info.format = pImage->format; - info.y_sample_bits = pImage->y_sample_bits; - info.u_sample_bits = pImage->u_sample_bits; - info.v_sample_bits = pImage->v_sample_bits; - info.horz_y_period = pImage->horz_y_period; - info.horz_u_period = pImage->horz_u_period; - info.horz_v_period = pImage->horz_v_period; - info.vert_y_period = pImage->vert_y_period; - info.vert_u_period = pImage->vert_u_period; - info.vert_v_period = pImage->vert_v_period; - memcpy(&info.comp_order, pImage->component_order, 32); - info.scanline_order = pImage->scanline_order; - _WriteImageFormatInfo(client, &info); - } - - return Success; -} - - - -/* Swapped Procs */ - -static int -SProcXvQueryExtension(ClientPtr client) -{ - register char n; - REQUEST(xvQueryExtensionReq); - swaps(&stuff->length, n); - return ProcXvQueryExtension(client); -} - -static int -SProcXvQueryAdaptors(ClientPtr client) -{ - register char n; - REQUEST(xvQueryAdaptorsReq); - swaps(&stuff->length, n); - swapl(&stuff->window, n); - return ProcXvQueryAdaptors(client); -} - -static int -SProcXvQueryEncodings(ClientPtr client) -{ - register char n; - REQUEST(xvQueryEncodingsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryEncodings(client); -} - -static int -SProcXvGrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvGrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvGrabPort(client); -} - -static int -SProcXvUngrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvUngrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvUngrabPort(client); -} - -static int -SProcXvPutVideo(ClientPtr client) -{ - register char n; - REQUEST(xvPutVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutVideo(client); -} - -static int -SProcXvPutStill(ClientPtr client) -{ - register char n; - REQUEST(xvPutStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutStill(client); -} - -static int -SProcXvGetVideo(ClientPtr client) -{ - register char n; - REQUEST(xvGetVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetVideo(client); -} - -static int -SProcXvGetStill(ClientPtr client) -{ - register char n; - REQUEST(xvGetStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetStill(client); -} - -static int -SProcXvPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvPutImage(client); -} - -#ifdef MITSHM -static int -SProcXvShmPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvShmPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->offset, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvShmPutImage(client); -} -#endif - - -static int -SProcXvSelectVideoNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectVideoNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return ProcXvSelectVideoNotify(client); -} - -static int -SProcXvSelectPortNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectPortNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvSelectPortNotify(client); -} - -static int -SProcXvStopVideo(ClientPtr client) -{ - register char n; - REQUEST(xvStopVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - return ProcXvStopVideo(client); -} - -static int -SProcXvSetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvSetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvSetPortAttribute(client); -} - -static int -SProcXvGetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvGetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvGetPortAttribute(client); -} - -static int -SProcXvQueryBestSize(ClientPtr client) -{ - register char n; - REQUEST(xvQueryBestSizeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvQueryBestSize(client); -} - -static int -SProcXvQueryPortAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryPortAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryPortAttributes(client); -} - -static int -SProcXvQueryImageAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryImageAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->id, n); - swaps(&stuff->width, n); - swaps(&stuff->width, n); - return ProcXvQueryImageAttributes(client); -} - -static int -SProcXvListImageFormats(ClientPtr client) -{ - register char n; - REQUEST(xvListImageFormatsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvListImageFormats(client); -} - - -static int -SWriteQueryExtensionReply( - ClientPtr client, - xvQueryExtensionReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->version, n); - swaps(&rep->revision, n); - - (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryAdaptorsReply( - ClientPtr client, - xvQueryAdaptorsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_adaptors, n); - - (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryEncodingsReply( - ClientPtr client, - xvQueryEncodingsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_encodings, n); - - (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep); - - return Success; -} - -static int -SWriteAdaptorInfo( - ClientPtr client, - xvAdaptorInfo *pAdaptor -){ - register char n; - - swapl(&pAdaptor->base_id, n); - swaps(&pAdaptor->name_size, n); - swaps(&pAdaptor->num_ports, n); - swaps(&pAdaptor->num_formats, n); - - (void)WriteToClient(client, sz_xvAdaptorInfo, (char *)pAdaptor); - - return Success; -} - -static int -SWriteEncodingInfo( - ClientPtr client, - xvEncodingInfo *pEncoding -){ - register char n; - - swapl(&pEncoding->encoding, n); - swaps(&pEncoding->name_size, n); - swaps(&pEncoding->width, n); - swaps(&pEncoding->height, n); - swapl(&pEncoding->rate.numerator, n); - swapl(&pEncoding->rate.denominator, n); - (void)WriteToClient(client, sz_xvEncodingInfo, (char *)pEncoding); - - return Success; -} - -static int -SWriteFormat( - ClientPtr client, - xvFormat *pFormat -){ - register char n; - - swapl(&pFormat->visual, n); - (void)WriteToClient(client, sz_xvFormat, (char *)pFormat); - - return Success; -} - -static int -SWriteAttributeInfo( - ClientPtr client, - xvAttributeInfo *pAtt -){ - register char n; - - swapl(&pAtt->flags, n); - swapl(&pAtt->size, n); - swapl(&pAtt->min, n); - swapl(&pAtt->max, n); - (void)WriteToClient(client, sz_xvAttributeInfo, (char *)pAtt); - - return Success; -} - -static int -SWriteImageFormatInfo( - ClientPtr client, - xvImageFormatInfo *pImage -){ - register char n; - - swapl(&pImage->id, n); - swapl(&pImage->red_mask, n); - swapl(&pImage->green_mask, n); - swapl(&pImage->blue_mask, n); - swapl(&pImage->y_sample_bits, n); - swapl(&pImage->u_sample_bits, n); - swapl(&pImage->v_sample_bits, n); - swapl(&pImage->horz_y_period, n); - swapl(&pImage->horz_u_period, n); - swapl(&pImage->horz_v_period, n); - swapl(&pImage->vert_y_period, n); - swapl(&pImage->vert_u_period, n); - swapl(&pImage->vert_v_period, n); - - (void)WriteToClient(client, sz_xvImageFormatInfo, (char *)pImage); - - return Success; -} - - - -static int -SWriteGrabPortReply( - ClientPtr client, - xvGrabPortReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - - (void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep); - - return Success; -} - -static int -SWriteGetPortAttributeReply( - ClientPtr client, - xvGetPortAttributeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->value, n); - - (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryBestSizeReply( - ClientPtr client, - xvQueryBestSizeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->actual_width, n); - swaps(&rep->actual_height, n); - - (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryPortAttributesReply( - ClientPtr client, - xvQueryPortAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_attributes, n); - swapl(&rep->text_size, n); - - (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryImageAttributesReply( - ClientPtr client, - xvQueryImageAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_planes, n); - swapl(&rep->data_size, n); - swaps(&rep->width, n); - swaps(&rep->height, n); - - (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep); - - return Success; -} - - -static int -SWriteListImageFormatsReply( - ClientPtr client, - xvListImageFormatsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_formats, n); - - (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep); - - return Success; -} - - -#ifdef PANORAMIX - - - - -static int -XineramaXvStopVideo(ClientPtr client) -{ - int result = Success, i; - PanoramiXRes *draw, *port; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - result = ProcXvStopVideo(client); - } - } - - return result; -} - -static int -XineramaXvSetPortAttribute(ClientPtr client) -{ - REQUEST(xvSetPortAttributeReq); - PanoramiXRes *port; - int result = Success, i; - - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->port = port->info[i].id; - result = ProcXvSetPortAttribute(client); - } - } - return result; -} - - -#ifdef MITSHM -static int -XineramaXvShmPutImage(ClientPtr client) -{ - REQUEST(xvShmPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool send_event = stuff->send_event; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - stuff->send_event = (send_event && !i) ? 1 : 0; - - result = ProcXvShmPutImage(client); - } - } - return result; -} -#endif - -static int -XineramaXvPutImage(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutImage(client); - } - } - return result; -} - -static int -XineramaXvPutVideo(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutVideo(client); - } - } - return result; -} - -static int -XineramaXvPutStill(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutStill(client); - } - } - return result; -} - - -void XineramifyXv(void) -{ - ScreenPtr pScreen, screen0 = screenInfo.screens[0]; - XvScreenPtr xvsp0 = (XvScreenPtr)screen0->devPrivates[XvScreenIndex].ptr; - XvAdaptorPtr refAdapt, pAdapt; - XvAttributePtr pAttr; - XvScreenPtr xvsp; - Bool isOverlay, hasOverlay; - PanoramiXRes *port; - XvAdaptorPtr MatchingAdaptors[MAXSCREENS]; - int i, j, k, l; - - XvXRTPort = CreateNewResourceType(XineramaDeleteResource); - - if(!xvsp0) return; - - for(i = 0; i < xvsp0->nAdaptors; i++) { - refAdapt = xvsp0->pAdaptors + i; - - bzero(MatchingAdaptors, sizeof(XvAdaptorPtr) * MAXSCREENS); - - MatchingAdaptors[0] = refAdapt; - - if(!(refAdapt->type & XvInputMask)) continue; - - isOverlay = FALSE; - for(j = 0; j < refAdapt->nAttributes; j++) { - pAttr = refAdapt->pAttributes + j; - if(!strcmp(pAttr->name, "XV_COLORKEY")) { - isOverlay = TRUE; - break; - } - } - - for(j = 1; j < PanoramiXNumScreens; j++) { - pScreen = screenInfo.screens[j]; - xvsp = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - /* Do not try to go on if xv is not supported on this screen */ - if (xvsp==NULL) continue ; - - /* if the adaptor has the same name it's a perfect match */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if(!strcmp(refAdapt->name, pAdapt->name)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - if(MatchingAdaptors[j]) continue; /* found it */ - - /* otherwise we only look for XvImage adaptors */ - if(!(refAdapt->type & XvImageMask)) continue; - if(refAdapt->nImages <= 0) continue; - - /* prefer overlay/overlay non-overlay/non-overlay pairing */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - hasOverlay = FALSE; - for(l = 0; l < pAdapt->nAttributes; l++) { - if(!strcmp(pAdapt->name, "XV_COLORKEY")) { - hasOverlay = TRUE; - break; - } - } - if(isOverlay && hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - else if(!isOverlay && !hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - if(MatchingAdaptors[j]) continue; /* found it */ - - /* but we'll take any XvImage pairing if we can get it */ - - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - /* now create a resource for each port */ - for(j = 0; j < refAdapt->nPorts; j++) { - if(!(port = xalloc(sizeof(PanoramiXRes)))) - break; - port->info[0].id = MatchingAdaptors[0]->base_id + j; - AddResource(port->info[0].id, XvXRTPort, port); - - for(k = 1; k < PanoramiXNumScreens; k++) { - if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) - port->info[k].id = MatchingAdaptors[k]->base_id + j; - else - port->info[k].id = 0; - } - } - } -} - -#endif - -#endif /* #ifdef NXAGENT_UPGRADE */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.XF86.original b/nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.XF86.original deleted file mode 100644 index 3d321e8ae..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/NXxvdisp.c.XF86.original +++ /dev/null @@ -1,2214 +0,0 @@ -/*********************************************************** -Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts, -and the Massachusetts Institute of Technology, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital or MIT not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $XFree86: xc/programs/Xserver/Xext/xvdisp.c,v 1.25 2001/11/18 23:55:48 mvojkovi Exp $ */ - -/* -** File: -** -** xvdisp.c --- Xv server extension dispatch module. -** -** Author: -** -** David Carver (Digital Workstation Engineering/Project Athena) -** -** Revisions: -** -** 11.06.91 Carver -** - changed SetPortControl to SetPortAttribute -** - changed GetPortControl to GetPortAttribute -** - changed QueryBestSize -** -** 15.05.91 Carver -** - version 2.0 upgrade -** -** 24.01.91 Carver -** - version 1.4 upgrade -** -*/ - -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "dixstruct.h" -#include "resource.h" -#include "opaque.h" - -#include "Xv.h" -#include "Xvproto.h" -#include "xvdix.h" -#ifdef MITSHM -#define _XSHM_SERVER_ -#include "shmstr.h" -#endif - -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -unsigned long XvXRTPort; - -#ifdef MITSHM -static int XineramaXvShmPutImage(ClientPtr); -#endif -static int XineramaXvPutImage(ClientPtr); -static int XineramaXvPutVideo(ClientPtr); -static int XineramaXvPutStill(ClientPtr); -static int XineramaXvSetPortAttribute(ClientPtr); -static int XineramaXvStopVideo(ClientPtr); -#endif - -/* INTERNAL */ - -static int ProcXvQueryExtension(ClientPtr); -static int ProcXvQueryAdaptors(ClientPtr); -static int ProcXvQueryEncodings(ClientPtr); -static int ProcXvPutVideo(ClientPtr); -static int ProcXvPutStill(ClientPtr); -static int ProcXvGetVideo(ClientPtr); -static int ProcXvGetStill(ClientPtr); -static int ProcXvGrabPort(ClientPtr); -static int ProcXvUngrabPort(ClientPtr); -static int ProcXvSelectVideoNotify(ClientPtr); -static int ProcXvSelectPortNotify(ClientPtr); -static int ProcXvStopVideo(ClientPtr); -static int ProcXvSetPortAttribute(ClientPtr); -static int ProcXvGetPortAttribute(ClientPtr); -static int ProcXvQueryBestSize(ClientPtr); -static int ProcXvQueryPortAttributes(ClientPtr); -static int ProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int ProcXvShmPutImage(ClientPtr); -#endif -static int ProcXvQueryImageAttributes(ClientPtr); -static int ProcXvListImageFormats(ClientPtr); - -static int SProcXvQueryExtension(ClientPtr); -static int SProcXvQueryAdaptors(ClientPtr); -static int SProcXvQueryEncodings(ClientPtr); -static int SProcXvPutVideo(ClientPtr); -static int SProcXvPutStill(ClientPtr); -static int SProcXvGetVideo(ClientPtr); -static int SProcXvGetStill(ClientPtr); -static int SProcXvGrabPort(ClientPtr); -static int SProcXvUngrabPort(ClientPtr); -static int SProcXvSelectVideoNotify(ClientPtr); -static int SProcXvSelectPortNotify(ClientPtr); -static int SProcXvStopVideo(ClientPtr); -static int SProcXvSetPortAttribute(ClientPtr); -static int SProcXvGetPortAttribute(ClientPtr); -static int SProcXvQueryBestSize(ClientPtr); -static int SProcXvQueryPortAttributes(ClientPtr); -static int SProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int SProcXvShmPutImage(ClientPtr); -#endif -static int SProcXvQueryImageAttributes(ClientPtr); -static int SProcXvListImageFormats(ClientPtr); - -static int SWriteQueryAdaptorsReply(ClientPtr, xvQueryAdaptorsReply *); -static int SWriteQueryExtensionReply(ClientPtr, xvQueryExtensionReply *); -static int SWriteQueryEncodingsReply(ClientPtr, xvQueryEncodingsReply *); -static int SWriteAdaptorInfo(ClientPtr, xvAdaptorInfo *); -static int SWriteEncodingInfo(ClientPtr, xvEncodingInfo *); -static int SWriteFormat(ClientPtr, xvFormat *); -static int SWriteAttributeInfo(ClientPtr, xvAttributeInfo *); -static int SWriteGrabPortReply(ClientPtr, xvGrabPortReply *); -static int SWriteGetPortAttributeReply(ClientPtr, xvGetPortAttributeReply *); -static int SWriteQueryBestSizeReply(ClientPtr, xvQueryBestSizeReply *); -static int SWriteQueryPortAttributesReply( - ClientPtr, xvQueryPortAttributesReply *); -static int SWriteQueryImageAttributesReply( - ClientPtr, xvQueryImageAttributesReply*); -static int SWriteListImageFormatsReply(ClientPtr, xvListImageFormatsReply*); -static int SWriteImageFormatInfo(ClientPtr, xvImageFormatInfo*); - -#define _WriteQueryAdaptorsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryAdaptorsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryAdaptorsReply, (char*)_d) - -#define _WriteQueryExtensionReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryExtensionReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryExtensionReply, (char*)_d) - -#define _WriteQueryEncodingsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryEncodingsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryEncodingsReply, (char*)_d) - -#define _WriteAdaptorInfo(_c,_d) \ - if ((_c)->swapped) SWriteAdaptorInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAdaptorInfo, (char*)_d) - -#define _WriteAttributeInfo(_c,_d) \ - if ((_c)->swapped) SWriteAttributeInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAttributeInfo, (char*)_d) - -#define _WriteEncodingInfo(_c,_d) \ - if ((_c)->swapped) SWriteEncodingInfo(_c, _d); \ - else WriteToClient(_c, sz_xvEncodingInfo, (char*)_d) - -#define _WriteFormat(_c,_d) \ - if ((_c)->swapped) SWriteFormat(_c, _d); \ - else WriteToClient(_c, sz_xvFormat, (char*)_d) - -#define _WriteGrabPortReply(_c,_d) \ - if ((_c)->swapped) SWriteGrabPortReply(_c, _d); \ - else WriteToClient(_c, sz_xvGrabPortReply, (char*)_d) - -#define _WriteGetPortAttributeReply(_c,_d) \ - if ((_c)->swapped) SWriteGetPortAttributeReply(_c, _d); \ - else WriteToClient(_c, sz_xvGetPortAttributeReply, (char*)_d) - -#define _WriteQueryBestSizeReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryBestSizeReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryBestSizeReply,(char*) _d) - -#define _WriteQueryPortAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryPortAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryPortAttributesReply,(char*) _d) - -#define _WriteQueryImageAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryImageAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryImageAttributesReply,(char*) _d) - -#define _WriteListImageFormatsReply(_c,_d) \ - if ((_c)->swapped) SWriteListImageFormatsReply(_c, _d); \ - else WriteToClient(_c, sz_xvListImageFormatsReply,(char*) _d) - -#define _WriteImageFormatInfo(_c,_d) \ - if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \ - else WriteToClient(_c, sz_xvImageFormatInfo, (char*)_d) - -#define _AllocatePort(_i,_p) \ - ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success - -/* -** ProcXvDispatch -** -** -** -*/ - -int -ProcXvDispatch(ClientPtr client) -{ - REQUEST(xReq); - - UpdateCurrentTime(); - - switch (stuff->data) - { - case xv_QueryExtension: return(ProcXvQueryExtension(client)); - case xv_QueryAdaptors: return(ProcXvQueryAdaptors(client)); - case xv_QueryEncodings: return(ProcXvQueryEncodings(client)); - case xv_PutVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvPutVideo(client)); - else -#endif - return(ProcXvPutVideo(client)); - case xv_PutStill: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvPutStill(client)); - else -#endif - return(ProcXvPutStill(client)); - case xv_GetVideo: return(ProcXvGetVideo(client)); - case xv_GetStill: return(ProcXvGetStill(client)); - case xv_GrabPort: return(ProcXvGrabPort(client)); - case xv_UngrabPort: return(ProcXvUngrabPort(client)); - case xv_SelectVideoNotify: return(ProcXvSelectVideoNotify(client)); - case xv_SelectPortNotify: return(ProcXvSelectPortNotify(client)); - case xv_StopVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvStopVideo(client)); - else -#endif - return(ProcXvStopVideo(client)); - case xv_SetPortAttribute: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvSetPortAttribute(client)); - else -#endif - return(ProcXvSetPortAttribute(client)); - case xv_GetPortAttribute: return(ProcXvGetPortAttribute(client)); - case xv_QueryBestSize: return(ProcXvQueryBestSize(client)); - case xv_QueryPortAttributes: return(ProcXvQueryPortAttributes(client)); - case xv_PutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvPutImage(client)); - else -#endif - return(ProcXvPutImage(client)); -#ifdef MITSHM - case xv_ShmPutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvShmPutImage(client)); - else -#endif - return(ProcXvShmPutImage(client)); -#endif - case xv_QueryImageAttributes: return(ProcXvQueryImageAttributes(client)); - case xv_ListImageFormats: return(ProcXvListImageFormats(client)); - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - return(BadImplementation); - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - return(BadRequest); - } - } -} - -int -SProcXvDispatch(ClientPtr client) -{ - REQUEST(xReq); - - UpdateCurrentTime(); - - switch (stuff->data) - { - case xv_QueryExtension: return(SProcXvQueryExtension(client)); - case xv_QueryAdaptors: return(SProcXvQueryAdaptors(client)); - case xv_QueryEncodings: return(SProcXvQueryEncodings(client)); - case xv_PutVideo: return(SProcXvPutVideo(client)); - case xv_PutStill: return(SProcXvPutStill(client)); - case xv_GetVideo: return(SProcXvGetVideo(client)); - case xv_GetStill: return(SProcXvGetStill(client)); - case xv_GrabPort: return(SProcXvGrabPort(client)); - case xv_UngrabPort: return(SProcXvUngrabPort(client)); - case xv_SelectVideoNotify: return(SProcXvSelectVideoNotify(client)); - case xv_SelectPortNotify: return(SProcXvSelectPortNotify(client)); - case xv_StopVideo: return(SProcXvStopVideo(client)); - case xv_SetPortAttribute: return(SProcXvSetPortAttribute(client)); - case xv_GetPortAttribute: return(SProcXvGetPortAttribute(client)); - case xv_QueryBestSize: return(SProcXvQueryBestSize(client)); - case xv_QueryPortAttributes: return(SProcXvQueryPortAttributes(client)); - case xv_PutImage: return(SProcXvPutImage(client)); -#ifdef MITSHM - case xv_ShmPutImage: return(SProcXvShmPutImage(client)); -#endif - case xv_QueryImageAttributes: return(SProcXvQueryImageAttributes(client)); - case xv_ListImageFormats: return(SProcXvListImageFormats(client)); - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - return(BadImplementation); - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - return(BadRequest); - } - } -} - -static int -ProcXvQueryExtension(ClientPtr client) -{ - xvQueryExtensionReply rep; - /* REQUEST(xvQueryExtensionReq); */ - REQUEST_SIZE_MATCH(xvQueryExtensionReq); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.version = XvVersion; - rep.revision = XvRevision; - - _WriteQueryExtensionReply(client, &rep); - - return Success; - -} - -static int -ProcXvQueryAdaptors(ClientPtr client) -{ - xvFormat format; - xvAdaptorInfo ainfo; - xvQueryAdaptorsReply rep; - int totalSize; - int na; - XvAdaptorPtr pa; - int nf; - XvFormatPtr pf; - WindowPtr pWin; - ScreenPtr pScreen; - XvScreenPtr pxvs; - - REQUEST(xvQueryAdaptorsReq); - REQUEST_SIZE_MATCH(xvQueryAdaptorsReq); - - if(!(pWin = (WindowPtr)LookupWindow(stuff->window, client) )) - { - client->errorValue = stuff->window; - return (BadWindow); - } - - pScreen = pWin->drawable.pScreen; - pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - if (!pxvs) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = 0; - rep.length = 0; - - _WriteQueryAdaptorsReply(client, &rep); - - return Success; - } - - (* pxvs->ddQueryAdaptors)(pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = pxvs->nAdaptors; - - /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ - - totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; - - /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - totalSize += (strlen(pa->name) + 3) & ~3; - totalSize += pa->nFormats * sz_xvFormat; - pa++; - } - - rep.length = totalSize >> 2; - - _WriteQueryAdaptorsReply(client, &rep); - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - - ainfo.base_id = pa->base_id; - ainfo.num_ports = pa->nPorts; - ainfo.type = pa->type; - ainfo.name_size = strlen(pa->name); - ainfo.num_formats = pa->nFormats; - - _WriteAdaptorInfo(client, &ainfo); - - WriteToClient(client, ainfo.name_size, pa->name); - - nf = pa->nFormats; - pf = pa->pFormats; - while (nf--) - { - format.depth = pf->depth; - format.visual = pf->visual; - _WriteFormat(client, &format); - pf++; - } - - pa++; - - } - - return (client->noClientException); - -} - -static int -ProcXvQueryEncodings(ClientPtr client) -{ - xvEncodingInfo einfo; - xvQueryEncodingsReply rep; - int totalSize; - XvPortPtr pPort; - int ne; - XvEncodingPtr pe; - int status; - - REQUEST(xvQueryEncodingsReq); - REQUEST_SIZE_MATCH(xvQueryEncodingsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_encodings = pPort->pAdaptor->nEncodings; - - /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */ - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - totalSize = ne * sz_xvEncodingInfo; - while (ne--) - { - totalSize += (strlen(pe->name) + 3) & ~3; - pe++; - } - - rep.length = totalSize >> 2; - - _WriteQueryEncodingsReply(client, &rep); - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - while (ne--) - { - einfo.encoding = pe->id; - einfo.name_size = strlen(pe->name); - einfo.width = pe->width; - einfo.height = pe->height; - einfo.rate.numerator = pe->rate.numerator; - einfo.rate.denominator = pe->rate.denominator; - _WriteEncodingInfo(client, &einfo); - WriteToClient(client, einfo.name_size, pe->name); - pe++; - } - - return (client->noClientException); - -} - -static int -ProcXvPutVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutVideoReq); - REQUEST_SIZE_MATCH(xvPutVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvPutStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutStillReq); - REQUEST_SIZE_MATCH(xvPutStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetVideoReq); - REQUEST_SIZE_MATCH(xvGetVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetStillReq); - REQUEST_SIZE_MATCH(xvGetStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvSelectVideoNotify(ClientPtr client) -{ - register DrawablePtr pDraw; - REQUEST(xvSelectVideoNotifyReq); - REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq); - - if(!(pDraw = (DrawablePtr)LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadWindow); - } - - return XVCALL(diSelectVideoNotify)(client, pDraw, stuff->onoff); - -} - -static int -ProcXvSelectPortNotify(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSelectPortNotifyReq); - REQUEST_SIZE_MATCH(xvSelectPortNotifyReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diSelectPortNotify)(client, pPort, stuff->onoff); - -} - -static int -ProcXvGrabPort(ClientPtr client) -{ - int result, status; - XvPortPtr pPort; - xvGrabPortReply rep; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - status = XVCALL(diGrabPort)(client, pPort, stuff->time, &result); - - if (status != Success) - { - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.result = result; - - _WriteGrabPortReply(client, &rep); - - return Success; - -} - -static int -ProcXvUngrabPort(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diUngrabPort)(client, pPort, stuff->time); - -} - - -static int -ProcXvStopVideo(ClientPtr client) -{ - int status; - register DrawablePtr pDraw; - XvPortPtr pPort; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if(!(pDraw = LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadDrawable); - } - - return XVCALL(diStopVideo)(client, pPort, pDraw); - -} - -static int -ProcXvSetPortAttribute(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSetPortAttributeReq); - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diSetPortAttribute)(client, pPort, - stuff->attribute, stuff->value); - - if (status == BadMatch) - client->errorValue = stuff->attribute; - else - client->errorValue = stuff->value; - - return status; -} - -static int -ProcXvGetPortAttribute(ClientPtr client) -{ - INT32 value; - int status; - XvPortPtr pPort; - xvGetPortAttributeReply rep; - REQUEST(xvGetPortAttributeReq); - REQUEST_SIZE_MATCH(xvGetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diGetPortAttribute)(client, pPort, stuff->attribute, &value); - if (status != Success) - { - client->errorValue = stuff->attribute; - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.value = value; - - _WriteGetPortAttributeReply(client, &rep); - - return Success; -} - -static int -ProcXvQueryBestSize(ClientPtr client) -{ - int status; - unsigned int actual_width, actual_height; - XvPortPtr pPort; - xvQueryBestSizeReply rep; - REQUEST(xvQueryBestSizeReq); - REQUEST_SIZE_MATCH(xvQueryBestSizeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - - (* pPort->pAdaptor->ddQueryBestSize)(client, pPort, stuff->motion, - stuff->vid_w, stuff->vid_h, - stuff->drw_w, stuff->drw_h, - &actual_width, &actual_height); - - rep.actual_width = actual_width; - rep.actual_height = actual_height; - - _WriteQueryBestSizeReply(client, &rep); - - return Success; -} - - -static int -ProcXvQueryPortAttributes(ClientPtr client) -{ - int status, size, i; - XvPortPtr pPort; - XvAttributePtr pAtt; - xvQueryPortAttributesReply rep; - xvAttributeInfo Info; - REQUEST(xvQueryPortAttributesReq); - REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_attributes = pPort->pAdaptor->nAttributes; - rep.text_size = 0; - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L; - } - - rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size; - rep.length >>= 2; - - _WriteQueryPortAttributesReply(client, &rep); - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - size = strlen(pAtt->name) + 1; /* pass the NULL */ - Info.flags = pAtt->flags; - Info.min = pAtt->min_value; - Info.max = pAtt->max_value; - Info.size = (size + 3) & ~3L; - - _WriteAttributeInfo(client, &Info); - - WriteToClient(client, size, pAtt->name); - } - - return Success; -} - - - -static int -ProcXvPutImage(ClientPtr client) -{ - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, i, size; - CARD16 width, height; - - REQUEST(xvPutImageReq); - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - width = stuff->width; - height = stuff->height; - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - size += sizeof(xvPutImageReq); - size = (size + 3) >> 2; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - if(client->req_len < size) - return BadLength; - - return XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, - pImage, (unsigned char*)(&stuff[1]), FALSE, - stuff->width, stuff->height); -} - -#ifdef MITSHM -/* redefined here since it's not in any header file */ -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -extern RESTYPE ShmSegType; -extern int BadShmSegCode; -extern int ShmCompletionCode; - -static int -ProcXvShmPutImage(ClientPtr client) -{ - ShmDescPtr shmdesc; - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, size_needed, i; - CARD16 width, height; - - REQUEST(xvShmPutImageReq); - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - if(!(shmdesc = (ShmDescPtr)LookupIDByType(stuff->shmseg, ShmSegType))) - { - client->errorValue = stuff->shmseg; - return BadShmSegCode; - } - - width = stuff->width; - height = stuff->height; - size_needed = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - if((size_needed + stuff->offset) > shmdesc->size) - return BadAccess; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - status = XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, pImage, - (unsigned char *)shmdesc->addr + stuff->offset, - stuff->send_event, stuff->width, stuff->height); - - if((status == Success) && stuff->send_event) { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = xv_ShmPutImage; - ev.majorEvent = XvReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return status; -} -#endif - -#ifdef XvMCExtension -XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id); -#endif - -static int -ProcXvQueryImageAttributes(ClientPtr client) -{ - xvQueryImageAttributesReply rep; - int size, num_planes, i; - CARD16 width, height; - XvImagePtr pImage = NULL; - XvPortPtr pPort; - int *offsets; - int *pitches; - REQUEST(xvQueryImageAttributesReq); - - REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - -#ifdef XvMCExtension - if(!pImage) - pImage = XvMCFindXvImage(pPort, stuff->id); -#endif - - if(!pImage) - return BadMatch; - - num_planes = pImage->num_planes; - - if(!(offsets = xalloc(num_planes << 3))) - return BadAlloc; - pitches = offsets + num_planes; - - width = stuff->width; - height = stuff->height; - - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, pPort, pImage, - &width, &height, offsets, pitches); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = num_planes << 1; - rep.num_planes = num_planes; - rep.width = width; - rep.height = height; - rep.data_size = size; - - _WriteQueryImageAttributesReply(client, &rep); - if(client->swapped) - SwapLongs((CARD32*)offsets, rep.length); - WriteToClient(client, rep.length << 2, (char*)offsets); - - xfree(offsets); - - return Success; -} - -static int -ProcXvListImageFormats(ClientPtr client) -{ - XvPortPtr pPort; - XvImagePtr pImage; - int i; - xvListImageFormatsReply rep; - xvImageFormatInfo info; - REQUEST(xvListImageFormatsReq); - - REQUEST_SIZE_MATCH(xvListImageFormatsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_formats = pPort->pAdaptor->nImages; - rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2; - - _WriteListImageFormatsReply(client, &rep); - - pImage = pPort->pAdaptor->pImages; - - for(i = 0; i < rep.num_formats; i++, pImage++) { - info.id = pImage->id; - info.type = pImage->type; - info.byte_order = pImage->byte_order; - memcpy(&info.guid, pImage->guid, 16); - info.bpp = pImage->bits_per_pixel; - info.num_planes = pImage->num_planes; - info.depth = pImage->depth; - info.red_mask = pImage->red_mask; - info.green_mask = pImage->green_mask; - info.blue_mask = pImage->blue_mask; - info.format = pImage->format; - info.y_sample_bits = pImage->y_sample_bits; - info.u_sample_bits = pImage->u_sample_bits; - info.v_sample_bits = pImage->v_sample_bits; - info.horz_y_period = pImage->horz_y_period; - info.horz_u_period = pImage->horz_u_period; - info.horz_v_period = pImage->horz_v_period; - info.vert_y_period = pImage->vert_y_period; - info.vert_u_period = pImage->vert_u_period; - info.vert_v_period = pImage->vert_v_period; - memcpy(&info.comp_order, pImage->component_order, 32); - info.scanline_order = pImage->scanline_order; - _WriteImageFormatInfo(client, &info); - } - - return Success; -} - - - -/* Swapped Procs */ - -static int -SProcXvQueryExtension(ClientPtr client) -{ - register char n; - REQUEST(xvQueryExtensionReq); - swaps(&stuff->length, n); - return ProcXvQueryExtension(client); -} - -static int -SProcXvQueryAdaptors(ClientPtr client) -{ - register char n; - REQUEST(xvQueryAdaptorsReq); - swaps(&stuff->length, n); - swapl(&stuff->window, n); - return ProcXvQueryAdaptors(client); -} - -static int -SProcXvQueryEncodings(ClientPtr client) -{ - register char n; - REQUEST(xvQueryEncodingsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryEncodings(client); -} - -static int -SProcXvGrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvGrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvGrabPort(client); -} - -static int -SProcXvUngrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvUngrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvUngrabPort(client); -} - -static int -SProcXvPutVideo(ClientPtr client) -{ - register char n; - REQUEST(xvPutVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutVideo(client); -} - -static int -SProcXvPutStill(ClientPtr client) -{ - register char n; - REQUEST(xvPutStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutStill(client); -} - -static int -SProcXvGetVideo(ClientPtr client) -{ - register char n; - REQUEST(xvGetVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetVideo(client); -} - -static int -SProcXvGetStill(ClientPtr client) -{ - register char n; - REQUEST(xvGetStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetStill(client); -} - -static int -SProcXvPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvPutImage(client); -} - -#ifdef MITSHM -static int -SProcXvShmPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvShmPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->offset, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvShmPutImage(client); -} -#endif - - -static int -SProcXvSelectVideoNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectVideoNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return ProcXvSelectVideoNotify(client); -} - -static int -SProcXvSelectPortNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectPortNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvSelectPortNotify(client); -} - -static int -SProcXvStopVideo(ClientPtr client) -{ - register char n; - REQUEST(xvStopVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - return ProcXvStopVideo(client); -} - -static int -SProcXvSetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvSetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvSetPortAttribute(client); -} - -static int -SProcXvGetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvGetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvGetPortAttribute(client); -} - -static int -SProcXvQueryBestSize(ClientPtr client) -{ - register char n; - REQUEST(xvQueryBestSizeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvQueryBestSize(client); -} - -static int -SProcXvQueryPortAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryPortAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryPortAttributes(client); -} - -static int -SProcXvQueryImageAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryImageAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->id, n); - swaps(&stuff->width, n); - swaps(&stuff->width, n); - return ProcXvQueryImageAttributes(client); -} - -static int -SProcXvListImageFormats(ClientPtr client) -{ - register char n; - REQUEST(xvListImageFormatsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvListImageFormats(client); -} - - -static int -SWriteQueryExtensionReply( - ClientPtr client, - xvQueryExtensionReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->version, n); - swaps(&rep->revision, n); - - (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryAdaptorsReply( - ClientPtr client, - xvQueryAdaptorsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_adaptors, n); - - (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryEncodingsReply( - ClientPtr client, - xvQueryEncodingsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_encodings, n); - - (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep); - - return Success; -} - -static int -SWriteAdaptorInfo( - ClientPtr client, - xvAdaptorInfo *pAdaptor -){ - register char n; - - swapl(&pAdaptor->base_id, n); - swaps(&pAdaptor->name_size, n); - swaps(&pAdaptor->num_ports, n); - swaps(&pAdaptor->num_formats, n); - - (void)WriteToClient(client, sz_xvAdaptorInfo, (char *)pAdaptor); - - return Success; -} - -static int -SWriteEncodingInfo( - ClientPtr client, - xvEncodingInfo *pEncoding -){ - register char n; - - swapl(&pEncoding->encoding, n); - swaps(&pEncoding->name_size, n); - swaps(&pEncoding->width, n); - swaps(&pEncoding->height, n); - swapl(&pEncoding->rate.numerator, n); - swapl(&pEncoding->rate.denominator, n); - (void)WriteToClient(client, sz_xvEncodingInfo, (char *)pEncoding); - - return Success; -} - -static int -SWriteFormat( - ClientPtr client, - xvFormat *pFormat -){ - register char n; - - swapl(&pFormat->visual, n); - (void)WriteToClient(client, sz_xvFormat, (char *)pFormat); - - return Success; -} - -static int -SWriteAttributeInfo( - ClientPtr client, - xvAttributeInfo *pAtt -){ - register char n; - - swapl(&pAtt->flags, n); - swapl(&pAtt->size, n); - swapl(&pAtt->min, n); - swapl(&pAtt->max, n); - (void)WriteToClient(client, sz_xvAttributeInfo, (char *)pAtt); - - return Success; -} - -static int -SWriteImageFormatInfo( - ClientPtr client, - xvImageFormatInfo *pImage -){ - register char n; - - swapl(&pImage->id, n); - swapl(&pImage->red_mask, n); - swapl(&pImage->green_mask, n); - swapl(&pImage->blue_mask, n); - swapl(&pImage->y_sample_bits, n); - swapl(&pImage->u_sample_bits, n); - swapl(&pImage->v_sample_bits, n); - swapl(&pImage->horz_y_period, n); - swapl(&pImage->horz_u_period, n); - swapl(&pImage->horz_v_period, n); - swapl(&pImage->vert_y_period, n); - swapl(&pImage->vert_u_period, n); - swapl(&pImage->vert_v_period, n); - - (void)WriteToClient(client, sz_xvImageFormatInfo, (char *)pImage); - - return Success; -} - - - -static int -SWriteGrabPortReply( - ClientPtr client, - xvGrabPortReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - - (void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep); - - return Success; -} - -static int -SWriteGetPortAttributeReply( - ClientPtr client, - xvGetPortAttributeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->value, n); - - (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryBestSizeReply( - ClientPtr client, - xvQueryBestSizeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->actual_width, n); - swaps(&rep->actual_height, n); - - (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryPortAttributesReply( - ClientPtr client, - xvQueryPortAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_attributes, n); - swapl(&rep->text_size, n); - - (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryImageAttributesReply( - ClientPtr client, - xvQueryImageAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_planes, n); - swapl(&rep->data_size, n); - swaps(&rep->width, n); - swaps(&rep->height, n); - - (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep); - - return Success; -} - - -static int -SWriteListImageFormatsReply( - ClientPtr client, - xvListImageFormatsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_formats, n); - - (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep); - - return Success; -} - - -#ifdef PANORAMIX - - - - -static int -XineramaXvStopVideo(ClientPtr client) -{ - int result = Success, i; - PanoramiXRes *draw, *port; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - result = ProcXvStopVideo(client); - } - } - - return result; -} - -static int -XineramaXvSetPortAttribute(ClientPtr client) -{ - REQUEST(xvSetPortAttributeReq); - PanoramiXRes *port; - int result = Success, i; - - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->port = port->info[i].id; - result = ProcXvSetPortAttribute(client); - } - } - return result; -} - - -#ifdef MITSHM -static int -XineramaXvShmPutImage(ClientPtr client) -{ - REQUEST(xvShmPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool send_event = stuff->send_event; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - stuff->send_event = (send_event && !i) ? 1 : 0; - - result = ProcXvShmPutImage(client); - } - } - return result; -} -#endif - -static int -XineramaXvPutImage(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutImage(client); - } - } - return result; -} - -static int -XineramaXvPutVideo(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutVideo(client); - } - } - return result; -} - -static int -XineramaXvPutStill(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && - (stuff->drawable == WindowTable[0]->drawable.id); - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutStill(client); - } - } - return result; -} - - -void XineramifyXv(void) -{ - ScreenPtr pScreen, screen0 = screenInfo.screens[0]; - XvScreenPtr xvsp0 = (XvScreenPtr)screen0->devPrivates[XvScreenIndex].ptr; - XvAdaptorPtr refAdapt, pAdapt; - XvAttributePtr pAttr; - XvScreenPtr xvsp; - Bool isOverlay, hasOverlay; - PanoramiXRes *port; - XvAdaptorPtr MatchingAdaptors[MAXSCREENS]; - int i, j, k, l; - - XvXRTPort = CreateNewResourceType(XineramaDeleteResource); - - if(!xvsp0) return; - - for(i = 0; i < xvsp0->nAdaptors; i++) { - refAdapt = xvsp0->pAdaptors + i; - - bzero(MatchingAdaptors, sizeof(XvAdaptorPtr) * MAXSCREENS); - - MatchingAdaptors[0] = refAdapt; - - if(!(refAdapt->type & XvInputMask)) continue; - - isOverlay = FALSE; - for(j = 0; j < refAdapt->nAttributes; j++) { - pAttr = refAdapt->pAttributes + j; - if(!strcmp(pAttr->name, "XV_COLORKEY")) { - isOverlay = TRUE; - break; - } - } - - for(j = 1; j < PanoramiXNumScreens; j++) { - pScreen = screenInfo.screens[j]; - xvsp = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - /* Do not try to go on if xv is not supported on this screen */ - if (xvsp==NULL) continue ; - - /* if the adaptor has the same name it's a perfect match */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if(!strcmp(refAdapt->name, pAdapt->name)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - if(MatchingAdaptors[j]) continue; /* found it */ - - /* otherwise we only look for XvImage adaptors */ - if(!(refAdapt->type & XvImageMask)) continue; - if(refAdapt->nImages <= 0) continue; - - /* prefer overlay/overlay non-overlay/non-overlay pairing */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - hasOverlay = FALSE; - for(l = 0; l < pAdapt->nAttributes; l++) { - if(!strcmp(pAdapt->name, "XV_COLORKEY")) { - hasOverlay = TRUE; - break; - } - } - if(isOverlay && hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - else if(!isOverlay && !hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - if(MatchingAdaptors[j]) continue; /* found it */ - - /* but we'll take any XvImage pairing if we can get it */ - - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - /* now create a resource for each port */ - for(j = 0; j < refAdapt->nPorts; j++) { - if(!(port = xalloc(sizeof(PanoramiXRes)))) - break; - port->info[0].id = MatchingAdaptors[0]->base_id + j; - AddResource(port->info[0].id, XvXRTPort, port); - - for(k = 1; k < PanoramiXNumScreens; k++) { - if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) - port->info[k].id = MatchingAdaptors[k]->base_id + j; - else - port->info[k].id = 0; - } - } - } -} - -#endif diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.NX.original deleted file mode 100644 index cf5d48ba2..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.NX.original +++ /dev/null @@ -1,2073 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $Id: damage.c,v 1.19 2005/10/06 21:55:41 anholt Exp $ - * - * Copyright © 2003 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include "dixfontstr.h" -#include -#include "mi.h" -#include "regionstr.h" -#include "globals.h" -#include "gcstruct.h" -#include "damage.h" -#include "damagestr.h" -#ifdef COMPOSITE -#include "cw.h" -#endif - -#define wrap(priv, real, mem, func) {\ - priv->mem = real->mem; \ - real->mem = func; \ -} - -#define unwrap(priv, real, mem) {\ - real->mem = priv->mem; \ -} - -#define BOX_SAME(a,b) \ - ((a)->x1 == (b)->x1 && \ - (a)->y1 == (b)->y1 && \ - (a)->x2 == (b)->x2 && \ - (a)->y2 == (b)->y2) - -#define DAMAGE_VALIDATE_ENABLE 0 -#define DAMAGE_DEBUG_ENABLE 0 -#if DAMAGE_DEBUG_ENABLE -#define DAMAGE_DEBUG(x) ErrorF x -#else -#define DAMAGE_DEBUG(x) -#endif - -#define getPixmapDamageRef(pPixmap) \ - ((DamagePtr *) &(pPixmap->devPrivates[damagePixPrivateIndex].ptr)) - -#define pixmapDamage(pPixmap) damagePixPriv(pPixmap) - -static DamagePtr * -getDrawableDamageRef (DrawablePtr pDrawable) -{ - PixmapPtr pPixmap; - - if (pDrawable->type == DRAWABLE_WINDOW) - { - ScreenPtr pScreen = pDrawable->pScreen; - - pPixmap = 0; - if (pScreen->GetWindowPixmap -#ifdef ROOTLESS_WORKAROUND - && ((WindowPtr)pDrawable)->viewable -#endif - ) - pPixmap = (*pScreen->GetWindowPixmap) ((WindowPtr)pDrawable); - - if (!pPixmap) - { - damageScrPriv(pScreen); - - return &pScrPriv->pScreenDamage; - } - } - else - pPixmap = (PixmapPtr) pDrawable; - return getPixmapDamageRef (pPixmap); -} - -#define getDrawableDamage(pDrawable) (*getDrawableDamageRef (pDrawable)) -#define getWindowDamage(pWin) getDrawableDamage(&(pWin)->drawable) - -#define drawableDamage(pDrawable) \ - DamagePtr pDamage = getDrawableDamage(pDrawable) - -#define windowDamage(pWin) drawableDamage(&(pWin)->drawable) - -#define winDamageRef(pWindow) \ - DamagePtr *pPrev = (DamagePtr *) \ - &(pWindow->devPrivates[damageWinPrivateIndex].ptr) - -#if DAMAGE_DEBUG_ENABLE -static void -_damageDamageRegion (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip, int subWindowMode, const char *where) -#define damageDamageRegion(d,r,c,m) _damageDamageRegion(d,r,c,m,__FUNCTION__) -#else -static void -damageDamageRegion (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip, - int subWindowMode) -#endif -{ - ScreenPtr pScreen = pDrawable->pScreen; - damageScrPriv(pScreen); - drawableDamage(pDrawable); - DamagePtr pNext; - RegionRec clippedRec; - RegionPtr pDamageRegion; - RegionRec pixClip; - Bool was_empty; - RegionRec tmpRegion; - BoxRec tmpBox; - int draw_x, draw_y; -#ifdef COMPOSITE - int screen_x = 0, screen_y = 0; -#endif - - /* short circuit for empty regions */ - if (!REGION_NOTEMPTY(pScreen, pRegion)) - return; - -#ifdef COMPOSITE - /* - * When drawing to a pixmap which is storing window contents, - * the region presented is in pixmap relative coordinates which - * need to be converted to screen relative coordinates - */ - if (pDrawable->type != DRAWABLE_WINDOW) - { - screen_x = ((PixmapPtr) pDrawable)->screen_x - pDrawable->x; - screen_y = ((PixmapPtr) pDrawable)->screen_y - pDrawable->y; - } - if (screen_x || screen_y) - REGION_TRANSLATE (pScreen, pRegion, screen_x, screen_y); -#endif - - if (pDrawable->type == DRAWABLE_WINDOW && - ((WindowPtr)(pDrawable))->backingStore == NotUseful) - { - if (subWindowMode == ClipByChildren) - { - REGION_INTERSECT(pScreen, pRegion, pRegion, - &((WindowPtr)(pDrawable))->clipList); - } - else if (subWindowMode == IncludeInferiors) - { - RegionPtr pTempRegion = - NotClippedByChildren((WindowPtr)(pDrawable)); - REGION_INTERSECT(pScreen, pRegion, pRegion, pTempRegion); - REGION_DESTROY(pScreen, pTempRegion); - } - /* If subWindowMode is set to an invalid value, don't perform - * any drawable-based clipping. */ - } - - - REGION_NULL (pScreen, &clippedRec); - for (; pDamage; pDamage = pNext) - { - pNext = pDamage->pNext; - /* - * Check for internal damage and don't send events - */ - if (pScrPriv->internalLevel > 0 && !pDamage->isInternal) - { - DAMAGE_DEBUG (("non internal damage, skipping at %d\n", - pScrPriv->internalLevel)); - continue; - } - /* - * Check for unrealized windows - */ - if (pDamage->pDrawable->type == DRAWABLE_WINDOW && - !((WindowPtr) (pDamage->pDrawable))->realized) - { -#if 0 - DAMAGE_DEBUG (("damage while window unrealized\n")); -#endif - continue; - } - - draw_x = pDamage->pDrawable->x; - draw_y = pDamage->pDrawable->y; -#ifdef COMPOSITE - /* - * Need to move everyone to screen coordinates - * XXX what about off-screen pixmaps with non-zero x/y? - */ - if (pDamage->pDrawable->type != DRAWABLE_WINDOW) - { - draw_x += ((PixmapPtr) pDamage->pDrawable)->screen_x; - draw_y += ((PixmapPtr) pDamage->pDrawable)->screen_y; - } -#endif - - /* - * Clip against border or pixmap bounds - */ - - pDamageRegion = pRegion; - if (clip || pDamage->pDrawable != pDrawable) - { - pDamageRegion = &clippedRec; - if (pDamage->pDrawable->type == DRAWABLE_WINDOW) { - REGION_INTERSECT (pScreen, pDamageRegion, pRegion, - &((WindowPtr)(pDamage->pDrawable))->borderClip); - } else { - BoxRec box; - box.x1 = draw_x; - box.y1 = draw_y; - box.x2 = draw_x + pDamage->pDrawable->width; - box.y2 = draw_y + pDamage->pDrawable->height; - REGION_INIT(pScreen, &pixClip, &box, 1); - REGION_INTERSECT (pScreen, pDamageRegion, pRegion, &pixClip); - REGION_UNINIT(pScreen, &pixClip); - } - /* - * Short circuit empty results - */ - if (!REGION_NOTEMPTY(pScreen, pDamageRegion)) - continue; - } - - DAMAGE_DEBUG (("%s %d x %d +%d +%d (target 0x%lx monitor 0x%lx)\n", - where, - pDamageRegion->extents.x2 - pDamageRegion->extents.x1, - pDamageRegion->extents.y2 - pDamageRegion->extents.y1, - pDamageRegion->extents.x1, pDamageRegion->extents.y1, - pDrawable->id, pDamage->pDrawable->id)); - - /* - * Move region to target coordinate space - */ - if (draw_x || draw_y) - REGION_TRANSLATE (pScreen, pDamageRegion, -draw_x, -draw_y); - - switch (pDamage->damageLevel) { - case DamageReportRawRegion: - (*pDamage->damageReport) (pDamage, pDamageRegion, pDamage->closure); - break; - case DamageReportDeltaRegion: - REGION_NULL (pScreen, &tmpRegion); - REGION_SUBTRACT (pScreen, &tmpRegion, pDamageRegion, &pDamage->damage); - if (REGION_NOTEMPTY (pScreen, &tmpRegion)) - { - REGION_UNION(pScreen, &pDamage->damage, - &pDamage->damage, pDamageRegion); - (*pDamage->damageReport) (pDamage, &tmpRegion, pDamage->closure); - } - REGION_UNINIT(pScreen, &tmpRegion); - break; - case DamageReportBoundingBox: - tmpBox = *REGION_EXTENTS (pScreen, &pDamage->damage); - REGION_UNION(pScreen, &pDamage->damage, - &pDamage->damage, pDamageRegion); - if (!BOX_SAME (&tmpBox, REGION_EXTENTS (pScreen, &pDamage->damage))) - (*pDamage->damageReport) (pDamage, &pDamage->damage, pDamage->closure); - break; - case DamageReportNonEmpty: - was_empty = !REGION_NOTEMPTY(pScreen, &pDamage->damage); - REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage, - pDamageRegion); - if (was_empty && REGION_NOTEMPTY(pScreen, &pDamage->damage)) - (*pDamage->damageReport) (pDamage, &pDamage->damage, pDamage->closure); - break; - case DamageReportNone: - REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage, - pDamageRegion); - break; - } - /* - * translate original region back - */ - if (pDamageRegion == pRegion && (draw_x || draw_y)) - REGION_TRANSLATE (pScreen, pDamageRegion, draw_x, draw_y); - } -#ifdef COMPOSITE - if (screen_x || screen_y) - REGION_TRANSLATE (pScreen, pRegion, -screen_x, -screen_y); -#endif - - REGION_UNINIT (pScreen, &clippedRec); -} - -#if DAMAGE_DEBUG_ENABLE -#define damageDamageBox(d,b,m) _damageDamageBox(d,b,m,__FUNCTION__) -static void -_damageDamageBox (DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode, const char *where) -#else -static void -damageDamageBox (DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode) -#endif -{ - RegionRec region; - - REGION_INIT (pDrawable->pScreen, ®ion, pBox, 1); -#if DAMAGE_DEBUG_ENABLE - _damageDamageRegion (pDrawable, ®ion, TRUE, subWindowMode, where); -#else - damageDamageRegion (pDrawable, ®ion, TRUE, subWindowMode); -#endif - REGION_UNINIT (pDrawable->pScreen, ®ion); -} - -static void damageValidateGC(GCPtr, unsigned long, DrawablePtr); -static void damageChangeGC(GCPtr, unsigned long); -static void damageCopyGC(GCPtr, unsigned long, GCPtr); -static void damageDestroyGC(GCPtr); -static void damageChangeClip(GCPtr, int, pointer, int); -static void damageDestroyClip(GCPtr); -static void damageCopyClip(GCPtr, GCPtr); - -GCFuncs damageGCFuncs = { - damageValidateGC, damageChangeGC, damageCopyGC, damageDestroyGC, - damageChangeClip, damageDestroyClip, damageCopyClip -}; - -extern GCOps damageGCOps; - -static Bool -damageCreateGC(GCPtr pGC) -{ - ScreenPtr pScreen = pGC->pScreen; - damageScrPriv(pScreen); - damageGCPriv(pGC); - Bool ret; - - pGC->pCompositeClip = 0; - unwrap (pScrPriv, pScreen, CreateGC); - if((ret = (*pScreen->CreateGC) (pGC))) { - pGCPriv->ops = NULL; - pGCPriv->funcs = pGC->funcs; - pGC->funcs = &damageGCFuncs; - } - wrap (pScrPriv, pScreen, CreateGC, damageCreateGC); - - return ret; -} - -#ifdef NOTUSED -static void -damageWrapGC (GCPtr pGC) -{ - damageGCPriv(pGC); - - pGCPriv->ops = NULL; - pGCPriv->funcs = pGC->funcs; - pGC->funcs = &damageGCFuncs; -} - -static void -damageUnwrapGC (GCPtr pGC) -{ - damageGCPriv(pGC); - - pGC->funcs = pGCPriv->funcs; - if (pGCPriv->ops) - pGC->ops = pGCPriv->ops; -} -#endif - -#define DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable) \ - damageGCPriv(pGC); \ - GCFuncs *oldFuncs = pGC->funcs; \ - unwrap(pGCPriv, pGC, funcs); \ - unwrap(pGCPriv, pGC, ops); \ - -#define DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable) \ - wrap(pGCPriv, pGC, funcs, oldFuncs); \ - wrap(pGCPriv, pGC, ops, &damageGCOps) - -#define DAMAGE_GC_FUNC_PROLOGUE(pGC) \ - damageGCPriv(pGC); \ - unwrap(pGCPriv, pGC, funcs); \ - if (pGCPriv->ops) unwrap(pGCPriv, pGC, ops) - -#define DAMAGE_GC_FUNC_EPILOGUE(pGC) \ - wrap(pGCPriv, pGC, funcs, &damageGCFuncs); \ - if (pGCPriv->ops) wrap(pGCPriv, pGC, ops, &damageGCOps) - -static void -damageValidateGC(GCPtr pGC, - unsigned long changes, - DrawablePtr pDrawable) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->ValidateGC)(pGC, changes, pDrawable); - pGCPriv->ops = pGC->ops; /* just so it's not NULL */ - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageDestroyGC(GCPtr pGC) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->DestroyGC)(pGC); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageChangeGC (GCPtr pGC, - unsigned long mask) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->ChangeGC) (pGC, mask); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageCopyGC (GCPtr pGCSrc, - unsigned long mask, - GCPtr pGCDst) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGCDst); - (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst); - DAMAGE_GC_FUNC_EPILOGUE (pGCDst); -} - -static void -damageChangeClip (GCPtr pGC, - int type, - pointer pvalue, - int nrects) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageCopyClip(GCPtr pgcDst, GCPtr pgcSrc) -{ - DAMAGE_GC_FUNC_PROLOGUE (pgcDst); - (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc); - DAMAGE_GC_FUNC_EPILOGUE (pgcDst); -} - -static void -damageDestroyClip(GCPtr pGC) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (* pGC->funcs->DestroyClip)(pGC); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -#define TRIM_BOX(box, pGC) if (pGC->pCompositeClip) { \ - BoxPtr extents = &pGC->pCompositeClip->extents;\ - if(box.x1 < extents->x1) box.x1 = extents->x1; \ - if(box.x2 > extents->x2) box.x2 = extents->x2; \ - if(box.y1 < extents->y1) box.y1 = extents->y1; \ - if(box.y2 > extents->y2) box.y2 = extents->y2; \ - } - -#define TRANSLATE_BOX(box, pDrawable) { \ - box.x1 += pDrawable->x; \ - box.x2 += pDrawable->x; \ - box.y1 += pDrawable->y; \ - box.y2 += pDrawable->y; \ - } - -#define TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC) { \ - TRANSLATE_BOX(box, pDrawable); \ - TRIM_BOX(box, pGC); \ - } - -#define BOX_NOT_EMPTY(box) \ - (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0)) - -#define checkGCDamage(d,g) (getDrawableDamage(d) && \ - (!g->pCompositeClip ||\ - REGION_NOTEMPTY(d->pScreen, \ - g->pCompositeClip))) - -#ifdef RENDER - -#define TRIM_PICTURE_BOX(box, pDst) { \ - BoxPtr extents = &pDst->pCompositeClip->extents;\ - if(box.x1 < extents->x1) box.x1 = extents->x1; \ - if(box.x2 > extents->x2) box.x2 = extents->x2; \ - if(box.y1 < extents->y1) box.y1 = extents->y1; \ - if(box.y2 > extents->y2) box.y2 = extents->y2; \ - } - -#define checkPictureDamage(p) (getDrawableDamage(p->pDrawable) && \ - REGION_NOTEMPTY(pScreen, p->pCompositeClip)) - -static void -damageComposite (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - damageScrPriv(pScreen); - - if (checkPictureDamage (pDst)) - { - BoxRec box; - - box.x1 = xDst + pDst->pDrawable->x; - box.y1 = yDst + pDst->pDrawable->y; - box.x2 = box.x1 + width; - box.y2 = box.y1 + height; - TRIM_PICTURE_BOX(box, pDst); - if (BOX_NOT_EMPTY(box)) - damageDamageBox (pDst->pDrawable, &box, pDst->subWindowMode); - } - unwrap (pScrPriv, ps, Composite); - (*ps->Composite) (op, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height); - wrap (pScrPriv, ps, Composite, damageComposite); -} - -static void -damageGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr list, - GlyphPtr *glyphs) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - damageScrPriv(pScreen); - - if (checkPictureDamage (pDst)) - { - int nlistTmp = nlist; - GlyphListPtr listTmp = list; - GlyphPtr *glyphsTmp = glyphs; - int x, y; - int n; - GlyphPtr glyph; - BoxRec box; - int x1, y1, x2, y2; - - box.x1 = 32767; - box.y1 = 32767; - box.x2 = -32767; - box.y2 = -32767; - x = pDst->pDrawable->x; - y = pDst->pDrawable->y; - while (nlistTmp--) - { - x += listTmp->xOff; - y += listTmp->yOff; - n = listTmp->len; - while (n--) - { - glyph = *glyphsTmp++; - x1 = x - glyph->info.x; - y1 = y - glyph->info.y; - x2 = x1 + glyph->info.width; - y2 = y1 + glyph->info.height; - if (x1 < box.x1) - box.x1 = x1; - if (y1 < box.y1) - box.y1 = y1; - if (x2 > box.x2) - box.x2 = x2; - if (y2 > box.y2) - box.y2 = y2; - x += glyph->info.xOff; - y += glyph->info.yOff; - } - listTmp++; - } - TRIM_PICTURE_BOX (box, pDst); - if (BOX_NOT_EMPTY(box)) - damageDamageBox (pDst->pDrawable, &box, pDst->subWindowMode); - } - unwrap (pScrPriv, ps, Glyphs); - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs); - wrap (pScrPriv, ps, Glyphs, damageGlyphs); -} -#endif - -/**********************************************************/ - - -static void -damageFillSpans(DrawablePtr pDrawable, - GC *pGC, - int npt, - DDXPointPtr ppt, - int *pwidth, - int fSorted) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - int nptTmp = npt; - DDXPointPtr pptTmp = ppt; - int *pwidthTmp = pwidth; - BoxRec box; - - box.x1 = pptTmp->x; - box.x2 = box.x1 + *pwidthTmp; - box.y2 = box.y1 = pptTmp->y; - - while(--nptTmp) - { - pptTmp++; - pwidthTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - if(box.x2 < (pptTmp->x + *pwidthTmp)) - box.x2 = pptTmp->x + *pwidthTmp; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - - box.y2++; - - if(!pGC->miTranslate) { - TRANSLATE_BOX(box, pDrawable); - } - TRIM_BOX(box, pGC); - - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - - (*pGC->ops->FillSpans)(pDrawable, pGC, npt, ppt, pwidth, fSorted); - - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageSetSpans(DrawablePtr pDrawable, - GCPtr pGC, - char *pcharsrc, - DDXPointPtr ppt, - int *pwidth, - int npt, - int fSorted) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - DDXPointPtr pptTmp = ppt; - int *pwidthTmp = pwidth; - int nptTmp = npt; - BoxRec box; - - box.x1 = pptTmp->x; - box.x2 = box.x1 + *pwidthTmp; - box.y2 = box.y1 = pptTmp->y; - - while(--nptTmp) - { - pptTmp++; - pwidthTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - if(box.x2 < (pptTmp->x + *pwidthTmp)) - box.x2 = pptTmp->x + *pwidthTmp; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - - box.y2++; - - if(!pGC->miTranslate) { - TRANSLATE_BOX(box, pDrawable); - } - TRIM_BOX(box, pGC); - - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->SetSpans)(pDrawable, pGC, pcharsrc, ppt, pwidth, npt, fSorted); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePutImage(DrawablePtr pDrawable, - GCPtr pGC, - int depth, - int x, - int y, - int w, - int h, - int leftPad, - int format, - char *pImage) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - if (checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - - box.x1 = x + pDrawable->x; - box.x2 = box.x1 + w; - box.y1 = y + pDrawable->y; - box.y2 = box.y1 + h; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PutImage)(pDrawable, pGC, depth, x, y, w, h, - leftPad, format, pImage); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static RegionPtr -damageCopyArea(DrawablePtr pSrc, - DrawablePtr pDst, - GC *pGC, - int srcx, - int srcy, - int width, - int height, - int dstx, - int dsty) -{ - RegionPtr ret; - DAMAGE_GC_OP_PROLOGUE(pGC, pDst); - - /* The driver will only call SourceValidate() when pSrc != pDst, - * but the software sprite (misprite.c) always need to know when a - * drawable is copied so it can remove the sprite. See #1030. */ - if ((pSrc == pDst) && pSrc->pScreen->SourceValidate && - pSrc->type == DRAWABLE_WINDOW && - ((WindowPtr)pSrc)->viewable) - { - (*pSrc->pScreen->SourceValidate) (pSrc, srcx, srcy, width, height); - } - - if (checkGCDamage (pDst, pGC)) - { - BoxRec box; - - box.x1 = dstx + pDst->x; - box.x2 = box.x1 + width; - box.y1 = dsty + pDst->y; - box.y2 = box.y1 + height; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDst, &box, pGC->subWindowMode); - } - - ret = (*pGC->ops->CopyArea)(pSrc, pDst, - pGC, srcx, srcy, width, height, dstx, dsty); - DAMAGE_GC_OP_EPILOGUE(pGC, pDst); - return ret; -} - -static RegionPtr -damageCopyPlane(DrawablePtr pSrc, - DrawablePtr pDst, - GCPtr pGC, - int srcx, - int srcy, - int width, - int height, - int dstx, - int dsty, - unsigned long bitPlane) -{ - RegionPtr ret; - DAMAGE_GC_OP_PROLOGUE(pGC, pDst); - - /* The driver will only call SourceValidate() when pSrc != pDst, - * but the software sprite (misprite.c) always need to know when a - * drawable is copied so it can remove the sprite. See #1030. */ - if ((pSrc == pDst) && pSrc->pScreen->SourceValidate && - pSrc->type == DRAWABLE_WINDOW && - ((WindowPtr)pSrc)->viewable) - { - (*pSrc->pScreen->SourceValidate) (pSrc, srcx, srcy, width, height); - } - - if (checkGCDamage (pDst, pGC)) - { - BoxRec box; - - box.x1 = dstx + pDst->x; - box.x2 = box.x1 + width; - box.y1 = dsty + pDst->y; - box.y2 = box.y1 + height; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDst, &box, pGC->subWindowMode); - } - - ret = (*pGC->ops->CopyPlane)(pSrc, pDst, - pGC, srcx, srcy, width, height, dstx, dsty, bitPlane); - DAMAGE_GC_OP_EPILOGUE(pGC, pDst); - return ret; -} - -static void -damagePolyPoint(DrawablePtr pDrawable, - GCPtr pGC, - int mode, - int npt, - xPoint *ppt) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int nptTmp = npt; - xPoint *pptTmp = ppt; - - box.x2 = box.x1 = pptTmp->x; - box.y2 = box.y1 = pptTmp->y; - - /* this could be slow if the points were spread out */ - - while(--nptTmp) - { - pptTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - else if(box.x2 < pptTmp->x) box.x2 = pptTmp->x; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - - box.x2++; - box.y2++; - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyPoint)(pDrawable, pGC, mode, npt, ppt); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolylines(DrawablePtr pDrawable, - GCPtr pGC, - int mode, - int npt, - DDXPointPtr ppt) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - int nptTmp = npt; - DDXPointPtr pptTmp = ppt; - BoxRec box; - int extra = pGC->lineWidth >> 1; - - box.x2 = box.x1 = pptTmp->x; - box.y2 = box.y1 = pptTmp->y; - - if(nptTmp > 1) - { - if(pGC->joinStyle == JoinMiter) - extra = 6 * pGC->lineWidth; - else if(pGC->capStyle == CapProjecting) - extra = pGC->lineWidth; - } - - if(mode == CoordModePrevious) - { - int x = box.x1; - int y = box.y1; - while(--nptTmp) - { - pptTmp++; - x += pptTmp->x; - y += pptTmp->y; - if(box.x1 > x) box.x1 = x; - else if(box.x2 < x) box.x2 = x; - if(box.y1 > y) box.y1 = y; - else if(box.y2 < y) box.y2 = y; - } - } - else - { - while(--nptTmp) - { - pptTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - else if(box.x2 < pptTmp->x) box.x2 = pptTmp->x; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - } - - box.x2++; - box.y2++; - - if(extra) - { - box.x1 -= extra; - box.x2 += extra; - box.y1 -= extra; - box.y2 += extra; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->Polylines)(pDrawable, pGC, mode, npt, ppt); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolySegment(DrawablePtr pDrawable, - GCPtr pGC, - int nSeg, - xSegment *pSeg) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nSeg && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int extra = pGC->lineWidth; - int nsegTmp = nSeg; - xSegment *pSegTmp = pSeg; - - if(pGC->capStyle != CapProjecting) - extra >>= 1; - - if(pSegTmp->x2 > pSegTmp->x1) { - box.x1 = pSegTmp->x1; - box.x2 = pSegTmp->x2; - } else { - box.x2 = pSegTmp->x1; - box.x1 = pSegTmp->x2; - } - - if(pSegTmp->y2 > pSegTmp->y1) { - box.y1 = pSegTmp->y1; - box.y2 = pSegTmp->y2; - } else { - box.y2 = pSegTmp->y1; - box.y1 = pSegTmp->y2; - } - - while(--nsegTmp) - { - pSegTmp++; - if(pSegTmp->x2 > pSegTmp->x1) - { - if(pSegTmp->x1 < box.x1) box.x1 = pSegTmp->x1; - if(pSegTmp->x2 > box.x2) box.x2 = pSegTmp->x2; - } - else - { - if(pSegTmp->x2 < box.x1) box.x1 = pSegTmp->x2; - if(pSegTmp->x1 > box.x2) box.x2 = pSegTmp->x1; - } - if(pSegTmp->y2 > pSegTmp->y1) - { - if(pSegTmp->y1 < box.y1) box.y1 = pSegTmp->y1; - if(pSegTmp->y2 > box.y2) box.y2 = pSegTmp->y2; - } - else - { - if(pSegTmp->y2 < box.y1) box.y1 = pSegTmp->y2; - if(pSegTmp->y1 > box.y2) box.y2 = pSegTmp->y1; - } - } - - box.x2++; - box.y2++; - - if(extra) - { - box.x1 -= extra; - box.x2 += extra; - box.y1 -= extra; - box.y2 += extra; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolySegment)(pDrawable, pGC, nSeg, pSeg); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolyRectangle(DrawablePtr pDrawable, - GCPtr pGC, - int nRects, - xRectangle *pRects) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nRects && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int offset1, offset2, offset3; - int nRectsTmp = nRects; - xRectangle *pRectsTmp = pRects; - - offset2 = pGC->lineWidth; - if(!offset2) offset2 = 1; - offset1 = offset2 >> 1; - offset3 = offset2 - offset1; - - while(nRectsTmp--) - { - box.x1 = pRectsTmp->x - offset1; - box.y1 = pRectsTmp->y - offset1; - box.x2 = box.x1 + pRectsTmp->width + offset2; - box.y2 = box.y1 + offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - box.x1 = pRectsTmp->x - offset1; - box.y1 = pRectsTmp->y + offset3; - box.x2 = box.x1 + offset2; - box.y2 = box.y1 + pRectsTmp->height - offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - box.x1 = pRectsTmp->x + pRectsTmp->width - offset1; - box.y1 = pRectsTmp->y + offset3; - box.x2 = box.x1 + offset2; - box.y2 = box.y1 + pRectsTmp->height - offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - box.x1 = pRectsTmp->x - offset1; - box.y1 = pRectsTmp->y + pRectsTmp->height - offset1; - box.x2 = box.x1 + pRectsTmp->width + offset2; - box.y2 = box.y1 + offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - pRectsTmp++; - } - } - (*pGC->ops->PolyRectangle)(pDrawable, pGC, nRects, pRects); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolyArc(DrawablePtr pDrawable, - GCPtr pGC, - int nArcs, - xArc *pArcs) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nArcs && checkGCDamage (pDrawable, pGC)) - { - int extra = pGC->lineWidth >> 1; - BoxRec box; - int nArcsTmp = nArcs; - xArc *pArcsTmp = pArcs; - - box.x1 = pArcsTmp->x; - box.x2 = box.x1 + pArcsTmp->width; - box.y1 = pArcsTmp->y; - box.y2 = box.y1 + pArcsTmp->height; - - while(--nArcsTmp) - { - pArcsTmp++; - if(box.x1 > pArcsTmp->x) - box.x1 = pArcsTmp->x; - if(box.x2 < (pArcsTmp->x + pArcsTmp->width)) - box.x2 = pArcsTmp->x + pArcsTmp->width; - if(box.y1 > pArcsTmp->y) - box.y1 = pArcsTmp->y; - if(box.y2 < (pArcsTmp->y + pArcsTmp->height)) - box.y2 = pArcsTmp->y + pArcsTmp->height; - } - - if(extra) - { - box.x1 -= extra; - box.x2 += extra; - box.y1 -= extra; - box.y2 += extra; - } - - box.x2++; - box.y2++; - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyArc)(pDrawable, pGC, nArcs, pArcs); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageFillPolygon(DrawablePtr pDrawable, - GCPtr pGC, - int shape, - int mode, - int npt, - DDXPointPtr ppt) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt > 2 && checkGCDamage (pDrawable, pGC)) - { - DDXPointPtr pptTmp = ppt; - int nptTmp = npt; - BoxRec box; - - box.x2 = box.x1 = pptTmp->x; - box.y2 = box.y1 = pptTmp->y; - - if(mode != CoordModeOrigin) - { - int x = box.x1; - int y = box.y1; - while(--nptTmp) - { - pptTmp++; - x += pptTmp->x; - y += pptTmp->y; - if(box.x1 > x) box.x1 = x; - else if(box.x2 < x) box.x2 = x; - if(box.y1 > y) box.y1 = y; - else if(box.y2 < y) box.y2 = y; - } - } - else - { - while(--nptTmp) - { - pptTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - else if(box.x2 < pptTmp->x) box.x2 = pptTmp->x; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - } - - box.x2++; - box.y2++; - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - - (*pGC->ops->FillPolygon)(pDrawable, pGC, shape, mode, npt, ppt); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - - -static void -damagePolyFillRect(DrawablePtr pDrawable, - GCPtr pGC, - int nRects, - xRectangle *pRects) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - if (nRects && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - xRectangle *pRectsTmp = pRects; - int nRectsTmp = nRects; - - box.x1 = pRectsTmp->x; - box.x2 = box.x1 + pRectsTmp->width; - box.y1 = pRectsTmp->y; - box.y2 = box.y1 + pRectsTmp->height; - - while(--nRectsTmp) - { - pRectsTmp++; - if(box.x1 > pRectsTmp->x) box.x1 = pRectsTmp->x; - if(box.x2 < (pRectsTmp->x + pRectsTmp->width)) - box.x2 = pRectsTmp->x + pRectsTmp->width; - if(box.y1 > pRectsTmp->y) box.y1 = pRectsTmp->y; - if(box.y2 < (pRectsTmp->y + pRectsTmp->height)) - box.y2 = pRectsTmp->y + pRectsTmp->height; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyFillRect)(pDrawable, pGC, nRects, pRects); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - - -static void -damagePolyFillArc(DrawablePtr pDrawable, - GCPtr pGC, - int nArcs, - xArc *pArcs) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nArcs && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int nArcsTmp = nArcs; - xArc *pArcsTmp = pArcs; - - box.x1 = pArcsTmp->x; - box.x2 = box.x1 + pArcsTmp->width; - box.y1 = pArcsTmp->y; - box.y2 = box.y1 + pArcsTmp->height; - - while(--nArcsTmp) - { - pArcsTmp++; - if(box.x1 > pArcsTmp->x) - box.x1 = pArcsTmp->x; - if(box.x2 < (pArcsTmp->x + pArcsTmp->width)) - box.x2 = pArcsTmp->x + pArcsTmp->width; - if(box.y1 > pArcsTmp->y) - box.y1 = pArcsTmp->y; - if(box.y2 < (pArcsTmp->y + pArcsTmp->height)) - box.y2 = pArcsTmp->y + pArcsTmp->height; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyFillArc)(pDrawable, pGC, nArcs, pArcs); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -/* - * general Poly/Image text function. Extract glyph information, - * compute bounding box and remove cursor if it is overlapped. - */ - -static void -damageDamageChars (DrawablePtr pDrawable, - FontPtr font, - int x, - int y, - unsigned int n, - CharInfoPtr *charinfo, - Bool imageblt, - int subWindowMode) -{ - ExtentInfoRec extents; - BoxRec box; - - QueryGlyphExtents(font, charinfo, n, &extents); - if (imageblt) - { - if (extents.overallWidth > extents.overallRight) - extents.overallRight = extents.overallWidth; - if (extents.overallWidth < extents.overallLeft) - extents.overallLeft = extents.overallWidth; - if (extents.overallLeft > 0) - extents.overallLeft = 0; - if (extents.fontAscent > extents.overallAscent) - extents.overallAscent = extents.fontAscent; - if (extents.fontDescent > extents.overallDescent) - extents.overallDescent = extents.fontDescent; - } - box.x1 = x + extents.overallLeft; - box.y1 = y - extents.overallAscent; - box.x2 = x + extents.overallRight; - box.y2 = y + extents.overallDescent; - damageDamageBox (pDrawable, &box, subWindowMode); -} - -/* - * values for textType: - */ -#define TT_POLY8 0 -#define TT_IMAGE8 1 -#define TT_POLY16 2 -#define TT_IMAGE16 3 - -static int -damageText (DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - unsigned long count, - char *chars, - FontEncoding fontEncoding, - Bool textType) -{ - CharInfoPtr *charinfo; - CharInfoPtr *info; - unsigned long i; - unsigned int n; - int w; - Bool imageblt; - - imageblt = (textType == TT_IMAGE8) || (textType == TT_IMAGE16); - - charinfo = (CharInfoPtr *) ALLOCATE_LOCAL(count * sizeof(CharInfoPtr)); - if (!charinfo) - return x; - - GetGlyphs(pGC->font, count, (unsigned char *)chars, - fontEncoding, &i, charinfo); - n = (unsigned int)i; - w = 0; - if (!imageblt) - for (info = charinfo; i--; info++) - w += (*info)->metrics.characterWidth; - - if (n != 0) { - damageDamageChars (pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, n, - charinfo, imageblt, pGC->subWindowMode); - -#ifndef NXAGENT_SERVER - - if (imageblt) - (*pGC->ops->ImageGlyphBlt)(pDrawable, pGC, x, y, n, charinfo, - FONTGLYPHS(pGC->font)); - else - (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, n, charinfo, - FONTGLYPHS(pGC->font)); -#endif - - } - DEALLOCATE_LOCAL(charinfo); - return x + w; -} - -#ifndef NXAGENT_SERVER - -static int -damagePolyText8(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - char *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - x = damageText (pDrawable, pGC, x, y, (unsigned long) count, chars, - Linear8Bit, TT_POLY8); - else - x = (*pGC->ops->PolyText8)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); - return x; -} - -static int -damagePolyText16(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - x = damageText (pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, - FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, - TT_POLY16); - else - x = (*pGC->ops->PolyText16)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); - return x; -} - -static void -damageImageText8(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - char *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, chars, - Linear8Bit, TT_IMAGE8); - else - (*pGC->ops->ImageText8)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageImageText16(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, - FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, - TT_IMAGE16); - else - (*pGC->ops->ImageText16)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -#else /* #ifndef NXAGENT_SERVER */ - -static int -damagePolyText8(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - char *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, chars, - Linear8Bit, TT_POLY8); - - x = (*pGC->ops->PolyText8)(pDrawable, pGC, x, y, count, chars); - - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); - return x; -} - -static int -damagePolyText16(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, - FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, - TT_POLY16); - - x = (*pGC->ops->PolyText16)(pDrawable, pGC, x, y, count, chars); - - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); - return x; -} - -static void -damageImageText8(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - char *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, chars, - Linear8Bit, TT_IMAGE8); - - (*pGC->ops->ImageText8)(pDrawable, pGC, x, y, count, chars); - - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageImageText16(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, - FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, - TT_IMAGE16); - - (*pGC->ops->ImageText16)(pDrawable, pGC, x, y, count, chars); - - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -#endif /* #ifndef NXAGENT_SERVER */ - -static void -damageImageGlyphBlt(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - unsigned int nglyph, - CharInfoPtr *ppci, - pointer pglyphBase) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - damageDamageChars (pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, - nglyph, ppci, TRUE, pGC->subWindowMode); - (*pGC->ops->ImageGlyphBlt)(pDrawable, pGC, x, y, nglyph, - ppci, pglyphBase); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolyGlyphBlt(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - unsigned int nglyph, - CharInfoPtr *ppci, - pointer pglyphBase) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - damageDamageChars (pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, - nglyph, ppci, FALSE, pGC->subWindowMode); - (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, - ppci, pglyphBase); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePushPixels(GCPtr pGC, - PixmapPtr pBitMap, - DrawablePtr pDrawable, - int dx, - int dy, - int xOrg, - int yOrg) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - if(checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - - box.x1 = xOrg; - box.y1 = yOrg; - - if(!pGC->miTranslate) { - box.x1 += pDrawable->x; - box.y1 += pDrawable->y; - } - - box.x2 = box.x1 + dx; - box.y2 = box.y1 + dy; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PushPixels)(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageRemoveDamage (DamagePtr *pPrev, DamagePtr pDamage) -{ - while (*pPrev) - { - if (*pPrev == pDamage) - { - *pPrev = pDamage->pNext; - return; - } - pPrev = &(*pPrev)->pNext; - } -#if DAMAGE_VALIDATE_ENABLE - ErrorF ("Damage not on list\n"); - abort (); -#endif -} - -static void -damageInsertDamage (DamagePtr *pPrev, DamagePtr pDamage) -{ -#if DAMAGE_VALIDATE_ENABLE - DamagePtr pOld; - - for (pOld = *pPrev; pOld; pOld = pOld->pNext) - if (pOld == pDamage) { - ErrorF ("Damage already on list\n"); - abort (); - } -#endif - pDamage->pNext = *pPrev; - *pPrev = pDamage; -} - -static Bool -damageDestroyPixmap (PixmapPtr pPixmap) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - damageScrPriv(pScreen); - - if (pPixmap->refcnt == 1) - { - DamagePtr *pPrev = getPixmapDamageRef (pPixmap); - DamagePtr pDamage; - - while ((pDamage = *pPrev)) - { - damageRemoveDamage (pPrev, pDamage); - if (!pDamage->isWindow) - DamageDestroy (pDamage); - } - } - unwrap (pScrPriv, pScreen, DestroyPixmap); - (*pScreen->DestroyPixmap) (pPixmap); - wrap (pScrPriv, pScreen, DestroyPixmap, damageDestroyPixmap); - return TRUE; -} - -static void -damagePaintWindow(WindowPtr pWindow, - RegionPtr prgn, - int what) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - /* - * Painting background none doesn't actually *do* anything, so - * no damage is recorded - */ - if ((what != PW_BACKGROUND || pWindow->backgroundState != None) && - getWindowDamage (pWindow)) - damageDamageRegion (&pWindow->drawable, prgn, FALSE, -1); - if(what == PW_BACKGROUND) { - unwrap (pScrPriv, pScreen, PaintWindowBackground); - (*pScreen->PaintWindowBackground) (pWindow, prgn, what); - wrap (pScrPriv, pScreen, PaintWindowBackground, damagePaintWindow); - } else { - unwrap (pScrPriv, pScreen, PaintWindowBorder); - (*pScreen->PaintWindowBorder) (pWindow, prgn, what); - wrap (pScrPriv, pScreen, PaintWindowBorder, damagePaintWindow); - } -} - - -static void -damageCopyWindow(WindowPtr pWindow, - DDXPointRec ptOldOrg, - RegionPtr prgnSrc) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - if (getWindowDamage (pWindow)) - { - int dx = pWindow->drawable.x - ptOldOrg.x; - int dy = pWindow->drawable.y - ptOldOrg.y; - - /* - * The region comes in source relative, but the damage occurs - * at the destination location. Translate back and forth. - */ - REGION_TRANSLATE (pScreen, prgnSrc, dx, dy); - damageDamageRegion (&pWindow->drawable, prgnSrc, FALSE, -1); - REGION_TRANSLATE (pScreen, prgnSrc, -dx, -dy); - } - unwrap (pScrPriv, pScreen, CopyWindow); - (*pScreen->CopyWindow) (pWindow, ptOldOrg, prgnSrc); - wrap (pScrPriv, pScreen, CopyWindow, damageCopyWindow); -} - -GCOps damageGCOps = { - damageFillSpans, damageSetSpans, - damagePutImage, damageCopyArea, - damageCopyPlane, damagePolyPoint, - damagePolylines, damagePolySegment, - damagePolyRectangle, damagePolyArc, - damageFillPolygon, damagePolyFillRect, - damagePolyFillArc, damagePolyText8, - damagePolyText16, damageImageText8, - damageImageText16, damageImageGlyphBlt, - damagePolyGlyphBlt, damagePushPixels, -#ifdef NEED_LINEHELPER - NULL, -#endif - {NULL} /* devPrivate */ -}; - -static void -damageRestoreAreas (PixmapPtr pPixmap, - RegionPtr prgn, - int xorg, - int yorg, - WindowPtr pWindow) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - damageDamageRegion (&pWindow->drawable, prgn, FALSE, -1); - unwrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas); - (*pScreen->BackingStoreFuncs.RestoreAreas) (pPixmap, prgn, - xorg, yorg, pWindow); - wrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas, - damageRestoreAreas); -} - -static void -damageSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap) -{ - DamagePtr pDamage; - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - if ((pDamage = damageGetWinPriv(pWindow))) - { - PixmapPtr pOldPixmap = (*pScreen->GetWindowPixmap) (pWindow); - DamagePtr *pPrev = getPixmapDamageRef(pOldPixmap); - - while (pDamage) - { - damageRemoveDamage (pPrev, pDamage); - pDamage = pDamage->pNextWin; - } - } - unwrap (pScrPriv, pScreen, SetWindowPixmap); - (*pScreen->SetWindowPixmap) (pWindow, pPixmap); - wrap (pScrPriv, pScreen, SetWindowPixmap, damageSetWindowPixmap); - if ((pDamage = damageGetWinPriv(pWindow))) - { - DamagePtr *pPrev = getPixmapDamageRef(pPixmap); - - while (pDamage) - { - damageInsertDamage (pPrev, pDamage); - pDamage = pDamage->pNextWin; - } - } -} - -static Bool -damageDestroyWindow (WindowPtr pWindow) -{ - DamagePtr pDamage; - ScreenPtr pScreen = pWindow->drawable.pScreen; - Bool ret; - damageScrPriv(pScreen); - - while ((pDamage = damageGetWinPriv(pWindow))) - { - DamageUnregister (&pWindow->drawable, pDamage); - DamageDestroy (pDamage); - } - unwrap (pScrPriv, pScreen, DestroyWindow); - ret = (*pScreen->DestroyWindow) (pWindow); - wrap (pScrPriv, pScreen, DestroyWindow, damageDestroyWindow); - return ret; -} - -static Bool -damageCloseScreen (int i, ScreenPtr pScreen) -{ - damageScrPriv(pScreen); - - unwrap (pScrPriv, pScreen, DestroyPixmap); - unwrap (pScrPriv, pScreen, CreateGC); - unwrap (pScrPriv, pScreen, PaintWindowBackground); - unwrap (pScrPriv, pScreen, PaintWindowBorder); - unwrap (pScrPriv, pScreen, CopyWindow); - unwrap (pScrPriv, pScreen, CloseScreen); - unwrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas); - xfree (pScrPriv); - return (*pScreen->CloseScreen) (i, pScreen); -} - -int damageScrPrivateIndex; -int damagePixPrivateIndex; -int damageGCPrivateIndex; -int damageWinPrivateIndex; -int damageGeneration; - -Bool -DamageSetup (ScreenPtr pScreen) -{ - DamageScrPrivPtr pScrPriv; -#ifdef RENDER - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); -#endif - - if (damageGeneration != serverGeneration) - { - damageScrPrivateIndex = AllocateScreenPrivateIndex (); - if (damageScrPrivateIndex == -1) - return FALSE; - damageGCPrivateIndex = AllocateGCPrivateIndex (); - if (damageGCPrivateIndex == -1) - return FALSE; - damagePixPrivateIndex = AllocatePixmapPrivateIndex (); - if (damagePixPrivateIndex == -1) - return FALSE; - damageWinPrivateIndex = AllocateWindowPrivateIndex (); - if (damageWinPrivateIndex == -1) - return FALSE; - damageGeneration = serverGeneration; - } - if (pScreen->devPrivates[damageScrPrivateIndex].ptr) - return TRUE; - - if (!AllocateGCPrivate (pScreen, damageGCPrivateIndex, sizeof (DamageGCPrivRec))) - return FALSE; - if (!AllocatePixmapPrivate (pScreen, damagePixPrivateIndex, 0)) - return FALSE; - if (!AllocateWindowPrivate (pScreen, damageWinPrivateIndex, 0)) - return FALSE; - - pScrPriv = (DamageScrPrivPtr) xalloc (sizeof (DamageScrPrivRec)); - if (!pScrPriv) - return FALSE; - -#ifdef COMPOSITE - /* This is a kludge to ensure wrapping order with the composite wrapper. - * If it's done from compinit.c, then DamageSetup may be called before the - * extension init phase, so that cw will be higher in the wrapping chain and - * rewrite drawables before damage gets to it, causing confusion. - */ - if (!noCompositeExtension) - miInitializeCompositeWrapper (pScreen); -#endif - - pScrPriv->internalLevel = 0; - pScrPriv->pScreenDamage = 0; - - wrap (pScrPriv, pScreen, DestroyPixmap, damageDestroyPixmap); - wrap (pScrPriv, pScreen, CreateGC, damageCreateGC); - wrap (pScrPriv, pScreen, PaintWindowBackground, damagePaintWindow); - wrap (pScrPriv, pScreen, PaintWindowBorder, damagePaintWindow); - wrap (pScrPriv, pScreen, DestroyWindow, damageDestroyWindow); - wrap (pScrPriv, pScreen, SetWindowPixmap, damageSetWindowPixmap); - wrap (pScrPriv, pScreen, CopyWindow, damageCopyWindow); - wrap (pScrPriv, pScreen, CloseScreen, damageCloseScreen); - wrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas, - damageRestoreAreas); -#ifdef RENDER - if (ps) { - wrap (pScrPriv, ps, Glyphs, damageGlyphs); - wrap (pScrPriv, ps, Composite, damageComposite); - } -#endif - - pScreen->devPrivates[damageScrPrivateIndex].ptr = (pointer) pScrPriv; - return TRUE; -} - -DamagePtr -DamageCreate (DamageReportFunc damageReport, - DamageDestroyFunc damageDestroy, - DamageReportLevel damageLevel, - Bool isInternal, - ScreenPtr pScreen, - void *closure) -{ - DamagePtr pDamage; - - pDamage = xalloc (sizeof (DamageRec)); - if (!pDamage) - return 0; - pDamage->pNext = 0; - pDamage->pNextWin = 0; - REGION_NULL(pScreen, &pDamage->damage); - - pDamage->damageLevel = damageLevel; - pDamage->isInternal = isInternal; - pDamage->closure = closure; - pDamage->isWindow = FALSE; - pDamage->pDrawable = 0; - - pDamage->damageReport = damageReport; - pDamage->damageDestroy = damageDestroy; - return pDamage; -} - -void -DamageRegister (DrawablePtr pDrawable, - DamagePtr pDamage) -{ - if (pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pDrawable; - winDamageRef(pWindow); - -#if DAMAGE_VALIDATE_ENABLE - DamagePtr pOld; - - for (pOld = *pPrev; pOld; pOld = pOld->pNextWin) - if (pOld == pDamage) { - ErrorF ("Damage already on window list\n"); - abort (); - } -#endif - pDamage->pNextWin = *pPrev; - *pPrev = pDamage; - pDamage->isWindow = TRUE; - } - else - pDamage->isWindow = FALSE; - pDamage->pDrawable = pDrawable; - damageInsertDamage (getDrawableDamageRef (pDrawable), pDamage); -} - -void -DamageDrawInternal (ScreenPtr pScreen, Bool enable) -{ - damageScrPriv (pScreen); - - pScrPriv->internalLevel += enable ? 1 : -1; -} - -void -DamageUnregister (DrawablePtr pDrawable, - DamagePtr pDamage) -{ - if (pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pDrawable; - winDamageRef (pWindow); -#if DAMAGE_VALIDATE_ENABLE - int found = 0; -#endif - - while (*pPrev) - { - if (*pPrev == pDamage) - { - *pPrev = pDamage->pNextWin; -#if DAMAGE_VALIDATE_ENABLE - found = 1; -#endif - break; - } - pPrev = &(*pPrev)->pNextWin; - } -#if DAMAGE_VALIDATE_ENABLE - if (!found) { - ErrorF ("Damage not on window list\n"); - abort (); - } -#endif - } - pDamage->pDrawable = 0; - damageRemoveDamage (getDrawableDamageRef (pDrawable), pDamage); -} - -void -DamageDestroy (DamagePtr pDamage) -{ - if (pDamage->damageDestroy) - (*pDamage->damageDestroy) (pDamage, pDamage->closure); - REGION_UNINIT (pDamage->pDrawable->pScreen, &pDamage->damage); - xfree (pDamage); -} - -Bool -DamageSubtract (DamagePtr pDamage, - const RegionPtr pRegion) -{ - RegionPtr pClip; - RegionRec pixmapClip; - DrawablePtr pDrawable = pDamage->pDrawable; - - REGION_SUBTRACT (pDrawable->pScreen, &pDamage->damage, &pDamage->damage, pRegion); - if (pDrawable) - { - if (pDrawable->type == DRAWABLE_WINDOW) - pClip = &((WindowPtr) pDrawable)->borderClip; - else - { - BoxRec box; - - box.x1 = pDrawable->x; - box.y1 = pDrawable->y; - box.x2 = pDrawable->x + pDrawable->width; - box.y2 = pDrawable->y + pDrawable->height; - REGION_INIT (pDrawable->pScreen, &pixmapClip, &box, 1); - pClip = &pixmapClip; - } - REGION_TRANSLATE (pDrawable->pScreen, &pDamage->damage, pDrawable->x, pDrawable->y); - REGION_INTERSECT (pDrawable->pScreen, &pDamage->damage, &pDamage->damage, pClip); - REGION_TRANSLATE (pDrawable->pScreen, &pDamage->damage, -pDrawable->x, -pDrawable->y); - if (pDrawable->type != DRAWABLE_WINDOW) - REGION_UNINIT(pDrawable->pScreen, &pixmapClip); - } - return REGION_NOTEMPTY (pDrawable->pScreen, &pDamage->damage); -} - -void -DamageEmpty (DamagePtr pDamage) -{ - REGION_EMPTY (pDamage->pDrawable->pScreen, &pDamage->damage); -} - -RegionPtr -DamageRegion (DamagePtr pDamage) -{ - return &pDamage->damage; -} - -void -DamageDamageRegion (DrawablePtr pDrawable, - RegionPtr pRegion) -{ - damageDamageRegion (pDrawable, pRegion, FALSE, -1); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.X.original deleted file mode 100644 index 286728cd1..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdamage.c.X.original +++ /dev/null @@ -1,1966 +0,0 @@ -/* - * $Id: damage.c,v 1.19 2005/10/06 21:55:41 anholt Exp $ - * - * Copyright © 2003 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include "dixfontstr.h" -#include -#include "mi.h" -#include "regionstr.h" -#include "globals.h" -#include "gcstruct.h" -#include "damage.h" -#include "damagestr.h" -#ifdef COMPOSITE -#include "cw.h" -#endif - -#define wrap(priv, real, mem, func) {\ - priv->mem = real->mem; \ - real->mem = func; \ -} - -#define unwrap(priv, real, mem) {\ - real->mem = priv->mem; \ -} - -#define BOX_SAME(a,b) \ - ((a)->x1 == (b)->x1 && \ - (a)->y1 == (b)->y1 && \ - (a)->x2 == (b)->x2 && \ - (a)->y2 == (b)->y2) - -#define DAMAGE_VALIDATE_ENABLE 0 -#define DAMAGE_DEBUG_ENABLE 0 -#if DAMAGE_DEBUG_ENABLE -#define DAMAGE_DEBUG(x) ErrorF x -#else -#define DAMAGE_DEBUG(x) -#endif - -#define getPixmapDamageRef(pPixmap) \ - ((DamagePtr *) &(pPixmap->devPrivates[damagePixPrivateIndex].ptr)) - -#define pixmapDamage(pPixmap) damagePixPriv(pPixmap) - -static DamagePtr * -getDrawableDamageRef (DrawablePtr pDrawable) -{ - PixmapPtr pPixmap; - - if (pDrawable->type == DRAWABLE_WINDOW) - { - ScreenPtr pScreen = pDrawable->pScreen; - - pPixmap = 0; - if (pScreen->GetWindowPixmap -#ifdef ROOTLESS_WORKAROUND - && ((WindowPtr)pDrawable)->viewable -#endif - ) - pPixmap = (*pScreen->GetWindowPixmap) ((WindowPtr)pDrawable); - - if (!pPixmap) - { - damageScrPriv(pScreen); - - return &pScrPriv->pScreenDamage; - } - } - else - pPixmap = (PixmapPtr) pDrawable; - return getPixmapDamageRef (pPixmap); -} - -#define getDrawableDamage(pDrawable) (*getDrawableDamageRef (pDrawable)) -#define getWindowDamage(pWin) getDrawableDamage(&(pWin)->drawable) - -#define drawableDamage(pDrawable) \ - DamagePtr pDamage = getDrawableDamage(pDrawable) - -#define windowDamage(pWin) drawableDamage(&(pWin)->drawable) - -#define winDamageRef(pWindow) \ - DamagePtr *pPrev = (DamagePtr *) \ - &(pWindow->devPrivates[damageWinPrivateIndex].ptr) - -#if DAMAGE_DEBUG_ENABLE -static void -_damageDamageRegion (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip, int subWindowMode, const char *where) -#define damageDamageRegion(d,r,c,m) _damageDamageRegion(d,r,c,m,__FUNCTION__) -#else -static void -damageDamageRegion (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip, - int subWindowMode) -#endif -{ - ScreenPtr pScreen = pDrawable->pScreen; - damageScrPriv(pScreen); - drawableDamage(pDrawable); - DamagePtr pNext; - RegionRec clippedRec; - RegionPtr pDamageRegion; - RegionRec pixClip; - Bool was_empty; - RegionRec tmpRegion; - BoxRec tmpBox; - int draw_x, draw_y; -#ifdef COMPOSITE - int screen_x = 0, screen_y = 0; -#endif - - /* short circuit for empty regions */ - if (!REGION_NOTEMPTY(pScreen, pRegion)) - return; - -#ifdef COMPOSITE - /* - * When drawing to a pixmap which is storing window contents, - * the region presented is in pixmap relative coordinates which - * need to be converted to screen relative coordinates - */ - if (pDrawable->type != DRAWABLE_WINDOW) - { - screen_x = ((PixmapPtr) pDrawable)->screen_x - pDrawable->x; - screen_y = ((PixmapPtr) pDrawable)->screen_y - pDrawable->y; - } - if (screen_x || screen_y) - REGION_TRANSLATE (pScreen, pRegion, screen_x, screen_y); -#endif - - if (pDrawable->type == DRAWABLE_WINDOW && - ((WindowPtr)(pDrawable))->backingStore == NotUseful) - { - if (subWindowMode == ClipByChildren) - { - REGION_INTERSECT(pScreen, pRegion, pRegion, - &((WindowPtr)(pDrawable))->clipList); - } - else if (subWindowMode == IncludeInferiors) - { - RegionPtr pTempRegion = - NotClippedByChildren((WindowPtr)(pDrawable)); - REGION_INTERSECT(pScreen, pRegion, pRegion, pTempRegion); - REGION_DESTROY(pScreen, pTempRegion); - } - /* If subWindowMode is set to an invalid value, don't perform - * any drawable-based clipping. */ - } - - - REGION_NULL (pScreen, &clippedRec); - for (; pDamage; pDamage = pNext) - { - pNext = pDamage->pNext; - /* - * Check for internal damage and don't send events - */ - if (pScrPriv->internalLevel > 0 && !pDamage->isInternal) - { - DAMAGE_DEBUG (("non internal damage, skipping at %d\n", - pScrPriv->internalLevel)); - continue; - } - /* - * Check for unrealized windows - */ - if (pDamage->pDrawable->type == DRAWABLE_WINDOW && - !((WindowPtr) (pDamage->pDrawable))->realized) - { -#if 0 - DAMAGE_DEBUG (("damage while window unrealized\n")); -#endif - continue; - } - - draw_x = pDamage->pDrawable->x; - draw_y = pDamage->pDrawable->y; -#ifdef COMPOSITE - /* - * Need to move everyone to screen coordinates - * XXX what about off-screen pixmaps with non-zero x/y? - */ - if (pDamage->pDrawable->type != DRAWABLE_WINDOW) - { - draw_x += ((PixmapPtr) pDamage->pDrawable)->screen_x; - draw_y += ((PixmapPtr) pDamage->pDrawable)->screen_y; - } -#endif - - /* - * Clip against border or pixmap bounds - */ - - pDamageRegion = pRegion; - if (clip || pDamage->pDrawable != pDrawable) - { - pDamageRegion = &clippedRec; - if (pDamage->pDrawable->type == DRAWABLE_WINDOW) { - REGION_INTERSECT (pScreen, pDamageRegion, pRegion, - &((WindowPtr)(pDamage->pDrawable))->borderClip); - } else { - BoxRec box; - box.x1 = draw_x; - box.y1 = draw_y; - box.x2 = draw_x + pDamage->pDrawable->width; - box.y2 = draw_y + pDamage->pDrawable->height; - REGION_INIT(pScreen, &pixClip, &box, 1); - REGION_INTERSECT (pScreen, pDamageRegion, pRegion, &pixClip); - REGION_UNINIT(pScreen, &pixClip); - } - /* - * Short circuit empty results - */ - if (!REGION_NOTEMPTY(pScreen, pDamageRegion)) - continue; - } - - DAMAGE_DEBUG (("%s %d x %d +%d +%d (target 0x%lx monitor 0x%lx)\n", - where, - pDamageRegion->extents.x2 - pDamageRegion->extents.x1, - pDamageRegion->extents.y2 - pDamageRegion->extents.y1, - pDamageRegion->extents.x1, pDamageRegion->extents.y1, - pDrawable->id, pDamage->pDrawable->id)); - - /* - * Move region to target coordinate space - */ - if (draw_x || draw_y) - REGION_TRANSLATE (pScreen, pDamageRegion, -draw_x, -draw_y); - - switch (pDamage->damageLevel) { - case DamageReportRawRegion: - (*pDamage->damageReport) (pDamage, pDamageRegion, pDamage->closure); - break; - case DamageReportDeltaRegion: - REGION_NULL (pScreen, &tmpRegion); - REGION_SUBTRACT (pScreen, &tmpRegion, pDamageRegion, &pDamage->damage); - if (REGION_NOTEMPTY (pScreen, &tmpRegion)) - { - REGION_UNION(pScreen, &pDamage->damage, - &pDamage->damage, pDamageRegion); - (*pDamage->damageReport) (pDamage, &tmpRegion, pDamage->closure); - } - REGION_UNINIT(pScreen, &tmpRegion); - break; - case DamageReportBoundingBox: - tmpBox = *REGION_EXTENTS (pScreen, &pDamage->damage); - REGION_UNION(pScreen, &pDamage->damage, - &pDamage->damage, pDamageRegion); - if (!BOX_SAME (&tmpBox, REGION_EXTENTS (pScreen, &pDamage->damage))) - (*pDamage->damageReport) (pDamage, &pDamage->damage, pDamage->closure); - break; - case DamageReportNonEmpty: - was_empty = !REGION_NOTEMPTY(pScreen, &pDamage->damage); - REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage, - pDamageRegion); - if (was_empty && REGION_NOTEMPTY(pScreen, &pDamage->damage)) - (*pDamage->damageReport) (pDamage, &pDamage->damage, pDamage->closure); - break; - case DamageReportNone: - REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage, - pDamageRegion); - break; - } - /* - * translate original region back - */ - if (pDamageRegion == pRegion && (draw_x || draw_y)) - REGION_TRANSLATE (pScreen, pDamageRegion, draw_x, draw_y); - } -#ifdef COMPOSITE - if (screen_x || screen_y) - REGION_TRANSLATE (pScreen, pRegion, -screen_x, -screen_y); -#endif - - REGION_UNINIT (pScreen, &clippedRec); -} - -#if DAMAGE_DEBUG_ENABLE -#define damageDamageBox(d,b,m) _damageDamageBox(d,b,m,__FUNCTION__) -static void -_damageDamageBox (DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode, const char *where) -#else -static void -damageDamageBox (DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode) -#endif -{ - RegionRec region; - - REGION_INIT (pDrawable->pScreen, ®ion, pBox, 1); -#if DAMAGE_DEBUG_ENABLE - _damageDamageRegion (pDrawable, ®ion, TRUE, subWindowMode, where); -#else - damageDamageRegion (pDrawable, ®ion, TRUE, subWindowMode); -#endif - REGION_UNINIT (pDrawable->pScreen, ®ion); -} - -static void damageValidateGC(GCPtr, unsigned long, DrawablePtr); -static void damageChangeGC(GCPtr, unsigned long); -static void damageCopyGC(GCPtr, unsigned long, GCPtr); -static void damageDestroyGC(GCPtr); -static void damageChangeClip(GCPtr, int, pointer, int); -static void damageDestroyClip(GCPtr); -static void damageCopyClip(GCPtr, GCPtr); - -GCFuncs damageGCFuncs = { - damageValidateGC, damageChangeGC, damageCopyGC, damageDestroyGC, - damageChangeClip, damageDestroyClip, damageCopyClip -}; - -extern GCOps damageGCOps; - -static Bool -damageCreateGC(GCPtr pGC) -{ - ScreenPtr pScreen = pGC->pScreen; - damageScrPriv(pScreen); - damageGCPriv(pGC); - Bool ret; - - pGC->pCompositeClip = 0; - unwrap (pScrPriv, pScreen, CreateGC); - if((ret = (*pScreen->CreateGC) (pGC))) { - pGCPriv->ops = NULL; - pGCPriv->funcs = pGC->funcs; - pGC->funcs = &damageGCFuncs; - } - wrap (pScrPriv, pScreen, CreateGC, damageCreateGC); - - return ret; -} - -#ifdef NOTUSED -static void -damageWrapGC (GCPtr pGC) -{ - damageGCPriv(pGC); - - pGCPriv->ops = NULL; - pGCPriv->funcs = pGC->funcs; - pGC->funcs = &damageGCFuncs; -} - -static void -damageUnwrapGC (GCPtr pGC) -{ - damageGCPriv(pGC); - - pGC->funcs = pGCPriv->funcs; - if (pGCPriv->ops) - pGC->ops = pGCPriv->ops; -} -#endif - -#define DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable) \ - damageGCPriv(pGC); \ - GCFuncs *oldFuncs = pGC->funcs; \ - unwrap(pGCPriv, pGC, funcs); \ - unwrap(pGCPriv, pGC, ops); \ - -#define DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable) \ - wrap(pGCPriv, pGC, funcs, oldFuncs); \ - wrap(pGCPriv, pGC, ops, &damageGCOps) - -#define DAMAGE_GC_FUNC_PROLOGUE(pGC) \ - damageGCPriv(pGC); \ - unwrap(pGCPriv, pGC, funcs); \ - if (pGCPriv->ops) unwrap(pGCPriv, pGC, ops) - -#define DAMAGE_GC_FUNC_EPILOGUE(pGC) \ - wrap(pGCPriv, pGC, funcs, &damageGCFuncs); \ - if (pGCPriv->ops) wrap(pGCPriv, pGC, ops, &damageGCOps) - -static void -damageValidateGC(GCPtr pGC, - unsigned long changes, - DrawablePtr pDrawable) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->ValidateGC)(pGC, changes, pDrawable); - pGCPriv->ops = pGC->ops; /* just so it's not NULL */ - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageDestroyGC(GCPtr pGC) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->DestroyGC)(pGC); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageChangeGC (GCPtr pGC, - unsigned long mask) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->ChangeGC) (pGC, mask); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageCopyGC (GCPtr pGCSrc, - unsigned long mask, - GCPtr pGCDst) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGCDst); - (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst); - DAMAGE_GC_FUNC_EPILOGUE (pGCDst); -} - -static void -damageChangeClip (GCPtr pGC, - int type, - pointer pvalue, - int nrects) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -static void -damageCopyClip(GCPtr pgcDst, GCPtr pgcSrc) -{ - DAMAGE_GC_FUNC_PROLOGUE (pgcDst); - (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc); - DAMAGE_GC_FUNC_EPILOGUE (pgcDst); -} - -static void -damageDestroyClip(GCPtr pGC) -{ - DAMAGE_GC_FUNC_PROLOGUE (pGC); - (* pGC->funcs->DestroyClip)(pGC); - DAMAGE_GC_FUNC_EPILOGUE (pGC); -} - -#define TRIM_BOX(box, pGC) if (pGC->pCompositeClip) { \ - BoxPtr extents = &pGC->pCompositeClip->extents;\ - if(box.x1 < extents->x1) box.x1 = extents->x1; \ - if(box.x2 > extents->x2) box.x2 = extents->x2; \ - if(box.y1 < extents->y1) box.y1 = extents->y1; \ - if(box.y2 > extents->y2) box.y2 = extents->y2; \ - } - -#define TRANSLATE_BOX(box, pDrawable) { \ - box.x1 += pDrawable->x; \ - box.x2 += pDrawable->x; \ - box.y1 += pDrawable->y; \ - box.y2 += pDrawable->y; \ - } - -#define TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC) { \ - TRANSLATE_BOX(box, pDrawable); \ - TRIM_BOX(box, pGC); \ - } - -#define BOX_NOT_EMPTY(box) \ - (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0)) - -#define checkGCDamage(d,g) (getDrawableDamage(d) && \ - (!g->pCompositeClip ||\ - REGION_NOTEMPTY(d->pScreen, \ - g->pCompositeClip))) - -#ifdef RENDER - -#define TRIM_PICTURE_BOX(box, pDst) { \ - BoxPtr extents = &pDst->pCompositeClip->extents;\ - if(box.x1 < extents->x1) box.x1 = extents->x1; \ - if(box.x2 > extents->x2) box.x2 = extents->x2; \ - if(box.y1 < extents->y1) box.y1 = extents->y1; \ - if(box.y2 > extents->y2) box.y2 = extents->y2; \ - } - -#define checkPictureDamage(p) (getDrawableDamage(p->pDrawable) && \ - REGION_NOTEMPTY(pScreen, p->pCompositeClip)) - -static void -damageComposite (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - damageScrPriv(pScreen); - - if (checkPictureDamage (pDst)) - { - BoxRec box; - - box.x1 = xDst + pDst->pDrawable->x; - box.y1 = yDst + pDst->pDrawable->y; - box.x2 = box.x1 + width; - box.y2 = box.y1 + height; - TRIM_PICTURE_BOX(box, pDst); - if (BOX_NOT_EMPTY(box)) - damageDamageBox (pDst->pDrawable, &box, pDst->subWindowMode); - } - unwrap (pScrPriv, ps, Composite); - (*ps->Composite) (op, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height); - wrap (pScrPriv, ps, Composite, damageComposite); -} - -static void -damageGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr list, - GlyphPtr *glyphs) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - damageScrPriv(pScreen); - - if (checkPictureDamage (pDst)) - { - int nlistTmp = nlist; - GlyphListPtr listTmp = list; - GlyphPtr *glyphsTmp = glyphs; - int x, y; - int n; - GlyphPtr glyph; - BoxRec box; - int x1, y1, x2, y2; - - box.x1 = 32767; - box.y1 = 32767; - box.x2 = -32767; - box.y2 = -32767; - x = pDst->pDrawable->x; - y = pDst->pDrawable->y; - while (nlistTmp--) - { - x += listTmp->xOff; - y += listTmp->yOff; - n = listTmp->len; - while (n--) - { - glyph = *glyphsTmp++; - x1 = x - glyph->info.x; - y1 = y - glyph->info.y; - x2 = x1 + glyph->info.width; - y2 = y1 + glyph->info.height; - if (x1 < box.x1) - box.x1 = x1; - if (y1 < box.y1) - box.y1 = y1; - if (x2 > box.x2) - box.x2 = x2; - if (y2 > box.y2) - box.y2 = y2; - x += glyph->info.xOff; - y += glyph->info.yOff; - } - listTmp++; - } - TRIM_PICTURE_BOX (box, pDst); - if (BOX_NOT_EMPTY(box)) - damageDamageBox (pDst->pDrawable, &box, pDst->subWindowMode); - } - unwrap (pScrPriv, ps, Glyphs); - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs); - wrap (pScrPriv, ps, Glyphs, damageGlyphs); -} -#endif - -/**********************************************************/ - - -static void -damageFillSpans(DrawablePtr pDrawable, - GC *pGC, - int npt, - DDXPointPtr ppt, - int *pwidth, - int fSorted) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - int nptTmp = npt; - DDXPointPtr pptTmp = ppt; - int *pwidthTmp = pwidth; - BoxRec box; - - box.x1 = pptTmp->x; - box.x2 = box.x1 + *pwidthTmp; - box.y2 = box.y1 = pptTmp->y; - - while(--nptTmp) - { - pptTmp++; - pwidthTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - if(box.x2 < (pptTmp->x + *pwidthTmp)) - box.x2 = pptTmp->x + *pwidthTmp; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - - box.y2++; - - if(!pGC->miTranslate) { - TRANSLATE_BOX(box, pDrawable); - } - TRIM_BOX(box, pGC); - - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - - (*pGC->ops->FillSpans)(pDrawable, pGC, npt, ppt, pwidth, fSorted); - - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageSetSpans(DrawablePtr pDrawable, - GCPtr pGC, - char *pcharsrc, - DDXPointPtr ppt, - int *pwidth, - int npt, - int fSorted) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - DDXPointPtr pptTmp = ppt; - int *pwidthTmp = pwidth; - int nptTmp = npt; - BoxRec box; - - box.x1 = pptTmp->x; - box.x2 = box.x1 + *pwidthTmp; - box.y2 = box.y1 = pptTmp->y; - - while(--nptTmp) - { - pptTmp++; - pwidthTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - if(box.x2 < (pptTmp->x + *pwidthTmp)) - box.x2 = pptTmp->x + *pwidthTmp; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - - box.y2++; - - if(!pGC->miTranslate) { - TRANSLATE_BOX(box, pDrawable); - } - TRIM_BOX(box, pGC); - - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->SetSpans)(pDrawable, pGC, pcharsrc, ppt, pwidth, npt, fSorted); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePutImage(DrawablePtr pDrawable, - GCPtr pGC, - int depth, - int x, - int y, - int w, - int h, - int leftPad, - int format, - char *pImage) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - if (checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - - box.x1 = x + pDrawable->x; - box.x2 = box.x1 + w; - box.y1 = y + pDrawable->y; - box.y2 = box.y1 + h; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PutImage)(pDrawable, pGC, depth, x, y, w, h, - leftPad, format, pImage); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static RegionPtr -damageCopyArea(DrawablePtr pSrc, - DrawablePtr pDst, - GC *pGC, - int srcx, - int srcy, - int width, - int height, - int dstx, - int dsty) -{ - RegionPtr ret; - DAMAGE_GC_OP_PROLOGUE(pGC, pDst); - - /* The driver will only call SourceValidate() when pSrc != pDst, - * but the software sprite (misprite.c) always need to know when a - * drawable is copied so it can remove the sprite. See #1030. */ - if ((pSrc == pDst) && pSrc->pScreen->SourceValidate && - pSrc->type == DRAWABLE_WINDOW && - ((WindowPtr)pSrc)->viewable) - { - (*pSrc->pScreen->SourceValidate) (pSrc, srcx, srcy, width, height); - } - - if (checkGCDamage (pDst, pGC)) - { - BoxRec box; - - box.x1 = dstx + pDst->x; - box.x2 = box.x1 + width; - box.y1 = dsty + pDst->y; - box.y2 = box.y1 + height; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDst, &box, pGC->subWindowMode); - } - - ret = (*pGC->ops->CopyArea)(pSrc, pDst, - pGC, srcx, srcy, width, height, dstx, dsty); - DAMAGE_GC_OP_EPILOGUE(pGC, pDst); - return ret; -} - -static RegionPtr -damageCopyPlane(DrawablePtr pSrc, - DrawablePtr pDst, - GCPtr pGC, - int srcx, - int srcy, - int width, - int height, - int dstx, - int dsty, - unsigned long bitPlane) -{ - RegionPtr ret; - DAMAGE_GC_OP_PROLOGUE(pGC, pDst); - - /* The driver will only call SourceValidate() when pSrc != pDst, - * but the software sprite (misprite.c) always need to know when a - * drawable is copied so it can remove the sprite. See #1030. */ - if ((pSrc == pDst) && pSrc->pScreen->SourceValidate && - pSrc->type == DRAWABLE_WINDOW && - ((WindowPtr)pSrc)->viewable) - { - (*pSrc->pScreen->SourceValidate) (pSrc, srcx, srcy, width, height); - } - - if (checkGCDamage (pDst, pGC)) - { - BoxRec box; - - box.x1 = dstx + pDst->x; - box.x2 = box.x1 + width; - box.y1 = dsty + pDst->y; - box.y2 = box.y1 + height; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDst, &box, pGC->subWindowMode); - } - - ret = (*pGC->ops->CopyPlane)(pSrc, pDst, - pGC, srcx, srcy, width, height, dstx, dsty, bitPlane); - DAMAGE_GC_OP_EPILOGUE(pGC, pDst); - return ret; -} - -static void -damagePolyPoint(DrawablePtr pDrawable, - GCPtr pGC, - int mode, - int npt, - xPoint *ppt) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int nptTmp = npt; - xPoint *pptTmp = ppt; - - box.x2 = box.x1 = pptTmp->x; - box.y2 = box.y1 = pptTmp->y; - - /* this could be slow if the points were spread out */ - - while(--nptTmp) - { - pptTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - else if(box.x2 < pptTmp->x) box.x2 = pptTmp->x; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - - box.x2++; - box.y2++; - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyPoint)(pDrawable, pGC, mode, npt, ppt); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolylines(DrawablePtr pDrawable, - GCPtr pGC, - int mode, - int npt, - DDXPointPtr ppt) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt && checkGCDamage (pDrawable, pGC)) - { - int nptTmp = npt; - DDXPointPtr pptTmp = ppt; - BoxRec box; - int extra = pGC->lineWidth >> 1; - - box.x2 = box.x1 = pptTmp->x; - box.y2 = box.y1 = pptTmp->y; - - if(nptTmp > 1) - { - if(pGC->joinStyle == JoinMiter) - extra = 6 * pGC->lineWidth; - else if(pGC->capStyle == CapProjecting) - extra = pGC->lineWidth; - } - - if(mode == CoordModePrevious) - { - int x = box.x1; - int y = box.y1; - while(--nptTmp) - { - pptTmp++; - x += pptTmp->x; - y += pptTmp->y; - if(box.x1 > x) box.x1 = x; - else if(box.x2 < x) box.x2 = x; - if(box.y1 > y) box.y1 = y; - else if(box.y2 < y) box.y2 = y; - } - } - else - { - while(--nptTmp) - { - pptTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - else if(box.x2 < pptTmp->x) box.x2 = pptTmp->x; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - } - - box.x2++; - box.y2++; - - if(extra) - { - box.x1 -= extra; - box.x2 += extra; - box.y1 -= extra; - box.y2 += extra; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->Polylines)(pDrawable, pGC, mode, npt, ppt); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolySegment(DrawablePtr pDrawable, - GCPtr pGC, - int nSeg, - xSegment *pSeg) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nSeg && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int extra = pGC->lineWidth; - int nsegTmp = nSeg; - xSegment *pSegTmp = pSeg; - - if(pGC->capStyle != CapProjecting) - extra >>= 1; - - if(pSegTmp->x2 > pSegTmp->x1) { - box.x1 = pSegTmp->x1; - box.x2 = pSegTmp->x2; - } else { - box.x2 = pSegTmp->x1; - box.x1 = pSegTmp->x2; - } - - if(pSegTmp->y2 > pSegTmp->y1) { - box.y1 = pSegTmp->y1; - box.y2 = pSegTmp->y2; - } else { - box.y2 = pSegTmp->y1; - box.y1 = pSegTmp->y2; - } - - while(--nsegTmp) - { - pSegTmp++; - if(pSegTmp->x2 > pSegTmp->x1) - { - if(pSegTmp->x1 < box.x1) box.x1 = pSegTmp->x1; - if(pSegTmp->x2 > box.x2) box.x2 = pSegTmp->x2; - } - else - { - if(pSegTmp->x2 < box.x1) box.x1 = pSegTmp->x2; - if(pSegTmp->x1 > box.x2) box.x2 = pSegTmp->x1; - } - if(pSegTmp->y2 > pSegTmp->y1) - { - if(pSegTmp->y1 < box.y1) box.y1 = pSegTmp->y1; - if(pSegTmp->y2 > box.y2) box.y2 = pSegTmp->y2; - } - else - { - if(pSegTmp->y2 < box.y1) box.y1 = pSegTmp->y2; - if(pSegTmp->y1 > box.y2) box.y2 = pSegTmp->y1; - } - } - - box.x2++; - box.y2++; - - if(extra) - { - box.x1 -= extra; - box.x2 += extra; - box.y1 -= extra; - box.y2 += extra; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolySegment)(pDrawable, pGC, nSeg, pSeg); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolyRectangle(DrawablePtr pDrawable, - GCPtr pGC, - int nRects, - xRectangle *pRects) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nRects && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int offset1, offset2, offset3; - int nRectsTmp = nRects; - xRectangle *pRectsTmp = pRects; - - offset2 = pGC->lineWidth; - if(!offset2) offset2 = 1; - offset1 = offset2 >> 1; - offset3 = offset2 - offset1; - - while(nRectsTmp--) - { - box.x1 = pRectsTmp->x - offset1; - box.y1 = pRectsTmp->y - offset1; - box.x2 = box.x1 + pRectsTmp->width + offset2; - box.y2 = box.y1 + offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - box.x1 = pRectsTmp->x - offset1; - box.y1 = pRectsTmp->y + offset3; - box.x2 = box.x1 + offset2; - box.y2 = box.y1 + pRectsTmp->height - offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - box.x1 = pRectsTmp->x + pRectsTmp->width - offset1; - box.y1 = pRectsTmp->y + offset3; - box.x2 = box.x1 + offset2; - box.y2 = box.y1 + pRectsTmp->height - offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - box.x1 = pRectsTmp->x - offset1; - box.y1 = pRectsTmp->y + pRectsTmp->height - offset1; - box.x2 = box.x1 + pRectsTmp->width + offset2; - box.y2 = box.y1 + offset2; - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - - pRectsTmp++; - } - } - (*pGC->ops->PolyRectangle)(pDrawable, pGC, nRects, pRects); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolyArc(DrawablePtr pDrawable, - GCPtr pGC, - int nArcs, - xArc *pArcs) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nArcs && checkGCDamage (pDrawable, pGC)) - { - int extra = pGC->lineWidth >> 1; - BoxRec box; - int nArcsTmp = nArcs; - xArc *pArcsTmp = pArcs; - - box.x1 = pArcsTmp->x; - box.x2 = box.x1 + pArcsTmp->width; - box.y1 = pArcsTmp->y; - box.y2 = box.y1 + pArcsTmp->height; - - while(--nArcsTmp) - { - pArcsTmp++; - if(box.x1 > pArcsTmp->x) - box.x1 = pArcsTmp->x; - if(box.x2 < (pArcsTmp->x + pArcsTmp->width)) - box.x2 = pArcsTmp->x + pArcsTmp->width; - if(box.y1 > pArcsTmp->y) - box.y1 = pArcsTmp->y; - if(box.y2 < (pArcsTmp->y + pArcsTmp->height)) - box.y2 = pArcsTmp->y + pArcsTmp->height; - } - - if(extra) - { - box.x1 -= extra; - box.x2 += extra; - box.y1 -= extra; - box.y2 += extra; - } - - box.x2++; - box.y2++; - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyArc)(pDrawable, pGC, nArcs, pArcs); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageFillPolygon(DrawablePtr pDrawable, - GCPtr pGC, - int shape, - int mode, - int npt, - DDXPointPtr ppt) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (npt > 2 && checkGCDamage (pDrawable, pGC)) - { - DDXPointPtr pptTmp = ppt; - int nptTmp = npt; - BoxRec box; - - box.x2 = box.x1 = pptTmp->x; - box.y2 = box.y1 = pptTmp->y; - - if(mode != CoordModeOrigin) - { - int x = box.x1; - int y = box.y1; - while(--nptTmp) - { - pptTmp++; - x += pptTmp->x; - y += pptTmp->y; - if(box.x1 > x) box.x1 = x; - else if(box.x2 < x) box.x2 = x; - if(box.y1 > y) box.y1 = y; - else if(box.y2 < y) box.y2 = y; - } - } - else - { - while(--nptTmp) - { - pptTmp++; - if(box.x1 > pptTmp->x) box.x1 = pptTmp->x; - else if(box.x2 < pptTmp->x) box.x2 = pptTmp->x; - if(box.y1 > pptTmp->y) box.y1 = pptTmp->y; - else if(box.y2 < pptTmp->y) box.y2 = pptTmp->y; - } - } - - box.x2++; - box.y2++; - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - - (*pGC->ops->FillPolygon)(pDrawable, pGC, shape, mode, npt, ppt); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - - -static void -damagePolyFillRect(DrawablePtr pDrawable, - GCPtr pGC, - int nRects, - xRectangle *pRects) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - if (nRects && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - xRectangle *pRectsTmp = pRects; - int nRectsTmp = nRects; - - box.x1 = pRectsTmp->x; - box.x2 = box.x1 + pRectsTmp->width; - box.y1 = pRectsTmp->y; - box.y2 = box.y1 + pRectsTmp->height; - - while(--nRectsTmp) - { - pRectsTmp++; - if(box.x1 > pRectsTmp->x) box.x1 = pRectsTmp->x; - if(box.x2 < (pRectsTmp->x + pRectsTmp->width)) - box.x2 = pRectsTmp->x + pRectsTmp->width; - if(box.y1 > pRectsTmp->y) box.y1 = pRectsTmp->y; - if(box.y2 < (pRectsTmp->y + pRectsTmp->height)) - box.y2 = pRectsTmp->y + pRectsTmp->height; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyFillRect)(pDrawable, pGC, nRects, pRects); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - - -static void -damagePolyFillArc(DrawablePtr pDrawable, - GCPtr pGC, - int nArcs, - xArc *pArcs) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (nArcs && checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - int nArcsTmp = nArcs; - xArc *pArcsTmp = pArcs; - - box.x1 = pArcsTmp->x; - box.x2 = box.x1 + pArcsTmp->width; - box.y1 = pArcsTmp->y; - box.y2 = box.y1 + pArcsTmp->height; - - while(--nArcsTmp) - { - pArcsTmp++; - if(box.x1 > pArcsTmp->x) - box.x1 = pArcsTmp->x; - if(box.x2 < (pArcsTmp->x + pArcsTmp->width)) - box.x2 = pArcsTmp->x + pArcsTmp->width; - if(box.y1 > pArcsTmp->y) - box.y1 = pArcsTmp->y; - if(box.y2 < (pArcsTmp->y + pArcsTmp->height)) - box.y2 = pArcsTmp->y + pArcsTmp->height; - } - - TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PolyFillArc)(pDrawable, pGC, nArcs, pArcs); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -/* - * general Poly/Image text function. Extract glyph information, - * compute bounding box and remove cursor if it is overlapped. - */ - -static void -damageDamageChars (DrawablePtr pDrawable, - FontPtr font, - int x, - int y, - unsigned int n, - CharInfoPtr *charinfo, - Bool imageblt, - int subWindowMode) -{ - ExtentInfoRec extents; - BoxRec box; - - QueryGlyphExtents(font, charinfo, n, &extents); - if (imageblt) - { - if (extents.overallWidth > extents.overallRight) - extents.overallRight = extents.overallWidth; - if (extents.overallWidth < extents.overallLeft) - extents.overallLeft = extents.overallWidth; - if (extents.overallLeft > 0) - extents.overallLeft = 0; - if (extents.fontAscent > extents.overallAscent) - extents.overallAscent = extents.fontAscent; - if (extents.fontDescent > extents.overallDescent) - extents.overallDescent = extents.fontDescent; - } - box.x1 = x + extents.overallLeft; - box.y1 = y - extents.overallAscent; - box.x2 = x + extents.overallRight; - box.y2 = y + extents.overallDescent; - damageDamageBox (pDrawable, &box, subWindowMode); -} - -/* - * values for textType: - */ -#define TT_POLY8 0 -#define TT_IMAGE8 1 -#define TT_POLY16 2 -#define TT_IMAGE16 3 - -static int -damageText (DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - unsigned long count, - char *chars, - FontEncoding fontEncoding, - Bool textType) -{ - CharInfoPtr *charinfo; - CharInfoPtr *info; - unsigned long i; - unsigned int n; - int w; - Bool imageblt; - - imageblt = (textType == TT_IMAGE8) || (textType == TT_IMAGE16); - - charinfo = (CharInfoPtr *) ALLOCATE_LOCAL(count * sizeof(CharInfoPtr)); - if (!charinfo) - return x; - - GetGlyphs(pGC->font, count, (unsigned char *)chars, - fontEncoding, &i, charinfo); - n = (unsigned int)i; - w = 0; - if (!imageblt) - for (info = charinfo; i--; info++) - w += (*info)->metrics.characterWidth; - - if (n != 0) { - damageDamageChars (pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, n, - charinfo, imageblt, pGC->subWindowMode); - if (imageblt) - (*pGC->ops->ImageGlyphBlt)(pDrawable, pGC, x, y, n, charinfo, - FONTGLYPHS(pGC->font)); - else - (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, n, charinfo, - FONTGLYPHS(pGC->font)); - } - DEALLOCATE_LOCAL(charinfo); - return x + w; -} - -static int -damagePolyText8(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - char *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - x = damageText (pDrawable, pGC, x, y, (unsigned long) count, chars, - Linear8Bit, TT_POLY8); - else - x = (*pGC->ops->PolyText8)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); - return x; -} - -static int -damagePolyText16(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - x = damageText (pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, - FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, - TT_POLY16); - else - x = (*pGC->ops->PolyText16)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); - return x; -} - -static void -damageImageText8(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - char *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, chars, - Linear8Bit, TT_IMAGE8); - else - (*pGC->ops->ImageText8)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageImageText16(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - - if (checkGCDamage (pDrawable, pGC)) - damageText (pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, - FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, - TT_IMAGE16); - else - (*pGC->ops->ImageText16)(pDrawable, pGC, x, y, count, chars); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - - -static void -damageImageGlyphBlt(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - unsigned int nglyph, - CharInfoPtr *ppci, - pointer pglyphBase) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - damageDamageChars (pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, - nglyph, ppci, TRUE, pGC->subWindowMode); - (*pGC->ops->ImageGlyphBlt)(pDrawable, pGC, x, y, nglyph, - ppci, pglyphBase); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePolyGlyphBlt(DrawablePtr pDrawable, - GCPtr pGC, - int x, - int y, - unsigned int nglyph, - CharInfoPtr *ppci, - pointer pglyphBase) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - damageDamageChars (pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, - nglyph, ppci, FALSE, pGC->subWindowMode); - (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, - ppci, pglyphBase); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damagePushPixels(GCPtr pGC, - PixmapPtr pBitMap, - DrawablePtr pDrawable, - int dx, - int dy, - int xOrg, - int yOrg) -{ - DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); - if(checkGCDamage (pDrawable, pGC)) - { - BoxRec box; - - box.x1 = xOrg; - box.y1 = yOrg; - - if(!pGC->miTranslate) { - box.x1 += pDrawable->x; - box.y1 += pDrawable->y; - } - - box.x2 = box.x1 + dx; - box.y2 = box.y1 + dy; - - TRIM_BOX(box, pGC); - if(BOX_NOT_EMPTY(box)) - damageDamageBox (pDrawable, &box, pGC->subWindowMode); - } - (*pGC->ops->PushPixels)(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg); - DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); -} - -static void -damageRemoveDamage (DamagePtr *pPrev, DamagePtr pDamage) -{ - while (*pPrev) - { - if (*pPrev == pDamage) - { - *pPrev = pDamage->pNext; - return; - } - pPrev = &(*pPrev)->pNext; - } -#if DAMAGE_VALIDATE_ENABLE - ErrorF ("Damage not on list\n"); - abort (); -#endif -} - -static void -damageInsertDamage (DamagePtr *pPrev, DamagePtr pDamage) -{ -#if DAMAGE_VALIDATE_ENABLE - DamagePtr pOld; - - for (pOld = *pPrev; pOld; pOld = pOld->pNext) - if (pOld == pDamage) { - ErrorF ("Damage already on list\n"); - abort (); - } -#endif - pDamage->pNext = *pPrev; - *pPrev = pDamage; -} - -static Bool -damageDestroyPixmap (PixmapPtr pPixmap) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - damageScrPriv(pScreen); - - if (pPixmap->refcnt == 1) - { - DamagePtr *pPrev = getPixmapDamageRef (pPixmap); - DamagePtr pDamage; - - while ((pDamage = *pPrev)) - { - damageRemoveDamage (pPrev, pDamage); - if (!pDamage->isWindow) - DamageDestroy (pDamage); - } - } - unwrap (pScrPriv, pScreen, DestroyPixmap); - (*pScreen->DestroyPixmap) (pPixmap); - wrap (pScrPriv, pScreen, DestroyPixmap, damageDestroyPixmap); - return TRUE; -} - -static void -damagePaintWindow(WindowPtr pWindow, - RegionPtr prgn, - int what) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - /* - * Painting background none doesn't actually *do* anything, so - * no damage is recorded - */ - if ((what != PW_BACKGROUND || pWindow->backgroundState != None) && - getWindowDamage (pWindow)) - damageDamageRegion (&pWindow->drawable, prgn, FALSE, -1); - if(what == PW_BACKGROUND) { - unwrap (pScrPriv, pScreen, PaintWindowBackground); - (*pScreen->PaintWindowBackground) (pWindow, prgn, what); - wrap (pScrPriv, pScreen, PaintWindowBackground, damagePaintWindow); - } else { - unwrap (pScrPriv, pScreen, PaintWindowBorder); - (*pScreen->PaintWindowBorder) (pWindow, prgn, what); - wrap (pScrPriv, pScreen, PaintWindowBorder, damagePaintWindow); - } -} - - -static void -damageCopyWindow(WindowPtr pWindow, - DDXPointRec ptOldOrg, - RegionPtr prgnSrc) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - if (getWindowDamage (pWindow)) - { - int dx = pWindow->drawable.x - ptOldOrg.x; - int dy = pWindow->drawable.y - ptOldOrg.y; - - /* - * The region comes in source relative, but the damage occurs - * at the destination location. Translate back and forth. - */ - REGION_TRANSLATE (pScreen, prgnSrc, dx, dy); - damageDamageRegion (&pWindow->drawable, prgnSrc, FALSE, -1); - REGION_TRANSLATE (pScreen, prgnSrc, -dx, -dy); - } - unwrap (pScrPriv, pScreen, CopyWindow); - (*pScreen->CopyWindow) (pWindow, ptOldOrg, prgnSrc); - wrap (pScrPriv, pScreen, CopyWindow, damageCopyWindow); -} - -GCOps damageGCOps = { - damageFillSpans, damageSetSpans, - damagePutImage, damageCopyArea, - damageCopyPlane, damagePolyPoint, - damagePolylines, damagePolySegment, - damagePolyRectangle, damagePolyArc, - damageFillPolygon, damagePolyFillRect, - damagePolyFillArc, damagePolyText8, - damagePolyText16, damageImageText8, - damageImageText16, damageImageGlyphBlt, - damagePolyGlyphBlt, damagePushPixels, -#ifdef NEED_LINEHELPER - NULL, -#endif - {NULL} /* devPrivate */ -}; - -static void -damageRestoreAreas (PixmapPtr pPixmap, - RegionPtr prgn, - int xorg, - int yorg, - WindowPtr pWindow) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - damageDamageRegion (&pWindow->drawable, prgn, FALSE, -1); - unwrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas); - (*pScreen->BackingStoreFuncs.RestoreAreas) (pPixmap, prgn, - xorg, yorg, pWindow); - wrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas, - damageRestoreAreas); -} - -static void -damageSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap) -{ - DamagePtr pDamage; - ScreenPtr pScreen = pWindow->drawable.pScreen; - damageScrPriv(pScreen); - - if ((pDamage = damageGetWinPriv(pWindow))) - { - PixmapPtr pOldPixmap = (*pScreen->GetWindowPixmap) (pWindow); - DamagePtr *pPrev = getPixmapDamageRef(pOldPixmap); - - while (pDamage) - { - damageRemoveDamage (pPrev, pDamage); - pDamage = pDamage->pNextWin; - } - } - unwrap (pScrPriv, pScreen, SetWindowPixmap); - (*pScreen->SetWindowPixmap) (pWindow, pPixmap); - wrap (pScrPriv, pScreen, SetWindowPixmap, damageSetWindowPixmap); - if ((pDamage = damageGetWinPriv(pWindow))) - { - DamagePtr *pPrev = getPixmapDamageRef(pPixmap); - - while (pDamage) - { - damageInsertDamage (pPrev, pDamage); - pDamage = pDamage->pNextWin; - } - } -} - -static Bool -damageDestroyWindow (WindowPtr pWindow) -{ - DamagePtr pDamage; - ScreenPtr pScreen = pWindow->drawable.pScreen; - Bool ret; - damageScrPriv(pScreen); - - while ((pDamage = damageGetWinPriv(pWindow))) - { - DamageUnregister (&pWindow->drawable, pDamage); - DamageDestroy (pDamage); - } - unwrap (pScrPriv, pScreen, DestroyWindow); - ret = (*pScreen->DestroyWindow) (pWindow); - wrap (pScrPriv, pScreen, DestroyWindow, damageDestroyWindow); - return ret; -} - -static Bool -damageCloseScreen (int i, ScreenPtr pScreen) -{ - damageScrPriv(pScreen); - - unwrap (pScrPriv, pScreen, DestroyPixmap); - unwrap (pScrPriv, pScreen, CreateGC); - unwrap (pScrPriv, pScreen, PaintWindowBackground); - unwrap (pScrPriv, pScreen, PaintWindowBorder); - unwrap (pScrPriv, pScreen, CopyWindow); - unwrap (pScrPriv, pScreen, CloseScreen); - unwrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas); - xfree (pScrPriv); - return (*pScreen->CloseScreen) (i, pScreen); -} - -int damageScrPrivateIndex; -int damagePixPrivateIndex; -int damageGCPrivateIndex; -int damageWinPrivateIndex; -int damageGeneration; - -Bool -DamageSetup (ScreenPtr pScreen) -{ - DamageScrPrivPtr pScrPriv; -#ifdef RENDER - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); -#endif - - if (damageGeneration != serverGeneration) - { - damageScrPrivateIndex = AllocateScreenPrivateIndex (); - if (damageScrPrivateIndex == -1) - return FALSE; - damageGCPrivateIndex = AllocateGCPrivateIndex (); - if (damageGCPrivateIndex == -1) - return FALSE; - damagePixPrivateIndex = AllocatePixmapPrivateIndex (); - if (damagePixPrivateIndex == -1) - return FALSE; - damageWinPrivateIndex = AllocateWindowPrivateIndex (); - if (damageWinPrivateIndex == -1) - return FALSE; - damageGeneration = serverGeneration; - } - if (pScreen->devPrivates[damageScrPrivateIndex].ptr) - return TRUE; - - if (!AllocateGCPrivate (pScreen, damageGCPrivateIndex, sizeof (DamageGCPrivRec))) - return FALSE; - if (!AllocatePixmapPrivate (pScreen, damagePixPrivateIndex, 0)) - return FALSE; - if (!AllocateWindowPrivate (pScreen, damageWinPrivateIndex, 0)) - return FALSE; - - pScrPriv = (DamageScrPrivPtr) xalloc (sizeof (DamageScrPrivRec)); - if (!pScrPriv) - return FALSE; - -#ifdef COMPOSITE - /* This is a kludge to ensure wrapping order with the composite wrapper. - * If it's done from compinit.c, then DamageSetup may be called before the - * extension init phase, so that cw will be higher in the wrapping chain and - * rewrite drawables before damage gets to it, causing confusion. - */ - if (!noCompositeExtension) - miInitializeCompositeWrapper (pScreen); -#endif - - pScrPriv->internalLevel = 0; - pScrPriv->pScreenDamage = 0; - - wrap (pScrPriv, pScreen, DestroyPixmap, damageDestroyPixmap); - wrap (pScrPriv, pScreen, CreateGC, damageCreateGC); - wrap (pScrPriv, pScreen, PaintWindowBackground, damagePaintWindow); - wrap (pScrPriv, pScreen, PaintWindowBorder, damagePaintWindow); - wrap (pScrPriv, pScreen, DestroyWindow, damageDestroyWindow); - wrap (pScrPriv, pScreen, SetWindowPixmap, damageSetWindowPixmap); - wrap (pScrPriv, pScreen, CopyWindow, damageCopyWindow); - wrap (pScrPriv, pScreen, CloseScreen, damageCloseScreen); - wrap (pScrPriv, pScreen, BackingStoreFuncs.RestoreAreas, - damageRestoreAreas); -#ifdef RENDER - if (ps) { - wrap (pScrPriv, ps, Glyphs, damageGlyphs); - wrap (pScrPriv, ps, Composite, damageComposite); - } -#endif - - pScreen->devPrivates[damageScrPrivateIndex].ptr = (pointer) pScrPriv; - return TRUE; -} - -DamagePtr -DamageCreate (DamageReportFunc damageReport, - DamageDestroyFunc damageDestroy, - DamageReportLevel damageLevel, - Bool isInternal, - ScreenPtr pScreen, - void *closure) -{ - DamagePtr pDamage; - - pDamage = xalloc (sizeof (DamageRec)); - if (!pDamage) - return 0; - pDamage->pNext = 0; - pDamage->pNextWin = 0; - REGION_NULL(pScreen, &pDamage->damage); - - pDamage->damageLevel = damageLevel; - pDamage->isInternal = isInternal; - pDamage->closure = closure; - pDamage->isWindow = FALSE; - pDamage->pDrawable = 0; - - pDamage->damageReport = damageReport; - pDamage->damageDestroy = damageDestroy; - return pDamage; -} - -void -DamageRegister (DrawablePtr pDrawable, - DamagePtr pDamage) -{ - if (pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pDrawable; - winDamageRef(pWindow); - -#if DAMAGE_VALIDATE_ENABLE - DamagePtr pOld; - - for (pOld = *pPrev; pOld; pOld = pOld->pNextWin) - if (pOld == pDamage) { - ErrorF ("Damage already on window list\n"); - abort (); - } -#endif - pDamage->pNextWin = *pPrev; - *pPrev = pDamage; - pDamage->isWindow = TRUE; - } - else - pDamage->isWindow = FALSE; - pDamage->pDrawable = pDrawable; - damageInsertDamage (getDrawableDamageRef (pDrawable), pDamage); -} - -void -DamageDrawInternal (ScreenPtr pScreen, Bool enable) -{ - damageScrPriv (pScreen); - - pScrPriv->internalLevel += enable ? 1 : -1; -} - -void -DamageUnregister (DrawablePtr pDrawable, - DamagePtr pDamage) -{ - if (pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pDrawable; - winDamageRef (pWindow); -#if DAMAGE_VALIDATE_ENABLE - int found = 0; -#endif - - while (*pPrev) - { - if (*pPrev == pDamage) - { - *pPrev = pDamage->pNextWin; -#if DAMAGE_VALIDATE_ENABLE - found = 1; -#endif - break; - } - pPrev = &(*pPrev)->pNextWin; - } -#if DAMAGE_VALIDATE_ENABLE - if (!found) { - ErrorF ("Damage not on window list\n"); - abort (); - } -#endif - } - pDamage->pDrawable = 0; - damageRemoveDamage (getDrawableDamageRef (pDrawable), pDamage); -} - -void -DamageDestroy (DamagePtr pDamage) -{ - if (pDamage->damageDestroy) - (*pDamage->damageDestroy) (pDamage, pDamage->closure); - REGION_UNINIT (pDamage->pDrawable->pScreen, &pDamage->damage); - xfree (pDamage); -} - -Bool -DamageSubtract (DamagePtr pDamage, - const RegionPtr pRegion) -{ - RegionPtr pClip; - RegionRec pixmapClip; - DrawablePtr pDrawable = pDamage->pDrawable; - - REGION_SUBTRACT (pDrawable->pScreen, &pDamage->damage, &pDamage->damage, pRegion); - if (pDrawable) - { - if (pDrawable->type == DRAWABLE_WINDOW) - pClip = &((WindowPtr) pDrawable)->borderClip; - else - { - BoxRec box; - - box.x1 = pDrawable->x; - box.y1 = pDrawable->y; - box.x2 = pDrawable->x + pDrawable->width; - box.y2 = pDrawable->y + pDrawable->height; - REGION_INIT (pDrawable->pScreen, &pixmapClip, &box, 1); - pClip = &pixmapClip; - } - REGION_TRANSLATE (pDrawable->pScreen, &pDamage->damage, pDrawable->x, pDrawable->y); - REGION_INTERSECT (pDrawable->pScreen, &pDamage->damage, &pDamage->damage, pClip); - REGION_TRANSLATE (pDrawable->pScreen, &pDamage->damage, -pDrawable->x, -pDrawable->y); - if (pDrawable->type != DRAWABLE_WINDOW) - REGION_UNINIT(pDrawable->pScreen, &pixmapClip); - } - return REGION_NOTEMPTY (pDrawable->pScreen, &pDamage->damage); -} - -void -DamageEmpty (DamagePtr pDamage) -{ - REGION_EMPTY (pDamage->pDrawable->pScreen, &pDamage->damage); -} - -RegionPtr -DamageRegion (DamagePtr pDamage) -{ - return &pDamage->damage; -} - -void -DamageDamageRegion (DrawablePtr pDrawable, - RegionPtr pRegion) -{ - damageDamageRegion (pDrawable, pRegion, FALSE, -1); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.NX.original deleted file mode 100644 index 69ad30d2d..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.NX.original +++ /dev/null @@ -1,4679 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XdotOrg: xc/programs/Xserver/dix/dispatch.c,v 1.13 2005/09/13 01:33:19 daniels Exp $ */ -/* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ -/************************************************************ - -Copyright 1987, 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.32 2003/11/10 18:21:45 tsi Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef PANORAMIX_DEBUG -#include -int ProcInitialConnection(); -#endif - -#ifdef __sun -#define False 0 -#define True 1 -#endif - -#define GC XlibGC -#include -#undef GC - -#include "windowstr.h" -#include -#include "dixfontstr.h" -#include "gcstruct.h" -#include "selection.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "opaque.h" -#include "input.h" -#include "servermd.h" -#include "extnsionst.h" -#include "dixfont.h" -#include "../../dix/dispatch.h" -#include "swaprep.h" -#include "swapreq.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef XAPPGROUP -#include -#endif -#ifdef XKB -#define XKB_IN_SERVER -#include "inputstr.h" -#include -#endif - -#include "Atoms.h" -#include "Splash.h" -#include "Client.h" -#include "Clipboard.h" -#include "Reconnect.h" -#include "Millis.h" -#include "Font.h" -#include "Shadow.h" -#include "Handlers.h" -#include "Keyboard.h" - -const int nxagentMaxFontNames = 10000; - -char dispatchExceptionAtReset = DE_RESET; - -/* - * This allows the agent to exit if no - * client is connected within a timeout. - */ - -int nxagentClients = 0; - -void nxagentWaitDisplay(void); - -void nxagentListRemoteFonts(const char *, int); - -unsigned int nxagentWMtimeout = 0; -Bool nxagentWMPassed = 0; - -/* - * Timeouts based on screen saver time. - */ - -int nxagentAutoDisconnectTimeout = 0; - -#ifdef LBX -#include "../../lbx/lbxserve.h" -#endif - -#include "Xatom.h" - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef WATCH - -/* - * Log begin and end of the important handlers. - */ - -#undef BLOCKS - -#ifdef WATCH -#include "unistd.h" -#endif - -#ifdef TEST -#include "Literals.h" -#endif - -#define mskcnt ((MAXCLIENTS + 31) / 32) -#define BITMASK(i) (1U << ((i) & 31)) -#define MASKIDX(i) ((i) >> 5) -#define MASKWORD(buf, i) buf[MASKIDX(i)] -#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) -#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) -#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) - -extern xConnSetupPrefix connSetupPrefix; -extern char *ConnectionInfo; - -Selection *CurrentSelections; -int NumCurrentSelections; -CallbackListPtr SelectionCallback = NULL; - -#ifdef VIEWPORT_FRAME - -extern WindowPtr nxagentViewportFrameLeft; -extern WindowPtr nxagentViewportFrameRight; -extern WindowPtr nxagentViewportFrameAbove; -extern WindowPtr nxagentViewportFrameBelow; - -#define IsViewportFrame(pWin) ((pWin) == nxagentViewportFrameLeft || \ - (pWin) == nxagentViewportFrameRight || \ - (pWin) == nxagentViewportFrameAbove || \ - (pWin) == nxagentViewportFrameBelow) - -#else - -#define IsViewportFrame(pWin) (0) - -#endif /* #ifdef VIEWPORT_FRAME */ - -extern int nxagentMaxAllowedResets; - -extern int nxagentFindClientResource(int, RESTYPE, pointer); - -static ClientPtr grabClient; -#define GrabNone 0 -#define GrabActive 1 -#define GrabKickout 2 -static int grabState = GrabNone; -static long grabWaiters[mskcnt]; -CallbackListPtr ServerGrabCallback = NULL; -HWEventQueuePtr checkForInput[2]; -extern int connBlockScreenStart; - -static void KillAllClients(void); - -static void DeleteClientFromAnySelections(ClientPtr client); - -static int nextFreeClientID; /* always MIN free client ID */ - -static int nClients; /* number of authorized clients */ - -CallbackListPtr ClientStateCallback; - -/* dispatchException & isItTimeToYield must be declared volatile since they - * are modified by signal handlers - otherwise optimizer may assume it doesn't - * need to actually check value in memory when used and may miss changes from - * signal handlers. - */ -volatile char dispatchException = 0; -volatile char isItTimeToYield; - -/* Various of the DIX function interfaces were not designed to allow - * the client->errorValue to be set on BadValue and other errors. - * Rather than changing interfaces and breaking untold code we introduce - * a new global that dispatch can use. - */ -XID clientErrorValue; /* XXX this is a kludge */ - -#define SAME_SCREENS(a, b) (\ - (a.pScreen == b.pScreen)) - -void -SetInputCheck(HWEventQueuePtr c0, HWEventQueuePtr c1) -{ - checkForInput[0] = c0; - checkForInput[1] = c1; -} - -void -UpdateCurrentTime() -{ - TimeStamp systime; - - /* To avoid time running backwards, we must call GetTimeInMillis before - * calling ProcessInputEvents. - */ - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] != *checkForInput[1]) - ProcessInputEvents(); - if (CompareTimeStamps(systime, currentTime) == LATER) - currentTime = systime; -} - -/* Like UpdateCurrentTime, but can't call ProcessInputEvents */ -void -UpdateCurrentTimeIf() -{ - TimeStamp systime; - - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] == *checkForInput[1]) - currentTime = systime; -} - -void -InitSelections() -{ - if (CurrentSelections) - xfree(CurrentSelections); - CurrentSelections = (Selection *)NULL; - NumCurrentSelections = 0; - -#ifdef NXAGENT_CLIPBOARD - { - Selection *newsels; - newsels = (Selection *)xalloc(2 * sizeof(Selection)); - if (!newsels) - return; - NumCurrentSelections += 2; - CurrentSelections = newsels; - - CurrentSelections[0].selection = XA_PRIMARY; - CurrentSelections[0].lastTimeChanged = ClientTimeToServerTime(0); - CurrentSelections[0].window = WindowTable[0]->drawable.id; - CurrentSelections[0].pWin = NULL; - CurrentSelections[0].client = NullClient; - - CurrentSelections[1].selection = MakeAtom("CLIPBOARD", 9, 1); - CurrentSelections[1].lastTimeChanged = ClientTimeToServerTime(0); - CurrentSelections[1].window = WindowTable[0]->drawable.id; - CurrentSelections[1].pWin = NULL; - CurrentSelections[1].client = NullClient; - } -#endif - -} - -void -FlushClientCaches(XID id) -{ - int i; - register ClientPtr client; - - client = clients[CLIENT_ID(id)]; - if (client == NullClient) - return ; - for (i=0; ilastDrawableID == id) - { - client->lastDrawableID = WindowTable[0]->drawable.id; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - } - else if (client->lastGCID == id) - { - client->lastGCID = INVALID; - client->lastGC = (GCPtr)NULL; - } - } - } -} -#ifdef SMART_SCHEDULE - -#undef SMART_DEBUG - -#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */ -#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */ - -Bool SmartScheduleDisable = FALSE; -long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE; -long SmartScheduleTime; -ClientPtr SmartLastClient; -int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1]; -int SmartScheduleClient(int *clientReady, int nready); - -#ifdef SMART_DEBUG -long SmartLastPrint; -#endif - -void Dispatch(void); -void InitProcVectors(void); - -int -SmartScheduleClient (int *clientReady, int nready) -{ - ClientPtr pClient; - int i; - int client; - int bestPrio, best = 0; - int bestRobin, robin; - long now = SmartScheduleTime; - long idle; - - bestPrio = -0x7fffffff; - bestRobin = 0; - idle = 2 * SmartScheduleSlice; - for (i = 0; i < nready; i++) - { - client = clientReady[i]; - pClient = clients[client]; - /* Praise clients which are idle */ - if ((now - pClient->smart_check_tick) >= idle) - { - if (pClient->smart_priority < 0) - pClient->smart_priority++; - } - pClient->smart_check_tick = now; - - /* check priority to select best client */ - robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff; - if (pClient->smart_priority > bestPrio || - (pClient->smart_priority == bestPrio && robin > bestRobin)) - { - bestPrio = pClient->smart_priority; - bestRobin = robin; - best = client; - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - fprintf (stderr, " %2d: %3d", client, pClient->smart_priority); -#endif - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - { - fprintf (stderr, " use %2d\n", best); - SmartLastPrint = now; - } -#endif - pClient = clients[best]; - SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index; - /* - * Set current client pointer - */ - if (SmartLastClient != pClient) - { - pClient->smart_start_tick = now; - SmartLastClient = pClient; - } - /* - * Adjust slice - */ - if (nready == 1) - { - /* - * If it's been a long time since another client - * has run, bump the slice up to get maximal - * performance from a single client - */ - if ((now - pClient->smart_start_tick) > 1000 && - SmartScheduleSlice < SmartScheduleMaxSlice) - { - SmartScheduleSlice += SmartScheduleInterval; - } - } - else - { - SmartScheduleSlice = SmartScheduleInterval; - } - return best; -} -#endif - -#define MAJOROP ((xReq *)client->requestBuffer)->reqType - -void -Dispatch(void) -{ - register int *clientReady; /* array of request ready clients */ - register int result; - register ClientPtr client; - register int nready; - register HWEventQueuePtr* icheck = checkForInput; -#ifdef SMART_SCHEDULE - long start_tick; -#endif - - unsigned long currentDispatch = 0; - - nextFreeClientID = 1; - InitSelections(); - nClients = 0; - - /* - * The agent initialization was successfully - * completed. We can now handle our clients. - */ - - #ifdef XKB - - nxagentInitXkbWrapper(); - - nxagentTuneXkbWrapper(); - - #endif - - #ifdef NXAGENT_ONSTART - - /* - * Set NX_WM property (used by NX client to identify - * the agent's window) three seconds since the first - * client connects. - */ - - nxagentWMtimeout = GetTimeInMillis() + 3000; - - #endif - - clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients); - if (!clientReady) - return; - - #ifdef WATCH - - fprintf(stderr, "Dispatch: Watchpoint 12.\n"); - -/* -Reply Total Cached Bits In Bits Out Bits/Reply Ratio -------- ----- ------ ------- -------- ---------- ----- -#3 1 352 bits (0 KB) -> 236 bits (0 KB) -> 352/1 -> 236/1 = 1.492:1 -#14 1 256 bits (0 KB) -> 101 bits (0 KB) -> 256/1 -> 101/1 = 2.535:1 -#16 1 256 bits (0 KB) -> 26 bits (0 KB) -> 256/1 -> 26/1 = 9.846:1 -#20 2 2 12256 bits (1 KB) -> 56 bits (0 KB) -> 6128/1 -> 28/1 = 218.857:1 -#43 1 256 bits (0 KB) -> 45 bits (0 KB) -> 256/1 -> 45/1 = 5.689:1 -#47 2 2 42304 bits (5 KB) -> 49 bits (0 KB) -> 21152/1 -> 24/1 = 863.347:1 -#98 1 256 bits (0 KB) -> 34 bits (0 KB) -> 256/1 -> 34/1 = 7.529:1 -*/ - - sleep(30); - - #endif - - #ifdef TEST - fprintf(stderr, "Dispatch: Value of dispatchException is [%x].\n", - dispatchException); - - fprintf(stderr, "Dispatch: Value of dispatchExceptionAtReset is [%x].\n", - dispatchExceptionAtReset); - #endif - - if (!(dispatchException & DE_TERMINATE)) - dispatchException = 0; - - while (!dispatchException) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } - - /* - * Ensure we remove the splash after the timeout. - * Initializing clientReady[0] to -1 will tell - * WaitForSomething() to yield control after the - * timeout set in clientReady[1]. - */ - - clientReady[0] = 0; - - if (nxagentSplashWindow != None || (nxagentOption(Xdmcp) == 1 && nxagentXdmcpUp == 0)) - { - #ifdef TEST - fprintf(stderr, "******Dispatch: Requesting a timeout of [%d] Ms.\n", - NXAGENT_WAKEUP); - #endif - - clientReady[0] = -1; - clientReady[1] = NXAGENT_WAKEUP; - } - - if (serverGeneration > nxagentMaxAllowedResets && - nxagentSessionState == SESSION_STARTING && - (nxagentOption(Xdmcp) == 0 || nxagentXdmcpUp == 1)) - { - #ifdef NX_DEBUG_INPUT - fprintf(stderr, "Session: Session started at '%s' timestamp [%lu].\n", - GetTimeAsString(), GetTimeInMillis()); - #else - fprintf(stderr, "Session: Session started at '%s'.\n", - GetTimeAsString()); - #endif - - nxagentSessionState = SESSION_UP; - } - - #ifdef BLOCKS - fprintf(stderr, "[End dispatch]\n"); - #endif - - nready = WaitForSomething(clientReady); - - #ifdef BLOCKS - fprintf(stderr, "[Begin dispatch]\n"); - #endif - - #ifdef TEST - fprintf(stderr, "******Dispatch: Running with [%d] clients ready.\n", - nready); - #endif - - #ifdef NXAGENT_ONSTART - - currentDispatch = GetTimeInMillis(); - - /* - * If the timeout is expired set the - * selection informing the NX client - * that the agent is ready. - */ - - if (!nxagentWMPassed && (nxagentWMtimeout < currentDispatch)) - { - nxagentRemoveSplashWindow(NULL); - } - - nxagentClients = nClients; - - #endif - -#ifdef SMART_SCHEDULE - if (nready && !SmartScheduleDisable) - { - clientReady[0] = SmartScheduleClient (clientReady, nready); - nready = 1; - } -#endif - /***************** - * Handle events in round robin fashion, doing input between - * each round - *****************/ - - while (!dispatchException && (--nready >= 0)) - { - client = clients[clientReady[nready]]; - if (! client) - { - /* KillClient can cause this to happen */ - continue; - } - /* GrabServer activation can cause this to be true */ - if (grabState == GrabKickout) - { - grabState = GrabActive; - break; - } - isItTimeToYield = FALSE; - - requestingClient = client; -#ifdef SMART_SCHEDULE - start_tick = SmartScheduleTime; -#endif - while (!isItTimeToYield) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } -#ifdef SMART_SCHEDULE - if (!SmartScheduleDisable && - (SmartScheduleTime - start_tick) >= SmartScheduleSlice) - { - /* Penalize clients which consume ticks */ - if (client->smart_priority > SMART_MIN_PRIORITY) - client->smart_priority--; - break; - } -#endif - /* now, finally, deal with client requests */ - - #ifdef TEST - fprintf(stderr, "******Dispatch: Reading request from client [%d].\n", - client->index); - #endif - - result = ReadRequestFromClient(client); - if (result <= 0) - { - if (result < 0) - CloseDownClient(client); - break; - } -#ifdef NXAGENT_SERVER - - #ifdef TEST - - else - { - - if (MAJOROP > 127) - { - fprintf(stderr, "******Dispatch: Read [Extension] request OPCODE#%d MINOR#%d " - "size [%d] client [%d].\n", MAJOROP, *((char *) client->requestBuffer + 1), - client->req_len << 2, client->index); - } - else - { - fprintf(stderr, "******Dispatch: Read [%s] request OPCODE#%d size [%d] client [%d].\n", - nxagentRequestLiteral[MAJOROP], MAJOROP, client->req_len << 2, - client->index); - } - } - - #endif -#endif - - client->sequence++; -#ifdef DEBUG - if (client->requestLogIndex == MAX_REQUEST_LOG) - client->requestLogIndex = 0; - client->requestLog[client->requestLogIndex] = MAJOROP; - client->requestLogIndex++; -#endif - if (result > (maxBigRequestSize << 2)) - result = BadLength; - else -#ifdef NXAGENT_SERVER - { - result = (* client->requestVector[MAJOROP])(client); - - #ifdef TEST - - if (MAJOROP > 127) - { - fprintf(stderr, "******Dispatch: Handled [Extension] request OPCODE#%d MINOR#%d " - "size [%d] client [%d] result [%d].\n", MAJOROP, - *((char *) client->requestBuffer + 1), client->req_len << 2, - client->index, result); - } - else - { - fprintf(stderr, "******Dispatch: Handled [%s] request OPCODE#%d size [%d] client [%d] " - "result [%d].\n", nxagentRequestLiteral[MAJOROP], MAJOROP, - client->req_len << 2, client->index, result); - } - - #endif - - /* - * Can set isItTimeToYield to force - * the dispatcher to pay attention - * to another client. - */ - - nxagentDispatchHandler(client, client->req_len << 2, 0); - } -#else - result = (* client->requestVector[MAJOROP])(client); -#endif - - if (result != Success) - { - if (client->noClientException != Success) - CloseDownClient(client); - else - SendErrorToClient(client, MAJOROP, - MinorOpcodeOfRequest(client), - client->errorValue, result); - break; - } -#ifdef DAMAGEEXT - FlushIfCriticalOutputPending (); -#endif - } - FlushAllOutput(); -#ifdef SMART_SCHEDULE - client = clients[clientReady[nready]]; - if (client) - client->smart_stop_tick = SmartScheduleTime; -#endif - requestingClient = NULL; - } - dispatchException &= ~DE_PRIORITYCHANGE; - } -#if defined(DDXBEFORERESET) - ddxBeforeReset (); -#endif - if ((dispatchException & DE_RESET) && - (serverGeneration > nxagentMaxAllowedResets)) - { - dispatchException &= ~DE_RESET; - dispatchException |= DE_TERMINATE; - - fprintf(stderr, "Info: Reached threshold of maximum allowed resets.\n"); - } - - nxagentResetAtomMap(); - - if (serverGeneration > nxagentMaxAllowedResets) - { - /* - * The session is terminating. Force an I/O - * error on the display and wait until the - * NX transport is gone. - */ - - fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString()); - - nxagentWaitDisplay(); - - fprintf(stderr, "Session: Session terminated at '%s'.\n", GetTimeAsString()); - } - - if (nxagentOption(Shadow) == 1) - { - NXShadowDestroy(); - } - - KillAllClients(); - DEALLOCATE_LOCAL(clientReady); - dispatchException &= ~DE_RESET; -} - -#undef MAJOROP - -int -ProcBadRequest(ClientPtr client) -{ - return (BadRequest); -} - -int -ProcCreateWindow(ClientPtr client) -{ - register WindowPtr pParent, pWin; - REQUEST(xCreateWindowReq); - int result; - int len; - - REQUEST_AT_LEAST_SIZE(xCreateWindowReq); - - LEGAL_NEW_RESOURCE(stuff->wid, client); - if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess))) - return BadWindow; - len = client->req_len - (sizeof(xCreateWindowReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - pWin = CreateWindow(stuff->wid, pParent, stuff->x, - stuff->y, stuff->width, stuff->height, - stuff->borderWidth, stuff->class, - stuff->mask, (XID *) &stuff[1], - (int)stuff->depth, - client, stuff->visual, &result); - if (pWin) - { - Mask mask = pWin->eventMask; - - pWin->eventMask = 0; /* subterfuge in case AddResource fails */ - if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin)) - return BadAlloc; - pWin->eventMask = mask; - } - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcChangeWindowAttributes(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xChangeWindowAttributesReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2); - if (len != Ones(stuff->valueMask)) - return BadLength; - result = ChangeWindowAttributes(pWin, - stuff->valueMask, - (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcGetWindowAttributes(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - xGetWindowAttributesReply wa; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - GetWindowAttributes(pWin, client, &wa); - WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa); - return(client->noClientException); -} - -int -ProcDestroyWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - if (pWin->parent) - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcDestroySubwindows(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - DestroySubwindows(pWin, client); - return(client->noClientException); -} - -int -ProcChangeSaveSet(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xChangeSaveSetReq); - register int result; - - REQUEST_SIZE_MATCH(xChangeSaveSetReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) - return BadMatch; - if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete)) - { - result = AlterSaveSetForClient(client, pWin, stuff->mode, FALSE, TRUE); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->mode; - return( BadValue ); - } -} - -int -ProcReparentWindow(register ClientPtr client) -{ - register WindowPtr pWin, pParent; - REQUEST(xReparentWindowReq); - register int result; - - REQUEST_SIZE_MATCH(xReparentWindowReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - - if (!nxagentWMPassed) - { - nxagentRemoveSplashWindow(pWin); - } - - pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess); - if (!pParent) - return(BadWindow); - if (SAME_SCREENS(pWin->drawable, pParent->drawable)) - { - if ((pWin->backgroundState == ParentRelative) && - (pParent->drawable.depth != pWin->drawable.depth)) - return BadMatch; - if ((pWin->drawable.class != InputOnly) && - (pParent->drawable.class == InputOnly)) - return BadMatch; - result = ReparentWindow(pWin, pParent, - (short)stuff->x, (short)stuff->y, client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - return (BadMatch); -} - -int -ProcMapWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapWindow(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcMapSubwindows(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapSubwindows(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcUnmapWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapWindow(pWin, FALSE); - /* update cache to say it is mapped */ - - return(client->noClientException); -} - -int -ProcUnmapSubwindows(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapSubwindows(pWin); - return(client->noClientException); -} - -int -ProcConfigureWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xConfigureWindowReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xConfigureWindowReq) >> 2); - if (Ones((Mask)stuff->mask) != len) - return BadLength; - result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], - client); - - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcCirculateWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xCirculateWindowReq); - - REQUEST_SIZE_MATCH(xCirculateWindowReq); - if ((stuff->direction != RaiseLowest) && - (stuff->direction != LowerHighest)) - { - client->errorValue = stuff->direction; - return BadValue; - } - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - CirculateWindow(pWin, (int)stuff->direction, client); - return(client->noClientException); -} - -int -GetGeometry(register ClientPtr client, xGetGeometryReply *rep) -{ - register DrawablePtr pDraw; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess); - rep->type = X_Reply; - rep->length = 0; - rep->sequenceNumber = client->sequence; - rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - rep->depth = pDraw->depth; - rep->width = pDraw->width; - rep->height = pDraw->height; - - /* XXX - Because the pixmap-implementation of the multibuffer extension - * may have the buffer-id's drawable resource value be a pointer - * to the buffer's window instead of the buffer itself - * (this happens if the buffer is the displayed buffer), - * we also have to check that the id matches before we can - * truly say that it is a DRAWABLE_WINDOW. - */ - - if ((pDraw->type == UNDRAWABLE_WINDOW) || - ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id))) - { - register WindowPtr pWin = (WindowPtr)pDraw; - rep->x = pWin->origin.x - wBorderWidth (pWin); - rep->y = pWin->origin.y - wBorderWidth (pWin); - rep->borderWidth = pWin->borderWidth; - } - else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */ - { - rep->x = rep->y = rep->borderWidth = 0; - } - - return Success; -} - - -int -ProcGetGeometry(register ClientPtr client) -{ - xGetGeometryReply rep; - int status; - - if ((status = GetGeometry(client, &rep)) != Success) - return status; - - WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); - return(client->noClientException); -} - - -int -ProcQueryTree(register ClientPtr client) -{ - xQueryTreeReply reply; - int numChildren = 0; - register WindowPtr pChild, pWin, pHead; - Window *childIDs = (Window *)NULL; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - reply.type = X_Reply; - reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - reply.sequenceNumber = client->sequence; - if (pWin->parent) - reply.parent = pWin->parent->drawable.id; - else - reply.parent = (Window)None; - pHead = RealChildHead(pWin); - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (!IsViewportFrame(pChild)) - { - numChildren++; - } - } - if (numChildren) - { - int curChild = 0; - - childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window)); - if (!childIDs) - return BadAlloc; - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (!IsViewportFrame(pChild)) - { - childIDs[curChild++] = pChild->drawable.id; - } - } - } - - reply.nChildren = numChildren; - reply.length = (numChildren * sizeof(Window)) >> 2; - - WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply); - if (numChildren) - { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs); - DEALLOCATE_LOCAL(childIDs); - } - - return(client->noClientException); -} - -int -ProcInternAtom(register ClientPtr client) -{ - Atom atom; - char *tchar; - REQUEST(xInternAtomReq); - - REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes); - if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse)) - { - client->errorValue = stuff->onlyIfExists; - return(BadValue); - } - tchar = (char *) &stuff[1]; - atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists); - if (atom != BAD_RESOURCE) - { - xInternAtomReply reply; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.atom = atom; - WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); - return(client->noClientException); - } - else - return (BadAlloc); -} - -int -ProcGetAtomName(register ClientPtr client) -{ - char *str; - xGetAtomNameReply reply; - int len; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if ( (str = NameForAtom(stuff->id)) ) - { - len = strlen(str); - reply.type = X_Reply; - reply.length = (len + 3) >> 2; - reply.sequenceNumber = client->sequence; - reply.nameLength = len; - WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); - (void)WriteToClient(client, len, str); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -#ifdef K5AUTH -extern int k5_bad(); -#endif - -int -ProcSetSelectionOwner(register ClientPtr client) -{ - WindowPtr pWin; - TimeStamp time; - REQUEST(xSetSelectionOwnerReq); - - REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); - UpdateCurrentTime(); - time = ClientTimeToServerTime(stuff->time); - - /* If the client's time stamp is in the future relative to the server's - time stamp, do not set the selection, just return success. */ - if (CompareTimeStamps(time, currentTime) == LATER) - return Success; - if (stuff->window != None) - { - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - } - else - pWin = (WindowPtr)None; - if (ValidAtom(stuff->selection)) - { - int i = 0; - - /* - * First, see if the selection is already set... - */ - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) - i++; - if (i < NumCurrentSelections) - { - xEvent event; - - /* If the timestamp in client's request is in the past relative - to the time stamp indicating the last time the owner of the - selection was set, do not set the selection, just return - success. */ - if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged) - == EARLIER) - return Success; - if (CurrentSelections[i].client && - (!pWin || (CurrentSelections[i].client != client))) - { - event.u.u.type = SelectionClear; - event.u.selectionClear.time = time.milliseconds; - event.u.selectionClear.window = CurrentSelections[i].window; - event.u.selectionClear.atom = CurrentSelections[i].selection; - (void) TryClientEvents (CurrentSelections[i].client, &event, 1, - NoEventMask, NoEventMask /* CantBeFiltered */, - NullGrab); - } - } - else - { - /* - * It doesn't exist, so add it... - */ - Selection *newsels; - - if (i == 0) - newsels = (Selection *)xalloc(sizeof(Selection)); - else - newsels = (Selection *)xrealloc(CurrentSelections, - (NumCurrentSelections + 1) * sizeof(Selection)); - if (!newsels) - return BadAlloc; - NumCurrentSelections++; - CurrentSelections = newsels; - CurrentSelections[i].selection = stuff->selection; - } - CurrentSelections[i].lastTimeChanged = time; - CurrentSelections[i].window = stuff->window; - CurrentSelections[i].pWin = pWin; - CurrentSelections[i].client = (pWin ? client : NullClient); - if (SelectionCallback) - { - SelectionInfoRec info; - - info.selection = &CurrentSelections[i]; - info.kind= SelectionSetOwner; - CallCallbacks(&SelectionCallback, &info); - } - -#ifdef NXAGENT_CLIPBOARD - if ((CurrentSelections[i].pWin != NULL) && - (nxagentOption(Clipboard) != ClipboardNone) && - ((CurrentSelections[i].selection == XA_PRIMARY) || - (CurrentSelections[i].selection == MakeAtom("CLIPBOARD", 9, 0)))) - { - nxagentSetSelectionOwner(&CurrentSelections[i]); - } -#endif - return (client->noClientException); - } - else - { - client->errorValue = stuff->selection; - return (BadAtom); - } -} - -int -ProcGetSelectionOwner(register ClientPtr client) -{ - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if (ValidAtom(stuff->id)) - { - int i; - xGetSelectionOwnerReply reply; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->id) i++; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - if (i < NumCurrentSelections) - reply.owner = CurrentSelections[i].window; - else - reply.owner = None; - WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -int -ProcConvertSelection(register ClientPtr client) -{ - Bool paramsOkay; - xEvent event; - WindowPtr pWin; - REQUEST(xConvertSelectionReq); - - REQUEST_SIZE_MATCH(xConvertSelectionReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - -#ifdef NXAGENT_CLIPBOARD - if (((stuff->selection == XA_PRIMARY) || - (stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) && - nxagentOption(Clipboard) != ClipboardNone) - { - int i = 0; - - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - - if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None)) - { - if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor, - stuff->property, stuff->target, stuff->time)) - { - return (client->noClientException); - } - } - } -#endif - - paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target)); - if (stuff->property != None) - paramsOkay &= ValidAtom(stuff->property); - if (paramsOkay) - { - int i; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - if ((i < NumCurrentSelections) && - (CurrentSelections[i].window != None) && (CurrentSelections[i].client != NullClient) -#ifdef XCSECURITY - && (!client->CheckAccess || - (* client->CheckAccess)(client, CurrentSelections[i].window, - RT_WINDOW, SecurityReadAccess, - CurrentSelections[i].pWin)) -#endif - ) - { - event.u.u.type = SelectionRequest; - event.u.selectionRequest.time = stuff->time; - event.u.selectionRequest.owner = - CurrentSelections[i].window; - event.u.selectionRequest.requestor = stuff->requestor; - event.u.selectionRequest.selection = stuff->selection; - event.u.selectionRequest.target = stuff->target; - event.u.selectionRequest.property = stuff->property; - if (TryClientEvents( - CurrentSelections[i].client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab)) - return (client->noClientException); - } - event.u.u.type = SelectionNotify; - event.u.selectionNotify.time = stuff->time; - event.u.selectionNotify.requestor = stuff->requestor; - event.u.selectionNotify.selection = stuff->selection; - event.u.selectionNotify.target = stuff->target; - event.u.selectionNotify.property = None; - (void) TryClientEvents(client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab); - return (client->noClientException); - } - else - { - client->errorValue = stuff->property; - return (BadAtom); - } -} - -int -ProcGrabServer(register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xReq); - if (grabState != GrabNone && client != grabClient) - { - ResetCurrentRequest(client); - client->sequence--; - BITSET(grabWaiters, client->index); - IgnoreClient(client); - return(client->noClientException); - } - OnlyListenToOneClient(client); - grabState = GrabKickout; - grabClient = client; - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_GRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } - - return(client->noClientException); -} - -static void -UngrabServer(ClientPtr client) -{ - int i; - - grabState = GrabNone; - ListenToAllClients(); - for (i = mskcnt; --i >= 0 && !grabWaiters[i]; ) - ; - if (i >= 0) - { - i <<= 5; - while (!GETBIT(grabWaiters, i)) - i++; - BITCLEAR(grabWaiters, i); - AttendClient(clients[i]); - } - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_UNGRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } -} - -int -ProcUngrabServer(register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xReq); - UngrabServer(client); - return(client->noClientException); -} - -int -ProcTranslateCoords(register ClientPtr client) -{ - REQUEST(xTranslateCoordsReq); - - register WindowPtr pWin, pDst; - xTranslateCoordsReply rep; - - REQUEST_SIZE_MATCH(xTranslateCoordsReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client, - SecurityReadAccess); - if (!pDst) - return(BadWindow); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) - { - rep.sameScreen = xFalse; - rep.child = None; - rep.dstX = rep.dstY = 0; - } - else - { - INT16 x, y; - rep.sameScreen = xTrue; - rep.child = None; - /* computing absolute coordinates -- adjust to destination later */ - x = pWin->drawable.x + stuff->srcX; - y = pWin->drawable.y + stuff->srcY; - pWin = pDst->firstChild; - while (pWin) - { -#ifdef SHAPE - BoxRec box; -#endif - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth (pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - &pWin->borderSize, x, y, &box)) - - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) -#endif - ) - { - rep.child = pWin->drawable.id; - pWin = (WindowPtr) NULL; - } - else - pWin = pWin->nextSib; - } - /* adjust to destination coordinates */ - rep.dstX = x - pDst->drawable.x; - rep.dstY = y - pDst->drawable.y; - } - WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep); - return(client->noClientException); -} - -int -ProcOpenFont(register ClientPtr client) -{ - int err; - char fontReq[256]; - REQUEST(xOpenFontReq); - - REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes); - client->errorValue = stuff->fid; - LEGAL_NEW_RESOURCE(stuff->fid, client); - - memcpy(fontReq,(char *)&stuff[1],(stuff->nbytes<256)?stuff->nbytes:255); - fontReq[stuff->nbytes]=0; - if (strchr(fontReq,'*') || strchr(fontReq,'?')) - { - extern int nxOpenFont(ClientPtr, XID, Mask, unsigned, char*); -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Dispatch: ProcOpenFont try to find a common font with font pattern=%s\n",fontReq); -#endif - nxagentListRemoteFonts(fontReq, nxagentMaxFontNames); - err = nxOpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - } - else - err = OpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcCloseFont(register ClientPtr client) -{ - FontPtr pFont; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityDestroyAccess); - if (pFont != (FontPtr)NULL) - { - #ifdef NXAGENT_SERVER - - /* - * When a client closes a font the resource - * should not be lost if the reference counter - * is not 0, otherwise the server will not be - * able to find this font looping through the - * resources. - */ - - if (pFont -> refcnt > 0) - { - if (nxagentFindClientResource(serverClient -> index, RT_NX_FONT, pFont) == 0) - { - #ifdef TEST - fprintf(stderr, "ProcCloseFont: Switching resource for font at [%p].\n", - (void *) pFont); - #endif - - nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index); - - AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont); - - } - #ifdef TEST - else - { - fprintf(stderr, "ProcCloseFont: Found duplicated font at [%p], " - "resource switching skipped.\n", (void *) pFont); - } - #endif - } - - #endif - - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadFont); - } -} - -int -ProcQueryFont(register ClientPtr client) -{ - xQueryFontReply *reply; - FontPtr pFont; - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - client->errorValue = stuff->id; /* EITHER font or gc */ - - pFont = NULL; - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - /* can't use VERIFY_GC because it might return BadGC */ - pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->id; - return(BadFont); /* procotol spec says only error is BadFont */ - } - pFont = pGC->font; - } - -/* test -{ - Atom name_atom, value_atom; - int nprops; - FontPropPtr props; - int i; - char *name; - - name_atom = MakeAtom("FONT", 4, True); - value_atom = 0L; - - nprops = pFont->info.nprops; - props = pFont->info.props; - - for (i = 0; i < nprops; i++) - if (props[i].name == name_atom) { - value_atom = props[i].value; - break; - } - - if (!value_atom) return (BadFont); - - name = (char *)NameForAtom(value_atom); - fprintf(stderr, "QueryFont: font name [%s]\n",name); -} - end test */ - - { - xCharInfo *pmax = FONTINKMAX(pFont); - xCharInfo *pmin = FONTINKMIN(pFont); - int nprotoxcistructs; - int rlength; - - nprotoxcistructs = ( - pmax->rightSideBearing == pmin->rightSideBearing && - pmax->leftSideBearing == pmin->leftSideBearing && - pmax->descent == pmin->descent && - pmax->ascent == pmin->ascent && - pmax->characterWidth == pmin->characterWidth) ? - 0 : N2dChars(pFont); - - rlength = sizeof(xQueryFontReply) + - FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) + - nprotoxcistructs * sizeof(xCharInfo); - reply = NULL; - reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength); - if(!reply) - { - return(BadAlloc); - } - - reply->type = X_Reply; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->sequenceNumber = client->sequence; - QueryFont( pFont, reply, nprotoxcistructs); - - WriteReplyToClient(client, rlength, reply); - DEALLOCATE_LOCAL(reply); - return(client->noClientException); - } -} - -int -ProcQueryTextExtents(register ClientPtr client) -{ - REQUEST(xQueryTextExtentsReq); - xQueryTextExtentsReply reply; - FontPtr pFont; - GC *pGC; - ExtentInfoRec info; - unsigned long length; - - REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); - - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->fid; - return(BadFont); - } - pFont = pGC->font; - } - length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2); - length = length << 1; - if (stuff->oddLength) - { - if (length == 0) - return(BadLength); - length--; - } - if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info)) - return(BadAlloc); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.drawDirection = info.drawDirection; - reply.fontAscent = info.fontAscent; - reply.fontDescent = info.fontDescent; - reply.overallAscent = info.overallAscent; - reply.overallDescent = info.overallDescent; - reply.overallWidth = info.overallWidth; - reply.overallLeft = info.overallLeft; - reply.overallRight = info.overallRight; - WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply); - return(client->noClientException); -} - -int -ProcListFonts(register ClientPtr client) -{ - char tmp[256]; - - REQUEST(xListFontsReq); - - REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes); - memcpy(tmp,(unsigned char *) &stuff[1],(stuff->nbytes<256)?stuff->nbytes:255); - tmp[stuff->nbytes]=0; - -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Dispatch: ListFont request with pattern %s max_names=%d\n",tmp,stuff->maxNames); -#endif - nxagentListRemoteFonts(tmp, stuff -> maxNames < nxagentMaxFontNames ? nxagentMaxFontNames : stuff->maxNames); - return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, - stuff->maxNames); -} - -int -ProcListFontsWithInfo(register ClientPtr client) -{ - char tmp[256]; - REQUEST(xListFontsWithInfoReq); - - REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes); - - memcpy(tmp,(unsigned char *) &stuff[1],(stuff->nbytes<256)?stuff->nbytes:255); - tmp[stuff->nbytes]=0; -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Dispatch: ListFont with info request with pattern %s max_names=%d\n",tmp,stuff->maxNames); -#endif - nxagentListRemoteFonts(tmp, stuff -> maxNames < nxagentMaxFontNames ? nxagentMaxFontNames :stuff->maxNames); - - return StartListFontsWithInfo(client, stuff->nbytes, - (unsigned char *) &stuff[1], stuff->maxNames); -} - -/** - * - * \param value must conform to DeleteType - */ -int -dixDestroyPixmap(pointer value, XID pid) -{ - PixmapPtr pPixmap = (PixmapPtr)value; - return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); -} - -int -ProcCreatePixmap(register ClientPtr client) -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - REQUEST(xCreatePixmapReq); - DepthPtr pDepth; - register int i; - - REQUEST_SIZE_MATCH(xCreatePixmapReq); - client->errorValue = stuff->pid; - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->width > 32767 || stuff->height > 32767) - { - /* It is allowed to try and allocate a pixmap which is larger than - * 32767 in either dimension. However, all of the framebuffer code - * is buggy and does not reliably draw to such big pixmaps, basically - * because the Region data structure operates with signed shorts - * for the rectangles in it. - * - * Furthermore, several places in the X server computes the - * size in bytes of the pixmap and tries to store it in an - * integer. This integer can overflow and cause the allocated size - * to be much smaller. - * - * So, such big pixmaps are rejected here with a BadAlloc - */ - return BadAlloc; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap) - (pDraw->pScreen, stuff->width, - stuff->height, stuff->depth); - if (pMap) - { - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - return(client->noClientException); - } - return (BadAlloc); -} - -int -ProcFreePixmap(register ClientPtr client) -{ - PixmapPtr pMap; - - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP, - SecurityDestroyAccess); - if (pMap) - { - #ifdef NXAGENT_SERVER - - /* - * When a client releases a pixmap the resource - * should not be lost if the reference counter - * is not 0, otherwise the server will not be - * able to find this pixmap looping through the - * resources. - */ - - if (pMap -> refcnt > 0) - { - if (nxagentFindClientResource(serverClient -> index, RT_NX_PIXMAP, pMap) == 0) - { - #ifdef TEST - fprintf(stderr, "ProcFreePixmap: Switching resource for pixmap at [%p].\n", - (void *) pMap); - #endif - - nxagentPixmapPriv(pMap) -> mid = FakeClientID(serverClient -> index); - - AddResource(nxagentPixmapPriv(pMap) -> mid, RT_NX_PIXMAP, pMap); - } - #ifdef TEST - else - { - fprintf(stderr, "ProcFreePixmap: Found duplicated pixmap at [%p], " - "resource switching skipped.\n", (void *) pMap); - } - #endif - } - - #endif - - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadPixmap); - } -} - -int -ProcCreateGC(register ClientPtr client) -{ - int error; - GC *pGC; - register DrawablePtr pDraw; - unsigned len; - REQUEST(xCreateGCReq); - - REQUEST_AT_LEAST_SIZE(xCreateGCReq); - client->errorValue = stuff->gc; - LEGAL_NEW_RESOURCE(stuff->gc, client); - SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - len = client->req_len - (sizeof(xCreateGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - pGC = (GC *)CreateGC(pDraw, stuff->mask, - (XID *) &stuff[1], &error); - if (error != Success) - return error; - if (!AddResource(stuff->gc, RT_GC, (pointer)pGC)) - return (BadAlloc); - return(client->noClientException); -} - -int -ProcChangeGC(register ClientPtr client) -{ - GC *pGC; - REQUEST(xChangeGCReq); - int result; - unsigned len; - - REQUEST_AT_LEAST_SIZE(xChangeGCReq); - SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess); - len = client->req_len - (sizeof(xChangeGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - - result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcCopyGC(register ClientPtr client) -{ - register GC *dstGC; - register GC *pGC; - int result; - REQUEST(xCopyGCReq); - - REQUEST_SIZE_MATCH(xCopyGCReq); - SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess); - SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess); - if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth)) - return (BadMatch); - result = CopyGC(pGC, dstGC, stuff->mask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetDashes(register ClientPtr client) -{ - register GC *pGC; - int result; - REQUEST(xSetDashesReq); - - REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes); - if (stuff->nDashes == 0) - { - client->errorValue = 0; - return BadValue; - } - - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes, - (unsigned char *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetClipRectangles(register ClientPtr client) -{ - int nr; - int result; - register GC *pGC; - REQUEST(xSetClipRectanglesReq); - - REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq); - if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && - (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) - { - client->errorValue = stuff->ordering; - return BadValue; - } - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq); - if (nr & 4) - return(BadLength); - nr >>= 3; - result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *)&stuff[1], (int)stuff->ordering); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcFreeGC(register ClientPtr client) -{ - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess); - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcClearToBackground(register ClientPtr client) -{ - REQUEST(xClearAreaReq); - register WindowPtr pWin; - - REQUEST_SIZE_MATCH(xClearAreaReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (pWin->drawable.class == InputOnly) - { - client->errorValue = stuff->window; - return (BadMatch); - } - if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) - { - client->errorValue = stuff->exposures; - return(BadValue); - } - (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y, - stuff->width, stuff->height, - (Bool)stuff->exposures); - return(client->noClientException); -} - -int -ProcCopyArea(register ClientPtr client) -{ - register DrawablePtr pDst; - register DrawablePtr pSrc; - register GC *pGC; - REQUEST(xCopyAreaReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyAreaReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client, - SecurityReadAccess); - if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - pSrc = pDst; - - SET_DBE_SRCBUF(pSrc, stuff->srcDrawable); - - pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY); - if (pGC->graphicsExposures) - { - (*pDst->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); - if (pRgn) - REGION_DESTROY(pDst->pScreen, pRgn); - } - - return(client->noClientException); -} - -int -ProcCopyPlane(register ClientPtr client) -{ - register DrawablePtr psrcDraw, pdstDraw; - register GC *pGC; - REQUEST(xCopyPlaneReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyPlaneReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client, - SecurityReadAccess); - if (pdstDraw->pScreen != psrcDraw->pScreen) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - psrcDraw = pdstDraw; - - SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable); - - /* Check to see if stuff->bitPlane has exactly ONE good bit set */ - if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || - (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) - { - client->errorValue = stuff->bitPlane; - return(BadValue); - } - - pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY, stuff->bitPlane); - if (pGC->graphicsExposures) - { - (*pdstDraw->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); - if (pRgn) - REGION_DESTROY(pdstDraw->pScreen, pRgn); - } - return(client->noClientException); -} - -int -ProcPolyPoint(register ClientPtr client) -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyPointReq); - - REQUEST_AT_LEAST_SIZE(xPolyPointReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2; - if (npoint) - { - (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, - (xPoint *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcPolyLine(register ClientPtr client) -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyLineReq); - - REQUEST_AT_LEAST_SIZE(xPolyLineReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2; - if (npoint > 1) - { - (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, - (DDXPointPtr) &stuff[1]); - } - return(client->noClientException); -} - -int -ProcPolySegment(register ClientPtr client) -{ - int nsegs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolySegmentReq); - - REQUEST_AT_LEAST_SIZE(xPolySegmentReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); - if (nsegs & 4) - return(BadLength); - nsegs >>= 3; - if (nsegs) - { - (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcPolyRectangle (register ClientPtr client) -{ - int nrects; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); - if (nrects & 4) - return(BadLength); - nrects >>= 3; - if (nrects) - { - (*pGC->ops->PolyRectangle)(pDraw, pGC, - nrects, (xRectangle *) &stuff[1]); - } - return(client->noClientException); -} - -int -ProcPolyArc(register ClientPtr client) -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - { - (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcFillPoly(register ClientPtr client) -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xFillPolyReq); - - REQUEST_AT_LEAST_SIZE(xFillPolyReq); - if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) && - (stuff->shape != Convex)) - { - client->errorValue = stuff->shape; - return BadValue; - } - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2; - if (things) - { - (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, - stuff->coordMode, things, - (DDXPointPtr) &stuff[1]); - } - return(client->noClientException); -} - -int -ProcPolyFillRectangle(register ClientPtr client) -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); - if (things & 4) - return(BadLength); - things >>= 3; - - if (things) - { - (*pGC->ops->PolyFillRect) (pDraw, pGC, things, - (xRectangle *) &stuff[1]); - } - return (client->noClientException); -} - -int -ProcPolyFillArc(register ClientPtr client) -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - { - (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); - } - return (client->noClientException); -} - -#ifdef MATCH_CLIENT_ENDIAN - -int -ServerOrder (void) -{ - int whichbyte = 1; - - if (*((char *) &whichbyte)) - return LSBFirst; - return MSBFirst; -} - -#define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder()) - -void -ReformatImage (char *base, int nbytes, int bpp, int order) -{ - switch (bpp) { - case 1: /* yuck */ - if (BITMAP_BIT_ORDER != order) - BitOrderInvert ((unsigned char *) base, nbytes); -#if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8 - ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order); -#endif - break; - case 4: - break; /* yuck */ - case 8: - break; - case 16: - if (IMAGE_BYTE_ORDER != order) - TwoByteSwap ((unsigned char *) base, nbytes); - break; - case 32: - if (IMAGE_BYTE_ORDER != order) - FourByteSwap ((unsigned char *) base, nbytes); - break; - } -} -#else -#define ReformatImage(b,n,bpp,o) -#endif - -/* 64-bit server notes: the protocol restricts padding of images to - * 8-, 16-, or 32-bits. We would like to have 64-bits for the server - * to use internally. Removes need for internal alignment checking. - * All of the PutImage functions could be changed individually, but - * as currently written, they call other routines which require things - * to be 64-bit padded on scanlines, so we changed things here. - * If an image would be padded differently for 64- versus 32-, then - * copy each scanline to a 64-bit padded scanline. - * Also, we need to make sure that the image is aligned on a 64-bit - * boundary, even if the scanlines are padded to our satisfaction. - */ -int -ProcPutImage(register ClientPtr client) -{ - register GC *pGC; - register DrawablePtr pDraw; - long length; /* length of scanline server padded */ - long lengthProto; /* length of scanline protocol padded */ - char *tmpImage; - REQUEST(xPutImageReq); - - REQUEST_AT_LEAST_SIZE(xPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - if (stuff->format == XYBitmap) - { - if ((stuff->depth != 1) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - } - else if (stuff->format == XYPixmap) - { - if ((pDraw->depth != stuff->depth) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0)) - return BadMatch; - length = PixmapBytePad(stuff->width, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - tmpImage = (char *)&stuff[1]; - lengthProto = length; - - if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) + - (sizeof(xPutImageReq) >> 2)) != client->req_len) - return BadLength; - - ReformatImage (tmpImage, lengthProto * stuff->height, - stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1, - ClientOrder(client)); - - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY, - stuff->width, stuff->height, - stuff->leftPad, stuff->format, tmpImage); - - return (client->noClientException); -} - - -int -DoGetImage(register ClientPtr client, int format, Drawable drawable, - int x, int y, int width, int height, - Mask planemask, xGetImageReply **im_return) -{ - register DrawablePtr pDraw; - int nlines, linesPerBuf; - register int linesDone; - long widthBytesLine, length; - Mask plane = 0; - char *pBuf; - xGetImageReply xgi; -#ifdef XCSECURITY - RegionPtr pVisibleRegion = NULL; -#endif - - if ((format != XYPixmap) && (format != ZPixmap)) - { - client->errorValue = format; - return(BadValue); - } - SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess); - if(pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + x < 0 || - pDraw->x + x + width > pDraw->pScreen->width || - pDraw->y + y < 0 || - pDraw->y + y + height > pDraw->pScreen->height || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual (((WindowPtr) pDraw)); - } - else - { - if(x < 0 || - x+width > (int)pDraw->width || - y < 0 || - y+height > (int)pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - - SET_DBE_SRCBUF(pDraw, drawable); - - xgi.type = X_Reply; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(format == ZPixmap) - { - widthBytesLine = PixmapBytePad(width, pDraw->depth); - length = widthBytesLine * height; - - } - else - { - widthBytesLine = BitmapBytePad(width); - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = widthBytesLine * height * - Ones(planemask & (plane | (plane - 1))); - - } - - xgi.length = length; - - if (im_return) { - pBuf = (char *)xalloc(sz_xGetImageReply + length); - if (!pBuf) - return (BadAlloc); - if (widthBytesLine == 0) - linesPerBuf = 0; - else - linesPerBuf = height; - *im_return = (xGetImageReply *)pBuf; - *(xGetImageReply *)pBuf = xgi; - pBuf += sz_xGetImageReply; - } else { - xgi.length = (xgi.length + 3) >> 2; - if (widthBytesLine == 0 || height == 0) - linesPerBuf = 0; - else if (widthBytesLine >= IMAGE_BUFSIZE) - linesPerBuf = 1; - else - { - linesPerBuf = IMAGE_BUFSIZE / widthBytesLine; - if (linesPerBuf > height) - linesPerBuf = height; - } - length = linesPerBuf * widthBytesLine; - if (linesPerBuf < height) - { - /* we have to make sure intermediate buffers don't need padding */ - while ((linesPerBuf > 1) && - (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))) - { - linesPerBuf--; - length -= widthBytesLine; - } - while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)) - { - linesPerBuf++; - length += widthBytesLine; - } - } - if(!(pBuf = (char *) ALLOCATE_LOCAL(length))) - return (BadAlloc); - WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); - } - -#ifdef XCSECURITY - if (client->trustLevel != XSecurityClientTrusted && - pDraw->type == DRAWABLE_WINDOW) - { - pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw); - if (pVisibleRegion) - { - REGION_TRANSLATE(pDraw->pScreen, pVisibleRegion, -pDraw->x, -pDraw->y); - } - } -#endif - - if (linesPerBuf == 0) - { - /* nothing to do */ - } - else if (format == ZPixmap) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - planemask, - (pointer) pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note that this is NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (!im_return) - { - ReformatImage (pBuf, (int)(nlines * widthBytesLine), - BitsPerPixel (pDraw->depth), - ClientOrder(client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - else /* XYPixmap */ - { - for (; plane; plane >>= 1) - { - if (planemask & plane) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - plane, - (pointer)pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, - widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note: NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (im_return) { - pBuf += nlines * widthBytesLine; - } else { - ReformatImage (pBuf, - (int)(nlines * widthBytesLine), - 1, - ClientOrder (client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - } - } -#ifdef XCSECURITY - if (pVisibleRegion) - REGION_DESTROY(pDraw->pScreen, pVisibleRegion); -#endif - if (!im_return) - DEALLOCATE_LOCAL(pBuf); - return (client->noClientException); -} - -int -ProcGetImage(register ClientPtr client) -{ - REQUEST(xGetImageReq); - - REQUEST_SIZE_MATCH(xGetImageReq); - - return DoGetImage(client, stuff->format, stuff->drawable, - stuff->x, stuff->y, - (int)stuff->width, (int)stuff->height, - stuff->planeMask, (xGetImageReply **)NULL); -} - -int -ProcPolyText(register ClientPtr client) -{ - int err; - REQUEST(xPolyTextReq); - DrawablePtr pDraw; - GC *pGC; - - REQUEST_AT_LEAST_SIZE(xPolyTextReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = PolyText(client, - pDraw, - pGC, - (unsigned char *)&stuff[1], - ((unsigned char *) stuff) + (client->req_len << 2), - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText8(register ClientPtr client) -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText16(register ClientPtr client) -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - - -int -ProcCreateColormap(register ClientPtr client) -{ - VisualPtr pVisual; - ColormapPtr pmap; - Colormap mid; - register WindowPtr pWin; - ScreenPtr pScreen; - REQUEST(xCreateColormapReq); - int i, result; - - REQUEST_SIZE_MATCH(xCreateColormapReq); - - if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) - { - client->errorValue = stuff->alloc; - return(BadValue); - } - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pScreen = pWin->drawable.pScreen; - for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid != stuff->visual) - continue; - result = CreateColormap(mid, pScreen, pVisual, &pmap, - (int)stuff->alloc, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - client->errorValue = stuff->visual; - return(BadValue); -} - -int -ProcFreeColormap(register ClientPtr client) -{ - ColormapPtr pmap; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP, - SecurityDestroyAccess); - if (pmap) - { - /* Freeing a default colormap is a no-op */ - if (!(pmap->flags & IsDefault)) - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - - -int -ProcCopyColormapAndFree(register ClientPtr client) -{ - Colormap mid; - ColormapPtr pSrcMap; - REQUEST(xCopyColormapAndFreeReq); - int result; - - REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client, stuff->srcCmap, - RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) ) - { - result = CopyColormapAndFree(mid, pSrcMap, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->srcCmap; - return(BadColor); - } -} - -int -ProcInstallColormap(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - (*(pcmp->pScreen->InstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcUninstallColormap(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - if(pcmp->mid != pcmp->pScreen->defColormap) - (*(pcmp->pScreen->UninstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcListInstalledColormaps(register ClientPtr client) -{ - xListInstalledColormapsReply *preply; - int nummaps; - WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - - if (!pWin) - return(BadWindow); - - preply = (xListInstalledColormapsReply *) - ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) + - pWin->drawable.pScreen->maxInstalledCmaps * - sizeof(Colormap)); - if(!preply) - return(BadAlloc); - - preply->type = X_Reply; - preply->sequenceNumber = client->sequence; - nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pWin->drawable.pScreen, (Colormap *)&preply[1]); - preply->nColormaps = nummaps; - preply->length = nummaps; - WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); - DEALLOCATE_LOCAL(preply); - return(client->noClientException); -} - -int -ProcAllocColor (register ClientPtr client) -{ - ColormapPtr pmap; - int retval; - xAllocColorReply acr; - REQUEST(xAllocColorReq); - - REQUEST_SIZE_MATCH(xAllocColorReq); - pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pmap) - { -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pmap, (xReq *) stuff)) - return Success; -#endif - acr.type = X_Reply; - acr.length = 0; - acr.sequenceNumber = client->sequence; - acr.red = stuff->red; - acr.green = stuff->green; - acr.blue = stuff->blue; - acr.pixel = 0; - if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, - &acr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return (retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pmap->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); - return (client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocNamedColor (register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xAllocNamedColorReq); - - REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int retval; - - xAllocNamedColorReply ancr; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocNamedColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - ancr.type = X_Reply; - ancr.length = 0; - ancr.sequenceNumber = client->sequence; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) - { - ancr.screenRed = ancr.exactRed; - ancr.screenGreen = ancr.exactGreen; - ancr.screenBlue = ancr.exactBlue; - ancr.pixel = 0; - if( (retval = AllocColor(pcmp, - &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue, - &ancr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr); - return (client->noClientException); - } - else - return(BadName); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorCells (register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xAllocColorCellsReq); - - REQUEST_SIZE_MATCH(xAllocColorCellsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorCellsReply accr; - int npixels, nmasks, retval; - long length; - Pixel *ppixels, *pmasks; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorCells request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - nmasks = stuff->planes; - length = ((long)npixels + (long)nmasks) * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - pmasks = ppixels + npixels; - - if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, - (Bool)stuff->contiguous, ppixels, pmasks)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - accr.type = X_Reply; - accr.length = length >> 2; - accr.sequenceNumber = client->sequence; - accr.nPixels = npixels; - accr.nMasks = nmasks; - WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorPlanes(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xAllocColorPlanesReq); - - REQUEST_SIZE_MATCH(xAllocColorPlanesReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorPlanesReply acpr; - int npixels, retval; - long length; - Pixel *ppixels; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorPlanes request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - acpr.type = X_Reply; - acpr.sequenceNumber = client->sequence; - acpr.nPixels = npixels; - length = (long)npixels * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - if( (retval = AllocColorPlanes(client->index, pcmp, npixels, - (int)stuff->red, (int)stuff->green, (int)stuff->blue, - (Bool)stuff->contiguous, ppixels, - &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - acpr.length = length >> 2; -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcFreeColors(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xFreeColorsReq); - - REQUEST_AT_LEAST_SIZE(xFreeColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - if(pcmp->flags & AllAllocated) - return(BadAccess); - count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2; - retval = FreeColors(pcmp, client->index, count, - (Pixel *)&stuff[1], (Pixel)stuff->planeMask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreColors (ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xStoreColorsReq); - - REQUEST_AT_LEAST_SIZE(xStoreColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - count = (client->req_len << 2) - sizeof(xStoreColorsReq); - if (count % sizeof(xColorItem)) - return(BadLength); - count /= sizeof(xColorItem); - retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreNamedColor (register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xStoreNamedColorReq); - - REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xColorItem def; - int retval; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], - stuff->nbytes, &def.red, &def.green, &def.blue)) - { - def.flags = stuff->flags; - def.pixel = stuff->pixel; - retval = StoreColors(pcmp, 1, &def); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcQueryColors(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xQueryColorsReq); - - REQUEST_AT_LEAST_SIZE(xQueryColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - int count, retval; - xrgb *prgbs; - xQueryColorsReply qcr; - - count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2; - prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb)); - if(!prgbs && count) - return(BadAlloc); - if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) ) - { - if (prgbs) DEALLOCATE_LOCAL(prgbs); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return (retval); - } - } - qcr.type = X_Reply; - qcr.length = (count * sizeof(xrgb)) >> 2; - qcr.sequenceNumber = client->sequence; - qcr.nColors = count; - WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); - if (count) - { - client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; - WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); - } - if (prgbs) DEALLOCATE_LOCAL(prgbs); - return(client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcLookupColor(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xLookupColorReq); - - REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - xLookupColorReply lcr; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) - { - lcr.type = X_Reply; - lcr.length = 0; - lcr.sequenceNumber = client->sequence; - lcr.screenRed = lcr.exactRed; - lcr.screenGreen = lcr.exactGreen; - lcr.screenBlue = lcr.exactBlue; - (*pcmp->pScreen->ResolveColor)(&lcr.screenRed, - &lcr.screenGreen, - &lcr.screenBlue, - pcmp->pVisual); - WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); - return(client->noClientException); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcCreateCursor (register ClientPtr client) -{ - CursorPtr pCursor; - - register PixmapPtr src; - register PixmapPtr msk; - unsigned char * srcbits; - unsigned char * mskbits; - unsigned short width, height; - long n; - CursorMetricRec cm; - - - REQUEST(xCreateCursorReq); - - REQUEST_SIZE_MATCH(xCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source, - RT_PIXMAP, SecurityReadAccess); - msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask, - RT_PIXMAP, SecurityReadAccess); - if ( src == (PixmapPtr)NULL) - { - client->errorValue = stuff->source; - return (BadPixmap); - } - if ( msk == (PixmapPtr)NULL) - { - if (stuff->mask != None) - { - client->errorValue = stuff->mask; - return (BadPixmap); - } - } - else if ( src->drawable.width != msk->drawable.width - || src->drawable.height != msk->drawable.height - || src->drawable.depth != 1 - || msk->drawable.depth != 1) - return (BadMatch); - - width = src->drawable.width; - height = src->drawable.height; - - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - - n = BitmapBytePad(width)*height; - srcbits = (unsigned char *)xalloc(n); - if (!srcbits) - return (BadAlloc); - mskbits = (unsigned char *)xalloc(n); - if (!mskbits) - { - xfree(srcbits); - return (BadAlloc); - } - - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)srcbits, n); - (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height, - XYPixmap, 1, (pointer)srcbits); - if ( msk == (PixmapPtr)NULL) - { - register unsigned char *bits = mskbits; - while (--n >= 0) - *bits++ = ~0; - } - else - { - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)mskbits, n); - (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width, - height, XYPixmap, 1, (pointer)mskbits); - } - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - pCursor = AllocCursor( srcbits, mskbits, &cm, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue); - - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - { - #ifdef TEST - fprintf(stderr, "ProcCreateCursor: Created cursor at [%p].\n", (void *) pCursor); - #endif - - return (client->noClientException); - } - - return BadAlloc; -} - -int -ProcCreateGlyphCursor (register ClientPtr client) -{ - CursorPtr pCursor; - int res; - - REQUEST(xCreateGlyphCursorReq); - - REQUEST_SIZE_MATCH(xCreateGlyphCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - res = AllocGlyphCursor(stuff->source, stuff->sourceChar, - stuff->mask, stuff->maskChar, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client); - if (res != Success) - return res; - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - - -int -ProcFreeCursor (register ClientPtr client) -{ - CursorPtr pCursor; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id, - RT_CURSOR, SecurityDestroyAccess); - if (pCursor) - { - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadCursor); - } -} - -int -ProcQueryBestSize (register ClientPtr client) -{ - xQueryBestSizeReply reply; - register DrawablePtr pDraw; - ScreenPtr pScreen; - REQUEST(xQueryBestSizeReq); - - REQUEST_SIZE_MATCH(xQueryBestSizeReq); - if ((stuff->class != CursorShape) && - (stuff->class != TileShape) && - (stuff->class != StippleShape)) - { - client->errorValue = stuff->class; - return(BadValue); - } - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW) - return (BadMatch); - pScreen = pDraw->pScreen; - (* pScreen->QueryBestSize)(stuff->class, &stuff->width, - &stuff->height, pScreen); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.width = stuff->width; - reply.height = stuff->height; - WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply); - return (client->noClientException); -} - - -int -ProcSetScreenSaver (register ClientPtr client) -{ - int blankingOption, exposureOption; - REQUEST(xSetScreenSaverReq); - - REQUEST_SIZE_MATCH(xSetScreenSaverReq); - blankingOption = stuff->preferBlank; - if ((blankingOption != DontPreferBlanking) && - (blankingOption != PreferBlanking) && - (blankingOption != DefaultBlanking)) - { - client->errorValue = blankingOption; - return BadValue; - } - exposureOption = stuff->allowExpose; - if ((exposureOption != DontAllowExposures) && - (exposureOption != AllowExposures) && - (exposureOption != DefaultExposures)) - { - client->errorValue = exposureOption; - return BadValue; - } - if (stuff->timeout < -1) - { - client->errorValue = stuff->timeout; - return BadValue; - } - if (stuff->interval < -1) - { - client->errorValue = stuff->interval; - return BadValue; - } - - /* - * The NX agent uses the screen saver procedure - * to monitor the user activities and launch its - * handlers (like timeout feature), so we can't - * always allow the clients to change our values. - */ - - #ifdef TEST - fprintf(stderr, "ProcSetScreenSaver: Called with timeout [%d] interval [%d] Blanking [%d] Exposure [%d].\n", - stuff -> timeout, stuff -> interval, blankingOption, exposureOption); - #endif - - if (nxagentOption(Timeout) == 0) - { - if (blankingOption == DefaultBlanking) - { - ScreenSaverBlanking = defaultScreenSaverBlanking; - } - else - { - ScreenSaverBlanking = blankingOption; - } - - if (exposureOption == DefaultExposures) - { - ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; - } - else - { - ScreenSaverAllowExposures = exposureOption; - } - - if (stuff->timeout >= 0) - { - ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND; - } - else - { - ScreenSaverTime = defaultScreenSaverTime; - } - - if (stuff->interval >= 0) - { - ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND; - } - else - { - ScreenSaverInterval = defaultScreenSaverInterval; - } - - SetScreenSaverTimer(); - } - #ifdef TEST - - else - { - fprintf(stderr, "ProcSetScreenSaver: Keeping auto-disconnect timeout set to [%d] seconds.\n", - nxagentOption(Timeout)); - } - - #endif - - return (client->noClientException); -} - -int -ProcGetScreenSaver(register ClientPtr client) -{ - xGetScreenSaverReply rep; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.timeout = ScreenSaverTime / MILLI_PER_SECOND; - rep.interval = ScreenSaverInterval / MILLI_PER_SECOND; - rep.preferBlanking = ScreenSaverBlanking; - rep.allowExposures = ScreenSaverAllowExposures; - WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep); - return (client->noClientException); -} - -int -ProcChangeHosts(register ClientPtr client) -{ - REQUEST(xChangeHostsReq); - int result; - - REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength); - - if(stuff->mode == HostInsert) - result = AddHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else if (stuff->mode == HostDelete) - result = RemoveHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else - { - client->errorValue = stuff->mode; - return BadValue; - } - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcListHosts(register ClientPtr client) -{ - xListHostsReply reply; - int len, nHosts, result; - pointer pdata; - /* REQUEST(xListHostsReq); */ - - REQUEST_SIZE_MATCH(xListHostsReq); -#ifdef XCSECURITY - /* untrusted clients can't list hosts */ - if (client->trustLevel != XSecurityClientTrusted) - { - SecurityAudit("client %d attempted to list hosts\n", client->index); - return BadAccess; - } -#endif - result = GetHosts(&pdata, &nHosts, &len, &reply.enabled); - if (result != Success) - return(result); - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.nHosts = nHosts; - reply.length = len >> 2; - WriteReplyToClient(client, sizeof(xListHostsReply), &reply); - if (nHosts) - { - client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; - WriteSwappedDataToClient(client, len, pdata); - } - xfree(pdata); - return (client->noClientException); -} - -int -ProcChangeAccessControl(register ClientPtr client) -{ - int result; - REQUEST(xSetAccessControlReq); - - REQUEST_SIZE_MATCH(xSetAccessControlReq); - if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) - { - client->errorValue = stuff->mode; - return BadValue; - } - result = ChangeAccessControl(client, stuff->mode == EnableAccess); - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcKillClient(register ClientPtr client) -{ - REQUEST(xResourceReq); - ClientPtr killclient; - - REQUEST_SIZE_MATCH(xResourceReq); - if (stuff->id == AllTemporary) - { - CloseDownRetainedResources(); - return (client->noClientException); - } - - if ((killclient = LookupClient(stuff->id, client))) - { - CloseDownClient(killclient); - /* if an LBX proxy gets killed, isItTimeToYield will be set */ - if (isItTimeToYield || (client == killclient)) - { - /* force yield and return Success, so that Dispatch() - * doesn't try to touch client - */ - isItTimeToYield = TRUE; - return (Success); - } - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadValue); - } -} - -int -ProcSetFontPath(register ClientPtr client) -{ - unsigned char *ptr; - unsigned long nbytes, total; - long nfonts; - int n, result; - int error; - REQUEST(xSetFontPathReq); - - REQUEST_AT_LEAST_SIZE(xSetFontPathReq); - - nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq); - total = nbytes; - ptr = (unsigned char *)&stuff[1]; - nfonts = stuff->nFonts; - while (--nfonts >= 0) - { - if ((total == 0) || (total < (n = (*ptr + 1)))) - return(BadLength); - total -= n; - ptr += n; - } - if (total >= 4) - return(BadLength); - result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1], - &error); - if (!result) - { - result = client->noClientException; - client->errorValue = error; - } - return (result); -} - -int -ProcGetFontPath(register ClientPtr client) -{ - xGetFontPathReply reply; - int stringLens, numpaths; - unsigned char *bufferStart; - /* REQUEST (xReq); */ - - REQUEST_SIZE_MATCH(xReq); - bufferStart = GetFontPath(&numpaths, &stringLens); - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = (stringLens + numpaths + 3) >> 2; - reply.nPaths = numpaths; - - WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); - if (stringLens || numpaths) - (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart); - return(client->noClientException); -} - -int -ProcChangeCloseDownMode(register ClientPtr client) -{ - REQUEST(xSetCloseDownModeReq); - - REQUEST_SIZE_MATCH(xSetCloseDownModeReq); - if ((stuff->mode == AllTemporary) || - (stuff->mode == RetainPermanent) || - (stuff->mode == RetainTemporary)) - { - client->closeDownMode = stuff->mode; - return (client->noClientException); - } - else - { - client->errorValue = stuff->mode; - return (BadValue); - } -} - -int ProcForceScreenSaver(register ClientPtr client) -{ - REQUEST(xForceScreenSaverReq); - - REQUEST_SIZE_MATCH(xForceScreenSaverReq); - - if ((stuff->mode != ScreenSaverReset) && - (stuff->mode != ScreenSaverActive)) - { - client->errorValue = stuff->mode; - return BadValue; - } - - /* - * The NX agent uses the screen saver procedure - * to monitor the user activities and launch its - * handlers (like timeout feature), so we can't - * always allow the clients to force the screen - * saver handler execution. - */ - - if (nxagentOption(Timeout) == 0) - { - SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode); - } - - #ifdef TEST - - else - { - fprintf(stderr, "ProcForceScreenSaver: Ignoring the client request with mode [%d].\n", - stuff -> mode); - } - - #endif - - return client->noClientException; -} - -int ProcNoOperation(register ClientPtr client) -{ - REQUEST_AT_LEAST_SIZE(xReq); - - /* noop -- don't do anything */ - return(client->noClientException); -} - -void -InitProcVectors(void) -{ - int i; - for (i = 0; i<256; i++) - { - if(!ProcVector[i]) - { - ProcVector[i] = SwappedProcVector[i] = ProcBadRequest; - ReplySwapVector[i] = ReplyNotSwappd; - } -#ifdef K5AUTH - if (!k5_Vector[i]) - { - k5_Vector[i] = k5_bad; - } -#endif - } - for(i = LASTEvent; i < 128; i++) - { - EventSwapVector[i] = NotImplemented; - } - -} - -/********************** - * CloseDownClient - * - * Client can either mark his resources destroy or retain. If retained and - * then killed again, the client is really destroyed. - *********************/ - -void -CloseDownClient(register ClientPtr client) -{ - Bool really_close_down = client->clientGone || - client->closeDownMode == DestroyAll; - - /* - * There must be a better way to hook a - * call-back function to be called any - * time a client is going to be closed. - */ - - nxagentClearClipboard(client, NULL); - - /* - * Need to reset the karma counter and - * get rid of the pending sync replies. - */ - - nxagentWakeupByReset(client); - - /* - * Check if the client - * is a shadow nxagent. - */ - - nxagentCheckIfShadowAgent(client); - - if (!client->clientGone) - { - /* ungrab server if grabbing client dies */ - if (grabState != GrabNone && grabClient == client) - { - UngrabServer(client); - } - BITCLEAR(grabWaiters, client->index); - DeleteClientFromAnySelections(client); - ReleaseActiveGrabs(client); - DeleteClientFontStuff(client); - if (!really_close_down) - { - /* This frees resources that should never be retained - * no matter what the close down mode is. Actually we - * could do this unconditionally, but it's probably - * better not to traverse all the client's resources - * twice (once here, once a few lines down in - * FreeClientResources) in the common case of - * really_close_down == TRUE. - */ - FreeClientNeverRetainResources(client); - client->clientState = ClientStateRetained; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - } - client->clientGone = TRUE; /* so events aren't sent to client */ - if (ClientIsAsleep(client)) - ClientSignal (client); - ProcessWorkQueueZombies(); -#ifdef LBX - ProcessQTagZombies(); -#endif - CloseDownConnection(client); - - /* If the client made it to the Running stage, nClients has - * been incremented on its behalf, so we need to decrement it - * now. If it hasn't gotten to Running, nClients has *not* - * been incremented, so *don't* decrement it. - */ - if (client->clientState != ClientStateInitial && - client->clientState != ClientStateAuthenticating ) - { - --nClients; - } - } - - if (really_close_down) - { - if (client->clientState == ClientStateRunning && nClients == 0) - dispatchException |= dispatchExceptionAtReset; - - client->clientState = ClientStateGone; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - FreeClientResources(client); - if (client->index < nextFreeClientID) - nextFreeClientID = client->index; - clients[client->index] = NullClient; -#ifdef SMART_SCHEDULE - SmartLastClient = NullClient; -#endif - xfree(client); - - while (!clients[currentMaxClients-1]) - currentMaxClients--; - } -} - -static void -KillAllClients() -{ - int i; - for (i=1; icloseDownMode = DestroyAll; - CloseDownClient(clients[i]); - } -} - -/********************* - * CloseDownRetainedResources - * - * Find all clients that are gone and have terminated in RetainTemporary - * and destroy their resources. - *********************/ - -void -CloseDownRetainedResources() -{ - register int i; - register ClientPtr client; - - for (i=1; icloseDownMode == RetainTemporary) - && (client->clientGone)) - CloseDownClient(client); - } -} - -void InitClient(ClientPtr client, int i, pointer ospriv) -{ - client->index = i; - client->sequence = 0; - client->clientAsMask = ((Mask)i) << CLIENTOFFSET; - client->clientGone = FALSE; - if (i) - { - client->closeDownMode = DestroyAll; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - client->lastDrawableID = WindowTable[0]->drawable.id; - } - else - { - client->closeDownMode = RetainPermanent; - client->lastDrawable = (DrawablePtr)NULL; - client->lastDrawableID = INVALID; - } - client->lastGC = (GCPtr) NULL; - client->lastGCID = INVALID; - client->numSaved = 0; - client->saveSet = (SaveSetElt *)NULL; - client->noClientException = Success; -#ifdef LOG_DEBUG - client->requestLogIndex = 0; -#endif - client->requestVector = InitialVector; - client->osPrivate = ospriv; - client->swapped = FALSE; - client->big_requests = FALSE; - client->priority = 0; - client->clientState = ClientStateInitial; -#ifdef XKB - if (!noXkbExtension) { - client->xkbClientFlags = 0; - client->mapNotifyMask = 0; - QueryMinMaxKeyCodes(&client->minKC,&client->maxKC); - } -#endif - client->replyBytesRemaining = 0; -#ifdef LBX - client->readRequest = StandardReadRequestFromClient; -#endif -#ifdef XCSECURITY - client->trustLevel = XSecurityClientTrusted; - client->CheckAccess = NULL; - client->authId = 0; -#endif -#ifdef XAPPGROUP - client->appgroup = NULL; -#endif - client->fontResFunc = NULL; -#ifdef SMART_SCHEDULE - client->smart_priority = 0; - client->smart_start_tick = SmartScheduleTime; - client->smart_stop_tick = SmartScheduleTime; - client->smart_check_tick = SmartScheduleTime; -#endif -} - -extern int clientPrivateLen; -extern unsigned *clientPrivateSizes; -extern unsigned totalClientSize; - -int -InitClientPrivates(ClientPtr client) -{ - register char *ptr; - DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - if (totalClientSize == sizeof(ClientRec)) - ppriv = (DevUnion *)NULL; - else if (client->index) - ppriv = (DevUnion *)(client + 1); - else - { - ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec)); - if (!ppriv) - return 0; - } - client->devPrivates = ppriv; - sizes = clientPrivateSizes; - ptr = (char *)(ppriv + clientPrivateLen); - for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - - /* - * Initialize the private members. - */ - - nxagentInitClientPrivates(client); - - return 1; -} - -/************************ - * int NextAvailableClient(ospriv) - * - * OS dependent portion can't assign client id's because of CloseDownModes. - * Returns NULL if there are no free clients. - *************************/ - -ClientPtr NextAvailableClient(pointer ospriv) -{ - register int i; - register ClientPtr client; - xReq data; - - i = nextFreeClientID; - if (i == MAXCLIENTS) - return (ClientPtr)NULL; - clients[i] = client = (ClientPtr)xalloc(totalClientSize); - if (!client) - return (ClientPtr)NULL; - InitClient(client, i, ospriv); - InitClientPrivates(client); - if (!InitClientResources(client)) - { - xfree(client); - return (ClientPtr)NULL; - } - data.reqType = 1; - data.length = (sz_xReq + sz_xConnClientPrefix) >> 2; - if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) - { - FreeClientResources(client); - xfree(client); - return (ClientPtr)NULL; - } - if (i == currentMaxClients) - currentMaxClients++; - while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID]) - nextFreeClientID++; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return(client); -} - -int -ProcInitialConnection(register ClientPtr client) -{ - REQUEST(xReq); - register xConnClientPrefix *prefix; - int whichbyte = 1; - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B')) - return (client->noClientException = -1); - if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) - { - client->swapped = TRUE; - SwapConnClientPrefix(prefix); - } - stuff->reqType = 2; - stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) + - ((prefix->nbytesAuthString + (unsigned)3) >> 2); - if (client->swapped) - { - swaps(&stuff->length, whichbyte); - } - ResetCurrentRequest(client); - return (client->noClientException); -} - -#ifdef LBX -void -IncrementClientCount() -{ - nClients++; -} -#endif - -int -SendConnSetup(register ClientPtr client, char *reason) -{ - register xWindowRoot *root; - register int i; - int numScreens; - char* lConnectionInfo; - xConnSetupPrefix* lconnSetupPrefix; - - if (reason) - { - xConnSetupPrefix csp; - - csp.success = xFalse; - csp.lengthReason = strlen(reason); - csp.length = (csp.lengthReason + (unsigned)3) >> 2; - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (client->swapped) - WriteSConnSetupPrefix(client, &csp); - else - (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); - (void)WriteToClient(client, (int)csp.lengthReason, reason); - return (client->noClientException = -1); - } - - numScreens = screenInfo.numScreens; - lConnectionInfo = ConnectionInfo; - lconnSetupPrefix = &connSetupPrefix; - - /* We're about to start speaking X protocol back to the client by - * sending the connection setup info. This means the authorization - * step is complete, and we can count the client as an - * authorized one. - */ - nClients++; - - client->requestVector = client->swapped ? SwappedProcVector : ProcVector; - client->sequence = 0; -#ifdef XAPPGROUP - XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens); -#endif - ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask; - ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK; -#ifdef MATCH_CLIENT_ENDIAN - ((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client); - ((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client); -#endif - /* fill in the "currentInputMask" */ - root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart); -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#endif - - for (i=0; icurrentInputMask = WindowTable[i]->eventMask | - wOtherEventMasks (WindowTable[i]); - pDepth = (xDepth *)(root + 1); - for (j = 0; j < root->nDepths; j++) - { - pDepth = (xDepth *)(((char *)(pDepth + 1)) + - pDepth->nVisuals * sizeof(xVisualType)); - } - root = (xWindowRoot *)pDepth; - } - - if (client->swapped) - { - WriteSConnSetupPrefix(client, lconnSetupPrefix); - WriteSConnectionInfo(client, - (unsigned long)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - else - { - (void)WriteToClient(client, sizeof(xConnSetupPrefix), - (char *) lconnSetupPrefix); - (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - client->clientState = ClientStateRunning; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = lconnSetupPrefix; - clientinfo.setup = (xConnSetup *)lConnectionInfo; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return (client->noClientException); -} - -int -ProcEstablishConnection(register ClientPtr client) -{ - char *reason, *auth_proto, *auth_string; - register xConnClientPrefix *prefix; - REQUEST(xReq); - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - auth_proto = (char *)prefix + sz_xConnClientPrefix; - auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3); - if ((prefix->majorVersion != X_PROTOCOL) || - (prefix->minorVersion != X_PROTOCOL_REVISION)) - reason = "Protocol version mismatch"; - else - reason = ClientAuthorized(client, - (unsigned short)prefix->nbytesAuthProto, - auth_proto, - (unsigned short)prefix->nbytesAuthString, - auth_string); - /* - * If Kerberos is being used for this client, the clientState - * will be set to ClientStateAuthenticating at this point. - * More messages need to be exchanged among the X server, Kerberos - * server, and client to figure out if everyone is authorized. - * So we don't want to send the connection setup info yet, since - * the auth step isn't really done. - */ - if (client->clientState == ClientStateCheckingSecurity) - client->clientState = ClientStateCheckedSecurity; - else if (client->clientState != ClientStateAuthenticating) - return(SendConnSetup(client, reason)); - return(client->noClientException); -} - -void -SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, - XID resId, int errorCode) -{ - xError rep; - - rep.type = X_Error; - rep.sequenceNumber = client->sequence; - rep.errorCode = errorCode; - rep.majorCode = majorCode; - rep.minorCode = minorCode; - rep.resourceID = resId; - - WriteEventsToClient (client, 1, (xEvent *)&rep); -} - -void -DeleteWindowFromAnySelections(WindowPtr pWin) -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].pWin == pWin) - { - if (SelectionCallback) - { - SelectionInfoRec info; - - info.selection = &CurrentSelections[i]; - info.kind = SelectionWindowDestroy; - CallCallbacks(&SelectionCallback, &info); - } - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -static void -DeleteClientFromAnySelections(ClientPtr client) -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].client == client) - { - if (SelectionCallback) - { - SelectionInfoRec info; - - info.selection = &CurrentSelections[i]; - info.kind = SelectionWindowDestroy; - CallCallbacks(&SelectionCallback, &info); - } - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -void -MarkClientException(ClientPtr client) -{ - client->noClientException = -1; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.X.original deleted file mode 100644 index 6941456de..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c.X.original +++ /dev/null @@ -1,4035 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/dix/dispatch.c,v 1.13 2005/09/13 01:33:19 daniels Exp $ */ -/* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ -/************************************************************ - -Copyright 1987, 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.32 2003/11/10 18:21:45 tsi Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef PANORAMIX_DEBUG -#include -int ProcInitialConnection(); -#endif - -#include "windowstr.h" -#include -#include "dixfontstr.h" -#include "gcstruct.h" -#include "selection.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "opaque.h" -#include "input.h" -#include "servermd.h" -#include "extnsionst.h" -#include "dixfont.h" -#include "dispatch.h" -#include "swaprep.h" -#include "swapreq.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef XAPPGROUP -#include -#endif -#ifdef XKB -#define XKB_IN_SERVER -#include "inputstr.h" -#include -#endif -#ifdef LBX -#include "lbxserve.h" -#endif - -#define mskcnt ((MAXCLIENTS + 31) / 32) -#define BITMASK(i) (1U << ((i) & 31)) -#define MASKIDX(i) ((i) >> 5) -#define MASKWORD(buf, i) buf[MASKIDX(i)] -#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) -#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) -#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) - -extern xConnSetupPrefix connSetupPrefix; -extern char *ConnectionInfo; - -Selection *CurrentSelections; -int NumCurrentSelections; -CallbackListPtr SelectionCallback = NULL; - -static ClientPtr grabClient; -#define GrabNone 0 -#define GrabActive 1 -#define GrabKickout 2 -static int grabState = GrabNone; -static long grabWaiters[mskcnt]; -CallbackListPtr ServerGrabCallback = NULL; -HWEventQueuePtr checkForInput[2]; -extern int connBlockScreenStart; - -static void KillAllClients(void); - -static void DeleteClientFromAnySelections(ClientPtr client); - -static int nextFreeClientID; /* always MIN free client ID */ - -static int nClients; /* number of authorized clients */ - -CallbackListPtr ClientStateCallback; - -/* dispatchException & isItTimeToYield must be declared volatile since they - * are modified by signal handlers - otherwise optimizer may assume it doesn't - * need to actually check value in memory when used and may miss changes from - * signal handlers. - */ -volatile char dispatchException = 0; -volatile char isItTimeToYield; - -/* Various of the DIX function interfaces were not designed to allow - * the client->errorValue to be set on BadValue and other errors. - * Rather than changing interfaces and breaking untold code we introduce - * a new global that dispatch can use. - */ -XID clientErrorValue; /* XXX this is a kludge */ - -#define SAME_SCREENS(a, b) (\ - (a.pScreen == b.pScreen)) - -void -SetInputCheck(HWEventQueuePtr c0, HWEventQueuePtr c1) -{ - checkForInput[0] = c0; - checkForInput[1] = c1; -} - -void -UpdateCurrentTime() -{ - TimeStamp systime; - - /* To avoid time running backwards, we must call GetTimeInMillis before - * calling ProcessInputEvents. - */ - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] != *checkForInput[1]) - ProcessInputEvents(); - if (CompareTimeStamps(systime, currentTime) == LATER) - currentTime = systime; -} - -/* Like UpdateCurrentTime, but can't call ProcessInputEvents */ -void -UpdateCurrentTimeIf() -{ - TimeStamp systime; - - systime.months = currentTime.months; - systime.milliseconds = GetTimeInMillis(); - if (systime.milliseconds < currentTime.milliseconds) - systime.months++; - if (*checkForInput[0] == *checkForInput[1]) - currentTime = systime; -} - -void -InitSelections() -{ - if (CurrentSelections) - xfree(CurrentSelections); - CurrentSelections = (Selection *)NULL; - NumCurrentSelections = 0; -} - -void -FlushClientCaches(XID id) -{ - int i; - register ClientPtr client; - - client = clients[CLIENT_ID(id)]; - if (client == NullClient) - return ; - for (i=0; ilastDrawableID == id) - { - client->lastDrawableID = WindowTable[0]->drawable.id; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - } - else if (client->lastGCID == id) - { - client->lastGCID = INVALID; - client->lastGC = (GCPtr)NULL; - } - } - } -} -#ifdef SMART_SCHEDULE - -#undef SMART_DEBUG - -#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */ -#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */ - -Bool SmartScheduleDisable = FALSE; -long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL; -long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE; -long SmartScheduleTime; -ClientPtr SmartLastClient; -int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1]; -int SmartScheduleClient(int *clientReady, int nready); - -#ifdef SMART_DEBUG -long SmartLastPrint; -#endif - -void Dispatch(void); -void InitProcVectors(void); - -int -SmartScheduleClient (int *clientReady, int nready) -{ - ClientPtr pClient; - int i; - int client; - int bestPrio, best = 0; - int bestRobin, robin; - long now = SmartScheduleTime; - long idle; - - bestPrio = -0x7fffffff; - bestRobin = 0; - idle = 2 * SmartScheduleSlice; - for (i = 0; i < nready; i++) - { - client = clientReady[i]; - pClient = clients[client]; - /* Praise clients which are idle */ - if ((now - pClient->smart_check_tick) >= idle) - { - if (pClient->smart_priority < 0) - pClient->smart_priority++; - } - pClient->smart_check_tick = now; - - /* check priority to select best client */ - robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff; - if (pClient->smart_priority > bestPrio || - (pClient->smart_priority == bestPrio && robin > bestRobin)) - { - bestPrio = pClient->smart_priority; - bestRobin = robin; - best = client; - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - fprintf (stderr, " %2d: %3d", client, pClient->smart_priority); -#endif - } -#ifdef SMART_DEBUG - if ((now - SmartLastPrint) >= 5000) - { - fprintf (stderr, " use %2d\n", best); - SmartLastPrint = now; - } -#endif - pClient = clients[best]; - SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index; - /* - * Set current client pointer - */ - if (SmartLastClient != pClient) - { - pClient->smart_start_tick = now; - SmartLastClient = pClient; - } - /* - * Adjust slice - */ - if (nready == 1) - { - /* - * If it's been a long time since another client - * has run, bump the slice up to get maximal - * performance from a single client - */ - if ((now - pClient->smart_start_tick) > 1000 && - SmartScheduleSlice < SmartScheduleMaxSlice) - { - SmartScheduleSlice += SmartScheduleInterval; - } - } - else - { - SmartScheduleSlice = SmartScheduleInterval; - } - return best; -} -#endif - -#define MAJOROP ((xReq *)client->requestBuffer)->reqType - -void -Dispatch(void) -{ - register int *clientReady; /* array of request ready clients */ - register int result; - register ClientPtr client; - register int nready; - register HWEventQueuePtr* icheck = checkForInput; -#ifdef SMART_SCHEDULE - long start_tick; -#endif - - nextFreeClientID = 1; - InitSelections(); - nClients = 0; - - clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients); - if (!clientReady) - return; - - while (!dispatchException) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } - - nready = WaitForSomething(clientReady); - -#ifdef SMART_SCHEDULE - if (nready && !SmartScheduleDisable) - { - clientReady[0] = SmartScheduleClient (clientReady, nready); - nready = 1; - } -#endif - /***************** - * Handle events in round robin fashion, doing input between - * each round - *****************/ - - while (!dispatchException && (--nready >= 0)) - { - client = clients[clientReady[nready]]; - if (! client) - { - /* KillClient can cause this to happen */ - continue; - } - /* GrabServer activation can cause this to be true */ - if (grabState == GrabKickout) - { - grabState = GrabActive; - break; - } - isItTimeToYield = FALSE; - - requestingClient = client; -#ifdef SMART_SCHEDULE - start_tick = SmartScheduleTime; -#endif - while (!isItTimeToYield) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } -#ifdef SMART_SCHEDULE - if (!SmartScheduleDisable && - (SmartScheduleTime - start_tick) >= SmartScheduleSlice) - { - /* Penalize clients which consume ticks */ - if (client->smart_priority > SMART_MIN_PRIORITY) - client->smart_priority--; - break; - } -#endif - /* now, finally, deal with client requests */ - - result = ReadRequestFromClient(client); - if (result <= 0) - { - if (result < 0) - CloseDownClient(client); - break; - } - - client->sequence++; -#ifdef DEBUG - if (client->requestLogIndex == MAX_REQUEST_LOG) - client->requestLogIndex = 0; - client->requestLog[client->requestLogIndex] = MAJOROP; - client->requestLogIndex++; -#endif - if (result > (maxBigRequestSize << 2)) - result = BadLength; - else - result = (* client->requestVector[MAJOROP])(client); - - if (result != Success) - { - if (client->noClientException != Success) - CloseDownClient(client); - else - SendErrorToClient(client, MAJOROP, - MinorOpcodeOfRequest(client), - client->errorValue, result); - break; - } -#ifdef DAMAGEEXT - FlushIfCriticalOutputPending (); -#endif - } - FlushAllOutput(); -#ifdef SMART_SCHEDULE - client = clients[clientReady[nready]]; - if (client) - client->smart_stop_tick = SmartScheduleTime; -#endif - requestingClient = NULL; - } - dispatchException &= ~DE_PRIORITYCHANGE; - } -#if defined(DDXBEFORERESET) - ddxBeforeReset (); -#endif - KillAllClients(); - DEALLOCATE_LOCAL(clientReady); - dispatchException &= ~DE_RESET; -} - -#undef MAJOROP - -int -ProcBadRequest(ClientPtr client) -{ - return (BadRequest); -} - -int -ProcCreateWindow(ClientPtr client) -{ - register WindowPtr pParent, pWin; - REQUEST(xCreateWindowReq); - int result; - int len; - - REQUEST_AT_LEAST_SIZE(xCreateWindowReq); - - LEGAL_NEW_RESOURCE(stuff->wid, client); - if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess))) - return BadWindow; - len = client->req_len - (sizeof(xCreateWindowReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - pWin = CreateWindow(stuff->wid, pParent, stuff->x, - stuff->y, stuff->width, stuff->height, - stuff->borderWidth, stuff->class, - stuff->mask, (XID *) &stuff[1], - (int)stuff->depth, - client, stuff->visual, &result); - if (pWin) - { - Mask mask = pWin->eventMask; - - pWin->eventMask = 0; /* subterfuge in case AddResource fails */ - if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin)) - return BadAlloc; - pWin->eventMask = mask; - } - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcChangeWindowAttributes(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xChangeWindowAttributesReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2); - if (len != Ones(stuff->valueMask)) - return BadLength; - result = ChangeWindowAttributes(pWin, - stuff->valueMask, - (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcGetWindowAttributes(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - xGetWindowAttributesReply wa; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - GetWindowAttributes(pWin, client, &wa); - WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa); - return(client->noClientException); -} - -int -ProcDestroyWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - if (pWin->parent) - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcDestroySubwindows(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityDestroyAccess); - if (!pWin) - return(BadWindow); - DestroySubwindows(pWin, client); - return(client->noClientException); -} - -int -ProcChangeSaveSet(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xChangeSaveSetReq); - register int result; - - REQUEST_SIZE_MATCH(xChangeSaveSetReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) - return BadMatch; - if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete)) - { - result = AlterSaveSetForClient(client, pWin, stuff->mode, FALSE, TRUE); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->mode; - return( BadValue ); - } -} - -int -ProcReparentWindow(register ClientPtr client) -{ - register WindowPtr pWin, pParent; - REQUEST(xReparentWindowReq); - register int result; - - REQUEST_SIZE_MATCH(xReparentWindowReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client, - SecurityWriteAccess); - if (!pParent) - return(BadWindow); - if (SAME_SCREENS(pWin->drawable, pParent->drawable)) - { - if ((pWin->backgroundState == ParentRelative) && - (pParent->drawable.depth != pWin->drawable.depth)) - return BadMatch; - if ((pWin->drawable.class != InputOnly) && - (pParent->drawable.class == InputOnly)) - return BadMatch; - result = ReparentWindow(pWin, pParent, - (short)stuff->x, (short)stuff->y, client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - return (BadMatch); -} - -int -ProcMapWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapWindow(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcMapSubwindows(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - MapSubwindows(pWin, client); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcUnmapWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapWindow(pWin, FALSE); - /* update cache to say it is mapped */ - return(client->noClientException); -} - -int -ProcUnmapSubwindows(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - UnmapSubwindows(pWin); - return(client->noClientException); -} - -int -ProcConfigureWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xConfigureWindowReq); - register int result; - int len; - - REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); - pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - len = client->req_len - (sizeof(xConfigureWindowReq) >> 2); - if (Ones((Mask)stuff->mask) != len) - return BadLength; - result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcCirculateWindow(register ClientPtr client) -{ - register WindowPtr pWin; - REQUEST(xCirculateWindowReq); - - REQUEST_SIZE_MATCH(xCirculateWindowReq); - if ((stuff->direction != RaiseLowest) && - (stuff->direction != LowerHighest)) - { - client->errorValue = stuff->direction; - return BadValue; - } - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - CirculateWindow(pWin, (int)stuff->direction, client); - return(client->noClientException); -} - -int -GetGeometry(register ClientPtr client, xGetGeometryReply *rep) -{ - register DrawablePtr pDraw; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess); - rep->type = X_Reply; - rep->length = 0; - rep->sequenceNumber = client->sequence; - rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - rep->depth = pDraw->depth; - rep->width = pDraw->width; - rep->height = pDraw->height; - - /* XXX - Because the pixmap-implementation of the multibuffer extension - * may have the buffer-id's drawable resource value be a pointer - * to the buffer's window instead of the buffer itself - * (this happens if the buffer is the displayed buffer), - * we also have to check that the id matches before we can - * truly say that it is a DRAWABLE_WINDOW. - */ - - if ((pDraw->type == UNDRAWABLE_WINDOW) || - ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id))) - { - register WindowPtr pWin = (WindowPtr)pDraw; - rep->x = pWin->origin.x - wBorderWidth (pWin); - rep->y = pWin->origin.y - wBorderWidth (pWin); - rep->borderWidth = pWin->borderWidth; - } - else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */ - { - rep->x = rep->y = rep->borderWidth = 0; - } - - return Success; -} - - -int -ProcGetGeometry(register ClientPtr client) -{ - xGetGeometryReply rep; - int status; - - if ((status = GetGeometry(client, &rep)) != Success) - return status; - - WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); - return(client->noClientException); -} - - -int -ProcQueryTree(register ClientPtr client) -{ - xQueryTreeReply reply; - int numChildren = 0; - register WindowPtr pChild, pWin, pHead; - Window *childIDs = (Window *)NULL; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - reply.type = X_Reply; - reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - reply.sequenceNumber = client->sequence; - if (pWin->parent) - reply.parent = pWin->parent->drawable.id; - else - reply.parent = (Window)None; - pHead = RealChildHead(pWin); - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - numChildren++; - if (numChildren) - { - int curChild = 0; - - childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window)); - if (!childIDs) - return BadAlloc; - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - childIDs[curChild++] = pChild->drawable.id; - } - - reply.nChildren = numChildren; - reply.length = (numChildren * sizeof(Window)) >> 2; - - WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply); - if (numChildren) - { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs); - DEALLOCATE_LOCAL(childIDs); - } - - return(client->noClientException); -} - -int -ProcInternAtom(register ClientPtr client) -{ - Atom atom; - char *tchar; - REQUEST(xInternAtomReq); - - REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes); - if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse)) - { - client->errorValue = stuff->onlyIfExists; - return(BadValue); - } - tchar = (char *) &stuff[1]; - atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists); - if (atom != BAD_RESOURCE) - { - xInternAtomReply reply; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.atom = atom; - WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); - return(client->noClientException); - } - else - return (BadAlloc); -} - -int -ProcGetAtomName(register ClientPtr client) -{ - char *str; - xGetAtomNameReply reply; - int len; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if ( (str = NameForAtom(stuff->id)) ) - { - len = strlen(str); - reply.type = X_Reply; - reply.length = (len + 3) >> 2; - reply.sequenceNumber = client->sequence; - reply.nameLength = len; - WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); - (void)WriteToClient(client, len, str); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -#ifdef K5AUTH -extern int k5_bad(); -#endif - -int -ProcSetSelectionOwner(register ClientPtr client) -{ - WindowPtr pWin; - TimeStamp time; - REQUEST(xSetSelectionOwnerReq); - - REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); - UpdateCurrentTime(); - time = ClientTimeToServerTime(stuff->time); - - /* If the client's time stamp is in the future relative to the server's - time stamp, do not set the selection, just return success. */ - if (CompareTimeStamps(time, currentTime) == LATER) - return Success; - if (stuff->window != None) - { - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - } - else - pWin = (WindowPtr)None; - if (ValidAtom(stuff->selection)) - { - int i = 0; - - /* - * First, see if the selection is already set... - */ - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) - i++; - if (i < NumCurrentSelections) - { - xEvent event; - - /* If the timestamp in client's request is in the past relative - to the time stamp indicating the last time the owner of the - selection was set, do not set the selection, just return - success. */ - if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged) - == EARLIER) - return Success; - if (CurrentSelections[i].client && - (!pWin || (CurrentSelections[i].client != client))) - { - event.u.u.type = SelectionClear; - event.u.selectionClear.time = time.milliseconds; - event.u.selectionClear.window = CurrentSelections[i].window; - event.u.selectionClear.atom = CurrentSelections[i].selection; - (void) TryClientEvents (CurrentSelections[i].client, &event, 1, - NoEventMask, NoEventMask /* CantBeFiltered */, - NullGrab); - } - } - else - { - /* - * It doesn't exist, so add it... - */ - Selection *newsels; - - if (i == 0) - newsels = (Selection *)xalloc(sizeof(Selection)); - else - newsels = (Selection *)xrealloc(CurrentSelections, - (NumCurrentSelections + 1) * sizeof(Selection)); - if (!newsels) - return BadAlloc; - NumCurrentSelections++; - CurrentSelections = newsels; - CurrentSelections[i].selection = stuff->selection; - } - CurrentSelections[i].lastTimeChanged = time; - CurrentSelections[i].window = stuff->window; - CurrentSelections[i].pWin = pWin; - CurrentSelections[i].client = (pWin ? client : NullClient); - if (SelectionCallback) - { - SelectionInfoRec info; - - info.selection = &CurrentSelections[i]; - info.kind= SelectionSetOwner; - CallCallbacks(&SelectionCallback, &info); - } - return (client->noClientException); - } - else - { - client->errorValue = stuff->selection; - return (BadAtom); - } -} - -int -ProcGetSelectionOwner(register ClientPtr client) -{ - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - if (ValidAtom(stuff->id)) - { - int i; - xGetSelectionOwnerReply reply; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->id) i++; - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - if (i < NumCurrentSelections) - reply.owner = CurrentSelections[i].window; - else - reply.owner = None; - WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadAtom); - } -} - -int -ProcConvertSelection(register ClientPtr client) -{ - Bool paramsOkay; - xEvent event; - WindowPtr pWin; - REQUEST(xConvertSelectionReq); - - REQUEST_SIZE_MATCH(xConvertSelectionReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target)); - if (stuff->property != None) - paramsOkay &= ValidAtom(stuff->property); - if (paramsOkay) - { - int i; - - i = 0; - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - if ((i < NumCurrentSelections) && - (CurrentSelections[i].window != None) -#ifdef XCSECURITY - && (!client->CheckAccess || - (* client->CheckAccess)(client, CurrentSelections[i].window, - RT_WINDOW, SecurityReadAccess, - CurrentSelections[i].pWin)) -#endif - ) - { - event.u.u.type = SelectionRequest; - event.u.selectionRequest.time = stuff->time; - event.u.selectionRequest.owner = - CurrentSelections[i].window; - event.u.selectionRequest.requestor = stuff->requestor; - event.u.selectionRequest.selection = stuff->selection; - event.u.selectionRequest.target = stuff->target; - event.u.selectionRequest.property = stuff->property; - if (TryClientEvents( - CurrentSelections[i].client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab)) - return (client->noClientException); - } - event.u.u.type = SelectionNotify; - event.u.selectionNotify.time = stuff->time; - event.u.selectionNotify.requestor = stuff->requestor; - event.u.selectionNotify.selection = stuff->selection; - event.u.selectionNotify.target = stuff->target; - event.u.selectionNotify.property = None; - (void) TryClientEvents(client, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab); - return (client->noClientException); - } - else - { - client->errorValue = stuff->property; - return (BadAtom); - } -} - -int -ProcGrabServer(register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xReq); - if (grabState != GrabNone && client != grabClient) - { - ResetCurrentRequest(client); - client->sequence--; - BITSET(grabWaiters, client->index); - IgnoreClient(client); - return(client->noClientException); - } - OnlyListenToOneClient(client); - grabState = GrabKickout; - grabClient = client; - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_GRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } - - return(client->noClientException); -} - -static void -UngrabServer(ClientPtr client) -{ - int i; - - grabState = GrabNone; - ListenToAllClients(); - for (i = mskcnt; --i >= 0 && !grabWaiters[i]; ) - ; - if (i >= 0) - { - i <<= 5; - while (!GETBIT(grabWaiters, i)) - i++; - BITCLEAR(grabWaiters, i); - AttendClient(clients[i]); - } - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_UNGRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); - } -} - -int -ProcUngrabServer(register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xReq); - UngrabServer(client); - return(client->noClientException); -} - -int -ProcTranslateCoords(register ClientPtr client) -{ - REQUEST(xTranslateCoordsReq); - - register WindowPtr pWin, pDst; - xTranslateCoordsReply rep; - - REQUEST_SIZE_MATCH(xTranslateCoordsReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client, - SecurityReadAccess); - if (!pDst) - return(BadWindow); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) - { - rep.sameScreen = xFalse; - rep.child = None; - rep.dstX = rep.dstY = 0; - } - else - { - INT16 x, y; - rep.sameScreen = xTrue; - rep.child = None; - /* computing absolute coordinates -- adjust to destination later */ - x = pWin->drawable.x + stuff->srcX; - y = pWin->drawable.y + stuff->srcY; - pWin = pDst->firstChild; - while (pWin) - { -#ifdef SHAPE - BoxRec box; -#endif - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth (pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - &pWin->borderSize, x, y, &box)) - - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) -#endif - ) - { - rep.child = pWin->drawable.id; - pWin = (WindowPtr) NULL; - } - else - pWin = pWin->nextSib; - } - /* adjust to destination coordinates */ - rep.dstX = x - pDst->drawable.x; - rep.dstY = y - pDst->drawable.y; - } - WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep); - return(client->noClientException); -} - -int -ProcOpenFont(register ClientPtr client) -{ - int err; - REQUEST(xOpenFontReq); - - REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes); - client->errorValue = stuff->fid; - LEGAL_NEW_RESOURCE(stuff->fid, client); - err = OpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcCloseFont(register ClientPtr client) -{ - FontPtr pFont; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityDestroyAccess); - if ( pFont != (FontPtr)NULL) /* id was valid */ - { - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadFont); - } -} - -int -ProcQueryFont(register ClientPtr client) -{ - xQueryFontReply *reply; - FontPtr pFont; - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - client->errorValue = stuff->id; /* EITHER font or gc */ - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - /* can't use VERIFY_GC because it might return BadGC */ - pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->id; - return(BadFont); /* procotol spec says only error is BadFont */ - } - pFont = pGC->font; - } - - { - xCharInfo *pmax = FONTINKMAX(pFont); - xCharInfo *pmin = FONTINKMIN(pFont); - int nprotoxcistructs; - int rlength; - - nprotoxcistructs = ( - pmax->rightSideBearing == pmin->rightSideBearing && - pmax->leftSideBearing == pmin->leftSideBearing && - pmax->descent == pmin->descent && - pmax->ascent == pmin->ascent && - pmax->characterWidth == pmin->characterWidth) ? - 0 : N2dChars(pFont); - - rlength = sizeof(xQueryFontReply) + - FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) + - nprotoxcistructs * sizeof(xCharInfo); - reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength); - if(!reply) - { - return(BadAlloc); - } - - reply->type = X_Reply; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->sequenceNumber = client->sequence; - QueryFont( pFont, reply, nprotoxcistructs); - - WriteReplyToClient(client, rlength, reply); - DEALLOCATE_LOCAL(reply); - return(client->noClientException); - } -} - -int -ProcQueryTextExtents(register ClientPtr client) -{ - REQUEST(xQueryTextExtentsReq); - xQueryTextExtentsReply reply; - FontPtr pFont; - GC *pGC; - ExtentInfoRec info; - unsigned long length; - - REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); - - pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC, - SecurityReadAccess); - if (!pGC) - { - client->errorValue = stuff->fid; - return(BadFont); - } - pFont = pGC->font; - } - length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2); - length = length << 1; - if (stuff->oddLength) - { - if (length == 0) - return(BadLength); - length--; - } - if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info)) - return(BadAlloc); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.drawDirection = info.drawDirection; - reply.fontAscent = info.fontAscent; - reply.fontDescent = info.fontDescent; - reply.overallAscent = info.overallAscent; - reply.overallDescent = info.overallDescent; - reply.overallWidth = info.overallWidth; - reply.overallLeft = info.overallLeft; - reply.overallRight = info.overallRight; - WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply); - return(client->noClientException); -} - -int -ProcListFonts(register ClientPtr client) -{ - REQUEST(xListFontsReq); - - REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes); - - return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, - stuff->maxNames); -} - -int -ProcListFontsWithInfo(register ClientPtr client) -{ - REQUEST(xListFontsWithInfoReq); - - REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes); - - return StartListFontsWithInfo(client, stuff->nbytes, - (unsigned char *) &stuff[1], stuff->maxNames); -} - -/** - * - * \param value must conform to DeleteType - */ -int -dixDestroyPixmap(pointer value, XID pid) -{ - PixmapPtr pPixmap = (PixmapPtr)value; - return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); -} - -int -ProcCreatePixmap(register ClientPtr client) -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - REQUEST(xCreatePixmapReq); - DepthPtr pDepth; - register int i; - - REQUEST_SIZE_MATCH(xCreatePixmapReq); - client->errorValue = stuff->pid; - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; - return BadValue; - } - if (stuff->width > 32767 || stuff->height > 32767) - { - /* It is allowed to try and allocate a pixmap which is larger than - * 32767 in either dimension. However, all of the framebuffer code - * is buggy and does not reliably draw to such big pixmaps, basically - * because the Region data structure operates with signed shorts - * for the rectangles in it. - * - * Furthermore, several places in the X server computes the - * size in bytes of the pixmap and tries to store it in an - * integer. This integer can overflow and cause the allocated size - * to be much smaller. - * - * So, such big pixmaps are rejected here with a BadAlloc - */ - return BadAlloc; - } - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } -CreatePmap: - pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap) - (pDraw->pScreen, stuff->width, - stuff->height, stuff->depth); - if (pMap) - { - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - return(client->noClientException); - } - return (BadAlloc); -} - -int -ProcFreePixmap(register ClientPtr client) -{ - PixmapPtr pMap; - - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP, - SecurityDestroyAccess); - if (pMap) - { - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadPixmap); - } -} - -int -ProcCreateGC(register ClientPtr client) -{ - int error; - GC *pGC; - register DrawablePtr pDraw; - unsigned len; - REQUEST(xCreateGCReq); - - REQUEST_AT_LEAST_SIZE(xCreateGCReq); - client->errorValue = stuff->gc; - LEGAL_NEW_RESOURCE(stuff->gc, client); - SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - len = client->req_len - (sizeof(xCreateGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - pGC = (GC *)CreateGC(pDraw, stuff->mask, - (XID *) &stuff[1], &error); - if (error != Success) - return error; - if (!AddResource(stuff->gc, RT_GC, (pointer)pGC)) - return (BadAlloc); - return(client->noClientException); -} - -int -ProcChangeGC(register ClientPtr client) -{ - GC *pGC; - REQUEST(xChangeGCReq); - int result; - unsigned len; - - REQUEST_AT_LEAST_SIZE(xChangeGCReq); - SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess); - len = client->req_len - (sizeof(xChangeGCReq) >> 2); - if (len != Ones(stuff->mask)) - return BadLength; - - result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcCopyGC(register ClientPtr client) -{ - register GC *dstGC; - register GC *pGC; - int result; - REQUEST(xCopyGCReq); - - REQUEST_SIZE_MATCH(xCopyGCReq); - SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess); - SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess); - if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth)) - return (BadMatch); - result = CopyGC(pGC, dstGC, stuff->mask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetDashes(register ClientPtr client) -{ - register GC *pGC; - int result; - REQUEST(xSetDashesReq); - - REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes); - if (stuff->nDashes == 0) - { - client->errorValue = 0; - return BadValue; - } - - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes, - (unsigned char *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } -} - -int -ProcSetClipRectangles(register ClientPtr client) -{ - int nr; - int result; - register GC *pGC; - REQUEST(xSetClipRectanglesReq); - - REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq); - if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && - (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) - { - client->errorValue = stuff->ordering; - return BadValue; - } - SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess); - - nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq); - if (nr & 4) - return(BadLength); - nr >>= 3; - result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *)&stuff[1], (int)stuff->ordering); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -int -ProcFreeGC(register ClientPtr client) -{ - register GC *pGC; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess); - FreeResource(stuff->id, RT_NONE); - return(client->noClientException); -} - -int -ProcClearToBackground(register ClientPtr client) -{ - REQUEST(xClearAreaReq); - register WindowPtr pWin; - - REQUEST_SIZE_MATCH(xClearAreaReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (pWin->drawable.class == InputOnly) - { - client->errorValue = stuff->window; - return (BadMatch); - } - if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) - { - client->errorValue = stuff->exposures; - return(BadValue); - } - (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y, - stuff->width, stuff->height, - (Bool)stuff->exposures); - return(client->noClientException); -} - -int -ProcCopyArea(register ClientPtr client) -{ - register DrawablePtr pDst; - register DrawablePtr pSrc; - register GC *pGC; - REQUEST(xCopyAreaReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyAreaReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client, - SecurityReadAccess); - if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - pSrc = pDst; - - SET_DBE_SRCBUF(pSrc, stuff->srcDrawable); - - pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY); - if (pGC->graphicsExposures) - { - (*pDst->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); - if (pRgn) - REGION_DESTROY(pDst->pScreen, pRgn); - } - - return(client->noClientException); -} - -int -ProcCopyPlane(register ClientPtr client) -{ - register DrawablePtr psrcDraw, pdstDraw; - register GC *pGC; - REQUEST(xCopyPlaneReq); - RegionPtr pRgn; - - REQUEST_SIZE_MATCH(xCopyPlaneReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client); - if (stuff->dstDrawable != stuff->srcDrawable) - { - SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client, - SecurityReadAccess); - if (pdstDraw->pScreen != psrcDraw->pScreen) - { - client->errorValue = stuff->dstDrawable; - return (BadMatch); - } - } - else - psrcDraw = pdstDraw; - - SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable); - - /* Check to see if stuff->bitPlane has exactly ONE good bit set */ - if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || - (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) - { - client->errorValue = stuff->bitPlane; - return(BadValue); - } - - pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY, stuff->bitPlane); - if (pGC->graphicsExposures) - { - (*pdstDraw->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); - if (pRgn) - REGION_DESTROY(pdstDraw->pScreen, pRgn); - } - return(client->noClientException); -} - -int -ProcPolyPoint(register ClientPtr client) -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyPointReq); - - REQUEST_AT_LEAST_SIZE(xPolyPointReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2; - if (npoint) - (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, - (xPoint *) &stuff[1]); - return (client->noClientException); -} - -int -ProcPolyLine(register ClientPtr client) -{ - int npoint; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyLineReq); - - REQUEST_AT_LEAST_SIZE(xPolyLineReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2; - if (npoint > 1) - (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, - (DDXPointPtr) &stuff[1]); - return(client->noClientException); -} - -int -ProcPolySegment(register ClientPtr client) -{ - int nsegs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolySegmentReq); - - REQUEST_AT_LEAST_SIZE(xPolySegmentReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); - if (nsegs & 4) - return(BadLength); - nsegs >>= 3; - if (nsegs) - (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]); - return (client->noClientException); -} - -int -ProcPolyRectangle (register ClientPtr client) -{ - int nrects; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); - if (nrects & 4) - return(BadLength); - nrects >>= 3; - if (nrects) - (*pGC->ops->PolyRectangle)(pDraw, pGC, - nrects, (xRectangle *) &stuff[1]); - return(client->noClientException); -} - -int -ProcPolyArc(register ClientPtr client) -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]); - return (client->noClientException); -} - -int -ProcFillPoly(register ClientPtr client) -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xFillPolyReq); - - REQUEST_AT_LEAST_SIZE(xFillPolyReq); - if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) && - (stuff->shape != Convex)) - { - client->errorValue = stuff->shape; - return BadValue; - } - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; - return BadValue; - } - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2; - if (things) - (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, - stuff->coordMode, things, - (DDXPointPtr) &stuff[1]); - return(client->noClientException); -} - -int -ProcPolyFillRectangle(register ClientPtr client) -{ - int things; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillRectangleReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); - if (things & 4) - return(BadLength); - things >>= 3; - - if (things) - (*pGC->ops->PolyFillRect) (pDraw, pGC, things, - (xRectangle *) &stuff[1]); - return (client->noClientException); -} - -int -ProcPolyFillArc(register ClientPtr client) -{ - int narcs; - register GC *pGC; - register DrawablePtr pDraw; - REQUEST(xPolyFillArcReq); - - REQUEST_AT_LEAST_SIZE(xPolyFillArcReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); - if (narcs % sizeof(xArc)) - return(BadLength); - narcs /= sizeof(xArc); - if (narcs) - (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); - return (client->noClientException); -} - -#ifdef MATCH_CLIENT_ENDIAN - -int -ServerOrder (void) -{ - int whichbyte = 1; - - if (*((char *) &whichbyte)) - return LSBFirst; - return MSBFirst; -} - -#define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder()) - -void -ReformatImage (char *base, int nbytes, int bpp, int order) -{ - switch (bpp) { - case 1: /* yuck */ - if (BITMAP_BIT_ORDER != order) - BitOrderInvert ((unsigned char *) base, nbytes); -#if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8 - ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order); -#endif - break; - case 4: - break; /* yuck */ - case 8: - break; - case 16: - if (IMAGE_BYTE_ORDER != order) - TwoByteSwap ((unsigned char *) base, nbytes); - break; - case 32: - if (IMAGE_BYTE_ORDER != order) - FourByteSwap ((unsigned char *) base, nbytes); - break; - } -} -#else -#define ReformatImage(b,n,bpp,o) -#endif - -/* 64-bit server notes: the protocol restricts padding of images to - * 8-, 16-, or 32-bits. We would like to have 64-bits for the server - * to use internally. Removes need for internal alignment checking. - * All of the PutImage functions could be changed individually, but - * as currently written, they call other routines which require things - * to be 64-bit padded on scanlines, so we changed things here. - * If an image would be padded differently for 64- versus 32-, then - * copy each scanline to a 64-bit padded scanline. - * Also, we need to make sure that the image is aligned on a 64-bit - * boundary, even if the scanlines are padded to our satisfaction. - */ -int -ProcPutImage(register ClientPtr client) -{ - register GC *pGC; - register DrawablePtr pDraw; - long length; /* length of scanline server padded */ - long lengthProto; /* length of scanline protocol padded */ - char *tmpImage; - REQUEST(xPutImageReq); - - REQUEST_AT_LEAST_SIZE(xPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - if (stuff->format == XYBitmap) - { - if ((stuff->depth != 1) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - } - else if (stuff->format == XYPixmap) - { - if ((pDraw->depth != stuff->depth) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) - return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0)) - return BadMatch; - length = PixmapBytePad(stuff->width, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - tmpImage = (char *)&stuff[1]; - lengthProto = length; - - if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) + - (sizeof(xPutImageReq) >> 2)) != client->req_len) - return BadLength; - - ReformatImage (tmpImage, lengthProto * stuff->height, - stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1, - ClientOrder(client)); - - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY, - stuff->width, stuff->height, - stuff->leftPad, stuff->format, tmpImage); - - return (client->noClientException); -} - - -int -DoGetImage(register ClientPtr client, int format, Drawable drawable, - int x, int y, int width, int height, - Mask planemask, xGetImageReply **im_return) -{ - register DrawablePtr pDraw; - int nlines, linesPerBuf; - register int linesDone; - long widthBytesLine, length; - Mask plane = 0; - char *pBuf; - xGetImageReply xgi; -#ifdef XCSECURITY - RegionPtr pVisibleRegion = NULL; -#endif - - if ((format != XYPixmap) && (format != ZPixmap)) - { - client->errorValue = format; - return(BadValue); - } - SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess); - if(pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + x < 0 || - pDraw->x + x + width > pDraw->pScreen->width || - pDraw->y + y < 0 || - pDraw->y + y + height > pDraw->pScreen->height || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual (((WindowPtr) pDraw)); - } - else - { - if(x < 0 || - x+width > (int)pDraw->width || - y < 0 || - y+height > (int)pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - - SET_DBE_SRCBUF(pDraw, drawable); - - xgi.type = X_Reply; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(format == ZPixmap) - { - widthBytesLine = PixmapBytePad(width, pDraw->depth); - length = widthBytesLine * height; - - } - else - { - widthBytesLine = BitmapBytePad(width); - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = widthBytesLine * height * - Ones(planemask & (plane | (plane - 1))); - - } - - xgi.length = length; - - if (im_return) { - pBuf = (char *)xalloc(sz_xGetImageReply + length); - if (!pBuf) - return (BadAlloc); - if (widthBytesLine == 0) - linesPerBuf = 0; - else - linesPerBuf = height; - *im_return = (xGetImageReply *)pBuf; - *(xGetImageReply *)pBuf = xgi; - pBuf += sz_xGetImageReply; - } else { - xgi.length = (xgi.length + 3) >> 2; - if (widthBytesLine == 0 || height == 0) - linesPerBuf = 0; - else if (widthBytesLine >= IMAGE_BUFSIZE) - linesPerBuf = 1; - else - { - linesPerBuf = IMAGE_BUFSIZE / widthBytesLine; - if (linesPerBuf > height) - linesPerBuf = height; - } - length = linesPerBuf * widthBytesLine; - if (linesPerBuf < height) - { - /* we have to make sure intermediate buffers don't need padding */ - while ((linesPerBuf > 1) && - (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))) - { - linesPerBuf--; - length -= widthBytesLine; - } - while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)) - { - linesPerBuf++; - length += widthBytesLine; - } - } - if(!(pBuf = (char *) ALLOCATE_LOCAL(length))) - return (BadAlloc); - WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); - } - -#ifdef XCSECURITY - if (client->trustLevel != XSecurityClientTrusted && - pDraw->type == DRAWABLE_WINDOW) - { - pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw); - if (pVisibleRegion) - { - REGION_TRANSLATE(pDraw->pScreen, pVisibleRegion, -pDraw->x, -pDraw->y); - } - } -#endif - - if (linesPerBuf == 0) - { - /* nothing to do */ - } - else if (format == ZPixmap) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - planemask, - (pointer) pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note that this is NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (!im_return) - { - ReformatImage (pBuf, (int)(nlines * widthBytesLine), - BitsPerPixel (pDraw->depth), - ClientOrder(client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - else /* XYPixmap */ - { - for (; plane; plane >>= 1) - { - if (planemask & plane) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - plane, - (pointer)pBuf); -#ifdef XCSECURITY - if (pVisibleRegion) - SecurityCensorImage(client, pVisibleRegion, - widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); -#endif - - /* Note: NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (im_return) { - pBuf += nlines * widthBytesLine; - } else { - ReformatImage (pBuf, - (int)(nlines * widthBytesLine), - 1, - ClientOrder (client)); - -/* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } - } - } - } -#ifdef XCSECURITY - if (pVisibleRegion) - REGION_DESTROY(pDraw->pScreen, pVisibleRegion); -#endif - if (!im_return) - DEALLOCATE_LOCAL(pBuf); - return (client->noClientException); -} - -int -ProcGetImage(register ClientPtr client) -{ - REQUEST(xGetImageReq); - - REQUEST_SIZE_MATCH(xGetImageReq); - - return DoGetImage(client, stuff->format, stuff->drawable, - stuff->x, stuff->y, - (int)stuff->width, (int)stuff->height, - stuff->planeMask, (xGetImageReply **)NULL); -} - -int -ProcPolyText(register ClientPtr client) -{ - int err; - REQUEST(xPolyTextReq); - DrawablePtr pDraw; - GC *pGC; - - REQUEST_AT_LEAST_SIZE(xPolyTextReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = PolyText(client, - pDraw, - pGC, - (unsigned char *)&stuff[1], - ((unsigned char *) stuff) + (client->req_len << 2), - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText8(register ClientPtr client) -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - -int -ProcImageText16(register ClientPtr client) -{ - int err; - register DrawablePtr pDraw; - register GC *pGC; - - REQUEST(xImageTextReq); - - REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return(client->noClientException); - } - else - return err; -} - - -int -ProcCreateColormap(register ClientPtr client) -{ - VisualPtr pVisual; - ColormapPtr pmap; - Colormap mid; - register WindowPtr pWin; - ScreenPtr pScreen; - REQUEST(xCreateColormapReq); - int i, result; - - REQUEST_SIZE_MATCH(xCreateColormapReq); - - if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) - { - client->errorValue = stuff->alloc; - return(BadValue); - } - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pScreen = pWin->drawable.pScreen; - for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid != stuff->visual) - continue; - result = CreateColormap(mid, pScreen, pVisual, &pmap, - (int)stuff->alloc, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - client->errorValue = stuff->visual; - return(BadValue); -} - -int -ProcFreeColormap(register ClientPtr client) -{ - ColormapPtr pmap; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP, - SecurityDestroyAccess); - if (pmap) - { - /* Freeing a default colormap is a no-op */ - if (!(pmap->flags & IsDefault)) - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - - -int -ProcCopyColormapAndFree(register ClientPtr client) -{ - Colormap mid; - ColormapPtr pSrcMap; - REQUEST(xCopyColormapAndFreeReq); - int result; - - REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); - mid = stuff->mid; - LEGAL_NEW_RESOURCE(mid, client); - if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client, stuff->srcCmap, - RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) ) - { - result = CopyColormapAndFree(mid, pSrcMap, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->srcCmap; - return(BadColor); - } -} - -int -ProcInstallColormap(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - (*(pcmp->pScreen->InstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcUninstallColormap(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - if(pcmp->mid != pcmp->pScreen->defColormap) - (*(pcmp->pScreen->UninstallColormap)) (pcmp); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadColor); - } -} - -int -ProcListInstalledColormaps(register ClientPtr client) -{ - xListInstalledColormapsReply *preply; - int nummaps; - WindowPtr pWin; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - - if (!pWin) - return(BadWindow); - - preply = (xListInstalledColormapsReply *) - ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) + - pWin->drawable.pScreen->maxInstalledCmaps * - sizeof(Colormap)); - if(!preply) - return(BadAlloc); - - preply->type = X_Reply; - preply->sequenceNumber = client->sequence; - nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pWin->drawable.pScreen, (Colormap *)&preply[1]); - preply->nColormaps = nummaps; - preply->length = nummaps; - WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); - DEALLOCATE_LOCAL(preply); - return(client->noClientException); -} - -int -ProcAllocColor (register ClientPtr client) -{ - ColormapPtr pmap; - int retval; - xAllocColorReply acr; - REQUEST(xAllocColorReq); - - REQUEST_SIZE_MATCH(xAllocColorReq); - pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pmap) - { -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pmap, (xReq *) stuff)) - return Success; -#endif - acr.type = X_Reply; - acr.length = 0; - acr.sequenceNumber = client->sequence; - acr.red = stuff->red; - acr.green = stuff->green; - acr.blue = stuff->blue; - acr.pixel = 0; - if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, - &acr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return (retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pmap->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); - return (client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocNamedColor (register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xAllocNamedColorReq); - - REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int retval; - - xAllocNamedColorReply ancr; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocNamedColor request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - ancr.type = X_Reply; - ancr.length = 0; - ancr.sequenceNumber = client->sequence; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) - { - ancr.screenRed = ancr.exactRed; - ancr.screenGreen = ancr.exactGreen; - ancr.screenBlue = ancr.exactBlue; - ancr.pixel = 0; - if( (retval = AllocColor(pcmp, - &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue, - &ancr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr); - return (client->noClientException); - } - else - return(BadName); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorCells (register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xAllocColorCellsReq); - - REQUEST_SIZE_MATCH(xAllocColorCellsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorCellsReply accr; - int npixels, nmasks, retval; - long length; - Pixel *ppixels, *pmasks; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorCells request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - nmasks = stuff->planes; - length = ((long)npixels + (long)nmasks) * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - pmasks = ppixels + npixels; - - if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, - (Bool)stuff->contiguous, ppixels, pmasks)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - accr.type = X_Reply; - accr.length = length >> 2; - accr.sequenceNumber = client->sequence; - accr.nPixels = npixels; - accr.nMasks = nmasks; - WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcAllocColorPlanes(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xAllocColorPlanesReq); - - REQUEST_SIZE_MATCH(xAllocColorPlanesReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xAllocColorPlanesReply acpr; - int npixels, retval; - long length; - Pixel *ppixels; - -#ifdef LBX - /* - * If the colormap is grabbed by a proxy, the server will have - * to regain control over the colormap. This AllocColorPlanes request - * will be handled after the server gets back the colormap control. - */ - if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff)) - return Success; -#endif - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return (BadValue); - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return (BadValue); - } - acpr.type = X_Reply; - acpr.sequenceNumber = client->sequence; - acpr.nPixels = npixels; - length = (long)npixels * sizeof(Pixel); - ppixels = (Pixel *)ALLOCATE_LOCAL(length); - if(!ppixels) - return(BadAlloc); - if( (retval = AllocColorPlanes(client->index, pcmp, npixels, - (int)stuff->red, (int)stuff->green, (int)stuff->blue, - (Bool)stuff->contiguous, ppixels, - &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) ) - { - DEALLOCATE_LOCAL(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - acpr.length = length >> 2; -#ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) -#endif - { - WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - DEALLOCATE_LOCAL(ppixels); - return (client->noClientException); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcFreeColors(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xFreeColorsReq); - - REQUEST_AT_LEAST_SIZE(xFreeColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - if(pcmp->flags & AllAllocated) - return(BadAccess); - count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2; - retval = FreeColors(pcmp, client->index, count, - (Pixel *)&stuff[1], (Pixel)stuff->planeMask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreColors (ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xStoreColorsReq); - - REQUEST_AT_LEAST_SIZE(xStoreColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - int count; - int retval; - - count = (client->req_len << 2) - sizeof(xStoreColorsReq); - if (count % sizeof(xColorItem)) - return(BadLength); - count /= sizeof(xColorItem); - retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(retval); - } - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcStoreNamedColor (register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xStoreNamedColorReq); - - REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityWriteAccess); - if (pcmp) - { - xColorItem def; - int retval; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], - stuff->nbytes, &def.red, &def.green, &def.blue)) - { - def.flags = stuff->flags; - def.pixel = stuff->pixel; - retval = StoreColors(pcmp, 1, &def); - if (client->noClientException != Success) - return(client->noClientException); - else - return(retval); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcQueryColors(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xQueryColorsReq); - - REQUEST_AT_LEAST_SIZE(xQueryColorsReq); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - int count, retval; - xrgb *prgbs; - xQueryColorsReply qcr; - - count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2; - prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb)); - if(!prgbs && count) - return(BadAlloc); - if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) ) - { - if (prgbs) DEALLOCATE_LOCAL(prgbs); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return (retval); - } - } - qcr.type = X_Reply; - qcr.length = (count * sizeof(xrgb)) >> 2; - qcr.sequenceNumber = client->sequence; - qcr.nColors = count; - WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); - if (count) - { - client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; - WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); - } - if (prgbs) DEALLOCATE_LOCAL(prgbs); - return(client->noClientException); - - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcLookupColor(register ClientPtr client) -{ - ColormapPtr pcmp; - REQUEST(xLookupColorReq); - - REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes); - pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap, - RT_COLORMAP, SecurityReadAccess); - if (pcmp) - { - xLookupColorReply lcr; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) - { - lcr.type = X_Reply; - lcr.length = 0; - lcr.sequenceNumber = client->sequence; - lcr.screenRed = lcr.exactRed; - lcr.screenGreen = lcr.exactGreen; - lcr.screenBlue = lcr.exactBlue; - (*pcmp->pScreen->ResolveColor)(&lcr.screenRed, - &lcr.screenGreen, - &lcr.screenBlue, - pcmp->pVisual); - WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); - return(client->noClientException); - } - return (BadName); - } - else - { - client->errorValue = stuff->cmap; - return (BadColor); - } -} - -int -ProcCreateCursor (register ClientPtr client) -{ - CursorPtr pCursor; - - register PixmapPtr src; - register PixmapPtr msk; - unsigned char * srcbits; - unsigned char * mskbits; - unsigned short width, height; - long n; - CursorMetricRec cm; - - - REQUEST(xCreateCursorReq); - - REQUEST_SIZE_MATCH(xCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source, - RT_PIXMAP, SecurityReadAccess); - msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask, - RT_PIXMAP, SecurityReadAccess); - if ( src == (PixmapPtr)NULL) - { - client->errorValue = stuff->source; - return (BadPixmap); - } - if ( msk == (PixmapPtr)NULL) - { - if (stuff->mask != None) - { - client->errorValue = stuff->mask; - return (BadPixmap); - } - } - else if ( src->drawable.width != msk->drawable.width - || src->drawable.height != msk->drawable.height - || src->drawable.depth != 1 - || msk->drawable.depth != 1) - return (BadMatch); - - width = src->drawable.width; - height = src->drawable.height; - - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - - n = BitmapBytePad(width)*height; - srcbits = (unsigned char *)xalloc(n); - if (!srcbits) - return (BadAlloc); - mskbits = (unsigned char *)xalloc(n); - if (!mskbits) - { - xfree(srcbits); - return (BadAlloc); - } - - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)srcbits, n); - (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height, - XYPixmap, 1, (pointer)srcbits); - if ( msk == (PixmapPtr)NULL) - { - register unsigned char *bits = mskbits; - while (--n >= 0) - *bits++ = ~0; - } - else - { - /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)mskbits, n); - (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width, - height, XYPixmap, 1, (pointer)mskbits); - } - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - pCursor = AllocCursor( srcbits, mskbits, &cm, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue); - - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; -} - -int -ProcCreateGlyphCursor (register ClientPtr client) -{ - CursorPtr pCursor; - int res; - - REQUEST(xCreateGlyphCursorReq); - - REQUEST_SIZE_MATCH(xCreateGlyphCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - res = AllocGlyphCursor(stuff->source, stuff->sourceChar, - stuff->mask, stuff->maskChar, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client); - if (res != Success) - return res; - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - - -int -ProcFreeCursor (register ClientPtr client) -{ - CursorPtr pCursor; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id, - RT_CURSOR, SecurityDestroyAccess); - if (pCursor) - { - FreeResource(stuff->id, RT_NONE); - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadCursor); - } -} - -int -ProcQueryBestSize (register ClientPtr client) -{ - xQueryBestSizeReply reply; - register DrawablePtr pDraw; - ScreenPtr pScreen; - REQUEST(xQueryBestSizeReq); - - REQUEST_SIZE_MATCH(xQueryBestSizeReq); - if ((stuff->class != CursorShape) && - (stuff->class != TileShape) && - (stuff->class != StippleShape)) - { - client->errorValue = stuff->class; - return(BadValue); - } - SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client, - SecurityReadAccess); - if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW) - return (BadMatch); - pScreen = pDraw->pScreen; - (* pScreen->QueryBestSize)(stuff->class, &stuff->width, - &stuff->height, pScreen); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.width = stuff->width; - reply.height = stuff->height; - WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply); - return (client->noClientException); -} - - -int -ProcSetScreenSaver (register ClientPtr client) -{ - int blankingOption, exposureOption; - REQUEST(xSetScreenSaverReq); - - REQUEST_SIZE_MATCH(xSetScreenSaverReq); - blankingOption = stuff->preferBlank; - if ((blankingOption != DontPreferBlanking) && - (blankingOption != PreferBlanking) && - (blankingOption != DefaultBlanking)) - { - client->errorValue = blankingOption; - return BadValue; - } - exposureOption = stuff->allowExpose; - if ((exposureOption != DontAllowExposures) && - (exposureOption != AllowExposures) && - (exposureOption != DefaultExposures)) - { - client->errorValue = exposureOption; - return BadValue; - } - if (stuff->timeout < -1) - { - client->errorValue = stuff->timeout; - return BadValue; - } - if (stuff->interval < -1) - { - client->errorValue = stuff->interval; - return BadValue; - } - - if (blankingOption == DefaultBlanking) - ScreenSaverBlanking = defaultScreenSaverBlanking; - else - ScreenSaverBlanking = blankingOption; - if (exposureOption == DefaultExposures) - ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; - else - ScreenSaverAllowExposures = exposureOption; - - if (stuff->timeout >= 0) - ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND; - else - ScreenSaverTime = defaultScreenSaverTime; - if (stuff->interval >= 0) - ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND; - else - ScreenSaverInterval = defaultScreenSaverInterval; - - SetScreenSaverTimer(); - return (client->noClientException); -} - -int -ProcGetScreenSaver(register ClientPtr client) -{ - xGetScreenSaverReply rep; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.timeout = ScreenSaverTime / MILLI_PER_SECOND; - rep.interval = ScreenSaverInterval / MILLI_PER_SECOND; - rep.preferBlanking = ScreenSaverBlanking; - rep.allowExposures = ScreenSaverAllowExposures; - WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep); - return (client->noClientException); -} - -int -ProcChangeHosts(register ClientPtr client) -{ - REQUEST(xChangeHostsReq); - int result; - - REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength); - - if(stuff->mode == HostInsert) - result = AddHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else if (stuff->mode == HostDelete) - result = RemoveHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); - else - { - client->errorValue = stuff->mode; - return BadValue; - } - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcListHosts(register ClientPtr client) -{ - xListHostsReply reply; - int len, nHosts, result; - pointer pdata; - /* REQUEST(xListHostsReq); */ - - REQUEST_SIZE_MATCH(xListHostsReq); -#ifdef XCSECURITY - /* untrusted clients can't list hosts */ - if (client->trustLevel != XSecurityClientTrusted) - { - SecurityAudit("client %d attempted to list hosts\n", client->index); - return BadAccess; - } -#endif - result = GetHosts(&pdata, &nHosts, &len, &reply.enabled); - if (result != Success) - return(result); - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.nHosts = nHosts; - reply.length = len >> 2; - WriteReplyToClient(client, sizeof(xListHostsReply), &reply); - if (nHosts) - { - client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; - WriteSwappedDataToClient(client, len, pdata); - } - xfree(pdata); - return (client->noClientException); -} - -int -ProcChangeAccessControl(register ClientPtr client) -{ - int result; - REQUEST(xSetAccessControlReq); - - REQUEST_SIZE_MATCH(xSetAccessControlReq); - if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) - { - client->errorValue = stuff->mode; - return BadValue; - } - result = ChangeAccessControl(client, stuff->mode == EnableAccess); - if (!result) - result = client->noClientException; - return (result); -} - -int -ProcKillClient(register ClientPtr client) -{ - REQUEST(xResourceReq); - ClientPtr killclient; - - REQUEST_SIZE_MATCH(xResourceReq); - if (stuff->id == AllTemporary) - { - CloseDownRetainedResources(); - return (client->noClientException); - } - - if ((killclient = LookupClient(stuff->id, client))) - { - CloseDownClient(killclient); - /* if an LBX proxy gets killed, isItTimeToYield will be set */ - if (isItTimeToYield || (client == killclient)) - { - /* force yield and return Success, so that Dispatch() - * doesn't try to touch client - */ - isItTimeToYield = TRUE; - return (Success); - } - return (client->noClientException); - } - else - { - client->errorValue = stuff->id; - return (BadValue); - } -} - -int -ProcSetFontPath(register ClientPtr client) -{ - unsigned char *ptr; - unsigned long nbytes, total; - long nfonts; - int n, result; - int error; - REQUEST(xSetFontPathReq); - - REQUEST_AT_LEAST_SIZE(xSetFontPathReq); - - nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq); - total = nbytes; - ptr = (unsigned char *)&stuff[1]; - nfonts = stuff->nFonts; - while (--nfonts >= 0) - { - if ((total == 0) || (total < (n = (*ptr + 1)))) - return(BadLength); - total -= n; - ptr += n; - } - if (total >= 4) - return(BadLength); - result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1], - &error); - if (!result) - { - result = client->noClientException; - client->errorValue = error; - } - return (result); -} - -int -ProcGetFontPath(register ClientPtr client) -{ - xGetFontPathReply reply; - int stringLens, numpaths; - unsigned char *bufferStart; - /* REQUEST (xReq); */ - - REQUEST_SIZE_MATCH(xReq); - bufferStart = GetFontPath(&numpaths, &stringLens); - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = (stringLens + numpaths + 3) >> 2; - reply.nPaths = numpaths; - - WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); - if (stringLens || numpaths) - (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart); - return(client->noClientException); -} - -int -ProcChangeCloseDownMode(register ClientPtr client) -{ - REQUEST(xSetCloseDownModeReq); - - REQUEST_SIZE_MATCH(xSetCloseDownModeReq); - if ((stuff->mode == AllTemporary) || - (stuff->mode == RetainPermanent) || - (stuff->mode == RetainTemporary)) - { - client->closeDownMode = stuff->mode; - return (client->noClientException); - } - else - { - client->errorValue = stuff->mode; - return (BadValue); - } -} - -int ProcForceScreenSaver(register ClientPtr client) -{ - REQUEST(xForceScreenSaverReq); - - REQUEST_SIZE_MATCH(xForceScreenSaverReq); - - if ((stuff->mode != ScreenSaverReset) && - (stuff->mode != ScreenSaverActive)) - { - client->errorValue = stuff->mode; - return BadValue; - } - SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode); - return client->noClientException; -} - -int ProcNoOperation(register ClientPtr client) -{ - REQUEST_AT_LEAST_SIZE(xReq); - - /* noop -- don't do anything */ - return(client->noClientException); -} - -void -InitProcVectors(void) -{ - int i; - for (i = 0; i<256; i++) - { - if(!ProcVector[i]) - { - ProcVector[i] = SwappedProcVector[i] = ProcBadRequest; - ReplySwapVector[i] = ReplyNotSwappd; - } -#ifdef K5AUTH - if (!k5_Vector[i]) - { - k5_Vector[i] = k5_bad; - } -#endif - } - for(i = LASTEvent; i < 128; i++) - { - EventSwapVector[i] = NotImplemented; - } - -} - -/********************** - * CloseDownClient - * - * Client can either mark his resources destroy or retain. If retained and - * then killed again, the client is really destroyed. - *********************/ - -char dispatchExceptionAtReset = DE_RESET; - -void -CloseDownClient(register ClientPtr client) -{ - Bool really_close_down = client->clientGone || - client->closeDownMode == DestroyAll; - - if (!client->clientGone) - { - /* ungrab server if grabbing client dies */ - if (grabState != GrabNone && grabClient == client) - { - UngrabServer(client); - } - BITCLEAR(grabWaiters, client->index); - DeleteClientFromAnySelections(client); - ReleaseActiveGrabs(client); - DeleteClientFontStuff(client); - if (!really_close_down) - { - /* This frees resources that should never be retained - * no matter what the close down mode is. Actually we - * could do this unconditionally, but it's probably - * better not to traverse all the client's resources - * twice (once here, once a few lines down in - * FreeClientResources) in the common case of - * really_close_down == TRUE. - */ - FreeClientNeverRetainResources(client); - client->clientState = ClientStateRetained; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - } - client->clientGone = TRUE; /* so events aren't sent to client */ - if (ClientIsAsleep(client)) - ClientSignal (client); - ProcessWorkQueueZombies(); -#ifdef LBX - ProcessQTagZombies(); -#endif - CloseDownConnection(client); - - /* If the client made it to the Running stage, nClients has - * been incremented on its behalf, so we need to decrement it - * now. If it hasn't gotten to Running, nClients has *not* - * been incremented, so *don't* decrement it. - */ - if (client->clientState != ClientStateInitial && - client->clientState != ClientStateAuthenticating ) - { - --nClients; - } - } - - if (really_close_down) - { - if (client->clientState == ClientStateRunning && nClients == 0) - dispatchException |= dispatchExceptionAtReset; - - client->clientState = ClientStateGone; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - FreeClientResources(client); - if (client->index < nextFreeClientID) - nextFreeClientID = client->index; - clients[client->index] = NullClient; -#ifdef SMART_SCHEDULE - SmartLastClient = NullClient; -#endif - xfree(client); - - while (!clients[currentMaxClients-1]) - currentMaxClients--; - } -} - -static void -KillAllClients() -{ - int i; - for (i=1; icloseDownMode = DestroyAll; - CloseDownClient(clients[i]); - } -} - -/********************* - * CloseDownRetainedResources - * - * Find all clients that are gone and have terminated in RetainTemporary - * and destroy their resources. - *********************/ - -void -CloseDownRetainedResources() -{ - register int i; - register ClientPtr client; - - for (i=1; icloseDownMode == RetainTemporary) - && (client->clientGone)) - CloseDownClient(client); - } -} - -void InitClient(ClientPtr client, int i, pointer ospriv) -{ - client->index = i; - client->sequence = 0; - client->clientAsMask = ((Mask)i) << CLIENTOFFSET; - client->clientGone = FALSE; - if (i) - { - client->closeDownMode = DestroyAll; - client->lastDrawable = (DrawablePtr)WindowTable[0]; - client->lastDrawableID = WindowTable[0]->drawable.id; - } - else - { - client->closeDownMode = RetainPermanent; - client->lastDrawable = (DrawablePtr)NULL; - client->lastDrawableID = INVALID; - } - client->lastGC = (GCPtr) NULL; - client->lastGCID = INVALID; - client->numSaved = 0; - client->saveSet = (SaveSetElt *)NULL; - client->noClientException = Success; -#ifdef DEBUG - client->requestLogIndex = 0; -#endif - client->requestVector = InitialVector; - client->osPrivate = ospriv; - client->swapped = FALSE; - client->big_requests = FALSE; - client->priority = 0; - client->clientState = ClientStateInitial; -#ifdef XKB - if (!noXkbExtension) { - client->xkbClientFlags = 0; - client->mapNotifyMask = 0; - QueryMinMaxKeyCodes(&client->minKC,&client->maxKC); - } -#endif - client->replyBytesRemaining = 0; -#ifdef LBX - client->readRequest = StandardReadRequestFromClient; -#endif -#ifdef XCSECURITY - client->trustLevel = XSecurityClientTrusted; - client->CheckAccess = NULL; - client->authId = 0; -#endif -#ifdef XAPPGROUP - client->appgroup = NULL; -#endif - client->fontResFunc = NULL; -#ifdef SMART_SCHEDULE - client->smart_priority = 0; - client->smart_start_tick = SmartScheduleTime; - client->smart_stop_tick = SmartScheduleTime; - client->smart_check_tick = SmartScheduleTime; -#endif -} - -extern int clientPrivateLen; -extern unsigned *clientPrivateSizes; -extern unsigned totalClientSize; - -int -InitClientPrivates(ClientPtr client) -{ - register char *ptr; - DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - if (totalClientSize == sizeof(ClientRec)) - ppriv = (DevUnion *)NULL; - else if (client->index) - ppriv = (DevUnion *)(client + 1); - else - { - ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec)); - if (!ppriv) - return 0; - } - client->devPrivates = ppriv; - sizes = clientPrivateSizes; - ptr = (char *)(ppriv + clientPrivateLen); - for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - return 1; -} - -/************************ - * int NextAvailableClient(ospriv) - * - * OS dependent portion can't assign client id's because of CloseDownModes. - * Returns NULL if there are no free clients. - *************************/ - -ClientPtr NextAvailableClient(pointer ospriv) -{ - register int i; - register ClientPtr client; - xReq data; - - i = nextFreeClientID; - if (i == MAXCLIENTS) - return (ClientPtr)NULL; - clients[i] = client = (ClientPtr)xalloc(totalClientSize); - if (!client) - return (ClientPtr)NULL; - InitClient(client, i, ospriv); - InitClientPrivates(client); - if (!InitClientResources(client)) - { - xfree(client); - return (ClientPtr)NULL; - } - data.reqType = 1; - data.length = (sz_xReq + sz_xConnClientPrefix) >> 2; - if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) - { - FreeClientResources(client); - xfree(client); - return (ClientPtr)NULL; - } - if (i == currentMaxClients) - currentMaxClients++; - while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID]) - nextFreeClientID++; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return(client); -} - -int -ProcInitialConnection(register ClientPtr client) -{ - REQUEST(xReq); - register xConnClientPrefix *prefix; - int whichbyte = 1; - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B')) - return (client->noClientException = -1); - if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) - { - client->swapped = TRUE; - SwapConnClientPrefix(prefix); - } - stuff->reqType = 2; - stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) + - ((prefix->nbytesAuthString + (unsigned)3) >> 2); - if (client->swapped) - { - swaps(&stuff->length, whichbyte); - } - ResetCurrentRequest(client); - return (client->noClientException); -} - -#ifdef LBX -void -IncrementClientCount() -{ - nClients++; -} -#endif - -int -SendConnSetup(register ClientPtr client, char *reason) -{ - register xWindowRoot *root; - register int i; - int numScreens; - char* lConnectionInfo; - xConnSetupPrefix* lconnSetupPrefix; - - if (reason) - { - xConnSetupPrefix csp; - - csp.success = xFalse; - csp.lengthReason = strlen(reason); - csp.length = (csp.lengthReason + (unsigned)3) >> 2; - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (client->swapped) - WriteSConnSetupPrefix(client, &csp); - else - (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); - (void)WriteToClient(client, (int)csp.lengthReason, reason); - return (client->noClientException = -1); - } - - numScreens = screenInfo.numScreens; - lConnectionInfo = ConnectionInfo; - lconnSetupPrefix = &connSetupPrefix; - - /* We're about to start speaking X protocol back to the client by - * sending the connection setup info. This means the authorization - * step is complete, and we can count the client as an - * authorized one. - */ - nClients++; - - client->requestVector = client->swapped ? SwappedProcVector : ProcVector; - client->sequence = 0; -#ifdef XAPPGROUP - XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens); -#endif - ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask; - ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK; -#ifdef MATCH_CLIENT_ENDIAN - ((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client); - ((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client); -#endif - /* fill in the "currentInputMask" */ - root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart); -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#endif - - for (i=0; icurrentInputMask = WindowTable[i]->eventMask | - wOtherEventMasks (WindowTable[i]); - pDepth = (xDepth *)(root + 1); - for (j = 0; j < root->nDepths; j++) - { - pDepth = (xDepth *)(((char *)(pDepth + 1)) + - pDepth->nVisuals * sizeof(xVisualType)); - } - root = (xWindowRoot *)pDepth; - } - - if (client->swapped) - { - WriteSConnSetupPrefix(client, lconnSetupPrefix); - WriteSConnectionInfo(client, - (unsigned long)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - else - { - (void)WriteToClient(client, sizeof(xConnSetupPrefix), - (char *) lconnSetupPrefix); - (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2), - lConnectionInfo); - } - client->clientState = ClientStateRunning; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = lconnSetupPrefix; - clientinfo.setup = (xConnSetup *)lConnectionInfo; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - return (client->noClientException); -} - -int -ProcEstablishConnection(register ClientPtr client) -{ - char *reason, *auth_proto, *auth_string; - register xConnClientPrefix *prefix; - REQUEST(xReq); - - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - auth_proto = (char *)prefix + sz_xConnClientPrefix; - auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3); - if ((prefix->majorVersion != X_PROTOCOL) || - (prefix->minorVersion != X_PROTOCOL_REVISION)) - reason = "Protocol version mismatch"; - else - reason = ClientAuthorized(client, - (unsigned short)prefix->nbytesAuthProto, - auth_proto, - (unsigned short)prefix->nbytesAuthString, - auth_string); - /* - * If Kerberos is being used for this client, the clientState - * will be set to ClientStateAuthenticating at this point. - * More messages need to be exchanged among the X server, Kerberos - * server, and client to figure out if everyone is authorized. - * So we don't want to send the connection setup info yet, since - * the auth step isn't really done. - */ - if (client->clientState == ClientStateCheckingSecurity) - client->clientState = ClientStateCheckedSecurity; - else if (client->clientState != ClientStateAuthenticating) - return(SendConnSetup(client, reason)); - return(client->noClientException); -} - -void -SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, - XID resId, int errorCode) -{ - xError rep; - - rep.type = X_Error; - rep.sequenceNumber = client->sequence; - rep.errorCode = errorCode; - rep.majorCode = majorCode; - rep.minorCode = minorCode; - rep.resourceID = resId; - - WriteEventsToClient (client, 1, (xEvent *)&rep); -} - -void -DeleteWindowFromAnySelections(WindowPtr pWin) -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].pWin == pWin) - { - if (SelectionCallback) - { - SelectionInfoRec info; - - info.selection = &CurrentSelections[i]; - info.kind = SelectionWindowDestroy; - CallCallbacks(&SelectionCallback, &info); - } - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -static void -DeleteClientFromAnySelections(ClientPtr client) -{ - register int i; - - for (i = 0; i< NumCurrentSelections; i++) - if (CurrentSelections[i].client == client) - { - if (SelectionCallback) - { - SelectionInfoRec info; - - info.selection = &CurrentSelections[i]; - info.kind = SelectionWindowDestroy; - CallCallbacks(&SelectionCallback, &info); - } - CurrentSelections[i].pWin = (WindowPtr)NULL; - CurrentSelections[i].window = None; - CurrentSelections[i].client = NullClient; - } -} - -void -MarkClientException(ClientPtr client) -{ - client->noClientException = -1; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.NX.original deleted file mode 100644 index 04fc047fc..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.NX.original +++ /dev/null @@ -1,2804 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XdotOrg: xc/programs/Xserver/dix/dixfonts.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */ -/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.28 2003/11/08 02:02:03 dawes Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* The panoramix components contained the following notice */ -/* -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ -/* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */ - -#define NEED_REPLIES -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "cursorstr.h" -#include "misc.h" -#include "opaque.h" -#include "dixfontstr.h" -#include "closestr.h" - -/* -#define NXAGENT_DEBUG -*/ - -#ifdef DEBUG -#include -#endif - -#include "Agent.h" -#include "Font.h" - -#ifndef NX_TRANS_SOCKET - -#define NX_TRANS_SOCKET - -#endif - -#ifdef NX_TRANS_SOCKET - -char _NXFontPath[1024]; - -/* - * Override the default font path and make - * it configurable at run time, based on - * the NX_FONT environment. - */ - -static const char *_NXGetFontPath(const char *path) -{ - const char *fontEnv; - - /* - * Check the environment only once. - */ - - if (*_NXFontPath != '\0') - { - return _NXFontPath; - } - - fontEnv = getenv("NX_FONT"); - - if (fontEnv != NULL && *fontEnv != '\0') - { - if (strlen(fontEnv) + 1 > 1024) - { -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: WARNING! Maximum length of font path exceeded.\n"); -#endif - goto _NXGetFontPathError; - } - - strcpy(_NXFontPath, fontEnv); - -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: Using NX font path [%s].\n", _NXFontPath); -#endif - - return _NXFontPath; - } - -_NXGetFontPathError: - - strcpy(_NXFontPath, path); - -#ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetFontPath: Using default font path [%s].\n", _NXFontPath); -#endif - - return _NXFontPath; -} - -#endif - -#ifdef PANORAMIX -#include "../../Xext/panoramiX.h" -#include "../../Xext/panoramiXsrv.h" -#endif - -#ifdef LBX -#include "lbxserve.h" -#endif - -#ifdef XF86BIGFONT -#define _XF86BIGFONT_SERVER_ -#include -#endif - -#define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics - -extern pointer fosNaturalParams; -extern FontPtr defaultFont; - -static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; -FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; - -static unsigned char *font_path_string; - -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; -static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; -static FontPatternCachePtr patternCache; - -int -FontToXError(err) - int err; -{ - switch (err) { - case Successful: - return Success; - case AllocError: - return BadAlloc; - case BadFontName: - return BadName; - case BadFontPath: - case BadFontFormat: /* is there something better? */ - case BadCharRange: - return BadValue; - default: - return err; - } -} - - -/* - * adding RT_FONT prevents conflict with default cursor font - */ -Bool -SetDefaultFont(char *defaultfontname) -{ - int err; - FontPtr pf; - XID fid; - - fid = FakeClientID(0); - err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); - if (err != Success) - return FALSE; - pf = (FontPtr) LookupIDByType(fid, RT_FONT); - if (pf == (FontPtr) NULL) - return FALSE; - defaultFont = pf; - return TRUE; -} - -/* - * note that the font wakeup queue is not refcounted. this is because - * an fpe needs to be added when it's inited, and removed when it's finally - * freed, in order to handle any data that isn't requested, like FS events. - * - * since the only thing that should call these routines is the renderer's - * init_fpe() and free_fpe(), there shouldn't be any problem in using - * freed data. - */ -void -QueueFontWakeup(FontPathElementPtr fpe) -{ - int i; - FontPathElementPtr *new; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - -#ifdef DEBUG - fprintf(stderr, "re-queueing fpe wakeup\n"); -#endif - - return; - } - } - if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - xrealloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; - } - slept_fpes[num_slept_fpes] = fpe; - num_slept_fpes++; -} - -void -RemoveFontWakeup(FontPathElementPtr fpe) -{ - int i, - j; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } - } -} - -void -FontWakeup(pointer data, int count, pointer LastSelectMask) -{ - int i; - FontPathElementPtr fpe; - - if (count < 0) - return; - /* wake up any fpe's that may be waiting for information */ - for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); - } -} - -/* XXX -- these two funcs may want to be broken into macros */ -static void -UseFPE(FontPathElementPtr fpe) -{ - fpe->refcount++; -} - -static void -FreeFPE (FontPathElementPtr fpe) -{ - fpe->refcount--; - if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); - } -} - -static Bool -doOpenFont(ClientPtr client, OFclosurePtr c) -{ - FontPtr pfont = NullFont; - FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; - char nxagentOrigFontName[256]; - int nxagentOrigFontNameLen; - - /* - * Decide at runtime what FontFormat to use. - */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - -#if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | -#endif - -#if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | -#endif - -#if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | -#endif - -#if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | -#endif - - BitmapFormatScanlineUnit8; - - - nxagentOrigFontNameLen = (c -> origFontNameLen < 256) ? c -> origFontNameLen : 255; - - memcpy(nxagentOrigFontName, c -> origFontName, nxagentOrigFontNameLen); - - nxagentOrigFontName[nxagentOrigFontNameLen] = 0; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) - break; - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doOpenFont: client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - break; - } - - if (err != Successful) - goto bail; - if (!pfont) { - err = BadFontName; - goto bail; - } - /* check values for firstCol, lastCol, firstRow, and lastRow */ - if (pfont->info.firstCol > pfont->info.lastCol || - pfont->info.firstRow > pfont->info.lastRow || - pfont->info.lastCol - pfont->info.firstCol > 255) { - err = AllocError; - goto bail; - } - if (!pfont->fpe) - pfont->fpe = fpe; - pfont->refcnt++; - if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - - /* NXAGENT uses useless screen pointer to pass the original font name - * to realizeFont, could be a source of problems in the future. - */ - - if (!(*pScr->RealizeFont) ((ScreenPtr)nxagentOrigFontName, pfont)) - { - CloseFont (pfont, (Font) 0); - err=BadFontName; - goto bail; - } - } - } - } - if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; - } - if( nxagentFontPriv(pfont) -> mirrorID == 0 ) - { - extern RESTYPE RT_NX_FONT; - - nxagentFontPriv(pfont) -> mirrorID = FakeClientID(0); - if (!AddResource(nxagentFontPriv(pfont) -> mirrorID, RT_NX_FONT, (pointer) pfont)) { - FreeResource(c->fontid, RT_NONE); - err = AllocError; - goto bail; - } - } - if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, nxagentOrigFontName, nxagentOrigFontNameLen, - pfont); -bail: - if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); - } - if (c->slept) - { - ClientWakeup(c->client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doOpenFont: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); - } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); - return TRUE; -} - -int -OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontname) -{ - OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - c = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!c) - return BadAlloc; - c->fontname = (char *) xalloc(lenfname); - c->origFontName = pfontname; - c->origFontNameLen = lenfname; - if (!c->fontname) { - xfree(c); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); - return BadAlloc; - } - memmove(c->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->fontid = fid; - c->current_fpe = 0; - c->num_fpes = num_fpes; - c->fnamelen = lenfname; - c->slept = FALSE; - c->flags = flags; - c->non_cachable_font = cached; - - (void) doOpenFont(client, c); - return Success; -} - -/** - * Decrement font's ref count, and free storage if ref count equals zero - * - * \param value must conform to DeleteType - */ -int -CloseFont(pointer value, XID fid) -{ - int nscr; - ScreenPtr pscr; - FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; - - if (pfont == NullFont) - return (Success); - if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; -#ifdef LBX - LbxFreeFontTag(pfont); -#endif -#ifdef XF86BIGFONT - { - extern void XF86BigfontFreeFontShm(FontPtr); - XF86BigfontFreeFontShm(pfont); - } -#endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); - } - return (Success); -} - - -/***====================================================================***/ - -/** - * Sets up pReply as the correct QueryFontReply for pFont with the first - * nProtoCCIStructs char infos. - * - * \param pReply caller must allocate this storage - */ -void -QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs) -{ - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; - - /* pr->length set in dispatch */ - pReply->minCharOrByte2 = pFont->info.firstCol; - pReply->defaultChar = pFont->info.defaultCh; - pReply->maxCharOrByte2 = pFont->info.lastCol; - pReply->drawDirection = pFont->info.drawDirection; - pReply->allCharsExist = pFont->info.allExist; - pReply->minByte1 = pFont->info.firstRow; - pReply->maxByte1 = pFont->info.lastRow; - pReply->fontAscent = pFont->info.fontAscent; - pReply->fontDescent = pFont->info.fontDescent; - - pReply->minBounds = pFont->info.ink_minbounds; - pReply->maxBounds = pFont->info.ink_maxbounds; - - pReply->nFontProps = pFont->info.nprops; - pReply->nCharInfos = nProtoCCIStructs; - - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - } - - ninfos = 0; - ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); - prCI = (xCharInfo *) (prFP); - for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } - } - return; -} - -static Bool -doListFontsAndAliases(ClientPtr client, LFclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont (1): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont (2): client [%lx] sleeping.\n", client); -#endif -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont (3): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ - if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; - } - -finish: - - names = c->names; - nnames = names->nnames; - client = c->client; - stringLens = 0; - for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - - reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; - reply.nFonts = nnames; - reply.sequenceNumber = client->sequence; - - bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2); - - if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; - } - /* - * since WriteToClient long word aligns things, copy to temp buffer and - * write all at once - */ - for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - { - /* dirty hack: don't list to client fonts not existing on the remote side */ - char tmp[256]; - - memcpy(tmp, names->names[i], names->length[i]); - tmp[ names->length[i] ] = 0; - - if (nxagentFontLookUp(tmp) == 0) - { -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "doListFontsAndAliases:\n"); - fprintf(stderr, " removing font: %s \n", tmp); -#endif - reply.nFonts--; - stringLens -= names->length[i]; - continue; - } - } - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } - } - nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); - (void) WriteToClient(client, stringLens + nnames, bufferStart); - DEALLOCATE_LOCAL(bufferStart); - -bail: - if (c->slept) - { - ClientWakeup(client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFont: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); - return TRUE; -} - -int -ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, - unsigned max_names) -{ - int i; - LFclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - return BadAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - return BadAlloc; - } - c->names = MakeFontNamesRecord(max_names < nxagentMaxFontNames ? max_names : nxagentMaxFontNames); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - return BadAlloc; - } - memmove( c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsAndAliases(client, c); - return Success; -} - -int -doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; - xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; - xListFontsWithInfoReply finalReply; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; - if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFontWinfo (1): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFontWinfo (2): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - - if (nxagentFontLookUp(name) == 0) - { -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "doListFontsAndAliases (with info):\n"); - fprintf(stderr, " removing font: %s \n", name); -#endif - continue; - } - - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - c->reply = reply; - c->length = length; - } - reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: - length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); - finalReply.type = X_Reply; - finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; - WriteSwappedDataToClient(client, length, &finalReply); -bail: - if (c->slept) - { - ClientWakeup(client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doListFontWinfo: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - xfree(c); - return TRUE; -} - -int -StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, - int max_names) -{ - int i; - LFWIclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFWIclosurePtr) xalloc(sizeof *c))) - goto badAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - xfree(c); - goto badAlloc; - } - memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->reply = 0; - c->length = 0; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->savedNumFonts = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsWithInfo(client, c); - return Success; -badAlloc: - return BadAlloc; -} - -#define TextEltHeader 2 -#define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; -#define clearGCmask (GCClipMask) - -int -doPolyText(ClientPtr client, register PTclosurePtr c) -{ - register FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; - int err = Success, lgerr; /* err is in X error, not font error, space */ - enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; - FontPathElementPtr fpe; - GC *origGC = NULL; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (c->slept) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } - - client_state = c->slept ? SLEEPING : NEVER_SLEPT; - - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - oldfid = fid; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - client->errorValue = fid; - err = BadFont; - /* restore pFont and fid for step 4 (described below) */ - pFont = oldpFont; - fid = oldfid; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGC( c->pGC, GCFont, &fid); - ValidateGC(c->pDraw, c->pGC); - if (c->reqType == X_PolyText8) - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; - else - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16; - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!c->slept) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - len = c->endReq - c->pElt; - c->data = (unsigned char *)xalloc(len); - if (!c->data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(c->data, c->pElt, len); - c->pElt = c->data; - c->endReq = c->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - - pGC->tileIsPixel = TRUE; - pGC->tile.pixel = 0; - pGC->stipple = NullPixmap; - - if ((err = CopyGC(c->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doPolyText (1): client [%lx] sleeping.\n", client); -#endif - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, c->pElt + TextEltHeader); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGC(origGC, GCFont, &fid); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; - if (err != Success && c->client != serverClient) { -#ifdef PANORAMIX - if (noPanoramiXExtension || !c->pGC->pScreen->myNum) -#endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doPolytext: client [%lx] wakeup.\n", client); -#endif - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, - unsigned char *endReq, int xorg, int yorg, int reqType, XID did) -{ - PTclosureRec local_closure; - - local_closure.pElt = pElt; - local_closure.endReq = endReq; - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_PolyText8) - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8; - local_closure.itemSize = 1; - } - else - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16; - local_closure.itemSize = 2; - } - local_closure.pGC = pGC; - local_closure.did = did; - local_closure.err = Success; - local_closure.slept = FALSE; - - (void) doPolyText(client, &local_closure); - return Success; -} - - -#undef TextEltHeader -#undef FontShiftSize - -int -doImageText(ClientPtr client, register ITclosurePtr c) -{ - int err = Success, lgerr; /* err is in X error, not font error, space */ - FontPathElementPtr fpe; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); - if (lgerr == Suspended) - { - if (!c->slept) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = (unsigned char *)xalloc(c->nChars * c->itemSize); - if (!data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * c->itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - - pGC->tileIsPixel = TRUE; - pGC->tile.pixel = 0; - pGC->stipple = NullPixmap; - - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doImageText (1): client [%lx] sleeping.\n", client); -#endif - - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, c->data); - } - -bail: - - if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: doImageText: client [%lx] wakeup.\n", client); -#endif - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, - unsigned char *data, int xorg, int yorg, int reqType, XID did) -{ - ITclosureRec local_closure; - - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.pGC = pGC; - local_closure.nChars = nChars; - local_closure.data = data; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_ImageText8) - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8; - local_closure.itemSize = 1; - } - else - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16; - local_closure.itemSize = 2; - } - local_closure.did = did; - local_closure.slept = FALSE; - - (void) doImageText(client, &local_closure); - return Success; -} - - -/* does the necessary magic to figure out the fpe type */ -static int -DetermineFPEType(char *pathname) -{ - int i; - - for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; - } - return -1; -} - - -static void -FreeFontPath(FontPathElementPtr *list, int n, Bool force) -{ - int i; - - for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n", - list[i]->name_length, list[i]->name, - list[i]->refcount, found); - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); - } - xfree((char *) list); -} - -static FontPathElementPtr -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) -{ - FontPathElementPtr fpe; - int i; - - for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; - } - return (FontPathElementPtr) 0; -} - - -static int -SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) -{ - int i, err = 0; - int valid_paths = 0; - unsigned int len; - unsigned char *cp = paths; - FontPathElementPtr fpe = NULL, *fplist; - - fplist = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * npaths); - if (!fplist) { - *bad = 0; - return BadAlloc; - } - for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF ("Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = (char *) xalloc(len + 1); - if (!fpe->name) - { - xfree(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - #ifndef NXAGENT_SERVER - if (persist) - { - ErrorF("Could not init font path element %s, removing from list!\n", - fpe->name); - } - #endif - xfree (fpe->name); - xfree (fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; - } - - FreeFontPath(font_path_elements, num_fpes, FALSE); - font_path_elements = fplist; - if (patternCache) - EmptyFontPatternCache(patternCache); - num_fpes = valid_paths; - - return Success; -bail: - *bad = i; - while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); - xfree(fplist); - return FontToXError(err); -} - -/* XXX -- do we need to pass error down to each renderer? */ -int -SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error) -{ - int err = Success; - - if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - err = SetFontPathElements(npaths, paths, error, FALSE); - } - return err; -} - -int -SetDefaultFontPath(char *path) -{ - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; - - /* get enough for string, plus values -- use up commas */ -#ifdef NX_TRANS_SOCKET - len = strlen(_NXGetFontPath(path)) + 1; -#else - len = strlen(path) + 1; -#endif - nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len); - if (!newpath) - return BadAlloc; -#ifdef NX_TRANS_SOCKET - pp = (unsigned char *) _NXGetFontPath(path); -#else - pp = (unsigned char *) path; -#endif - cp++; - while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } - } - *nump = (unsigned char) size; - - err = SetFontPathElements(num, newpath, &bad, TRUE); - - DEALLOCATE_LOCAL(newpath); - - return err; -} - -unsigned char * -GetFontPath(int *count, int *length) -{ - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; - - len = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; - } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); - if (!font_path_string) - return NULL; - - c = font_path_string; - *length = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; - } - *count = num_fpes; - return font_path_string; -} - -int -LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size, unsigned char *data) -{ - if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); - else - return Successful; -} - -void -DeleteClientFontStuff(ClientPtr client) -{ - int i; - FontPathElementPtr fpe; - - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } -} - -void -InitFonts () -{ - patternCache = MakeFontPatternCache(); - -#ifndef KDRIVESERVER - if (screenInfo.numScreens > screenInfo.numVideoScreens) { - PrinterFontRegisterFpeFunctions(); - FontFileCheckRegisterFpeFunctions(); - check_fs_register_fpe_functions(); - } else -#endif - { -#ifdef KDRIVESERVER - BuiltinRegisterFpeFunctions(); -#endif - FontFileRegisterFpeFunctions(); -#ifndef NOFONTSERVERACCESS - fs_register_fpe_functions(); -#endif - } -} - -int -GetDefaultPointSize () -{ - return 120; -} - - -FontResolutionPtr -GetClientResolutions (int *num) -{ - if (requestingClient && requestingClient->fontResFunc != NULL && - !requestingClient->clientGone) - { - return (*requestingClient->fontResFunc)(requestingClient, num); - } - else { - static struct _FontResolution res; - ScreenPtr pScreen; - - pScreen = screenInfo.screens[0]; - res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; - /* - * XXX - we'll want this as long as bitmap instances are prevalent - so that we can match them from scalable fonts - */ - if (res.x_resolution < 88) - res.x_resolution = 75; - else - res.x_resolution = 100; - res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; - if (res.y_resolution < 88) - res.y_resolution = 75; - else - res.y_resolution = 100; - res.point_size = 120; - *num = 1; - return &res; - } -} - -/* - * returns the type index of the new fpe - * - * should be called (only once!) by each type of fpe when initialized - */ - -int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) -{ - FPEFunctions *new; - - /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); - if (!new) - return -1; - fpe_functions = new; - - fpe_functions[num_fpe_types].name_check = name_func; - fpe_functions[num_fpe_types].open_font = open_func; - fpe_functions[num_fpe_types].close_font = close_func; - fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; - fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; - fpe_functions[num_fpe_types].init_fpe = init_func; - fpe_functions[num_fpe_types].free_fpe = free_func; - fpe_functions[num_fpe_types].reset_fpe = reset_func; - fpe_functions[num_fpe_types].client_died = client_died; - fpe_functions[num_fpe_types].load_glyphs = load_glyphs; - fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; - fpe_functions[num_fpe_types].set_path_hook = set_path_func; - - return num_fpe_types++; -} - -void -FreeFonts() -{ - if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; - } - FreeFontPath(font_path_elements, num_fpes, TRUE); - font_path_elements = 0; - num_fpes = 0; - xfree(fpe_functions); - num_fpe_types = 0; - fpe_functions = (FPEFunctions *) 0; -} - -/* convenience functions for FS interface */ - -FontPtr -find_old_font(XID id) -{ - return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE, - SecurityUnknownAccess); -} - -Font -GetNewFontClientID() -{ - return FakeClientID(0); -} - -int -StoreFontClientFont(FontPtr pfont, Font id) -{ - return AddResource(id, RT_NONE, (pointer) pfont); -} - -void -DeleteFontClientID(Font id) -{ - FreeResource(id, RT_NONE); -} - -int -client_auth_generation(ClientPtr client) -{ - return 0; -} - -static int fs_handlers_installed = 0; -static unsigned int last_server_gen; - -int -init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler) -{ - /* if server has reset, make sure the b&w handlers are reinstalled */ - if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; - } - if (fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "adding FS b & w handlers\n"); -#endif - - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; - } - QueueFontWakeup(fpe); - return Successful; -} - -void -remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler, Bool all) -{ - if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "removing FS b & w handlers\n"); -#endif - - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } - } - RemoveFontWakeup(fpe); -} - -#ifdef DEBUG -#define GLWIDTHBYTESPADDED(bits,nbytes) \ - ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ - :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ - :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ - :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ - : 0) - -#define GLYPH_SIZE(ch, nbytes) \ - GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \ - (ch)->metrics.leftSideBearing, (nbytes)) -void -dump_char_ascii(CharInfoPtr cip) -{ - int r, - l; - int bpr; - int byte; - static unsigned maskTab[] = { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - bpr = GLYPH_SIZE(cip, 4); - for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) { - pointer row = (pointer) cip->bits + r * bpr; - - byte = 0; - for (l = 0; l <= (cip->metrics.rightSideBearing - - cip->metrics.leftSideBearing); l++) { - if (maskTab[l & 7] & row[l >> 3]) - putchar('X'); - else - putchar('.'); - } - putchar('\n'); - } -} - -#endif - - -typedef struct -{ - LFclosurePtr c; - OFclosurePtr oc; -} nxFs,*nxFsPtr; - -static Bool -#if NeedFunctionPrototypes -nxdoListFontsAndAliases(ClientPtr client, nxFsPtr fss) -#else -nxdoListFontsAndAliases(client, fss) - ClientPtr client; - nxFsPtr fss; -#endif -{ - LFclosurePtr c=fss->c; - OFclosurePtr oc=fss->oc; - FontPathElementPtr fpe; - int err = Successful; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int i; - int aliascount = 0; - char tmp[256]; - tmp[0]=0; - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)nxdoListFontsAndAliases, - (pointer) fss); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont (1): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)nxdoListFontsAndAliases, - (pointer) fss); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont (2): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)nxdoListFontsAndAliases, - (pointer) fss); - c->slept = TRUE; -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont (3): client [%lx] sleeping.\n", client); -#endif - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - { - memmove(resolved, tmpname, resolvedlen); - resolved[resolvedlen] = '\0'; - } - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - { - memcpy(tmp,c->savedName,c->savedNameLen>255?255:c->savedNameLen); - tmp[c->savedNameLen>255?256:c->savedNameLen]=0; - if (nxagentFontLookUp(tmp)) - break; - else tmp[0]=0; - } - } - else - { - memcpy(tmp,name,namelen>255?255:namelen); - tmp[namelen>255?256:namelen]=0; - if (nxagentFontLookUp(tmp)) - break; - else tmp[0]=0; - } - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - { - memmove(c->savedName, name, namelen); - c->savedName[namelen] = '\0'; - } - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ -bail: -finish: - if (strlen(tmp)) - { -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "nxListFont changed (0) font to %s\n",tmp); -#endif - memcpy(oc->fontname, tmp, strlen(tmp)); - oc->fnamelen = strlen(tmp); - - oc->origFontName = oc->fontname; - oc->origFontNameLen = oc->fnamelen; - - } - else - { - for (i = 0; i < c->names->nnames; i++) - { - if (c->names->length[i] > 255) - continue; - else - { - memcpy(tmp, c->names->names[i], c->names->length[i]); - tmp[ c->names->length[i] ] = 0; - if (nxagentFontLookUp(tmp) == 0) - continue; - memcpy(oc->fontname, tmp, strlen(tmp)); - oc->fnamelen = strlen(tmp); - - oc->origFontName = oc->fontname; - oc->origFontNameLen = oc->fnamelen; - -#ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "nxListFont changed (1) font to %s\n",tmp); -#endif - break; - } - } - } - - if (c->slept) - { - ClientWakeup(client); -#ifdef NXAGENT_DEBUG - fprintf(stderr, " NXdixfonts: nxdoListFont: client [%lx] wakeup.\n", client); -#endif - } - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(c->names); - xfree(c); - xfree(fss); - if (resolved) xfree(resolved); - - return doOpenFont(client, oc); -} - -int -nxOpenFont(client, fid, flags, lenfname, pfontname) - ClientPtr client; - XID fid; - Mask flags; - unsigned lenfname; - char *pfontname; -{ - nxFsPtr fss; - LFclosurePtr c; - OFclosurePtr oc; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - if (!(fss = (nxFsPtr) xalloc(sizeof(nxFs)))) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - { - xfree(fss); - return BadAlloc; - } - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - xfree(fss); - return BadAlloc; - } - c->names = MakeFontNamesRecord(100); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - xfree(fss); - return BadAlloc; - } - memmove( c->current.pattern, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = lenfname; - c->current.current_fpe = 0; - c->current.max_names = nxagentMaxFontNames; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - - oc = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!oc) - { - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - xfree(c); - xfree(fss); - return BadAlloc; - } - oc->fontname = (char *) xalloc(256);/* I don't want to deal with future reallocs errors */ - oc->origFontName = pfontname; - oc->origFontNameLen = lenfname; - if (!oc->fontname) { - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - xfree(c); - xfree(oc); - xfree(fss); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - oc->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!oc->fpe_list) { - xfree(oc->fontname); - xfree(oc); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - xfree(c); - xfree(fss); - return BadAlloc; - } - memmove(oc->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - oc->fpe_list[i] = font_path_elements[i]; - UseFPE(oc->fpe_list[i]); - } - oc->client = client; - oc->fontid = fid; - oc->current_fpe = 0; - oc->num_fpes = num_fpes; - oc->fnamelen = lenfname; - oc->slept = FALSE; - oc->flags = flags; - oc->non_cachable_font = cached; - fss->c=c; - fss->oc=oc; - nxdoListFontsAndAliases(client, fss); - return Success; -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.X.original deleted file mode 100644 index 2c5874e8d..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c.X.original +++ /dev/null @@ -1,2150 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/dix/dixfonts.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */ -/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.28 2003/11/08 02:02:03 dawes Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* The panoramix components contained the following notice */ -/* -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ -/* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */ - -#define NEED_REPLIES -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" -#include "cursorstr.h" -#include "misc.h" -#include "opaque.h" -#include "dixfontstr.h" -#include "closestr.h" - -#ifdef DEBUG -#include -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#endif - -#ifdef LBX -#include "lbxserve.h" -#endif - -#ifdef XF86BIGFONT -#define _XF86BIGFONT_SERVER_ -#include -#endif - -#define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics - -extern pointer fosNaturalParams; -extern FontPtr defaultFont; - -static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; -FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; - -static unsigned char *font_path_string; - -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; -static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; -static FontPatternCachePtr patternCache; - -int -FontToXError(err) - int err; -{ - switch (err) { - case Successful: - return Success; - case AllocError: - return BadAlloc; - case BadFontName: - return BadName; - case BadFontPath: - case BadFontFormat: /* is there something better? */ - case BadCharRange: - return BadValue; - default: - return err; - } -} - - -/* - * adding RT_FONT prevents conflict with default cursor font - */ -Bool -SetDefaultFont(char *defaultfontname) -{ - int err; - FontPtr pf; - XID fid; - - fid = FakeClientID(0); - err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); - if (err != Success) - return FALSE; - pf = (FontPtr) LookupIDByType(fid, RT_FONT); - if (pf == (FontPtr) NULL) - return FALSE; - defaultFont = pf; - return TRUE; -} - -/* - * note that the font wakeup queue is not refcounted. this is because - * an fpe needs to be added when it's inited, and removed when it's finally - * freed, in order to handle any data that isn't requested, like FS events. - * - * since the only thing that should call these routines is the renderer's - * init_fpe() and free_fpe(), there shouldn't be any problem in using - * freed data. - */ -void -QueueFontWakeup(FontPathElementPtr fpe) -{ - int i; - FontPathElementPtr *new; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - -#ifdef DEBUG - fprintf(stderr, "re-queueing fpe wakeup\n"); -#endif - - return; - } - } - if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - xrealloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; - } - slept_fpes[num_slept_fpes] = fpe; - num_slept_fpes++; -} - -void -RemoveFontWakeup(FontPathElementPtr fpe) -{ - int i, - j; - - for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } - } -} - -void -FontWakeup(pointer data, int count, pointer LastSelectMask) -{ - int i; - FontPathElementPtr fpe; - - if (count < 0) - return; - /* wake up any fpe's that may be waiting for information */ - for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); - } -} - -/* XXX -- these two funcs may want to be broken into macros */ -static void -UseFPE(FontPathElementPtr fpe) -{ - fpe->refcount++; -} - -static void -FreeFPE (FontPathElementPtr fpe) -{ - fpe->refcount--; - if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); - } -} - -static Bool -doOpenFont(ClientPtr client, OFclosurePtr c) -{ - FontPtr pfont = NullFont; - FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; - /* - * Decide at runtime what FontFormat to use. - */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - -#if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | -#endif - -#if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | -#endif - -#if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | -#endif - -#if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | -#endif - - BitmapFormatScanlineUnit8; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) - break; - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); - } - return TRUE; - } - break; - } - - if (err != Successful) - goto bail; - if (!pfont) { - err = BadFontName; - goto bail; - } - /* check values for firstCol, lastCol, firstRow, and lastRow */ - if (pfont->info.firstCol > pfont->info.lastCol || - pfont->info.firstRow > pfont->info.lastRow || - pfont->info.lastCol - pfont->info.firstCol > 255) { - err = AllocError; - goto bail; - } - if (!pfont->fpe) - pfont->fpe = fpe; - pfont->refcnt++; - if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - if (!(*pScr->RealizeFont) (pScr, pfont)) - { - CloseFont (pfont, (Font) 0); - err = AllocError; - goto bail; - } - } - } - } - if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; - } - if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen, - pfont); -bail: - if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); - } - if (c->slept) - ClientWakeup(c->client); - for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); - } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); - return TRUE; -} - -int -OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontname) -{ - OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; - -#ifdef FONTDEBUG - char *f; - f = (char *)xalloc(lenfname + 1); - memmove(f, pfontname, lenfname); - f[lenfname] = '\0'; - ErrorF("OpenFont: fontname is \"%s\"\n", f); - xfree(f); -#endif - if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { - - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } - } - c = (OFclosurePtr) xalloc(sizeof(OFclosureRec)); - if (!c) - return BadAlloc; - c->fontname = (char *) xalloc(lenfname); - c->origFontName = pfontname; - c->origFontNameLen = lenfname; - if (!c->fontname) { - xfree(c); - return BadAlloc; - } - /* - * copy the current FPE list, so that if it gets changed by another client - * while we're blocking, the request still appears atomic - */ - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); - return BadAlloc; - } - memmove(c->fontname, pfontname, lenfname); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->fontid = fid; - c->current_fpe = 0; - c->num_fpes = num_fpes; - c->fnamelen = lenfname; - c->slept = FALSE; - c->flags = flags; - c->non_cachable_font = cached; - - (void) doOpenFont(client, c); - return Success; -} - -/** - * Decrement font's ref count, and free storage if ref count equals zero - * - * \param value must conform to DeleteType - */ -int -CloseFont(pointer value, XID fid) -{ - int nscr; - ScreenPtr pscr; - FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; - - if (pfont == NullFont) - return (Success); - if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; -#ifdef LBX - LbxFreeFontTag(pfont); -#endif -#ifdef XF86BIGFONT - XF86BigfontFreeFontShm(pfont); -#endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); - } - return (Success); -} - - -/***====================================================================***/ - -/** - * Sets up pReply as the correct QueryFontReply for pFont with the first - * nProtoCCIStructs char infos. - * - * \param pReply caller must allocate this storage - */ -void -QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs) -{ - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; - - /* pr->length set in dispatch */ - pReply->minCharOrByte2 = pFont->info.firstCol; - pReply->defaultChar = pFont->info.defaultCh; - pReply->maxCharOrByte2 = pFont->info.lastCol; - pReply->drawDirection = pFont->info.drawDirection; - pReply->allCharsExist = pFont->info.allExist; - pReply->minByte1 = pFont->info.firstRow; - pReply->maxByte1 = pFont->info.lastRow; - pReply->fontAscent = pFont->info.fontAscent; - pReply->fontDescent = pFont->info.fontDescent; - - pReply->minBounds = pFont->info.ink_minbounds; - pReply->maxBounds = pFont->info.ink_maxbounds; - - pReply->nFontProps = pFont->info.nprops; - pReply->nCharInfos = nProtoCCIStructs; - - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - } - - ninfos = 0; - ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); - prCI = (xCharInfo *) (prFP); - for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } - } - return; -} - -static Bool -doListFontsAndAliases(ClientPtr client, LFclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - - if (!c->current.patlen) - goto finish; - - while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - } - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!c->slept) { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } - return TRUE; - } - if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = (char *) xalloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } - } - - /* - * send the reply - */ - if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; - } - -finish: - - names = c->names; - nnames = names->nnames; - client = c->client; - stringLens = 0; - for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - - reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; - reply.nFonts = nnames; - reply.sequenceNumber = client->sequence; - - bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2); - - if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; - } - /* - * since WriteToClient long word aligns things, copy to temp buffer and - * write all at once - */ - for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } - } - nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); - (void) WriteToClient(client, stringLens + nnames, bufferStart); - DEALLOCATE_LOCAL(bufferStart); - -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); - return TRUE; -} - -int -ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, - unsigned max_names) -{ - int i; - LFclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFclosurePtr) xalloc(sizeof *c))) - return BadAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) { - xfree(c); - return BadAlloc; - } - c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100); - if (!c->names) - { - xfree(c->fpe_list); - xfree(c); - return BadAlloc; - } - memmove( c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsAndAliases(client, c); - return Success; -} - -int -doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) -{ - FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; - xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; - xListFontsWithInfoReply finalReply; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; - } - client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; - if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; - } - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!c->slept) - { - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; - } - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - if (c->savedName) - xfree(c->savedName); - c->savedName = (char *)xalloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - c->reply = reply; - c->length = length; - } - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: - length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); - finalReply.type = X_Reply; - finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; - WriteSwappedDataToClient(client, length, &finalReply); -bail: - if (c->slept) - ClientWakeup(client); - for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - xfree(c); - return TRUE; -} - -int -StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, - int max_names) -{ - int i; - LFWIclosurePtr c; - - /* - * The right error to return here would be BadName, however the - * specification does not allow for a Name error on this request. - * Perhaps a better solution would be to return a nil list, i.e. - * a list containing zero fontnames. - */ - if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; - - if (!(c = (LFWIclosurePtr) xalloc(sizeof *c))) - goto badAlloc; - c->fpe_list = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - xfree(c); - goto badAlloc; - } - memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); - } - c->client = client; - c->num_fpes = num_fpes; - c->reply = 0; - c->length = 0; - c->current.patlen = length; - c->current.current_fpe = 0; - c->current.max_names = max_names; - c->current.list_started = FALSE; - c->current.private = 0; - c->savedNumFonts = 0; - c->haveSaved = FALSE; - c->slept = FALSE; - c->savedName = 0; - doListFontsWithInfo(client, c); - return Success; -badAlloc: - return BadAlloc; -} - -#define TextEltHeader 2 -#define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; -#define clearGCmask (GCClipMask) - -int -doPolyText(ClientPtr client, register PTclosurePtr c) -{ - register FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; - int err = Success, lgerr; /* err is in X error, not font error, space */ - enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; - FontPathElementPtr fpe; - GC *origGC = NULL; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (c->slept) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } - - client_state = c->slept ? SLEEPING : NEVER_SLEPT; - - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - oldfid = fid; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT, - SecurityReadAccess); - if (!pFont) - { - client->errorValue = fid; - err = BadFont; - /* restore pFont and fid for step 4 (described below) */ - pFont = oldpFont; - fid = oldfid; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGC( c->pGC, GCFont, &fid); - ValidateGC(c->pDraw, c->pGC); - if (c->reqType == X_PolyText8) - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; - else - c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16; - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!c->slept) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - len = c->endReq - c->pElt; - c->data = (unsigned char *)xalloc(len); - if (!c->data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(c->data, c->pElt, len); - c->pElt = c->data; - c->endReq = c->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, c->pElt + TextEltHeader); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGC(origGC, GCFont, &fid); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; - if (err != Success && c->client != serverClient) { -#ifdef PANORAMIX - if (noPanoramiXExtension || !c->pGC->pScreen->myNum) -#endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, - unsigned char *endReq, int xorg, int yorg, int reqType, XID did) -{ - PTclosureRec local_closure; - - local_closure.pElt = pElt; - local_closure.endReq = endReq; - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_PolyText8) - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8; - local_closure.itemSize = 1; - } - else - { - local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16; - local_closure.itemSize = 2; - } - local_closure.pGC = pGC; - local_closure.did = did; - local_closure.err = Success; - local_closure.slept = FALSE; - - (void) doPolyText(client, &local_closure); - return Success; -} - - -#undef TextEltHeader -#undef FontShiftSize - -int -doImageText(ClientPtr client, register ITclosurePtr c) -{ - int err = Success, lgerr; /* err is in X error, not font error, space */ - FontPathElementPtr fpe; - - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && - c->pDraw && - c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did, - RC_DRAWABLE, SecurityWriteAccess)) - { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } - - lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); - if (lgerr == Suspended) - { - if (!c->slept) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = (unsigned char *)xalloc(c->nChars * c->itemSize); - if (!data) - { - xfree(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * c->itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - xfree(c->data); - xfree(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); - } - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, c->data); - } - -bail: - - if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); - } - if (c->slept) - { - ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); - - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; - - FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); - } - return TRUE; -} - -int -ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, - unsigned char *data, int xorg, int yorg, int reqType, XID did) -{ - ITclosureRec local_closure; - - local_closure.client = client; - local_closure.pDraw = pDraw; - local_closure.pGC = pGC; - local_closure.nChars = nChars; - local_closure.data = data; - local_closure.xorg = xorg; - local_closure.yorg = yorg; - if ((local_closure.reqType = reqType) == X_ImageText8) - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8; - local_closure.itemSize = 1; - } - else - { - local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16; - local_closure.itemSize = 2; - } - local_closure.did = did; - local_closure.slept = FALSE; - - (void) doImageText(client, &local_closure); - return Success; -} - - -/* does the necessary magic to figure out the fpe type */ -static int -DetermineFPEType(char *pathname) -{ - int i; - - for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; - } - return -1; -} - - -static void -FreeFontPath(FontPathElementPtr *list, int n, Bool force) -{ - int i; - - for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n", - list[i]->name_length, list[i]->name, - list[i]->refcount, found); - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); - } - xfree((char *) list); -} - -static FontPathElementPtr -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) -{ - FontPathElementPtr fpe; - int i; - - for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; - } - return (FontPathElementPtr) 0; -} - - -static int -SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) -{ - int i, err = 0; - int valid_paths = 0; - unsigned int len; - unsigned char *cp = paths; - FontPathElementPtr fpe = NULL, *fplist; - - fplist = (FontPathElementPtr *) - xalloc(sizeof(FontPathElementPtr) * npaths); - if (!fplist) { - *bad = 0; - return BadAlloc; - } - for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF ("Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = (char *) xalloc(len + 1); - if (!fpe->name) - { - xfree(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - if (persist) - { - ErrorF("Could not init font path element %s, removing from list!\n", - fpe->name); - } - xfree (fpe->name); - xfree (fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; - } - - FreeFontPath(font_path_elements, num_fpes, FALSE); - font_path_elements = fplist; - if (patternCache) - EmptyFontPatternCache(patternCache); - num_fpes = valid_paths; - - return Success; -bail: - *bad = i; - while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); - xfree(fplist); - return FontToXError(err); -} - -/* XXX -- do we need to pass error down to each renderer? */ -int -SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error) -{ - int err = Success; - - if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - err = SetFontPathElements(npaths, paths, error, FALSE); - } - return err; -} - -int -SetDefaultFontPath(char *path) -{ - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; - - /* get enough for string, plus values -- use up commas */ - len = strlen(path) + 1; - nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len); - if (!newpath) - return BadAlloc; - pp = (unsigned char *) path; - cp++; - while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } - } - *nump = (unsigned char) size; - - err = SetFontPathElements(num, newpath, &bad, TRUE); - - DEALLOCATE_LOCAL(newpath); - - return err; -} - -unsigned char * -GetFontPath(int *count, int *length) -{ - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; - - len = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; - } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); - if (!font_path_string) - return NULL; - - c = font_path_string; - *length = 0; - for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; - } - *count = num_fpes; - return font_path_string; -} - -int -LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size, unsigned char *data) -{ - if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); - else - return Successful; -} - -void -DeleteClientFontStuff(ClientPtr client) -{ - int i; - FontPathElementPtr fpe; - - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } -} - -void -InitFonts () -{ - patternCache = MakeFontPatternCache(); - -#ifndef KDRIVESERVER - if (screenInfo.numScreens > screenInfo.numVideoScreens) { - PrinterFontRegisterFpeFunctions(); - FontFileCheckRegisterFpeFunctions(); - check_fs_register_fpe_functions(); - } else -#endif - { -#ifdef KDRIVESERVER - BuiltinRegisterFpeFunctions(); -#endif - FontFileRegisterFpeFunctions(); -#ifndef NOFONTSERVERACCESS - fs_register_fpe_functions(); -#endif - } -} - -int -GetDefaultPointSize () -{ - return 120; -} - - -FontResolutionPtr -GetClientResolutions (int *num) -{ - if (requestingClient && requestingClient->fontResFunc != NULL && - !requestingClient->clientGone) - { - return (*requestingClient->fontResFunc)(requestingClient, num); - } - else { - static struct _FontResolution res; - ScreenPtr pScreen; - - pScreen = screenInfo.screens[0]; - res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; - /* - * XXX - we'll want this as long as bitmap instances are prevalent - so that we can match them from scalable fonts - */ - if (res.x_resolution < 88) - res.x_resolution = 75; - else - res.x_resolution = 100; - res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; - if (res.y_resolution < 88) - res.y_resolution = 75; - else - res.y_resolution = 100; - res.point_size = 120; - *num = 1; - return &res; - } -} - -/* - * returns the type index of the new fpe - * - * should be called (only once!) by each type of fpe when initialized - */ - -int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) -{ - FPEFunctions *new; - - /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); - if (!new) - return -1; - fpe_functions = new; - - fpe_functions[num_fpe_types].name_check = name_func; - fpe_functions[num_fpe_types].open_font = open_func; - fpe_functions[num_fpe_types].close_font = close_func; - fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; - fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; - fpe_functions[num_fpe_types].init_fpe = init_func; - fpe_functions[num_fpe_types].free_fpe = free_func; - fpe_functions[num_fpe_types].reset_fpe = reset_func; - fpe_functions[num_fpe_types].client_died = client_died; - fpe_functions[num_fpe_types].load_glyphs = load_glyphs; - fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; - fpe_functions[num_fpe_types].set_path_hook = set_path_func; - - return num_fpe_types++; -} - -void -FreeFonts() -{ - if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; - } - FreeFontPath(font_path_elements, num_fpes, TRUE); - font_path_elements = 0; - num_fpes = 0; - xfree(fpe_functions); - num_fpe_types = 0; - fpe_functions = (FPEFunctions *) 0; -} - -/* convenience functions for FS interface */ - -FontPtr -find_old_font(XID id) -{ - return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE, - SecurityUnknownAccess); -} - -Font -GetNewFontClientID() -{ - return FakeClientID(0); -} - -int -StoreFontClientFont(FontPtr pfont, Font id) -{ - return AddResource(id, RT_NONE, (pointer) pfont); -} - -void -DeleteFontClientID(Font id) -{ - FreeResource(id, RT_NONE); -} - -int -client_auth_generation(ClientPtr client) -{ - return 0; -} - -static int fs_handlers_installed = 0; -static unsigned int last_server_gen; - -int -init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler) -{ - /* if server has reset, make sure the b&w handlers are reinstalled */ - if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; - } - if (fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "adding FS b & w handlers\n"); -#endif - - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; - } - QueueFontWakeup(fpe); - return Successful; -} - -void -remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler, Bool all) -{ - if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - -#ifdef DEBUG - fprintf(stderr, "removing FS b & w handlers\n"); -#endif - - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } - } - RemoveFontWakeup(fpe); -} - -#ifdef DEBUG -#define GLWIDTHBYTESPADDED(bits,nbytes) \ - ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ - :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ - :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ - :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ - : 0) - -#define GLYPH_SIZE(ch, nbytes) \ - GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \ - (ch)->metrics.leftSideBearing, (nbytes)) -void -dump_char_ascii(CharInfoPtr cip) -{ - int r, - l; - int bpr; - int byte; - static unsigned maskTab[] = { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - bpr = GLYPH_SIZE(cip, 4); - for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) { - pointer row = (pointer) cip->bits + r * bpr; - - byte = 0; - for (l = 0; l <= (cip->metrics.rightSideBearing - - cip->metrics.leftSideBearing); l++) { - if (maskTab[l & 7] & row[l >> 3]) - putchar('X'); - else - putchar('.'); - } - putchar('\n'); - } -} - -#endif diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.NX.original deleted file mode 100644 index c5593adbb..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.NX.original +++ /dev/null @@ -1,5044 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XdotOrg: xc/programs/Xserver/dix/events.c,v 1.17 2005/08/25 22:11:04 anholt Exp $ */ -/* $XFree86: xc/programs/Xserver/dix/events.c,v 3.51 2004/01/12 17:04:52 tsi Exp $ */ -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/***************************************************************** - -Copyright 2003-2005 Sun Microsystems, Inc. - -All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, and/or sell copies of the Software, and to permit persons -to whom the Software is furnished to do so, provided that the above -copyright notice(s) and this permission notice appear in all copies of -the Software and that both the above copyright notice(s) and this -permission notice appear in supporting documentation. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL -INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING -FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -Except as contained in this notice, the name of a copyright holder -shall not be used in advertising or otherwise to promote the sale, use -or other dealings in this Software without prior written authorization -of the copyright holder. - -******************************************************************/ - -/* $Xorg: events.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "Xlib.h" -#include "misc.h" -#include "resource.h" -#define NEED_EVENTS -#define NEED_REPLIES -#include -#include "windowstr.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "cursorstr.h" - -#include "dixstruct.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include "globals.h" - -#ifdef XKB -#include -extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); -#endif - -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif - -#ifdef XEVIE -extern WindowPtr *WindowTable; -extern int xevieFlag; -extern int xevieClientIndex; -extern DeviceIntPtr xeviemouse; -extern DeviceIntPtr xeviekb; -extern Mask xevieMask; -extern Mask xevieFilters[128]; -extern int xevieEventSent; -extern int xevieKBEventSent; -int xeviegrabState = 0; -xEvent *xeviexE; -#endif - -#include -#include "exevents.h" -#include "extnsionst.h" - -#include "dixevents.h" -#include "dixgrabs.h" -#include "../../dix/dispatch.h" - -#include "NXlib.h" - -#include "Events.h" -#include "Windows.h" -#include "Args.h" - -#ifdef NX_DEBUG_INPUT -extern int nxagentDebugInput; -extern int nxagentDebugInputDevices; -#endif - -extern Display *nxagentDisplay; - -extern WindowPtr nxagentLastEnteredWindow; - -#define EXTENSION_EVENT_BASE 64 - -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ -#define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask ) -#define AllButtonsMask ( \ - Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) -#define MotionMask ( \ - PointerMotionMask | Button1MotionMask | \ - Button2MotionMask | Button3MotionMask | Button4MotionMask | \ - Button5MotionMask | ButtonMotionMask ) -#define PropagateMask ( \ - KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \ - MotionMask ) -#define PointerGrabMask ( \ - ButtonPressMask | ButtonReleaseMask | \ - EnterWindowMask | LeaveWindowMask | \ - PointerMotionHintMask | KeymapStateMask | \ - MotionMask ) -#define AllModifiersMask ( \ - ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \ - Mod3Mask | Mod4Mask | Mod5Mask ) -#define AllEventMasks (lastEventMask|(lastEventMask-1)) -/* - * The following relies on the fact that the ButtonMotionMasks are equal - * to the corresponding ButtonMasks from the current modifier/button state. - */ -#define Motion_Filter(class) (PointerMotionMask | \ - (class)->state | (class)->motionMask) - - -#define WID(w) ((w) ? ((w)->drawable.id) : 0) - -#define XE_KBPTR (xE->u.keyButtonPointer) - - -#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) - -CallbackListPtr EventCallback; -CallbackListPtr DeviceEventCallback; - -#define DNPMCOUNT 8 - -Mask DontPropagateMasks[DNPMCOUNT]; -static int DontPropagateRefCnts[DNPMCOUNT]; - -#ifdef DEBUG -static debug_events = 0; -#endif -InputInfo inputInfo; - -static struct { - QdEventPtr pending, *pendtail; - DeviceIntPtr replayDev; /* kludgy rock to put flag for */ - WindowPtr replayWin; /* ComputeFreezes */ - Bool playingEvents; - TimeStamp time; -} syncEvents; - -/* - * The window trace information is used to avoid having to compute all the - * windows between the root and the current pointer window each time a button - * or key goes down. The grabs on each of those windows must be checked. - */ -static WindowPtr *spriteTrace = (WindowPtr *)NULL; -#define ROOT spriteTrace[0] -static int spriteTraceSize = 0; -static int spriteTraceGood; - -static struct { - CursorPtr current; - BoxRec hotLimits; /* logical constraints of hot spot */ - Bool confined; /* confined to screen */ -#if defined(SHAPE) || defined(PANORAMIX) - RegionPtr hotShape; /* additional logical shape constraint */ -#endif - BoxRec physLimits; /* physical constraints of hot spot */ - WindowPtr win; /* window of logical position */ - HotSpot hot; /* logical pointer position */ - HotSpot hotPhys; /* physical pointer position */ -#ifdef PANORAMIX - ScreenPtr screen; /* all others are in Screen 0 coordinates */ - RegionRec Reg1; /* Region 1 for confining motion */ - RegionRec Reg2; /* Region 2 for confining virtual motion */ - WindowPtr windows[MAXSCREENS]; - WindowPtr confineWin; /* confine window */ -#endif -} sprite; /* info about the cursor sprite */ - -#ifdef XEVIE -WindowPtr xeviewin; -HotSpot xeviehot; -#endif - -static void DoEnterLeaveEvents( - WindowPtr fromWin, - WindowPtr toWin, - int mode -); - -static WindowPtr XYToWindow( - int x, - int y -); - -extern int lastEvent; - -static Mask lastEventMask; - -#ifdef XINPUT -extern int DeviceMotionNotify; -#endif - -#define CantBeFiltered NoEventMask -static Mask filters[128] = -{ - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ - EnterWindowMask, /* EnterNotify */ - LeaveWindowMask, /* LeaveNotify */ - FocusChangeMask, /* FocusIn */ - FocusChangeMask, /* FocusOut */ - KeymapStateMask, /* KeymapNotify */ - ExposureMask, /* Expose */ - CantBeFiltered, /* GraphicsExpose */ - CantBeFiltered, /* NoExpose */ - VisibilityChangeMask, /* VisibilityNotify */ - SubstructureNotifyMask, /* CreateNotify */ - StructureAndSubMask, /* DestroyNotify */ - StructureAndSubMask, /* UnmapNotify */ - StructureAndSubMask, /* MapNotify */ - SubstructureRedirectMask, /* MapRequest */ - StructureAndSubMask, /* ReparentNotify */ - StructureAndSubMask, /* ConfigureNotify */ - SubstructureRedirectMask, /* ConfigureRequest */ - StructureAndSubMask, /* GravityNotify */ - ResizeRedirectMask, /* ResizeRequest */ - StructureAndSubMask, /* CirculateNotify */ - SubstructureRedirectMask, /* CirculateRequest */ - PropertyChangeMask, /* PropertyNotify */ - CantBeFiltered, /* SelectionClear */ - CantBeFiltered, /* SelectionRequest */ - CantBeFiltered, /* SelectionNotify */ - ColormapChangeMask, /* ColormapNotify */ - CantBeFiltered, /* ClientMessage */ - CantBeFiltered /* MappingNotify */ -}; - -static CARD8 criticalEvents[32] = -{ - 0x7c /* key and button events */ -}; - -#ifdef PANORAMIX - -static void ConfineToShape(RegionPtr shape, int *px, int *py); -static void SyntheticMotion(int x, int y); -static void PostNewCursor(void); - -static Bool -XineramaSetCursorPosition( - int x, - int y, - Bool generateEvent -){ - ScreenPtr pScreen; - BoxRec box; - int i; - - /* x,y are in Screen 0 coordinates. We need to decide what Screen - to send the message too and what the coordinates relative to - that screen are. */ - - pScreen = sprite.screen; - x += panoramiXdataPtr[0].x; - y += panoramiXdataPtr[0].y; - - if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum], - x, y, &box)) - { - FOR_NSCREENS(i) - { - if(i == pScreen->myNum) - continue; - if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i], x, y, &box)) - { - pScreen = screenInfo.screens[i]; - break; - } - } - } - - sprite.screen = pScreen; - sprite.hotPhys.x = x - panoramiXdataPtr[0].x; - sprite.hotPhys.y = y - panoramiXdataPtr[0].y; - x -= panoramiXdataPtr[pScreen->myNum].x; - y -= panoramiXdataPtr[pScreen->myNum].y; - - return (*pScreen->SetCursorPosition)(pScreen, x, y, generateEvent); -} - - -static void -XineramaConstrainCursor(void) -{ - ScreenPtr pScreen = sprite.screen; - BoxRec newBox = sprite.physLimits; - - /* Translate the constraining box to the screen - the sprite is actually on */ - newBox.x1 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.x2 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.y1 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - newBox.y2 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - - (* pScreen->ConstrainCursor)(pScreen, &newBox); -} - -static void -XineramaCheckPhysLimits( - CursorPtr cursor, - Bool generateEvents -){ - HotSpot new; - - if (!cursor) - return; - - new = sprite.hotPhys; - - /* I don't care what the DDX has to say about it */ - sprite.physLimits = sprite.hotLimits; - - /* constrain the pointer to those limits */ - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) /* more work if the shape is a mess */ - ConfineToShape(sprite.hotShape, &new.x, &new.y); - - if((new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - XineramaSetCursorPosition (new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } - - /* Tell DDX what the limits are */ - XineramaConstrainCursor(); -} - - -static Bool -XineramaSetWindowPntrs(WindowPtr pWin) -{ - if(pWin == WindowTable[0]) { - memcpy(sprite.windows, WindowTable, - PanoramiXNumScreens*sizeof(WindowPtr)); - } else { - PanoramiXRes *win; - int i; - - win = (PanoramiXRes*)LookupIDByType(pWin->drawable.id, XRT_WINDOW); - - if(!win) - return FALSE; - - for(i = 0; i < PanoramiXNumScreens; i++) { - sprite.windows[i] = LookupIDByType(win->info[i].id, RT_WINDOW); - if(!sprite.windows[i]) /* window is being unmapped */ - return FALSE; - } - } - return TRUE; -} - -static void -XineramaCheckVirtualMotion( - QdEventPtr qe, - WindowPtr pWin -){ - - if (qe) - { - sprite.hot.pScreen = qe->pScreen; /* should always be Screen 0 */ -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - int x, y, off_x, off_y, i; - BoxRec lims; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg2, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg2, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg2, &sprite.Reg2, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - lims = *REGION_EXTENTS(sprite.screen, &sprite.Reg2); - - if (sprite.hot.x < lims.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y2 - 1; - - if (REGION_NUM_RECTS(&sprite.Reg2) > 1) - ConfineToShape(&sprite.Reg2, &sprite.hot.x, &sprite.hot.y); - - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } -} - - -static Bool -XineramaCheckMotion(xEvent *xE) -{ - WindowPtr prevSpriteWin = sprite.win; - - if (xE && !syncEvents.playingEvents) - { - /* Motion events entering DIX get translated to Screen 0 - coordinates. Replayed events have already been - translated since they've entered DIX before */ - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = XE_KBPTR.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); - - sprite.hotPhys = sprite.hot; - if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - (sprite.hotPhys.y != XE_KBPTR.rootY)) - { - XineramaSetCursorPosition( - sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - } - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - -#ifdef XEVIE - xeviewin = -#endif - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); - - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - - -static void -XineramaConfineCursorToWindow(WindowPtr pWin, Bool generateEvents) -{ - - if (syncEvents.playingEvents) - { - XineramaCheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - int x, y, off_x, off_y, i; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg1, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg1, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg1, &sprite.Reg1, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - sprite.hotLimits = *REGION_EXTENTS(sprite.screen, &sprite.Reg1); - - if(REGION_NUM_RECTS(&sprite.Reg1) > 1) - sprite.hotShape = &sprite.Reg1; - else - sprite.hotShape = NullRegion; - - sprite.confined = FALSE; - sprite.confineWin = (pWin == WindowTable[0]) ? NullWindow : pWin; - - XineramaCheckPhysLimits(sprite.current, generateEvents); - } -} - - -static void -XineramaChangeToCursor(CursorPtr cursor) -{ - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - XineramaCheckPhysLimits(cursor, FALSE); - (*sprite.screen->DisplayCursor)(sprite.screen, cursor); - FreeCursor(sprite.current, (Cursor)0); - sprite.current = cursor; - sprite.current->refcnt++; - } -} - - -#endif /* PANORAMIX */ - -void -SetMaskForEvent(Mask mask, int event) -{ - if ((event < LASTEvent) || (event >= 128)) - FatalError("SetMaskForEvent: bogus event number"); - filters[event] = mask; -} - -void -SetCriticalEvent(int event) -{ - if (event >= 128) - FatalError("SetCriticalEvent: bogus event number"); - criticalEvents[event >> 3] |= 1 << (event & 7); -} - -static void -SyntheticMotion(int x, int y) -{ - xEvent xE; - -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - x += panoramiXdataPtr[0].x - panoramiXdataPtr[sprite.screen->myNum].x; - y += panoramiXdataPtr[0].y - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; - if (syncEvents.playingEvents) - xE.u.keyButtonPointer.time = syncEvents.time.milliseconds; - else - xE.u.keyButtonPointer.time = currentTime.milliseconds; - xE.u.u.type = MotionNotify; - (*inputInfo.pointer->public.processInputProc)(&xE, inputInfo.pointer, 1); -} - -#ifdef SHAPE -static void -ConfineToShape(RegionPtr shape, int *px, int *py) -{ - BoxRec box; - int x = *px, y = *py; - int incx = 1, incy = 1; - - if (POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)) - return; - box = *REGION_EXTENTS(sprite.hot.pScreen, shape); - /* this is rather crude */ - do { - x += incx; - if (x >= box.x2) - { - incx = -1; - x = *px - 1; - } - else if (x < box.x1) - { - incx = 1; - x = *px; - y += incy; - if (y >= box.y2) - { - incy = -1; - y = *py - 1; - } - else if (y < box.y1) - return; /* should never get here! */ - } - } while (!POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)); - *px = x; - *py = y; -} -#endif - -static void -CheckPhysLimits( - CursorPtr cursor, - Bool generateEvents, - Bool confineToScreen, - ScreenPtr pScreen) -{ - HotSpot new; - - if (!cursor) - return; - new = sprite.hotPhys; - if (pScreen) - new.pScreen = pScreen; - else - pScreen = new.pScreen; - (*pScreen->CursorLimits) (pScreen, cursor, &sprite.hotLimits, - &sprite.physLimits); - sprite.confined = confineToScreen; - (* pScreen->ConstrainCursor)(pScreen, &sprite.physLimits); - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &new.x, &new.y); -#endif - if ((pScreen != sprite.hotPhys.pScreen) || - (new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - if (pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys = new; - (*pScreen->SetCursorPosition) (pScreen, new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } -} - -static void -CheckVirtualMotion( - register QdEventPtr qe, - register WindowPtr pWin) -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaCheckVirtualMotion(qe, pWin); - return; - } -#endif - if (qe) - { - sprite.hot.pScreen = qe->pScreen; -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - BoxRec lims; - - if (sprite.hot.pScreen != pWin->drawable.pScreen) - { - sprite.hot.pScreen = pWin->drawable.pScreen; -#ifdef XEVIE - xeviehot.x = xeviehot.y = 0; -#endif - sprite.hot.x = sprite.hot.y = 0; - } - lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize); - if (sprite.hot.x < lims.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y2 - 1; -#ifdef SHAPE - if (wBoundingShape(pWin)) - ConfineToShape(&pWin->borderSize, &sprite.hot.x, &sprite.hot.y); -#endif - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } - ROOT = WindowTable[sprite.hot.pScreen->myNum]; -} - -static void -ConfineCursorToWindow(WindowPtr pWin, Bool generateEvents, Bool confineToScreen) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaConfineCursorToWindow(pWin, generateEvents); - return; - } -#endif - - if (syncEvents.playingEvents) - { - CheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - sprite.hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize); -#ifdef SHAPE - sprite.hotShape = wBoundingShape(pWin) ? &pWin->borderSize - : NullRegion; -#endif - CheckPhysLimits(sprite.current, generateEvents, confineToScreen, - pScreen); - } -} - -Bool -PointerConfinedToScreen() -{ - return sprite.confined; -} - -static void -ChangeToCursor(CursorPtr cursor) -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaChangeToCursor(cursor); - return; - } -#endif - - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - CheckPhysLimits(cursor, FALSE, sprite.confined, - (ScreenPtr)NULL); - (*sprite.hotPhys.pScreen->DisplayCursor) (sprite.hotPhys.pScreen, - cursor); - FreeCursor(sprite.current, (Cursor)0); - sprite.current = cursor; - sprite.current->refcnt++; - } -} - -/* returns true if b is a descendent of a */ -Bool -IsParent(register WindowPtr a, register WindowPtr b) -{ - for (b = b->parent; b; b = b->parent) - if (b == a) return TRUE; - return FALSE; -} - -static void -PostNewCursor(void) -{ - register WindowPtr win; - register GrabPtr grab = inputInfo.pointer->grab; - - if (syncEvents.playingEvents) - return; - if (grab) - { - if (grab->cursor) - { - ChangeToCursor(grab->cursor); - return; - } - if (IsParent(grab->window, sprite.win)) - win = sprite.win; - else - win = grab->window; - } - else - win = sprite.win; - for (; win; win = win->parent) - if (win->optional && win->optional->cursor != NullCursor) - { - ChangeToCursor(win->optional->cursor); - return; - } -} - -WindowPtr -GetCurrentRootWindow() -{ - return ROOT; -} - -WindowPtr -GetSpriteWindow() -{ - return sprite.win; -} - -CursorPtr -GetSpriteCursor() -{ - return sprite.current; -} - -void -GetSpritePosition(int *px, int *py) -{ - *px = sprite.hotPhys.x; - *py = sprite.hotPhys.y; -} - -#ifdef PANORAMIX -int -XineramaGetCursorScreen() -{ - if(!noPanoramiXExtension) { - return sprite.screen->myNum; - } else { - return 0; - } -} -#endif /* PANORAMIX */ - -#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */ - -static void -MonthChangedOrBadTime(register xEvent *xE) -{ - /* If the ddx/OS is careless about not processing timestamped events from - * different sources in sorted order, then it's possible for time to go - * backwards when it should not. Here we ensure a decent time. - */ - if ((currentTime.milliseconds - XE_KBPTR.time) > TIMESLOP) - currentTime.months++; - else - XE_KBPTR.time = currentTime.milliseconds; -} - -#define NoticeTime(xE) { \ - if ((xE)->u.keyButtonPointer.time < currentTime.milliseconds) \ - MonthChangedOrBadTime(xE); \ - currentTime.milliseconds = (xE)->u.keyButtonPointer.time; \ - lastDeviceEventTime = currentTime; } - -void -NoticeEventTime(register xEvent *xE) -{ - if (!syncEvents.playingEvents) - NoticeTime(xE); -} - -/************************************************************************** - * The following procedures deal with synchronous events * - **************************************************************************/ - -void -EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count) -{ - register QdEventPtr tail = *syncEvents.pendtail; - register QdEventPtr qe; - xEvent *qxE; - - NoticeTime(xE); - -#ifdef XKB - /* Fix for key repeating bug. */ - if (device->key != NULL && device->key->xkbInfo != NULL && - xE->u.u.type == KeyRelease) - AccessXCancelRepeatKey(device->key->xkbInfo, xE->u.u.detail); -#endif - - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* The RECORD spec says that the root window field of motion events - * must be valid. At this point, it hasn't been filled in yet, so - * we do it here. The long expression below is necessary to get - * the current root window; the apparently reasonable alternative - * GetCurrentRootWindow()->drawable.id doesn't give you the right - * answer on the first motion event after a screen change because - * the data that GetCurrentRootWindow relies on hasn't been - * updated yet. - */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - if (xE->u.u.type == MotionNotify) - { -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; - } -#endif - sprite.hotPhys.x = XE_KBPTR.rootX; - sprite.hotPhys.y = XE_KBPTR.rootY; - /* do motion compression */ - if (tail && - (tail->event->u.u.type == MotionNotify) && - (tail->pScreen == sprite.hotPhys.pScreen)) - { - tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x; - tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y; - tail->event->u.keyButtonPointer.time = XE_KBPTR.time; - tail->months = currentTime.months; - return; - } - } - qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + (count * sizeof(xEvent))); - if (!qe) - return; - qe->next = (QdEventPtr)NULL; - qe->device = device; - qe->pScreen = sprite.hotPhys.pScreen; - qe->months = currentTime.months; - qe->event = (xEvent *)(qe + 1); - qe->evcount = count; - for (qxE = qe->event; --count >= 0; qxE++, xE++) - *qxE = *xE; - if (tail) - syncEvents.pendtail = &tail->next; - *syncEvents.pendtail = qe; -} - -static void -PlayReleasedEvents(void) -{ - register QdEventPtr *prev, qe; - register DeviceIntPtr dev; - - prev = &syncEvents.pending; - while ( (qe = *prev) ) - { - if (!qe->device->sync.frozen) - { - *prev = qe->next; - if (*syncEvents.pendtail == *prev) - syncEvents.pendtail = prev; - if (qe->event->u.u.type == MotionNotify) - CheckVirtualMotion(qe, NullWindow); - syncEvents.time.months = qe->months; - syncEvents.time.milliseconds = qe->event->u.keyButtonPointer.time; -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - qe->event->u.keyButtonPointer.rootX += - panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x; - qe->event->u.keyButtonPointer.rootY += - panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - (*qe->device->public.processInputProc)(qe->event, qe->device, - qe->evcount); - xfree(qe); - for (dev = inputInfo.devices; dev && dev->sync.frozen; dev = dev->next) - ; - if (!dev) - break; - /* Playing the event may have unfrozen another device. */ - /* So to play it safe, restart at the head of the queue */ - prev = &syncEvents.pending; - } - else - prev = &qe->next; - } -} - -static void -FreezeThaw(register DeviceIntPtr dev, Bool frozen) -{ - dev->sync.frozen = frozen; - if (frozen) - dev->public.processInputProc = dev->public.enqueueInputProc; - else - dev->public.processInputProc = dev->public.realInputProc; -} - -void -ComputeFreezes() -{ - register DeviceIntPtr replayDev = syncEvents.replayDev; - register int i; - WindowPtr w; - register xEvent *xE; - int count; - GrabPtr grab; - register DeviceIntPtr dev; - - for (dev = inputInfo.devices; dev; dev = dev->next) - FreezeThaw(dev, dev->sync.other || (dev->sync.state >= FROZEN)); - if (syncEvents.playingEvents || (!replayDev && !syncEvents.pending)) - return; - syncEvents.playingEvents = TRUE; - if (replayDev) - { - xE = replayDev->sync.event; - count = replayDev->sync.evcount; - syncEvents.replayDev = (DeviceIntPtr)NULL; - - w = XYToWindow( XE_KBPTR.rootX, XE_KBPTR.rootY); - for (i = 0; i < spriteTraceGood; i++) - { - if (syncEvents.replayWin == spriteTrace[i]) - { - if (!CheckDeviceGrabs(replayDev, xE, i+1, count)) { - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, - replayDev, count); - } - goto playmore; - } - } - /* must not still be in the same stack */ - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, replayDev, count); - } -playmore: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!dev->sync.frozen) - { - PlayReleasedEvents(); - break; - } - } - syncEvents.playingEvents = FALSE; - /* the following may have been skipped during replay, so do it now */ - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); - PostNewCursor(); -} - -#ifdef RANDR -void -ScreenRestructured (ScreenPtr pScreen) -{ - GrabPtr grab; - - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); -} -#endif - -void -CheckGrabForSyncs(register DeviceIntPtr thisDev, Bool thisMode, Bool otherMode) -{ - register GrabPtr grab = thisDev->grab; - register DeviceIntPtr dev; - - if (thisMode == GrabModeSync) - thisDev->sync.state = FROZEN_NO_EVENT; - else - { /* free both if same client owns both */ - thisDev->sync.state = THAWED; - if (thisDev->sync.other && - (CLIENT_BITS(thisDev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - thisDev->sync.other = NullGrab; - } - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev != thisDev) - { - if (otherMode == GrabModeSync) - dev->sync.other = grab; - else - { /* free both if same client owns both */ - if (dev->sync.other && - (CLIENT_BITS(dev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - dev->sync.other = NullGrab; - } - } - } - ComputeFreezes(); -} - -void -ActivatePointerGrab(register DeviceIntPtr mouse, register GrabPtr grab, - TimeStamp time, Bool autoGrab) -{ - WindowPtr oldWin = (mouse->grab) ? mouse->grab->window - : sprite.win; - - if (grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, FALSE, TRUE); - } - DoEnterLeaveEvents(oldWin, grab->window, NotifyGrab); - mouse->valuator->motionHintWindow = NullWindow; - if (syncEvents.playingEvents) - mouse->grabTime = syncEvents.time; - else - mouse->grabTime = time; - if (grab->cursor) - grab->cursor->refcnt++; - mouse->activeGrab = *grab; - mouse->grab = &mouse->activeGrab; - mouse->fromPassiveGrab = autoGrab; - PostNewCursor(); - CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); - - #ifdef NXAGENT_SERVER - - /* - * If grab is synchronous, events are delivered to clients only if they send - * an AllowEvent request. If mode field in AllowEvent request is SyncPointer, the - * delivered event is saved in a queue and replayed later, when grab is released. - * We should export sync grab to X as async in order to avoid events to be - * queued twice, in the agent and in the X server. This solution have a drawback: - * replayed events are not delivered to that application that are not clients of - * the agent. - * A different solution could be to make the grab asynchronous in the agent and - * to export it as synchronous. But this seems to be less safe. - * - * To make internal grab asynchronous, change previous line as follows. - * - * if (nxagentOption(Rootless)) - * { - * CheckGrabForSyncs(mouse, GrabModeAsync, (Bool)grab->keyboardMode); - * } - * else - * { - * CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); - * } - */ - - if (nxagentOption(Rootless) == 1) - { - /* - * FIXME: We should use the correct value - * for the cursor. Temporarily we set it - * to None. - */ - - int resource = nxagentWaitForResource(NXGetCollectGrabPointerResource, - nxagentCollectGrabPointerPredicate); - - NXCollectGrabPointer(nxagentDisplay, resource, nxagentWindow(grab -> window), - 1, grab -> eventMask & PointerGrabMask, - GrabModeAsync, GrabModeAsync, (grab -> confineTo) ? - nxagentWindow(grab -> confineTo) : None, - None, CurrentTime); - } - - #endif -} - -void -DeactivatePointerGrab(register DeviceIntPtr mouse) -{ - register GrabPtr grab = mouse->grab; - register DeviceIntPtr dev; - - mouse->valuator->motionHintWindow = NullWindow; - mouse->grab = NullGrab; - mouse->sync.state = NOT_GRABBED; - mouse->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoEnterLeaveEvents(grab->window, sprite.win, NotifyUngrab); - if (grab->confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - PostNewCursor(); - if (grab->cursor) - FreeCursor(grab->cursor, (Cursor)0); - ComputeFreezes(); - - #ifdef NXAGENT_SERVER - - if (nxagentOption(Rootless) == 1) - { - XUngrabPointer(nxagentDisplay, CurrentTime); - - if (sprite.win == ROOT) - { - mouse -> button -> state &= - ~(Button1Mask | Button2Mask | Button3Mask | - Button4Mask | Button5Mask); - } - } - - #endif -} - -void -ActivateKeyboardGrab(register DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool passive) -{ - WindowPtr oldWin; - - if (keybd->grab) - oldWin = keybd->grab->window; - else if (keybd->focus) - oldWin = keybd->focus->win; - else - oldWin = sprite.win; - if (oldWin == FollowKeyboardWin) - oldWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab); - if (syncEvents.playingEvents) - keybd->grabTime = syncEvents.time; - else - keybd->grabTime = time; - keybd->activeGrab = *grab; - keybd->grab = &keybd->activeGrab; - keybd->fromPassiveGrab = passive; - CheckGrabForSyncs(keybd, (Bool)grab->keyboardMode, (Bool)grab->pointerMode); -} - -void -DeactivateKeyboardGrab(register DeviceIntPtr keybd) -{ - register GrabPtr grab = keybd->grab; - register DeviceIntPtr dev; - register WindowPtr focusWin = keybd->focus ? keybd->focus->win - : sprite.win; - - if (focusWin == FollowKeyboardWin) - focusWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - keybd->grab = NullGrab; - keybd->sync.state = NOT_GRABBED; - keybd->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab); - ComputeFreezes(); -} - -void -AllowSome(ClientPtr client, TimeStamp time, DeviceIntPtr thisDev, int newState) -{ - Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced; - TimeStamp grabTime; - register DeviceIntPtr dev; - - thisGrabbed = thisDev->grab && SameClient(thisDev->grab, client); - thisSynced = FALSE; - otherGrabbed = FALSE; - othersFrozen = TRUE; - grabTime = thisDev->grabTime; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - { - if (!(thisGrabbed || otherGrabbed) || - (CompareTimeStamps(dev->grabTime, grabTime) == LATER)) - grabTime = dev->grabTime; - otherGrabbed = TRUE; - if (thisDev->sync.other == dev->grab) - thisSynced = TRUE; - if (dev->sync.state < FROZEN) - othersFrozen = FALSE; - } - else if (!dev->sync.other || !SameClient(dev->sync.other, client)) - othersFrozen = FALSE; - } - if (!((thisGrabbed && thisDev->sync.state >= FROZEN) || thisSynced)) - return; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, grabTime) == EARLIER)) - return; - switch (newState) - { - case THAWED: /* Async */ - if (thisGrabbed) - thisDev->sync.state = THAWED; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - break; - case FREEZE_NEXT_EVENT: /* Sync */ - if (thisGrabbed) - { - thisDev->sync.state = FREEZE_NEXT_EVENT; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - } - break; - case THAWED_BOTH: /* AsyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case FREEZE_BOTH_NEXT_EVENT: /* SyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = FREEZE_BOTH_NEXT_EVENT; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case NOT_GRABBED: /* Replay */ - if (thisGrabbed && thisDev->sync.state == FROZEN_WITH_EVENT) - { - if (thisSynced) - thisDev->sync.other = NullGrab; - syncEvents.replayDev = thisDev; - syncEvents.replayWin = thisDev->grab->window; - (*thisDev->DeactivateGrab)(thisDev); - syncEvents.replayDev = (DeviceIntPtr)NULL; - } - break; - case THAW_OTHERS: /* AsyncOthers */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - } -} - -int -ProcAllowEvents(register ClientPtr client) -{ - TimeStamp time; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - REQUEST(xAllowEventsReq); - - REQUEST_SIZE_MATCH(xAllowEventsReq); - time = ClientTimeToServerTime(stuff->time); - switch (stuff->mode) - { - case ReplayPointer: - AllowSome(client, time, mouse, NOT_GRABBED); - break; - case SyncPointer: - AllowSome(client, time, mouse, FREEZE_NEXT_EVENT); - break; - case AsyncPointer: - AllowSome(client, time, mouse, THAWED); - break; - case ReplayKeyboard: - AllowSome(client, time, keybd, NOT_GRABBED); - break; - case SyncKeyboard: - AllowSome(client, time, keybd, FREEZE_NEXT_EVENT); - break; - case AsyncKeyboard: - AllowSome(client, time, keybd, THAWED); - break; - case SyncBoth: - AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT); - break; - case AsyncBoth: - AllowSome(client, time, keybd, THAWED_BOTH); - break; - default: - client->errorValue = stuff->mode; - return BadValue; - } - - /* - * This is not necessary if we export grab to X as asynchronous. - * - * if (nxagentOption(Rootless) && stuff -> mode != ReplayKeyboard && - * stuff -> mode != SyncKeyboard && stuff -> mode != AsyncKeyboard) - * { - * XAllowEvents(nxagentDisplay, stuff -> mode, CurrentTime); - * } - */ - - return Success; -} - -void -ReleaseActiveGrabs(ClientPtr client) -{ - register DeviceIntPtr dev; - Bool done; - - /* XXX CloseDownClient should remove passive grabs before - * releasing active grabs. - */ - do { - done = TRUE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - { - (*dev->DeactivateGrab)(dev); - done = FALSE; - } - } - } while (!done); -} - -/************************************************************************** - * The following procedures deal with delivering events * - **************************************************************************/ - -int -TryClientEvents (ClientPtr client, xEvent *pEvents, int count, Mask mask, - Mask filter, GrabPtr grab) -{ - int i; - int type; - -#ifdef NX_DEBUG_INPUT - if (grab && nxagentDebugInput && grab->window) - { - fprintf(stderr, "TryClientEvents: Grab window is [0x%x].\n", - (unsigned int)grab->window->drawable.id); - if (!SameClient(grab, client)) - fprintf(stderr, "TryClientEvents: Events are going to be " - "discarded.\n"); - } -#endif -#if defined(DEBUG) || defined(NX_DEBUG_INPUT) -#ifdef NX_DEBUG_INPUT - if (nxagentDebugInput == 1) - fprintf(stderr, "Event([%d, %d], mask=0x%x), client=%d", - pEvents->u.u.type, pEvents->u.u.detail, (unsigned int)mask, - client->index); -#else - if (debug_events) ErrorF( - "Event([%d, %d], mask=0x%x), client=%d", - pEvents->u.u.type, pEvents->u.u.detail, mask, client->index); -#endif -#endif - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) - return -1; /* don't send, but notify caller */ - type = pEvents->u.u.type; - if (type == MotionNotify) - { - if (mask & PointerMotionHintMask) - { - if (WID(inputInfo.pointer->valuator->motionHintWindow) == - pEvents->u.keyButtonPointer.event) - { -#if defined(DEBUG) || defined(NX_DEBUG_INPUT) -#ifdef NX_DEBUG_INPUT - if (nxagentDebugInput == 1) - { - fprintf(stderr,"\nmotionHintWindow == keyButtonPointer.event\n"); - } -#else - if (debug_events) ErrorF("\n"); - fprintf(stderr,"motionHintWindow == keyButtonPointer.event\n"); -#endif -#endif - return 1; /* don't send, but pretend we did */ - } - pEvents->u.u.detail = NotifyHint; - } - else - { - pEvents->u.u.detail = NotifyNormal; - } - } -#ifdef XINPUT - else - { - if ((type == DeviceMotionNotify) && - MaybeSendDeviceMotionNotifyHint - ((deviceKeyButtonPointer*)pEvents, mask) != 0) - return 1; - } -#endif - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } - - if (BitIsOn(criticalEvents, type)) - { -#ifdef SMART_SCHEDULE - if (client->smart_priority < SMART_MAX_PRIORITY) - client->smart_priority++; -#endif - SetCriticalOutputPending(); - } - - WriteEventsToClient(client, count, pEvents); -#if defined(DEBUG) || defined(NX_DEBUG_INPUT) -#ifdef NX_DEBUG_INPUT - if (nxagentDebugInput == 1) - fprintf(stderr, " delivered\n"); -#else - if (debug_events) ErrorF( " delivered\n"); -#endif -#endif - return 1; - } - else - { -#if defined(DEBUG) || defined(NX_DEBUG_INPUT) -#ifdef NX_DEBUG_INPUT - if (nxagentDebugInput == 1) - fprintf(stderr, "\n"); -#else - if (debug_events) ErrorF("\n"); -#endif -#endif - return 0; - } -} - -int -DeliverEventsToWindow(register WindowPtr pWin, xEvent *pEvents, int count, - Mask filter, GrabPtr grab, int mskidx) -{ - int deliveries = 0, nondeliveries = 0; - int attempt; - register InputClients *other; - ClientPtr client = NullClient; - Mask deliveryMask = 0; /* If a grab occurs due to a button press, then - this mask is the mask of the grab. */ - int type = pEvents->u.u.type; - - /* CantBeFiltered means only window owner gets the event */ - if ((filter == CantBeFiltered) || !(type & EXTENSION_EVENT_BASE)) - { - /* if nobody ever wants to see this event, skip some work */ - if (filter != CantBeFiltered && - !((wOtherEventMasks(pWin)|pWin->eventMask) & filter)) - return 0; - if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = wClient(pWin); - deliveryMask = pWin->eventMask; - } else - nondeliveries--; - } - } - if (filter != CantBeFiltered) - { - if (type & EXTENSION_EVENT_BASE) - { - OtherInputMasks *inputMasks; - - inputMasks = wOtherInputMasks(pWin); - if (!inputMasks || - !(inputMasks->inputEvents[mskidx] & filter)) - return 0; - other = inputMasks->inputClients; - } - else - other = (InputClients *)wOtherClients(pWin); - for (; other; other = other->next) - { - if ( (attempt = TryClientEvents(rClient(other), pEvents, count, - other->mask[mskidx], filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = rClient(other); - deliveryMask = other->mask[mskidx]; - } else - nondeliveries--; - } - } - } - if ((type == ButtonPress) && deliveries && (!grab)) - { - GrabRec tempGrab; - - tempGrab.device = inputInfo.pointer; - tempGrab.resource = client->clientAsMask; - tempGrab.window = pWin; - tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE; - tempGrab.eventMask = deliveryMask; - tempGrab.keyboardMode = GrabModeAsync; - tempGrab.pointerMode = GrabModeAsync; - tempGrab.confineTo = NullWindow; - tempGrab.cursor = NullCursor; - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "DeliverEventsToWindow: Activating passive grab on pointer.\n"); - } - #endif - (*inputInfo.pointer->ActivateGrab)(inputInfo.pointer, &tempGrab, - currentTime, TRUE); - } - else if ((type == MotionNotify) && deliveries) - inputInfo.pointer->valuator->motionHintWindow = pWin; -#ifdef XINPUT - else - { - if (((type == DeviceMotionNotify) -#ifdef XKB - || (type == DeviceButtonPress) -#endif - ) && deliveries) - CheckDeviceGrabAndHintWindow (pWin, type, - (deviceKeyButtonPointer*) pEvents, - grab, client, deliveryMask); - } -#endif - if (deliveries) - return deliveries; - return nondeliveries; -} - -/* If the event goes to dontClient, don't send it and return 0. if - send works, return 1 or if send didn't work, return 2. - Only works for core events. -*/ - -#ifdef PANORAMIX -static int -XineramaTryClientEventsResult( - ClientPtr client, - GrabPtr grab, - Mask mask, - Mask filter -){ - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) return -1; - else return 1; - } - return 0; -} -#endif - -int -MaybeDeliverEventsToClient(register WindowPtr pWin, xEvent *pEvents, - int count, Mask filter, ClientPtr dontClient) -{ - register OtherClients *other; - - - if (pWin->eventMask & filter) - { - if (wClient(pWin) == dontClient) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - wClient(pWin), NullGrab, pWin->eventMask, filter); -#endif - return TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, NullGrab); - } - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & filter) - { - if (SameClient(other, dontClient)) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - rClient(other), NullGrab, other->mask, filter); -#endif - return TryClientEvents(rClient(other), pEvents, count, - other->mask, filter, NullGrab); - } - } - return 2; -} - -static void -FixUpEventFromWindow( - xEvent *xE, - WindowPtr pWin, - Window child, - Bool calcChild) -{ - if (calcChild) - { - WindowPtr w=spriteTrace[spriteTraceGood-1]; - /* If the search ends up past the root should the child field be - set to none or should the value in the argument be passed - through. It probably doesn't matter since everyone calls - this function with child == None anyway. */ - - while (w) - { - /* If the source window is same as event window, child should be - none. Don't bother going all all the way back to the root. */ - - if (w == pWin) - { - child = None; - break; - } - - if (w->parent == pWin) - { - child = w->drawable.id; - break; - } - w = w->parent; - } - } - XE_KBPTR.root = ROOT->drawable.id; - XE_KBPTR.event = pWin->drawable.id; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - XE_KBPTR.sameScreen = xTrue; - XE_KBPTR.child = child; - XE_KBPTR.eventX = - XE_KBPTR.rootX - pWin->drawable.x; - XE_KBPTR.eventY = - XE_KBPTR.rootY - pWin->drawable.y; - } - else - { - XE_KBPTR.sameScreen = xFalse; - XE_KBPTR.child = None; - XE_KBPTR.eventX = 0; - XE_KBPTR.eventY = 0; - } -} - -int -DeliverDeviceEvents(register WindowPtr pWin, register xEvent *xE, GrabPtr grab, - register WindowPtr stopAt, DeviceIntPtr dev, int count) -{ - Window child = None; - int type = xE->u.u.type; - Mask filter = filters[type]; - int deliveries = 0; - - if (type & EXTENSION_EVENT_BASE) - { - register OtherInputMasks *inputMasks; - int mskidx = dev->id; - - inputMasks = wOtherInputMasks(pWin); - if (inputMasks && !(filter & inputMasks->deliverableEvents[mskidx])) - return 0; - while (pWin) - { - if (inputMasks && (inputMasks->inputEvents[mskidx] & filter)) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, mskidx); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (inputMasks && - (filter & inputMasks->dontPropagateMask[mskidx]))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - if (pWin) - inputMasks = wOtherInputMasks(pWin); - } - } - else - { - if (!(filter & pWin->deliverableEvents)) - return 0; - while (pWin) - { - if ((wOtherEventMasks(pWin)|pWin->eventMask) & filter) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, 0); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (filter & wDontPropagateMask(pWin))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - } - } - return 0; -} - -/* not useful for events that propagate up the tree or extension events */ -int -DeliverEvents(register WindowPtr pWin, register xEvent *xE, int count, - register WindowPtr otherParent) -{ - Mask filter; - int deliveries; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return count; -#endif - - if (!count) - return 0; - filter = filters[xE->u.u.type]; - if ((filter & SubstructureNotifyMask) && (xE->u.u.type != CreateNotify)) - xE->u.destroyNotify.event = pWin->drawable.id; - if (filter != StructureAndSubMask) - return DeliverEventsToWindow(pWin, xE, count, filter, NullGrab, 0); - deliveries = DeliverEventsToWindow(pWin, xE, count, StructureNotifyMask, - NullGrab, 0); - if (pWin->parent) - { - xE->u.destroyNotify.event = pWin->parent->drawable.id; - deliveries += DeliverEventsToWindow(pWin->parent, xE, count, - SubstructureNotifyMask, NullGrab, - 0); - if (xE->u.u.type == ReparentNotify) - { - xE->u.destroyNotify.event = otherParent->drawable.id; - deliveries += DeliverEventsToWindow(otherParent, xE, count, - SubstructureNotifyMask, - NullGrab, 0); - } - } - return deliveries; -} - - -static Bool -PointInBorderSize(WindowPtr pWin, int x, int y) -{ - BoxRec box; - - if(POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderSize, x, y, &box)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(POINT_IN_REGION(sprite.screen, - &sprite.windows[i]->borderSize, - x + panoramiXdataPtr[0].x - panoramiXdataPtr[i].x, - y + panoramiXdataPtr[0].y - panoramiXdataPtr[i].y, - &box)) - return TRUE; - } - } -#endif - return FALSE; -} - -static WindowPtr -XYToWindow(int x, int y) -{ - register WindowPtr pWin; - BoxRec box; - - spriteTraceGood = 1; /* root window still there */ - - if (nxagentOption(Rootless)) - { - if (nxagentLastEnteredWindow == NULL) - { - return ROOT; - } - - pWin = ROOT->lastChild; - - while (pWin && pWin != ROOT->firstChild && pWin != nxagentLastEnteredWindow) - { - pWin = pWin->prevSib; - } - } - else - { - pWin = ROOT->firstChild; - } - - while (pWin) - { - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth(pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) -#endif - ) - { - if (spriteTraceGood >= spriteTraceSize) - { - spriteTraceSize += 10; - Must_have_memory = TRUE; /* XXX */ - spriteTrace = (WindowPtr *)xrealloc( - spriteTrace, spriteTraceSize*sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - spriteTrace[spriteTraceGood++] = pWin; - pWin = pWin->firstChild; - } - else - pWin = pWin->nextSib; - } - return spriteTrace[spriteTraceGood-1]; -} - -static Bool -CheckMotion(xEvent *xE) -{ - WindowPtr prevSpriteWin = sprite.win; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaCheckMotion(xE); -#endif - - if (xE && !syncEvents.playingEvents) - { - if (sprite.hot.pScreen != sprite.hotPhys.pScreen) - { - sprite.hot.pScreen = sprite.hotPhys.pScreen; - ROOT = WindowTable[sprite.hot.pScreen->myNum]; - } -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = XE_KBPTR.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); -#endif - sprite.hotPhys = sprite.hot; - - /* - * This code force cursor position to be inside the - * root window of the agent. We can't view a reason - * to do this and it interacts in an undesirable way - * with toggling fullscreen. - * - * if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - * (sprite.hotPhys.y != XE_KBPTR.rootY)) - * { - * (*sprite.hotPhys.pScreen->SetCursorPosition)( - * sprite.hotPhys.pScreen, - * sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - * } - */ - - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - -#ifdef XEVIE - xeviewin = -#endif - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); -#ifdef notyet - if (!(sprite.win->deliverableEvents & - Motion_Filter(inputInfo.pointer->button)) - !syncEvents.playingEvents) - { - /* XXX Do PointerNonInterestBox here */ - } -#endif - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - -void -WindowsRestructured() -{ - (void) CheckMotion((xEvent *)NULL); -} - -#ifdef PANORAMIX -/* This was added to support reconfiguration under Xdmx. The problem is - * that if the 0th screen (i.e., WindowTable[0]) is moved to an origin - * other than 0,0, the information in the private sprite structure must - * be updated accordingly, or XYToWindow (and other routines) will not - * compute correctly. */ -void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) -{ - ScreenPtr pScreen = win->drawable.pScreen; - GrabPtr grab; - - if (noPanoramiXExtension) return; - - sprite.hot.x -= xoff; - sprite.hot.y -= yoff; - - sprite.hotPhys.x -= xoff; - sprite.hotPhys.y -= yoff; - - sprite.hotLimits.x1 -= xoff; - sprite.hotLimits.y1 -= yoff; - sprite.hotLimits.x2 -= xoff; - sprite.hotLimits.y2 -= yoff; - - if (REGION_NOTEMPTY(sprite.screen, &sprite.Reg1)) - REGION_TRANSLATE(sprite.screen, &sprite.Reg1, xoff, yoff); - if (REGION_NOTEMPTY(sprite.screen, &sprite.Reg2)) - REGION_TRANSLATE(sprite.screen, &sprite.Reg2, xoff, yoff); - - /* FIXME: if we call ConfineCursorToWindow, must we do anything else? */ - if ((grab = inputInfo.pointer->grab) && grab->confineTo) { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); -} -#endif - -void -DefineInitialRootWindow(register WindowPtr win) -{ - register ScreenPtr pScreen = win->drawable.pScreen; - #ifdef VIEWPORT_FRAME - extern void nxagentInitViewportFrame(ScreenPtr, WindowPtr); - #endif - extern int nxagentShadowInit(ScreenPtr, WindowPtr); - - sprite.hotPhys.pScreen = pScreen; - sprite.hotPhys.x = pScreen->width / 2; - sprite.hotPhys.y = pScreen->height / 2; - sprite.hot = sprite.hotPhys; - sprite.hotLimits.x2 = pScreen->width; - sprite.hotLimits.y2 = pScreen->height; -#ifdef XEVIE - xeviewin = -#endif - sprite.win = win; - sprite.current = wCursor (win); - sprite.current->refcnt++; - spriteTraceGood = 1; - ROOT = win; - (*pScreen->CursorLimits) ( - pScreen, sprite.current, &sprite.hotLimits, &sprite.physLimits); - sprite.confined = FALSE; - (*pScreen->ConstrainCursor) (pScreen, &sprite.physLimits); - (*pScreen->SetCursorPosition) (pScreen, sprite.hot.x, sprite.hot.y, FALSE); - (*pScreen->DisplayCursor) (pScreen, sprite.current); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotLimits.x1 = -panoramiXdataPtr[0].x; - sprite.hotLimits.y1 = -panoramiXdataPtr[0].y; - sprite.hotLimits.x2 = PanoramiXPixWidth - panoramiXdataPtr[0].x; - sprite.hotLimits.y2 = PanoramiXPixHeight - panoramiXdataPtr[0].y; - sprite.physLimits = sprite.hotLimits; - sprite.confineWin = NullWindow; -#ifdef SHAPE - sprite.hotShape = NullRegion; -#endif - sprite.screen = pScreen; - /* gotta UNINIT these someplace */ - REGION_NULL(pScreen, &sprite.Reg1); - REGION_NULL(pScreen, &sprite.Reg2); - } -#endif - - #ifdef VIEWPORT_FRAME - nxagentInitViewportFrame(pScreen, win); - #endif - - if (nxagentOption(Shadow)) - { - if (nxagentShadowInit(pScreen, win) == -1) - { - FatalError("Failed to connect to display '%s'", nxagentShadowDisplayName); - } - } -} - -/* - * This does not take any shortcuts, and even ignores its argument, since - * it does not happen very often, and one has to walk up the tree since - * this might be a newly instantiated cursor for an intermediate window - * between the one the pointer is in and the one that the last cursor was - * instantiated from. - */ -void -WindowHasNewCursor(WindowPtr pWin) -{ - PostNewCursor(); -} - -void -NewCurrentScreen(ScreenPtr newScreen, int x, int y) -{ - sprite.hotPhys.x = x; - sprite.hotPhys.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotPhys.x += panoramiXdataPtr[newScreen->myNum].x - - panoramiXdataPtr[0].x; - sprite.hotPhys.y += panoramiXdataPtr[newScreen->myNum].y - - panoramiXdataPtr[0].y; - if (newScreen != sprite.screen) { - sprite.screen = newScreen; - /* Make sure we tell the DDX to update its copy of the screen */ - if(sprite.confineWin) - XineramaConfineCursorToWindow(sprite.confineWin, TRUE); - else - XineramaConfineCursorToWindow(WindowTable[0], TRUE); - /* if the pointer wasn't confined, the DDX won't get - told of the pointer warp so we reposition it here */ - if(!syncEvents.playingEvents) - (*sprite.screen->SetCursorPosition)(sprite.screen, - sprite.hotPhys.x + panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x, - sprite.hotPhys.y + panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y, FALSE); - } - } else -#endif - if (newScreen != sprite.hotPhys.pScreen) - ConfineCursorToWindow(WindowTable[newScreen->myNum], TRUE, FALSE); -} - -#ifdef PANORAMIX - -static Bool -XineramaPointInWindowIsVisible( - WindowPtr pWin, - int x, - int y -) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - BoxRec box; - int i, xoff, yoff; - - if (!pWin->realized) return FALSE; - - if (POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) - return TRUE; - - if(!XineramaSetWindowPntrs(pWin)) return FALSE; - - xoff = x + panoramiXdataPtr[0].x; - yoff = y + panoramiXdataPtr[0].y; - - for(i = 1; i < PanoramiXNumScreens; i++) { - pWin = sprite.windows[i]; - pScreen = pWin->drawable.pScreen; - x = xoff - panoramiXdataPtr[i].x; - y = yoff - panoramiXdataPtr[i].y; - - if(POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box) - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) - return TRUE; - - } - - return FALSE; -} - -static int -XineramaWarpPointer(ClientPtr client) -{ - WindowPtr dest = NULL; - int x, y; - - REQUEST(xWarpPointerReq); - - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if(source == WindowTable[0]) { - winX -= panoramiXdataPtr[0].x; - winY -= panoramiXdataPtr[0].y; - } - if (x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !XineramaPointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) { - x = dest->drawable.x; - y = dest->drawable.y; - if(dest == WindowTable[0]) { - x -= panoramiXdataPtr[0].x; - y -= panoramiXdataPtr[0].y; - } - } - - x += stuff->dstX; - y += stuff->dstY; - - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); - - XineramaSetCursorPosition(x, y, TRUE); - - return Success; -} - -#endif - - -int -ProcWarpPointer(ClientPtr client) -{ - WindowPtr dest = NULL; - int x, y; - ScreenPtr newScreen; - - REQUEST(xWarpPointerReq); - - REQUEST_SIZE_MATCH(xWarpPointerReq); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaWarpPointer(client); -#endif - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if (source->drawable.pScreen != sprite.hotPhys.pScreen || - x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !PointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) - { - x = dest->drawable.x; - y = dest->drawable.y; - newScreen = dest->drawable.pScreen; - } else - newScreen = sprite.hotPhys.pScreen; - - x += stuff->dstX; - y += stuff->dstY; - - if (x < 0) - x = 0; - else if (x >= newScreen->width) - x = newScreen->width - 1; - if (y < 0) - y = 0; - else if (y >= newScreen->height) - y = newScreen->height - 1; - - if (newScreen == sprite.hotPhys.pScreen) - { - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; -#if defined(SHAPE) - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); -#endif - (*newScreen->SetCursorPosition)(newScreen, x, y, TRUE); - } - else if (!PointerConfinedToScreen()) - { - NewCurrentScreen(newScreen, x, y); - } - return Success; -} - -static Bool -BorderSizeNotEmpty(WindowPtr pWin) -{ - if(REGION_NOTEMPTY(sprite.hotPhys.pScreen, &pWin->borderSize)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(REGION_NOTEMPTY(sprite.screen, &sprite.windows[i]->borderSize)) - return TRUE; - } - } -#endif - return FALSE; -} - -/* "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a - passive grab set on the window to be activated. */ - -static Bool -CheckPassiveGrabsOnWindow( - WindowPtr pWin, - register DeviceIntPtr device, - register xEvent *xE, - int count) -{ - register GrabPtr grab = wPassiveGrabs(pWin); - GrabRec tempGrab; - register xEvent *dxE; - - if (!grab) - return FALSE; - tempGrab.window = pWin; - tempGrab.device = device; - tempGrab.type = xE->u.u.type; - tempGrab.detail.exact = xE->u.u.detail; - tempGrab.detail.pMask = NULL; - tempGrab.modifiersDetail.pMask = NULL; - for (; grab; grab = grab->next) - { -#ifdef XKB - DeviceIntPtr gdev; - XkbSrvInfoPtr xkbi; - - gdev= grab->modifierDevice; - xkbi= gdev->key->xkbInfo; -#endif - tempGrab.modifierDevice = grab->modifierDevice; - if ((device == grab->modifierDevice) && - ((xE->u.u.type == KeyPress) -#if defined(XINPUT) && defined(XKB) - || (xE->u.u.type == DeviceKeyPress) -#endif - )) - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension?gdev->key->prev_state:xkbi->state.grab_mods); -#else - grab->modifierDevice->key->prev_state; -#endif - else - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension ? gdev->key->state : xkbi->state.grab_mods); -#else - grab->modifierDevice->key->state; -#endif - if (GrabMatchesSecond(&tempGrab, grab) && - (!grab->confineTo || - (grab->confineTo->realized && - BorderSizeNotEmpty(grab->confineTo)))) - { -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(wClient(pWin), device, FALSE)) - return FALSE; -#endif -#ifdef XKB - if (!noXkbExtension) { - XE_KBPTR.state &= 0x1f00; - XE_KBPTR.state |= - tempGrab.modifiersDetail.exact&(~0x1f00); - } -#endif - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "CheckPassiveGrabsOnWindow: Activating passive grab on %s.\n", - device == inputInfo.keyboard ? "keyboard" : "pointer"); - } - #endif - (*device->ActivateGrab)(device, grab, currentTime, TRUE); - - FixUpEventFromWindow(xE, grab->window, None, TRUE); - - (void) TryClientEvents(rClient(grab), xE, count, - filters[xE->u.u.type], - filters[xE->u.u.type], grab); - - if (device->sync.state == FROZEN_NO_EVENT) - { - if (device->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - device->sync.event = (xEvent *)xrealloc(device->sync.event, - count* - sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - device->sync.evcount = count; - for (dxE = device->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - device->sync.state = FROZEN_WITH_EVENT; - } - return TRUE; - } - } - return FALSE; -} - -/** -"CheckDeviceGrabs" handles both keyboard and pointer events that may cause -a passive grab to be activated. If the event is a keyboard event, the -ancestors of the focus window are traced down and tried to see if they have -any passive grabs to be activated. If the focus window itself is reached and -it's descendants contain they pointer, the ancestors of the window that the -pointer is in are then traced down starting at the focus window, otherwise no -grabs are activated. If the event is a pointer event, the ancestors of the -window that the pointer is in are traced down starting at the root until -CheckPassiveGrabs causes a passive grab to activate or all the windows are -tried. PRH -*/ - -Bool -CheckDeviceGrabs(register DeviceIntPtr device, register xEvent *xE, - int checkFirst, int count) -{ - register int i; - register WindowPtr pWin = NULL; - register FocusClassPtr focus = device->focus; - - if (((xE->u.u.type == ButtonPress) -#if defined(XINPUT) && defined(XKB) - || (xE->u.u.type == DeviceButtonPress) -#endif - ) && (device->button->buttonsDown != 1)) - return FALSE; - - i = checkFirst; - - if (focus) - { - for (; i < focus->traceGood; i++) - { - pWin = focus->trace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - if ((focus->win == NoneWin) || - (i >= spriteTraceGood) || - ((i > checkFirst) && (pWin != spriteTrace[i-1]))) - return FALSE; - } - - for (; i < spriteTraceGood; i++) - { - pWin = spriteTrace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - return FALSE; -} - -void -DeliverFocusedEvent(DeviceIntPtr keybd, xEvent *xE, WindowPtr window, int count) -{ - WindowPtr focus = keybd->focus->win; - int mskidx = 0; - - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - if (!focus) - return; - if (focus == PointerRootWin) - { - DeliverDeviceEvents(window, xE, NullGrab, NullWindow, keybd, count); - return; - } - if ((focus == window) || IsParent(focus, window)) - { - if (DeliverDeviceEvents(window, xE, NullGrab, focus, keybd, count)) - return; - } - /* just deliver it to the focus window */ - FixUpEventFromWindow(xE, focus, None, FALSE); - if (xE->u.u.type & EXTENSION_EVENT_BASE) - mskidx = keybd->id; - (void)DeliverEventsToWindow(focus, xE, count, filters[xE->u.u.type], - NullGrab, mskidx); -} - -void -DeliverGrabbedEvent(register xEvent *xE, register DeviceIntPtr thisDev, - Bool deactivateGrab, int count) -{ - register GrabPtr grab = thisDev->grab; - int deliveries = 0; - register DeviceIntPtr dev; - register xEvent *dxE; - - if (grab->ownerEvents) - { - WindowPtr focus; - - if (thisDev->focus) - { - focus = thisDev->focus->win; - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - } - else - focus = PointerRootWin; - if (focus == PointerRootWin) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, NullWindow, - thisDev, count); - else if (focus && (focus == sprite.win || IsParent(focus, sprite.win))) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, focus, - thisDev, count); - else if (focus) - deliveries = DeliverDeviceEvents(focus, xE, grab, focus, - thisDev, count); - } - if (!deliveries) - { - FixUpEventFromWindow(xE, grab->window, None, TRUE); - deliveries = TryClientEvents(rClient(grab), xE, count, - (Mask)grab->eventMask, - filters[xE->u.u.type], grab); - if (deliveries && (xE->u.u.type == MotionNotify -#ifdef XINPUT - || xE->u.u.type == DeviceMotionNotify -#endif - )) - thisDev->valuator->motionHintWindow = grab->window; - } - if (deliveries && !deactivateGrab && (xE->u.u.type != MotionNotify -#ifdef XINPUT - && xE->u.u.type != DeviceMotionNotify -#endif - )) - switch (thisDev->sync.state) - { - case FREEZE_BOTH_NEXT_EVENT: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - FreezeThaw(dev, TRUE); - if ((dev->sync.state == FREEZE_BOTH_NEXT_EVENT) && - (CLIENT_BITS(dev->grab->resource) == - CLIENT_BITS(thisDev->grab->resource))) - dev->sync.state = FROZEN_NO_EVENT; - else - dev->sync.other = thisDev->grab; - } - /* fall through */ - case FREEZE_NEXT_EVENT: - thisDev->sync.state = FROZEN_WITH_EVENT; - FreezeThaw(thisDev, TRUE); - if (thisDev->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - thisDev->sync.event = (xEvent *)xrealloc(thisDev->sync.event, - count*sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - thisDev->sync.evcount = count; - for (dxE = thisDev->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - break; - } -} - -void -#ifdef XKB -CoreProcessKeyboardEvent (register xEvent *xE, register DeviceIntPtr keybd, int count) -#else -ProcessKeyboardEvent (register xEvent *xE, register DeviceIntPtr keybd, int count) -#endif -{ - int key, bit; - register BYTE *kptr; - register int i; - register CARD8 modifiers; - register CARD16 mask; - GrabPtr grab = keybd->grab; - Bool deactivateGrab = FALSE; - register KeyClassPtr keyc = keybd->key; -#ifdef XEVIE - static Window rootWin = 0; - - if(!xeviegrabState && xevieFlag && clients[xevieClientIndex] && - (xevieMask & xevieFilters[xE->u.u.type])) { - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - if((xE->u.u.type == KeyPress && (*kptr & bit)) || - (xE->u.u.type == KeyRelease && !(*kptr & bit))) - {} else { -#ifdef XKB - if(!noXkbExtension) - xevieKBEventSent = 1; -#endif - if(!xevieKBEventSent) - { - xeviekb = keybd; - if(!rootWin) { - rootWin = GetCurrentRootWindow()->drawable.id; - } - xE->u.keyButtonPointer.event = xeviewin->drawable.id; - xE->u.keyButtonPointer.root = rootWin; - xE->u.keyButtonPointer.child = (xeviewin->firstChild) ? xeviewin->firstChild-> -drawable.id:0; - xE->u.keyButtonPointer.rootX = xeviehot.x; - xE->u.keyButtonPointer.rootY = xeviehot.y; - xE->u.keyButtonPointer.state = keyc->state; - WriteToClient(clients[xevieClientIndex], sizeof(xEvent), (char *)xE); -#ifdef XKB - if(noXkbExtension) -#endif - return; - } else { - xevieKBEventSent = 0; - } - } - } -#endif - - if (!syncEvents.playingEvents) - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } -#ifdef XEVIE - /* fix for bug5094030: don't change the state bit if the event is from XEvIE client */ - if(!(!xeviegrabState && xevieFlag && clients[xevieClientIndex] && - (xevieMask & xevieFilters[xE->u.u.type] -#ifdef XKB - && !noXkbExtension -#endif - ))) -#endif - XE_KBPTR.state = (keyc->state | inputInfo.pointer->button->state); - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - modifiers = keyc->modifierMap[key]; -#if defined(XKB) && defined(XEVIE) - if(!noXkbExtension && !xeviegrabState && - xevieFlag && clients[xevieClientIndex] && - (xevieMask & xevieFilters[xE->u.u.type])) { - switch(xE->u.u.type) { - case KeyPress: *kptr &= ~bit; break; - case KeyRelease: *kptr |= bit; break; - } - } -#endif - -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("CoreProcessKbdEvent: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - if (*kptr & bit) /* allow ddx to generate multiple downs */ - { - if (!modifiers) - { - xE->u.u.type = KeyRelease; - (*keybd->public.processInputProc)(xE, keybd, count); - xE->u.u.type = KeyPress; - /* release can have side effects, don't fall through */ - (*keybd->public.processInputProc)(xE, keybd, count); - } - return; - } - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr |= bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) - { - /* This key affects modifier "i" */ - keyc->modifierKeyCount[i]++; - keyc->state |= mask; - modifiers &= ~mask; - } - } - if (!grab && CheckDeviceGrabs(keybd, xE, 0, count)) - { - keybd->activatingKey = key; - return; - } - break; - case KeyRelease: - if (!(*kptr & bit)) /* guard against duplicates */ - return; - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr &= ~bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) { - /* This key affects modifier "i" */ - if (--keyc->modifierKeyCount[i] <= 0) { - keyc->state &= ~mask; - keyc->modifierKeyCount[i] = 0; - } - modifiers &= ~mask; - } - } - if (keybd->fromPassiveGrab && (key == keybd->activatingKey)) - deactivateGrab = TRUE; - break; - default: - FatalError("Impossible keyboard event"); - } - if (grab) - DeliverGrabbedEvent(xE, keybd, deactivateGrab, count); - else - DeliverFocusedEvent(keybd, xE, sprite.win, count); - if (deactivateGrab) - #ifdef NX_DEBUG_INPUT - { - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcessKeyboardEvent: Deactivating grab on keyboard.\n"); - } - #endif - (*keybd->DeactivateGrab)(keybd); - #ifdef NX_DEBUG_INPUT - } - #endif -} - -#ifdef XKB -/* This function is used to set the key pressed or key released state - - this is only used when the pressing of keys does not cause - CoreProcessKeyEvent to be called, as in for example Mouse Keys. -*/ -void -FixKeyState (register xEvent *xE, register DeviceIntPtr keybd) -{ - int key, bit; - register BYTE *kptr; - register KeyClassPtr keyc = keybd->key; - - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("FixKeyState: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - *kptr |= bit; - break; - case KeyRelease: - *kptr &= ~bit; - break; - default: - FatalError("Impossible keyboard event"); - } -} -#endif - -void -#ifdef XKB -CoreProcessPointerEvent (register xEvent *xE, register DeviceIntPtr mouse, int count) -#else -ProcessPointerEvent (register xEvent *xE, register DeviceIntPtr mouse, int count) -#endif -{ - register GrabPtr grab = mouse->grab; - Bool deactivateGrab = FALSE; - register ButtonClassPtr butc = mouse->button; -#ifdef XKB - XkbSrvInfoPtr xkbi; - - xkbi = inputInfo.keyboard->key->xkbInfo; -#endif -#ifdef XEVIE - if(xevieFlag && clients[xevieClientIndex] && !xeviegrabState && - (xevieMask & xevieFilters[xE->u.u.type])) { - if(xevieEventSent) - xevieEventSent = 0; - else { - xeviemouse = mouse; - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: Going to send XEVIE event.\n"); - } - #endif - WriteToClient(clients[xevieClientIndex], sizeof(xEvent), (char *)xE); - return; - } - } -#endif - - if (!syncEvents.playingEvents) - NoticeTime(xE) - XE_KBPTR.state = (butc->state | ( -#ifdef XKB - (noXkbExtension ? - inputInfo.keyboard->key->state : - xkbi->state.grab_mods) -#else - inputInfo.keyboard->key->state -#endif - )); - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* see comment in EnqueueEvents regarding the next three lines */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } - if (xE->u.u.type != MotionNotify) - { - register int key; - register BYTE *kptr; - int bit; - - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - - key = xE->u.u.detail; - kptr = &butc->down[key >> 3]; - bit = 1 << (key & 7); - switch (xE->u.u.type) - { - case ButtonPress: - mouse->valuator->motionHintWindow = NullWindow; - if (!(*kptr & bit)) - butc->buttonsDown++; - butc->motionMask = ButtonMotionMask; - *kptr |= bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - #ifdef NX_DEBUG_INPUT - if (xE->u.u.detail == 0) - { - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: WARNING! detail == 0" - " for ButtonPress.\n"); - } - return; - } - #else - if (xE->u.u.detail == 0) - return; - #endif - if (xE->u.u.detail <= 5) - butc->state |= (Button1Mask >> 1) << xE->u.u.detail; - filters[MotionNotify] = Motion_Filter(butc); - if (!grab) - #ifdef NX_DEBUG_INPUT - if (CheckDeviceGrabs(mouse, xE, 0, count)) - { - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: CheckDeviceGrabs" - " returned True for ButtonPress.\n"); - } - return; - } - #else - if (CheckDeviceGrabs(mouse, xE, 0, count)) - return; - #endif - break; - case ButtonRelease: - mouse->valuator->motionHintWindow = NullWindow; - if (*kptr & bit) - --butc->buttonsDown; - if (!butc->buttonsDown) - butc->motionMask = 0; - *kptr &= ~bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - #ifdef NX_DEBUG_INPUT - if (xE->u.u.detail == 0) - { - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: WARNING! detail == 0" - " for ButtonRelease.\n"); - } - return; - } - #else - if (xE->u.u.detail == 0) - return; - #endif - if (xE->u.u.detail <= 5) - butc->state &= ~((Button1Mask >> 1) << xE->u.u.detail); - filters[MotionNotify] = Motion_Filter(butc); - if (!butc->state && mouse->fromPassiveGrab) - deactivateGrab = TRUE; - break; - default: - FatalError("bogus pointer event from ddx"); - } - } - #ifdef NX_DEBUG_INPUT - else if (!CheckMotion(xE)) - { - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: CheckMotion returned False" - " for MotionNotify.\n"); - } - return; - } - if (grab) - { - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: Going to deliver grabbed " - "events (count = %d).\n", count); - } - DeliverGrabbedEvent(xE, mouse, deactivateGrab, count); - } - else - { - if (nxagentDebugInput == 1) - { - fprintf(stderr, "ProcessPointerEvent: Going to deliver device " - "events (count = %d).\n", count); - } - DeliverDeviceEvents(sprite.win, xE, NullGrab, NullWindow, - mouse, count); - } - #else - else if (!CheckMotion(xE)) - return; - if (grab) - DeliverGrabbedEvent(xE, mouse, deactivateGrab, count); - else - DeliverDeviceEvents(sprite.win, xE, NullGrab, NullWindow, - mouse, count); - #endif - if (deactivateGrab) - #ifdef NX_DEBUG_INPUT - { - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcessPointerEvent: Deactivating grab on pointer.\n"); - } - #endif - (*mouse->DeactivateGrab)(mouse); - #ifdef NX_DEBUG_INPUT - } - #endif -} - -#define AtMostOneClient \ - (SubstructureRedirectMask | ResizeRedirectMask | ButtonPressMask) - -void -RecalculateDeliverableEvents(pWin) - register WindowPtr pWin; -{ - register OtherClients *others; - register WindowPtr pChild; - - pChild = pWin; - while (1) - { - if (pChild->optional) - { - pChild->optional->otherEventMasks = 0; - for (others = wOtherClients(pChild); others; others = others->next) - { - pChild->optional->otherEventMasks |= others->mask; - } - } - pChild->deliverableEvents = pChild->eventMask| - wOtherEventMasks(pChild); - if (pChild->parent) - pChild->deliverableEvents |= - (pChild->parent->deliverableEvents & - ~wDontPropagateMask(pChild) & PropagateMask); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -/** - * - * \param value must conform to DeleteType - */ -int -OtherClientGone(pointer value, XID id) -{ - register OtherClientsPtr other, prev; - register WindowPtr pWin = (WindowPtr)value; - - prev = 0; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->resource == id) - { - if (prev) - prev->next = other->next; - else - { - if (!(pWin->optional->otherClients = other->next)) - CheckWindowOptionalNeed (pWin); - } - xfree(other); - RecalculateDeliverableEvents(pWin); - return(Success); - } - prev = other; - } - FatalError("client not on event list"); - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} - -int -EventSelectForWindow(register WindowPtr pWin, register ClientPtr client, Mask mask) -{ - Mask check; - OtherClients * others; - - if (mask & ~AllEventMasks) - { - client->errorValue = mask; - return BadValue; - } - check = (mask & AtMostOneClient); - if (check & (pWin->eventMask|wOtherEventMasks(pWin))) - { /* It is illegal for two different - clients to select on any of the - events for AtMostOneClient. However, - it is OK, for some client to - continue selecting on one of those - events. */ - if ((wClient(pWin) != client) && (check & pWin->eventMask)) - return BadAccess; - for (others = wOtherClients (pWin); others; others = others->next) - { - if (!SameClient(others, client) && (check & others->mask)) - return BadAccess; - } - } - if (wClient (pWin) == client) - { - check = pWin->eventMask; -#ifdef SGIMISC - pWin->eventMask = - (mask & ~SGIMiscSpecialDestroyMask) | (pWin->eventMask & SGIMiscSpecialDestroyMask); -#else - pWin->eventMask = mask; -#endif - } - else - { - for (others = wOtherClients (pWin); others; others = others->next) - { - if (SameClient(others, client)) - { - check = others->mask; -#ifdef SGIMISC - mask = (mask & ~SGIMiscSpecialDestroyMask) | (others->mask & SGIMiscSpecialDestroyMask); -#endif - if (mask == 0) - { - FreeResource(others->resource, RT_NONE); - return Success; - } - else - others->mask = mask; - goto maskSet; - } - } - check = 0; - if (!pWin->optional && !MakeWindowOptional (pWin)) - return BadAlloc; - others = (OtherClients *) xalloc(sizeof(OtherClients)); - if (!others) - return BadAlloc; - others->mask = mask; - others->resource = FakeClientID(client->index); - others->next = pWin->optional->otherClients; - pWin->optional->otherClients = others; - if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer)pWin)) - return BadAlloc; - } -maskSet: - if ((inputInfo.pointer->valuator->motionHintWindow == pWin) && - (mask & PointerMotionHintMask) && - !(check & PointerMotionHintMask) && - !inputInfo.pointer->grab) - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - RecalculateDeliverableEvents(pWin); - return Success; -} - -int -EventSuppressForWindow(register WindowPtr pWin, register ClientPtr client, - Mask mask, Bool *checkOptional) -{ - register int i, free; - - if ((mask & ~PropagateMask) && !permitOldBugs) - { - client->errorValue = mask; - return BadValue; - } - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - if (!mask) - i = 0; - else - { - for (i = DNPMCOUNT, free = 0; --i > 0; ) - { - if (!DontPropagateRefCnts[i]) - free = i; - else if (mask == DontPropagateMasks[i]) - break; - } - if (!i && free) - { - i = free; - DontPropagateMasks[i] = mask; - } - } - if (i || !mask) - { - pWin->dontPropagate = i; - if (i) - DontPropagateRefCnts[i]++; - if (pWin->optional) - { - pWin->optional->dontPropagateMask = mask; - *checkOptional = TRUE; - } - } - else - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]++; - return BadAlloc; - } - pWin->dontPropagate = 0; - pWin->optional->dontPropagateMask = mask; - } - RecalculateDeliverableEvents(pWin); - return Success; -} - -static WindowPtr -CommonAncestor( - register WindowPtr a, - register WindowPtr b) -{ - for (b = b->parent; b; b = b->parent) - if (IsParent(b, a)) return b; - return NullWindow; -} - -static void -EnterLeaveEvent( - int type, - int mode, - int detail, - register WindowPtr pWin, - Window child) -{ - xEvent event; - register DeviceIntPtr keybd = inputInfo.keyboard; - WindowPtr focus; - register DeviceIntPtr mouse = inputInfo.pointer; - register GrabPtr grab = mouse->grab; - Mask mask; - - if ((pWin == mouse->valuator->motionHintWindow) && - (detail != NotifyInferior)) - mouse->valuator->motionHintWindow = NullWindow; - if (grab) - { - mask = (pWin == grab->window) ? grab->eventMask : 0; - if (grab->ownerEvents) - mask |= EventMaskForClient(pWin, rClient(grab)); - } - else - { - mask = pWin->eventMask | wOtherEventMasks(pWin); - } - if (mask & filters[type]) - { - event.u.u.type = type; - event.u.u.detail = detail; - event.u.enterLeave.time = currentTime.milliseconds; - event.u.enterLeave.rootX = sprite.hot.x; - event.u.enterLeave.rootY = sprite.hot.y; - /* Counts on the same initial structure of crossing & button events! */ - FixUpEventFromWindow(&event, pWin, None, FALSE); - /* Enter/Leave events always set child */ - event.u.enterLeave.child = child; - event.u.enterLeave.flags = event.u.keyButtonPointer.sameScreen ? - ELFlagSameScreen : 0; -#ifdef XKB - if (!noXkbExtension) { - event.u.enterLeave.state = mouse->button->state & 0x1f00; - event.u.enterLeave.state |= - XkbGrabStateFromRec(&keybd->key->xkbInfo->state); - } else -#endif - event.u.enterLeave.state = keybd->key->state | mouse->button->state; - event.u.enterLeave.mode = mode; - focus = keybd->focus->win; - if ((focus != NoneWin) && - ((pWin == focus) || (focus == PointerRootWin) || - IsParent(focus, pWin))) - event.u.enterLeave.flags |= ELFlagFocus; - if (grab) - (void)TryClientEvents(rClient(grab), &event, 1, mask, - filters[type], grab); - else - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], - NullGrab, 0); - } - if ((type == EnterNotify) && (mask & KeymapStateMask)) - { - xKeymapEvent ke; - -#ifdef XCSECURITY - ClientPtr client = grab ? rClient(grab) - : clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, keybd, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31); - ke.type = KeymapNotify; - if (grab) - (void)TryClientEvents(rClient(grab), (xEvent *)&ke, 1, mask, - KeymapStateMask, grab); - else - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - -static void -EnterNotifies(WindowPtr ancestor, WindowPtr child, int mode, int detail) -{ - WindowPtr parent = child->parent; - - if (ancestor == parent) - return; - EnterNotifies(ancestor, parent, mode, detail); - EnterLeaveEvent(EnterNotify, mode, detail, parent, child->drawable.id); -} - -static void -LeaveNotifies(WindowPtr child, WindowPtr ancestor, int mode, int detail) -{ - register WindowPtr pWin; - - if (ancestor == child) - return; - for (pWin = child->parent; pWin != ancestor; pWin = pWin->parent) - { - EnterLeaveEvent(LeaveNotify, mode, detail, pWin, child->drawable.id); - child = pWin; - } -} - -static void -DoEnterLeaveEvents(WindowPtr fromWin, WindowPtr toWin, int mode) -{ - if (fromWin == toWin) - return; - if (IsParent(fromWin, toWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyInferior, fromWin, None); - EnterNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyAncestor, toWin, None); - } - else if (IsParent(toWin, fromWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyAncestor, fromWin, None); - LeaveNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyInferior, toWin, None); - } - else - { /* neither fromWin nor toWin is descendent of the other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - EnterLeaveEvent(LeaveNotify, mode, NotifyNonlinear, fromWin, None); - LeaveNotifies(fromWin, common, mode, NotifyNonlinearVirtual); - EnterNotifies(common, toWin, mode, NotifyNonlinearVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyNonlinear, toWin, None); - } -} - -static void -FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, register WindowPtr pWin) -{ - xEvent event; - -#ifdef XINPUT - if (dev != inputInfo.keyboard) - { - DeviceFocusEvent(dev, type, mode, detail, pWin); - return; - } -#endif - event.u.focus.mode = mode; - event.u.u.type = type; - event.u.u.detail = detail; - event.u.focus.window = pWin->drawable.id; - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], NullGrab, - 0); - if ((type == FocusIn) && - ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) - { - xKeymapEvent ke; -#ifdef XCSECURITY - ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, dev, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31); - ke.type = KeymapNotify; - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - - /* - * recursive because it is easier - * no-op if child not descended from ancestor - */ -static Bool -FocusInEvents( - DeviceIntPtr dev, - WindowPtr ancestor, WindowPtr child, WindowPtr skipChild, - int mode, int detail, - Bool doAncestor) -{ - if (child == NullWindow) - return ancestor == NullWindow; - if (ancestor == child) - { - if (doAncestor) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - if (FocusInEvents(dev, ancestor, child->parent, skipChild, mode, detail, - doAncestor)) - { - if (child != skipChild) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - return FALSE; -} - -/* dies horribly if ancestor is not an ancestor of child */ -static void -FocusOutEvents( - DeviceIntPtr dev, - WindowPtr child, WindowPtr ancestor, - int mode, int detail, - Bool doAncestor) -{ - register WindowPtr pWin; - - for (pWin = child; pWin != ancestor; pWin = pWin->parent) - FocusEvent(dev, FocusOut, mode, detail, pWin); - if (doAncestor) - FocusEvent(dev, FocusOut, mode, detail, ancestor); -} - -void -DoFocusEvents(DeviceIntPtr dev, WindowPtr fromWin, WindowPtr toWin, int mode) -{ - int out, in; /* for holding details for to/from - PointerRoot/None */ - int i; - - if (fromWin == toWin) - return; - out = (fromWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - in = (toWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - /* wrong values if neither, but then not referenced */ - - if ((toWin == NullWindow) || (toWin == PointerRootWin)) - { - if ((fromWin == NullWindow) || (fromWin == PointerRootWin)) - { - if (fromWin == PointerRootWin) - FocusOutEvents(dev, sprite.win, ROOT, mode, NotifyPointer, - TRUE); - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusOut, mode, out, WindowTable[0]); - else -#endif - for (i=0; iparent, NullWindow, mode, - NotifyNonlinearVirtual, FALSE); - } - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusIn, mode, in, WindowTable[0]); - else -#endif - for (i=0; iparent != NullWindow) - (void)FocusInEvents(dev, ROOT, toWin, toWin, mode, - NotifyNonlinearVirtual, TRUE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, mode, - NotifyPointer, FALSE); - } - else - { - if (IsParent(toWin, fromWin)) - { - FocusEvent(dev, FocusOut, mode, NotifyAncestor, fromWin); - FocusOutEvents(dev, fromWin->parent, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyInferior, toWin); - if ((IsParent(toWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(fromWin, sprite.win)) && - (!IsParent(sprite.win, fromWin))) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - else - if (IsParent(fromWin, toWin)) - { - if ((IsParent(fromWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(toWin, sprite.win)) && - (!IsParent(sprite.win, toWin))) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyInferior, fromWin); - (void)FocusInEvents(dev, fromWin, toWin, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyAncestor, toWin); - } - else - { - /* neither fromWin or toWin is child of other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - if (IsParent(fromWin, sprite.win)) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyNonlinear, fromWin); - if (fromWin->parent != NullWindow) - FocusOutEvents(dev, fromWin->parent, common, mode, - NotifyNonlinearVirtual, FALSE); - if (toWin->parent != NullWindow) - (void)FocusInEvents(dev, common, toWin, toWin, mode, - NotifyNonlinearVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - } - } -} - -int -SetInputFocus( - ClientPtr client, - DeviceIntPtr dev, - Window focusID, - CARD8 revertTo, - Time ctime, - Bool followOK) -{ - register FocusClassPtr focus; - register WindowPtr focusWin; - int mode; - TimeStamp time; - - UpdateCurrentTime(); - if ((revertTo != RevertToParent) && - (revertTo != RevertToPointerRoot) && - (revertTo != RevertToNone) && - ((revertTo != RevertToFollowKeyboard) || !followOK)) - { - client->errorValue = revertTo; - return BadValue; - } - time = ClientTimeToServerTime(ctime); - if ((focusID == None) || (focusID == PointerRoot)) - focusWin = (WindowPtr)(long)focusID; - else if ((focusID == FollowKeyboard) && followOK) - focusWin = inputInfo.keyboard->focus->win; - else if (!(focusWin = SecurityLookupWindow(focusID, client, - SecurityReadAccess))) - return BadWindow; - else - { - /* It is a match error to try to set the input focus to an - unviewable window. */ - - if(!focusWin->realized) - return(BadMatch); - } - focus = dev->focus; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, focus->time) == EARLIER)) - return Success; - mode = (dev->grab) ? NotifyWhileGrabbed : NotifyNormal; - if (focus->win == FollowKeyboardWin) - DoFocusEvents(dev, inputInfo.keyboard->focus->win, focusWin, mode); - else - DoFocusEvents(dev, focus->win, focusWin, mode); - focus->time = time; - focus->revert = revertTo; - if (focusID == FollowKeyboard) - focus->win = FollowKeyboardWin; - else - focus->win = focusWin; - if ((focusWin == NoneWin) || (focusWin == PointerRootWin)) - focus->traceGood = 0; - else - { - int depth = 0; - register WindowPtr pWin; - - for (pWin = focusWin; pWin; pWin = pWin->parent) depth++; - if (depth > focus->traceSize) - { - focus->traceSize = depth+1; - Must_have_memory = TRUE; /* XXX */ - focus->trace = (WindowPtr *)xrealloc(focus->trace, - focus->traceSize * - sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - focus->traceGood = depth; - for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) - focus->trace[depth] = pWin; - } - return Success; -} - -int -ProcSetInputFocus(client) - ClientPtr client; -{ - REQUEST(xSetInputFocusReq); - - REQUEST_SIZE_MATCH(xSetInputFocusReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - return Success; -#endif - return SetInputFocus(client, inputInfo.keyboard, stuff->focus, - stuff->revertTo, stuff->time, FALSE); -} - -int -ProcGetInputFocus(ClientPtr client) -{ - xGetInputFocusReply rep; - /* REQUEST(xReq); */ - FocusClassPtr focus = inputInfo.keyboard->focus; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (focus->win == NoneWin) - rep.focus = None; - else if (focus->win == PointerRootWin) - rep.focus = PointerRoot; - else rep.focus = focus->win->drawable.id; - rep.revertTo = focus->revert; - WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep); - return Success; -} - -int -ProcGrabPointer(ClientPtr client) -{ - xGrabPointerReply rep; - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - WindowPtr pWin, confineTo; - CursorPtr cursor, oldCursor; - REQUEST(xGrabPointerReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xGrabPointerReq); - UpdateCurrentTime(); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcGrabPointer: pWin [%p] client [%d].\n", pWin, client -> index); - } - #endif - if (stuff->confineTo == None) - confineTo = NullWindow; - else - { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - /* at this point, some sort of reply is guaranteed. */ - time = ClientTimeToServerTime(stuff->time); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - grab = device->grab; - if ((grab) && !SameClient(grab, client)) - rep.status = AlreadyGrabbed; - else if ((!pWin->realized) || - (confineTo && - !(confineTo->realized && BorderSizeNotEmpty(confineTo)))) - rep.status = GrabNotViewable; - else if (device->sync.frozen && - device->sync.other && !SameClient(device->sync.other, client)) - rep.status = GrabFrozen; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - rep.status = GrabInvalidTime; - else - { - GrabRec tempGrab; - - oldCursor = NullCursor; - if (grab) - { - if (grab->confineTo && !confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - oldCursor = grab->cursor; - } - tempGrab.cursor = cursor; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = stuff->ownerEvents; - tempGrab.eventMask = stuff->eventMask; - tempGrab.confineTo = confineTo; - tempGrab.window = pWin; - tempGrab.keyboardMode = stuff->keyboardMode; - tempGrab.pointerMode = stuff->pointerMode; - tempGrab.device = device; - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcGrabPointer: Activating active grab on pointer.\n"); - } - #endif - (*device->ActivateGrab)(device, &tempGrab, time, FALSE); - if (oldCursor) - FreeCursor (oldCursor, (Cursor)0); - rep.status = GrabSuccess; - } - WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep); - return Success; -} - -int -ProcChangeActivePointerGrab(ClientPtr client) -{ - DeviceIntPtr device = inputInfo.pointer; - register GrabPtr grab = device->grab; - CursorPtr newCursor, oldCursor; - REQUEST(xChangeActivePointerGrabReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq); - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - if (stuff->cursor == None) - newCursor = NullCursor; - else - { - newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!newCursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - if (!grab) - return Success; - if (!SameClient(grab, client)) - return Success; - time = ClientTimeToServerTime(stuff->time); - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - return Success; - oldCursor = grab->cursor; - grab->cursor = newCursor; - if (newCursor) - newCursor->refcnt++; - PostNewCursor(); - if (oldCursor) - FreeCursor(oldCursor, (Cursor)0); - grab->eventMask = stuff->eventMask; - return Success; -} - -int -ProcUngrabPointer(ClientPtr client) -{ - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcUngrabPointer: client [%d].\n", client -> index); - } - #endif - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - #ifdef NX_DEBUG_INPUT - { - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcUngrabPointer: Deactivating grab on pointer.\n"); - } - #endif - (*device->DeactivateGrab)(device); - #ifdef NX_DEBUG_INPUT - } - else - { - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcUngrabPointer: current time [%lu] request time [%lu] grab time [%lu].\n", - currentTime.milliseconds, time.milliseconds, device->grabTime.milliseconds); - } - } - #endif - return Success; -} - -int -GrabDevice(register ClientPtr client, register DeviceIntPtr dev, - unsigned this_mode, unsigned other_mode, Window grabWindow, - unsigned ownerEvents, Time ctime, Mask mask, CARD8 *status) -{ - register WindowPtr pWin; - register GrabPtr grab; - TimeStamp time; - - UpdateCurrentTime(); - if ((this_mode != GrabModeSync) && (this_mode != GrabModeAsync)) - { - client->errorValue = this_mode; - return BadValue; - } - if ((other_mode != GrabModeSync) && (other_mode != GrabModeAsync)) - { - client->errorValue = other_mode; - return BadValue; - } - if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) - { - client->errorValue = ownerEvents; - return BadValue; - } - pWin = SecurityLookupWindow(grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - time = ClientTimeToServerTime(ctime); - grab = dev->grab; - if (grab && !SameClient(grab, client)) - *status = AlreadyGrabbed; - else if (!pWin->realized) - *status = GrabNotViewable; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, dev->grabTime) == EARLIER)) - *status = GrabInvalidTime; - else if (dev->sync.frozen && - dev->sync.other && !SameClient(dev->sync.other, client)) - *status = GrabFrozen; - else - { - GrabRec tempGrab; - - tempGrab.window = pWin; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = ownerEvents; - tempGrab.keyboardMode = this_mode; - tempGrab.pointerMode = other_mode; - tempGrab.eventMask = mask; - tempGrab.device = dev; - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "GrabDevice: Activating active grab on keyboard.\n"); - } - #endif - (*dev->ActivateGrab)(dev, &tempGrab, time, FALSE); - *status = GrabSuccess; - } - return Success; -} - -int -ProcGrabKeyboard(ClientPtr client) -{ - xGrabKeyboardReply rep; - REQUEST(xGrabKeyboardReq); - int result; - - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcGrabKeyboard: client [%d].\n", client -> index); - } - #endif - REQUEST_SIZE_MATCH(xGrabKeyboardReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - { - result = Success; - rep.status = AlreadyGrabbed; - } - else -#endif - result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode, - stuff->pointerMode, stuff->grabWindow, - stuff->ownerEvents, stuff->time, - KeyPressMask | KeyReleaseMask, &rep.status); - if (result != Success) - return result; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep); - return Success; -} - -int -ProcUngrabKeyboard(ClientPtr client) -{ - DeviceIntPtr device = inputInfo.keyboard; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - #ifdef NX_DEBUG_INPUT - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcUngrabKeyboard: client [%d].\n", client -> index); - } - #endif - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - #ifdef NX_DEBUG_INPUT - { - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcUngrabKeyboard: Deactivating grab on keyboard.\n"); - } - #endif - (*device->DeactivateGrab)(device); - #ifdef NX_DEBUG_INPUT - } - else - { - if (nxagentDebugInputDevices == 1) - { - fprintf(stderr, "ProcUngrabKeyboard: current time [%lu] request time [%lu] grab time [%lu].\n", - currentTime.milliseconds, time.milliseconds, device->grabTime.milliseconds); - } - } - #endif - return Success; -} - -int -ProcQueryPointer(ClientPtr client) -{ - xQueryPointerReply rep; - WindowPtr pWin, t; - REQUEST(xResourceReq); - DeviceIntPtr mouse = inputInfo.pointer; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = SecurityLookupWindow(stuff->id, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (mouse->valuator->motionHintWindow) - MaybeStopHint(mouse, client); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.mask = mouse->button->state | inputInfo.keyboard->key->state; - rep.length = 0; - rep.root = (ROOT)->drawable.id; - rep.rootX = sprite.hot.x; - rep.rootY = sprite.hot.y; - rep.child = None; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - rep.sameScreen = xTrue; - rep.winX = sprite.hot.x - pWin->drawable.x; - rep.winY = sprite.hot.y - pWin->drawable.y; - for (t = sprite.win; t; t = t->parent) - if (t->parent == pWin) - { - rep.child = t->drawable.id; - break; - } - } - else - { - rep.sameScreen = xFalse; - rep.winX = 0; - rep.winY = 0; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - rep.rootX += panoramiXdataPtr[0].x; - rep.rootY += panoramiXdataPtr[0].y; - if(stuff->id == rep.root) { - rep.winX += panoramiXdataPtr[0].x; - rep.winY += panoramiXdataPtr[0].y; - } - } -#endif - - WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep); - - return(Success); -} - -void -InitEvents() -{ - int i; - - sprite.hot.pScreen = sprite.hotPhys.pScreen = (ScreenPtr)NULL; - inputInfo.numDevices = 0; - inputInfo.devices = (DeviceIntPtr)NULL; - inputInfo.off_devices = (DeviceIntPtr)NULL; - inputInfo.keyboard = (DeviceIntPtr)NULL; - inputInfo.pointer = (DeviceIntPtr)NULL; - if (spriteTraceSize == 0) - { - spriteTraceSize = 32; - spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr)); - if (!spriteTrace) - FatalError("failed to allocate spriteTrace"); - } - spriteTraceGood = 0; - lastEventMask = OwnerGrabButtonMask; - filters[MotionNotify] = PointerMotionMask; -#ifdef XEVIE - xeviewin = -#endif - sprite.win = NullWindow; - sprite.current = NullCursor; - sprite.hotLimits.x1 = 0; - sprite.hotLimits.y1 = 0; - sprite.hotLimits.x2 = 0; - sprite.hotLimits.y2 = 0; - sprite.confined = FALSE; - syncEvents.replayDev = (DeviceIntPtr)NULL; - syncEvents.replayWin = NullWindow; - while (syncEvents.pending) - { - QdEventPtr next = syncEvents.pending->next; - xfree(syncEvents.pending); - syncEvents.pending = next; - } - syncEvents.pendtail = &syncEvents.pending; - syncEvents.playingEvents = FALSE; - syncEvents.time.months = 0; - syncEvents.time.milliseconds = 0; /* hardly matters */ - currentTime.months = 0; - currentTime.milliseconds = GetTimeInMillis(); - lastDeviceEventTime = currentTime; - for (i = 0; i < DNPMCOUNT; i++) - { - DontPropagateMasks[i] = 0; - DontPropagateRefCnts[i] = 0; - } -} - -void -CloseDownEvents(void) -{ - xfree(spriteTrace); - spriteTrace = NULL; - spriteTraceSize = 0; -} - -int -ProcSendEvent(ClientPtr client) -{ - WindowPtr pWin; - WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */ - REQUEST(xSendEventReq); - - REQUEST_SIZE_MATCH(xSendEventReq); - - /* The client's event type must be a core event type or one defined by an - extension. */ - - -#ifdef NXAGENT_CLIPBOARD - - if (stuff -> event.u.u.type == SelectionNotify) - { - extern int nxagentSendNotify(xEvent*); - if (nxagentSendNotify(&stuff->event) == 1) - return Success; - } -#endif - - if ( ! ((stuff->event.u.u.type > X_Reply && - stuff->event.u.u.type < LASTEvent) || - (stuff->event.u.u.type >= EXTENSION_EVENT_BASE && - stuff->event.u.u.type < (unsigned)lastEvent))) - { - client->errorValue = stuff->event.u.u.type; - return BadValue; - } - if (stuff->event.u.u.type == ClientMessage && - stuff->event.u.u.detail != 8 && - stuff->event.u.u.detail != 16 && - stuff->event.u.u.detail != 32 && - !permitOldBugs) - { - client->errorValue = stuff->event.u.u.detail; - return BadValue; - } - if ((stuff->eventMask & ~AllEventMasks) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - - if (stuff->destination == PointerWindow) - pWin = sprite.win; - else if (stuff->destination == InputFocus) - { - WindowPtr inputFocus = inputInfo.keyboard->focus->win; - - if (inputFocus == NoneWin) - return Success; - - /* If the input focus is PointerRootWin, send the event to where - the pointer is if possible, then perhaps propogate up to root. */ - if (inputFocus == PointerRootWin) - inputFocus = ROOT; - - if (IsParent(inputFocus, sprite.win)) - { - effectiveFocus = inputFocus; - pWin = sprite.win; - } - else - effectiveFocus = pWin = inputFocus; - } - else - pWin = SecurityLookupWindow(stuff->destination, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue)) - { - client->errorValue = stuff->propagate; - return BadValue; - } - stuff->event.u.u.type |= 0x80; - if (stuff->propagate) - { - for (;pWin; pWin = pWin->parent) - { - if (DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0)) - return Success; - if (pWin == effectiveFocus) - return Success; - stuff->eventMask &= ~wDontPropagateMask(pWin); - if (!stuff->eventMask) - break; - } - } - else - (void)DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0); - return Success; -} - -int -ProcUngrabKey(ClientPtr client) -{ - REQUEST(xUngrabKeyReq); - WindowPtr pWin; - GrabRec tempGrab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xUngrabKeyReq); - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - tempGrab.resource = client->clientAsMask; - tempGrab.device = keybd; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = KeyPress; - tempGrab.detail.exact = stuff->key; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -int -ProcGrabKey(ClientPtr client) -{ - WindowPtr pWin; - REQUEST(xGrabKeyReq); - GrabPtr grab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xGrabKeyReq); - if ((stuff->ownerEvents != xTrue) && (stuff->ownerEvents != xFalse)) - { - client->errorValue = stuff->ownerEvents; - return(BadValue); - } - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - grab = CreateGrab(client->index, keybd, pWin, - (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents, - (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode, - keybd, stuff->modifiers, KeyPress, stuff->key, - NullWindow, NullCursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - - -int -ProcGrabButton(ClientPtr client) -{ - WindowPtr pWin, confineTo; - REQUEST(xGrabButtonReq); - CursorPtr cursor; - GrabPtr grab; - - REQUEST_SIZE_MATCH(xGrabButtonReq); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - - - grab = CreateGrab(client->index, inputInfo.pointer, pWin, - permitOldBugs ? (Mask)(stuff->eventMask | - ButtonPressMask | ButtonReleaseMask) : - (Mask)stuff->eventMask, - (Bool)stuff->ownerEvents, (Bool) stuff->keyboardMode, - (Bool)stuff->pointerMode, inputInfo.keyboard, stuff->modifiers, - ButtonPress, stuff->button, confineTo, cursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - -int -ProcUngrabButton(ClientPtr client) -{ - REQUEST(xUngrabButtonReq); - WindowPtr pWin; - GrabRec tempGrab; - - REQUEST_SIZE_MATCH(xUngrabButtonReq); - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - tempGrab.resource = client->clientAsMask; - tempGrab.device = inputInfo.pointer; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = ButtonPress; - tempGrab.detail.exact = stuff->button; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -void -DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources) -{ - WindowPtr parent; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - FocusClassPtr focus = keybd->focus; - OtherClientsPtr oc; - GrabPtr passive; - - - /* Deactivate any grabs performed on this window, before making any - input focus changes. */ - - if (mouse->grab && - ((mouse->grab->window == pWin) || (mouse->grab->confineTo == pWin))) - (*mouse->DeactivateGrab)(mouse); - - /* Deactivating a keyboard grab should cause focus events. */ - - if (keybd->grab && (keybd->grab->window == pWin)) - (*keybd->DeactivateGrab)(keybd); - - /* If the focus window is a root window (ie. has no parent) then don't - delete the focus from it. */ - - if ((pWin == focus->win) && (pWin->parent != NullWindow)) - { - int focusEventMode = NotifyNormal; - - /* If a grab is in progress, then alter the mode of focus events. */ - - if (keybd->grab) - focusEventMode = NotifyWhileGrabbed; - - switch (focus->revert) - { - case RevertToNone: - DoFocusEvents(keybd, pWin, NoneWin, focusEventMode); - focus->win = NoneWin; - focus->traceGood = 0; - break; - case RevertToParent: - parent = pWin; - do - { - parent = parent->parent; - focus->traceGood--; - } while (!parent->realized -/* This would be a good protocol change -- windows being reparented - during SaveSet processing would cause the focus to revert to the - nearest enclosing window which will survive the death of the exiting - client, instead of ending up reverting to a dying window and thence - to None - */ -#ifdef NOTDEF - || clients[CLIENT_ID(parent->drawable.id)]->clientGone -#endif - ); - DoFocusEvents(keybd, pWin, parent, focusEventMode); - focus->win = parent; - focus->revert = RevertToNone; - break; - case RevertToPointerRoot: - DoFocusEvents(keybd, pWin, PointerRootWin, focusEventMode); - focus->win = PointerRootWin; - focus->traceGood = 0; - break; - } - } - - if (mouse->valuator->motionHintWindow == pWin) - mouse->valuator->motionHintWindow = NullWindow; - - if (freeResources) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - while ( (oc = wOtherClients(pWin)) ) - FreeResource(oc->resource, RT_NONE); - while ( (passive = wPassiveGrabs(pWin)) ) - FreeResource(passive->resource, RT_NONE); - } -#ifdef XINPUT - DeleteWindowFromAnyExtEvents(pWin, freeResources); -#endif -} - -/** - * Call this whenever some window at or below pWin has changed geometry - */ -void -CheckCursorConfinement(WindowPtr pWin) -{ - GrabPtr grab = inputInfo.pointer->grab; - WindowPtr confineTo; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) return; -#endif - - if (grab && (confineTo = grab->confineTo)) - { - if (!BorderSizeNotEmpty(confineTo)) - (*inputInfo.pointer->DeactivateGrab)(inputInfo.pointer); - else if ((pWin == confineTo) || IsParent(pWin, confineTo)) - ConfineCursorToWindow(confineTo, TRUE, TRUE); - } -} - -Mask -EventMaskForClient(WindowPtr pWin, ClientPtr client) -{ - register OtherClientsPtr other; - - if (wClient (pWin) == client) - return pWin->eventMask; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (SameClient(other, client)) - return other->mask; - } - return 0; -} - -int -ProcRecolorCursor(ClientPtr client) -{ - CursorPtr pCursor; - int nscr; - ScreenPtr pscr; - Bool displayed; - REQUEST(xRecolorCursorReq); - - REQUEST_SIZE_MATCH(xRecolorCursorReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityWriteAccess); - if ( !pCursor) - { - client->errorValue = stuff->cursor; - return (BadCursor); - } - - pCursor->foreRed = stuff->foreRed; - pCursor->foreGreen = stuff->foreGreen; - pCursor->foreBlue = stuff->foreBlue; - - pCursor->backRed = stuff->backRed; - pCursor->backGreen = stuff->backGreen; - pCursor->backBlue = stuff->backBlue; - - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { - pscr = screenInfo.screens[nscr]; -#ifdef PANORAMIX - if(!noPanoramiXExtension) - displayed = (pscr == sprite.screen); - else -#endif - displayed = (pscr == sprite.hotPhys.pScreen); - ( *pscr->RecolorCursor)(pscr, pCursor, - (pCursor == sprite.current) && displayed); - } - return (Success); -} - -void -WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) -{ -#ifdef PANORAMIX - xEvent eventCopy; -#endif - xEvent eventTo, *eventFrom; - int i; - -#ifdef XKB - if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events))) - return; -#endif - -#ifdef PANORAMIX - if(!noPanoramiXExtension && - (panoramiXdataPtr[0].x || panoramiXdataPtr[0].y)) - { - switch(events->u.u.type) { - case MotionNotify: - case ButtonPress: - case ButtonRelease: - case KeyPress: - case KeyRelease: - case EnterNotify: - case LeaveNotify: - /* - When multiple clients want the same event DeliverEventsToWindow - passes the same event structure multiple times so we can't - modify the one passed to us - */ - count = 1; /* should always be 1 */ - memcpy(&eventCopy, events, sizeof(xEvent)); - eventCopy.u.keyButtonPointer.rootX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.rootY += panoramiXdataPtr[0].y; - if(eventCopy.u.keyButtonPointer.event == - eventCopy.u.keyButtonPointer.root) - { - eventCopy.u.keyButtonPointer.eventX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.eventY += panoramiXdataPtr[0].y; - } - events = &eventCopy; - break; - default: break; - } - } -#endif - - if (EventCallback) - { - EventInfoRec eventinfo; - eventinfo.client = pClient; - eventinfo.events = events; - eventinfo.count = count; - CallCallbacks(&EventCallback, (pointer)&eventinfo); - } - if(pClient->swapped) - { - for(i = 0; i < count; i++) - { - eventFrom = &events[i]; - /* Remember to strip off the leading bit of type in case - this event was sent with "SendEvent." */ - (*EventSwapVector[eventFrom->u.u.type & 0177]) - (eventFrom, &eventTo); - (void)WriteToClient(pClient, sizeof(xEvent), (char *)&eventTo); - } - } - else - { - (void)WriteToClient(pClient, count * sizeof(xEvent), (char *) events); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.X.original deleted file mode 100644 index 4373673f9..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXevents.c.X.original +++ /dev/null @@ -1,4670 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/dix/events.c,v 1.17 2005/08/25 22:11:04 anholt Exp $ */ -/* $XFree86: xc/programs/Xserver/dix/events.c,v 3.51 2004/01/12 17:04:52 tsi Exp $ */ -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ - -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/***************************************************************** - -Copyright 2003-2005 Sun Microsystems, Inc. - -All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, and/or sell copies of the Software, and to permit persons -to whom the Software is furnished to do so, provided that the above -copyright notice(s) and this permission notice appear in all copies of -the Software and that both the above copyright notice(s) and this -permission notice appear in supporting documentation. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL -INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING -FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -Except as contained in this notice, the name of a copyright holder -shall not be used in advertising or otherwise to promote the sale, use -or other dealings in this Software without prior written authorization -of the copyright holder. - -******************************************************************/ - -/* $Xorg: events.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "misc.h" -#include "resource.h" -#define NEED_EVENTS -#define NEED_REPLIES -#include -#include "windowstr.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "cursorstr.h" - -#include "dixstruct.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include "globals.h" - -#ifdef XKB -#include -extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); -#endif - -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif - -#ifdef XEVIE -extern WindowPtr *WindowTable; -extern int xevieFlag; -extern int xevieClientIndex; -extern DeviceIntPtr xeviemouse; -extern DeviceIntPtr xeviekb; -extern Mask xevieMask; -extern Mask xevieFilters[128]; -extern int xevieEventSent; -extern int xevieKBEventSent; -int xeviegrabState = 0; -xEvent *xeviexE; -#endif - -#include -#include "exevents.h" -#include "extnsionst.h" - -#include "dixevents.h" -#include "dixgrabs.h" -#include "dispatch.h" - -#define EXTENSION_EVENT_BASE 64 - -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ -#define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask ) -#define AllButtonsMask ( \ - Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) -#define MotionMask ( \ - PointerMotionMask | Button1MotionMask | \ - Button2MotionMask | Button3MotionMask | Button4MotionMask | \ - Button5MotionMask | ButtonMotionMask ) -#define PropagateMask ( \ - KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \ - MotionMask ) -#define PointerGrabMask ( \ - ButtonPressMask | ButtonReleaseMask | \ - EnterWindowMask | LeaveWindowMask | \ - PointerMotionHintMask | KeymapStateMask | \ - MotionMask ) -#define AllModifiersMask ( \ - ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \ - Mod3Mask | Mod4Mask | Mod5Mask ) -#define AllEventMasks (lastEventMask|(lastEventMask-1)) -/* - * The following relies on the fact that the ButtonMotionMasks are equal - * to the corresponding ButtonMasks from the current modifier/button state. - */ -#define Motion_Filter(class) (PointerMotionMask | \ - (class)->state | (class)->motionMask) - - -#define WID(w) ((w) ? ((w)->drawable.id) : 0) - -#define XE_KBPTR (xE->u.keyButtonPointer) - - -#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) - -CallbackListPtr EventCallback; -CallbackListPtr DeviceEventCallback; - -#define DNPMCOUNT 8 - -Mask DontPropagateMasks[DNPMCOUNT]; -static int DontPropagateRefCnts[DNPMCOUNT]; - -#ifdef DEBUG -static debug_events = 0; -#endif -InputInfo inputInfo; - -static struct { - QdEventPtr pending, *pendtail; - DeviceIntPtr replayDev; /* kludgy rock to put flag for */ - WindowPtr replayWin; /* ComputeFreezes */ - Bool playingEvents; - TimeStamp time; -} syncEvents; - -/* - * The window trace information is used to avoid having to compute all the - * windows between the root and the current pointer window each time a button - * or key goes down. The grabs on each of those windows must be checked. - */ -static WindowPtr *spriteTrace = (WindowPtr *)NULL; -#define ROOT spriteTrace[0] -static int spriteTraceSize = 0; -static int spriteTraceGood; - -static struct { - CursorPtr current; - BoxRec hotLimits; /* logical constraints of hot spot */ - Bool confined; /* confined to screen */ -#if defined(SHAPE) || defined(PANORAMIX) - RegionPtr hotShape; /* additional logical shape constraint */ -#endif - BoxRec physLimits; /* physical constraints of hot spot */ - WindowPtr win; /* window of logical position */ - HotSpot hot; /* logical pointer position */ - HotSpot hotPhys; /* physical pointer position */ -#ifdef PANORAMIX - ScreenPtr screen; /* all others are in Screen 0 coordinates */ - RegionRec Reg1; /* Region 1 for confining motion */ - RegionRec Reg2; /* Region 2 for confining virtual motion */ - WindowPtr windows[MAXSCREENS]; - WindowPtr confineWin; /* confine window */ -#endif -} sprite; /* info about the cursor sprite */ - -#ifdef XEVIE -WindowPtr xeviewin; -HotSpot xeviehot; -#endif - -static void DoEnterLeaveEvents( - WindowPtr fromWin, - WindowPtr toWin, - int mode -); - -static WindowPtr XYToWindow( - int x, - int y -); - -extern int lastEvent; - -static Mask lastEventMask; - -#ifdef XINPUT -extern int DeviceMotionNotify; -#endif - -#define CantBeFiltered NoEventMask -static Mask filters[128] = -{ - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ - EnterWindowMask, /* EnterNotify */ - LeaveWindowMask, /* LeaveNotify */ - FocusChangeMask, /* FocusIn */ - FocusChangeMask, /* FocusOut */ - KeymapStateMask, /* KeymapNotify */ - ExposureMask, /* Expose */ - CantBeFiltered, /* GraphicsExpose */ - CantBeFiltered, /* NoExpose */ - VisibilityChangeMask, /* VisibilityNotify */ - SubstructureNotifyMask, /* CreateNotify */ - StructureAndSubMask, /* DestroyNotify */ - StructureAndSubMask, /* UnmapNotify */ - StructureAndSubMask, /* MapNotify */ - SubstructureRedirectMask, /* MapRequest */ - StructureAndSubMask, /* ReparentNotify */ - StructureAndSubMask, /* ConfigureNotify */ - SubstructureRedirectMask, /* ConfigureRequest */ - StructureAndSubMask, /* GravityNotify */ - ResizeRedirectMask, /* ResizeRequest */ - StructureAndSubMask, /* CirculateNotify */ - SubstructureRedirectMask, /* CirculateRequest */ - PropertyChangeMask, /* PropertyNotify */ - CantBeFiltered, /* SelectionClear */ - CantBeFiltered, /* SelectionRequest */ - CantBeFiltered, /* SelectionNotify */ - ColormapChangeMask, /* ColormapNotify */ - CantBeFiltered, /* ClientMessage */ - CantBeFiltered /* MappingNotify */ -}; - -static CARD8 criticalEvents[32] = -{ - 0x7c /* key and button events */ -}; - -#ifdef PANORAMIX - -static void ConfineToShape(RegionPtr shape, int *px, int *py); -static void SyntheticMotion(int x, int y); -static void PostNewCursor(void); - -static Bool -XineramaSetCursorPosition( - int x, - int y, - Bool generateEvent -){ - ScreenPtr pScreen; - BoxRec box; - int i; - - /* x,y are in Screen 0 coordinates. We need to decide what Screen - to send the message too and what the coordinates relative to - that screen are. */ - - pScreen = sprite.screen; - x += panoramiXdataPtr[0].x; - y += panoramiXdataPtr[0].y; - - if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum], - x, y, &box)) - { - FOR_NSCREENS(i) - { - if(i == pScreen->myNum) - continue; - if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i], x, y, &box)) - { - pScreen = screenInfo.screens[i]; - break; - } - } - } - - sprite.screen = pScreen; - sprite.hotPhys.x = x - panoramiXdataPtr[0].x; - sprite.hotPhys.y = y - panoramiXdataPtr[0].y; - x -= panoramiXdataPtr[pScreen->myNum].x; - y -= panoramiXdataPtr[pScreen->myNum].y; - - return (*pScreen->SetCursorPosition)(pScreen, x, y, generateEvent); -} - - -static void -XineramaConstrainCursor(void) -{ - ScreenPtr pScreen = sprite.screen; - BoxRec newBox = sprite.physLimits; - - /* Translate the constraining box to the screen - the sprite is actually on */ - newBox.x1 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.x2 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.y1 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - newBox.y2 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - - (* pScreen->ConstrainCursor)(pScreen, &newBox); -} - -static void -XineramaCheckPhysLimits( - CursorPtr cursor, - Bool generateEvents -){ - HotSpot new; - - if (!cursor) - return; - - new = sprite.hotPhys; - - /* I don't care what the DDX has to say about it */ - sprite.physLimits = sprite.hotLimits; - - /* constrain the pointer to those limits */ - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) /* more work if the shape is a mess */ - ConfineToShape(sprite.hotShape, &new.x, &new.y); - - if((new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - XineramaSetCursorPosition (new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } - - /* Tell DDX what the limits are */ - XineramaConstrainCursor(); -} - - -static Bool -XineramaSetWindowPntrs(WindowPtr pWin) -{ - if(pWin == WindowTable[0]) { - memcpy(sprite.windows, WindowTable, - PanoramiXNumScreens*sizeof(WindowPtr)); - } else { - PanoramiXRes *win; - int i; - - win = (PanoramiXRes*)LookupIDByType(pWin->drawable.id, XRT_WINDOW); - - if(!win) - return FALSE; - - for(i = 0; i < PanoramiXNumScreens; i++) { - sprite.windows[i] = LookupIDByType(win->info[i].id, RT_WINDOW); - if(!sprite.windows[i]) /* window is being unmapped */ - return FALSE; - } - } - return TRUE; -} - -static void -XineramaCheckVirtualMotion( - QdEventPtr qe, - WindowPtr pWin -){ - - if (qe) - { - sprite.hot.pScreen = qe->pScreen; /* should always be Screen 0 */ -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - int x, y, off_x, off_y, i; - BoxRec lims; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg2, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg2, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg2, &sprite.Reg2, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - lims = *REGION_EXTENTS(sprite.screen, &sprite.Reg2); - - if (sprite.hot.x < lims.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y2 - 1; - - if (REGION_NUM_RECTS(&sprite.Reg2) > 1) - ConfineToShape(&sprite.Reg2, &sprite.hot.x, &sprite.hot.y); - - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } -} - - -static Bool -XineramaCheckMotion(xEvent *xE) -{ - WindowPtr prevSpriteWin = sprite.win; - - if (xE && !syncEvents.playingEvents) - { - /* Motion events entering DIX get translated to Screen 0 - coordinates. Replayed events have already been - translated since they've entered DIX before */ - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = XE_KBPTR.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y2 - 1; - - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); - - sprite.hotPhys = sprite.hot; - if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - (sprite.hotPhys.y != XE_KBPTR.rootY)) - { - XineramaSetCursorPosition( - sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - } - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - -#ifdef XEVIE - xeviewin = -#endif - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); - - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - - -static void -XineramaConfineCursorToWindow(WindowPtr pWin, Bool generateEvents) -{ - - if (syncEvents.playingEvents) - { - XineramaCheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - int x, y, off_x, off_y, i; - - if(!XineramaSetWindowPntrs(pWin)) - return; - - i = PanoramiXNumScreens - 1; - - REGION_COPY(sprite.screen, &sprite.Reg1, - &sprite.windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - - while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; - - if(x || y) - REGION_TRANSLATE(sprite.screen, &sprite.Reg1, x, y); - - REGION_UNION(sprite.screen, &sprite.Reg1, &sprite.Reg1, - &sprite.windows[i]->borderSize); - - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; - } - - sprite.hotLimits = *REGION_EXTENTS(sprite.screen, &sprite.Reg1); - - if(REGION_NUM_RECTS(&sprite.Reg1) > 1) - sprite.hotShape = &sprite.Reg1; - else - sprite.hotShape = NullRegion; - - sprite.confined = FALSE; - sprite.confineWin = (pWin == WindowTable[0]) ? NullWindow : pWin; - - XineramaCheckPhysLimits(sprite.current, generateEvents); - } -} - - -static void -XineramaChangeToCursor(CursorPtr cursor) -{ - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - XineramaCheckPhysLimits(cursor, FALSE); - (*sprite.screen->DisplayCursor)(sprite.screen, cursor); - FreeCursor(sprite.current, (Cursor)0); - sprite.current = cursor; - sprite.current->refcnt++; - } -} - - -#endif /* PANORAMIX */ - -void -SetMaskForEvent(Mask mask, int event) -{ - if ((event < LASTEvent) || (event >= 128)) - FatalError("SetMaskForEvent: bogus event number"); - filters[event] = mask; -} - -void -SetCriticalEvent(int event) -{ - if (event >= 128) - FatalError("SetCriticalEvent: bogus event number"); - criticalEvents[event >> 3] |= 1 << (event & 7); -} - -static void -SyntheticMotion(int x, int y) -{ - xEvent xE; - -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - x += panoramiXdataPtr[0].x - panoramiXdataPtr[sprite.screen->myNum].x; - y += panoramiXdataPtr[0].y - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; - if (syncEvents.playingEvents) - xE.u.keyButtonPointer.time = syncEvents.time.milliseconds; - else - xE.u.keyButtonPointer.time = currentTime.milliseconds; - xE.u.u.type = MotionNotify; - (*inputInfo.pointer->public.processInputProc)(&xE, inputInfo.pointer, 1); -} - -#ifdef SHAPE -static void -ConfineToShape(RegionPtr shape, int *px, int *py) -{ - BoxRec box; - int x = *px, y = *py; - int incx = 1, incy = 1; - - if (POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)) - return; - box = *REGION_EXTENTS(sprite.hot.pScreen, shape); - /* this is rather crude */ - do { - x += incx; - if (x >= box.x2) - { - incx = -1; - x = *px - 1; - } - else if (x < box.x1) - { - incx = 1; - x = *px; - y += incy; - if (y >= box.y2) - { - incy = -1; - y = *py - 1; - } - else if (y < box.y1) - return; /* should never get here! */ - } - } while (!POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box)); - *px = x; - *py = y; -} -#endif - -static void -CheckPhysLimits( - CursorPtr cursor, - Bool generateEvents, - Bool confineToScreen, - ScreenPtr pScreen) -{ - HotSpot new; - - if (!cursor) - return; - new = sprite.hotPhys; - if (pScreen) - new.pScreen = pScreen; - else - pScreen = new.pScreen; - (*pScreen->CursorLimits) (pScreen, cursor, &sprite.hotLimits, - &sprite.physLimits); - sprite.confined = confineToScreen; - (* pScreen->ConstrainCursor)(pScreen, &sprite.physLimits); - if (new.x < sprite.physLimits.x1) - new.x = sprite.physLimits.x1; - else - if (new.x >= sprite.physLimits.x2) - new.x = sprite.physLimits.x2 - 1; - if (new.y < sprite.physLimits.y1) - new.y = sprite.physLimits.y1; - else - if (new.y >= sprite.physLimits.y2) - new.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &new.x, &new.y); -#endif - if ((pScreen != sprite.hotPhys.pScreen) || - (new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y)) - { - if (pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys = new; - (*pScreen->SetCursorPosition) (pScreen, new.x, new.y, generateEvents); - if (!generateEvents) - SyntheticMotion(new.x, new.y); - } -} - -static void -CheckVirtualMotion( - register QdEventPtr qe, - register WindowPtr pWin) -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaCheckVirtualMotion(qe, pWin); - return; - } -#endif - if (qe) - { - sprite.hot.pScreen = qe->pScreen; -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = qe->event->u.keyButtonPointer.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = qe->event->u.keyButtonPointer.rootY; - pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo : - NullWindow; - } - if (pWin) - { - BoxRec lims; - - if (sprite.hot.pScreen != pWin->drawable.pScreen) - { - sprite.hot.pScreen = pWin->drawable.pScreen; -#ifdef XEVIE - xeviehot.x = xeviehot.y = 0; -#endif - sprite.hot.x = sprite.hot.y = 0; - } - lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize); - if (sprite.hot.x < lims.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x1; - else if (sprite.hot.x >= lims.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = lims.x2 - 1; - if (sprite.hot.y < lims.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y1; - else if (sprite.hot.y >= lims.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = lims.y2 - 1; -#ifdef SHAPE - if (wBoundingShape(pWin)) - ConfineToShape(&pWin->borderSize, &sprite.hot.x, &sprite.hot.y); -#endif - if (qe) - { - qe->pScreen = sprite.hot.pScreen; - qe->event->u.keyButtonPointer.rootX = sprite.hot.x; - qe->event->u.keyButtonPointer.rootY = sprite.hot.y; - } - } - ROOT = WindowTable[sprite.hot.pScreen->myNum]; -} - -static void -ConfineCursorToWindow(WindowPtr pWin, Bool generateEvents, Bool confineToScreen) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaConfineCursorToWindow(pWin, generateEvents); - return; - } -#endif - - if (syncEvents.playingEvents) - { - CheckVirtualMotion((QdEventPtr)NULL, pWin); - SyntheticMotion(sprite.hot.x, sprite.hot.y); - } - else - { - sprite.hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize); -#ifdef SHAPE - sprite.hotShape = wBoundingShape(pWin) ? &pWin->borderSize - : NullRegion; -#endif - CheckPhysLimits(sprite.current, generateEvents, confineToScreen, - pScreen); - } -} - -Bool -PointerConfinedToScreen() -{ - return sprite.confined; -} - -static void -ChangeToCursor(CursorPtr cursor) -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XineramaChangeToCursor(cursor); - return; - } -#endif - - if (cursor != sprite.current) - { - if ((sprite.current->bits->xhot != cursor->bits->xhot) || - (sprite.current->bits->yhot != cursor->bits->yhot)) - CheckPhysLimits(cursor, FALSE, sprite.confined, - (ScreenPtr)NULL); - (*sprite.hotPhys.pScreen->DisplayCursor) (sprite.hotPhys.pScreen, - cursor); - FreeCursor(sprite.current, (Cursor)0); - sprite.current = cursor; - sprite.current->refcnt++; - } -} - -/* returns true if b is a descendent of a */ -Bool -IsParent(register WindowPtr a, register WindowPtr b) -{ - for (b = b->parent; b; b = b->parent) - if (b == a) return TRUE; - return FALSE; -} - -static void -PostNewCursor(void) -{ - register WindowPtr win; - register GrabPtr grab = inputInfo.pointer->grab; - - if (syncEvents.playingEvents) - return; - if (grab) - { - if (grab->cursor) - { - ChangeToCursor(grab->cursor); - return; - } - if (IsParent(grab->window, sprite.win)) - win = sprite.win; - else - win = grab->window; - } - else - win = sprite.win; - for (; win; win = win->parent) - if (win->optional && win->optional->cursor != NullCursor) - { - ChangeToCursor(win->optional->cursor); - return; - } -} - -WindowPtr -GetCurrentRootWindow() -{ - return ROOT; -} - -WindowPtr -GetSpriteWindow() -{ - return sprite.win; -} - -CursorPtr -GetSpriteCursor() -{ - return sprite.current; -} - -void -GetSpritePosition(int *px, int *py) -{ - *px = sprite.hotPhys.x; - *py = sprite.hotPhys.y; -} - -#ifdef PANORAMIX -int -XineramaGetCursorScreen() -{ - if(!noPanoramiXExtension) { - return sprite.screen->myNum; - } else { - return 0; - } -} -#endif /* PANORAMIX */ - -#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */ - -static void -MonthChangedOrBadTime(register xEvent *xE) -{ - /* If the ddx/OS is careless about not processing timestamped events from - * different sources in sorted order, then it's possible for time to go - * backwards when it should not. Here we ensure a decent time. - */ - if ((currentTime.milliseconds - XE_KBPTR.time) > TIMESLOP) - currentTime.months++; - else - XE_KBPTR.time = currentTime.milliseconds; -} - -#define NoticeTime(xE) { \ - if ((xE)->u.keyButtonPointer.time < currentTime.milliseconds) \ - MonthChangedOrBadTime(xE); \ - currentTime.milliseconds = (xE)->u.keyButtonPointer.time; \ - lastDeviceEventTime = currentTime; } - -void -NoticeEventTime(register xEvent *xE) -{ - if (!syncEvents.playingEvents) - NoticeTime(xE); -} - -/************************************************************************** - * The following procedures deal with synchronous events * - **************************************************************************/ - -void -EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count) -{ - register QdEventPtr tail = *syncEvents.pendtail; - register QdEventPtr qe; - xEvent *qxE; - - NoticeTime(xE); - -#ifdef XKB - /* Fix for key repeating bug. */ - if (device->key != NULL && device->key->xkbInfo != NULL && - xE->u.u.type == KeyRelease) - AccessXCancelRepeatKey(device->key->xkbInfo, xE->u.u.detail); -#endif - - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* The RECORD spec says that the root window field of motion events - * must be valid. At this point, it hasn't been filled in yet, so - * we do it here. The long expression below is necessary to get - * the current root window; the apparently reasonable alternative - * GetCurrentRootWindow()->drawable.id doesn't give you the right - * answer on the first motion event after a screen change because - * the data that GetCurrentRootWindow relies on hasn't been - * updated yet. - */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - if (xE->u.u.type == MotionNotify) - { -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - XE_KBPTR.rootX += panoramiXdataPtr[sprite.screen->myNum].x - - panoramiXdataPtr[0].x; - XE_KBPTR.rootY += panoramiXdataPtr[sprite.screen->myNum].y - - panoramiXdataPtr[0].y; - } -#endif - sprite.hotPhys.x = XE_KBPTR.rootX; - sprite.hotPhys.y = XE_KBPTR.rootY; - /* do motion compression */ - if (tail && - (tail->event->u.u.type == MotionNotify) && - (tail->pScreen == sprite.hotPhys.pScreen)) - { - tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x; - tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y; - tail->event->u.keyButtonPointer.time = XE_KBPTR.time; - tail->months = currentTime.months; - return; - } - } - qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + (count * sizeof(xEvent))); - if (!qe) - return; - qe->next = (QdEventPtr)NULL; - qe->device = device; - qe->pScreen = sprite.hotPhys.pScreen; - qe->months = currentTime.months; - qe->event = (xEvent *)(qe + 1); - qe->evcount = count; - for (qxE = qe->event; --count >= 0; qxE++, xE++) - *qxE = *xE; - if (tail) - syncEvents.pendtail = &tail->next; - *syncEvents.pendtail = qe; -} - -static void -PlayReleasedEvents(void) -{ - register QdEventPtr *prev, qe; - register DeviceIntPtr dev; - - prev = &syncEvents.pending; - while ( (qe = *prev) ) - { - if (!qe->device->sync.frozen) - { - *prev = qe->next; - if (*syncEvents.pendtail == *prev) - syncEvents.pendtail = prev; - if (qe->event->u.u.type == MotionNotify) - CheckVirtualMotion(qe, NullWindow); - syncEvents.time.months = qe->months; - syncEvents.time.milliseconds = qe->event->u.keyButtonPointer.time; -#ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { - qe->event->u.keyButtonPointer.rootX += - panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x; - qe->event->u.keyButtonPointer.rootY += - panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y; - } -#endif - (*qe->device->public.processInputProc)(qe->event, qe->device, - qe->evcount); - xfree(qe); - for (dev = inputInfo.devices; dev && dev->sync.frozen; dev = dev->next) - ; - if (!dev) - break; - /* Playing the event may have unfrozen another device. */ - /* So to play it safe, restart at the head of the queue */ - prev = &syncEvents.pending; - } - else - prev = &qe->next; - } -} - -static void -FreezeThaw(register DeviceIntPtr dev, Bool frozen) -{ - dev->sync.frozen = frozen; - if (frozen) - dev->public.processInputProc = dev->public.enqueueInputProc; - else - dev->public.processInputProc = dev->public.realInputProc; -} - -void -ComputeFreezes() -{ - register DeviceIntPtr replayDev = syncEvents.replayDev; - register int i; - WindowPtr w; - register xEvent *xE; - int count; - GrabPtr grab; - register DeviceIntPtr dev; - - for (dev = inputInfo.devices; dev; dev = dev->next) - FreezeThaw(dev, dev->sync.other || (dev->sync.state >= FROZEN)); - if (syncEvents.playingEvents || (!replayDev && !syncEvents.pending)) - return; - syncEvents.playingEvents = TRUE; - if (replayDev) - { - xE = replayDev->sync.event; - count = replayDev->sync.evcount; - syncEvents.replayDev = (DeviceIntPtr)NULL; - - w = XYToWindow( XE_KBPTR.rootX, XE_KBPTR.rootY); - for (i = 0; i < spriteTraceGood; i++) - { - if (syncEvents.replayWin == spriteTrace[i]) - { - if (!CheckDeviceGrabs(replayDev, xE, i+1, count)) { - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, - replayDev, count); - } - goto playmore; - } - } - /* must not still be in the same stack */ - if (replayDev->focus) - DeliverFocusedEvent(replayDev, xE, w, count); - else - DeliverDeviceEvents(w, xE, NullGrab, NullWindow, replayDev, count); - } -playmore: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!dev->sync.frozen) - { - PlayReleasedEvents(); - break; - } - } - syncEvents.playingEvents = FALSE; - /* the following may have been skipped during replay, so do it now */ - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); - PostNewCursor(); -} - -#ifdef RANDR -void -ScreenRestructured (ScreenPtr pScreen) -{ - GrabPtr grab; - - if ((grab = inputInfo.pointer->grab) && grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } - else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); -} -#endif - -void -CheckGrabForSyncs(register DeviceIntPtr thisDev, Bool thisMode, Bool otherMode) -{ - register GrabPtr grab = thisDev->grab; - register DeviceIntPtr dev; - - if (thisMode == GrabModeSync) - thisDev->sync.state = FROZEN_NO_EVENT; - else - { /* free both if same client owns both */ - thisDev->sync.state = THAWED; - if (thisDev->sync.other && - (CLIENT_BITS(thisDev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - thisDev->sync.other = NullGrab; - } - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev != thisDev) - { - if (otherMode == GrabModeSync) - dev->sync.other = grab; - else - { /* free both if same client owns both */ - if (dev->sync.other && - (CLIENT_BITS(dev->sync.other->resource) == - CLIENT_BITS(grab->resource))) - dev->sync.other = NullGrab; - } - } - } - ComputeFreezes(); -} - -void -ActivatePointerGrab(register DeviceIntPtr mouse, register GrabPtr grab, - TimeStamp time, Bool autoGrab) -{ - WindowPtr oldWin = (mouse->grab) ? mouse->grab->window - : sprite.win; - - if (grab->confineTo) - { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, FALSE, TRUE); - } - DoEnterLeaveEvents(oldWin, grab->window, NotifyGrab); - mouse->valuator->motionHintWindow = NullWindow; - if (syncEvents.playingEvents) - mouse->grabTime = syncEvents.time; - else - mouse->grabTime = time; - if (grab->cursor) - grab->cursor->refcnt++; - mouse->activeGrab = *grab; - mouse->grab = &mouse->activeGrab; - mouse->fromPassiveGrab = autoGrab; - PostNewCursor(); - CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); -} - -void -DeactivatePointerGrab(register DeviceIntPtr mouse) -{ - register GrabPtr grab = mouse->grab; - register DeviceIntPtr dev; - - mouse->valuator->motionHintWindow = NullWindow; - mouse->grab = NullGrab; - mouse->sync.state = NOT_GRABBED; - mouse->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoEnterLeaveEvents(grab->window, sprite.win, NotifyUngrab); - if (grab->confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - PostNewCursor(); - if (grab->cursor) - FreeCursor(grab->cursor, (Cursor)0); - ComputeFreezes(); -} - -void -ActivateKeyboardGrab(register DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool passive) -{ - WindowPtr oldWin; - - if (keybd->grab) - oldWin = keybd->grab->window; - else if (keybd->focus) - oldWin = keybd->focus->win; - else - oldWin = sprite.win; - if (oldWin == FollowKeyboardWin) - oldWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab); - if (syncEvents.playingEvents) - keybd->grabTime = syncEvents.time; - else - keybd->grabTime = time; - keybd->activeGrab = *grab; - keybd->grab = &keybd->activeGrab; - keybd->fromPassiveGrab = passive; - CheckGrabForSyncs(keybd, (Bool)grab->keyboardMode, (Bool)grab->pointerMode); -} - -void -DeactivateKeyboardGrab(register DeviceIntPtr keybd) -{ - register GrabPtr grab = keybd->grab; - register DeviceIntPtr dev; - register WindowPtr focusWin = keybd->focus ? keybd->focus->win - : sprite.win; - - if (focusWin == FollowKeyboardWin) - focusWin = inputInfo.keyboard->focus->win; - if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; - keybd->grab = NullGrab; - keybd->sync.state = NOT_GRABBED; - keybd->fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->sync.other == grab) - dev->sync.other = NullGrab; - } - DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab); - ComputeFreezes(); -} - -void -AllowSome(ClientPtr client, TimeStamp time, DeviceIntPtr thisDev, int newState) -{ - Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced; - TimeStamp grabTime; - register DeviceIntPtr dev; - - thisGrabbed = thisDev->grab && SameClient(thisDev->grab, client); - thisSynced = FALSE; - otherGrabbed = FALSE; - othersFrozen = TRUE; - grabTime = thisDev->grabTime; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - { - if (!(thisGrabbed || otherGrabbed) || - (CompareTimeStamps(dev->grabTime, grabTime) == LATER)) - grabTime = dev->grabTime; - otherGrabbed = TRUE; - if (thisDev->sync.other == dev->grab) - thisSynced = TRUE; - if (dev->sync.state < FROZEN) - othersFrozen = FALSE; - } - else if (!dev->sync.other || !SameClient(dev->sync.other, client)) - othersFrozen = FALSE; - } - if (!((thisGrabbed && thisDev->sync.state >= FROZEN) || thisSynced)) - return; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, grabTime) == EARLIER)) - return; - switch (newState) - { - case THAWED: /* Async */ - if (thisGrabbed) - thisDev->sync.state = THAWED; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - break; - case FREEZE_NEXT_EVENT: /* Sync */ - if (thisGrabbed) - { - thisDev->sync.state = FREEZE_NEXT_EVENT; - if (thisSynced) - thisDev->sync.other = NullGrab; - ComputeFreezes(); - } - break; - case THAWED_BOTH: /* AsyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case FREEZE_BOTH_NEXT_EVENT: /* SyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = FREEZE_BOTH_NEXT_EVENT; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case NOT_GRABBED: /* Replay */ - if (thisGrabbed && thisDev->sync.state == FROZEN_WITH_EVENT) - { - if (thisSynced) - thisDev->sync.other = NullGrab; - syncEvents.replayDev = thisDev; - syncEvents.replayWin = thisDev->grab->window; - (*thisDev->DeactivateGrab)(thisDev); - syncEvents.replayDev = (DeviceIntPtr)NULL; - } - break; - case THAW_OTHERS: /* AsyncOthers */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - if (dev->grab && SameClient(dev->grab, client)) - dev->sync.state = THAWED; - if (dev->sync.other && SameClient(dev->sync.other, client)) - dev->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - } -} - -int -ProcAllowEvents(register ClientPtr client) -{ - TimeStamp time; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - REQUEST(xAllowEventsReq); - - REQUEST_SIZE_MATCH(xAllowEventsReq); - time = ClientTimeToServerTime(stuff->time); - switch (stuff->mode) - { - case ReplayPointer: - AllowSome(client, time, mouse, NOT_GRABBED); - break; - case SyncPointer: - AllowSome(client, time, mouse, FREEZE_NEXT_EVENT); - break; - case AsyncPointer: - AllowSome(client, time, mouse, THAWED); - break; - case ReplayKeyboard: - AllowSome(client, time, keybd, NOT_GRABBED); - break; - case SyncKeyboard: - AllowSome(client, time, keybd, FREEZE_NEXT_EVENT); - break; - case AsyncKeyboard: - AllowSome(client, time, keybd, THAWED); - break; - case SyncBoth: - AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT); - break; - case AsyncBoth: - AllowSome(client, time, keybd, THAWED_BOTH); - break; - default: - client->errorValue = stuff->mode; - return BadValue; - } - return Success; -} - -void -ReleaseActiveGrabs(ClientPtr client) -{ - register DeviceIntPtr dev; - Bool done; - - /* XXX CloseDownClient should remove passive grabs before - * releasing active grabs. - */ - do { - done = TRUE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->grab && SameClient(dev->grab, client)) - { - (*dev->DeactivateGrab)(dev); - done = FALSE; - } - } - } while (!done); -} - -/************************************************************************** - * The following procedures deal with delivering events * - **************************************************************************/ - -int -TryClientEvents (ClientPtr client, xEvent *pEvents, int count, Mask mask, - Mask filter, GrabPtr grab) -{ - int i; - int type; - -#ifdef DEBUG - if (debug_events) ErrorF( - "Event([%d, %d], mask=0x%x), client=%d", - pEvents->u.u.type, pEvents->u.u.detail, mask, client->index); -#endif - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) - return -1; /* don't send, but notify caller */ - type = pEvents->u.u.type; - if (type == MotionNotify) - { - if (mask & PointerMotionHintMask) - { - if (WID(inputInfo.pointer->valuator->motionHintWindow) == - pEvents->u.keyButtonPointer.event) - { -#ifdef DEBUG - if (debug_events) ErrorF("\n"); - fprintf(stderr,"motionHintWindow == keyButtonPointer.event\n"); -#endif - return 1; /* don't send, but pretend we did */ - } - pEvents->u.u.detail = NotifyHint; - } - else - { - pEvents->u.u.detail = NotifyNormal; - } - } -#ifdef XINPUT - else - { - if ((type == DeviceMotionNotify) && - MaybeSendDeviceMotionNotifyHint - ((deviceKeyButtonPointer*)pEvents, mask) != 0) - return 1; - } -#endif - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } - - if (BitIsOn(criticalEvents, type)) - { -#ifdef SMART_SCHEDULE - if (client->smart_priority < SMART_MAX_PRIORITY) - client->smart_priority++; -#endif - SetCriticalOutputPending(); - } - - WriteEventsToClient(client, count, pEvents); -#ifdef DEBUG - if (debug_events) ErrorF( " delivered\n"); -#endif - return 1; - } - else - { -#ifdef DEBUG - if (debug_events) ErrorF("\n"); -#endif - return 0; - } -} - -int -DeliverEventsToWindow(register WindowPtr pWin, xEvent *pEvents, int count, - Mask filter, GrabPtr grab, int mskidx) -{ - int deliveries = 0, nondeliveries = 0; - int attempt; - register InputClients *other; - ClientPtr client = NullClient; - Mask deliveryMask = 0; /* If a grab occurs due to a button press, then - this mask is the mask of the grab. */ - int type = pEvents->u.u.type; - - /* CantBeFiltered means only window owner gets the event */ - if ((filter == CantBeFiltered) || !(type & EXTENSION_EVENT_BASE)) - { - /* if nobody ever wants to see this event, skip some work */ - if (filter != CantBeFiltered && - !((wOtherEventMasks(pWin)|pWin->eventMask) & filter)) - return 0; - if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = wClient(pWin); - deliveryMask = pWin->eventMask; - } else - nondeliveries--; - } - } - if (filter != CantBeFiltered) - { - if (type & EXTENSION_EVENT_BASE) - { - OtherInputMasks *inputMasks; - - inputMasks = wOtherInputMasks(pWin); - if (!inputMasks || - !(inputMasks->inputEvents[mskidx] & filter)) - return 0; - other = inputMasks->inputClients; - } - else - other = (InputClients *)wOtherClients(pWin); - for (; other; other = other->next) - { - if ( (attempt = TryClientEvents(rClient(other), pEvents, count, - other->mask[mskidx], filter, grab)) ) - { - if (attempt > 0) - { - deliveries++; - client = rClient(other); - deliveryMask = other->mask[mskidx]; - } else - nondeliveries--; - } - } - } - if ((type == ButtonPress) && deliveries && (!grab)) - { - GrabRec tempGrab; - - tempGrab.device = inputInfo.pointer; - tempGrab.resource = client->clientAsMask; - tempGrab.window = pWin; - tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE; - tempGrab.eventMask = deliveryMask; - tempGrab.keyboardMode = GrabModeAsync; - tempGrab.pointerMode = GrabModeAsync; - tempGrab.confineTo = NullWindow; - tempGrab.cursor = NullCursor; - (*inputInfo.pointer->ActivateGrab)(inputInfo.pointer, &tempGrab, - currentTime, TRUE); - } - else if ((type == MotionNotify) && deliveries) - inputInfo.pointer->valuator->motionHintWindow = pWin; -#ifdef XINPUT - else - { - if (((type == DeviceMotionNotify) -#ifdef XKB - || (type == DeviceButtonPress) -#endif - ) && deliveries) - CheckDeviceGrabAndHintWindow (pWin, type, - (deviceKeyButtonPointer*) pEvents, - grab, client, deliveryMask); - } -#endif - if (deliveries) - return deliveries; - return nondeliveries; -} - -/* If the event goes to dontClient, don't send it and return 0. if - send works, return 1 or if send didn't work, return 2. - Only works for core events. -*/ - -#ifdef PANORAMIX -static int -XineramaTryClientEventsResult( - ClientPtr client, - GrabPtr grab, - Mask mask, - Mask filter -){ - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) return -1; - else return 1; - } - return 0; -} -#endif - -int -MaybeDeliverEventsToClient(register WindowPtr pWin, xEvent *pEvents, - int count, Mask filter, ClientPtr dontClient) -{ - register OtherClients *other; - - - if (pWin->eventMask & filter) - { - if (wClient(pWin) == dontClient) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - wClient(pWin), NullGrab, pWin->eventMask, filter); -#endif - return TryClientEvents(wClient(pWin), pEvents, count, - pWin->eventMask, filter, NullGrab); - } - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & filter) - { - if (SameClient(other, dontClient)) - return 0; -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - rClient(other), NullGrab, other->mask, filter); -#endif - return TryClientEvents(rClient(other), pEvents, count, - other->mask, filter, NullGrab); - } - } - return 2; -} - -static void -FixUpEventFromWindow( - xEvent *xE, - WindowPtr pWin, - Window child, - Bool calcChild) -{ - if (calcChild) - { - WindowPtr w=spriteTrace[spriteTraceGood-1]; - /* If the search ends up past the root should the child field be - set to none or should the value in the argument be passed - through. It probably doesn't matter since everyone calls - this function with child == None anyway. */ - - while (w) - { - /* If the source window is same as event window, child should be - none. Don't bother going all all the way back to the root. */ - - if (w == pWin) - { - child = None; - break; - } - - if (w->parent == pWin) - { - child = w->drawable.id; - break; - } - w = w->parent; - } - } - XE_KBPTR.root = ROOT->drawable.id; - XE_KBPTR.event = pWin->drawable.id; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - XE_KBPTR.sameScreen = xTrue; - XE_KBPTR.child = child; - XE_KBPTR.eventX = - XE_KBPTR.rootX - pWin->drawable.x; - XE_KBPTR.eventY = - XE_KBPTR.rootY - pWin->drawable.y; - } - else - { - XE_KBPTR.sameScreen = xFalse; - XE_KBPTR.child = None; - XE_KBPTR.eventX = 0; - XE_KBPTR.eventY = 0; - } -} - -int -DeliverDeviceEvents(register WindowPtr pWin, register xEvent *xE, GrabPtr grab, - register WindowPtr stopAt, DeviceIntPtr dev, int count) -{ - Window child = None; - int type = xE->u.u.type; - Mask filter = filters[type]; - int deliveries = 0; - - if (type & EXTENSION_EVENT_BASE) - { - register OtherInputMasks *inputMasks; - int mskidx = dev->id; - - inputMasks = wOtherInputMasks(pWin); - if (inputMasks && !(filter & inputMasks->deliverableEvents[mskidx])) - return 0; - while (pWin) - { - if (inputMasks && (inputMasks->inputEvents[mskidx] & filter)) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, mskidx); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (inputMasks && - (filter & inputMasks->dontPropagateMask[mskidx]))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - if (pWin) - inputMasks = wOtherInputMasks(pWin); - } - } - else - { - if (!(filter & pWin->deliverableEvents)) - return 0; - while (pWin) - { - if ((wOtherEventMasks(pWin)|pWin->eventMask) & filter) - { - FixUpEventFromWindow(xE, pWin, child, FALSE); - deliveries = DeliverEventsToWindow(pWin, xE, count, filter, - grab, 0); - if (deliveries > 0) - return deliveries; - } - if ((deliveries < 0) || - (pWin == stopAt) || - (filter & wDontPropagateMask(pWin))) - return 0; - child = pWin->drawable.id; - pWin = pWin->parent; - } - } - return 0; -} - -/* not useful for events that propagate up the tree or extension events */ -int -DeliverEvents(register WindowPtr pWin, register xEvent *xE, int count, - register WindowPtr otherParent) -{ - Mask filter; - int deliveries; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return count; -#endif - - if (!count) - return 0; - filter = filters[xE->u.u.type]; - if ((filter & SubstructureNotifyMask) && (xE->u.u.type != CreateNotify)) - xE->u.destroyNotify.event = pWin->drawable.id; - if (filter != StructureAndSubMask) - return DeliverEventsToWindow(pWin, xE, count, filter, NullGrab, 0); - deliveries = DeliverEventsToWindow(pWin, xE, count, StructureNotifyMask, - NullGrab, 0); - if (pWin->parent) - { - xE->u.destroyNotify.event = pWin->parent->drawable.id; - deliveries += DeliverEventsToWindow(pWin->parent, xE, count, - SubstructureNotifyMask, NullGrab, - 0); - if (xE->u.u.type == ReparentNotify) - { - xE->u.destroyNotify.event = otherParent->drawable.id; - deliveries += DeliverEventsToWindow(otherParent, xE, count, - SubstructureNotifyMask, - NullGrab, 0); - } - } - return deliveries; -} - - -static Bool -PointInBorderSize(WindowPtr pWin, int x, int y) -{ - BoxRec box; - - if(POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderSize, x, y, &box)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(POINT_IN_REGION(sprite.screen, - &sprite.windows[i]->borderSize, - x + panoramiXdataPtr[0].x - panoramiXdataPtr[i].x, - y + panoramiXdataPtr[0].y - panoramiXdataPtr[i].y, - &box)) - return TRUE; - } - } -#endif - return FALSE; -} - -static WindowPtr -XYToWindow(int x, int y) -{ - register WindowPtr pWin; - BoxRec box; - - spriteTraceGood = 1; /* root window still there */ - pWin = ROOT->firstChild; - while (pWin) - { - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth(pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) -#ifdef SHAPE - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) -#endif - ) - { - if (spriteTraceGood >= spriteTraceSize) - { - spriteTraceSize += 10; - Must_have_memory = TRUE; /* XXX */ - spriteTrace = (WindowPtr *)xrealloc( - spriteTrace, spriteTraceSize*sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - spriteTrace[spriteTraceGood++] = pWin; - pWin = pWin->firstChild; - } - else - pWin = pWin->nextSib; - } - return spriteTrace[spriteTraceGood-1]; -} - -static Bool -CheckMotion(xEvent *xE) -{ - WindowPtr prevSpriteWin = sprite.win; - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaCheckMotion(xE); -#endif - - if (xE && !syncEvents.playingEvents) - { - if (sprite.hot.pScreen != sprite.hotPhys.pScreen) - { - sprite.hot.pScreen = sprite.hotPhys.pScreen; - ROOT = WindowTable[sprite.hot.pScreen->myNum]; - } -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = XE_KBPTR.rootX; -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = XE_KBPTR.rootY; - if (sprite.hot.x < sprite.physLimits.x1) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x1; - else if (sprite.hot.x >= sprite.physLimits.x2) -#ifdef XEVIE - xeviehot.x = -#endif - sprite.hot.x = sprite.physLimits.x2 - 1; - if (sprite.hot.y < sprite.physLimits.y1) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y1; - else if (sprite.hot.y >= sprite.physLimits.y2) -#ifdef XEVIE - xeviehot.y = -#endif - sprite.hot.y = sprite.physLimits.y2 - 1; -#ifdef SHAPE - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y); -#endif - sprite.hotPhys = sprite.hot; - if ((sprite.hotPhys.x != XE_KBPTR.rootX) || - (sprite.hotPhys.y != XE_KBPTR.rootY)) - { - (*sprite.hotPhys.pScreen->SetCursorPosition)( - sprite.hotPhys.pScreen, - sprite.hotPhys.x, sprite.hotPhys.y, FALSE); - } - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - } - -#ifdef XEVIE - xeviewin = -#endif - sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y); -#ifdef notyet - if (!(sprite.win->deliverableEvents & - Motion_Filter(inputInfo.pointer->button)) - !syncEvents.playingEvents) - { - /* XXX Do PointerNonInterestBox here */ - } -#endif - if (sprite.win != prevSpriteWin) - { - if (prevSpriteWin != NullWindow) { - if (!xE) - UpdateCurrentTimeIf(); - DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal); - } - PostNewCursor(); - return FALSE; - } - return TRUE; -} - -void -WindowsRestructured() -{ - (void) CheckMotion((xEvent *)NULL); -} - -#ifdef PANORAMIX -/* This was added to support reconfiguration under Xdmx. The problem is - * that if the 0th screen (i.e., WindowTable[0]) is moved to an origin - * other than 0,0, the information in the private sprite structure must - * be updated accordingly, or XYToWindow (and other routines) will not - * compute correctly. */ -void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) -{ - ScreenPtr pScreen = win->drawable.pScreen; - GrabPtr grab; - - if (noPanoramiXExtension) return; - - sprite.hot.x -= xoff; - sprite.hot.y -= yoff; - - sprite.hotPhys.x -= xoff; - sprite.hotPhys.y -= yoff; - - sprite.hotLimits.x1 -= xoff; - sprite.hotLimits.y1 -= yoff; - sprite.hotLimits.x2 -= xoff; - sprite.hotLimits.y2 -= yoff; - - if (REGION_NOTEMPTY(sprite.screen, &sprite.Reg1)) - REGION_TRANSLATE(sprite.screen, &sprite.Reg1, xoff, yoff); - if (REGION_NOTEMPTY(sprite.screen, &sprite.Reg2)) - REGION_TRANSLATE(sprite.screen, &sprite.Reg2, xoff, yoff); - - /* FIXME: if we call ConfineCursorToWindow, must we do anything else? */ - if ((grab = inputInfo.pointer->grab) && grab->confineTo) { - if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen) - sprite.hotPhys.x = sprite.hotPhys.y = 0; - ConfineCursorToWindow(grab->confineTo, TRUE, TRUE); - } else - ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum], - TRUE, FALSE); -} -#endif - -void -DefineInitialRootWindow(register WindowPtr win) -{ - register ScreenPtr pScreen = win->drawable.pScreen; - - sprite.hotPhys.pScreen = pScreen; - sprite.hotPhys.x = pScreen->width / 2; - sprite.hotPhys.y = pScreen->height / 2; - sprite.hot = sprite.hotPhys; - sprite.hotLimits.x2 = pScreen->width; - sprite.hotLimits.y2 = pScreen->height; -#ifdef XEVIE - xeviewin = -#endif - sprite.win = win; - sprite.current = wCursor (win); - sprite.current->refcnt++; - spriteTraceGood = 1; - ROOT = win; - (*pScreen->CursorLimits) ( - pScreen, sprite.current, &sprite.hotLimits, &sprite.physLimits); - sprite.confined = FALSE; - (*pScreen->ConstrainCursor) (pScreen, &sprite.physLimits); - (*pScreen->SetCursorPosition) (pScreen, sprite.hot.x, sprite.hot.y, FALSE); - (*pScreen->DisplayCursor) (pScreen, sprite.current); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotLimits.x1 = -panoramiXdataPtr[0].x; - sprite.hotLimits.y1 = -panoramiXdataPtr[0].y; - sprite.hotLimits.x2 = PanoramiXPixWidth - panoramiXdataPtr[0].x; - sprite.hotLimits.y2 = PanoramiXPixHeight - panoramiXdataPtr[0].y; - sprite.physLimits = sprite.hotLimits; - sprite.confineWin = NullWindow; -#ifdef SHAPE - sprite.hotShape = NullRegion; -#endif - sprite.screen = pScreen; - /* gotta UNINIT these someplace */ - REGION_NULL(pScreen, &sprite.Reg1); - REGION_NULL(pScreen, &sprite.Reg2); - } -#endif -} - -/* - * This does not take any shortcuts, and even ignores its argument, since - * it does not happen very often, and one has to walk up the tree since - * this might be a newly instantiated cursor for an intermediate window - * between the one the pointer is in and the one that the last cursor was - * instantiated from. - */ -void -WindowHasNewCursor(WindowPtr pWin) -{ - PostNewCursor(); -} - -void -NewCurrentScreen(ScreenPtr newScreen, int x, int y) -{ - sprite.hotPhys.x = x; - sprite.hotPhys.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - sprite.hotPhys.x += panoramiXdataPtr[newScreen->myNum].x - - panoramiXdataPtr[0].x; - sprite.hotPhys.y += panoramiXdataPtr[newScreen->myNum].y - - panoramiXdataPtr[0].y; - if (newScreen != sprite.screen) { - sprite.screen = newScreen; - /* Make sure we tell the DDX to update its copy of the screen */ - if(sprite.confineWin) - XineramaConfineCursorToWindow(sprite.confineWin, TRUE); - else - XineramaConfineCursorToWindow(WindowTable[0], TRUE); - /* if the pointer wasn't confined, the DDX won't get - told of the pointer warp so we reposition it here */ - if(!syncEvents.playingEvents) - (*sprite.screen->SetCursorPosition)(sprite.screen, - sprite.hotPhys.x + panoramiXdataPtr[0].x - - panoramiXdataPtr[sprite.screen->myNum].x, - sprite.hotPhys.y + panoramiXdataPtr[0].y - - panoramiXdataPtr[sprite.screen->myNum].y, FALSE); - } - } else -#endif - if (newScreen != sprite.hotPhys.pScreen) - ConfineCursorToWindow(WindowTable[newScreen->myNum], TRUE, FALSE); -} - -#ifdef PANORAMIX - -static Bool -XineramaPointInWindowIsVisible( - WindowPtr pWin, - int x, - int y -) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - BoxRec box; - int i, xoff, yoff; - - if (!pWin->realized) return FALSE; - - if (POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) - return TRUE; - - if(!XineramaSetWindowPntrs(pWin)) return FALSE; - - xoff = x + panoramiXdataPtr[0].x; - yoff = y + panoramiXdataPtr[0].y; - - for(i = 1; i < PanoramiXNumScreens; i++) { - pWin = sprite.windows[i]; - pScreen = pWin->drawable.pScreen; - x = xoff - panoramiXdataPtr[i].x; - y = yoff - panoramiXdataPtr[i].y; - - if(POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box) - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) - return TRUE; - - } - - return FALSE; -} - -static int -XineramaWarpPointer(ClientPtr client) -{ - WindowPtr dest = NULL; - int x, y; - - REQUEST(xWarpPointerReq); - - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if(source == WindowTable[0]) { - winX -= panoramiXdataPtr[0].x; - winY -= panoramiXdataPtr[0].y; - } - if (x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !XineramaPointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) { - x = dest->drawable.x; - y = dest->drawable.y; - if(dest == WindowTable[0]) { - x -= panoramiXdataPtr[0].x; - y -= panoramiXdataPtr[0].y; - } - } - - x += stuff->dstX; - y += stuff->dstY; - - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); - - XineramaSetCursorPosition(x, y, TRUE); - - return Success; -} - -#endif - - -int -ProcWarpPointer(ClientPtr client) -{ - WindowPtr dest = NULL; - int x, y; - ScreenPtr newScreen; - - REQUEST(xWarpPointerReq); - - REQUEST_SIZE_MATCH(xWarpPointerReq); - -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaWarpPointer(client); -#endif - - if (stuff->dstWid != None) - { - dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess); - if (!dest) - return BadWindow; - } - x = sprite.hotPhys.x; - y = sprite.hotPhys.y; - - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; - WindowPtr source; - - source = SecurityLookupWindow(winID, client, SecurityReadAccess); - if (!source) return BadWindow; - - winX = source->drawable.x; - winY = source->drawable.y; - if (source->drawable.pScreen != sprite.hotPhys.pScreen || - x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !PointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) - { - x = dest->drawable.x; - y = dest->drawable.y; - newScreen = dest->drawable.pScreen; - } else - newScreen = sprite.hotPhys.pScreen; - - x += stuff->dstX; - y += stuff->dstY; - - if (x < 0) - x = 0; - else if (x >= newScreen->width) - x = newScreen->width - 1; - if (y < 0) - y = 0; - else if (y >= newScreen->height) - y = newScreen->height - 1; - - if (newScreen == sprite.hotPhys.pScreen) - { - if (x < sprite.physLimits.x1) - x = sprite.physLimits.x1; - else if (x >= sprite.physLimits.x2) - x = sprite.physLimits.x2 - 1; - if (y < sprite.physLimits.y1) - y = sprite.physLimits.y1; - else if (y >= sprite.physLimits.y2) - y = sprite.physLimits.y2 - 1; -#if defined(SHAPE) - if (sprite.hotShape) - ConfineToShape(sprite.hotShape, &x, &y); -#endif - (*newScreen->SetCursorPosition)(newScreen, x, y, TRUE); - } - else if (!PointerConfinedToScreen()) - { - NewCurrentScreen(newScreen, x, y); - } - return Success; -} - -static Bool -BorderSizeNotEmpty(WindowPtr pWin) -{ - if(REGION_NOTEMPTY(sprite.hotPhys.pScreen, &pWin->borderSize)) - return TRUE; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pWin)) { - int i; - - for(i = 1; i < PanoramiXNumScreens; i++) { - if(REGION_NOTEMPTY(sprite.screen, &sprite.windows[i]->borderSize)) - return TRUE; - } - } -#endif - return FALSE; -} - -/* "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a - passive grab set on the window to be activated. */ - -static Bool -CheckPassiveGrabsOnWindow( - WindowPtr pWin, - register DeviceIntPtr device, - register xEvent *xE, - int count) -{ - register GrabPtr grab = wPassiveGrabs(pWin); - GrabRec tempGrab; - register xEvent *dxE; - - if (!grab) - return FALSE; - tempGrab.window = pWin; - tempGrab.device = device; - tempGrab.type = xE->u.u.type; - tempGrab.detail.exact = xE->u.u.detail; - tempGrab.detail.pMask = NULL; - tempGrab.modifiersDetail.pMask = NULL; - for (; grab; grab = grab->next) - { -#ifdef XKB - DeviceIntPtr gdev; - XkbSrvInfoPtr xkbi; - - gdev= grab->modifierDevice; - xkbi= gdev->key->xkbInfo; -#endif - tempGrab.modifierDevice = grab->modifierDevice; - if ((device == grab->modifierDevice) && - ((xE->u.u.type == KeyPress) -#if defined(XINPUT) && defined(XKB) - || (xE->u.u.type == DeviceKeyPress) -#endif - )) - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension?gdev->key->prev_state:xkbi->state.grab_mods); -#else - grab->modifierDevice->key->prev_state; -#endif - else - tempGrab.modifiersDetail.exact = -#ifdef XKB - (noXkbExtension ? gdev->key->state : xkbi->state.grab_mods); -#else - grab->modifierDevice->key->state; -#endif - if (GrabMatchesSecond(&tempGrab, grab) && - (!grab->confineTo || - (grab->confineTo->realized && - BorderSizeNotEmpty(grab->confineTo)))) - { -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(wClient(pWin), device, FALSE)) - return FALSE; -#endif -#ifdef XKB - if (!noXkbExtension) { - XE_KBPTR.state &= 0x1f00; - XE_KBPTR.state |= - tempGrab.modifiersDetail.exact&(~0x1f00); - } -#endif - (*device->ActivateGrab)(device, grab, currentTime, TRUE); - - FixUpEventFromWindow(xE, grab->window, None, TRUE); - - (void) TryClientEvents(rClient(grab), xE, count, - filters[xE->u.u.type], - filters[xE->u.u.type], grab); - - if (device->sync.state == FROZEN_NO_EVENT) - { - if (device->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - device->sync.event = (xEvent *)xrealloc(device->sync.event, - count* - sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - device->sync.evcount = count; - for (dxE = device->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - device->sync.state = FROZEN_WITH_EVENT; - } - return TRUE; - } - } - return FALSE; -} - -/** -"CheckDeviceGrabs" handles both keyboard and pointer events that may cause -a passive grab to be activated. If the event is a keyboard event, the -ancestors of the focus window are traced down and tried to see if they have -any passive grabs to be activated. If the focus window itself is reached and -it's descendants contain they pointer, the ancestors of the window that the -pointer is in are then traced down starting at the focus window, otherwise no -grabs are activated. If the event is a pointer event, the ancestors of the -window that the pointer is in are traced down starting at the root until -CheckPassiveGrabs causes a passive grab to activate or all the windows are -tried. PRH -*/ - -Bool -CheckDeviceGrabs(register DeviceIntPtr device, register xEvent *xE, - int checkFirst, int count) -{ - register int i; - register WindowPtr pWin = NULL; - register FocusClassPtr focus = device->focus; - - if (((xE->u.u.type == ButtonPress) -#if defined(XINPUT) && defined(XKB) - || (xE->u.u.type == DeviceButtonPress) -#endif - ) && (device->button->buttonsDown != 1)) - return FALSE; - - i = checkFirst; - - if (focus) - { - for (; i < focus->traceGood; i++) - { - pWin = focus->trace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - if ((focus->win == NoneWin) || - (i >= spriteTraceGood) || - ((i > checkFirst) && (pWin != spriteTrace[i-1]))) - return FALSE; - } - - for (; i < spriteTraceGood; i++) - { - pWin = spriteTrace[i]; - if (pWin->optional && - CheckPassiveGrabsOnWindow(pWin, device, xE, count)) - return TRUE; - } - - return FALSE; -} - -void -DeliverFocusedEvent(DeviceIntPtr keybd, xEvent *xE, WindowPtr window, int count) -{ - WindowPtr focus = keybd->focus->win; - int mskidx = 0; - - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - if (!focus) - return; - if (focus == PointerRootWin) - { - DeliverDeviceEvents(window, xE, NullGrab, NullWindow, keybd, count); - return; - } - if ((focus == window) || IsParent(focus, window)) - { - if (DeliverDeviceEvents(window, xE, NullGrab, focus, keybd, count)) - return; - } - /* just deliver it to the focus window */ - FixUpEventFromWindow(xE, focus, None, FALSE); - if (xE->u.u.type & EXTENSION_EVENT_BASE) - mskidx = keybd->id; - (void)DeliverEventsToWindow(focus, xE, count, filters[xE->u.u.type], - NullGrab, mskidx); -} - -void -DeliverGrabbedEvent(register xEvent *xE, register DeviceIntPtr thisDev, - Bool deactivateGrab, int count) -{ - register GrabPtr grab = thisDev->grab; - int deliveries = 0; - register DeviceIntPtr dev; - register xEvent *dxE; - - if (grab->ownerEvents) - { - WindowPtr focus; - - if (thisDev->focus) - { - focus = thisDev->focus->win; - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - } - else - focus = PointerRootWin; - if (focus == PointerRootWin) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, NullWindow, - thisDev, count); - else if (focus && (focus == sprite.win || IsParent(focus, sprite.win))) - deliveries = DeliverDeviceEvents(sprite.win, xE, grab, focus, - thisDev, count); - else if (focus) - deliveries = DeliverDeviceEvents(focus, xE, grab, focus, - thisDev, count); - } - if (!deliveries) - { - FixUpEventFromWindow(xE, grab->window, None, TRUE); - deliveries = TryClientEvents(rClient(grab), xE, count, - (Mask)grab->eventMask, - filters[xE->u.u.type], grab); - if (deliveries && (xE->u.u.type == MotionNotify -#ifdef XINPUT - || xE->u.u.type == DeviceMotionNotify -#endif - )) - thisDev->valuator->motionHintWindow = grab->window; - } - if (deliveries && !deactivateGrab && (xE->u.u.type != MotionNotify -#ifdef XINPUT - && xE->u.u.type != DeviceMotionNotify -#endif - )) - switch (thisDev->sync.state) - { - case FREEZE_BOTH_NEXT_EVENT: - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - FreezeThaw(dev, TRUE); - if ((dev->sync.state == FREEZE_BOTH_NEXT_EVENT) && - (CLIENT_BITS(dev->grab->resource) == - CLIENT_BITS(thisDev->grab->resource))) - dev->sync.state = FROZEN_NO_EVENT; - else - dev->sync.other = thisDev->grab; - } - /* fall through */ - case FREEZE_NEXT_EVENT: - thisDev->sync.state = FROZEN_WITH_EVENT; - FreezeThaw(thisDev, TRUE); - if (thisDev->sync.evcount < count) - { - Must_have_memory = TRUE; /* XXX */ - thisDev->sync.event = (xEvent *)xrealloc(thisDev->sync.event, - count*sizeof(xEvent)); - Must_have_memory = FALSE; /* XXX */ - } - thisDev->sync.evcount = count; - for (dxE = thisDev->sync.event; --count >= 0; dxE++, xE++) - *dxE = *xE; - break; - } -} - -void -#ifdef XKB -CoreProcessKeyboardEvent (register xEvent *xE, register DeviceIntPtr keybd, int count) -#else -ProcessKeyboardEvent (register xEvent *xE, register DeviceIntPtr keybd, int count) -#endif -{ - int key, bit; - register BYTE *kptr; - register int i; - register CARD8 modifiers; - register CARD16 mask; - GrabPtr grab = keybd->grab; - Bool deactivateGrab = FALSE; - register KeyClassPtr keyc = keybd->key; -#ifdef XEVIE - static Window rootWin = 0; - - if(!xeviegrabState && xevieFlag && clients[xevieClientIndex] && - (xevieMask & xevieFilters[xE->u.u.type])) { - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - if((xE->u.u.type == KeyPress && (*kptr & bit)) || - (xE->u.u.type == KeyRelease && !(*kptr & bit))) - {} else { -#ifdef XKB - if(!noXkbExtension) - xevieKBEventSent = 1; -#endif - if(!xevieKBEventSent) - { - xeviekb = keybd; - if(!rootWin) { - rootWin = GetCurrentRootWindow()->drawable.id; - } - xE->u.keyButtonPointer.event = xeviewin->drawable.id; - xE->u.keyButtonPointer.root = rootWin; - xE->u.keyButtonPointer.child = (xeviewin->firstChild) ? xeviewin->firstChild-> -drawable.id:0; - xE->u.keyButtonPointer.rootX = xeviehot.x; - xE->u.keyButtonPointer.rootY = xeviehot.y; - xE->u.keyButtonPointer.state = keyc->state; - WriteToClient(clients[xevieClientIndex], sizeof(xEvent), (char *)xE); -#ifdef XKB - if(noXkbExtension) -#endif - return; - } else { - xevieKBEventSent = 0; - } - } - } -#endif - - if (!syncEvents.playingEvents) - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } -#ifdef XEVIE - /* fix for bug5094030: don't change the state bit if the event is from XEvIE client */ - if(!(!xeviegrabState && xevieFlag && clients[xevieClientIndex] && - (xevieMask & xevieFilters[xE->u.u.type] -#ifdef XKB - && !noXkbExtension -#endif - ))) -#endif - XE_KBPTR.state = (keyc->state | inputInfo.pointer->button->state); - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - modifiers = keyc->modifierMap[key]; -#if defined(XKB) && defined(XEVIE) - if(!noXkbExtension && !xeviegrabState && - xevieFlag && clients[xevieClientIndex] && - (xevieMask & xevieFilters[xE->u.u.type])) { - switch(xE->u.u.type) { - case KeyPress: *kptr &= ~bit; break; - case KeyRelease: *kptr |= bit; break; - } - } -#endif - -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("CoreProcessKbdEvent: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - if (*kptr & bit) /* allow ddx to generate multiple downs */ - { - if (!modifiers) - { - xE->u.u.type = KeyRelease; - (*keybd->public.processInputProc)(xE, keybd, count); - xE->u.u.type = KeyPress; - /* release can have side effects, don't fall through */ - (*keybd->public.processInputProc)(xE, keybd, count); - } - return; - } - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr |= bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) - { - /* This key affects modifier "i" */ - keyc->modifierKeyCount[i]++; - keyc->state |= mask; - modifiers &= ~mask; - } - } - if (!grab && CheckDeviceGrabs(keybd, xE, 0, count)) - { - keybd->activatingKey = key; - return; - } - break; - case KeyRelease: - if (!(*kptr & bit)) /* guard against duplicates */ - return; - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - *kptr &= ~bit; - keyc->prev_state = keyc->state; - for (i = 0, mask = 1; modifiers; i++, mask <<= 1) - { - if (mask & modifiers) { - /* This key affects modifier "i" */ - if (--keyc->modifierKeyCount[i] <= 0) { - keyc->state &= ~mask; - keyc->modifierKeyCount[i] = 0; - } - modifiers &= ~mask; - } - } - if (keybd->fromPassiveGrab && (key == keybd->activatingKey)) - deactivateGrab = TRUE; - break; - default: - FatalError("Impossible keyboard event"); - } - if (grab) - DeliverGrabbedEvent(xE, keybd, deactivateGrab, count); - else - DeliverFocusedEvent(keybd, xE, sprite.win, count); - if (deactivateGrab) - (*keybd->DeactivateGrab)(keybd); -} - -#ifdef XKB -/* This function is used to set the key pressed or key released state - - this is only used when the pressing of keys does not cause - CoreProcessKeyEvent to be called, as in for example Mouse Keys. -*/ -void -FixKeyState (register xEvent *xE, register DeviceIntPtr keybd) -{ - int key, bit; - register BYTE *kptr; - register KeyClassPtr keyc = keybd->key; - - key = xE->u.u.detail; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); -#ifdef DEBUG - if ((xkbDebugFlags&0x4)&& - ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) { - ErrorF("FixKeyState: Key %d %s\n",key, - (xE->u.u.type==KeyPress?"down":"up")); - } -#endif - switch (xE->u.u.type) - { - case KeyPress: - *kptr |= bit; - break; - case KeyRelease: - *kptr &= ~bit; - break; - default: - FatalError("Impossible keyboard event"); - } -} -#endif - -void -#ifdef XKB -CoreProcessPointerEvent (register xEvent *xE, register DeviceIntPtr mouse, int count) -#else -ProcessPointerEvent (register xEvent *xE, register DeviceIntPtr mouse, int count) -#endif -{ - register GrabPtr grab = mouse->grab; - Bool deactivateGrab = FALSE; - register ButtonClassPtr butc = mouse->button; -#ifdef XKB - XkbSrvInfoPtr xkbi= inputInfo.keyboard->key->xkbInfo; -#endif -#ifdef XEVIE - if(xevieFlag && clients[xevieClientIndex] && !xeviegrabState && - (xevieMask & xevieFilters[xE->u.u.type])) { - if(xevieEventSent) - xevieEventSent = 0; - else { - xeviemouse = mouse; - WriteToClient(clients[xevieClientIndex], sizeof(xEvent), (char *)xE); - return; - } - } -#endif - - if (!syncEvents.playingEvents) - NoticeTime(xE) - XE_KBPTR.state = (butc->state | ( -#ifdef XKB - (noXkbExtension ? - inputInfo.keyboard->key->state : - xkbi->state.grab_mods) -#else - inputInfo.keyboard->key->state -#endif - )); - { - NoticeTime(xE); - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - /* see comment in EnqueueEvents regarding the next three lines */ - if (xE->u.u.type == MotionNotify) - XE_KBPTR.root = - WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id; - eventinfo.events = xE; - eventinfo.count = count; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - } - if (xE->u.u.type != MotionNotify) - { - register int key; - register BYTE *kptr; - int bit; - - XE_KBPTR.rootX = sprite.hot.x; - XE_KBPTR.rootY = sprite.hot.y; - - key = xE->u.u.detail; - kptr = &butc->down[key >> 3]; - bit = 1 << (key & 7); - switch (xE->u.u.type) - { - case ButtonPress: - mouse->valuator->motionHintWindow = NullWindow; - if (!(*kptr & bit)) - butc->buttonsDown++; - butc->motionMask = ButtonMotionMask; - *kptr |= bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - if (xE->u.u.detail == 0) - return; - if (xE->u.u.detail <= 5) - butc->state |= (Button1Mask >> 1) << xE->u.u.detail; - filters[MotionNotify] = Motion_Filter(butc); - if (!grab) - if (CheckDeviceGrabs(mouse, xE, 0, count)) - return; - break; - case ButtonRelease: - mouse->valuator->motionHintWindow = NullWindow; - if (*kptr & bit) - --butc->buttonsDown; - if (!butc->buttonsDown) - butc->motionMask = 0; - *kptr &= ~bit; -#if !defined(XFree86Server) || !defined(XINPUT) - xE->u.u.detail = butc->map[key]; -#endif - if (xE->u.u.detail == 0) - return; - if (xE->u.u.detail <= 5) - butc->state &= ~((Button1Mask >> 1) << xE->u.u.detail); - filters[MotionNotify] = Motion_Filter(butc); - if (!butc->state && mouse->fromPassiveGrab) - deactivateGrab = TRUE; - break; - default: - FatalError("bogus pointer event from ddx"); - } - } - else if (!CheckMotion(xE)) - return; - if (grab) - DeliverGrabbedEvent(xE, mouse, deactivateGrab, count); - else - DeliverDeviceEvents(sprite.win, xE, NullGrab, NullWindow, - mouse, count); - if (deactivateGrab) - (*mouse->DeactivateGrab)(mouse); -} - -#define AtMostOneClient \ - (SubstructureRedirectMask | ResizeRedirectMask | ButtonPressMask) - -void -RecalculateDeliverableEvents(pWin) - register WindowPtr pWin; -{ - register OtherClients *others; - register WindowPtr pChild; - - pChild = pWin; - while (1) - { - if (pChild->optional) - { - pChild->optional->otherEventMasks = 0; - for (others = wOtherClients(pChild); others; others = others->next) - { - pChild->optional->otherEventMasks |= others->mask; - } - } - pChild->deliverableEvents = pChild->eventMask| - wOtherEventMasks(pChild); - if (pChild->parent) - pChild->deliverableEvents |= - (pChild->parent->deliverableEvents & - ~wDontPropagateMask(pChild) & PropagateMask); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -/** - * - * \param value must conform to DeleteType - */ -int -OtherClientGone(pointer value, XID id) -{ - register OtherClientsPtr other, prev; - register WindowPtr pWin = (WindowPtr)value; - - prev = 0; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->resource == id) - { - if (prev) - prev->next = other->next; - else - { - if (!(pWin->optional->otherClients = other->next)) - CheckWindowOptionalNeed (pWin); - } - xfree(other); - RecalculateDeliverableEvents(pWin); - return(Success); - } - prev = other; - } - FatalError("client not on event list"); - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} - -int -EventSelectForWindow(register WindowPtr pWin, register ClientPtr client, Mask mask) -{ - Mask check; - OtherClients * others; - - if (mask & ~AllEventMasks) - { - client->errorValue = mask; - return BadValue; - } - check = (mask & AtMostOneClient); - if (check & (pWin->eventMask|wOtherEventMasks(pWin))) - { /* It is illegal for two different - clients to select on any of the - events for AtMostOneClient. However, - it is OK, for some client to - continue selecting on one of those - events. */ - if ((wClient(pWin) != client) && (check & pWin->eventMask)) - return BadAccess; - for (others = wOtherClients (pWin); others; others = others->next) - { - if (!SameClient(others, client) && (check & others->mask)) - return BadAccess; - } - } - if (wClient (pWin) == client) - { - check = pWin->eventMask; -#ifdef SGIMISC - pWin->eventMask = - (mask & ~SGIMiscSpecialDestroyMask) | (pWin->eventMask & SGIMiscSpecialDestroyMask); -#else - pWin->eventMask = mask; -#endif - } - else - { - for (others = wOtherClients (pWin); others; others = others->next) - { - if (SameClient(others, client)) - { - check = others->mask; -#ifdef SGIMISC - mask = (mask & ~SGIMiscSpecialDestroyMask) | (others->mask & SGIMiscSpecialDestroyMask); -#endif - if (mask == 0) - { - FreeResource(others->resource, RT_NONE); - return Success; - } - else - others->mask = mask; - goto maskSet; - } - } - check = 0; - if (!pWin->optional && !MakeWindowOptional (pWin)) - return BadAlloc; - others = (OtherClients *) xalloc(sizeof(OtherClients)); - if (!others) - return BadAlloc; - others->mask = mask; - others->resource = FakeClientID(client->index); - others->next = pWin->optional->otherClients; - pWin->optional->otherClients = others; - if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer)pWin)) - return BadAlloc; - } -maskSet: - if ((inputInfo.pointer->valuator->motionHintWindow == pWin) && - (mask & PointerMotionHintMask) && - !(check & PointerMotionHintMask) && - !inputInfo.pointer->grab) - inputInfo.pointer->valuator->motionHintWindow = NullWindow; - RecalculateDeliverableEvents(pWin); - return Success; -} - -int -EventSuppressForWindow(register WindowPtr pWin, register ClientPtr client, - Mask mask, Bool *checkOptional) -{ - register int i, free; - - if ((mask & ~PropagateMask) && !permitOldBugs) - { - client->errorValue = mask; - return BadValue; - } - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - if (!mask) - i = 0; - else - { - for (i = DNPMCOUNT, free = 0; --i > 0; ) - { - if (!DontPropagateRefCnts[i]) - free = i; - else if (mask == DontPropagateMasks[i]) - break; - } - if (!i && free) - { - i = free; - DontPropagateMasks[i] = mask; - } - } - if (i || !mask) - { - pWin->dontPropagate = i; - if (i) - DontPropagateRefCnts[i]++; - if (pWin->optional) - { - pWin->optional->dontPropagateMask = mask; - *checkOptional = TRUE; - } - } - else - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]++; - return BadAlloc; - } - pWin->dontPropagate = 0; - pWin->optional->dontPropagateMask = mask; - } - RecalculateDeliverableEvents(pWin); - return Success; -} - -static WindowPtr -CommonAncestor( - register WindowPtr a, - register WindowPtr b) -{ - for (b = b->parent; b; b = b->parent) - if (IsParent(b, a)) return b; - return NullWindow; -} - -static void -EnterLeaveEvent( - int type, - int mode, - int detail, - register WindowPtr pWin, - Window child) -{ - xEvent event; - register DeviceIntPtr keybd = inputInfo.keyboard; - WindowPtr focus; - register DeviceIntPtr mouse = inputInfo.pointer; - register GrabPtr grab = mouse->grab; - Mask mask; - - if ((pWin == mouse->valuator->motionHintWindow) && - (detail != NotifyInferior)) - mouse->valuator->motionHintWindow = NullWindow; - if (grab) - { - mask = (pWin == grab->window) ? grab->eventMask : 0; - if (grab->ownerEvents) - mask |= EventMaskForClient(pWin, rClient(grab)); - } - else - { - mask = pWin->eventMask | wOtherEventMasks(pWin); - } - if (mask & filters[type]) - { - event.u.u.type = type; - event.u.u.detail = detail; - event.u.enterLeave.time = currentTime.milliseconds; - event.u.enterLeave.rootX = sprite.hot.x; - event.u.enterLeave.rootY = sprite.hot.y; - /* Counts on the same initial structure of crossing & button events! */ - FixUpEventFromWindow(&event, pWin, None, FALSE); - /* Enter/Leave events always set child */ - event.u.enterLeave.child = child; - event.u.enterLeave.flags = event.u.keyButtonPointer.sameScreen ? - ELFlagSameScreen : 0; -#ifdef XKB - if (!noXkbExtension) { - event.u.enterLeave.state = mouse->button->state & 0x1f00; - event.u.enterLeave.state |= - XkbGrabStateFromRec(&keybd->key->xkbInfo->state); - } else -#endif - event.u.enterLeave.state = keybd->key->state | mouse->button->state; - event.u.enterLeave.mode = mode; - focus = keybd->focus->win; - if ((focus != NoneWin) && - ((pWin == focus) || (focus == PointerRootWin) || - IsParent(focus, pWin))) - event.u.enterLeave.flags |= ELFlagFocus; - if (grab) - (void)TryClientEvents(rClient(grab), &event, 1, mask, - filters[type], grab); - else - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], - NullGrab, 0); - } - if ((type == EnterNotify) && (mask & KeymapStateMask)) - { - xKeymapEvent ke; - -#ifdef XCSECURITY - ClientPtr client = grab ? rClient(grab) - : clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, keybd, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31); - ke.type = KeymapNotify; - if (grab) - (void)TryClientEvents(rClient(grab), (xEvent *)&ke, 1, mask, - KeymapStateMask, grab); - else - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - -static void -EnterNotifies(WindowPtr ancestor, WindowPtr child, int mode, int detail) -{ - WindowPtr parent = child->parent; - - if (ancestor == parent) - return; - EnterNotifies(ancestor, parent, mode, detail); - EnterLeaveEvent(EnterNotify, mode, detail, parent, child->drawable.id); -} - -static void -LeaveNotifies(WindowPtr child, WindowPtr ancestor, int mode, int detail) -{ - register WindowPtr pWin; - - if (ancestor == child) - return; - for (pWin = child->parent; pWin != ancestor; pWin = pWin->parent) - { - EnterLeaveEvent(LeaveNotify, mode, detail, pWin, child->drawable.id); - child = pWin; - } -} - -static void -DoEnterLeaveEvents(WindowPtr fromWin, WindowPtr toWin, int mode) -{ - if (fromWin == toWin) - return; - if (IsParent(fromWin, toWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyInferior, fromWin, None); - EnterNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyAncestor, toWin, None); - } - else if (IsParent(toWin, fromWin)) - { - EnterLeaveEvent(LeaveNotify, mode, NotifyAncestor, fromWin, None); - LeaveNotifies(fromWin, toWin, mode, NotifyVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyInferior, toWin, None); - } - else - { /* neither fromWin nor toWin is descendent of the other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - EnterLeaveEvent(LeaveNotify, mode, NotifyNonlinear, fromWin, None); - LeaveNotifies(fromWin, common, mode, NotifyNonlinearVirtual); - EnterNotifies(common, toWin, mode, NotifyNonlinearVirtual); - EnterLeaveEvent(EnterNotify, mode, NotifyNonlinear, toWin, None); - } -} - -static void -FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, register WindowPtr pWin) -{ - xEvent event; - -#ifdef XINPUT - if (dev != inputInfo.keyboard) - { - DeviceFocusEvent(dev, type, mode, detail, pWin); - return; - } -#endif - event.u.focus.mode = mode; - event.u.u.type = type; - event.u.u.detail = detail; - event.u.focus.window = pWin->drawable.id; - (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], NullGrab, - 0); - if ((type == FocusIn) && - ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) - { - xKeymapEvent ke; -#ifdef XCSECURITY - ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)]; - if (!SecurityCheckDeviceAccess(client, dev, FALSE)) - { - bzero((char *)&ke.map[0], 31); - } - else -#endif - memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31); - ke.type = KeymapNotify; - (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab, 0); - } -} - - /* - * recursive because it is easier - * no-op if child not descended from ancestor - */ -static Bool -FocusInEvents( - DeviceIntPtr dev, - WindowPtr ancestor, WindowPtr child, WindowPtr skipChild, - int mode, int detail, - Bool doAncestor) -{ - if (child == NullWindow) - return ancestor == NullWindow; - if (ancestor == child) - { - if (doAncestor) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - if (FocusInEvents(dev, ancestor, child->parent, skipChild, mode, detail, - doAncestor)) - { - if (child != skipChild) - FocusEvent(dev, FocusIn, mode, detail, child); - return TRUE; - } - return FALSE; -} - -/* dies horribly if ancestor is not an ancestor of child */ -static void -FocusOutEvents( - DeviceIntPtr dev, - WindowPtr child, WindowPtr ancestor, - int mode, int detail, - Bool doAncestor) -{ - register WindowPtr pWin; - - for (pWin = child; pWin != ancestor; pWin = pWin->parent) - FocusEvent(dev, FocusOut, mode, detail, pWin); - if (doAncestor) - FocusEvent(dev, FocusOut, mode, detail, ancestor); -} - -void -DoFocusEvents(DeviceIntPtr dev, WindowPtr fromWin, WindowPtr toWin, int mode) -{ - int out, in; /* for holding details for to/from - PointerRoot/None */ - int i; - - if (fromWin == toWin) - return; - out = (fromWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - in = (toWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot; - /* wrong values if neither, but then not referenced */ - - if ((toWin == NullWindow) || (toWin == PointerRootWin)) - { - if ((fromWin == NullWindow) || (fromWin == PointerRootWin)) - { - if (fromWin == PointerRootWin) - FocusOutEvents(dev, sprite.win, ROOT, mode, NotifyPointer, - TRUE); - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusOut, mode, out, WindowTable[0]); - else -#endif - for (i=0; iparent, NullWindow, mode, - NotifyNonlinearVirtual, FALSE); - } - /* Notify all the roots */ -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - FocusEvent(dev, FocusIn, mode, in, WindowTable[0]); - else -#endif - for (i=0; iparent != NullWindow) - (void)FocusInEvents(dev, ROOT, toWin, toWin, mode, - NotifyNonlinearVirtual, TRUE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, mode, - NotifyPointer, FALSE); - } - else - { - if (IsParent(toWin, fromWin)) - { - FocusEvent(dev, FocusOut, mode, NotifyAncestor, fromWin); - FocusOutEvents(dev, fromWin->parent, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyInferior, toWin); - if ((IsParent(toWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(fromWin, sprite.win)) && - (!IsParent(sprite.win, fromWin))) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - else - if (IsParent(fromWin, toWin)) - { - if ((IsParent(fromWin, sprite.win)) && - (sprite.win != fromWin) && - (!IsParent(toWin, sprite.win)) && - (!IsParent(sprite.win, toWin))) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyInferior, fromWin); - (void)FocusInEvents(dev, fromWin, toWin, toWin, mode, - NotifyVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyAncestor, toWin); - } - else - { - /* neither fromWin or toWin is child of other */ - WindowPtr common = CommonAncestor(toWin, fromWin); - /* common == NullWindow ==> different screens */ - if (IsParent(fromWin, sprite.win)) - FocusOutEvents(dev, sprite.win, fromWin, mode, - NotifyPointer, FALSE); - FocusEvent(dev, FocusOut, mode, NotifyNonlinear, fromWin); - if (fromWin->parent != NullWindow) - FocusOutEvents(dev, fromWin->parent, common, mode, - NotifyNonlinearVirtual, FALSE); - if (toWin->parent != NullWindow) - (void)FocusInEvents(dev, common, toWin, toWin, mode, - NotifyNonlinearVirtual, FALSE); - FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin); - if (IsParent(toWin, sprite.win)) - (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, - mode, NotifyPointer, FALSE); - } - } - } -} - -int -SetInputFocus( - ClientPtr client, - DeviceIntPtr dev, - Window focusID, - CARD8 revertTo, - Time ctime, - Bool followOK) -{ - register FocusClassPtr focus; - register WindowPtr focusWin; - int mode; - TimeStamp time; - - UpdateCurrentTime(); - if ((revertTo != RevertToParent) && - (revertTo != RevertToPointerRoot) && - (revertTo != RevertToNone) && - ((revertTo != RevertToFollowKeyboard) || !followOK)) - { - client->errorValue = revertTo; - return BadValue; - } - time = ClientTimeToServerTime(ctime); - if ((focusID == None) || (focusID == PointerRoot)) - focusWin = (WindowPtr)(long)focusID; - else if ((focusID == FollowKeyboard) && followOK) - focusWin = inputInfo.keyboard->focus->win; - else if (!(focusWin = SecurityLookupWindow(focusID, client, - SecurityReadAccess))) - return BadWindow; - else - { - /* It is a match error to try to set the input focus to an - unviewable window. */ - - if(!focusWin->realized) - return(BadMatch); - } - focus = dev->focus; - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, focus->time) == EARLIER)) - return Success; - mode = (dev->grab) ? NotifyWhileGrabbed : NotifyNormal; - if (focus->win == FollowKeyboardWin) - DoFocusEvents(dev, inputInfo.keyboard->focus->win, focusWin, mode); - else - DoFocusEvents(dev, focus->win, focusWin, mode); - focus->time = time; - focus->revert = revertTo; - if (focusID == FollowKeyboard) - focus->win = FollowKeyboardWin; - else - focus->win = focusWin; - if ((focusWin == NoneWin) || (focusWin == PointerRootWin)) - focus->traceGood = 0; - else - { - int depth = 0; - register WindowPtr pWin; - - for (pWin = focusWin; pWin; pWin = pWin->parent) depth++; - if (depth > focus->traceSize) - { - focus->traceSize = depth+1; - Must_have_memory = TRUE; /* XXX */ - focus->trace = (WindowPtr *)xrealloc(focus->trace, - focus->traceSize * - sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ - } - focus->traceGood = depth; - for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) - focus->trace[depth] = pWin; - } - return Success; -} - -int -ProcSetInputFocus(client) - ClientPtr client; -{ - REQUEST(xSetInputFocusReq); - - REQUEST_SIZE_MATCH(xSetInputFocusReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - return Success; -#endif - return SetInputFocus(client, inputInfo.keyboard, stuff->focus, - stuff->revertTo, stuff->time, FALSE); -} - -int -ProcGetInputFocus(ClientPtr client) -{ - xGetInputFocusReply rep; - /* REQUEST(xReq); */ - FocusClassPtr focus = inputInfo.keyboard->focus; - - REQUEST_SIZE_MATCH(xReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - if (focus->win == NoneWin) - rep.focus = None; - else if (focus->win == PointerRootWin) - rep.focus = PointerRoot; - else rep.focus = focus->win->drawable.id; - rep.revertTo = focus->revert; - WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep); - return Success; -} - -int -ProcGrabPointer(ClientPtr client) -{ - xGrabPointerReply rep; - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - WindowPtr pWin, confineTo; - CursorPtr cursor, oldCursor; - REQUEST(xGrabPointerReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xGrabPointerReq); - UpdateCurrentTime(); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else - { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - /* at this point, some sort of reply is guaranteed. */ - time = ClientTimeToServerTime(stuff->time); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - grab = device->grab; - if ((grab) && !SameClient(grab, client)) - rep.status = AlreadyGrabbed; - else if ((!pWin->realized) || - (confineTo && - !(confineTo->realized && BorderSizeNotEmpty(confineTo)))) - rep.status = GrabNotViewable; - else if (device->sync.frozen && - device->sync.other && !SameClient(device->sync.other, client)) - rep.status = GrabFrozen; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - rep.status = GrabInvalidTime; - else - { - GrabRec tempGrab; - - oldCursor = NullCursor; - if (grab) - { - if (grab->confineTo && !confineTo) - ConfineCursorToWindow(ROOT, FALSE, FALSE); - oldCursor = grab->cursor; - } - tempGrab.cursor = cursor; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = stuff->ownerEvents; - tempGrab.eventMask = stuff->eventMask; - tempGrab.confineTo = confineTo; - tempGrab.window = pWin; - tempGrab.keyboardMode = stuff->keyboardMode; - tempGrab.pointerMode = stuff->pointerMode; - tempGrab.device = device; - (*device->ActivateGrab)(device, &tempGrab, time, FALSE); - if (oldCursor) - FreeCursor (oldCursor, (Cursor)0); - rep.status = GrabSuccess; - } - WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep); - return Success; -} - -int -ProcChangeActivePointerGrab(ClientPtr client) -{ - DeviceIntPtr device = inputInfo.pointer; - register GrabPtr grab = device->grab; - CursorPtr newCursor, oldCursor; - REQUEST(xChangeActivePointerGrabReq); - TimeStamp time; - - REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq); - if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - if (stuff->cursor == None) - newCursor = NullCursor; - else - { - newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!newCursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - if (!grab) - return Success; - if (!SameClient(grab, client)) - return Success; - time = ClientTimeToServerTime(stuff->time); - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->grabTime) == EARLIER)) - return Success; - oldCursor = grab->cursor; - grab->cursor = newCursor; - if (newCursor) - newCursor->refcnt++; - PostNewCursor(); - if (oldCursor) - FreeCursor(oldCursor, (Cursor)0); - grab->eventMask = stuff->eventMask; - return Success; -} - -int -ProcUngrabPointer(ClientPtr client) -{ - DeviceIntPtr device = inputInfo.pointer; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->DeactivateGrab)(device); - return Success; -} - -int -GrabDevice(register ClientPtr client, register DeviceIntPtr dev, - unsigned this_mode, unsigned other_mode, Window grabWindow, - unsigned ownerEvents, Time ctime, Mask mask, CARD8 *status) -{ - register WindowPtr pWin; - register GrabPtr grab; - TimeStamp time; - - UpdateCurrentTime(); - if ((this_mode != GrabModeSync) && (this_mode != GrabModeAsync)) - { - client->errorValue = this_mode; - return BadValue; - } - if ((other_mode != GrabModeSync) && (other_mode != GrabModeAsync)) - { - client->errorValue = other_mode; - return BadValue; - } - if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) - { - client->errorValue = ownerEvents; - return BadValue; - } - pWin = SecurityLookupWindow(grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - time = ClientTimeToServerTime(ctime); - grab = dev->grab; - if (grab && !SameClient(grab, client)) - *status = AlreadyGrabbed; - else if (!pWin->realized) - *status = GrabNotViewable; - else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, dev->grabTime) == EARLIER)) - *status = GrabInvalidTime; - else if (dev->sync.frozen && - dev->sync.other && !SameClient(dev->sync.other, client)) - *status = GrabFrozen; - else - { - GrabRec tempGrab; - - tempGrab.window = pWin; - tempGrab.resource = client->clientAsMask; - tempGrab.ownerEvents = ownerEvents; - tempGrab.keyboardMode = this_mode; - tempGrab.pointerMode = other_mode; - tempGrab.eventMask = mask; - tempGrab.device = dev; - (*dev->ActivateGrab)(dev, &tempGrab, time, FALSE); - *status = GrabSuccess; - } - return Success; -} - -int -ProcGrabKeyboard(ClientPtr client) -{ - xGrabKeyboardReply rep; - REQUEST(xGrabKeyboardReq); - int result; - - REQUEST_SIZE_MATCH(xGrabKeyboardReq); -#ifdef XCSECURITY - if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE)) - { - result = Success; - rep.status = AlreadyGrabbed; - } - else -#endif - result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode, - stuff->pointerMode, stuff->grabWindow, - stuff->ownerEvents, stuff->time, - KeyPressMask | KeyReleaseMask, &rep.status); - if (result != Success) - return result; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep); - return Success; -} - -int -ProcUngrabKeyboard(ClientPtr client) -{ - DeviceIntPtr device = inputInfo.keyboard; - GrabPtr grab; - TimeStamp time; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - UpdateCurrentTime(); - grab = device->grab; - time = ClientTimeToServerTime(stuff->id); - if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->DeactivateGrab)(device); - return Success; -} - -int -ProcQueryPointer(ClientPtr client) -{ - xQueryPointerReply rep; - WindowPtr pWin, t; - REQUEST(xResourceReq); - DeviceIntPtr mouse = inputInfo.pointer; - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = SecurityLookupWindow(stuff->id, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (mouse->valuator->motionHintWindow) - MaybeStopHint(mouse, client); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.mask = mouse->button->state | inputInfo.keyboard->key->state; - rep.length = 0; - rep.root = (ROOT)->drawable.id; - rep.rootX = sprite.hot.x; - rep.rootY = sprite.hot.y; - rep.child = None; - if (sprite.hot.pScreen == pWin->drawable.pScreen) - { - rep.sameScreen = xTrue; - rep.winX = sprite.hot.x - pWin->drawable.x; - rep.winY = sprite.hot.y - pWin->drawable.y; - for (t = sprite.win; t; t = t->parent) - if (t->parent == pWin) - { - rep.child = t->drawable.id; - break; - } - } - else - { - rep.sameScreen = xFalse; - rep.winX = 0; - rep.winY = 0; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - rep.rootX += panoramiXdataPtr[0].x; - rep.rootY += panoramiXdataPtr[0].y; - if(stuff->id == rep.root) { - rep.winX += panoramiXdataPtr[0].x; - rep.winY += panoramiXdataPtr[0].y; - } - } -#endif - - WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep); - - return(Success); -} - -void -InitEvents() -{ - int i; - - sprite.hot.pScreen = sprite.hotPhys.pScreen = (ScreenPtr)NULL; - inputInfo.numDevices = 0; - inputInfo.devices = (DeviceIntPtr)NULL; - inputInfo.off_devices = (DeviceIntPtr)NULL; - inputInfo.keyboard = (DeviceIntPtr)NULL; - inputInfo.pointer = (DeviceIntPtr)NULL; - if (spriteTraceSize == 0) - { - spriteTraceSize = 32; - spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr)); - if (!spriteTrace) - FatalError("failed to allocate spriteTrace"); - } - spriteTraceGood = 0; - lastEventMask = OwnerGrabButtonMask; - filters[MotionNotify] = PointerMotionMask; -#ifdef XEVIE - xeviewin = -#endif - sprite.win = NullWindow; - sprite.current = NullCursor; - sprite.hotLimits.x1 = 0; - sprite.hotLimits.y1 = 0; - sprite.hotLimits.x2 = 0; - sprite.hotLimits.y2 = 0; - sprite.confined = FALSE; - syncEvents.replayDev = (DeviceIntPtr)NULL; - syncEvents.replayWin = NullWindow; - while (syncEvents.pending) - { - QdEventPtr next = syncEvents.pending->next; - xfree(syncEvents.pending); - syncEvents.pending = next; - } - syncEvents.pendtail = &syncEvents.pending; - syncEvents.playingEvents = FALSE; - syncEvents.time.months = 0; - syncEvents.time.milliseconds = 0; /* hardly matters */ - currentTime.months = 0; - currentTime.milliseconds = GetTimeInMillis(); - lastDeviceEventTime = currentTime; - for (i = 0; i < DNPMCOUNT; i++) - { - DontPropagateMasks[i] = 0; - DontPropagateRefCnts[i] = 0; - } -} - -void -CloseDownEvents(void) -{ - xfree(spriteTrace); - spriteTrace = NULL; - spriteTraceSize = 0; -} - -int -ProcSendEvent(ClientPtr client) -{ - WindowPtr pWin; - WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */ - REQUEST(xSendEventReq); - - REQUEST_SIZE_MATCH(xSendEventReq); - - /* The client's event type must be a core event type or one defined by an - extension. */ - - if ( ! ((stuff->event.u.u.type > X_Reply && - stuff->event.u.u.type < LASTEvent) || - (stuff->event.u.u.type >= EXTENSION_EVENT_BASE && - stuff->event.u.u.type < (unsigned)lastEvent))) - { - client->errorValue = stuff->event.u.u.type; - return BadValue; - } - if (stuff->event.u.u.type == ClientMessage && - stuff->event.u.u.detail != 8 && - stuff->event.u.u.detail != 16 && - stuff->event.u.u.detail != 32 && - !permitOldBugs) - { - client->errorValue = stuff->event.u.u.detail; - return BadValue; - } - if ((stuff->eventMask & ~AllEventMasks) && !permitOldBugs) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - - if (stuff->destination == PointerWindow) - pWin = sprite.win; - else if (stuff->destination == InputFocus) - { - WindowPtr inputFocus = inputInfo.keyboard->focus->win; - - if (inputFocus == NoneWin) - return Success; - - /* If the input focus is PointerRootWin, send the event to where - the pointer is if possible, then perhaps propogate up to root. */ - if (inputFocus == PointerRootWin) - inputFocus = ROOT; - - if (IsParent(inputFocus, sprite.win)) - { - effectiveFocus = inputFocus; - pWin = sprite.win; - } - else - effectiveFocus = pWin = inputFocus; - } - else - pWin = SecurityLookupWindow(stuff->destination, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue)) - { - client->errorValue = stuff->propagate; - return BadValue; - } - stuff->event.u.u.type |= 0x80; - if (stuff->propagate) - { - for (;pWin; pWin = pWin->parent) - { - if (DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0)) - return Success; - if (pWin == effectiveFocus) - return Success; - stuff->eventMask &= ~wDontPropagateMask(pWin); - if (!stuff->eventMask) - break; - } - } - else - (void)DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask, - NullGrab, 0); - return Success; -} - -int -ProcUngrabKey(ClientPtr client) -{ - REQUEST(xUngrabKeyReq); - WindowPtr pWin; - GrabRec tempGrab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xUngrabKeyReq); - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - tempGrab.resource = client->clientAsMask; - tempGrab.device = keybd; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = KeyPress; - tempGrab.detail.exact = stuff->key; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -int -ProcGrabKey(ClientPtr client) -{ - WindowPtr pWin; - REQUEST(xGrabKeyReq); - GrabPtr grab; - DeviceIntPtr keybd = inputInfo.keyboard; - - REQUEST_SIZE_MATCH(xGrabKeyReq); - if ((stuff->ownerEvents != xTrue) && (stuff->ownerEvents != xFalse)) - { - client->errorValue = stuff->ownerEvents; - return(BadValue); - } - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) || - (stuff->key < keybd->key->curKeySyms.minKeyCode)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - - grab = CreateGrab(client->index, keybd, pWin, - (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents, - (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode, - keybd, stuff->modifiers, KeyPress, stuff->key, - NullWindow, NullCursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - - -int -ProcGrabButton(ClientPtr client) -{ - WindowPtr pWin, confineTo; - REQUEST(xGrabButtonReq); - CursorPtr cursor; - GrabPtr grab; - - REQUEST_SIZE_MATCH(xGrabButtonReq); - if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; - return BadValue; - } - if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; - return BadValue; - } - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; - } - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - if (stuff->confineTo == None) - confineTo = NullWindow; - else { - confineTo = SecurityLookupWindow(stuff->confineTo, client, - SecurityReadAccess); - if (!confineTo) - return BadWindow; - } - if (stuff->cursor == None) - cursor = NullCursor; - else - { - cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursor) - { - client->errorValue = stuff->cursor; - return BadCursor; - } - } - - - grab = CreateGrab(client->index, inputInfo.pointer, pWin, - permitOldBugs ? (Mask)(stuff->eventMask | - ButtonPressMask | ButtonReleaseMask) : - (Mask)stuff->eventMask, - (Bool)stuff->ownerEvents, (Bool) stuff->keyboardMode, - (Bool)stuff->pointerMode, inputInfo.keyboard, stuff->modifiers, - ButtonPress, stuff->button, confineTo, cursor); - if (!grab) - return BadAlloc; - return AddPassiveGrabToList(grab); -} - -int -ProcUngrabButton(ClientPtr client) -{ - REQUEST(xUngrabButtonReq); - WindowPtr pWin; - GrabRec tempGrab; - - REQUEST_SIZE_MATCH(xUngrabButtonReq); - if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; - } - pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess); - if (!pWin) - return BadWindow; - tempGrab.resource = client->clientAsMask; - tempGrab.device = inputInfo.pointer; - tempGrab.window = pWin; - tempGrab.modifiersDetail.exact = stuff->modifiers; - tempGrab.modifiersDetail.pMask = NULL; - tempGrab.modifierDevice = inputInfo.keyboard; - tempGrab.type = ButtonPress; - tempGrab.detail.exact = stuff->button; - tempGrab.detail.pMask = NULL; - - if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); -} - -void -DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources) -{ - WindowPtr parent; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - FocusClassPtr focus = keybd->focus; - OtherClientsPtr oc; - GrabPtr passive; - - - /* Deactivate any grabs performed on this window, before making any - input focus changes. */ - - if (mouse->grab && - ((mouse->grab->window == pWin) || (mouse->grab->confineTo == pWin))) - (*mouse->DeactivateGrab)(mouse); - - /* Deactivating a keyboard grab should cause focus events. */ - - if (keybd->grab && (keybd->grab->window == pWin)) - (*keybd->DeactivateGrab)(keybd); - - /* If the focus window is a root window (ie. has no parent) then don't - delete the focus from it. */ - - if ((pWin == focus->win) && (pWin->parent != NullWindow)) - { - int focusEventMode = NotifyNormal; - - /* If a grab is in progress, then alter the mode of focus events. */ - - if (keybd->grab) - focusEventMode = NotifyWhileGrabbed; - - switch (focus->revert) - { - case RevertToNone: - DoFocusEvents(keybd, pWin, NoneWin, focusEventMode); - focus->win = NoneWin; - focus->traceGood = 0; - break; - case RevertToParent: - parent = pWin; - do - { - parent = parent->parent; - focus->traceGood--; - } while (!parent->realized -/* This would be a good protocol change -- windows being reparented - during SaveSet processing would cause the focus to revert to the - nearest enclosing window which will survive the death of the exiting - client, instead of ending up reverting to a dying window and thence - to None - */ -#ifdef NOTDEF - || clients[CLIENT_ID(parent->drawable.id)]->clientGone -#endif - ); - DoFocusEvents(keybd, pWin, parent, focusEventMode); - focus->win = parent; - focus->revert = RevertToNone; - break; - case RevertToPointerRoot: - DoFocusEvents(keybd, pWin, PointerRootWin, focusEventMode); - focus->win = PointerRootWin; - focus->traceGood = 0; - break; - } - } - - if (mouse->valuator->motionHintWindow == pWin) - mouse->valuator->motionHintWindow = NullWindow; - - if (freeResources) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - while ( (oc = wOtherClients(pWin)) ) - FreeResource(oc->resource, RT_NONE); - while ( (passive = wPassiveGrabs(pWin)) ) - FreeResource(passive->resource, RT_NONE); - } -#ifdef XINPUT - DeleteWindowFromAnyExtEvents(pWin, freeResources); -#endif -} - -/** - * Call this whenever some window at or below pWin has changed geometry - */ -void -CheckCursorConfinement(WindowPtr pWin) -{ - GrabPtr grab = inputInfo.pointer->grab; - WindowPtr confineTo; - -#ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) return; -#endif - - if (grab && (confineTo = grab->confineTo)) - { - if (!BorderSizeNotEmpty(confineTo)) - (*inputInfo.pointer->DeactivateGrab)(inputInfo.pointer); - else if ((pWin == confineTo) || IsParent(pWin, confineTo)) - ConfineCursorToWindow(confineTo, TRUE, TRUE); - } -} - -Mask -EventMaskForClient(WindowPtr pWin, ClientPtr client) -{ - register OtherClientsPtr other; - - if (wClient (pWin) == client) - return pWin->eventMask; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (SameClient(other, client)) - return other->mask; - } - return 0; -} - -int -ProcRecolorCursor(ClientPtr client) -{ - CursorPtr pCursor; - int nscr; - ScreenPtr pscr; - Bool displayed; - REQUEST(xRecolorCursorReq); - - REQUEST_SIZE_MATCH(xRecolorCursorReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, SecurityWriteAccess); - if ( !pCursor) - { - client->errorValue = stuff->cursor; - return (BadCursor); - } - - pCursor->foreRed = stuff->foreRed; - pCursor->foreGreen = stuff->foreGreen; - pCursor->foreBlue = stuff->foreBlue; - - pCursor->backRed = stuff->backRed; - pCursor->backGreen = stuff->backGreen; - pCursor->backBlue = stuff->backBlue; - - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { - pscr = screenInfo.screens[nscr]; -#ifdef PANORAMIX - if(!noPanoramiXExtension) - displayed = (pscr == sprite.screen); - else -#endif - displayed = (pscr == sprite.hotPhys.pScreen); - ( *pscr->RecolorCursor)(pscr, pCursor, - (pCursor == sprite.current) && displayed); - } - return (Success); -} - -void -WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) -{ -#ifdef PANORAMIX - xEvent eventCopy; -#endif - xEvent eventTo, *eventFrom; - int i; - -#ifdef XKB - if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events))) - return; -#endif - -#ifdef PANORAMIX - if(!noPanoramiXExtension && - (panoramiXdataPtr[0].x || panoramiXdataPtr[0].y)) - { - switch(events->u.u.type) { - case MotionNotify: - case ButtonPress: - case ButtonRelease: - case KeyPress: - case KeyRelease: - case EnterNotify: - case LeaveNotify: - /* - When multiple clients want the same event DeliverEventsToWindow - passes the same event structure multiple times so we can't - modify the one passed to us - */ - count = 1; /* should always be 1 */ - memcpy(&eventCopy, events, sizeof(xEvent)); - eventCopy.u.keyButtonPointer.rootX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.rootY += panoramiXdataPtr[0].y; - if(eventCopy.u.keyButtonPointer.event == - eventCopy.u.keyButtonPointer.root) - { - eventCopy.u.keyButtonPointer.eventX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.eventY += panoramiXdataPtr[0].y; - } - events = &eventCopy; - break; - default: break; - } - } -#endif - - if (EventCallback) - { - EventInfoRec eventinfo; - eventinfo.client = pClient; - eventinfo.events = events; - eventinfo.count = count; - CallCallbacks(&EventCallback, (pointer)&eventinfo); - } - if(pClient->swapped) - { - for(i = 0; i < count; i++) - { - eventFrom = &events[i]; - /* Remember to strip off the leading bit of type in case - this event was sent with "SendEvent." */ - (*EventSwapVector[eventFrom->u.u.type & 0177]) - (eventFrom, &eventTo); - (void)WriteToClient(pClient, sizeof(xEvent), (char *)&eventTo); - } - } - else - { - (void)WriteToClient(pClient, count * sizeof(xEvent), (char *) events); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.NX.original deleted file mode 100644 index ead9b9d28..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.NX.original +++ /dev/null @@ -1,508 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/extension.c,v 3.11 2001/12/14 19:59:31 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: extension.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#define NEED_EVENTS -#define NEED_REPLIES -#include -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "gcstruct.h" -#include "scrnintstr.h" -#include "../../dix/dispatch.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef LBX -#include "lbxserve.h" -#endif - -#include "Trap.h" - -#define EXTENSION_BASE 128 -#define EXTENSION_EVENT_BASE 64 -#define LAST_EVENT 128 -#define LAST_ERROR 255 - -ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS]; - -static ExtensionEntry **extensions = (ExtensionEntry **)NULL; - -int lastEvent = EXTENSION_EVENT_BASE; -static int lastError = FirstExtensionError; -static unsigned int NumExtensions = 0; - -ExtensionEntry * -AddExtension(char *name, int NumEvents, int NumErrors, - int (*MainProc)(ClientPtr c1), - int (*SwappedMainProc)(ClientPtr c2), - void (*CloseDownProc)(ExtensionEntry *e), - unsigned short (*MinorOpcodeProc)(ClientPtr c3)) -{ - int i; - register ExtensionEntry *ext, **newexts; - - if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc) - return((ExtensionEntry *) NULL); - if ((lastEvent + NumEvents > LAST_EVENT) || - (unsigned)(lastError + NumErrors > LAST_ERROR)) - return((ExtensionEntry *) NULL); - - ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry)); - if (!ext) - return((ExtensionEntry *) NULL); - ext->name = (char *)xalloc(strlen(name) + 1); - ext->num_aliases = 0; - ext->aliases = (char **)NULL; - if (!ext->name) - { - xfree(ext); - return((ExtensionEntry *) NULL); - } - strcpy(ext->name, name); - i = NumExtensions; - newexts = (ExtensionEntry **) xrealloc(extensions, - (i + 1) * sizeof(ExtensionEntry *)); - if (!newexts) - { - xfree(ext->name); - xfree(ext); - return((ExtensionEntry *) NULL); - } - NumExtensions++; - extensions = newexts; - extensions[i] = ext; - ext->index = i; - ext->base = i + EXTENSION_BASE; - ext->CloseDown = CloseDownProc; - ext->MinorOpcode = MinorOpcodeProc; - ProcVector[i + EXTENSION_BASE] = MainProc; - SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc; - if (NumEvents) - { - ext->eventBase = lastEvent; - ext->eventLast = lastEvent + NumEvents; - lastEvent += NumEvents; - } - else - { - ext->eventBase = 0; - ext->eventLast = 0; - } - if (NumErrors) - { - ext->errorBase = lastError; - ext->errorLast = lastError + NumErrors; - lastError += NumErrors; - } - else - { - ext->errorBase = 0; - ext->errorLast = 0; - } -#ifdef XCSECURITY - ext->secure = FALSE; -#endif - -#ifdef LBX - (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase); -#endif - return(ext); -} - -Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) -{ - char *name; - char **aliases; - - aliases = (char **)xrealloc(ext->aliases, - (ext->num_aliases + 1) * sizeof(char *)); - if (!aliases) - return FALSE; - ext->aliases = aliases; - name = (char *)xalloc(strlen(alias) + 1); - if (!name) - return FALSE; - strcpy(name, alias); - ext->aliases[ext->num_aliases] = name; - ext->num_aliases++; -#ifdef LBX - return LbxAddExtensionAlias(ext->index, alias); -#else - return TRUE; -#endif -} - -static int -FindExtension(char *extname, int len) -{ - int i, j; - - for (i=0; iname) == len) && - !strncmp(extname, extensions[i]->name, len)) - break; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - if ((strlen(extensions[i]->aliases[j]) == len) && - !strncmp(extname, extensions[i]->aliases[j], len)) - break; - } - if (j >= 0) break; - } - return ((i == NumExtensions) ? -1 : i); -} - -/* - * CheckExtension returns the extensions[] entry for the requested - * extension name. Maybe this could just return a Bool instead? - */ -ExtensionEntry * -CheckExtension(const char *extname) -{ - int n; - - n = FindExtension((char*)extname, strlen(extname)); - if (n != -1) - return extensions[n]; - else - return NULL; -} - -void -DeclareExtensionSecurity(char *extname, Bool secure) -{ -#ifdef XCSECURITY - int i = FindExtension(extname, strlen(extname)); - if (i >= 0) - { - int majorop = extensions[i]->base; - extensions[i]->secure = secure; - if (secure) - { - UntrustedProcVector[majorop] = ProcVector[majorop]; - SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop]; - } - else - { - UntrustedProcVector[majorop] = ProcBadRequest; - SwappedUntrustedProcVector[majorop] = ProcBadRequest; - } - } -#endif -#ifdef LBX - LbxDeclareExtensionSecurity(extname, secure); -#endif -} - -unsigned short -StandardMinorOpcode(ClientPtr client) -{ - return ((xReq *)client->requestBuffer)->data; -} - -unsigned short -MinorOpcodeOfRequest(ClientPtr client) -{ - unsigned char major; - - major = ((xReq *)client->requestBuffer)->reqType; - if (major < EXTENSION_BASE) - return 0; - major -= EXTENSION_BASE; - if (major >= NumExtensions) - return 0; - return (*extensions[major]->MinorOpcode)(client); -} - -void -CloseDownExtensions() -{ - register int i,j; - -#ifdef LBX - LbxCloseDownExtensions(); -#endif - - for (i = NumExtensions - 1; i >= 0; i--) - { - (* extensions[i]->CloseDown)(extensions[i]); - NumExtensions = i; - xfree(extensions[i]->name); - for (j = extensions[i]->num_aliases; --j >= 0;) - xfree(extensions[i]->aliases[j]); - xfree(extensions[i]->aliases); - xfree(extensions[i]); - } - xfree(extensions); - extensions = (ExtensionEntry **)NULL; - lastEvent = EXTENSION_EVENT_BASE; - lastError = FirstExtensionError; - for (i=0; inum) - { - spentry->num--; - xfree(spentry->procList[spentry->num].name); - } - xfree(spentry->procList); - spentry->procList = (ProcEntryPtr)NULL; - } -} - - -int -ProcQueryExtension(ClientPtr client) -{ - xQueryExtensionReply reply; - int i; - REQUEST(xQueryExtensionReq); - - REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes); - - reply.type = X_Reply; - reply.length = 0; - reply.major_opcode = 0; - reply.sequenceNumber = client->sequence; - - if ( ! NumExtensions ) - reply.present = xFalse; - else - { - i = FindExtension((char *)&stuff[1], stuff->nbytes); - if (i < 0 - - /* - * Hide RENDER if our implementation - * is faulty. - */ - - || (nxagentRenderTrap && strcmp(extensions[i]->name, "RENDER") == 0) -#ifdef XCSECURITY - /* don't show insecure extensions to untrusted clients */ - || (client->trustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) -#endif - ) - reply.present = xFalse; - else - { - reply.present = xTrue; - reply.major_opcode = extensions[i]->base; - reply.first_event = extensions[i]->eventBase; - reply.first_error = extensions[i]->errorBase; - } - } - WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply); - return(client->noClientException); -} - -int -ProcListExtensions(ClientPtr client) -{ - xListExtensionsReply reply; - char *bufptr, *buffer; - int total_length = 0; - - REQUEST_SIZE_MATCH(xReq); - - reply.type = X_Reply; - reply.nExtensions = 0; - reply.length = 0; - reply.sequenceNumber = client->sequence; - buffer = NULL; - - if ( NumExtensions ) - { - register int i, j; - - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - /* - * Hide RENDER if our implementation - * is faulty. - */ - - if (nxagentRenderTrap && strcmp(extensions[i]->name, "RENDER") == 0) - continue; - - total_length += strlen(extensions[i]->name) + 1; - reply.nExtensions += 1 + extensions[i]->num_aliases; - for (j = extensions[i]->num_aliases; --j >= 0;) - total_length += strlen(extensions[i]->aliases[j]) + 1; - } - reply.length = (total_length + 3) >> 2; - buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length); - if (!buffer) - return(BadAlloc); - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - *bufptr++ = len = strlen(extensions[i]->name); - memmove(bufptr, extensions[i]->name, len); - bufptr += len; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - *bufptr++ = len = strlen(extensions[i]->aliases[j]); - memmove(bufptr, extensions[i]->aliases[j], len); - bufptr += len; - } - } - } - WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply); - if (reply.length) - { - WriteToClient(client, total_length, buffer); - DEALLOCATE_LOCAL(buffer); - } - return(client->noClientException); -} - - -ExtensionLookupProc -LookupProc(char *name, GCPtr pGC) -{ - register int i; - register ScreenProcEntry *spentry; - spentry = &AuxillaryScreenProcs[pGC->pScreen->myNum]; - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - return(spentry->procList[i].proc); - } - return (ExtensionLookupProc)NULL; -} - -Bool -RegisterProc(char *name, GC *pGC, ExtensionLookupProc proc) -{ - return RegisterScreenProc(name, pGC->pScreen, proc); -} - -Bool -RegisterScreenProc(char *name, ScreenPtr pScreen, ExtensionLookupProc proc) -{ - register ScreenProcEntry *spentry; - register ProcEntryPtr procEntry = (ProcEntryPtr)NULL; - char *newname; - int i; - - spentry = &AuxillaryScreenProcs[pScreen->myNum]; - /* first replace duplicates */ - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - { - procEntry = &spentry->procList[i]; - break; - } - } - if (procEntry) - procEntry->proc = proc; - else - { - newname = (char *)xalloc(strlen(name)+1); - if (!newname) - return FALSE; - procEntry = (ProcEntryPtr) - xrealloc(spentry->procList, - sizeof(ProcEntryRec) * (spentry->num+1)); - if (!procEntry) - { - xfree(newname); - return FALSE; - } - spentry->procList = procEntry; - procEntry += spentry->num; - procEntry->name = newname; - strcpy(newname, name); - procEntry->proc = proc; - spentry->num++; - } - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.X.original deleted file mode 100644 index 270d54f9b..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXextension.c.X.original +++ /dev/null @@ -1,474 +0,0 @@ -/* $XFree86: xc/programs/Xserver/dix/extension.c,v 3.11 2001/12/14 19:59:31 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: extension.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#define NEED_EVENTS -#define NEED_REPLIES -#include -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "gcstruct.h" -#include "scrnintstr.h" -#include "dispatch.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef LBX -#include "lbxserve.h" -#endif - -#define EXTENSION_BASE 128 -#define EXTENSION_EVENT_BASE 64 -#define LAST_EVENT 128 -#define LAST_ERROR 255 - -ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS]; - -static ExtensionEntry **extensions = (ExtensionEntry **)NULL; - -int lastEvent = EXTENSION_EVENT_BASE; -static int lastError = FirstExtensionError; -static unsigned int NumExtensions = 0; - -ExtensionEntry * -AddExtension(char *name, int NumEvents, int NumErrors, - int (*MainProc)(ClientPtr c1), - int (*SwappedMainProc)(ClientPtr c2), - void (*CloseDownProc)(ExtensionEntry *e), - unsigned short (*MinorOpcodeProc)(ClientPtr c3)) -{ - int i; - register ExtensionEntry *ext, **newexts; - - if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc) - return((ExtensionEntry *) NULL); - if ((lastEvent + NumEvents > LAST_EVENT) || - (unsigned)(lastError + NumErrors > LAST_ERROR)) - return((ExtensionEntry *) NULL); - - ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry)); - if (!ext) - return((ExtensionEntry *) NULL); - ext->name = (char *)xalloc(strlen(name) + 1); - ext->num_aliases = 0; - ext->aliases = (char **)NULL; - if (!ext->name) - { - xfree(ext); - return((ExtensionEntry *) NULL); - } - strcpy(ext->name, name); - i = NumExtensions; - newexts = (ExtensionEntry **) xrealloc(extensions, - (i + 1) * sizeof(ExtensionEntry *)); - if (!newexts) - { - xfree(ext->name); - xfree(ext); - return((ExtensionEntry *) NULL); - } - NumExtensions++; - extensions = newexts; - extensions[i] = ext; - ext->index = i; - ext->base = i + EXTENSION_BASE; - ext->CloseDown = CloseDownProc; - ext->MinorOpcode = MinorOpcodeProc; - ProcVector[i + EXTENSION_BASE] = MainProc; - SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc; - if (NumEvents) - { - ext->eventBase = lastEvent; - ext->eventLast = lastEvent + NumEvents; - lastEvent += NumEvents; - } - else - { - ext->eventBase = 0; - ext->eventLast = 0; - } - if (NumErrors) - { - ext->errorBase = lastError; - ext->errorLast = lastError + NumErrors; - lastError += NumErrors; - } - else - { - ext->errorBase = 0; - ext->errorLast = 0; - } -#ifdef XCSECURITY - ext->secure = FALSE; -#endif - -#ifdef LBX - (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase); -#endif - return(ext); -} - -Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) -{ - char *name; - char **aliases; - - aliases = (char **)xrealloc(ext->aliases, - (ext->num_aliases + 1) * sizeof(char *)); - if (!aliases) - return FALSE; - ext->aliases = aliases; - name = (char *)xalloc(strlen(alias) + 1); - if (!name) - return FALSE; - strcpy(name, alias); - ext->aliases[ext->num_aliases] = name; - ext->num_aliases++; -#ifdef LBX - return LbxAddExtensionAlias(ext->index, alias); -#else - return TRUE; -#endif -} - -static int -FindExtension(char *extname, int len) -{ - int i, j; - - for (i=0; iname) == len) && - !strncmp(extname, extensions[i]->name, len)) - break; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - if ((strlen(extensions[i]->aliases[j]) == len) && - !strncmp(extname, extensions[i]->aliases[j], len)) - break; - } - if (j >= 0) break; - } - return ((i == NumExtensions) ? -1 : i); -} - -/* - * CheckExtension returns the extensions[] entry for the requested - * extension name. Maybe this could just return a Bool instead? - */ -ExtensionEntry * -CheckExtension(const char *extname) -{ - int n; - - n = FindExtension((char*)extname, strlen(extname)); - if (n != -1) - return extensions[n]; - else - return NULL; -} - -void -DeclareExtensionSecurity(char *extname, Bool secure) -{ -#ifdef XCSECURITY - int i = FindExtension(extname, strlen(extname)); - if (i >= 0) - { - int majorop = extensions[i]->base; - extensions[i]->secure = secure; - if (secure) - { - UntrustedProcVector[majorop] = ProcVector[majorop]; - SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop]; - } - else - { - UntrustedProcVector[majorop] = ProcBadRequest; - SwappedUntrustedProcVector[majorop] = ProcBadRequest; - } - } -#endif -#ifdef LBX - LbxDeclareExtensionSecurity(extname, secure); -#endif -} - -unsigned short -StandardMinorOpcode(ClientPtr client) -{ - return ((xReq *)client->requestBuffer)->data; -} - -unsigned short -MinorOpcodeOfRequest(ClientPtr client) -{ - unsigned char major; - - major = ((xReq *)client->requestBuffer)->reqType; - if (major < EXTENSION_BASE) - return 0; - major -= EXTENSION_BASE; - if (major >= NumExtensions) - return 0; - return (*extensions[major]->MinorOpcode)(client); -} - -void -CloseDownExtensions() -{ - register int i,j; - -#ifdef LBX - LbxCloseDownExtensions(); -#endif - - for (i = NumExtensions - 1; i >= 0; i--) - { - (* extensions[i]->CloseDown)(extensions[i]); - NumExtensions = i; - xfree(extensions[i]->name); - for (j = extensions[i]->num_aliases; --j >= 0;) - xfree(extensions[i]->aliases[j]); - xfree(extensions[i]->aliases); - xfree(extensions[i]); - } - xfree(extensions); - extensions = (ExtensionEntry **)NULL; - lastEvent = EXTENSION_EVENT_BASE; - lastError = FirstExtensionError; - for (i=0; inum) - { - spentry->num--; - xfree(spentry->procList[spentry->num].name); - } - xfree(spentry->procList); - spentry->procList = (ProcEntryPtr)NULL; - } -} - - -int -ProcQueryExtension(ClientPtr client) -{ - xQueryExtensionReply reply; - int i; - REQUEST(xQueryExtensionReq); - - REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes); - - reply.type = X_Reply; - reply.length = 0; - reply.major_opcode = 0; - reply.sequenceNumber = client->sequence; - - if ( ! NumExtensions ) - reply.present = xFalse; - else - { - i = FindExtension((char *)&stuff[1], stuff->nbytes); - if (i < 0 -#ifdef XCSECURITY - /* don't show insecure extensions to untrusted clients */ - || (client->trustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) -#endif - ) - reply.present = xFalse; - else - { - reply.present = xTrue; - reply.major_opcode = extensions[i]->base; - reply.first_event = extensions[i]->eventBase; - reply.first_error = extensions[i]->errorBase; - } - } - WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply); - return(client->noClientException); -} - -int -ProcListExtensions(ClientPtr client) -{ - xListExtensionsReply reply; - char *bufptr, *buffer; - int total_length = 0; - - REQUEST_SIZE_MATCH(xReq); - - reply.type = X_Reply; - reply.nExtensions = 0; - reply.length = 0; - reply.sequenceNumber = client->sequence; - buffer = NULL; - - if ( NumExtensions ) - { - register int i, j; - - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - total_length += strlen(extensions[i]->name) + 1; - reply.nExtensions += 1 + extensions[i]->num_aliases; - for (j = extensions[i]->num_aliases; --j >= 0;) - total_length += strlen(extensions[i]->aliases[j]) + 1; - } - reply.length = (total_length + 3) >> 2; - buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length); - if (!buffer) - return(BadAlloc); - for (i=0; itrustLevel == XSecurityClientUntrusted && - !extensions[i]->secure) - continue; -#endif - *bufptr++ = len = strlen(extensions[i]->name); - memmove(bufptr, extensions[i]->name, len); - bufptr += len; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - *bufptr++ = len = strlen(extensions[i]->aliases[j]); - memmove(bufptr, extensions[i]->aliases[j], len); - bufptr += len; - } - } - } - WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply); - if (reply.length) - { - WriteToClient(client, total_length, buffer); - DEALLOCATE_LOCAL(buffer); - } - return(client->noClientException); -} - - -ExtensionLookupProc -LookupProc(char *name, GCPtr pGC) -{ - register int i; - register ScreenProcEntry *spentry; - spentry = &AuxillaryScreenProcs[pGC->pScreen->myNum]; - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - return(spentry->procList[i].proc); - } - return (ExtensionLookupProc)NULL; -} - -Bool -RegisterProc(char *name, GC *pGC, ExtensionLookupProc proc) -{ - return RegisterScreenProc(name, pGC->pScreen, proc); -} - -Bool -RegisterScreenProc(char *name, ScreenPtr pScreen, ExtensionLookupProc proc) -{ - register ScreenProcEntry *spentry; - register ProcEntryPtr procEntry = (ProcEntryPtr)NULL; - char *newname; - int i; - - spentry = &AuxillaryScreenProcs[pScreen->myNum]; - /* first replace duplicates */ - if (spentry->num) - { - for (i = 0; i < spentry->num; i++) - if (strcmp(name, spentry->procList[i].name) == 0) - { - procEntry = &spentry->procList[i]; - break; - } - } - if (procEntry) - procEntry->proc = proc; - else - { - newname = (char *)xalloc(strlen(name)+1); - if (!newname) - return FALSE; - procEntry = (ProcEntryPtr) - xrealloc(spentry->procList, - sizeof(ProcEntryRec) * (spentry->num+1)); - if (!procEntry) - { - xfree(newname); - return FALSE; - } - spentry->procList = procEntry; - procEntry += spentry->num; - procEntry->name = newname; - strcpy(newname, name); - procEntry->proc = proc; - spentry->num++; - } - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.NX.original deleted file mode 100644 index 51c547984..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.NX.original +++ /dev/null @@ -1,575 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/GL/glx/glxext.c,v 1.9 2003/09/28 20:15:43 alanh Exp $ -** The contents of this file are subject to the GLX Public License Version 1.0 -** (the "License"). You may not use this file except in compliance with the -** License. You may obtain a copy of the License at Silicon Graphics, Inc., -** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043 -** or at http://www.sgi.com/software/opensource/glx/license.html. -** -** Software distributed under the License is distributed on an "AS IS" -** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY -** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR -** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific -** language governing rights and limitations under the License. -** -** The Original Software is GLX version 1.2 source code, released February, -** 1999. The developer of the Original Software is Silicon Graphics, Inc. -** Those portions of the Subject Software created by Silicon Graphics, Inc. -** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved. -** -*/ - -#define NEED_REPLIES -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "glxserver.h" -#include -#include -#include -#include "g_disptab.h" -#include "unpack.h" -#include "glxutil.h" -#include "glxext.h" -#include "micmap.h" - -#include "Trap.h" - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -void GlxWrapInitVisuals(miInitVisualsProcPtr *); -void GlxSetVisualConfigs(int nconfigs, - __GLXvisualConfig *configs, void **privates); - -static __GLXextensionInfo *__glXExt /* = &__glDDXExtensionInfo */; - -/* -** Forward declarations. -*/ -static int __glXSwapDispatch(ClientPtr); -static int __glXDispatch(ClientPtr); - -/* -** Called when the extension is reset. -*/ -static void ResetExtension(ExtensionEntry* extEntry) -{ - __glXFlushContextCache(); - (*__glXExt->resetExtension)(); - __glXScreenReset(); -} - -/* -** Initialize the per-client context storage. -*/ -static void ResetClientState(int clientIndex) -{ - __GLXclientState *cl = __glXClients[clientIndex]; - - if (cl->returnBuf) __glXFree(cl->returnBuf); - if (cl->largeCmdBuf) __glXFree(cl->largeCmdBuf); - if (cl->currentContexts) __glXFree(cl->currentContexts); - __glXMemset(cl, 0, sizeof(__GLXclientState)); - /* - ** By default, assume that the client supports - ** GLX major version 1 minor version 0 protocol. - */ - cl->GLClientmajorVersion = 1; - cl->GLClientminorVersion = 0; - if (cl->GLClientextensions) __glXFree(cl->GLClientextensions); - -} - -/* -** Reset state used to keep track of large (multi-request) commands. -*/ -void __glXResetLargeCommandStatus(__GLXclientState *cl) -{ - cl->largeCmdBytesSoFar = 0; - cl->largeCmdBytesTotal = 0; - cl->largeCmdRequestsSoFar = 0; - cl->largeCmdRequestsTotal = 0; -} - -/* -** This procedure is called when the client who created the context goes -** away OR when glXDestroyContext is called. In either case, all we do is -** flag that the ID is no longer valid, and (maybe) free the context. -** use. -*/ -static int ContextGone(__GLXcontext* cx, XID id) -{ - cx->idExists = GL_FALSE; - if (!cx->isCurrent) { - __glXFreeContext(cx); - } - - return True; -} - -/* -** Free a client's state. -*/ -static int ClientGone(int clientIndex, XID id) -{ - __GLXcontext *cx; - __GLXclientState *cl = __glXClients[clientIndex]; - int i; - - if (cl) { - /* - ** Free all the contexts that are current for this client. - */ - for (i=0; i < cl->numCurrentContexts; i++) { - cx = cl->currentContexts[i]; - if (cx) { - __glXDeassociateContext(cx); - cx->isCurrent = GL_FALSE; - if (!cx->idExists) { - __glXFreeContext(cx); - } - } - } - /* - ** Re-initialize the client state structure. Don't free it because - ** we'll probably get another client with this index and use the struct - ** again. There is a maximum of MAXCLIENTS of these structures. - */ - ResetClientState(clientIndex); - } - - return True; -} - -/* -** Free a GLX Pixmap. -*/ -static int PixmapGone(__GLXpixmap *pGlxPixmap, XID id) -{ - PixmapPtr pPixmap = (PixmapPtr) pGlxPixmap->pDraw; - - pGlxPixmap->idExists = False; - if (!pGlxPixmap->refcnt) { - /* - ** The DestroyPixmap routine should decrement the refcount and free - ** only if it's zero. - */ - (*pGlxPixmap->pScreen->DestroyPixmap)(pPixmap); - __glXFree(pGlxPixmap); - } - - return True; -} - -/* -** Free a context. -*/ -GLboolean __glXFreeContext(__GLXcontext *cx) -{ - if (cx->idExists || cx->isCurrent) return GL_FALSE; - - if (!cx->isDirect) { - if ((*cx->gc->exports.destroyContext)((__GLcontext *)cx->gc) == GL_FALSE) { - return GL_FALSE; - } - } - if (cx->feedbackBuf) __glXFree(cx->feedbackBuf); - if (cx->selectBuf) __glXFree(cx->selectBuf); - __glXFree(cx); - if (cx == __glXLastContext) { - __glXFlushContextCache(); - } - - return GL_TRUE; -} - -extern RESTYPE __glXSwapBarrierRes; - -static int SwapBarrierGone(int screen, XID drawable) -{ - if (__glXSwapBarrierFuncs && - __glXSwapBarrierFuncs[screen].bindSwapBarrierFunc != NULL) { - __glXSwapBarrierFuncs[screen].bindSwapBarrierFunc(screen, drawable, 0); - } - FreeResourceByType(drawable, __glXSwapBarrierRes, FALSE); - return True; -} - -/************************************************************************/ - -/* -** These routines can be used to check whether a particular GL command -** has caused an error. Specifically, we use them to check whether a -** given query has caused an error, in which case a zero-length data -** reply is sent to the client. -*/ - -static GLboolean errorOccured = GL_FALSE; - -/* -** The GL was will call this routine if an error occurs. -*/ -void __glXErrorCallBack(__GLinterface *gc, GLenum code) -{ - errorOccured = GL_TRUE; -} - -/* -** Clear the error flag before calling the GL command. -*/ -void __glXClearErrorOccured(void) -{ - errorOccured = GL_FALSE; -} - -/* -** Check if the GL command caused an error. -*/ -GLboolean __glXErrorOccured(void) -{ - return errorOccured; -} - -/************************************************************************/ - -/* -** Initialize the GLX extension. -*/ -void GlxExtensionInit(void) -{ - ExtensionEntry *extEntry; - int i; - - __glXContextRes = CreateNewResourceType((DeleteType)ContextGone); - __glXClientRes = CreateNewResourceType((DeleteType)ClientGone); - __glXPixmapRes = CreateNewResourceType((DeleteType)PixmapGone); - - /* - ** Add extension to server extensions. - */ - extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS, - __GLX_NUMBER_ERRORS, __glXDispatch, - __glXSwapDispatch, ResetExtension, - StandardMinorOpcode); - if (!extEntry) { - FatalError("__glXExtensionInit: AddExtensions failed\n"); - return; - } - if (!AddExtensionAlias(GLX_EXTENSION_ALIAS, extEntry)) { - ErrorF("__glXExtensionInit: AddExtensionAlias failed\n"); - return; - } - - __glXBadContext = extEntry->errorBase + GLXBadContext; - __glXBadContextState = extEntry->errorBase + GLXBadContextState; - __glXBadDrawable = extEntry->errorBase + GLXBadDrawable; - __glXBadPixmap = extEntry->errorBase + GLXBadPixmap; - __glXBadContextTag = extEntry->errorBase + GLXBadContextTag; - __glXBadCurrentWindow = extEntry->errorBase + GLXBadCurrentWindow; - __glXBadRenderRequest = extEntry->errorBase + GLXBadRenderRequest; - __glXBadLargeRequest = extEntry->errorBase + GLXBadLargeRequest; - __glXUnsupportedPrivateRequest = extEntry->errorBase + - GLXUnsupportedPrivateRequest; - - __glXSwapBarrierRes = CreateNewResourceType((DeleteType)SwapBarrierGone); - - /* - ** Initialize table of client state. There is never a client 0. - */ - for (i=1; i <= MAXCLIENTS; i++) { - __glXClients[i] = 0; - } - - /* - ** Initialize screen specific data. - */ - __glXScreenInit(screenInfo.numScreens); -} - -/************************************************************************/ - -Bool __glXCoreType(void) -{ - return __glXExt->type; -} - -/************************************************************************/ - -void GlxSetVisualConfigs(int nconfigs, - __GLXvisualConfig *configs, void **privates) -{ - (*__glXExt->setVisualConfigs)(nconfigs, configs, privates); -} - -static miInitVisualsProcPtr saveInitVisualsProc; - -Bool GlxInitVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, - int *rootDepthp, VisualID *defaultVisp, - unsigned long sizes, int bitsPerRGB, - int preferredVis) -{ - Bool ret; - - if (saveInitVisualsProc) { - ret = saveInitVisualsProc(visualp, depthp, nvisualp, ndepthp, - rootDepthp, defaultVisp, sizes, bitsPerRGB, - preferredVis); - if (!ret) - return False; - } - (*__glXExt->initVisuals)(visualp, depthp, nvisualp, ndepthp, rootDepthp, - defaultVisp, sizes, bitsPerRGB); - return True; -} - -void -GlxWrapInitVisuals(miInitVisualsProcPtr *initVisProc) -{ - saveInitVisualsProc = *initVisProc; - *initVisProc = GlxInitVisuals; - /* HACK: this shouldn't be done here but it's the earliest time */ - __glXExt = __glXglDDXExtensionInfo(); /* from GLcore */ -} - -/************************************************************************/ - -void __glXFlushContextCache(void) -{ - __glXLastContext = 0; -} - -/* -** Make a context the current one for the GL (in this implementation, there -** is only one instance of the GL, and we use it to serve all GL clients by -** switching it between different contexts). While we are at it, look up -** a context by its tag and return its (__GLXcontext *). -*/ -__GLXcontext *__glXForceCurrent(__GLXclientState *cl, GLXContextTag tag, - int *error) -{ - __GLXcontext *cx; - - /* - ** See if the context tag is legal; it is managed by the extension, - ** so if it's invalid, we have an implementation error. - */ - cx = (__GLXcontext *) __glXLookupContextByTag(cl, tag); - if (!cx) { - cl->client->errorValue = tag; - *error = __glXBadContextTag; - return 0; - } - - if (!cx->isDirect) { - if (cx->drawPriv == NULL) { - /* - ** The drawable has vanished. It must be a window, because only - ** windows can be destroyed from under us; GLX pixmaps are - ** refcounted and don't go away until no one is using them. - */ - *error = __glXBadCurrentWindow; - return 0; - } - } - - if (cx == __glXLastContext) { - /* No need to re-bind */ - return cx; - } - - /* Make this context the current one for the GL. */ - if (!cx->isDirect) { - if (!(*cx->gc->exports.forceCurrent)((__GLcontext *)cx->gc)) { - /* Bind failed, and set the error code. Bummer */ - cl->client->errorValue = cx->id; - *error = __glXBadContextState; - return 0; - } - } - __glXLastContext = cx; - return cx; -} - -/************************************************************************/ - -/* -** Top level dispatcher; all commands are executed from here down. -*/ -static int __glXDispatch(ClientPtr client) -{ - int result; - - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** If we're expecting a glXRenderLarge request, this better be one. - */ - if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) { - client->errorValue = stuff->glxCode; - return __glXBadLargeRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSingleTable[opcode]; - - /* - * Report upstream that we are - * dispatching a GLX operation. - */ - - nxagentGlxTrap = 1; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Going to dispatch GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - result = (*proc)(cl, (GLbyte *) stuff); - - nxagentGlxTrap = 0; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Dispatched GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - return result; -} - -static int __glXSwapDispatch(ClientPtr client) -{ - int result; - - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSwapSingleTable[opcode]; - - /* - * Report upstream that we are - * dispatching a GLX operation. - */ - - nxagentGlxTrap = 1; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Going to dispatch GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - result = (*proc)(cl, (GLbyte *) stuff); - - nxagentGlxTrap = 0; - - #ifdef TEST - fprintf(stderr, "__glXDispatch: Dispatched GLX operation [%d] for client [%d].\n", - opcode, client -> index); - #endif - - return result; -} - -int __glXNoSuchSingleOpcode(__GLXclientState *cl, GLbyte *pc) -{ - return BadRequest; -} - -void __glXNoSuchRenderOpcode(GLbyte *pc) -{ - return; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.X.original deleted file mode 100644 index fa1382983..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglxext.c.X.original +++ /dev/null @@ -1,505 +0,0 @@ -/* $XFree86: xc/programs/Xserver/GL/glx/glxext.c,v 1.9 2003/09/28 20:15:43 alanh Exp $ -** The contents of this file are subject to the GLX Public License Version 1.0 -** (the "License"). You may not use this file except in compliance with the -** License. You may obtain a copy of the License at Silicon Graphics, Inc., -** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043 -** or at http://www.sgi.com/software/opensource/glx/license.html. -** -** Software distributed under the License is distributed on an "AS IS" -** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY -** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR -** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific -** language governing rights and limitations under the License. -** -** The Original Software is GLX version 1.2 source code, released February, -** 1999. The developer of the Original Software is Silicon Graphics, Inc. -** Those portions of the Subject Software created by Silicon Graphics, Inc. -** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved. -** -*/ - -#define NEED_REPLIES -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "glxserver.h" -#include -#include -#include -#include "g_disptab.h" -#include "unpack.h" -#include "glxutil.h" -#include "glxext.h" -#include "micmap.h" - - -void GlxWrapInitVisuals(miInitVisualsProcPtr *); -void GlxSetVisualConfigs(int nconfigs, - __GLXvisualConfig *configs, void **privates); - -static __GLXextensionInfo *__glXExt /* = &__glDDXExtensionInfo */; - -/* -** Forward declarations. -*/ -static int __glXSwapDispatch(ClientPtr); -static int __glXDispatch(ClientPtr); - -/* -** Called when the extension is reset. -*/ -static void ResetExtension(ExtensionEntry* extEntry) -{ - __glXFlushContextCache(); - (*__glXExt->resetExtension)(); - __glXScreenReset(); -} - -/* -** Initialize the per-client context storage. -*/ -static void ResetClientState(int clientIndex) -{ - __GLXclientState *cl = __glXClients[clientIndex]; - - if (cl->returnBuf) __glXFree(cl->returnBuf); - if (cl->largeCmdBuf) __glXFree(cl->largeCmdBuf); - if (cl->currentContexts) __glXFree(cl->currentContexts); - __glXMemset(cl, 0, sizeof(__GLXclientState)); - /* - ** By default, assume that the client supports - ** GLX major version 1 minor version 0 protocol. - */ - cl->GLClientmajorVersion = 1; - cl->GLClientminorVersion = 0; - if (cl->GLClientextensions) __glXFree(cl->GLClientextensions); - -} - -/* -** Reset state used to keep track of large (multi-request) commands. -*/ -void __glXResetLargeCommandStatus(__GLXclientState *cl) -{ - cl->largeCmdBytesSoFar = 0; - cl->largeCmdBytesTotal = 0; - cl->largeCmdRequestsSoFar = 0; - cl->largeCmdRequestsTotal = 0; -} - -/* -** This procedure is called when the client who created the context goes -** away OR when glXDestroyContext is called. In either case, all we do is -** flag that the ID is no longer valid, and (maybe) free the context. -** use. -*/ -static int ContextGone(__GLXcontext* cx, XID id) -{ - cx->idExists = GL_FALSE; - if (!cx->isCurrent) { - __glXFreeContext(cx); - } - - return True; -} - -/* -** Free a client's state. -*/ -static int ClientGone(int clientIndex, XID id) -{ - __GLXcontext *cx; - __GLXclientState *cl = __glXClients[clientIndex]; - int i; - - if (cl) { - /* - ** Free all the contexts that are current for this client. - */ - for (i=0; i < cl->numCurrentContexts; i++) { - cx = cl->currentContexts[i]; - if (cx) { - __glXDeassociateContext(cx); - cx->isCurrent = GL_FALSE; - if (!cx->idExists) { - __glXFreeContext(cx); - } - } - } - /* - ** Re-initialize the client state structure. Don't free it because - ** we'll probably get another client with this index and use the struct - ** again. There is a maximum of MAXCLIENTS of these structures. - */ - ResetClientState(clientIndex); - } - - return True; -} - -/* -** Free a GLX Pixmap. -*/ -static int PixmapGone(__GLXpixmap *pGlxPixmap, XID id) -{ - PixmapPtr pPixmap = (PixmapPtr) pGlxPixmap->pDraw; - - pGlxPixmap->idExists = False; - if (!pGlxPixmap->refcnt) { - /* - ** The DestroyPixmap routine should decrement the refcount and free - ** only if it's zero. - */ - (*pGlxPixmap->pScreen->DestroyPixmap)(pPixmap); - __glXFree(pGlxPixmap); - } - - return True; -} - -/* -** Free a context. -*/ -GLboolean __glXFreeContext(__GLXcontext *cx) -{ - if (cx->idExists || cx->isCurrent) return GL_FALSE; - - if (!cx->isDirect) { - if ((*cx->gc->exports.destroyContext)((__GLcontext *)cx->gc) == GL_FALSE) { - return GL_FALSE; - } - } - if (cx->feedbackBuf) __glXFree(cx->feedbackBuf); - if (cx->selectBuf) __glXFree(cx->selectBuf); - __glXFree(cx); - if (cx == __glXLastContext) { - __glXFlushContextCache(); - } - - return GL_TRUE; -} - -extern RESTYPE __glXSwapBarrierRes; - -static int SwapBarrierGone(int screen, XID drawable) -{ - if (__glXSwapBarrierFuncs && - __glXSwapBarrierFuncs[screen].bindSwapBarrierFunc != NULL) { - __glXSwapBarrierFuncs[screen].bindSwapBarrierFunc(screen, drawable, 0); - } - FreeResourceByType(drawable, __glXSwapBarrierRes, FALSE); - return True; -} - -/************************************************************************/ - -/* -** These routines can be used to check whether a particular GL command -** has caused an error. Specifically, we use them to check whether a -** given query has caused an error, in which case a zero-length data -** reply is sent to the client. -*/ - -static GLboolean errorOccured = GL_FALSE; - -/* -** The GL was will call this routine if an error occurs. -*/ -void __glXErrorCallBack(__GLinterface *gc, GLenum code) -{ - errorOccured = GL_TRUE; -} - -/* -** Clear the error flag before calling the GL command. -*/ -void __glXClearErrorOccured(void) -{ - errorOccured = GL_FALSE; -} - -/* -** Check if the GL command caused an error. -*/ -GLboolean __glXErrorOccured(void) -{ - return errorOccured; -} - -/************************************************************************/ - -/* -** Initialize the GLX extension. -*/ -void GlxExtensionInit(void) -{ - ExtensionEntry *extEntry; - int i; - - __glXContextRes = CreateNewResourceType((DeleteType)ContextGone); - __glXClientRes = CreateNewResourceType((DeleteType)ClientGone); - __glXPixmapRes = CreateNewResourceType((DeleteType)PixmapGone); - - /* - ** Add extension to server extensions. - */ - extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS, - __GLX_NUMBER_ERRORS, __glXDispatch, - __glXSwapDispatch, ResetExtension, - StandardMinorOpcode); - if (!extEntry) { - FatalError("__glXExtensionInit: AddExtensions failed\n"); - return; - } - if (!AddExtensionAlias(GLX_EXTENSION_ALIAS, extEntry)) { - ErrorF("__glXExtensionInit: AddExtensionAlias failed\n"); - return; - } - - __glXBadContext = extEntry->errorBase + GLXBadContext; - __glXBadContextState = extEntry->errorBase + GLXBadContextState; - __glXBadDrawable = extEntry->errorBase + GLXBadDrawable; - __glXBadPixmap = extEntry->errorBase + GLXBadPixmap; - __glXBadContextTag = extEntry->errorBase + GLXBadContextTag; - __glXBadCurrentWindow = extEntry->errorBase + GLXBadCurrentWindow; - __glXBadRenderRequest = extEntry->errorBase + GLXBadRenderRequest; - __glXBadLargeRequest = extEntry->errorBase + GLXBadLargeRequest; - __glXUnsupportedPrivateRequest = extEntry->errorBase + - GLXUnsupportedPrivateRequest; - - __glXSwapBarrierRes = CreateNewResourceType((DeleteType)SwapBarrierGone); - - /* - ** Initialize table of client state. There is never a client 0. - */ - for (i=1; i <= MAXCLIENTS; i++) { - __glXClients[i] = 0; - } - - /* - ** Initialize screen specific data. - */ - __glXScreenInit(screenInfo.numScreens); -} - -/************************************************************************/ - -Bool __glXCoreType(void) -{ - return __glXExt->type; -} - -/************************************************************************/ - -void GlxSetVisualConfigs(int nconfigs, - __GLXvisualConfig *configs, void **privates) -{ - (*__glXExt->setVisualConfigs)(nconfigs, configs, privates); -} - -static miInitVisualsProcPtr saveInitVisualsProc; - -Bool GlxInitVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, - int *rootDepthp, VisualID *defaultVisp, - unsigned long sizes, int bitsPerRGB, - int preferredVis) -{ - Bool ret; - - if (saveInitVisualsProc) { - ret = saveInitVisualsProc(visualp, depthp, nvisualp, ndepthp, - rootDepthp, defaultVisp, sizes, bitsPerRGB, - preferredVis); - if (!ret) - return False; - } - (*__glXExt->initVisuals)(visualp, depthp, nvisualp, ndepthp, rootDepthp, - defaultVisp, sizes, bitsPerRGB); - return True; -} - -void -GlxWrapInitVisuals(miInitVisualsProcPtr *initVisProc) -{ - saveInitVisualsProc = *initVisProc; - *initVisProc = GlxInitVisuals; - /* HACK: this shouldn't be done here but it's the earliest time */ - __glXExt = __glXglDDXExtensionInfo(); /* from GLcore */ -} - -/************************************************************************/ - -void __glXFlushContextCache(void) -{ - __glXLastContext = 0; -} - -/* -** Make a context the current one for the GL (in this implementation, there -** is only one instance of the GL, and we use it to serve all GL clients by -** switching it between different contexts). While we are at it, look up -** a context by its tag and return its (__GLXcontext *). -*/ -__GLXcontext *__glXForceCurrent(__GLXclientState *cl, GLXContextTag tag, - int *error) -{ - __GLXcontext *cx; - - /* - ** See if the context tag is legal; it is managed by the extension, - ** so if it's invalid, we have an implementation error. - */ - cx = (__GLXcontext *) __glXLookupContextByTag(cl, tag); - if (!cx) { - cl->client->errorValue = tag; - *error = __glXBadContextTag; - return 0; - } - - if (!cx->isDirect) { - if (cx->drawPriv == NULL) { - /* - ** The drawable has vanished. It must be a window, because only - ** windows can be destroyed from under us; GLX pixmaps are - ** refcounted and don't go away until no one is using them. - */ - *error = __glXBadCurrentWindow; - return 0; - } - } - - if (cx == __glXLastContext) { - /* No need to re-bind */ - return cx; - } - - /* Make this context the current one for the GL. */ - if (!cx->isDirect) { - if (!(*cx->gc->exports.forceCurrent)((__GLcontext *)cx->gc)) { - /* Bind failed, and set the error code. Bummer */ - cl->client->errorValue = cx->id; - *error = __glXBadContextState; - return 0; - } - } - __glXLastContext = cx; - return cx; -} - -/************************************************************************/ - -/* -** Top level dispatcher; all commands are executed from here down. -*/ -static int __glXDispatch(ClientPtr client) -{ - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** If we're expecting a glXRenderLarge request, this better be one. - */ - if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) { - client->errorValue = stuff->glxCode; - return __glXBadLargeRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSingleTable[opcode]; - return (*proc)(cl, (GLbyte *) stuff); -} - -static int __glXSwapDispatch(ClientPtr client) -{ - REQUEST(xGLXSingleReq); - CARD8 opcode; - int (*proc)(__GLXclientState *cl, GLbyte *pc); - __GLXclientState *cl; - - opcode = stuff->glxCode; - cl = __glXClients[client->index]; - if (!cl) { - cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); - __glXClients[client->index] = cl; - if (!cl) { - return BadAlloc; - } - __glXMemset(cl, 0, sizeof(__GLXclientState)); - } - - if (!cl->inUse) { - /* - ** This is first request from this client. Associate a resource - ** with the client so we will be notified when the client dies. - */ - XID xid = FakeClientID(client->index); - if (!AddResource( xid, __glXClientRes, (pointer)(long)client->index)) { - return BadAlloc; - } - ResetClientState(client->index); - cl->inUse = GL_TRUE; - cl->client = client; - } - - /* - ** Check for valid opcode. - */ - if (opcode >= __GLX_SINGLE_TABLE_SIZE) { - return BadRequest; - } - - /* - ** Use the opcode to index into the procedure table. - */ - proc = __glXSwapSingleTable[opcode]; - return (*proc)(cl, (GLbyte *) stuff); -} - -int __glXNoSuchSingleOpcode(__GLXclientState *cl, GLbyte *pc) -{ - return BadRequest; -} - -void __glXNoSuchRenderOpcode(GLbyte *pc) -{ - return; -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.NX.original deleted file mode 100644 index cd65fdc0e..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.NX.original +++ /dev/null @@ -1,581 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/glyph.c,v 1.5 2001/01/30 07:01:22 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" - -#ifdef NXAGENT_SERVER - -#include "NXpicturestr.h" -#include "NXglyphstr.h" -#include "Render.h" - -#define PANIC -#define WARNING -#undef DEBUG -#undef TEST - -#else - -#include "picturestr.h" -#include "glyphstr.h" - -#endif - -#if HAVE_STDINT_H -#include -#elif !defined(UINT32_MAX) -#define UINT32_MAX 0xffffffffU -#endif - -/* - * From Knuth -- a good choice for hash/rehash values is p, p-2 where - * p and p-2 are both prime. These tables are sized to have an extra 10% - * free to avoid exponential performance degradation as the hash table fills - */ -static GlyphHashSetRec glyphHashSets[] = { - { 32, 43, 41 }, - { 64, 73, 71 }, - { 128, 151, 149 }, - { 256, 283, 281 }, - { 512, 571, 569 }, - { 1024, 1153, 1151 }, - { 2048, 2269, 2267 }, - { 4096, 4519, 4517 }, - { 8192, 9013, 9011 }, - { 16384, 18043, 18041 }, - { 32768, 36109, 36107 }, - { 65536, 72091, 72089 }, - { 131072, 144409, 144407 }, - { 262144, 288361, 288359 }, - { 524288, 576883, 576881 }, - { 1048576, 1153459, 1153457 }, - { 2097152, 2307163, 2307161 }, - { 4194304, 4613893, 4613891 }, - { 8388608, 9227641, 9227639 }, - { 16777216, 18455029, 18455027 }, - { 33554432, 36911011, 36911009 }, - { 67108864, 73819861, 73819859 }, - { 134217728, 147639589, 147639587 }, - { 268435456, 295279081, 295279079 }, - { 536870912, 590559793, 590559791 } -}; - -#define NGLYPHHASHSETS (sizeof(glyphHashSets)/sizeof(glyphHashSets[0])) - -const CARD8 glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 }; - -GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled) -{ - int i; - - for (i = 0; i < NGLYPHHASHSETS; i++) - if (glyphHashSets[i].entries >= filled) - return &glyphHashSets[i]; - return 0; -} - -static int _GlyphSetPrivateAllocateIndex = 0; - -int -AllocateGlyphSetPrivateIndex (void) -{ - return _GlyphSetPrivateAllocateIndex++; -} - -void -ResetGlyphSetPrivateIndex (void) -{ - _GlyphSetPrivateAllocateIndex = 0; -} - -Bool -_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr) -{ - pointer *new; - - if (n > glyphSet->maxPrivate) { - if (glyphSet->devPrivates && - glyphSet->devPrivates != (pointer)(&glyphSet[1])) { - new = (pointer *) xrealloc (glyphSet->devPrivates, - (n + 1) * sizeof (pointer)); - if (!new) - return FALSE; - } else { - new = (pointer *) xalloc ((n + 1) * sizeof (pointer)); - if (!new) - return FALSE; - if (glyphSet->devPrivates) - memcpy (new, - glyphSet->devPrivates, - (glyphSet->maxPrivate + 1) * sizeof (pointer)); - } - glyphSet->devPrivates = new; - /* Zero out new, uninitialize privates */ - while (++glyphSet->maxPrivate < n) - glyphSet->devPrivates[glyphSet->maxPrivate] = (pointer)0; - } - glyphSet->devPrivates[n] = ptr; - return TRUE; -} - -Bool -GlyphInit (ScreenPtr pScreen) -{ - return TRUE; -} - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare) -{ - CARD32 elt, step, s; - GlyphPtr glyph; - GlyphRefPtr table, gr, del; - CARD32 tableSize = hash->hashSet->size; - - table = hash->table; - elt = signature % tableSize; - step = 0; - del = 0; - for (;;) - { - gr = &table[elt]; - s = gr->signature; - glyph = gr->glyph; - if (!glyph) - { - if (del) - gr = del; - break; - } - if (glyph == DeletedGlyph) - { - if (!del) - del = gr; - else if (gr == del) - break; - } - else if (s == signature && - (!match || - memcmp (&compare->info, &glyph->info, compare->size) == 0)) - { - break; - } - if (!step) - { - step = signature % hash->hashSet->rehash; - if (!step) - step = 1; - } - elt += step; - if (elt >= tableSize) - elt -= tableSize; - } - return gr; -} - -CARD32 -HashGlyph (GlyphPtr glyph) -{ - CARD32 *bits = (CARD32 *) &(glyph->info); - CARD32 hash; - int n = glyph->size / sizeof (CARD32); - - hash = 0; - while (n--) - hash ^= *bits++; - return hash; -} - -#ifdef CHECK_DUPLICATES -void -DuplicateRef (GlyphPtr glyph, char *where) -{ - ErrorF ("Duplicate Glyph 0x%x from %s\n", glyph, where); -} - -void -CheckDuplicates (GlyphHashPtr hash, char *where) -{ - GlyphPtr g; - int i, j; - - for (i = 0; i < hash->hashSet->size; i++) - { - g = hash->table[i].glyph; - if (!g || g == DeletedGlyph) - continue; - for (j = i + 1; j < hash->hashSet->size; j++) - if (hash->table[j].glyph == g) - DuplicateRef (g, where); - } -} -#else -#define CheckDuplicates(a,b) -#define DuplicateRef(a,b) -#endif - -void -FreeGlyph (GlyphPtr glyph, int format) -{ - CheckDuplicates (&globalGlyphs[format], "FreeGlyph"); - if (--glyph->refcnt == 0) - { - GlyphRefPtr gr; - int i; - int first; - - first = -1; - for (i = 0; i < globalGlyphs[format].hashSet->size; i++) - if (globalGlyphs[format].table[i].glyph == glyph) - { - if (first != -1) - DuplicateRef (glyph, "FreeGlyph check"); - first = i; - } - - gr = FindGlyphRef (&globalGlyphs[format], - HashGlyph (glyph), TRUE, glyph); - if (gr - globalGlyphs[format].table != first) - DuplicateRef (glyph, "Found wrong one"); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - gr->signature = 0; - globalGlyphs[format].tableEntries--; - } - xfree (glyph); - } -} - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) -{ - GlyphRefPtr gr; - CARD32 hash; - - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph top global"); - /* Locate existing matching glyph */ - hash = HashGlyph (glyph); - gr = FindGlyphRef (&globalGlyphs[glyphSet->fdepth], hash, TRUE, glyph); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - xfree (glyph); - glyph = gr->glyph; - } - else - { - gr->glyph = glyph; - gr->signature = hash; - globalGlyphs[glyphSet->fdepth].tableEntries++; - } - - /* Insert/replace glyphset value */ - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - ++glyph->refcnt; - if (gr->glyph && gr->glyph != DeletedGlyph) - FreeGlyph (gr->glyph, glyphSet->fdepth); - else - glyphSet->hash.tableEntries++; - gr->glyph = glyph; - gr->signature = id; - - #ifdef NXAGENT_SERVER - - gr -> corruptedGlyph = 1; - - #endif - - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph bottom"); -} - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphRefPtr gr; - GlyphPtr glyph; - - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - glyph = gr->glyph; - if (glyph && glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - glyphSet->hash.tableEntries--; - FreeGlyph (glyph, glyphSet->fdepth); - return TRUE; - } - return FALSE; -} - -#ifdef NXAGENT_SERVER - -GlyphPtr FindGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphRefPtr gr; - GlyphPtr glyph; - - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - glyph = gr -> glyph; - - if (glyph == DeletedGlyph) - { - glyph = 0; - } - else if (gr -> corruptedGlyph == 1) - { - #ifdef DEBUG - fprintf(stderr, "FindGlyphRef: Going to synchronize the glyph [%p] for glyphset [%p].\n", - (void *) glyph, (void *) glyphSet); - #endif - - nxagentAddGlyphs(glyphSet, &id, &(glyph -> info), 1, - (CARD8*)(glyph + 1), glyph -> size - sizeof(xGlyphInfo)); - } - - return glyph; -} - -#else - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphPtr glyph; - - glyph = FindGlyphRef (&glyphSet->hash, id, FALSE, 0)->glyph; - if (glyph == DeletedGlyph) - glyph = 0; - return glyph; -} - -#endif - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int fdepth) -{ - int size; - GlyphPtr glyph; - size_t padded_width; - - padded_width = PixmapBytePad (gi->width, glyphDepths[fdepth]); - if (gi->height && padded_width > (UINT32_MAX - sizeof(GlyphRec))/gi->height) - return 0; - size = gi->height * padded_width; - glyph = (GlyphPtr) xalloc (size + sizeof (GlyphRec)); - if (!glyph) - return 0; - glyph->refcnt = 0; - glyph->size = size + sizeof (xGlyphInfo); - glyph->info = *gi; - return glyph; -} - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet) -{ - hash->table = (GlyphRefPtr) xalloc (hashSet->size * sizeof (GlyphRefRec)); - if (!hash->table) - return FALSE; - memset (hash->table, 0, hashSet->size * sizeof (GlyphRefRec)); - hash->hashSet = hashSet; - hash->tableEntries = 0; - return TRUE; -} - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global) -{ - CARD32 tableEntries; - GlyphHashSetPtr hashSet; - GlyphHashRec newHash; - GlyphRefPtr gr; - GlyphPtr glyph; - int i; - int oldSize; - CARD32 s; - - #ifdef NXAGENT_SERVER - - CARD32 c; - - #endif - - tableEntries = hash->tableEntries + change; - hashSet = FindGlyphHashSet (tableEntries); - if (hashSet == hash->hashSet) - return TRUE; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash top"); - if (!AllocateGlyphHash (&newHash, hashSet)) - return FALSE; - if (hash->table) - { - oldSize = hash->hashSet->size; - for (i = 0; i < oldSize; i++) - { - glyph = hash->table[i].glyph; - if (glyph && glyph != DeletedGlyph) - { - s = hash->table[i].signature; - - #ifdef NXAGENT_SERVER - - c = hash->table[i].corruptedGlyph; - - #endif - - gr = FindGlyphRef (&newHash, s, global, glyph); - gr->signature = s; - gr->glyph = glyph; - - #ifdef NXAGENT_SERVER - - gr -> corruptedGlyph = c; - - #endif - - ++newHash.tableEntries; - } - } - xfree (hash->table); - } - *hash = newHash; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash bottom"); - return TRUE; -} - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change) -{ - return (ResizeGlyphHash (&glyphSet->hash, change, FALSE) && - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], change, TRUE)); -} - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format) -{ - GlyphSetPtr glyphSet; - int size; - - if (!globalGlyphs[fdepth].hashSet) - { - if (!AllocateGlyphHash (&globalGlyphs[fdepth], &glyphHashSets[0])) - return FALSE; - } - - size = (sizeof (GlyphSetRec) + - (sizeof (pointer) * _GlyphSetPrivateAllocateIndex)); - glyphSet = xalloc (size); - if (!glyphSet) - return FALSE; - bzero((char *)glyphSet, size); - glyphSet->maxPrivate = _GlyphSetPrivateAllocateIndex - 1; - if (_GlyphSetPrivateAllocateIndex) - glyphSet->devPrivates = (pointer)(&glyphSet[1]); - - if (!AllocateGlyphHash (&glyphSet->hash, &glyphHashSets[0])) - { - xfree (glyphSet); - return FALSE; - } - glyphSet->refcnt = 1; - glyphSet->fdepth = fdepth; - glyphSet->format = format; - return glyphSet; -} - -int -FreeGlyphSet (pointer value, - XID gid) -{ - GlyphSetPtr glyphSet = (GlyphSetPtr) value; - - if (--glyphSet->refcnt == 0) - { - CARD32 i, tableSize = glyphSet->hash.hashSet->size; - GlyphRefPtr table = glyphSet->hash.table; - GlyphPtr glyph; - - for (i = 0; i < tableSize; i++) - { - glyph = table[i].glyph; - if (glyph && glyph != DeletedGlyph) - FreeGlyph (glyph, glyphSet->fdepth); - } - if (!globalGlyphs[glyphSet->fdepth].tableEntries) - { - xfree (globalGlyphs[glyphSet->fdepth].table); - globalGlyphs[glyphSet->fdepth].table = 0; - globalGlyphs[glyphSet->fdepth].hashSet = 0; - } - else - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE); - xfree (table); - - if (glyphSet->devPrivates && - glyphSet->devPrivates != (pointer)(&glyphSet[1])) - xfree(glyphSet->devPrivates); - - xfree (glyphSet); - } - return Success; -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.X.original deleted file mode 100644 index 9f4d1c87b..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyph.c.X.original +++ /dev/null @@ -1,488 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/glyph.c,v 1.5 2001/01/30 07:01:22 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "picturestr.h" -#include "glyphstr.h" - -#if HAVE_STDINT_H -#include -#elif !defined(UINT32_MAX) -#define UINT32_MAX 0xffffffffU -#endif - -/* - * From Knuth -- a good choice for hash/rehash values is p, p-2 where - * p and p-2 are both prime. These tables are sized to have an extra 10% - * free to avoid exponential performance degradation as the hash table fills - */ -static GlyphHashSetRec glyphHashSets[] = { - { 32, 43, 41 }, - { 64, 73, 71 }, - { 128, 151, 149 }, - { 256, 283, 281 }, - { 512, 571, 569 }, - { 1024, 1153, 1151 }, - { 2048, 2269, 2267 }, - { 4096, 4519, 4517 }, - { 8192, 9013, 9011 }, - { 16384, 18043, 18041 }, - { 32768, 36109, 36107 }, - { 65536, 72091, 72089 }, - { 131072, 144409, 144407 }, - { 262144, 288361, 288359 }, - { 524288, 576883, 576881 }, - { 1048576, 1153459, 1153457 }, - { 2097152, 2307163, 2307161 }, - { 4194304, 4613893, 4613891 }, - { 8388608, 9227641, 9227639 }, - { 16777216, 18455029, 18455027 }, - { 33554432, 36911011, 36911009 }, - { 67108864, 73819861, 73819859 }, - { 134217728, 147639589, 147639587 }, - { 268435456, 295279081, 295279079 }, - { 536870912, 590559793, 590559791 } -}; - -#define NGLYPHHASHSETS (sizeof(glyphHashSets)/sizeof(glyphHashSets[0])) - -const CARD8 glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 }; - -GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled) -{ - int i; - - for (i = 0; i < NGLYPHHASHSETS; i++) - if (glyphHashSets[i].entries >= filled) - return &glyphHashSets[i]; - return 0; -} - -static int _GlyphSetPrivateAllocateIndex = 0; - -int -AllocateGlyphSetPrivateIndex (void) -{ - return _GlyphSetPrivateAllocateIndex++; -} - -void -ResetGlyphSetPrivateIndex (void) -{ - _GlyphSetPrivateAllocateIndex = 0; -} - -Bool -_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr) -{ - pointer *new; - - if (n > glyphSet->maxPrivate) { - if (glyphSet->devPrivates && - glyphSet->devPrivates != (pointer)(&glyphSet[1])) { - new = (pointer *) xrealloc (glyphSet->devPrivates, - (n + 1) * sizeof (pointer)); - if (!new) - return FALSE; - } else { - new = (pointer *) xalloc ((n + 1) * sizeof (pointer)); - if (!new) - return FALSE; - if (glyphSet->devPrivates) - memcpy (new, - glyphSet->devPrivates, - (glyphSet->maxPrivate + 1) * sizeof (pointer)); - } - glyphSet->devPrivates = new; - /* Zero out new, uninitialize privates */ - while (++glyphSet->maxPrivate < n) - glyphSet->devPrivates[glyphSet->maxPrivate] = (pointer)0; - } - glyphSet->devPrivates[n] = ptr; - return TRUE; -} - -Bool -GlyphInit (ScreenPtr pScreen) -{ - return TRUE; -} - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare) -{ - CARD32 elt, step, s; - GlyphPtr glyph; - GlyphRefPtr table, gr, del; - CARD32 tableSize = hash->hashSet->size; - - table = hash->table; - elt = signature % tableSize; - step = 0; - del = 0; - for (;;) - { - gr = &table[elt]; - s = gr->signature; - glyph = gr->glyph; - if (!glyph) - { - if (del) - gr = del; - break; - } - if (glyph == DeletedGlyph) - { - if (!del) - del = gr; - else if (gr == del) - break; - } - else if (s == signature && - (!match || - memcmp (&compare->info, &glyph->info, compare->size) == 0)) - { - break; - } - if (!step) - { - step = signature % hash->hashSet->rehash; - if (!step) - step = 1; - } - elt += step; - if (elt >= tableSize) - elt -= tableSize; - } - return gr; -} - -CARD32 -HashGlyph (GlyphPtr glyph) -{ - CARD32 *bits = (CARD32 *) &(glyph->info); - CARD32 hash; - int n = glyph->size / sizeof (CARD32); - - hash = 0; - while (n--) - hash ^= *bits++; - return hash; -} - -#ifdef CHECK_DUPLICATES -void -DuplicateRef (GlyphPtr glyph, char *where) -{ - ErrorF ("Duplicate Glyph 0x%x from %s\n", glyph, where); -} - -void -CheckDuplicates (GlyphHashPtr hash, char *where) -{ - GlyphPtr g; - int i, j; - - for (i = 0; i < hash->hashSet->size; i++) - { - g = hash->table[i].glyph; - if (!g || g == DeletedGlyph) - continue; - for (j = i + 1; j < hash->hashSet->size; j++) - if (hash->table[j].glyph == g) - DuplicateRef (g, where); - } -} -#else -#define CheckDuplicates(a,b) -#define DuplicateRef(a,b) -#endif - -void -FreeGlyph (GlyphPtr glyph, int format) -{ - CheckDuplicates (&globalGlyphs[format], "FreeGlyph"); - if (--glyph->refcnt == 0) - { - GlyphRefPtr gr; - int i; - int first; - - first = -1; - for (i = 0; i < globalGlyphs[format].hashSet->size; i++) - if (globalGlyphs[format].table[i].glyph == glyph) - { - if (first != -1) - DuplicateRef (glyph, "FreeGlyph check"); - first = i; - } - - gr = FindGlyphRef (&globalGlyphs[format], - HashGlyph (glyph), TRUE, glyph); - if (gr - globalGlyphs[format].table != first) - DuplicateRef (glyph, "Found wrong one"); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - gr->signature = 0; - globalGlyphs[format].tableEntries--; - } - xfree (glyph); - } -} - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) -{ - GlyphRefPtr gr; - CARD32 hash; - - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph top global"); - /* Locate existing matching glyph */ - hash = HashGlyph (glyph); - gr = FindGlyphRef (&globalGlyphs[glyphSet->fdepth], hash, TRUE, glyph); - if (gr->glyph && gr->glyph != DeletedGlyph) - { - xfree (glyph); - glyph = gr->glyph; - } - else - { - gr->glyph = glyph; - gr->signature = hash; - globalGlyphs[glyphSet->fdepth].tableEntries++; - } - - /* Insert/replace glyphset value */ - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - ++glyph->refcnt; - if (gr->glyph && gr->glyph != DeletedGlyph) - FreeGlyph (gr->glyph, glyphSet->fdepth); - else - glyphSet->hash.tableEntries++; - gr->glyph = glyph; - gr->signature = id; - CheckDuplicates (&globalGlyphs[glyphSet->fdepth], "AddGlyph bottom"); -} - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphRefPtr gr; - GlyphPtr glyph; - - gr = FindGlyphRef (&glyphSet->hash, id, FALSE, 0); - glyph = gr->glyph; - if (glyph && glyph != DeletedGlyph) - { - gr->glyph = DeletedGlyph; - glyphSet->hash.tableEntries--; - FreeGlyph (glyph, glyphSet->fdepth); - return TRUE; - } - return FALSE; -} - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id) -{ - GlyphPtr glyph; - - glyph = FindGlyphRef (&glyphSet->hash, id, FALSE, 0)->glyph; - if (glyph == DeletedGlyph) - glyph = 0; - return glyph; -} - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int fdepth) -{ - int size; - GlyphPtr glyph; - size_t padded_width; - - padded_width = PixmapBytePad (gi->width, glyphDepths[fdepth]); - if (gi->height && padded_width > (UINT32_MAX - sizeof(GlyphRec))/gi->height) - return 0; - size = gi->height * padded_width; - glyph = (GlyphPtr) xalloc (size + sizeof (GlyphRec)); - if (!glyph) - return 0; - glyph->refcnt = 0; - glyph->size = size + sizeof (xGlyphInfo); - glyph->info = *gi; - return glyph; -} - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet) -{ - hash->table = (GlyphRefPtr) xalloc (hashSet->size * sizeof (GlyphRefRec)); - if (!hash->table) - return FALSE; - memset (hash->table, 0, hashSet->size * sizeof (GlyphRefRec)); - hash->hashSet = hashSet; - hash->tableEntries = 0; - return TRUE; -} - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global) -{ - CARD32 tableEntries; - GlyphHashSetPtr hashSet; - GlyphHashRec newHash; - GlyphRefPtr gr; - GlyphPtr glyph; - int i; - int oldSize; - CARD32 s; - - tableEntries = hash->tableEntries + change; - hashSet = FindGlyphHashSet (tableEntries); - if (hashSet == hash->hashSet) - return TRUE; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash top"); - if (!AllocateGlyphHash (&newHash, hashSet)) - return FALSE; - if (hash->table) - { - oldSize = hash->hashSet->size; - for (i = 0; i < oldSize; i++) - { - glyph = hash->table[i].glyph; - if (glyph && glyph != DeletedGlyph) - { - s = hash->table[i].signature; - gr = FindGlyphRef (&newHash, s, global, glyph); - gr->signature = s; - gr->glyph = glyph; - ++newHash.tableEntries; - } - } - xfree (hash->table); - } - *hash = newHash; - if (global) - CheckDuplicates (hash, "ResizeGlyphHash bottom"); - return TRUE; -} - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change) -{ - return (ResizeGlyphHash (&glyphSet->hash, change, FALSE) && - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], change, TRUE)); -} - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format) -{ - GlyphSetPtr glyphSet; - int size; - - if (!globalGlyphs[fdepth].hashSet) - { - if (!AllocateGlyphHash (&globalGlyphs[fdepth], &glyphHashSets[0])) - return FALSE; - } - - size = (sizeof (GlyphSetRec) + - (sizeof (pointer) * _GlyphSetPrivateAllocateIndex)); - glyphSet = xalloc (size); - if (!glyphSet) - return FALSE; - bzero((char *)glyphSet, size); - glyphSet->maxPrivate = _GlyphSetPrivateAllocateIndex - 1; - if (_GlyphSetPrivateAllocateIndex) - glyphSet->devPrivates = (pointer)(&glyphSet[1]); - - if (!AllocateGlyphHash (&glyphSet->hash, &glyphHashSets[0])) - { - xfree (glyphSet); - return FALSE; - } - glyphSet->refcnt = 1; - glyphSet->fdepth = fdepth; - glyphSet->format = format; - return glyphSet; -} - -int -FreeGlyphSet (pointer value, - XID gid) -{ - GlyphSetPtr glyphSet = (GlyphSetPtr) value; - - if (--glyphSet->refcnt == 0) - { - CARD32 i, tableSize = glyphSet->hash.hashSet->size; - GlyphRefPtr table = glyphSet->hash.table; - GlyphPtr glyph; - - for (i = 0; i < tableSize; i++) - { - glyph = table[i].glyph; - if (glyph && glyph != DeletedGlyph) - FreeGlyph (glyph, glyphSet->fdepth); - } - if (!globalGlyphs[glyphSet->fdepth].tableEntries) - { - xfree (globalGlyphs[glyphSet->fdepth].table); - globalGlyphs[glyphSet->fdepth].table = 0; - globalGlyphs[glyphSet->fdepth].hashSet = 0; - } - else - ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE); - xfree (table); - - if (glyphSet->devPrivates && - glyphSet->devPrivates != (pointer)(&glyphSet[1])) - xfree(glyphSet->devPrivates); - - xfree (glyphSet); - } - return Success; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.NX.original deleted file mode 100644 index 7a1d813b3..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.NX.original +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* $Xorg: glyphcurs.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include -#include "dixfontstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "resource.h" -#include "dix.h" -#include "cursorstr.h" -#include "opaque.h" -#include "servermd.h" - -#include "../../fb/fb.h" -#include "Pixmaps.h" - -#ifndef True -#define True 1 -#endif - -/* - get the bits out of the font in a portable way. to avoid -dealing with padding and such-like, we draw the glyph into -a bitmap, then read the bits out with GetImage, which -uses server-natural format. - since all screens return the same bitmap format, we'll just use -the first one we find. - the character origin lines up with the hotspot in the -cursor metrics. -*/ - -int -ServerBitsFromGlyph(FontPtr pfont, unsigned ch, register CursorMetricPtr cm, unsigned char **ppbits) -{ - register ScreenPtr pScreen; - register GCPtr pGC; - xRectangle rect; - PixmapPtr ppix; - long nby; - char *pbits; - ChangeGCVal gcval[3]; - unsigned char char2b[2]; - - /* turn glyph index into a protocol-format char2b */ - char2b[0] = (unsigned char)(ch >> 8); - char2b[1] = (unsigned char)(ch & 0xff); - - pScreen = screenInfo.screens[0]; - nby = BitmapBytePad(cm->width) * (long)cm->height; - pbits = (char *)xalloc(nby); - if (!pbits) - return BadAlloc; - /* zeroing the (pad) bits seems to help some ddx cursor handling */ - bzero(pbits, nby); - - ppix = fbCreatePixmap(pScreen, cm->width, cm->height, 1); - pGC = GetScratchGC(1, pScreen); - if (!ppix || !pGC) - { - if (ppix) - fbDestroyPixmap(ppix); - if (pGC) - FreeScratchGC(pGC); - xfree(pbits); - return BadAlloc; - } - - #ifdef TEST - fprintf(stderr, "ServerBitsFromGlyph: Created virtual pixmap at [%p] with width [%d] height [%d] depth [%d].\n", - (void *) ppix, cm->width, cm->height, 1); - #endif - - nxagentPixmapPriv(ppix) -> id = 0; - nxagentPixmapPriv(ppix) -> mid = 0; - nxagentPixmapPriv(ppix) -> isVirtual = True; - nxagentPixmapPriv(ppix) -> pRealPixmap = NULL; - nxagentPixmapPriv(ppix) -> pVirtualPixmap = NULL; - - rect.x = 0; - rect.y = 0; - rect.width = cm->width; - rect.height = cm->height; - - pGC->stateChanges |= GCFunction | GCForeground | GCFont; - pGC->alu = GXcopy; - - pGC->fgPixel = 0; - - pfont->refcnt++; - - if (pGC->font) - CloseFont(pGC->font, (Font)0); - - pGC->font = pfont; - - ValidateGC((DrawablePtr)ppix, pGC); - fbPolyFillRect((DrawablePtr)ppix, pGC, 1, &rect); - - /* draw the glyph */ - gcval[0].val = 1; - pGC->fgPixel = 1; - - pGC->stateChanges |= GCForeground; - - ValidateGC((DrawablePtr)ppix, pGC); - miPolyText16((DrawablePtr)ppix, pGC, (int)cm->xhot, (int)cm->yhot, (int)1, (unsigned short*)char2b); - fbGetImage((DrawablePtr)ppix, 0, 0, cm->width, cm->height, - XYPixmap, 1, pbits); - *ppbits = (unsigned char *)pbits; - FreeScratchGC(pGC); - fbDestroyPixmap(ppix); - - #ifdef TEST - fprintf(stderr, "ServerBitsFromGlyph: Destroyed virtual pixmap at [%p].\n", - (void *) ppix); - #endif - - return Success; -} - - -Bool -CursorMetricsFromGlyph(register FontPtr pfont, unsigned ch, register CursorMetricPtr cm) -{ - CharInfoPtr pci; - unsigned long nglyphs; - CARD8 chs[2]; - FontEncoding encoding; - - chs[0] = ch >> 8; - chs[1] = ch; - encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; - if (encoding == Linear16Bit) - { - if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) - return FALSE; - } - else - { - if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) - return FALSE; - if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) - return FALSE; - } - (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); - if (nglyphs == 0) - return FALSE; - cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; - cm->height = pci->metrics.descent + pci->metrics.ascent; - if (pci->metrics.leftSideBearing > 0) - { - cm->width += pci->metrics.leftSideBearing; - cm->xhot = 0; - } - else - { - cm->xhot = -pci->metrics.leftSideBearing; - if (pci->metrics.rightSideBearing < 0) - cm->width -= pci->metrics.rightSideBearing; - } - if (pci->metrics.ascent < 0) - { - cm->height -= pci->metrics.ascent; - cm->yhot = 0; - } - else - { - cm->yhot = pci->metrics.ascent; - if (pci->metrics.descent < 0) - cm->height -= pci->metrics.descent; - } - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.X.original deleted file mode 100644 index 8f8adf5ce..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphcurs.c.X.original +++ /dev/null @@ -1,194 +0,0 @@ -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* $Xorg: glyphcurs.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include -#include "dixfontstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "resource.h" -#include "dix.h" -#include "cursorstr.h" -#include "opaque.h" -#include "servermd.h" - - -/* - get the bits out of the font in a portable way. to avoid -dealing with padding and such-like, we draw the glyph into -a bitmap, then read the bits out with GetImage, which -uses server-natural format. - since all screens return the same bitmap format, we'll just use -the first one we find. - the character origin lines up with the hotspot in the -cursor metrics. -*/ - -int -ServerBitsFromGlyph(FontPtr pfont, unsigned ch, register CursorMetricPtr cm, unsigned char **ppbits) -{ - register ScreenPtr pScreen; - register GCPtr pGC; - xRectangle rect; - PixmapPtr ppix; - long nby; - char *pbits; - ChangeGCVal gcval[3]; - unsigned char char2b[2]; - - /* turn glyph index into a protocol-format char2b */ - char2b[0] = (unsigned char)(ch >> 8); - char2b[1] = (unsigned char)(ch & 0xff); - - pScreen = screenInfo.screens[0]; - nby = BitmapBytePad(cm->width) * (long)cm->height; - pbits = (char *)xalloc(nby); - if (!pbits) - return BadAlloc; - /* zeroing the (pad) bits seems to help some ddx cursor handling */ - bzero(pbits, nby); - - ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width, - cm->height, 1); - pGC = GetScratchGC(1, pScreen); - if (!ppix || !pGC) - { - if (ppix) - (*pScreen->DestroyPixmap)(ppix); - if (pGC) - FreeScratchGC(pGC); - xfree(pbits); - return BadAlloc; - } - - rect.x = 0; - rect.y = 0; - rect.width = cm->width; - rect.height = cm->height; - - /* fill the pixmap with 0 */ - gcval[0].val = GXcopy; - gcval[1].val = 0; - gcval[2].ptr = (pointer)pfont; - dixChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, - NULL, gcval); - ValidateGC((DrawablePtr)ppix, pGC); - (*pGC->ops->PolyFillRect)((DrawablePtr)ppix, pGC, 1, &rect); - - /* draw the glyph */ - gcval[0].val = 1; - dixChangeGC(NullClient, pGC, GCForeground, NULL, gcval); - ValidateGC((DrawablePtr)ppix, pGC); - (*pGC->ops->PolyText16)((DrawablePtr)ppix, pGC, cm->xhot, cm->yhot, - 1, (unsigned short *)char2b); - (*pScreen->GetImage)((DrawablePtr)ppix, 0, 0, cm->width, cm->height, - XYPixmap, 1, pbits); - *ppbits = (unsigned char *)pbits; - FreeScratchGC(pGC); - (*pScreen->DestroyPixmap)(ppix); - return Success; -} - - -Bool -CursorMetricsFromGlyph(register FontPtr pfont, unsigned ch, register CursorMetricPtr cm) -{ - CharInfoPtr pci; - unsigned long nglyphs; - CARD8 chs[2]; - FontEncoding encoding; - - chs[0] = ch >> 8; - chs[1] = ch; - encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; - if (encoding == Linear16Bit) - { - if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) - return FALSE; - } - else - { - if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) - return FALSE; - if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) - return FALSE; - } - (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); - if (nglyphs == 0) - return FALSE; - cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; - cm->height = pci->metrics.descent + pci->metrics.ascent; - if (pci->metrics.leftSideBearing > 0) - { - cm->width += pci->metrics.leftSideBearing; - cm->xhot = 0; - } - else - { - cm->xhot = -pci->metrics.leftSideBearing; - if (pci->metrics.rightSideBearing < 0) - cm->width -= pci->metrics.rightSideBearing; - } - if (pci->metrics.ascent < 0) - { - cm->height -= pci->metrics.ascent; - cm->yhot = 0; - } - else - { - cm->yhot = pci->metrics.ascent; - if (pci->metrics.descent < 0) - cm->height -= pci->metrics.descent; - } - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.NX.original deleted file mode 100644 index fa6b5fb02..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.NX.original +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/glyphstr.h,v 1.3 2000/11/20 07:13:13 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -/* - * This must keep the same symbol as the original glyphstr.h - * or symbols will be redefined. The code here adds a field - * to _GlyphSet. This should be done by defining a new type - * and casting when appropriate. - */ - -#ifndef _GLYPHSTR_H_ -#define _GLYPHSTR_H_ - -#include -#include "../../render/picture.h" -#include "screenint.h" - -#define GlyphFormat1 0 -#define GlyphFormat4 1 -#define GlyphFormat8 2 -#define GlyphFormat16 3 -#define GlyphFormat32 4 -#define GlyphFormatNum 5 - -typedef struct _Glyph { - CARD32 refcnt; - CARD32 size; /* info + bitmap */ - xGlyphInfo info; - /* bits follow */ -} GlyphRec, *GlyphPtr; - -typedef struct _GlyphRef { - CARD32 signature; - GlyphPtr glyph; - CARD16 corruptedGlyph; -} GlyphRefRec, *GlyphRefPtr; - -#define DeletedGlyph ((GlyphPtr) 1) - -typedef struct _GlyphHashSet { - CARD32 entries; - CARD32 size; - CARD32 rehash; -} GlyphHashSetRec, *GlyphHashSetPtr; - -typedef struct _GlyphHash { - GlyphRefPtr table; - GlyphHashSetPtr hashSet; - CARD32 tableEntries; -} GlyphHashRec, *GlyphHashPtr; - -typedef struct _GlyphSet { - CARD32 refcnt; - PictFormatPtr format; - int fdepth; - GlyphHashRec hash; - int maxPrivate; - pointer *devPrivates; - CARD32 remoteID; -} GlyphSetRec, *GlyphSetPtr; - -#define GlyphSetGetPrivate(pGlyphSet,n) \ - ((n) > (pGlyphSet)->maxPrivate ? \ - (pointer) 0 : \ - (pGlyphSet)->devPrivates[n]) - -#define GlyphSetSetPrivate(pGlyphSet,n,ptr) \ - ((n) > (pGlyphSet)->maxPrivate ? \ - _GlyphSetSetNewPrivate(pGlyphSet, n, ptr) : \ - ((((pGlyphSet)->devPrivates[n] = (ptr)) != 0) || TRUE)) - -typedef struct _GlyphList { - INT16 xOff; - INT16 yOff; - CARD8 len; - PictFormatPtr format; -} GlyphListRec, *GlyphListPtr; - -extern GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled); - -int -AllocateGlyphSetPrivateIndex (void); - -void -ResetGlyphSetPrivateIndex (void); - -Bool -_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr); - -Bool -GlyphInit (ScreenPtr pScreen); - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare); - -CARD32 -HashGlyph (GlyphPtr glyph); - -void -FreeGlyph (GlyphPtr glyph, int format); - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id); - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int format); - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet); - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global); - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change); - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format); - -int -FreeGlyphSet (pointer value, - XID gid); - - - -#endif /* _GLYPHSTR_H_ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.X.original deleted file mode 100644 index f4777a248..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXglyphstr.h.X.original +++ /dev/null @@ -1,148 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/glyphstr.h,v 1.3 2000/11/20 07:13:13 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifndef _GLYPHSTR_H_ -#define _GLYPHSTR_H_ - -#include -#include "picture.h" -#include "screenint.h" - -#define GlyphFormat1 0 -#define GlyphFormat4 1 -#define GlyphFormat8 2 -#define GlyphFormat16 3 -#define GlyphFormat32 4 -#define GlyphFormatNum 5 - -typedef struct _Glyph { - CARD32 refcnt; - CARD32 size; /* info + bitmap */ - xGlyphInfo info; - /* bits follow */ -} GlyphRec, *GlyphPtr; - -typedef struct _GlyphRef { - CARD32 signature; - GlyphPtr glyph; -} GlyphRefRec, *GlyphRefPtr; - -#define DeletedGlyph ((GlyphPtr) 1) - -typedef struct _GlyphHashSet { - CARD32 entries; - CARD32 size; - CARD32 rehash; -} GlyphHashSetRec, *GlyphHashSetPtr; - -typedef struct _GlyphHash { - GlyphRefPtr table; - GlyphHashSetPtr hashSet; - CARD32 tableEntries; -} GlyphHashRec, *GlyphHashPtr; - -typedef struct _GlyphSet { - CARD32 refcnt; - PictFormatPtr format; - int fdepth; - GlyphHashRec hash; - int maxPrivate; - pointer *devPrivates; -} GlyphSetRec, *GlyphSetPtr; - -#define GlyphSetGetPrivate(pGlyphSet,n) \ - ((n) > (pGlyphSet)->maxPrivate ? \ - (pointer) 0 : \ - (pGlyphSet)->devPrivates[n]) - -#define GlyphSetSetPrivate(pGlyphSet,n,ptr) \ - ((n) > (pGlyphSet)->maxPrivate ? \ - _GlyphSetSetNewPrivate(pGlyphSet, n, ptr) : \ - ((((pGlyphSet)->devPrivates[n] = (ptr)) != 0) || TRUE)) - -typedef struct _GlyphList { - INT16 xOff; - INT16 yOff; - CARD8 len; - PictFormatPtr format; -} GlyphListRec, *GlyphListPtr; - -extern GlyphHashRec globalGlyphs[GlyphFormatNum]; - -GlyphHashSetPtr -FindGlyphHashSet (CARD32 filled); - -int -AllocateGlyphSetPrivateIndex (void); - -void -ResetGlyphSetPrivateIndex (void); - -Bool -_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr); - -Bool -GlyphInit (ScreenPtr pScreen); - -GlyphRefPtr -FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare); - -CARD32 -HashGlyph (GlyphPtr glyph); - -void -FreeGlyph (GlyphPtr glyph, int format); - -void -AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id); - -Bool -DeleteGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -FindGlyph (GlyphSetPtr glyphSet, Glyph id); - -GlyphPtr -AllocateGlyph (xGlyphInfo *gi, int format); - -Bool -AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet); - -Bool -ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global); - -Bool -ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change); - -GlyphSetPtr -AllocateGlyphSet (int fdepth, PictFormatPtr format); - -int -FreeGlyphSet (pointer value, - XID gid); - - - -#endif /* _GLYPHSTR_H_ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.NX.original deleted file mode 100644 index 3fc73cf3b..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.NX.original +++ /dev/null @@ -1,979 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XdotOrg: xc/programs/Xserver/mi/miexpose.c,v 1.6 2005/07/03 08:53:51 daniels Exp $ */ -/* $XFree86: xc/programs/Xserver/mi/miexpose.c,v 3.9tsi Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $Xorg: miexpose.c,v 1.4 2001/02/09 02:05:20 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#define NEED_EVENTS -#include -#include - -#include "misc.h" -#include "regionstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "windowstr.h" -#include "pixmap.h" -#include "input.h" - -#include "dixstruct.h" -#include "mi.h" -#include - -#include "globals.h" - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -/* - machine-independent graphics exposure code. any device that uses -the region package can call this. -*/ - -#ifdef NXAGENT_SERVER - -#include "Windows.h" - -#endif - -#ifndef RECTLIMIT -#define RECTLIMIT 25 /* pick a number, any number > 8 */ -#endif - -/* miHandleExposures - generate a region for exposures for areas that were copied from obscured or -non-existent areas to non-obscured areas of the destination. Paint the -background for the region, if the destination is a window. - -NOTE: - this should generally be called, even if graphicsExposures is false, -because this is where bits get recovered from backing store. - -NOTE: - added argument 'plane' is used to indicate how exposures from backing -store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea -should be used, else a CopyPlane of the indicated plane will be used. The -exposing is done by the backing store's GraphicsExpose function, of course. - -*/ - -RegionPtr -miHandleExposures(pSrcDrawable, pDstDrawable, - pGC, srcx, srcy, width, height, dstx, dsty, plane) - register DrawablePtr pSrcDrawable; - register DrawablePtr pDstDrawable; - GCPtr pGC; - int srcx, srcy; - int width, height; - int dstx, dsty; - unsigned long plane; -{ - register ScreenPtr pscr; - RegionPtr prgnSrcClip; /* drawable-relative source clip */ - RegionRec rgnSrcRec; - RegionPtr prgnDstClip; /* drawable-relative dest clip */ - RegionRec rgnDstRec; - BoxRec srcBox; /* unclipped source */ - RegionRec rgnExposed; /* exposed region, calculated source- - relative, made dst relative to - intersect with visible parts of - dest and send events to client, - and then screen relative to paint - the window background - */ - WindowPtr pSrcWin; - BoxRec expBox; - Bool extents; - -#ifdef NXAGENT_SERVER - - /* - * Set the elements reported by the compiler - * as uninitialized. - */ - - expBox.x1 = 0; - expBox.y1 = 0; - expBox.x2 = 0; - expBox.y2 = 0; - -#endif - - /* This prevents warning about pscr not being used. */ - pGC->pScreen = pscr = pGC->pScreen; - - /* avoid work if we can */ - if (!pGC->graphicsExposures && - (pDstDrawable->type == DRAWABLE_PIXMAP) && - ((pSrcDrawable->type == DRAWABLE_PIXMAP) || - (((WindowPtr)pSrcDrawable)->backStorage == NULL))) - return NULL; - - srcBox.x1 = srcx; - srcBox.y1 = srcy; - srcBox.x2 = srcx+width; - srcBox.y2 = srcy+height; - - if (pSrcDrawable->type != DRAWABLE_PIXMAP) - { - BoxRec TsrcBox; - - TsrcBox.x1 = srcx + pSrcDrawable->x; - TsrcBox.y1 = srcy + pSrcDrawable->y; - TsrcBox.x2 = TsrcBox.x1 + width; - TsrcBox.y2 = TsrcBox.y1 + height; - pSrcWin = (WindowPtr) pSrcDrawable; - if (pGC->subWindowMode == IncludeInferiors) - { - prgnSrcClip = NotClippedByChildren (pSrcWin); - if ((RECT_IN_REGION(pscr, prgnSrcClip, &TsrcBox)) == rgnIN) - { - REGION_DESTROY(pscr, prgnSrcClip); - return NULL; - } - } - else - { - if ((RECT_IN_REGION(pscr, &pSrcWin->clipList, &TsrcBox)) == rgnIN) - return NULL; - prgnSrcClip = &rgnSrcRec; - REGION_NULL(pscr, prgnSrcClip); - REGION_COPY(pscr, prgnSrcClip, &pSrcWin->clipList); - } - REGION_TRANSLATE(pscr, prgnSrcClip, - -pSrcDrawable->x, -pSrcDrawable->y); - } - else - { - BoxRec box; - - if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) && - (srcBox.x2 <= pSrcDrawable->width) && - (srcBox.y2 <= pSrcDrawable->height)) - return NULL; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pSrcDrawable->width; - box.y2 = pSrcDrawable->height; - prgnSrcClip = &rgnSrcRec; - REGION_INIT(pscr, prgnSrcClip, &box, 1); - pSrcWin = (WindowPtr)NULL; - } - - if (pDstDrawable == pSrcDrawable) - { - prgnDstClip = prgnSrcClip; - } - else if (pDstDrawable->type != DRAWABLE_PIXMAP) - { - if (pGC->subWindowMode == IncludeInferiors) - { - prgnDstClip = NotClippedByChildren((WindowPtr)pDstDrawable); - } - else - { - prgnDstClip = &rgnDstRec; - REGION_NULL(pscr, prgnDstClip); - REGION_COPY(pscr, prgnDstClip, - &((WindowPtr)pDstDrawable)->clipList); - } - REGION_TRANSLATE(pscr, prgnDstClip, - -pDstDrawable->x, -pDstDrawable->y); - } - else - { - BoxRec box; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pDstDrawable->width; - box.y2 = pDstDrawable->height; - prgnDstClip = &rgnDstRec; - REGION_INIT(pscr, prgnDstClip, &box, 1); - } - - /* drawable-relative source region */ - REGION_INIT(pscr, &rgnExposed, &srcBox, 1); - - /* now get the hidden parts of the source box*/ - REGION_SUBTRACT(pscr, &rgnExposed, &rgnExposed, prgnSrcClip); - - if (pSrcWin && pSrcWin->backStorage) - { - /* - * Copy any areas from the source backing store. Modifies - * rgnExposed. - */ - (* pSrcWin->drawable.pScreen->ExposeCopy) ((WindowPtr)pSrcDrawable, - pDstDrawable, - pGC, - &rgnExposed, - srcx, srcy, - dstx, dsty, - plane); - } - - /* move them over the destination */ - REGION_TRANSLATE(pscr, &rgnExposed, dstx-srcx, dsty-srcy); - - /* intersect with visible areas of dest */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, prgnDstClip); - - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-) - * for windows. - */ - extents = pGC->graphicsExposures && - (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) && - (pDstDrawable->type != DRAWABLE_PIXMAP); -#ifdef SHAPE - if (pSrcWin) - { - RegionPtr region; - if (!(region = wClipShape (pSrcWin))) - region = wBoundingShape (pSrcWin); - /* - * If you try to CopyArea the extents of a shaped window, compacting the - * exposed region will undo all our work! - */ - if (extents && pSrcWin && region && - (RECT_IN_REGION(pscr, region, &srcBox) != rgnIN)) - extents = FALSE; - } -#endif - if (extents) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - expBox = *REGION_EXTENTS(pscr, &rgnExposed); - REGION_RESET(pscr, &rgnExposed, &expBox); - /* need to clear out new areas of backing store */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - expBox.x1, - expBox.y1, - expBox.x2 - expBox.x1, - expBox.y2 - expBox.y1, - FALSE); - } - if ((pDstDrawable->type != DRAWABLE_PIXMAP) && - (((WindowPtr)pDstDrawable)->backgroundState != None)) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - /* make the exposed area screen-relative */ - REGION_TRANSLATE(pscr, &rgnExposed, - pDstDrawable->x, pDstDrawable->y); - - if (extents) - { - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, &pWin->clipList); - } - (*pWin->drawable.pScreen->PaintWindowBackground)( - (WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND); - - if (extents) - { - REGION_RESET(pscr, &rgnExposed, &expBox); - } - else - REGION_TRANSLATE(pscr, &rgnExposed, - -pDstDrawable->x, -pDstDrawable->y); - } - if (prgnDstClip == &rgnDstRec) - { - REGION_UNINIT(pscr, prgnDstClip); - } - else if (prgnDstClip != prgnSrcClip) - { - REGION_DESTROY(pscr, prgnDstClip); - } - - if (prgnSrcClip == &rgnSrcRec) - { - REGION_UNINIT(pscr, prgnSrcClip); - } - else - { - REGION_DESTROY(pscr, prgnSrcClip); - } - - if (pGC->graphicsExposures) - { - /* don't look */ - RegionPtr exposed = REGION_CREATE(pscr, NullBox, 0); - *exposed = rgnExposed; - return exposed; - } - else - { - REGION_UNINIT(pscr, &rgnExposed); - return NULL; - } -} - -/* send GraphicsExpose events, or a NoExpose event, based on the region */ - -void -miSendGraphicsExpose (client, pRgn, drawable, major, minor) - ClientPtr client; - RegionPtr pRgn; - XID drawable; - int major; - int minor; -{ - if (pRgn && !REGION_NIL(pRgn)) - { - xEvent *pEvent; - register xEvent *pe; - register BoxPtr pBox; - register int i; - int numRects; - - numRects = REGION_NUM_RECTS(pRgn); - pBox = REGION_RECTS(pRgn); - if(!(pEvent = (xEvent *)ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - pe = pEvent; - - for (i=1; i<=numRects; i++, pe++, pBox++) - { - pe->u.u.type = GraphicsExpose; - pe->u.graphicsExposure.drawable = drawable; - pe->u.graphicsExposure.x = pBox->x1; - pe->u.graphicsExposure.y = pBox->y1; - pe->u.graphicsExposure.width = pBox->x2 - pBox->x1; - pe->u.graphicsExposure.height = pBox->y2 - pBox->y1; - pe->u.graphicsExposure.count = numRects - i; - pe->u.graphicsExposure.majorEvent = major; - pe->u.graphicsExposure.minorEvent = minor; - } - TryClientEvents(client, pEvent, numRects, - (Mask)0, NoEventMask, NullGrab); - DEALLOCATE_LOCAL(pEvent); - } - else - { - xEvent event; - event.u.u.type = NoExpose; - event.u.noExposure.drawable = drawable; - event.u.noExposure.majorEvent = major; - event.u.noExposure.minorEvent = minor; - TryClientEvents(client, &event, 1, - (Mask)0, NoEventMask, NullGrab); - } -} - - -void -miSendExposures(pWin, pRgn, dx, dy) - WindowPtr pWin; - RegionPtr pRgn; - register int dx, dy; -{ - register BoxPtr pBox; - int numRects; - register xEvent *pEvent, *pe; - register int i; - - pBox = REGION_RECTS(pRgn); - numRects = REGION_NUM_RECTS(pRgn); - if(!(pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - - for (i=numRects, pe = pEvent; --i >= 0; pe++, pBox++) - { - pe->u.u.type = Expose; - pe->u.expose.window = pWin->drawable.id; - pe->u.expose.x = pBox->x1 - dx; - pe->u.expose.y = pBox->y1 - dy; - pe->u.expose.width = pBox->x2 - pBox->x1; - pe->u.expose.height = pBox->y2 - pBox->y1; - pe->u.expose.count = i; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - int scrnum = pWin->drawable.pScreen->myNum; - int x = 0, y = 0; - XID realWin = 0; - - if(!pWin->parent) { - x = panoramiXdataPtr[scrnum].x; - y = panoramiXdataPtr[scrnum].y; - pWin = WindowTable[0]; - realWin = pWin->drawable.id; - } else if (scrnum) { - PanoramiXRes *win; - win = PanoramiXFindIDByScrnum(XRT_WINDOW, - pWin->drawable.id, scrnum); - if(!win) { - DEALLOCATE_LOCAL(pEvent); - return; - } - realWin = win->info[0].id; - pWin = LookupIDByType(realWin, RT_WINDOW); - } - if(x || y || scrnum) - for (i = 0; i < numRects; i++) { - pEvent[i].u.expose.window = realWin; - pEvent[i].u.expose.x += x; - pEvent[i].u.expose.y += y; - } - } -#endif - - DeliverEvents(pWin, pEvent, numRects, NullWindow); - - DEALLOCATE_LOCAL(pEvent); -} - -void -miWindowExposures(pWin, prgn, other_exposed) - WindowPtr pWin; - register RegionPtr prgn, other_exposed; -{ -#ifdef NXAGENT_SERVER - - int total; - -#endif - RegionPtr exposures = prgn; - if (pWin->backStorage && prgn) - /* - * in some cases, backing store will cause a different - * region to be exposed than needs to be repainted - * (like when a window is mapped). RestoreAreas is - * allowed to return a region other than prgn, - * in which case this routine will free the resultant - * region. If exposures is null, then no events will - * be sent to the client; if prgn is empty - * no areas will be repainted. - */ - exposures = (*pWin->drawable.pScreen->RestoreAreas)(pWin, prgn); - if ((prgn && !REGION_NIL(prgn)) || - (exposures && !REGION_NIL(exposures)) || other_exposed) - { - RegionRec expRec; - int clientInterested; - - /* - * Restore from backing-store FIRST. - */ - clientInterested = (pWin->eventMask|wOtherEventMasks(pWin)) & ExposureMask; - if (other_exposed) - { - if (exposures) - { - REGION_UNION(pWin->drawable.pScreen, other_exposed, - exposures, - other_exposed); - if (exposures != prgn) - REGION_DESTROY(pWin->drawable.pScreen, exposures); - } - exposures = other_exposed; - } -#ifdef NXAGENT_SERVER - - /* - * If the number of rectangles is greater - * than 4, let the function decide. - */ - - total = REGION_NUM_RECTS(exposures); - - if (clientInterested && exposures && (total > RECTLIMIT || - (total > 4 && nxagentExtentsPredicate(total) == 1))) -#else - if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT)) -#endif - { - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-). - */ - BoxRec box; - - box = *REGION_EXTENTS( pWin->drawable.pScreen, exposures); - if (exposures == prgn) { - exposures = &expRec; - REGION_INIT( pWin->drawable.pScreen, exposures, &box, 1); - REGION_RESET( pWin->drawable.pScreen, prgn, &box); - } else { - REGION_RESET( pWin->drawable.pScreen, exposures, &box); - REGION_UNION( pWin->drawable.pScreen, prgn, prgn, exposures); - } - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT( pWin->drawable.pScreen, prgn, prgn, &pWin->clipList); - /* need to clear out new areas of backing store, too */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - box.x1 - pWin->drawable.x, - box.y1 - pWin->drawable.y, - box.x2 - box.x1, - box.y2 - box.y1, - FALSE); - } - if (prgn && !REGION_NIL(prgn)) - (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, prgn, PW_BACKGROUND); - if (clientInterested && exposures && !REGION_NIL(exposures)) - miSendExposures(pWin, exposures, - pWin->drawable.x, pWin->drawable.y); - if (exposures == &expRec) - { - REGION_UNINIT( pWin->drawable.pScreen, exposures); - } - else if (exposures && exposures != prgn && exposures != other_exposed) - REGION_DESTROY( pWin->drawable.pScreen, exposures); - if (prgn) - REGION_EMPTY( pWin->drawable.pScreen, prgn); - } - else if (exposures && exposures != prgn) - REGION_DESTROY( pWin->drawable.pScreen, exposures); -} - - -/* - this code is highly unlikely. it is not haile selassie. - - there is some hair here. we can't just use the window's -clip region as it is, because if we are painting the border, -the border is not in the client area and so we will be excluded -when we validate the GC, and if we are painting a parent-relative -background, the area we want to paint is in some other window. -since we trust the code calling us to tell us to paint only areas -that are really ours, we will temporarily give the window a -clipList the size of the whole screen and an origin at (0,0). -this more or less assumes that ddX code will do translation -based on the window's absolute position, and that ValidateGC will -look at clipList, and that no other fields from the -window will be used. it's not possible to just draw -in the root because it may be a different depth. - -to get the tile to align correctly we set the GC's tile origin to -be the (x,y) of the window's upper left corner, after which we -get the right bits when drawing into the root. - -because the clip_mask is being set to None, we may call DoChangeGC with -fPointer set true, thus we no longer need to install the background or -border tile in the resource table. -*/ - -static RESTYPE ResType = 0; -static int numGCs = 0; -static GCPtr screenContext[MAXSCREENS]; - -/*ARGSUSED*/ -static int -tossGC ( - pointer value, - XID id) -{ - GCPtr pGC = (GCPtr)value; - screenContext[pGC->pScreen->myNum] = (GCPtr)NULL; - FreeGC (pGC, id); - numGCs--; - if (!numGCs) - ResType = 0; - - return 0; -} - - -void -miPaintWindow(pWin, prgn, what) -register WindowPtr pWin; -RegionPtr prgn; -int what; -{ - int status; - - Bool usingScratchGC = FALSE; - WindowPtr pRoot; - -#define FUNCTION 0 -#define FOREGROUND 1 -#define TILE 2 -#define FILLSTYLE 3 -#define ABSX 4 -#define ABSY 5 -#define CLIPMASK 6 -#define SUBWINDOW 7 -#define COUNT_BITS 8 - - ChangeGCVal gcval[7]; - ChangeGCVal newValues [COUNT_BITS]; - - BITS32 gcmask, index, mask; - RegionRec prgnWin; - DDXPointRec oldCorner; - BoxRec box; - WindowPtr pBgWin; - GCPtr pGC; - register int i; - register BoxPtr pbox; - register ScreenPtr pScreen = pWin->drawable.pScreen; - register xRectangle *prect; - int numRects; - -#ifdef NXAGENT_SERVER - - /* - * Set the elements reported by the compiler - * as uninitialized. - */ - - prgnWin.extents.x1 = 0; - prgnWin.extents.y1 = 0; - prgnWin.extents.x2 = 0; - prgnWin.extents.y2 = 0; - - prgnWin.data = NULL; - - oldCorner.x = 0; - oldCorner.y = 0; - -#endif - - gcmask = 0; - - if (what == PW_BACKGROUND) - { - switch (pWin->backgroundState) { - case None: - return; - case ParentRelative: - (*pWin->parent->drawable.pScreen->PaintWindowBackground)(pWin->parent, prgn, what); - return; - case BackgroundPixel: - newValues[FOREGROUND].val = pWin->background.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - break; - case BackgroundPixmap: - newValues[TILE].ptr = (pointer)pWin->background.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - break; - } - } - else - { - if (pWin->borderIsPixel) - { - newValues[FOREGROUND].val = pWin->border.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - } - else - { - newValues[TILE].ptr = (pointer)pWin->border.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - } - } - - prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(prgn) * - sizeof(xRectangle)); - if (!prect) - return; - - newValues[FUNCTION].val = GXcopy; - gcmask |= GCFunction | GCClipMask; - - i = pScreen->myNum; - pRoot = WindowTable[i]; - - pBgWin = pWin; - if (what == PW_BORDER) - { - while (pBgWin->backgroundState == ParentRelative) - pBgWin = pBgWin->parent; - } - - if ((pWin->drawable.depth != pRoot->drawable.depth) || - (pWin->drawable.bitsPerPixel != pRoot->drawable.bitsPerPixel)) - { - usingScratchGC = TRUE; - pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen); - if (!pGC) - { - DEALLOCATE_LOCAL(prect); - return; - } - /* - * mash the clip list so we can paint the border by - * mangling the window in place, pretending it - * spans the entire screen - */ - if (what == PW_BORDER) - { - prgnWin = pWin->clipList; - oldCorner.x = pWin->drawable.x; - oldCorner.y = pWin->drawable.y; - pWin->drawable.x = pWin->drawable.y = 0; - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - } - else - { - newValues[ABSX].val = 0; - newValues[ABSY].val = 0; - } - } else { - /* - * draw the background to the root window - */ - if (screenContext[i] == (GCPtr)NULL) - { - if (!ResType && !(ResType = CreateNewResourceType(tossGC))) - return; - screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0, - (XID *)NULL, &status); - if (!screenContext[i]) - return; - numGCs++; - if (!AddResource(FakeClientID(0), ResType, - (pointer)screenContext[i])) - return; - } - pGC = screenContext[i]; - newValues[SUBWINDOW].val = IncludeInferiors; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - gcmask |= GCSubwindowMode; - pWin = pRoot; - } - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack); - - mask = gcmask; - gcmask = 0; - i = 0; - while (mask) { - index = lowbit (mask); - mask &= ~index; - switch (index) { - case GCFunction: - if (pGC->alu != newValues[FUNCTION].val) { - gcmask |= index; - gcval[i++].val = newValues[FUNCTION].val; - } - break; - case GCTileStipXOrigin: - if ( pGC->patOrg.x != newValues[ABSX].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSX].val; - } - break; - case GCTileStipYOrigin: - if ( pGC->patOrg.y != newValues[ABSY].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSY].val; - } - break; - case GCClipMask: - if ( pGC->clientClipType != CT_NONE) { - gcmask |= index; - gcval[i++].val = CT_NONE; - } - break; - case GCSubwindowMode: - if ( pGC->subWindowMode != newValues[SUBWINDOW].val) { - gcmask |= index; - gcval[i++].val = newValues[SUBWINDOW].val; - } - break; - case GCTile: - if (pGC->tileIsPixel || pGC->tile.pixmap != newValues[TILE].ptr) - { - gcmask |= index; - gcval[i++].ptr = newValues[TILE].ptr; - } - break; - case GCFillStyle: - if ( pGC->fillStyle != newValues[FILLSTYLE].val) { - gcmask |= index; - gcval[i++].val = newValues[FILLSTYLE].val; - } - break; - case GCForeground: - if ( pGC->fgPixel != newValues[FOREGROUND].val) { - gcmask |= index; - gcval[i++].val = newValues[FOREGROUND].val; - } - break; - } - } - - if (gcmask) - dixChangeGC(NullClient, pGC, gcmask, NULL, gcval); - - if (pWin->drawable.serialNumber != pGC->serialNumber) - ValidateGC((DrawablePtr)pWin, pGC); - - numRects = REGION_NUM_RECTS(prgn); - pbox = REGION_RECTS(prgn); - for (i= numRects; --i >= 0; pbox++, prect++) - { - prect->x = pbox->x1 - pWin->drawable.x; - prect->y = pbox->y1 - pWin->drawable.y; - prect->width = pbox->x2 - pbox->x1; - prect->height = pbox->y2 - pbox->y1; - } - prect -= numRects; - (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect); - DEALLOCATE_LOCAL(prect); - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing); - - if (usingScratchGC) - { - if (what == PW_BORDER) - { - REGION_UNINIT(pScreen, &pWin->clipList); - pWin->clipList = prgnWin; - pWin->drawable.x = oldCorner.x; - pWin->drawable.y = oldCorner.y; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - FreeScratchGC(pGC); - } -} - - -/* MICLEARDRAWABLE -- sets the entire drawable to the background color of - * the GC. Useful when we have a scratch drawable and need to initialize - * it. */ -void -miClearDrawable(pDraw, pGC) - DrawablePtr pDraw; - GCPtr pGC; -{ - XID fg = pGC->fgPixel; - XID bg = pGC->bgPixel; - xRectangle rect; - - rect.x = 0; - rect.y = 0; - rect.width = pDraw->width; - rect.height = pDraw->height; - DoChangeGC(pGC, GCForeground, &bg, 0); - ValidateGC(pDraw, pGC); - (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect); - DoChangeGC(pGC, GCForeground, &fg, 0); - ValidateGC(pDraw, pGC); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.X.original deleted file mode 100644 index 9a0bd06b5..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiexpose.c.X.original +++ /dev/null @@ -1,905 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/mi/miexpose.c,v 1.6 2005/07/03 08:53:51 daniels Exp $ */ -/* $XFree86: xc/programs/Xserver/mi/miexpose.c,v 3.9tsi Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $Xorg: miexpose.c,v 1.4 2001/02/09 02:05:20 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#define NEED_EVENTS -#include -#include - -#include "misc.h" -#include "regionstr.h" -#include "scrnintstr.h" -#include "gcstruct.h" -#include "windowstr.h" -#include "pixmap.h" -#include "input.h" - -#include "dixstruct.h" -#include "mi.h" -#include - -#include "globals.h" - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -/* - machine-independent graphics exposure code. any device that uses -the region package can call this. -*/ - -#ifndef RECTLIMIT -#define RECTLIMIT 25 /* pick a number, any number > 8 */ -#endif - -/* miHandleExposures - generate a region for exposures for areas that were copied from obscured or -non-existent areas to non-obscured areas of the destination. Paint the -background for the region, if the destination is a window. - -NOTE: - this should generally be called, even if graphicsExposures is false, -because this is where bits get recovered from backing store. - -NOTE: - added argument 'plane' is used to indicate how exposures from backing -store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea -should be used, else a CopyPlane of the indicated plane will be used. The -exposing is done by the backing store's GraphicsExpose function, of course. - -*/ - -RegionPtr -miHandleExposures(pSrcDrawable, pDstDrawable, - pGC, srcx, srcy, width, height, dstx, dsty, plane) - register DrawablePtr pSrcDrawable; - register DrawablePtr pDstDrawable; - GCPtr pGC; - int srcx, srcy; - int width, height; - int dstx, dsty; - unsigned long plane; -{ - register ScreenPtr pscr; - RegionPtr prgnSrcClip; /* drawable-relative source clip */ - RegionRec rgnSrcRec; - RegionPtr prgnDstClip; /* drawable-relative dest clip */ - RegionRec rgnDstRec; - BoxRec srcBox; /* unclipped source */ - RegionRec rgnExposed; /* exposed region, calculated source- - relative, made dst relative to - intersect with visible parts of - dest and send events to client, - and then screen relative to paint - the window background - */ - WindowPtr pSrcWin; - BoxRec expBox; - Bool extents; - - /* This prevents warning about pscr not being used. */ - pGC->pScreen = pscr = pGC->pScreen; - - /* avoid work if we can */ - if (!pGC->graphicsExposures && - (pDstDrawable->type == DRAWABLE_PIXMAP) && - ((pSrcDrawable->type == DRAWABLE_PIXMAP) || - (((WindowPtr)pSrcDrawable)->backStorage == NULL))) - return NULL; - - srcBox.x1 = srcx; - srcBox.y1 = srcy; - srcBox.x2 = srcx+width; - srcBox.y2 = srcy+height; - - if (pSrcDrawable->type != DRAWABLE_PIXMAP) - { - BoxRec TsrcBox; - - TsrcBox.x1 = srcx + pSrcDrawable->x; - TsrcBox.y1 = srcy + pSrcDrawable->y; - TsrcBox.x2 = TsrcBox.x1 + width; - TsrcBox.y2 = TsrcBox.y1 + height; - pSrcWin = (WindowPtr) pSrcDrawable; - if (pGC->subWindowMode == IncludeInferiors) - { - prgnSrcClip = NotClippedByChildren (pSrcWin); - if ((RECT_IN_REGION(pscr, prgnSrcClip, &TsrcBox)) == rgnIN) - { - REGION_DESTROY(pscr, prgnSrcClip); - return NULL; - } - } - else - { - if ((RECT_IN_REGION(pscr, &pSrcWin->clipList, &TsrcBox)) == rgnIN) - return NULL; - prgnSrcClip = &rgnSrcRec; - REGION_NULL(pscr, prgnSrcClip); - REGION_COPY(pscr, prgnSrcClip, &pSrcWin->clipList); - } - REGION_TRANSLATE(pscr, prgnSrcClip, - -pSrcDrawable->x, -pSrcDrawable->y); - } - else - { - BoxRec box; - - if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) && - (srcBox.x2 <= pSrcDrawable->width) && - (srcBox.y2 <= pSrcDrawable->height)) - return NULL; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pSrcDrawable->width; - box.y2 = pSrcDrawable->height; - prgnSrcClip = &rgnSrcRec; - REGION_INIT(pscr, prgnSrcClip, &box, 1); - pSrcWin = (WindowPtr)NULL; - } - - if (pDstDrawable == pSrcDrawable) - { - prgnDstClip = prgnSrcClip; - } - else if (pDstDrawable->type != DRAWABLE_PIXMAP) - { - if (pGC->subWindowMode == IncludeInferiors) - { - prgnDstClip = NotClippedByChildren((WindowPtr)pDstDrawable); - } - else - { - prgnDstClip = &rgnDstRec; - REGION_NULL(pscr, prgnDstClip); - REGION_COPY(pscr, prgnDstClip, - &((WindowPtr)pDstDrawable)->clipList); - } - REGION_TRANSLATE(pscr, prgnDstClip, - -pDstDrawable->x, -pDstDrawable->y); - } - else - { - BoxRec box; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pDstDrawable->width; - box.y2 = pDstDrawable->height; - prgnDstClip = &rgnDstRec; - REGION_INIT(pscr, prgnDstClip, &box, 1); - } - - /* drawable-relative source region */ - REGION_INIT(pscr, &rgnExposed, &srcBox, 1); - - /* now get the hidden parts of the source box*/ - REGION_SUBTRACT(pscr, &rgnExposed, &rgnExposed, prgnSrcClip); - - if (pSrcWin && pSrcWin->backStorage) - { - /* - * Copy any areas from the source backing store. Modifies - * rgnExposed. - */ - (* pSrcWin->drawable.pScreen->ExposeCopy) ((WindowPtr)pSrcDrawable, - pDstDrawable, - pGC, - &rgnExposed, - srcx, srcy, - dstx, dsty, - plane); - } - - /* move them over the destination */ - REGION_TRANSLATE(pscr, &rgnExposed, dstx-srcx, dsty-srcy); - - /* intersect with visible areas of dest */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, prgnDstClip); - - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-) - * for windows. - */ - extents = pGC->graphicsExposures && - (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) && - (pDstDrawable->type != DRAWABLE_PIXMAP); -#ifdef SHAPE - if (pSrcWin) - { - RegionPtr region; - if (!(region = wClipShape (pSrcWin))) - region = wBoundingShape (pSrcWin); - /* - * If you try to CopyArea the extents of a shaped window, compacting the - * exposed region will undo all our work! - */ - if (extents && pSrcWin && region && - (RECT_IN_REGION(pscr, region, &srcBox) != rgnIN)) - extents = FALSE; - } -#endif - if (extents) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - expBox = *REGION_EXTENTS(pscr, &rgnExposed); - REGION_RESET(pscr, &rgnExposed, &expBox); - /* need to clear out new areas of backing store */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - expBox.x1, - expBox.y1, - expBox.x2 - expBox.x1, - expBox.y2 - expBox.y1, - FALSE); - } - if ((pDstDrawable->type != DRAWABLE_PIXMAP) && - (((WindowPtr)pDstDrawable)->backgroundState != None)) - { - WindowPtr pWin = (WindowPtr)pDstDrawable; - - /* make the exposed area screen-relative */ - REGION_TRANSLATE(pscr, &rgnExposed, - pDstDrawable->x, pDstDrawable->y); - - if (extents) - { - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, &pWin->clipList); - } - (*pWin->drawable.pScreen->PaintWindowBackground)( - (WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND); - - if (extents) - { - REGION_RESET(pscr, &rgnExposed, &expBox); - } - else - REGION_TRANSLATE(pscr, &rgnExposed, - -pDstDrawable->x, -pDstDrawable->y); - } - if (prgnDstClip == &rgnDstRec) - { - REGION_UNINIT(pscr, prgnDstClip); - } - else if (prgnDstClip != prgnSrcClip) - { - REGION_DESTROY(pscr, prgnDstClip); - } - - if (prgnSrcClip == &rgnSrcRec) - { - REGION_UNINIT(pscr, prgnSrcClip); - } - else - { - REGION_DESTROY(pscr, prgnSrcClip); - } - - if (pGC->graphicsExposures) - { - /* don't look */ - RegionPtr exposed = REGION_CREATE(pscr, NullBox, 0); - *exposed = rgnExposed; - return exposed; - } - else - { - REGION_UNINIT(pscr, &rgnExposed); - return NULL; - } -} - -/* send GraphicsExpose events, or a NoExpose event, based on the region */ - -void -miSendGraphicsExpose (client, pRgn, drawable, major, minor) - ClientPtr client; - RegionPtr pRgn; - XID drawable; - int major; - int minor; -{ - if (pRgn && !REGION_NIL(pRgn)) - { - xEvent *pEvent; - register xEvent *pe; - register BoxPtr pBox; - register int i; - int numRects; - - numRects = REGION_NUM_RECTS(pRgn); - pBox = REGION_RECTS(pRgn); - if(!(pEvent = (xEvent *)ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - pe = pEvent; - - for (i=1; i<=numRects; i++, pe++, pBox++) - { - pe->u.u.type = GraphicsExpose; - pe->u.graphicsExposure.drawable = drawable; - pe->u.graphicsExposure.x = pBox->x1; - pe->u.graphicsExposure.y = pBox->y1; - pe->u.graphicsExposure.width = pBox->x2 - pBox->x1; - pe->u.graphicsExposure.height = pBox->y2 - pBox->y1; - pe->u.graphicsExposure.count = numRects - i; - pe->u.graphicsExposure.majorEvent = major; - pe->u.graphicsExposure.minorEvent = minor; - } - TryClientEvents(client, pEvent, numRects, - (Mask)0, NoEventMask, NullGrab); - DEALLOCATE_LOCAL(pEvent); - } - else - { - xEvent event; - event.u.u.type = NoExpose; - event.u.noExposure.drawable = drawable; - event.u.noExposure.majorEvent = major; - event.u.noExposure.minorEvent = minor; - TryClientEvents(client, &event, 1, - (Mask)0, NoEventMask, NullGrab); - } -} - - -void -miSendExposures(pWin, pRgn, dx, dy) - WindowPtr pWin; - RegionPtr pRgn; - register int dx, dy; -{ - register BoxPtr pBox; - int numRects; - register xEvent *pEvent, *pe; - register int i; - - pBox = REGION_RECTS(pRgn); - numRects = REGION_NUM_RECTS(pRgn); - if(!(pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent)))) - return; - - for (i=numRects, pe = pEvent; --i >= 0; pe++, pBox++) - { - pe->u.u.type = Expose; - pe->u.expose.window = pWin->drawable.id; - pe->u.expose.x = pBox->x1 - dx; - pe->u.expose.y = pBox->y1 - dy; - pe->u.expose.width = pBox->x2 - pBox->x1; - pe->u.expose.height = pBox->y2 - pBox->y1; - pe->u.expose.count = i; - } - -#ifdef PANORAMIX - if(!noPanoramiXExtension) { - int scrnum = pWin->drawable.pScreen->myNum; - int x = 0, y = 0; - XID realWin = 0; - - if(!pWin->parent) { - x = panoramiXdataPtr[scrnum].x; - y = panoramiXdataPtr[scrnum].y; - pWin = WindowTable[0]; - realWin = pWin->drawable.id; - } else if (scrnum) { - PanoramiXRes *win; - win = PanoramiXFindIDByScrnum(XRT_WINDOW, - pWin->drawable.id, scrnum); - if(!win) { - DEALLOCATE_LOCAL(pEvent); - return; - } - realWin = win->info[0].id; - pWin = LookupIDByType(realWin, RT_WINDOW); - } - if(x || y || scrnum) - for (i = 0; i < numRects; i++) { - pEvent[i].u.expose.window = realWin; - pEvent[i].u.expose.x += x; - pEvent[i].u.expose.y += y; - } - } -#endif - - DeliverEvents(pWin, pEvent, numRects, NullWindow); - - DEALLOCATE_LOCAL(pEvent); -} - -void -miWindowExposures(pWin, prgn, other_exposed) - WindowPtr pWin; - register RegionPtr prgn, other_exposed; -{ - RegionPtr exposures = prgn; - if (pWin->backStorage && prgn) - /* - * in some cases, backing store will cause a different - * region to be exposed than needs to be repainted - * (like when a window is mapped). RestoreAreas is - * allowed to return a region other than prgn, - * in which case this routine will free the resultant - * region. If exposures is null, then no events will - * be sent to the client; if prgn is empty - * no areas will be repainted. - */ - exposures = (*pWin->drawable.pScreen->RestoreAreas)(pWin, prgn); - if ((prgn && !REGION_NIL(prgn)) || - (exposures && !REGION_NIL(exposures)) || other_exposed) - { - RegionRec expRec; - int clientInterested; - - /* - * Restore from backing-store FIRST. - */ - clientInterested = (pWin->eventMask|wOtherEventMasks(pWin)) & ExposureMask; - if (other_exposed) - { - if (exposures) - { - REGION_UNION(pWin->drawable.pScreen, other_exposed, - exposures, - other_exposed); - if (exposures != prgn) - REGION_DESTROY(pWin->drawable.pScreen, exposures); - } - exposures = other_exposed; - } - if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT)) - { - /* - * If we have LOTS of rectangles, we decide to take the extents - * and force an exposure on that. This should require much less - * work overall, on both client and server. This is cheating, but - * isn't prohibited by the protocol ("spontaneous combustion" :-). - */ - BoxRec box; - - box = *REGION_EXTENTS( pWin->drawable.pScreen, exposures); - if (exposures == prgn) { - exposures = &expRec; - REGION_INIT( pWin->drawable.pScreen, exposures, &box, 1); - REGION_RESET( pWin->drawable.pScreen, prgn, &box); - } else { - REGION_RESET( pWin->drawable.pScreen, exposures, &box); - REGION_UNION( pWin->drawable.pScreen, prgn, prgn, exposures); - } - /* PaintWindowBackground doesn't clip, so we have to */ - REGION_INTERSECT( pWin->drawable.pScreen, prgn, prgn, &pWin->clipList); - /* need to clear out new areas of backing store, too */ - if (pWin->backStorage) - (void) (* pWin->drawable.pScreen->ClearBackingStore)( - pWin, - box.x1 - pWin->drawable.x, - box.y1 - pWin->drawable.y, - box.x2 - box.x1, - box.y2 - box.y1, - FALSE); - } - if (prgn && !REGION_NIL(prgn)) - (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, prgn, PW_BACKGROUND); - if (clientInterested && exposures && !REGION_NIL(exposures)) - miSendExposures(pWin, exposures, - pWin->drawable.x, pWin->drawable.y); - if (exposures == &expRec) - { - REGION_UNINIT( pWin->drawable.pScreen, exposures); - } - else if (exposures && exposures != prgn && exposures != other_exposed) - REGION_DESTROY( pWin->drawable.pScreen, exposures); - if (prgn) - REGION_EMPTY( pWin->drawable.pScreen, prgn); - } - else if (exposures && exposures != prgn) - REGION_DESTROY( pWin->drawable.pScreen, exposures); -} - - -/* - this code is highly unlikely. it is not haile selassie. - - there is some hair here. we can't just use the window's -clip region as it is, because if we are painting the border, -the border is not in the client area and so we will be excluded -when we validate the GC, and if we are painting a parent-relative -background, the area we want to paint is in some other window. -since we trust the code calling us to tell us to paint only areas -that are really ours, we will temporarily give the window a -clipList the size of the whole screen and an origin at (0,0). -this more or less assumes that ddX code will do translation -based on the window's absolute position, and that ValidateGC will -look at clipList, and that no other fields from the -window will be used. it's not possible to just draw -in the root because it may be a different depth. - -to get the tile to align correctly we set the GC's tile origin to -be the (x,y) of the window's upper left corner, after which we -get the right bits when drawing into the root. - -because the clip_mask is being set to None, we may call DoChangeGC with -fPointer set true, thus we no longer need to install the background or -border tile in the resource table. -*/ - -static RESTYPE ResType = 0; -static int numGCs = 0; -static GCPtr screenContext[MAXSCREENS]; - -/*ARGSUSED*/ -static int -tossGC ( - pointer value, - XID id) -{ - GCPtr pGC = (GCPtr)value; - screenContext[pGC->pScreen->myNum] = (GCPtr)NULL; - FreeGC (pGC, id); - numGCs--; - if (!numGCs) - ResType = 0; - - return 0; -} - - -void -miPaintWindow(pWin, prgn, what) -register WindowPtr pWin; -RegionPtr prgn; -int what; -{ - int status; - - Bool usingScratchGC = FALSE; - WindowPtr pRoot; - -#define FUNCTION 0 -#define FOREGROUND 1 -#define TILE 2 -#define FILLSTYLE 3 -#define ABSX 4 -#define ABSY 5 -#define CLIPMASK 6 -#define SUBWINDOW 7 -#define COUNT_BITS 8 - - ChangeGCVal gcval[7]; - ChangeGCVal newValues [COUNT_BITS]; - - BITS32 gcmask, index, mask; - RegionRec prgnWin; - DDXPointRec oldCorner; - BoxRec box; - WindowPtr pBgWin; - GCPtr pGC; - register int i; - register BoxPtr pbox; - register ScreenPtr pScreen = pWin->drawable.pScreen; - register xRectangle *prect; - int numRects; - - gcmask = 0; - - if (what == PW_BACKGROUND) - { - switch (pWin->backgroundState) { - case None: - return; - case ParentRelative: - (*pWin->parent->drawable.pScreen->PaintWindowBackground)(pWin->parent, prgn, what); - return; - case BackgroundPixel: - newValues[FOREGROUND].val = pWin->background.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - break; - case BackgroundPixmap: - newValues[TILE].ptr = (pointer)pWin->background.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - break; - } - } - else - { - if (pWin->borderIsPixel) - { - newValues[FOREGROUND].val = pWin->border.pixel; - newValues[FILLSTYLE].val = FillSolid; - gcmask |= GCForeground | GCFillStyle; - } - else - { - newValues[TILE].ptr = (pointer)pWin->border.pixmap; - newValues[FILLSTYLE].val = FillTiled; - gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - } - } - - prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(prgn) * - sizeof(xRectangle)); - if (!prect) - return; - - newValues[FUNCTION].val = GXcopy; - gcmask |= GCFunction | GCClipMask; - - i = pScreen->myNum; - pRoot = WindowTable[i]; - - pBgWin = pWin; - if (what == PW_BORDER) - { - while (pBgWin->backgroundState == ParentRelative) - pBgWin = pBgWin->parent; - } - - if ((pWin->drawable.depth != pRoot->drawable.depth) || - (pWin->drawable.bitsPerPixel != pRoot->drawable.bitsPerPixel)) - { - usingScratchGC = TRUE; - pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen); - if (!pGC) - { - DEALLOCATE_LOCAL(prect); - return; - } - /* - * mash the clip list so we can paint the border by - * mangling the window in place, pretending it - * spans the entire screen - */ - if (what == PW_BORDER) - { - prgnWin = pWin->clipList; - oldCorner.x = pWin->drawable.x; - oldCorner.y = pWin->drawable.y; - pWin->drawable.x = pWin->drawable.y = 0; - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - } - else - { - newValues[ABSX].val = 0; - newValues[ABSY].val = 0; - } - } else { - /* - * draw the background to the root window - */ - if (screenContext[i] == (GCPtr)NULL) - { - if (!ResType && !(ResType = CreateNewResourceType(tossGC))) - return; - screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0, - (XID *)NULL, &status); - if (!screenContext[i]) - return; - numGCs++; - if (!AddResource(FakeClientID(0), ResType, - (pointer)screenContext[i])) - return; - } - pGC = screenContext[i]; - newValues[SUBWINDOW].val = IncludeInferiors; - newValues[ABSX].val = pBgWin->drawable.x; - newValues[ABSY].val = pBgWin->drawable.y; - gcmask |= GCSubwindowMode; - pWin = pRoot; - } - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack); - - mask = gcmask; - gcmask = 0; - i = 0; - while (mask) { - index = lowbit (mask); - mask &= ~index; - switch (index) { - case GCFunction: - if (pGC->alu != newValues[FUNCTION].val) { - gcmask |= index; - gcval[i++].val = newValues[FUNCTION].val; - } - break; - case GCTileStipXOrigin: - if ( pGC->patOrg.x != newValues[ABSX].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSX].val; - } - break; - case GCTileStipYOrigin: - if ( pGC->patOrg.y != newValues[ABSY].val) { - gcmask |= index; - gcval[i++].val = newValues[ABSY].val; - } - break; - case GCClipMask: - if ( pGC->clientClipType != CT_NONE) { - gcmask |= index; - gcval[i++].val = CT_NONE; - } - break; - case GCSubwindowMode: - if ( pGC->subWindowMode != newValues[SUBWINDOW].val) { - gcmask |= index; - gcval[i++].val = newValues[SUBWINDOW].val; - } - break; - case GCTile: - if (pGC->tileIsPixel || pGC->tile.pixmap != newValues[TILE].ptr) - { - gcmask |= index; - gcval[i++].ptr = newValues[TILE].ptr; - } - break; - case GCFillStyle: - if ( pGC->fillStyle != newValues[FILLSTYLE].val) { - gcmask |= index; - gcval[i++].val = newValues[FILLSTYLE].val; - } - break; - case GCForeground: - if ( pGC->fgPixel != newValues[FOREGROUND].val) { - gcmask |= index; - gcval[i++].val = newValues[FOREGROUND].val; - } - break; - } - } - - if (gcmask) - dixChangeGC(NullClient, pGC, gcmask, NULL, gcval); - - if (pWin->drawable.serialNumber != pGC->serialNumber) - ValidateGC((DrawablePtr)pWin, pGC); - - numRects = REGION_NUM_RECTS(prgn); - pbox = REGION_RECTS(prgn); - for (i= numRects; --i >= 0; pbox++, prect++) - { - prect->x = pbox->x1 - pWin->drawable.x; - prect->y = pbox->y1 - pWin->drawable.y; - prect->width = pbox->x2 - pbox->x1; - prect->height = pbox->y2 - pbox->y1; - } - prect -= numRects; - (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect); - DEALLOCATE_LOCAL(prect); - - if (pWin->backStorage) - (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing); - - if (usingScratchGC) - { - if (what == PW_BORDER) - { - REGION_UNINIT(pScreen, &pWin->clipList); - pWin->clipList = prgnWin; - pWin->drawable.x = oldCorner.x; - pWin->drawable.y = oldCorner.y; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - FreeScratchGC(pGC); - } -} - - -/* MICLEARDRAWABLE -- sets the entire drawable to the background color of - * the GC. Useful when we have a scratch drawable and need to initialize - * it. */ -void -miClearDrawable(pDraw, pGC) - DrawablePtr pDraw; - GCPtr pGC; -{ - XID fg = pGC->fgPixel; - XID bg = pGC->bgPixel; - xRectangle rect; - - rect.x = 0; - rect.y = 0; - rect.width = pDraw->width; - rect.height = pDraw->height; - DoChangeGC(pGC, GCForeground, &bg, 0); - ValidateGC(pDraw, pGC); - (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect); - DoChangeGC(pGC, GCForeground, &fg, 0); - ValidateGC(pDraw, pGC); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.NX.original deleted file mode 100644 index 5f32334ae..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.NX.original +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/miglyph.c,v 1.4 2000/11/20 07:13:13 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -#ifdef NXAGENT_SERVER - -#include "Render.h" - -#endif - -void -miGlyphExtents (int nlist, - GlyphListPtr list, - GlyphPtr *glyphs, - BoxPtr extents) -{ - int x1, x2, y1, y2; - int n; - GlyphPtr glyph; - int x, y; - - x = 0; - y = 0; - extents->x1 = MAXSHORT; - extents->x2 = MINSHORT; - extents->y1 = MAXSHORT; - extents->y2 = MINSHORT; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - list++; - while (n--) - { - glyph = *glyphs++; - x1 = x - glyph->info.x; - if (x1 < MINSHORT) - x1 = MINSHORT; - y1 = y - glyph->info.y; - if (y1 < MINSHORT) - y1 = MINSHORT; - x2 = x1 + glyph->info.width; - if (x2 > MAXSHORT) - x2 = MAXSHORT; - y2 = y1 + glyph->info.height; - if (y2 > MAXSHORT) - y2 = MAXSHORT; - if (x1 < extents->x1) - extents->x1 = x1; - if (x2 > extents->x2) - extents->x2 = x2; - if (y1 < extents->y1) - extents->y1 = y1; - if (y2 > extents->y2) - extents->y2 = y2; - x += glyph->info.xOff; - y += glyph->info.yOff; - } - } -} - -#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0) - -void -miGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr list, - GlyphPtr *glyphs) -{ - PixmapPtr pPixmap = 0; - PicturePtr pPicture; - PixmapPtr pMaskPixmap = 0; - PicturePtr pMask; - ScreenPtr pScreen = pDst->pDrawable->pScreen; - int width = 0, height = 0; - int x, y; - int xDst = list->xOff, yDst = list->yOff; - int n; - GlyphPtr glyph; - int error; - BoxRec extents; - CARD32 component_alpha; - - #ifdef NXAGENT_SERVER - - /* - * Get rid of the warning. - */ - - extents.x1 = 0; - extents.y1 = 0; - - #endif - - if (maskFormat) - { - GCPtr pGC; - xRectangle rect; - - #ifdef NXAGENT_SERVER - - if (nxagentGlyphsExtents != NullBox) - { - memcpy(&extents, nxagentGlyphsExtents, sizeof(BoxRec)); - } - else - { - nxagentGlyphsExtents = (BoxPtr) xalloc(sizeof(BoxRec)); - - miGlyphExtents (nlist, list, glyphs, &extents); - - memcpy(nxagentGlyphsExtents, &extents, sizeof(BoxRec)); - } - - #else - - miGlyphExtents (nlist, list, glyphs, &extents); - - #endif - - if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1) - return; - width = extents.x2 - extents.x1; - height = extents.y2 - extents.y1; - pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, maskFormat->depth); - - if (!pMaskPixmap) - return; - - component_alpha = NeedsComponent(maskFormat->format); - pMask = CreatePicture (0, &pMaskPixmap->drawable, - maskFormat, CPComponentAlpha, &component_alpha, - serverClient, &error); - - if (!pMask) - { - (*pScreen->DestroyPixmap) (pMaskPixmap); - return; - } - pGC = GetScratchGC (pMaskPixmap->drawable.depth, pScreen); - ValidateGC (&pMaskPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect) (&pMaskPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - x = -extents.x1; - y = -extents.y1; - } - else - { - pMask = pDst; - x = 0; - y = 0; - } - pPicture = 0; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - - while (n--) - { - glyph = *glyphs++; - if (!pPicture) - { - pPixmap = GetScratchPixmapHeader (pScreen, glyph->info.width, glyph->info.height, - list->format->depth, - list->format->depth, - 0, (pointer) (glyph + 1)); - if (!pPixmap) - return; - component_alpha = NeedsComponent(list->format->format); - pPicture = CreatePicture (0, &pPixmap->drawable, list->format, - CPComponentAlpha, &component_alpha, - serverClient, &error); - if (!pPicture) - { - FreeScratchPixmapHeader (pPixmap); - return; - } - } - (*pScreen->ModifyPixmapHeader) (pPixmap, - glyph->info.width, glyph->info.height, - 0, 0, -1, (pointer) (glyph + 1)); - - #ifdef NXAGENT_SERVER - - /* - * The following line fixes a problem with glyphs that appeared - * as clipped. It was a side effect due the validate function - * "ValidatePicture" that makes a check on the Drawable serial - * number instead of the picture serial number, failing thus - * the clip mask update. - */ - - pPicture->pDrawable->serialNumber = NEXT_SERIAL_NUMBER; - - #endif - - pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - if (maskFormat) - { - CompositePicture (PictOpAdd, - pPicture, - None, - pMask, - 0, 0, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - else - { - CompositePicture (op, - pSrc, - pPicture, - pDst, - xSrc + (x - glyph->info.x) - xDst, - ySrc + (y - glyph->info.y) - yDst, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - x += glyph->info.xOff; - y += glyph->info.yOff; - } - - list++; - if (pPicture) - { - FreeScratchPixmapHeader (pPixmap); - FreePicture ((pointer) pPicture, 0); - pPicture = 0; - pPixmap = 0; - } - } - if (maskFormat) - { - x = extents.x1; - y = extents.y1; - CompositePicture (op, - pSrc, - pMask, - pDst, - xSrc + x - xDst, - ySrc + y - yDst, - 0, 0, - x, y, - width, height); - - FreePicture ((pointer) pMask, (XID) 0); - (*pScreen->DestroyPixmap) (pMaskPixmap); - } - -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.X.original deleted file mode 100644 index 237ec13a4..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiglyph.c.X.original +++ /dev/null @@ -1,243 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/miglyph.c,v 1.4 2000/11/20 07:13:13 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -void -miGlyphExtents (int nlist, - GlyphListPtr list, - GlyphPtr *glyphs, - BoxPtr extents) -{ - int x1, x2, y1, y2; - int n; - GlyphPtr glyph; - int x, y; - - x = 0; - y = 0; - extents->x1 = MAXSHORT; - extents->x2 = MINSHORT; - extents->y1 = MAXSHORT; - extents->y2 = MINSHORT; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - list++; - while (n--) - { - glyph = *glyphs++; - x1 = x - glyph->info.x; - if (x1 < MINSHORT) - x1 = MINSHORT; - y1 = y - glyph->info.y; - if (y1 < MINSHORT) - y1 = MINSHORT; - x2 = x1 + glyph->info.width; - if (x2 > MAXSHORT) - x2 = MAXSHORT; - y2 = y1 + glyph->info.height; - if (y2 > MAXSHORT) - y2 = MAXSHORT; - if (x1 < extents->x1) - extents->x1 = x1; - if (x2 > extents->x2) - extents->x2 = x2; - if (y1 < extents->y1) - extents->y1 = y1; - if (y2 > extents->y2) - extents->y2 = y2; - x += glyph->info.xOff; - y += glyph->info.yOff; - } - } -} - -#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0) - -void -miGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr list, - GlyphPtr *glyphs) -{ - PixmapPtr pPixmap = 0; - PicturePtr pPicture; - PixmapPtr pMaskPixmap = 0; - PicturePtr pMask; - ScreenPtr pScreen = pDst->pDrawable->pScreen; - int width = 0, height = 0; - int x, y; - int xDst = list->xOff, yDst = list->yOff; - int n; - GlyphPtr glyph; - int error; - BoxRec extents; - CARD32 component_alpha; - - if (maskFormat) - { - GCPtr pGC; - xRectangle rect; - - miGlyphExtents (nlist, list, glyphs, &extents); - - if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1) - return; - width = extents.x2 - extents.x1; - height = extents.y2 - extents.y1; - pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, maskFormat->depth); - if (!pMaskPixmap) - return; - component_alpha = NeedsComponent(maskFormat->format); - pMask = CreatePicture (0, &pMaskPixmap->drawable, - maskFormat, CPComponentAlpha, &component_alpha, - serverClient, &error); - if (!pMask) - { - (*pScreen->DestroyPixmap) (pMaskPixmap); - return; - } - pGC = GetScratchGC (pMaskPixmap->drawable.depth, pScreen); - ValidateGC (&pMaskPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect) (&pMaskPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - x = -extents.x1; - y = -extents.y1; - } - else - { - pMask = pDst; - x = 0; - y = 0; - } - pPicture = 0; - while (nlist--) - { - x += list->xOff; - y += list->yOff; - n = list->len; - while (n--) - { - glyph = *glyphs++; - if (!pPicture) - { - pPixmap = GetScratchPixmapHeader (pScreen, glyph->info.width, glyph->info.height, - list->format->depth, - list->format->depth, - 0, (pointer) (glyph + 1)); - if (!pPixmap) - return; - component_alpha = NeedsComponent(list->format->format); - pPicture = CreatePicture (0, &pPixmap->drawable, list->format, - CPComponentAlpha, &component_alpha, - serverClient, &error); - if (!pPicture) - { - FreeScratchPixmapHeader (pPixmap); - return; - } - } - (*pScreen->ModifyPixmapHeader) (pPixmap, - glyph->info.width, glyph->info.height, - 0, 0, -1, (pointer) (glyph + 1)); - pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - if (maskFormat) - { - CompositePicture (PictOpAdd, - pPicture, - None, - pMask, - 0, 0, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - else - { - CompositePicture (op, - pSrc, - pPicture, - pDst, - xSrc + (x - glyph->info.x) - xDst, - ySrc + (y - glyph->info.y) - yDst, - 0, 0, - x - glyph->info.x, - y - glyph->info.y, - glyph->info.width, - glyph->info.height); - } - x += glyph->info.xOff; - y += glyph->info.yOff; - } - list++; - if (pPicture) - { - FreeScratchPixmapHeader (pPixmap); - FreePicture ((pointer) pPicture, 0); - pPicture = 0; - pPixmap = 0; - } - } - if (maskFormat) - { - x = extents.x1; - y = extents.y1; - CompositePicture (op, - pSrc, - pMask, - pDst, - xSrc + x - xDst, - ySrc + y - yDst, - 0, 0, - x, y, - width, height); - FreePicture ((pointer) pMask, (XID) 0); - (*pScreen->DestroyPixmap) (pMaskPixmap); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.NX.original deleted file mode 100644 index f418654b4..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.NX.original +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/mitrap.c,v 1.8 2002/09/03 19:28:28 keithp Exp $ - * - * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "servermd.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -#ifdef NXAGENT_SERVER - -#include "Render.h" - -#endif - -PicturePtr -miCreateAlphaPicture (ScreenPtr pScreen, - PicturePtr pDst, - PictFormatPtr pPictFormat, - CARD16 width, - CARD16 height) -{ - PixmapPtr pPixmap; - PicturePtr pPicture; - GCPtr pGC; - int error; - xRectangle rect; - - if (width > 32767 || height > 32767) - return 0; - - if (!pPictFormat) - { - if (pDst->polyEdge == PolyEdgeSharp) - pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1); - else - pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8); - if (!pPictFormat) - return 0; - } - - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, - pPictFormat->depth); - if (!pPixmap) - return 0; - pGC = GetScratchGC (pPixmap->drawable.depth, pScreen); - if (!pGC) - { - (*pScreen->DestroyPixmap) (pPixmap); - return 0; - } - ValidateGC (&pPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect)(&pPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat, - 0, 0, serverClient, &error); - (*pScreen->DestroyPixmap) (pPixmap); - return pPicture; -} - -static xFixed -miLineFixedX (xLineFixed *l, xFixed y, Bool ceil) -{ - xFixed dx = l->p2.x - l->p1.x; - xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx; - xFixed dy = l->p2.y - l->p1.y; - if (ceil) - ex += (dy - 1); - return l->p1.x + (xFixed) (ex / dy); -} - -void -miTrapezoidBounds (int ntrap, xTrapezoid *traps, BoxPtr box) -{ - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - for (; ntrap; ntrap--, traps++) - { - INT16 x1, y1, x2, y2; - - if (!xTrapezoidValid(traps)) - continue; - y1 = xFixedToInt (traps->top); - if (y1 < box->y1) - box->y1 = y1; - - y2 = xFixedToInt (xFixedCeil (traps->bottom)); - if (y2 > box->y2) - box->y2 = y2; - - x1 = xFixedToInt (min (miLineFixedX (&traps->left, traps->top, FALSE), - miLineFixedX (&traps->left, traps->bottom, FALSE))); - if (x1 < box->x1) - box->x1 = x1; - - x2 = xFixedToInt (xFixedCeil (max (miLineFixedX (&traps->right, traps->top, TRUE), - miLineFixedX (&traps->right, traps->bottom, TRUE)))); - if (x2 > box->x2) - box->x2 = x2; - } -} - -void -miTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - /* - * Check for solid alpha add - */ - if (op == PictOpAdd && miIsSolidAlpha (pSrc)) - { - for (; ntrap; ntrap--, traps++) - (*ps->RasterizeTrapezoid) (pDst, traps, 0, 0); - } - else if (maskFormat) - { - PicturePtr pPicture; - BoxRec bounds; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = traps[0].left.p1.x >> 16; - yDst = traps[0].left.p1.y >> 16; - - #ifdef NXAGENT_SERVER - - if (nxagentTrapezoidExtents != NullBox) - { - memcpy(&bounds, nxagentTrapezoidExtents, sizeof(BoxRec)); - } - else - { - nxagentTrapezoidExtents = (BoxPtr) xalloc(sizeof(BoxRec)); - - miTrapezoidBounds (ntrap, traps, &bounds); - - memcpy(nxagentTrapezoidExtents, &bounds, sizeof(BoxRec)); - } - - #else - - miTrapezoidBounds (ntrap, traps, &bounds); - - #endif - - if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - return; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - return; - for (; ntrap; ntrap--, traps++) - (*ps->RasterizeTrapezoid) (pPicture, traps, - -bounds.x1, -bounds.y1); - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - else - { - if (pDst->polyEdge == PolyEdgeSharp) - maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1); - else - maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8); - for (; ntrap; ntrap--, traps++) - miTrapezoids (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, traps); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.X.original deleted file mode 100644 index be1712420..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmitrap.c.X.original +++ /dev/null @@ -1,190 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/mitrap.c,v 1.8 2002/09/03 19:28:28 keithp Exp $ - * - * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "scrnintstr.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "servermd.h" -#include "mi.h" -#include "picturestr.h" -#include "mipict.h" - -PicturePtr -miCreateAlphaPicture (ScreenPtr pScreen, - PicturePtr pDst, - PictFormatPtr pPictFormat, - CARD16 width, - CARD16 height) -{ - PixmapPtr pPixmap; - PicturePtr pPicture; - GCPtr pGC; - int error; - xRectangle rect; - - if (width > 32767 || height > 32767) - return 0; - - if (!pPictFormat) - { - if (pDst->polyEdge == PolyEdgeSharp) - pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1); - else - pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8); - if (!pPictFormat) - return 0; - } - - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, - pPictFormat->depth); - if (!pPixmap) - return 0; - pGC = GetScratchGC (pPixmap->drawable.depth, pScreen); - if (!pGC) - { - (*pScreen->DestroyPixmap) (pPixmap); - return 0; - } - ValidateGC (&pPixmap->drawable, pGC); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - (*pGC->ops->PolyFillRect)(&pPixmap->drawable, pGC, 1, &rect); - FreeScratchGC (pGC); - pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat, - 0, 0, serverClient, &error); - (*pScreen->DestroyPixmap) (pPixmap); - return pPicture; -} - -static xFixed -miLineFixedX (xLineFixed *l, xFixed y, Bool ceil) -{ - xFixed dx = l->p2.x - l->p1.x; - xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx; - xFixed dy = l->p2.y - l->p1.y; - if (ceil) - ex += (dy - 1); - return l->p1.x + (xFixed) (ex / dy); -} - -void -miTrapezoidBounds (int ntrap, xTrapezoid *traps, BoxPtr box) -{ - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - for (; ntrap; ntrap--, traps++) - { - INT16 x1, y1, x2, y2; - - if (!xTrapezoidValid(traps)) - continue; - y1 = xFixedToInt (traps->top); - if (y1 < box->y1) - box->y1 = y1; - - y2 = xFixedToInt (xFixedCeil (traps->bottom)); - if (y2 > box->y2) - box->y2 = y2; - - x1 = xFixedToInt (min (miLineFixedX (&traps->left, traps->top, FALSE), - miLineFixedX (&traps->left, traps->bottom, FALSE))); - if (x1 < box->x1) - box->x1 = x1; - - x2 = xFixedToInt (xFixedCeil (max (miLineFixedX (&traps->right, traps->top, TRUE), - miLineFixedX (&traps->right, traps->bottom, TRUE)))); - if (x2 > box->x2) - box->x2 = x2; - } -} - -void -miTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - /* - * Check for solid alpha add - */ - if (op == PictOpAdd && miIsSolidAlpha (pSrc)) - { - for (; ntrap; ntrap--, traps++) - (*ps->RasterizeTrapezoid) (pDst, traps, 0, 0); - } - else if (maskFormat) - { - PicturePtr pPicture; - BoxRec bounds; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = traps[0].left.p1.x >> 16; - yDst = traps[0].left.p1.y >> 16; - - miTrapezoidBounds (ntrap, traps, &bounds); - if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - return; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - return; - for (; ntrap; ntrap--, traps++) - (*ps->RasterizeTrapezoid) (pPicture, traps, - -bounds.x1, -bounds.y1); - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - else - { - if (pDst->polyEdge == PolyEdgeSharp) - maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1); - else - maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8); - for (; ntrap; ntrap--, traps++) - miTrapezoids (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, traps); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.NX.original deleted file mode 100644 index 190294979..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.NX.original +++ /dev/null @@ -1,1222 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/mi/miwindow.c,v 1.9tsi Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: miwindow.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "regionstr.h" -#include "region.h" -#include "mi.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" - -void -miClearToBackground(pWin, x, y, w, h, generateExposures) - WindowPtr pWin; - int x,y; - int w,h; - Bool generateExposures; -{ - BoxRec box; - RegionRec reg; - RegionPtr pBSReg = NullRegion; - ScreenPtr pScreen; - BoxPtr extents; - int x1, y1, x2, y2; - - /* compute everything using ints to avoid overflow */ - - x1 = pWin->drawable.x + x; - y1 = pWin->drawable.y + y; - if (w) - x2 = x1 + (int) w; - else - x2 = x1 + (int) pWin->drawable.width - (int) x; - if (h) - y2 = y1 + h; - else - y2 = y1 + (int) pWin->drawable.height - (int) y; - - extents = &pWin->clipList.extents; - - /* clip the resulting rectangle to the window clipList extents. This - * makes sure that the result will fit in a box, given that the - * screen is < 32768 on a side. - */ - - if (x1 < extents->x1) - x1 = extents->x1; - if (x2 > extents->x2) - x2 = extents->x2; - if (y1 < extents->y1) - y1 = extents->y1; - if (y2 > extents->y2) - y2 = extents->y2; - - if (x2 <= x1 || y2 <= y1) - { - x2 = x1 = 0; - y2 = y1 = 0; - } - - box.x1 = x1; - box.x2 = x2; - box.y1 = y1; - box.y2 = y2; - - pScreen = pWin->drawable.pScreen; - REGION_INIT(pScreen, ®, &box, 1); - if (pWin->backStorage) - { - /* - * If the window has backing-store on, call through the - * ClearToBackground vector to handle the special semantics - * (i.e. things backing store is to be cleared out and - * an Expose event is to be generated for those areas in backing - * store if generateExposures is TRUE). - */ - pBSReg = (* pScreen->ClearBackingStore)(pWin, x, y, w, h, - generateExposures); - } - - REGION_INTERSECT(pScreen, ®, ®, &pWin->clipList); - if (generateExposures) - (*pScreen->WindowExposures)(pWin, ®, pBSReg); - else if (pWin->backgroundState != None) - (*pScreen->PaintWindowBackground)(pWin, ®, PW_BACKGROUND); - REGION_UNINIT(pScreen, ®); - if (pBSReg) - REGION_DESTROY(pScreen, pBSReg); -} - -/* - * For SaveUnders using backing-store. The idea is that when a window is mapped - * with saveUnder set TRUE, any windows it obscures will have its backing - * store turned on setting the DIXsaveUnder bit, - * The backing-store code must be written to allow for this - */ - -/*- - *----------------------------------------------------------------------- - * miCheckSubSaveUnder -- - * Check all the inferiors of a window for coverage by saveUnder - * windows. Called from ChangeSaveUnder and CheckSaveUnder. - * This code is very inefficient. - * - * Results: - * TRUE if any windows need to have backing-store removed. - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -static Bool -miCheckSubSaveUnder( - register WindowPtr pParent, /* Parent to check */ - WindowPtr pFirst, /* first reconfigured window */ - RegionPtr pRegion) /* Initial area obscured by saveUnder */ -{ - register WindowPtr pChild; /* Current child */ - register ScreenPtr pScreen; /* Screen to use */ - RegionRec SubRegion; /* Area of children obscured */ - Bool res = FALSE; /* result */ - Bool subInited=FALSE;/* SubRegion initialized */ - - pScreen = pParent->drawable.pScreen; - if ( (pChild = pParent->firstChild) ) - { - /* - * build region above first changed window - */ - - for (; pChild != pFirst; pChild = pChild->nextSib) - if (pChild->viewable && pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - - /* - * check region below and including first changed window - */ - - for (; pChild; pChild = pChild->nextSib) - { - if (pChild->viewable) - { - /* - * don't save under nephew/niece windows; - * use a separate region - */ - - if (pChild->firstChild) - { - if (!subInited) - { - REGION_NULL(pScreen, &SubRegion); - subInited = TRUE; - } - REGION_COPY(pScreen, &SubRegion, pRegion); - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - &SubRegion); - } - else - { - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - pRegion); - } - - if (pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - } - } - - if (subInited) - REGION_UNINIT(pScreen, &SubRegion); - } - - /* - * Check the state of this window. DIX save unders are - * enabled for viewable windows with some client expressing - * exposure interest and which intersect the save under region - */ - - if (pParent->viewable && - ((pParent->eventMask | wOtherEventMasks(pParent)) & ExposureMask) && - REGION_NOTEMPTY(pScreen, &pParent->borderSize) && - RECT_IN_REGION(pScreen, pRegion, REGION_EXTENTS(pScreen, - &pParent->borderSize)) != rgnOUT) - { - if (!pParent->DIXsaveUnder) - { - pParent->DIXsaveUnder = TRUE; - (*pScreen->ChangeWindowAttributes) (pParent, CWBackingStore); - } - } - else - { - if (pParent->DIXsaveUnder) - { - res = TRUE; - pParent->DIXsaveUnder = FALSE; - } - } - return res; -} - - -/*- - *----------------------------------------------------------------------- - * miChangeSaveUnder -- - * Change the save-under state of a tree of windows. Called when - * a window with saveUnder TRUE is mapped/unmapped/reconfigured. - * - * Results: - * TRUE if any windows need to have backing-store removed (which - * means that PostChangeSaveUnder needs to be called later to - * finish the job). - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -Bool -miChangeSaveUnder(pWin, first) - register WindowPtr pWin; - WindowPtr first; /* First window to check. - * Used when pWin was restacked */ -{ - RegionRec rgn; /* Area obscured by saveUnder windows */ - register ScreenPtr pScreen; - Bool res; - - if (!deltaSaveUndersViewable && !numSaveUndersViewable) - return FALSE; - numSaveUndersViewable += deltaSaveUndersViewable; - deltaSaveUndersViewable = 0; - pScreen = pWin->drawable.pScreen; - REGION_NULL(pScreen, &rgn); - res = miCheckSubSaveUnder (pWin->parent, - pWin->saveUnder ? first : pWin->nextSib, - &rgn); - REGION_UNINIT(pScreen, &rgn); - return res; -} - -/*- - *----------------------------------------------------------------------- - * miPostChangeSaveUnder -- - * Actually turn backing-store off for those windows that no longer - * need to have it on. - * - * Results: - * None. - * - * Side Effects: - * Backing-store and SAVE_UNDER_CHANGE_BIT are turned off for those - * windows affected. - * - *----------------------------------------------------------------------- - */ -void -miPostChangeSaveUnder(pWin, pFirst) - WindowPtr pWin; - WindowPtr pFirst; -{ - register WindowPtr pParent, pChild; - ChangeWindowAttributesProcPtr ChangeWindowAttributes; - - if (!(pParent = pWin->parent)) - return; - ChangeWindowAttributes = pParent->drawable.pScreen->ChangeWindowAttributes; - if (!pParent->DIXsaveUnder && - (pParent->backingStore == NotUseful) && pParent->backStorage) - (*ChangeWindowAttributes)(pParent, CWBackingStore); - if (!(pChild = pFirst)) - return; - while (1) - { - if (!pChild->DIXsaveUnder && - (pChild->backingStore == NotUseful) && pChild->backStorage) - (*ChangeWindowAttributes)(pChild, CWBackingStore); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib) - { - pChild = pChild->parent; - if (pChild == pParent) - return; - } - pChild = pChild->nextSib; - } -} - -void -miMarkWindow(pWin) - register WindowPtr pWin; -{ - register ValidatePtr val; - - if (pWin->valdata) - return; - val = (ValidatePtr)xnfalloc(sizeof(ValidateRec)); - val->before.oldAbsCorner.x = pWin->drawable.x; - val->before.oldAbsCorner.y = pWin->drawable.y; - val->before.borderVisible = NullRegion; - val->before.resized = FALSE; - pWin->valdata = val; -} - -Bool -miMarkOverlappedWindows(pWin, pFirst, ppLayerWin) - WindowPtr pWin; - WindowPtr pFirst; - WindowPtr *ppLayerWin; -{ - register BoxPtr box; - register WindowPtr pChild, pLast; - Bool anyMarked = FALSE; - MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow; - ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - - /* single layered systems are easy */ - if (ppLayerWin) *ppLayerWin = pWin; - - if (pWin == pFirst) - { - /* Blindly mark pWin and all of its inferiors. This is a slight - * overkill if there are mapped windows that outside pWin's border, - * but it's better than wasting time on RectIn checks. - */ - pChild = pWin; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - (* MarkWindow)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - anyMarked = TRUE; - pFirst = pFirst->nextSib; - } - if ( (pChild = pFirst) ) - { - box = REGION_EXTENTS(pChild->drawable.pScreen, &pWin->borderSize); - pLast = pChild->parent->lastChild; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - if (RECT_IN_REGION(pScreen, &pChild->borderSize, box)) - { - (* MarkWindow)(pChild); - anyMarked = TRUE; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - } - while (!pChild->nextSib && (pChild != pLast)) - pChild = pChild->parent; - if (pChild == pLast) - break; - pChild = pChild->nextSib; - } - } - if (anyMarked) - (* MarkWindow)(pWin->parent); - return anyMarked; -} - -/***** - * miHandleValidateExposures(pWin) - * starting at pWin, draw background in any windows that have exposure - * regions, translate the regions, restore any backing store, - * and then send any regions still exposed to the client - *****/ -void -miHandleValidateExposures(pWin) - WindowPtr pWin; -{ - register WindowPtr pChild; - register ValidatePtr val; - ScreenPtr pScreen; - WindowExposuresProcPtr WindowExposures; - - pScreen = pWin->drawable.pScreen; - - pChild = pWin; - WindowExposures = pChild->drawable.pScreen->WindowExposures; - while (1) - { - if ( (val = pChild->valdata) ) - { - if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed)) - (*pChild->drawable.pScreen->PaintWindowBorder)(pChild, - &val->after.borderExposed, - PW_BORDER); - REGION_UNINIT(pScreen, &val->after.borderExposed); - (*WindowExposures)(pChild, &val->after.exposed, NullRegion); - REGION_UNINIT(pScreen, &val->after.exposed); - xfree(val); - pChild->valdata = (ValidatePtr)NULL; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -void -miMoveWindow(pWin, x, y, pNextSib, kind) - register WindowPtr pWin; - int x,y; - WindowPtr pNextSib; - VTKind kind; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - short bw; - RegionPtr oldRegion = NULL; - DDXPointRec oldpt; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr windowToValidate; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be moved */ - if (!(pParent = pWin->parent)) - return ; - pScreen = pWin->drawable.pScreen; - bw = wBorderWidth (pWin); - - oldpt.x = pWin->drawable.x; - oldpt.y = pWin->drawable.y; - if (WasViewable) - { - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->borderClip); - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - } - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - x = pWin->drawable.x = pParent->drawable.x + x + (int)bw; - y = pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - SetWinSize (pWin); - SetBorderSize (pWin); - - (*pScreen->PositionWindow)(pWin, x, y); - - windowToValidate = MoveWindowInStack(pWin, pNextSib); - - ResizeChildrenWinSize(pWin, x - oldpt.x, y - oldpt.y, 0, 0); - - if (WasViewable) - { - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, windowToValidate, (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, pLayerWin, (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, windowToValidate); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind); - (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion); - REGION_DESTROY(pScreen, oldRegion); - /* XXX need to retile border if ParentRelative origin */ - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, windowToValidate); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - - -/* - * pValid is a region of the screen which has been - * successfully copied -- recomputed exposed regions for affected windows - */ - -static int -miRecomputeExposures ( - register WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - register ScreenPtr pScreen; - RegionPtr pValid = (RegionPtr)value; - - if (pWin->valdata) - { - pScreen = pWin->drawable.pScreen; - /* - * compute exposed regions of this window - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->clipList, pValid); - /* - * compute exposed regions of the border - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->borderClip, &pWin->winSize); - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->valdata->after.borderExposed, pValid); - return WT_WALKCHILDREN; - } - return WT_NOMATCH; -} - -void -miSlideAndSizeWindow(pWin, x, y, w, h, pSib) - register WindowPtr pWin; - int x,y; - unsigned int w, h; - WindowPtr pSib; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - unsigned short width = pWin->drawable.width, - height = pWin->drawable.height; - short oldx = pWin->drawable.x, - oldy = pWin->drawable.y; - int bw = wBorderWidth (pWin); - short dw, dh; - DDXPointRec oldpt; - RegionPtr oldRegion = NULL; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr pFirstChange; - register WindowPtr pChild; - RegionPtr gravitate[StaticGravity + 1]; - register unsigned g; - int nx, ny; /* destination x,y */ - int newx, newy; /* new inner window position */ - RegionPtr pRegion = NULL; - RegionPtr destClip; /* portions of destination already written */ - RegionPtr oldWinClip = NULL; /* old clip list for window */ - RegionPtr borderVisible = NullRegion; /* visible area of the border */ - RegionPtr bsExposed = NullRegion; /* backing store exposures */ - Bool shrunk = FALSE; /* shrunk in an inner dimension */ - Bool moved = FALSE; /* window position changed */ -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be resized */ - if (!(pParent = pWin->parent)) - return ; - - pScreen = pWin->drawable.pScreen; - newx = pParent->drawable.x + x + bw; - newy = pParent->drawable.y + y + bw; - if (WasViewable) - { - anyMarked = FALSE; - /* - * save the visible region of the window - */ - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->winSize); - - /* - * categorize child windows into regions to be moved - */ - for (g = 0; g <= StaticGravity; g++) - gravitate[g] = (RegionPtr) NULL; - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - g = pChild->winGravity; - if (g != UnmapGravity) - { - if (!gravitate[g]) - gravitate[g] = REGION_CREATE(pScreen, NullBox, 1); - REGION_UNION(pScreen, gravitate[g], - gravitate[g], &pChild->borderClip); - } - else - { - UnmapWindow(pChild, TRUE); - anyMarked = TRUE; - } - } - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - - oldWinClip = NULL; - if (pWin->bitGravity != ForgetGravity) - { - oldWinClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldWinClip, &pWin->clipList); - } - /* - * if the window is changing size, borderExposed - * can't be computed correctly without some help. - */ - if (pWin->drawable.height > h || pWin->drawable.width > w) - shrunk = TRUE; - - if (newx != oldx || newy != oldy) - moved = TRUE; - - if ((pWin->drawable.height != h || pWin->drawable.width != w) && - HasBorder (pWin)) - { - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - /* for tiled borders, we punt and draw the whole thing */ - if (pWin->borderIsPixel || !moved) - { - if (shrunk || moved) - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, - &pWin->winSize); - else - REGION_COPY(pScreen, borderVisible, - &pWin->borderClip); - } - } - } - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.height = h; - pWin->drawable.width = w; - - x = pWin->drawable.x = newx; - y = pWin->drawable.y = newy; - - SetWinSize (pWin); - SetBorderSize (pWin); - - dw = (int)w - (int)width; - dh = (int)h - (int)height; - ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh); - - /* let the hardware adjust background and border pixmaps, if any */ - (*pScreen->PositionWindow)(pWin, x, y); - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - pRegion = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->backStorage) - REGION_COPY(pScreen, pRegion, &pWin->clipList); - - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - - if (pWin->valdata) - { - pWin->valdata->before.resized = TRUE; - pWin->valdata->before.borderVisible = borderVisible; - } - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, VTOther); - /* - * the entire window is trashed unless bitGravity - * recovers portions of it - */ - REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList); - } - - GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny); - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pRegion = &pWin->clipList; /* a convenient empty region */ - if (pWin->bitGravity == ForgetGravity) - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, NullRegion, oldx, oldy); - else - { - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, nx - x, ny - y, pRegion, oldx, oldy); - } - } - - if (WasViewable) - { - /* avoid the border */ - if (HasBorder (pWin)) - { - int offx, offy, dx, dy; - - /* kruft to avoid double translates for each gravity */ - offx = 0; - offy = 0; - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - /* align winSize to gravitate[g]. - * winSize is in new coordinates, - * gravitate[g] is still in old coordinates */ - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - dx = (oldx - nx) - offx; - dy = (oldy - ny) - offy; - if (dx || dy) - { - REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy); - offx += dx; - offy += dy; - } - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], - &pWin->winSize); - } - /* get winSize back where it belongs */ - if (offx || offy) - REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy); - } - /* - * add screen bits to the appropriate bucket - */ - - if (oldWinClip) - { - /* - * clip to new clipList - */ - REGION_COPY(pScreen, pRegion, oldWinClip); - REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy); - REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList); - /* - * don't step on any gravity bits which will be copied after this - * region. Note -- this assumes that the regions will be copied - * in gravity order. - */ - for (g = pWin->bitGravity + 1; g <= StaticGravity; g++) - { - if (gravitate[g]) - REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip, - gravitate[g]); - } - REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny); - g = pWin->bitGravity; - if (!gravitate[g]) - gravitate[g] = oldWinClip; - else - { - REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip); - REGION_DESTROY(pScreen, oldWinClip); - } - } - - /* - * move the bits on the screen - */ - - destClip = NULL; - - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - oldpt.x = oldx + (x - nx); - oldpt.y = oldy + (y - ny); - - /* Note that gravitate[g] is *translated* by CopyWindow */ - - /* only copy the remaining useful bits */ - - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], oldRegion); - - /* clip to not overwrite already copied areas */ - - if (destClip) { - REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y); - REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip); - REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y); - } - - /* and move those bits */ - - if (oldpt.x != x || oldpt.y != y -#ifdef COMPOSITE - || pWin->redirectDraw -#endif - ) - { - (*pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, gravitate[g]); - } - - /* remove any overwritten bits from the remaining useful bits */ - - REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]); - - /* - * recompute exposed regions of child windows - */ - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->winGravity != g) - continue; - REGION_INTERSECT(pScreen, pRegion, - &pChild->borderClip, gravitate[g]); - TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion); - } - - /* - * remove the successfully copied regions of the - * window from its exposed region - */ - - if (g == pWin->bitGravity) - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->valdata->after.exposed, gravitate[g]); - if (!destClip) - destClip = gravitate[g]; - else - { - REGION_UNION(pScreen, destClip, destClip, gravitate[g]); - REGION_DESTROY(pScreen, gravitate[g]); - } - } - - REGION_DESTROY(pScreen, oldRegion); - REGION_DESTROY(pScreen, pRegion); - if (destClip) - REGION_DESTROY(pScreen, destClip); - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, - VTOther); - } - else if (bsExposed) - { - (*pScreen->WindowExposures) (pWin, NullRegion, bsExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (pWin->realized) - WindowsRestructured (); -} - -WindowPtr -miGetLayerWindow(pWin) - WindowPtr pWin; -{ - return pWin->firstChild; -} - -#ifdef SHAPE -/****** - * - * miSetShape - * The border/window shape has changed. Recompute winSize/borderSize - * and send appropriate exposure events - */ - -void -miSetShape(pWin) - register WindowPtr pWin; -{ - Bool WasViewable = (Bool)(pWin->viewable); - register ScreenPtr pScreen = pWin->drawable.pScreen; - Bool anyMarked = FALSE; - RegionPtr pOldClip = NULL, bsExposed; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - if (pWin->valdata) - { - if (HasBorder (pWin)) - { - RegionPtr borderVisible; - - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - pWin->valdata->before.resized = TRUE; - } - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - if (WasViewable) - { - if (pWin->backStorage) - { - pOldClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, pOldClip, &pWin->clipList); - } - - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pOldClip = &pWin->clipList; /* a convenient empty region */ - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, pOldClip, - pWin->drawable.x, pWin->drawable.y); -#ifdef NXAGENT_SERVER - - /* - * We got a few, rare, segfaults here after having - * started using the backing store. It may be a - * different bug but miChangeSaveUnder() calls mi- - * CheckSubSaveUnder() that, in turn, can change - * the backing store attribute of the window. This - * means that we may try to destroy the region - * even if it was not created at the beginning of - * this function as, at the time, the backing store - * was off. miCheckSubSaveUnder() appear to get a - * pointer to the parent, so maybe doesn't change - * the attribute of the window itself. This is to - * be better investigated. - */ - - if (WasViewable && pOldClip) - REGION_DESTROY(pScreen, pOldClip); -#else - if (WasViewable) - REGION_DESTROY(pScreen, pOldClip); -#endif - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - } - if (WasViewable) - { - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - if (pWin->realized) - WindowsRestructured (); - CheckCursorConfinement(pWin); -} -#endif - -/* Keeps the same inside(!) origin */ - -void -miChangeBorderWidth(pWin, width) - register WindowPtr pWin; - unsigned int width; -{ - int oldwidth; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - Bool WasViewable = (Bool)(pWin->viewable); - Bool HadBorder; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - oldwidth = wBorderWidth (pWin); - if (oldwidth == width) - return; - HadBorder = HasBorder(pWin); - pScreen = pWin->drawable.pScreen; - if (WasViewable && width < oldwidth) - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - - pWin->borderWidth = width; - SetBorderSize (pWin); - - if (WasViewable) - { - if (width > oldwidth) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - /* - * save the old border visible region to correctly compute - * borderExposed. - */ - if (pWin->valdata && HadBorder) - { - RegionPtr borderVisible; - borderVisible = REGION_CREATE(pScreen, NULL, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTOther); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, - VTOther); - } - if (pWin->realized) - WindowsRestructured (); -} - -void -miMarkUnrealizedWindow(pChild, pWin, fromConfigure) - WindowPtr pChild; - WindowPtr pWin; - Bool fromConfigure; -{ - if ((pChild != pWin) || fromConfigure) - { - REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList); - if (pChild->drawable.pScreen->ClipNotify) - (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0); - REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip); - } -} - -void -miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth) -{ - ScreenPtr pScreen; - WindowPtr pChild; - - pScreen = pWin->drawable.pScreen; - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->drawable.depth == depth) - REGION_UNION(pScreen, pReg, pReg, &pChild->borderClip); - - if (pChild->firstChild) - miSegregateChildren(pChild, pReg, depth); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.X.original deleted file mode 100644 index 280d0f8eb..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXmiwindow.c.X.original +++ /dev/null @@ -1,1184 +0,0 @@ -/* $XFree86: xc/programs/Xserver/mi/miwindow.c,v 1.9tsi Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: miwindow.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "regionstr.h" -#include "region.h" -#include "mi.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" - -void -miClearToBackground(pWin, x, y, w, h, generateExposures) - WindowPtr pWin; - int x,y; - int w,h; - Bool generateExposures; -{ - BoxRec box; - RegionRec reg; - RegionPtr pBSReg = NullRegion; - ScreenPtr pScreen; - BoxPtr extents; - int x1, y1, x2, y2; - - /* compute everything using ints to avoid overflow */ - - x1 = pWin->drawable.x + x; - y1 = pWin->drawable.y + y; - if (w) - x2 = x1 + (int) w; - else - x2 = x1 + (int) pWin->drawable.width - (int) x; - if (h) - y2 = y1 + h; - else - y2 = y1 + (int) pWin->drawable.height - (int) y; - - extents = &pWin->clipList.extents; - - /* clip the resulting rectangle to the window clipList extents. This - * makes sure that the result will fit in a box, given that the - * screen is < 32768 on a side. - */ - - if (x1 < extents->x1) - x1 = extents->x1; - if (x2 > extents->x2) - x2 = extents->x2; - if (y1 < extents->y1) - y1 = extents->y1; - if (y2 > extents->y2) - y2 = extents->y2; - - if (x2 <= x1 || y2 <= y1) - { - x2 = x1 = 0; - y2 = y1 = 0; - } - - box.x1 = x1; - box.x2 = x2; - box.y1 = y1; - box.y2 = y2; - - pScreen = pWin->drawable.pScreen; - REGION_INIT(pScreen, ®, &box, 1); - if (pWin->backStorage) - { - /* - * If the window has backing-store on, call through the - * ClearToBackground vector to handle the special semantics - * (i.e. things backing store is to be cleared out and - * an Expose event is to be generated for those areas in backing - * store if generateExposures is TRUE). - */ - pBSReg = (* pScreen->ClearBackingStore)(pWin, x, y, w, h, - generateExposures); - } - - REGION_INTERSECT(pScreen, ®, ®, &pWin->clipList); - if (generateExposures) - (*pScreen->WindowExposures)(pWin, ®, pBSReg); - else if (pWin->backgroundState != None) - (*pScreen->PaintWindowBackground)(pWin, ®, PW_BACKGROUND); - REGION_UNINIT(pScreen, ®); - if (pBSReg) - REGION_DESTROY(pScreen, pBSReg); -} - -/* - * For SaveUnders using backing-store. The idea is that when a window is mapped - * with saveUnder set TRUE, any windows it obscures will have its backing - * store turned on setting the DIXsaveUnder bit, - * The backing-store code must be written to allow for this - */ - -/*- - *----------------------------------------------------------------------- - * miCheckSubSaveUnder -- - * Check all the inferiors of a window for coverage by saveUnder - * windows. Called from ChangeSaveUnder and CheckSaveUnder. - * This code is very inefficient. - * - * Results: - * TRUE if any windows need to have backing-store removed. - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -static Bool -miCheckSubSaveUnder( - register WindowPtr pParent, /* Parent to check */ - WindowPtr pFirst, /* first reconfigured window */ - RegionPtr pRegion) /* Initial area obscured by saveUnder */ -{ - register WindowPtr pChild; /* Current child */ - register ScreenPtr pScreen; /* Screen to use */ - RegionRec SubRegion; /* Area of children obscured */ - Bool res = FALSE; /* result */ - Bool subInited=FALSE;/* SubRegion initialized */ - - pScreen = pParent->drawable.pScreen; - if ( (pChild = pParent->firstChild) ) - { - /* - * build region above first changed window - */ - - for (; pChild != pFirst; pChild = pChild->nextSib) - if (pChild->viewable && pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - - /* - * check region below and including first changed window - */ - - for (; pChild; pChild = pChild->nextSib) - { - if (pChild->viewable) - { - /* - * don't save under nephew/niece windows; - * use a separate region - */ - - if (pChild->firstChild) - { - if (!subInited) - { - REGION_NULL(pScreen, &SubRegion); - subInited = TRUE; - } - REGION_COPY(pScreen, &SubRegion, pRegion); - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - &SubRegion); - } - else - { - res |= miCheckSubSaveUnder(pChild, pChild->firstChild, - pRegion); - } - - if (pChild->saveUnder) - REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize); - } - } - - if (subInited) - REGION_UNINIT(pScreen, &SubRegion); - } - - /* - * Check the state of this window. DIX save unders are - * enabled for viewable windows with some client expressing - * exposure interest and which intersect the save under region - */ - - if (pParent->viewable && - ((pParent->eventMask | wOtherEventMasks(pParent)) & ExposureMask) && - REGION_NOTEMPTY(pScreen, &pParent->borderSize) && - RECT_IN_REGION(pScreen, pRegion, REGION_EXTENTS(pScreen, - &pParent->borderSize)) != rgnOUT) - { - if (!pParent->DIXsaveUnder) - { - pParent->DIXsaveUnder = TRUE; - (*pScreen->ChangeWindowAttributes) (pParent, CWBackingStore); - } - } - else - { - if (pParent->DIXsaveUnder) - { - res = TRUE; - pParent->DIXsaveUnder = FALSE; - } - } - return res; -} - - -/*- - *----------------------------------------------------------------------- - * miChangeSaveUnder -- - * Change the save-under state of a tree of windows. Called when - * a window with saveUnder TRUE is mapped/unmapped/reconfigured. - * - * Results: - * TRUE if any windows need to have backing-store removed (which - * means that PostChangeSaveUnder needs to be called later to - * finish the job). - * - * Side Effects: - * Windows may have backing-store turned on or off. - * - *----------------------------------------------------------------------- - */ -Bool -miChangeSaveUnder(pWin, first) - register WindowPtr pWin; - WindowPtr first; /* First window to check. - * Used when pWin was restacked */ -{ - RegionRec rgn; /* Area obscured by saveUnder windows */ - register ScreenPtr pScreen; - Bool res; - - if (!deltaSaveUndersViewable && !numSaveUndersViewable) - return FALSE; - numSaveUndersViewable += deltaSaveUndersViewable; - deltaSaveUndersViewable = 0; - pScreen = pWin->drawable.pScreen; - REGION_NULL(pScreen, &rgn); - res = miCheckSubSaveUnder (pWin->parent, - pWin->saveUnder ? first : pWin->nextSib, - &rgn); - REGION_UNINIT(pScreen, &rgn); - return res; -} - -/*- - *----------------------------------------------------------------------- - * miPostChangeSaveUnder -- - * Actually turn backing-store off for those windows that no longer - * need to have it on. - * - * Results: - * None. - * - * Side Effects: - * Backing-store and SAVE_UNDER_CHANGE_BIT are turned off for those - * windows affected. - * - *----------------------------------------------------------------------- - */ -void -miPostChangeSaveUnder(pWin, pFirst) - WindowPtr pWin; - WindowPtr pFirst; -{ - register WindowPtr pParent, pChild; - ChangeWindowAttributesProcPtr ChangeWindowAttributes; - - if (!(pParent = pWin->parent)) - return; - ChangeWindowAttributes = pParent->drawable.pScreen->ChangeWindowAttributes; - if (!pParent->DIXsaveUnder && - (pParent->backingStore == NotUseful) && pParent->backStorage) - (*ChangeWindowAttributes)(pParent, CWBackingStore); - if (!(pChild = pFirst)) - return; - while (1) - { - if (!pChild->DIXsaveUnder && - (pChild->backingStore == NotUseful) && pChild->backStorage) - (*ChangeWindowAttributes)(pChild, CWBackingStore); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib) - { - pChild = pChild->parent; - if (pChild == pParent) - return; - } - pChild = pChild->nextSib; - } -} - -void -miMarkWindow(pWin) - register WindowPtr pWin; -{ - register ValidatePtr val; - - if (pWin->valdata) - return; - val = (ValidatePtr)xnfalloc(sizeof(ValidateRec)); - val->before.oldAbsCorner.x = pWin->drawable.x; - val->before.oldAbsCorner.y = pWin->drawable.y; - val->before.borderVisible = NullRegion; - val->before.resized = FALSE; - pWin->valdata = val; -} - -Bool -miMarkOverlappedWindows(pWin, pFirst, ppLayerWin) - WindowPtr pWin; - WindowPtr pFirst; - WindowPtr *ppLayerWin; -{ - register BoxPtr box; - register WindowPtr pChild, pLast; - Bool anyMarked = FALSE; - MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow; - ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - - /* single layered systems are easy */ - if (ppLayerWin) *ppLayerWin = pWin; - - if (pWin == pFirst) - { - /* Blindly mark pWin and all of its inferiors. This is a slight - * overkill if there are mapped windows that outside pWin's border, - * but it's better than wasting time on RectIn checks. - */ - pChild = pWin; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - (* MarkWindow)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - anyMarked = TRUE; - pFirst = pFirst->nextSib; - } - if ( (pChild = pFirst) ) - { - box = REGION_EXTENTS(pChild->drawable.pScreen, &pWin->borderSize); - pLast = pChild->parent->lastChild; - while (1) - { - if (pChild->viewable) - { - if (REGION_BROKEN (pScreen, &pChild->winSize)) - SetWinSize (pChild); - if (REGION_BROKEN (pScreen, &pChild->borderSize)) - SetBorderSize (pChild); - if (RECT_IN_REGION(pScreen, &pChild->borderSize, box)) - { - (* MarkWindow)(pChild); - anyMarked = TRUE; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - } - while (!pChild->nextSib && (pChild != pLast)) - pChild = pChild->parent; - if (pChild == pLast) - break; - pChild = pChild->nextSib; - } - } - if (anyMarked) - (* MarkWindow)(pWin->parent); - return anyMarked; -} - -/***** - * miHandleValidateExposures(pWin) - * starting at pWin, draw background in any windows that have exposure - * regions, translate the regions, restore any backing store, - * and then send any regions still exposed to the client - *****/ -void -miHandleValidateExposures(pWin) - WindowPtr pWin; -{ - register WindowPtr pChild; - register ValidatePtr val; - ScreenPtr pScreen; - WindowExposuresProcPtr WindowExposures; - - pScreen = pWin->drawable.pScreen; - - pChild = pWin; - WindowExposures = pChild->drawable.pScreen->WindowExposures; - while (1) - { - if ( (val = pChild->valdata) ) - { - if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed)) - (*pChild->drawable.pScreen->PaintWindowBorder)(pChild, - &val->after.borderExposed, - PW_BORDER); - REGION_UNINIT(pScreen, &val->after.borderExposed); - (*WindowExposures)(pChild, &val->after.exposed, NullRegion); - REGION_UNINIT(pScreen, &val->after.exposed); - xfree(val); - pChild->valdata = (ValidatePtr)NULL; - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } -} - -void -miMoveWindow(pWin, x, y, pNextSib, kind) - register WindowPtr pWin; - int x,y; - WindowPtr pNextSib; - VTKind kind; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - short bw; - RegionPtr oldRegion = NULL; - DDXPointRec oldpt; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr windowToValidate; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be moved */ - if (!(pParent = pWin->parent)) - return ; - pScreen = pWin->drawable.pScreen; - bw = wBorderWidth (pWin); - - oldpt.x = pWin->drawable.x; - oldpt.y = pWin->drawable.y; - if (WasViewable) - { - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->borderClip); - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - } - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - x = pWin->drawable.x = pParent->drawable.x + x + (int)bw; - y = pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - SetWinSize (pWin); - SetBorderSize (pWin); - - (*pScreen->PositionWindow)(pWin, x, y); - - windowToValidate = MoveWindowInStack(pWin, pNextSib); - - ResizeChildrenWinSize(pWin, x - oldpt.x, y - oldpt.y, 0, 0); - - if (WasViewable) - { - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, windowToValidate, (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows) - (pWin, pLayerWin, (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, windowToValidate); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind); - (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion); - REGION_DESTROY(pScreen, oldRegion); - /* XXX need to retile border if ParentRelative origin */ - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, windowToValidate); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - - -/* - * pValid is a region of the screen which has been - * successfully copied -- recomputed exposed regions for affected windows - */ - -static int -miRecomputeExposures ( - register WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - register ScreenPtr pScreen; - RegionPtr pValid = (RegionPtr)value; - - if (pWin->valdata) - { - pScreen = pWin->drawable.pScreen; - /* - * compute exposed regions of this window - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->clipList, pValid); - /* - * compute exposed regions of the border - */ - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->borderClip, &pWin->winSize); - REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed, - &pWin->valdata->after.borderExposed, pValid); - return WT_WALKCHILDREN; - } - return WT_NOMATCH; -} - -void -miSlideAndSizeWindow(pWin, x, y, w, h, pSib) - register WindowPtr pWin; - int x,y; - unsigned int w, h; - WindowPtr pSib; -{ - WindowPtr pParent; - Bool WasViewable = (Bool)(pWin->viewable); - unsigned short width = pWin->drawable.width, - height = pWin->drawable.height; - short oldx = pWin->drawable.x, - oldy = pWin->drawable.y; - int bw = wBorderWidth (pWin); - short dw, dh; - DDXPointRec oldpt; - RegionPtr oldRegion = NULL; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - WindowPtr pFirstChange; - register WindowPtr pChild; - RegionPtr gravitate[StaticGravity + 1]; - register unsigned g; - int nx, ny; /* destination x,y */ - int newx, newy; /* new inner window position */ - RegionPtr pRegion = NULL; - RegionPtr destClip; /* portions of destination already written */ - RegionPtr oldWinClip = NULL; /* old clip list for window */ - RegionPtr borderVisible = NullRegion; /* visible area of the border */ - RegionPtr bsExposed = NullRegion; /* backing store exposures */ - Bool shrunk = FALSE; /* shrunk in an inner dimension */ - Bool moved = FALSE; /* window position changed */ -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - /* if this is a root window, can't be resized */ - if (!(pParent = pWin->parent)) - return ; - - pScreen = pWin->drawable.pScreen; - newx = pParent->drawable.x + x + bw; - newy = pParent->drawable.y + y + bw; - if (WasViewable) - { - anyMarked = FALSE; - /* - * save the visible region of the window - */ - oldRegion = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldRegion, &pWin->winSize); - - /* - * categorize child windows into regions to be moved - */ - for (g = 0; g <= StaticGravity; g++) - gravitate[g] = (RegionPtr) NULL; - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - g = pChild->winGravity; - if (g != UnmapGravity) - { - if (!gravitate[g]) - gravitate[g] = REGION_CREATE(pScreen, NullBox, 1); - REGION_UNION(pScreen, gravitate[g], - gravitate[g], &pChild->borderClip); - } - else - { - UnmapWindow(pChild, TRUE); - anyMarked = TRUE; - } - } - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - - oldWinClip = NULL; - if (pWin->bitGravity != ForgetGravity) - { - oldWinClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, oldWinClip, &pWin->clipList); - } - /* - * if the window is changing size, borderExposed - * can't be computed correctly without some help. - */ - if (pWin->drawable.height > h || pWin->drawable.width > w) - shrunk = TRUE; - - if (newx != oldx || newy != oldy) - moved = TRUE; - - if ((pWin->drawable.height != h || pWin->drawable.width != w) && - HasBorder (pWin)) - { - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - /* for tiled borders, we punt and draw the whole thing */ - if (pWin->borderIsPixel || !moved) - { - if (shrunk || moved) - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, - &pWin->winSize); - else - REGION_COPY(pScreen, borderVisible, - &pWin->borderClip); - } - } - } - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.height = h; - pWin->drawable.width = w; - - x = pWin->drawable.x = newx; - y = pWin->drawable.y = newy; - - SetWinSize (pWin); - SetBorderSize (pWin); - - dw = (int)w - (int)width; - dh = (int)h - (int)height; - ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh); - - /* let the hardware adjust background and border pixmaps, if any */ - (*pScreen->PositionWindow)(pWin, x, y); - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - pRegion = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->backStorage) - REGION_COPY(pScreen, pRegion, &pWin->clipList); - - if (pLayerWin == pWin) - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - (WindowPtr *)NULL); - else - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - - if (pWin->valdata) - { - pWin->valdata->before.resized = TRUE; - pWin->valdata->before.borderVisible = borderVisible; - } - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, VTOther); - /* - * the entire window is trashed unless bitGravity - * recovers portions of it - */ - REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList); - } - - GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny); - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pRegion = &pWin->clipList; /* a convenient empty region */ - if (pWin->bitGravity == ForgetGravity) - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, NullRegion, oldx, oldy); - else - { - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, nx - x, ny - y, pRegion, oldx, oldy); - } - } - - if (WasViewable) - { - /* avoid the border */ - if (HasBorder (pWin)) - { - int offx, offy, dx, dy; - - /* kruft to avoid double translates for each gravity */ - offx = 0; - offy = 0; - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - /* align winSize to gravitate[g]. - * winSize is in new coordinates, - * gravitate[g] is still in old coordinates */ - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - dx = (oldx - nx) - offx; - dy = (oldy - ny) - offy; - if (dx || dy) - { - REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy); - offx += dx; - offy += dy; - } - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], - &pWin->winSize); - } - /* get winSize back where it belongs */ - if (offx || offy) - REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy); - } - /* - * add screen bits to the appropriate bucket - */ - - if (oldWinClip) - { - /* - * clip to new clipList - */ - REGION_COPY(pScreen, pRegion, oldWinClip); - REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy); - REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList); - /* - * don't step on any gravity bits which will be copied after this - * region. Note -- this assumes that the regions will be copied - * in gravity order. - */ - for (g = pWin->bitGravity + 1; g <= StaticGravity; g++) - { - if (gravitate[g]) - REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip, - gravitate[g]); - } - REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny); - g = pWin->bitGravity; - if (!gravitate[g]) - gravitate[g] = oldWinClip; - else - { - REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip); - REGION_DESTROY(pScreen, oldWinClip); - } - } - - /* - * move the bits on the screen - */ - - destClip = NULL; - - for (g = 0; g <= StaticGravity; g++) - { - if (!gravitate[g]) - continue; - - GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny); - - oldpt.x = oldx + (x - nx); - oldpt.y = oldy + (y - ny); - - /* Note that gravitate[g] is *translated* by CopyWindow */ - - /* only copy the remaining useful bits */ - - REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], oldRegion); - - /* clip to not overwrite already copied areas */ - - if (destClip) { - REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y); - REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip); - REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y); - } - - /* and move those bits */ - - if (oldpt.x != x || oldpt.y != y -#ifdef COMPOSITE - || pWin->redirectDraw -#endif - ) - { - (*pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, gravitate[g]); - } - - /* remove any overwritten bits from the remaining useful bits */ - - REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]); - - /* - * recompute exposed regions of child windows - */ - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->winGravity != g) - continue; - REGION_INTERSECT(pScreen, pRegion, - &pChild->borderClip, gravitate[g]); - TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion); - } - - /* - * remove the successfully copied regions of the - * window from its exposed region - */ - - if (g == pWin->bitGravity) - REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed, - &pWin->valdata->after.exposed, gravitate[g]); - if (!destClip) - destClip = gravitate[g]; - else - { - REGION_UNION(pScreen, destClip, destClip, gravitate[g]); - REGION_DESTROY(pScreen, gravitate[g]); - } - } - - REGION_DESTROY(pScreen, oldRegion); - REGION_DESTROY(pScreen, pRegion); - if (destClip) - REGION_DESTROY(pScreen, destClip); - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, - VTOther); - } - else if (bsExposed) - { - (*pScreen->WindowExposures) (pWin, NullRegion, bsExposed); - REGION_DESTROY(pScreen, bsExposed); - } - if (pWin->realized) - WindowsRestructured (); -} - -WindowPtr -miGetLayerWindow(pWin) - WindowPtr pWin; -{ - return pWin->firstChild; -} - -#ifdef SHAPE -/****** - * - * miSetShape - * The border/window shape has changed. Recompute winSize/borderSize - * and send appropriate exposure events - */ - -void -miSetShape(pWin) - register WindowPtr pWin; -{ - Bool WasViewable = (Bool)(pWin->viewable); - register ScreenPtr pScreen = pWin->drawable.pScreen; - Bool anyMarked = FALSE; - RegionPtr pOldClip = NULL, bsExposed; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - if (pWin->valdata) - { - if (HasBorder (pWin)) - { - RegionPtr borderVisible; - - borderVisible = REGION_CREATE(pScreen, NullBox, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - pWin->valdata->before.resized = TRUE; - } - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - if (WasViewable) - { - if (pWin->backStorage) - { - pOldClip = REGION_CREATE(pScreen, NullBox, 1); - REGION_COPY(pScreen, pOldClip, &pWin->clipList); - } - - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); - -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - - if (pWin->backStorage && - ((pWin->backingStore == Always) || WasViewable)) - { - if (!WasViewable) - pOldClip = &pWin->clipList; /* a convenient empty region */ - bsExposed = (*pScreen->TranslateBackingStore) - (pWin, 0, 0, pOldClip, - pWin->drawable.x, pWin->drawable.y); - if (WasViewable) - REGION_DESTROY(pScreen, pOldClip); - if (bsExposed) - { - RegionPtr valExposed = NullRegion; - - if (pWin->valdata) - valExposed = &pWin->valdata->after.exposed; - (*pScreen->WindowExposures) (pWin, valExposed, bsExposed); - if (valExposed) - REGION_EMPTY(pScreen, valExposed); - REGION_DESTROY(pScreen, bsExposed); - } - } - if (WasViewable) - { - if (anyMarked) - (*pScreen->HandleExposures)(pLayerWin->parent); -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, VTOther); - } - if (pWin->realized) - WindowsRestructured (); - CheckCursorConfinement(pWin); -} -#endif - -/* Keeps the same inside(!) origin */ - -void -miChangeBorderWidth(pWin, width) - register WindowPtr pWin; - unsigned int width; -{ - int oldwidth; - Bool anyMarked = FALSE; - register ScreenPtr pScreen; - Bool WasViewable = (Bool)(pWin->viewable); - Bool HadBorder; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - oldwidth = wBorderWidth (pWin); - if (oldwidth == width) - return; - HadBorder = HasBorder(pWin); - pScreen = pWin->drawable.pScreen; - if (WasViewable && width < oldwidth) - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin); - - pWin->borderWidth = width; - SetBorderSize (pWin); - - if (WasViewable) - { - if (width > oldwidth) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - /* - * save the old border visible region to correctly compute - * borderExposed. - */ - if (pWin->valdata && HadBorder) - { - RegionPtr borderVisible; - borderVisible = REGION_CREATE(pScreen, NULL, 1); - REGION_SUBTRACT(pScreen, borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTOther); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, - VTOther); - } - if (pWin->realized) - WindowsRestructured (); -} - -void -miMarkUnrealizedWindow(pChild, pWin, fromConfigure) - WindowPtr pChild; - WindowPtr pWin; - Bool fromConfigure; -{ - if ((pChild != pWin) || fromConfigure) - { - REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList); - if (pChild->drawable.pScreen->ClipNotify) - (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0); - REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip); - } -} - -void -miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth) -{ - ScreenPtr pScreen; - WindowPtr pChild; - - pScreen = pWin->drawable.pScreen; - - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (pChild->drawable.depth == depth) - REGION_UNION(pScreen, pReg, pReg, &pChild->borderClip); - - if (pChild->firstChild) - miSegregateChildren(pChild, pReg, depth); - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.NX.original deleted file mode 100644 index d9054b4b6..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.NX.original +++ /dev/null @@ -1,2270 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $XFree86: xc/programs/Xserver/render/picture.c,v 1.29 2002/11/23 02:38:15 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "NXpicturestr.h" - -#include "Screen.h" -#include "Pixmaps.h" -#include "Drawable.h" -#include "Render.h" - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -void *nxagentVisualFromID(ScreenPtr pScreen, VisualID visual); - -void *nxagentMatchingFormats(PictFormatPtr pForm); - -int PictureScreenPrivateIndex = -1; -int PictureWindowPrivateIndex; -int PictureGeneration; -RESTYPE PictureType; -RESTYPE PictFormatType; -RESTYPE GlyphSetType; -int PictureCmapPolicy = PictureCmapPolicyDefault; - -typedef struct _formatInit { - CARD32 format; - CARD8 depth; -} FormatInitRec, *FormatInitPtr; - -void nxagentPictureCreateDefaultFormats(ScreenPtr pScreen, FormatInitRec *formats, int *nformats); - -/* Picture Private machinery */ - -static int picturePrivateCount; - -void -ResetPicturePrivateIndex (void) -{ - picturePrivateCount = 0; -} - -int -AllocatePicturePrivateIndex (void) -{ - return picturePrivateCount++; -} - -Bool -AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - unsigned int oldamount; - - /* Round up sizes for proper alignment */ - amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long); - - if (index2 >= ps->PicturePrivateLen) - { - unsigned int *nsizes; - - nsizes = (unsigned int *)xrealloc(ps->PicturePrivateSizes, - (index2 + 1) * sizeof(unsigned int)); - if (!nsizes) - return FALSE; - while (ps->PicturePrivateLen <= index2) - { - nsizes[ps->PicturePrivateLen++] = 0; - ps->totalPictureSize += sizeof(DevUnion); - } - ps->PicturePrivateSizes = nsizes; - } - oldamount = ps->PicturePrivateSizes[index2]; - if (amount > oldamount) - { - ps->PicturePrivateSizes[index2] = amount; - ps->totalPictureSize += (amount - oldamount); - } - - return TRUE; -} - - -Bool -PictureDestroyWindow (WindowPtr pWindow) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - - while ((pPicture = GetPictureWindow(pWindow))) - { - SetPictureWindow(pWindow, pPicture->pNext); - if (pPicture->id) - FreeResource (pPicture->id, PictureType); - FreePicture ((pointer) pPicture, pPicture->id); - } - pScreen->DestroyWindow = ps->DestroyWindow; - ret = (*pScreen->DestroyWindow) (pWindow); - ps->DestroyWindow = pScreen->DestroyWindow; - pScreen->DestroyWindow = PictureDestroyWindow; - return ret; -} - -Bool -PictureCloseScreen (int index, ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - int n; - - pScreen->CloseScreen = ps->CloseScreen; - ret = (*pScreen->CloseScreen) (index, pScreen); - PictureResetFilters (pScreen); - for (n = 0; n < ps->nformats; n++) - if (ps->formats[n].type == PictTypeIndexed) - (*ps->CloseIndexed) (pScreen, &ps->formats[n]); - SetPictureScreen(pScreen, 0); - if (ps->PicturePrivateSizes) - xfree (ps->PicturePrivateSizes); - xfree (ps->formats); - xfree (ps); - return ret; -} - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef) -{ - ScreenPtr pScreen = pColormap->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - pScreen->StoreColors = ps->StoreColors; - (*pScreen->StoreColors) (pColormap, ndef, pdef); - ps->StoreColors = pScreen->StoreColors; - pScreen->StoreColors = PictureStoreColors; - - if (pColormap->class == PseudoColor || pColormap->class == GrayScale) - { - PictFormatPtr format = ps->formats; - int nformats = ps->nformats; - - while (nformats--) - { - if (format->type == PictTypeIndexed && - format->index.pColormap == pColormap) - { - (*ps->UpdateIndexed) (pScreen, format, ndef, pdef); - break; - } - format++; - } - } -} - -static int -visualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - int d, v; - DepthPtr pDepth; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - for (v = 0; v < pDepth->numVids; v++) - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - return 0; -} - -static int -addFormat (FormatInitRec formats[256], - int nformat, - CARD32 format, - CARD8 depth) -{ - int n; - - for (n = 0; n < nformat; n++) - if (formats[n].format == format && formats[n].depth == depth) - return nformat; - formats[nformat].format = format; - formats[nformat].depth = depth; - - #ifdef DEBUG - fprintf(stderr, "addFormat: Added format [%lu] depth [%d].\n", format, depth); - #endif - - return ++nformat; -} - -#define Mask(n) ((n) == 32 ? 0xffffffff : ((1 << (n))-1)) - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp) -{ - int nformats, f; - PictFormatPtr pFormats; - FormatInitRec formats[1024]; - CARD32 format; - -#ifndef NXAGENT_SERVER - - CARD8 depth; - VisualPtr pVisual; - int v; - int bpp; - int type; - int r, g, b; - int d; - DepthPtr pDepth; - -#endif - - nformats = 0; - -#ifdef NXAGENT_SERVER - - nxagentPictureCreateDefaultFormats(pScreen, formats, &nformats); - -#else - - /* formats required by protocol */ - formats[nformats].format = PICT_a1; - formats[nformats].depth = 1; - nformats++; - formats[nformats].format = PICT_a8; - formats[nformats].depth = 8; - nformats++; - formats[nformats].format = PICT_a4; - formats[nformats].depth = 4; - nformats++; - formats[nformats].format = PICT_a8r8g8b8; - formats[nformats].depth = 32; - nformats++; - formats[nformats].format = PICT_x8r8g8b8; - formats[nformats].depth = 32; - nformats++; - - /* now look through the depths and visuals adding other formats */ - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = &pScreen->visuals[v]; - depth = visualDepth (pScreen, pVisual); - if (!depth) - continue; - bpp = BitsPerPixel (depth); - - switch (pVisual->class) { - case DirectColor: - case TrueColor: - r = Ones (pVisual->redMask); - g = Ones (pVisual->greenMask); - b = Ones (pVisual->blueMask); - type = PICT_TYPE_OTHER; - /* - * Current rendering code supports only two direct formats, - * fields must be packed together at the bottom of the pixel - * and must be either RGB or BGR - */ - if (pVisual->offsetBlue == 0 && - pVisual->offsetGreen == b && - pVisual->offsetRed == b + g) - { - type = PICT_TYPE_ARGB; - } - else if (pVisual->offsetRed == 0 && - pVisual->offsetGreen == r && - pVisual->offsetBlue == r + g) - { - type = PICT_TYPE_ABGR; - } - if (type != PICT_TYPE_OTHER) - { - format = PICT_FORMAT(bpp, type, 0, r, g, b); - nformats = addFormat (formats, nformats, format, depth); - } - break; - case StaticColor: - case PseudoColor: - format = PICT_VISFORMAT (bpp, PICT_TYPE_COLOR, v); - nformats = addFormat (formats, nformats, format, depth); - break; - case StaticGray: - case GrayScale: - format = PICT_VISFORMAT (bpp, PICT_TYPE_GRAY, v); - nformats = addFormat (formats, nformats, format, depth); - break; - } - } - - /* - * Walk supported depths and add useful Direct formats - */ - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - bpp = BitsPerPixel (pDepth->depth); - format = 0; - - switch (bpp) { - case 16: - /* depth 12 formats */ - if (pDepth->depth >= 12) - { - nformats = addFormat (formats, nformats, - PICT_x4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x4b4g4r4, pDepth->depth); - } - - /* depth 15 formats */ - if (pDepth->depth >= 15) - { - nformats = addFormat (formats, nformats, - PICT_x1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x1b5g5r5, pDepth->depth); - } - /* depth 16 formats */ - if (pDepth->depth >= 16) - { - nformats = addFormat (formats, nformats, - PICT_a1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a1b5g5r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_r5g6b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b5g6r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4b4g4r4, pDepth->depth); - } - break; - case 24: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b8g8r8, pDepth->depth); - } - break; - case 32: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_x8r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x8b8g8r8, pDepth->depth); - } - break; - } - } - -#endif - - pFormats = (PictFormatPtr) xalloc (nformats * sizeof (PictFormatRec)); - if (!pFormats) - return 0; - memset (pFormats, '\0', nformats * sizeof (PictFormatRec)); - for (f = 0; f < nformats; f++) - { - pFormats[f].id = FakeClientID (0); - pFormats[f].depth = formats[f].depth; - format = formats[f].format; - pFormats[f].format = format; - switch (PICT_FORMAT_TYPE(format)) { - case PICT_TYPE_ARGB: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_R(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = (PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_B(format); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = 0; - break; - - case PICT_TYPE_ABGR: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_B(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = (PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_R(format); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = 0; - break; - - case PICT_TYPE_A: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alpha = 0; - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - - /* remaining fields already set to zero */ - break; - - case PICT_TYPE_COLOR: - case PICT_TYPE_GRAY: - pFormats[f].type = PictTypeIndexed; - pFormats[f].index.vid = pScreen->visuals[PICT_FORMAT_VIS(format)].vid; - break; - } - -#ifdef NXAGENT_SERVER - if (nxagentMatchingFormats(&pFormats[f]) != NULL) - { - #ifdef DEBUG - fprintf(stderr, "PictureCreateDefaultFormats: Format with type [%d] depth [%d] rgb [%d,%d,%d] " - "mask rgb [%d,%d,%d] alpha [%d] alpha mask [%d] matches.\n", - pFormats[f].type, pFormats[f].depth, pFormats[f].direct.red, pFormats[f].direct.green, - pFormats[f].direct.blue, pFormats[f].direct.redMask, pFormats[f].direct.greenMask, - pFormats[f].direct.blueMask, pFormats[f].direct.alpha, pFormats[f].direct.alphaMask); - #endif - } - else - { - #ifdef DEBUG - fprintf(stderr, "PictureCreateDefaultFormats: Format with type [%d] depth [%d] rgb [%d,%d,%d] " - "mask rgb [%d,%d,%d] alpha [%d] alpha mask [%d] doesn't match.\n", - pFormats[f].type, pFormats[f].depth, pFormats[f].direct.red, pFormats[f].direct.green, - pFormats[f].direct.blue, pFormats[f].direct.redMask, pFormats[f].direct.greenMask, - pFormats[f].direct.blueMask, pFormats[f].direct.alpha, pFormats[f].direct.alphaMask); - #endif - } -#endif - } - *nformatp = nformats; - return pFormats; -} - -static VisualPtr -PictureFindVisual (ScreenPtr pScreen, VisualID visual) -{ - int i; - VisualPtr pVisual; - for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid == visual) - return pVisual; - } - return 0; -} - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return FALSE; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->type == PictTypeIndexed && !format->index.pColormap) - { - if (format->index.vid == pScreen->rootVisual) - format->index.pColormap = (ColormapPtr) LookupIDByType(pScreen->defColormap, - RT_COLORMAP); - else - { - VisualPtr pVisual; - - pVisual = PictureFindVisual (pScreen, format->index.vid); - if (CreateColormap (FakeClientID (0), pScreen, - pVisual, - &format->index.pColormap, AllocNone, - 0) != Success) - { - return FALSE; - } - } - if (!(*ps->InitIndexed) (pScreen, format)) - return FALSE; - } - format++; - } - return TRUE; -} - -Bool -PictureFinishInit (void) -{ - int s; - - for (s = 0; s < screenInfo.numScreens; s++) - { - if (!PictureInitIndexedFormats (screenInfo.screens[s])) - return FALSE; - (void) AnimCurInit (screenInfo.screens[s]); - } - - return TRUE; -} - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return FALSE; - ps->subpixel = subpixel; - return TRUE; - -} - -int -PictureGetSubpixelOrder (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return SubPixelUnknown; - return ps->subpixel; -} - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - int type; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - switch (pVisual->class) { - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - type = PictTypeIndexed; - break; - case TrueColor: - case DirectColor: - type = PictTypeDirect; - break; - default: - return 0; - } - while (nformat--) - { - if (format->depth == depth && format->type == type) - { - if (type == PictTypeIndexed) - { - if (format->index.vid == pVisual->vid) - return format; - } - else - { - if (format->direct.redMask << format->direct.red == - pVisual->redMask && - format->direct.greenMask << format->direct.green == - pVisual->greenMask && - format->direct.blueMask << format->direct.blue == - pVisual->blueMask) - { - return format; - } - } - } - format++; - } - return 0; -} - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 f) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->depth == depth && format->format == (f & 0xffffff)) - return format; - format++; - } - return 0; -} - -int -PictureParseCmapPolicy (const char *name) -{ - if ( strcmp (name, "default" ) == 0) - return PictureCmapPolicyDefault; - else if ( strcmp (name, "mono" ) == 0) - return PictureCmapPolicyMono; - else if ( strcmp (name, "gray" ) == 0) - return PictureCmapPolicyGray; - else if ( strcmp (name, "color" ) == 0) - return PictureCmapPolicyColor; - else if ( strcmp (name, "all" ) == 0) - return PictureCmapPolicyAll; - else - return PictureCmapPolicyInvalid; -} - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats) -{ - PictureScreenPtr ps; - int n; - CARD32 type, a, r, g, b; - - if (PictureGeneration != serverGeneration) - { - PictureType = CreateNewResourceType (FreePicture); - if (!PictureType) - return FALSE; - PictFormatType = CreateNewResourceType (FreePictFormat); - if (!PictFormatType) - return FALSE; - GlyphSetType = CreateNewResourceType (FreeGlyphSet); - if (!GlyphSetType) - return FALSE; - PictureScreenPrivateIndex = AllocateScreenPrivateIndex(); - if (PictureScreenPrivateIndex < 0) - return FALSE; - PictureWindowPrivateIndex = AllocateWindowPrivateIndex(); - PictureGeneration = serverGeneration; -#ifdef XResExtension - RegisterResourceName (PictureType, "PICTURE"); - RegisterResourceName (PictFormatType, "PICTFORMAT"); - RegisterResourceName (GlyphSetType, "GLYPHSET"); -#endif - } - if (!AllocateWindowPrivate (pScreen, PictureWindowPrivateIndex, 0)) - return FALSE; - - if (!formats) - { - formats = PictureCreateDefaultFormats (pScreen, &nformats); - if (!formats) - return FALSE; - } - for (n = 0; n < nformats; n++) - { - if (!AddResource (formats[n].id, PictFormatType, (pointer) (formats+n))) - { - xfree (formats); - return FALSE; - } - if (formats[n].type == PictTypeIndexed) - { - VisualPtr pVisual = PictureFindVisual (pScreen, formats[n].index.vid); - if ((pVisual->class | DynamicClass) == PseudoColor) - type = PICT_TYPE_COLOR; - else - type = PICT_TYPE_GRAY; - a = r = g = b = 0; - } - else - { - if ((formats[n].direct.redMask| - formats[n].direct.blueMask| - formats[n].direct.greenMask) == 0) - type = PICT_TYPE_A; - else if (formats[n].direct.red > formats[n].direct.blue) - type = PICT_TYPE_ARGB; - else - type = PICT_TYPE_ABGR; - a = Ones (formats[n].direct.alphaMask); - r = Ones (formats[n].direct.redMask); - g = Ones (formats[n].direct.greenMask); - b = Ones (formats[n].direct.blueMask); - } - formats[n].format = PICT_FORMAT(0,type,a,r,g,b); - } - ps = (PictureScreenPtr) xalloc (sizeof (PictureScreenRec)); - if (!ps) - { - xfree (formats); - return FALSE; - } - SetPictureScreen(pScreen, ps); - if (!GlyphInit (pScreen)) - { - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - ps->totalPictureSize = sizeof (PictureRec); - ps->PicturePrivateSizes = 0; - ps->PicturePrivateLen = 0; - - ps->formats = formats; - ps->fallback = formats; - ps->nformats = nformats; - - ps->filters = 0; - ps->nfilters = 0; - ps->filterAliases = 0; - ps->nfilterAliases = 0; - - ps->subpixel = SubPixelUnknown; - - ps->CloseScreen = pScreen->CloseScreen; - ps->DestroyWindow = pScreen->DestroyWindow; - ps->StoreColors = pScreen->StoreColors; - pScreen->DestroyWindow = PictureDestroyWindow; - pScreen->CloseScreen = PictureCloseScreen; - pScreen->StoreColors = PictureStoreColors; - - if (!PictureSetDefaultFilters (pScreen)) - { - PictureResetFilters (pScreen); - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - return TRUE; -} - -void -SetPictureToDefaults (PicturePtr pPicture) -{ - pPicture->refcnt = 1; - pPicture->repeat = 0; - pPicture->graphicsExposures = FALSE; - pPicture->subWindowMode = ClipByChildren; - pPicture->polyEdge = PolyEdgeSharp; - pPicture->polyMode = PolyModePrecise; - pPicture->freeCompClip = FALSE; - pPicture->clientClipType = CT_NONE; - pPicture->componentAlpha = FALSE; - pPicture->repeatType = RepeatNone; - - pPicture->alphaMap = 0; - pPicture->alphaOrigin.x = 0; - pPicture->alphaOrigin.y = 0; - - pPicture->clipOrigin.x = 0; - pPicture->clipOrigin.y = 0; - pPicture->clientClip = 0; - - pPicture->transform = 0; - - pPicture->dither = None; - pPicture->filter = PictureGetFilterId (FilterNearest, -1, TRUE); - pPicture->filter_params = 0; - pPicture->filter_nparams = 0; - - pPicture->serialNumber = GC_CHANGE_SERIAL_BIT; - pPicture->stateChanges = (1 << (CPLastBit+1)) - 1; - pPicture->pSourcePict = 0; -} - -PicturePtr -AllocatePicture (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture; - char *ptr; - DevUnion *ppriv; - unsigned int *sizes; - unsigned int size; - int i; - - pPicture = (PicturePtr) xalloc (ps->totalPictureSize); - if (!pPicture) - return 0; - ppriv = (DevUnion *)(pPicture + 1); - pPicture->devPrivates = ppriv; - sizes = ps->PicturePrivateSizes; - ptr = (char *)(ppriv + ps->PicturePrivateLen); - for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - - nxagentPicturePriv(pPicture) -> picture = 0; - - return pPicture; -} - -/* - * Let picture always point to the virtual pixmap. - * For sure this is not the best way to deal with - * the virtual frame-buffer. - */ - -#define NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask vmask, - XID *vlist, - ClientPtr client, - int *error) -{ - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen); - - pPicture = AllocatePicture (pDrawable->pScreen); - if (!pPicture) - { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pDrawable = pDrawable; - pPicture->pFormat = pFormat; - pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24); - if (pDrawable->type == DRAWABLE_PIXMAP) - { - #ifdef NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - - pPicture->pDrawable = nxagentVirtualDrawable(pDrawable); - - #endif - - ++((PixmapPtr)pDrawable)->refcnt; - pPicture->pNext = 0; - } - else - { - pPicture->pNext = GetPictureWindow(((WindowPtr) pDrawable)); - SetPictureWindow(((WindowPtr) pDrawable), pPicture); - } - - SetPictureToDefaults (pPicture); - - if (vmask) - *error = ChangePicture (pPicture, vmask, vlist, 0, client); - else - *error = Success; - if (*error == Success) - *error = (*ps->CreatePicture) (pPicture); - if (*error != Success) - { - FreePicture (pPicture, (XID) 0); - pPicture = 0; - } - return pPicture; -} - -static CARD32 xRenderColorToCard32(xRenderColor c) -{ - return - (c.alpha >> 8 << 24) | - (c.red >> 8 << 16) | - (c.green & 0xff00) | - (c.blue >> 8); -} - -static unsigned int premultiply(unsigned int x) -{ - unsigned int a = x >> 24; - unsigned int t = (x & 0xff00ff) * a; - t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; - t &= 0xff00ff; - - x = ((x >> 8) & 0xff) * a; - x = (x + ((x >> 8) & 0xff) + 0x80); - x &= 0xff00; - x |= t | (a << 24); - return x; -} - -static unsigned int INTERPOLATE_PIXEL_256(unsigned int x, unsigned int a, - unsigned int y, unsigned int b) -{ - CARD32 t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; - t >>= 8; - t &= 0xff00ff; - - x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b; - x &= 0xff00ff00; - x |= t; - return x; -} - -static void initGradientColorTable(SourcePictPtr pGradient, int *error) -{ - int begin_pos, end_pos; - xFixed incr, dpos; - int pos, current_stop; - PictGradientStopPtr stops = pGradient->linear.stops; - int nstops = pGradient->linear.nstops; - - /* The position where the gradient begins and ends */ - begin_pos = (stops[0].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16; - end_pos = (stops[nstops - 1].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16; - - pos = 0; /* The position in the color table. */ - - /* Up to first point */ - while (pos <= begin_pos) { - pGradient->linear.colorTable[pos] = xRenderColorToCard32(stops[0].color); - ++pos; - } - - incr = (1<<16)/ PICT_GRADIENT_STOPTABLE_SIZE; /* the double increment. */ - dpos = incr * pos; /* The position in terms of 0-1. */ - - current_stop = 0; /* We always interpolate between current and current + 1. */ - - /* Gradient area */ - while (pos < end_pos) { - unsigned int current_color = xRenderColorToCard32(stops[current_stop].color); - unsigned int next_color = xRenderColorToCard32(stops[current_stop + 1].color); - - int dist = (int)(256*(dpos - stops[current_stop].x) - / (stops[current_stop+1].x - stops[current_stop].x)); - int idist = 256 - dist; - - pGradient->linear.colorTable[pos] = premultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)); - - ++pos; - dpos += incr; - - if (dpos > stops[current_stop + 1].x) - ++current_stop; - } - - /* After last point */ - while (pos < PICT_GRADIENT_STOPTABLE_SIZE) { - pGradient->linear.colorTable[pos] = xRenderColorToCard32(stops[nstops - 1].color); - ++pos; - } -} - -static void initGradient(SourcePictPtr pGradient, int stopCount, - xFixed *stopPoints, xRenderColor *stopColors, int *error) -{ - int i; - xFixed dpos; - - if (stopCount <= 0) { - *error = BadValue; - return; - } - - dpos = -1; - for (i = 0; i < stopCount; ++i) { - if (stopPoints[i] <= dpos || stopPoints[i] > (1<<16)) { - *error = BadValue; - return; - } - dpos = stopPoints[i]; - } - - pGradient->linear.stops = xalloc(stopCount*sizeof(PictGradientStop)); - if (!pGradient->linear.stops) { - *error = BadAlloc; - return; - } - - pGradient->linear.nstops = stopCount; - - for (i = 0; i < stopCount; ++i) { - pGradient->linear.stops[i].x = stopPoints[i]; - pGradient->linear.stops[i].color = stopColors[i]; - } - initGradientColorTable(pGradient, error); -} - -static PicturePtr createSourcePicture(void) -{ - PicturePtr pPicture; - - extern int nxagentPicturePrivateIndex; - - unsigned int totalPictureSize; - - DevUnion *ppriv; - - char *privPictureRecAddr; - - int i; - - /* - * Compute size of entire PictureRect, plus privates. - */ - - totalPictureSize = sizeof(PictureRec) + - picturePrivateCount * sizeof(DevUnion) + - sizeof(nxagentPrivPictureRec); - - pPicture = (PicturePtr) xalloc(totalPictureSize); - - if (pPicture != NULL) - { - ppriv = (DevUnion *) (pPicture + 1); - - for (i = 0; i < picturePrivateCount; ++i) - { - /* - * Other privates are inaccessible. - */ - - ppriv[i].ptr = NULL; - } - - privPictureRecAddr = (char *) &ppriv[picturePrivateCount]; - - ppriv[nxagentPicturePrivateIndex].ptr = (pointer) privPictureRecAddr; - - pPicture -> devPrivates = ppriv; - - nxagentPicturePriv(pPicture) -> picture = 0; - } - - pPicture->pDrawable = 0; - pPicture->pFormat = 0; - pPicture->pNext = 0; - - SetPictureToDefaults(pPicture); - return pPicture; -} - -PicturePtr -CreateSolidPicture (Picture pid, xRenderColor *color, int *error) -{ - PicturePtr pPicture; - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictSolidFill)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - pPicture->pSourcePict->type = SourcePictTypeSolidFill; - pPicture->pSourcePict->solidFill.color = xRenderColorToCard32(*color); - return pPicture; -} - -PicturePtr -CreateLinearGradientPicture (Picture pid, xPointFixed *p1, xPointFixed *p2, - int nStops, xFixed *stops, xRenderColor *colors, int *error) -{ - PicturePtr pPicture; - - if (nStops < 2) { - *error = BadValue; - return 0; - } - - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - if (p1->x == p2->x && p1->y == p2->y) { - *error = BadValue; - return 0; - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictLinearGradient)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - - pPicture->pSourcePict->linear.type = SourcePictTypeLinear; - pPicture->pSourcePict->linear.p1 = *p1; - pPicture->pSourcePict->linear.p2 = *p2; - - initGradient(pPicture->pSourcePict, nStops, stops, colors, error); - if (*error) { - xfree(pPicture); - return 0; - } - return pPicture; -} - -#define FixedToDouble(x) ((x)/65536.) - -PicturePtr -CreateRadialGradientPicture (Picture pid, xPointFixed *inner, xPointFixed *outer, - xFixed innerRadius, xFixed outerRadius, - int nStops, xFixed *stops, xRenderColor *colors, int *error) -{ - PicturePtr pPicture; - PictRadialGradient *radial; - - if (nStops < 2) { - *error = BadValue; - return 0; - } - - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - { - double dx = (double)(inner->x - outer->x); - double dy = (double)(inner->y - outer->y); - if (sqrt(dx*dx + dy*dy) + (double)(innerRadius) > (double)(outerRadius)) { - *error = BadValue; - return 0; - } - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictRadialGradient)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - radial = &pPicture->pSourcePict->radial; - - radial->type = SourcePictTypeRadial; - { - double x = (double)innerRadius / (double)outerRadius; - radial->dx = (outer->x - inner->x); - radial->dy = (outer->y - inner->y); - radial->fx = (inner->x) - x*radial->dx; - radial->fy = (inner->y) - x*radial->dy; - radial->m = 1./(1+x); - radial->b = -x*radial->m; - radial->dx /= 65536.; - radial->dy /= 65536.; - radial->fx /= 65536.; - radial->fy /= 65536.; - x = outerRadius/65536.; - radial->a = x*x - radial->dx*radial->dx - radial->dy*radial->dy; - } - - initGradient(pPicture->pSourcePict, nStops, stops, colors, error); - if (*error) { - xfree(pPicture); - return 0; - } - return pPicture; -} - -PicturePtr -CreateConicalGradientPicture (Picture pid, xPointFixed *center, xFixed angle, - int nStops, xFixed *stops, xRenderColor *colors, int *error) -{ - PicturePtr pPicture; - - if (nStops < 2) { - *error = BadValue; - return 0; - } - - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictConicalGradient)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - - pPicture->pSourcePict->conical.type = SourcePictTypeConical; - pPicture->pSourcePict->conical.center = *center; - pPicture->pSourcePict->conical.angle = angle; - - initGradient(pPicture->pSourcePict, nStops, stops, colors, error); - if (*error) { - xfree(pPicture); - return 0; - } - return pPicture; -} - -#define NEXT_VAL(_type) (vlist ? (_type) *vlist++ : (_type) ulist++->val) - -#define NEXT_PTR(_type) ((_type) ulist++->ptr) - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client) -{ - ScreenPtr pScreen = pPicture->pDrawable ? pPicture->pDrawable->pScreen : 0; - PictureScreenPtr ps = pScreen ? GetPictureScreen(pScreen) : 0; - BITS32 index2; - int error = 0; - BITS32 maskQ; - - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - maskQ = vmask; - while (vmask && !error) - { - index2 = (BITS32) lowbit (vmask); - vmask &= ~index2; - pPicture->stateChanges |= index2; - switch (index2) - { - case CPRepeat: - { - unsigned int newr; - newr = NEXT_VAL(unsigned int); - if (newr <= RepeatReflect) - { - pPicture->repeat = (newr != RepeatNone); - pPicture->repeatType = newr; - } - else - { - client->errorValue = newr; - error = BadValue; - } - } - break; - case CPAlphaMap: - { - PicturePtr pAlpha; - - if (vlist) - { - Picture pid = NEXT_VAL(Picture); - - if (pid == None) - pAlpha = 0; - else - { - pAlpha = (PicturePtr) SecurityLookupIDByType(client, - pid, - PictureType, - SecurityWriteAccess|SecurityReadAccess); - if (!pAlpha) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - if (pAlpha->pDrawable->type != DRAWABLE_PIXMAP) - { - client->errorValue = pid; - error = BadMatch; - break; - } - } - } - else - pAlpha = NEXT_PTR(PicturePtr); - if (!error) - { - if (pAlpha && pAlpha->pDrawable->type == DRAWABLE_PIXMAP) - pAlpha->refcnt++; - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - pPicture->alphaMap = pAlpha; - } - } - break; - case CPAlphaXOrigin: - pPicture->alphaOrigin.x = NEXT_VAL(INT16); - break; - case CPAlphaYOrigin: - pPicture->alphaOrigin.y = NEXT_VAL(INT16); - break; - case CPClipXOrigin: - pPicture->clipOrigin.x = NEXT_VAL(INT16); - break; - case CPClipYOrigin: - pPicture->clipOrigin.y = NEXT_VAL(INT16); - break; - case CPClipMask: - { - Pixmap pid; - PixmapPtr pPixmap; - int clipType; - if (!pScreen) - return BadDrawable; - - if (vlist) - { - pid = NEXT_VAL(Pixmap); - if (pid == None) - { - clipType = CT_NONE; - pPixmap = NullPixmap; - } - else - { - clipType = CT_PIXMAP; - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, - pid, - RT_PIXMAP, - SecurityReadAccess); - if (!pPixmap) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - } - } - else - { - pPixmap = NEXT_PTR(PixmapPtr); - if (pPixmap) - clipType = CT_PIXMAP; - else - clipType = CT_NONE; - } - - if (pPixmap) - { - if ((pPixmap->drawable.depth != 1) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - break; - } - else - { - clipType = CT_PIXMAP; - pPixmap->refcnt++; - } - } - - #ifdef DEBUG - fprintf(stderr, "ChangePicture: Going to call ChangePictureClip with clipType [%d] pPixmap [%p].\n", - clipType, (void *) pPixmap); - #endif - - error = (*ps->ChangePictureClip)(pPicture, clipType, - (pointer)pPixmap, 0); - break; - } - case CPGraphicsExposure: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe <= xTrue) - pPicture->graphicsExposures = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPSubwindowMode: - { - unsigned int news; - news = NEXT_VAL(unsigned int); - if (news == ClipByChildren || news == IncludeInferiors) - pPicture->subWindowMode = news; - else - { - client->errorValue = news; - error = BadValue; - } - } - break; - case CPPolyEdge: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe == PolyEdgeSharp || newe == PolyEdgeSmooth) - pPicture->polyEdge = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPPolyMode: - { - unsigned int newm; - newm = NEXT_VAL(unsigned int); - if (newm == PolyModePrecise || newm == PolyModeImprecise) - pPicture->polyMode = newm; - else - { - client->errorValue = newm; - error = BadValue; - } - } - break; - case CPDither: - pPicture->dither = NEXT_VAL(Atom); - break; - case CPComponentAlpha: - { - unsigned int newca; - - newca = NEXT_VAL (unsigned int); - if (newca <= xTrue) - pPicture->componentAlpha = newca; - else - { - client->errorValue = newca; - error = BadValue; - } - } - break; - default: - client->errorValue = maskQ; - error = BadValue; - break; - } - } - if (ps) - (*ps->ChangePicture) (pPicture, maskQ); - return error; -} - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - RegionPtr clientClip; - int result; - - clientClip = RECTS_TO_REGION(pScreen, - nRect, rects, CT_UNSORTED); - if (!clientClip) - return BadAlloc; - result =(*ps->ChangePictureClip) (pPicture, CT_REGION, - (pointer) clientClip, 0); - if (result == Success) - { - pPicture->clipOrigin.x = xOrigin; - pPicture->clipOrigin.y = yOrigin; - pPicture->stateChanges |= CPClipXOrigin|CPClipYOrigin|CPClipMask; - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - } - return result; -} - -int -SetPictureClipRegion (PicturePtr pPicture, - int xOrigin, - int yOrigin, - RegionPtr pRegion) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - RegionPtr clientClip; - int result; - int type; - - if (pRegion) - { - type = CT_REGION; - clientClip = REGION_CREATE (pScreen, - REGION_EXTENTS(pScreen, pRegion), - REGION_NUM_RECTS(pRegion)); - if (!clientClip) - return BadAlloc; - if (!REGION_COPY (pSCreen, clientClip, pRegion)) - { - REGION_DESTROY (pScreen, clientClip); - return BadAlloc; - } - } - else - { - type = CT_NONE; - clientClip = 0; - } - - result =(*ps->ChangePictureClip) (pPicture, type, - (pointer) clientClip, 0); - if (result == Success) - { - pPicture->clipOrigin.x = xOrigin; - pPicture->clipOrigin.y = yOrigin; - pPicture->stateChanges |= CPClipXOrigin|CPClipYOrigin|CPClipMask; - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - } - return result; -} - - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform) -{ - static const PictTransform identity = { { - { xFixed1, 0x00000, 0x00000 }, - { 0x00000, xFixed1, 0x00000 }, - { 0x00000, 0x00000, xFixed1 }, - } }; - - if (transform && memcmp (transform, &identity, sizeof (PictTransform)) == 0) - transform = 0; - - if (transform) - { - if (!pPicture->transform) - { - pPicture->transform = (PictTransform *) xalloc (sizeof (PictTransform)); - if (!pPicture->transform) - return BadAlloc; - } - *pPicture->transform = *transform; - } - else - { - if (pPicture->transform) - { - xfree (pPicture->transform); - pPicture->transform = 0; - } - } - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - - return Success; -} - -void -CopyPicture (PicturePtr pSrc, - Mask mask, - PicturePtr pDst) -{ - PictureScreenPtr ps = GetPictureScreen(pSrc->pDrawable->pScreen); - Mask origMask = mask; - - pDst->serialNumber |= GC_CHANGE_SERIAL_BIT; - pDst->stateChanges |= mask; - - while (mask) { - Mask bit = lowbit(mask); - - switch (bit) - { - case CPRepeat: - pDst->repeat = pSrc->repeat; - pDst->repeatType = pSrc->repeatType; - break; - case CPAlphaMap: - if (pSrc->alphaMap && pSrc->alphaMap->pDrawable->type == DRAWABLE_PIXMAP) - pSrc->alphaMap->refcnt++; - if (pDst->alphaMap) - FreePicture ((pointer) pDst->alphaMap, (XID) 0); - pDst->alphaMap = pSrc->alphaMap; - break; - case CPAlphaXOrigin: - pDst->alphaOrigin.x = pSrc->alphaOrigin.x; - break; - case CPAlphaYOrigin: - pDst->alphaOrigin.y = pSrc->alphaOrigin.y; - break; - case CPClipXOrigin: - pDst->clipOrigin.x = pSrc->clipOrigin.x; - break; - case CPClipYOrigin: - pDst->clipOrigin.y = pSrc->clipOrigin.y; - break; - case CPClipMask: - switch (pSrc->clientClipType) { - case CT_NONE: - (*ps->ChangePictureClip)(pDst, CT_NONE, NULL, 0); - break; - case CT_REGION: - if (!pSrc->clientClip) { - (*ps->ChangePictureClip)(pDst, CT_NONE, NULL, 0); - } else { - RegionPtr clientClip; - RegionPtr srcClientClip = (RegionPtr)pSrc->clientClip; - - clientClip = REGION_CREATE(pSrc->pDrawable->pScreen, - REGION_EXTENTS(pSrc->pDrawable->pScreen, srcClientClip), - REGION_NUM_RECTS(srcClientClip)); - (*ps->ChangePictureClip)(pDst, CT_REGION, clientClip, 0); - } - break; - default: - /* XXX: CT_PIXMAP unimplemented */ - break; - } - break; - case CPGraphicsExposure: - pDst->graphicsExposures = pSrc->graphicsExposures; - break; - case CPPolyEdge: - pDst->polyEdge = pSrc->polyEdge; - break; - case CPPolyMode: - pDst->polyMode = pSrc->polyMode; - break; - case CPDither: - pDst->dither = pSrc->dither; - break; - case CPComponentAlpha: - pDst->componentAlpha = pSrc->componentAlpha; - break; - } - mask &= ~bit; - } - - (*ps->ChangePicture)(pDst, origMask); -} - -static void -ValidateOnePicture (PicturePtr pPicture) -{ - if (pPicture->pDrawable && pPicture->serialNumber != pPicture->pDrawable->serialNumber) - { - PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen); - - (*ps->ValidatePicture) (pPicture, pPicture->stateChanges); - pPicture->stateChanges = 0; - pPicture->serialNumber = pPicture->pDrawable->serialNumber; - } -} - -void -ValidatePicture(PicturePtr pPicture) -{ - ValidateOnePicture (pPicture); - if (pPicture->alphaMap) - ValidateOnePicture (pPicture->alphaMap); -} - -int -FreePicture (pointer value, - XID pid) -{ - PicturePtr pPicture = (PicturePtr) value; - - if (--pPicture->refcnt == 0) - { -#ifdef NXAGENT_SERVER - nxagentDestroyPicture(pPicture); -#endif - - if (pPicture->transform) - xfree (pPicture->transform); - if (!pPicture->pDrawable) { - if (pPicture->pSourcePict) { - if (pPicture->pSourcePict->type != SourcePictTypeSolidFill) - xfree(pPicture->pSourcePict->linear.stops); - xfree(pPicture->pSourcePict); - } - } else { - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - (*ps->DestroyPicture) (pPicture); - (*ps->DestroyPictureClip) (pPicture); - if (pPicture->pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pPicture->pDrawable; - PicturePtr *pPrev; - - for (pPrev = (PicturePtr *) &((pWindow)->devPrivates[PictureWindowPrivateIndex].ptr); - *pPrev; - pPrev = &(*pPrev)->pNext) - { - if (*pPrev == pPicture) - { - *pPrev = pPicture->pNext; - break; - } - } - } - else if (pPicture->pDrawable->type == DRAWABLE_PIXMAP) - { - (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable); - } - } - xfree (pPicture); - } - return Success; -} - -int -FreePictFormat (pointer pPictFormat, - XID pid) -{ - return Success; -} - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - if (pMask) - ValidatePicture (pMask); - ValidatePicture (pDst); - (*ps->Composite) (op, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height); -} - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - - #ifdef TEST - fprintf(stderr, "CompositeGlyphs: Going to composite glyphs with " - "source at [%p] and destination at [%p].\n", - (void *) pSrc, (void *) pDst); - #endif - - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, lists, glyphs); -} - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pDst); - (*ps->CompositeRects) (op, pDst, color, nRect, rects); -} - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Trapezoids) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps); -} - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntriangles, triangles); -} - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriStrip) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriFan) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -void -AddTraps (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntrap, - xTrap *traps) -{ - PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen); - - ValidatePicture (pPicture); - (*ps->AddTraps) (pPicture, xOff, yOff, ntrap, traps); -} - -#define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff) -#define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31)) - -Bool -PictureTransformPoint3d (PictTransformPtr transform, - PictVectorPtr vector) -{ - PictVector result; - int i, j; - xFixed_32_32 partial; - xFixed_48_16 v; - - for (j = 0; j < 3; j++) - { - v = 0; - for (i = 0; i < 3; i++) - { - partial = ((xFixed_48_16) transform->matrix[j][i] * - (xFixed_48_16) vector->vector[i]); - v += partial >> 16; - } - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - result.vector[j] = (xFixed) v; - } - if (!result.vector[2]) - return FALSE; - *vector = result; - return TRUE; -} - - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector) -{ - PictVector result; - int i, j; - xFixed_32_32 partial; - xFixed_48_16 v; - - for (j = 0; j < 3; j++) - { - v = 0; - for (i = 0; i < 3; i++) - { - partial = ((xFixed_48_16) transform->matrix[j][i] * - (xFixed_48_16) vector->vector[i]); - v += partial >> 16; - } - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - result.vector[j] = (xFixed) v; - } - if (!result.vector[2]) - return FALSE; - for (j = 0; j < 2; j++) - { - partial = (xFixed_48_16) result.vector[j] << 16; - v = partial / result.vector[2]; - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - vector->vector[j] = (xFixed) v; - } - vector->vector[2] = xFixed1; - return TRUE; -} - -#ifndef True -# define True 1 -#endif - -#ifndef False -# define False 0 -#endif - -void nxagentReconnectPictFormat(void*, XID, void*); - -Bool nxagentReconnectAllPictFormat(void *p) -{ - PictFormatPtr formats_old, formats; - int nformats, nformats_old; - VisualPtr pVisual; - Bool success = True; - Bool matched; - int i, n; - CARD32 type, a, r, g, b; - - #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_PICTFORMAT_DEBUG) - fprintf(stderr, "nxagentReconnectAllPictFormat\n"); - #endif - - formats_old = GetPictureScreen(nxagentDefaultScreen) -> formats; - nformats_old = GetPictureScreen(nxagentDefaultScreen) -> nformats; - - /* - * TODO: We could copy PictureCreateDefaultFormats, - * in order not to waste ID with FakeClientID(). - */ - formats = PictureCreateDefaultFormats (nxagentDefaultScreen, &nformats); - - if (!formats) - return False; - - for (n = 0; n < nformats; n++) - { - if (formats[n].type == PictTypeIndexed) - { - pVisual = nxagentVisualFromID(nxagentDefaultScreen, formats[n].index.vid); - - if ((pVisual->class | DynamicClass) == PseudoColor) - type = PICT_TYPE_COLOR; - else - type = PICT_TYPE_GRAY; - a = r = g = b = 0; - } - else - { - if ((formats[n].direct.redMask| - formats[n].direct.blueMask| - formats[n].direct.greenMask) == 0) - type = PICT_TYPE_A; - else if (formats[n].direct.red > formats[n].direct.blue) - type = PICT_TYPE_ARGB; - else - type = PICT_TYPE_ABGR; - a = Ones (formats[n].direct.alphaMask); - r = Ones (formats[n].direct.redMask); - g = Ones (formats[n].direct.greenMask); - b = Ones (formats[n].direct.blueMask); - } - formats[n].format = PICT_FORMAT(0,type,a,r,g,b); - } - - for (n = 0; n < nformats_old; n++) - { - for (i = 0, matched = False; (!matched) && (i < nformats); i++) - { - if (formats_old[n].format == formats[i].format && - formats_old[n].type == formats[i].type && - formats_old[n].direct.red == formats[i].direct.red && - formats_old[n].direct.green == formats[i].direct.green && - formats_old[n].direct.blue == formats[i].direct.blue && - formats_old[n].direct.redMask == formats[i].direct.redMask && - formats_old[n].direct.greenMask == formats[i].direct.greenMask && - formats_old[n].direct.blueMask == formats[i].direct.blueMask && - formats_old[n].direct.alpha == formats[i].direct.alpha && - formats_old[n].direct.alphaMask == formats[i].direct.alphaMask) - { - /* - * Regard depth 16 and 15 as were the same, if all other values match. - */ - - if ((formats_old[n].depth == formats[i].depth) || - ((formats_old[n].depth == 15 || formats_old[n].depth == 16) && - (formats[i].depth == 15 || formats[i].depth == 16))) - { - matched = True; - } - } - } - - if (!matched) - { - return False; - } - } - - xfree(formats); - - /* TODO: Perhaps do i have to do PictureFinishInit ?. */ - /* TODO: We have to check for new Render protocol version. */ - - for (i = 0; (i < MAXCLIENTS) && (success); i++) - { - if (clients[i]) - { - FindClientResourcesByType(clients[i], PictFormatType, nxagentReconnectPictFormat, &success); - } - } - - return success; -} - -/* - * It seem we don't have nothing - * to do for reconnect PictureFormat. - */ - -void nxagentReconnectPictFormat(void *p0, XID x1, void *p2) -{ - PictFormatPtr pFormat; - Bool *pBool; - - pFormat = (PictFormatPtr)p0; - pBool = (Bool*)p2; - - #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_PICTFORMAT_DEBUG) - fprintf(stderr, "nxagentReconnectPictFormat.\n"); - #endif -} - -/* - * The set of picture formats may change considerably - * between different X servers. This poses a problem - * while migrating NX sessions, because a requisite to - * successfully reconnect the session is that all pic- - * ture formats have to be available on the new X server. - * To reduce such problems, we use a limited set of - * pictures available on the most X servers. - */ - -void nxagentPictureCreateDefaultFormats(ScreenPtr pScreen, FormatInitRec *formats, int *nformats) -{ - DepthPtr pDepth; - VisualPtr pVisual; - - CARD32 format; - CARD8 depth; - - int r, g, b; - int bpp; - int d; - int v; - - - formats[*nformats].format = PICT_a1; - formats[*nformats].depth = 1; - *nformats += 1; - formats[*nformats].format = PICT_a4; - formats[*nformats].depth = 4; - *nformats += 1; - formats[*nformats].format = PICT_a8; - formats[*nformats].depth = 8; - *nformats += 1; - formats[*nformats].format = PICT_a8r8g8b8; - formats[*nformats].depth = 32; - *nformats += 1; - - /* - * This format should be required by the - * protocol, but it's not used by Xgl. - * - * formats[*nformats].format = PICT_x8r8g8b8; - * formats[*nformats].depth = 32; - * *nformats += 1; - */ - - /* now look through the depths and visuals adding other formats */ - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = &pScreen->visuals[v]; - depth = visualDepth (pScreen, pVisual); - if (!depth) - continue; - - bpp = BitsPerPixel (depth); - - switch (pVisual->class) - { - case DirectColor: - case TrueColor: - r = Ones (pVisual->redMask); - g = Ones (pVisual->greenMask); - b = Ones (pVisual->blueMask); - - if (pVisual->offsetBlue == 0 && - pVisual->offsetGreen == b && - pVisual->offsetRed == b + g) - { - format = PICT_FORMAT(bpp, PICT_TYPE_ARGB, 0, r, g, b); - *nformats = addFormat (formats, *nformats, format, depth); - } - break; - case StaticColor: - case PseudoColor: - case StaticGray: - case GrayScale: - break; - } - } - - for (d = 0; d < pScreen -> numDepths; d++) - { - pDepth = &pScreen -> allowedDepths[d]; - bpp = BitsPerPixel(pDepth -> depth); - - switch (bpp) { - case 16: - if (pDepth->depth == 15) - { - *nformats = addFormat (formats, *nformats, - PICT_x1r5g5b5, pDepth->depth); - } - - if (pDepth->depth == 16) - { - *nformats = addFormat (formats, *nformats, - PICT_r5g6b5, pDepth->depth); - } - break; - case 24: - if (pDepth->depth == 24) - { - *nformats = addFormat (formats, *nformats, - PICT_r8g8b8, pDepth->depth); - } - break; - case 32: - if (pDepth->depth == 24) - { - *nformats = addFormat (formats, *nformats, - PICT_x8r8g8b8, pDepth->depth); - } - break; - } - } -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.X.original deleted file mode 100644 index 3ed60310e..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicture.c.X.original +++ /dev/null @@ -1,1864 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/render/picture.c,v 1.29 2002/11/23 02:38:15 keithp Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "picturestr.h" - -int PictureScreenPrivateIndex = -1; -int PictureWindowPrivateIndex; -int PictureGeneration; -RESTYPE PictureType; -RESTYPE PictFormatType; -RESTYPE GlyphSetType; -int PictureCmapPolicy = PictureCmapPolicyDefault; - -/* Picture Private machinery */ - -static int picturePrivateCount; - -void -ResetPicturePrivateIndex (void) -{ - picturePrivateCount = 0; -} - -int -AllocatePicturePrivateIndex (void) -{ - return picturePrivateCount++; -} - -Bool -AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - unsigned int oldamount; - - /* Round up sizes for proper alignment */ - amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long); - - if (index2 >= ps->PicturePrivateLen) - { - unsigned int *nsizes; - - nsizes = (unsigned int *)xrealloc(ps->PicturePrivateSizes, - (index2 + 1) * sizeof(unsigned int)); - if (!nsizes) - return FALSE; - while (ps->PicturePrivateLen <= index2) - { - nsizes[ps->PicturePrivateLen++] = 0; - ps->totalPictureSize += sizeof(DevUnion); - } - ps->PicturePrivateSizes = nsizes; - } - oldamount = ps->PicturePrivateSizes[index2]; - if (amount > oldamount) - { - ps->PicturePrivateSizes[index2] = amount; - ps->totalPictureSize += (amount - oldamount); - } - - return TRUE; -} - - -Bool -PictureDestroyWindow (WindowPtr pWindow) -{ - ScreenPtr pScreen = pWindow->drawable.pScreen; - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - - while ((pPicture = GetPictureWindow(pWindow))) - { - SetPictureWindow(pWindow, pPicture->pNext); - if (pPicture->id) - FreeResource (pPicture->id, PictureType); - FreePicture ((pointer) pPicture, pPicture->id); - } - pScreen->DestroyWindow = ps->DestroyWindow; - ret = (*pScreen->DestroyWindow) (pWindow); - ps->DestroyWindow = pScreen->DestroyWindow; - pScreen->DestroyWindow = PictureDestroyWindow; - return ret; -} - -Bool -PictureCloseScreen (int index, ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - Bool ret; - int n; - - pScreen->CloseScreen = ps->CloseScreen; - ret = (*pScreen->CloseScreen) (index, pScreen); - PictureResetFilters (pScreen); - for (n = 0; n < ps->nformats; n++) - if (ps->formats[n].type == PictTypeIndexed) - (*ps->CloseIndexed) (pScreen, &ps->formats[n]); - SetPictureScreen(pScreen, 0); - if (ps->PicturePrivateSizes) - xfree (ps->PicturePrivateSizes); - xfree (ps->formats); - xfree (ps); - return ret; -} - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef) -{ - ScreenPtr pScreen = pColormap->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - pScreen->StoreColors = ps->StoreColors; - (*pScreen->StoreColors) (pColormap, ndef, pdef); - ps->StoreColors = pScreen->StoreColors; - pScreen->StoreColors = PictureStoreColors; - - if (pColormap->class == PseudoColor || pColormap->class == GrayScale) - { - PictFormatPtr format = ps->formats; - int nformats = ps->nformats; - - while (nformats--) - { - if (format->type == PictTypeIndexed && - format->index.pColormap == pColormap) - { - (*ps->UpdateIndexed) (pScreen, format, ndef, pdef); - break; - } - format++; - } - } -} - -static int -visualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - int d, v; - DepthPtr pDepth; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - for (v = 0; v < pDepth->numVids; v++) - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - return 0; -} - -typedef struct _formatInit { - CARD32 format; - CARD8 depth; -} FormatInitRec, *FormatInitPtr; - -static int -addFormat (FormatInitRec formats[256], - int nformat, - CARD32 format, - CARD8 depth) -{ - int n; - - for (n = 0; n < nformat; n++) - if (formats[n].format == format && formats[n].depth == depth) - return nformat; - formats[nformat].format = format; - formats[nformat].depth = depth; - return ++nformat; -} - -#define Mask(n) ((n) == 32 ? 0xffffffff : ((1 << (n))-1)) - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp) -{ - int nformats, f; - PictFormatPtr pFormats; - FormatInitRec formats[1024]; - CARD32 format; - CARD8 depth; - VisualPtr pVisual; - int v; - int bpp; - int type; - int r, g, b; - int d; - DepthPtr pDepth; - - nformats = 0; - /* formats required by protocol */ - formats[nformats].format = PICT_a1; - formats[nformats].depth = 1; - nformats++; - formats[nformats].format = PICT_a8; - formats[nformats].depth = 8; - nformats++; - formats[nformats].format = PICT_a4; - formats[nformats].depth = 4; - nformats++; - formats[nformats].format = PICT_a8r8g8b8; - formats[nformats].depth = 32; - nformats++; - formats[nformats].format = PICT_x8r8g8b8; - formats[nformats].depth = 32; - nformats++; - - /* now look through the depths and visuals adding other formats */ - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = &pScreen->visuals[v]; - depth = visualDepth (pScreen, pVisual); - if (!depth) - continue; - bpp = BitsPerPixel (depth); - switch (pVisual->class) { - case DirectColor: - case TrueColor: - r = Ones (pVisual->redMask); - g = Ones (pVisual->greenMask); - b = Ones (pVisual->blueMask); - type = PICT_TYPE_OTHER; - /* - * Current rendering code supports only two direct formats, - * fields must be packed together at the bottom of the pixel - * and must be either RGB or BGR - */ - if (pVisual->offsetBlue == 0 && - pVisual->offsetGreen == b && - pVisual->offsetRed == b + g) - { - type = PICT_TYPE_ARGB; - } - else if (pVisual->offsetRed == 0 && - pVisual->offsetGreen == r && - pVisual->offsetBlue == r + g) - { - type = PICT_TYPE_ABGR; - } - if (type != PICT_TYPE_OTHER) - { - format = PICT_FORMAT(bpp, type, 0, r, g, b); - nformats = addFormat (formats, nformats, format, depth); - } - break; - case StaticColor: - case PseudoColor: - format = PICT_VISFORMAT (bpp, PICT_TYPE_COLOR, v); - nformats = addFormat (formats, nformats, format, depth); - break; - case StaticGray: - case GrayScale: - format = PICT_VISFORMAT (bpp, PICT_TYPE_GRAY, v); - nformats = addFormat (formats, nformats, format, depth); - break; - } - } - /* - * Walk supported depths and add useful Direct formats - */ - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = &pScreen->allowedDepths[d]; - bpp = BitsPerPixel (pDepth->depth); - format = 0; - switch (bpp) { - case 16: - /* depth 12 formats */ - if (pDepth->depth >= 12) - { - nformats = addFormat (formats, nformats, - PICT_x4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x4b4g4r4, pDepth->depth); - } - /* depth 15 formats */ - if (pDepth->depth >= 15) - { - nformats = addFormat (formats, nformats, - PICT_x1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x1b5g5r5, pDepth->depth); - } - /* depth 16 formats */ - if (pDepth->depth >= 16) - { - nformats = addFormat (formats, nformats, - PICT_a1r5g5b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a1b5g5r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_r5g6b5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b5g6r5, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4r4g4b4, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_a4b4g4r4, pDepth->depth); - } - break; - case 24: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_b8g8r8, pDepth->depth); - } - break; - case 32: - if (pDepth->depth >= 24) - { - nformats = addFormat (formats, nformats, - PICT_x8r8g8b8, pDepth->depth); - nformats = addFormat (formats, nformats, - PICT_x8b8g8r8, pDepth->depth); - } - break; - } - } - - - pFormats = (PictFormatPtr) xalloc (nformats * sizeof (PictFormatRec)); - if (!pFormats) - return 0; - memset (pFormats, '\0', nformats * sizeof (PictFormatRec)); - for (f = 0; f < nformats; f++) - { - pFormats[f].id = FakeClientID (0); - pFormats[f].depth = formats[f].depth; - format = formats[f].format; - pFormats[f].format = format; - switch (PICT_FORMAT_TYPE(format)) { - case PICT_TYPE_ARGB: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_R(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = (PICT_FORMAT_G(format) + - PICT_FORMAT_B(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_B(format); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = 0; - break; - - case PICT_TYPE_ABGR: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - if (pFormats[f].direct.alphaMask) - pFormats[f].direct.alpha = (PICT_FORMAT_B(format) + - PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format)); - pFormats[f].direct.blue = (PICT_FORMAT_G(format) + - PICT_FORMAT_R(format)); - - pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format)); - pFormats[f].direct.green = PICT_FORMAT_R(format); - - pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format)); - pFormats[f].direct.red = 0; - break; - - case PICT_TYPE_A: - pFormats[f].type = PictTypeDirect; - - pFormats[f].direct.alpha = 0; - pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format)); - - /* remaining fields already set to zero */ - break; - - case PICT_TYPE_COLOR: - case PICT_TYPE_GRAY: - pFormats[f].type = PictTypeIndexed; - pFormats[f].index.vid = pScreen->visuals[PICT_FORMAT_VIS(format)].vid; - break; - } - } - *nformatp = nformats; - return pFormats; -} - -static VisualPtr -PictureFindVisual (ScreenPtr pScreen, VisualID visual) -{ - int i; - VisualPtr pVisual; - for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid == visual) - return pVisual; - } - return 0; -} - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return FALSE; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->type == PictTypeIndexed && !format->index.pColormap) - { - if (format->index.vid == pScreen->rootVisual) - format->index.pColormap = (ColormapPtr) LookupIDByType(pScreen->defColormap, - RT_COLORMAP); - else - { - VisualPtr pVisual; - - pVisual = PictureFindVisual (pScreen, format->index.vid); - if (CreateColormap (FakeClientID (0), pScreen, - pVisual, - &format->index.pColormap, AllocNone, - 0) != Success) - { - return FALSE; - } - } - if (!(*ps->InitIndexed) (pScreen, format)) - return FALSE; - } - format++; - } - return TRUE; -} - -Bool -PictureFinishInit (void) -{ - int s; - - for (s = 0; s < screenInfo.numScreens; s++) - { - if (!PictureInitIndexedFormats (screenInfo.screens[s])) - return FALSE; - (void) AnimCurInit (screenInfo.screens[s]); - } - - return TRUE; -} - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return FALSE; - ps->subpixel = subpixel; - return TRUE; - -} - -int -PictureGetSubpixelOrder (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - if (!ps) - return SubPixelUnknown; - return ps->subpixel; -} - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - int type; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - switch (pVisual->class) { - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - type = PictTypeIndexed; - break; - case TrueColor: - case DirectColor: - type = PictTypeDirect; - break; - default: - return 0; - } - while (nformat--) - { - if (format->depth == depth && format->type == type) - { - if (type == PictTypeIndexed) - { - if (format->index.vid == pVisual->vid) - return format; - } - else - { - if (format->direct.redMask << format->direct.red == - pVisual->redMask && - format->direct.greenMask << format->direct.green == - pVisual->greenMask && - format->direct.blueMask << format->direct.blue == - pVisual->blueMask) - { - return format; - } - } - } - format++; - } - return 0; -} - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 f) -{ - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - PictFormatPtr format; - int nformat; - - if (!ps) - return 0; - format = ps->formats; - nformat = ps->nformats; - while (nformat--) - { - if (format->depth == depth && format->format == (f & 0xffffff)) - return format; - format++; - } - return 0; -} - -int -PictureParseCmapPolicy (const char *name) -{ - if ( strcmp (name, "default" ) == 0) - return PictureCmapPolicyDefault; - else if ( strcmp (name, "mono" ) == 0) - return PictureCmapPolicyMono; - else if ( strcmp (name, "gray" ) == 0) - return PictureCmapPolicyGray; - else if ( strcmp (name, "color" ) == 0) - return PictureCmapPolicyColor; - else if ( strcmp (name, "all" ) == 0) - return PictureCmapPolicyAll; - else - return PictureCmapPolicyInvalid; -} - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats) -{ - PictureScreenPtr ps; - int n; - CARD32 type, a, r, g, b; - - if (PictureGeneration != serverGeneration) - { - PictureType = CreateNewResourceType (FreePicture); - if (!PictureType) - return FALSE; - PictFormatType = CreateNewResourceType (FreePictFormat); - if (!PictFormatType) - return FALSE; - GlyphSetType = CreateNewResourceType (FreeGlyphSet); - if (!GlyphSetType) - return FALSE; - PictureScreenPrivateIndex = AllocateScreenPrivateIndex(); - if (PictureScreenPrivateIndex < 0) - return FALSE; - PictureWindowPrivateIndex = AllocateWindowPrivateIndex(); - PictureGeneration = serverGeneration; -#ifdef XResExtension - RegisterResourceName (PictureType, "PICTURE"); - RegisterResourceName (PictFormatType, "PICTFORMAT"); - RegisterResourceName (GlyphSetType, "GLYPHSET"); -#endif - } - if (!AllocateWindowPrivate (pScreen, PictureWindowPrivateIndex, 0)) - return FALSE; - - if (!formats) - { - formats = PictureCreateDefaultFormats (pScreen, &nformats); - if (!formats) - return FALSE; - } - for (n = 0; n < nformats; n++) - { - if (!AddResource (formats[n].id, PictFormatType, (pointer) (formats+n))) - { - xfree (formats); - return FALSE; - } - if (formats[n].type == PictTypeIndexed) - { - VisualPtr pVisual = PictureFindVisual (pScreen, formats[n].index.vid); - if ((pVisual->class | DynamicClass) == PseudoColor) - type = PICT_TYPE_COLOR; - else - type = PICT_TYPE_GRAY; - a = r = g = b = 0; - } - else - { - if ((formats[n].direct.redMask| - formats[n].direct.blueMask| - formats[n].direct.greenMask) == 0) - type = PICT_TYPE_A; - else if (formats[n].direct.red > formats[n].direct.blue) - type = PICT_TYPE_ARGB; - else - type = PICT_TYPE_ABGR; - a = Ones (formats[n].direct.alphaMask); - r = Ones (formats[n].direct.redMask); - g = Ones (formats[n].direct.greenMask); - b = Ones (formats[n].direct.blueMask); - } - formats[n].format = PICT_FORMAT(0,type,a,r,g,b); - } - ps = (PictureScreenPtr) xalloc (sizeof (PictureScreenRec)); - if (!ps) - { - xfree (formats); - return FALSE; - } - SetPictureScreen(pScreen, ps); - if (!GlyphInit (pScreen)) - { - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - ps->totalPictureSize = sizeof (PictureRec); - ps->PicturePrivateSizes = 0; - ps->PicturePrivateLen = 0; - - ps->formats = formats; - ps->fallback = formats; - ps->nformats = nformats; - - ps->filters = 0; - ps->nfilters = 0; - ps->filterAliases = 0; - ps->nfilterAliases = 0; - - ps->subpixel = SubPixelUnknown; - - ps->CloseScreen = pScreen->CloseScreen; - ps->DestroyWindow = pScreen->DestroyWindow; - ps->StoreColors = pScreen->StoreColors; - pScreen->DestroyWindow = PictureDestroyWindow; - pScreen->CloseScreen = PictureCloseScreen; - pScreen->StoreColors = PictureStoreColors; - - if (!PictureSetDefaultFilters (pScreen)) - { - PictureResetFilters (pScreen); - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - - return TRUE; -} - -void -SetPictureToDefaults (PicturePtr pPicture) -{ - pPicture->refcnt = 1; - pPicture->repeat = 0; - pPicture->graphicsExposures = FALSE; - pPicture->subWindowMode = ClipByChildren; - pPicture->polyEdge = PolyEdgeSharp; - pPicture->polyMode = PolyModePrecise; - pPicture->freeCompClip = FALSE; - pPicture->clientClipType = CT_NONE; - pPicture->componentAlpha = FALSE; - pPicture->repeatType = RepeatNone; - - pPicture->alphaMap = 0; - pPicture->alphaOrigin.x = 0; - pPicture->alphaOrigin.y = 0; - - pPicture->clipOrigin.x = 0; - pPicture->clipOrigin.y = 0; - pPicture->clientClip = 0; - - pPicture->transform = 0; - - pPicture->dither = None; - pPicture->filter = PictureGetFilterId (FilterNearest, -1, TRUE); - pPicture->filter_params = 0; - pPicture->filter_nparams = 0; - - pPicture->serialNumber = GC_CHANGE_SERIAL_BIT; - pPicture->stateChanges = (1 << (CPLastBit+1)) - 1; - pPicture->pSourcePict = 0; -} - -PicturePtr -AllocatePicture (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture; - char *ptr; - DevUnion *ppriv; - unsigned int *sizes; - unsigned int size; - int i; - - pPicture = (PicturePtr) xalloc (ps->totalPictureSize); - if (!pPicture) - return 0; - ppriv = (DevUnion *)(pPicture + 1); - pPicture->devPrivates = ppriv; - sizes = ps->PicturePrivateSizes; - ptr = (char *)(ppriv + ps->PicturePrivateLen); - for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - return pPicture; -} - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask vmask, - XID *vlist, - ClientPtr client, - int *error) -{ - PicturePtr pPicture; - PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen); - - pPicture = AllocatePicture (pDrawable->pScreen); - if (!pPicture) - { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pDrawable = pDrawable; - pPicture->pFormat = pFormat; - pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24); - if (pDrawable->type == DRAWABLE_PIXMAP) - { - ++((PixmapPtr)pDrawable)->refcnt; - pPicture->pNext = 0; - } - else - { - pPicture->pNext = GetPictureWindow(((WindowPtr) pDrawable)); - SetPictureWindow(((WindowPtr) pDrawable), pPicture); - } - - SetPictureToDefaults (pPicture); - - if (vmask) - *error = ChangePicture (pPicture, vmask, vlist, 0, client); - else - *error = Success; - if (*error == Success) - *error = (*ps->CreatePicture) (pPicture); - if (*error != Success) - { - FreePicture (pPicture, (XID) 0); - pPicture = 0; - } - return pPicture; -} - -static CARD32 xRenderColorToCard32(xRenderColor c) -{ - return - (c.alpha >> 8 << 24) | - (c.red >> 8 << 16) | - (c.green & 0xff00) | - (c.blue >> 8); -} - -static unsigned int premultiply(unsigned int x) -{ - unsigned int a = x >> 24; - unsigned int t = (x & 0xff00ff) * a; - t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; - t &= 0xff00ff; - - x = ((x >> 8) & 0xff) * a; - x = (x + ((x >> 8) & 0xff) + 0x80); - x &= 0xff00; - x |= t | (a << 24); - return x; -} - -static unsigned int INTERPOLATE_PIXEL_256(unsigned int x, unsigned int a, - unsigned int y, unsigned int b) -{ - CARD32 t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; - t >>= 8; - t &= 0xff00ff; - - x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b; - x &= 0xff00ff00; - x |= t; - return x; -} - -static void initGradientColorTable(SourcePictPtr pGradient, int *error) -{ - int begin_pos, end_pos; - xFixed incr, dpos; - int pos, current_stop; - PictGradientStopPtr stops = pGradient->linear.stops; - int nstops = pGradient->linear.nstops; - - /* The position where the gradient begins and ends */ - begin_pos = (stops[0].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16; - end_pos = (stops[nstops - 1].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16; - - pos = 0; /* The position in the color table. */ - - /* Up to first point */ - while (pos <= begin_pos) { - pGradient->linear.colorTable[pos] = xRenderColorToCard32(stops[0].color); - ++pos; - } - - incr = (1<<16)/ PICT_GRADIENT_STOPTABLE_SIZE; /* the double increment. */ - dpos = incr * pos; /* The position in terms of 0-1. */ - - current_stop = 0; /* We always interpolate between current and current + 1. */ - - /* Gradient area */ - while (pos < end_pos) { - unsigned int current_color = xRenderColorToCard32(stops[current_stop].color); - unsigned int next_color = xRenderColorToCard32(stops[current_stop + 1].color); - - int dist = (int)(256*(dpos - stops[current_stop].x) - / (stops[current_stop+1].x - stops[current_stop].x)); - int idist = 256 - dist; - - pGradient->linear.colorTable[pos] = premultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)); - - ++pos; - dpos += incr; - - if (dpos > stops[current_stop + 1].x) - ++current_stop; - } - - /* After last point */ - while (pos < PICT_GRADIENT_STOPTABLE_SIZE) { - pGradient->linear.colorTable[pos] = xRenderColorToCard32(stops[nstops - 1].color); - ++pos; - } -} - -static void initGradient(SourcePictPtr pGradient, int stopCount, - xFixed *stopPoints, xRenderColor *stopColors, int *error) -{ - int i; - xFixed dpos; - - if (stopCount <= 0) { - *error = BadValue; - return; - } - - dpos = -1; - for (i = 0; i < stopCount; ++i) { - if (stopPoints[i] <= dpos || stopPoints[i] > (1<<16)) { - *error = BadValue; - return; - } - dpos = stopPoints[i]; - } - - pGradient->linear.stops = xalloc(stopCount*sizeof(PictGradientStop)); - if (!pGradient->linear.stops) { - *error = BadAlloc; - return; - } - - pGradient->linear.nstops = stopCount; - - for (i = 0; i < stopCount; ++i) { - pGradient->linear.stops[i].x = stopPoints[i]; - pGradient->linear.stops[i].color = stopColors[i]; - } - initGradientColorTable(pGradient, error); -} - -static PicturePtr createSourcePicture(void) -{ - PicturePtr pPicture; - pPicture = (PicturePtr) xalloc(sizeof(PictureRec)); - pPicture->pDrawable = 0; - pPicture->pFormat = 0; - pPicture->pNext = 0; - - SetPictureToDefaults(pPicture); - return pPicture; -} - -PicturePtr -CreateSolidPicture (Picture pid, xRenderColor *color, int *error) -{ - PicturePtr pPicture; - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictSolidFill)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - pPicture->pSourcePict->type = SourcePictTypeSolidFill; - pPicture->pSourcePict->solidFill.color = xRenderColorToCard32(*color); - return pPicture; -} - -PicturePtr -CreateLinearGradientPicture (Picture pid, xPointFixed *p1, xPointFixed *p2, - int nStops, xFixed *stops, xRenderColor *colors, int *error) -{ - PicturePtr pPicture; - - if (nStops < 2) { - *error = BadValue; - return 0; - } - - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - if (p1->x == p2->x && p1->y == p2->y) { - *error = BadValue; - return 0; - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictLinearGradient)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - - pPicture->pSourcePict->linear.type = SourcePictTypeLinear; - pPicture->pSourcePict->linear.p1 = *p1; - pPicture->pSourcePict->linear.p2 = *p2; - - initGradient(pPicture->pSourcePict, nStops, stops, colors, error); - if (*error) { - xfree(pPicture); - return 0; - } - return pPicture; -} - -#define FixedToDouble(x) ((x)/65536.) - -PicturePtr -CreateRadialGradientPicture (Picture pid, xPointFixed *inner, xPointFixed *outer, - xFixed innerRadius, xFixed outerRadius, - int nStops, xFixed *stops, xRenderColor *colors, int *error) -{ - PicturePtr pPicture; - PictRadialGradient *radial; - - if (nStops < 2) { - *error = BadValue; - return 0; - } - - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - { - double dx = (double)(inner->x - outer->x); - double dy = (double)(inner->y - outer->y); - if (sqrt(dx*dx + dy*dy) + (double)(innerRadius) > (double)(outerRadius)) { - *error = BadValue; - return 0; - } - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictRadialGradient)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - radial = &pPicture->pSourcePict->radial; - - radial->type = SourcePictTypeRadial; - { - double x = (double)innerRadius / (double)outerRadius; - radial->dx = (outer->x - inner->x); - radial->dy = (outer->y - inner->y); - radial->fx = (inner->x) - x*radial->dx; - radial->fy = (inner->y) - x*radial->dy; - radial->m = 1./(1+x); - radial->b = -x*radial->m; - radial->dx /= 65536.; - radial->dy /= 65536.; - radial->fx /= 65536.; - radial->fy /= 65536.; - x = outerRadius/65536.; - radial->a = x*x - radial->dx*radial->dx - radial->dy*radial->dy; - } - - initGradient(pPicture->pSourcePict, nStops, stops, colors, error); - if (*error) { - xfree(pPicture); - return 0; - } - return pPicture; -} - -PicturePtr -CreateConicalGradientPicture (Picture pid, xPointFixed *center, xFixed angle, - int nStops, xFixed *stops, xRenderColor *colors, int *error) -{ - PicturePtr pPicture; - - if (nStops < 2) { - *error = BadValue; - return 0; - } - - pPicture = createSourcePicture(); - if (!pPicture) { - *error = BadAlloc; - return 0; - } - - pPicture->id = pid; - pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictConicalGradient)); - if (!pPicture->pSourcePict) { - *error = BadAlloc; - xfree(pPicture); - return 0; - } - - pPicture->pSourcePict->conical.type = SourcePictTypeConical; - pPicture->pSourcePict->conical.center = *center; - pPicture->pSourcePict->conical.angle = angle; - - initGradient(pPicture->pSourcePict, nStops, stops, colors, error); - if (*error) { - xfree(pPicture); - return 0; - } - return pPicture; -} - -#define NEXT_VAL(_type) (vlist ? (_type) *vlist++ : (_type) ulist++->val) - -#define NEXT_PTR(_type) ((_type) ulist++->ptr) - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client) -{ - ScreenPtr pScreen = pPicture->pDrawable ? pPicture->pDrawable->pScreen : 0; - PictureScreenPtr ps = pScreen ? GetPictureScreen(pScreen) : 0; - BITS32 index2; - int error = 0; - BITS32 maskQ; - - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - maskQ = vmask; - while (vmask && !error) - { - index2 = (BITS32) lowbit (vmask); - vmask &= ~index2; - pPicture->stateChanges |= index2; - switch (index2) - { - case CPRepeat: - { - unsigned int newr; - newr = NEXT_VAL(unsigned int); - if (newr <= RepeatReflect) - { - pPicture->repeat = (newr != RepeatNone); - pPicture->repeatType = newr; - } - else - { - client->errorValue = newr; - error = BadValue; - } - } - break; - case CPAlphaMap: - { - PicturePtr pAlpha; - - if (vlist) - { - Picture pid = NEXT_VAL(Picture); - - if (pid == None) - pAlpha = 0; - else - { - pAlpha = (PicturePtr) SecurityLookupIDByType(client, - pid, - PictureType, - SecurityWriteAccess|SecurityReadAccess); - if (!pAlpha) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - if (pAlpha->pDrawable->type != DRAWABLE_PIXMAP) - { - client->errorValue = pid; - error = BadMatch; - break; - } - } - } - else - pAlpha = NEXT_PTR(PicturePtr); - if (!error) - { - if (pAlpha && pAlpha->pDrawable->type == DRAWABLE_PIXMAP) - pAlpha->refcnt++; - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - pPicture->alphaMap = pAlpha; - } - } - break; - case CPAlphaXOrigin: - pPicture->alphaOrigin.x = NEXT_VAL(INT16); - break; - case CPAlphaYOrigin: - pPicture->alphaOrigin.y = NEXT_VAL(INT16); - break; - case CPClipXOrigin: - pPicture->clipOrigin.x = NEXT_VAL(INT16); - break; - case CPClipYOrigin: - pPicture->clipOrigin.y = NEXT_VAL(INT16); - break; - case CPClipMask: - { - Pixmap pid; - PixmapPtr pPixmap; - int clipType; - if (!pScreen) - return BadDrawable; - - if (vlist) - { - pid = NEXT_VAL(Pixmap); - if (pid == None) - { - clipType = CT_NONE; - pPixmap = NullPixmap; - } - else - { - clipType = CT_PIXMAP; - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, - pid, - RT_PIXMAP, - SecurityReadAccess); - if (!pPixmap) - { - client->errorValue = pid; - error = BadPixmap; - break; - } - } - } - else - { - pPixmap = NEXT_PTR(PixmapPtr); - if (pPixmap) - clipType = CT_PIXMAP; - else - clipType = CT_NONE; - } - - if (pPixmap) - { - if ((pPixmap->drawable.depth != 1) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - break; - } - else - { - clipType = CT_PIXMAP; - pPixmap->refcnt++; - } - } - error = (*ps->ChangePictureClip)(pPicture, clipType, - (pointer)pPixmap, 0); - break; - } - case CPGraphicsExposure: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe <= xTrue) - pPicture->graphicsExposures = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPSubwindowMode: - { - unsigned int news; - news = NEXT_VAL(unsigned int); - if (news == ClipByChildren || news == IncludeInferiors) - pPicture->subWindowMode = news; - else - { - client->errorValue = news; - error = BadValue; - } - } - break; - case CPPolyEdge: - { - unsigned int newe; - newe = NEXT_VAL(unsigned int); - if (newe == PolyEdgeSharp || newe == PolyEdgeSmooth) - pPicture->polyEdge = newe; - else - { - client->errorValue = newe; - error = BadValue; - } - } - break; - case CPPolyMode: - { - unsigned int newm; - newm = NEXT_VAL(unsigned int); - if (newm == PolyModePrecise || newm == PolyModeImprecise) - pPicture->polyMode = newm; - else - { - client->errorValue = newm; - error = BadValue; - } - } - break; - case CPDither: - pPicture->dither = NEXT_VAL(Atom); - break; - case CPComponentAlpha: - { - unsigned int newca; - - newca = NEXT_VAL (unsigned int); - if (newca <= xTrue) - pPicture->componentAlpha = newca; - else - { - client->errorValue = newca; - error = BadValue; - } - } - break; - default: - client->errorValue = maskQ; - error = BadValue; - break; - } - } - if (ps) - (*ps->ChangePicture) (pPicture, maskQ); - return error; -} - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - RegionPtr clientClip; - int result; - - clientClip = RECTS_TO_REGION(pScreen, - nRect, rects, CT_UNSORTED); - if (!clientClip) - return BadAlloc; - result =(*ps->ChangePictureClip) (pPicture, CT_REGION, - (pointer) clientClip, 0); - if (result == Success) - { - pPicture->clipOrigin.x = xOrigin; - pPicture->clipOrigin.y = yOrigin; - pPicture->stateChanges |= CPClipXOrigin|CPClipYOrigin|CPClipMask; - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - } - return result; -} - -int -SetPictureClipRegion (PicturePtr pPicture, - int xOrigin, - int yOrigin, - RegionPtr pRegion) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - RegionPtr clientClip; - int result; - int type; - - if (pRegion) - { - type = CT_REGION; - clientClip = REGION_CREATE (pScreen, - REGION_EXTENTS(pScreen, pRegion), - REGION_NUM_RECTS(pRegion)); - if (!clientClip) - return BadAlloc; - if (!REGION_COPY (pSCreen, clientClip, pRegion)) - { - REGION_DESTROY (pScreen, clientClip); - return BadAlloc; - } - } - else - { - type = CT_NONE; - clientClip = 0; - } - - result =(*ps->ChangePictureClip) (pPicture, type, - (pointer) clientClip, 0); - if (result == Success) - { - pPicture->clipOrigin.x = xOrigin; - pPicture->clipOrigin.y = yOrigin; - pPicture->stateChanges |= CPClipXOrigin|CPClipYOrigin|CPClipMask; - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - } - return result; -} - - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform) -{ - static const PictTransform identity = { { - { xFixed1, 0x00000, 0x00000 }, - { 0x00000, xFixed1, 0x00000 }, - { 0x00000, 0x00000, xFixed1 }, - } }; - - if (transform && memcmp (transform, &identity, sizeof (PictTransform)) == 0) - transform = 0; - - if (transform) - { - if (!pPicture->transform) - { - pPicture->transform = (PictTransform *) xalloc (sizeof (PictTransform)); - if (!pPicture->transform) - return BadAlloc; - } - *pPicture->transform = *transform; - } - else - { - if (pPicture->transform) - { - xfree (pPicture->transform); - pPicture->transform = 0; - } - } - pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; - - return Success; -} - -void -CopyPicture (PicturePtr pSrc, - Mask mask, - PicturePtr pDst) -{ - PictureScreenPtr ps = GetPictureScreen(pSrc->pDrawable->pScreen); - Mask origMask = mask; - - pDst->serialNumber |= GC_CHANGE_SERIAL_BIT; - pDst->stateChanges |= mask; - - while (mask) { - Mask bit = lowbit(mask); - - switch (bit) - { - case CPRepeat: - pDst->repeat = pSrc->repeat; - pDst->repeatType = pSrc->repeatType; - break; - case CPAlphaMap: - if (pSrc->alphaMap && pSrc->alphaMap->pDrawable->type == DRAWABLE_PIXMAP) - pSrc->alphaMap->refcnt++; - if (pDst->alphaMap) - FreePicture ((pointer) pDst->alphaMap, (XID) 0); - pDst->alphaMap = pSrc->alphaMap; - break; - case CPAlphaXOrigin: - pDst->alphaOrigin.x = pSrc->alphaOrigin.x; - break; - case CPAlphaYOrigin: - pDst->alphaOrigin.y = pSrc->alphaOrigin.y; - break; - case CPClipXOrigin: - pDst->clipOrigin.x = pSrc->clipOrigin.x; - break; - case CPClipYOrigin: - pDst->clipOrigin.y = pSrc->clipOrigin.y; - break; - case CPClipMask: - switch (pSrc->clientClipType) { - case CT_NONE: - (*ps->ChangePictureClip)(pDst, CT_NONE, NULL, 0); - break; - case CT_REGION: - if (!pSrc->clientClip) { - (*ps->ChangePictureClip)(pDst, CT_NONE, NULL, 0); - } else { - RegionPtr clientClip; - RegionPtr srcClientClip = (RegionPtr)pSrc->clientClip; - - clientClip = REGION_CREATE(pSrc->pDrawable->pScreen, - REGION_EXTENTS(pSrc->pDrawable->pScreen, srcClientClip), - REGION_NUM_RECTS(srcClientClip)); - (*ps->ChangePictureClip)(pDst, CT_REGION, clientClip, 0); - } - break; - default: - /* XXX: CT_PIXMAP unimplemented */ - break; - } - break; - case CPGraphicsExposure: - pDst->graphicsExposures = pSrc->graphicsExposures; - break; - case CPPolyEdge: - pDst->polyEdge = pSrc->polyEdge; - break; - case CPPolyMode: - pDst->polyMode = pSrc->polyMode; - break; - case CPDither: - pDst->dither = pSrc->dither; - break; - case CPComponentAlpha: - pDst->componentAlpha = pSrc->componentAlpha; - break; - } - mask &= ~bit; - } - - (*ps->ChangePicture)(pDst, origMask); -} - -static void -ValidateOnePicture (PicturePtr pPicture) -{ - if (pPicture->pDrawable && pPicture->serialNumber != pPicture->pDrawable->serialNumber) - { - PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen); - - (*ps->ValidatePicture) (pPicture, pPicture->stateChanges); - pPicture->stateChanges = 0; - pPicture->serialNumber = pPicture->pDrawable->serialNumber; - } -} - -void -ValidatePicture(PicturePtr pPicture) -{ - ValidateOnePicture (pPicture); - if (pPicture->alphaMap) - ValidateOnePicture (pPicture->alphaMap); -} - -int -FreePicture (pointer value, - XID pid) -{ - PicturePtr pPicture = (PicturePtr) value; - - if (--pPicture->refcnt == 0) - { - if (pPicture->transform) - xfree (pPicture->transform); - if (!pPicture->pDrawable) { - if (pPicture->pSourcePict) { - if (pPicture->pSourcePict->type != SourcePictTypeSolidFill) - xfree(pPicture->pSourcePict->linear.stops); - xfree(pPicture->pSourcePict); - } - } else { - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - if (pPicture->alphaMap) - FreePicture ((pointer) pPicture->alphaMap, (XID) 0); - (*ps->DestroyPicture) (pPicture); - (*ps->DestroyPictureClip) (pPicture); - if (pPicture->pDrawable->type == DRAWABLE_WINDOW) - { - WindowPtr pWindow = (WindowPtr) pPicture->pDrawable; - PicturePtr *pPrev; - - for (pPrev = (PicturePtr *) &((pWindow)->devPrivates[PictureWindowPrivateIndex].ptr); - *pPrev; - pPrev = &(*pPrev)->pNext) - { - if (*pPrev == pPicture) - { - *pPrev = pPicture->pNext; - break; - } - } - } - else if (pPicture->pDrawable->type == DRAWABLE_PIXMAP) - { - (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable); - } - } - xfree (pPicture); - } - return Success; -} - -int -FreePictFormat (pointer pPictFormat, - XID pid) -{ - return Success; -} - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - if (pMask) - ValidatePicture (pMask); - ValidatePicture (pDst); - (*ps->Composite) (op, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height); -} - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, lists, glyphs); -} - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pDst); - (*ps->CompositeRects) (op, pDst, color, nRect, rects); -} - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Trapezoids) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps); -} - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntriangles, triangles); -} - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriStrip) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points) -{ - PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen); - - ValidatePicture (pSrc); - ValidatePicture (pDst); - (*ps->TriFan) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points); -} - -void -AddTraps (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntrap, - xTrap *traps) -{ - PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen); - - ValidatePicture (pPicture); - (*ps->AddTraps) (pPicture, xOff, yOff, ntrap, traps); -} - -#define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff) -#define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31)) - -Bool -PictureTransformPoint3d (PictTransformPtr transform, - PictVectorPtr vector) -{ - PictVector result; - int i, j; - xFixed_32_32 partial; - xFixed_48_16 v; - - for (j = 0; j < 3; j++) - { - v = 0; - for (i = 0; i < 3; i++) - { - partial = ((xFixed_48_16) transform->matrix[j][i] * - (xFixed_48_16) vector->vector[i]); - v += partial >> 16; - } - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - result.vector[j] = (xFixed) v; - } - if (!result.vector[2]) - return FALSE; - *vector = result; - return TRUE; -} - - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector) -{ - PictVector result; - int i, j; - xFixed_32_32 partial; - xFixed_48_16 v; - - for (j = 0; j < 3; j++) - { - v = 0; - for (i = 0; i < 3; i++) - { - partial = ((xFixed_48_16) transform->matrix[j][i] * - (xFixed_48_16) vector->vector[i]); - v += partial >> 16; - } - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - result.vector[j] = (xFixed) v; - } - if (!result.vector[2]) - return FALSE; - for (j = 0; j < 2; j++) - { - partial = (xFixed_48_16) result.vector[j] << 16; - v = partial / result.vector[2]; - if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) - return FALSE; - vector->vector[j] = (xFixed) v; - } - vector->vector[2] = xFixed1; - return TRUE; -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.NX.original deleted file mode 100644 index 0d1a8e1d8..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.NX.original +++ /dev/null @@ -1,678 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * $Id: picturestr.h,v 1.15 2005/12/09 18:35:21 ajax Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -/* - * This must keep the same symbol as the original - * picturestr.h or symbols will be redefined. We - * should define a new types and cast when appro- - * priate. - */ - -#ifndef _PICTURESTR_H_ -#define _PICTURESTR_H_ - -#include "NXglyphstr.h" -#include "scrnintstr.h" -#include "resource.h" - -typedef struct _DirectFormat { - CARD16 red, redMask; - CARD16 green, greenMask; - CARD16 blue, blueMask; - CARD16 alpha, alphaMask; -} DirectFormatRec; - -typedef struct _IndexFormat { - VisualID vid; - ColormapPtr pColormap; - int nvalues; - xIndexValue *pValues; - void *devPrivate; -} IndexFormatRec; - -typedef struct _PictFormat { - CARD32 id; - CARD32 format; /* except bpp */ - unsigned char type; - unsigned char depth; - DirectFormatRec direct; - IndexFormatRec index; -} PictFormatRec; - -typedef struct _PictVector { - xFixed vector[3]; -} PictVector, *PictVectorPtr; - -typedef struct _PictTransform { - xFixed matrix[3][3]; -} PictTransform, *PictTransformPtr; - -#define PICT_GRADIENT_STOPTABLE_SIZE 1024 -#define SourcePictTypeSolidFill 0 -#define SourcePictTypeLinear 1 -#define SourcePictTypeRadial 2 -#define SourcePictTypeConical 3 - -typedef struct _PictSolidFill { - unsigned int type; - CARD32 color; -} PictSolidFill, *PictSolidFillPtr; - -typedef struct _PictGradientStop { - xFixed x; - xRenderColor color; -} PictGradientStop, *PictGradientStopPtr; - -typedef struct _PictGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; -} PictGradient, *PictGradientPtr; - -typedef struct _PictLinearGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; - xPointFixed p1; - xPointFixed p2; -} PictLinearGradient, *PictLinearGradientPtr; - -typedef struct _PictRadialGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; - double fx; - double fy; - double dx; - double dy; - double a; - double m; - double b; -} PictRadialGradient, *PictRadialGradientPtr; - -typedef struct _PictConicalGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; - xPointFixed center; - xFixed angle; -} PictConicalGradient, *PictConicalGradientPtr; - -typedef union _SourcePict { - unsigned int type; - PictSolidFill solidFill; - PictGradient gradient; - PictLinearGradient linear; - PictRadialGradient radial; - PictConicalGradient conical; -} SourcePict, *SourcePictPtr; - -typedef struct _Picture { - DrawablePtr pDrawable; - PictFormatPtr pFormat; - CARD32 format; /* PICT_FORMAT */ - int refcnt; - CARD32 id; - PicturePtr pNext; /* chain on same drawable */ - - unsigned int repeat : 1; - unsigned int graphicsExposures : 1; - unsigned int subWindowMode : 1; - unsigned int polyEdge : 1; - unsigned int polyMode : 1; - unsigned int freeCompClip : 1; - unsigned int clientClipType : 2; - unsigned int componentAlpha : 1; - unsigned int repeatType : 2; - unsigned int unused : 21; - - PicturePtr alphaMap; - DDXPointRec alphaOrigin; - - DDXPointRec clipOrigin; - pointer clientClip; - - Atom dither; - - unsigned long stateChanges; - unsigned long serialNumber; - - RegionPtr pCompositeClip; - - DevUnion *devPrivates; - - PictTransform *transform; - - int filter; - xFixed *filter_params; - int filter_nparams; - SourcePictPtr pSourcePict; -} PictureRec; - -typedef Bool (*PictFilterValidateParamsProcPtr) (PicturePtr pPicture, int id, - xFixed *params, int nparams); -typedef struct { - char *name; - int id; - PictFilterValidateParamsProcPtr ValidateParams; -} PictFilterRec, *PictFilterPtr; - -#define PictFilterNearest 0 -#define PictFilterBilinear 1 - -#define PictFilterFast 2 -#define PictFilterGood 3 -#define PictFilterBest 4 - -#define PictFilterConvolution 5 - -typedef struct { - char *alias; - int alias_id; - int filter_id; -} PictFilterAliasRec, *PictFilterAliasPtr; - -typedef int (*CreatePictureProcPtr) (PicturePtr pPicture); -typedef void (*DestroyPictureProcPtr) (PicturePtr pPicture); -typedef int (*ChangePictureClipProcPtr) (PicturePtr pPicture, - int clipType, - pointer value, - int n); -typedef void (*DestroyPictureClipProcPtr)(PicturePtr pPicture); - -typedef int (*ChangePictureTransformProcPtr) (PicturePtr pPicture, - PictTransform *transform); - -typedef int (*ChangePictureFilterProcPtr) (PicturePtr pPicture, - int filter, - xFixed *params, - int nparams); - -typedef void (*DestroyPictureFilterProcPtr) (PicturePtr pPicture); - -typedef void (*ChangePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*ValidatePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*CompositeProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -typedef void (*GlyphsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlists, - GlyphListPtr lists, - GlyphPtr *glyphs); - -typedef void (*CompositeRectsProcPtr) (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -typedef void (*RasterizeTrapezoidProcPtr)(PicturePtr pMask, - xTrapezoid *trap, - int x_off, - int y_off); - -typedef void (*TrapezoidsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -typedef void (*TrianglesProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntri, - xTriangle *tris); - -typedef void (*TriStripProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef void (*TriFanProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef Bool (*InitIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*CloseIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*UpdateIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat, - int ndef, - xColorItem *pdef); - -typedef void (*AddTrapsProcPtr) (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntrap, - xTrap *traps); - -typedef void (*AddTrianglesProcPtr) (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntri, - xTriangle *tris); - -typedef struct _PictureScreen { - int totalPictureSize; - unsigned int *PicturePrivateSizes; - int PicturePrivateLen; - - PictFormatPtr formats; - PictFormatPtr fallback; - int nformats; - - CreatePictureProcPtr CreatePicture; - DestroyPictureProcPtr DestroyPicture; - ChangePictureClipProcPtr ChangePictureClip; - DestroyPictureClipProcPtr DestroyPictureClip; - - ChangePictureProcPtr ChangePicture; - ValidatePictureProcPtr ValidatePicture; - - CompositeProcPtr Composite; - GlyphsProcPtr Glyphs; - CompositeRectsProcPtr CompositeRects; - - DestroyWindowProcPtr DestroyWindow; - CloseScreenProcPtr CloseScreen; - - StoreColorsProcPtr StoreColors; - - InitIndexedProcPtr InitIndexed; - CloseIndexedProcPtr CloseIndexed; - UpdateIndexedProcPtr UpdateIndexed; - - int subpixel; - - PictFilterPtr filters; - int nfilters; - PictFilterAliasPtr filterAliases; - int nfilterAliases; - - ChangePictureTransformProcPtr ChangePictureTransform; - ChangePictureFilterProcPtr ChangePictureFilter; - DestroyPictureFilterProcPtr DestroyPictureFilter; - - TrapezoidsProcPtr Trapezoids; - TrianglesProcPtr Triangles; - TriStripProcPtr TriStrip; - TriFanProcPtr TriFan; - - RasterizeTrapezoidProcPtr RasterizeTrapezoid; - - AddTrianglesProcPtr AddTriangles; - - AddTrapsProcPtr AddTraps; - -} PictureScreenRec, *PictureScreenPtr; - -extern int PictureScreenPrivateIndex; -extern int PictureWindowPrivateIndex; -extern RESTYPE PictureType; -extern RESTYPE PictFormatType; -extern RESTYPE GlyphSetType; - -#define GetPictureScreen(s) ((PictureScreenPtr) ((s)->devPrivates[PictureScreenPrivateIndex].ptr)) -#define GetPictureScreenIfSet(s) ((PictureScreenPrivateIndex != -1) ? GetPictureScreen(s) : NULL) -#define SetPictureScreen(s,p) ((s)->devPrivates[PictureScreenPrivateIndex].ptr = (pointer) (p)) -#define GetPictureWindow(w) ((PicturePtr) ((w)->devPrivates[PictureWindowPrivateIndex].ptr)) -#define SetPictureWindow(w,p) ((w)->devPrivates[PictureWindowPrivateIndex].ptr = (pointer) (p)) - -#define VERIFY_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, PictureType, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -void -ResetPicturePrivateIndex (void); - -int -AllocatePicturePrivateIndex (void); - -Bool -AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount); - -Bool -PictureDestroyWindow (WindowPtr pWindow); - -Bool -PictureCloseScreen (int Index, ScreenPtr pScreen); - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef); - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen); - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel); - -int -PictureGetSubpixelOrder (ScreenPtr pScreen); - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp); - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual); - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 format); - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); - -int -PictureGetFilterId (char *filter, int len, Bool makeit); - -char * -PictureGetFilterName (int id); - -int -PictureAddFilter (ScreenPtr pScreen, - char *filter, - PictFilterValidateParamsProcPtr ValidateParams); - -Bool -PictureSetFilterAlias (ScreenPtr pScreen, char *filter, char *alias); - -Bool -PictureSetDefaultFilters (ScreenPtr pScreen); - -void -PictureResetFilters (ScreenPtr pScreen); - -PictFilterPtr -PictureFindFilter (ScreenPtr pScreen, char *name, int len); - -int -SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams); - -Bool -PictureFinishInit (void); - -void -SetPictureToDefaults (PicturePtr pPicture); - -PicturePtr -AllocatePicture (ScreenPtr pScreen); - -#if 0 -Bool -miPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); -#endif - - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask mask, - XID *list, - ClientPtr client, - int *error); - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client); - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects); - -int -SetPictureClipRegion (PicturePtr pPicture, - int xOrigin, - int yOrigin, - RegionPtr pRegion); - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform); - -void -CopyPicture (PicturePtr pSrc, - Mask mask, - PicturePtr pDst); - -void -ValidatePicture(PicturePtr pPicture); - -int -FreePicture (pointer pPicture, - XID pid); - -int -FreePictFormat (pointer pPictFormat, - XID pid); - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs); - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles); - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector); - -Bool -PictureTransformPoint3d (PictTransformPtr transform, - PictVectorPtr vector); - -void RenderExtensionInit (void); - -Bool -AnimCurInit (ScreenPtr pScreen); - -int -AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor); - -void -AddTraps (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntraps, - xTrap *traps); - -PicturePtr -CreateSolidPicture (Picture pid, - xRenderColor *color, - int *error); - -PicturePtr -CreateLinearGradientPicture (Picture pid, - xPointFixed *p1, - xPointFixed *p2, - int nStops, - xFixed *stops, - xRenderColor *colors, - int *error); - -PicturePtr -CreateRadialGradientPicture (Picture pid, - xPointFixed *inner, - xPointFixed *outer, - xFixed innerRadius, - xFixed outerRadius, - int nStops, - xFixed *stops, - xRenderColor *colors, - int *error); - -PicturePtr -CreateConicalGradientPicture (Picture pid, - xPointFixed *center, - xFixed angle, - int nStops, - xFixed *stops, - xRenderColor *colors, - int *error); - -#ifdef PANORAMIX -void PanoramiXRenderInit (void); -void PanoramiXRenderReset (void); -#endif - -#endif /* _PICTURESTR_H_ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.X.original deleted file mode 100644 index 4775793ab..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXpicturestr.h.X.original +++ /dev/null @@ -1,654 +0,0 @@ -/* - * $Id: picturestr.h,v 1.15 2005/12/09 18:35:21 ajax Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#ifndef _PICTURESTR_H_ -#define _PICTURESTR_H_ - -#include "glyphstr.h" -#include "scrnintstr.h" -#include "resource.h" - -typedef struct _DirectFormat { - CARD16 red, redMask; - CARD16 green, greenMask; - CARD16 blue, blueMask; - CARD16 alpha, alphaMask; -} DirectFormatRec; - -typedef struct _IndexFormat { - VisualID vid; - ColormapPtr pColormap; - int nvalues; - xIndexValue *pValues; - void *devPrivate; -} IndexFormatRec; - -typedef struct _PictFormat { - CARD32 id; - CARD32 format; /* except bpp */ - unsigned char type; - unsigned char depth; - DirectFormatRec direct; - IndexFormatRec index; -} PictFormatRec; - -typedef struct _PictVector { - xFixed vector[3]; -} PictVector, *PictVectorPtr; - -typedef struct _PictTransform { - xFixed matrix[3][3]; -} PictTransform, *PictTransformPtr; - -#define PICT_GRADIENT_STOPTABLE_SIZE 1024 -#define SourcePictTypeSolidFill 0 -#define SourcePictTypeLinear 1 -#define SourcePictTypeRadial 2 -#define SourcePictTypeConical 3 - -typedef struct _PictSolidFill { - unsigned int type; - CARD32 color; -} PictSolidFill, *PictSolidFillPtr; - -typedef struct _PictGradientStop { - xFixed x; - xRenderColor color; -} PictGradientStop, *PictGradientStopPtr; - -typedef struct _PictGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; -} PictGradient, *PictGradientPtr; - -typedef struct _PictLinearGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; - xPointFixed p1; - xPointFixed p2; -} PictLinearGradient, *PictLinearGradientPtr; - -typedef struct _PictRadialGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; - double fx; - double fy; - double dx; - double dy; - double a; - double m; - double b; -} PictRadialGradient, *PictRadialGradientPtr; - -typedef struct _PictConicalGradient { - unsigned int type; - int nstops; - PictGradientStopPtr stops; - CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE]; - xPointFixed center; - xFixed angle; -} PictConicalGradient, *PictConicalGradientPtr; - -typedef union _SourcePict { - unsigned int type; - PictSolidFill solidFill; - PictGradient gradient; - PictLinearGradient linear; - PictRadialGradient radial; - PictConicalGradient conical; -} SourcePict, *SourcePictPtr; - -typedef struct _Picture { - DrawablePtr pDrawable; - PictFormatPtr pFormat; - CARD32 format; /* PICT_FORMAT */ - int refcnt; - CARD32 id; - PicturePtr pNext; /* chain on same drawable */ - - unsigned int repeat : 1; - unsigned int graphicsExposures : 1; - unsigned int subWindowMode : 1; - unsigned int polyEdge : 1; - unsigned int polyMode : 1; - unsigned int freeCompClip : 1; - unsigned int clientClipType : 2; - unsigned int componentAlpha : 1; - unsigned int repeatType : 2; - unsigned int unused : 21; - - PicturePtr alphaMap; - DDXPointRec alphaOrigin; - - DDXPointRec clipOrigin; - pointer clientClip; - - Atom dither; - - unsigned long stateChanges; - unsigned long serialNumber; - - RegionPtr pCompositeClip; - - DevUnion *devPrivates; - - PictTransform *transform; - - int filter; - xFixed *filter_params; - int filter_nparams; - SourcePictPtr pSourcePict; -} PictureRec; - -typedef Bool (*PictFilterValidateParamsProcPtr) (PicturePtr pPicture, int id, - xFixed *params, int nparams); -typedef struct { - char *name; - int id; - PictFilterValidateParamsProcPtr ValidateParams; -} PictFilterRec, *PictFilterPtr; - -#define PictFilterNearest 0 -#define PictFilterBilinear 1 - -#define PictFilterFast 2 -#define PictFilterGood 3 -#define PictFilterBest 4 - -#define PictFilterConvolution 5 - -typedef struct { - char *alias; - int alias_id; - int filter_id; -} PictFilterAliasRec, *PictFilterAliasPtr; - -typedef int (*CreatePictureProcPtr) (PicturePtr pPicture); -typedef void (*DestroyPictureProcPtr) (PicturePtr pPicture); -typedef int (*ChangePictureClipProcPtr) (PicturePtr pPicture, - int clipType, - pointer value, - int n); -typedef void (*DestroyPictureClipProcPtr)(PicturePtr pPicture); - -typedef int (*ChangePictureTransformProcPtr) (PicturePtr pPicture, - PictTransform *transform); - -typedef int (*ChangePictureFilterProcPtr) (PicturePtr pPicture, - int filter, - xFixed *params, - int nparams); - -typedef void (*DestroyPictureFilterProcPtr) (PicturePtr pPicture); - -typedef void (*ChangePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*ValidatePictureProcPtr) (PicturePtr pPicture, - Mask mask); -typedef void (*CompositeProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -typedef void (*GlyphsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlists, - GlyphListPtr lists, - GlyphPtr *glyphs); - -typedef void (*CompositeRectsProcPtr) (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -typedef void (*RasterizeTrapezoidProcPtr)(PicturePtr pMask, - xTrapezoid *trap, - int x_off, - int y_off); - -typedef void (*TrapezoidsProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -typedef void (*TrianglesProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntri, - xTriangle *tris); - -typedef void (*TriStripProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef void (*TriFanProcPtr) (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoint, - xPointFixed *points); - -typedef Bool (*InitIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*CloseIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat); - -typedef void (*UpdateIndexedProcPtr) (ScreenPtr pScreen, - PictFormatPtr pFormat, - int ndef, - xColorItem *pdef); - -typedef void (*AddTrapsProcPtr) (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntrap, - xTrap *traps); - -typedef void (*AddTrianglesProcPtr) (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntri, - xTriangle *tris); - -typedef struct _PictureScreen { - int totalPictureSize; - unsigned int *PicturePrivateSizes; - int PicturePrivateLen; - - PictFormatPtr formats; - PictFormatPtr fallback; - int nformats; - - CreatePictureProcPtr CreatePicture; - DestroyPictureProcPtr DestroyPicture; - ChangePictureClipProcPtr ChangePictureClip; - DestroyPictureClipProcPtr DestroyPictureClip; - - ChangePictureProcPtr ChangePicture; - ValidatePictureProcPtr ValidatePicture; - - CompositeProcPtr Composite; - GlyphsProcPtr Glyphs; - CompositeRectsProcPtr CompositeRects; - - DestroyWindowProcPtr DestroyWindow; - CloseScreenProcPtr CloseScreen; - - StoreColorsProcPtr StoreColors; - - InitIndexedProcPtr InitIndexed; - CloseIndexedProcPtr CloseIndexed; - UpdateIndexedProcPtr UpdateIndexed; - - int subpixel; - - PictFilterPtr filters; - int nfilters; - PictFilterAliasPtr filterAliases; - int nfilterAliases; - - ChangePictureTransformProcPtr ChangePictureTransform; - ChangePictureFilterProcPtr ChangePictureFilter; - DestroyPictureFilterProcPtr DestroyPictureFilter; - - TrapezoidsProcPtr Trapezoids; - TrianglesProcPtr Triangles; - TriStripProcPtr TriStrip; - TriFanProcPtr TriFan; - - RasterizeTrapezoidProcPtr RasterizeTrapezoid; - - AddTrianglesProcPtr AddTriangles; - - AddTrapsProcPtr AddTraps; - -} PictureScreenRec, *PictureScreenPtr; - -extern int PictureScreenPrivateIndex; -extern int PictureWindowPrivateIndex; -extern RESTYPE PictureType; -extern RESTYPE PictFormatType; -extern RESTYPE GlyphSetType; - -#define GetPictureScreen(s) ((PictureScreenPtr) ((s)->devPrivates[PictureScreenPrivateIndex].ptr)) -#define GetPictureScreenIfSet(s) ((PictureScreenPrivateIndex != -1) ? GetPictureScreen(s) : NULL) -#define SetPictureScreen(s,p) ((s)->devPrivates[PictureScreenPrivateIndex].ptr = (pointer) (p)) -#define GetPictureWindow(w) ((PicturePtr) ((w)->devPrivates[PictureWindowPrivateIndex].ptr)) -#define SetPictureWindow(w,p) ((w)->devPrivates[PictureWindowPrivateIndex].ptr = (pointer) (p)) - -#define VERIFY_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, PictureType, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -void -ResetPicturePrivateIndex (void); - -int -AllocatePicturePrivateIndex (void); - -Bool -AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount); - -Bool -PictureDestroyWindow (WindowPtr pWindow); - -Bool -PictureCloseScreen (int Index, ScreenPtr pScreen); - -void -PictureStoreColors (ColormapPtr pColormap, int ndef, xColorItem *pdef); - -Bool -PictureInitIndexedFormats (ScreenPtr pScreen); - -Bool -PictureSetSubpixelOrder (ScreenPtr pScreen, int subpixel); - -int -PictureGetSubpixelOrder (ScreenPtr pScreen); - -PictFormatPtr -PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp); - -PictFormatPtr -PictureMatchVisual (ScreenPtr pScreen, int depth, VisualPtr pVisual); - -PictFormatPtr -PictureMatchFormat (ScreenPtr pScreen, int depth, CARD32 format); - -Bool -PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); - -int -PictureGetFilterId (char *filter, int len, Bool makeit); - -char * -PictureGetFilterName (int id); - -int -PictureAddFilter (ScreenPtr pScreen, - char *filter, - PictFilterValidateParamsProcPtr ValidateParams); - -Bool -PictureSetFilterAlias (ScreenPtr pScreen, char *filter, char *alias); - -Bool -PictureSetDefaultFilters (ScreenPtr pScreen); - -void -PictureResetFilters (ScreenPtr pScreen); - -PictFilterPtr -PictureFindFilter (ScreenPtr pScreen, char *name, int len); - -int -SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams); - -Bool -PictureFinishInit (void); - -void -SetPictureToDefaults (PicturePtr pPicture); - -PicturePtr -AllocatePicture (ScreenPtr pScreen); - -#if 0 -Bool -miPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); -#endif - - -PicturePtr -CreatePicture (Picture pid, - DrawablePtr pDrawable, - PictFormatPtr pFormat, - Mask mask, - XID *list, - ClientPtr client, - int *error); - -int -ChangePicture (PicturePtr pPicture, - Mask vmask, - XID *vlist, - DevUnion *ulist, - ClientPtr client); - -int -SetPictureClipRects (PicturePtr pPicture, - int xOrigin, - int yOrigin, - int nRect, - xRectangle *rects); - -int -SetPictureClipRegion (PicturePtr pPicture, - int xOrigin, - int yOrigin, - RegionPtr pRegion); - -int -SetPictureTransform (PicturePtr pPicture, - PictTransform *transform); - -void -CopyPicture (PicturePtr pSrc, - Mask mask, - PicturePtr pDst); - -void -ValidatePicture(PicturePtr pPicture); - -int -FreePicture (pointer pPicture, - XID pid); - -int -FreePictFormat (pointer pPictFormat, - XID pid); - -void -CompositePicture (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -CompositeGlyphs (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int nlist, - GlyphListPtr lists, - GlyphPtr *glyphs); - -void -CompositeRects (CARD8 op, - PicturePtr pDst, - xRenderColor *color, - int nRect, - xRectangle *rects); - -void -CompositeTrapezoids (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntrap, - xTrapezoid *traps); - -void -CompositeTriangles (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int ntriangles, - xTriangle *triangles); - -void -CompositeTriStrip (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -void -CompositeTriFan (CARD8 op, - PicturePtr pSrc, - PicturePtr pDst, - PictFormatPtr maskFormat, - INT16 xSrc, - INT16 ySrc, - int npoints, - xPointFixed *points); - -Bool -PictureTransformPoint (PictTransformPtr transform, - PictVectorPtr vector); - -Bool -PictureTransformPoint3d (PictTransformPtr transform, - PictVectorPtr vector); - -void RenderExtensionInit (void); - -Bool -AnimCurInit (ScreenPtr pScreen); - -int -AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor); - -void -AddTraps (PicturePtr pPicture, - INT16 xOff, - INT16 yOff, - int ntraps, - xTrap *traps); - -PicturePtr -CreateSolidPicture (Picture pid, - xRenderColor *color, - int *error); - -PicturePtr -CreateLinearGradientPicture (Picture pid, - xPointFixed *p1, - xPointFixed *p2, - int nStops, - xFixed *stops, - xRenderColor *colors, - int *error); - -PicturePtr -CreateRadialGradientPicture (Picture pid, - xPointFixed *inner, - xPointFixed *outer, - xFixed innerRadius, - xFixed outerRadius, - int nStops, - xFixed *stops, - xRenderColor *colors, - int *error); - -PicturePtr -CreateConicalGradientPicture (Picture pid, - xPointFixed *center, - xFixed angle, - int nStops, - xFixed *stops, - xRenderColor *colors, - int *error); - -#ifdef PANORAMIX -void PanoramiXRenderInit (void); -void PanoramiXRenderReset (void); -#endif - -#endif /* _PICTURESTR_H_ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.NX.original deleted file mode 100644 index cd1ec6ddd..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.NX.original +++ /dev/null @@ -1,992 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/property.c,v 3.12 2002/02/19 11:09:22 alanh Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: property.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#define NEED_REPLIES -#define NEED_EVENTS -#include -#include "windowstr.h" -#include "propertyst.h" -#include "dixstruct.h" -#include "../../dix/dispatch.h" -#include "swaprep.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef LBX -#include "lbxserve.h" -#include "lbxtags.h" -#endif - -#include "Options.h" -#include "Rootless.h" -#include "Client.h" -#include "Windows.h" - -#if defined(LBX) || defined(LBX_COMPAT) -#if 0 /* no header in X11 environment, not used in X11 environment */ -int fWriteToClient(ClientPtr client, int len, char *buf) -{ - return WriteToClient(client, len, buf); -} -#endif -#endif - -extern Atom clientCutProperty; - -#ifdef NXAGENT_SERVER -typedef struct -{ - CARD32 state; - Window icon; -} -nxagentWMStateRec; -#endif - -/***************************************************************** - * Property Stuff - * - * ChangeProperty, DeleteProperty, GetProperties, - * ListProperties - * - * Properties below to windows. A allocate slots each time - * a property is added. No fancy searching done. - * - *****************************************************************/ - -#ifdef notdef -static void -PrintPropertys(WindowPtr pWin) -{ - PropertyPtr pProp; - register int j; - - pProp = pWin->userProps; - while (pProp) - { - ErrorF( "%x %x\n", pProp->propertyName, pProp->type); - ErrorF("property format: %d\n", pProp->format); - ErrorF("property data: \n"); - for (j=0; j<(pProp->format/8)*pProp->size; j++) - ErrorF("%c\n", pProp->data[j]); - pProp = pProp->next; - } -} -#endif - -int -ProcRotateProperties(ClientPtr client) -{ - int i, j, delta; - REQUEST(xRotatePropertiesReq); - WindowPtr pWin; - register Atom * atoms; - PropertyPtr * props; /* array of pointer */ - PropertyPtr pProp; - xEvent event; - - REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2); - UpdateCurrentTime(); - pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!stuff->nAtoms) - return(Success); - atoms = (Atom *) & stuff[1]; - props = (PropertyPtr *)ALLOCATE_LOCAL(stuff->nAtoms * sizeof(PropertyPtr)); - if (!props) - return(BadAlloc); - for (i = 0; i < stuff->nAtoms; i++) - { -#ifdef XCSECURITY - char action = SecurityCheckPropertyAccess(client, pWin, atoms[i], - SecurityReadAccess|SecurityWriteAccess); -#endif - if (!ValidAtom(atoms[i]) -#ifdef XCSECURITY - || (SecurityErrorOperation == action) -#endif - ) - { - DEALLOCATE_LOCAL(props); - client->errorValue = atoms[i]; - return BadAtom; - } -#ifdef XCSECURITY - if (SecurityIgnoreOperation == action) - { - DEALLOCATE_LOCAL(props); - return Success; - } -#endif - for (j = i + 1; j < stuff->nAtoms; j++) - if (atoms[j] == atoms[i]) - { - DEALLOCATE_LOCAL(props); - return BadMatch; - } - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == atoms[i]) - goto found; - pProp = pProp->next; - } - DEALLOCATE_LOCAL(props); - return BadMatch; -found: - props[i] = pProp; - } - delta = stuff->nPositions; - - /* If the rotation is a complete 360 degrees, then moving the properties - around and generating PropertyNotify events should be skipped. */ - - if ( (stuff->nAtoms != 0) && (abs(delta) % stuff->nAtoms) != 0 ) - { - while (delta < 0) /* faster if abs value is small */ - delta += stuff->nAtoms; - for (i = 0; i < stuff->nAtoms; i++) - { - /* Generate a PropertyNotify event for each property whose value - is changed in the order in which they appear in the request. */ - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = props[i]->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - - props[i]->propertyName = atoms[(i + delta) % stuff->nAtoms]; - } - } - DEALLOCATE_LOCAL(props); - return Success; -} - -int -ProcChangeProperty(ClientPtr client) -{ - WindowPtr pWin; - char format, mode; - unsigned long len; - int sizeInBytes; - int totalSize; - int err; - REQUEST(xChangePropertyReq); - - REQUEST_AT_LEAST_SIZE(xChangePropertyReq); - UpdateCurrentTime(); - format = stuff->format; - mode = stuff->mode; - if ((mode != PropModeReplace) && (mode != PropModeAppend) && - (mode != PropModePrepend)) - { - client->errorValue = mode; - return BadValue; - } - if ((format != 8) && (format != 16) && (format != 32)) - { - client->errorValue = format; - return BadValue; - } - len = stuff->nUnits; - if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2)) - return BadLength; - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize); - -#ifdef NXAGENT_CLIPBOARD - { - extern WindowPtr nxagentGetClipboardWindow(Atom, WindowPtr); - - pWin = nxagentGetClipboardWindow(stuff->property, NULL); - } - - if (pWin == NULL) -#endif - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if (!ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - -#ifdef XCSECURITY - switch (SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityWriteAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom; - case SecurityIgnoreOperation: - return Success; - } -#endif - -#ifdef NXAGENT_ARTSD - { - /* Do not process MCOPGLOBALS property changes, - they are already set reflecting the server side settings. - Just return success. - */ - extern Atom mcop_local_atom; - if (stuff->property == mcop_local_atom) - return client->noClientException; - } -#endif - -#ifdef LBX - err = LbxChangeWindowProperty(client, pWin, stuff->property, stuff->type, - (int)format, (int)mode, len, TRUE, (pointer)&stuff[1], TRUE, NULL); -#else - err = ChangeWindowProperty(pWin, stuff->property, stuff->type, (int)format, - (int)mode, len, (pointer)&stuff[1], TRUE); -#endif - if (err != Success) - return err; - else - { - if (nxagentOption(Rootless) == 1) - { - nxagentExportProperty(pWin, stuff->property, stuff->type, (int) format, - (int) mode, len, (pointer) &stuff[1]); - } - - nxagentGuessClientHint(client, stuff->property, (char *) &stuff[1]); - - nxagentGuessShadowHint(client, stuff->property); - - #ifdef NX_DEBUG_INPUT - nxagentGuessDumpInputInfo(client, stuff->property, (char *) &stuff[1]); - #endif - - return client->noClientException; - } -} - -int -ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, - int mode, unsigned long len, pointer value, - Bool sendevent) -{ -#ifdef LBX - return LbxChangeWindowProperty(NULL, pWin, property, type, - format, mode, len, TRUE, value, - sendevent, NULL); -#else - PropertyPtr pProp; - xEvent event; - int sizeInBytes; - int totalSize; - pointer data; - int copySize; - - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - - copySize = nxagentOption(CopyBufferSize); - - if (copySize != COPY_UNLIMITED && property == clientCutProperty) - { - if (totalSize > copySize) - { - totalSize = copySize; - totalSize = totalSize - (totalSize % sizeInBytes); - len = totalSize / sizeInBytes; - } - } - - /* first see if property already exists */ - - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == property) - break; - pProp = pProp->next; - } - if (!pProp) /* just add to list */ - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - return(BadAlloc); - pProp = (PropertyPtr)xalloc(sizeof(PropertyRec)); - if (!pProp) - return(BadAlloc); - data = (pointer)xalloc(totalSize); - if (!data && len) - { - xfree(pProp); - return(BadAlloc); - } - pProp->propertyName = property; - pProp->type = type; - pProp->format = format; - pProp->data = data; - if (len) - memmove((char *)data, (char *)value, totalSize); - pProp->size = len; - pProp->next = pWin->optional->userProps; - pWin->optional->userProps = pProp; - } - else - { - /* To append or prepend to a property the request format and type - must match those of the already defined property. The - existing format and type are irrelevant when using the mode - "PropModeReplace" since they will be written over. */ - - if ((format != pProp->format) && (mode != PropModeReplace)) - return(BadMatch); - if ((pProp->type != type) && (mode != PropModeReplace)) - return(BadMatch); - if (mode == PropModeReplace) - { - if (totalSize != pProp->size * (pProp->format >> 3)) - { - data = (pointer)xrealloc(pProp->data, totalSize); - if (!data && len) - return(BadAlloc); - pProp->data = data; - } - if (len) - memmove((char *)pProp->data, (char *)value, totalSize); - pProp->size = len; - pProp->type = type; - pProp->format = format; - } - else if (len == 0) - { - /* do nothing */ - } - else if (mode == PropModeAppend) - { - data = (pointer)xrealloc(pProp->data, - sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - pProp->data = data; - memmove(&((char *)data)[pProp->size * sizeInBytes], - (char *)value, - totalSize); - pProp->size += len; - } - else if (mode == PropModePrepend) - { - data = (pointer)xalloc(sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - memmove(&((char *)data)[totalSize], (char *)pProp->data, - (int)(pProp->size * sizeInBytes)); - memmove((char *)data, (char *)value, totalSize); - xfree(pProp->data); - pProp->data = data; - pProp->size += len; - } - } - if (sendevent) - { - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - return(Success); -#endif -} - -int -DeleteProperty(WindowPtr pWin, Atom propName) -{ - PropertyPtr pProp, prevProp; - xEvent event; - - if (!(pProp = wUserProps (pWin))) - return(Success); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == propName) - break; - prevProp = pProp; - pProp = pProp->next; - } - if (pProp) - { - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - { - prevProp->next = pProp->next; - } -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - xfree(pProp->data); - xfree(pProp); - } - return(Success); -} - -void -DeleteAllWindowProperties(WindowPtr pWin) -{ - PropertyPtr pProp, pNextProp; - xEvent event; - - pProp = wUserProps (pWin); - while (pProp) - { -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - pNextProp = pProp->next; - xfree(pProp->data); - xfree(pProp); - pProp = pNextProp; - } -} - -static int -NullPropertyReply( - ClientPtr client, - ATOM propertyType, - int format, - xGetPropertyReply *reply) -{ - reply->nItems = 0; - reply->length = 0; - reply->bytesAfter = 0; - reply->propertyType = propertyType; - reply->format = format; - WriteReplyToClient(client, sizeof(xGenericReply), reply); - return(client->noClientException); -} - -/***************** - * GetProperty - * If type Any is specified, returns the property from the specified - * window regardless of its type. If a type is specified, returns the - * property only if its type equals the specified type. - * If delete is True and a property is returned, the property is also - * deleted from the window and a PropertyNotify event is generated on the - * window. - *****************/ - -int -ProcGetProperty(ClientPtr client) -{ - #ifdef NXAGENT_SERVER - nxagentWMStateRec wmState; - nxagentWMStateRec *wmsP = &wmState; - #endif - - PropertyPtr pProp, prevProp; - unsigned long n, len, ind; - WindowPtr pWin; - xGetPropertyReply reply; - REQUEST(xGetPropertyReq); - - REQUEST_SIZE_MATCH(xGetPropertyReq); - - if (stuff->delete) - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) - { - client->errorValue = stuff->delete; - return(BadValue); - } - if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - - pProp = wUserProps (pWin); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == stuff->property) - break; - prevProp = pProp; - pProp = pProp->next; - } - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - - #ifdef NXAGENT_SERVER - - /* - * Creating a reply for WM_STATE property if it doesn't exist. - * This is intended to allow drag & drop work in JAva 1.6 when - * the agent is connected to NXWin in multiwindow mode. - */ - - if (nxagentOption(Rootless) && - nxagentWindowTopLevel(pWin) && - (!pProp) && - strcmp(NameForAtom(stuff->property), "WM_STATE") == 0) - { - wmState.state = 1; - wmState.icon = None; - - if (ChangeWindowProperty(pWin, stuff->property, stuff->property, 32, 0, 2, &wmState, 1) == Success) - { - nxagentExportProperty(pWin, stuff->property, stuff->property, 32, 0, 2, &wmState); - } - - n = 8; - ind = stuff->longOffset << 2; - - if (n < ind) - { - client->errorValue = stuff->longOffset; - return BadValue; - } - - len = min(n - ind, 4 * stuff->longLength); - - reply.bytesAfter = n - (ind + len); - reply.length = (len + 3) >> 2; - - reply.format = 32; - reply.nItems = len / 4; - reply.propertyType = stuff->property; - - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - - if (len) - { - client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; - - WriteSwappedDataToClient(client, len, (char *)wmsP + ind); - } - - return(client->noClientException); - } - #endif - - if (!pProp) - return NullPropertyReply(client, None, 0, &reply); - -#ifdef XCSECURITY - { - Mask access_mode = SecurityReadAccess; - - if (stuff->delete) - access_mode |= SecurityDestroyAccess; - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - access_mode)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return NullPropertyReply(client, pProp->type, pProp->format, - &reply); - } - } -#endif - /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((stuff->type != pProp->type) && - (stuff->type != AnyPropertyType)) - ) - { - reply.bytesAfter = pProp->size; - reply.format = pProp->format; - reply.length = 0; - reply.nItems = 0; - reply.propertyType = pProp->type; - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - return(Success); - } -#ifdef LBX - /* make sure we have the current value */ - if (pProp->tag_id && pProp->owner_pid) { - LbxStallPropRequest(client, pProp); - return client->noClientException; - } -#endif - -/* - * Return type, format, value to client - */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = stuff->longOffset << 2; - - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ - - if (n < ind) - { - client->errorValue = stuff->longOffset; - return BadValue; - } - - len = min(n - ind, 4 * stuff->longLength); - - reply.bytesAfter = n - (ind + len); - reply.format = pProp->format; - reply.length = (len + 3) >> 2; - reply.nItems = len / (pProp->format / 8 ); - reply.propertyType = pProp->type; - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* send the event */ - xEvent event; - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - if (len) - { - switch (reply.format) { - case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break; - case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break; - default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break; - } - WriteSwappedDataToClient(client, len, - (char *)pProp->data + ind); - } - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* delete the Property */ -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - prevProp->next = pProp->next; - xfree(pProp->data); - xfree(pProp); - } - return(client->noClientException); -} - -#ifdef NXAGENT_CLIPBOARD -/* GetWindowProperty clipboard use only */ -int -GetWindowProperty(pWin, property, longOffset, longLength, delete, - type, actualType, format, nItems, bytesAfter, propData ) - WindowPtr pWin; - Atom property; - long longOffset; - long longLength; - Bool delete; - Atom type; - Atom *actualType; - int *format; - unsigned long *nItems; - unsigned long *bytesAfter; - unsigned char **propData; -{ - PropertyPtr pProp, prevProp; - unsigned long n, len, ind; - - if (!pWin) - return BadWindow; - - - if (!ValidAtom(property)) - { - return(BadAtom); - } - if ((type != AnyPropertyType) && !ValidAtom(type)) - { - return(BadAtom); - } - - pProp = wUserProps (pWin); - prevProp = (PropertyPtr)NULL; - - while (pProp) - { - if (pProp->propertyName == property) - break; - prevProp = pProp; - pProp = pProp->next; - } - - - if (!pProp) - return (BadAtom); - - /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((type != pProp->type) && - (type != AnyPropertyType)) - ) - { - *bytesAfter = pProp->size; - *format = pProp->format; - *nItems = 0; - *actualType = pProp->type; - return(Success); - } - -/* - * Return type, format, value to client - */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = longOffset << 2; - - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ - - if (n < ind) - { - return BadValue; - } - - len = min(n - ind, 4 * longLength); - - *bytesAfter = n - (ind + len); - *format = pProp->format; - *nItems = len / (pProp->format / 8 ); - *actualType = pProp->type; - - if (delete && (*bytesAfter == 0)) - { /* send the event */ - xEvent event; - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - - if (len) - { - *propData = (unsigned char *)(pProp->data) + ind; - } - - if (delete && (*bytesAfter == 0)) - { /* delete the Property */ -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - prevProp->next = pProp->next; - xfree(pProp->data); - xfree(pProp); - } - return(Success); -} -#endif - -int -ProcListProperties(ClientPtr client) -{ - Atom *pAtoms = NULL, *temppAtoms; - xListPropertiesReply xlpr; - int numProps = 0; - WindowPtr pWin; - PropertyPtr pProp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pProp = wUserProps (pWin); - while (pProp) - { - pProp = pProp->next; - numProps++; - } - if (numProps) - if(!(pAtoms = (Atom *)ALLOCATE_LOCAL(numProps * sizeof(Atom)))) - return(BadAlloc); - - xlpr.type = X_Reply; - xlpr.nProperties = numProps; - xlpr.length = (numProps * sizeof(Atom)) >> 2; - xlpr.sequenceNumber = client->sequence; - pProp = wUserProps (pWin); - temppAtoms = pAtoms; - while (pProp) - { - *temppAtoms++ = pProp->propertyName; - pProp = pProp->next; - } - WriteReplyToClient(client, sizeof(xGenericReply), &xlpr); - if (numProps) - { - client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write; - WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); - DEALLOCATE_LOCAL(pAtoms); - } - return(client->noClientException); -} - -int -ProcDeleteProperty(register ClientPtr client) -{ - WindowPtr pWin; - REQUEST(xDeletePropertyReq); - int result; - - REQUEST_SIZE_MATCH(xDeletePropertyReq); - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return (BadAtom); - } - -#ifdef XCSECURITY - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityDestroyAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return Success; - } -#endif - - result = DeleteProperty(pWin, stuff->property); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.X.original deleted file mode 100644 index cabe46ecc..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXproperty.c.X.original +++ /dev/null @@ -1,729 +0,0 @@ -/* $XFree86: xc/programs/Xserver/dix/property.c,v 3.12 2002/02/19 11:09:22 alanh Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: property.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#define NEED_REPLIES -#define NEED_EVENTS -#include -#include "windowstr.h" -#include "propertyst.h" -#include "dixstruct.h" -#include "dispatch.h" -#include "swaprep.h" -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef LBX -#include "lbxserve.h" -#include "lbxtags.h" -#endif - -#if defined(LBX) || defined(LBX_COMPAT) -#if 0 /* no header in X11 environment, not used in X11 environment */ -int fWriteToClient(ClientPtr client, int len, char *buf) -{ - return WriteToClient(client, len, buf); -} -#endif -#endif - -/***************************************************************** - * Property Stuff - * - * ChangeProperty, DeleteProperty, GetProperties, - * ListProperties - * - * Properties below to windows. A allocate slots each time - * a property is added. No fancy searching done. - * - *****************************************************************/ - -#ifdef notdef -static void -PrintPropertys(WindowPtr pWin) -{ - PropertyPtr pProp; - register int j; - - pProp = pWin->userProps; - while (pProp) - { - ErrorF( "%x %x\n", pProp->propertyName, pProp->type); - ErrorF("property format: %d\n", pProp->format); - ErrorF("property data: \n"); - for (j=0; j<(pProp->format/8)*pProp->size; j++) - ErrorF("%c\n", pProp->data[j]); - pProp = pProp->next; - } -} -#endif - -int -ProcRotateProperties(ClientPtr client) -{ - int i, j, delta; - REQUEST(xRotatePropertiesReq); - WindowPtr pWin; - register Atom * atoms; - PropertyPtr * props; /* array of pointer */ - PropertyPtr pProp; - xEvent event; - - REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2); - UpdateCurrentTime(); - pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!stuff->nAtoms) - return(Success); - atoms = (Atom *) & stuff[1]; - props = (PropertyPtr *)ALLOCATE_LOCAL(stuff->nAtoms * sizeof(PropertyPtr)); - if (!props) - return(BadAlloc); - for (i = 0; i < stuff->nAtoms; i++) - { -#ifdef XCSECURITY - char action = SecurityCheckPropertyAccess(client, pWin, atoms[i], - SecurityReadAccess|SecurityWriteAccess); -#endif - if (!ValidAtom(atoms[i]) -#ifdef XCSECURITY - || (SecurityErrorOperation == action) -#endif - ) - { - DEALLOCATE_LOCAL(props); - client->errorValue = atoms[i]; - return BadAtom; - } -#ifdef XCSECURITY - if (SecurityIgnoreOperation == action) - { - DEALLOCATE_LOCAL(props); - return Success; - } -#endif - for (j = i + 1; j < stuff->nAtoms; j++) - if (atoms[j] == atoms[i]) - { - DEALLOCATE_LOCAL(props); - return BadMatch; - } - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == atoms[i]) - goto found; - pProp = pProp->next; - } - DEALLOCATE_LOCAL(props); - return BadMatch; -found: - props[i] = pProp; - } - delta = stuff->nPositions; - - /* If the rotation is a complete 360 degrees, then moving the properties - around and generating PropertyNotify events should be skipped. */ - - if ( (stuff->nAtoms != 0) && (abs(delta) % stuff->nAtoms) != 0 ) - { - while (delta < 0) /* faster if abs value is small */ - delta += stuff->nAtoms; - for (i = 0; i < stuff->nAtoms; i++) - { - /* Generate a PropertyNotify event for each property whose value - is changed in the order in which they appear in the request. */ - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = props[i]->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - - props[i]->propertyName = atoms[(i + delta) % stuff->nAtoms]; - } - } - DEALLOCATE_LOCAL(props); - return Success; -} - -int -ProcChangeProperty(ClientPtr client) -{ - WindowPtr pWin; - char format, mode; - unsigned long len; - int sizeInBytes; - int totalSize; - int err; - REQUEST(xChangePropertyReq); - - REQUEST_AT_LEAST_SIZE(xChangePropertyReq); - UpdateCurrentTime(); - format = stuff->format; - mode = stuff->mode; - if ((mode != PropModeReplace) && (mode != PropModeAppend) && - (mode != PropModePrepend)) - { - client->errorValue = mode; - return BadValue; - } - if ((format != 8) && (format != 16) && (format != 32)) - { - client->errorValue = format; - return BadValue; - } - len = stuff->nUnits; - if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2)) - return BadLength; - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize); - - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if (!ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - -#ifdef XCSECURITY - switch (SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityWriteAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom; - case SecurityIgnoreOperation: - return Success; - } -#endif - -#ifdef LBX - err = LbxChangeWindowProperty(client, pWin, stuff->property, stuff->type, - (int)format, (int)mode, len, TRUE, (pointer)&stuff[1], TRUE, NULL); -#else - err = ChangeWindowProperty(pWin, stuff->property, stuff->type, (int)format, - (int)mode, len, (pointer)&stuff[1], TRUE); -#endif - if (err != Success) - return err; - else - return client->noClientException; -} - -int -ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, - int mode, unsigned long len, pointer value, - Bool sendevent) -{ -#ifdef LBX - return LbxChangeWindowProperty(NULL, pWin, property, type, - format, mode, len, TRUE, value, - sendevent, NULL); -#else - PropertyPtr pProp; - xEvent event; - int sizeInBytes; - int totalSize; - pointer data; - - sizeInBytes = format>>3; - totalSize = len * sizeInBytes; - - /* first see if property already exists */ - - pProp = wUserProps (pWin); - while (pProp) - { - if (pProp->propertyName == property) - break; - pProp = pProp->next; - } - if (!pProp) /* just add to list */ - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - return(BadAlloc); - pProp = (PropertyPtr)xalloc(sizeof(PropertyRec)); - if (!pProp) - return(BadAlloc); - data = (pointer)xalloc(totalSize); - if (!data && len) - { - xfree(pProp); - return(BadAlloc); - } - pProp->propertyName = property; - pProp->type = type; - pProp->format = format; - pProp->data = data; - if (len) - memmove((char *)data, (char *)value, totalSize); - pProp->size = len; - pProp->next = pWin->optional->userProps; - pWin->optional->userProps = pProp; - } - else - { - /* To append or prepend to a property the request format and type - must match those of the already defined property. The - existing format and type are irrelevant when using the mode - "PropModeReplace" since they will be written over. */ - - if ((format != pProp->format) && (mode != PropModeReplace)) - return(BadMatch); - if ((pProp->type != type) && (mode != PropModeReplace)) - return(BadMatch); - if (mode == PropModeReplace) - { - if (totalSize != pProp->size * (pProp->format >> 3)) - { - data = (pointer)xrealloc(pProp->data, totalSize); - if (!data && len) - return(BadAlloc); - pProp->data = data; - } - if (len) - memmove((char *)pProp->data, (char *)value, totalSize); - pProp->size = len; - pProp->type = type; - pProp->format = format; - } - else if (len == 0) - { - /* do nothing */ - } - else if (mode == PropModeAppend) - { - data = (pointer)xrealloc(pProp->data, - sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - pProp->data = data; - memmove(&((char *)data)[pProp->size * sizeInBytes], - (char *)value, - totalSize); - pProp->size += len; - } - else if (mode == PropModePrepend) - { - data = (pointer)xalloc(sizeInBytes * (len + pProp->size)); - if (!data) - return(BadAlloc); - memmove(&((char *)data)[totalSize], (char *)pProp->data, - (int)(pProp->size * sizeInBytes)); - memmove((char *)data, (char *)value, totalSize); - xfree(pProp->data); - pProp->data = data; - pProp->size += len; - } - } - if (sendevent) - { - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyNewValue; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - return(Success); -#endif -} - -int -DeleteProperty(WindowPtr pWin, Atom propName) -{ - PropertyPtr pProp, prevProp; - xEvent event; - - if (!(pProp = wUserProps (pWin))) - return(Success); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == propName) - break; - prevProp = pProp; - pProp = pProp->next; - } - if (pProp) - { - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - { - prevProp->next = pProp->next; - } -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - xfree(pProp->data); - xfree(pProp); - } - return(Success); -} - -void -DeleteAllWindowProperties(WindowPtr pWin) -{ - PropertyPtr pProp, pNextProp; - xEvent event; - - pProp = wUserProps (pWin); - while (pProp) - { -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - pNextProp = pProp->next; - xfree(pProp->data); - xfree(pProp); - pProp = pNextProp; - } -} - -static int -NullPropertyReply( - ClientPtr client, - ATOM propertyType, - int format, - xGetPropertyReply *reply) -{ - reply->nItems = 0; - reply->length = 0; - reply->bytesAfter = 0; - reply->propertyType = propertyType; - reply->format = format; - WriteReplyToClient(client, sizeof(xGenericReply), reply); - return(client->noClientException); -} - -/***************** - * GetProperty - * If type Any is specified, returns the property from the specified - * window regardless of its type. If a type is specified, returns the - * property only if its type equals the specified type. - * If delete is True and a property is returned, the property is also - * deleted from the window and a PropertyNotify event is generated on the - * window. - *****************/ - -int -ProcGetProperty(ClientPtr client) -{ - PropertyPtr pProp, prevProp; - unsigned long n, len, ind; - WindowPtr pWin; - xGetPropertyReply reply; - REQUEST(xGetPropertyReq); - - REQUEST_SIZE_MATCH(xGetPropertyReq); - if (stuff->delete) - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return BadWindow; - - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return(BadAtom); - } - if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) - { - client->errorValue = stuff->delete; - return(BadValue); - } - if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return(BadAtom); - } - - pProp = wUserProps (pWin); - prevProp = (PropertyPtr)NULL; - while (pProp) - { - if (pProp->propertyName == stuff->property) - break; - prevProp = pProp; - pProp = pProp->next; - } - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - if (!pProp) - return NullPropertyReply(client, None, 0, &reply); - -#ifdef XCSECURITY - { - Mask access_mode = SecurityReadAccess; - - if (stuff->delete) - access_mode |= SecurityDestroyAccess; - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - access_mode)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return NullPropertyReply(client, pProp->type, pProp->format, - &reply); - } - } -#endif - /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((stuff->type != pProp->type) && - (stuff->type != AnyPropertyType)) - ) - { - reply.bytesAfter = pProp->size; - reply.format = pProp->format; - reply.length = 0; - reply.nItems = 0; - reply.propertyType = pProp->type; - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - return(Success); - } -#ifdef LBX - /* make sure we have the current value */ - if (pProp->tag_id && pProp->owner_pid) { - LbxStallPropRequest(client, pProp); - return client->noClientException; - } -#endif - -/* - * Return type, format, value to client - */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = stuff->longOffset << 2; - - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ - - if (n < ind) - { - client->errorValue = stuff->longOffset; - return BadValue; - } - - len = min(n - ind, 4 * stuff->longLength); - - reply.bytesAfter = n - (ind + len); - reply.format = pProp->format; - reply.length = (len + 3) >> 2; - reply.nItems = len / (pProp->format / 8 ); - reply.propertyType = pProp->type; - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* send the event */ - xEvent event; - - event.u.u.type = PropertyNotify; - event.u.property.window = pWin->drawable.id; - event.u.property.state = PropertyDelete; - event.u.property.atom = pProp->propertyName; - event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); - } - - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - if (len) - { - switch (reply.format) { - case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break; - case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break; - default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break; - } - WriteSwappedDataToClient(client, len, - (char *)pProp->data + ind); - } - - if (stuff->delete && (reply.bytesAfter == 0)) - { /* delete the Property */ -#ifdef LBX - if (pProp->tag_id) - TagDeleteTag(pProp->tag_id); -#endif - if (prevProp == (PropertyPtr)NULL) /* takes care of head */ - { - if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } - else - prevProp->next = pProp->next; - xfree(pProp->data); - xfree(pProp); - } - return(client->noClientException); -} - -int -ProcListProperties(ClientPtr client) -{ - Atom *pAtoms = NULL, *temppAtoms; - xListPropertiesReply xlpr; - int numProps = 0; - WindowPtr pWin; - PropertyPtr pProp; - REQUEST(xResourceReq); - - REQUEST_SIZE_MATCH(xResourceReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - - pProp = wUserProps (pWin); - while (pProp) - { - pProp = pProp->next; - numProps++; - } - if (numProps) - if(!(pAtoms = (Atom *)ALLOCATE_LOCAL(numProps * sizeof(Atom)))) - return(BadAlloc); - - xlpr.type = X_Reply; - xlpr.nProperties = numProps; - xlpr.length = (numProps * sizeof(Atom)) >> 2; - xlpr.sequenceNumber = client->sequence; - pProp = wUserProps (pWin); - temppAtoms = pAtoms; - while (pProp) - { - *temppAtoms++ = pProp->propertyName; - pProp = pProp->next; - } - WriteReplyToClient(client, sizeof(xGenericReply), &xlpr); - if (numProps) - { - client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write; - WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); - DEALLOCATE_LOCAL(pAtoms); - } - return(client->noClientException); -} - -int -ProcDeleteProperty(register ClientPtr client) -{ - WindowPtr pWin; - REQUEST(xDeletePropertyReq); - int result; - - REQUEST_SIZE_MATCH(xDeletePropertyReq); - UpdateCurrentTime(); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityWriteAccess); - if (!pWin) - return(BadWindow); - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return (BadAtom); - } - -#ifdef XCSECURITY - switch(SecurityCheckPropertyAccess(client, pWin, stuff->property, - SecurityDestroyAccess)) - { - case SecurityErrorOperation: - client->errorValue = stuff->property; - return BadAtom;; - case SecurityIgnoreOperation: - return Success; - } -#endif - - result = DeleteProperty(pWin, stuff->property); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.NX.original deleted file mode 100644 index 89e790135..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.NX.original +++ /dev/null @@ -1,3861 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/render/render.c,v 1.12 2005/08/28 19:47:39 ajax Exp $ */ -/* - * $XFree86: xc/programs/Xserver/render/render.c,v 1.27tsi Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#define NEED_REPLIES -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "colormapst.h" -#include "extnsionst.h" -#include "servermd.h" -#include -#include -#include -#include "cursorstr.h" -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#if !defined(UINT32_MAX) -#define UINT32_MAX 0xffffffffU -#endif - -#include "NXpicturestr.h" -#include "NXglyphstr.h" - -#include "Trap.h" - -#include "Render.h" -#include "Pixmaps.h" -#include "Options.h" -#include "Screen.h" -#include "Cursor.h" - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -#ifdef TEST -#include "Literals.h" -#endif - -/* - * From NXmiglyph.c. - */ - -void miGlyphExtents(int nlist, GlyphListPtr list, - GlyphPtr *glyphs, BoxPtr extents); - -/* - * From NXmitrap.c. - */ - -void miTrapezoidBounds (int ntrap, xTrapezoid *traps, BoxPtr box); - -/* - * Functions from Render.c. - */ - -int nxagentCursorSaveRenderInfo(ScreenPtr, CursorPtr); -void nxagentCursorPostSaveRenderInfo(CursorPtr, ScreenPtr, PicturePtr, int, int); -int nxagentRenderRealizeCursor(ScreenPtr, CursorPtr); -int nxagentCreatePicture(PicturePtr, Mask); -void nxagentChangePicture(PicturePtr, Mask); -int nxagentChangePictureClip(PicturePtr, int, int, xRectangle *, int, int); -void nxagentComposite(CARD8, PicturePtr, PicturePtr, PicturePtr, INT16, INT16, - INT16, INT16, INT16, INT16, CARD16, CARD16); -void nxagentCompositeRects(CARD8, PicturePtr, xRenderColor *, int, xRectangle *); -void nxagentCreateGlyphSet(GlyphSetPtr glyphSet); -void nxagentReferenceGlyphSet(GlyphSetPtr glyphSet); -void nxagentFreeGlyphs(GlyphSetPtr glyphSet, CARD32 *gids, int nglyph); -void nxagentFreeGlyphSet(GlyphSetPtr glyphSet); -void nxagentSetPictureTransform(PicturePtr pPicture, pointer transform); -void nxagentSetPictureFilter(PicturePtr pPicture, char *filter, int name_size, - pointer params, int nparams); -void nxagentTrapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst, PictFormatPtr maskFormat, - INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid *traps); - -void nxagentRenderCreateSolidFill(PicturePtr pPicture, xRenderColor *color); - -void nxagentRenderCreateLinearGradient(PicturePtr pPicture, xPointFixed *p1, - xPointFixed *p2, int nStops, - xFixed *stops, - xRenderColor *colors); - -void nxagentRenderCreateRadialGradient(PicturePtr pPicture, xPointFixed *inner, - xPointFixed *outer, - xFixed innerRadius, - xFixed outerRadius, - int nStops, - xFixed *stops, - xRenderColor *colors); - -void nxagentRenderCreateConicalGradient(PicturePtr pPicture, - xPointFixed *center, - xFixed angle, int nStops, - xFixed *stops, - xRenderColor *colors); - - -/* - * The void pointer is actually a XGlyphElt8. - */ - -void nxagentGlyphs(CARD8, PicturePtr, PicturePtr, PictFormatPtr, - INT16, INT16, int, void *, int, GlyphPtr *); - -static int ProcRenderQueryVersion (ClientPtr pClient); -static int ProcRenderQueryPictFormats (ClientPtr pClient); -static int ProcRenderQueryPictIndexValues (ClientPtr pClient); -static int ProcRenderQueryDithers (ClientPtr pClient); -static int ProcRenderCreatePicture (ClientPtr pClient); -static int ProcRenderChangePicture (ClientPtr pClient); -static int ProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int ProcRenderFreePicture (ClientPtr pClient); -static int ProcRenderComposite (ClientPtr pClient); -static int ProcRenderScale (ClientPtr pClient); -static int ProcRenderTrapezoids (ClientPtr pClient); -static int ProcRenderTriangles (ClientPtr pClient); -static int ProcRenderTriStrip (ClientPtr pClient); -static int ProcRenderTriFan (ClientPtr pClient); -static int ProcRenderColorTrapezoids (ClientPtr pClient); -static int ProcRenderColorTriangles (ClientPtr pClient); -static int ProcRenderTransform (ClientPtr pClient); -static int ProcRenderCreateGlyphSet (ClientPtr pClient); -static int ProcRenderReferenceGlyphSet (ClientPtr pClient); -static int ProcRenderFreeGlyphSet (ClientPtr pClient); -static int ProcRenderAddGlyphs (ClientPtr pClient); -static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int ProcRenderFreeGlyphs (ClientPtr pClient); -static int ProcRenderCompositeGlyphs (ClientPtr pClient); -static int ProcRenderFillRectangles (ClientPtr pClient); -static int ProcRenderCreateCursor (ClientPtr pClient); -static int ProcRenderSetPictureTransform (ClientPtr pClient); -static int ProcRenderQueryFilters (ClientPtr pClient); -static int ProcRenderSetPictureFilter (ClientPtr pClient); -static int ProcRenderCreateAnimCursor (ClientPtr pClient); -static int ProcRenderAddTraps (ClientPtr pClient); -static int ProcRenderCreateSolidFill (ClientPtr pClient); -static int ProcRenderCreateLinearGradient (ClientPtr pClient); -static int ProcRenderCreateRadialGradient (ClientPtr pClient); -static int ProcRenderCreateConicalGradient (ClientPtr pClient); - -static int ProcRenderDispatch (ClientPtr pClient); - -static int SProcRenderQueryVersion (ClientPtr pClient); -static int SProcRenderQueryPictFormats (ClientPtr pClient); -static int SProcRenderQueryPictIndexValues (ClientPtr pClient); -static int SProcRenderQueryDithers (ClientPtr pClient); -static int SProcRenderCreatePicture (ClientPtr pClient); -static int SProcRenderChangePicture (ClientPtr pClient); -static int SProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int SProcRenderFreePicture (ClientPtr pClient); -static int SProcRenderComposite (ClientPtr pClient); -static int SProcRenderScale (ClientPtr pClient); -static int SProcRenderTrapezoids (ClientPtr pClient); -static int SProcRenderTriangles (ClientPtr pClient); -static int SProcRenderTriStrip (ClientPtr pClient); -static int SProcRenderTriFan (ClientPtr pClient); -static int SProcRenderColorTrapezoids (ClientPtr pClient); -static int SProcRenderColorTriangles (ClientPtr pClient); -static int SProcRenderTransform (ClientPtr pClient); -static int SProcRenderCreateGlyphSet (ClientPtr pClient); -static int SProcRenderReferenceGlyphSet (ClientPtr pClient); -static int SProcRenderFreeGlyphSet (ClientPtr pClient); -static int SProcRenderAddGlyphs (ClientPtr pClient); -static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int SProcRenderFreeGlyphs (ClientPtr pClient); -static int SProcRenderCompositeGlyphs (ClientPtr pClient); -static int SProcRenderFillRectangles (ClientPtr pClient); -static int SProcRenderCreateCursor (ClientPtr pClient); -static int SProcRenderSetPictureTransform (ClientPtr pClient); -static int SProcRenderQueryFilters (ClientPtr pClient); -static int SProcRenderSetPictureFilter (ClientPtr pClient); -static int SProcRenderCreateAnimCursor (ClientPtr pClient); -static int SProcRenderAddTraps (ClientPtr pClient); -static int SProcRenderCreateSolidFill (ClientPtr pClient); -static int SProcRenderCreateLinearGradient (ClientPtr pClient); -static int SProcRenderCreateRadialGradient (ClientPtr pClient); -static int SProcRenderCreateConicalGradient (ClientPtr pClient); - -static int SProcRenderDispatch (ClientPtr pClient); - -int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = { - ProcRenderQueryVersion, - ProcRenderQueryPictFormats, - ProcRenderQueryPictIndexValues, - ProcRenderQueryDithers, - ProcRenderCreatePicture, - ProcRenderChangePicture, - ProcRenderSetPictureClipRectangles, - ProcRenderFreePicture, - ProcRenderComposite, - ProcRenderScale, - ProcRenderTrapezoids, - ProcRenderTriangles, - ProcRenderTriStrip, - ProcRenderTriFan, - ProcRenderColorTrapezoids, - ProcRenderColorTriangles, - ProcRenderTransform, - ProcRenderCreateGlyphSet, - ProcRenderReferenceGlyphSet, - ProcRenderFreeGlyphSet, - ProcRenderAddGlyphs, - ProcRenderAddGlyphsFromPicture, - ProcRenderFreeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderFillRectangles, - ProcRenderCreateCursor, - ProcRenderSetPictureTransform, - ProcRenderQueryFilters, - ProcRenderSetPictureFilter, - ProcRenderCreateAnimCursor, - ProcRenderAddTraps, - ProcRenderCreateSolidFill, - ProcRenderCreateLinearGradient, - ProcRenderCreateRadialGradient, - ProcRenderCreateConicalGradient -}; - -int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = { - SProcRenderQueryVersion, - SProcRenderQueryPictFormats, - SProcRenderQueryPictIndexValues, - SProcRenderQueryDithers, - SProcRenderCreatePicture, - SProcRenderChangePicture, - SProcRenderSetPictureClipRectangles, - SProcRenderFreePicture, - SProcRenderComposite, - SProcRenderScale, - SProcRenderTrapezoids, - SProcRenderTriangles, - SProcRenderTriStrip, - SProcRenderTriFan, - SProcRenderColorTrapezoids, - SProcRenderColorTriangles, - SProcRenderTransform, - SProcRenderCreateGlyphSet, - SProcRenderReferenceGlyphSet, - SProcRenderFreeGlyphSet, - SProcRenderAddGlyphs, - SProcRenderAddGlyphsFromPicture, - SProcRenderFreeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderFillRectangles, - SProcRenderCreateCursor, - SProcRenderSetPictureTransform, - SProcRenderQueryFilters, - SProcRenderSetPictureFilter, - SProcRenderCreateAnimCursor, - SProcRenderAddTraps, - SProcRenderCreateSolidFill, - SProcRenderCreateLinearGradient, - SProcRenderCreateRadialGradient, - SProcRenderCreateConicalGradient -}; - -static void -RenderResetProc (ExtensionEntry *extEntry); - -#if 0 -static CARD8 RenderReqCode; -#endif -int RenderErrBase; -int RenderClientPrivateIndex; - -typedef struct _RenderClient { - int major_version; - int minor_version; -} RenderClientRec, *RenderClientPtr; - -#define GetRenderClient(pClient) ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr) - -static void -RenderClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - RenderClientPtr pRenderClient = GetRenderClient (pClient); - - pRenderClient->major_version = 0; - pRenderClient->minor_version = 0; -} - -void -RenderExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (!PictureType) - return; - if (!PictureFinishInit ()) - return; - RenderClientPrivateIndex = AllocateClientPrivateIndex (); - if (!AllocateClientPrivate (RenderClientPrivateIndex, - sizeof (RenderClientRec))) - return; - if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0)) - return; - - extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors, - ProcRenderDispatch, SProcRenderDispatch, - RenderResetProc, StandardMinorOpcode); - if (!extEntry) - return; -#if 0 - RenderReqCode = (CARD8) extEntry->base; -#endif - RenderErrBase = extEntry->errorBase; -} - -static void -RenderResetProc (ExtensionEntry *extEntry) -{ - ResetPicturePrivateIndex(); - ResetGlyphSetPrivateIndex(); -} - -static int -ProcRenderQueryVersion (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryVersionReply rep; - register int n; - REQUEST(xRenderQueryVersionReq); - - pRenderClient->major_version = stuff->majorVersion; - pRenderClient->minor_version = stuff->minorVersion; - - REQUEST_SIZE_MATCH(xRenderQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = nxagentRenderVersionMajor; - rep.minorVersion = nxagentRenderVersionMinor; - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.majorVersion, n); - swapl(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -#if 0 -static int -VisualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - DepthPtr pDepth; - int d, v; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - for (v = 0; v < pDepth->numVids; v++) - { - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - } - return 0; -} -#endif - -static VisualPtr -findVisual (ScreenPtr pScreen, VisualID vid) -{ - VisualPtr pVisual; - int v; - - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = pScreen->visuals + v; - if (pVisual->vid == vid) - return pVisual; - } - return 0; -} - -extern char *ConnectionInfo; - -static int -ProcRenderQueryPictFormats (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryPictFormatsReply *reply; - xPictScreen *pictScreen; - xPictDepth *pictDepth; - xPictVisual *pictVisual; - xPictFormInfo *pictForm; - CARD32 *pictSubpixel; - ScreenPtr pScreen; - VisualPtr pVisual; - DepthPtr pDepth; - int v, d; - PictureScreenPtr ps; - PictFormatPtr pFormat; - int nformat; - int ndepth; - int nvisual; - int rlength; - int s; - int n; - int numScreens; - int numSubpixel; - - extern int nxagentAlphaEnabled; -/* REQUEST(xRenderQueryPictFormatsReq); */ - - REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq); - -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#else - numScreens = screenInfo.numScreens; -#endif - ndepth = nformat = nvisual = 0; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - ++ndepth; - - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual)) - ++nvisual; - } - } - ps = GetPictureScreenIfSet(pScreen); - if (ps) - nformat += ps->nformats; - } - if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6) - numSubpixel = 0; - else - numSubpixel = numScreens; - - rlength = (sizeof (xRenderQueryPictFormatsReply) + - nformat * sizeof (xPictFormInfo) + - numScreens * sizeof (xPictScreen) + - ndepth * sizeof (xPictDepth) + - nvisual * sizeof (xPictVisual) + - numSubpixel * sizeof (CARD32)); - reply = (xRenderQueryPictFormatsReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numFormats = nformat; - reply->numScreens = numScreens; - reply->numDepths = ndepth; - reply->numVisuals = nvisual; - reply->numSubpixel = numSubpixel; - - pictForm = (xPictFormInfo *) (reply + 1); - - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (nformat = 0, pFormat = ps->formats; - nformat < ps->nformats; - nformat++, pFormat++) - { - pictForm->id = pFormat->id; - pictForm->type = pFormat->type; - pictForm->depth = pFormat->depth; - pictForm->direct.red = pFormat->direct.red; - pictForm->direct.redMask = pFormat->direct.redMask; - pictForm->direct.green = pFormat->direct.green; - pictForm->direct.greenMask = pFormat->direct.greenMask; - pictForm->direct.blue = pFormat->direct.blue; - pictForm->direct.blueMask = pFormat->direct.blueMask; - pictForm->direct.alpha = nxagentAlphaEnabled ? pFormat->direct.alpha : 0; - pictForm->direct.alphaMask = pFormat->direct.alphaMask; - if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap) - pictForm->colormap = pFormat->index.pColormap->mid; - else - pictForm->colormap = None; - if (client->swapped) - { - swapl (&pictForm->id, n); - swaps (&pictForm->direct.red, n); - swaps (&pictForm->direct.redMask, n); - swaps (&pictForm->direct.green, n); - swaps (&pictForm->direct.greenMask, n); - swaps (&pictForm->direct.blue, n); - swaps (&pictForm->direct.blueMask, n); - swaps (&pictForm->direct.alpha, n); - swaps (&pictForm->direct.alphaMask, n); - swapl (&pictForm->colormap, n); - } - pictForm++; - } - } - } - - pictScreen = (xPictScreen *) pictForm; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - pictDepth = (xPictDepth *) (pictScreen + 1); - ndepth = 0; - for (d = 0; d < pScreen->numDepths; d++) - { - pictVisual = (xPictVisual *) (pictDepth + 1); - pDepth = pScreen->allowedDepths + d; - - nvisual = 0; - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && (pFormat = PictureMatchVisual (pScreen, - pDepth->depth, - pVisual))) - { - pictVisual->visual = pVisual->vid; - pictVisual->format = pFormat->id; - if (client->swapped) - { - swapl (&pictVisual->visual, n); - swapl (&pictVisual->format, n); - } - pictVisual++; - nvisual++; - } - } - pictDepth->depth = pDepth->depth; - pictDepth->nPictVisuals = nvisual; - if (client->swapped) - { - swaps (&pictDepth->nPictVisuals, n); - } - ndepth++; - pictDepth = (xPictDepth *) pictVisual; - } - pictScreen->nDepth = ndepth; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - pictScreen->fallback = ps->fallback->id; - else - pictScreen->fallback = 0; - if (client->swapped) - { - swapl (&pictScreen->nDepth, n); - swapl (&pictScreen->fallback, n); - } - pictScreen = (xPictScreen *) pictDepth; - } - pictSubpixel = (CARD32 *) pictScreen; - - for (s = 0; s < numSubpixel; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - *pictSubpixel = ps->subpixel; - else - *pictSubpixel = SubPixelUnknown; - if (client->swapped) - { - swapl (pictSubpixel, n); - } - ++pictSubpixel; - } - - if (client->swapped) - { - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numFormats, n); - swapl (&reply->numScreens, n); - swapl (&reply->numDepths, n); - swapl (&reply->numVisuals, n); - swapl (&reply->numSubpixel, n); - } - WriteToClient(client, rlength, (char *) reply); - xfree (reply); - return client->noClientException; -} - -static int -ProcRenderQueryPictIndexValues (ClientPtr client) -{ - PictFormatPtr pFormat; - int num; - int rlength; - int i, n; - REQUEST(xRenderQueryPictIndexValuesReq); - xRenderQueryPictIndexValuesReply *reply; - xIndexValue *values; - - REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq); - - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->type != PictTypeIndexed) - { - client->errorValue = stuff->format; - return BadMatch; - } - num = pFormat->index.nvalues; - rlength = (sizeof (xRenderQueryPictIndexValuesReply) + - num * sizeof(xIndexValue)); - reply = (xRenderQueryPictIndexValuesReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numIndexValues = num; - - values = (xIndexValue *) (reply + 1); - - memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue)); - - if (client->swapped) - { - for (i = 0; i < num; i++) - { - swapl (&values[i].pixel, n); - swaps (&values[i].red, n); - swaps (&values[i].green, n); - swaps (&values[i].blue, n); - swaps (&values[i].alpha, n); - } - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numIndexValues, n); - } - - WriteToClient(client, rlength, (char *) reply); - xfree(reply); - return (client->noClientException); -} - -static int -ProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreatePicture (ClientPtr client) -{ - PicturePtr pPicture; - DrawablePtr pDrawable; - PictFormatPtr pFormat; - int len; - int error; - REQUEST(xRenderCreatePictureReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, - SecurityWriteAccess); - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->depth != pDrawable->depth) - return BadMatch; - len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - pPicture = CreatePicture (stuff->pid, - pDrawable, - pFormat, - stuff->mask, - (XID *) (stuff + 1), - client, - &error); - if (!pPicture) - return error; - nxagentCreatePicture(pPicture, stuff -> mask); - - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int -ProcRenderChangePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderChangePictureReq); - int len; - int error; - - REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - error = ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1), - (DevUnion *) 0, client); - - nxagentChangePicture(pPicture, stuff->mask); - - return error; -} - -static int -ProcRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - PicturePtr pPicture; - int nr; - int result; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pPicture->pDrawable) - return BadDrawable; - - /* - * The original code used sizeof(xRenderChangePictureReq). - * This was harmless, as both structures have the same size. - * - * nr = (client->req_len << 2) - sizeof(xRenderChangePictureReq); - */ - nr = (client->req_len << 2) - sizeof(xRenderSetPictureClipRectanglesReq); - if (nr & 4) - return BadLength; - nr >>= 3; - result = SetPictureClipRects (pPicture, - stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *) &stuff[1]); - nxagentChangePictureClip (pPicture, - CT_NONE, - nr, - (xRectangle *) &stuff[1], - (int)stuff -> xOrigin, - (int)stuff -> yOrigin); - - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderFreePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - - FreeResource (stuff->picture, RT_NONE); - return(client->noClientException); -} - -static Bool -PictOpValid (CARD8 op) -{ - if (/*PictOpMinimum <= op && */ op <= PictOpMaximum) - return TRUE; - if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum) - return TRUE; - if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum) - return TRUE; - return FALSE; -} - -/* - * Check if both pictures have drawables which are - * virtual pixmaps. See the corresponding define - * in NXpicture.c - */ - -#define NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - -#ifdef NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - -#define nxagentCompositePredicate(pSrc, pDst) TRUE - -#else - -/* - * This is still under development. The final - * goal is to let pictures point to the real - * pixmaps instead of pointing to virtuals. - */ - -int nxagentCompositePredicate(PicturePtr pSrc, PicturePtr pDst) -{ - PixmapPtr pPixmap1; - PixmapPtr pPixmap2; - - pPixmap1 = (pSrc -> pDrawable -> type == DRAWABLE_PIXMAP ? - ((PixmapPtr) pSrc -> pDrawable) : NULL); - - pPixmap2 = (pDst -> pDrawable -> type == DRAWABLE_PIXMAP ? - ((PixmapPtr) pDst -> pDrawable) : NULL); - - if (pPixmap1 == NULL || pPixmap2 == NULL) - { - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 0.\n"); - #endif - - return FALSE; - } - else - { - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 1.\n"); - #endif - - if (nxagentPixmapIsVirtual(pPixmap1) == 1 && - nxagentPixmapIsVirtual(pPixmap2) == 1) - { - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 2.\n"); - #endif - - return TRUE; - } - } - - #ifdef TEST - fprintf(stderr, "nxagentCompositePredicate: Case 3.\n"); - #endif - - return FALSE; -} - -#endif - -static int -ProcRenderComposite (ClientPtr client) -{ - PicturePtr pSrc, pMask, pDst; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_ALPHA (pMask, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); -/* -FIXME: Imported change from newest version of Xorg. Changed pSrc to pDst. - - if ((pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) || - (pMask && pMask->pDrawable && pSrc->pDrawable->pScreen != pMask->pDrawable->pScreen)) - return BadMatch; -*/ - if ((pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) || - (pMask && pMask->pDrawable && pDst->pDrawable->pScreen != pMask->pDrawable->pScreen)) - return BadMatch; - - ValidatePicture (pSrc); - if (pMask) - ValidatePicture (pMask); - ValidatePicture (pDst); - - #ifdef NXAGENT_PICTURE_ALWAYS_POINTS_TO_VIRTUAL - - if (nxagentCompositePredicate(pSrc, pDst)) - { - #ifdef TEST - fprintf(stderr, "ProcRenderComposite: Going to composite with " - "source at [%p] mask at [%p] and destination at [%p].\n", - (void *) pSrc, (void *) pMask, (void *) pDst); - #endif - - CompositePicture (stuff->op, - pSrc, - pMask, - pDst, - stuff->xSrc, - stuff->ySrc, - stuff->xMask, - stuff->yMask, - stuff->xDst, - stuff->yDst, - stuff->width, - stuff->height); - } - - #else - - if (pSrc -> pDrawable -> type == DRAWABLE_PIXMAP && - pDst -> pDrawable -> type == DRAWABLE_PIXMAP && - (!pMask || pMask -> pDrawable -> type == DRAWABLE_PIXMAP)) - { - PixmapPtr pVirtualPixmapSrc; - PixmapPtr pVirtualPixmapDst; - PixmapPtr pVirtualPixmapMask; - - PicturePtr pVirtualPictureSrc; - PicturePtr pVirtualPictureDst; - PicturePtr pVirtualPictureMask; - - pVirtualPixmapSrc = (PixmapPtr) pSrc -> pDrawable; - pVirtualPictureSrc = nxagentPixmapPriv(pVirtualPixmapSrc) -> pPicture; - - pVirtualPixmapDst = (PixmapPtr) pDst -> pDrawable; - pVirtualPictureDst = nxagentPixmapPriv(pVirtualPixmapDst) -> pPicture; - - if (pMask) - { - pVirtualPixmapMask = (PixmapPtr) pMask -> pDrawable; - pVirtualPictureMask = nxagentPixmapPriv(pVirtualPixmapMask) -> pPicture; - } - else - { - pVirtualPixmapMask = NULL; - pVirtualPictureMask = NULL; - } - - if (pVirtualPictureSrc && pVirtualPictureDst) - { - #ifdef TEST - fprintf(stderr, "ProcRenderComposite: Going to composite with " - "source at [%p] mask at [%p] and destination at [%p].\n", - (void *) pVirtualPixmapSrc, (void *) pVirtualPixmapMask, - (void *) pVirtualPixmapDst); - #endif - - CompositePicture (stuff->op, - pVirtualPictureSrc, - pVirtualPictureMask, - pVirtualPictureDst, - stuff->xSrc, - stuff->ySrc, - stuff->xMask, - stuff->yMask, - stuff->xDst, - stuff->yDst, - stuff->width, - stuff->height); - } - } - - #endif - - nxagentComposite (stuff -> op, - pSrc, - pMask, - pDst, - stuff -> xSrc, - stuff -> ySrc, - stuff -> xMask, - stuff -> yMask, - stuff -> xDst, - stuff -> yDst, - stuff -> width, - stuff -> height); - - return Success; -} - -static int -ProcRenderScale (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTrapezoids (ClientPtr client) -{ - int ntraps; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); - if (ntraps % sizeof (xTrapezoid)) - return BadLength; - ntraps /= sizeof (xTrapezoid); - if (ntraps) - { - if (pFormat != NULL) - { - nxagentTrapezoidExtents = (BoxPtr) xalloc(sizeof(BoxRec)); - - miTrapezoidBounds (ntraps, (xTrapezoid *) &stuff[1], nxagentTrapezoidExtents); - } - - if (nxagentCompositePredicate(pSrc, pDst) == 1) - { - CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntraps, (xTrapezoid *) &stuff[1]); - } - - nxagentTrapezoids (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntraps, (xTrapezoid *) &stuff[1]); - - if (nxagentTrapezoidExtents != NullBox) - { - xfree(nxagentTrapezoidExtents); - - nxagentTrapezoidExtents = NullBox; - } - } - - return client->noClientException; -} - -static int -ProcRenderTriangles (ClientPtr client) -{ - int ntris; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq); - if (ntris % sizeof (xTriangle)) - return BadLength; - ntris /= sizeof (xTriangle); - if (ntris) - CompositeTriangles (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntris, (xTriangle *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriStrip (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriStrip (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriFan (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriFan (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreateGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - PictFormatPtr format; - int f; - REQUEST(xRenderCreateGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - format = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!format) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - switch (format->depth) { - case 1: - f = GlyphFormat1; - break; - case 4: - f = GlyphFormat4; - break; - case 8: - f = GlyphFormat8; - break; - case 16: - f = GlyphFormat16; - break; - case 32: - f = GlyphFormat32; - break; - default: - return BadMatch; - } - if (format->type != PictTypeDirect) - return BadMatch; - glyphSet = AllocateGlyphSet (f, format); - if (!glyphSet) - return BadAlloc; - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - - nxagentCreateGlyphSet(glyphSet); - - return Success; -} - -static int -ProcRenderReferenceGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderReferenceGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->existing, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->existing; - return RenderErrBase + BadGlyphSet; - } - glyphSet->refcnt++; - - nxagentReferenceGlyphSet(glyphSet); - - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - return client->noClientException; -} - -#define NLOCALDELTA 64 -#define NLOCALGLYPH 256 - -static int -ProcRenderFreeGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderFreeGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityDestroyAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - nxagentFreeGlyphSet(glyphSet); - - FreeResource (stuff->glyphset, RT_NONE); - return client->noClientException; -} - -typedef struct _GlyphNew { - Glyph id; - GlyphPtr glyph; -} GlyphNewRec, *GlyphNewPtr; - -static int -ProcRenderAddGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderAddGlyphsReq); - GlyphNewRec glyphsLocal[NLOCALGLYPH]; - GlyphNewPtr glyphsBase, glyphs; - GlyphPtr glyph = NULL; - int remain, nglyphs; - CARD32 *gids; - xGlyphInfo *gi; - CARD8 *bits; - int size; - int err = BadAlloc; - - int totSizeImages; - - REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - nglyphs = stuff->nglyphs; - if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec)) - return BadAlloc; - - if (nglyphs <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphNewPtr) Xalloc (nglyphs * sizeof (GlyphNewRec)); - if (!glyphsBase) - return BadAlloc; - } - - remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq); - - glyphs = glyphsBase; - - totSizeImages = 0; - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + nglyphs); - bits = (CARD8 *) (gi + nglyphs); - remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs; - - while (remain >= 0 && nglyphs) - { - glyph = AllocateGlyph (gi, glyphSet->fdepth); - if (!glyph) - { - err = BadAlloc; - goto bail; - } - - glyphs->glyph = glyph; - glyphs->id = *gids; - - size = glyph->size - sizeof (xGlyphInfo); - if (remain < size) - break; - memcpy ((CARD8 *) (glyph + 1), bits, size); - - if (size & 3) - size += 4 - (size & 3); - bits += size; - totSizeImages += size; - remain -= size; - gi++; - gids++; - glyphs++; - nglyphs--; - } - - if (nglyphs || remain) - { - err = BadLength; - goto bail; - } - nglyphs = stuff->nglyphs; - if (!ResizeGlyphSet (glyphSet, nglyphs)) - { - err = BadAlloc; - goto bail; - } - glyphs = glyphsBase; - while (nglyphs--) { - AddGlyph (glyphSet, glyphs->glyph, glyphs->id); - glyphs++; - } - - if (glyphsBase != glyphsLocal) - Xfree (glyphsBase); - return client->noClientException; -bail: - while (glyphs != glyphsBase) - { - --glyphs; - xfree (glyphs->glyph); - } - if (glyphsBase != glyphsLocal) - Xfree (glyphsBase); - return err; -} - -static int -ProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderFreeGlyphs (ClientPtr client) -{ - REQUEST(xRenderFreeGlyphsReq); - GlyphSetPtr glyphSet; - int nglyph; - CARD32 *gids; - CARD32 glyph; - - REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2; - gids = (CARD32 *) (stuff + 1); - - nxagentFreeGlyphs(glyphSet, gids, nglyph); - - while (nglyph-- > 0) - { - glyph = *gids++; - if (!DeleteGlyph (glyphSet, glyph)) - { - client->errorValue = glyph; - return RenderErrBase + BadGlyph; - } - } - return client->noClientException; -} - -typedef struct XGlyphElt8{ - GlyphSet glyphset; - _Xconst char *chars; - int nchars; - int xOff; - int yOff; -} XGlyphElt8; - -static int -ProcRenderCompositeGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - GlyphSet gs; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - GlyphListRec listsLocal[NLOCALDELTA]; - GlyphListPtr lists, listsBase; - GlyphPtr glyphsLocal[NLOCALGLYPH]; - Glyph glyph; - GlyphPtr *glyphs, *glyphsBase; - xGlyphElt *elt; - CARD8 *buffer, *end; - int nglyph; - int nlist; - int space; - int size; - int n; - - XGlyphElt8 *elements, *elementsBase; - - REQUEST(xRenderCompositeGlyphsReq); - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - nglyph = 0; - nlist = 0; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - buffer += 4; - } - else - { - nlist++; - nglyph += elt->len; - space = size * elt->len; - if (space & 3) - space += 4 - (space & 3); - buffer += space; - } - } - if (nglyph <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphPtr *) ALLOCATE_LOCAL (nglyph * sizeof (GlyphPtr)); - if (!glyphsBase) - return BadAlloc; - } - if (nlist <= NLOCALDELTA) - listsBase = listsLocal; - else - { - listsBase = (GlyphListPtr) ALLOCATE_LOCAL (nlist * sizeof (GlyphListRec)); - if (!listsBase) - return BadAlloc; - } - - elementsBase = xalloc(nlist * sizeof(XGlyphElt8)); - if (!elementsBase) - return BadAlloc; - - buffer = (CARD8 *) (stuff + 1); - glyphs = glyphsBase; - lists = listsBase; - elements = elementsBase; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - #ifdef DEBUG - fprintf(stderr, "ProcRenderCompositeGlyphs: Glyphset change with base size [%d].\n", - size); - #endif - - if (buffer + sizeof (GlyphSet) < end) - { - memcpy(&gs, buffer, sizeof(GlyphSet)); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - gs, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = gs; - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - return RenderErrBase + BadGlyphSet; - } - } - buffer += 4; - } - else - { - lists->xOff = elt->deltax; - lists->yOff = elt->deltay; - lists->format = glyphSet->format; - lists->len = 0; - - if (glyphSet -> remoteID == 0) - { - #ifdef TEST - fprintf(stderr, "ProcRenderCompositeGlyphs: Going to reconnect glyphset at [%p].\n", - (void *) glyphSet); - #endif - - nxagentReconnectGlyphSet(glyphSet, (XID) 0, (void*) NULL); - } - - elements -> glyphset = glyphSet -> remoteID; - elements -> chars = (char *) buffer; - elements -> nchars = elt->len; - elements -> xOff = elt->deltax; - elements -> yOff = elt->deltay; - n = elt->len; - while (n--) - { - if (buffer + size <= end) - { - switch (size) { - case 1: - glyph = *((CARD8 *)buffer); break; - case 2: - glyph = *((CARD16 *)buffer); break; - case 4: - default: - glyph = *((CARD32 *)buffer); break; - } - if ((*glyphs = FindGlyph (glyphSet, glyph))) - { - lists->len++; - glyphs++; - } - } - buffer += size; - } - space = size * elt->len; - if (space & 3) - buffer += 4 - (space & 3); - lists++; - elements++; - } - } - if (buffer > end) - return BadLength; - - /* - * We need to know the glyphs extents to synchronize - * the drawables involved in the composite text ope- - * ration. Also we need to synchronize only the back- - * ground of the text we are going to render, so the - * operations on the framebuffer must be executed - * after the X requests. - */ - - nxagentGlyphsExtents = (BoxPtr) xalloc(sizeof(BoxRec)); - - miGlyphExtents(nlist, listsBase, glyphsBase, nxagentGlyphsExtents); - - nxagentGlyphs(stuff -> op, - pSrc, - pDst, - pFormat, - stuff -> xSrc, - stuff -> ySrc, - nlist, - elementsBase, - size, - glyphsBase); - - if (nxagentCompositePredicate(pSrc, pDst) == 1) - { - #ifdef TEST - fprintf(stderr, "ProcRenderCompositeGlyphs: Going to composite glyphs with " - "source at [%p] and destination at [%p].\n", - (void *) pSrc, (void *) pDst); - #endif - - CompositeGlyphs(stuff -> op, - pSrc, - pDst, - pFormat, - stuff -> xSrc, - stuff -> ySrc, - nlist, - listsBase, - glyphsBase); - } - - xfree(nxagentGlyphsExtents); - nxagentGlyphsExtents = NullBox; - - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - - xfree(elementsBase); - - return client->noClientException; -} - -static int -ProcRenderFillRectangles (ClientPtr client) -{ - PicturePtr pDst; - int things; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - - things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq); - if (things & 4) - return(BadLength); - things >>= 3; - - CompositeRects (stuff->op, - pDst, - &stuff->color, - things, - (xRectangle *) &stuff[1]); - - ValidatePicture (pDst); - nxagentCompositeRects(stuff -> op, - pDst, - &stuff -> color, - things, - (xRectangle *) &stuff[1]); - - return client->noClientException; -} - -static void -SetBit (unsigned char *line, int x, int bit) -{ - unsigned char mask; - - if (screenInfo.bitmapBitOrder == LSBFirst) - mask = (1 << (x & 7)); - else - mask = (0x80 >> (x & 7)); - /* XXX assumes byte order is host byte order */ - line += (x >> 3); - if (bit) - *line |= mask; - else - *line &= ~mask; -} - -#define DITHER_DIM 2 - -static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = { - { 1, 3, }, - { 4, 2, }, -}; - -#define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1) - -static int -ProcRenderCreateCursor (ClientPtr client) -{ - REQUEST(xRenderCreateCursorReq); - PicturePtr pSrc; - ScreenPtr pScreen; - unsigned short width, height; - CARD32 *argbbits, *argb; - unsigned char *srcbits, *srcline; - unsigned char *mskbits, *mskline; - int stride; - int x, y; - int nbytes_mono; - CursorMetricRec cm; - CursorPtr pCursor; - CARD32 twocolor[3]; - int ncolor; - - RealizeCursorProcPtr saveRealizeCursor; - - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - if (!pSrc->pDrawable) - return BadDrawable; - pScreen = pSrc->pDrawable->pScreen; - width = pSrc->pDrawable->width; - height = pSrc->pDrawable->height; - if (height && width > UINT32_MAX/(height*sizeof(CARD32))) - return BadAlloc; - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - argbbits = xalloc (width * height * sizeof (CARD32)); - if (!argbbits) - return (BadAlloc); - - stride = BitmapBytePad(width); - nbytes_mono = stride*height; - srcbits = (unsigned char *)xalloc(nbytes_mono); - if (!srcbits) - { - xfree (argbbits); - return (BadAlloc); - } - mskbits = (unsigned char *)xalloc(nbytes_mono); - if (!mskbits) - { - xfree(argbbits); - xfree(srcbits); - return (BadAlloc); - } - bzero ((char *) mskbits, nbytes_mono); - bzero ((char *) srcbits, nbytes_mono); - - if (pSrc->format == PICT_a8r8g8b8) - { - (*pScreen->GetImage) (pSrc->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - } - else - { - PixmapPtr pPixmap; - PicturePtr pPicture; - PictFormatPtr pFormat; - int error; - - pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8); - if (!pFormat) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadImplementation); - } - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32); - if (!pPixmap) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadAlloc); - } - pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0, - client, &error); - if (!pPicture) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return error; - } - (*pScreen->DestroyPixmap) (pPixmap); - CompositePicture (PictOpSrc, - pSrc, 0, pPicture, - 0, 0, 0, 0, 0, 0, width, height); - (*pScreen->GetImage) (pPicture->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - FreePicture (pPicture, 0); - } - /* - * Check whether the cursor can be directly supported by - * the core cursor code - */ - ncolor = 0; - argb = argbbits; - for (y = 0; ncolor <= 2 && y < height; y++) - { - for (x = 0; ncolor <= 2 && x < width; x++) - { - CARD32 p = *argb++; - CARD32 a = (p >> 24); - - if (a == 0) /* transparent */ - continue; - if (a == 0xff) /* opaque */ - { - int n; - for (n = 0; n < ncolor; n++) - if (p == twocolor[n]) - break; - if (n == ncolor) - twocolor[ncolor++] = p; - } - else - ncolor = 3; - } - } - - /* - * Convert argb image to two plane cursor - */ - srcline = srcbits; - mskline = mskbits; - argb = argbbits; - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - CARD32 p = *argb++; - - if (ncolor <= 2) - { - CARD32 a = ((p >> 24)); - - SetBit (mskline, x, a != 0); - SetBit (srcline, x, a != 0 && p == twocolor[0]); - } - else - { - CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255; - CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255; - CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)]; - /* Set mask from dithered alpha value */ - SetBit(mskline, x, a > d); - /* Set src from dithered intensity value */ - SetBit(srcline, x, a > d && i <= d); - } - } - srcline += stride; - mskline += stride; - } - /* - * Dither to white and black if the cursor has more than two colors - */ - if (ncolor > 2) - { - twocolor[0] = 0xff000000; - twocolor[1] = 0xffffffff; - } - else - { - xfree (argbbits); - argbbits = 0; - } - -#define GetByte(p,s) (((p) >> (s)) & 0xff) -#define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8)) - - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - - /* - * This cursor uses RENDER, so we make sure - * that it is allocated in a way that allows - * the mi and dix layers to handle it but we - * later create it on the server by mirror- - * ing the RENDER operation we got from the - * client. - */ - - saveRealizeCursor = pScreen -> RealizeCursor; - - pScreen -> RealizeCursor = nxagentCursorSaveRenderInfo; - - pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm, - GetColor(twocolor[0], 16), - GetColor(twocolor[0], 8), - GetColor(twocolor[0], 0), - GetColor(twocolor[1], 16), - GetColor(twocolor[1], 8), - GetColor(twocolor[1], 0)); - - pScreen -> RealizeCursor = saveRealizeCursor; - - /* - * Store into the private data members the - * information needed to recreate it at - * reconnection. This is done in two steps - * as in the first step we don't have the - * picture info. - */ - - if (pCursor == NULL) - { - return BadAlloc; - } - - nxagentCursorPostSaveRenderInfo(pCursor, pScreen, pSrc, stuff -> x, stuff -> y); - - nxagentRenderRealizeCursor(pScreen, pCursor); - - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; -} - -static int -ProcRenderSetPictureTransform (ClientPtr client) -{ - REQUEST(xRenderSetPictureTransformReq); - PicturePtr pPicture; - int result; - - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - result = SetPictureTransform (pPicture, (PictTransform *) &stuff->transform); - - nxagentSetPictureTransform(pPicture, &stuff->transform); - - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderQueryFilters (ClientPtr client) -{ - REQUEST (xRenderQueryFiltersReq); - DrawablePtr pDrawable; - xRenderQueryFiltersReply *reply; - int nbytesName; - int nnames; - ScreenPtr pScreen; - PictureScreenPtr ps; - int i, j; - int len; - int total_bytes; - INT16 *aliases; - char *names; - - REQUEST_SIZE_MATCH(xRenderQueryFiltersReq); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, SecurityReadAccess); - - pScreen = pDrawable->pScreen; - nbytesName = 0; - nnames = 0; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (i = 0; i < ps->nfilters; i++) - nbytesName += 1 + strlen (ps->filters[i].name); - for (i = 0; i < ps->nfilterAliases; i++) - nbytesName += 1 + strlen (ps->filterAliases[i].alias); - nnames = ps->nfilters + ps->nfilterAliases; - } - len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2); - total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2); - reply = (xRenderQueryFiltersReply *) xalloc (total_bytes); - if (!reply) - return BadAlloc; - aliases = (INT16 *) (reply + 1); - names = (char *) (aliases + ((nnames + 1) & ~1)); - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = len; - reply->numAliases = nnames; - reply->numFilters = nnames; - if (ps) - { - - /* fill in alias values */ - for (i = 0; i < ps->nfilters; i++) - aliases[i] = FilterAliasNone; - for (i = 0; i < ps->nfilterAliases; i++) - { - for (j = 0; j < ps->nfilters; j++) - if (ps->filterAliases[i].filter_id == ps->filters[j].id) - break; - if (j == ps->nfilters) - { - for (j = 0; j < ps->nfilterAliases; j++) - if (ps->filterAliases[i].filter_id == - ps->filterAliases[j].alias_id) - { - break; - } - if (j == ps->nfilterAliases) - j = FilterAliasNone; - else - j = j + ps->nfilters; - } - aliases[i + ps->nfilters] = j; - } - - /* fill in filter names */ - for (i = 0; i < ps->nfilters; i++) - { - j = strlen (ps->filters[i].name); - *names++ = j; - strncpy (names, ps->filters[i].name, j); - names += j; - } - - /* fill in filter alias names */ - for (i = 0; i < ps->nfilterAliases; i++) - { - j = strlen (ps->filterAliases[i].alias); - *names++ = j; - strncpy (names, ps->filterAliases[i].alias, j); - names += j; - } - } - - if (client->swapped) - { - register int n; - - for (i = 0; i < (int)reply->numAliases; i++) - { - swaps (&aliases[i], n); - } - swaps(&reply->sequenceNumber, n); - swapl(&reply->length, n); - swapl(&reply->numAliases, n); - swapl(&reply->numFilters, n); - } - WriteToClient(client, total_bytes, (char *) reply); - xfree (reply); - - return(client->noClientException); -} - -static int -ProcRenderSetPictureFilter (ClientPtr client) -{ - REQUEST (xRenderSetPictureFilterReq); - PicturePtr pPicture; - int result; - xFixed *params; - int nparams; - char *name; - - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - name = (char *) (stuff + 1); - params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3)); - nparams = ((xFixed *) stuff + client->req_len) - params; - result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams); - - nxagentSetPictureFilter(pPicture, name, stuff->nbytes, params, nparams); - - return result; -} - -static int -ProcRenderCreateAnimCursor (ClientPtr client) -{ - REQUEST(xRenderCreateAnimCursorReq); - CursorPtr *cursors; - CARD32 *deltas; - CursorPtr pCursor; - int ncursor; - xAnimCursorElt *elt; - int i; - int ret; - - REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - if (client->req_len & 1) - return BadLength; - ncursor = (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1; - cursors = xalloc (ncursor * (sizeof (CursorPtr) + sizeof (CARD32))); - if (!cursors) - return BadAlloc; - deltas = (CARD32 *) (cursors + ncursor); - elt = (xAnimCursorElt *) (stuff + 1); - for (i = 0; i < ncursor; i++) - { - cursors[i] = (CursorPtr)SecurityLookupIDByType(client, elt->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursors[i]) - { - xfree (cursors); - client->errorValue = elt->cursor; - return BadCursor; - } - deltas[i] = elt->delay; - elt++; - } - ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor); - xfree (cursors); - if (ret != Success) - return ret; - - nxagentAnimCursorBits = pCursor -> bits; - - for (i = 0; i < MAXSCREENS; i++) - { - pCursor -> devPriv[i] = NULL; - } - - if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - -static int -ProcRenderAddTraps (ClientPtr client) -{ - int ntraps; - PicturePtr pPicture; - REQUEST(xRenderAddTrapsReq); - - REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pPicture->pDrawable) - return BadDrawable; - ntraps = (client->req_len << 2) - sizeof (xRenderAddTrapsReq); - if (ntraps % sizeof (xTrap)) - return BadLength; - ntraps /= sizeof (xTrap); - if (ntraps) - AddTraps (pPicture, - stuff->xOff, stuff->yOff, - ntraps, (xTrap *) &stuff[1]); - return client->noClientException; -} - -static int ProcRenderCreateSolidFill(ClientPtr client) -{ - PicturePtr pPicture; - int error = 0; - REQUEST(xRenderCreateSolidFillReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error); - if (!pPicture) - return error; - /* AGENT SERVER */ - - nxagentRenderCreateSolidFill(pPicture, &stuff -> color); - - /* AGENT SERVER */ - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int ProcRenderCreateLinearGradient (ClientPtr client) -{ - PicturePtr pPicture; - int len; - int error = 0; - xFixed *stops; - xRenderColor *colors; - REQUEST(xRenderCreateLinearGradientReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - stops = (xFixed *)(stuff + 1); - colors = (xRenderColor *)(stops + stuff->nStops); - - pPicture = CreateLinearGradientPicture (stuff->pid, &stuff->p1, &stuff->p2, - stuff->nStops, stops, colors, &error); - if (!pPicture) - return error; - /* AGENT SERVER */ - - nxagentRenderCreateLinearGradient(pPicture, &stuff->p1, &stuff->p2, - stuff->nStops, stops, colors); - - /* AGENT SERVER */ - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int ProcRenderCreateRadialGradient (ClientPtr client) -{ - PicturePtr pPicture; - int len; - int error = 0; - xFixed *stops; - xRenderColor *colors; - REQUEST(xRenderCreateRadialGradientReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq); - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - stops = (xFixed *)(stuff + 1); - colors = (xRenderColor *)(stops + stuff->nStops); - - pPicture = CreateRadialGradientPicture (stuff->pid, &stuff->inner, &stuff->outer, - stuff->inner_radius, stuff->outer_radius, - stuff->nStops, stops, colors, &error); - if (!pPicture) - return error; - /* AGENT SERVER */ - - nxagentRenderCreateRadialGradient(pPicture, &stuff->inner, &stuff->outer, - stuff->inner_radius, - stuff->outer_radius, - stuff->nStops, stops, colors); - - /* AGENT SERVER */ - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int ProcRenderCreateConicalGradient (ClientPtr client) -{ - PicturePtr pPicture; - int len; - int error = 0; - xFixed *stops; - xRenderColor *colors; - REQUEST(xRenderCreateConicalGradientReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq); - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - stops = (xFixed *)(stuff + 1); - colors = (xRenderColor *)(stops + stuff->nStops); - - pPicture = CreateConicalGradientPicture (stuff->pid, &stuff->center, stuff->angle, - stuff->nStops, stops, colors, &error); - if (!pPicture) - return error; - /* AGENT SERVER */ - - nxagentRenderCreateConicalGradient(pPicture, &stuff->center, - stuff->angle, stuff->nStops, stops, - colors); - - /* AGENT SERVER */ - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - - -static int -ProcRenderDispatch (ClientPtr client) -{ - int result; - - REQUEST(xReq); - - /* - * Let the client fail if we are - * hiding the RENDER extension. - */ - - if (nxagentRenderTrap) - { - return BadRequest; - } - - if (stuff->data < RenderNumberRequests) - { - #ifdef TEST - fprintf(stderr, "ProcRenderDispatch: Request [%s] OPCODE#%d.\n", - nxagentRenderRequestLiteral[stuff->data], stuff->data); - #endif - - /* - * Set the nxagentGCTrap flag while - * dispatching a render operation to - * avoid reentrancy in GCOps.c. - */ - - nxagentGCTrap = 1; - - result = (*ProcRenderVector[stuff->data]) (client); - - nxagentGCTrap = 0; - - return result; - } - else - return BadRequest; -} - -static int -SProcRenderQueryVersion (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryVersionReq); - - swaps(&stuff->length, n); - swapl(&stuff->majorVersion, n); - swapl(&stuff->minorVersion, n); - return (*ProcRenderVector[stuff->renderReqType])(client); -} - -static int -SProcRenderQueryPictFormats (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictFormatsReq); - swaps(&stuff->length, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryPictIndexValues (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictIndexValuesReq); - swaps(&stuff->length, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreatePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreatePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->drawable, n); - swapl(&stuff->format, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderChangePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderChangePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureClipRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureClipRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderComposite (ClientPtr client) -{ - register int n; - REQUEST(xRenderCompositeReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->mask, n); - swapl(&stuff->dst, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xMask, n); - swaps(&stuff->yMask, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderScale (ClientPtr client) -{ - register int n; - REQUEST(xRenderScaleReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->colorScale, n); - swapl(&stuff->alphaScale, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTrapezoids (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriStrip (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriStripReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriStripReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriFan (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriFanReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriFanReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreateGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderReferenceGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderReferenceGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->existing, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreeGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphs (ClientPtr client) -{ - register int n; - register unsigned int i; - CARD32 *gids; - void *end; - xGlyphInfo *gi; - REQUEST(xRenderAddGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - swapl(&stuff->nglyphs, n); - if (stuff->nglyphs & 0xe0000000) - return BadLength; - end = (CARD8 *) stuff + (client->req_len << 2); - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + stuff->nglyphs); - if ((char *) end - (char *) (gids + stuff->nglyphs) < 0) - return BadLength; - if ((char *) end - (char *) (gi + stuff->nglyphs) < 0) - return BadLength; - for (i = 0; i < stuff->nglyphs; i++) - { - swapl (&gids[i], n); - swaps (&gi[i].width, n); - swaps (&gi[i].height, n); - swaps (&gi[i].x, n); - swaps (&gi[i].y, n); - swaps (&gi[i].xOff, n); - swaps (&gi[i].yOff, n); - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderFreeGlyphs (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCompositeGlyphs (ClientPtr client) -{ - register int n; - xGlyphElt *elt; - CARD8 *buffer; - CARD8 *end; - int space; - int i; - int size; - - REQUEST(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->maskFormat, n); - swapl(&stuff->glyphset, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - swaps (&elt->deltax, n); - swaps (&elt->deltay, n); - - i = elt->len; - if (i == 0xff) - { - swapl (buffer, n); - buffer += 4; - } - else - { - space = size * i; - switch (size) { - case 1: - buffer += i; - break; - case 2: - while (i--) - { - swaps (buffer, n); - buffer += 2; - } - break; - case 4: - while (i--) - { - swapl (buffer, n); - buffer += 4; - } - break; - } - if (space & 3) - buffer += 4 - (space & 3); - } - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFillRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->dst, n); - swaps(&stuff->color.red, n); - swaps(&stuff->color.green, n); - swaps(&stuff->color.blue, n); - swaps(&stuff->color.alpha, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateCursor (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateCursorReq); - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - swapl(&stuff->src, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureTransform (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureTransformReq); - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->transform.matrix11, n); - swapl(&stuff->transform.matrix12, n); - swapl(&stuff->transform.matrix13, n); - swapl(&stuff->transform.matrix21, n); - swapl(&stuff->transform.matrix22, n); - swapl(&stuff->transform.matrix23, n); - swapl(&stuff->transform.matrix31, n); - swapl(&stuff->transform.matrix32, n); - swapl(&stuff->transform.matrix33, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryFilters (ClientPtr client) -{ - register int n; - REQUEST (xRenderQueryFiltersReq); - REQUEST_SIZE_MATCH (xRenderQueryFiltersReq); - - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureFilter (ClientPtr client) -{ - register int n; - REQUEST (xRenderSetPictureFilterReq); - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swaps(&stuff->nbytes, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateAnimCursor (ClientPtr client) -{ - register int n; - REQUEST (xRenderCreateAnimCursorReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddTraps (ClientPtr client) -{ - register int n; - REQUEST (xRenderAddTrapsReq); - REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swaps(&stuff->xOff, n); - swaps(&stuff->yOff, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateSolidFill(ClientPtr client) -{ - register int n; - REQUEST (xRenderCreateSolidFillReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateSolidFillReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swaps(&stuff->color.alpha, n); - swaps(&stuff->color.red, n); - swaps(&stuff->color.green, n); - swaps(&stuff->color.blue, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static void swapStops(void *stuff, int num) -{ - int i, n; - CARD32 *stops; - CARD16 *colors; - stops = (CARD32 *)(stuff); - for (i = 0; i < num; ++i) { - swapl(stops, n); - ++stops; - } - colors = (CARD16 *)(stops); - for (i = 0; i < 4*num; ++i) { - swaps(stops, n); - ++stops; - } -} - -static int -SProcRenderCreateLinearGradient (ClientPtr client) -{ - register int n; - int len; - REQUEST (xRenderCreateLinearGradientReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateLinearGradientReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->p1.x, n); - swapl(&stuff->p1.y, n); - swapl(&stuff->p2.x, n); - swapl(&stuff->p2.y, n); - swapl(&stuff->nStops, n); - - len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - swapStops(stuff+1, stuff->nStops); - - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateRadialGradient (ClientPtr client) -{ - register int n; - int len; - REQUEST (xRenderCreateRadialGradientReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateRadialGradientReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->inner.x, n); - swapl(&stuff->inner.y, n); - swapl(&stuff->outer.x, n); - swapl(&stuff->outer.y, n); - swapl(&stuff->inner_radius, n); - swapl(&stuff->outer_radius, n); - swapl(&stuff->nStops, n); - - len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - swapStops(stuff+1, stuff->nStops); - - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateConicalGradient (ClientPtr client) -{ - register int n; - int len; - REQUEST (xRenderCreateConicalGradientReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateConicalGradientReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->center.x, n); - swapl(&stuff->center.y, n); - swapl(&stuff->angle, n); - swapl(&stuff->nStops, n); - - len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - swapStops(stuff+1, stuff->nStops); - - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderDispatch (ClientPtr client) -{ - int result; - - REQUEST(xReq); - - /* - * Let the client fail if we are - * hiding the RENDER extension. - */ - - if (nxagentRenderTrap) - { - return BadRequest; - } - - if (stuff->data < RenderNumberRequests) - { - /* - * Set the nxagentGCTrap flag while - * dispatching a render operation to - * avoid reentrancy in GCOps.c. - */ - - nxagentGCTrap = 1; - - result = (*SProcRenderVector[stuff->data]) (client); - - nxagentGCTrap = 0; - - return result; - } - else - return BadRequest; -} - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -#define VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, XRT_PICTURE, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_XIN_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr); - -unsigned long XRT_PICTURE; - -static int -PanoramiXRenderCreatePicture (ClientPtr client) -{ - REQUEST(xRenderCreatePictureReq); - PanoramiXRes *refDraw, *newPict; - int result = Success, j; - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - if(!(refDraw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - if(!(newPict = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - newPict->type = XRT_PICTURE; - newPict->info[0].id = stuff->pid; - - if (refDraw->type == XRT_WINDOW && - stuff->drawable == WindowTable[0]->drawable.id) - { - newPict->u.pict.root = TRUE; - } - else - newPict->u.pict.root = FALSE; - - for(j = 1; j < PanoramiXNumScreens; j++) - newPict->info[j].id = FakeClientID(client->index); - - FOR_NSCREENS_BACKWARD(j) { - stuff->pid = newPict->info[j].id; - stuff->drawable = refDraw->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client); - if(result != Success) break; - } - - if (result == Success) - AddResource(newPict->info[0].id, XRT_PICTURE, newPict); - else - xfree(newPict); - - return (result); -} - -static int -PanoramiXRenderChangePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderChangePictureReq); - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureTransform (ClientPtr client) -{ - REQUEST(xRenderSetPictureTransformReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureTransformReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureTransform]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureFilter (ClientPtr client) -{ - REQUEST(xRenderSetPictureFilterReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureFilter]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderFreePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - client->errorValue = stuff->picture; - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client); - if(result != Success) break; - } - - /* Since ProcRenderFreePicture is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - - return (result); -} - -static int -PanoramiXRenderComposite (ClientPtr client) -{ - PanoramiXRes *src, *msk, *dst; - int result = Success, j; - xRenderCompositeReq orig; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_ALPHA (msk, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - orig = *stuff; - - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - stuff->xDst = orig.xDst - panoramiXdataPtr[j].x; - stuff->yDst = orig.yDst - panoramiXdataPtr[j].y; - } - if (msk) - { - stuff->mask = msk->info[j].id; - if (msk->u.pict.root) - { - stuff->xMask = orig.xMask - panoramiXdataPtr[j].x; - stuff->yMask = orig.yMask - panoramiXdataPtr[j].y; - } - } - result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client); - if(result != Success) break; - } - - return result; -} - -static int -PanoramiXRenderCompositeGlyphs (ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderCompositeGlyphsReq); - xGlyphElt origElt, *elt; - INT16 xSrc, ySrc; - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) + - sizeof (xGlyphElt))) - { - elt = (xGlyphElt *) (stuff + 1); - origElt = *elt; - xSrc = stuff->xSrc; - ySrc = stuff->ySrc; - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - elt->deltax = origElt.deltax - panoramiXdataPtr[j].x; - elt->deltay = origElt.deltay - panoramiXdataPtr[j].y; - } - result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client); - if(result != Success) break; - } - } - - return result; -} - -static int -PanoramiXRenderFillRectangles (ClientPtr client) -{ - PanoramiXRes *dst; - int result = Success, j; - REQUEST(xRenderFillRectanglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq); - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) - { - memcpy (extra, stuff + 1, extra_len); - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) - { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xRectangle *rects = (xRectangle *) (stuff + 1); - int i = extra_len / sizeof (xRectangle); - - while (i--) - { - rects->x -= x_off; - rects->y -= y_off; - rects++; - } - } - } - stuff->dst = dst->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client); - if(result != Success) break; - } - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTrapezoids(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTrapezoidsReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTrapezoidsReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xTrapezoid *trap = (xTrapezoid *) (stuff + 1); - int i = extra_len / sizeof (xTrapezoid); - - while (i--) { - trap->top -= y_off; - trap->bottom -= y_off; - trap->left.p1.x -= x_off; - trap->left.p1.y -= y_off; - trap->left.p2.x -= x_off; - trap->left.p2.y -= y_off; - trap->right.p1.x -= x_off; - trap->right.p1.y -= y_off; - trap->right.p2.x -= x_off; - trap->right.p2.y -= y_off; - trap++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTrapezoids]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTriangles(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTrianglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTrianglesReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTrianglesReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xTriangle *tri = (xTriangle *) (stuff + 1); - int i = extra_len / sizeof (xTriangle); - - while (i--) { - tri->p1.x -= x_off; - tri->p1.y -= y_off; - tri->p2.x -= x_off; - tri->p2.y -= y_off; - tri->p3.x -= x_off; - tri->p3.y -= y_off; - tri++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTriangles]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTriStrip(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTriStripReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTriStripReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTriStripReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xPointFixed *fixed = (xPointFixed *) (stuff + 1); - int i = extra_len / sizeof (xPointFixed); - - while (i--) { - fixed->x -= x_off; - fixed->y -= y_off; - fixed++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTriStrip]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTriFan(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTriFanReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTriFanReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTriFanReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xPointFixed *fixed = (xPointFixed *) (stuff + 1); - int i = extra_len / sizeof (xPointFixed); - - while (i--) { - fixed->x -= x_off; - fixed->y -= y_off; - fixed++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTriFan]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -#if 0 /* Not implemented yet */ - -static int -PanoramiXRenderColorTrapezoids(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderColorTrapezoidsReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderColorTrapezoidsReq); - - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderColorTrapezoidsReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - ....; - } - } - - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderColorTrapezoids]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderColorTriangles(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderColorTrianglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderColorTrianglesReq); - - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderColorTrianglesReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - ....; - } - } - - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderColorTriangles]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -#endif - -static int -PanoramiXRenderAddTraps (ClientPtr client) -{ - PanoramiXRes *picture; - int result = Success, j; - REQUEST(xRenderAddTrapsReq); - char *extra; - int extra_len; - INT16 x_off, y_off; - - REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq); - VERIFY_XIN_PICTURE (picture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - extra_len = (client->req_len << 2) - sizeof (xRenderAddTrapsReq); - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) - { - memcpy (extra, stuff + 1, extra_len); - x_off = stuff->xOff; - y_off = stuff->yOff; - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - stuff->picture = picture->info[j].id; - - if (picture->u.pict.root) - { - stuff->xOff = x_off + panoramiXdataPtr[j].x; - stuff->yOff = y_off + panoramiXdataPtr[j].y; - } - result = (*PanoramiXSaveRenderVector[X_RenderAddTraps]) (client); - if(result != Success) break; - } - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -void -PanoramiXRenderInit (void) -{ - int i; - - XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource); - for (i = 0; i < RenderNumberRequests; i++) - PanoramiXSaveRenderVector[i] = ProcRenderVector[i]; - /* - * Stuff in Xinerama aware request processing hooks - */ - ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture; - ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture; - ProcRenderVector[X_RenderSetPictureTransform] = PanoramiXRenderSetPictureTransform; - ProcRenderVector[X_RenderSetPictureFilter] = PanoramiXRenderSetPictureFilter; - ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles; - ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture; - ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite; - ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles; - - ProcRenderVector[X_RenderTrapezoids] = PanoramiXRenderTrapezoids; - ProcRenderVector[X_RenderTriangles] = PanoramiXRenderTriangles; - ProcRenderVector[X_RenderTriStrip] = PanoramiXRenderTriStrip; - ProcRenderVector[X_RenderTriFan] = PanoramiXRenderTriFan; - ProcRenderVector[X_RenderAddTraps] = PanoramiXRenderAddTraps; -} - -void -PanoramiXRenderReset (void) -{ - int i; - for (i = 0; i < RenderNumberRequests; i++) - ProcRenderVector[i] = PanoramiXSaveRenderVector[i]; -} - -#endif /* PANORAMIX */ - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.X.original deleted file mode 100644 index d25d49756..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXrender.c.X.original +++ /dev/null @@ -1,3316 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/render/render.c,v 1.12 2005/08/28 19:47:39 ajax Exp $ */ -/* - * $XFree86: xc/programs/Xserver/render/render.c,v 1.27tsi Exp $ - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - -#define NEED_REPLIES -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "colormapst.h" -#include "extnsionst.h" -#include "servermd.h" -#include -#include -#include "picturestr.h" -#include "glyphstr.h" -#include -#include "cursorstr.h" -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#if !defined(UINT32_MAX) -#define UINT32_MAX 0xffffffffU -#endif - -static int ProcRenderQueryVersion (ClientPtr pClient); -static int ProcRenderQueryPictFormats (ClientPtr pClient); -static int ProcRenderQueryPictIndexValues (ClientPtr pClient); -static int ProcRenderQueryDithers (ClientPtr pClient); -static int ProcRenderCreatePicture (ClientPtr pClient); -static int ProcRenderChangePicture (ClientPtr pClient); -static int ProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int ProcRenderFreePicture (ClientPtr pClient); -static int ProcRenderComposite (ClientPtr pClient); -static int ProcRenderScale (ClientPtr pClient); -static int ProcRenderTrapezoids (ClientPtr pClient); -static int ProcRenderTriangles (ClientPtr pClient); -static int ProcRenderTriStrip (ClientPtr pClient); -static int ProcRenderTriFan (ClientPtr pClient); -static int ProcRenderColorTrapezoids (ClientPtr pClient); -static int ProcRenderColorTriangles (ClientPtr pClient); -static int ProcRenderTransform (ClientPtr pClient); -static int ProcRenderCreateGlyphSet (ClientPtr pClient); -static int ProcRenderReferenceGlyphSet (ClientPtr pClient); -static int ProcRenderFreeGlyphSet (ClientPtr pClient); -static int ProcRenderAddGlyphs (ClientPtr pClient); -static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int ProcRenderFreeGlyphs (ClientPtr pClient); -static int ProcRenderCompositeGlyphs (ClientPtr pClient); -static int ProcRenderFillRectangles (ClientPtr pClient); -static int ProcRenderCreateCursor (ClientPtr pClient); -static int ProcRenderSetPictureTransform (ClientPtr pClient); -static int ProcRenderQueryFilters (ClientPtr pClient); -static int ProcRenderSetPictureFilter (ClientPtr pClient); -static int ProcRenderCreateAnimCursor (ClientPtr pClient); -static int ProcRenderAddTraps (ClientPtr pClient); -static int ProcRenderCreateSolidFill (ClientPtr pClient); -static int ProcRenderCreateLinearGradient (ClientPtr pClient); -static int ProcRenderCreateRadialGradient (ClientPtr pClient); -static int ProcRenderCreateConicalGradient (ClientPtr pClient); - -static int ProcRenderDispatch (ClientPtr pClient); - -static int SProcRenderQueryVersion (ClientPtr pClient); -static int SProcRenderQueryPictFormats (ClientPtr pClient); -static int SProcRenderQueryPictIndexValues (ClientPtr pClient); -static int SProcRenderQueryDithers (ClientPtr pClient); -static int SProcRenderCreatePicture (ClientPtr pClient); -static int SProcRenderChangePicture (ClientPtr pClient); -static int SProcRenderSetPictureClipRectangles (ClientPtr pClient); -static int SProcRenderFreePicture (ClientPtr pClient); -static int SProcRenderComposite (ClientPtr pClient); -static int SProcRenderScale (ClientPtr pClient); -static int SProcRenderTrapezoids (ClientPtr pClient); -static int SProcRenderTriangles (ClientPtr pClient); -static int SProcRenderTriStrip (ClientPtr pClient); -static int SProcRenderTriFan (ClientPtr pClient); -static int SProcRenderColorTrapezoids (ClientPtr pClient); -static int SProcRenderColorTriangles (ClientPtr pClient); -static int SProcRenderTransform (ClientPtr pClient); -static int SProcRenderCreateGlyphSet (ClientPtr pClient); -static int SProcRenderReferenceGlyphSet (ClientPtr pClient); -static int SProcRenderFreeGlyphSet (ClientPtr pClient); -static int SProcRenderAddGlyphs (ClientPtr pClient); -static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient); -static int SProcRenderFreeGlyphs (ClientPtr pClient); -static int SProcRenderCompositeGlyphs (ClientPtr pClient); -static int SProcRenderFillRectangles (ClientPtr pClient); -static int SProcRenderCreateCursor (ClientPtr pClient); -static int SProcRenderSetPictureTransform (ClientPtr pClient); -static int SProcRenderQueryFilters (ClientPtr pClient); -static int SProcRenderSetPictureFilter (ClientPtr pClient); -static int SProcRenderCreateAnimCursor (ClientPtr pClient); -static int SProcRenderAddTraps (ClientPtr pClient); -static int SProcRenderCreateSolidFill (ClientPtr pClient); -static int SProcRenderCreateLinearGradient (ClientPtr pClient); -static int SProcRenderCreateRadialGradient (ClientPtr pClient); -static int SProcRenderCreateConicalGradient (ClientPtr pClient); - -static int SProcRenderDispatch (ClientPtr pClient); - -int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = { - ProcRenderQueryVersion, - ProcRenderQueryPictFormats, - ProcRenderQueryPictIndexValues, - ProcRenderQueryDithers, - ProcRenderCreatePicture, - ProcRenderChangePicture, - ProcRenderSetPictureClipRectangles, - ProcRenderFreePicture, - ProcRenderComposite, - ProcRenderScale, - ProcRenderTrapezoids, - ProcRenderTriangles, - ProcRenderTriStrip, - ProcRenderTriFan, - ProcRenderColorTrapezoids, - ProcRenderColorTriangles, - ProcRenderTransform, - ProcRenderCreateGlyphSet, - ProcRenderReferenceGlyphSet, - ProcRenderFreeGlyphSet, - ProcRenderAddGlyphs, - ProcRenderAddGlyphsFromPicture, - ProcRenderFreeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderCompositeGlyphs, - ProcRenderFillRectangles, - ProcRenderCreateCursor, - ProcRenderSetPictureTransform, - ProcRenderQueryFilters, - ProcRenderSetPictureFilter, - ProcRenderCreateAnimCursor, - ProcRenderAddTraps, - ProcRenderCreateSolidFill, - ProcRenderCreateLinearGradient, - ProcRenderCreateRadialGradient, - ProcRenderCreateConicalGradient -}; - -int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = { - SProcRenderQueryVersion, - SProcRenderQueryPictFormats, - SProcRenderQueryPictIndexValues, - SProcRenderQueryDithers, - SProcRenderCreatePicture, - SProcRenderChangePicture, - SProcRenderSetPictureClipRectangles, - SProcRenderFreePicture, - SProcRenderComposite, - SProcRenderScale, - SProcRenderTrapezoids, - SProcRenderTriangles, - SProcRenderTriStrip, - SProcRenderTriFan, - SProcRenderColorTrapezoids, - SProcRenderColorTriangles, - SProcRenderTransform, - SProcRenderCreateGlyphSet, - SProcRenderReferenceGlyphSet, - SProcRenderFreeGlyphSet, - SProcRenderAddGlyphs, - SProcRenderAddGlyphsFromPicture, - SProcRenderFreeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderCompositeGlyphs, - SProcRenderFillRectangles, - SProcRenderCreateCursor, - SProcRenderSetPictureTransform, - SProcRenderQueryFilters, - SProcRenderSetPictureFilter, - SProcRenderCreateAnimCursor, - SProcRenderAddTraps, - SProcRenderCreateSolidFill, - SProcRenderCreateLinearGradient, - SProcRenderCreateRadialGradient, - SProcRenderCreateConicalGradient -}; - -static void -RenderResetProc (ExtensionEntry *extEntry); - -#if 0 -static CARD8 RenderReqCode; -#endif -int RenderErrBase; -int RenderClientPrivateIndex; - -typedef struct _RenderClient { - int major_version; - int minor_version; -} RenderClientRec, *RenderClientPtr; - -#define GetRenderClient(pClient) ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr) - -static void -RenderClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - RenderClientPtr pRenderClient = GetRenderClient (pClient); - - pRenderClient->major_version = 0; - pRenderClient->minor_version = 0; -} - -void -RenderExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (!PictureType) - return; - if (!PictureFinishInit ()) - return; - RenderClientPrivateIndex = AllocateClientPrivateIndex (); - if (!AllocateClientPrivate (RenderClientPrivateIndex, - sizeof (RenderClientRec))) - return; - if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0)) - return; - - extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors, - ProcRenderDispatch, SProcRenderDispatch, - RenderResetProc, StandardMinorOpcode); - if (!extEntry) - return; -#if 0 - RenderReqCode = (CARD8) extEntry->base; -#endif - RenderErrBase = extEntry->errorBase; -} - -static void -RenderResetProc (ExtensionEntry *extEntry) -{ - ResetPicturePrivateIndex(); - ResetGlyphSetPrivateIndex(); -} - -static int -ProcRenderQueryVersion (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryVersionReply rep; - register int n; - REQUEST(xRenderQueryVersionReq); - - pRenderClient->major_version = stuff->majorVersion; - pRenderClient->minor_version = stuff->minorVersion; - - REQUEST_SIZE_MATCH(xRenderQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = RENDER_MAJOR; - rep.minorVersion = RENDER_MINOR; - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.majorVersion, n); - swapl(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -#if 0 -static int -VisualDepth (ScreenPtr pScreen, VisualPtr pVisual) -{ - DepthPtr pDepth; - int d, v; - - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - for (v = 0; v < pDepth->numVids; v++) - { - if (pDepth->vids[v] == pVisual->vid) - return pDepth->depth; - } - } - return 0; -} -#endif - -static VisualPtr -findVisual (ScreenPtr pScreen, VisualID vid) -{ - VisualPtr pVisual; - int v; - - for (v = 0; v < pScreen->numVisuals; v++) - { - pVisual = pScreen->visuals + v; - if (pVisual->vid == vid) - return pVisual; - } - return 0; -} - -extern char *ConnectionInfo; - -static int -ProcRenderQueryPictFormats (ClientPtr client) -{ - RenderClientPtr pRenderClient = GetRenderClient (client); - xRenderQueryPictFormatsReply *reply; - xPictScreen *pictScreen; - xPictDepth *pictDepth; - xPictVisual *pictVisual; - xPictFormInfo *pictForm; - CARD32 *pictSubpixel; - ScreenPtr pScreen; - VisualPtr pVisual; - DepthPtr pDepth; - int v, d; - PictureScreenPtr ps; - PictFormatPtr pFormat; - int nformat; - int ndepth; - int nvisual; - int rlength; - int s; - int n; - int numScreens; - int numSubpixel; -/* REQUEST(xRenderQueryPictFormatsReq); */ - - REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq); - -#ifdef PANORAMIX - if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; -#else - numScreens = screenInfo.numScreens; -#endif - ndepth = nformat = nvisual = 0; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - for (d = 0; d < pScreen->numDepths; d++) - { - pDepth = pScreen->allowedDepths + d; - ++ndepth; - - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual)) - ++nvisual; - } - } - ps = GetPictureScreenIfSet(pScreen); - if (ps) - nformat += ps->nformats; - } - if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6) - numSubpixel = 0; - else - numSubpixel = numScreens; - - rlength = (sizeof (xRenderQueryPictFormatsReply) + - nformat * sizeof (xPictFormInfo) + - numScreens * sizeof (xPictScreen) + - ndepth * sizeof (xPictDepth) + - nvisual * sizeof (xPictVisual) + - numSubpixel * sizeof (CARD32)); - reply = (xRenderQueryPictFormatsReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numFormats = nformat; - reply->numScreens = numScreens; - reply->numDepths = ndepth; - reply->numVisuals = nvisual; - reply->numSubpixel = numSubpixel; - - pictForm = (xPictFormInfo *) (reply + 1); - - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (nformat = 0, pFormat = ps->formats; - nformat < ps->nformats; - nformat++, pFormat++) - { - pictForm->id = pFormat->id; - pictForm->type = pFormat->type; - pictForm->depth = pFormat->depth; - pictForm->direct.red = pFormat->direct.red; - pictForm->direct.redMask = pFormat->direct.redMask; - pictForm->direct.green = pFormat->direct.green; - pictForm->direct.greenMask = pFormat->direct.greenMask; - pictForm->direct.blue = pFormat->direct.blue; - pictForm->direct.blueMask = pFormat->direct.blueMask; - pictForm->direct.alpha = pFormat->direct.alpha; - pictForm->direct.alphaMask = pFormat->direct.alphaMask; - if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap) - pictForm->colormap = pFormat->index.pColormap->mid; - else - pictForm->colormap = None; - if (client->swapped) - { - swapl (&pictForm->id, n); - swaps (&pictForm->direct.red, n); - swaps (&pictForm->direct.redMask, n); - swaps (&pictForm->direct.green, n); - swaps (&pictForm->direct.greenMask, n); - swaps (&pictForm->direct.blue, n); - swaps (&pictForm->direct.blueMask, n); - swaps (&pictForm->direct.alpha, n); - swaps (&pictForm->direct.alphaMask, n); - swapl (&pictForm->colormap, n); - } - pictForm++; - } - } - } - - pictScreen = (xPictScreen *) pictForm; - for (s = 0; s < numScreens; s++) - { - pScreen = screenInfo.screens[s]; - pictDepth = (xPictDepth *) (pictScreen + 1); - ndepth = 0; - for (d = 0; d < pScreen->numDepths; d++) - { - pictVisual = (xPictVisual *) (pictDepth + 1); - pDepth = pScreen->allowedDepths + d; - - nvisual = 0; - for (v = 0; v < pDepth->numVids; v++) - { - pVisual = findVisual (pScreen, pDepth->vids[v]); - if (pVisual && (pFormat = PictureMatchVisual (pScreen, - pDepth->depth, - pVisual))) - { - pictVisual->visual = pVisual->vid; - pictVisual->format = pFormat->id; - if (client->swapped) - { - swapl (&pictVisual->visual, n); - swapl (&pictVisual->format, n); - } - pictVisual++; - nvisual++; - } - } - pictDepth->depth = pDepth->depth; - pictDepth->nPictVisuals = nvisual; - if (client->swapped) - { - swaps (&pictDepth->nPictVisuals, n); - } - ndepth++; - pictDepth = (xPictDepth *) pictVisual; - } - pictScreen->nDepth = ndepth; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - pictScreen->fallback = ps->fallback->id; - else - pictScreen->fallback = 0; - if (client->swapped) - { - swapl (&pictScreen->nDepth, n); - swapl (&pictScreen->fallback, n); - } - pictScreen = (xPictScreen *) pictDepth; - } - pictSubpixel = (CARD32 *) pictScreen; - - for (s = 0; s < numSubpixel; s++) - { - pScreen = screenInfo.screens[s]; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - *pictSubpixel = ps->subpixel; - else - *pictSubpixel = SubPixelUnknown; - if (client->swapped) - { - swapl (pictSubpixel, n); - } - ++pictSubpixel; - } - - if (client->swapped) - { - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numFormats, n); - swapl (&reply->numScreens, n); - swapl (&reply->numDepths, n); - swapl (&reply->numVisuals, n); - swapl (&reply->numSubpixel, n); - } - WriteToClient(client, rlength, (char *) reply); - xfree (reply); - return client->noClientException; -} - -static int -ProcRenderQueryPictIndexValues (ClientPtr client) -{ - PictFormatPtr pFormat; - int num; - int rlength; - int i, n; - REQUEST(xRenderQueryPictIndexValuesReq); - xRenderQueryPictIndexValuesReply *reply; - xIndexValue *values; - - REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq); - - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->type != PictTypeIndexed) - { - client->errorValue = stuff->format; - return BadMatch; - } - num = pFormat->index.nvalues; - rlength = (sizeof (xRenderQueryPictIndexValuesReply) + - num * sizeof(xIndexValue)); - reply = (xRenderQueryPictIndexValuesReply *) xalloc (rlength); - if (!reply) - return BadAlloc; - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; - reply->numIndexValues = num; - - values = (xIndexValue *) (reply + 1); - - memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue)); - - if (client->swapped) - { - for (i = 0; i < num; i++) - { - swapl (&values[i].pixel, n); - swaps (&values[i].red, n); - swaps (&values[i].green, n); - swaps (&values[i].blue, n); - swaps (&values[i].alpha, n); - } - swaps (&reply->sequenceNumber, n); - swapl (&reply->length, n); - swapl (&reply->numIndexValues, n); - } - - WriteToClient(client, rlength, (char *) reply); - xfree(reply); - return (client->noClientException); -} - -static int -ProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreatePicture (ClientPtr client) -{ - PicturePtr pPicture; - DrawablePtr pDrawable; - PictFormatPtr pFormat; - int len; - int error; - REQUEST(xRenderCreatePictureReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, - SecurityWriteAccess); - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - if (pFormat->depth != pDrawable->depth) - return BadMatch; - len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - pPicture = CreatePicture (stuff->pid, - pDrawable, - pFormat, - stuff->mask, - (XID *) (stuff + 1), - client, - &error); - if (!pPicture) - return error; - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int -ProcRenderChangePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderChangePictureReq); - int len; - - REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2); - if (Ones(stuff->mask) != len) - return BadLength; - - return ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1), - (DevUnion *) 0, client); -} - -static int -ProcRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - PicturePtr pPicture; - int nr; - int result; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pPicture->pDrawable) - return BadDrawable; - - nr = (client->req_len << 2) - sizeof(xRenderChangePictureReq); - if (nr & 4) - return BadLength; - nr >>= 3; - result = SetPictureClipRects (pPicture, - stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *) &stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderFreePicture (ClientPtr client) -{ - PicturePtr pPicture; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - FreeResource (stuff->picture, RT_NONE); - return(client->noClientException); -} - -static Bool -PictOpValid (CARD8 op) -{ - if (/*PictOpMinimum <= op && */ op <= PictOpMaximum) - return TRUE; - if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum) - return TRUE; - if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum) - return TRUE; - return FALSE; -} - -static int -ProcRenderComposite (ClientPtr client) -{ - PicturePtr pSrc, pMask, pDst; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_ALPHA (pMask, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - if ((pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) || - (pMask && pMask->pDrawable && pSrc->pDrawable->pScreen != pMask->pDrawable->pScreen)) - return BadMatch; - CompositePicture (stuff->op, - pSrc, - pMask, - pDst, - stuff->xSrc, - stuff->ySrc, - stuff->xMask, - stuff->yMask, - stuff->xDst, - stuff->yDst, - stuff->width, - stuff->height); - return Success; -} - -static int -ProcRenderScale (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTrapezoids (ClientPtr client) -{ - int ntraps; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); - if (ntraps % sizeof (xTrapezoid)) - return BadLength; - ntraps /= sizeof (xTrapezoid); - if (ntraps) - CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntraps, (xTrapezoid *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriangles (ClientPtr client) -{ - int ntris; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq); - if (ntris % sizeof (xTriangle)) - return BadLength; - ntris /= sizeof (xTriangle); - if (ntris) - CompositeTriangles (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - ntris, (xTriangle *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriStrip (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriStrip (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderTriFan (ClientPtr client) -{ - int npoints; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); - if (npoints & 4) - return(BadLength); - npoints >>= 3; - if (npoints >= 3) - CompositeTriFan (stuff->op, pSrc, pDst, pFormat, - stuff->xSrc, stuff->ySrc, - npoints, (xPointFixed *) &stuff[1]); - return client->noClientException; -} - -static int -ProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderCreateGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - PictFormatPtr format; - int f; - REQUEST(xRenderCreateGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - format = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->format, - PictFormatType, - SecurityReadAccess); - if (!format) - { - client->errorValue = stuff->format; - return RenderErrBase + BadPictFormat; - } - switch (format->depth) { - case 1: - f = GlyphFormat1; - break; - case 4: - f = GlyphFormat4; - break; - case 8: - f = GlyphFormat8; - break; - case 16: - f = GlyphFormat16; - break; - case 32: - f = GlyphFormat32; - break; - default: - return BadMatch; - } - if (format->type != PictTypeDirect) - return BadMatch; - glyphSet = AllocateGlyphSet (f, format); - if (!glyphSet) - return BadAlloc; - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - return Success; -} - -static int -ProcRenderReferenceGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderReferenceGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq); - - LEGAL_NEW_RESOURCE(stuff->gsid, client); - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->existing, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->existing; - return RenderErrBase + BadGlyphSet; - } - glyphSet->refcnt++; - if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) - return BadAlloc; - return client->noClientException; -} - -#define NLOCALDELTA 64 -#define NLOCALGLYPH 256 - -static int -ProcRenderFreeGlyphSet (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderFreeGlyphSetReq); - - REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityDestroyAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - FreeResource (stuff->glyphset, RT_NONE); - return client->noClientException; -} - -typedef struct _GlyphNew { - Glyph id; - GlyphPtr glyph; -} GlyphNewRec, *GlyphNewPtr; - -static int -ProcRenderAddGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - REQUEST(xRenderAddGlyphsReq); - GlyphNewRec glyphsLocal[NLOCALGLYPH]; - GlyphNewPtr glyphsBase, glyphs; - GlyphPtr glyph; - int remain, nglyphs; - CARD32 *gids; - xGlyphInfo *gi; - CARD8 *bits; - int size; - int err = BadAlloc; - - REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - nglyphs = stuff->nglyphs; - if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec)) - return BadAlloc; - - if (nglyphs <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphNewPtr) Xalloc (nglyphs * sizeof (GlyphNewRec)); - if (!glyphsBase) - return BadAlloc; - } - - remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq); - - glyphs = glyphsBase; - - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + nglyphs); - bits = (CARD8 *) (gi + nglyphs); - remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs; - while (remain >= 0 && nglyphs) - { - glyph = AllocateGlyph (gi, glyphSet->fdepth); - if (!glyph) - { - err = BadAlloc; - goto bail; - } - - glyphs->glyph = glyph; - glyphs->id = *gids; - - size = glyph->size - sizeof (xGlyphInfo); - if (remain < size) - break; - memcpy ((CARD8 *) (glyph + 1), bits, size); - - if (size & 3) - size += 4 - (size & 3); - bits += size; - remain -= size; - gi++; - gids++; - glyphs++; - nglyphs--; - } - if (nglyphs || remain) - { - err = BadLength; - goto bail; - } - nglyphs = stuff->nglyphs; - if (!ResizeGlyphSet (glyphSet, nglyphs)) - { - err = BadAlloc; - goto bail; - } - glyphs = glyphsBase; - while (nglyphs--) { - AddGlyph (glyphSet, glyphs->glyph, glyphs->id); - glyphs++; - } - - if (glyphsBase != glyphsLocal) - Xfree (glyphsBase); - return client->noClientException; -bail: - while (glyphs != glyphsBase) - { - --glyphs; - xfree (glyphs->glyph); - } - if (glyphsBase != glyphsLocal) - Xfree (glyphsBase); - return err; -} - -static int -ProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -ProcRenderFreeGlyphs (ClientPtr client) -{ - REQUEST(xRenderFreeGlyphsReq); - GlyphSetPtr glyphSet; - int nglyph; - CARD32 *gids; - CARD32 glyph; - - REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityWriteAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2; - gids = (CARD32 *) (stuff + 1); - while (nglyph-- > 0) - { - glyph = *gids++; - if (!DeleteGlyph (glyphSet, glyph)) - { - client->errorValue = glyph; - return RenderErrBase + BadGlyph; - } - } - return client->noClientException; -} - -static int -ProcRenderCompositeGlyphs (ClientPtr client) -{ - GlyphSetPtr glyphSet; - GlyphSet gs; - PicturePtr pSrc, pDst; - PictFormatPtr pFormat; - GlyphListRec listsLocal[NLOCALDELTA]; - GlyphListPtr lists, listsBase; - GlyphPtr glyphsLocal[NLOCALGLYPH]; - Glyph glyph; - GlyphPtr *glyphs, *glyphsBase; - xGlyphElt *elt; - CARD8 *buffer, *end; - int nglyph; - int nlist; - int space; - int size; - int n; - - REQUEST(xRenderCompositeGlyphsReq); - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) - return BadMatch; - if (stuff->maskFormat) - { - pFormat = (PictFormatPtr) SecurityLookupIDByType (client, - stuff->maskFormat, - PictFormatType, - SecurityReadAccess); - if (!pFormat) - { - client->errorValue = stuff->maskFormat; - return RenderErrBase + BadPictFormat; - } - } - else - pFormat = 0; - - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - stuff->glyphset, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = stuff->glyphset; - return RenderErrBase + BadGlyphSet; - } - - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - nglyph = 0; - nlist = 0; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - buffer += 4; - } - else - { - nlist++; - nglyph += elt->len; - space = size * elt->len; - if (space & 3) - space += 4 - (space & 3); - buffer += space; - } - } - if (nglyph <= NLOCALGLYPH) - glyphsBase = glyphsLocal; - else - { - glyphsBase = (GlyphPtr *) ALLOCATE_LOCAL (nglyph * sizeof (GlyphPtr)); - if (!glyphsBase) - return BadAlloc; - } - if (nlist <= NLOCALDELTA) - listsBase = listsLocal; - else - { - listsBase = (GlyphListPtr) ALLOCATE_LOCAL (nlist * sizeof (GlyphListRec)); - if (!listsBase) - return BadAlloc; - } - buffer = (CARD8 *) (stuff + 1); - glyphs = glyphsBase; - lists = listsBase; - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - if (elt->len == 0xff) - { - if (buffer + sizeof (GlyphSet) < end) - { - memcpy(&gs, buffer, sizeof(GlyphSet)); - glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client, - gs, - GlyphSetType, - SecurityReadAccess); - if (!glyphSet) - { - client->errorValue = gs; - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - return RenderErrBase + BadGlyphSet; - } - } - buffer += 4; - } - else - { - lists->xOff = elt->deltax; - lists->yOff = elt->deltay; - lists->format = glyphSet->format; - lists->len = 0; - n = elt->len; - while (n--) - { - if (buffer + size <= end) - { - switch (size) { - case 1: - glyph = *((CARD8 *)buffer); break; - case 2: - glyph = *((CARD16 *)buffer); break; - case 4: - default: - glyph = *((CARD32 *)buffer); break; - } - if ((*glyphs = FindGlyph (glyphSet, glyph))) - { - lists->len++; - glyphs++; - } - } - buffer += size; - } - space = size * elt->len; - if (space & 3) - buffer += 4 - (space & 3); - lists++; - } - } - if (buffer > end) - return BadLength; - - CompositeGlyphs (stuff->op, - pSrc, - pDst, - pFormat, - stuff->xSrc, - stuff->ySrc, - nlist, - listsBase, - glyphsBase); - - if (glyphsBase != glyphsLocal) - DEALLOCATE_LOCAL (glyphsBase); - if (listsBase != listsLocal) - DEALLOCATE_LOCAL (listsBase); - - return client->noClientException; -} - -static int -ProcRenderFillRectangles (ClientPtr client) -{ - PicturePtr pDst; - int things; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - if (!PictOpValid (stuff->op)) - { - client->errorValue = stuff->op; - return BadValue; - } - VERIFY_PICTURE (pDst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pDst->pDrawable) - return BadDrawable; - - things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq); - if (things & 4) - return(BadLength); - things >>= 3; - - CompositeRects (stuff->op, - pDst, - &stuff->color, - things, - (xRectangle *) &stuff[1]); - - return client->noClientException; -} - -static void -SetBit (unsigned char *line, int x, int bit) -{ - unsigned char mask; - - if (screenInfo.bitmapBitOrder == LSBFirst) - mask = (1 << (x & 7)); - else - mask = (0x80 >> (x & 7)); - /* XXX assumes byte order is host byte order */ - line += (x >> 3); - if (bit) - *line |= mask; - else - *line &= ~mask; -} - -#define DITHER_DIM 2 - -static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = { - { 1, 3, }, - { 4, 2, }, -}; - -#define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1) - -static int -ProcRenderCreateCursor (ClientPtr client) -{ - REQUEST(xRenderCreateCursorReq); - PicturePtr pSrc; - ScreenPtr pScreen; - unsigned short width, height; - CARD32 *argbbits, *argb; - unsigned char *srcbits, *srcline; - unsigned char *mskbits, *mskline; - int stride; - int x, y; - int nbytes_mono; - CursorMetricRec cm; - CursorPtr pCursor; - CARD32 twocolor[3]; - int ncolor; - - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - - VERIFY_PICTURE (pSrc, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - if (!pSrc->pDrawable) - return BadDrawable; - pScreen = pSrc->pDrawable->pScreen; - width = pSrc->pDrawable->width; - height = pSrc->pDrawable->height; - if (height && width > UINT32_MAX/(height*sizeof(CARD32))) - return BadAlloc; - if ( stuff->x > width - || stuff->y > height ) - return (BadMatch); - argbbits = xalloc (width * height * sizeof (CARD32)); - if (!argbbits) - return (BadAlloc); - - stride = BitmapBytePad(width); - nbytes_mono = stride*height; - srcbits = (unsigned char *)xalloc(nbytes_mono); - if (!srcbits) - { - xfree (argbbits); - return (BadAlloc); - } - mskbits = (unsigned char *)xalloc(nbytes_mono); - if (!mskbits) - { - xfree(argbbits); - xfree(srcbits); - return (BadAlloc); - } - bzero ((char *) mskbits, nbytes_mono); - bzero ((char *) srcbits, nbytes_mono); - - if (pSrc->format == PICT_a8r8g8b8) - { - (*pScreen->GetImage) (pSrc->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - } - else - { - PixmapPtr pPixmap; - PicturePtr pPicture; - PictFormatPtr pFormat; - int error; - - pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8); - if (!pFormat) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadImplementation); - } - pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32); - if (!pPixmap) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return (BadAlloc); - } - pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0, - client, &error); - if (!pPicture) - { - xfree (argbbits); - xfree (srcbits); - xfree (mskbits); - return error; - } - (*pScreen->DestroyPixmap) (pPixmap); - CompositePicture (PictOpSrc, - pSrc, 0, pPicture, - 0, 0, 0, 0, 0, 0, width, height); - (*pScreen->GetImage) (pPicture->pDrawable, - 0, 0, width, height, ZPixmap, - 0xffffffff, (pointer) argbbits); - FreePicture (pPicture, 0); - } - /* - * Check whether the cursor can be directly supported by - * the core cursor code - */ - ncolor = 0; - argb = argbbits; - for (y = 0; ncolor <= 2 && y < height; y++) - { - for (x = 0; ncolor <= 2 && x < width; x++) - { - CARD32 p = *argb++; - CARD32 a = (p >> 24); - - if (a == 0) /* transparent */ - continue; - if (a == 0xff) /* opaque */ - { - int n; - for (n = 0; n < ncolor; n++) - if (p == twocolor[n]) - break; - if (n == ncolor) - twocolor[ncolor++] = p; - } - else - ncolor = 3; - } - } - - /* - * Convert argb image to two plane cursor - */ - srcline = srcbits; - mskline = mskbits; - argb = argbbits; - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - CARD32 p = *argb++; - - if (ncolor <= 2) - { - CARD32 a = ((p >> 24)); - - SetBit (mskline, x, a != 0); - SetBit (srcline, x, a != 0 && p == twocolor[0]); - } - else - { - CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255; - CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255; - CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)]; - /* Set mask from dithered alpha value */ - SetBit(mskline, x, a > d); - /* Set src from dithered intensity value */ - SetBit(srcline, x, a > d && i <= d); - } - } - srcline += stride; - mskline += stride; - } - /* - * Dither to white and black if the cursor has more than two colors - */ - if (ncolor > 2) - { - twocolor[0] = 0xff000000; - twocolor[1] = 0xffffffff; - } - else - { - xfree (argbbits); - argbbits = 0; - } - -#define GetByte(p,s) (((p) >> (s)) & 0xff) -#define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8)) - - cm.width = width; - cm.height = height; - cm.xhot = stuff->x; - cm.yhot = stuff->y; - pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm, - GetColor(twocolor[0], 16), - GetColor(twocolor[0], 8), - GetColor(twocolor[0], 0), - GetColor(twocolor[1], 16), - GetColor(twocolor[1], 8), - GetColor(twocolor[1], 0)); - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; -} - -static int -ProcRenderSetPictureTransform (ClientPtr client) -{ - REQUEST(xRenderSetPictureTransformReq); - PicturePtr pPicture; - int result; - - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - result = SetPictureTransform (pPicture, (PictTransform *) &stuff->transform); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); -} - -static int -ProcRenderQueryFilters (ClientPtr client) -{ - REQUEST (xRenderQueryFiltersReq); - DrawablePtr pDrawable; - xRenderQueryFiltersReply *reply; - int nbytesName; - int nnames; - ScreenPtr pScreen; - PictureScreenPtr ps; - int i, j; - int len; - int total_bytes; - INT16 *aliases; - char *names; - - REQUEST_SIZE_MATCH(xRenderQueryFiltersReq); - SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client, SecurityReadAccess); - - pScreen = pDrawable->pScreen; - nbytesName = 0; - nnames = 0; - ps = GetPictureScreenIfSet(pScreen); - if (ps) - { - for (i = 0; i < ps->nfilters; i++) - nbytesName += 1 + strlen (ps->filters[i].name); - for (i = 0; i < ps->nfilterAliases; i++) - nbytesName += 1 + strlen (ps->filterAliases[i].alias); - nnames = ps->nfilters + ps->nfilterAliases; - } - len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2); - total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2); - reply = (xRenderQueryFiltersReply *) xalloc (total_bytes); - if (!reply) - return BadAlloc; - aliases = (INT16 *) (reply + 1); - names = (char *) (aliases + ((nnames + 1) & ~1)); - - reply->type = X_Reply; - reply->sequenceNumber = client->sequence; - reply->length = len; - reply->numAliases = nnames; - reply->numFilters = nnames; - if (ps) - { - - /* fill in alias values */ - for (i = 0; i < ps->nfilters; i++) - aliases[i] = FilterAliasNone; - for (i = 0; i < ps->nfilterAliases; i++) - { - for (j = 0; j < ps->nfilters; j++) - if (ps->filterAliases[i].filter_id == ps->filters[j].id) - break; - if (j == ps->nfilters) - { - for (j = 0; j < ps->nfilterAliases; j++) - if (ps->filterAliases[i].filter_id == - ps->filterAliases[j].alias_id) - { - break; - } - if (j == ps->nfilterAliases) - j = FilterAliasNone; - else - j = j + ps->nfilters; - } - aliases[i + ps->nfilters] = j; - } - - /* fill in filter names */ - for (i = 0; i < ps->nfilters; i++) - { - j = strlen (ps->filters[i].name); - *names++ = j; - strncpy (names, ps->filters[i].name, j); - names += j; - } - - /* fill in filter alias names */ - for (i = 0; i < ps->nfilterAliases; i++) - { - j = strlen (ps->filterAliases[i].alias); - *names++ = j; - strncpy (names, ps->filterAliases[i].alias, j); - names += j; - } - } - - if (client->swapped) - { - register int n; - - for (i = 0; i < reply->numAliases; i++) - { - swaps (&aliases[i], n); - } - swaps(&reply->sequenceNumber, n); - swapl(&reply->length, n); - swapl(&reply->numAliases, n); - swapl(&reply->numFilters, n); - } - WriteToClient(client, total_bytes, (char *) reply); - xfree (reply); - - return(client->noClientException); -} - -static int -ProcRenderSetPictureFilter (ClientPtr client) -{ - REQUEST (xRenderSetPictureFilterReq); - PicturePtr pPicture; - int result; - xFixed *params; - int nparams; - char *name; - - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - name = (char *) (stuff + 1); - params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3)); - nparams = ((xFixed *) stuff + client->req_len) - params; - result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams); - return result; -} - -static int -ProcRenderCreateAnimCursor (ClientPtr client) -{ - REQUEST(xRenderCreateAnimCursorReq); - CursorPtr *cursors; - CARD32 *deltas; - CursorPtr pCursor; - int ncursor; - xAnimCursorElt *elt; - int i; - int ret; - - REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq); - LEGAL_NEW_RESOURCE(stuff->cid, client); - if (client->req_len & 1) - return BadLength; - ncursor = (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1; - cursors = xalloc (ncursor * (sizeof (CursorPtr) + sizeof (CARD32))); - if (!cursors) - return BadAlloc; - deltas = (CARD32 *) (cursors + ncursor); - elt = (xAnimCursorElt *) (stuff + 1); - for (i = 0; i < ncursor; i++) - { - cursors[i] = (CursorPtr)SecurityLookupIDByType(client, elt->cursor, - RT_CURSOR, SecurityReadAccess); - if (!cursors[i]) - { - xfree (cursors); - client->errorValue = elt->cursor; - return BadCursor; - } - deltas[i] = elt->delay; - elt++; - } - ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor); - xfree (cursors); - if (ret != Success) - return ret; - - if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; - return BadAlloc; -} - -static int -ProcRenderAddTraps (ClientPtr client) -{ - int ntraps; - PicturePtr pPicture; - REQUEST(xRenderAddTrapsReq); - - REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq); - VERIFY_PICTURE (pPicture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - if (!pPicture->pDrawable) - return BadDrawable; - ntraps = (client->req_len << 2) - sizeof (xRenderAddTrapsReq); - if (ntraps % sizeof (xTrap)) - return BadLength; - ntraps /= sizeof (xTrap); - if (ntraps) - AddTraps (pPicture, - stuff->xOff, stuff->yOff, - ntraps, (xTrap *) &stuff[1]); - return client->noClientException; -} - -static int ProcRenderCreateSolidFill(ClientPtr client) -{ - PicturePtr pPicture; - int error = 0; - REQUEST(xRenderCreateSolidFillReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error); - if (!pPicture) - return error; - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int ProcRenderCreateLinearGradient (ClientPtr client) -{ - PicturePtr pPicture; - int len; - int error = 0; - xFixed *stops; - xRenderColor *colors; - REQUEST(xRenderCreateLinearGradientReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - stops = (xFixed *)(stuff + 1); - colors = (xRenderColor *)(stops + stuff->nStops); - - pPicture = CreateLinearGradientPicture (stuff->pid, &stuff->p1, &stuff->p2, - stuff->nStops, stops, colors, &error); - if (!pPicture) - return error; - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int ProcRenderCreateRadialGradient (ClientPtr client) -{ - PicturePtr pPicture; - int len; - int error = 0; - xFixed *stops; - xRenderColor *colors; - REQUEST(xRenderCreateRadialGradientReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq); - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - stops = (xFixed *)(stuff + 1); - colors = (xRenderColor *)(stops + stuff->nStops); - - pPicture = CreateRadialGradientPicture (stuff->pid, &stuff->inner, &stuff->outer, - stuff->inner_radius, stuff->outer_radius, - stuff->nStops, stops, colors, &error); - if (!pPicture) - return error; - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - -static int ProcRenderCreateConicalGradient (ClientPtr client) -{ - PicturePtr pPicture; - int len; - int error = 0; - xFixed *stops; - xRenderColor *colors; - REQUEST(xRenderCreateConicalGradientReq); - - REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq); - - LEGAL_NEW_RESOURCE(stuff->pid, client); - - len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq); - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - stops = (xFixed *)(stuff + 1); - colors = (xRenderColor *)(stops + stuff->nStops); - - pPicture = CreateConicalGradientPicture (stuff->pid, &stuff->center, stuff->angle, - stuff->nStops, stops, colors, &error); - if (!pPicture) - return error; - if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) - return BadAlloc; - return Success; -} - - -static int -ProcRenderDispatch (ClientPtr client) -{ - REQUEST(xReq); - - if (stuff->data < RenderNumberRequests) - return (*ProcRenderVector[stuff->data]) (client); - else - return BadRequest; -} - -static int -SProcRenderQueryVersion (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryVersionReq); - - swaps(&stuff->length, n); - swapl(&stuff->majorVersion, n); - swapl(&stuff->minorVersion, n); - return (*ProcRenderVector[stuff->renderReqType])(client); -} - -static int -SProcRenderQueryPictFormats (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictFormatsReq); - swaps(&stuff->length, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryPictIndexValues (ClientPtr client) -{ - register int n; - REQUEST(xRenderQueryPictIndexValuesReq); - swaps(&stuff->length, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryDithers (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreatePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreatePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->drawable, n); - swapl(&stuff->format, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderChangePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderChangePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->mask, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureClipRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureClipRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreePicture (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreePictureReq); - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderComposite (ClientPtr client) -{ - register int n; - REQUEST(xRenderCompositeReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->mask, n); - swapl(&stuff->dst, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xMask, n); - swaps(&stuff->yMask, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderScale (ClientPtr client) -{ - register int n; - REQUEST(xRenderScaleReq); - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->colorScale, n); - swapl(&stuff->alphaScale, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - swaps(&stuff->xDst, n); - swaps(&stuff->yDst, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTrapezoids (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrapezoidsReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderTrianglesReq); - - REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriStrip (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriStripReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriStripReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderTriFan (ClientPtr client) -{ - register int n; - REQUEST(xRenderTriFanReq); - - REQUEST_AT_LEAST_SIZE(xRenderTriFanReq); - swaps (&stuff->length, n); - swapl (&stuff->src, n); - swapl (&stuff->dst, n); - swapl (&stuff->maskFormat, n); - swaps (&stuff->xSrc, n); - swaps (&stuff->ySrc, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderColorTrapezoids (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderColorTriangles (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderTransform (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderCreateGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->format, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderReferenceGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderReferenceGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->gsid, n); - swapl(&stuff->existing, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFreeGlyphSet (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphSetReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphs (ClientPtr client) -{ - register int n; - register int i; - CARD32 *gids; - void *end; - xGlyphInfo *gi; - REQUEST(xRenderAddGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - swapl(&stuff->nglyphs, n); - if (stuff->nglyphs & 0xe0000000) - return BadLength; - end = (CARD8 *) stuff + (client->req_len << 2); - gids = (CARD32 *) (stuff + 1); - gi = (xGlyphInfo *) (gids + stuff->nglyphs); - if ((char *) end - (char *) (gids + stuff->nglyphs) < 0) - return BadLength; - if ((char *) end - (char *) (gi + stuff->nglyphs) < 0) - return BadLength; - for (i = 0; i < stuff->nglyphs; i++) - { - swapl (&gids[i], n); - swaps (&gi[i].width, n); - swaps (&gi[i].height, n); - swaps (&gi[i].x, n); - swaps (&gi[i].y, n); - swaps (&gi[i].xOff, n); - swaps (&gi[i].yOff, n); - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddGlyphsFromPicture (ClientPtr client) -{ - return BadImplementation; -} - -static int -SProcRenderFreeGlyphs (ClientPtr client) -{ - register int n; - REQUEST(xRenderFreeGlyphsReq); - swaps(&stuff->length, n); - swapl(&stuff->glyphset, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCompositeGlyphs (ClientPtr client) -{ - register int n; - xGlyphElt *elt; - CARD8 *buffer; - CARD8 *end; - int space; - int i; - int size; - - REQUEST(xRenderCompositeGlyphsReq); - - switch (stuff->renderReqType) { - default: size = 1; break; - case X_RenderCompositeGlyphs16: size = 2; break; - case X_RenderCompositeGlyphs32: size = 4; break; - } - - swaps(&stuff->length, n); - swapl(&stuff->src, n); - swapl(&stuff->dst, n); - swapl(&stuff->maskFormat, n); - swapl(&stuff->glyphset, n); - swaps(&stuff->xSrc, n); - swaps(&stuff->ySrc, n); - buffer = (CARD8 *) (stuff + 1); - end = (CARD8 *) stuff + (client->req_len << 2); - while (buffer + sizeof (xGlyphElt) < end) - { - elt = (xGlyphElt *) buffer; - buffer += sizeof (xGlyphElt); - - swaps (&elt->deltax, n); - swaps (&elt->deltay, n); - - i = elt->len; - if (i == 0xff) - { - swapl (buffer, n); - buffer += 4; - } - else - { - space = size * i; - switch (size) { - case 1: - buffer += i; - break; - case 2: - while (i--) - { - swaps (buffer, n); - buffer += 2; - } - break; - case 4: - while (i--) - { - swapl (buffer, n); - buffer += 4; - } - break; - } - if (space & 3) - buffer += 4 - (space & 3); - } - } - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderFillRectangles (ClientPtr client) -{ - register int n; - REQUEST(xRenderFillRectanglesReq); - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - swaps(&stuff->length, n); - swapl(&stuff->dst, n); - swaps(&stuff->color.red, n); - swaps(&stuff->color.green, n); - swaps(&stuff->color.blue, n); - swaps(&stuff->color.alpha, n); - SwapRestS(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateCursor (ClientPtr client) -{ - register int n; - REQUEST(xRenderCreateCursorReq); - REQUEST_SIZE_MATCH (xRenderCreateCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - swapl(&stuff->src, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureTransform (ClientPtr client) -{ - register int n; - REQUEST(xRenderSetPictureTransformReq); - REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swapl(&stuff->transform.matrix11, n); - swapl(&stuff->transform.matrix12, n); - swapl(&stuff->transform.matrix13, n); - swapl(&stuff->transform.matrix21, n); - swapl(&stuff->transform.matrix22, n); - swapl(&stuff->transform.matrix23, n); - swapl(&stuff->transform.matrix31, n); - swapl(&stuff->transform.matrix32, n); - swapl(&stuff->transform.matrix33, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderQueryFilters (ClientPtr client) -{ - register int n; - REQUEST (xRenderQueryFiltersReq); - REQUEST_SIZE_MATCH (xRenderQueryFiltersReq); - - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderSetPictureFilter (ClientPtr client) -{ - register int n; - REQUEST (xRenderSetPictureFilterReq); - REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swaps(&stuff->nbytes, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateAnimCursor (ClientPtr client) -{ - register int n; - REQUEST (xRenderCreateAnimCursorReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq); - - swaps(&stuff->length, n); - swapl(&stuff->cid, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderAddTraps (ClientPtr client) -{ - register int n; - REQUEST (xRenderAddTrapsReq); - REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq); - - swaps(&stuff->length, n); - swapl(&stuff->picture, n); - swaps(&stuff->xOff, n); - swaps(&stuff->yOff, n); - SwapRestL(stuff); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateSolidFill(ClientPtr client) -{ - register int n; - REQUEST (xRenderCreateSolidFillReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateSolidFillReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swaps(&stuff->color.alpha, n); - swaps(&stuff->color.red, n); - swaps(&stuff->color.green, n); - swaps(&stuff->color.blue, n); - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static void swapStops(void *stuff, int num) -{ - int i, n; - CARD32 *stops; - CARD16 *colors; - stops = (CARD32 *)(stuff); - for (i = 0; i < num; ++i) { - swapl(stops, n); - ++stops; - } - colors = (CARD16 *)(stops); - for (i = 0; i < 4*num; ++i) { - swaps(stops, n); - ++stops; - } -} - -static int -SProcRenderCreateLinearGradient (ClientPtr client) -{ - register int n; - int len; - REQUEST (xRenderCreateLinearGradientReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateLinearGradientReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->p1.x, n); - swapl(&stuff->p1.y, n); - swapl(&stuff->p2.x, n); - swapl(&stuff->p2.y, n); - swapl(&stuff->nStops, n); - - len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - swapStops(stuff+1, stuff->nStops); - - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateRadialGradient (ClientPtr client) -{ - register int n; - int len; - REQUEST (xRenderCreateRadialGradientReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateRadialGradientReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->inner.x, n); - swapl(&stuff->inner.y, n); - swapl(&stuff->outer.x, n); - swapl(&stuff->outer.y, n); - swapl(&stuff->inner_radius, n); - swapl(&stuff->outer_radius, n); - swapl(&stuff->nStops, n); - - len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - swapStops(stuff+1, stuff->nStops); - - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderCreateConicalGradient (ClientPtr client) -{ - register int n; - int len; - REQUEST (xRenderCreateConicalGradientReq); - REQUEST_AT_LEAST_SIZE (xRenderCreateConicalGradientReq); - - swaps(&stuff->length, n); - swapl(&stuff->pid, n); - swapl(&stuff->center.x, n); - swapl(&stuff->center.y, n); - swapl(&stuff->angle, n); - swapl(&stuff->nStops, n); - - len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq); - if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) - return BadLength; - - swapStops(stuff+1, stuff->nStops); - - return (*ProcRenderVector[stuff->renderReqType]) (client); -} - -static int -SProcRenderDispatch (ClientPtr client) -{ - REQUEST(xReq); - - if (stuff->data < RenderNumberRequests) - return (*SProcRenderVector[stuff->data]) (client); - else - return BadRequest; -} - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -#define VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err) {\ - pPicture = SecurityLookupIDByType(client, pid, XRT_PICTURE, mode);\ - if (!pPicture) { \ - client->errorValue = pid; \ - return err; \ - } \ -} - -#define VERIFY_XIN_ALPHA(pPicture, pid, client, mode, err) {\ - if (pid == None) \ - pPicture = 0; \ - else { \ - VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err); \ - } \ -} \ - -int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr); - -unsigned long XRT_PICTURE; - -static int -PanoramiXRenderCreatePicture (ClientPtr client) -{ - REQUEST(xRenderCreatePictureReq); - PanoramiXRes *refDraw, *newPict; - int result = Success, j; - - REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); - if(!(refDraw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - if(!(newPict = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - newPict->type = XRT_PICTURE; - newPict->info[0].id = stuff->pid; - - if (refDraw->type == XRT_WINDOW && - stuff->drawable == WindowTable[0]->drawable.id) - { - newPict->u.pict.root = TRUE; - } - else - newPict->u.pict.root = FALSE; - - for(j = 1; j < PanoramiXNumScreens; j++) - newPict->info[j].id = FakeClientID(client->index); - - FOR_NSCREENS_BACKWARD(j) { - stuff->pid = newPict->info[j].id; - stuff->drawable = refDraw->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client); - if(result != Success) break; - } - - if (result == Success) - AddResource(newPict->info[0].id, XRT_PICTURE, newPict); - else - xfree(newPict); - - return (result); -} - -static int -PanoramiXRenderChangePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderChangePictureReq); - - REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureClipRectangles (ClientPtr client) -{ - REQUEST(xRenderSetPictureClipRectanglesReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureTransform (ClientPtr client) -{ - REQUEST(xRenderSetPictureTransformReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureTransformReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureTransform]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderSetPictureFilter (ClientPtr client) -{ - REQUEST(xRenderSetPictureFilterReq); - int result = Success, j; - PanoramiXRes *pict; - - REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq); - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderSetPictureFilter]) (client); - if(result != Success) break; - } - - return (result); -} - -static int -PanoramiXRenderFreePicture (ClientPtr client) -{ - PanoramiXRes *pict; - int result = Success, j; - REQUEST(xRenderFreePictureReq); - - REQUEST_SIZE_MATCH(xRenderFreePictureReq); - - client->errorValue = stuff->picture; - - VERIFY_XIN_PICTURE(pict, stuff->picture, client, SecurityDestroyAccess, - RenderErrBase + BadPicture); - - - FOR_NSCREENS_BACKWARD(j) { - stuff->picture = pict->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client); - if(result != Success) break; - } - - /* Since ProcRenderFreePicture is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - - return (result); -} - -static int -PanoramiXRenderComposite (ClientPtr client) -{ - PanoramiXRes *src, *msk, *dst; - int result = Success, j; - xRenderCompositeReq orig; - REQUEST(xRenderCompositeReq); - - REQUEST_SIZE_MATCH(xRenderCompositeReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_ALPHA (msk, stuff->mask, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - orig = *stuff; - - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - stuff->xDst = orig.xDst - panoramiXdataPtr[j].x; - stuff->yDst = orig.yDst - panoramiXdataPtr[j].y; - } - if (msk) - { - stuff->mask = msk->info[j].id; - if (msk->u.pict.root) - { - stuff->xMask = orig.xMask - panoramiXdataPtr[j].x; - stuff->yMask = orig.yMask - panoramiXdataPtr[j].y; - } - } - result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client); - if(result != Success) break; - } - - return result; -} - -static int -PanoramiXRenderCompositeGlyphs (ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderCompositeGlyphsReq); - xGlyphElt origElt, *elt; - INT16 xSrc, ySrc; - - REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) + - sizeof (xGlyphElt))) - { - elt = (xGlyphElt *) (stuff + 1); - origElt = *elt; - xSrc = stuff->xSrc; - ySrc = stuff->ySrc; - FOR_NSCREENS_FORWARD(j) { - stuff->src = src->info[j].id; - if (src->u.pict.root) - { - stuff->xSrc = xSrc - panoramiXdataPtr[j].x; - stuff->ySrc = ySrc - panoramiXdataPtr[j].y; - } - stuff->dst = dst->info[j].id; - if (dst->u.pict.root) - { - elt->deltax = origElt.deltax - panoramiXdataPtr[j].x; - elt->deltay = origElt.deltay - panoramiXdataPtr[j].y; - } - result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client); - if(result != Success) break; - } - } - - return result; -} - -static int -PanoramiXRenderFillRectangles (ClientPtr client) -{ - PanoramiXRes *dst; - int result = Success, j; - REQUEST(xRenderFillRectanglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq); - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) - { - memcpy (extra, stuff + 1, extra_len); - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) - { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xRectangle *rects = (xRectangle *) (stuff + 1); - int i = extra_len / sizeof (xRectangle); - - while (i--) - { - rects->x -= x_off; - rects->y -= y_off; - rects++; - } - } - } - stuff->dst = dst->info[j].id; - result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client); - if(result != Success) break; - } - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTrapezoids(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTrapezoidsReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTrapezoidsReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xTrapezoid *trap = (xTrapezoid *) (stuff + 1); - int i = extra_len / sizeof (xTrapezoid); - - while (i--) { - trap->top -= y_off; - trap->bottom -= y_off; - trap->left.p1.x -= x_off; - trap->left.p1.y -= y_off; - trap->left.p2.x -= x_off; - trap->left.p2.y -= y_off; - trap->right.p1.x -= x_off; - trap->right.p1.y -= y_off; - trap->right.p2.x -= x_off; - trap->right.p2.y -= y_off; - trap++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTrapezoids]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTriangles(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTrianglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTrianglesReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTrianglesReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xTriangle *tri = (xTriangle *) (stuff + 1); - int i = extra_len / sizeof (xTriangle); - - while (i--) { - tri->p1.x -= x_off; - tri->p1.y -= y_off; - tri->p2.x -= x_off; - tri->p2.y -= y_off; - tri->p3.x -= x_off; - tri->p3.y -= y_off; - tri++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTriangles]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTriStrip(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTriStripReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTriStripReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTriStripReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xPointFixed *fixed = (xPointFixed *) (stuff + 1); - int i = extra_len / sizeof (xPointFixed); - - while (i--) { - fixed->x -= x_off; - fixed->y -= y_off; - fixed++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTriStrip]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderTriFan(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderTriFanReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderTriFanReq); - - VERIFY_XIN_PICTURE (src, stuff->src, client, SecurityReadAccess, - RenderErrBase + BadPicture); - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderTriFanReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - xPointFixed *fixed = (xPointFixed *) (stuff + 1); - int i = extra_len / sizeof (xPointFixed); - - while (i--) { - fixed->x -= x_off; - fixed->y -= y_off; - fixed++; - } - } - } - - stuff->src = src->info[j].id; - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderTriFan]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -#if 0 /* Not implemented yet */ - -static int -PanoramiXRenderColorTrapezoids(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderColorTrapezoidsReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderColorTrapezoidsReq); - - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderColorTrapezoidsReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - ....; - } - } - - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderColorTrapezoids]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -static int -PanoramiXRenderColorTriangles(ClientPtr client) -{ - PanoramiXRes *src, *dst; - int result = Success, j; - REQUEST(xRenderColorTrianglesReq); - char *extra; - int extra_len; - - REQUEST_AT_LEAST_SIZE (xRenderColorTrianglesReq); - - VERIFY_XIN_PICTURE (dst, stuff->dst, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - - extra_len = (client->req_len << 2) - sizeof (xRenderColorTrianglesReq); - - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) { - memcpy (extra, stuff + 1, extra_len); - - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - if (dst->u.pict.root) { - int x_off = panoramiXdataPtr[j].x; - int y_off = panoramiXdataPtr[j].y; - - if(x_off || y_off) { - ....; - } - } - - stuff->dst = dst->info[j].id; - result = - (*PanoramiXSaveRenderVector[X_RenderColorTriangles]) (client); - - if(result != Success) break; - } - - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -#endif - -static int -PanoramiXRenderAddTraps (ClientPtr client) -{ - PanoramiXRes *picture; - int result = Success, j; - REQUEST(xRenderAddTrapsReq); - char *extra; - int extra_len; - INT16 x_off, y_off; - - REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq); - VERIFY_XIN_PICTURE (picture, stuff->picture, client, SecurityWriteAccess, - RenderErrBase + BadPicture); - extra_len = (client->req_len << 2) - sizeof (xRenderAddTrapsReq); - if (extra_len && - (extra = (char *) ALLOCATE_LOCAL (extra_len))) - { - memcpy (extra, stuff + 1, extra_len); - x_off = stuff->xOff; - y_off = stuff->yOff; - FOR_NSCREENS_FORWARD(j) { - if (j) memcpy (stuff + 1, extra, extra_len); - stuff->picture = picture->info[j].id; - - if (picture->u.pict.root) - { - stuff->xOff = x_off + panoramiXdataPtr[j].x; - stuff->yOff = y_off + panoramiXdataPtr[j].y; - } - result = (*PanoramiXSaveRenderVector[X_RenderAddTraps]) (client); - if(result != Success) break; - } - DEALLOCATE_LOCAL(extra); - } - - return result; -} - -void -PanoramiXRenderInit (void) -{ - int i; - - XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource); - for (i = 0; i < RenderNumberRequests; i++) - PanoramiXSaveRenderVector[i] = ProcRenderVector[i]; - /* - * Stuff in Xinerama aware request processing hooks - */ - ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture; - ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture; - ProcRenderVector[X_RenderSetPictureTransform] = PanoramiXRenderSetPictureTransform; - ProcRenderVector[X_RenderSetPictureFilter] = PanoramiXRenderSetPictureFilter; - ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles; - ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture; - ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite; - ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs; - ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles; - - ProcRenderVector[X_RenderTrapezoids] = PanoramiXRenderTrapezoids; - ProcRenderVector[X_RenderTriangles] = PanoramiXRenderTriangles; - ProcRenderVector[X_RenderTriStrip] = PanoramiXRenderTriStrip; - ProcRenderVector[X_RenderTriFan] = PanoramiXRenderTriFan; - ProcRenderVector[X_RenderAddTraps] = PanoramiXRenderAddTraps; -} - -void -PanoramiXRenderReset (void) -{ - int i; - for (i = 0; i < RenderNumberRequests; i++) - ProcRenderVector[i] = PanoramiXSaveRenderVector[i]; -} - -#endif /* PANORAMIX */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original deleted file mode 100644 index d1c8325f2..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original +++ /dev/null @@ -1,1250 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $Xorg: resource.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ -/* $XdotOrg: xc/programs/Xserver/dix/resource.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */ -/* $TOG: resource.c /main/41 1998/02/09 14:20:31 kaleb $ */ - -/* Routines to manage various kinds of resources: - * - * CreateNewResourceType, CreateNewResourceClass, InitClientResources, - * FakeClientID, AddResource, FreeResource, FreeClientResources, - * FreeAllResources, LookupIDByType, LookupIDByClass, GetXIDRange - */ - -/* - * A resource ID is a 32 bit quantity, the upper 2 bits of which are - * off-limits for client-visible resources. The next 8 bits are - * used as client ID, and the low 22 bits come from the client. - * A resource ID is "hashed" by extracting and xoring subfields - * (varying with the size of the hash table). - * - * It is sometimes necessary for the server to create an ID that looks - * like it belongs to a client. This ID, however, must not be one - * the client actually can create, or we have the potential for conflict. - * The 31st bit of the ID is reserved for the server's use for this - * purpose. By setting CLIENT_ID(id) to the client, the SERVER_BIT to - * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a - * resource "owned" by the client. - */ -/* $XFree86: xc/programs/Xserver/dix/resource.c,v 3.13 2003/09/24 02:43:13 dawes Exp $ */ - -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "misc.h" -#include "os.h" -#include "resource.h" -#include "dixstruct.h" -#include "opaque.h" -#include "windowstr.h" -#include "dixfont.h" -#include "colormap.h" -#include "inputstr.h" -#include "dixevents.h" -#include "dixgrabs.h" -#include "cursor.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include - -#ifdef NXAGENT_SERVER - -#include "Agent.h" -#include "Font.h" -#include "Pixmaps.h" -#include "GCs.h" - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -#endif - -static void RebuildTable( - int /*client*/ -); - -#define SERVER_MINID 32 - -#define INITBUCKETS 64 -#define INITHASHSIZE 6 -#define MAXHASHSIZE 11 - -typedef struct _Resource { - struct _Resource *next; - XID id; - RESTYPE type; - pointer value; -} ResourceRec, *ResourcePtr; -#define NullResource ((ResourcePtr)NULL) - -typedef struct _ClientResource { - ResourcePtr *resources; - int elements; - int buckets; - int hashsize; /* log(2)(buckets) */ - XID fakeID; - XID endFakeID; - XID expectID; -} ClientResourceRec; - -RESTYPE lastResourceType; -static RESTYPE lastResourceClass; -RESTYPE TypeMask; - -static DeleteType *DeleteFuncs = (DeleteType *)NULL; - -#ifdef XResExtension - -Atom * ResourceNames = NULL; - -void RegisterResourceName (RESTYPE type, char *name) -{ - ResourceNames[type & TypeMask] = MakeAtom(name, strlen(name), TRUE); -} - -#endif - -#ifdef NXAGENT_SERVER -static int nxagentResChangedFlag = 0; -#endif - -RESTYPE -CreateNewResourceType(DeleteType deleteFunc) -{ - RESTYPE next = lastResourceType + 1; - DeleteType *funcs; - - if (next & lastResourceClass) - return 0; - funcs = (DeleteType *)xrealloc(DeleteFuncs, - (next + 1) * sizeof(DeleteType)); - if (!funcs) - return 0; - -#ifdef XResExtension - { - Atom *newnames; - newnames = xrealloc(ResourceNames, (next + 1) * sizeof(Atom)); - if(!newnames) - return 0; - ResourceNames = newnames; - ResourceNames[next] = 0; - } -#endif - - lastResourceType = next; - DeleteFuncs = funcs; - DeleteFuncs[next] = deleteFunc; - return next; -} - -RESTYPE -CreateNewResourceClass() -{ - RESTYPE next = lastResourceClass >> 1; - - if (next & lastResourceType) - return 0; - lastResourceClass = next; - TypeMask = next - 1; - return next; -} - -ClientResourceRec clientTable[MAXCLIENTS]; - -/***************** - * InitClientResources - * When a new client is created, call this to allocate space - * in resource table - *****************/ - -Bool -InitClientResources(ClientPtr client) -{ - register int i, j; - - if (client == serverClient) - { - lastResourceType = RT_LASTPREDEF; - lastResourceClass = RC_LASTPREDEF; - TypeMask = RC_LASTPREDEF - 1; - if (DeleteFuncs) - xfree(DeleteFuncs); - DeleteFuncs = (DeleteType *)xalloc((lastResourceType + 1) * - sizeof(DeleteType)); - if (!DeleteFuncs) - return FALSE; - DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA; - DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow; - DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap; - DeleteFuncs[RT_GC & TypeMask] = FreeGC; - DeleteFuncs[RT_FONT & TypeMask] = CloseFont; - DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor; - DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap; - DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels; - DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone; - DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab; - -#ifdef XResExtension - if(ResourceNames) - xfree(ResourceNames); - ResourceNames = xalloc((lastResourceType + 1) * sizeof(Atom)); - if(!ResourceNames) - return FALSE; -#endif - } - clientTable[i = client->index].resources = - (ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr)); - if (!clientTable[i].resources) - return FALSE; - clientTable[i].buckets = INITBUCKETS; - clientTable[i].elements = 0; - clientTable[i].hashsize = INITHASHSIZE; - /* Many IDs allocated from the server client are visible to clients, - * so we don't use the SERVER_BIT for them, but we have to start - * past the magic value constants used in the protocol. For normal - * clients, we can start from zero, with SERVER_BIT set. - */ - clientTable[i].fakeID = client->clientAsMask | - (client->index ? SERVER_BIT : SERVER_MINID); - clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1; - clientTable[i].expectID = client->clientAsMask; - for (j=0; j>6) ^ (id>>12)))); - case 7: - return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13)))); - case 8: - return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16)))); - case 9: - return ((int)(0x1FF & (id ^ (id>>9)))); - case 10: - return ((int)(0x3FF & (id ^ (id>>10)))); - case 11: - return ((int)(0x7FF & (id ^ (id>>11)))); - } - return -1; -} - -static XID -AvailableID( - register int client, - register XID id, - register XID maxid, - register XID goodid) -{ - register ResourcePtr res; - - if ((goodid >= id) && (goodid <= maxid)) - return goodid; - for (; id <= maxid; id++) - { - res = clientTable[client].resources[Hash(client, id)]; - while (res && (res->id != id)) - res = res->next; - if (!res) - return id; - } - return 0; -} - -void -GetXIDRange(int client, Bool server, XID *minp, XID *maxp) -{ - register XID id, maxid; - register ResourcePtr *resp; - register ResourcePtr res; - register int i; - XID goodid; - - id = (Mask)client << CLIENTOFFSET; - if (server) - id |= client ? SERVER_BIT : SERVER_MINID; - maxid = id | RESOURCE_ID_MASK; - goodid = 0; - for (resp = clientTable[client].resources, i = clientTable[client].buckets; - --i >= 0;) - { - for (res = *resp++; res; res = res->next) - { - if ((res->id < id) || (res->id > maxid)) - continue; - if (((res->id - id) >= (maxid - res->id)) ? - (goodid = AvailableID(client, id, res->id - 1, goodid)) : - !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) - maxid = res->id - 1; - else - id = res->id + 1; - } - } - if (id > maxid) - id = maxid = 0; - *minp = id; - *maxp = maxid; -} - -/** - * GetXIDList is called by the XC-MISC extension's MiscGetXIDList function. - * This function tries to find count unused XIDs for the given client. It - * puts the IDs in the array pids and returns the number found, which should - * almost always be the number requested. - * - * The circumstances that lead to a call to this function are very rare. - * Xlib must run out of IDs while trying to generate a request that wants - * multiple ID's, like the Multi-buffering CreateImageBuffers request. - * - * No rocket science in the implementation; just iterate over all - * possible IDs for the given client and pick the first count IDs - * that aren't in use. A more efficient algorithm could probably be - * invented, but this will be used so rarely that this should suffice. - */ - -unsigned int -GetXIDList(ClientPtr pClient, unsigned count, XID *pids) -{ - unsigned int found = 0; - XID id = pClient->clientAsMask; - XID maxid; - - maxid = id | RESOURCE_ID_MASK; - while ( (found < count) && (id <= maxid) ) - { - if (!LookupIDByClass(id, RC_ANY)) - { - pids[found++] = id; - } - id++; - } - return found; -} - -/* - * Return the next usable fake client ID. - * - * Normally this is just the next one in line, but if we've used the last - * in the range, we need to find a new range of safe IDs to avoid - * over-running another client. - */ - -XID -FakeClientID(register int client) -{ - XID id, maxid; - - id = clientTable[client].fakeID++; - if (id != clientTable[client].endFakeID) - return id; - GetXIDRange(client, TRUE, &id, &maxid); - if (!id) { - if (!client) - FatalError("FakeClientID: server internal ids exhausted\n"); - MarkClientException(clients[client]); - id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3); - maxid = id | RESOURCE_ID_MASK; - } - clientTable[client].fakeID = id + 1; - clientTable[client].endFakeID = maxid + 1; - return id; -} - -#ifdef NXAGENT_SERVER - -int nxagentFindClientResource(int client, RESTYPE type, pointer value) -{ - ResourcePtr pResource; - ResourcePtr *resources; - - int i; - - for (i = 0; i < clientTable[client].buckets; i++) - { - resources = clientTable[client].resources; - - for (pResource = resources[i]; pResource; pResource = pResource -> next) - { - if (pResource -> type == type && pResource -> value == value) - { - #ifdef TEST - fprintf(stderr, "nxagentFindClientResource: Found resource [%p] type [%lu] " - "for client [%d].\n", (void *) value, - pResource -> type, client); - #endif - - return 1; - } - } - } - - return 0; -} - -int nxagentSwitchResourceType(int client, RESTYPE type, pointer value) -{ - ResourcePtr pResource; - ResourcePtr *resources; - - RESTYPE internalType = 0; - - int i; - - if (type == RT_PIXMAP) - { - internalType = RT_NX_PIXMAP; - } - else if (type == RT_GC) - { - internalType = RT_NX_GC; - } - else if (type == RT_FONT) - { - internalType = RT_NX_FONT; - } - else - { - return 0; - } - - if (client == serverClient -> index) - { - #ifdef TEST - fprintf(stderr, "nxagentSwitchResourceType: Requesting client is [%d]. Skipping the resource switch.\n", - client); - #endif - - return 0; - } - - for (i = 0; i < clientTable[serverClient -> index].buckets; i++) - { - resources = clientTable[serverClient -> index].resources; - - for (pResource = resources[i]; pResource; pResource = pResource -> next) - { - if (pResource -> type == internalType && - pResource -> value == value) - { - #ifdef TEST - fprintf(stderr, "nxagentSwitchResourceType: Changing resource [%p] type from [%lu] to " - "[%lu] for server client [%d].\n", (void *) value, - (unsigned long) pResource -> type, (unsigned long) type, serverClient -> index); - #endif - - FreeResource(pResource -> id, RT_NONE); - - return 1; - } - } - } - - return 0; -} - -#endif - -Bool -AddResource(XID id, RESTYPE type, pointer value) -{ - int client; - register ClientResourceRec *rrec; - register ResourcePtr res, *head; - - client = CLIENT_ID(id); - rrec = &clientTable[client]; - if (!rrec->buckets) - { - ErrorF("AddResource(%lx, %lx, %lx), client=%d \n", - (unsigned long)id, type, (unsigned long)value, client); - FatalError("client not in use\n"); - } - -#ifdef NXAGENT_SERVER - - nxagentSwitchResourceType(client, type, value); - - #ifdef TEST - fprintf(stderr, "AddResource: Adding resource for client [%d] type [%lu] value [%p] id [%lu].\n", - client, (unsigned long) type, (void *) value, (unsigned long) id); - #endif - -#endif - - if ((rrec->elements >= 4*rrec->buckets) && - (rrec->hashsize < MAXHASHSIZE)) - RebuildTable(client); - head = &rrec->resources[Hash(client, id)]; - res = (ResourcePtr)xalloc(sizeof(ResourceRec)); - if (!res) - { - (*DeleteFuncs[type & TypeMask])(value, id); - return FALSE; - } - res->next = *head; - res->id = id; - res->type = type; - res->value = value; - *head = res; - rrec->elements++; - #ifdef NXAGENT_SERVER - nxagentResChangedFlag = 1; - #endif - if (!(id & SERVER_BIT) && (id >= rrec->expectID)) - rrec->expectID = id + 1; - return TRUE; -} - -static void -RebuildTable(int client) -{ - register int j; - register ResourcePtr res, next; - ResourcePtr **tails, *resources; - register ResourcePtr **tptr, *rptr; - - /* - * For now, preserve insertion order, since some ddx layers depend - * on resources being free in the opposite order they are added. - */ - - j = 2 * clientTable[client].buckets; - tails = (ResourcePtr **)ALLOCATE_LOCAL(j * sizeof(ResourcePtr *)); - if (!tails) - return; - resources = (ResourcePtr *)xalloc(j * sizeof(ResourcePtr)); - if (!resources) - { - DEALLOCATE_LOCAL(tails); - return; - } - for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) - { - *rptr = NullResource; - *tptr = rptr; - } - clientTable[client].hashsize++; - for (j = clientTable[client].buckets, - rptr = clientTable[client].resources; - --j >= 0; - rptr++) - { - for (res = *rptr; res; res = next) - { - next = res->next; - res->next = NullResource; - tptr = &tails[Hash(client, res->id)]; - **tptr = res; - *tptr = &res->next; - } - } - DEALLOCATE_LOCAL(tails); - clientTable[client].buckets *= 2; - xfree(clientTable[client].resources); - clientTable[client].resources = resources; -} - -void -FreeResource(XID id, RESTYPE skipDeleteFuncType) -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - register int *eltptr; - int elements; - Bool gotOne = FALSE; - -#ifdef NXAGENT_SERVER - - #ifdef TEST - fprintf(stderr, "FreeResource: Freeing resource id [%lu].\n", (unsigned long) id); - #endif - -#endif - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - eltptr = &clientTable[cid].elements; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id) - { - RESTYPE rtype = res->type; - *prev = res->next; - elements = --*eltptr; - #ifdef NXAGENT_SERVER - nxagentResChangedFlag = 1; - #endif - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - if (rtype != skipDeleteFuncType) - (*DeleteFuncs[rtype & TypeMask])(res->value, res->id); - xfree(res); - if (*eltptr != elements) - prev = head; /* prev may no longer be valid */ - gotOne = TRUE; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } - if (!gotOne) - ErrorF("Freeing resource id=%lX which isn't there.\n", - (unsigned long)id); -} - - -void -FreeResourceByType(XID id, RESTYPE type, Bool skipFree) -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id && res->type == type) - { - *prev = res->next; - #ifdef NXAGENT_SERVER - nxagentResChangedFlag = 1; - #endif - if (type & RC_CACHED) - FlushClientCaches(res->id); - if (!skipFree) - (*DeleteFuncs[type & TypeMask])(res->value, res->id); - xfree(res); - break; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } -} - -/* - * Change the value associated with a resource id. Caller - * is responsible for "doing the right thing" with the old - * data - */ - -Bool -ChangeResourceValue (XID id, RESTYPE rtype, pointer value) -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - res->value = value; - return TRUE; - } - } - return FALSE; -} - -/* Note: if func adds or deletes resources, then func can get called - * more than once for some resources. If func adds new resources, - * func might or might not get called for them. func cannot both - * add and delete an equal number of resources! - */ - -void -FindClientResourcesByType( - ClientPtr client, - RESTYPE type, - FindResType func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - #ifdef NXAGENT_SERVER - register ResourcePtr **resptr; - #endif - - if (!client) - client = serverClient; - -/* - * If func triggers a resource table - * rebuild then restart the loop. - */ - -#ifdef NXAGENT_SERVER -RestartLoop: -#endif - - resources = clientTable[client->index].resources; - - #ifdef NXAGENT_SERVER - resptr = &clientTable[client->index].resources; - #endif - - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - if (!type || this->type == type) { - elements = *eltptr; - - /* - * FIXME: - * It is not safe to let a function change the resource - * table we are reading! - */ - - #ifdef NXAGENT_SERVER - nxagentResChangedFlag = 0; - #endif - (*func)(this->value, this->id, cdata); - - /* - * Avoid that a call to RebuildTable() could invalidate the - * pointer. This is safe enough, because in RebuildTable() - * the new pointer is allocated just before the old one is - * freed, so it can't point to the same address. - */ - - #ifdef NXAGENT_SERVER - if (*resptr != resources) - goto RestartLoop; - #endif - - /* - * It's not enough to check if the number of elements has - * changed, beacause it could happen that the number of - * resources that have been added matches the number of - * the freed ones. - * 'nxagentResChangedFlag' is set if a resource has been - * added or freed. - */ - - #ifdef NXAGENT_SERVER - if (*eltptr != elements || nxagentResChangedFlag) - #else - if (*eltptr != elements) - #endif - next = resources[i]; /* start over */ - } - } - } -} - -void -FindAllClientResources( - ClientPtr client, - FindAllRes func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - #ifdef NXAGENT_SERVER - register ResourcePtr **resptr; - #endif - - if (!client) - client = serverClient; - -/* - * If func triggers a resource table - * rebuild then restart the loop. - */ - -#ifdef NXAGENT_SERVER -RestartLoop: -#endif - - resources = clientTable[client->index].resources; - - #ifdef NXAGENT_SERVER - resptr = &clientTable[client->index].resources; - #endif - - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - elements = *eltptr; - - /* - * FIXME: - * It is not safe to let a function change the resource - * table we are reading! - */ - - #ifdef NXAGENT_SERVER - nxagentResChangedFlag = 0; - #endif - (*func)(this->value, this->id, this->type, cdata); - - /* - * Avoid that a call to RebuildTable() could invalidate the - * pointer. This is safe enough, because in RebuildTable() - * the new pointer is allocated just before the old one is - * freed, so it can't point to the same address. - */ - - #ifdef NXAGENT_SERVER - if (*resptr != resources) - goto RestartLoop; - #endif - - /* - * It's not enough to check if the number of elements has - * changed, beacause it could happen that the number of - * resources that have been added matches the number of - * the freed ones. - * 'nxagentResChangedFlag' is set if a resource has been - * added or freed. - */ - - #ifdef NXAGENT_SERVER - if (*eltptr != elements || nxagentResChangedFlag) - #else - if (*eltptr != elements) - #endif - next = resources[i]; /* start over */ - } - } -} - - -pointer -LookupClientResourceComplex( - ClientPtr client, - RESTYPE type, - FindComplexResType func, - pointer cdata -){ - ResourcePtr *resources; - ResourcePtr this; - int i; - - #ifdef NXAGENT_SERVER - ResourcePtr **resptr; - Bool res; - #endif - - if (!client) - client = serverClient; - -/* - * If func triggers a resource table - * rebuild then restart the loop. - */ - -#ifdef NXAGENT_SERVER -RestartLoop: -#endif - - resources = clientTable[client->index].resources; - - #ifdef NXAGENT_SERVER - resptr = &clientTable[client->index].resources; - #endif - - for (i = 0; i < clientTable[client->index].buckets; i++) { - for (this = resources[i]; this; this = this->next) { - if (!type || this->type == type) { - #ifdef NXAGENT_SERVER - res = (*func)(this->value, this->id, cdata); - - if (*resptr != resources) - goto RestartLoop; - - if (res) - return this->value; - #else - if((*func)(this->value, this->id, cdata)) - return this->value; - #endif - } - } - } - return NULL; -} - - -void -FreeClientNeverRetainResources(ClientPtr client) -{ - ResourcePtr *resources; - ResourcePtr this; - ResourcePtr *prev; - int j; - - if (!client) - return; - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - prev = &resources[j]; - while ( (this = *prev) ) - { - RESTYPE rtype = this->type; - if (rtype & RC_NEVERRETAIN) - { - *prev = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - else - prev = &this->next; - } - } -} - -void -FreeClientResources(ClientPtr client) -{ - register ResourcePtr *resources; - register ResourcePtr this; - int j; - - /* This routine shouldn't be called with a null client, but just in - case ... */ - - if (!client) - return; - - HandleSaveSet(client); - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - /* It may seem silly to update the head of this resource list as - we delete the members, since the entire list will be deleted any way, - but there are some resource deletion functions "FreeClientPixels" for - one which do a LookupID on another resource id (a Colormap id in this - case), so the resource list must be kept valid up to the point that - it is deleted, so every time we delete a resource, we must update the - head, just like in FreeResource. I hope that this doesn't slow down - mass deletion appreciably. PRH */ - - ResourcePtr *head; - - head = &resources[j]; - - for (this = *head; this; this = *head) - { - RESTYPE rtype = this->type; - *head = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - } - xfree(clientTable[client->index].resources); - clientTable[client->index].resources = NULL; - clientTable[client->index].buckets = 0; -} - -void -FreeAllResources() -{ - int i; - - for (i = currentMaxClients; --i >= 0; ) - { - if (clientTable[i].buckets) - FreeClientResources(clients[i]); - } -} - -Bool -LegalNewID(XID id, register ClientPtr client) -{ - -#ifdef PANORAMIX - XID minid, maxid; - - if (!noPanoramiXExtension) { - minid = client->clientAsMask | (client->index ? - SERVER_BIT : SERVER_MINID); - maxid = (clientTable[client->index].fakeID | RESOURCE_ID_MASK) + 1; - if ((id >= minid) && (id <= maxid)) - return TRUE; - } -#endif /* PANORAMIX */ - return ((client->clientAsMask == (id & ~RESOURCE_ID_MASK)) && - ((clientTable[client->index].expectID <= id) || - !LookupIDByClass(id, RC_ANY))); -} - -#ifdef XCSECURITY - -/* SecurityLookupIDByType and SecurityLookupIDByClass: - * These are the heart of the resource ID security system. They take - * two additional arguments compared to the old LookupID functions: - * the client doing the lookup, and the access mode (see resource.h). - * The resource is returned if it exists and the client is allowed access, - * else NULL is returned. - */ - -pointer -SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype, Mask mode) -{ - int cid; - register ResourcePtr res; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert( (rtype & TypeMask) <= lastResourceType); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, rtype, mode, retval); - return retval; -} - - -pointer -SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes, Mask mode) -{ - int cid; - register ResourcePtr res = NULL; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert (classes >= lastResourceClass); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, res->type, mode, retval); - return retval; -} - -/* We can't replace the LookupIDByType and LookupIDByClass functions with - * macros because of compatibility with loadable servers. - */ - -pointer -LookupIDByType(XID id, RESTYPE rtype) -{ - return SecurityLookupIDByType(NullClient, id, rtype, - SecurityUnknownAccess); -} - -pointer -LookupIDByClass(XID id, RESTYPE classes) -{ - return SecurityLookupIDByClass(NullClient, id, classes, - SecurityUnknownAccess); -} - -#else /* not XCSECURITY */ - -/* - * LookupIDByType returns the object with the given id and type, else NULL. - */ -pointer -LookupIDByType(XID id, RESTYPE rtype) -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - return res->value; - } - return (pointer)NULL; -} - -/* - * LookupIDByClass returns the object with the given id and any one of the - * given classes, else NULL. - */ -pointer -LookupIDByClass(XID id, RESTYPE classes) -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - return res->value; - } - return (pointer)NULL; -} - -#endif /* XCSECURITY */ - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.X.original deleted file mode 100644 index e12bc7b67..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.X.original +++ /dev/null @@ -1,954 +0,0 @@ -/************************************************************ - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -********************************************************/ -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $Xorg: resource.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */ -/* $XdotOrg: xc/programs/Xserver/dix/resource.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */ -/* $TOG: resource.c /main/41 1998/02/09 14:20:31 kaleb $ */ - -/* Routines to manage various kinds of resources: - * - * CreateNewResourceType, CreateNewResourceClass, InitClientResources, - * FakeClientID, AddResource, FreeResource, FreeClientResources, - * FreeAllResources, LookupIDByType, LookupIDByClass, GetXIDRange - */ - -/* - * A resource ID is a 32 bit quantity, the upper 2 bits of which are - * off-limits for client-visible resources. The next 8 bits are - * used as client ID, and the low 22 bits come from the client. - * A resource ID is "hashed" by extracting and xoring subfields - * (varying with the size of the hash table). - * - * It is sometimes necessary for the server to create an ID that looks - * like it belongs to a client. This ID, however, must not be one - * the client actually can create, or we have the potential for conflict. - * The 31st bit of the ID is reserved for the server's use for this - * purpose. By setting CLIENT_ID(id) to the client, the SERVER_BIT to - * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a - * resource "owned" by the client. - */ -/* $XFree86: xc/programs/Xserver/dix/resource.c,v 3.13 2003/09/24 02:43:13 dawes Exp $ */ - -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "misc.h" -#include "os.h" -#include "resource.h" -#include "dixstruct.h" -#include "opaque.h" -#include "windowstr.h" -#include "dixfont.h" -#include "colormap.h" -#include "inputstr.h" -#include "dixevents.h" -#include "dixgrabs.h" -#include "cursor.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include - -static void RebuildTable( - int /*client*/ -); - -#define SERVER_MINID 32 - -#define INITBUCKETS 64 -#define INITHASHSIZE 6 -#define MAXHASHSIZE 11 - -typedef struct _Resource { - struct _Resource *next; - XID id; - RESTYPE type; - pointer value; -} ResourceRec, *ResourcePtr; -#define NullResource ((ResourcePtr)NULL) - -typedef struct _ClientResource { - ResourcePtr *resources; - int elements; - int buckets; - int hashsize; /* log(2)(buckets) */ - XID fakeID; - XID endFakeID; - XID expectID; -} ClientResourceRec; - -RESTYPE lastResourceType; -static RESTYPE lastResourceClass; -RESTYPE TypeMask; - -static DeleteType *DeleteFuncs = (DeleteType *)NULL; - -#ifdef XResExtension - -Atom * ResourceNames = NULL; - -void RegisterResourceName (RESTYPE type, char *name) -{ - ResourceNames[type & TypeMask] = MakeAtom(name, strlen(name), TRUE); -} - -#endif - -RESTYPE -CreateNewResourceType(DeleteType deleteFunc) -{ - RESTYPE next = lastResourceType + 1; - DeleteType *funcs; - - if (next & lastResourceClass) - return 0; - funcs = (DeleteType *)xrealloc(DeleteFuncs, - (next + 1) * sizeof(DeleteType)); - if (!funcs) - return 0; - -#ifdef XResExtension - { - Atom *newnames; - newnames = xrealloc(ResourceNames, (next + 1) * sizeof(Atom)); - if(!newnames) - return 0; - ResourceNames = newnames; - ResourceNames[next] = 0; - } -#endif - - lastResourceType = next; - DeleteFuncs = funcs; - DeleteFuncs[next] = deleteFunc; - return next; -} - -RESTYPE -CreateNewResourceClass() -{ - RESTYPE next = lastResourceClass >> 1; - - if (next & lastResourceType) - return 0; - lastResourceClass = next; - TypeMask = next - 1; - return next; -} - -ClientResourceRec clientTable[MAXCLIENTS]; - -/***************** - * InitClientResources - * When a new client is created, call this to allocate space - * in resource table - *****************/ - -Bool -InitClientResources(ClientPtr client) -{ - register int i, j; - - if (client == serverClient) - { - lastResourceType = RT_LASTPREDEF; - lastResourceClass = RC_LASTPREDEF; - TypeMask = RC_LASTPREDEF - 1; - if (DeleteFuncs) - xfree(DeleteFuncs); - DeleteFuncs = (DeleteType *)xalloc((lastResourceType + 1) * - sizeof(DeleteType)); - if (!DeleteFuncs) - return FALSE; - DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA; - DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow; - DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap; - DeleteFuncs[RT_GC & TypeMask] = FreeGC; - DeleteFuncs[RT_FONT & TypeMask] = CloseFont; - DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor; - DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap; - DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels; - DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone; - DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab; - -#ifdef XResExtension - if(ResourceNames) - xfree(ResourceNames); - ResourceNames = xalloc((lastResourceType + 1) * sizeof(Atom)); - if(!ResourceNames) - return FALSE; -#endif - } - clientTable[i = client->index].resources = - (ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr)); - if (!clientTable[i].resources) - return FALSE; - clientTable[i].buckets = INITBUCKETS; - clientTable[i].elements = 0; - clientTable[i].hashsize = INITHASHSIZE; - /* Many IDs allocated from the server client are visible to clients, - * so we don't use the SERVER_BIT for them, but we have to start - * past the magic value constants used in the protocol. For normal - * clients, we can start from zero, with SERVER_BIT set. - */ - clientTable[i].fakeID = client->clientAsMask | - (client->index ? SERVER_BIT : SERVER_MINID); - clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1; - clientTable[i].expectID = client->clientAsMask; - for (j=0; j>6) ^ (id>>12)))); - case 7: - return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13)))); - case 8: - return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16)))); - case 9: - return ((int)(0x1FF & (id ^ (id>>9)))); - case 10: - return ((int)(0x3FF & (id ^ (id>>10)))); - case 11: - return ((int)(0x7FF & (id ^ (id>>11)))); - } - return -1; -} - -static XID -AvailableID( - register int client, - register XID id, - register XID maxid, - register XID goodid) -{ - register ResourcePtr res; - - if ((goodid >= id) && (goodid <= maxid)) - return goodid; - for (; id <= maxid; id++) - { - res = clientTable[client].resources[Hash(client, id)]; - while (res && (res->id != id)) - res = res->next; - if (!res) - return id; - } - return 0; -} - -void -GetXIDRange(int client, Bool server, XID *minp, XID *maxp) -{ - register XID id, maxid; - register ResourcePtr *resp; - register ResourcePtr res; - register int i; - XID goodid; - - id = (Mask)client << CLIENTOFFSET; - if (server) - id |= client ? SERVER_BIT : SERVER_MINID; - maxid = id | RESOURCE_ID_MASK; - goodid = 0; - for (resp = clientTable[client].resources, i = clientTable[client].buckets; - --i >= 0;) - { - for (res = *resp++; res; res = res->next) - { - if ((res->id < id) || (res->id > maxid)) - continue; - if (((res->id - id) >= (maxid - res->id)) ? - (goodid = AvailableID(client, id, res->id - 1, goodid)) : - !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) - maxid = res->id - 1; - else - id = res->id + 1; - } - } - if (id > maxid) - id = maxid = 0; - *minp = id; - *maxp = maxid; -} - -/** - * GetXIDList is called by the XC-MISC extension's MiscGetXIDList function. - * This function tries to find count unused XIDs for the given client. It - * puts the IDs in the array pids and returns the number found, which should - * almost always be the number requested. - * - * The circumstances that lead to a call to this function are very rare. - * Xlib must run out of IDs while trying to generate a request that wants - * multiple ID's, like the Multi-buffering CreateImageBuffers request. - * - * No rocket science in the implementation; just iterate over all - * possible IDs for the given client and pick the first count IDs - * that aren't in use. A more efficient algorithm could probably be - * invented, but this will be used so rarely that this should suffice. - */ - -unsigned int -GetXIDList(ClientPtr pClient, unsigned count, XID *pids) -{ - unsigned int found = 0; - XID id = pClient->clientAsMask; - XID maxid; - - maxid = id | RESOURCE_ID_MASK; - while ( (found < count) && (id <= maxid) ) - { - if (!LookupIDByClass(id, RC_ANY)) - { - pids[found++] = id; - } - id++; - } - return found; -} - -/* - * Return the next usable fake client ID. - * - * Normally this is just the next one in line, but if we've used the last - * in the range, we need to find a new range of safe IDs to avoid - * over-running another client. - */ - -XID -FakeClientID(register int client) -{ - XID id, maxid; - - id = clientTable[client].fakeID++; - if (id != clientTable[client].endFakeID) - return id; - GetXIDRange(client, TRUE, &id, &maxid); - if (!id) { - if (!client) - FatalError("FakeClientID: server internal ids exhausted\n"); - MarkClientException(clients[client]); - id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3); - maxid = id | RESOURCE_ID_MASK; - } - clientTable[client].fakeID = id + 1; - clientTable[client].endFakeID = maxid + 1; - return id; -} - -Bool -AddResource(XID id, RESTYPE type, pointer value) -{ - int client; - register ClientResourceRec *rrec; - register ResourcePtr res, *head; - - client = CLIENT_ID(id); - rrec = &clientTable[client]; - if (!rrec->buckets) - { - ErrorF("AddResource(%lx, %lx, %lx), client=%d \n", - (unsigned long)id, type, (unsigned long)value, client); - FatalError("client not in use\n"); - } - if ((rrec->elements >= 4*rrec->buckets) && - (rrec->hashsize < MAXHASHSIZE)) - RebuildTable(client); - head = &rrec->resources[Hash(client, id)]; - res = (ResourcePtr)xalloc(sizeof(ResourceRec)); - if (!res) - { - (*DeleteFuncs[type & TypeMask])(value, id); - return FALSE; - } - res->next = *head; - res->id = id; - res->type = type; - res->value = value; - *head = res; - rrec->elements++; - if (!(id & SERVER_BIT) && (id >= rrec->expectID)) - rrec->expectID = id + 1; - return TRUE; -} - -static void -RebuildTable(int client) -{ - register int j; - register ResourcePtr res, next; - ResourcePtr **tails, *resources; - register ResourcePtr **tptr, *rptr; - - /* - * For now, preserve insertion order, since some ddx layers depend - * on resources being free in the opposite order they are added. - */ - - j = 2 * clientTable[client].buckets; - tails = (ResourcePtr **)ALLOCATE_LOCAL(j * sizeof(ResourcePtr *)); - if (!tails) - return; - resources = (ResourcePtr *)xalloc(j * sizeof(ResourcePtr)); - if (!resources) - { - DEALLOCATE_LOCAL(tails); - return; - } - for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) - { - *rptr = NullResource; - *tptr = rptr; - } - clientTable[client].hashsize++; - for (j = clientTable[client].buckets, - rptr = clientTable[client].resources; - --j >= 0; - rptr++) - { - for (res = *rptr; res; res = next) - { - next = res->next; - res->next = NullResource; - tptr = &tails[Hash(client, res->id)]; - **tptr = res; - *tptr = &res->next; - } - } - DEALLOCATE_LOCAL(tails); - clientTable[client].buckets *= 2; - xfree(clientTable[client].resources); - clientTable[client].resources = resources; -} - -void -FreeResource(XID id, RESTYPE skipDeleteFuncType) -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - register int *eltptr; - int elements; - Bool gotOne = FALSE; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - eltptr = &clientTable[cid].elements; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id) - { - RESTYPE rtype = res->type; - *prev = res->next; - elements = --*eltptr; - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - if (rtype != skipDeleteFuncType) - (*DeleteFuncs[rtype & TypeMask])(res->value, res->id); - xfree(res); - if (*eltptr != elements) - prev = head; /* prev may no longer be valid */ - gotOne = TRUE; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } - if (!gotOne) - ErrorF("Freeing resource id=%lX which isn't there.\n", - (unsigned long)id); -} - - -void -FreeResourceByType(XID id, RESTYPE type, Bool skipFree) -{ - int cid; - register ResourcePtr res; - register ResourcePtr *prev, *head; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id && res->type == type) - { - *prev = res->next; - if (type & RC_CACHED) - FlushClientCaches(res->id); - if (!skipFree) - (*DeleteFuncs[type & TypeMask])(res->value, res->id); - xfree(res); - break; - } - else - prev = &res->next; - } - if(clients[cid] && (id == clients[cid]->lastDrawableID)) - { - clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0]; - clients[cid]->lastDrawableID = WindowTable[0]->drawable.id; - } - } -} - -/* - * Change the value associated with a resource id. Caller - * is responsible for "doing the right thing" with the old - * data - */ - -Bool -ChangeResourceValue (XID id, RESTYPE rtype, pointer value) -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - if (rtype & RC_CACHED) - FlushClientCaches(res->id); - res->value = value; - return TRUE; - } - } - return FALSE; -} - -/* Note: if func adds or deletes resources, then func can get called - * more than once for some resources. If func adds new resources, - * func might or might not get called for them. func cannot both - * add and delete an equal number of resources! - */ - -void -FindClientResourcesByType( - ClientPtr client, - RESTYPE type, - FindResType func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - if (!type || this->type == type) { - elements = *eltptr; - (*func)(this->value, this->id, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } - } -} - -void -FindAllClientResources( - ClientPtr client, - FindAllRes func, - pointer cdata -){ - register ResourcePtr *resources; - register ResourcePtr this, next; - int i, elements; - register int *eltptr; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - elements = *eltptr; - (*func)(this->value, this->id, this->type, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } -} - - -pointer -LookupClientResourceComplex( - ClientPtr client, - RESTYPE type, - FindComplexResType func, - pointer cdata -){ - ResourcePtr *resources; - ResourcePtr this; - int i; - - if (!client) - client = serverClient; - - resources = clientTable[client->index].resources; - for (i = 0; i < clientTable[client->index].buckets; i++) { - for (this = resources[i]; this; this = this->next) { - if (!type || this->type == type) { - if((*func)(this->value, this->id, cdata)) - return this->value; - } - } - } - return NULL; -} - - -void -FreeClientNeverRetainResources(ClientPtr client) -{ - ResourcePtr *resources; - ResourcePtr this; - ResourcePtr *prev; - int j; - - if (!client) - return; - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - prev = &resources[j]; - while ( (this = *prev) ) - { - RESTYPE rtype = this->type; - if (rtype & RC_NEVERRETAIN) - { - *prev = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - else - prev = &this->next; - } - } -} - -void -FreeClientResources(ClientPtr client) -{ - register ResourcePtr *resources; - register ResourcePtr this; - int j; - - /* This routine shouldn't be called with a null client, but just in - case ... */ - - if (!client) - return; - - HandleSaveSet(client); - - resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { - /* It may seem silly to update the head of this resource list as - we delete the members, since the entire list will be deleted any way, - but there are some resource deletion functions "FreeClientPixels" for - one which do a LookupID on another resource id (a Colormap id in this - case), so the resource list must be kept valid up to the point that - it is deleted, so every time we delete a resource, we must update the - head, just like in FreeResource. I hope that this doesn't slow down - mass deletion appreciably. PRH */ - - ResourcePtr *head; - - head = &resources[j]; - - for (this = *head; this; this = *head) - { - RESTYPE rtype = this->type; - *head = this->next; - if (rtype & RC_CACHED) - FlushClientCaches(this->id); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); - } - } - xfree(clientTable[client->index].resources); - clientTable[client->index].resources = NULL; - clientTable[client->index].buckets = 0; -} - -void -FreeAllResources() -{ - int i; - - for (i = currentMaxClients; --i >= 0; ) - { - if (clientTable[i].buckets) - FreeClientResources(clients[i]); - } -} - -Bool -LegalNewID(XID id, register ClientPtr client) -{ - -#ifdef PANORAMIX - XID minid, maxid; - - if (!noPanoramiXExtension) { - minid = client->clientAsMask | (client->index ? - SERVER_BIT : SERVER_MINID); - maxid = (clientTable[client->index].fakeID | RESOURCE_ID_MASK) + 1; - if ((id >= minid) && (id <= maxid)) - return TRUE; - } -#endif /* PANORAMIX */ - return ((client->clientAsMask == (id & ~RESOURCE_ID_MASK)) && - ((clientTable[client->index].expectID <= id) || - !LookupIDByClass(id, RC_ANY))); -} - -#ifdef XCSECURITY - -/* SecurityLookupIDByType and SecurityLookupIDByClass: - * These are the heart of the resource ID security system. They take - * two additional arguments compared to the old LookupID functions: - * the client doing the lookup, and the access mode (see resource.h). - * The resource is returned if it exists and the client is allowed access, - * else NULL is returned. - */ - -pointer -SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype, Mask mode) -{ - int cid; - register ResourcePtr res; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert( (rtype & TypeMask) <= lastResourceType); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, rtype, mode, retval); - return retval; -} - - -pointer -SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes, Mask mode) -{ - int cid; - register ResourcePtr res = NULL; - pointer retval = NULL; - - assert(client == NullClient || - (client->index <= currentMaxClients && clients[client->index] == client)); - assert (classes >= lastResourceClass); - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - { - retval = res->value; - break; - } - } - if (retval && client && client->CheckAccess) - retval = (* client->CheckAccess)(client, id, res->type, mode, retval); - return retval; -} - -/* We can't replace the LookupIDByType and LookupIDByClass functions with - * macros because of compatibility with loadable servers. - */ - -pointer -LookupIDByType(XID id, RESTYPE rtype) -{ - return SecurityLookupIDByType(NullClient, id, rtype, - SecurityUnknownAccess); -} - -pointer -LookupIDByClass(XID id, RESTYPE classes) -{ - return SecurityLookupIDByClass(NullClient, id, classes, - SecurityUnknownAccess); -} - -#else /* not XCSECURITY */ - -/* - * LookupIDByType returns the object with the given id and type, else NULL. - */ -pointer -LookupIDByType(XID id, RESTYPE rtype) -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - return res->value; - } - return (pointer)NULL; -} - -/* - * LookupIDByClass returns the object with the given id and any one of the - * given classes, else NULL. - */ -pointer -LookupIDByClass(XID id, RESTYPE classes) -{ - int cid; - register ResourcePtr res; - - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && - clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; - - for (; res; res = res->next) - if ((res->id == id) && (res->type & classes)) - return res->value; - } - return (pointer)NULL; -} - -#endif /* XCSECURITY */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.NX.original deleted file mode 100644 index eaaa92041..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.NX.original +++ /dev/null @@ -1,1498 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/Xext/shm.c,v 3.41 2003/12/17 23:28:56 alanh Exp $ */ -/************************************************************ - -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -********************************************************/ - -/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */ - -/* $Xorg: shm.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */ - -#define SHM - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#ifndef Lynx -#include -#include -#else -#include -#include -#endif -#include -#include -#define NEED_REPLIES -#define NEED_EVENTS -#include -#include -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "extnsionst.h" -#include "servermd.h" -#define _XSHM_SERVER_ -#include -#include -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -#include "modinit.h" - -#include "Trap.h" -#include "Agent.h" -#include "Drawable.h" -#include "Pixmaps.h" - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -#ifdef TEST -#include "Literals.h" -#endif - -extern void fbGetImage(DrawablePtr pDrw, int x, int y, int w, int h, - unsigned int format, unsigned long planeMask, char *d); - -extern void fbPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, - int x, int y, int w, int h, int leftPad, int format, - char *pImage); - -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -static void miShmPutImage(XSHM_PUT_IMAGE_ARGS); -static void fbShmPutImage(XSHM_PUT_IMAGE_ARGS); -static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS); -static int ShmDetachSegment( - pointer /* value */, - XID /* shmseg */ - ); -static void ShmResetProc( - ExtensionEntry * /* extEntry */ - ); -static void SShmCompletionEvent( - xShmCompletionEvent * /* from */, - xShmCompletionEvent * /* to */ - ); - -static Bool ShmDestroyPixmap (PixmapPtr pPixmap); - -static DISPATCH_PROC(ProcShmAttach); -static DISPATCH_PROC(ProcShmCreatePixmap); -static DISPATCH_PROC(ProcShmDetach); -static DISPATCH_PROC(ProcShmDispatch); -static DISPATCH_PROC(ProcShmGetImage); -static DISPATCH_PROC(ProcShmPutImage); -static DISPATCH_PROC(ProcShmQueryVersion); -static DISPATCH_PROC(SProcShmAttach); -static DISPATCH_PROC(SProcShmCreatePixmap); -static DISPATCH_PROC(SProcShmDetach); -static DISPATCH_PROC(SProcShmDispatch); -static DISPATCH_PROC(SProcShmGetImage); -static DISPATCH_PROC(SProcShmPutImage); -static DISPATCH_PROC(SProcShmQueryVersion); - -static unsigned char ShmReqCode; -int ShmCompletionCode; -int BadShmSegCode; -RESTYPE ShmSegType; -static ShmDescPtr Shmsegs; -static Bool sharedPixmaps; -static int pixmapFormat; -static int shmPixFormat[MAXSCREENS]; -static ShmFuncsPtr shmFuncs[MAXSCREENS]; -static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS]; -#ifdef PIXPRIV -static int shmPixmapPrivate; -#endif -static ShmFuncs miFuncs = {NULL, miShmPutImage}; -static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage}; - -#define VERIFY_SHMSEG(shmseg,shmdesc,client) \ -{ \ - shmdesc = (ShmDescPtr)LookupIDByType(shmseg, ShmSegType); \ - if (!shmdesc) \ - { \ - client->errorValue = shmseg; \ - return BadShmSegCode; \ - } \ -} - -#define VERIFY_SHMPTR(shmseg,offset,needwrite,shmdesc,client) \ -{ \ - VERIFY_SHMSEG(shmseg, shmdesc, client); \ - if ((offset & 3) || (offset > shmdesc->size)) \ - { \ - client->errorValue = offset; \ - return BadValue; \ - } \ - if (needwrite && !shmdesc->writable) \ - return BadAccess; \ -} - -#define VERIFY_SHMSIZE(shmdesc,offset,len,client) \ -{ \ - if ((offset + len) > shmdesc->size) \ - { \ - return BadAccess; \ - } \ -} - - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) -#include - -static Bool badSysCall = FALSE; - -static void -SigSysHandler(signo) -int signo; -{ - badSysCall = TRUE; -} - -static Bool CheckForShmSyscall() -{ - void (*oldHandler)(); - int shmid = -1; - - /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */ - oldHandler = signal(SIGSYS, SigSysHandler); - - badSysCall = FALSE; - shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT); - - if (shmid != -1) - { - /* Successful allocation - clean up */ - shmctl(shmid, IPC_RMID, (struct shmid_ds *)NULL); - } - else - { - /* Allocation failed */ - badSysCall = TRUE; - } - signal(SIGSYS, oldHandler); - return(!badSysCall); -} - -#define MUST_CHECK_FOR_SHM_SYSCALL - -#endif - -void -ShmExtensionInit(INITARGS) -{ - ExtensionEntry *extEntry; - int i; - -#ifdef MUST_CHECK_FOR_SHM_SYSCALL - if (!CheckForShmSyscall()) - { - ErrorF("MIT-SHM extension disabled due to lack of kernel support\n"); - return; - } -#endif - - if (nxagentOption(SharedMemory) == False) - { - return; - } - - sharedPixmaps = xFalse; - pixmapFormat = 0; - { - sharedPixmaps = nxagentOption(SharedPixmaps); - pixmapFormat = shmPixFormat[0]; - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!shmFuncs[i]) - { - #ifdef TEST - fprintf(stderr, "ShmExtensionInit: Registering shmFuncs as miFuncs.\n"); - #endif - shmFuncs[i] = &miFuncs; - } - if (!shmFuncs[i]->CreatePixmap) - sharedPixmaps = xFalse; - if (shmPixFormat[i] && (shmPixFormat[i] != pixmapFormat)) - { - sharedPixmaps = xFalse; - pixmapFormat = 0; - } - } - if (!pixmapFormat) - pixmapFormat = ZPixmap; - if (sharedPixmaps) - { - for (i = 0; i < screenInfo.numScreens; i++) - { - destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap; - screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap; - } -#ifdef PIXPRIV - shmPixmapPrivate = AllocatePixmapPrivateIndex(); - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!AllocatePixmapPrivate(screenInfo.screens[i], - shmPixmapPrivate, 0)) - return; - } -#endif - } - } - ShmSegType = CreateNewResourceType(ShmDetachSegment); - if (ShmSegType && - (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors, - ProcShmDispatch, SProcShmDispatch, - ShmResetProc, StandardMinorOpcode))) - { - ShmReqCode = (unsigned char)extEntry->base; - ShmCompletionCode = extEntry->eventBase; - BadShmSegCode = extEntry->errorBase; - EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent; - } -} - -/*ARGSUSED*/ -static void -ShmResetProc (extEntry) -ExtensionEntry *extEntry; -{ - int i; - - for (i = 0; i < MAXSCREENS; i++) - { - shmFuncs[i] = (ShmFuncsPtr)NULL; - shmPixFormat[i] = 0; - } -} - -void -ShmRegisterFuncs( - ScreenPtr pScreen, - ShmFuncsPtr funcs) -{ - shmFuncs[pScreen->myNum] = funcs; -} - -void -ShmSetPixmapFormat( - ScreenPtr pScreen, - int format) -{ - shmPixFormat[pScreen->myNum] = format; -} - -static Bool -ShmDestroyPixmap (PixmapPtr pPixmap) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - Bool ret; - if (pPixmap->refcnt == 1) - { - ShmDescPtr shmdesc; -#ifdef PIXPRIV - shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr; -#else - char *base = (char *) pPixmap->devPrivate.ptr; - - if (base != (pointer) (pPixmap + 1)) - { - for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) - { - if (shmdesc->addr <= base && base <= shmdesc->addr + shmdesc->size) - break; - } - } - else - shmdesc = 0; -#endif - if (shmdesc) - ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id); - } - - pScreen->DestroyPixmap = destroyPixmap[pScreen->myNum]; - ret = (*pScreen->DestroyPixmap) (pPixmap); - destroyPixmap[pScreen->myNum] = pScreen->DestroyPixmap; - pScreen->DestroyPixmap = ShmDestroyPixmap; - return ret; -} - -void -ShmRegisterFbFuncs(pScreen) - ScreenPtr pScreen; -{ - #ifdef TEST - fprintf(stderr, "ShmRegisterFbFuncs: Registering shmFuncs as fbFuncs.\n"); - #endif - shmFuncs[pScreen->myNum] = &fbFuncs; -} - -static int -ProcShmQueryVersion(client) - register ClientPtr client; -{ - xShmQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xShmQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.sharedPixmaps = sharedPixmaps; - rep.pixmapFormat = pixmapFormat; - rep.majorVersion = SHM_MAJOR_VERSION; - rep.minorVersion = SHM_MINOR_VERSION; - rep.uid = geteuid(); - rep.gid = getegid(); - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - swaps(&rep.uid, n); - swaps(&rep.gid, n); - } - WriteToClient(client, sizeof(xShmQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -/* - * Simulate the access() system call for a shared memory segement, - * using the credentials from the client if available - */ -static int -shm_access(ClientPtr client, struct ipc_perm *perm, int readonly) -{ - int uid, gid; - mode_t mask; - - if (LocalClientCred(client, &uid, &gid) != -1) { - - /* User id 0 always gets access */ - if (uid == 0) { - return 0; - } - /* Check the owner */ - if (perm->uid == uid || perm->cuid == uid) { - mask = S_IRUSR; - if (!readonly) { - mask |= S_IWUSR; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - /* Check the group */ - if (perm->gid == gid || perm->cgid == gid) { - mask = S_IRGRP; - if (!readonly) { - mask |= S_IWGRP; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - } - /* Otherwise, check everyone else */ - mask = S_IROTH; - if (!readonly) { - mask |= S_IWOTH; - } - return (perm->mode & mask) == mask ? 0 : -1; -} - -static int -ProcShmAttach(client) - register ClientPtr client; -{ - struct shmid_ds buf; - ShmDescPtr shmdesc; - REQUEST(xShmAttachReq); - - REQUEST_SIZE_MATCH(xShmAttachReq); - LEGAL_NEW_RESOURCE(stuff->shmseg, client); - if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) - { - client->errorValue = stuff->readOnly; - return(BadValue); - } - for (shmdesc = Shmsegs; - shmdesc && (shmdesc->shmid != stuff->shmid); - shmdesc = shmdesc->next) - ; - if (shmdesc) - { - if (!stuff->readOnly && !shmdesc->writable) - return BadAccess; - shmdesc->refcnt++; - } - else - { - shmdesc = (ShmDescPtr) xalloc(sizeof(ShmDescRec)); - if (!shmdesc) - return BadAlloc; - shmdesc->addr = shmat(stuff->shmid, 0, - stuff->readOnly ? SHM_RDONLY : 0); - if ((shmdesc->addr == ((char *)-1)) || - shmctl(stuff->shmid, IPC_STAT, &buf)) - { - xfree(shmdesc); - return BadAccess; - } - - /* The attach was performed with root privs. We must - * do manual checking of access rights for the credentials - * of the client */ - - if (shm_access(client, &(buf.shm_perm), stuff->readOnly) == -1) { - shmdt(shmdesc->addr); - xfree(shmdesc); - return BadAccess; - } - - shmdesc->shmid = stuff->shmid; - shmdesc->refcnt = 1; - shmdesc->writable = !stuff->readOnly; - shmdesc->size = buf.shm_segsz; - shmdesc->next = Shmsegs; - Shmsegs = shmdesc; - } - if (!AddResource(stuff->shmseg, ShmSegType, (pointer)shmdesc)) - return BadAlloc; - return(client->noClientException); -} - -/*ARGSUSED*/ -static int -ShmDetachSegment(value, shmseg) - pointer value; /* must conform to DeleteType */ - XID shmseg; -{ - ShmDescPtr shmdesc = (ShmDescPtr)value; - ShmDescPtr *prev; - - if (--shmdesc->refcnt) - return TRUE; - shmdt(shmdesc->addr); - for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next) - ; - *prev = shmdesc->next; - xfree(shmdesc); - return Success; -} - -static int -ProcShmDetach(client) - register ClientPtr client; -{ - ShmDescPtr shmdesc; - REQUEST(xShmDetachReq); - - REQUEST_SIZE_MATCH(xShmDetachReq); - VERIFY_SHMSEG(stuff->shmseg, shmdesc, client); - FreeResource(stuff->shmseg, RT_NONE); - return(client->noClientException); -} - -static void -miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - PixmapPtr pmap; - GCPtr putGC; - - nxagentShmTrap = 0; - putGC = GetScratchGC(depth, dst->pScreen); - if (!putGC) - { - nxagentShmTrap = 1; - return; - } - pmap = (*dst->pScreen->CreatePixmap)(dst->pScreen, sw, sh, depth); - if (!pmap) - { - nxagentShmTrap = 1; - FreeScratchGC(putGC); - return; - } - ValidateGC((DrawablePtr)pmap, putGC); - (*putGC->ops->PutImage)((DrawablePtr)pmap, putGC, depth, -sx, -sy, w, h, 0, - (format == XYPixmap) ? XYPixmap : ZPixmap, data); - FreeScratchGC(putGC); - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy); - (*pmap->drawable.pScreen->DestroyPixmap)(pmap); - nxagentShmTrap = 1; -} - -static void -fbShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - int length; - char *newdata; - extern int nxagentImageLength(int, int, int, int, int); - - #ifdef TEST - fprintf(stderr, "fbShmPutImage: Called with drawable at [%p] GC at [%p] data at [%p].\n", - (void *) dst, (void *) pGC, (void *) data); - #endif - - if ((format == ZPixmap) || (depth == 1)) - { - PixmapPtr pPixmap; - - pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth, - BitsPerPixel(depth), PixmapBytePad(w, depth), (pointer)data); - if (!pPixmap) - return; - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy); - - /* - * We updated the internal framebuffer, - * now we want to go on the real X. - */ - - #ifdef TEST - fprintf(stderr, "fbShmPutImage: Realizing the PutImage with depth [%d] " - " format [%d] w [%d] h [%d] sx [%d] sy [%d] sw [%d] " - " sh [%d] dx [%d].\n", depth, format, w, h, - sx, sy, sw, sh, dx); - #endif - - length = nxagentImageLength(sw, sh, format, 0, depth); - - if ((newdata = xalloc(length)) != NULL) - { - fbGetImage((DrawablePtr) pPixmap, sx, sy, sw, sh, format, AllPlanes, newdata); - (*pGC->ops->PutImage)(dst, pGC, depth, dx, dy, sw, sh, 0, format, newdata); - - xfree(newdata); - } - else - { - #ifdef WARNING - fprintf(stderr, "fbShmPutImage: WARNING! Data allocation failed.\n"); - #endif - } - - FreeScratchPixmapHeader(pPixmap); - } - else - { - #ifdef TEST - fprintf(stderr, "fbShmPutImage: Calling miShmPutImage().\n"); - #endif - miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, - data); - } -} - - -#ifdef PANORAMIX -static int -ProcPanoramiXShmPutImage(register ClientPtr client) -{ - int j, result = 0, orig_x, orig_y; - PanoramiXRes *draw, *gc; - Bool sendEvent, isRoot; - - REQUEST(xShmPutImageReq); - REQUEST_SIZE_MATCH(xShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - orig_x = stuff->dstX; - orig_y = stuff->dstY; - sendEvent = stuff->sendEvent; - stuff->sendEvent = 0; - FOR_NSCREENS(j) { - if(!j) stuff->sendEvent = sendEvent; - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->dstX = orig_x - panoramiXdataPtr[j].x; - stuff->dstY = orig_y - panoramiXdataPtr[j].y; - } - result = ProcShmPutImage(client); - if(result != client->noClientException) break; - } - return(result); -} - -static int -ProcPanoramiXShmGetImage(ClientPtr client) -{ - PanoramiXRes *draw; - DrawablePtr drawables[MAXSCREENS]; - DrawablePtr pDraw; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int i, x, y, w, h, format; - Mask plane = 0, planemask; - long lenPer = 0, length, widthBytesLine; - Bool isRoot; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { - client->errorValue = stuff->format; - return(BadValue); - } - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if (draw->type == XRT_PIXMAP) - return ProcShmGetImage(client); - - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - x = stuff->x; - y = stuff->y; - w = stuff->width; - h = stuff->height; - format = stuff->format; - planemask = stuff->planeMask; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - if(isRoot) { - if( /* check for being onscreen */ - x < 0 || x + w > PanoramiXPixWidth || - y < 0 || y + h > PanoramiXPixHeight ) - return(BadMatch); - } else { - if( /* check for being onscreen */ - panoramiXdataPtr[0].x + pDraw->x + x < 0 || - panoramiXdataPtr[0].x + pDraw->x + x + w > PanoramiXPixWidth || - panoramiXdataPtr[0].y + pDraw->y + y < 0 || - panoramiXdataPtr[0].y + pDraw->y + y + h > PanoramiXPixHeight || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height) - return(BadMatch); - } - - drawables[0] = pDraw; - for(i = 1; i < PanoramiXNumScreens; i++) - VERIFY_DRAWABLE(drawables[i], draw->info[i].id, client); - - xgi.visual = wVisual(((WindowPtr)pDraw)); - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - - if(format == ZPixmap) { - widthBytesLine = PixmapBytePad(w, pDraw->depth); - length = widthBytesLine * h; - } else { - widthBytesLine = PixmapBytePad(w, 1); - lenPer = widthBytesLine * h; - plane = ((Mask)1) << (pDraw->depth - 1); - length = lenPer * Ones(planemask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) {/* nothing to do */ } - else if (format == ZPixmap) { - XineramaGetImageData(drawables, x, y, w, h, format, planemask, - shmdesc->addr + stuff->offset, - widthBytesLine, isRoot); - } else { - - length = stuff->offset; - for (; plane; plane >>= 1) { - if (planemask & plane) { - XineramaGetImageData(drawables, x, y, w, h, - format, plane, shmdesc->addr + length, - widthBytesLine, isRoot); - length += lenPer; - } - } - } - - if (client->swapped) { - register int n; - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static int -ProcPanoramiXShmCreatePixmap( - register ClientPtr client) -{ - ScreenPtr pScreen = NULL; - PixmapPtr pMap = NULL; - DrawablePtr pDraw; - DepthPtr pDepth; - int i, j, result; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - unsigned int width, height, depth; - unsigned long size; - PanoramiXRes *newPix; - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - width = stuff->width; - height = stuff->height; - depth = stuff->depth; - if (!width || !height || !depth) - { - client->errorValue = 0; - return BadValue; - } - if (width > 32767 || height > 32767) - return BadAlloc; - - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } - -CreatePmap: - size = PixmapBytePad(width, depth) * height; - if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { - if (size < width * height) - return BadAlloc; - /* thankfully, offset is unsigned */ - if (stuff->offset + size < size) - return BadAlloc; - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); - - if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - - newPix->type = XRT_PIXMAP; - newPix->u.pix.shared = TRUE; - newPix->info[0].id = stuff->pid; - for(j = 1; j < PanoramiXNumScreens; j++) - newPix->info[j].id = FakeClientID(client->index); - - result = (client->noClientException); - - FOR_NSCREENS(j) { - pScreen = screenInfo.screens[j]; - - pMap = (*shmFuncs[j]->CreatePixmap)(pScreen, - stuff->width, stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - - if (pMap) { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = newPix->info[j].id; - if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer)pMap)) { - (*pScreen->DestroyPixmap)(pMap); - result = BadAlloc; - break; - } - } else { - result = BadAlloc; - break; - } - } - - if(result == BadAlloc) { - while(j--) { - (*pScreen->DestroyPixmap)(pMap); - FreeResource(newPix->info[j].id, RT_NONE); - } - xfree(newPix); - } else - AddResource(stuff->pid, XRT_PIXMAP, newPix); - - return result; -} - -#endif - -static int -ProcShmPutImage(client) - register ClientPtr client; -{ - register GCPtr pGC; - register DrawablePtr pDraw; - long length; - ShmDescPtr shmdesc; - REQUEST(xShmPutImageReq); - - REQUEST_SIZE_MATCH(xShmPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client); - if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse)) - return BadValue; - if (stuff->format == XYBitmap) - { - if (stuff->depth != 1) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - } - else if (stuff->format == XYPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - /* - * There's a potential integer overflow in this check: - * VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight, - * client); - * the version below ought to avoid it - */ - if (stuff->totalHeight != 0 && - length > (shmdesc->size - stuff->offset)/stuff->totalHeight) { - client->errorValue = stuff->totalWidth; - return BadValue; - } - if (stuff->srcX > stuff->totalWidth) - { - client->errorValue = stuff->srcX; - return BadValue; - } - if (stuff->srcY > stuff->totalHeight) - { - client->errorValue = stuff->srcY; - return BadValue; - } - if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth) - { - client->errorValue = stuff->srcWidth; - return BadValue; - } - if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight) - { - client->errorValue = stuff->srcHeight; - return BadValue; - } - - #ifdef TEST - fprintf(stderr, "ProcShmPutImage: Format [%d] srcX [%d] srcY [%d], " - "totalWidth [%d] totalHeight [%d]\n", stuff->format, stuff->srcX, - stuff->srcY, stuff->totalWidth, stuff->totalHeight); - #endif - - #ifdef TEST - fprintf(stderr, "ProcShmPutImage: Calling (*shmFuncs[pDraw->pScreen->myNum]->PutImage)().\n"); - #endif - - (*shmFuncs[pDraw->pScreen->myNum]->PutImage)( - pDraw, pGC, stuff->depth, stuff->format, - stuff->totalWidth, stuff->totalHeight, - stuff->srcX, stuff->srcY, - stuff->srcWidth, stuff->srcHeight, - stuff->dstX, stuff->dstY, - shmdesc->addr + stuff->offset); - - if (stuff->sendEvent) - { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = X_ShmPutImage; - ev.majorEvent = ShmReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return (client->noClientException); -} - - - -static int -ProcShmGetImage(client) - register ClientPtr client; -{ - register DrawablePtr pDraw; - long lenPer = 0, length; - Mask plane = 0; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int n; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) - { - client->errorValue = stuff->format; - return(BadValue); - } - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + stuff->x < 0 || - pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width || - pDraw->y + stuff->y < 0 || - pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height || - /* check for being inside of border */ - stuff->x < - wBorderWidth((WindowPtr)pDraw) || - stuff->x + (int)stuff->width > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - stuff->y < -wBorderWidth((WindowPtr)pDraw) || - stuff->y + (int)stuff->height > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual(((WindowPtr)pDraw)); - } - else - { - if (stuff->x < 0 || - stuff->x+(int)stuff->width > pDraw->width || - stuff->y < 0 || - stuff->y+(int)stuff->height > pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(stuff->format == ZPixmap) - { - length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height; - } - else - { - lenPer = PixmapBytePad(stuff->width, 1) * stuff->height; - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) - { - /* nothing to do */ - } - else if (stuff->format == ZPixmap) - { - (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, stuff->planeMask, - shmdesc->addr + stuff->offset); - } - else - { - - length = stuff->offset; - for (; plane; plane >>= 1) - { - if (stuff->planeMask & plane) - { - (*pDraw->pScreen->GetImage)(pDraw, - stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, plane, - shmdesc->addr + length); - length += lenPer; - } - } - } - - if (client->swapped) { - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static PixmapPtr -fbShmCreatePixmap (pScreen, width, height, depth, addr) - ScreenPtr pScreen; - int width; - int height; - int depth; - char *addr; -{ - register PixmapPtr pPixmap; - - nxagentShmPixmapTrap = 1; - - pPixmap = (*pScreen->CreatePixmap)(pScreen, width, height, depth); - - if (!pPixmap) - { - nxagentShmPixmapTrap = 0; - - return NullPixmap; - } - - #ifdef TEST - fprintf(stderr,"fbShmCreatePixmap: Width [%d] Height [%d] Depth [%d]\n", width, height, depth); - #endif - - if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - BitsPerPixel(depth), PixmapBytePad(width, depth), (pointer)addr)) - { - #ifdef WARNING - fprintf(stderr,"fbShmCreatePixmap: Return Null Pixmap.\n"); - #endif - - (*pScreen->DestroyPixmap)(pPixmap); - - nxagentShmPixmapTrap = 0; - - return NullPixmap; - } - - nxagentShmPixmapTrap = 0; - - return pPixmap; -} - -static int -ProcShmCreatePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - DepthPtr pDepth; - register int i; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - unsigned int width, height, depth; - unsigned long size; - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - width = stuff->width; - height = stuff->height; - depth = stuff->depth; - if (!width || !height || !depth) - { - client->errorValue = 0; - return BadValue; - } - if (width > 32767 || height > 32767) - return BadAlloc; - - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } - -CreatePmap: - size = PixmapBytePad(width, depth) * height; - if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { - if (size < width * height) - return BadAlloc; - /* thankfully, offset is unsigned */ - if (stuff->offset + size < size) - return BadAlloc; - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); - pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)( - pDraw->pScreen, stuff->width, - stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - if (pMap) - { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - { - return(client->noClientException); - } - } - return (BadAlloc); -} - -static int -ProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - - #ifdef TEST - fprintf(stderr, "ProcShmDispatch: Going to execute operation [%d] for client [%d].\n", - stuff -> data, client -> index); - - if (stuff->data <= X_ShmCreatePixmap) - { - fprintf(stderr, "ProcShmDispatch: Request [%s] OPCODE#%d.\n", - nxagentShmRequestLiteral[stuff->data], stuff->data); - } - #endif - - switch (stuff->data) - { - case X_ShmQueryVersion: - return ProcShmQueryVersion(client); - case X_ShmAttach: - return ProcShmAttach(client); - case X_ShmDetach: - return ProcShmDetach(client); - case X_ShmPutImage: - { - int result; - - #ifdef TEST - fprintf(stderr, "ProcShmDispatch: Going to execute ProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - nxagentShmTrap = 1; - -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - { - result = ProcPanoramiXShmPutImage(client); - - nxagentShmTrap = 0; - - return result; - } -#endif - - result = ProcShmPutImage(client); - - nxagentShmTrap = 0; - - #ifdef TEST - fprintf(stderr, "ProcShmDispatch: Returning from ProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - return result; - } - case X_ShmGetImage: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmGetImage(client); -#endif - return ProcShmGetImage(client); - case X_ShmCreatePixmap: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmCreatePixmap(client); -#endif - return ProcShmCreatePixmap(client); - default: - return BadRequest; - } -} - -static void -SShmCompletionEvent(from, to) - xShmCompletionEvent *from, *to; -{ - to->type = from->type; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->drawable, to->drawable); - cpswaps(from->minorEvent, to->minorEvent); - to->majorEvent = from->majorEvent; - cpswapl(from->shmseg, to->shmseg); - cpswapl(from->offset, to->offset); -} - -static int -SProcShmQueryVersion(client) - register ClientPtr client; -{ - register int n; - REQUEST(xShmQueryVersionReq); - - swaps(&stuff->length, n); - return ProcShmQueryVersion(client); -} - -static int -SProcShmAttach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmAttachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmAttachReq); - swapl(&stuff->shmseg, n); - swapl(&stuff->shmid, n); - return ProcShmAttach(client); -} - -static int -SProcShmDetach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmDetachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmDetachReq); - swapl(&stuff->shmseg, n); - return ProcShmDetach(client); -} - -static int -SProcShmPutImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmPutImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmPutImageReq); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->totalWidth, n); - swaps(&stuff->totalHeight, n); - swaps(&stuff->srcX, n); - swaps(&stuff->srcY, n); - swaps(&stuff->srcWidth, n); - swaps(&stuff->srcHeight, n); - swaps(&stuff->dstX, n); - swaps(&stuff->dstY, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmPutImage(client); -} - -static int -SProcShmGetImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmGetImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmGetImageReq); - swapl(&stuff->drawable, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->planeMask, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmGetImage(client); -} - -static int -SProcShmCreatePixmap(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmCreatePixmapReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - swapl(&stuff->pid, n); - swapl(&stuff->drawable, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmCreatePixmap(client); -} - -static int -SProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - - #ifdef TEST - fprintf(stderr, "SProcShmDispatch: Going to execute operation [%d] for client [%d].\n", - stuff -> data, client -> index); - #endif - - switch (stuff->data) - { - case X_ShmQueryVersion: - return SProcShmQueryVersion(client); - case X_ShmAttach: - return SProcShmAttach(client); - case X_ShmDetach: - return SProcShmDetach(client); - case X_ShmPutImage: - { - int result; - - #ifdef TEST - fprintf(stderr, "SProcShmDispatch: Going to execute SProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - nxagentShmTrap = 1; - - result = SProcShmPutImage(client); - - nxagentShmTrap = 0; - - #ifdef TEST - fprintf(stderr, "SProcShmDispatch: Returning from SProcShmPutImage() for client [%d].\n", - client -> index); - #endif - - return result; - } - case X_ShmGetImage: - return SProcShmGetImage(client); - case X_ShmCreatePixmap: - return SProcShmCreatePixmap(client); - default: - return BadRequest; - } -} - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.X.original deleted file mode 100644 index f25bb9b5d..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXshm.c.X.original +++ /dev/null @@ -1,1310 +0,0 @@ -/* $XFree86: xc/programs/Xserver/Xext/shm.c,v 3.41 2003/12/17 23:28:56 alanh Exp $ */ -/************************************************************ - -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -********************************************************/ - -/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */ - -/* $Xorg: shm.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */ - -#define SHM - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#ifndef Lynx -#include -#include -#else -#include -#include -#endif -#include -#include -#define NEED_REPLIES -#define NEED_EVENTS -#include -#include -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "extnsionst.h" -#include "servermd.h" -#define _XSHM_SERVER_ -#include -#include -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif - -#include "modinit.h" - -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -static void miShmPutImage(XSHM_PUT_IMAGE_ARGS); -static void fbShmPutImage(XSHM_PUT_IMAGE_ARGS); -static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS); -static int ShmDetachSegment( - pointer /* value */, - XID /* shmseg */ - ); -static void ShmResetProc( - ExtensionEntry * /* extEntry */ - ); -static void SShmCompletionEvent( - xShmCompletionEvent * /* from */, - xShmCompletionEvent * /* to */ - ); - -static Bool ShmDestroyPixmap (PixmapPtr pPixmap); - -static DISPATCH_PROC(ProcShmAttach); -static DISPATCH_PROC(ProcShmCreatePixmap); -static DISPATCH_PROC(ProcShmDetach); -static DISPATCH_PROC(ProcShmDispatch); -static DISPATCH_PROC(ProcShmGetImage); -static DISPATCH_PROC(ProcShmPutImage); -static DISPATCH_PROC(ProcShmQueryVersion); -static DISPATCH_PROC(SProcShmAttach); -static DISPATCH_PROC(SProcShmCreatePixmap); -static DISPATCH_PROC(SProcShmDetach); -static DISPATCH_PROC(SProcShmDispatch); -static DISPATCH_PROC(SProcShmGetImage); -static DISPATCH_PROC(SProcShmPutImage); -static DISPATCH_PROC(SProcShmQueryVersion); - -static unsigned char ShmReqCode; -int ShmCompletionCode; -int BadShmSegCode; -RESTYPE ShmSegType; -static ShmDescPtr Shmsegs; -static Bool sharedPixmaps; -static int pixmapFormat; -static int shmPixFormat[MAXSCREENS]; -static ShmFuncsPtr shmFuncs[MAXSCREENS]; -static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS]; -#ifdef PIXPRIV -static int shmPixmapPrivate; -#endif -static ShmFuncs miFuncs = {NULL, miShmPutImage}; -static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage}; - -#define VERIFY_SHMSEG(shmseg,shmdesc,client) \ -{ \ - shmdesc = (ShmDescPtr)LookupIDByType(shmseg, ShmSegType); \ - if (!shmdesc) \ - { \ - client->errorValue = shmseg; \ - return BadShmSegCode; \ - } \ -} - -#define VERIFY_SHMPTR(shmseg,offset,needwrite,shmdesc,client) \ -{ \ - VERIFY_SHMSEG(shmseg, shmdesc, client); \ - if ((offset & 3) || (offset > shmdesc->size)) \ - { \ - client->errorValue = offset; \ - return BadValue; \ - } \ - if (needwrite && !shmdesc->writable) \ - return BadAccess; \ -} - -#define VERIFY_SHMSIZE(shmdesc,offset,len,client) \ -{ \ - if ((offset + len) > shmdesc->size) \ - { \ - return BadAccess; \ - } \ -} - - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) -#include - -static Bool badSysCall = FALSE; - -static void -SigSysHandler(signo) -int signo; -{ - badSysCall = TRUE; -} - -static Bool CheckForShmSyscall() -{ - void (*oldHandler)(); - int shmid = -1; - - /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */ - oldHandler = signal(SIGSYS, SigSysHandler); - - badSysCall = FALSE; - shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT); - - if (shmid != -1) - { - /* Successful allocation - clean up */ - shmctl(shmid, IPC_RMID, (struct shmid_ds *)NULL); - } - else - { - /* Allocation failed */ - badSysCall = TRUE; - } - signal(SIGSYS, oldHandler); - return(!badSysCall); -} - -#define MUST_CHECK_FOR_SHM_SYSCALL - -#endif - -void -ShmExtensionInit(INITARGS) -{ - ExtensionEntry *extEntry; - int i; - -#ifdef MUST_CHECK_FOR_SHM_SYSCALL - if (!CheckForShmSyscall()) - { - ErrorF("MIT-SHM extension disabled due to lack of kernel support\n"); - return; - } -#endif - - sharedPixmaps = xFalse; - pixmapFormat = 0; - { - sharedPixmaps = xTrue; - pixmapFormat = shmPixFormat[0]; - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!shmFuncs[i]) - shmFuncs[i] = &miFuncs; - if (!shmFuncs[i]->CreatePixmap) - sharedPixmaps = xFalse; - if (shmPixFormat[i] && (shmPixFormat[i] != pixmapFormat)) - { - sharedPixmaps = xFalse; - pixmapFormat = 0; - } - } - if (!pixmapFormat) - pixmapFormat = ZPixmap; - if (sharedPixmaps) - { - for (i = 0; i < screenInfo.numScreens; i++) - { - destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap; - screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap; - } -#ifdef PIXPRIV - shmPixmapPrivate = AllocatePixmapPrivateIndex(); - for (i = 0; i < screenInfo.numScreens; i++) - { - if (!AllocatePixmapPrivate(screenInfo.screens[i], - shmPixmapPrivate, 0)) - return; - } -#endif - } - } - ShmSegType = CreateNewResourceType(ShmDetachSegment); - if (ShmSegType && - (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors, - ProcShmDispatch, SProcShmDispatch, - ShmResetProc, StandardMinorOpcode))) - { - ShmReqCode = (unsigned char)extEntry->base; - ShmCompletionCode = extEntry->eventBase; - BadShmSegCode = extEntry->errorBase; - EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent; - } -} - -/*ARGSUSED*/ -static void -ShmResetProc (extEntry) -ExtensionEntry *extEntry; -{ - int i; - - for (i = 0; i < MAXSCREENS; i++) - { - shmFuncs[i] = (ShmFuncsPtr)NULL; - shmPixFormat[i] = 0; - } -} - -void -ShmRegisterFuncs( - ScreenPtr pScreen, - ShmFuncsPtr funcs) -{ - shmFuncs[pScreen->myNum] = funcs; -} - -void -ShmSetPixmapFormat( - ScreenPtr pScreen, - int format) -{ - shmPixFormat[pScreen->myNum] = format; -} - -static Bool -ShmDestroyPixmap (PixmapPtr pPixmap) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - Bool ret; - if (pPixmap->refcnt == 1) - { - ShmDescPtr shmdesc; -#ifdef PIXPRIV - shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr; -#else - char *base = (char *) pPixmap->devPrivate.ptr; - - if (base != (pointer) (pPixmap + 1)) - { - for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) - { - if (shmdesc->addr <= base && base <= shmdesc->addr + shmdesc->size) - break; - } - } - else - shmdesc = 0; -#endif - if (shmdesc) - ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id); - } - - pScreen->DestroyPixmap = destroyPixmap[pScreen->myNum]; - ret = (*pScreen->DestroyPixmap) (pPixmap); - destroyPixmap[pScreen->myNum] = pScreen->DestroyPixmap; - pScreen->DestroyPixmap = ShmDestroyPixmap; - return ret; -} - -void -ShmRegisterFbFuncs(pScreen) - ScreenPtr pScreen; -{ - shmFuncs[pScreen->myNum] = &fbFuncs; -} - -static int -ProcShmQueryVersion(client) - register ClientPtr client; -{ - xShmQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xShmQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.sharedPixmaps = sharedPixmaps; - rep.pixmapFormat = pixmapFormat; - rep.majorVersion = SHM_MAJOR_VERSION; - rep.minorVersion = SHM_MINOR_VERSION; - rep.uid = geteuid(); - rep.gid = getegid(); - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - swaps(&rep.uid, n); - swaps(&rep.gid, n); - } - WriteToClient(client, sizeof(xShmQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -/* - * Simulate the access() system call for a shared memory segement, - * using the credentials from the client if available - */ -static int -shm_access(ClientPtr client, struct ipc_perm *perm, int readonly) -{ - int uid, gid; - mode_t mask; - - if (LocalClientCred(client, &uid, &gid) != -1) { - - /* User id 0 always gets access */ - if (uid == 0) { - return 0; - } - /* Check the owner */ - if (perm->uid == uid || perm->cuid == uid) { - mask = S_IRUSR; - if (!readonly) { - mask |= S_IWUSR; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - /* Check the group */ - if (perm->gid == gid || perm->cgid == gid) { - mask = S_IRGRP; - if (!readonly) { - mask |= S_IWGRP; - } - return (perm->mode & mask) == mask ? 0 : -1; - } - } - /* Otherwise, check everyone else */ - mask = S_IROTH; - if (!readonly) { - mask |= S_IWOTH; - } - return (perm->mode & mask) == mask ? 0 : -1; -} - -static int -ProcShmAttach(client) - register ClientPtr client; -{ - struct shmid_ds buf; - ShmDescPtr shmdesc; - REQUEST(xShmAttachReq); - - REQUEST_SIZE_MATCH(xShmAttachReq); - LEGAL_NEW_RESOURCE(stuff->shmseg, client); - if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) - { - client->errorValue = stuff->readOnly; - return(BadValue); - } - for (shmdesc = Shmsegs; - shmdesc && (shmdesc->shmid != stuff->shmid); - shmdesc = shmdesc->next) - ; - if (shmdesc) - { - if (!stuff->readOnly && !shmdesc->writable) - return BadAccess; - shmdesc->refcnt++; - } - else - { - shmdesc = (ShmDescPtr) xalloc(sizeof(ShmDescRec)); - if (!shmdesc) - return BadAlloc; - shmdesc->addr = shmat(stuff->shmid, 0, - stuff->readOnly ? SHM_RDONLY : 0); - if ((shmdesc->addr == ((char *)-1)) || - shmctl(stuff->shmid, IPC_STAT, &buf)) - { - xfree(shmdesc); - return BadAccess; - } - - /* The attach was performed with root privs. We must - * do manual checking of access rights for the credentials - * of the client */ - - if (shm_access(client, &(buf.shm_perm), stuff->readOnly) == -1) { - shmdt(shmdesc->addr); - xfree(shmdesc); - return BadAccess; - } - - shmdesc->shmid = stuff->shmid; - shmdesc->refcnt = 1; - shmdesc->writable = !stuff->readOnly; - shmdesc->size = buf.shm_segsz; - shmdesc->next = Shmsegs; - Shmsegs = shmdesc; - } - if (!AddResource(stuff->shmseg, ShmSegType, (pointer)shmdesc)) - return BadAlloc; - return(client->noClientException); -} - -/*ARGSUSED*/ -static int -ShmDetachSegment(value, shmseg) - pointer value; /* must conform to DeleteType */ - XID shmseg; -{ - ShmDescPtr shmdesc = (ShmDescPtr)value; - ShmDescPtr *prev; - - if (--shmdesc->refcnt) - return TRUE; - shmdt(shmdesc->addr); - for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next) - ; - *prev = shmdesc->next; - xfree(shmdesc); - return Success; -} - -static int -ProcShmDetach(client) - register ClientPtr client; -{ - ShmDescPtr shmdesc; - REQUEST(xShmDetachReq); - - REQUEST_SIZE_MATCH(xShmDetachReq); - VERIFY_SHMSEG(stuff->shmseg, shmdesc, client); - FreeResource(stuff->shmseg, RT_NONE); - return(client->noClientException); -} - -static void -miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - PixmapPtr pmap; - GCPtr putGC; - - putGC = GetScratchGC(depth, dst->pScreen); - if (!putGC) - return; - pmap = (*dst->pScreen->CreatePixmap)(dst->pScreen, sw, sh, depth); - if (!pmap) - { - FreeScratchGC(putGC); - return; - } - ValidateGC((DrawablePtr)pmap, putGC); - (*putGC->ops->PutImage)((DrawablePtr)pmap, putGC, depth, -sx, -sy, w, h, 0, - (format == XYPixmap) ? XYPixmap : ZPixmap, data); - FreeScratchGC(putGC); - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh, - dx, dy); - (*pmap->drawable.pScreen->DestroyPixmap)(pmap); -} - -static void -fbShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data) - DrawablePtr dst; - GCPtr pGC; - int depth, w, h, sx, sy, sw, sh, dx, dy; - unsigned int format; - char *data; -{ - if ((format == ZPixmap) || (depth == 1)) - { - PixmapPtr pPixmap; - - pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth, - BitsPerPixel(depth), PixmapBytePad(w, depth), (pointer)data); - if (!pPixmap) - return; - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, dst, pGC, - sx, sy, sw, sh, dx, dy); - FreeScratchPixmapHeader(pPixmap); - } - else - miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, - data); -} - - -#ifdef PANORAMIX -static int -ProcPanoramiXShmPutImage(register ClientPtr client) -{ - int j, result = 0, orig_x, orig_y; - PanoramiXRes *draw, *gc; - Bool sendEvent, isRoot; - - REQUEST(xShmPutImageReq); - REQUEST_SIZE_MATCH(xShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - orig_x = stuff->dstX; - orig_y = stuff->dstY; - sendEvent = stuff->sendEvent; - stuff->sendEvent = 0; - FOR_NSCREENS(j) { - if(!j) stuff->sendEvent = sendEvent; - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->dstX = orig_x - panoramiXdataPtr[j].x; - stuff->dstY = orig_y - panoramiXdataPtr[j].y; - } - result = ProcShmPutImage(client); - if(result != client->noClientException) break; - } - return(result); -} - -static int -ProcPanoramiXShmGetImage(ClientPtr client) -{ - PanoramiXRes *draw; - DrawablePtr drawables[MAXSCREENS]; - DrawablePtr pDraw; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int i, x, y, w, h, format; - Mask plane = 0, planemask; - long lenPer = 0, length, widthBytesLine; - Bool isRoot; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { - client->errorValue = stuff->format; - return(BadValue); - } - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if (draw->type == XRT_PIXMAP) - return ProcShmGetImage(client); - - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - x = stuff->x; - y = stuff->y; - w = stuff->width; - h = stuff->height; - format = stuff->format; - planemask = stuff->planeMask; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - if(isRoot) { - if( /* check for being onscreen */ - x < 0 || x + w > PanoramiXPixWidth || - y < 0 || y + h > PanoramiXPixHeight ) - return(BadMatch); - } else { - if( /* check for being onscreen */ - panoramiXdataPtr[0].x + pDraw->x + x < 0 || - panoramiXdataPtr[0].x + pDraw->x + x + w > PanoramiXPixWidth || - panoramiXdataPtr[0].y + pDraw->y + y < 0 || - panoramiXdataPtr[0].y + pDraw->y + y + h > PanoramiXPixHeight || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height) - return(BadMatch); - } - - drawables[0] = pDraw; - for(i = 1; i < PanoramiXNumScreens; i++) - VERIFY_DRAWABLE(drawables[i], draw->info[i].id, client); - - xgi.visual = wVisual(((WindowPtr)pDraw)); - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - - if(format == ZPixmap) { - widthBytesLine = PixmapBytePad(w, pDraw->depth); - length = widthBytesLine * h; - } else { - widthBytesLine = PixmapBytePad(w, 1); - lenPer = widthBytesLine * h; - plane = ((Mask)1) << (pDraw->depth - 1); - length = lenPer * Ones(planemask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) {/* nothing to do */ } - else if (format == ZPixmap) { - XineramaGetImageData(drawables, x, y, w, h, format, planemask, - shmdesc->addr + stuff->offset, - widthBytesLine, isRoot); - } else { - - length = stuff->offset; - for (; plane; plane >>= 1) { - if (planemask & plane) { - XineramaGetImageData(drawables, x, y, w, h, - format, plane, shmdesc->addr + length, - widthBytesLine, isRoot); - length += lenPer; - } - } - } - - if (client->swapped) { - register int n; - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static int -ProcPanoramiXShmCreatePixmap( - register ClientPtr client) -{ - ScreenPtr pScreen = NULL; - PixmapPtr pMap = NULL; - DrawablePtr pDraw; - DepthPtr pDepth; - int i, j, result; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - unsigned int width, height, depth; - unsigned long size; - PanoramiXRes *newPix; - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - width = stuff->width; - height = stuff->height; - depth = stuff->depth; - if (!width || !height || !depth) - { - client->errorValue = 0; - return BadValue; - } - if (width > 32767 || height > 32767) - return BadAlloc; - - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } - -CreatePmap: - size = PixmapBytePad(width, depth) * height; - if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { - if (size < width * height) - return BadAlloc; - /* thankfully, offset is unsigned */ - if (stuff->offset + size < size) - return BadAlloc; - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); - - if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes)))) - return BadAlloc; - - newPix->type = XRT_PIXMAP; - newPix->u.pix.shared = TRUE; - newPix->info[0].id = stuff->pid; - for(j = 1; j < PanoramiXNumScreens; j++) - newPix->info[j].id = FakeClientID(client->index); - - result = (client->noClientException); - - FOR_NSCREENS(j) { - pScreen = screenInfo.screens[j]; - - pMap = (*shmFuncs[j]->CreatePixmap)(pScreen, - stuff->width, stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - - if (pMap) { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = newPix->info[j].id; - if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer)pMap)) { - (*pScreen->DestroyPixmap)(pMap); - result = BadAlloc; - break; - } - } else { - result = BadAlloc; - break; - } - } - - if(result == BadAlloc) { - while(j--) { - (*pScreen->DestroyPixmap)(pMap); - FreeResource(newPix->info[j].id, RT_NONE); - } - xfree(newPix); - } else - AddResource(stuff->pid, XRT_PIXMAP, newPix); - - return result; -} - -#endif - -static int -ProcShmPutImage(client) - register ClientPtr client; -{ - register GCPtr pGC; - register DrawablePtr pDraw; - long length; - ShmDescPtr shmdesc; - REQUEST(xShmPutImageReq); - - REQUEST_SIZE_MATCH(xShmPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client); - if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse)) - return BadValue; - if (stuff->format == XYBitmap) - { - if (stuff->depth != 1) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - } - else if (stuff->format == XYPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, 1); - length *= stuff->depth; - } - else if (stuff->format == ZPixmap) - { - if (pDraw->depth != stuff->depth) - return BadMatch; - length = PixmapBytePad(stuff->totalWidth, stuff->depth); - } - else - { - client->errorValue = stuff->format; - return BadValue; - } - - /* - * There's a potential integer overflow in this check: - * VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight, - * client); - * the version below ought to avoid it - */ - if (stuff->totalHeight != 0 && - length > (shmdesc->size - stuff->offset)/stuff->totalHeight) { - client->errorValue = stuff->totalWidth; - return BadValue; - } - if (stuff->srcX > stuff->totalWidth) - { - client->errorValue = stuff->srcX; - return BadValue; - } - if (stuff->srcY > stuff->totalHeight) - { - client->errorValue = stuff->srcY; - return BadValue; - } - if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth) - { - client->errorValue = stuff->srcWidth; - return BadValue; - } - if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight) - { - client->errorValue = stuff->srcHeight; - return BadValue; - } - - if ((((stuff->format == ZPixmap) && (stuff->srcX == 0)) || - ((stuff->format != ZPixmap) && - (stuff->srcX < screenInfo.bitmapScanlinePad) && - ((stuff->format == XYBitmap) || - ((stuff->srcY == 0) && - (stuff->srcHeight == stuff->totalHeight))))) && - ((stuff->srcX + stuff->srcWidth) == stuff->totalWidth)) - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, - stuff->dstX, stuff->dstY, - stuff->totalWidth, stuff->srcHeight, - stuff->srcX, stuff->format, - shmdesc->addr + stuff->offset + - (stuff->srcY * length)); - else - (*shmFuncs[pDraw->pScreen->myNum]->PutImage)( - pDraw, pGC, stuff->depth, stuff->format, - stuff->totalWidth, stuff->totalHeight, - stuff->srcX, stuff->srcY, - stuff->srcWidth, stuff->srcHeight, - stuff->dstX, stuff->dstY, - shmdesc->addr + stuff->offset); - - if (stuff->sendEvent) - { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = X_ShmPutImage; - ev.majorEvent = ShmReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return (client->noClientException); -} - - - -static int -ProcShmGetImage(client) - register ClientPtr client; -{ - register DrawablePtr pDraw; - long lenPer = 0, length; - Mask plane = 0; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int n; - - REQUEST(xShmGetImageReq); - - REQUEST_SIZE_MATCH(xShmGetImageReq); - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) - { - client->errorValue = stuff->format; - return(BadValue); - } - VERIFY_DRAWABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + stuff->x < 0 || - pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width || - pDraw->y + stuff->y < 0 || - pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height || - /* check for being inside of border */ - stuff->x < - wBorderWidth((WindowPtr)pDraw) || - stuff->x + (int)stuff->width > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - stuff->y < -wBorderWidth((WindowPtr)pDraw) || - stuff->y + (int)stuff->height > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual(((WindowPtr)pDraw)); - } - else - { - if (stuff->x < 0 || - stuff->x+(int)stuff->width > pDraw->width || - stuff->y < 0 || - stuff->y+(int)stuff->height > pDraw->height - ) - return(BadMatch); - xgi.visual = None; - } - xgi.type = X_Reply; - xgi.length = 0; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; - if(stuff->format == ZPixmap) - { - length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height; - } - else - { - lenPer = PixmapBytePad(stuff->width, 1) * stuff->height; - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); - xgi.size = length; - - if (length == 0) - { - /* nothing to do */ - } - else if (stuff->format == ZPixmap) - { - (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, stuff->planeMask, - shmdesc->addr + stuff->offset); - } - else - { - - length = stuff->offset; - for (; plane; plane >>= 1) - { - if (stuff->planeMask & plane) - { - (*pDraw->pScreen->GetImage)(pDraw, - stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, plane, - shmdesc->addr + length); - length += lenPer; - } - } - } - - if (client->swapped) { - swaps(&xgi.sequenceNumber, n); - swapl(&xgi.length, n); - swapl(&xgi.visual, n); - swapl(&xgi.size, n); - } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); - - return(client->noClientException); -} - -static PixmapPtr -fbShmCreatePixmap (pScreen, width, height, depth, addr) - ScreenPtr pScreen; - int width; - int height; - int depth; - char *addr; -{ - register PixmapPtr pPixmap; - - pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth); - if (!pPixmap) - return NullPixmap; - - if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - BitsPerPixel(depth), PixmapBytePad(width, depth), (pointer)addr)) { - (*pScreen->DestroyPixmap)(pPixmap); - return NullPixmap; - } - return pPixmap; -} - -static int -ProcShmCreatePixmap(client) - register ClientPtr client; -{ - PixmapPtr pMap; - register DrawablePtr pDraw; - DepthPtr pDepth; - register int i; - ShmDescPtr shmdesc; - REQUEST(xShmCreatePixmapReq); - unsigned int width, height, depth; - unsigned long size; - - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - client->errorValue = stuff->pid; - if (!sharedPixmaps) - return BadImplementation; - LEGAL_NEW_RESOURCE(stuff->pid, client); - VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); - VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - - width = stuff->width; - height = stuff->height; - depth = stuff->depth; - if (!width || !height || !depth) - { - client->errorValue = 0; - return BadValue; - } - if (width > 32767 || height > 32767) - return BadAlloc; - - if (stuff->depth != 1) - { - pDepth = pDraw->pScreen->allowedDepths; - for (i=0; ipScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; - return BadValue; - } - -CreatePmap: - size = PixmapBytePad(width, depth) * height; - if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { - if (size < width * height) - return BadAlloc; - /* thankfully, offset is unsigned */ - if (stuff->offset + size < size) - return BadAlloc; - } - - VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); - pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)( - pDraw->pScreen, stuff->width, - stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - if (pMap) - { -#ifdef PIXPRIV - pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc; -#endif - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - { - return(client->noClientException); - } - } - return (BadAlloc); -} - -static int -ProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - switch (stuff->data) - { - case X_ShmQueryVersion: - return ProcShmQueryVersion(client); - case X_ShmAttach: - return ProcShmAttach(client); - case X_ShmDetach: - return ProcShmDetach(client); - case X_ShmPutImage: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmPutImage(client); -#endif - return ProcShmPutImage(client); - case X_ShmGetImage: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmGetImage(client); -#endif - return ProcShmGetImage(client); - case X_ShmCreatePixmap: -#ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmCreatePixmap(client); -#endif - return ProcShmCreatePixmap(client); - default: - return BadRequest; - } -} - -static void -SShmCompletionEvent(from, to) - xShmCompletionEvent *from, *to; -{ - to->type = from->type; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->drawable, to->drawable); - cpswaps(from->minorEvent, to->minorEvent); - to->majorEvent = from->majorEvent; - cpswapl(from->shmseg, to->shmseg); - cpswapl(from->offset, to->offset); -} - -static int -SProcShmQueryVersion(client) - register ClientPtr client; -{ - register int n; - REQUEST(xShmQueryVersionReq); - - swaps(&stuff->length, n); - return ProcShmQueryVersion(client); -} - -static int -SProcShmAttach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmAttachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmAttachReq); - swapl(&stuff->shmseg, n); - swapl(&stuff->shmid, n); - return ProcShmAttach(client); -} - -static int -SProcShmDetach(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmDetachReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmDetachReq); - swapl(&stuff->shmseg, n); - return ProcShmDetach(client); -} - -static int -SProcShmPutImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmPutImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmPutImageReq); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->totalWidth, n); - swaps(&stuff->totalHeight, n); - swaps(&stuff->srcX, n); - swaps(&stuff->srcY, n); - swaps(&stuff->srcWidth, n); - swaps(&stuff->srcHeight, n); - swaps(&stuff->dstX, n); - swaps(&stuff->dstY, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmPutImage(client); -} - -static int -SProcShmGetImage(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmGetImageReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmGetImageReq); - swapl(&stuff->drawable, n); - swaps(&stuff->x, n); - swaps(&stuff->y, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->planeMask, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmGetImage(client); -} - -static int -SProcShmCreatePixmap(client) - ClientPtr client; -{ - register int n; - REQUEST(xShmCreatePixmapReq); - swaps(&stuff->length, n); - REQUEST_SIZE_MATCH(xShmCreatePixmapReq); - swapl(&stuff->pid, n); - swapl(&stuff->drawable, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->offset, n); - return ProcShmCreatePixmap(client); -} - -static int -SProcShmDispatch (client) - register ClientPtr client; -{ - REQUEST(xReq); - switch (stuff->data) - { - case X_ShmQueryVersion: - return SProcShmQueryVersion(client); - case X_ShmAttach: - return SProcShmAttach(client); - case X_ShmDetach: - return SProcShmDetach(client); - case X_ShmPutImage: - return SProcShmPutImage(client); - case X_ShmGetImage: - return SProcShmGetImage(client); - case X_ShmCreatePixmap: - return SProcShmCreatePixmap(client); - default: - return BadRequest; - } -} diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.NX.original deleted file mode 100644 index 76e86fd2a..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.NX.original +++ /dev/null @@ -1,4167 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XdotOrg: xc/programs/Xserver/dix/window.c,v 1.12 2005/07/03 08:53:38 daniels Exp $ */ -/* $Xorg: window.c,v 1.4 2001/02/09 02:04:41 xorgcvs Exp $ */ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -*/ - -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/window.c,v 3.36 2003/11/14 23:52:50 torrey Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#include "selection.h" -#ifdef PANORAMIX -#include "../../Xext/panoramiX.h" -#include "../../Xext/panoramiXsrv.h" -#endif -#include "dixevents.h" -#include "globals.h" - -#ifdef XAPPGROUP -#include -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif - -#include "Screen.h" -#include "Options.h" -#include "Atoms.h" -#include "Clipboard.h" -#include "Splash.h" -#include "Rootless.h" -#include "Composite.h" -#include "Drawable.h" -#include "Colormap.h" - -extern Bool nxagentWMIsRunning; -extern Bool nxagentScreenTrap; - -/****** - * Window stuff for server - * - * CreateRootWindow, CreateWindow, ChangeWindowAttributes, - * GetWindowAttributes, DeleteWindow, DestroySubWindows, - * HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows, - * UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow, - * - ******/ - -static unsigned char _back_lsb[4] = {0x88, 0x22, 0x44, 0x11}; -static unsigned char _back_msb[4] = {0x11, 0x44, 0x22, 0x88}; - -int screenIsSaved = SCREEN_SAVER_OFF; - -ScreenSaverStuffRec savedScreenInfo[MAXSCREENS]; - -#if 0 -extern void DeleteWindowFromAnyEvents(); -extern Mask EventMaskForClient(); -extern void WindowHasNewCursor(); -extern void RecalculateDeliverableEvents(); -#endif - -static Bool TileScreenSaver(int i, int kind); - - -#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \ - CWDontPropagate | CWOverrideRedirect | CWCursor ) - -#define BOXES_OVERLAP(b1, b2) \ - (!( ((b1)->x2 <= (b2)->x1) || \ - ( ((b1)->x1 >= (b2)->x2)) || \ - ( ((b1)->y2 <= (b2)->y1)) || \ - ( ((b1)->y1 >= (b2)->y2)) ) ) - -#define RedirectSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask) - -#define SubSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask) - -#define StrSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask) - -#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent)) - - -/* - * Set here the required log level. - */ - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -int numSaveUndersViewable = 0; -int deltaSaveUndersViewable = 0; - -WindowPtr nxagentRootTileWindow; - -/* - * This block used the DEBUG symbol. - */ - -#ifdef WINDOW_TREE_DEBUG -/****** - * PrintWindowTree - * For debugging only - ******/ - -int -PrintChildren(WindowPtr p1, int indent) -{ - WindowPtr p2; - int i; - - while (p1) - { - p2 = p1->firstChild; - for (i=0; idrawable.id); - miPrintRegion(&p1->clipList); - PrintChildren(p2, indent+4); - p1 = p1->nextSib; - } -} - -PrintWindowTree() -{ - int i; - WindowPtr pWin, p1; - - for (i=0; iclipList); - p1 = pWin->firstChild; - PrintChildren(p1, 4); - } -} -#endif - -int -TraverseTree(register WindowPtr pWin, VisitWindowProcPtr func, pointer data) -{ - register int result; - register WindowPtr pChild; - - if (!(pChild = pWin)) - return(WT_NOMATCH); - while (1) - { - result = (* func)(pChild, data); - if (result == WT_STOPWALKING) - return(WT_STOPWALKING); - if ((result == WT_WALKCHILDREN) && pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - return(WT_NOMATCH); -} - -/***** - * WalkTree - * Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on - * each window. If FUNC returns WT_WALKCHILDREN, traverse the children, - * if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING - * exit WalkTree. Does depth-first traverse. - *****/ - -int -WalkTree(ScreenPtr pScreen, VisitWindowProcPtr func, pointer data) -{ - return(TraverseTree(WindowTable[pScreen->myNum], func, data)); -} - -/* hack for forcing backing store on all windows */ -int defaultBackingStore = NotUseful; -/* hack to force no backing store */ -Bool disableBackingStore = FALSE; -Bool enableBackingStore = FALSE; -/* hack to force no save unders */ -Bool disableSaveUnders = FALSE; - -static void -SetWindowToDefaults(register WindowPtr pWin) -{ - pWin->prevSib = NullWindow; - pWin->firstChild = NullWindow; - pWin->lastChild = NullWindow; - - pWin->valdata = (ValidatePtr)NULL; - pWin->optional = (WindowOptPtr)NULL; - pWin->cursorIsNone = TRUE; - - pWin->backingStore = NotUseful; - pWin->DIXsaveUnder = FALSE; - pWin->backStorage = (pointer) NULL; - - pWin->mapped = FALSE; /* off */ - pWin->realized = FALSE; /* off */ - pWin->viewable = FALSE; - pWin->visibility = VisibilityNotViewable; - pWin->overrideRedirect = FALSE; - pWin->saveUnder = FALSE; - - pWin->bitGravity = ForgetGravity; - pWin->winGravity = NorthWestGravity; - - pWin->eventMask = 0; - pWin->deliverableEvents = 0; - pWin->dontPropagate = 0; - pWin->forcedBS = FALSE; -#ifdef NEED_DBE_BUF_BITS - pWin->srcBuffer = DBE_FRONT_BUFFER; - pWin->dstBuffer = DBE_FRONT_BUFFER; -#endif -#ifdef COMPOSITE - pWin->redirectDraw = 0; -#endif -} - -#ifdef NXAGENT_SERVER - -void nxagentClearSplash(WindowPtr pW) -{ - int w, h; - ScreenPtr pScreen; - - w = pW->drawable.width; - h = pW->drawable.height; - - pScreen = pW->drawable.pScreen; - - if (pW->backgroundState == BackgroundPixmap) - { - (*pScreen->DestroyPixmap)(pW->background.pixmap); - } - - pW->backgroundState = BackgroundPixel; - pW->background.pixel = nxagentLogoBlack; - - (*pScreen->ChangeWindowAttributes)(pW, CWBackPixmap|CWBackPixel); -} - -#endif /* NXAGENT_SERVER */ - -static void -MakeRootTile(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - GCPtr pGC; - unsigned char back[128]; - int len = BitmapBytePad(sizeof(long)); - register unsigned char *from, *to; - register int i, j; - - pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4, - pScreen->rootDepth); - - pWin->backgroundState = BackgroundPixmap; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pWin->background.pixmap || !pGC) - FatalError("could not create root tile"); - - { - CARD32 attributes[2]; - - attributes[0] = pScreen->whitePixel; - attributes[1] = pScreen->blackPixel; - - (void)ChangeGC(pGC, GCForeground | GCBackground, attributes); - } - - ValidateGC((DrawablePtr)pWin->background.pixmap, pGC); - - from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb; - to = back; - - for (i = 4; i > 0; i--, from++) - for (j = len; j > 0; j--) - *to++ = *from; - - if (blackRoot) - bzero(back, sizeof(back)); - - (*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, pGC, 1, - 0, 0, len, 4, 0, XYBitmap, (char *)back); - - FreeScratchGC(pGC); - -#ifdef NXAGENT_SERVER - nxagentRootTileWindow = pWin; -#endif /* NXAGENT_SERVER */ -} - -WindowPtr -AllocateWindow(ScreenPtr pScreen) -{ - WindowPtr pWin; - register char *ptr; - register DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - pWin = (WindowPtr)xalloc(pScreen->totalWindowSize); - if (pWin) - { - ppriv = (DevUnion *)(pWin + 1); - pWin->devPrivates = ppriv; - sizes = pScreen->WindowPrivateSizes; - ptr = (char *)(ppriv + pScreen->WindowPrivateLen); - for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - } - return pWin; -} - -/***** - * CreateRootWindow - * Makes a window at initialization time for specified screen - *****/ - -Bool -CreateRootWindow(ScreenPtr pScreen) -{ - WindowPtr pWin; - BoxRec box; - PixmapFormatRec *format; - - pWin = AllocateWindow(pScreen); - if (!pWin) - return FALSE; - - savedScreenInfo[pScreen->myNum].pWindow = NULL; - savedScreenInfo[pScreen->myNum].wid = FakeClientID(0); - savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL; - screenIsSaved = SCREEN_SAVER_OFF; - - WindowTable[pScreen->myNum] = pWin; - - pWin->drawable.pScreen = pScreen; - pWin->drawable.type = DRAWABLE_WINDOW; - - pWin->drawable.depth = pScreen->rootDepth; - for (format = screenInfo.formats; - format->depth != pScreen->rootDepth; - format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->parent = NullWindow; - SetWindowToDefaults(pWin); - - pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec)); - if (!pWin->optional) - return FALSE; - - pWin->optional->dontPropagateMask = 0; - pWin->optional->otherEventMasks = 0; - pWin->optional->otherClients = NULL; - pWin->optional->passiveGrabs = NULL; - pWin->optional->userProps = NULL; - pWin->optional->backingBitPlanes = ~0L; - pWin->optional->backingPixel = 0; -#ifdef SHAPE - pWin->optional->boundingShape = NULL; - pWin->optional->clipShape = NULL; - pWin->optional->inputShape = NULL; -#endif -#ifdef XINPUT - pWin->optional->inputMasks = NULL; -#endif - pWin->optional->colormap = pScreen->defColormap; - pWin->optional->visual = pScreen->rootVisual; - - pWin->nextSib = NullWindow; - - pWin->drawable.id = FakeClientID(0); - - pWin->origin.x = pWin->origin.y = 0; - pWin->drawable.height = pScreen->height; - pWin->drawable.width = pScreen->width; - pWin->drawable.x = pWin->drawable.y = 0; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - REGION_INIT(pScreen, &pWin->winSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderClip, &box, 1); - - pWin->drawable.class = InputOutput; - pWin->optional->visual = pScreen->rootVisual; - - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = pScreen->whitePixel; - - pWin->borderIsPixel = TRUE; - pWin->border.pixel = pScreen->blackPixel; - pWin->borderWidth = 0; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin)) - return FALSE; - - if (disableBackingStore) - { - pScreen -> backingStoreSupport = NotUseful; - } - - if (enableBackingStore) - { - pScreen -> backingStoreSupport = Always; - } - - pScreen->saveUnderSupport = False; - -#ifdef DO_SAVE_UNDERS - if ((pScreen->backingStoreSupport != NotUseful) && - (pScreen->saveUnderSupport == NotUseful)) - { - /* - * If the screen has backing-store but no save-unders, let the - * clients know we can support save-unders using backing-store. - */ - pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS; - } -#endif /* DO_SAVE_UNDERS */ - - if (disableSaveUnders) - pScreen->saveUnderSupport = NotUseful; - - return TRUE; -} - -#ifdef NXAGENT_SERVER - -void -InitRootWindow(WindowPtr pWin) -{ - ScreenPtr pScreen; - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Called for window at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - if (nxagentOption(Rootless)) - { - #ifdef TEST - fprintf(stderr, "InitRootWindow: Assigned agent root to window at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - nxagentRootlessWindow = pWin; - } - - pScreen = pWin->drawable.pScreen; - - /* - * A root window is created for each screen by main - * and the pointer is saved in WindowTable as in the - * following snippet: - * - * for (i = 0; i < screenInfo.numScreens; i++) - * InitRootWindow(WindowTable[i]); - * - * Our root window on the real display was already - * created at the time the screen was opened, so it - * is unclear how this window (or the other window, - * if you prefer) fits in the big picture. - */ - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Going to create window as root at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - if (!(*pScreen->CreateWindow)(pWin)) - return; /* XXX */ - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Created window as root at [%p][%ld] with parent [%p].\n", - (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent); - #endif - - (*pScreen->PositionWindow)(pWin, 0, 0); - - pWin->cursorIsNone = FALSE; - pWin->optional->cursor = rootCursor; - rootCursor->refcnt++; - pWin->backingStore = defaultBackingStore; - pWin->forcedBS = (defaultBackingStore != NotUseful); - - #ifdef NXAGENT_SPLASH - /* We SHOULD check for an error value here XXX */ - pWin -> background.pixel = pScreen -> blackPixel; - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixel|CWBorderPixel|CWCursor|CWBackingStore); - #else - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore); - #endif - - MakeRootTile(pWin); - - /* - * Map both the root and the default agent window. - */ - - #ifdef TEST - fprintf(stderr, "InitRootWindow: Mapping default windows.\n"); - #endif - - nxagentInitAtoms(pWin); - - nxagentInitClipboard(pWin); - - nxagentMapDefaultWindows(); - - nxagentRedirectDefaultWindows(); - - #ifdef NXAGENT_ARTSD - { - char artsd_port[10]; - int nPort; - extern void nxagentPropagateArtsdProperties(ScreenPtr pScreen, char *port); - nPort = atoi(display) + 7000; - sprintf(artsd_port,"%d", nPort); - nxagentPropagateArtsdProperties(pScreen, artsd_port); - } - #endif -} - -#else /* NXAGENT_SERVER */ - -void -InitRootWindow(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - - if (!(*pScreen->CreateWindow)(pWin)) - return; /* XXX */ - (*pScreen->PositionWindow)(pWin, 0, 0); - - pWin->cursorIsNone = FALSE; - pWin->optional->cursor = rootCursor; - rootCursor->refcnt++; - MakeRootTile(pWin); - pWin->backingStore = defaultBackingStore; - pWin->forcedBS = (defaultBackingStore != NotUseful); - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore); - - MapWindow(pWin, serverClient); -} - -#endif /* NXAGENT_SERVER */ - -/* Set the region to the intersection of the rectangle and the - * window's winSize. The window is typically the parent of the - * window from which the region came. - */ - -void -ClippedRegionFromBox(register WindowPtr pWin, RegionPtr Rgn, - register int x, register int y, - register int w, register int h) -{ -#ifndef NXAGENT_SERVER - ScreenPtr pScreen = pWin->drawable.pScreen; -#endif /* NXAGENT_SERVER */ - BoxRec box; - - box = *(REGION_EXTENTS(pScreen, &pWin->winSize)); - /* we do these calculations to avoid overflows */ - if (x > box.x1) - box.x1 = x; - if (y > box.y1) - box.y1 = y; - x += w; - if (x < box.x2) - box.x2 = x; - y += h; - if (y < box.y2) - box.y2 = y; - if (box.x1 > box.x2) - box.x2 = box.x1; - if (box.y1 > box.y2) - box.y2 = box.y1; - REGION_RESET(pScreen, Rgn, &box); - REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize); -} - -WindowPtr -RealChildHead(register WindowPtr pWin) -{ - if (!pWin->parent && - (screenIsSaved == SCREEN_SAVER_ON) && - (HasSaverWindow (pWin->drawable.pScreen->myNum))) - return (pWin->firstChild); - else - return (NullWindow); -} - -/***** - * CreateWindow - * Makes a window in response to client request - *****/ - -WindowPtr -CreateWindow(Window wid, register WindowPtr pParent, int x, int y, unsigned w, - unsigned h, unsigned bw, unsigned class, register Mask vmask, XID *vlist, - int depth, ClientPtr client, VisualID visual, int *error) -{ - register WindowPtr pWin; - WindowPtr pHead; - register ScreenPtr pScreen; - xEvent event; - int idepth, ivisual; - Bool fOK; - DepthPtr pDepth; - PixmapFormatRec *format; - register WindowOptPtr ancwopt; - - if (class == CopyFromParent) - class = pParent->drawable.class; - - if ((class != InputOutput) && (class != InputOnly)) - { - *error = BadValue; - client->errorValue = class; - return NullWindow; - } - - if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) - { - *error = BadMatch; - return NullWindow; - } - - if ((class == InputOnly) && ((bw != 0) || (depth != 0))) - { - *error = BadMatch; - return NullWindow; - } - - pScreen = pParent->drawable.pScreen; - if ((class == InputOutput) && (depth == 0)) - depth = pParent->drawable.depth; - ancwopt = pParent->optional; - if (!ancwopt) - ancwopt = FindWindowWithOptional(pParent)->optional; - if (visual == CopyFromParent) { -#ifdef XAPPGROUP - VisualID ag_visual; - - if (client->appgroup && !pParent->parent && - (ag_visual = XagRootVisual (client))) - visual = ag_visual; - else -#endif - visual = ancwopt->visual; - } - - /* Find out if the depth and visual are acceptable for this Screen */ - if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) - { - fOK = FALSE; - for(idepth = 0; idepth < pScreen->numDepths; idepth++) - { - pDepth = (DepthPtr) &pScreen->allowedDepths[idepth]; - if ((depth == pDepth->depth) || (depth == 0)) - { - for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) - { - if (visual == pDepth->vids[ivisual]) - { - fOK = TRUE; - break; - } - } - } - } - if (fOK == FALSE) - { - *error = BadMatch; - return NullWindow; - } - } - - if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) && - (class != InputOnly) && - (depth != pParent->drawable.depth)) - { - *error = BadMatch; - return NullWindow; - } - - if (((vmask & CWColormap) == 0) && - (class != InputOnly) && - ((visual != ancwopt->visual) || (ancwopt->colormap == None))) - { - *error = BadMatch; - return NullWindow; - } - - pWin = AllocateWindow(pScreen); - if (!pWin) - { - *error = BadAlloc; - return NullWindow; - } - pWin->drawable = pParent->drawable; - pWin->drawable.depth = depth; - if (depth == pParent->drawable.depth) - pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; - else - { - for (format = screenInfo.formats; format->depth != depth; format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - } - if (class == InputOnly) - pWin->drawable.type = (short) UNDRAWABLE_WINDOW; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->drawable.id = wid; - pWin->drawable.class = class; - - pWin->parent = pParent; - SetWindowToDefaults(pWin); - - if (visual != ancwopt->visual) - { - if (!MakeWindowOptional (pWin)) - { - xfree (pWin); - *error = BadAlloc; - return NullWindow; - } - pWin->optional->visual = visual; - pWin->optional->colormap = None; - } - - pWin->borderWidth = bw; -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows; - * they make it too easy to steal window contents - */ - if (client->trustLevel != XSecurityClientTrusted) - { - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = 0; - } - else -#endif - pWin->backgroundState = None; - - pWin->borderIsPixel = pParent->borderIsPixel; - pWin->border = pParent->border; - if (pWin->borderIsPixel == FALSE) - pWin->border.pixmap->refcnt++; - - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - pWin->drawable.width = w; - pWin->drawable.height = h; - pWin->drawable.x = pParent->drawable.x + x + (int)bw; - pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - /* set up clip list correctly for unobscured WindowPtr */ - REGION_NULL(pScreen, &pWin->clipList); - REGION_NULL(pScreen, &pWin->borderClip); - REGION_NULL(pScreen, &pWin->winSize); - REGION_NULL(pScreen, &pWin->borderSize); - - pHead = RealChildHead(pParent); - if (pHead) - { - pWin->nextSib = pHead->nextSib; - if (pHead->nextSib) - pHead->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pHead->nextSib = pWin; - pWin->prevSib = pHead; - } - else - { - pWin->nextSib = pParent->firstChild; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - /* We SHOULD check for an error value here XXX */ - if (!(*pScreen->CreateWindow)(pWin)) - { - *error = BadAlloc; - DeleteWindow(pWin, None); - return NullWindow; - } - /* We SHOULD check for an error value here XXX */ - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - - if (!(vmask & CWEventMask)) - RecalculateDeliverableEvents(pWin); - - if (vmask) - *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin)); - else - *error = Success; - - if (*error != Success) - { - DeleteWindow(pWin, None); - return NullWindow; - } - if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful)) - { - XID value = defaultBackingStore; - (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin)); - pWin->forcedBS = TRUE; - } - - if (SubSend(pParent)) - { - event.u.u.type = CreateNotify; - event.u.createNotify.window = wid; - event.u.createNotify.parent = pParent->drawable.id; - event.u.createNotify.x = x; - event.u.createNotify.y = y; - event.u.createNotify.width = w; - event.u.createNotify.height = h; - event.u.createNotify.borderWidth = bw; - event.u.createNotify.override = pWin->overrideRedirect; - DeliverEvents(pParent, &event, 1, NullWindow); - } - return pWin; -} - -static void -FreeWindowResources(register WindowPtr pWin) -{ - register ScreenPtr pScreen = pWin->drawable.pScreen; - - DeleteWindowFromAnySaveSet(pWin); - DeleteWindowFromAnySelections(pWin); - DeleteWindowFromAnyEvents(pWin, TRUE); - REGION_UNINIT(pScreen, &pWin->clipList); - REGION_UNINIT(pScreen, &pWin->winSize); - REGION_UNINIT(pScreen, &pWin->borderClip); - REGION_UNINIT(pScreen, &pWin->borderSize); -#ifdef SHAPE - if (wBoundingShape (pWin)) - REGION_DESTROY(pScreen, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_DESTROY(pScreen, wClipShape (pWin)); - if (wInputShape (pWin)) - REGION_DESTROY(pScreen, wInputShape (pWin)); -#endif - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - - DeleteAllWindowProperties(pWin); - /* We SHOULD check for an error value here XXX */ - (*pScreen->DestroyWindow)(pWin); - DisposeWindowOptional (pWin); -} - -static void -CrushTree(WindowPtr pWin) -{ - register WindowPtr pChild, pSib, pParent; - UnrealizeWindowProcPtr UnrealizeWindow; - xEvent event; - - if (!(pChild = pWin->firstChild)) - return; - UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow; - while (1) - { - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (1) - { - pParent = pChild->parent; - if (SubStrSend(pChild, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pChild->drawable.id; - DeliverEvents(pChild, &event, 1, NullWindow); - } - FreeResource(pChild->drawable.id, RT_WINDOW); - pSib = pChild->nextSib; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder && pChild->viewable) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->realized) - { - pChild->realized = FALSE; - (*UnrealizeWindow)(pChild); - } - FreeWindowResources(pChild); - xfree(pChild); - if ( (pChild = pSib) ) - break; - pChild = pParent; - pChild->firstChild = NullWindow; - pChild->lastChild = NullWindow; - if (pChild == pWin) - return; - } - } -} - -/***** - * DeleteWindow - * Deletes child of window then window itself - * If wid is None, don't send any events - *****/ - -int -DeleteWindow(pointer value, XID wid) - { - register WindowPtr pParent; - register WindowPtr pWin = (WindowPtr)value; - xEvent event; - - UnmapWindow(pWin, FALSE); - - CrushTree(pWin); - - pParent = pWin->parent; - if (wid && pParent && SubStrSend(pWin, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pWin->drawable.id; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - FreeWindowResources(pWin); - if (pParent) - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - } - - if (pWin -> optional && - pWin -> optional -> colormap && - pWin -> parent) - { - nxagentSetInstalledColormapWindows(pWin -> drawable.pScreen); - } - - xfree(pWin); - return Success; -} - -void -DestroySubwindows(register WindowPtr pWin, ClientPtr client) -{ - /* XXX - * The protocol is quite clear that each window should be - * destroyed in turn, however, unmapping all of the first - * eliminates most of the calls to ValidateTree. So, - * this implementation is incorrect in that all of the - * UnmapNotifies occur before all of the DestroyNotifies. - * If you care, simply delete the call to UnmapSubwindows. - */ - UnmapSubwindows(pWin); - while (pWin->lastChild) - FreeResource(pWin->lastChild->drawable.id, RT_NONE); -} - -#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \ - ButtonReleaseMask | PointerMotionMask) - -/***** - * ChangeWindowAttributes - * - * The value-mask specifies which attributes are to be changed; the - * value-list contains one value for each one bit in the mask, from least - * to most significant bit in the mask. - *****/ - -int -ChangeWindowAttributes(register WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) -{ - register Mask index2; - register XID *pVlist; - PixmapPtr pPixmap; - Pixmap pixID; - CursorPtr pCursor, pOldCursor; - Cursor cursorID; - WindowPtr pChild; - Colormap cmap; - ColormapPtr pCmap; - xEvent xE; - int result; - register ScreenPtr pScreen; - Mask vmaskCopy = 0; - register Mask tmask; - unsigned int val; - int error; - Bool checkOptional = FALSE; - Bool borderRelative = FALSE; - WindowPtr pLayerWin; - - if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK))) - return BadMatch; - - error = Success; - pScreen = pWin->drawable.pScreen; - pVlist = vlist; - tmask = vmask; - while (tmask) - { - index2 = (Mask) lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBackPixmap: - pixID = (Pixmap )*pVlist; - pVlist++; - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pixID == None) - { -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows */ - if (client->trustLevel == XSecurityClientTrusted) - { -#endif - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = None; -#ifdef XCSECURITY - } - else - { /* didn't change the background to None, so don't tell ddx */ - index2 = 0; - } -#endif - } - else if (pixID == ParentRelative) - { - if (pWin->parent && - pWin->drawable.depth != pWin->parent->drawable.depth) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = ParentRelative; - borderRelative = TRUE; - /* Note that the parent's backgroundTile's refcnt is NOT - * incremented. */ - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap != (PixmapPtr) NULL) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixmap; - pWin->background.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBackPixel: - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = (CARD32 ) *pVlist; - /* background pixel overrides background pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBackPixmap; - pVlist++; - break; - case CWBorderPixmap: - pixID = (Pixmap ) *pVlist; - pVlist++; - if (pixID == CopyFromParent) - { - if (!pWin->parent || - (pWin->drawable.depth != pWin->parent->drawable.depth)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->border = pWin->parent->border; - if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE) - { - index2 = CWBorderPixel; - } - else - { - pWin->parent->border.pixmap->refcnt++; - } - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = FALSE; - pWin->border.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBorderPixel: - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = TRUE; - pWin->border.pixel = (CARD32) *pVlist; - /* border pixel overrides border pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBorderPixmap; - pVlist++; - break; - case CWBitGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->bitGravity = val; - break; - case CWWinGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->winGravity = val; - break; - case CWBackingStore: - val = (CARD8 )*pVlist; - pVlist++; - if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->backingStore = val; - - #ifdef TEST - fprintf(stderr, "ChangeWindowAttributes: Changed backing store value to %d for window at %p.\n", - val, (void*)pWin); - #endif - - pWin->forcedBS = FALSE; - break; - case CWBackingPlanes: - if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingBitPlanes = (CARD32) *pVlist; - if ((CARD32)*pVlist == (CARD32)~0L) - checkOptional = TRUE; - } - pVlist++; - break; - case CWBackingPixel: - if (pWin->optional || (CARD32) *pVlist) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingPixel = (CARD32) *pVlist; - if (!*pVlist) - checkOptional = TRUE; - } - pVlist++; - break; - case CWSaveUnder: - val = (BOOL) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } -#ifdef DO_SAVE_UNDERS - if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) && - DO_SAVE_UNDERS(pWin)) - { - /* - * Re-check all siblings and inferiors for obscurity or - * exposition (hee hee). - */ - if (pWin->saveUnder) - deltaSaveUndersViewable--; - else - deltaSaveUndersViewable++; - pWin->saveUnder = val; - - if (pWin->firstChild) - { - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pLayerWin->parent, - pWin->nextSib); - } - else - { - if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pWin, - pWin->nextSib); - } - } - else - { - /* If we're changing the saveUnder attribute of the root - * window, all we do is set pWin->saveUnder so that - * GetWindowAttributes returns the right value. We don't - * do the "normal" save-under processing (as above). - * Hope that doesn't cause any problems. - */ - pWin->saveUnder = val; - } -#else - pWin->saveUnder = val; -#endif /* DO_SAVE_UNDERS */ - break; - case CWEventMask: - /* - * TODO: Some applications like java bean shell - * don' t work if they cannot monitor the root - * window for Structure Redirect events. However - * this doesn't seem to be the best solution, since - * also an X server with a window manager running, - * doesn't allow to monitor for those events, but - * the java bean shell works flawlessy on this - * server. - * - * if (nxagentCheckIllegalRootMonitoring(pWin, (Mask)*pVlist)) - * { - * return BadAccess; - * } - */ - - result = EventSelectForWindow(pWin, client, (Mask )*pVlist); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWDontPropagate: - result = EventSuppressForWindow(pWin, client, (Mask )*pVlist, - &checkOptional); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWOverrideRedirect: - val = (BOOL ) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->overrideRedirect = val; - break; - case CWColormap: - cmap = (Colormap) *pVlist; - pVlist++; - if (cmap == CopyFromParent) - { -#ifdef XAPPGROUP - Colormap ag_colormap; - ClientPtr win_owner; - - /* - * win_owner == client for CreateWindow, other clients - * can ChangeWindowAttributes - */ - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - - if ( win_owner && win_owner->appgroup && - !pWin->parent->parent && - (ag_colormap = XagDefaultColormap (win_owner))) - cmap = ag_colormap; - else -#endif - if (pWin->parent && - (!pWin->optional || - pWin->optional->visual == wVisual (pWin->parent))) - { - cmap = wColormap (pWin->parent); - } - else - cmap = None; - } - if (cmap == None) - { - error = BadMatch; - goto PatchUp; - } - pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap, - RT_COLORMAP, SecurityReadAccess); - if (!pCmap) - { - error = BadColor; - client->errorValue = cmap; - goto PatchUp; - } - if (pCmap->pVisual->vid != wVisual (pWin) || - pCmap->pScreen != pScreen) - { - error = BadMatch; - goto PatchUp; - } - if (cmap != wColormap (pWin)) - { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && cmap == wColormap (pWin->parent)) - checkOptional = TRUE; - - /* - * propagate the original colormap to any children - * inheriting it - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pWin->optional->colormap = cmap; - - /* - * check on any children now matching the new colormap - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional->colormap == cmap) - CheckWindowOptionalNeed (pChild); - } - - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pWin->drawable.id; - xE.u.colormap.colormap = cmap; - xE.u.colormap.new = xTrue; - xE.u.colormap.state = IsMapInstalled(cmap, pWin); - DeliverEvents(pWin, &xE, 1, NullWindow); - } - break; - case CWCursor: - cursorID = (Cursor ) *pVlist; - pVlist++; - /* - * install the new - */ - if ( cursorID == None) - { - if (pWin == WindowTable[pWin->drawable.pScreen->myNum]) - pCursor = rootCursor; - else - pCursor = (CursorPtr) None; - } - else - { - pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID, - RT_CURSOR, SecurityReadAccess); - if (!pCursor) - { - error = BadCursor; - client->errorValue = cursorID; - goto PatchUp; - } - } - - if (pCursor != wCursor (pWin)) - { - /* - * patch up child windows so they don't lose cursors. - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !pChild->cursorIsNone && - !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pOldCursor = 0; - if (pCursor == (CursorPtr) None) - { - pWin->cursorIsNone = TRUE; - if (pWin->optional) - { - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = (CursorPtr) None; - checkOptional = TRUE; - } - } else { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && pCursor == wCursor (pWin->parent)) - checkOptional = TRUE; - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = pCursor; - pCursor->refcnt++; - pWin->cursorIsNone = FALSE; - /* - * check on any children now matching the new cursor - */ - - for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional && - (pChild->optional->cursor == pCursor)) - CheckWindowOptionalNeed (pChild); - } - } - - if (pWin->realized) - WindowHasNewCursor( pWin); - - /* Can't free cursor until here - old cursor - * is needed in WindowHasNewCursor - */ - if (pOldCursor) - FreeCursor (pOldCursor, (Cursor)0); - } - break; - default: - error = BadValue; - client->errorValue = vmask; - goto PatchUp; - } - vmaskCopy |= index2; - } -PatchUp: - if (checkOptional) - CheckWindowOptionalNeed (pWin); - - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy); - - /* - If the border contents have changed, redraw the border. - Note that this has to be done AFTER pScreen->ChangeWindowAttributes - for the tile to be rotated, and the correct function selected. - */ - if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative) - && pWin->viewable && HasBorder (pWin)) - { - RegionRec exposed; - - REGION_NULL(pScreen, &exposed); - REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize); - (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER); - REGION_UNINIT(pScreen, &exposed); - } - return error; -} - - -/***** - * GetWindowAttributes - * Notice that this is different than ChangeWindowAttributes - *****/ - -void -GetWindowAttributes(register WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply *wa) -{ - wa->type = X_Reply; - wa->bitGravity = pWin->bitGravity; - wa->winGravity = pWin->winGravity; - if (pWin->forcedBS && pWin->backingStore != Always) - wa->backingStore = NotUseful; - else - wa->backingStore = pWin->backingStore; - wa->length = (sizeof(xGetWindowAttributesReply) - - sizeof(xGenericReply)) >> 2; - wa->sequenceNumber = client->sequence; - wa->backingBitPlanes = wBackingBitPlanes (pWin); - wa->backingPixel = wBackingPixel (pWin); - wa->saveUnder = (BOOL)pWin->saveUnder; - wa->override = pWin->overrideRedirect; - if (!pWin->mapped) - wa->mapState = IsUnmapped; - else if (pWin->realized) - wa->mapState = IsViewable; - else - wa->mapState = IsUnviewable; - - wa->colormap = wColormap (pWin); - wa->mapInstalled = (wa->colormap == None) ? xFalse - : IsMapInstalled(wa->colormap, pWin); - - wa->yourEventMask = EventMaskForClient(pWin, client); - wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin); - wa->doNotPropagateMask = wDontPropagateMask (pWin); - wa->class = pWin->drawable.class; - wa->visualID = wVisual (pWin); -} - - -WindowPtr -MoveWindowInStack(register WindowPtr pWin, register WindowPtr pNextSib) -{ - register WindowPtr pParent = pWin->parent; - WindowPtr pFirstChange = pWin; /* highest window where list changes */ - - if (pWin->nextSib != pNextSib) - { - WindowPtr pOldNextSib = pWin->nextSib; - - if (!pNextSib) /* move to bottom */ - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL - * and pWin->nextSib != pNextSib - * therefore pWin->nextSib != NULL */ - pFirstChange = pWin->nextSib; - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pParent->lastChild->nextSib = pWin; - pWin->prevSib = pParent->lastChild; - pWin->nextSib = NullWindow; - pParent->lastChild = pWin; - } - else if (pParent->firstChild == pNextSib) /* move to top */ - { - pFirstChange = pWin; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pParent->firstChild; - pWin->prevSib = (WindowPtr ) NULL; - pNextSib->prevSib = pWin; - pParent->firstChild = pWin; - } - else /* move in middle of list */ - { - WindowPtr pOldNext = pWin->nextSib; - - pFirstChange = NullWindow; - if (pParent->firstChild == pWin) - pFirstChange = pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) { - pFirstChange = pWin; - pParent->lastChild = pWin->prevSib; - } - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pNextSib; - pWin->prevSib = pNextSib->prevSib; - if (pNextSib->prevSib) - pNextSib->prevSib->nextSib = pWin; - pNextSib->prevSib = pWin; - if (!pFirstChange) { /* do we know it yet? */ - pFirstChange = pParent->firstChild; /* no, search from top */ - while ((pFirstChange != pWin) && (pFirstChange != pOldNext)) - pFirstChange = pFirstChange->nextSib; - } - } - if(pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib); - } - -#ifdef ROOTLESS - /* - * In rootless mode we can't optimize away window restacks. - * There may be non-X windows around, so even if the window - * is in the correct position from X's point of view, - * the underlying window system may want to reorder it. - */ - else if (pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pWin->nextSib); -#endif - - return( pFirstChange ); -} - -RegionPtr -CreateUnclippedWinSize (register WindowPtr pWin) -{ - RegionPtr pRgn; - BoxRec box; - - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + (int) pWin->drawable.width; - box.y2 = pWin->drawable.y + (int) pWin->drawable.height; - pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { -#ifndef NXAGENT_SERVER - ScreenPtr pScreen = pWin->drawable.pScreen; -#endif /* NXAGENT_SERVER */ - REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y); - } -#endif - return pRgn; -} - -void -SetWinSize (register WindowPtr pWin) -{ -#ifdef COMPOSITE - if (pWin->redirectDraw) - { - BoxRec box; - - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + pWin->drawable.width; - box.y2 = pWin->drawable.y + pWin->drawable.height; - REGION_RESET (pScreen, &pWin->winSize, &box); - } - else -#endif - ClippedRegionFromBox(pWin->parent, &pWin->winSize, - pWin->drawable.x, pWin->drawable.y, - (int)pWin->drawable.width, - (int)pWin->drawable.height); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { -#ifndef NXAGENT_SERVER - ScreenPtr pScreen = pWin->drawable.pScreen; -#endif /* NXAGENT_SERVER */ - REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wClipShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x, - pWin->drawable.y); - } -#endif -} - -void -SetBorderSize (register WindowPtr pWin) -{ - int bw; - - if (HasBorder (pWin)) { - bw = wBorderWidth (pWin); -#ifdef COMPOSITE - if (pWin->redirectDraw) - { - BoxRec box; - - box.x1 = pWin->drawable.x - bw; - box.y1 = pWin->drawable.y - bw; - box.x2 = pWin->drawable.x + pWin->drawable.width + bw; - box.y2 = pWin->drawable.y + pWin->drawable.height + bw; - REGION_RESET (pScreen, &pWin->borderSize, &box); - } - else -#endif - ClippedRegionFromBox(pWin->parent, &pWin->borderSize, - pWin->drawable.x - bw, pWin->drawable.y - bw, - (int)(pWin->drawable.width + (bw<<1)), - (int)(pWin->drawable.height + (bw<<1))); -#ifdef SHAPE - if (wBoundingShape (pWin)) { -#ifndef NXAGENT_SERVER - ScreenPtr pScreen = pWin->drawable.pScreen; -#endif /* NXAGENT_SERVER */ - REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x, - - pWin->drawable.y); - REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize, - wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x, - pWin->drawable.y); - REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize, - &pWin->winSize); - } -#endif - } else { - REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize, - &pWin->winSize); - } -} - -/** - * - * \param x,y new window position - * \param oldx,oldy old window position - * \param destx,desty position relative to gravity - */ - -void -GravityTranslate (register int x, register int y, int oldx, int oldy, - int dw, int dh, unsigned gravity, - register int *destx, register int *desty) -{ - switch (gravity) { - case NorthGravity: - *destx = x + dw / 2; - *desty = y; - break; - case NorthEastGravity: - *destx = x + dw; - *desty = y; - break; - case WestGravity: - *destx = x; - *desty = y + dh / 2; - break; - case CenterGravity: - *destx = x + dw / 2; - *desty = y + dh / 2; - break; - case EastGravity: - *destx = x + dw; - *desty = y + dh / 2; - break; - case SouthWestGravity: - *destx = x; - *desty = y + dh; - break; - case SouthGravity: - *destx = x + dw / 2; - *desty = y + dh; - break; - case SouthEastGravity: - *destx = x + dw; - *desty = y + dh; - break; - case StaticGravity: - *destx = oldx; - *desty = oldy; - break; - default: - *destx = x; - *desty = y; - break; - } -} - -/* XXX need to retile border on each window with ParentRelative origin */ -void -ResizeChildrenWinSize(register WindowPtr pWin, int dx, int dy, int dw, int dh) -{ - register ScreenPtr pScreen; - register WindowPtr pSib, pChild; - Bool resized = (dw || dh); - - pScreen = pWin->drawable.pScreen; - - for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) - { - if (resized && (pSib->winGravity > NorthWestGravity)) - { - int cwsx, cwsy; - - cwsx = pSib->origin.x; - cwsy = pSib->origin.y; - GravityTranslate (cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh, - pSib->winGravity, &cwsx, &cwsy); - if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) - { - xEvent event; - - event.u.u.type = GravityNotify; - event.u.gravity.window = pSib->drawable.id; - event.u.gravity.x = cwsx - wBorderWidth (pSib); - event.u.gravity.y = cwsy - wBorderWidth (pSib); - DeliverEvents (pSib, &event, 1, NullWindow); - pSib->origin.x = cwsx; - pSib->origin.y = cwsy; - } - } - pSib->drawable.x = pWin->drawable.x + pSib->origin.x; - pSib->drawable.y = pWin->drawable.y + pSib->origin.y; - SetWinSize (pSib); - SetBorderSize (pSib); - - /* - * Don't force X to move children. It will position them - * according with gravity. - * - * (*pScreen->PositionWindow)(pSib, pSib->drawable.x, pSib->drawable.y); - */ - - /* - * Update pSib privates, as this window is moved by X. - */ - - nxagentAddConfiguredWindow(pSib, CW_Update); - - if ( (pChild = pSib->firstChild) ) - { - while (1) - { - pChild->drawable.x = pChild->parent->drawable.x + - pChild->origin.x; - pChild->drawable.y = pChild->parent->drawable.y + - pChild->origin.y; - SetWinSize (pChild); - SetBorderSize (pChild); - - (*pScreen->PositionWindow)(pChild, pChild->drawable.x, - pChild->drawable.y); - - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pSib)) - pChild = pChild->parent; - if (pChild == pSib) - break; - pChild = pChild->nextSib; - } - } - } -} - -#define GET_INT16(m, f) \ - if (m & mask) \ - { \ - f = (INT16) *pVlist;\ - pVlist++; \ - } -#define GET_CARD16(m, f) \ - if (m & mask) \ - { \ - f = (CARD16) *pVlist;\ - pVlist++;\ - } - -#define GET_CARD8(m, f) \ - if (m & mask) \ - { \ - f = (CARD8) *pVlist;\ - pVlist++;\ - } - -#define ChangeMask ((Mask)(CWX | CWY | CWWidth | CWHeight)) - -#define IllegalInputOnlyConfigureMask (CWBorderWidth) - -/* - * IsSiblingAboveMe - * returns Above if pSib above pMe in stack or Below otherwise - */ - -static int -IsSiblingAboveMe( - register WindowPtr pMe, - register WindowPtr pSib) -{ - register WindowPtr pWin; - - pWin = pMe->parent->firstChild; - while (pWin) - { - if (pWin == pSib) - return(Above); - else if (pWin == pMe) - return(Below); - pWin = pWin->nextSib; - } - return(Below); -} - -static BoxPtr -WindowExtents( - register WindowPtr pWin, - register BoxPtr pBox) -{ - pBox->x1 = pWin->drawable.x - wBorderWidth (pWin); - pBox->y1 = pWin->drawable.y - wBorderWidth (pWin); - pBox->x2 = pWin->drawable.x + (int)pWin->drawable.width - + wBorderWidth (pWin); - pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height - + wBorderWidth (pWin); - return(pBox); -} - -#ifdef SHAPE -#define IS_SHAPED(pWin) (wBoundingShape (pWin) != (RegionPtr) NULL) - -static RegionPtr -MakeBoundingRegion ( - register WindowPtr pWin, - BoxPtr pBox) -{ - RegionPtr pRgn; -#ifndef NXAGENT_SERVER - ScreenPtr pScreen = pWin->drawable.pScreen; -#endif /* NXAGENT_SERVER */ - pRgn = REGION_CREATE(pScreen, pBox, 1); - if (wBoundingShape (pWin)) { - REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x, - -pWin->origin.y); - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x, - pWin->origin.y); - } - return pRgn; -} - -static Bool -ShapeOverlap ( - WindowPtr pWin, - BoxPtr pWinBox, - WindowPtr pSib, - BoxPtr pSibBox) -{ - RegionPtr pWinRgn, pSibRgn; - register ScreenPtr pScreen; - Bool ret; - - if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib)) - return TRUE; - pScreen = pWin->drawable.pScreen; - pWinRgn = MakeBoundingRegion (pWin, pWinBox); - pSibRgn = MakeBoundingRegion (pSib, pSibBox); - REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn); - ret = REGION_NOTEMPTY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pSibRgn); - return ret; -} -#endif - -static Bool -AnyWindowOverlapsMe( - WindowPtr pWin, - WindowPtr pHead, - register BoxPtr box) -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -static Bool -IOverlapAnyWindow( - WindowPtr pWin, - register BoxPtr box) -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -/* - * WhereDoIGoInTheStack() - * Given pWin and pSib and the relationshipe smode, return - * the window that pWin should go ABOVE. - * If a pSib is specified: - * Above: pWin is placed just above pSib - * Below: pWin is placed just below pSib - * TopIf: if pSib occludes pWin, then pWin is placed - * at the top of the stack - * BottomIf: if pWin occludes pSib, then pWin is - * placed at the bottom of the stack - * Opposite: if pSib occludes pWin, then pWin is placed at the - * top of the stack, else if pWin occludes pSib, then - * pWin is placed at the bottom of the stack - * - * If pSib is NULL: - * Above: pWin is placed at the top of the stack - * Below: pWin is placed at the bottom of the stack - * TopIf: if any sibling occludes pWin, then pWin is placed at - * the top of the stack - * BottomIf: if pWin occludes any sibline, then pWin is placed at - * the bottom of the stack - * Opposite: if any sibling occludes pWin, then pWin is placed at - * the top of the stack, else if pWin occludes any - * sibling, then pWin is placed at the bottom of the stack - * - */ - -static WindowPtr -WhereDoIGoInTheStack( - register WindowPtr pWin, - register WindowPtr pSib, - short x, - short y, - unsigned short w, - unsigned short h, - int smode) -{ - BoxRec box; - register ScreenPtr pScreen; - WindowPtr pHead, pFirst; - - if ((pWin == pWin->parent->firstChild) && - (pWin == pWin->parent->lastChild)) - return((WindowPtr ) NULL); - pHead = RealChildHead(pWin->parent); - pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild; - pScreen = pWin->drawable.pScreen; - box.x1 = x; - box.y1 = y; - box.x2 = x + (int)w; - box.y2 = y + (int)h; - switch (smode) - { - case Above: - if (pSib) - return(pSib); - else if (pWin == pFirst) - return(pWin->nextSib); - else - return(pFirst); - case Below: - if (pSib) - if (pSib->nextSib != pWin) - return(pSib->nextSib); - else - return(pWin->nextSib); - else - return NullWindow; - case TopIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Above) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return(pFirst); - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - return(pFirst); - else - return(pWin->nextSib); - case BottomIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Below) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return NullWindow; - else - return(pWin->nextSib); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return(pWin->nextSib); - case Opposite: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT) - { - if (IsSiblingAboveMe(pWin, pSib) == Above) - return(pFirst); - else - return NullWindow; - } - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - { - /* If I'm occluded, I can't possibly be the first child - * if (pWin == pWin->parent->firstChild) - * return pWin->nextSib; - */ - return(pFirst); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return pWin->nextSib; - default: - { - ErrorF("Internal error in ConfigureWindow, smode == %d\n",smode ); - return pWin->nextSib; - } - } -} - -static void -ReflectStackChange( - register WindowPtr pWin, - register WindowPtr pSib, - VTKind kind) -{ -/* Note that pSib might be NULL */ - - Bool WasViewable = (Bool)pWin->viewable; - Bool anyMarked; - WindowPtr pFirstChange; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - ScreenPtr pScreen = pWin->drawable.pScreen; - - /* if this is a root window, can't be restacked */ - if (!pWin->parent) - return; - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - &pLayerWin); - if (pLayerWin != pWin) pFirstChange = pLayerWin; -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, kind); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pWin->drawable.pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - -/***** - * ConfigureWindow - *****/ - -int -ConfigureWindow(register WindowPtr pWin, register Mask mask, XID *vlist, ClientPtr client) -{ -#define RESTACK_WIN 0 -#define MOVE_WIN 1 -#define RESIZE_WIN 2 -#define REBORDER_WIN 3 - register WindowPtr pSib = NullWindow; - register WindowPtr pParent = pWin->parent; - Window sibwid = 0; - Mask index2, tmask; - register XID *pVlist; - short x, y, beforeX, beforeY; - unsigned short w = pWin->drawable.width, - h = pWin->drawable.height, - bw = pWin->borderWidth; - int action, smode = Above; -#ifdef XAPPGROUP - ClientPtr win_owner; - ClientPtr ag_leader = NULL; -#endif - xEvent event; - - if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask)) - return(BadMatch); - - if ((mask & CWSibling) && !(mask & CWStackMode)) - return(BadMatch); - - pVlist = vlist; - - if (pParent) - { - x = pWin->drawable.x - pParent->drawable.x - (int)bw; - y = pWin->drawable.y - pParent->drawable.y - (int)bw; - } - else - { - x = pWin->drawable.x; - y = pWin->drawable.y; - } - beforeX = x; - beforeY = y; - action = RESTACK_WIN; - if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - action = MOVE_WIN; - } - /* or should be resized */ - else if (mask & (CWX | CWY | CWWidth | CWHeight)) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - GET_CARD16(CWWidth, w); - GET_CARD16 (CWHeight, h); - if (!w || !h) - { - client->errorValue = 0; - return BadValue; - } - action = RESIZE_WIN; - } - tmask = mask & ~ChangeMask; - while (tmask) - { - index2 = (Mask)lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBorderWidth: - GET_CARD16(CWBorderWidth, bw); - break; - case CWSibling: - sibwid = (Window ) *pVlist; - pVlist++; - pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid, - RT_WINDOW, SecurityReadAccess); - if (!pSib) - { - client->errorValue = sibwid; - return(BadWindow); - } - if (pSib->parent != pParent) - return(BadMatch); - if (pSib == pWin) - return(BadMatch); - break; - case CWStackMode: - GET_CARD8(CWStackMode, smode); - if ((smode != TopIf) && (smode != BottomIf) && - (smode != Opposite) && (smode != Above) && (smode != Below)) - { - client->errorValue = smode; - return(BadValue); - } - break; - default: - client->errorValue = mask; - return(BadValue); - } - } - /* root really can't be reconfigured, so just return */ - if (!pParent) - return Success; - - /* Figure out if the window should be moved. Doesnt - make the changes to the window if event sent */ - - #ifdef TEST - if (nxagentWindowTopLevel(pWin)) - { - - fprintf(stderr, "ConfigureWindow: pWin [%p] mask [%lu] client [%p]\n", - pWin, mask, client); - - fprintf(stderr, "ConfigureWindow: x [%d] y [%d] w [%d] h [%d] CWStackMode [%d] " - "smode [%d] pSib [%p]\n", - x, y, w, h, (mask & CWStackMode) ? 1 : 0, smode, pSib); - } - #endif - - if (nxagentOption(Rootless) && nxagentWindowTopLevel(pWin) && - pWin -> overrideRedirect == 0 && - nxagentScreenTrap == 0) - { - nxagentConfigureRootlessWindow(pWin, x, y, w, h, bw, pSib, smode, mask); - - return Success; - } - - if (mask & CWStackMode) - pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x, - pParent->drawable.y + y, - w + (bw << 1), h + (bw << 1), smode); - else - pSib = pWin->nextSib; - -#ifdef XAPPGROUP - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = ConfigureRequest; - event.u.configureRequest.window = pWin->drawable.id; - if (mask & CWSibling) - event.u.configureRequest.sibling = sibwid; - else - event.u.configureRequest.sibling = None; - if (mask & CWStackMode) - event.u.u.detail = smode; - else - event.u.u.detail = Above; - event.u.configureRequest.x = x; - event.u.configureRequest.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureRequest.x += panoramiXdataPtr[0].x; - event.u.configureRequest.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureRequest.width = w; - event.u.configureRequest.height = h; - event.u.configureRequest.borderWidth = bw; - event.u.configureRequest.valueMask = mask; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.configureRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.configureRequest.parent = pParent->drawable.id; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - if (action == RESIZE_WIN) - { - Bool size_change = (w != pWin->drawable.width) - || (h != pWin->drawable.height); - if (size_change && ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask)) - { - xEvent eventT; - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = w; - eventT.u.resizeRequest.height = h; - if (MaybeDeliverEventsToClient(pWin, &eventT, 1, - ResizeRedirectMask, client) == 1) - { - /* if event is delivered, leave the actual size alone. */ - w = pWin->drawable.width; - h = pWin->drawable.height; - size_change = FALSE; - } - } - if (!size_change) - { - if (mask & (CWX | CWY)) - action = MOVE_WIN; - else if (mask & (CWStackMode | CWBorderWidth)) - action = RESTACK_WIN; - else /* really nothing to do */ - return(Success) ; - } - } - - if (action == RESIZE_WIN) - /* we've already checked whether there's really a size change */ - goto ActuallyDoSomething; - if ((mask & CWX) && (x != beforeX)) - goto ActuallyDoSomething; - if ((mask & CWY) && (y != beforeY)) - goto ActuallyDoSomething; - if ((mask & CWBorderWidth) && (bw != wBorderWidth (pWin))) - goto ActuallyDoSomething; - if (mask & CWStackMode) - { -#ifndef ROOTLESS - /* See above for why we always reorder in rootless mode. */ - if (pWin->nextSib != pSib) -#endif - goto ActuallyDoSomething; - } - return(Success); - -ActuallyDoSomething: - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - if (pSib) - event.u.configureNotify.aboveSibling = pSib->drawable.id; - else - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = x; - event.u.configureNotify.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureNotify.x += panoramiXdataPtr[0].x; - event.u.configureNotify.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureNotify.width = w; - event.u.configureNotify.height = h; - event.u.configureNotify.borderWidth = bw; - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (mask & CWBorderWidth) - { - if (action == RESTACK_WIN) - { - action = MOVE_WIN; - pWin->borderWidth = bw; - } - else if ((action == MOVE_WIN) && - (beforeX + wBorderWidth (pWin) == x + (int)bw) && - (beforeY + wBorderWidth (pWin) == y + (int)bw)) - { - action = REBORDER_WIN; - (*pWin->drawable.pScreen->ChangeBorderWidth)(pWin, bw); - } - else - pWin->borderWidth = bw; - } - if (action == MOVE_WIN) - (*pWin->drawable.pScreen->MoveWindow)(pWin, x, y, pSib, - (mask & CWBorderWidth) ? VTOther : VTMove); - else if (action == RESIZE_WIN) - (*pWin->drawable.pScreen->ResizeWindow)(pWin, x, y, w, h, pSib); - else if (mask & CWStackMode) - ReflectStackChange(pWin, pSib, VTOther); - - if (action != RESTACK_WIN) - CheckCursorConfinement(pWin); - - nxagentFlushConfigureWindow(); - - return(Success); -#undef RESTACK_WIN -#undef MOVE_WIN -#undef RESIZE_WIN -#undef REBORDER_WIN -} - - -/****** - * - * CirculateWindow - * For RaiseLowest, raises the lowest mapped child (if any) that is - * obscured by another child to the top of the stack. For LowerHighest, - * lowers the highest mapped child (if any) that is obscuring another - * child to the bottom of the stack. Exposure processing is performed - * - ******/ - -int -CirculateWindow(WindowPtr pParent, int direction, ClientPtr client) -{ - register WindowPtr pWin, pHead, pFirst; - xEvent event; - BoxRec box; - - #ifdef TEST - fprintf(stderr, "CirculateWindow: pParent [%p] direction [%d] client [%p]\n", - pParent, direction, client); - #endif - - /* - * if (nxagentOption(Rootless) && nxagentWMIsRunning && - * nxagentWindowTopLevel(pWin) && pWin -> overrideRedirect == 0) - * { - * nxagentCirculateRootlessWindows(direction); - * return Success; - * } - */ - - pHead = RealChildHead(pParent); - pFirst = pHead ? pHead->nextSib : pParent->firstChild; - if (direction == RaiseLowest) - { - for (pWin = pParent->lastChild; - (pWin != pHead) && - !(pWin->mapped && - AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box))); - pWin = pWin->prevSib) ; - if (pWin == pHead) - return Success; - } - else - { - for (pWin = pFirst; - pWin && - !(pWin->mapped && - IOverlapAnyWindow(pWin, WindowExtents(pWin, &box))); - pWin = pWin->nextSib) ; - if (!pWin) - return Success; - } - - event.u.circulate.window = pWin->drawable.id; - event.u.circulate.parent = pParent->drawable.id; - event.u.circulate.event = pParent->drawable.id; - if (direction == RaiseLowest) - event.u.circulate.place = PlaceOnTop; - else - event.u.circulate.place = PlaceOnBottom; - - if (RedirectSend(pParent)) - { - event.u.u.type = CirculateRequest; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - event.u.u.type = CirculateNotify; - DeliverEvents(pWin, &event, 1, NullWindow); - ReflectStackChange(pWin, - (direction == RaiseLowest) ? pFirst : NullWindow, - VTStack); - - return(Success); -} - -static int -CompareWIDs( - WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - Window *wid = (Window *)value; - - if (pWin->drawable.id == *wid) - return(WT_STOPWALKING); - else - return(WT_WALKCHILDREN); -} - -/***** - * ReparentWindow - *****/ - -int -ReparentWindow(register WindowPtr pWin, register WindowPtr pParent, - int x, int y, ClientPtr client) -{ - WindowPtr pPrev, pPriorParent; - Bool WasMapped = (Bool)(pWin->mapped); - xEvent event; - int bw = wBorderWidth (pWin); - register ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING) - return(BadMatch); - if (!MakeWindowOptional(pWin)) - return(BadAlloc); - - if (WasMapped) - UnmapWindow(pWin, FALSE); - - event.u.u.type = ReparentNotify; - event.u.reparent.window = pWin->drawable.id; - event.u.reparent.parent = pParent->drawable.id; - event.u.reparent.x = x; - event.u.reparent.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pParent->parent) { - event.u.reparent.x += panoramiXdataPtr[0].x; - event.u.reparent.y += panoramiXdataPtr[0].y; - } -#endif - event.u.reparent.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, pParent); - - /* take out of sibling chain */ - - pPriorParent = pPrev = pWin->parent; - if (pPrev->firstChild == pWin) - pPrev->firstChild = pWin->nextSib; - if (pPrev->lastChild == pWin) - pPrev->lastChild = pWin->prevSib; - - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - - /* insert at begining of pParent */ - pWin->parent = pParent; - pPrev = RealChildHead(pParent); - - if (pWin->parent == WindowTable[0]) - { - nxagentSetTopLevelEventMask(pWin); - } - - if (pPrev) - { - pWin->nextSib = pPrev->nextSib; - if (pPrev->nextSib) - pPrev->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pPrev->nextSib = pWin; - pWin->prevSib = pPrev; - } - else - { - pWin->nextSib = pParent->firstChild; - pWin->prevSib = NullWindow; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.x = x + bw + pParent->drawable.x; - pWin->drawable.y = y + bw + pParent->drawable.y; - - /* clip to parent */ - SetWinSize (pWin); - SetBorderSize (pWin); - - if (pScreen->ReparentWindow) - (*pScreen->ReparentWindow)(pWin, pPriorParent); - - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - CheckWindowOptionalNeed(pWin); - - if (WasMapped) - MapWindow(pWin, client); - RecalculateDeliverableEvents(pWin); - return(Success); -} - -static void -RealizeTree(WindowPtr pWin) -{ - register WindowPtr pChild; - RealizeWindowProcPtr Realize; - - Realize = pWin->drawable.pScreen->RealizeWindow; - pChild = pWin; - while (1) - { - if (pChild->mapped) - { - pChild->realized = TRUE; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable++; -#endif - pChild->viewable = (pChild->drawable.class == InputOutput); - (* Realize)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * MapWindow - * If some other client has selected SubStructureReDirect on the parent - * and override-redirect is xFalse, then a MapRequest event is generated, - * but the window remains unmapped. Otherwise, the window is mapped and a - * MapNotify event is generated. - *****/ - -int -MapWindow(register WindowPtr pWin, ClientPtr client) -{ - register ScreenPtr pScreen; - - register WindowPtr pParent; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - #ifdef TEST - if (nxagentWindowTopLevel(pWin)) - { - fprintf(stderr, "MapWindow: pWin [%p] client [%p]\n", pWin, client); - } - #endif - - if (pWin->mapped) - return(Success); - -#ifdef XCSECURITY - /* don't let an untrusted client map a child-of-trusted-window, InputOnly - * window; too easy to steal device input - */ - if ( (client->trustLevel != XSecurityClientTrusted) && - (pWin->drawable.class == InputOnly) && - (wClient(pWin->parent)->trustLevel == XSecurityClientTrusted) ) - return Success; -#endif - - pScreen = pWin->drawable.pScreen; - if ( (pParent = pWin->parent) ) - { - xEvent event; - Bool anyMarked; -#ifdef XAPPGROUP - ClientPtr win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ClientPtr ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.mapRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - pWin->mapped = TRUE; - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pParent->realized) - return(Success); - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - } - WindowsRestructured (); - } - else - { - RegionRec temp; - - pWin->mapped = TRUE; - pWin->realized = TRUE; /* for roots */ - pWin->viewable = pWin->drawable.class == InputOutput; - /* We SHOULD check for an error value here XXX */ - (*pScreen->RealizeWindow)(pWin); - if (pScreen->ClipNotify) - (*pScreen->ClipNotify) (pWin, 0, 0); - if (pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap); - REGION_NULL(pScreen, &temp); - REGION_COPY(pScreen, &temp, &pWin->clipList); - (*pScreen->WindowExposures) (pWin, &temp, NullRegion); - REGION_UNINIT(pScreen, &temp); - } - - nxagentFlushConfigureWindow(); - - return(Success); -} - - -/***** - * MapSubwindows - * Performs a MapWindow all unmapped children of the window, in top - * to bottom stacking order. - *****/ - -void -MapSubwindows(register WindowPtr pParent, ClientPtr client) -{ - register WindowPtr pWin; - WindowPtr pFirstMapped = NullWindow; -#ifdef DO_SAVE_UNDERS - WindowPtr pFirstSaveUndered = NullWindow; -#endif - register ScreenPtr pScreen; - register Mask parentRedirect; - register Mask parentNotify; - xEvent event; - Bool anyMarked; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - pScreen = pParent->drawable.pScreen; - parentRedirect = RedirectSend(pParent); - parentNotify = SubSend(pParent); - anyMarked = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (!pWin->mapped) - { - if (parentRedirect && !pWin->overrideRedirect) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - continue; - } - - pWin->mapped = TRUE; - if (parentNotify || StrSend(pWin)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pFirstMapped) - pFirstMapped = pWin; - if (pParent->realized) - { - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = TRUE; - } -#endif /* DO_SAVE_UNDERS */ - } - } - } - } - - if (pFirstMapped) - { - pLayerWin = (*pScreen->GetLayerWindow)(pParent); - if (pLayerWin->parent != pParent) { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pLayerWin, - pLayerWin, - (WindowPtr *)NULL); - pFirstMapped = pLayerWin; - } - if (anyMarked) - { -#ifdef DO_SAVE_UNDERS - if (pLayerWin->parent != pParent) - { - if (dosave || (DO_SAVE_UNDERS(pLayerWin))) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, - pLayerWin); - } - } - else if (dosave) - { - dosave = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (DO_SAVE_UNDERS(pWin)) - { - dosave |= (*pScreen->ChangeSaveUnder)(pWin, - pWin->nextSib); - if (dosave && !pFirstSaveUndered) - pFirstSaveUndered = pWin; - } - } - } -#endif /* DO_SAVE_UNDERS */ - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstMapped, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, - pFirstSaveUndered->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstMapped, - VTMap); - WindowsRestructured (); - } -} - -static void -UnrealizeTree( - WindowPtr pWin, - Bool fromConfigure) -{ - register WindowPtr pChild; - UnrealizeWindowProcPtr Unrealize; - MarkUnrealizedWindowProcPtr MarkUnrealizedWindow; - - Unrealize = pWin->drawable.pScreen->UnrealizeWindow; - MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow; - pChild = pWin; - while (1) - { - if (pChild->realized) - { - pChild->realized = FALSE; - pChild->visibility = VisibilityNotViewable; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { - PanoramiXRes *win; - win = (PanoramiXRes*)LookupIDByType(pChild->drawable.id, - XRT_WINDOW); - if(win) - win->u.win.visibility = VisibilityNotViewable; - } -#endif - (* Unrealize)(pChild); - DeleteWindowFromAnyEvents(pChild, FALSE); - if (pChild->viewable) - { -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->backStorage) - (*pChild->drawable.pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - (* MarkUnrealizedWindow)(pChild, pWin, fromConfigure); - pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * UnmapWindow - * If the window is already unmapped, this request has no effect. - * Otherwise, the window is unmapped and an UnMapNotify event is - * generated. Cannot unmap a root window. - *****/ - -int -UnmapWindow(register WindowPtr pWin, Bool fromConfigure) -{ - register WindowPtr pParent; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - ScreenPtr pScreen = pWin->drawable.pScreen; - WindowPtr pLayerWin = pWin; - - #ifdef TEST - if (nxagentWindowTopLevel(pWin)) - { - fprintf(stderr, "UnmapWindow: pWin [%p] fromConfigure [%d]\n", pWin, - fromConfigure); - } - #endif - - if ((!pWin->mapped) || (!(pParent = pWin->parent))) - return(Success); - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pWin->drawable.id; - event.u.unmapNotify.fromConfigure = fromConfigure; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (wasViewable && !fromConfigure) - { - pWin->valdata = UnmapValData; - (*pScreen->MarkOverlappedWindows)(pWin, pWin->nextSib, &pLayerWin); - (*pScreen->MarkWindow)(pLayerWin->parent); - } - pWin->mapped = FALSE; - if (wasRealized) - UnrealizeTree(pWin, fromConfigure); - if (wasViewable) - { - if (!fromConfigure) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pWin, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib) ) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); - } - } - pWin->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (!fromConfigure && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pWin, VTUnmap); - } - if (wasRealized && !fromConfigure) - WindowsRestructured (); - return(Success); -} - -/***** - * UnmapSubwindows - * Performs an UnmapWindow request with the specified mode on all mapped - * children of the window, in bottom to top stacking order. - *****/ - -void -UnmapSubwindows(register WindowPtr pWin) -{ - register WindowPtr pChild, pHead; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - Bool anyMarked = FALSE; - Mask parentNotify; - WindowPtr pLayerWin = NULL; - ScreenPtr pScreen = pWin->drawable.pScreen; - - if (!pWin->firstChild) - return; - parentNotify = SubSend(pWin); - pHead = RealChildHead(pWin); - - if (wasViewable) - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (pChild->mapped) - { - if (parentNotify || StrSend(pChild)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pChild->drawable.id; - event.u.unmapNotify.fromConfigure = xFalse; - DeliverEvents(pChild, &event, 1, NullWindow); - } - if (pChild->viewable) - { - pChild->valdata = UnmapValData; - anyMarked = TRUE; - } - pChild->mapped = FALSE; - if (pChild->realized) - UnrealizeTree(pChild, FALSE); - if (wasViewable) - { -#ifdef DO_SAVE_UNDERS - pChild->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (pChild->backStorage) - (*pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - } - } - } - if (wasViewable) - { - if (anyMarked) - { - if (pLayerWin->parent == pWin) - (*pScreen->MarkWindow)(pWin); - else - { - WindowPtr ptmp; - (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - (*pScreen->MarkWindow)(pLayerWin->parent); - - /* Windows between pWin and pLayerWin may not have been marked */ - ptmp = pWin; - - while (ptmp != pLayerWin->parent) - { - (*pScreen->MarkWindow)(ptmp); - ptmp = ptmp->parent; - } - pHead = pWin->firstChild; - } - (*pScreen->ValidateTree)(pLayerWin->parent, pHead, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin)) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pHead, VTUnmap); - } - if (wasRealized) - WindowsRestructured (); -} - - -void -HandleSaveSet(register ClientPtr client) -{ - register WindowPtr pParent, pWin; - register int j; - - for (j=0; jnumSaved; j++) - { - pWin = SaveSetWindow(client->saveSet[j]); -#ifdef XFIXES - if (SaveSetToRoot(client->saveSet[j])) - pParent = WindowTable[pWin->drawable.pScreen->myNum]; - else -#endif - { - pParent = pWin->parent; - while (pParent && (wClient (pParent) == client)) - pParent = pParent->parent; - } - if (pParent) - { - if (pParent != pWin->parent) - { - ReparentWindow(pWin, pParent, - pWin->drawable.x - wBorderWidth (pWin) - pParent->drawable.x, - pWin->drawable.y - wBorderWidth (pWin) - pParent->drawable.y, - client); - if(!pWin->realized && pWin->mapped) - pWin->mapped = FALSE; - } -#ifdef XFIXES - if (SaveSetRemap (client->saveSet[j])) -#endif - MapWindow(pWin, client); - } - } - xfree(client->saveSet); - client->numSaved = 0; - client->saveSet = (SaveSetElt *)NULL; -} - -/** - * - * \param x,y in root - * \param box "return" value - */ -Bool -VisibleBoundingBoxFromPoint(register WindowPtr pWin, int x, int y, BoxPtr box) -{ - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->clipList, x, y, box)) - return(TRUE); - return(FALSE); -} - -/** - * - * \param x,y in root - */ -Bool -PointInWindowIsVisible(register WindowPtr pWin, int x, int y) -{ - BoxRec box; - - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip, - x, y, &box) - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) - return(TRUE); - return(FALSE); -} - - -RegionPtr -NotClippedByChildren(register WindowPtr pWin) -{ - register ScreenPtr pScreen; - RegionPtr pReg; - - pScreen = pWin->drawable.pScreen; - pReg = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->parent || - screenIsSaved != SCREEN_SAVER_ON || - !HasSaverWindow (pWin->drawable.pScreen->myNum)) - { - REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize); - } - return(pReg); -} - -void -SendVisibilityNotify(WindowPtr pWin) -{ - xEvent event; -#ifndef NO_XINERAMA_PORT - unsigned int visibility = pWin->visibility; -#endif -#ifdef PANORAMIX - /* This is not quite correct yet, but it's close */ - if(!noPanoramiXExtension) { - PanoramiXRes *win; - WindowPtr pWin2; - int i, Scrnum; - - Scrnum = pWin->drawable.pScreen->myNum; - - win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, Scrnum); - - if(!win || (win->u.win.visibility == visibility)) - return; - - switch(visibility) { - case VisibilityUnobscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility == VisibilityPartiallyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - case VisibilityPartiallyObscured: - if(Scrnum) { - pWin2 = (WindowPtr)LookupIDByType(win->info[0].id, RT_WINDOW); - if (pWin2) pWin = pWin2; - } - break; - case VisibilityFullyObscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility != VisibilityFullyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - } - - win->u.win.visibility = visibility; - } -#endif - - event.u.u.type = VisibilityNotify; - event.u.visibility.window = pWin->drawable.id; - event.u.visibility.state = visibility; - DeliverEvents(pWin, &event, 1, NullWindow); -} - - -#define RANDOM_WIDTH 32 - -#ifndef NOLOGOHACK -static void DrawLogo( - WindowPtr pWin -); -#endif - -void -SaveScreens(int on, int mode) -{ - int i; - int what; - int type; - - if (on == SCREEN_SAVER_FORCER) - { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; - if (mode == ScreenSaverReset) - what = SCREEN_SAVER_OFF; - else - what = SCREEN_SAVER_ON; - type = what; - } - else - { - what = on; - type = what; - if (what == screenIsSaved) - type = SCREEN_SAVER_CYCLE; - } - for (i = 0; i < screenInfo.numScreens; i++) - { - if (on == SCREEN_SAVER_FORCER) - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], on); - if (savedScreenInfo[i].ExternalScreenSaver) - { - if (nxagentOption(Timeout) != 0) - { - #ifdef TEST - fprintf(stderr, "SaveScreens: An external screen-saver handler is installed. " - "Ignoring it to let the auto-disconnect feature work.\n"); - #endif - } - else - { - if ((*savedScreenInfo[i].ExternalScreenSaver) - (screenInfo.screens[i], type, on == SCREEN_SAVER_FORCER)) - continue; - } - } - if (type == screenIsSaved) - continue; - switch (type) { - case SCREEN_SAVER_OFF: - if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - what); - } - else if (HasSaverWindow (i)) - { - savedScreenInfo[i].pWindow = NullWindow; - FreeResource(savedScreenInfo[i].wid, RT_NONE); - } - break; - case SCREEN_SAVER_CYCLE: - if (savedScreenInfo[i].blanked == SCREEN_IS_TILED) - { - WindowPtr pWin = savedScreenInfo[i].pWindow; - /* make it look like screen saver is off, so that - * NotClippedByChildren will compute a clip list - * for the root window, so miPaintWindow works - */ - screenIsSaved = SCREEN_SAVER_OFF; -#ifndef NOLOGOHACK - if (logoScreenSaver) - (*pWin->drawable.pScreen->ClearToBackground)(pWin, 0, 0, 0, 0, FALSE); -#endif - (*pWin->drawable.pScreen->MoveWindow)(pWin, - (short)(-(rand() % RANDOM_WIDTH)), - (short)(-(rand() % RANDOM_WIDTH)), - pWin->nextSib, VTMove); -#ifndef NOLOGOHACK - if (logoScreenSaver) - DrawLogo(pWin); -#endif - screenIsSaved = SCREEN_SAVER_ON; - } - /* - * Call the DDX saver in case it wants to do something - * at cycle time - */ - else if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - type); - } - break; - case SCREEN_SAVER_ON: - if (ScreenSaverBlanking != DontPreferBlanking) - { - if ((* screenInfo.screens[i]->SaveScreen) - (screenInfo.screens[i], what)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLANKED; - continue; - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_BLACK)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLACK; - continue; - } - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_TILED)) - { - savedScreenInfo[i].blanked = SCREEN_IS_TILED; - } - else - savedScreenInfo[i].blanked = SCREEN_ISNT_SAVED; - break; - } - } - screenIsSaved = what; - if (mode == ScreenSaverReset) - SetScreenSaverTimer(); -} - -static Bool -TileScreenSaver(int i, int kind) -{ - int j; - int result; - XID attributes[3]; - Mask mask; - WindowPtr pWin; - CursorMetricRec cm; - unsigned char *srcbits, *mskbits; - CursorPtr cursor; - XID cursorID = 0; - int attri; - - mask = 0; - attri = 0; - switch (kind) { - case SCREEN_IS_TILED: - switch (WindowTable[i]->backgroundState) { - case BackgroundPixel: - attributes[attri++] = WindowTable[i]->background.pixel; - mask |= CWBackPixel; - break; - case BackgroundPixmap: - attributes[attri++] = None; - mask |= CWBackPixmap; - break; - default: - break; - } - break; - case SCREEN_IS_BLACK: - attributes[attri++] = WindowTable[i]->drawable.pScreen->blackPixel; - mask |= CWBackPixel; - break; - } - mask |= CWOverrideRedirect; - attributes[attri++] = xTrue; - - /* - * create a blank cursor - */ - - cm.width=16; - cm.height=16; - cm.xhot=8; - cm.yhot=8; - srcbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - mskbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - if (!srcbits || !mskbits) - { - xfree(srcbits); - xfree(mskbits); - cursor = 0; - } - else - { - for (j=0; jwidth + RANDOM_WIDTH, - (unsigned short)screenInfo.screens[i]->height + RANDOM_WIDTH, - 0, InputOutput, mask, attributes, 0, serverClient, - wVisual (WindowTable[i]), &result); - - if (cursor) - FreeResource (cursorID, RT_NONE); - - if (!pWin) - return FALSE; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, - (pointer)savedScreenInfo[i].pWindow)) - return FALSE; - - if (mask & CWBackPixmap) - { - MakeRootTile (pWin); - (*pWin->drawable.pScreen->ChangeWindowAttributes)(pWin, CWBackPixmap); - } - MapWindow(pWin, serverClient); -#ifndef NOLOGOHACK - if (kind == SCREEN_IS_TILED && logoScreenSaver) - DrawLogo(pWin); -#endif - return TRUE; -} - -/* - * FindWindowWithOptional - * - * search ancestors of the given window for an entry containing - * a WindowOpt structure. Assumptions: some parent will - * contain the structure. - */ - -WindowPtr -FindWindowWithOptional (register WindowPtr w) -{ - do - w = w->parent; - while (!w->optional); - return w; -} - -/* - * CheckWindowOptionalNeed - * - * check each optional entry in the given window to see if - * the value is satisfied by the default rules. If so, - * release the optional record - */ - -void -CheckWindowOptionalNeed (register WindowPtr w) -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (!w->parent) - return; - optional = w->optional; - if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate]) - return; - if (optional->otherEventMasks != 0) - return; - if (optional->otherClients != NULL) - return; - if (optional->passiveGrabs != NULL) - return; - if (optional->userProps != NULL) - return; - if (optional->backingBitPlanes != ~0L) - return; - if (optional->backingPixel != 0) - return; -#ifdef SHAPE - if (optional->boundingShape != NULL) - return; - if (optional->clipShape != NULL) - return; - if (optional->inputShape != NULL) - return; -#endif -#ifdef XINPUT - if (optional->inputMasks != NULL) - return; -#endif - parentOptional = FindWindowWithOptional(w)->optional; - if (optional->visual != parentOptional->visual) - return; - if (optional->cursor != None && - (optional->cursor != parentOptional->cursor || - w->parent->cursorIsNone)) - return; - if (optional->colormap != parentOptional->colormap) - return; - DisposeWindowOptional (w); -} - -/* - * MakeWindowOptional - * - * create an optional record and initialize it with the default - * values. - */ - -Bool -MakeWindowOptional (register WindowPtr pWin) -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (pWin->optional) - return TRUE; - optional = (WindowOptPtr) xalloc (sizeof (WindowOptRec)); - if (!optional) - return FALSE; - optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; - optional->otherEventMasks = 0; - optional->otherClients = NULL; - optional->passiveGrabs = NULL; - optional->userProps = NULL; - optional->backingBitPlanes = ~0L; - optional->backingPixel = 0; -#ifdef SHAPE - optional->boundingShape = NULL; - optional->clipShape = NULL; - optional->inputShape = NULL; -#endif -#ifdef XINPUT - optional->inputMasks = NULL; -#endif - parentOptional = FindWindowWithOptional(pWin)->optional; - optional->visual = parentOptional->visual; - if (!pWin->cursorIsNone) - { - optional->cursor = parentOptional->cursor; - optional->cursor->refcnt++; - } - else - { - optional->cursor = None; - } - optional->colormap = parentOptional->colormap; - pWin->optional = optional; - return TRUE; -} - -void -DisposeWindowOptional (register WindowPtr pWin) -{ - if (!pWin->optional) - return; - /* - * everything is peachy. Delete the optional record - * and clean up - */ - /* - * TOG changed this code to: - * - * if (pWin->cursorIsNone == FALSE) - * FreeCursor (pWin->optional->cursor, (Cursor)0); - * pWin->cursorIsNone = TRUE; - * - * This is blatently wrong; windows without optionals can have - * two different cursor values, either None or sharing their - * parents cursor. This difference is controlled by the - * cursorIsNone value; when TRUE, the window has no cursor, - * when false, it shares its cursor with its parent; TOG - * made it impossible for a window to have a cursor without - * an optional record. - */ - if (pWin->optional->cursor) - { - FreeCursor (pWin->optional->cursor, (Cursor)0); - pWin->cursorIsNone = FALSE; - } - else - pWin->cursorIsNone = TRUE; -/* FIXME - There is an error when disposing ClientResources on Agent exit - this xfree is not valid in some window at exit -*/ - - xfree (pWin->optional); - pWin->optional = NULL; -} - -#ifndef NOLOGOHACK -static void -DrawLogo(WindowPtr pWin) -{ - DrawablePtr pDraw; - ScreenPtr pScreen; - int x, y; - unsigned int width, height, size; - GC *pGC; - int thin, gap, d31; - DDXPointRec poly[4]; - ChangeGCVal fore[2], back[2]; - xrgb rgb[2]; - BITS32 fmask, bmask; - ColormapPtr cmap; - - pDraw = (DrawablePtr)pWin; - pScreen = pDraw->pScreen; - x = -pWin->origin.x; - y = -pWin->origin.y; - width = pScreen->width; - height = pScreen->height; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pGC) - return; - - if ((rand() % 100) <= 17) /* make the probability for white fairly low */ - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - if ((pWin->backgroundState == BackgroundPixel) && - (cmap = (ColormapPtr)LookupIDByType(wColormap (pWin), RT_COLORMAP))) { - Pixel querypixels[2]; - - querypixels[0] = fore[0].val; - querypixels[1] = pWin->background.pixel; - QueryColors(cmap, 2, querypixels, rgb); - if ((rgb[0].red == rgb[1].red) && - (rgb[0].green == rgb[1].green) && - (rgb[0].blue == rgb[1].blue)) { - if (fore[0].val == pScreen->blackPixel) - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - } - } - fore[1].val = FillSolid; - fmask = GCForeground|GCFillStyle; - if (pWin->backgroundState == BackgroundPixel) { - back[0].val = pWin->background.pixel; - back[1].val = FillSolid; - bmask = GCForeground|GCFillStyle; - } else { - back[0].val = 0; - back[1].val = 0; - dixChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin, - NULL, back); - back[0].val = FillTiled; - back[1].ptr = pWin->background.pixmap; - bmask = GCFillStyle|GCTile; - } - - /* should be the same as the reference function XmuDrawLogo() */ - - size = width; - if (height < width) - size = height; - size = RANDOM_WIDTH + rand() % (size - RANDOM_WIDTH); - size &= ~1; - x += rand() % (width - size); - y += rand() % (height - size); - -/* - * Draw what will be the thin strokes. - * - * ----- - * / / - * / / - * / / - * / / - * /____/ - * d - * - * Point d is 9/44 (~1/5) of the way across. - */ - - thin = (size / 11); - if (thin < 1) thin = 1; - gap = (thin+3) / 4; - d31 = thin + thin + gap; - poly[0].x = x + size; poly[0].y = y; - poly[1].x = x + size-d31; poly[1].y = y; - poly[2].x = x + 0; poly[2].y = y + size; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for lower thin stroke. - * - * ------ - * / / - * / __ / - * / / / - * / / / - * /__/__/ - */ - - poly[0].x = x + d31/2; poly[0].y = y + size; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)+(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for upper thin stroke. - * - * ------ - * / / / - * /--/ / - * / / - * / / - * /_____/ - */ - - poly[0].x = x + size - d31/2; poly[0].y = y; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)-(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + size - d31; poly[3].y = y; - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Draw thick stroke. - * Point b is 1/4 of the way across. - * - * b - * ----- - * \ \ - * \ \ - * \ \ - * \ \ - * \____\ - */ - - poly[0].x = x; poly[0].y = y; - poly[1].x = x + size/4; poly[1].y = y; - poly[2].x = x + size; poly[2].y = y + size; - poly[3].x = x + size - size/4; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase to create gap. - * - * / - * / - * / - * / - * / - */ - - poly[0].x = x + size- thin; poly[0].y = y; - poly[1].x = x + size-( thin+gap); poly[1].y = y; - poly[2].x = x + thin; poly[2].y = y + size; - poly[3].x = x + thin + gap; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - - FreeScratchGC(pGC); -} - -#endif - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.X.original deleted file mode 100644 index c060f4a23..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c.X.original +++ /dev/null @@ -1,3853 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/dix/window.c,v 1.12 2005/07/03 08:53:38 daniels Exp $ */ -/* $Xorg: window.c,v 1.4 2001/02/09 02:04:41 xorgcvs Exp $ */ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -*/ - -/* The panoramix components contained the following notice */ -/***************************************************************** - -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. - -******************************************************************/ - -/* $XFree86: xc/programs/Xserver/dix/window.c,v 3.36 2003/11/14 23:52:50 torrey Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "misc.h" -#include "scrnintstr.h" -#include "os.h" -#include "regionstr.h" -#include "validate.h" -#include "windowstr.h" -#include "input.h" -#include "resource.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "dixstruct.h" -#include "gcstruct.h" -#include "servermd.h" -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" -#endif -#include "dixevents.h" -#include "globals.h" - -#ifdef XAPPGROUP -#include -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif - -/****** - * Window stuff for server - * - * CreateRootWindow, CreateWindow, ChangeWindowAttributes, - * GetWindowAttributes, DeleteWindow, DestroySubWindows, - * HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows, - * UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow, - * - ******/ - -static unsigned char _back_lsb[4] = {0x88, 0x22, 0x44, 0x11}; -static unsigned char _back_msb[4] = {0x11, 0x44, 0x22, 0x88}; - -int screenIsSaved = SCREEN_SAVER_OFF; - -ScreenSaverStuffRec savedScreenInfo[MAXSCREENS]; - -#if 0 -extern void DeleteWindowFromAnyEvents(); -extern Mask EventMaskForClient(); -extern void WindowHasNewCursor(); -extern void RecalculateDeliverableEvents(); -#endif - -static Bool TileScreenSaver(int i, int kind); - - -#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \ - CWDontPropagate | CWOverrideRedirect | CWCursor ) - -#define BOXES_OVERLAP(b1, b2) \ - (!( ((b1)->x2 <= (b2)->x1) || \ - ( ((b1)->x1 >= (b2)->x2)) || \ - ( ((b1)->y2 <= (b2)->y1)) || \ - ( ((b1)->y1 >= (b2)->y2)) ) ) - -#define RedirectSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask) - -#define SubSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask) - -#define StrSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask) - -#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent)) - - -int numSaveUndersViewable = 0; -int deltaSaveUndersViewable = 0; - -#ifdef DEBUG -/****** - * PrintWindowTree - * For debugging only - ******/ - -int -PrintChildren(WindowPtr p1, int indent) -{ - WindowPtr p2; - int i; - - while (p1) - { - p2 = p1->firstChild; - for (i=0; idrawable.id); - miPrintRegion(&p1->clipList); - PrintChildren(p2, indent+4); - p1 = p1->nextSib; - } -} - -PrintWindowTree() -{ - int i; - WindowPtr pWin, p1; - - for (i=0; iclipList); - p1 = pWin->firstChild; - PrintChildren(p1, 4); - } -} -#endif - -int -TraverseTree(register WindowPtr pWin, VisitWindowProcPtr func, pointer data) -{ - register int result; - register WindowPtr pChild; - - if (!(pChild = pWin)) - return(WT_NOMATCH); - while (1) - { - result = (* func)(pChild, data); - if (result == WT_STOPWALKING) - return(WT_STOPWALKING); - if ((result == WT_WALKCHILDREN) && pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; - } - return(WT_NOMATCH); -} - -/***** - * WalkTree - * Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on - * each window. If FUNC returns WT_WALKCHILDREN, traverse the children, - * if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING - * exit WalkTree. Does depth-first traverse. - *****/ - -int -WalkTree(ScreenPtr pScreen, VisitWindowProcPtr func, pointer data) -{ - return(TraverseTree(WindowTable[pScreen->myNum], func, data)); -} - -/* hack for forcing backing store on all windows */ -int defaultBackingStore = NotUseful; -/* hack to force no backing store */ -Bool disableBackingStore = FALSE; -Bool enableBackingStore = FALSE; -/* hack to force no save unders */ -Bool disableSaveUnders = FALSE; - -static void -SetWindowToDefaults(register WindowPtr pWin) -{ - pWin->prevSib = NullWindow; - pWin->firstChild = NullWindow; - pWin->lastChild = NullWindow; - - pWin->valdata = (ValidatePtr)NULL; - pWin->optional = (WindowOptPtr)NULL; - pWin->cursorIsNone = TRUE; - - pWin->backingStore = NotUseful; - pWin->DIXsaveUnder = FALSE; - pWin->backStorage = (pointer) NULL; - - pWin->mapped = FALSE; /* off */ - pWin->realized = FALSE; /* off */ - pWin->viewable = FALSE; - pWin->visibility = VisibilityNotViewable; - pWin->overrideRedirect = FALSE; - pWin->saveUnder = FALSE; - - pWin->bitGravity = ForgetGravity; - pWin->winGravity = NorthWestGravity; - - pWin->eventMask = 0; - pWin->deliverableEvents = 0; - pWin->dontPropagate = 0; - pWin->forcedBS = FALSE; -#ifdef NEED_DBE_BUF_BITS - pWin->srcBuffer = DBE_FRONT_BUFFER; - pWin->dstBuffer = DBE_FRONT_BUFFER; -#endif -#ifdef COMPOSITE - pWin->redirectDraw = 0; -#endif -} - -static void -MakeRootTile(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - GCPtr pGC; - unsigned char back[128]; - int len = BitmapBytePad(sizeof(long)); - register unsigned char *from, *to; - register int i, j; - - pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4, - pScreen->rootDepth); - - pWin->backgroundState = BackgroundPixmap; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pWin->background.pixmap || !pGC) - FatalError("could not create root tile"); - - { - CARD32 attributes[2]; - - attributes[0] = pScreen->whitePixel; - attributes[1] = pScreen->blackPixel; - - (void)ChangeGC(pGC, GCForeground | GCBackground, attributes); - } - - ValidateGC((DrawablePtr)pWin->background.pixmap, pGC); - - from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb; - to = back; - - for (i = 4; i > 0; i--, from++) - for (j = len; j > 0; j--) - *to++ = *from; - - if (blackRoot) - bzero(back, sizeof(back)); - - (*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, pGC, 1, - 0, 0, len, 4, 0, XYBitmap, (char *)back); - - FreeScratchGC(pGC); - -} - -WindowPtr -AllocateWindow(ScreenPtr pScreen) -{ - WindowPtr pWin; - register char *ptr; - register DevUnion *ppriv; - register unsigned *sizes; - register unsigned size; - register int i; - - pWin = (WindowPtr)xalloc(pScreen->totalWindowSize); - if (pWin) - { - ppriv = (DevUnion *)(pWin + 1); - pWin->devPrivates = ppriv; - sizes = pScreen->WindowPrivateSizes; - ptr = (char *)(ppriv + pScreen->WindowPrivateLen); - for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - } - return pWin; -} - -/***** - * CreateRootWindow - * Makes a window at initialization time for specified screen - *****/ - -Bool -CreateRootWindow(ScreenPtr pScreen) -{ - WindowPtr pWin; - BoxRec box; - PixmapFormatRec *format; - - pWin = AllocateWindow(pScreen); - if (!pWin) - return FALSE; - - savedScreenInfo[pScreen->myNum].pWindow = NULL; - savedScreenInfo[pScreen->myNum].wid = FakeClientID(0); - savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL; - screenIsSaved = SCREEN_SAVER_OFF; - - WindowTable[pScreen->myNum] = pWin; - - pWin->drawable.pScreen = pScreen; - pWin->drawable.type = DRAWABLE_WINDOW; - - pWin->drawable.depth = pScreen->rootDepth; - for (format = screenInfo.formats; - format->depth != pScreen->rootDepth; - format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->parent = NullWindow; - SetWindowToDefaults(pWin); - - pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec)); - if (!pWin->optional) - return FALSE; - - pWin->optional->dontPropagateMask = 0; - pWin->optional->otherEventMasks = 0; - pWin->optional->otherClients = NULL; - pWin->optional->passiveGrabs = NULL; - pWin->optional->userProps = NULL; - pWin->optional->backingBitPlanes = ~0L; - pWin->optional->backingPixel = 0; -#ifdef SHAPE - pWin->optional->boundingShape = NULL; - pWin->optional->clipShape = NULL; - pWin->optional->inputShape = NULL; -#endif -#ifdef XINPUT - pWin->optional->inputMasks = NULL; -#endif - pWin->optional->colormap = pScreen->defColormap; - pWin->optional->visual = pScreen->rootVisual; - - pWin->nextSib = NullWindow; - - pWin->drawable.id = FakeClientID(0); - - pWin->origin.x = pWin->origin.y = 0; - pWin->drawable.height = pScreen->height; - pWin->drawable.width = pScreen->width; - pWin->drawable.x = pWin->drawable.y = 0; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - REGION_INIT(pScreen, &pWin->winSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderClip, &box, 1); - - pWin->drawable.class = InputOutput; - pWin->optional->visual = pScreen->rootVisual; - - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = pScreen->whitePixel; - - pWin->borderIsPixel = TRUE; - pWin->border.pixel = pScreen->blackPixel; - pWin->borderWidth = 0; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin)) - return FALSE; - - if (disableBackingStore) - pScreen->backingStoreSupport = NotUseful; - if (enableBackingStore) - pScreen->backingStoreSupport = Always; - -#ifdef DO_SAVE_UNDERS - if ((pScreen->backingStoreSupport != NotUseful) && - (pScreen->saveUnderSupport == NotUseful)) - { - /* - * If the screen has backing-store but no save-unders, let the - * clients know we can support save-unders using backing-store. - */ - pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS; - } -#endif /* DO_SAVE_UNDERS */ - - if (disableSaveUnders) - pScreen->saveUnderSupport = NotUseful; - - return TRUE; -} - -void -InitRootWindow(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - - if (!(*pScreen->CreateWindow)(pWin)) - return; /* XXX */ - (*pScreen->PositionWindow)(pWin, 0, 0); - - pWin->cursorIsNone = FALSE; - pWin->optional->cursor = rootCursor; - rootCursor->refcnt++; - MakeRootTile(pWin); - pWin->backingStore = defaultBackingStore; - pWin->forcedBS = (defaultBackingStore != NotUseful); - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, - CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore); - - MapWindow(pWin, serverClient); -} - -/* Set the region to the intersection of the rectangle and the - * window's winSize. The window is typically the parent of the - * window from which the region came. - */ - -void -ClippedRegionFromBox(register WindowPtr pWin, RegionPtr Rgn, - register int x, register int y, - register int w, register int h) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - BoxRec box; - - box = *(REGION_EXTENTS(pScreen, &pWin->winSize)); - /* we do these calculations to avoid overflows */ - if (x > box.x1) - box.x1 = x; - if (y > box.y1) - box.y1 = y; - x += w; - if (x < box.x2) - box.x2 = x; - y += h; - if (y < box.y2) - box.y2 = y; - if (box.x1 > box.x2) - box.x2 = box.x1; - if (box.y1 > box.y2) - box.y2 = box.y1; - REGION_RESET(pScreen, Rgn, &box); - REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize); -} - -WindowPtr -RealChildHead(register WindowPtr pWin) -{ - if (!pWin->parent && - (screenIsSaved == SCREEN_SAVER_ON) && - (HasSaverWindow (pWin->drawable.pScreen->myNum))) - return (pWin->firstChild); - else - return (NullWindow); -} - -/***** - * CreateWindow - * Makes a window in response to client request - *****/ - -WindowPtr -CreateWindow(Window wid, register WindowPtr pParent, int x, int y, unsigned w, - unsigned h, unsigned bw, unsigned class, register Mask vmask, XID *vlist, - int depth, ClientPtr client, VisualID visual, int *error) -{ - register WindowPtr pWin; - WindowPtr pHead; - register ScreenPtr pScreen; - xEvent event; - int idepth, ivisual; - Bool fOK; - DepthPtr pDepth; - PixmapFormatRec *format; - register WindowOptPtr ancwopt; - - if (class == CopyFromParent) - class = pParent->drawable.class; - - if ((class != InputOutput) && (class != InputOnly)) - { - *error = BadValue; - client->errorValue = class; - return NullWindow; - } - - if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) - { - *error = BadMatch; - return NullWindow; - } - - if ((class == InputOnly) && ((bw != 0) || (depth != 0))) - { - *error = BadMatch; - return NullWindow; - } - - pScreen = pParent->drawable.pScreen; - if ((class == InputOutput) && (depth == 0)) - depth = pParent->drawable.depth; - ancwopt = pParent->optional; - if (!ancwopt) - ancwopt = FindWindowWithOptional(pParent)->optional; - if (visual == CopyFromParent) { -#ifdef XAPPGROUP - VisualID ag_visual; - - if (client->appgroup && !pParent->parent && - (ag_visual = XagRootVisual (client))) - visual = ag_visual; - else -#endif - visual = ancwopt->visual; - } - - /* Find out if the depth and visual are acceptable for this Screen */ - if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) - { - fOK = FALSE; - for(idepth = 0; idepth < pScreen->numDepths; idepth++) - { - pDepth = (DepthPtr) &pScreen->allowedDepths[idepth]; - if ((depth == pDepth->depth) || (depth == 0)) - { - for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) - { - if (visual == pDepth->vids[ivisual]) - { - fOK = TRUE; - break; - } - } - } - } - if (fOK == FALSE) - { - *error = BadMatch; - return NullWindow; - } - } - - if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) && - (class != InputOnly) && - (depth != pParent->drawable.depth)) - { - *error = BadMatch; - return NullWindow; - } - - if (((vmask & CWColormap) == 0) && - (class != InputOnly) && - ((visual != ancwopt->visual) || (ancwopt->colormap == None))) - { - *error = BadMatch; - return NullWindow; - } - - pWin = AllocateWindow(pScreen); - if (!pWin) - { - *error = BadAlloc; - return NullWindow; - } - pWin->drawable = pParent->drawable; - pWin->drawable.depth = depth; - if (depth == pParent->drawable.depth) - pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; - else - { - for (format = screenInfo.formats; format->depth != depth; format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; - } - if (class == InputOnly) - pWin->drawable.type = (short) UNDRAWABLE_WINDOW; - pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; - - pWin->drawable.id = wid; - pWin->drawable.class = class; - - pWin->parent = pParent; - SetWindowToDefaults(pWin); - - if (visual != ancwopt->visual) - { - if (!MakeWindowOptional (pWin)) - { - xfree (pWin); - *error = BadAlloc; - return NullWindow; - } - pWin->optional->visual = visual; - pWin->optional->colormap = None; - } - - pWin->borderWidth = bw; -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows; - * they make it too easy to steal window contents - */ - if (client->trustLevel != XSecurityClientTrusted) - { - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = 0; - } - else -#endif - pWin->backgroundState = None; - - pWin->borderIsPixel = pParent->borderIsPixel; - pWin->border = pParent->border; - if (pWin->borderIsPixel == FALSE) - pWin->border.pixmap->refcnt++; - - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; - pWin->drawable.width = w; - pWin->drawable.height = h; - pWin->drawable.x = pParent->drawable.x + x + (int)bw; - pWin->drawable.y = pParent->drawable.y + y + (int)bw; - - /* set up clip list correctly for unobscured WindowPtr */ - REGION_NULL(pScreen, &pWin->clipList); - REGION_NULL(pScreen, &pWin->borderClip); - REGION_NULL(pScreen, &pWin->winSize); - REGION_NULL(pScreen, &pWin->borderSize); - - pHead = RealChildHead(pParent); - if (pHead) - { - pWin->nextSib = pHead->nextSib; - if (pHead->nextSib) - pHead->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pHead->nextSib = pWin; - pWin->prevSib = pHead; - } - else - { - pWin->nextSib = pParent->firstChild; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - SetWinSize (pWin); - SetBorderSize (pWin); - - /* We SHOULD check for an error value here XXX */ - if (!(*pScreen->CreateWindow)(pWin)) - { - *error = BadAlloc; - DeleteWindow(pWin, None); - return NullWindow; - } - /* We SHOULD check for an error value here XXX */ - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - - if (!(vmask & CWEventMask)) - RecalculateDeliverableEvents(pWin); - - if (vmask) - *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin)); - else - *error = Success; - - if (*error != Success) - { - DeleteWindow(pWin, None); - return NullWindow; - } - if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful)) - { - XID value = defaultBackingStore; - (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin)); - pWin->forcedBS = TRUE; - } - - if (SubSend(pParent)) - { - event.u.u.type = CreateNotify; - event.u.createNotify.window = wid; - event.u.createNotify.parent = pParent->drawable.id; - event.u.createNotify.x = x; - event.u.createNotify.y = y; - event.u.createNotify.width = w; - event.u.createNotify.height = h; - event.u.createNotify.borderWidth = bw; - event.u.createNotify.override = pWin->overrideRedirect; - DeliverEvents(pParent, &event, 1, NullWindow); - } - return pWin; -} - -static void -FreeWindowResources(register WindowPtr pWin) -{ - register ScreenPtr pScreen = pWin->drawable.pScreen; - - DeleteWindowFromAnySaveSet(pWin); - DeleteWindowFromAnySelections(pWin); - DeleteWindowFromAnyEvents(pWin, TRUE); - REGION_UNINIT(pScreen, &pWin->clipList); - REGION_UNINIT(pScreen, &pWin->winSize); - REGION_UNINIT(pScreen, &pWin->borderClip); - REGION_UNINIT(pScreen, &pWin->borderSize); -#ifdef SHAPE - if (wBoundingShape (pWin)) - REGION_DESTROY(pScreen, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_DESTROY(pScreen, wClipShape (pWin)); - if (wInputShape (pWin)) - REGION_DESTROY(pScreen, wInputShape (pWin)); -#endif - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - - DeleteAllWindowProperties(pWin); - /* We SHOULD check for an error value here XXX */ - (*pScreen->DestroyWindow)(pWin); - DisposeWindowOptional (pWin); -} - -static void -CrushTree(WindowPtr pWin) -{ - register WindowPtr pChild, pSib, pParent; - UnrealizeWindowProcPtr UnrealizeWindow; - xEvent event; - - if (!(pChild = pWin->firstChild)) - return; - UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow; - while (1) - { - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (1) - { - pParent = pChild->parent; - if (SubStrSend(pChild, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pChild->drawable.id; - DeliverEvents(pChild, &event, 1, NullWindow); - } - FreeResource(pChild->drawable.id, RT_WINDOW); - pSib = pChild->nextSib; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder && pChild->viewable) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->realized) - { - pChild->realized = FALSE; - (*UnrealizeWindow)(pChild); - } - FreeWindowResources(pChild); - xfree(pChild); - if ( (pChild = pSib) ) - break; - pChild = pParent; - pChild->firstChild = NullWindow; - pChild->lastChild = NullWindow; - if (pChild == pWin) - return; - } - } -} - -/***** - * DeleteWindow - * Deletes child of window then window itself - * If wid is None, don't send any events - *****/ - -int -DeleteWindow(pointer value, XID wid) - { - register WindowPtr pParent; - register WindowPtr pWin = (WindowPtr)value; - xEvent event; - - UnmapWindow(pWin, FALSE); - - CrushTree(pWin); - - pParent = pWin->parent; - if (wid && pParent && SubStrSend(pWin, pParent)) - { - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pWin->drawable.id; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - FreeWindowResources(pWin); - if (pParent) - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - } - xfree(pWin); - return Success; -} - -void -DestroySubwindows(register WindowPtr pWin, ClientPtr client) -{ - /* XXX - * The protocol is quite clear that each window should be - * destroyed in turn, however, unmapping all of the first - * eliminates most of the calls to ValidateTree. So, - * this implementation is incorrect in that all of the - * UnmapNotifies occur before all of the DestroyNotifies. - * If you care, simply delete the call to UnmapSubwindows. - */ - UnmapSubwindows(pWin); - while (pWin->lastChild) - FreeResource(pWin->lastChild->drawable.id, RT_NONE); -} - -#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \ - ButtonReleaseMask | PointerMotionMask) - -/***** - * ChangeWindowAttributes - * - * The value-mask specifies which attributes are to be changed; the - * value-list contains one value for each one bit in the mask, from least - * to most significant bit in the mask. - *****/ - -int -ChangeWindowAttributes(register WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) -{ - register Mask index2; - register XID *pVlist; - PixmapPtr pPixmap; - Pixmap pixID; - CursorPtr pCursor, pOldCursor; - Cursor cursorID; - WindowPtr pChild; - Colormap cmap; - ColormapPtr pCmap; - xEvent xE; - int result; - register ScreenPtr pScreen; - Mask vmaskCopy = 0; - register Mask tmask; - unsigned int val; - int error; - Bool checkOptional = FALSE; - Bool borderRelative = FALSE; - WindowPtr pLayerWin; - - if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK))) - return BadMatch; - - error = Success; - pScreen = pWin->drawable.pScreen; - pVlist = vlist; - tmask = vmask; - while (tmask) - { - index2 = (Mask) lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBackPixmap: - pixID = (Pixmap )*pVlist; - pVlist++; - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pixID == None) - { -#ifdef XCSECURITY - /* can't let untrusted clients have background None windows */ - if (client->trustLevel == XSecurityClientTrusted) - { -#endif - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = None; -#ifdef XCSECURITY - } - else - { /* didn't change the background to None, so don't tell ddx */ - index2 = 0; - } -#endif - } - else if (pixID == ParentRelative) - { - if (pWin->parent && - pWin->drawable.depth != pWin->parent->drawable.depth) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - MakeRootTile(pWin); - else - pWin->backgroundState = ParentRelative; - borderRelative = TRUE; - /* Note that the parent's backgroundTile's refcnt is NOT - * incremented. */ - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap != (PixmapPtr) NULL) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixmap; - pWin->background.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBackPixel: - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = (CARD32 ) *pVlist; - /* background pixel overrides background pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBackPixmap; - pVlist++; - break; - case CWBorderPixmap: - pixID = (Pixmap ) *pVlist; - pVlist++; - if (pixID == CopyFromParent) - { - if (!pWin->parent || - (pWin->drawable.depth != pWin->parent->drawable.depth)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->border = pWin->parent->border; - if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE) - { - index2 = CWBorderPixel; - } - else - { - pWin->parent->border.pixmap->refcnt++; - } - } - else - { - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID, - RT_PIXMAP, SecurityReadAccess); - if (pPixmap) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = FALSE; - pWin->border.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = BadPixmap; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBorderPixel: - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = TRUE; - pWin->border.pixel = (CARD32) *pVlist; - /* border pixel overrides border pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBorderPixmap; - pVlist++; - break; - case CWBitGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->bitGravity = val; - break; - case CWWinGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->winGravity = val; - break; - case CWBackingStore: - val = (CARD8 )*pVlist; - pVlist++; - if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->backingStore = val; - pWin->forcedBS = FALSE; - break; - case CWBackingPlanes: - if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingBitPlanes = (CARD32) *pVlist; - if ((CARD32)*pVlist == (CARD32)~0L) - checkOptional = TRUE; - } - pVlist++; - break; - case CWBackingPixel: - if (pWin->optional || (CARD32) *pVlist) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingPixel = (CARD32) *pVlist; - if (!*pVlist) - checkOptional = TRUE; - } - pVlist++; - break; - case CWSaveUnder: - val = (BOOL) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } -#ifdef DO_SAVE_UNDERS - if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) && - DO_SAVE_UNDERS(pWin)) - { - /* - * Re-check all siblings and inferiors for obscurity or - * exposition (hee hee). - */ - if (pWin->saveUnder) - deltaSaveUndersViewable--; - else - deltaSaveUndersViewable++; - pWin->saveUnder = val; - - if (pWin->firstChild) - { - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pLayerWin->parent, - pWin->nextSib); - } - else - { - if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib)) - (*pScreen->PostChangeSaveUnder)(pWin, - pWin->nextSib); - } - } - else - { - /* If we're changing the saveUnder attribute of the root - * window, all we do is set pWin->saveUnder so that - * GetWindowAttributes returns the right value. We don't - * do the "normal" save-under processing (as above). - * Hope that doesn't cause any problems. - */ - pWin->saveUnder = val; - } -#else - pWin->saveUnder = val; -#endif /* DO_SAVE_UNDERS */ - break; - case CWEventMask: - result = EventSelectForWindow(pWin, client, (Mask )*pVlist); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWDontPropagate: - result = EventSuppressForWindow(pWin, client, (Mask )*pVlist, - &checkOptional); - if (result) - { - error = result; - goto PatchUp; - } - pVlist++; - break; - case CWOverrideRedirect: - val = (BOOL ) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->overrideRedirect = val; - break; - case CWColormap: - cmap = (Colormap) *pVlist; - pVlist++; - if (cmap == CopyFromParent) - { -#ifdef XAPPGROUP - Colormap ag_colormap; - ClientPtr win_owner; - - /* - * win_owner == client for CreateWindow, other clients - * can ChangeWindowAttributes - */ - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - - if ( win_owner && win_owner->appgroup && - !pWin->parent->parent && - (ag_colormap = XagDefaultColormap (win_owner))) - cmap = ag_colormap; - else -#endif - if (pWin->parent && - (!pWin->optional || - pWin->optional->visual == wVisual (pWin->parent))) - { - cmap = wColormap (pWin->parent); - } - else - cmap = None; - } - if (cmap == None) - { - error = BadMatch; - goto PatchUp; - } - pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap, - RT_COLORMAP, SecurityReadAccess); - if (!pCmap) - { - error = BadColor; - client->errorValue = cmap; - goto PatchUp; - } - if (pCmap->pVisual->vid != wVisual (pWin) || - pCmap->pScreen != pScreen) - { - error = BadMatch; - goto PatchUp; - } - if (cmap != wColormap (pWin)) - { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && cmap == wColormap (pWin->parent)) - checkOptional = TRUE; - - /* - * propagate the original colormap to any children - * inheriting it - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pWin->optional->colormap = cmap; - - /* - * check on any children now matching the new colormap - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional->colormap == cmap) - CheckWindowOptionalNeed (pChild); - } - - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pWin->drawable.id; - xE.u.colormap.colormap = cmap; - xE.u.colormap.new = xTrue; - xE.u.colormap.state = IsMapInstalled(cmap, pWin); - DeliverEvents(pWin, &xE, 1, NullWindow); - } - break; - case CWCursor: - cursorID = (Cursor ) *pVlist; - pVlist++; - /* - * install the new - */ - if ( cursorID == None) - { - if (pWin == WindowTable[pWin->drawable.pScreen->myNum]) - pCursor = rootCursor; - else - pCursor = (CursorPtr) None; - } - else - { - pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID, - RT_CURSOR, SecurityReadAccess); - if (!pCursor) - { - error = BadCursor; - client->errorValue = cursorID; - goto PatchUp; - } - } - - if (pCursor != wCursor (pWin)) - { - /* - * patch up child windows so they don't lose cursors. - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !pChild->cursorIsNone && - !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pOldCursor = 0; - if (pCursor == (CursorPtr) None) - { - pWin->cursorIsNone = TRUE; - if (pWin->optional) - { - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = (CursorPtr) None; - checkOptional = TRUE; - } - } else { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && pCursor == wCursor (pWin->parent)) - checkOptional = TRUE; - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = pCursor; - pCursor->refcnt++; - pWin->cursorIsNone = FALSE; - /* - * check on any children now matching the new cursor - */ - - for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional && - (pChild->optional->cursor == pCursor)) - CheckWindowOptionalNeed (pChild); - } - } - - if (pWin->realized) - WindowHasNewCursor( pWin); - - /* Can't free cursor until here - old cursor - * is needed in WindowHasNewCursor - */ - if (pOldCursor) - FreeCursor (pOldCursor, (Cursor)0); - } - break; - default: - error = BadValue; - client->errorValue = vmask; - goto PatchUp; - } - vmaskCopy |= index2; - } -PatchUp: - if (checkOptional) - CheckWindowOptionalNeed (pWin); - - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy); - - /* - If the border contents have changed, redraw the border. - Note that this has to be done AFTER pScreen->ChangeWindowAttributes - for the tile to be rotated, and the correct function selected. - */ - if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative) - && pWin->viewable && HasBorder (pWin)) - { - RegionRec exposed; - - REGION_NULL(pScreen, &exposed); - REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize); - (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER); - REGION_UNINIT(pScreen, &exposed); - } - return error; -} - - -/***** - * GetWindowAttributes - * Notice that this is different than ChangeWindowAttributes - *****/ - -void -GetWindowAttributes(register WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply *wa) -{ - wa->type = X_Reply; - wa->bitGravity = pWin->bitGravity; - wa->winGravity = pWin->winGravity; - if (pWin->forcedBS && pWin->backingStore != Always) - wa->backingStore = NotUseful; - else - wa->backingStore = pWin->backingStore; - wa->length = (sizeof(xGetWindowAttributesReply) - - sizeof(xGenericReply)) >> 2; - wa->sequenceNumber = client->sequence; - wa->backingBitPlanes = wBackingBitPlanes (pWin); - wa->backingPixel = wBackingPixel (pWin); - wa->saveUnder = (BOOL)pWin->saveUnder; - wa->override = pWin->overrideRedirect; - if (!pWin->mapped) - wa->mapState = IsUnmapped; - else if (pWin->realized) - wa->mapState = IsViewable; - else - wa->mapState = IsUnviewable; - - wa->colormap = wColormap (pWin); - wa->mapInstalled = (wa->colormap == None) ? xFalse - : IsMapInstalled(wa->colormap, pWin); - - wa->yourEventMask = EventMaskForClient(pWin, client); - wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin); - wa->doNotPropagateMask = wDontPropagateMask (pWin); - wa->class = pWin->drawable.class; - wa->visualID = wVisual (pWin); -} - - -WindowPtr -MoveWindowInStack(register WindowPtr pWin, register WindowPtr pNextSib) -{ - register WindowPtr pParent = pWin->parent; - WindowPtr pFirstChange = pWin; /* highest window where list changes */ - - if (pWin->nextSib != pNextSib) - { - WindowPtr pOldNextSib = pWin->nextSib; - - if (!pNextSib) /* move to bottom */ - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL - * and pWin->nextSib != pNextSib - * therefore pWin->nextSib != NULL */ - pFirstChange = pWin->nextSib; - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pParent->lastChild->nextSib = pWin; - pWin->prevSib = pParent->lastChild; - pWin->nextSib = NullWindow; - pParent->lastChild = pWin; - } - else if (pParent->firstChild == pNextSib) /* move to top */ - { - pFirstChange = pWin; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pParent->firstChild; - pWin->prevSib = (WindowPtr ) NULL; - pNextSib->prevSib = pWin; - pParent->firstChild = pWin; - } - else /* move in middle of list */ - { - WindowPtr pOldNext = pWin->nextSib; - - pFirstChange = NullWindow; - if (pParent->firstChild == pWin) - pFirstChange = pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) { - pFirstChange = pWin; - pParent->lastChild = pWin->prevSib; - } - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pNextSib; - pWin->prevSib = pNextSib->prevSib; - if (pNextSib->prevSib) - pNextSib->prevSib->nextSib = pWin; - pNextSib->prevSib = pWin; - if (!pFirstChange) { /* do we know it yet? */ - pFirstChange = pParent->firstChild; /* no, search from top */ - while ((pFirstChange != pWin) && (pFirstChange != pOldNext)) - pFirstChange = pFirstChange->nextSib; - } - } - if(pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib); - } - -#ifdef ROOTLESS - /* - * In rootless mode we can't optimize away window restacks. - * There may be non-X windows around, so even if the window - * is in the correct position from X's point of view, - * the underlying window system may want to reorder it. - */ - else if (pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pWin->nextSib); -#endif - - return( pFirstChange ); -} - -RegionPtr -CreateUnclippedWinSize (register WindowPtr pWin) -{ - RegionPtr pRgn; - BoxRec box; - - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + (int) pWin->drawable.width; - box.y2 = pWin->drawable.y + (int) pWin->drawable.height; - pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { - ScreenPtr pScreen = pWin->drawable.pScreen; - - REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y); - } -#endif - return pRgn; -} - -void -SetWinSize (register WindowPtr pWin) -{ -#ifdef COMPOSITE - if (pWin->redirectDraw) - { - BoxRec box; - - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + pWin->drawable.width; - box.y2 = pWin->drawable.y + pWin->drawable.height; - REGION_RESET (pScreen, &pWin->winSize, &box); - } - else -#endif - ClippedRegionFromBox(pWin->parent, &pWin->winSize, - pWin->drawable.x, pWin->drawable.y, - (int)pWin->drawable.width, - (int)pWin->drawable.height); -#ifdef SHAPE - if (wBoundingShape (pWin) || wClipShape (pWin)) { - ScreenPtr pScreen = pWin->drawable.pScreen; - - REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wBoundingShape (pWin)); - if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, - wClipShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x, - pWin->drawable.y); - } -#endif -} - -void -SetBorderSize (register WindowPtr pWin) -{ - int bw; - - if (HasBorder (pWin)) { - bw = wBorderWidth (pWin); -#ifdef COMPOSITE - if (pWin->redirectDraw) - { - BoxRec box; - - box.x1 = pWin->drawable.x - bw; - box.y1 = pWin->drawable.y - bw; - box.x2 = pWin->drawable.x + pWin->drawable.width + bw; - box.y2 = pWin->drawable.y + pWin->drawable.height + bw; - REGION_RESET (pScreen, &pWin->borderSize, &box); - } - else -#endif - ClippedRegionFromBox(pWin->parent, &pWin->borderSize, - pWin->drawable.x - bw, pWin->drawable.y - bw, - (int)(pWin->drawable.width + (bw<<1)), - (int)(pWin->drawable.height + (bw<<1))); -#ifdef SHAPE - if (wBoundingShape (pWin)) { - ScreenPtr pScreen = pWin->drawable.pScreen; - - REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x, - - pWin->drawable.y); - REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize, - wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x, - pWin->drawable.y); - REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize, - &pWin->winSize); - } -#endif - } else { - REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize, - &pWin->winSize); - } -} - -/** - * - * \param x,y new window position - * \param oldx,oldy old window position - * \param destx,desty position relative to gravity - */ - -void -GravityTranslate (register int x, register int y, int oldx, int oldy, - int dw, int dh, unsigned gravity, - register int *destx, register int *desty) -{ - switch (gravity) { - case NorthGravity: - *destx = x + dw / 2; - *desty = y; - break; - case NorthEastGravity: - *destx = x + dw; - *desty = y; - break; - case WestGravity: - *destx = x; - *desty = y + dh / 2; - break; - case CenterGravity: - *destx = x + dw / 2; - *desty = y + dh / 2; - break; - case EastGravity: - *destx = x + dw; - *desty = y + dh / 2; - break; - case SouthWestGravity: - *destx = x; - *desty = y + dh; - break; - case SouthGravity: - *destx = x + dw / 2; - *desty = y + dh; - break; - case SouthEastGravity: - *destx = x + dw; - *desty = y + dh; - break; - case StaticGravity: - *destx = oldx; - *desty = oldy; - break; - default: - *destx = x; - *desty = y; - break; - } -} - -/* XXX need to retile border on each window with ParentRelative origin */ -void -ResizeChildrenWinSize(register WindowPtr pWin, int dx, int dy, int dw, int dh) -{ - register ScreenPtr pScreen; - register WindowPtr pSib, pChild; - Bool resized = (dw || dh); - - pScreen = pWin->drawable.pScreen; - - for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) - { - if (resized && (pSib->winGravity > NorthWestGravity)) - { - int cwsx, cwsy; - - cwsx = pSib->origin.x; - cwsy = pSib->origin.y; - GravityTranslate (cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh, - pSib->winGravity, &cwsx, &cwsy); - if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) - { - xEvent event; - - event.u.u.type = GravityNotify; - event.u.gravity.window = pSib->drawable.id; - event.u.gravity.x = cwsx - wBorderWidth (pSib); - event.u.gravity.y = cwsy - wBorderWidth (pSib); - DeliverEvents (pSib, &event, 1, NullWindow); - pSib->origin.x = cwsx; - pSib->origin.y = cwsy; - } - } - pSib->drawable.x = pWin->drawable.x + pSib->origin.x; - pSib->drawable.y = pWin->drawable.y + pSib->origin.y; - SetWinSize (pSib); - SetBorderSize (pSib); - (*pScreen->PositionWindow)(pSib, pSib->drawable.x, pSib->drawable.y); - - if ( (pChild = pSib->firstChild) ) - { - while (1) - { - pChild->drawable.x = pChild->parent->drawable.x + - pChild->origin.x; - pChild->drawable.y = pChild->parent->drawable.y + - pChild->origin.y; - SetWinSize (pChild); - SetBorderSize (pChild); - (*pScreen->PositionWindow)(pChild, - pChild->drawable.x, pChild->drawable.y); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pSib)) - pChild = pChild->parent; - if (pChild == pSib) - break; - pChild = pChild->nextSib; - } - } - } -} - -#define GET_INT16(m, f) \ - if (m & mask) \ - { \ - f = (INT16) *pVlist;\ - pVlist++; \ - } -#define GET_CARD16(m, f) \ - if (m & mask) \ - { \ - f = (CARD16) *pVlist;\ - pVlist++;\ - } - -#define GET_CARD8(m, f) \ - if (m & mask) \ - { \ - f = (CARD8) *pVlist;\ - pVlist++;\ - } - -#define ChangeMask ((Mask)(CWX | CWY | CWWidth | CWHeight)) - -#define IllegalInputOnlyConfigureMask (CWBorderWidth) - -/* - * IsSiblingAboveMe - * returns Above if pSib above pMe in stack or Below otherwise - */ - -static int -IsSiblingAboveMe( - register WindowPtr pMe, - register WindowPtr pSib) -{ - register WindowPtr pWin; - - pWin = pMe->parent->firstChild; - while (pWin) - { - if (pWin == pSib) - return(Above); - else if (pWin == pMe) - return(Below); - pWin = pWin->nextSib; - } - return(Below); -} - -static BoxPtr -WindowExtents( - register WindowPtr pWin, - register BoxPtr pBox) -{ - pBox->x1 = pWin->drawable.x - wBorderWidth (pWin); - pBox->y1 = pWin->drawable.y - wBorderWidth (pWin); - pBox->x2 = pWin->drawable.x + (int)pWin->drawable.width - + wBorderWidth (pWin); - pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height - + wBorderWidth (pWin); - return(pBox); -} - -#ifdef SHAPE -#define IS_SHAPED(pWin) (wBoundingShape (pWin) != (RegionPtr) NULL) - -static RegionPtr -MakeBoundingRegion ( - register WindowPtr pWin, - BoxPtr pBox) -{ - RegionPtr pRgn; - ScreenPtr pScreen = pWin->drawable.pScreen; - - pRgn = REGION_CREATE(pScreen, pBox, 1); - if (wBoundingShape (pWin)) { - REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x, - -pWin->origin.y); - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x, - pWin->origin.y); - } - return pRgn; -} - -static Bool -ShapeOverlap ( - WindowPtr pWin, - BoxPtr pWinBox, - WindowPtr pSib, - BoxPtr pSibBox) -{ - RegionPtr pWinRgn, pSibRgn; - register ScreenPtr pScreen; - Bool ret; - - if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib)) - return TRUE; - pScreen = pWin->drawable.pScreen; - pWinRgn = MakeBoundingRegion (pWin, pWinBox); - pSibRgn = MakeBoundingRegion (pSib, pSibBox); - REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn); - ret = REGION_NOTEMPTY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pSibRgn); - return ret; -} -#endif - -static Bool -AnyWindowOverlapsMe( - WindowPtr pWin, - WindowPtr pHead, - register BoxPtr box) -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -static Bool -IOverlapAnyWindow( - WindowPtr pWin, - register BoxPtr box) -{ - register WindowPtr pSib; - BoxRec sboxrec; - register BoxPtr sbox; - - for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) -#ifdef SHAPE - && ShapeOverlap (pWin, box, pSib, sbox) -#endif - ) - return(TRUE); - } - } - return(FALSE); -} - -/* - * WhereDoIGoInTheStack() - * Given pWin and pSib and the relationshipe smode, return - * the window that pWin should go ABOVE. - * If a pSib is specified: - * Above: pWin is placed just above pSib - * Below: pWin is placed just below pSib - * TopIf: if pSib occludes pWin, then pWin is placed - * at the top of the stack - * BottomIf: if pWin occludes pSib, then pWin is - * placed at the bottom of the stack - * Opposite: if pSib occludes pWin, then pWin is placed at the - * top of the stack, else if pWin occludes pSib, then - * pWin is placed at the bottom of the stack - * - * If pSib is NULL: - * Above: pWin is placed at the top of the stack - * Below: pWin is placed at the bottom of the stack - * TopIf: if any sibling occludes pWin, then pWin is placed at - * the top of the stack - * BottomIf: if pWin occludes any sibline, then pWin is placed at - * the bottom of the stack - * Opposite: if any sibling occludes pWin, then pWin is placed at - * the top of the stack, else if pWin occludes any - * sibling, then pWin is placed at the bottom of the stack - * - */ - -static WindowPtr -WhereDoIGoInTheStack( - register WindowPtr pWin, - register WindowPtr pSib, - short x, - short y, - unsigned short w, - unsigned short h, - int smode) -{ - BoxRec box; - register ScreenPtr pScreen; - WindowPtr pHead, pFirst; - - if ((pWin == pWin->parent->firstChild) && - (pWin == pWin->parent->lastChild)) - return((WindowPtr ) NULL); - pHead = RealChildHead(pWin->parent); - pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild; - pScreen = pWin->drawable.pScreen; - box.x1 = x; - box.y1 = y; - box.x2 = x + (int)w; - box.y2 = y + (int)h; - switch (smode) - { - case Above: - if (pSib) - return(pSib); - else if (pWin == pFirst) - return(pWin->nextSib); - else - return(pFirst); - case Below: - if (pSib) - if (pSib->nextSib != pWin) - return(pSib->nextSib); - else - return(pWin->nextSib); - else - return NullWindow; - case TopIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Above) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return(pFirst); - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - return(pFirst); - else - return(pWin->nextSib); - case BottomIf: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Below) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return NullWindow; - else - return(pWin->nextSib); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return(pWin->nextSib); - case Opposite: - if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs) - return(pWin->nextSib); - else if (pSib) - { - if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT) - { - if (IsSiblingAboveMe(pWin, pSib) == Above) - return(pFirst); - else - return NullWindow; - } - else - return(pWin->nextSib); - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - { - /* If I'm occluded, I can't possibly be the first child - * if (pWin == pWin->parent->firstChild) - * return pWin->nextSib; - */ - return(pFirst); - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return pWin->nextSib; - default: - { - ErrorF("Internal error in ConfigureWindow, smode == %d\n",smode ); - return pWin->nextSib; - } - } -} - -static void -ReflectStackChange( - register WindowPtr pWin, - register WindowPtr pSib, - VTKind kind) -{ -/* Note that pSib might be NULL */ - - Bool WasViewable = (Bool)pWin->viewable; - Bool anyMarked; - WindowPtr pFirstChange; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - ScreenPtr pScreen = pWin->drawable.pScreen; - - /* if this is a root window, can't be restacked */ - if (!pWin->parent) - return; - - pFirstChange = MoveWindowInStack(pWin, pSib); - - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - &pLayerWin); - if (pLayerWin != pWin) pFirstChange = pLayerWin; -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, kind); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pWin->drawable.pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, kind); - } - if (pWin->realized) - WindowsRestructured (); -} - -/***** - * ConfigureWindow - *****/ - -int -ConfigureWindow(register WindowPtr pWin, register Mask mask, XID *vlist, ClientPtr client) -{ -#define RESTACK_WIN 0 -#define MOVE_WIN 1 -#define RESIZE_WIN 2 -#define REBORDER_WIN 3 - register WindowPtr pSib = NullWindow; - register WindowPtr pParent = pWin->parent; - Window sibwid = 0; - Mask index2, tmask; - register XID *pVlist; - short x, y, beforeX, beforeY; - unsigned short w = pWin->drawable.width, - h = pWin->drawable.height, - bw = pWin->borderWidth; - int action, smode = Above; -#ifdef XAPPGROUP - ClientPtr win_owner; - ClientPtr ag_leader = NULL; -#endif - xEvent event; - - if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask)) - return(BadMatch); - - if ((mask & CWSibling) && !(mask & CWStackMode)) - return(BadMatch); - - pVlist = vlist; - - if (pParent) - { - x = pWin->drawable.x - pParent->drawable.x - (int)bw; - y = pWin->drawable.y - pParent->drawable.y - (int)bw; - } - else - { - x = pWin->drawable.x; - y = pWin->drawable.y; - } - beforeX = x; - beforeY = y; - action = RESTACK_WIN; - if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - action = MOVE_WIN; - } - /* or should be resized */ - else if (mask & (CWX | CWY | CWWidth | CWHeight)) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - GET_CARD16(CWWidth, w); - GET_CARD16 (CWHeight, h); - if (!w || !h) - { - client->errorValue = 0; - return BadValue; - } - action = RESIZE_WIN; - } - tmask = mask & ~ChangeMask; - while (tmask) - { - index2 = (Mask)lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBorderWidth: - GET_CARD16(CWBorderWidth, bw); - break; - case CWSibling: - sibwid = (Window ) *pVlist; - pVlist++; - pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid, - RT_WINDOW, SecurityReadAccess); - if (!pSib) - { - client->errorValue = sibwid; - return(BadWindow); - } - if (pSib->parent != pParent) - return(BadMatch); - if (pSib == pWin) - return(BadMatch); - break; - case CWStackMode: - GET_CARD8(CWStackMode, smode); - if ((smode != TopIf) && (smode != BottomIf) && - (smode != Opposite) && (smode != Above) && (smode != Below)) - { - client->errorValue = smode; - return(BadValue); - } - break; - default: - client->errorValue = mask; - return(BadValue); - } - } - /* root really can't be reconfigured, so just return */ - if (!pParent) - return Success; - - /* Figure out if the window should be moved. Doesnt - make the changes to the window if event sent */ - - if (mask & CWStackMode) - pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x, - pParent->drawable.y + y, - w + (bw << 1), h + (bw << 1), smode); - else - pSib = pWin->nextSib; - -#ifdef XAPPGROUP - win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = ConfigureRequest; - event.u.configureRequest.window = pWin->drawable.id; - if (mask & CWSibling) - event.u.configureRequest.sibling = sibwid; - else - event.u.configureRequest.sibling = None; - if (mask & CWStackMode) - event.u.u.detail = smode; - else - event.u.u.detail = Above; - event.u.configureRequest.x = x; - event.u.configureRequest.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureRequest.x += panoramiXdataPtr[0].x; - event.u.configureRequest.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureRequest.width = w; - event.u.configureRequest.height = h; - event.u.configureRequest.borderWidth = bw; - event.u.configureRequest.valueMask = mask; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.configureRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.configureRequest.parent = pParent->drawable.id; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - if (action == RESIZE_WIN) - { - Bool size_change = (w != pWin->drawable.width) - || (h != pWin->drawable.height); - if (size_change && ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask)) - { - xEvent eventT; - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = w; - eventT.u.resizeRequest.height = h; - if (MaybeDeliverEventsToClient(pWin, &eventT, 1, - ResizeRedirectMask, client) == 1) - { - /* if event is delivered, leave the actual size alone. */ - w = pWin->drawable.width; - h = pWin->drawable.height; - size_change = FALSE; - } - } - if (!size_change) - { - if (mask & (CWX | CWY)) - action = MOVE_WIN; - else if (mask & (CWStackMode | CWBorderWidth)) - action = RESTACK_WIN; - else /* really nothing to do */ - return(Success) ; - } - } - - if (action == RESIZE_WIN) - /* we've already checked whether there's really a size change */ - goto ActuallyDoSomething; - if ((mask & CWX) && (x != beforeX)) - goto ActuallyDoSomething; - if ((mask & CWY) && (y != beforeY)) - goto ActuallyDoSomething; - if ((mask & CWBorderWidth) && (bw != wBorderWidth (pWin))) - goto ActuallyDoSomething; - if (mask & CWStackMode) - { -#ifndef ROOTLESS - /* See above for why we always reorder in rootless mode. */ - if (pWin->nextSib != pSib) -#endif - goto ActuallyDoSomething; - } - return(Success); - -ActuallyDoSomething: - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - if (pSib) - event.u.configureNotify.aboveSibling = pSib->drawable.id; - else - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = x; - event.u.configureNotify.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureNotify.x += panoramiXdataPtr[0].x; - event.u.configureNotify.y += panoramiXdataPtr[0].y; - } -#endif - event.u.configureNotify.width = w; - event.u.configureNotify.height = h; - event.u.configureNotify.borderWidth = bw; - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (mask & CWBorderWidth) - { - if (action == RESTACK_WIN) - { - action = MOVE_WIN; - pWin->borderWidth = bw; - } - else if ((action == MOVE_WIN) && - (beforeX + wBorderWidth (pWin) == x + (int)bw) && - (beforeY + wBorderWidth (pWin) == y + (int)bw)) - { - action = REBORDER_WIN; - (*pWin->drawable.pScreen->ChangeBorderWidth)(pWin, bw); - } - else - pWin->borderWidth = bw; - } - if (action == MOVE_WIN) - (*pWin->drawable.pScreen->MoveWindow)(pWin, x, y, pSib, - (mask & CWBorderWidth) ? VTOther : VTMove); - else if (action == RESIZE_WIN) - (*pWin->drawable.pScreen->ResizeWindow)(pWin, x, y, w, h, pSib); - else if (mask & CWStackMode) - ReflectStackChange(pWin, pSib, VTOther); - - if (action != RESTACK_WIN) - CheckCursorConfinement(pWin); - return(Success); -#undef RESTACK_WIN -#undef MOVE_WIN -#undef RESIZE_WIN -#undef REBORDER_WIN -} - - -/****** - * - * CirculateWindow - * For RaiseLowest, raises the lowest mapped child (if any) that is - * obscured by another child to the top of the stack. For LowerHighest, - * lowers the highest mapped child (if any) that is obscuring another - * child to the bottom of the stack. Exposure processing is performed - * - ******/ - -int -CirculateWindow(WindowPtr pParent, int direction, ClientPtr client) -{ - register WindowPtr pWin, pHead, pFirst; - xEvent event; - BoxRec box; - - pHead = RealChildHead(pParent); - pFirst = pHead ? pHead->nextSib : pParent->firstChild; - if (direction == RaiseLowest) - { - for (pWin = pParent->lastChild; - (pWin != pHead) && - !(pWin->mapped && - AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box))); - pWin = pWin->prevSib) ; - if (pWin == pHead) - return Success; - } - else - { - for (pWin = pFirst; - pWin && - !(pWin->mapped && - IOverlapAnyWindow(pWin, WindowExtents(pWin, &box))); - pWin = pWin->nextSib) ; - if (!pWin) - return Success; - } - - event.u.circulate.window = pWin->drawable.id; - event.u.circulate.parent = pParent->drawable.id; - event.u.circulate.event = pParent->drawable.id; - if (direction == RaiseLowest) - event.u.circulate.place = PlaceOnTop; - else - event.u.circulate.place = PlaceOnBottom; - - if (RedirectSend(pParent)) - { - event.u.u.type = CirculateRequest; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - event.u.u.type = CirculateNotify; - DeliverEvents(pWin, &event, 1, NullWindow); - ReflectStackChange(pWin, - (direction == RaiseLowest) ? pFirst : NullWindow, - VTStack); - - return(Success); -} - -static int -CompareWIDs( - WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - Window *wid = (Window *)value; - - if (pWin->drawable.id == *wid) - return(WT_STOPWALKING); - else - return(WT_WALKCHILDREN); -} - -/***** - * ReparentWindow - *****/ - -int -ReparentWindow(register WindowPtr pWin, register WindowPtr pParent, - int x, int y, ClientPtr client) -{ - WindowPtr pPrev, pPriorParent; - Bool WasMapped = (Bool)(pWin->mapped); - xEvent event; - int bw = wBorderWidth (pWin); - register ScreenPtr pScreen; - - pScreen = pWin->drawable.pScreen; - if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING) - return(BadMatch); - if (!MakeWindowOptional(pWin)) - return(BadAlloc); - - if (WasMapped) - UnmapWindow(pWin, FALSE); - - event.u.u.type = ReparentNotify; - event.u.reparent.window = pWin->drawable.id; - event.u.reparent.parent = pParent->drawable.id; - event.u.reparent.x = x; - event.u.reparent.y = y; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pParent->parent) { - event.u.reparent.x += panoramiXdataPtr[0].x; - event.u.reparent.y += panoramiXdataPtr[0].y; - } -#endif - event.u.reparent.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, pParent); - - /* take out of sibling chain */ - - pPriorParent = pPrev = pWin->parent; - if (pPrev->firstChild == pWin) - pPrev->firstChild = pWin->nextSib; - if (pPrev->lastChild == pWin) - pPrev->lastChild = pWin->prevSib; - - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - - /* insert at begining of pParent */ - pWin->parent = pParent; - pPrev = RealChildHead(pParent); - if (pPrev) - { - pWin->nextSib = pPrev->nextSib; - if (pPrev->nextSib) - pPrev->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pPrev->nextSib = pWin; - pWin->prevSib = pPrev; - } - else - { - pWin->nextSib = pParent->firstChild; - pWin->prevSib = NullWindow; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; - } - - pWin->origin.x = x + bw; - pWin->origin.y = y + bw; - pWin->drawable.x = x + bw + pParent->drawable.x; - pWin->drawable.y = y + bw + pParent->drawable.y; - - /* clip to parent */ - SetWinSize (pWin); - SetBorderSize (pWin); - - if (pScreen->ReparentWindow) - (*pScreen->ReparentWindow)(pWin, pPriorParent); - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); - ResizeChildrenWinSize(pWin, 0, 0, 0, 0); - - CheckWindowOptionalNeed(pWin); - - if (WasMapped) - MapWindow(pWin, client); - RecalculateDeliverableEvents(pWin); - return(Success); -} - -static void -RealizeTree(WindowPtr pWin) -{ - register WindowPtr pChild; - RealizeWindowProcPtr Realize; - - Realize = pWin->drawable.pScreen->RealizeWindow; - pChild = pWin; - while (1) - { - if (pChild->mapped) - { - pChild->realized = TRUE; -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable++; -#endif - pChild->viewable = (pChild->drawable.class == InputOutput); - (* Realize)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * MapWindow - * If some other client has selected SubStructureReDirect on the parent - * and override-redirect is xFalse, then a MapRequest event is generated, - * but the window remains unmapped. Otherwise, the window is mapped and a - * MapNotify event is generated. - *****/ - -int -MapWindow(register WindowPtr pWin, ClientPtr client) -{ - register ScreenPtr pScreen; - - register WindowPtr pParent; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - if (pWin->mapped) - return(Success); - -#ifdef XCSECURITY - /* don't let an untrusted client map a child-of-trusted-window, InputOnly - * window; too easy to steal device input - */ - if ( (client->trustLevel != XSecurityClientTrusted) && - (pWin->drawable.class == InputOnly) && - (wClient(pWin->parent)->trustLevel == XSecurityClientTrusted) ) - return Success; -#endif - - pScreen = pWin->drawable.pScreen; - if ( (pParent = pWin->parent) ) - { - xEvent event; - Bool anyMarked; -#ifdef XAPPGROUP - ClientPtr win_owner = clients[CLIENT_ID(pWin->drawable.id)]; - ClientPtr ag_leader = XagLeader (win_owner); -#endif - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) -#ifdef XAPPGROUP - || (win_owner->appgroup && ag_leader && - XagIsControlledRoot (client, pParent)) -#endif - )) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; -#ifdef XAPPGROUP - /* make sure if the ag_leader maps the window it goes to the wm */ - if (ag_leader && ag_leader != client && - XagIsControlledRoot (client, pParent)) { - event.u.mapRequest.parent = XagId (win_owner); - (void) TryClientEvents (ag_leader, &event, 1, - NoEventMask, NoEventMask, NullGrab); - return Success; - } -#endif - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return(Success); - } - - pWin->mapped = TRUE; - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pParent->realized) - return(Success); - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - } - WindowsRestructured (); - } - else - { - RegionRec temp; - - pWin->mapped = TRUE; - pWin->realized = TRUE; /* for roots */ - pWin->viewable = pWin->drawable.class == InputOutput; - /* We SHOULD check for an error value here XXX */ - (*pScreen->RealizeWindow)(pWin); - if (pScreen->ClipNotify) - (*pScreen->ClipNotify) (pWin, 0, 0); - if (pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap); - REGION_NULL(pScreen, &temp); - REGION_COPY(pScreen, &temp, &pWin->clipList); - (*pScreen->WindowExposures) (pWin, &temp, NullRegion); - REGION_UNINIT(pScreen, &temp); - } - - return(Success); -} - - -/***** - * MapSubwindows - * Performs a MapWindow all unmapped children of the window, in top - * to bottom stacking order. - *****/ - -void -MapSubwindows(register WindowPtr pParent, ClientPtr client) -{ - register WindowPtr pWin; - WindowPtr pFirstMapped = NullWindow; -#ifdef DO_SAVE_UNDERS - WindowPtr pFirstSaveUndered = NullWindow; -#endif - register ScreenPtr pScreen; - register Mask parentRedirect; - register Mask parentNotify; - xEvent event; - Bool anyMarked; -#ifdef DO_SAVE_UNDERS - Bool dosave = FALSE; -#endif - WindowPtr pLayerWin; - - pScreen = pParent->drawable.pScreen; - parentRedirect = RedirectSend(pParent); - parentNotify = SubSend(pParent); - anyMarked = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (!pWin->mapped) - { - if (parentRedirect && !pWin->overrideRedirect) - { - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - continue; - } - - pWin->mapped = TRUE; - if (parentNotify || StrSend(pWin)) - { - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pFirstMapped) - pFirstMapped = pWin; - if (pParent->realized) - { - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - dosave = TRUE; - } -#endif /* DO_SAVE_UNDERS */ - } - } - } - } - - if (pFirstMapped) - { - pLayerWin = (*pScreen->GetLayerWindow)(pParent); - if (pLayerWin->parent != pParent) { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pLayerWin, - pLayerWin, - (WindowPtr *)NULL); - pFirstMapped = pLayerWin; - } - if (anyMarked) - { -#ifdef DO_SAVE_UNDERS - if (pLayerWin->parent != pParent) - { - if (dosave || (DO_SAVE_UNDERS(pLayerWin))) - { - dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, - pLayerWin); - } - } - else if (dosave) - { - dosave = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (DO_SAVE_UNDERS(pWin)) - { - dosave |= (*pScreen->ChangeSaveUnder)(pWin, - pWin->nextSib); - if (dosave && !pFirstSaveUndered) - pFirstSaveUndered = pWin; - } - } - } -#endif /* DO_SAVE_UNDERS */ - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstMapped, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (dosave) - (*pScreen->PostChangeSaveUnder)(pLayerWin, - pFirstSaveUndered->nextSib); -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstMapped, - VTMap); - WindowsRestructured (); - } -} - -static void -UnrealizeTree( - WindowPtr pWin, - Bool fromConfigure) -{ - register WindowPtr pChild; - UnrealizeWindowProcPtr Unrealize; - MarkUnrealizedWindowProcPtr MarkUnrealizedWindow; - - Unrealize = pWin->drawable.pScreen->UnrealizeWindow; - MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow; - pChild = pWin; - while (1) - { - if (pChild->realized) - { - pChild->realized = FALSE; - pChild->visibility = VisibilityNotViewable; -#ifdef PANORAMIX - if(!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { - PanoramiXRes *win; - win = (PanoramiXRes*)LookupIDByType(pChild->drawable.id, - XRT_WINDOW); - if(win) - win->u.win.visibility = VisibilityNotViewable; - } -#endif - (* Unrealize)(pChild); - DeleteWindowFromAnyEvents(pChild, FALSE); - if (pChild->viewable) - { -#ifdef DO_SAVE_UNDERS - if (pChild->saveUnder) - deltaSaveUndersViewable--; -#endif - pChild->viewable = FALSE; - if (pChild->backStorage) - (*pChild->drawable.pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - (* MarkUnrealizedWindow)(pChild, pWin, fromConfigure); - pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; - } -} - -/***** - * UnmapWindow - * If the window is already unmapped, this request has no effect. - * Otherwise, the window is unmapped and an UnMapNotify event is - * generated. Cannot unmap a root window. - *****/ - -int -UnmapWindow(register WindowPtr pWin, Bool fromConfigure) -{ - register WindowPtr pParent; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - ScreenPtr pScreen = pWin->drawable.pScreen; - WindowPtr pLayerWin = pWin; - - if ((!pWin->mapped) || (!(pParent = pWin->parent))) - return(Success); - if (SubStrSend(pWin, pParent)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pWin->drawable.id; - event.u.unmapNotify.fromConfigure = fromConfigure; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (wasViewable && !fromConfigure) - { - pWin->valdata = UnmapValData; - (*pScreen->MarkOverlappedWindows)(pWin, pWin->nextSib, &pLayerWin); - (*pScreen->MarkWindow)(pLayerWin->parent); - } - pWin->mapped = FALSE; - if (wasRealized) - UnrealizeTree(pWin, fromConfigure); - if (wasViewable) - { - if (!fromConfigure) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pWin, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib) ) - { - (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib); - } - } - pWin->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (!fromConfigure && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pWin, VTUnmap); - } - if (wasRealized && !fromConfigure) - WindowsRestructured (); - return(Success); -} - -/***** - * UnmapSubwindows - * Performs an UnmapWindow request with the specified mode on all mapped - * children of the window, in bottom to top stacking order. - *****/ - -void -UnmapSubwindows(register WindowPtr pWin) -{ - register WindowPtr pChild, pHead; - xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; - Bool anyMarked = FALSE; - Mask parentNotify; - WindowPtr pLayerWin = NULL; - ScreenPtr pScreen = pWin->drawable.pScreen; - - if (!pWin->firstChild) - return; - parentNotify = SubSend(pWin); - pHead = RealChildHead(pWin); - - if (wasViewable) - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (pChild->mapped) - { - if (parentNotify || StrSend(pChild)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pChild->drawable.id; - event.u.unmapNotify.fromConfigure = xFalse; - DeliverEvents(pChild, &event, 1, NullWindow); - } - if (pChild->viewable) - { - pChild->valdata = UnmapValData; - anyMarked = TRUE; - } - pChild->mapped = FALSE; - if (pChild->realized) - UnrealizeTree(pChild, FALSE); - if (wasViewable) - { -#ifdef DO_SAVE_UNDERS - pChild->DIXsaveUnder = FALSE; -#endif /* DO_SAVE_UNDERS */ - if (pChild->backStorage) - (*pScreen->SaveDoomedAreas)( - pChild, &pChild->clipList, 0, 0); - } - } - } - if (wasViewable) - { - if (anyMarked) - { - if (pLayerWin->parent == pWin) - (*pScreen->MarkWindow)(pWin); - else - { - WindowPtr ptmp; - (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - (*pScreen->MarkWindow)(pLayerWin->parent); - - /* Windows between pWin and pLayerWin may not have been marked */ - ptmp = pWin; - - while (ptmp != pLayerWin->parent) - { - (*pScreen->MarkWindow)(ptmp); - ptmp = ptmp->parent; - } - pHead = pWin->firstChild; - } - (*pScreen->ValidateTree)(pLayerWin->parent, pHead, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } -#ifdef DO_SAVE_UNDERS - if (DO_SAVE_UNDERS(pWin)) - { - if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin)) - (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin); - } -#endif /* DO_SAVE_UNDERS */ - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pHead, VTUnmap); - } - if (wasRealized) - WindowsRestructured (); -} - - -void -HandleSaveSet(register ClientPtr client) -{ - register WindowPtr pParent, pWin; - register int j; - - for (j=0; jnumSaved; j++) - { - pWin = SaveSetWindow(client->saveSet[j]); -#ifdef XFIXES - if (SaveSetToRoot(client->saveSet[j])) - pParent = WindowTable[pWin->drawable.pScreen->myNum]; - else -#endif - { - pParent = pWin->parent; - while (pParent && (wClient (pParent) == client)) - pParent = pParent->parent; - } - if (pParent) - { - if (pParent != pWin->parent) - { - ReparentWindow(pWin, pParent, - pWin->drawable.x - wBorderWidth (pWin) - pParent->drawable.x, - pWin->drawable.y - wBorderWidth (pWin) - pParent->drawable.y, - client); - if(!pWin->realized && pWin->mapped) - pWin->mapped = FALSE; - } -#ifdef XFIXES - if (SaveSetRemap (client->saveSet[j])) -#endif - MapWindow(pWin, client); - } - } - xfree(client->saveSet); - client->numSaved = 0; - client->saveSet = (SaveSetElt *)NULL; -} - -/** - * - * \param x,y in root - * \param box "return" value - */ -Bool -VisibleBoundingBoxFromPoint(register WindowPtr pWin, int x, int y, BoxPtr box) -{ - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->clipList, x, y, box)) - return(TRUE); - return(FALSE); -} - -/** - * - * \param x,y in root - */ -Bool -PointInWindowIsVisible(register WindowPtr pWin, int x, int y) -{ - BoxRec box; - - if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip, - x, y, &box) - && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) - return(TRUE); - return(FALSE); -} - - -RegionPtr -NotClippedByChildren(register WindowPtr pWin) -{ - register ScreenPtr pScreen; - RegionPtr pReg; - - pScreen = pWin->drawable.pScreen; - pReg = REGION_CREATE(pScreen, NullBox, 1); - if (pWin->parent || - screenIsSaved != SCREEN_SAVER_ON || - !HasSaverWindow (pWin->drawable.pScreen->myNum)) - { - REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize); - } - return(pReg); -} - -void -SendVisibilityNotify(WindowPtr pWin) -{ - xEvent event; -#ifndef NO_XINERAMA_PORT - unsigned int visibility = pWin->visibility; -#endif -#ifdef PANORAMIX - /* This is not quite correct yet, but it's close */ - if(!noPanoramiXExtension) { - PanoramiXRes *win; - WindowPtr pWin2; - int i, Scrnum; - - Scrnum = pWin->drawable.pScreen->myNum; - - win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, Scrnum); - - if(!win || (win->u.win.visibility == visibility)) - return; - - switch(visibility) { - case VisibilityUnobscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility == VisibilityPartiallyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - case VisibilityPartiallyObscured: - if(Scrnum) { - pWin2 = (WindowPtr)LookupIDByType(win->info[0].id, RT_WINDOW); - if (pWin2) pWin = pWin2; - } - break; - case VisibilityFullyObscured: - for(i = 0; i < PanoramiXNumScreens; i++) { - if(i == Scrnum) continue; - - pWin2 = (WindowPtr)LookupIDByType(win->info[i].id, RT_WINDOW); - - if (pWin2) { - if(pWin2->visibility != VisibilityFullyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - } - - win->u.win.visibility = visibility; - } -#endif - - event.u.u.type = VisibilityNotify; - event.u.visibility.window = pWin->drawable.id; - event.u.visibility.state = visibility; - DeliverEvents(pWin, &event, 1, NullWindow); -} - - -#define RANDOM_WIDTH 32 - -#ifndef NOLOGOHACK -static void DrawLogo( - WindowPtr pWin -); -#endif - -void -SaveScreens(int on, int mode) -{ - int i; - int what; - int type; - - if (on == SCREEN_SAVER_FORCER) - { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; - if (mode == ScreenSaverReset) - what = SCREEN_SAVER_OFF; - else - what = SCREEN_SAVER_ON; - type = what; - } - else - { - what = on; - type = what; - if (what == screenIsSaved) - type = SCREEN_SAVER_CYCLE; - } - for (i = 0; i < screenInfo.numScreens; i++) - { - if (on == SCREEN_SAVER_FORCER) - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], on); - if (savedScreenInfo[i].ExternalScreenSaver) - { - if ((*savedScreenInfo[i].ExternalScreenSaver) - (screenInfo.screens[i], type, on == SCREEN_SAVER_FORCER)) - continue; - } - if (type == screenIsSaved) - continue; - switch (type) { - case SCREEN_SAVER_OFF: - if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - what); - } - else if (HasSaverWindow (i)) - { - savedScreenInfo[i].pWindow = NullWindow; - FreeResource(savedScreenInfo[i].wid, RT_NONE); - } - break; - case SCREEN_SAVER_CYCLE: - if (savedScreenInfo[i].blanked == SCREEN_IS_TILED) - { - WindowPtr pWin = savedScreenInfo[i].pWindow; - /* make it look like screen saver is off, so that - * NotClippedByChildren will compute a clip list - * for the root window, so miPaintWindow works - */ - screenIsSaved = SCREEN_SAVER_OFF; -#ifndef NOLOGOHACK - if (logoScreenSaver) - (*pWin->drawable.pScreen->ClearToBackground)(pWin, 0, 0, 0, 0, FALSE); -#endif - (*pWin->drawable.pScreen->MoveWindow)(pWin, - (short)(-(rand() % RANDOM_WIDTH)), - (short)(-(rand() % RANDOM_WIDTH)), - pWin->nextSib, VTMove); -#ifndef NOLOGOHACK - if (logoScreenSaver) - DrawLogo(pWin); -#endif - screenIsSaved = SCREEN_SAVER_ON; - } - /* - * Call the DDX saver in case it wants to do something - * at cycle time - */ - else if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) - { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - type); - } - break; - case SCREEN_SAVER_ON: - if (ScreenSaverBlanking != DontPreferBlanking) - { - if ((* screenInfo.screens[i]->SaveScreen) - (screenInfo.screens[i], what)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLANKED; - continue; - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_BLACK)) - { - savedScreenInfo[i].blanked = SCREEN_IS_BLACK; - continue; - } - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_TILED)) - { - savedScreenInfo[i].blanked = SCREEN_IS_TILED; - } - else - savedScreenInfo[i].blanked = SCREEN_ISNT_SAVED; - break; - } - } - screenIsSaved = what; - if (mode == ScreenSaverReset) - SetScreenSaverTimer(); -} - -static Bool -TileScreenSaver(int i, int kind) -{ - int j; - int result; - XID attributes[3]; - Mask mask; - WindowPtr pWin; - CursorMetricRec cm; - unsigned char *srcbits, *mskbits; - CursorPtr cursor; - XID cursorID = 0; - int attri; - - mask = 0; - attri = 0; - switch (kind) { - case SCREEN_IS_TILED: - switch (WindowTable[i]->backgroundState) { - case BackgroundPixel: - attributes[attri++] = WindowTable[i]->background.pixel; - mask |= CWBackPixel; - break; - case BackgroundPixmap: - attributes[attri++] = None; - mask |= CWBackPixmap; - break; - default: - break; - } - break; - case SCREEN_IS_BLACK: - attributes[attri++] = WindowTable[i]->drawable.pScreen->blackPixel; - mask |= CWBackPixel; - break; - } - mask |= CWOverrideRedirect; - attributes[attri++] = xTrue; - - /* - * create a blank cursor - */ - - cm.width=16; - cm.height=16; - cm.xhot=8; - cm.yhot=8; - srcbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - mskbits = (unsigned char *)xalloc( BitmapBytePad(32)*16); - if (!srcbits || !mskbits) - { - xfree(srcbits); - xfree(mskbits); - cursor = 0; - } - else - { - for (j=0; jwidth + RANDOM_WIDTH, - (unsigned short)screenInfo.screens[i]->height + RANDOM_WIDTH, - 0, InputOutput, mask, attributes, 0, serverClient, - wVisual (WindowTable[i]), &result); - - if (cursor) - FreeResource (cursorID, RT_NONE); - - if (!pWin) - return FALSE; - - if (!AddResource(pWin->drawable.id, RT_WINDOW, - (pointer)savedScreenInfo[i].pWindow)) - return FALSE; - - if (mask & CWBackPixmap) - { - MakeRootTile (pWin); - (*pWin->drawable.pScreen->ChangeWindowAttributes)(pWin, CWBackPixmap); - } - MapWindow(pWin, serverClient); -#ifndef NOLOGOHACK - if (kind == SCREEN_IS_TILED && logoScreenSaver) - DrawLogo(pWin); -#endif - return TRUE; -} - -/* - * FindWindowWithOptional - * - * search ancestors of the given window for an entry containing - * a WindowOpt structure. Assumptions: some parent will - * contain the structure. - */ - -WindowPtr -FindWindowWithOptional (register WindowPtr w) -{ - do - w = w->parent; - while (!w->optional); - return w; -} - -/* - * CheckWindowOptionalNeed - * - * check each optional entry in the given window to see if - * the value is satisfied by the default rules. If so, - * release the optional record - */ - -void -CheckWindowOptionalNeed (register WindowPtr w) -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (!w->parent) - return; - optional = w->optional; - if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate]) - return; - if (optional->otherEventMasks != 0) - return; - if (optional->otherClients != NULL) - return; - if (optional->passiveGrabs != NULL) - return; - if (optional->userProps != NULL) - return; - if (optional->backingBitPlanes != ~0L) - return; - if (optional->backingPixel != 0) - return; -#ifdef SHAPE - if (optional->boundingShape != NULL) - return; - if (optional->clipShape != NULL) - return; - if (optional->inputShape != NULL) - return; -#endif -#ifdef XINPUT - if (optional->inputMasks != NULL) - return; -#endif - parentOptional = FindWindowWithOptional(w)->optional; - if (optional->visual != parentOptional->visual) - return; - if (optional->cursor != None && - (optional->cursor != parentOptional->cursor || - w->parent->cursorIsNone)) - return; - if (optional->colormap != parentOptional->colormap) - return; - DisposeWindowOptional (w); -} - -/* - * MakeWindowOptional - * - * create an optional record and initialize it with the default - * values. - */ - -Bool -MakeWindowOptional (register WindowPtr pWin) -{ - register WindowOptPtr optional; - register WindowOptPtr parentOptional; - - if (pWin->optional) - return TRUE; - optional = (WindowOptPtr) xalloc (sizeof (WindowOptRec)); - if (!optional) - return FALSE; - optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; - optional->otherEventMasks = 0; - optional->otherClients = NULL; - optional->passiveGrabs = NULL; - optional->userProps = NULL; - optional->backingBitPlanes = ~0L; - optional->backingPixel = 0; -#ifdef SHAPE - optional->boundingShape = NULL; - optional->clipShape = NULL; - optional->inputShape = NULL; -#endif -#ifdef XINPUT - optional->inputMasks = NULL; -#endif - parentOptional = FindWindowWithOptional(pWin)->optional; - optional->visual = parentOptional->visual; - if (!pWin->cursorIsNone) - { - optional->cursor = parentOptional->cursor; - optional->cursor->refcnt++; - } - else - { - optional->cursor = None; - } - optional->colormap = parentOptional->colormap; - pWin->optional = optional; - return TRUE; -} - -void -DisposeWindowOptional (register WindowPtr pWin) -{ - if (!pWin->optional) - return; - /* - * everything is peachy. Delete the optional record - * and clean up - */ - /* - * TOG changed this code to: - * - * if (pWin->cursorIsNone == FALSE) - * FreeCursor (pWin->optional->cursor, (Cursor)0); - * pWin->cursorIsNone = TRUE; - * - * This is blatently wrong; windows without optionals can have - * two different cursor values, either None or sharing their - * parents cursor. This difference is controlled by the - * cursorIsNone value; when TRUE, the window has no cursor, - * when false, it shares its cursor with its parent; TOG - * made it impossible for a window to have a cursor without - * an optional record. - */ - if (pWin->optional->cursor) - { - FreeCursor (pWin->optional->cursor, (Cursor)0); - pWin->cursorIsNone = FALSE; - } - else - pWin->cursorIsNone = TRUE; - xfree (pWin->optional); - pWin->optional = NULL; -} - -#ifndef NOLOGOHACK -static void -DrawLogo(WindowPtr pWin) -{ - DrawablePtr pDraw; - ScreenPtr pScreen; - int x, y; - unsigned int width, height, size; - GC *pGC; - int thin, gap, d31; - DDXPointRec poly[4]; - ChangeGCVal fore[2], back[2]; - xrgb rgb[2]; - BITS32 fmask, bmask; - ColormapPtr cmap; - - pDraw = (DrawablePtr)pWin; - pScreen = pDraw->pScreen; - x = -pWin->origin.x; - y = -pWin->origin.y; - width = pScreen->width; - height = pScreen->height; - pGC = GetScratchGC(pScreen->rootDepth, pScreen); - if (!pGC) - return; - - if ((rand() % 100) <= 17) /* make the probability for white fairly low */ - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - if ((pWin->backgroundState == BackgroundPixel) && - (cmap = (ColormapPtr)LookupIDByType(wColormap (pWin), RT_COLORMAP))) { - Pixel querypixels[2]; - - querypixels[0] = fore[0].val; - querypixels[1] = pWin->background.pixel; - QueryColors(cmap, 2, querypixels, rgb); - if ((rgb[0].red == rgb[1].red) && - (rgb[0].green == rgb[1].green) && - (rgb[0].blue == rgb[1].blue)) { - if (fore[0].val == pScreen->blackPixel) - fore[0].val = pScreen->whitePixel; - else - fore[0].val = pScreen->blackPixel; - } - } - fore[1].val = FillSolid; - fmask = GCForeground|GCFillStyle; - if (pWin->backgroundState == BackgroundPixel) { - back[0].val = pWin->background.pixel; - back[1].val = FillSolid; - bmask = GCForeground|GCFillStyle; - } else { - back[0].val = 0; - back[1].val = 0; - dixChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin, - NULL, back); - back[0].val = FillTiled; - back[1].ptr = pWin->background.pixmap; - bmask = GCFillStyle|GCTile; - } - - /* should be the same as the reference function XmuDrawLogo() */ - - size = width; - if (height < width) - size = height; - size = RANDOM_WIDTH + rand() % (size - RANDOM_WIDTH); - size &= ~1; - x += rand() % (width - size); - y += rand() % (height - size); - -/* - * Draw what will be the thin strokes. - * - * ----- - * / / - * / / - * / / - * / / - * /____/ - * d - * - * Point d is 9/44 (~1/5) of the way across. - */ - - thin = (size / 11); - if (thin < 1) thin = 1; - gap = (thin+3) / 4; - d31 = thin + thin + gap; - poly[0].x = x + size; poly[0].y = y; - poly[1].x = x + size-d31; poly[1].y = y; - poly[2].x = x + 0; poly[2].y = y + size; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for lower thin stroke. - * - * ------ - * / / - * / __ / - * / / / - * / / / - * /__/__/ - */ - - poly[0].x = x + d31/2; poly[0].y = y + size; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)+(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase area not needed for upper thin stroke. - * - * ------ - * / / / - * /--/ / - * / / - * / / - * /_____/ - */ - - poly[0].x = x + size - d31/2; poly[0].y = y; - poly[1].x = x + size / 2; poly[1].y = y + size/2; - poly[2].x = x + (size/2)-(d31-(d31/2)); poly[2].y = y + size/2; - poly[3].x = x + size - d31; poly[3].y = y; - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Draw thick stroke. - * Point b is 1/4 of the way across. - * - * b - * ----- - * \ \ - * \ \ - * \ \ - * \ \ - * \____\ - */ - - poly[0].x = x; poly[0].y = y; - poly[1].x = x + size/4; poly[1].y = y; - poly[2].x = x + size; poly[2].y = y + size; - poly[3].x = x + size - size/4; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - -/* - * Erase to create gap. - * - * / - * / - * / - * / - * / - */ - - poly[0].x = x + size- thin; poly[0].y = y; - poly[1].x = x + size-( thin+gap); poly[1].y = y; - poly[2].x = x + thin; poly[2].y = y + size; - poly[3].x = x + thin + gap; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); - ValidateGC(pDraw, pGC); - (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); - - FreeScratchGC(pGC); -} - -#endif diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.NX.original deleted file mode 100644 index f6dad312a..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.NX.original +++ /dev/null @@ -1,2286 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NXAGENT, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* $XdotOrg: xc/programs/Xserver/Xext/xvdisp.c,v 1.6 2005/07/03 08:53:36 daniels Exp $ */ -/*********************************************************** -Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts, -and the Massachusetts Institute of Technology, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital or MIT not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $XFree86: xc/programs/Xserver/Xext/xvdisp.c,v 1.27 2003/07/16 01:38:31 dawes Exp $ */ - -/* -** File: -** -** xvdisp.c --- Xv server extension dispatch module. -** -** Author: -** -** David Carver (Digital Workstation Engineering/Project Athena) -** -** Revisions: -** -** 11.06.91 Carver -** - changed SetPortControl to SetPortAttribute -** - changed GetPortControl to GetPortAttribute -** - changed QueryBestSize -** -** 15.05.91 Carver -** - version 2.0 upgrade -** -** 24.01.91 Carver -** - version 1.4 upgrade -** -*/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include "misc.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "dixstruct.h" -#include "resource.h" -#include "opaque.h" - -#include -#include -#include "xvdix.h" -#ifdef MITSHM -#define _XSHM_SERVER_ -#include -#endif - -#include "Trap.h" - -#undef TEST -#undef DEBUG - -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#include "xvdisp.h" - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -unsigned long XvXRTPort; - -#ifdef MITSHM -static int XineramaXvShmPutImage(ClientPtr); -#endif -static int XineramaXvPutImage(ClientPtr); -static int XineramaXvPutVideo(ClientPtr); -static int XineramaXvPutStill(ClientPtr); -static int XineramaXvSetPortAttribute(ClientPtr); -static int XineramaXvStopVideo(ClientPtr); -#endif - -/* INTERNAL */ - -static int ProcXvQueryExtension(ClientPtr); -static int ProcXvQueryAdaptors(ClientPtr); -static int ProcXvQueryEncodings(ClientPtr); -static int ProcXvPutVideo(ClientPtr); -static int ProcXvPutStill(ClientPtr); -static int ProcXvGetVideo(ClientPtr); -static int ProcXvGetStill(ClientPtr); -static int ProcXvGrabPort(ClientPtr); -static int ProcXvUngrabPort(ClientPtr); -static int ProcXvSelectVideoNotify(ClientPtr); -static int ProcXvSelectPortNotify(ClientPtr); -static int ProcXvStopVideo(ClientPtr); -static int ProcXvSetPortAttribute(ClientPtr); -static int ProcXvGetPortAttribute(ClientPtr); -static int ProcXvQueryBestSize(ClientPtr); -static int ProcXvQueryPortAttributes(ClientPtr); -static int ProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int ProcXvShmPutImage(ClientPtr); -#endif -static int ProcXvQueryImageAttributes(ClientPtr); -static int ProcXvListImageFormats(ClientPtr); - -static int SProcXvQueryExtension(ClientPtr); -static int SProcXvQueryAdaptors(ClientPtr); -static int SProcXvQueryEncodings(ClientPtr); -static int SProcXvPutVideo(ClientPtr); -static int SProcXvPutStill(ClientPtr); -static int SProcXvGetVideo(ClientPtr); -static int SProcXvGetStill(ClientPtr); -static int SProcXvGrabPort(ClientPtr); -static int SProcXvUngrabPort(ClientPtr); -static int SProcXvSelectVideoNotify(ClientPtr); -static int SProcXvSelectPortNotify(ClientPtr); -static int SProcXvStopVideo(ClientPtr); -static int SProcXvSetPortAttribute(ClientPtr); -static int SProcXvGetPortAttribute(ClientPtr); -static int SProcXvQueryBestSize(ClientPtr); -static int SProcXvQueryPortAttributes(ClientPtr); -static int SProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int SProcXvShmPutImage(ClientPtr); -#endif -static int SProcXvQueryImageAttributes(ClientPtr); -static int SProcXvListImageFormats(ClientPtr); - -static int SWriteQueryAdaptorsReply(ClientPtr, xvQueryAdaptorsReply *); -static int SWriteQueryExtensionReply(ClientPtr, xvQueryExtensionReply *); -static int SWriteQueryEncodingsReply(ClientPtr, xvQueryEncodingsReply *); -static int SWriteAdaptorInfo(ClientPtr, xvAdaptorInfo *); -static int SWriteEncodingInfo(ClientPtr, xvEncodingInfo *); -static int SWriteFormat(ClientPtr, xvFormat *); -static int SWriteAttributeInfo(ClientPtr, xvAttributeInfo *); -static int SWriteGrabPortReply(ClientPtr, xvGrabPortReply *); -static int SWriteGetPortAttributeReply(ClientPtr, xvGetPortAttributeReply *); -static int SWriteQueryBestSizeReply(ClientPtr, xvQueryBestSizeReply *); -static int SWriteQueryPortAttributesReply( - ClientPtr, xvQueryPortAttributesReply *); -static int SWriteQueryImageAttributesReply( - ClientPtr, xvQueryImageAttributesReply*); -static int SWriteListImageFormatsReply(ClientPtr, xvListImageFormatsReply*); -static int SWriteImageFormatInfo(ClientPtr, xvImageFormatInfo*); - -#define _WriteQueryAdaptorsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryAdaptorsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryAdaptorsReply, (char*)_d) - -#define _WriteQueryExtensionReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryExtensionReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryExtensionReply, (char*)_d) - -#define _WriteQueryEncodingsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryEncodingsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryEncodingsReply, (char*)_d) - -#define _WriteAdaptorInfo(_c,_d) \ - if ((_c)->swapped) SWriteAdaptorInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAdaptorInfo, (char*)_d) - -#define _WriteAttributeInfo(_c,_d) \ - if ((_c)->swapped) SWriteAttributeInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAttributeInfo, (char*)_d) - -#define _WriteEncodingInfo(_c,_d) \ - if ((_c)->swapped) SWriteEncodingInfo(_c, _d); \ - else WriteToClient(_c, sz_xvEncodingInfo, (char*)_d) - -#define _WriteFormat(_c,_d) \ - if ((_c)->swapped) SWriteFormat(_c, _d); \ - else WriteToClient(_c, sz_xvFormat, (char*)_d) - -#define _WriteGrabPortReply(_c,_d) \ - if ((_c)->swapped) SWriteGrabPortReply(_c, _d); \ - else WriteToClient(_c, sz_xvGrabPortReply, (char*)_d) - -#define _WriteGetPortAttributeReply(_c,_d) \ - if ((_c)->swapped) SWriteGetPortAttributeReply(_c, _d); \ - else WriteToClient(_c, sz_xvGetPortAttributeReply, (char*)_d) - -#define _WriteQueryBestSizeReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryBestSizeReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryBestSizeReply,(char*) _d) - -#define _WriteQueryPortAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryPortAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryPortAttributesReply,(char*) _d) - -#define _WriteQueryImageAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryImageAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryImageAttributesReply,(char*) _d) - -#define _WriteListImageFormatsReply(_c,_d) \ - if ((_c)->swapped) SWriteListImageFormatsReply(_c, _d); \ - else WriteToClient(_c, sz_xvListImageFormatsReply,(char*) _d) - -#define _WriteImageFormatInfo(_c,_d) \ - if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \ - else WriteToClient(_c, sz_xvImageFormatInfo, (char*)_d) - -#define _AllocatePort(_i,_p) \ - ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success - -/* -** ProcXvDispatch -** -** -** -*/ - -int -ProcXvDispatch(ClientPtr client) -{ - int result; - - REQUEST(xReq); - - UpdateCurrentTime(); - - /* - * Report upstream that we are - * dispatching a XVideo operation. - */ - - nxagentXvTrap = 1; - - #ifdef TEST - fprintf(stderr, "ProcXvDispatch: Going to dispatch XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - switch (stuff->data) - { - case xv_QueryExtension: result = (ProcXvQueryExtension(client)); break; - case xv_QueryAdaptors: result = (ProcXvQueryAdaptors(client)); break; - case xv_QueryEncodings: result = (ProcXvQueryEncodings(client)); break; - case xv_PutVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvPutVideo(client)); break; - else -#endif - result = (ProcXvPutVideo(client)); break; - case xv_PutStill: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvPutStill(client)); break - else -#endif - result = (ProcXvPutStill(client)); break; - case xv_GetVideo: result = (ProcXvGetVideo(client)); break; - case xv_GetStill: result = (ProcXvGetStill(client)); break; - case xv_GrabPort: result = (ProcXvGrabPort(client)); break; - case xv_UngrabPort: result = (ProcXvUngrabPort(client)); break; - case xv_SelectVideoNotify: result = (ProcXvSelectVideoNotify(client)); break; - case xv_SelectPortNotify: result = (ProcXvSelectPortNotify(client)); break; - case xv_StopVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvStopVideo(client)); break; - else -#endif - result = (ProcXvStopVideo(client)); break; - case xv_SetPortAttribute: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvSetPortAttribute(client)); break; - else -#endif - result = (ProcXvSetPortAttribute(client)); break; - case xv_GetPortAttribute: result = (ProcXvGetPortAttribute(client)); break; - case xv_QueryBestSize: result = (ProcXvQueryBestSize(client)); break; - case xv_QueryPortAttributes: result = (ProcXvQueryPortAttributes(client)); break; - case xv_PutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvPutImage(client)); break; - else -#endif - result = (ProcXvPutImage(client)); break; -#ifdef MITSHM - case xv_ShmPutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - result = (XineramaXvShmPutImage(client)); break; - else -#endif - result = (ProcXvShmPutImage(client)); break; -#endif - case xv_QueryImageAttributes: result = (ProcXvQueryImageAttributes(client)); break; - case xv_ListImageFormats: result = (ProcXvListImageFormats(client)); break; - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - result = (BadImplementation); break; - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - result = (BadRequest); break; - } - } - - nxagentXvTrap = 0; - - #ifdef TEST - fprintf(stderr, "ProcXvDispatch: Dispatched XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - return result; -} - -int -SProcXvDispatch(ClientPtr client) -{ - int result; - - REQUEST(xReq); - - UpdateCurrentTime(); - - /* - * Report upstream that we are - * dispatching a XVideo operation. - */ - - nxagentXvTrap = 1; - - #ifdef TEST - fprintf(stderr, "SProcXvDispatch: Going to dispatch XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - switch (stuff->data) - { - case xv_QueryExtension: result = (SProcXvQueryExtension(client)); break; - case xv_QueryAdaptors: result = (SProcXvQueryAdaptors(client)); break; - case xv_QueryEncodings: result = (SProcXvQueryEncodings(client)); break; - case xv_PutVideo: result = (SProcXvPutVideo(client)); break; - case xv_PutStill: result = (SProcXvPutStill(client)); break; - case xv_GetVideo: result = (SProcXvGetVideo(client)); break; - case xv_GetStill: result = (SProcXvGetStill(client)); break; - case xv_GrabPort: result = (SProcXvGrabPort(client)); break; - case xv_UngrabPort: result = (SProcXvUngrabPort(client)); break; - case xv_SelectVideoNotify: result = (SProcXvSelectVideoNotify(client)); break; - case xv_SelectPortNotify: result = (SProcXvSelectPortNotify(client)); break; - case xv_StopVideo: result = (SProcXvStopVideo(client)); break; - case xv_SetPortAttribute: result = (SProcXvSetPortAttribute(client)); break; - case xv_GetPortAttribute: result = (SProcXvGetPortAttribute(client)); break; - case xv_QueryBestSize: result = (SProcXvQueryBestSize(client)); break; - case xv_QueryPortAttributes: result = (SProcXvQueryPortAttributes(client)); break; - case xv_PutImage: result = (SProcXvPutImage(client)); break; -#ifdef MITSHM - case xv_ShmPutImage: result = (SProcXvShmPutImage(client)); break; -#endif - case xv_QueryImageAttributes: result = (SProcXvQueryImageAttributes(client)); break; - case xv_ListImageFormats: result = (SProcXvListImageFormats(client)); break; - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - result = (BadImplementation); break; - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - result = (BadRequest); break; - } - } - - nxagentXvTrap = 0; - - #ifdef TEST - fprintf(stderr, "ProcXvDispatch: Dispatched XVideo operation [%d] for client [%d].\n", - stuff->data, client -> index); - #endif - - return result; -} - -static int -ProcXvQueryExtension(ClientPtr client) -{ - xvQueryExtensionReply rep; - /* REQUEST(xvQueryExtensionReq); */ - REQUEST_SIZE_MATCH(xvQueryExtensionReq); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.version = XvVersion; - rep.revision = XvRevision; - - _WriteQueryExtensionReply(client, &rep); - - return Success; - -} - -static int -ProcXvQueryAdaptors(ClientPtr client) -{ - xvFormat format; - xvAdaptorInfo ainfo; - xvQueryAdaptorsReply rep; - int totalSize; - int na; - XvAdaptorPtr pa; - int nf; - XvFormatPtr pf; - WindowPtr pWin; - ScreenPtr pScreen; - XvScreenPtr pxvs; - - REQUEST(xvQueryAdaptorsReq); - REQUEST_SIZE_MATCH(xvQueryAdaptorsReq); - - if(!(pWin = (WindowPtr)LookupWindow(stuff->window, client) )) - { - client->errorValue = stuff->window; - return (BadWindow); - } - - pScreen = pWin->drawable.pScreen; - pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - if (!pxvs) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = 0; - rep.length = 0; - - _WriteQueryAdaptorsReply(client, &rep); - - return Success; - } - - (* pxvs->ddQueryAdaptors)(pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = pxvs->nAdaptors; - - /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ - - totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; - - /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - totalSize += (strlen(pa->name) + 3) & ~3; - totalSize += pa->nFormats * sz_xvFormat; - pa++; - } - - rep.length = totalSize >> 2; - - _WriteQueryAdaptorsReply(client, &rep); - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - - ainfo.base_id = pa->base_id; - ainfo.num_ports = pa->nPorts; - ainfo.type = pa->type; - ainfo.name_size = strlen(pa->name); - ainfo.num_formats = pa->nFormats; - - _WriteAdaptorInfo(client, &ainfo); - - WriteToClient(client, ainfo.name_size, pa->name); - - nf = pa->nFormats; - pf = pa->pFormats; - while (nf--) - { - format.depth = pf->depth; - format.visual = pf->visual; - _WriteFormat(client, &format); - pf++; - } - - pa++; - - } - - return (client->noClientException); - -} - -static int -ProcXvQueryEncodings(ClientPtr client) -{ - xvEncodingInfo einfo; - xvQueryEncodingsReply rep; - int totalSize; - XvPortPtr pPort; - int ne; - XvEncodingPtr pe; - int status; - - REQUEST(xvQueryEncodingsReq); - REQUEST_SIZE_MATCH(xvQueryEncodingsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_encodings = pPort->pAdaptor->nEncodings; - - /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */ - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - totalSize = ne * sz_xvEncodingInfo; - while (ne--) - { - totalSize += (strlen(pe->name) + 3) & ~3; - pe++; - } - - rep.length = totalSize >> 2; - - _WriteQueryEncodingsReply(client, &rep); - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - while (ne--) - { - einfo.encoding = pe->id; - einfo.name_size = strlen(pe->name); - einfo.width = pe->width; - einfo.height = pe->height; - einfo.rate.numerator = pe->rate.numerator; - einfo.rate.denominator = pe->rate.denominator; - _WriteEncodingInfo(client, &einfo); - WriteToClient(client, einfo.name_size, pe->name); - pe++; - } - - return (client->noClientException); - -} - -static int -ProcXvPutVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutVideoReq); - REQUEST_SIZE_MATCH(xvPutVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvPutStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutStillReq); - REQUEST_SIZE_MATCH(xvPutStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetVideoReq); - REQUEST_SIZE_MATCH(xvGetVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetStillReq); - REQUEST_SIZE_MATCH(xvGetStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvSelectVideoNotify(ClientPtr client) -{ - register DrawablePtr pDraw; - REQUEST(xvSelectVideoNotifyReq); - REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq); - - if(!(pDraw = (DrawablePtr)LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadWindow); - } - - return XVCALL(diSelectVideoNotify)(client, pDraw, stuff->onoff); - -} - -static int -ProcXvSelectPortNotify(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSelectPortNotifyReq); - REQUEST_SIZE_MATCH(xvSelectPortNotifyReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diSelectPortNotify)(client, pPort, stuff->onoff); - -} - -static int -ProcXvGrabPort(ClientPtr client) -{ - int result, status; - XvPortPtr pPort; - xvGrabPortReply rep; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - status = XVCALL(diGrabPort)(client, pPort, stuff->time, &result); - - if (status != Success) - { - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.result = result; - - _WriteGrabPortReply(client, &rep); - - return Success; - -} - -static int -ProcXvUngrabPort(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diUngrabPort)(client, pPort, stuff->time); - -} - - -static int -ProcXvStopVideo(ClientPtr client) -{ - int status; - register DrawablePtr pDraw; - XvPortPtr pPort; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if(!(pDraw = LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadDrawable); - } - - return XVCALL(diStopVideo)(client, pPort, pDraw); - -} - -static int -ProcXvSetPortAttribute(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSetPortAttributeReq); - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diSetPortAttribute)(client, pPort, - stuff->attribute, stuff->value); - - if (status == BadMatch) - client->errorValue = stuff->attribute; - else - client->errorValue = stuff->value; - - return status; -} - -static int -ProcXvGetPortAttribute(ClientPtr client) -{ - INT32 value; - int status; - XvPortPtr pPort; - xvGetPortAttributeReply rep; - REQUEST(xvGetPortAttributeReq); - REQUEST_SIZE_MATCH(xvGetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diGetPortAttribute)(client, pPort, stuff->attribute, &value); - if (status != Success) - { - client->errorValue = stuff->attribute; - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.value = value; - - _WriteGetPortAttributeReply(client, &rep); - - return Success; -} - -static int -ProcXvQueryBestSize(ClientPtr client) -{ - int status; - unsigned int actual_width, actual_height; - XvPortPtr pPort; - xvQueryBestSizeReply rep; - REQUEST(xvQueryBestSizeReq); - REQUEST_SIZE_MATCH(xvQueryBestSizeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - - (* pPort->pAdaptor->ddQueryBestSize)(client, pPort, stuff->motion, - stuff->vid_w, stuff->vid_h, - stuff->drw_w, stuff->drw_h, - &actual_width, &actual_height); - - rep.actual_width = actual_width; - rep.actual_height = actual_height; - - _WriteQueryBestSizeReply(client, &rep); - - return Success; -} - - -static int -ProcXvQueryPortAttributes(ClientPtr client) -{ - int status, size, i; - XvPortPtr pPort; - XvAttributePtr pAtt; - xvQueryPortAttributesReply rep; - xvAttributeInfo Info; - REQUEST(xvQueryPortAttributesReq); - REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_attributes = pPort->pAdaptor->nAttributes; - rep.text_size = 0; - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L; - } - - rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size; - rep.length >>= 2; - - _WriteQueryPortAttributesReply(client, &rep); - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - size = strlen(pAtt->name) + 1; /* pass the NULL */ - Info.flags = pAtt->flags; - Info.min = pAtt->min_value; - Info.max = pAtt->max_value; - Info.size = (size + 3) & ~3L; - - _WriteAttributeInfo(client, &Info); - - WriteToClient(client, size, pAtt->name); - } - - return Success; -} - - - -static int -ProcXvPutImage(ClientPtr client) -{ - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, i, size; - CARD16 width, height; - - REQUEST(xvPutImageReq); - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - width = stuff->width; - height = stuff->height; - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - size += sizeof(xvPutImageReq); - size = (size + 3) >> 2; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - if(client->req_len < size) - return BadLength; - - return XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, - pImage, (unsigned char*)(&stuff[1]), FALSE, - stuff->width, stuff->height); -} - -#ifdef MITSHM -/* redefined here since it's not in any header file */ -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -extern RESTYPE ShmSegType; -extern int BadShmSegCode; -extern int ShmCompletionCode; - -static int -ProcXvShmPutImage(ClientPtr client) -{ - ShmDescPtr shmdesc; - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, size_needed, i; - CARD16 width, height; - - REQUEST(xvShmPutImageReq); - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - if(!(shmdesc = (ShmDescPtr)LookupIDByType(stuff->shmseg, ShmSegType))) - { - client->errorValue = stuff->shmseg; - return BadShmSegCode; - } - - width = stuff->width; - height = stuff->height; - size_needed = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - if((size_needed + stuff->offset) > shmdesc->size) - return BadAccess; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - status = XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, pImage, - (unsigned char *)shmdesc->addr + stuff->offset, - stuff->send_event, stuff->width, stuff->height); - - if((status == Success) && stuff->send_event) { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = xv_ShmPutImage; - ev.majorEvent = XvReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return status; -} -#endif - -#ifdef XvMCExtension -#include "xvmcext.h" -#endif - -static int -ProcXvQueryImageAttributes(ClientPtr client) -{ - xvQueryImageAttributesReply rep; - int size, num_planes, i; - CARD16 width, height; - XvImagePtr pImage = NULL; - XvPortPtr pPort; - int *offsets; - int *pitches; - REQUEST(xvQueryImageAttributesReq); - - REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - -#ifdef XvMCExtension - if(!pImage) - pImage = XvMCFindXvImage(pPort, stuff->id); -#endif - - if(!pImage) - return BadMatch; - - num_planes = pImage->num_planes; - - if(!(offsets = xalloc(num_planes << 3))) - return BadAlloc; - pitches = offsets + num_planes; - - width = stuff->width; - height = stuff->height; - - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, pPort, pImage, - &width, &height, offsets, pitches); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = num_planes << 1; - rep.num_planes = num_planes; - rep.width = width; - rep.height = height; - rep.data_size = size; - - _WriteQueryImageAttributesReply(client, &rep); - if(client->swapped) - SwapLongs((CARD32*)offsets, rep.length); - WriteToClient(client, rep.length << 2, (char*)offsets); - - xfree(offsets); - - return Success; -} - -static int -ProcXvListImageFormats(ClientPtr client) -{ - XvPortPtr pPort; - XvImagePtr pImage; - int i; - xvListImageFormatsReply rep; - xvImageFormatInfo info; - REQUEST(xvListImageFormatsReq); - - REQUEST_SIZE_MATCH(xvListImageFormatsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_formats = pPort->pAdaptor->nImages; - rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2; - - _WriteListImageFormatsReply(client, &rep); - - pImage = pPort->pAdaptor->pImages; - - for(i = 0; i < rep.num_formats; i++, pImage++) { - info.id = pImage->id; - info.type = pImage->type; - info.byte_order = pImage->byte_order; - memcpy(&info.guid, pImage->guid, 16); - info.bpp = pImage->bits_per_pixel; - info.num_planes = pImage->num_planes; - info.depth = pImage->depth; - info.red_mask = pImage->red_mask; - info.green_mask = pImage->green_mask; - info.blue_mask = pImage->blue_mask; - info.format = pImage->format; - info.y_sample_bits = pImage->y_sample_bits; - info.u_sample_bits = pImage->u_sample_bits; - info.v_sample_bits = pImage->v_sample_bits; - info.horz_y_period = pImage->horz_y_period; - info.horz_u_period = pImage->horz_u_period; - info.horz_v_period = pImage->horz_v_period; - info.vert_y_period = pImage->vert_y_period; - info.vert_u_period = pImage->vert_u_period; - info.vert_v_period = pImage->vert_v_period; - memcpy(&info.comp_order, pImage->component_order, 32); - info.scanline_order = pImage->scanline_order; - _WriteImageFormatInfo(client, &info); - } - - return Success; -} - - - -/* Swapped Procs */ - -static int -SProcXvQueryExtension(ClientPtr client) -{ - register char n; - REQUEST(xvQueryExtensionReq); - swaps(&stuff->length, n); - return ProcXvQueryExtension(client); -} - -static int -SProcXvQueryAdaptors(ClientPtr client) -{ - register char n; - REQUEST(xvQueryAdaptorsReq); - swaps(&stuff->length, n); - swapl(&stuff->window, n); - return ProcXvQueryAdaptors(client); -} - -static int -SProcXvQueryEncodings(ClientPtr client) -{ - register char n; - REQUEST(xvQueryEncodingsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryEncodings(client); -} - -static int -SProcXvGrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvGrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvGrabPort(client); -} - -static int -SProcXvUngrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvUngrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvUngrabPort(client); -} - -static int -SProcXvPutVideo(ClientPtr client) -{ - register char n; - REQUEST(xvPutVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutVideo(client); -} - -static int -SProcXvPutStill(ClientPtr client) -{ - register char n; - REQUEST(xvPutStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutStill(client); -} - -static int -SProcXvGetVideo(ClientPtr client) -{ - register char n; - REQUEST(xvGetVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetVideo(client); -} - -static int -SProcXvGetStill(ClientPtr client) -{ - register char n; - REQUEST(xvGetStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetStill(client); -} - -static int -SProcXvPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvPutImage(client); -} - -#ifdef MITSHM -static int -SProcXvShmPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvShmPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->offset, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvShmPutImage(client); -} -#endif - - -static int -SProcXvSelectVideoNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectVideoNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return ProcXvSelectVideoNotify(client); -} - -static int -SProcXvSelectPortNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectPortNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvSelectPortNotify(client); -} - -static int -SProcXvStopVideo(ClientPtr client) -{ - register char n; - REQUEST(xvStopVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - return ProcXvStopVideo(client); -} - -static int -SProcXvSetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvSetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvSetPortAttribute(client); -} - -static int -SProcXvGetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvGetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvGetPortAttribute(client); -} - -static int -SProcXvQueryBestSize(ClientPtr client) -{ - register char n; - REQUEST(xvQueryBestSizeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvQueryBestSize(client); -} - -static int -SProcXvQueryPortAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryPortAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryPortAttributes(client); -} - -static int -SProcXvQueryImageAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryImageAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->id, n); - swaps(&stuff->width, n); - swaps(&stuff->width, n); - return ProcXvQueryImageAttributes(client); -} - -static int -SProcXvListImageFormats(ClientPtr client) -{ - register char n; - REQUEST(xvListImageFormatsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvListImageFormats(client); -} - - -static int -SWriteQueryExtensionReply( - ClientPtr client, - xvQueryExtensionReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->version, n); - swaps(&rep->revision, n); - - (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryAdaptorsReply( - ClientPtr client, - xvQueryAdaptorsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_adaptors, n); - - (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryEncodingsReply( - ClientPtr client, - xvQueryEncodingsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_encodings, n); - - (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep); - - return Success; -} - -static int -SWriteAdaptorInfo( - ClientPtr client, - xvAdaptorInfo *pAdaptor -){ - register char n; - - swapl(&pAdaptor->base_id, n); - swaps(&pAdaptor->name_size, n); - swaps(&pAdaptor->num_ports, n); - swaps(&pAdaptor->num_formats, n); - - (void)WriteToClient(client, sz_xvAdaptorInfo, (char *)pAdaptor); - - return Success; -} - -static int -SWriteEncodingInfo( - ClientPtr client, - xvEncodingInfo *pEncoding -){ - register char n; - - swapl(&pEncoding->encoding, n); - swaps(&pEncoding->name_size, n); - swaps(&pEncoding->width, n); - swaps(&pEncoding->height, n); - swapl(&pEncoding->rate.numerator, n); - swapl(&pEncoding->rate.denominator, n); - (void)WriteToClient(client, sz_xvEncodingInfo, (char *)pEncoding); - - return Success; -} - -static int -SWriteFormat( - ClientPtr client, - xvFormat *pFormat -){ - register char n; - - swapl(&pFormat->visual, n); - (void)WriteToClient(client, sz_xvFormat, (char *)pFormat); - - return Success; -} - -static int -SWriteAttributeInfo( - ClientPtr client, - xvAttributeInfo *pAtt -){ - register char n; - - swapl(&pAtt->flags, n); - swapl(&pAtt->size, n); - swapl(&pAtt->min, n); - swapl(&pAtt->max, n); - (void)WriteToClient(client, sz_xvAttributeInfo, (char *)pAtt); - - return Success; -} - -static int -SWriteImageFormatInfo( - ClientPtr client, - xvImageFormatInfo *pImage -){ - register char n; - - swapl(&pImage->id, n); - swapl(&pImage->red_mask, n); - swapl(&pImage->green_mask, n); - swapl(&pImage->blue_mask, n); - swapl(&pImage->y_sample_bits, n); - swapl(&pImage->u_sample_bits, n); - swapl(&pImage->v_sample_bits, n); - swapl(&pImage->horz_y_period, n); - swapl(&pImage->horz_u_period, n); - swapl(&pImage->horz_v_period, n); - swapl(&pImage->vert_y_period, n); - swapl(&pImage->vert_u_period, n); - swapl(&pImage->vert_v_period, n); - - (void)WriteToClient(client, sz_xvImageFormatInfo, (char *)pImage); - - return Success; -} - - - -static int -SWriteGrabPortReply( - ClientPtr client, - xvGrabPortReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - - (void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep); - - return Success; -} - -static int -SWriteGetPortAttributeReply( - ClientPtr client, - xvGetPortAttributeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->value, n); - - (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryBestSizeReply( - ClientPtr client, - xvQueryBestSizeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->actual_width, n); - swaps(&rep->actual_height, n); - - (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryPortAttributesReply( - ClientPtr client, - xvQueryPortAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_attributes, n); - swapl(&rep->text_size, n); - - (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryImageAttributesReply( - ClientPtr client, - xvQueryImageAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_planes, n); - swapl(&rep->data_size, n); - swaps(&rep->width, n); - swaps(&rep->height, n); - - (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep); - - return Success; -} - - -static int -SWriteListImageFormatsReply( - ClientPtr client, - xvListImageFormatsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_formats, n); - - (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep); - - return Success; -} - - -#ifdef PANORAMIX - - - - -static int -XineramaXvStopVideo(ClientPtr client) -{ - int result = Success, i; - PanoramiXRes *draw, *port; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - result = ProcXvStopVideo(client); - } - } - - return result; -} - -static int -XineramaXvSetPortAttribute(ClientPtr client) -{ - REQUEST(xvSetPortAttributeReq); - PanoramiXRes *port; - int result = Success, i; - - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->port = port->info[i].id; - result = ProcXvSetPortAttribute(client); - } - } - return result; -} - - -#ifdef MITSHM -static int -XineramaXvShmPutImage(ClientPtr client) -{ - REQUEST(xvShmPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool send_event = stuff->send_event; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - stuff->send_event = (send_event && !i) ? 1 : 0; - - result = ProcXvShmPutImage(client); - } - } - return result; -} -#endif - -static int -XineramaXvPutImage(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutImage(client); - } - } - return result; -} - -static int -XineramaXvPutVideo(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutVideo(client); - } - } - return result; -} - -static int -XineramaXvPutStill(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutStill(client); - } - } - return result; -} - - -void XineramifyXv(void) -{ - ScreenPtr pScreen, screen0 = screenInfo.screens[0]; - XvScreenPtr xvsp0 = (XvScreenPtr)screen0->devPrivates[XvScreenIndex].ptr; - XvAdaptorPtr refAdapt, pAdapt; - XvAttributePtr pAttr; - XvScreenPtr xvsp; - Bool isOverlay, hasOverlay; - PanoramiXRes *port; - XvAdaptorPtr MatchingAdaptors[MAXSCREENS]; - int i, j, k, l; - - XvXRTPort = CreateNewResourceType(XineramaDeleteResource); - - if(!xvsp0) return; - - for(i = 0; i < xvsp0->nAdaptors; i++) { - refAdapt = xvsp0->pAdaptors + i; - - bzero(MatchingAdaptors, sizeof(XvAdaptorPtr) * MAXSCREENS); - - MatchingAdaptors[0] = refAdapt; - - if(!(refAdapt->type & XvInputMask)) continue; - - isOverlay = FALSE; - for(j = 0; j < refAdapt->nAttributes; j++) { - pAttr = refAdapt->pAttributes + j; - if(!strcmp(pAttr->name, "XV_COLORKEY")) { - isOverlay = TRUE; - break; - } - } - - for(j = 1; j < PanoramiXNumScreens; j++) { - pScreen = screenInfo.screens[j]; - xvsp = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - /* Do not try to go on if xv is not supported on this screen */ - if (xvsp==NULL) continue ; - - /* if the adaptor has the same name it's a perfect match */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if(!strcmp(refAdapt->name, pAdapt->name)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - if(MatchingAdaptors[j]) continue; /* found it */ - - /* otherwise we only look for XvImage adaptors */ - if(!(refAdapt->type & XvImageMask)) continue; - if(refAdapt->nImages <= 0) continue; - - /* prefer overlay/overlay non-overlay/non-overlay pairing */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - hasOverlay = FALSE; - for(l = 0; l < pAdapt->nAttributes; l++) { - if(!strcmp(pAdapt->name, "XV_COLORKEY")) { - hasOverlay = TRUE; - break; - } - } - if(isOverlay && hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - else if(!isOverlay && !hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - if(MatchingAdaptors[j]) continue; /* found it */ - - /* but we'll take any XvImage pairing if we can get it */ - - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - /* now create a resource for each port */ - for(j = 0; j < refAdapt->nPorts; j++) { - if(!(port = xalloc(sizeof(PanoramiXRes)))) - break; - port->info[0].id = MatchingAdaptors[0]->base_id + j; - AddResource(port->info[0].id, XvXRTPort, port); - - for(k = 1; k < PanoramiXNumScreens; k++) { - if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) - port->info[k].id = MatchingAdaptors[k]->base_id + j; - else - port->info[k].id = 0; - } - } - } -} - -#endif - diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.X.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.X.original deleted file mode 100644 index 21ab0b6a0..000000000 --- a/nx-X11/programs/Xserver/hw/nxagent/X/NXxvdisp.c.X.original +++ /dev/null @@ -1,2217 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/Xext/xvdisp.c,v 1.6 2005/07/03 08:53:36 daniels Exp $ */ -/*********************************************************** -Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts, -and the Massachusetts Institute of Technology, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital or MIT not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $XFree86: xc/programs/Xserver/Xext/xvdisp.c,v 1.27 2003/07/16 01:38:31 dawes Exp $ */ - -/* -** File: -** -** xvdisp.c --- Xv server extension dispatch module. -** -** Author: -** -** David Carver (Digital Workstation Engineering/Project Athena) -** -** Revisions: -** -** 11.06.91 Carver -** - changed SetPortControl to SetPortAttribute -** - changed GetPortControl to GetPortAttribute -** - changed QueryBestSize -** -** 15.05.91 Carver -** - version 2.0 upgrade -** -** 24.01.91 Carver -** - version 1.4 upgrade -** -*/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include "misc.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "gcstruct.h" -#include "dixstruct.h" -#include "resource.h" -#include "opaque.h" - -#include -#include -#include "xvdix.h" -#ifdef MITSHM -#define _XSHM_SERVER_ -#include -#endif - -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -#include "xvdisp.h" - -#ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - -unsigned long XvXRTPort; - -#ifdef MITSHM -static int XineramaXvShmPutImage(ClientPtr); -#endif -static int XineramaXvPutImage(ClientPtr); -static int XineramaXvPutVideo(ClientPtr); -static int XineramaXvPutStill(ClientPtr); -static int XineramaXvSetPortAttribute(ClientPtr); -static int XineramaXvStopVideo(ClientPtr); -#endif - -/* INTERNAL */ - -static int ProcXvQueryExtension(ClientPtr); -static int ProcXvQueryAdaptors(ClientPtr); -static int ProcXvQueryEncodings(ClientPtr); -static int ProcXvPutVideo(ClientPtr); -static int ProcXvPutStill(ClientPtr); -static int ProcXvGetVideo(ClientPtr); -static int ProcXvGetStill(ClientPtr); -static int ProcXvGrabPort(ClientPtr); -static int ProcXvUngrabPort(ClientPtr); -static int ProcXvSelectVideoNotify(ClientPtr); -static int ProcXvSelectPortNotify(ClientPtr); -static int ProcXvStopVideo(ClientPtr); -static int ProcXvSetPortAttribute(ClientPtr); -static int ProcXvGetPortAttribute(ClientPtr); -static int ProcXvQueryBestSize(ClientPtr); -static int ProcXvQueryPortAttributes(ClientPtr); -static int ProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int ProcXvShmPutImage(ClientPtr); -#endif -static int ProcXvQueryImageAttributes(ClientPtr); -static int ProcXvListImageFormats(ClientPtr); - -static int SProcXvQueryExtension(ClientPtr); -static int SProcXvQueryAdaptors(ClientPtr); -static int SProcXvQueryEncodings(ClientPtr); -static int SProcXvPutVideo(ClientPtr); -static int SProcXvPutStill(ClientPtr); -static int SProcXvGetVideo(ClientPtr); -static int SProcXvGetStill(ClientPtr); -static int SProcXvGrabPort(ClientPtr); -static int SProcXvUngrabPort(ClientPtr); -static int SProcXvSelectVideoNotify(ClientPtr); -static int SProcXvSelectPortNotify(ClientPtr); -static int SProcXvStopVideo(ClientPtr); -static int SProcXvSetPortAttribute(ClientPtr); -static int SProcXvGetPortAttribute(ClientPtr); -static int SProcXvQueryBestSize(ClientPtr); -static int SProcXvQueryPortAttributes(ClientPtr); -static int SProcXvPutImage(ClientPtr); -#ifdef MITSHM -static int SProcXvShmPutImage(ClientPtr); -#endif -static int SProcXvQueryImageAttributes(ClientPtr); -static int SProcXvListImageFormats(ClientPtr); - -static int SWriteQueryAdaptorsReply(ClientPtr, xvQueryAdaptorsReply *); -static int SWriteQueryExtensionReply(ClientPtr, xvQueryExtensionReply *); -static int SWriteQueryEncodingsReply(ClientPtr, xvQueryEncodingsReply *); -static int SWriteAdaptorInfo(ClientPtr, xvAdaptorInfo *); -static int SWriteEncodingInfo(ClientPtr, xvEncodingInfo *); -static int SWriteFormat(ClientPtr, xvFormat *); -static int SWriteAttributeInfo(ClientPtr, xvAttributeInfo *); -static int SWriteGrabPortReply(ClientPtr, xvGrabPortReply *); -static int SWriteGetPortAttributeReply(ClientPtr, xvGetPortAttributeReply *); -static int SWriteQueryBestSizeReply(ClientPtr, xvQueryBestSizeReply *); -static int SWriteQueryPortAttributesReply( - ClientPtr, xvQueryPortAttributesReply *); -static int SWriteQueryImageAttributesReply( - ClientPtr, xvQueryImageAttributesReply*); -static int SWriteListImageFormatsReply(ClientPtr, xvListImageFormatsReply*); -static int SWriteImageFormatInfo(ClientPtr, xvImageFormatInfo*); - -#define _WriteQueryAdaptorsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryAdaptorsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryAdaptorsReply, (char*)_d) - -#define _WriteQueryExtensionReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryExtensionReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryExtensionReply, (char*)_d) - -#define _WriteQueryEncodingsReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryEncodingsReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryEncodingsReply, (char*)_d) - -#define _WriteAdaptorInfo(_c,_d) \ - if ((_c)->swapped) SWriteAdaptorInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAdaptorInfo, (char*)_d) - -#define _WriteAttributeInfo(_c,_d) \ - if ((_c)->swapped) SWriteAttributeInfo(_c, _d); \ - else WriteToClient(_c, sz_xvAttributeInfo, (char*)_d) - -#define _WriteEncodingInfo(_c,_d) \ - if ((_c)->swapped) SWriteEncodingInfo(_c, _d); \ - else WriteToClient(_c, sz_xvEncodingInfo, (char*)_d) - -#define _WriteFormat(_c,_d) \ - if ((_c)->swapped) SWriteFormat(_c, _d); \ - else WriteToClient(_c, sz_xvFormat, (char*)_d) - -#define _WriteGrabPortReply(_c,_d) \ - if ((_c)->swapped) SWriteGrabPortReply(_c, _d); \ - else WriteToClient(_c, sz_xvGrabPortReply, (char*)_d) - -#define _WriteGetPortAttributeReply(_c,_d) \ - if ((_c)->swapped) SWriteGetPortAttributeReply(_c, _d); \ - else WriteToClient(_c, sz_xvGetPortAttributeReply, (char*)_d) - -#define _WriteQueryBestSizeReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryBestSizeReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryBestSizeReply,(char*) _d) - -#define _WriteQueryPortAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryPortAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryPortAttributesReply,(char*) _d) - -#define _WriteQueryImageAttributesReply(_c,_d) \ - if ((_c)->swapped) SWriteQueryImageAttributesReply(_c, _d); \ - else WriteToClient(_c, sz_xvQueryImageAttributesReply,(char*) _d) - -#define _WriteListImageFormatsReply(_c,_d) \ - if ((_c)->swapped) SWriteListImageFormatsReply(_c, _d); \ - else WriteToClient(_c, sz_xvListImageFormatsReply,(char*) _d) - -#define _WriteImageFormatInfo(_c,_d) \ - if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \ - else WriteToClient(_c, sz_xvImageFormatInfo, (char*)_d) - -#define _AllocatePort(_i,_p) \ - ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success - -/* -** ProcXvDispatch -** -** -** -*/ - -int -ProcXvDispatch(ClientPtr client) -{ - REQUEST(xReq); - - UpdateCurrentTime(); - - switch (stuff->data) - { - case xv_QueryExtension: return(ProcXvQueryExtension(client)); - case xv_QueryAdaptors: return(ProcXvQueryAdaptors(client)); - case xv_QueryEncodings: return(ProcXvQueryEncodings(client)); - case xv_PutVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvPutVideo(client)); - else -#endif - return(ProcXvPutVideo(client)); - case xv_PutStill: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvPutStill(client)); - else -#endif - return(ProcXvPutStill(client)); - case xv_GetVideo: return(ProcXvGetVideo(client)); - case xv_GetStill: return(ProcXvGetStill(client)); - case xv_GrabPort: return(ProcXvGrabPort(client)); - case xv_UngrabPort: return(ProcXvUngrabPort(client)); - case xv_SelectVideoNotify: return(ProcXvSelectVideoNotify(client)); - case xv_SelectPortNotify: return(ProcXvSelectPortNotify(client)); - case xv_StopVideo: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvStopVideo(client)); - else -#endif - return(ProcXvStopVideo(client)); - case xv_SetPortAttribute: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvSetPortAttribute(client)); - else -#endif - return(ProcXvSetPortAttribute(client)); - case xv_GetPortAttribute: return(ProcXvGetPortAttribute(client)); - case xv_QueryBestSize: return(ProcXvQueryBestSize(client)); - case xv_QueryPortAttributes: return(ProcXvQueryPortAttributes(client)); - case xv_PutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvPutImage(client)); - else -#endif - return(ProcXvPutImage(client)); -#ifdef MITSHM - case xv_ShmPutImage: -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return(XineramaXvShmPutImage(client)); - else -#endif - return(ProcXvShmPutImage(client)); -#endif - case xv_QueryImageAttributes: return(ProcXvQueryImageAttributes(client)); - case xv_ListImageFormats: return(ProcXvListImageFormats(client)); - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - return(BadImplementation); - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - return(BadRequest); - } - } -} - -int -SProcXvDispatch(ClientPtr client) -{ - REQUEST(xReq); - - UpdateCurrentTime(); - - switch (stuff->data) - { - case xv_QueryExtension: return(SProcXvQueryExtension(client)); - case xv_QueryAdaptors: return(SProcXvQueryAdaptors(client)); - case xv_QueryEncodings: return(SProcXvQueryEncodings(client)); - case xv_PutVideo: return(SProcXvPutVideo(client)); - case xv_PutStill: return(SProcXvPutStill(client)); - case xv_GetVideo: return(SProcXvGetVideo(client)); - case xv_GetStill: return(SProcXvGetStill(client)); - case xv_GrabPort: return(SProcXvGrabPort(client)); - case xv_UngrabPort: return(SProcXvUngrabPort(client)); - case xv_SelectVideoNotify: return(SProcXvSelectVideoNotify(client)); - case xv_SelectPortNotify: return(SProcXvSelectPortNotify(client)); - case xv_StopVideo: return(SProcXvStopVideo(client)); - case xv_SetPortAttribute: return(SProcXvSetPortAttribute(client)); - case xv_GetPortAttribute: return(SProcXvGetPortAttribute(client)); - case xv_QueryBestSize: return(SProcXvQueryBestSize(client)); - case xv_QueryPortAttributes: return(SProcXvQueryPortAttributes(client)); - case xv_PutImage: return(SProcXvPutImage(client)); -#ifdef MITSHM - case xv_ShmPutImage: return(SProcXvShmPutImage(client)); -#endif - case xv_QueryImageAttributes: return(SProcXvQueryImageAttributes(client)); - case xv_ListImageFormats: return(SProcXvListImageFormats(client)); - default: - if (stuff->data < xvNumRequests) - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, - BadImplementation); - return(BadImplementation); - } - else - { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - return(BadRequest); - } - } -} - -static int -ProcXvQueryExtension(ClientPtr client) -{ - xvQueryExtensionReply rep; - /* REQUEST(xvQueryExtensionReq); */ - REQUEST_SIZE_MATCH(xvQueryExtensionReq); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.version = XvVersion; - rep.revision = XvRevision; - - _WriteQueryExtensionReply(client, &rep); - - return Success; - -} - -static int -ProcXvQueryAdaptors(ClientPtr client) -{ - xvFormat format; - xvAdaptorInfo ainfo; - xvQueryAdaptorsReply rep; - int totalSize; - int na; - XvAdaptorPtr pa; - int nf; - XvFormatPtr pf; - WindowPtr pWin; - ScreenPtr pScreen; - XvScreenPtr pxvs; - - REQUEST(xvQueryAdaptorsReq); - REQUEST_SIZE_MATCH(xvQueryAdaptorsReq); - - if(!(pWin = (WindowPtr)LookupWindow(stuff->window, client) )) - { - client->errorValue = stuff->window; - return (BadWindow); - } - - pScreen = pWin->drawable.pScreen; - pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - if (!pxvs) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = 0; - rep.length = 0; - - _WriteQueryAdaptorsReply(client, &rep); - - return Success; - } - - (* pxvs->ddQueryAdaptors)(pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = pxvs->nAdaptors; - - /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ - - totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; - - /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - totalSize += (strlen(pa->name) + 3) & ~3; - totalSize += pa->nFormats * sz_xvFormat; - pa++; - } - - rep.length = totalSize >> 2; - - _WriteQueryAdaptorsReply(client, &rep); - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - - ainfo.base_id = pa->base_id; - ainfo.num_ports = pa->nPorts; - ainfo.type = pa->type; - ainfo.name_size = strlen(pa->name); - ainfo.num_formats = pa->nFormats; - - _WriteAdaptorInfo(client, &ainfo); - - WriteToClient(client, ainfo.name_size, pa->name); - - nf = pa->nFormats; - pf = pa->pFormats; - while (nf--) - { - format.depth = pf->depth; - format.visual = pf->visual; - _WriteFormat(client, &format); - pf++; - } - - pa++; - - } - - return (client->noClientException); - -} - -static int -ProcXvQueryEncodings(ClientPtr client) -{ - xvEncodingInfo einfo; - xvQueryEncodingsReply rep; - int totalSize; - XvPortPtr pPort; - int ne; - XvEncodingPtr pe; - int status; - - REQUEST(xvQueryEncodingsReq); - REQUEST_SIZE_MATCH(xvQueryEncodingsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_encodings = pPort->pAdaptor->nEncodings; - - /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */ - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - totalSize = ne * sz_xvEncodingInfo; - while (ne--) - { - totalSize += (strlen(pe->name) + 3) & ~3; - pe++; - } - - rep.length = totalSize >> 2; - - _WriteQueryEncodingsReply(client, &rep); - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - while (ne--) - { - einfo.encoding = pe->id; - einfo.name_size = strlen(pe->name); - einfo.width = pe->width; - einfo.height = pe->height; - einfo.rate.numerator = pe->rate.numerator; - einfo.rate.denominator = pe->rate.denominator; - _WriteEncodingInfo(client, &einfo); - WriteToClient(client, einfo.name_size, pe->name); - pe++; - } - - return (client->noClientException); - -} - -static int -ProcXvPutVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutVideoReq); - REQUEST_SIZE_MATCH(xvPutVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvPutStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvPutStillReq); - REQUEST_SIZE_MATCH(xvPutStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diPutStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetVideo(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetVideoReq); - REQUEST_SIZE_MATCH(xvGetVideoReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetVideo)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - - -static int -ProcXvGetStill(ClientPtr client) -{ - register DrawablePtr pDraw; - XvPortPtr pPort; - register GCPtr pGC; - int status; - - REQUEST(xvGetStillReq); - REQUEST_SIZE_MATCH(xvGetStillReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - return XVCALL(diGetStill)(client, pDraw, pPort, pGC, - stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); - -} - -static int -ProcXvSelectVideoNotify(ClientPtr client) -{ - register DrawablePtr pDraw; - REQUEST(xvSelectVideoNotifyReq); - REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq); - - if(!(pDraw = (DrawablePtr)LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadWindow); - } - - return XVCALL(diSelectVideoNotify)(client, pDraw, stuff->onoff); - -} - -static int -ProcXvSelectPortNotify(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSelectPortNotifyReq); - REQUEST_SIZE_MATCH(xvSelectPortNotifyReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diSelectPortNotify)(client, pPort, stuff->onoff); - -} - -static int -ProcXvGrabPort(ClientPtr client) -{ - int result, status; - XvPortPtr pPort; - xvGrabPortReply rep; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - status = XVCALL(diGrabPort)(client, pPort, stuff->time, &result); - - if (status != Success) - { - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.result = result; - - _WriteGrabPortReply(client, &rep); - - return Success; - -} - -static int -ProcXvUngrabPort(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - return XVCALL(diUngrabPort)(client, pPort, stuff->time); - -} - - -static int -ProcXvStopVideo(ClientPtr client) -{ - int status; - register DrawablePtr pDraw; - XvPortPtr pPort; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if(!(pDraw = LOOKUP_DRAWABLE(stuff->drawable, client) )) - { - client->errorValue = stuff->drawable; - return (BadDrawable); - } - - return XVCALL(diStopVideo)(client, pPort, pDraw); - -} - -static int -ProcXvSetPortAttribute(ClientPtr client) -{ - int status; - XvPortPtr pPort; - REQUEST(xvSetPortAttributeReq); - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diSetPortAttribute)(client, pPort, - stuff->attribute, stuff->value); - - if (status == BadMatch) - client->errorValue = stuff->attribute; - else - client->errorValue = stuff->value; - - return status; -} - -static int -ProcXvGetPortAttribute(ClientPtr client) -{ - INT32 value; - int status; - XvPortPtr pPort; - xvGetPortAttributeReply rep; - REQUEST(xvGetPortAttributeReq); - REQUEST_SIZE_MATCH(xvGetPortAttributeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return(BadAtom); - } - - status = XVCALL(diGetPortAttribute)(client, pPort, stuff->attribute, &value); - if (status != Success) - { - client->errorValue = stuff->attribute; - return status; - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.value = value; - - _WriteGetPortAttributeReply(client, &rep); - - return Success; -} - -static int -ProcXvQueryBestSize(ClientPtr client) -{ - int status; - unsigned int actual_width, actual_height; - XvPortPtr pPort; - xvQueryBestSizeReply rep; - REQUEST(xvQueryBestSizeReq); - REQUEST_SIZE_MATCH(xvQueryBestSizeReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - - (* pPort->pAdaptor->ddQueryBestSize)(client, pPort, stuff->motion, - stuff->vid_w, stuff->vid_h, - stuff->drw_w, stuff->drw_h, - &actual_width, &actual_height); - - rep.actual_width = actual_width; - rep.actual_height = actual_height; - - _WriteQueryBestSizeReply(client, &rep); - - return Success; -} - - -static int -ProcXvQueryPortAttributes(ClientPtr client) -{ - int status, size, i; - XvPortPtr pPort; - XvAttributePtr pAtt; - xvQueryPortAttributesReply rep; - xvAttributeInfo Info; - REQUEST(xvQueryPortAttributesReq); - REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_attributes = pPort->pAdaptor->nAttributes; - rep.text_size = 0; - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L; - } - - rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size; - rep.length >>= 2; - - _WriteQueryPortAttributesReply(client, &rep); - - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < rep.num_attributes; i++, pAtt++) - { - size = strlen(pAtt->name) + 1; /* pass the NULL */ - Info.flags = pAtt->flags; - Info.min = pAtt->min_value; - Info.max = pAtt->max_value; - Info.size = (size + 3) & ~3L; - - _WriteAttributeInfo(client, &Info); - - WriteToClient(client, size, pAtt->name); - } - - return Success; -} - - - -static int -ProcXvPutImage(ClientPtr client) -{ - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, i, size; - CARD16 width, height; - - REQUEST(xvPutImageReq); - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - width = stuff->width; - height = stuff->height; - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - size += sizeof(xvPutImageReq); - size = (size + 3) >> 2; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - if(client->req_len < size) - return BadLength; - - return XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, - pImage, (unsigned char*)(&stuff[1]), FALSE, - stuff->width, stuff->height); -} - -#ifdef MITSHM -/* redefined here since it's not in any header file */ -typedef struct _ShmDesc { - struct _ShmDesc *next; - int shmid; - int refcnt; - char *addr; - Bool writable; - unsigned long size; -} ShmDescRec, *ShmDescPtr; - -extern RESTYPE ShmSegType; -extern int BadShmSegCode; -extern int ShmCompletionCode; - -static int -ProcXvShmPutImage(ClientPtr client) -{ - ShmDescPtr shmdesc; - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, size_needed, i; - CARD16 width, height; - - REQUEST(xvShmPutImageReq); - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return (status); - } - - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return (BadMatch); - } - - status = XVCALL(diMatchPort)(pPort, pDraw); - if (status != Success) - { - return status; - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - if(!(shmdesc = (ShmDescPtr)LookupIDByType(stuff->shmseg, ShmSegType))) - { - client->errorValue = stuff->shmseg; - return BadShmSegCode; - } - - width = stuff->width; - height = stuff->height; - size_needed = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - if((size_needed + stuff->offset) > shmdesc->size) - return BadAccess; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - status = XVCALL(diPutImage)(client, pDraw, pPort, pGC, - stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, - stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, pImage, - (unsigned char *)shmdesc->addr + stuff->offset, - stuff->send_event, stuff->width, stuff->height); - - if((status == Success) && stuff->send_event) { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; - ev.minorEvent = xv_ShmPutImage; - ev.majorEvent = XvReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); - } - - return status; -} -#endif - -#ifdef XvMCExtension -#include "xvmcext.h" -#endif - -static int -ProcXvQueryImageAttributes(ClientPtr client) -{ - xvQueryImageAttributesReply rep; - int size, num_planes, i; - CARD16 width, height; - XvImagePtr pImage = NULL; - XvPortPtr pPort; - int *offsets; - int *pitches; - REQUEST(xvQueryImageAttributesReq); - - REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - -#ifdef XvMCExtension - if(!pImage) - pImage = XvMCFindXvImage(pPort, stuff->id); -#endif - - if(!pImage) - return BadMatch; - - num_planes = pImage->num_planes; - - if(!(offsets = xalloc(num_planes << 3))) - return BadAlloc; - pitches = offsets + num_planes; - - width = stuff->width; - height = stuff->height; - - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, pPort, pImage, - &width, &height, offsets, pitches); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = num_planes << 1; - rep.num_planes = num_planes; - rep.width = width; - rep.height = height; - rep.data_size = size; - - _WriteQueryImageAttributesReply(client, &rep); - if(client->swapped) - SwapLongs((CARD32*)offsets, rep.length); - WriteToClient(client, rep.length << 2, (char*)offsets); - - xfree(offsets); - - return Success; -} - -static int -ProcXvListImageFormats(ClientPtr client) -{ - XvPortPtr pPort; - XvImagePtr pImage; - int i; - xvListImageFormatsReply rep; - xvImageFormatInfo info; - REQUEST(xvListImageFormatsReq); - - REQUEST_SIZE_MATCH(xvListImageFormatsReq); - - if(!(pPort = LOOKUP_PORT(stuff->port, client) )) - { - client->errorValue = stuff->port; - return (_XvBadPort); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_formats = pPort->pAdaptor->nImages; - rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2; - - _WriteListImageFormatsReply(client, &rep); - - pImage = pPort->pAdaptor->pImages; - - for(i = 0; i < rep.num_formats; i++, pImage++) { - info.id = pImage->id; - info.type = pImage->type; - info.byte_order = pImage->byte_order; - memcpy(&info.guid, pImage->guid, 16); - info.bpp = pImage->bits_per_pixel; - info.num_planes = pImage->num_planes; - info.depth = pImage->depth; - info.red_mask = pImage->red_mask; - info.green_mask = pImage->green_mask; - info.blue_mask = pImage->blue_mask; - info.format = pImage->format; - info.y_sample_bits = pImage->y_sample_bits; - info.u_sample_bits = pImage->u_sample_bits; - info.v_sample_bits = pImage->v_sample_bits; - info.horz_y_period = pImage->horz_y_period; - info.horz_u_period = pImage->horz_u_period; - info.horz_v_period = pImage->horz_v_period; - info.vert_y_period = pImage->vert_y_period; - info.vert_u_period = pImage->vert_u_period; - info.vert_v_period = pImage->vert_v_period; - memcpy(&info.comp_order, pImage->component_order, 32); - info.scanline_order = pImage->scanline_order; - _WriteImageFormatInfo(client, &info); - } - - return Success; -} - - - -/* Swapped Procs */ - -static int -SProcXvQueryExtension(ClientPtr client) -{ - register char n; - REQUEST(xvQueryExtensionReq); - swaps(&stuff->length, n); - return ProcXvQueryExtension(client); -} - -static int -SProcXvQueryAdaptors(ClientPtr client) -{ - register char n; - REQUEST(xvQueryAdaptorsReq); - swaps(&stuff->length, n); - swapl(&stuff->window, n); - return ProcXvQueryAdaptors(client); -} - -static int -SProcXvQueryEncodings(ClientPtr client) -{ - register char n; - REQUEST(xvQueryEncodingsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryEncodings(client); -} - -static int -SProcXvGrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvGrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvGrabPort(client); -} - -static int -SProcXvUngrabPort(ClientPtr client) -{ - register char n; - REQUEST(xvUngrabPortReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->time, n); - return ProcXvUngrabPort(client); -} - -static int -SProcXvPutVideo(ClientPtr client) -{ - register char n; - REQUEST(xvPutVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutVideo(client); -} - -static int -SProcXvPutStill(ClientPtr client) -{ - register char n; - REQUEST(xvPutStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvPutStill(client); -} - -static int -SProcXvGetVideo(ClientPtr client) -{ - register char n; - REQUEST(xvGetVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetVideo(client); -} - -static int -SProcXvGetStill(ClientPtr client) -{ - register char n; - REQUEST(xvGetStillReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swaps(&stuff->vid_x, n); - swaps(&stuff->vid_y, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvGetStill(client); -} - -static int -SProcXvPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvPutImage(client); -} - -#ifdef MITSHM -static int -SProcXvShmPutImage(ClientPtr client) -{ - register char n; - REQUEST(xvShmPutImageReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - swapl(&stuff->gc, n); - swapl(&stuff->shmseg, n); - swapl(&stuff->id, n); - swaps(&stuff->src_x, n); - swaps(&stuff->src_y, n); - swaps(&stuff->src_w, n); - swaps(&stuff->src_h, n); - swaps(&stuff->drw_x, n); - swaps(&stuff->drw_y, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - swaps(&stuff->offset, n); - swaps(&stuff->width, n); - swaps(&stuff->height, n); - return ProcXvShmPutImage(client); -} -#endif - - -static int -SProcXvSelectVideoNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectVideoNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - return ProcXvSelectVideoNotify(client); -} - -static int -SProcXvSelectPortNotify(ClientPtr client) -{ - register char n; - REQUEST(xvSelectPortNotifyReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvSelectPortNotify(client); -} - -static int -SProcXvStopVideo(ClientPtr client) -{ - register char n; - REQUEST(xvStopVideoReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->drawable, n); - return ProcXvStopVideo(client); -} - -static int -SProcXvSetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvSetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvSetPortAttribute(client); -} - -static int -SProcXvGetPortAttribute(ClientPtr client) -{ - register char n; - REQUEST(xvGetPortAttributeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swapl(&stuff->attribute, n); - return ProcXvGetPortAttribute(client); -} - -static int -SProcXvQueryBestSize(ClientPtr client) -{ - register char n; - REQUEST(xvQueryBestSizeReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - swaps(&stuff->vid_w, n); - swaps(&stuff->vid_h, n); - swaps(&stuff->drw_w, n); - swaps(&stuff->drw_h, n); - return ProcXvQueryBestSize(client); -} - -static int -SProcXvQueryPortAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryPortAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvQueryPortAttributes(client); -} - -static int -SProcXvQueryImageAttributes(ClientPtr client) -{ - register char n; - REQUEST(xvQueryImageAttributesReq); - swaps(&stuff->length, n); - swapl(&stuff->id, n); - swaps(&stuff->width, n); - swaps(&stuff->width, n); - return ProcXvQueryImageAttributes(client); -} - -static int -SProcXvListImageFormats(ClientPtr client) -{ - register char n; - REQUEST(xvListImageFormatsReq); - swaps(&stuff->length, n); - swapl(&stuff->port, n); - return ProcXvListImageFormats(client); -} - - -static int -SWriteQueryExtensionReply( - ClientPtr client, - xvQueryExtensionReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->version, n); - swaps(&rep->revision, n); - - (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryAdaptorsReply( - ClientPtr client, - xvQueryAdaptorsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_adaptors, n); - - (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryEncodingsReply( - ClientPtr client, - xvQueryEncodingsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->num_encodings, n); - - (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep); - - return Success; -} - -static int -SWriteAdaptorInfo( - ClientPtr client, - xvAdaptorInfo *pAdaptor -){ - register char n; - - swapl(&pAdaptor->base_id, n); - swaps(&pAdaptor->name_size, n); - swaps(&pAdaptor->num_ports, n); - swaps(&pAdaptor->num_formats, n); - - (void)WriteToClient(client, sz_xvAdaptorInfo, (char *)pAdaptor); - - return Success; -} - -static int -SWriteEncodingInfo( - ClientPtr client, - xvEncodingInfo *pEncoding -){ - register char n; - - swapl(&pEncoding->encoding, n); - swaps(&pEncoding->name_size, n); - swaps(&pEncoding->width, n); - swaps(&pEncoding->height, n); - swapl(&pEncoding->rate.numerator, n); - swapl(&pEncoding->rate.denominator, n); - (void)WriteToClient(client, sz_xvEncodingInfo, (char *)pEncoding); - - return Success; -} - -static int -SWriteFormat( - ClientPtr client, - xvFormat *pFormat -){ - register char n; - - swapl(&pFormat->visual, n); - (void)WriteToClient(client, sz_xvFormat, (char *)pFormat); - - return Success; -} - -static int -SWriteAttributeInfo( - ClientPtr client, - xvAttributeInfo *pAtt -){ - register char n; - - swapl(&pAtt->flags, n); - swapl(&pAtt->size, n); - swapl(&pAtt->min, n); - swapl(&pAtt->max, n); - (void)WriteToClient(client, sz_xvAttributeInfo, (char *)pAtt); - - return Success; -} - -static int -SWriteImageFormatInfo( - ClientPtr client, - xvImageFormatInfo *pImage -){ - register char n; - - swapl(&pImage->id, n); - swapl(&pImage->red_mask, n); - swapl(&pImage->green_mask, n); - swapl(&pImage->blue_mask, n); - swapl(&pImage->y_sample_bits, n); - swapl(&pImage->u_sample_bits, n); - swapl(&pImage->v_sample_bits, n); - swapl(&pImage->horz_y_period, n); - swapl(&pImage->horz_u_period, n); - swapl(&pImage->horz_v_period, n); - swapl(&pImage->vert_y_period, n); - swapl(&pImage->vert_u_period, n); - swapl(&pImage->vert_v_period, n); - - (void)WriteToClient(client, sz_xvImageFormatInfo, (char *)pImage); - - return Success; -} - - - -static int -SWriteGrabPortReply( - ClientPtr client, - xvGrabPortReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - - (void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep); - - return Success; -} - -static int -SWriteGetPortAttributeReply( - ClientPtr client, - xvGetPortAttributeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->value, n); - - (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryBestSizeReply( - ClientPtr client, - xvQueryBestSizeReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swaps(&rep->actual_width, n); - swaps(&rep->actual_height, n); - - (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryPortAttributesReply( - ClientPtr client, - xvQueryPortAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_attributes, n); - swapl(&rep->text_size, n); - - (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep); - - return Success; -} - -static int -SWriteQueryImageAttributesReply( - ClientPtr client, - xvQueryImageAttributesReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_planes, n); - swapl(&rep->data_size, n); - swaps(&rep->width, n); - swaps(&rep->height, n); - - (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep); - - return Success; -} - - -static int -SWriteListImageFormatsReply( - ClientPtr client, - xvListImageFormatsReply *rep -){ - register char n; - - swaps(&rep->sequenceNumber, n); - swapl(&rep->length, n); - swapl(&rep->num_formats, n); - - (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep); - - return Success; -} - - -#ifdef PANORAMIX - - - - -static int -XineramaXvStopVideo(ClientPtr client) -{ - int result = Success, i; - PanoramiXRes *draw, *port; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - result = ProcXvStopVideo(client); - } - } - - return result; -} - -static int -XineramaXvSetPortAttribute(ClientPtr client) -{ - REQUEST(xvSetPortAttributeReq); - PanoramiXRes *port; - int result = Success, i; - - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->port = port->info[i].id; - result = ProcXvSetPortAttribute(client); - } - } - return result; -} - - -#ifdef MITSHM -static int -XineramaXvShmPutImage(ClientPtr client) -{ - REQUEST(xvShmPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool send_event = stuff->send_event; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_SIZE_MATCH(xvShmPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - stuff->send_event = (send_event && !i) ? 1 : 0; - - result = ProcXvShmPutImage(client); - } - } - return result; -} -#endif - -static int -XineramaXvPutImage(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutImage(client); - } - } - return result; -} - -static int -XineramaXvPutVideo(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutVideoReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutVideo(client); - } - } - return result; -} - -static int -XineramaXvPutStill(ClientPtr client) -{ - REQUEST(xvPutImageReq); - PanoramiXRes *draw, *gc, *port; - Bool isRoot; - int result = Success, i, x, y; - - REQUEST_AT_LEAST_SIZE(xvPutImageReq); - - if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass( - client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess))) - return BadDrawable; - - if(!(gc = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->gc, XRT_GC, SecurityReadAccess))) - return BadGC; - - if(!(port = (PanoramiXRes *)SecurityLookupIDByType( - client, stuff->port, XvXRTPort, SecurityReadAccess))) - return _XvBadPort; - - isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - - x = stuff->drw_x; - y = stuff->drw_y; - - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= panoramiXdataPtr[i].x; - stuff->drw_y -= panoramiXdataPtr[i].y; - } - - result = ProcXvPutStill(client); - } - } - return result; -} - - -void XineramifyXv(void) -{ - ScreenPtr pScreen, screen0 = screenInfo.screens[0]; - XvScreenPtr xvsp0 = (XvScreenPtr)screen0->devPrivates[XvScreenIndex].ptr; - XvAdaptorPtr refAdapt, pAdapt; - XvAttributePtr pAttr; - XvScreenPtr xvsp; - Bool isOverlay, hasOverlay; - PanoramiXRes *port; - XvAdaptorPtr MatchingAdaptors[MAXSCREENS]; - int i, j, k, l; - - XvXRTPort = CreateNewResourceType(XineramaDeleteResource); - - if(!xvsp0) return; - - for(i = 0; i < xvsp0->nAdaptors; i++) { - refAdapt = xvsp0->pAdaptors + i; - - bzero(MatchingAdaptors, sizeof(XvAdaptorPtr) * MAXSCREENS); - - MatchingAdaptors[0] = refAdapt; - - if(!(refAdapt->type & XvInputMask)) continue; - - isOverlay = FALSE; - for(j = 0; j < refAdapt->nAttributes; j++) { - pAttr = refAdapt->pAttributes + j; - if(!strcmp(pAttr->name, "XV_COLORKEY")) { - isOverlay = TRUE; - break; - } - } - - for(j = 1; j < PanoramiXNumScreens; j++) { - pScreen = screenInfo.screens[j]; - xvsp = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr; - - /* Do not try to go on if xv is not supported on this screen */ - if (xvsp==NULL) continue ; - - /* if the adaptor has the same name it's a perfect match */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if(!strcmp(refAdapt->name, pAdapt->name)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - if(MatchingAdaptors[j]) continue; /* found it */ - - /* otherwise we only look for XvImage adaptors */ - if(!(refAdapt->type & XvImageMask)) continue; - if(refAdapt->nImages <= 0) continue; - - /* prefer overlay/overlay non-overlay/non-overlay pairing */ - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - hasOverlay = FALSE; - for(l = 0; l < pAdapt->nAttributes; l++) { - if(!strcmp(pAdapt->name, "XV_COLORKEY")) { - hasOverlay = TRUE; - break; - } - } - if(isOverlay && hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - else if(!isOverlay && !hasOverlay) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - if(MatchingAdaptors[j]) continue; /* found it */ - - /* but we'll take any XvImage pairing if we can get it */ - - for(k = 0; k < xvsp->nAdaptors; k++) { - pAdapt = xvsp->pAdaptors + k; - if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) { - MatchingAdaptors[j] = pAdapt; - break; - } - } - } - - /* now create a resource for each port */ - for(j = 0; j < refAdapt->nPorts; j++) { - if(!(port = xalloc(sizeof(PanoramiXRes)))) - break; - port->info[0].id = MatchingAdaptors[0]->base_id + j; - AddResource(port->info[0].id, XvXRTPort, port); - - for(k = 1; k < PanoramiXNumScreens; k++) { - if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) - port->info[k].id = MatchingAdaptors[k]->base_id + j; - else - port->info[k].id = 0; - } - } - } -} - -#endif diff --git a/nx-X11/programs/Xserver/include/dixstruct.h.NX.original b/nx-X11/programs/Xserver/include/dixstruct.h.NX.original deleted file mode 100644 index 6266ec9f8..000000000 --- a/nx-X11/programs/Xserver/include/dixstruct.h.NX.original +++ /dev/null @@ -1,236 +0,0 @@ -/* $XFree86: xc/programs/Xserver/include/dixstruct.h,v 3.19tsi Exp $ */ -/*********************************************************** -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: dixstruct.h,v 1.3 2000/08/17 19:53:29 cpqbld Exp $ */ - -#ifndef DIXSTRUCT_H -#define DIXSTRUCT_H - -#include "dix.h" -#include "resource.h" -#include "cursor.h" -#include "gc.h" -#include "pixmap.h" -#include - -/* - * direct-mapped hash table, used by resource manager to store - * translation from client ids to server addresses. - */ - -#ifdef DEBUG -#define MAX_REQUEST_LOG 100 -#endif - -extern CallbackListPtr ClientStateCallback; - -typedef struct { - ClientPtr client; - xConnSetupPrefix *prefix; - xConnSetup *setup; -} NewClientInfoRec; - -typedef void (*ReplySwapPtr) ( - ClientPtr /* pClient */, - int /* size */, - void * /* pbuf */); - -extern void ReplyNotSwappd ( - ClientPtr /* pClient */, - int /* size */, - void * /* pbuf */); - -typedef enum {ClientStateInitial, - ClientStateAuthenticating, - ClientStateRunning, - ClientStateRetained, - ClientStateGone, - ClientStateCheckingSecurity, - ClientStateCheckedSecurity} ClientState; - -#ifdef XFIXES -typedef struct _saveSet { - struct _Window *windowPtr; - Bool toRoot; - Bool remap; -} SaveSetElt; -#define SaveSetWindow(ss) ((ss).windowPtr) -#define SaveSetToRoot(ss) ((ss).toRoot) -#define SaveSetRemap(ss) ((ss).remap) -#define SaveSetAssignWindow(ss,w) ((ss).windowPtr = (w)) -#define SaveSetAssignToRoot(ss,tr) ((ss).toRoot = (tr)) -#define SaveSetAssignRemap(ss,rm) ((ss).remap = (rm)) -#else -typedef struct _Window *SaveSetElt; -#define SaveSetWindow(ss) (ss) -#define SaveSetToRoot(ss) FALSE -#define SaveSetRemap(ss) TRUE -#define SaveSetAssignWindow(ss,w) ((ss) = (w)) -#define SaveSetAssignToRoot(ss,tr) -#define SaveSetAssignRemap(ss,rm) -#endif - -typedef struct _Client { - int index; - Mask clientAsMask; - pointer requestBuffer; - pointer osPrivate; /* for OS layer, including scheduler */ - Bool swapped; - ReplySwapPtr pSwapReplyFunc; - XID errorValue; - int sequence; - int closeDownMode; - int clientGone; - int noClientException; /* this client died or needs to be - * killed */ - DrawablePtr lastDrawable; - Drawable lastDrawableID; - GCPtr lastGC; - GContext lastGCID; - SaveSetElt *saveSet; - int numSaved; - pointer screenPrivate[MAXSCREENS]; - int (**requestVector) ( - ClientPtr /* pClient */); - CARD32 req_len; /* length of current request */ - Bool big_requests; /* supports large requests */ - int priority; - ClientState clientState; - DevUnion *devPrivates; -#ifdef XKB - unsigned short xkbClientFlags; - unsigned short mapNotifyMask; - unsigned short newKeyboardNotifyMask; - unsigned short vMajor,vMinor; - KeyCode minKC,maxKC; -#endif - -#ifdef DEBUG - unsigned char requestLog[MAX_REQUEST_LOG]; - int requestLogIndex; -#endif -#ifdef LBX - int (*readRequest)(ClientPtr /*client*/); -#endif - unsigned long replyBytesRemaining; -#ifdef XCSECURITY - XID authId; - unsigned int trustLevel; - pointer (* CheckAccess)( - ClientPtr /*pClient*/, - XID /*id*/, - RESTYPE /*classes*/, - Mask /*access_mode*/, - pointer /*resourceval*/); -#endif -#ifdef XAPPGROUP - struct _AppGroupRec* appgroup; -#endif - struct _FontResolution * (*fontResFunc) ( /* no need for font.h */ - ClientPtr /* pClient */, - int * /* num */); -#ifdef SMART_SCHEDULE - int smart_priority; - long smart_start_tick; - long smart_stop_tick; - long smart_check_tick; -#endif -} ClientRec; - -#ifdef SMART_SCHEDULE -/* - * Scheduling interface - */ -extern long SmartScheduleTime; -extern long SmartScheduleInterval; -extern long SmartScheduleSlice; -extern long SmartScheduleMaxSlice; -extern unsigned long SmartScheduleIdleCount; -extern Bool SmartScheduleDisable; -extern Bool SmartScheduleIdle; -extern Bool SmartScheduleTimerStopped; -extern Bool SmartScheduleStartTimer(void); -#ifdef NXAGENT_SERVER -extern Bool SmartScheduleStopTimer(void); -#endif -#define SMART_MAX_PRIORITY (20) -#define SMART_MIN_PRIORITY (-20) - -extern Bool SmartScheduleInit(void); - -#endif - -/* This prototype is used pervasively in Xext, dix */ -#define DISPATCH_PROC(func) int func(ClientPtr /* client */) - -typedef struct _WorkQueue { - struct _WorkQueue *next; - Bool (*function) ( - ClientPtr /* pClient */, - pointer /* closure */ -); - ClientPtr client; - pointer closure; -} WorkQueueRec; - -extern TimeStamp currentTime; -extern TimeStamp lastDeviceEventTime; - -extern int CompareTimeStamps( - TimeStamp /*a*/, - TimeStamp /*b*/); - -extern TimeStamp ClientTimeToServerTime(CARD32 /*c*/); - -typedef struct _CallbackRec { - CallbackProcPtr proc; - pointer data; - Bool deleted; - struct _CallbackRec *next; -} CallbackRec, *CallbackPtr; - -typedef struct _CallbackList { - CallbackFuncsRec funcs; - int inCallback; - Bool deleted; - int numDeleted; - CallbackPtr list; -} CallbackListRec; - -/* proc vectors */ - -extern int (* InitialVector[3]) (ClientPtr /*client*/); - -extern int (* ProcVector[256]) (ClientPtr /*client*/); - -extern int (* SwappedProcVector[256]) (ClientPtr /*client*/); - -#ifdef K5AUTH -extern int (*k5_Vector[256])(ClientPtr /*client*/); -#endif - -extern ReplySwapPtr ReplySwapVector[256]; - -extern int ProcBadRequest(ClientPtr /*client*/); - -#endif /* DIXSTRUCT_H */ diff --git a/nx-X11/programs/Xserver/include/dixstruct.h.X.original b/nx-X11/programs/Xserver/include/dixstruct.h.X.original deleted file mode 100644 index d7d810272..000000000 --- a/nx-X11/programs/Xserver/include/dixstruct.h.X.original +++ /dev/null @@ -1,233 +0,0 @@ -/* $XFree86: xc/programs/Xserver/include/dixstruct.h,v 3.19tsi Exp $ */ -/*********************************************************** -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: dixstruct.h,v 1.3 2000/08/17 19:53:29 cpqbld Exp $ */ - -#ifndef DIXSTRUCT_H -#define DIXSTRUCT_H - -#include "dix.h" -#include "resource.h" -#include "cursor.h" -#include "gc.h" -#include "pixmap.h" -#include - -/* - * direct-mapped hash table, used by resource manager to store - * translation from client ids to server addresses. - */ - -#ifdef DEBUG -#define MAX_REQUEST_LOG 100 -#endif - -extern CallbackListPtr ClientStateCallback; - -typedef struct { - ClientPtr client; - xConnSetupPrefix *prefix; - xConnSetup *setup; -} NewClientInfoRec; - -typedef void (*ReplySwapPtr) ( - ClientPtr /* pClient */, - int /* size */, - void * /* pbuf */); - -extern void ReplyNotSwappd ( - ClientPtr /* pClient */, - int /* size */, - void * /* pbuf */); - -typedef enum {ClientStateInitial, - ClientStateAuthenticating, - ClientStateRunning, - ClientStateRetained, - ClientStateGone, - ClientStateCheckingSecurity, - ClientStateCheckedSecurity} ClientState; - -#ifdef XFIXES -typedef struct _saveSet { - struct _Window *windowPtr; - Bool toRoot; - Bool remap; -} SaveSetElt; -#define SaveSetWindow(ss) ((ss).windowPtr) -#define SaveSetToRoot(ss) ((ss).toRoot) -#define SaveSetRemap(ss) ((ss).remap) -#define SaveSetAssignWindow(ss,w) ((ss).windowPtr = (w)) -#define SaveSetAssignToRoot(ss,tr) ((ss).toRoot = (tr)) -#define SaveSetAssignRemap(ss,rm) ((ss).remap = (rm)) -#else -typedef struct _Window *SaveSetElt; -#define SaveSetWindow(ss) (ss) -#define SaveSetToRoot(ss) FALSE -#define SaveSetRemap(ss) TRUE -#define SaveSetAssignWindow(ss,w) ((ss) = (w)) -#define SaveSetAssignToRoot(ss,tr) -#define SaveSetAssignRemap(ss,rm) -#endif - -typedef struct _Client { - int index; - Mask clientAsMask; - pointer requestBuffer; - pointer osPrivate; /* for OS layer, including scheduler */ - Bool swapped; - ReplySwapPtr pSwapReplyFunc; - XID errorValue; - int sequence; - int closeDownMode; - int clientGone; - int noClientException; /* this client died or needs to be - * killed */ - DrawablePtr lastDrawable; - Drawable lastDrawableID; - GCPtr lastGC; - GContext lastGCID; - SaveSetElt *saveSet; - int numSaved; - pointer screenPrivate[MAXSCREENS]; - int (**requestVector) ( - ClientPtr /* pClient */); - CARD32 req_len; /* length of current request */ - Bool big_requests; /* supports large requests */ - int priority; - ClientState clientState; - DevUnion *devPrivates; -#ifdef XKB - unsigned short xkbClientFlags; - unsigned short mapNotifyMask; - unsigned short newKeyboardNotifyMask; - unsigned short vMajor,vMinor; - KeyCode minKC,maxKC; -#endif - -#ifdef DEBUG - unsigned char requestLog[MAX_REQUEST_LOG]; - int requestLogIndex; -#endif -#ifdef LBX - int (*readRequest)(ClientPtr /*client*/); -#endif - unsigned long replyBytesRemaining; -#ifdef XCSECURITY - XID authId; - unsigned int trustLevel; - pointer (* CheckAccess)( - ClientPtr /*pClient*/, - XID /*id*/, - RESTYPE /*classes*/, - Mask /*access_mode*/, - pointer /*resourceval*/); -#endif -#ifdef XAPPGROUP - struct _AppGroupRec* appgroup; -#endif - struct _FontResolution * (*fontResFunc) ( /* no need for font.h */ - ClientPtr /* pClient */, - int * /* num */); -#ifdef SMART_SCHEDULE - int smart_priority; - long smart_start_tick; - long smart_stop_tick; - long smart_check_tick; -#endif -} ClientRec; - -#ifdef SMART_SCHEDULE -/* - * Scheduling interface - */ -extern long SmartScheduleTime; -extern long SmartScheduleInterval; -extern long SmartScheduleSlice; -extern long SmartScheduleMaxSlice; -extern unsigned long SmartScheduleIdleCount; -extern Bool SmartScheduleDisable; -extern Bool SmartScheduleIdle; -extern Bool SmartScheduleTimerStopped; -extern Bool SmartScheduleStartTimer(void); -#define SMART_MAX_PRIORITY (20) -#define SMART_MIN_PRIORITY (-20) - -extern Bool SmartScheduleInit(void); - -#endif - -/* This prototype is used pervasively in Xext, dix */ -#define DISPATCH_PROC(func) int func(ClientPtr /* client */) - -typedef struct _WorkQueue { - struct _WorkQueue *next; - Bool (*function) ( - ClientPtr /* pClient */, - pointer /* closure */ -); - ClientPtr client; - pointer closure; -} WorkQueueRec; - -extern TimeStamp currentTime; -extern TimeStamp lastDeviceEventTime; - -extern int CompareTimeStamps( - TimeStamp /*a*/, - TimeStamp /*b*/); - -extern TimeStamp ClientTimeToServerTime(CARD32 /*c*/); - -typedef struct _CallbackRec { - CallbackProcPtr proc; - pointer data; - Bool deleted; - struct _CallbackRec *next; -} CallbackRec, *CallbackPtr; - -typedef struct _CallbackList { - CallbackFuncsRec funcs; - int inCallback; - Bool deleted; - int numDeleted; - CallbackPtr list; -} CallbackListRec; - -/* proc vectors */ - -extern int (* InitialVector[3]) (ClientPtr /*client*/); - -extern int (* ProcVector[256]) (ClientPtr /*client*/); - -extern int (* SwappedProcVector[256]) (ClientPtr /*client*/); - -#ifdef K5AUTH -extern int (*k5_Vector[256])(ClientPtr /*client*/); -#endif - -extern ReplySwapPtr ReplySwapVector[256]; - -extern int ProcBadRequest(ClientPtr /*client*/); - -#endif /* DIXSTRUCT_H */ diff --git a/nx-X11/programs/Xserver/mi/Imakefile.NX.original b/nx-X11/programs/Xserver/mi/Imakefile.NX.original deleted file mode 100644 index b85a9f98b..000000000 --- a/nx-X11/programs/Xserver/mi/Imakefile.NX.original +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:36 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/mi/Imakefile,v 3.34 2002/05/22 21:38:31 herrb Exp $ - -#include - -#if ! HasCbrt -CBRT_SRC = cbrt.c -CBRT_OBJ = cbrt.o -#endif - -#if HasFfs -FFS_DEFINES = -DHAS_FFS -#endif - -#if DoLoadableServer -EXTRAMIINITEXTOBJ = miinitext.o -#else -MIINITEXTSRC = miinitext.c -MIINITEXTOBJ = miinitext.o -#endif - -SRCS = $(CBRT_SRC) mivaltree.c mipolyseg.c mipolyrect.c \ - mipoly.c mipolycon.c mipolygen.c mipolyutil.c \ - mifillrct.c miwideline.c mispans.c \ - miarc.c mizerarc.c mifillarc.c \ - miwindow.c micursor.c miregion.c \ - mipolytext.c mibitblt.c mipolypnt.c mipushpxl.c \ - miexpose.c miglblt.c mizerline.c mizerclip.c mifpolycon.c \ - midash.c mibstore.c mibank.c $(MIINITEXTSRC) mieq.c \ - mipointer.c misprite.c midispcur.c miscrinit.c miclipn.c migc.c \ - micmap.c mioverlay.c - -OBJS = $(CBRT_OBJ) mivaltree.o mipolyseg.o mipolyrect.o \ - mipoly.o mipolycon.o mipolygen.o mipolyutil.o \ - mifillrct.o miwideline.o mispans.o \ - miarc.o mizerarc.o mifillarc.o \ - miwindow.o micursor.o miregion.o \ - mipolytext.o mibitblt.o mipolypnt.o mipushpxl.o \ - miexpose.o miglblt.o mizerline.o mizerclip.o mifpolycon.o \ - midash.o mibstore.o mibank.o $(MIINITEXTOBJ) mieq.o \ - mipointer.o misprite.o midispcur.o miscrinit.o miclipn.o migc.o \ - micmap.o mioverlay.o - -#if (defined (XFree86Version) || defined(XorgVersion)) -/* - * Make sure XINPUT, XF86VidTune, etc aren't defined for the miinitext.o - * used by Xnest, Xvfb - */ - -#if NXLibraries - -/* - * To build the NX agent we need the XINPUT symbol - * in order to build the XInputExtension, since we - * don't use the XF86 module loader. - */ - -EXT_DEFINES = ExtensionDefines -UXF86VIDMODE -UXFreeXDGA -UXF86MISC \ - -UXFree86LOADER - -#else - -EXT_DEFINES = ExtensionDefines -UXINPUT -UXF86VIDMODE -UXFreeXDGA -UXF86MISC \ - -UXFree86LOADER - -#endif - -#endif - -INCLUDES = -I. -I../include -I../../../include/fonts -I../render \ - -I../xfixes -I../damageext -I../miext/damage \ - -I$(XINCLUDESRC) -I$(FONTINCSRC) -I$(EXTINCSRC) -I$(SERVERSRC)/Xext -LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln -DEFINES = $(FFS_DEFINES) - -NormalLibraryObjectRule() -NormalLibraryTarget(mi,$(OBJS)) -LintLibraryTarget(mi,$(SRCS)) -NormalLintTarget($(SRCS)) - -#ifndef Win32Architecture -NormalLibraryTarget(cbrt,cbrt.o) -#endif - -SpecialCObjectRule(miinitext,$(ICONFIGFILES),$(EXT_DEFINES)) -SpecialCObjectRule(miscrinit,$(ICONFIGFILES),$(EXT_DEFINES)) -#ifdef ItsyCompilerBug -SpecialCObjectRule(mipolycon,$(_NOOP_),-O0) -#endif -#if defined(OpenBSDArchitecture) && defined(Sparc64Architecture) -SpecialCObjectRule(mizerclip,NullParameter,-O0) -#endif - -AllTarget($(EXTRAMIINITEXTOBJ)) - -DependTarget() - -InstallDriverSDKNonExecFile(mi.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mibank.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mibstore.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(micmap.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(migc.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(miline.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mipointer.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mipointrst.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mizerarc.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(micoord.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/mi/Imakefile.X.original b/nx-X11/programs/Xserver/mi/Imakefile.X.original deleted file mode 100644 index a6a3c97fa..000000000 --- a/nx-X11/programs/Xserver/mi/Imakefile.X.original +++ /dev/null @@ -1,94 +0,0 @@ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:36 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/mi/Imakefile,v 3.34 2002/05/22 21:38:31 herrb Exp $ - -#include - -#if ! HasCbrt -CBRT_SRC = cbrt.c -CBRT_OBJ = cbrt.o -#endif - -#if HasFfs -FFS_DEFINES = -DHAS_FFS -#endif - -#if DoLoadableServer -EXTRAMIINITEXTOBJ = miinitext.o -#else -MIINITEXTSRC = miinitext.c -MIINITEXTOBJ = miinitext.o -#endif - -SRCS = $(CBRT_SRC) mivaltree.c mipolyseg.c mipolyrect.c \ - mipoly.c mipolycon.c mipolygen.c mipolyutil.c \ - mifillrct.c miwideline.c mispans.c \ - miarc.c mizerarc.c mifillarc.c \ - miwindow.c micursor.c miregion.c \ - mipolytext.c mibitblt.c mipolypnt.c mipushpxl.c \ - miexpose.c miglblt.c mizerline.c mizerclip.c mifpolycon.c \ - midash.c mibstore.c mibank.c $(MIINITEXTSRC) mieq.c \ - mipointer.c misprite.c midispcur.c miscrinit.c miclipn.c migc.c \ - micmap.c mioverlay.c - -OBJS = $(CBRT_OBJ) mivaltree.o mipolyseg.o mipolyrect.o \ - mipoly.o mipolycon.o mipolygen.o mipolyutil.o \ - mifillrct.o miwideline.o mispans.o \ - miarc.o mizerarc.o mifillarc.o \ - miwindow.o micursor.o miregion.o \ - mipolytext.o mibitblt.o mipolypnt.o mipushpxl.o \ - miexpose.o miglblt.o mizerline.o mizerclip.o mifpolycon.o \ - midash.o mibstore.o mibank.o $(MIINITEXTOBJ) mieq.o \ - mipointer.o misprite.o midispcur.o miscrinit.o miclipn.o migc.o \ - micmap.o mioverlay.o - -#if (defined (XFree86Version) || defined(XorgVersion)) -/* - * Make sure XINPUT, XF86VidTune, etc aren't defined for the miinitext.o - * used by Xnest, Xvfb - */ -EXT_DEFINES = ExtensionDefines -UXINPUT -UXF86VIDMODE -UXFreeXDGA -UXF86MISC \ - -UXFree86LOADER -#endif - -INCLUDES = -I. -I../include -I../../../include/fonts -I../render \ - -I../xfixes -I../damageext -I../miext/damage \ - -I$(XINCLUDESRC) -I$(FONTINCSRC) -I$(EXTINCSRC) -I$(SERVERSRC)/Xext -LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln -DEFINES = $(FFS_DEFINES) - -NormalLibraryObjectRule() -NormalLibraryTarget(mi,$(OBJS)) -LintLibraryTarget(mi,$(SRCS)) -NormalLintTarget($(SRCS)) - -#ifndef Win32Architecture -NormalLibraryTarget(cbrt,cbrt.o) -#endif - -SpecialCObjectRule(miinitext,$(ICONFIGFILES),$(EXT_DEFINES)) -SpecialCObjectRule(miscrinit,$(ICONFIGFILES),$(EXT_DEFINES)) -#ifdef ItsyCompilerBug -SpecialCObjectRule(mipolycon,$(_NOOP_),-O0) -#endif -#if defined(OpenBSDArchitecture) && defined(Sparc64Architecture) -SpecialCObjectRule(mizerclip,NullParameter,-O0) -#endif - -AllTarget($(EXTRAMIINITEXTOBJ)) - -DependTarget() - -InstallDriverSDKNonExecFile(mi.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mibank.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mibstore.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(micmap.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(migc.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(miline.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mipointer.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mipointrst.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(mizerarc.h,$(DRIVERSDKINCLUDEDIR)) -InstallDriverSDKNonExecFile(micoord.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/os/Imakefile.NX.original b/nx-X11/programs/Xserver/os/Imakefile.NX.original deleted file mode 100644 index 22be06074..000000000 --- a/nx-X11/programs/Xserver/os/Imakefile.NX.original +++ /dev/null @@ -1,235 +0,0 @@ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:40 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/os/Imakefile,v 3.40 2003/09/09 03:20:41 dawes Exp $ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#include - -/* - * If you have any extra files to be put into the library, define them here. - */ - -#if NXLibraries - -NX_INCLUDES = -I../../../../nxcomp - -NX_DEFINES = -DNX_TRANS_SOCKET \ - -DNX_TRANS_AUTH \ - -DNX_TRANS_FOPEN \ - -DNX_TRANS_SLEEP \ - -DNX_TRANS_EXIT \ - -DNX_TRANS_WAKEUP=1000 - -# -DNX_TRANS_WARN \ -# -DNX_TRANS_INFO \ -# -DNX_TRANS_TEST \ -# -DNX_TRANS_DEBUG \ - -#endif - -/* - * do not modify the following two definitions - */ - -#ifndef OtherSources -#define OtherSources -#endif - -#ifndef OtherObjects -#define OtherObjects -#endif - -#if HasXdmAuth -XDMAUTHDEFS = -DHASXDMAUTH -XDMAUTHOBJS = xdmauth.o -XDMAUTHSRCS = xdmauth.c -#else -XDMAUTHDEFS = -XDMAUTHOBJS = -XDMAUTHSCRS = -#endif - -#if HasSecureRPC -RPCDEFS = -DSECURE_RPC -RPCOBJS = rpcauth.o -RPCSRCS = rpcauth.c -#else -RPCDEFS = -RPCOBJS = -RPCSRCS = -#endif - -#if HasKrb5 -KRB5OBJS = k5auth.o k5encode.o -KRB5SRCS = k5auth.c k5encode.c -#endif - -#if HasBSD44Sockets - SOCK_DEFINES = -DBSD44SOCKETS -#endif - -#if HasGetIfAddrs - IFADDRS_DEFINES = -DHAS_GETIFADDRS -#endif - -#if BuildLBX - LBX_SRCS = lbxio.c - LBX_OBJS = lbxio.o -#else - LBX_SRCS = - LBX_OBJS = -#endif - -#if !defined(DDXOsColor) -COLOR_SRCS=oscolor.c -COLOR_OBJS=oscolor.o -#endif - -#if UseInternalMalloc -MALLOC_SRCS=xalloc.c -MALLOC_OBJS=xalloc.o -#endif - -#if !HasSnprintf -SNPRINTF_SRCS = snprintf.c -SNPRINTF_OBJS = snprintf.o -#endif - -#if !HasStrlcat -STRLCAT_SRCS = strlcat.c strlcpy.c -STRLCAT_OBJS = strlcat.o strlcpy.o -#endif - -#if HasGetpeerucred -GETPEER_DEFINES = -DHAS_GETPEERUCRED -#else -# if HasGetpeereid -GETPEER_DEFINES = -DHAS_GETPEEREID -# endif -#endif - -BOOTSTRAPCFLAGS = - SRCS = WaitFor.c access.c connection.c io.c $(COLOR_SRCS) \ - osinit.c utils.c log.c auth.c mitauth.c secauth.c \ - $(XDMAUTHSRCS) $(RPCSRCS) $(KRB5SRCS) xdmcp.c OtherSources \ - transport.c $(SNPRINTF_SRCS) $(STRLCAT_SRCS) \ - $(MALLOC_SRCS) $(LBX_SRCS) xprintf.c - OBJS = WaitFor.o access.o connection.o io.o $(COLOR_OBJS) \ - osinit.o utils.o log.o auth.o mitauth.o secauth.o \ - $(XDMAUTHOBJS) $(RPCOBJS) $(KRB5OBJS) xdmcp.o OtherObjects \ - transport.o $(SNPRINTF_OBJS) $(STRLCAT_OBJS) \ - $(MALLOC_OBJS) $(LBX_OBJS) xprintf.o - -#if SpecialMalloc - MEM_DEFINES = -DSPECIAL_MALLOC -#endif /* SpecialMalloc */ -#if UseInternalMalloc - MEM_DEFINES = -DINTERNAL_MALLOC -#endif -#if UseMemLeak - MEM_DEFINES = -DMEMBUG -#endif -#if UseRgbTxt - RGB_DEFINES = -DUSE_RGB_TXT -#endif - DBM_DEFINES = NdbmDefines - ADM_DEFINES = -DADMPATH=\"$(ADMDIR)/X\%smsgs\" - XDMCP_DEFINES = ServerXdmcpDefines - KRB5_DEFINES = Krb5Defines - XALLOC_DEFINES = XallocDefines - ERROR_DEFINES = ServerErrorDefines -#if HasPam && HasPamMisc - PAM_DEFINES = -DUSE_PAM -#endif - DEFINES = -DXSERV_t -DTRANS_SERVER $(CONNECTION_FLAGS) $(MEM_DEFINES) \ - $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) \ - $(KRB5_DEFINES) $(RGB_DEFINES) $(GETPEER_DEFINES) \ - $(RANDOM_DEFINES) $(BUGMSG) $(XTRANS_FAILDEFINES) $(NX_DEFINES) - INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \ - -I$(SERVERSRC)/Xext -I$(FONTINCSRC) -I$(SERVERSRC)/render \ - -I$(TOP)/lib/Xau -I../lbx -I../Xprint Krb5Includes $(NX_INCLUDES) - DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) \ - $(TRANS_INCLUDES) $(CONNECTION_FLAGS) $(GETPEER_DEFINES) \ - DependDefines - LINTLIBS = ../dix/llib-ldix.ln - -#ifdef NEED_ALLOCA_FROM_LIBPW - PWLIB = /lib/libPW.a -#endif /* NEED_ALLOCA_FROM_LIBPW */ - -NormalLibraryObjectRule() -NormalLibraryTarget(os,$(OBJS)) -LintLibraryTarget(os,$(SRCS)) -NormalLintTarget($(SRCS)) - -#ifdef NEED_ALLOCA_FROM_LIBPW -XCOMM -XCOMM And this one is to get the version of alloca that lives in /lib/libPW.a -XCOMM without getting all of the rest of the stuff in there. -XCOMM -alloca.o: $(PWLIB) - rm -f alloca.o - ar x $(PWLIB) alloca.o -#endif /* NEED_ALLOCA_FROM_LIBPW */ - -SpecialCObjectRule(access,$(ICONFIGFILES),$(XDMCP_DEFINES) $(SOCK_DEFINES) $(IFADDRS_DEFINES)) -SpecialCObjectRule(auth,$(ICONFIGFILES),$(XDMCP_DEFINES)) -SpecialCObjectRule(xdmauth,$(ICONFIGFILES),$(XDMCP_DEFINES)) -SpecialCObjectRule(xdmcp,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES)) -SpecialCObjectRule(connection,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES)) -SpecialCObjectRule(transport,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES)) -LinkSourceFile(transport.c,$(TRANSCOMMSRC)) -SpecialCObjectRule(osinit,$(ICONFIGFILES),$(ADM_DEFINES)) -SpecialCObjectRule(WaitFor,$(ICONFIGFILES),$(EXT_DEFINES)) -SpecialCObjectRule(io,$(ICONFIGFILES),$(EXT_DEFINES)) -#if BuildLBX -SpecialCObjectRule(lbxio,$(ICONFIGFILES),$(EXT_DEFINES)) -#endif -SpecialCObjectRule(utils,$(ICONFIGFILES),$(XDMCP_DEFINES) $(EXT_DEFINES) $(ERROR_DEFINES) $(PAM_DEFINES)) -SpecialCObjectRule(xalloc,$(ICONFIGFILES),$(XALLOC_DEFINES)) -#if defined(SparcArchitecture) && HasGcc && !HasGcc2 -oscolor.o: oscolor.c $(ICONFIGFILES) - $(RM) $@ - cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c -#else -SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES)) -#endif - -#if HasKrb5 -LinkSourceFile(k5encode.c,$(XAUTHSRC)) -#endif - -#if !HasSnprintf -LinkSourceFile(snprintf.c,$(LIBSRC)/misc) -#endif - -#if !HasStrlcat -LinkSourceFile(strlcat.c,$(LIBSRC)/misc) -LinkSourceFile(strlcpy.c,$(LIBSRC)/misc) -#endif - -#if DoLoadableServer -AllTarget(libcwrapper.o) -ObjectFromSpecialSource(libcwrapper,$(XF86OSSRC)/shared/libc_wrapper,-DSELF_CONTAINED_WRAPPER) -#endif - -DependTarget() diff --git a/nx-X11/programs/Xserver/os/Imakefile.X.original b/nx-X11/programs/Xserver/os/Imakefile.X.original deleted file mode 100644 index c24a016dc..000000000 --- a/nx-X11/programs/Xserver/os/Imakefile.X.original +++ /dev/null @@ -1,200 +0,0 @@ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:40 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/os/Imakefile,v 3.40 2003/09/09 03:20:41 dawes Exp $ - -#include - -/* - * If you have any extra files to be put into the library, define them here. - */ - -/* - * do not modify the following two definitions - */ - -#ifndef OtherSources -#define OtherSources -#endif - -#ifndef OtherObjects -#define OtherObjects -#endif - -#if HasXdmAuth -XDMAUTHDEFS = -DHASXDMAUTH -XDMAUTHOBJS = xdmauth.o -XDMAUTHSRCS = xdmauth.c -#else -XDMAUTHDEFS = -XDMAUTHOBJS = -XDMAUTHSCRS = -#endif - -#if HasSecureRPC -RPCDEFS = -DSECURE_RPC -RPCOBJS = rpcauth.o -RPCSRCS = rpcauth.c -#else -RPCDEFS = -RPCOBJS = -RPCSRCS = -#endif - -#if HasKrb5 -KRB5OBJS = k5auth.o k5encode.o -KRB5SRCS = k5auth.c k5encode.c -#endif - -#if HasBSD44Sockets - SOCK_DEFINES = -DBSD44SOCKETS -#endif - -#if HasGetIfAddrs - IFADDRS_DEFINES = -DHAS_GETIFADDRS -#endif - -#if BuildLBX - LBX_SRCS = lbxio.c - LBX_OBJS = lbxio.o -#else - LBX_SRCS = - LBX_OBJS = -#endif - -#if !defined(DDXOsColor) -COLOR_SRCS=oscolor.c -COLOR_OBJS=oscolor.o -#endif - -#if UseInternalMalloc -MALLOC_SRCS=xalloc.c -MALLOC_OBJS=xalloc.o -#endif - -#if !HasSnprintf -SNPRINTF_SRCS = snprintf.c -SNPRINTF_OBJS = snprintf.o -#endif - -#if !HasStrlcat -STRLCAT_SRCS = strlcat.c strlcpy.c -STRLCAT_OBJS = strlcat.o strlcpy.o -#endif - -#if HasGetpeerucred -GETPEER_DEFINES = -DHAS_GETPEERUCRED -#else -# if HasGetpeereid -GETPEER_DEFINES = -DHAS_GETPEEREID -# endif -#endif - -BOOTSTRAPCFLAGS = - SRCS = WaitFor.c access.c connection.c io.c $(COLOR_SRCS) \ - osinit.c utils.c log.c auth.c mitauth.c secauth.c \ - $(XDMAUTHSRCS) $(RPCSRCS) $(KRB5SRCS) xdmcp.c OtherSources \ - transport.c $(SNPRINTF_SRCS) $(STRLCAT_SRCS) \ - $(MALLOC_SRCS) $(LBX_SRCS) xprintf.c - OBJS = WaitFor.o access.o connection.o io.o $(COLOR_OBJS) \ - osinit.o utils.o log.o auth.o mitauth.o secauth.o \ - $(XDMAUTHOBJS) $(RPCOBJS) $(KRB5OBJS) xdmcp.o OtherObjects \ - transport.o $(SNPRINTF_OBJS) $(STRLCAT_OBJS) \ - $(MALLOC_OBJS) $(LBX_OBJS) xprintf.o - -#if SpecialMalloc - MEM_DEFINES = -DSPECIAL_MALLOC -#endif /* SpecialMalloc */ -#if UseInternalMalloc - MEM_DEFINES = -DINTERNAL_MALLOC -#endif -#if UseMemLeak - MEM_DEFINES = -DMEMBUG -#endif -#if UseRgbTxt - RGB_DEFINES = -DUSE_RGB_TXT -#endif - DBM_DEFINES = NdbmDefines - ADM_DEFINES = -DADMPATH=\"$(ADMDIR)/X\%smsgs\" - XDMCP_DEFINES = ServerXdmcpDefines - KRB5_DEFINES = Krb5Defines - XALLOC_DEFINES = XallocDefines - ERROR_DEFINES = ServerErrorDefines -#if HasPam && HasPamMisc - PAM_DEFINES = -DUSE_PAM -#endif - DEFINES = -DXSERV_t -DTRANS_SERVER $(CONNECTION_FLAGS) $(MEM_DEFINES) \ - $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) \ - $(KRB5_DEFINES) $(RGB_DEFINES) $(GETPEER_DEFINES) \ - $(RANDOM_DEFINES) $(BUGMSG) $(XTRANS_FAILDEFINES) - INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \ - -I$(SERVERSRC)/Xext -I$(FONTINCSRC) -I$(SERVERSRC)/render \ - -I$(TOP)/lib/Xau -I../lbx -I../Xprint Krb5Includes - DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) \ - $(TRANS_INCLUDES) $(CONNECTION_FLAGS) $(GETPEER_DEFINES) \ - DependDefines - LINTLIBS = ../dix/llib-ldix.ln - -#ifdef NEED_ALLOCA_FROM_LIBPW - PWLIB = /lib/libPW.a -#endif /* NEED_ALLOCA_FROM_LIBPW */ - -NormalLibraryObjectRule() -NormalLibraryTarget(os,$(OBJS)) -LintLibraryTarget(os,$(SRCS)) -NormalLintTarget($(SRCS)) - -#ifdef NEED_ALLOCA_FROM_LIBPW -XCOMM -XCOMM And this one is to get the version of alloca that lives in /lib/libPW.a -XCOMM without getting all of the rest of the stuff in there. -XCOMM -alloca.o: $(PWLIB) - rm -f alloca.o - ar x $(PWLIB) alloca.o -#endif /* NEED_ALLOCA_FROM_LIBPW */ - -SpecialCObjectRule(access,$(ICONFIGFILES),$(XDMCP_DEFINES) $(SOCK_DEFINES) $(IFADDRS_DEFINES)) -SpecialCObjectRule(auth,$(ICONFIGFILES),$(XDMCP_DEFINES)) -SpecialCObjectRule(xdmauth,$(ICONFIGFILES),$(XDMCP_DEFINES)) -SpecialCObjectRule(xdmcp,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES)) -SpecialCObjectRule(connection,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES)) -SpecialCObjectRule(transport,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES)) -LinkSourceFile(transport.c,$(TRANSCOMMSRC)) -SpecialCObjectRule(osinit,$(ICONFIGFILES),$(ADM_DEFINES)) -SpecialCObjectRule(WaitFor,$(ICONFIGFILES),$(EXT_DEFINES)) -SpecialCObjectRule(io,$(ICONFIGFILES),$(EXT_DEFINES)) -#if BuildLBX -SpecialCObjectRule(lbxio,$(ICONFIGFILES),$(EXT_DEFINES)) -#endif -SpecialCObjectRule(utils,$(ICONFIGFILES),$(XDMCP_DEFINES) $(EXT_DEFINES) $(ERROR_DEFINES) $(PAM_DEFINES)) -SpecialCObjectRule(xalloc,$(ICONFIGFILES),$(XALLOC_DEFINES)) -#if defined(SparcArchitecture) && HasGcc && !HasGcc2 -oscolor.o: oscolor.c $(ICONFIGFILES) - $(RM) $@ - cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c -#else -SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES)) -#endif - -#if HasKrb5 -LinkSourceFile(k5encode.c,$(XAUTHSRC)) -#endif - -#if !HasSnprintf -LinkSourceFile(snprintf.c,$(LIBSRC)/misc) -#endif - -#if !HasStrlcat -LinkSourceFile(strlcat.c,$(LIBSRC)/misc) -LinkSourceFile(strlcpy.c,$(LIBSRC)/misc) -#endif - -#if DoLoadableServer -AllTarget(libcwrapper.o) -ObjectFromSpecialSource(libcwrapper,$(XF86OSSRC)/shared/libc_wrapper,-DSELF_CONTAINED_WRAPPER) -#endif - -DependTarget() diff --git a/nx-X11/programs/Xserver/os/WaitFor.c.NX.original b/nx-X11/programs/Xserver/os/WaitFor.c.NX.original deleted file mode 100644 index 2ef474229..000000000 --- a/nx-X11/programs/Xserver/os/WaitFor.c.NX.original +++ /dev/null @@ -1,882 +0,0 @@ -/* $XFree86: xc/programs/Xserver/os/WaitFor.c,v 3.42 2003/10/16 01:33:35 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ - -/* $Xorg: WaitFor.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/***************************************************************** - * OS Dependent input routines: - * - * WaitForSomething - * TimerForce, TimerSet, TimerCheck, TimerFree - * - *****************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef WIN32 -#include -#endif -#include /* for strings, fcntl, time */ -#include -#include -#include -#include "misc.h" - -#ifdef __UNIXOS2__ -#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t) -#endif -#include "osdep.h" -#include -#include "dixstruct.h" -#include "opaque.h" -#ifdef DPMSExtension -#include "dpmsproc.h" -#endif - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) - -static unsigned long startTimeInMillis; - -#endif - -#ifdef WIN32 -/* Error codes from windows sockets differ from fileio error codes */ -#undef EINTR -#define EINTR WSAEINTR -#undef EINVAL -#define EINVAL WSAEINVAL -#undef EBADF -#define EBADF WSAENOTSOCK -/* Windows select does not set errno. Use GetErrno as wrapper for - WSAGetLastError */ -#define GetErrno WSAGetLastError -#else -/* This is just a fallback to errno to hide the differences between unix and - Windows in the code */ -#define GetErrno() errno -#endif - -/* modifications by raphael */ -int -mffs(fd_mask mask) -{ - int i; - - if (!mask) return 0; - i = 1; - while (!(mask & 1)) - { - i++; - mask >>= 1; - } - return i; -} - -#ifdef DPMSExtension -#define DPMS_SERVER -#include -#endif - -#ifdef XTESTEXT1 -/* - * defined in xtestext1dd.c - */ -extern int playback_on; -#endif /* XTESTEXT1 */ - -struct _OsTimerRec { - OsTimerPtr next; - CARD32 expires; - OsTimerCallback callback; - pointer arg; -}; - -static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev); -static OsTimerPtr timers = NULL; - -/***************** - * WaitForSomething: - * Make the server suspend until there is - * 1. data from clients or - * 2. input events available or - * 3. ddx notices something of interest (graphics - * queue ready, etc.) or - * 4. clients that have buffered replies/events are ready - * - * If the time between INPUT events is - * greater than ScreenSaverTime, the display is turned off (or - * saved, depending on the hardware). So, WaitForSomething() - * has to handle this also (that's why the select() has a timeout. - * For more info on ClientsWithInput, see ReadRequestFromClient(). - * pClientsReady is an array to store ready client->index values into. - *****************/ - -int -WaitForSomething(int *pClientsReady) -{ - int i; - struct timeval waittime, *wt; - INT32 timeout = 0; - fd_set clientsReadable; - fd_set clientsWritable; - int curclient; - int selecterr; - int nready; - fd_set devicesReadable; - CARD32 now = 0; -#ifdef SMART_SCHEDULE - Bool someReady = FALSE; -#endif - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Got called.\n"); -#endif - - FD_ZERO(&clientsReadable); - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) - - startTimeInMillis = GetTimeInMillis(); - -#endif - - /* We need a while loop here to handle - crashed connections and the screen saver timeout */ - while (1) - { - /* deal with any blocked jobs */ - if (workQueue) - ProcessWorkQueue(); - if (XFD_ANYSET (&ClientsWithInput)) - { -#ifdef SMART_SCHEDULE - if (!SmartScheduleDisable) - { - someReady = TRUE; - waittime.tv_sec = 0; - waittime.tv_usec = 0; - wt = &waittime; - } - else -#endif - { - XFD_COPYSET (&ClientsWithInput, &clientsReadable); - break; - } - } -#ifdef SMART_SCHEDULE - if (someReady) - { - XFD_COPYSET(&AllSockets, &LastSelectMask); - XFD_UNSET(&LastSelectMask, &ClientsWithInput); - } - else - { -#endif - wt = NULL; - if (timers) - { - now = GetTimeInMillis(); - timeout = timers->expires - now; - if (timeout < 0) - timeout = 0; - waittime.tv_sec = timeout / MILLI_PER_SECOND; - waittime.tv_usec = (timeout % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - wt = &waittime; - } - XFD_COPYSET(&AllSockets, &LastSelectMask); -#ifdef SMART_SCHEDULE - } - SmartScheduleIdle = TRUE; -#endif - BlockHandler((pointer)&wt, (pointer)&LastSelectMask); - if (NewOutputPending) - FlushAllOutput(); -#ifdef XTESTEXT1 - /* XXX how does this interact with new write block handling? */ - if (playback_on) { - wt = &waittime; - XTestComputeWaitTime (&waittime); - } -#endif /* XTESTEXT1 */ - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) - - /* - * If caller has marked the first element of pClientsReady[], - * bail out of select after a short timeout. We need this to - * let the NX agent remove the splash screen when the timeout - * is expired. A better option would be to use the existing - * screen-saver timeout but it can be modified by clients, so - * we would need a special handling. This hack is trivial and - * keeps WaitForSomething() backward compatible with the exis- - * ting servers. - */ - - if (pClientsReady[0] == -1) - { - unsigned long timeoutInMillis; - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: pClientsReady[0] is [%d], pClientsReady[1] is [%d].\n", - pClientsReady[0], pClientsReady[1]); -#endif - - timeoutInMillis = GetTimeInMillis(); - - if (timeoutInMillis - startTimeInMillis >= NX_TRANS_WAKEUP) - { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Returning 0 because of wakeup timeout.\n"); -#endif - return 0; - } - - timeoutInMillis = NX_TRANS_WAKEUP - (timeoutInMillis - startTimeInMillis); - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Milliseconds to next wakeup are %ld.\n", - timeoutInMillis); -#endif - if (wt == NULL || (wt -> tv_sec * MILLI_PER_SECOND + - wt -> tv_usec / MILLI_PER_SECOND) > timeoutInMillis) - { - if ((waittime.tv_sec * MILLI_PER_SECOND + - waittime.tv_usec / MILLI_PER_SECOND) > timeoutInMillis) - { - waittime.tv_sec = timeoutInMillis / MILLI_PER_SECOND; - waittime.tv_usec = (timeoutInMillis * MILLI_PER_SECOND) % - (MILLI_PER_SECOND * 1000); - wt = &waittime; - } - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Next wakeup timeout set to %ld milliseconds.\n", - (waittime.tv_sec * MILLI_PER_SECOND) + - (waittime.tv_usec / MILLI_PER_SECOND)); -#endif - } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) - else - { - fprintf(stderr, "WaitForSomething: Using existing timeout of %ld milliseconds.\n", - (waittime.tv_sec * MILLI_PER_SECOND) + - (waittime.tv_usec / MILLI_PER_SECOND)); - } -#endif - } -#endif - - /* keep this check close to select() call to minimize race */ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - if (dispatchException) - { - i = -1; - - fprintf(stderr, "WaitForSomething: Value of dispatchException is true. Set i = -1.\n"); - } -#else - if (dispatchException) - i = -1; -#endif - else if (AnyClientsWriteBlocked) - { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - if (wt == NULL) - { - fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask and " - "clientsWritable and null timeout.\n"); - } - else - { - fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask, " - "clientsWritable, %ld secs and %ld usecs.\n", - wt -> tv_sec, wt -> tv_usec); - } -#endif - XFD_COPYSET(&ClientsWriteBlocked, &clientsWritable); - i = Select (MaxClients, &LastSelectMask, &clientsWritable, NULL, wt); - } - else - { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - if (wt == NULL) - { - fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask and null timeout.\n"); - } - else - { - fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask, %ld secs and %ld usecs.\n", - wt -> tv_sec, wt -> tv_usec); - } -#endif - i = Select (MaxClients, &LastSelectMask, NULL, NULL, wt); - } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Bailed out with i = [%d] and errno = [%d].\n", i, errno); - - if (i < 0) - { - fprintf(stderr, "WaitForSomething: Error is [%s].\n", strerror(errno)); - } -#endif - selecterr = GetErrno(); - WakeupHandler(i, (pointer)&LastSelectMask); -#ifdef XTESTEXT1 - if (playback_on) { - i = XTestProcessInputAction (i, &waittime); - } -#endif /* XTESTEXT1 */ -#ifdef SMART_SCHEDULE - if (i >= 0) - { - SmartScheduleIdle = FALSE; - SmartScheduleIdleCount = 0; - if (SmartScheduleTimerStopped) - (void) SmartScheduleStartTimer (); - } -#endif - if (i <= 0) /* An error or timeout occurred */ - { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - if (dispatchException) - { - fprintf(stderr, "WaitForSomething: Returning 0 because of (dispatchException).\n"); - return 0; - } -#else - if (dispatchException) - return 0; -#endif - if (i < 0) - { - if (selecterr == EBADF) /* Some client disconnected */ - { - CheckConnections (); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - if (! XFD_ANYSET (&AllClients)) - { - fprintf(stderr, "WaitForSomething: Returning 0 because of (! XFD_ANYSET (&AllClients)).\n"); - return 0; - } -#else - if (! XFD_ANYSET (&AllClients)) - return 0; -#endif - } - else if (selecterr == EINVAL) - { - FatalError("WaitForSomething(): select: errno=%d\n", - selecterr); - } - else if (selecterr != EINTR) - { - ErrorF("WaitForSomething(): select: errno=%d\n", - selecterr); - } - } -#ifdef SMART_SCHEDULE - else if (someReady) - { - /* - * If no-one else is home, bail quickly - */ - XFD_COPYSET(&ClientsWithInput, &LastSelectMask); - XFD_COPYSET(&ClientsWithInput, &clientsReadable); - break; - } -#endif -#if defined(NX_TRANS_SOCKET) - if (*checkForInput[0] != *checkForInput[1]) - { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Returning 0 because of (*checkForInput[0] != *checkForInput[1]).\n"); -#endif - return 0; - } -#else - if (*checkForInput[0] != *checkForInput[1]) - return 0; -#endif - - if (timers) - { - int expired = 0; - now = GetTimeInMillis(); - if ((int) (timers->expires - now) <= 0) - expired = 1; - - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); - - if (expired) - return 0; - } - } - else - { - fd_set tmp_set; - - if (*checkForInput[0] == *checkForInput[1]) { - if (timers) - { - int expired = 0; - now = GetTimeInMillis(); - if ((int) (timers->expires - now) <= 0) - expired = 1; - - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); - - if (expired) - return 0; - } - } -#ifdef SMART_SCHEDULE - if (someReady) - XFD_ORSET(&LastSelectMask, &ClientsWithInput, &LastSelectMask); -#endif - if (AnyClientsWriteBlocked && XFD_ANYSET (&clientsWritable)) - { - NewOutputPending = TRUE; - XFD_ORSET(&OutputPending, &clientsWritable, &OutputPending); - XFD_UNSET(&ClientsWriteBlocked, &clientsWritable); - if (! XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; - } - - XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices); - XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients); - XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections); - if (XFD_ANYSET(&tmp_set)) - QueueWorkProc(EstablishNewConnections, NULL, - (pointer)&LastSelectMask); -#ifdef DPMSExtension - if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn)) - DPMSSet(DPMSModeOn); -#endif - if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable)) - break; -#ifdef WIN32 - /* Windows keyboard and mouse events are added to the input queue - in Block- and WakupHandlers. There is no device to check if - data is ready. So check here if new input is available */ -#if defined(NX_TRANS_SOCKET) - if (*checkForInput[0] != *checkForInput[1]) - { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Returning 0 because of (*checkForInput[0] != *checkForInput[1]).\n"); -#endif - return 0; - } -#else - if (*checkForInput[0] != *checkForInput[1]) - return 0; -#endif -#endif - } - } - - nready = 0; - if (XFD_ANYSET (&clientsReadable)) - { -#ifndef WIN32 - for (i=0; ipriority; - if (nready == 0 || client_priority > highest_priority) - { - /* Either we found the first client, or we found - * a client whose priority is greater than all others - * that have been found so far. Either way, we want - * to initialize the list of clients to contain just - * this client. - */ - pClientsReady[0] = client_index; - highest_priority = client_priority; - nready = 1; - } - /* the following if makes sure that multiple same-priority - * clients get batched together - */ - else if (client_priority == highest_priority) -#endif - { - pClientsReady[nready++] = client_index; - } -#ifndef WIN32 - clientsReadable.fds_bits[i] &= ~(((fd_mask)1L) << curclient); - } -#else - FD_CLR(curclient, &clientsReadable); -#endif - } - } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) - fprintf(stderr, "WaitForSomething: Returning nready.\n"); -#endif - return nready; -} - -#if 0 -/* - * This is not always a macro. - */ -ANYSET(FdMask *src) -{ - int i; - - for (i=0; inext; - timer->next = NULL; - newTime = (*timer->callback)(timer, now, timer->arg); - if (newTime) - TimerSet(timer, 0, newTime, timer->callback, timer->arg); -} - -OsTimerPtr -TimerSet(OsTimerPtr timer, int flags, CARD32 millis, - OsTimerCallback func, pointer arg) -{ - register OsTimerPtr *prev; - CARD32 now = GetTimeInMillis(); - - if (!timer) - { - timer = (OsTimerPtr)xalloc(sizeof(struct _OsTimerRec)); - if (!timer) - return NULL; - } - else - { - for (prev = &timers; *prev; prev = &(*prev)->next) - { - if (*prev == timer) - { - *prev = timer->next; - if (flags & TimerForceOld) - (void)(*timer->callback)(timer, now, timer->arg); - break; - } - } - } - if (!millis) - return timer; - if (!(flags & TimerAbsolute)) - millis += now; - timer->expires = millis; - timer->callback = func; - timer->arg = arg; - if ((int) (millis - now) <= 0) - { - timer->next = NULL; - millis = (*timer->callback)(timer, now, timer->arg); - if (!millis) - return timer; - } - for (prev = &timers; - *prev && (int) ((*prev)->expires - millis) <= 0; - prev = &(*prev)->next) - ; - timer->next = *prev; - *prev = timer; - return timer; -} - -Bool -TimerForce(OsTimerPtr timer) -{ - OsTimerPtr *prev; - - for (prev = &timers; *prev; prev = &(*prev)->next) - { - if (*prev == timer) - { - DoTimer(timer, GetTimeInMillis(), prev); - return TRUE; - } - } - return FALSE; -} - - -void -TimerCancel(OsTimerPtr timer) -{ - OsTimerPtr *prev; - - if (!timer) - return; - for (prev = &timers; *prev; prev = &(*prev)->next) - { - if (*prev == timer) - { - *prev = timer->next; - break; - } - } -} - -void -TimerFree(OsTimerPtr timer) -{ - if (!timer) - return; - TimerCancel(timer); - xfree(timer); -} - -void -TimerCheck(void) -{ - CARD32 now = GetTimeInMillis(); - - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); -} - -void -TimerInit(void) -{ - OsTimerPtr timer; - - while ((timer = timers)) - { - timers = timer->next; - xfree(timer); - } -} - -static CARD32 -ScreenSaverTimeoutExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < ScreenSaverTime) { - return ScreenSaverTime - timeout; - } - - ResetOsBuffers(); /* not ideal, but better than nothing */ - SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive); - -#ifdef DPMSExtension - if (ScreenSaverInterval > 0 && DPMSPowerLevel == DPMSModeOn) -#else - if (ScreenSaverInterval > 0) -#endif /* DPMSExtension */ - return ScreenSaverInterval; - - return 0; -} - -static OsTimerPtr ScreenSaverTimer = NULL; - -void -FreeScreenSaverTimer(void) -{ - if (ScreenSaverTimer) { - TimerFree(ScreenSaverTimer); - ScreenSaverTimer = NULL; - } -} - -void -SetScreenSaverTimer(void) -{ - if (ScreenSaverTime > 0) { - ScreenSaverTimer = TimerSet(ScreenSaverTimer, 0, ScreenSaverTime, - ScreenSaverTimeoutExpire, NULL); - } else if (ScreenSaverTimer) { - FreeScreenSaverTimer(); - } -} - -#ifdef DPMSExtension - -static OsTimerPtr DPMSStandbyTimer = NULL; -static OsTimerPtr DPMSSuspendTimer = NULL; -static OsTimerPtr DPMSOffTimer = NULL; - -static CARD32 -DPMSStandbyTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < DPMSStandbyTime) { - return DPMSStandbyTime - timeout; - } - if (DPMSPowerLevel < DPMSModeStandby) { - if (DPMSEnabled) - DPMSSet(DPMSModeStandby); - } - return DPMSStandbyTime; -} - -static CARD32 -DPMSSuspendTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < DPMSSuspendTime) { - return DPMSSuspendTime - timeout; - } - if (DPMSPowerLevel < DPMSModeSuspend) { - if (DPMSEnabled) - DPMSSet(DPMSModeSuspend); - } - return DPMSSuspendTime; -} - -static CARD32 -DPMSOffTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < DPMSOffTime) { - return DPMSOffTime - timeout; - } - if (DPMSPowerLevel < DPMSModeOff) { - if (DPMSEnabled) - DPMSSet(DPMSModeOff); - } - return DPMSOffTime; -} - -void -FreeDPMSTimers(void) -{ - if (DPMSStandbyTimer) { - TimerFree(DPMSStandbyTimer); - DPMSStandbyTimer = NULL; - } - if (DPMSSuspendTimer) { - TimerFree(DPMSSuspendTimer); - DPMSSuspendTimer = NULL; - } - if (DPMSOffTimer) { - TimerFree(DPMSOffTimer); - DPMSOffTimer = NULL; - } -} - -void -SetDPMSTimers(void) -{ - if (!DPMSEnabled) - return; - - DPMSStandbyTimer = TimerSet(DPMSStandbyTimer, 0, DPMSStandbyTime, - DPMSStandbyTimerExpire, NULL); - DPMSSuspendTimer = TimerSet(DPMSSuspendTimer, 0, DPMSSuspendTime, - DPMSSuspendTimerExpire, NULL); - DPMSOffTimer = TimerSet(DPMSOffTimer, 0, DPMSOffTime, - DPMSOffTimerExpire, NULL); -} -#endif diff --git a/nx-X11/programs/Xserver/os/WaitFor.c.X.original b/nx-X11/programs/Xserver/os/WaitFor.c.X.original deleted file mode 100644 index 31e16210b..000000000 --- a/nx-X11/programs/Xserver/os/WaitFor.c.X.original +++ /dev/null @@ -1,701 +0,0 @@ -/* $XFree86: xc/programs/Xserver/os/WaitFor.c,v 3.42 2003/10/16 01:33:35 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ - -/* $Xorg: WaitFor.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ - -/***************************************************************** - * OS Dependent input routines: - * - * WaitForSomething - * TimerForce, TimerSet, TimerCheck, TimerFree - * - *****************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef WIN32 -#include -#endif -#include /* for strings, fcntl, time */ -#include -#include -#include -#include "misc.h" - -#ifdef __UNIXOS2__ -#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t) -#endif -#include "osdep.h" -#include -#include "dixstruct.h" -#include "opaque.h" -#ifdef DPMSExtension -#include "dpmsproc.h" -#endif - -#ifdef WIN32 -/* Error codes from windows sockets differ from fileio error codes */ -#undef EINTR -#define EINTR WSAEINTR -#undef EINVAL -#define EINVAL WSAEINVAL -#undef EBADF -#define EBADF WSAENOTSOCK -/* Windows select does not set errno. Use GetErrno as wrapper for - WSAGetLastError */ -#define GetErrno WSAGetLastError -#else -/* This is just a fallback to errno to hide the differences between unix and - Windows in the code */ -#define GetErrno() errno -#endif - -/* modifications by raphael */ -int -mffs(fd_mask mask) -{ - int i; - - if (!mask) return 0; - i = 1; - while (!(mask & 1)) - { - i++; - mask >>= 1; - } - return i; -} - -#ifdef DPMSExtension -#define DPMS_SERVER -#include -#endif - -#ifdef XTESTEXT1 -/* - * defined in xtestext1dd.c - */ -extern int playback_on; -#endif /* XTESTEXT1 */ - -struct _OsTimerRec { - OsTimerPtr next; - CARD32 expires; - OsTimerCallback callback; - pointer arg; -}; - -static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev); -static OsTimerPtr timers = NULL; - -/***************** - * WaitForSomething: - * Make the server suspend until there is - * 1. data from clients or - * 2. input events available or - * 3. ddx notices something of interest (graphics - * queue ready, etc.) or - * 4. clients that have buffered replies/events are ready - * - * If the time between INPUT events is - * greater than ScreenSaverTime, the display is turned off (or - * saved, depending on the hardware). So, WaitForSomething() - * has to handle this also (that's why the select() has a timeout. - * For more info on ClientsWithInput, see ReadRequestFromClient(). - * pClientsReady is an array to store ready client->index values into. - *****************/ - -int -WaitForSomething(int *pClientsReady) -{ - int i; - struct timeval waittime, *wt; - INT32 timeout = 0; - fd_set clientsReadable; - fd_set clientsWritable; - int curclient; - int selecterr; - int nready; - fd_set devicesReadable; - CARD32 now = 0; -#ifdef SMART_SCHEDULE - Bool someReady = FALSE; -#endif - - FD_ZERO(&clientsReadable); - - /* We need a while loop here to handle - crashed connections and the screen saver timeout */ - while (1) - { - /* deal with any blocked jobs */ - if (workQueue) - ProcessWorkQueue(); - if (XFD_ANYSET (&ClientsWithInput)) - { -#ifdef SMART_SCHEDULE - if (!SmartScheduleDisable) - { - someReady = TRUE; - waittime.tv_sec = 0; - waittime.tv_usec = 0; - wt = &waittime; - } - else -#endif - { - XFD_COPYSET (&ClientsWithInput, &clientsReadable); - break; - } - } -#ifdef SMART_SCHEDULE - if (someReady) - { - XFD_COPYSET(&AllSockets, &LastSelectMask); - XFD_UNSET(&LastSelectMask, &ClientsWithInput); - } - else - { -#endif - wt = NULL; - if (timers) - { - now = GetTimeInMillis(); - timeout = timers->expires - now; - if (timeout < 0) - timeout = 0; - waittime.tv_sec = timeout / MILLI_PER_SECOND; - waittime.tv_usec = (timeout % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - wt = &waittime; - } - XFD_COPYSET(&AllSockets, &LastSelectMask); -#ifdef SMART_SCHEDULE - } - SmartScheduleIdle = TRUE; -#endif - BlockHandler((pointer)&wt, (pointer)&LastSelectMask); - if (NewOutputPending) - FlushAllOutput(); -#ifdef XTESTEXT1 - /* XXX how does this interact with new write block handling? */ - if (playback_on) { - wt = &waittime; - XTestComputeWaitTime (&waittime); - } -#endif /* XTESTEXT1 */ - /* keep this check close to select() call to minimize race */ - if (dispatchException) - i = -1; - else if (AnyClientsWriteBlocked) - { - XFD_COPYSET(&ClientsWriteBlocked, &clientsWritable); - i = Select (MaxClients, &LastSelectMask, &clientsWritable, NULL, wt); - } - else - { - i = Select (MaxClients, &LastSelectMask, NULL, NULL, wt); - } - selecterr = GetErrno(); - WakeupHandler(i, (pointer)&LastSelectMask); -#ifdef XTESTEXT1 - if (playback_on) { - i = XTestProcessInputAction (i, &waittime); - } -#endif /* XTESTEXT1 */ -#ifdef SMART_SCHEDULE - if (i >= 0) - { - SmartScheduleIdle = FALSE; - SmartScheduleIdleCount = 0; - if (SmartScheduleTimerStopped) - (void) SmartScheduleStartTimer (); - } -#endif - if (i <= 0) /* An error or timeout occurred */ - { - if (dispatchException) - return 0; - if (i < 0) - { - if (selecterr == EBADF) /* Some client disconnected */ - { - CheckConnections (); - if (! XFD_ANYSET (&AllClients)) - return 0; - } - else if (selecterr == EINVAL) - { - FatalError("WaitForSomething(): select: errno=%d\n", - selecterr); - } - else if (selecterr != EINTR) - { - ErrorF("WaitForSomething(): select: errno=%d\n", - selecterr); - } - } -#ifdef SMART_SCHEDULE - else if (someReady) - { - /* - * If no-one else is home, bail quickly - */ - XFD_COPYSET(&ClientsWithInput, &LastSelectMask); - XFD_COPYSET(&ClientsWithInput, &clientsReadable); - break; - } -#endif - if (*checkForInput[0] != *checkForInput[1]) - return 0; - - if (timers) - { - int expired = 0; - now = GetTimeInMillis(); - if ((int) (timers->expires - now) <= 0) - expired = 1; - - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); - - if (expired) - return 0; - } - } - else - { - fd_set tmp_set; - - if (*checkForInput[0] == *checkForInput[1]) { - if (timers) - { - int expired = 0; - now = GetTimeInMillis(); - if ((int) (timers->expires - now) <= 0) - expired = 1; - - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); - - if (expired) - return 0; - } - } -#ifdef SMART_SCHEDULE - if (someReady) - XFD_ORSET(&LastSelectMask, &ClientsWithInput, &LastSelectMask); -#endif - if (AnyClientsWriteBlocked && XFD_ANYSET (&clientsWritable)) - { - NewOutputPending = TRUE; - XFD_ORSET(&OutputPending, &clientsWritable, &OutputPending); - XFD_UNSET(&ClientsWriteBlocked, &clientsWritable); - if (! XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; - } - - XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices); - XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients); - XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections); - if (XFD_ANYSET(&tmp_set)) - QueueWorkProc(EstablishNewConnections, NULL, - (pointer)&LastSelectMask); -#ifdef DPMSExtension - if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn)) - DPMSSet(DPMSModeOn); -#endif - if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable)) - break; -#ifdef WIN32 - /* Windows keyboard and mouse events are added to the input queue - in Block- and WakupHandlers. There is no device to check if - data is ready. So check here if new input is available */ - if (*checkForInput[0] != *checkForInput[1]) - return 0; -#endif - } - } - - nready = 0; - if (XFD_ANYSET (&clientsReadable)) - { -#ifndef WIN32 - for (i=0; ipriority; - if (nready == 0 || client_priority > highest_priority) - { - /* Either we found the first client, or we found - * a client whose priority is greater than all others - * that have been found so far. Either way, we want - * to initialize the list of clients to contain just - * this client. - */ - pClientsReady[0] = client_index; - highest_priority = client_priority; - nready = 1; - } - /* the following if makes sure that multiple same-priority - * clients get batched together - */ - else if (client_priority == highest_priority) -#endif - { - pClientsReady[nready++] = client_index; - } -#ifndef WIN32 - clientsReadable.fds_bits[i] &= ~(((fd_mask)1L) << curclient); - } -#else - FD_CLR(curclient, &clientsReadable); -#endif - } - } - return nready; -} - -#if 0 -/* - * This is not always a macro. - */ -ANYSET(FdMask *src) -{ - int i; - - for (i=0; inext; - timer->next = NULL; - newTime = (*timer->callback)(timer, now, timer->arg); - if (newTime) - TimerSet(timer, 0, newTime, timer->callback, timer->arg); -} - -OsTimerPtr -TimerSet(OsTimerPtr timer, int flags, CARD32 millis, - OsTimerCallback func, pointer arg) -{ - register OsTimerPtr *prev; - CARD32 now = GetTimeInMillis(); - - if (!timer) - { - timer = (OsTimerPtr)xalloc(sizeof(struct _OsTimerRec)); - if (!timer) - return NULL; - } - else - { - for (prev = &timers; *prev; prev = &(*prev)->next) - { - if (*prev == timer) - { - *prev = timer->next; - if (flags & TimerForceOld) - (void)(*timer->callback)(timer, now, timer->arg); - break; - } - } - } - if (!millis) - return timer; - if (!(flags & TimerAbsolute)) - millis += now; - timer->expires = millis; - timer->callback = func; - timer->arg = arg; - if ((int) (millis - now) <= 0) - { - timer->next = NULL; - millis = (*timer->callback)(timer, now, timer->arg); - if (!millis) - return timer; - } - for (prev = &timers; - *prev && (int) ((*prev)->expires - millis) <= 0; - prev = &(*prev)->next) - ; - timer->next = *prev; - *prev = timer; - return timer; -} - -Bool -TimerForce(OsTimerPtr timer) -{ - OsTimerPtr *prev; - - for (prev = &timers; *prev; prev = &(*prev)->next) - { - if (*prev == timer) - { - DoTimer(timer, GetTimeInMillis(), prev); - return TRUE; - } - } - return FALSE; -} - - -void -TimerCancel(OsTimerPtr timer) -{ - OsTimerPtr *prev; - - if (!timer) - return; - for (prev = &timers; *prev; prev = &(*prev)->next) - { - if (*prev == timer) - { - *prev = timer->next; - break; - } - } -} - -void -TimerFree(OsTimerPtr timer) -{ - if (!timer) - return; - TimerCancel(timer); - xfree(timer); -} - -void -TimerCheck(void) -{ - CARD32 now = GetTimeInMillis(); - - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); -} - -void -TimerInit(void) -{ - OsTimerPtr timer; - - while ((timer = timers)) - { - timers = timer->next; - xfree(timer); - } -} - -static CARD32 -ScreenSaverTimeoutExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < ScreenSaverTime) { - return ScreenSaverTime - timeout; - } - - ResetOsBuffers(); /* not ideal, but better than nothing */ - SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive); - -#ifdef DPMSExtension - if (ScreenSaverInterval > 0 && DPMSPowerLevel == DPMSModeOn) -#else - if (ScreenSaverInterval > 0) -#endif /* DPMSExtension */ - return ScreenSaverInterval; - - return 0; -} - -static OsTimerPtr ScreenSaverTimer = NULL; - -void -FreeScreenSaverTimer(void) -{ - if (ScreenSaverTimer) { - TimerFree(ScreenSaverTimer); - ScreenSaverTimer = NULL; - } -} - -void -SetScreenSaverTimer(void) -{ - if (ScreenSaverTime > 0) { - ScreenSaverTimer = TimerSet(ScreenSaverTimer, 0, ScreenSaverTime, - ScreenSaverTimeoutExpire, NULL); - } else if (ScreenSaverTimer) { - FreeScreenSaverTimer(); - } -} - -#ifdef DPMSExtension - -static OsTimerPtr DPMSStandbyTimer = NULL; -static OsTimerPtr DPMSSuspendTimer = NULL; -static OsTimerPtr DPMSOffTimer = NULL; - -static CARD32 -DPMSStandbyTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < DPMSStandbyTime) { - return DPMSStandbyTime - timeout; - } - if (DPMSPowerLevel < DPMSModeStandby) { - if (DPMSEnabled) - DPMSSet(DPMSModeStandby); - } - return DPMSStandbyTime; -} - -static CARD32 -DPMSSuspendTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < DPMSSuspendTime) { - return DPMSSuspendTime - timeout; - } - if (DPMSPowerLevel < DPMSModeSuspend) { - if (DPMSEnabled) - DPMSSet(DPMSModeSuspend); - } - return DPMSSuspendTime; -} - -static CARD32 -DPMSOffTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) -{ - INT32 timeout = now - lastDeviceEventTime.milliseconds; - - if (timeout < DPMSOffTime) { - return DPMSOffTime - timeout; - } - if (DPMSPowerLevel < DPMSModeOff) { - if (DPMSEnabled) - DPMSSet(DPMSModeOff); - } - return DPMSOffTime; -} - -void -FreeDPMSTimers(void) -{ - if (DPMSStandbyTimer) { - TimerFree(DPMSStandbyTimer); - DPMSStandbyTimer = NULL; - } - if (DPMSSuspendTimer) { - TimerFree(DPMSSuspendTimer); - DPMSSuspendTimer = NULL; - } - if (DPMSOffTimer) { - TimerFree(DPMSOffTimer); - DPMSOffTimer = NULL; - } -} - -void -SetDPMSTimers(void) -{ - if (!DPMSEnabled) - return; - - DPMSStandbyTimer = TimerSet(DPMSStandbyTimer, 0, DPMSStandbyTime, - DPMSStandbyTimerExpire, NULL); - DPMSSuspendTimer = TimerSet(DPMSSuspendTimer, 0, DPMSSuspendTime, - DPMSSuspendTimerExpire, NULL); - DPMSOffTimer = TimerSet(DPMSOffTimer, 0, DPMSOffTime, - DPMSOffTimerExpire, NULL); -} -#endif diff --git a/nx-X11/programs/Xserver/os/auth.c.NX.original b/nx-X11/programs/Xserver/os/auth.c.NX.original deleted file mode 100644 index dfb6f8899..000000000 --- a/nx-X11/programs/Xserver/os/auth.c.NX.original +++ /dev/null @@ -1,608 +0,0 @@ -/* $Xorg: auth.c,v 1.5 2001/02/09 02:05:23 xorgcvs Exp $ */ -/* - -Copyright 1988, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ -/* $XFree86: auth.c,v 1.13 2003/04/27 21:31:08 herrb Exp $ */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -/* - * authorization hooks for the server - * Author: Keith Packard, MIT X Consortium - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef K5AUTH -# include -#endif -# include -# include -# include "misc.h" -# include "osdep.h" -# include "dixstruct.h" -# include -# include -#ifdef XCSECURITY -#define _SECURITY_SERVER -# include -#endif -#ifdef WIN32 -#include -#endif - -struct protocol { - unsigned short name_length; - char *name; - AuthAddCFunc Add; /* new authorization data */ - AuthCheckFunc Check; /* verify client authorization data */ - AuthRstCFunc Reset; /* delete all authorization data entries */ - AuthToIDFunc ToID; /* convert cookie to ID */ - AuthFromIDFunc FromID; /* convert ID to cookie */ - AuthRemCFunc Remove; /* remove a specific cookie */ -#ifdef XCSECURITY - AuthGenCFunc Generate; -#endif -}; - -static struct protocol protocols[] = { -{ (unsigned short) 18, "MIT-MAGIC-COOKIE-1", - MitAddCookie, MitCheckCookie, MitResetCookie, - MitToID, MitFromID, MitRemoveCookie, -#ifdef XCSECURITY - MitGenerateCookie -#endif -}, -#ifdef HASXDMAUTH -{ (unsigned short) 19, "XDM-AUTHORIZATION-1", - XdmAddCookie, XdmCheckCookie, XdmResetCookie, - XdmToID, XdmFromID, XdmRemoveCookie, -#ifdef XCSECURITY - NULL -#endif -}, -#endif -#ifdef SECURE_RPC -{ (unsigned short) 9, "SUN-DES-1", - SecureRPCAdd, SecureRPCCheck, SecureRPCReset, - SecureRPCToID, SecureRPCFromID,SecureRPCRemove, -#ifdef XCSECURITY - NULL -#endif -}, -#endif -#ifdef K5AUTH -{ (unsigned short) 14, "MIT-KERBEROS-5", - K5Add, K5Check, K5Reset, - K5ToID, K5FromID, K5Remove, -#ifdef XCSECURITY - NULL -#endif -}, -#endif -#ifdef XCSECURITY -{ (unsigned short) XSecurityAuthorizationNameLen, - XSecurityAuthorizationName, - NULL, AuthSecurityCheck, NULL, - NULL, NULL, NULL, - NULL -}, -#endif -}; - -# define NUM_AUTHORIZATION (sizeof (protocols) /\ - sizeof (struct protocol)) - -/* - * Initialize all classes of authorization by reading the - * specified authorization file - */ - -static char *authorization_file = (char *)NULL; - -static Bool ShouldLoadAuth = TRUE; - -void -InitAuthorization (char *file_name) -{ -#ifdef __sun - char * envBuffer; -#endif - authorization_file = file_name; -#ifdef NX_TRANS_AUTH -#ifdef NX_TRANS_TEST - fprintf(stderr, "InitAuthorization: Going to propagate auth file '%s' to the environment.\n", - authorization_file); -#endif -#ifdef __sun - envBuffer = malloc(15+strlen(authorization_file)); - sprintf(envBuffer,"NX_XAUTHORITY=%s",authorization_file); - putenv(envBuffer); -#else - setenv("NX_XAUTHORITY", authorization_file, 1); -#endif -#endif - -} - -static int -LoadAuthorization (void) -{ - FILE *f; - Xauth *auth; - int i; - int count = 0; - - ShouldLoadAuth = FALSE; - if (!authorization_file) - return 0; - -#ifdef NX_TRANS_AUTH - - /* - * We think that the way LoadAuthorization() is working is wrong. - * It doesn't reset the list of stored authorizations before reading - * the new cookies. Our take is that if a new auth file is to be - * read, the only cookies that are to be accepted are those that are - * in the new file, not those in the file -plus- those that have - * been in the file in the past. Furthermore, if the list can't be - * read or it is empty, it should assume that it ignores which co- - * okies are valid and thus it should disable any access. Your mile- - * age can vary. A less draconian approach could be to leave the old - * cookies if the file can't be read and remove them only if the - * file is empty. - * - * Adding the cookies without removing the old values for the same - * protocol has an important implication. If an user shares the co- - * okie with somebody and later wants to revoke the access to the - * display, changing the cookie will not work. This is especially - * important with NX. For security reasons, after reconnecting the - * session to a different display, it is advisable to generate a - * new set of cookies, but doing that it is useless with the current - * code, as the old cookies are going to be still accepted. On the - * same topic, consider that once an user has got access to the X - * server, he/she can freely enable host authentication from any - * host, so the safe behaviour should be to reset the host based - * authenthication at least at reconnection, and keep as valid only - * the cookies that are actually in the file. This behaviour would - * surely break many applications, among them a SSH connection run - * inside a NX session, as ssh -X reads the cookie for the display - * only at session startup and does not read the cookies again - * when the auth file is changed. - * - * Another bug (or feature, depending on how you want to consider - * it) is that if the authority file contains entries for different - * displays (as it is the norm when the authority file is the default - * .Xauthority in the user's home), the server will match -any- of - * the cookies, even cookies that are not for its own display. This - * means that you have be careful when passing an authority file to - * nxagent or Xnest and maybe keep separate files for letting nxagent - * find the cookie to be used to connect to the remote display and - * for letting it find what cookies to accept. If the file is the - * same, clients will be able to connect to nxagent with both the - * cookies. - */ - -#ifdef NX_TRANS_AUTH_RESET - - #ifdef NX_TRANS_TEST - fprintf(stderr, "LoadAuthorization: Resetting authorization info.\n"); - #endif - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].Reset) { - (*protocols[i].Reset) (); - } - } - -#endif - -#endif /* #ifdef NX_TRANS_AUTH */ - - f = Fopen (authorization_file, "r"); - if (!f) - return -1; - - while ((auth = XauReadAuth (f)) != 0) { - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == auth->name_length && - memcmp (protocols[i].name, auth->name, (int) auth->name_length) == 0 && - protocols[i].Add) - { -#ifdef NX_TRANS_AUTH - - #ifdef NX_TRANS_TEST - fprintf(stderr, "LoadAuthorization: Adding new record from file [%s].\n", - authorization_file); - #endif - -#endif - ++count; - (*protocols[i].Add) (auth->data_length, auth->data, - FakeClientID(0)); - } - } - XauDisposeAuth (auth); - } - -#ifdef NX_TRANS_AUTH - - if (count == 0) - { - fprintf(stderr, "Warning: No authorization record could be read from file '%s'.\n", - authorization_file); - - fprintf(stderr, "Warning: Please, create a valid authorization cookie using the command\n" - "Warning: 'xauth -f %s add MIT-MAGIC-COOKIE-1 '.\n", - authorization_file); - } - -#endif - -#ifdef NX_TRANS_AUTH - if (Fclose (f) != 0) - { - /* - * If the Fclose() fails, for example because of a signal, - * it's advisable to return the number of protocols read, - * if any, or otherwise the server would believe that no - * cookie is valid and eventually fall back to host based - * authentication. Note anyway that the new code in Check- - * Authorization() doesn't care the return value and gives - * a chance to the function to check the file at the next - * connection. - */ - - if (count > 0) - { - return count; - } - else - { - return -1; - } - } -#else - Fclose (f); -#endif - return count; -} - -#ifdef XDMCP -/* - * XdmcpInit calls this function to discover all authorization - * schemes supported by the display - */ -void -RegisterAuthorizations (void) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) - XdmcpRegisterAuthorization (protocols[i].name, - (int)protocols[i].name_length); -} -#endif - -XID -CheckAuthorization ( - unsigned int name_length, - char *name, - unsigned int data_length, - char *data, - ClientPtr client, - char **reason) /* failure message. NULL for default msg */ -{ - int i; - struct stat buf; - static time_t lastmod = 0; - - #ifndef NX_TRANS_AUTH - static Bool loaded = FALSE; - #endif - - if (!authorization_file || stat(authorization_file, &buf)) - { - if (lastmod != 0) { - lastmod = 0; - ShouldLoadAuth = TRUE; /* stat lost, so force reload */ - } - } - else if (buf.st_mtime > lastmod) - { - lastmod = buf.st_mtime; - ShouldLoadAuth = TRUE; - } - if (ShouldLoadAuth) - { - int loadauth = LoadAuthorization(); - - /* - * If the authorization file has at least one entry for this server, - * disable local host access. (loadauth > 0) - * - * If there are zero entries (either initially or when the - * authorization file is later reloaded), or if a valid - * authorization file was never loaded, enable local host access. - * (loadauth == 0 || !loaded) - * - * If the authorization file was loaded initially (with valid - * entries for this server), and reloading it later fails, don't - * change anything. (loadauth == -1 && loaded) - */ - -#ifdef NX_TRANS_AUTH - - /* - * The implementation of CheckAuthorization() was changed. The way - * the auth file was handled previously was questionable and could - * open the way to a vast array of security problems. There might be - * ways for an attacker to prevent the server from reading the file - * and it was enough for the server to fail reading the file once - * (because of a not blocked signal, for example) to leave the dis- - * play open to all the users running a session on the same terminal - * server. - * - * In NX we want to have only two cases: either we have to check an - * authorization file or we don't. In the first case we need to do our - * best to read the file at any new client access and never fall back - * to host based authentication. Falling back to local host access has - * no way back, as it will always take precedence over the auth cookie - * (unless the user explicitly disables, one by one, all the rules - * allowing local access, if and only if he/she becomes aware of the - * problem). In the second case we assume that user doesn't care secu- - * rity and so allow unrestricted access from the local machine. - */ - - #ifdef NX_TRANS_TEST - fprintf(stderr, "CheckAuthorization: Going to set authorization with loadauth [%d].\n", - loadauth); - #endif - - if (authorization_file) - { - #ifdef NX_TRANS_TEST - fprintf(stderr, "CheckAuthorization: Disabling local host access.\n"); - #endif - - DisableLocalHost(); - } - else - { - /* - * Enable host-based authentication only if - * the authorization file was not specified - * either on the command line or in the env- - * ironment. - */ - - #ifdef NX_TRANS_TEST - fprintf(stderr, "CheckAuthorization: Enabling local host access.\n"); - #endif - - EnableLocalHost(); - } - - /* - * Avoid the 'unused variable' warning. - */ - - loadauth = loadauth; - -#else /* #ifdef NX_TRANS_AUTH */ - - if (loadauth > 0) - { - DisableLocalHost(); /* got at least one */ - loaded = TRUE; - } - else if (loadauth == 0 || !loaded) - EnableLocalHost (); - -#endif /* #ifdef NX_TRANS_AUTH */ - } - if (name_length) { - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0) - { - return (*protocols[i].Check) (data_length, data, client, reason); - } - *reason = "Protocol not supported by server\n"; - } - } else *reason = "No protocol specified\n"; - return (XID) ~0L; -} - -void -ResetAuthorization (void) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) - if (protocols[i].Reset) - (*protocols[i].Reset)(); - ShouldLoadAuth = TRUE; -} - -XID -AuthorizationToID ( - unsigned short name_length, - char *name, - unsigned short data_length, - char *data) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].ToID) - { - return (*protocols[i].ToID) (data_length, data); - } - } - return (XID) ~0L; -} - -int -AuthorizationFromID ( - XID id, - unsigned short *name_lenp, - char **namep, - unsigned short *data_lenp, - char **datap) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].FromID && - (*protocols[i].FromID) (id, data_lenp, datap)) { - *name_lenp = protocols[i].name_length; - *namep = protocols[i].name; - return 1; - } - } - return 0; -} - -int -RemoveAuthorization ( - unsigned short name_length, - char *name, - unsigned short data_length, - char *data) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].Remove) - { - return (*protocols[i].Remove) (data_length, data); - } - } - return 0; -} - -int -AddAuthorization (unsigned name_length, char *name, unsigned data_length, char *data) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].Add) - { - return (*protocols[i].Add) (data_length, data, FakeClientID(0)); - } - } - return 0; -} - -#ifdef XCSECURITY - -XID -GenerateAuthorization( - unsigned name_length, - char *name, - unsigned data_length, - char *data, - unsigned *data_length_return, - char **data_return) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].Generate) - { - return (*protocols[i].Generate) (data_length, data, - FakeClientID(0), data_length_return, data_return); - } - } - return -1; -} - -/* A random number generator that is more unpredictable - than that shipped with some systems. - This code is taken from the C standard. */ - -static unsigned long int next = 1; - -static int -xdm_rand(void) -{ - next = next * 1103515245 + 12345; - return (unsigned int)(next/65536) % 32768; -} - -static void -xdm_srand(unsigned int seed) -{ - next = seed; -} - -void -GenerateRandomData (int len, char *buf) -{ - static int seed; - int value; - int i; - - seed += GetTimeInMillis(); - xdm_srand (seed); - for (i = 0; i < len; i++) - { - value = xdm_rand (); - buf[i] ^= (value & 0xff00) >> 8; - } - - /* XXX add getrusage, popen("ps -ale") */ -} - -#endif /* XCSECURITY */ diff --git a/nx-X11/programs/Xserver/os/auth.c.X.original b/nx-X11/programs/Xserver/os/auth.c.X.original deleted file mode 100644 index 19c5534d3..000000000 --- a/nx-X11/programs/Xserver/os/auth.c.X.original +++ /dev/null @@ -1,400 +0,0 @@ -/* $Xorg: auth.c,v 1.5 2001/02/09 02:05:23 xorgcvs Exp $ */ -/* - -Copyright 1988, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ -/* $XFree86: auth.c,v 1.13 2003/04/27 21:31:08 herrb Exp $ */ - -/* - * authorization hooks for the server - * Author: Keith Packard, MIT X Consortium - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef K5AUTH -# include -#endif -# include -# include -# include "misc.h" -# include "osdep.h" -# include "dixstruct.h" -# include -# include -#ifdef XCSECURITY -#define _SECURITY_SERVER -# include -#endif -#ifdef WIN32 -#include -#endif - -struct protocol { - unsigned short name_length; - char *name; - AuthAddCFunc Add; /* new authorization data */ - AuthCheckFunc Check; /* verify client authorization data */ - AuthRstCFunc Reset; /* delete all authorization data entries */ - AuthToIDFunc ToID; /* convert cookie to ID */ - AuthFromIDFunc FromID; /* convert ID to cookie */ - AuthRemCFunc Remove; /* remove a specific cookie */ -#ifdef XCSECURITY - AuthGenCFunc Generate; -#endif -}; - -static struct protocol protocols[] = { -{ (unsigned short) 18, "MIT-MAGIC-COOKIE-1", - MitAddCookie, MitCheckCookie, MitResetCookie, - MitToID, MitFromID, MitRemoveCookie, -#ifdef XCSECURITY - MitGenerateCookie -#endif -}, -#ifdef HASXDMAUTH -{ (unsigned short) 19, "XDM-AUTHORIZATION-1", - XdmAddCookie, XdmCheckCookie, XdmResetCookie, - XdmToID, XdmFromID, XdmRemoveCookie, -#ifdef XCSECURITY - NULL -#endif -}, -#endif -#ifdef SECURE_RPC -{ (unsigned short) 9, "SUN-DES-1", - SecureRPCAdd, SecureRPCCheck, SecureRPCReset, - SecureRPCToID, SecureRPCFromID,SecureRPCRemove, -#ifdef XCSECURITY - NULL -#endif -}, -#endif -#ifdef K5AUTH -{ (unsigned short) 14, "MIT-KERBEROS-5", - K5Add, K5Check, K5Reset, - K5ToID, K5FromID, K5Remove, -#ifdef XCSECURITY - NULL -#endif -}, -#endif -#ifdef XCSECURITY -{ (unsigned short) XSecurityAuthorizationNameLen, - XSecurityAuthorizationName, - NULL, AuthSecurityCheck, NULL, - NULL, NULL, NULL, - NULL -}, -#endif -}; - -# define NUM_AUTHORIZATION (sizeof (protocols) /\ - sizeof (struct protocol)) - -/* - * Initialize all classes of authorization by reading the - * specified authorization file - */ - -static char *authorization_file = (char *)NULL; - -static Bool ShouldLoadAuth = TRUE; - -void -InitAuthorization (char *file_name) -{ - authorization_file = file_name; -} - -static int -LoadAuthorization (void) -{ - FILE *f; - Xauth *auth; - int i; - int count = 0; - - ShouldLoadAuth = FALSE; - if (!authorization_file) - return 0; - - f = Fopen (authorization_file, "r"); - if (!f) - return -1; - - while ((auth = XauReadAuth (f)) != 0) { - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == auth->name_length && - memcmp (protocols[i].name, auth->name, (int) auth->name_length) == 0 && - protocols[i].Add) - { - ++count; - (*protocols[i].Add) (auth->data_length, auth->data, - FakeClientID(0)); - } - } - XauDisposeAuth (auth); - } - - Fclose (f); - return count; -} - -#ifdef XDMCP -/* - * XdmcpInit calls this function to discover all authorization - * schemes supported by the display - */ -void -RegisterAuthorizations (void) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) - XdmcpRegisterAuthorization (protocols[i].name, - (int)protocols[i].name_length); -} -#endif - -XID -CheckAuthorization ( - unsigned int name_length, - char *name, - unsigned int data_length, - char *data, - ClientPtr client, - char **reason) /* failure message. NULL for default msg */ -{ - int i; - struct stat buf; - static time_t lastmod = 0; - static Bool loaded = FALSE; - - if (!authorization_file || stat(authorization_file, &buf)) - { - if (lastmod != 0) { - lastmod = 0; - ShouldLoadAuth = TRUE; /* stat lost, so force reload */ - } - } - else if (buf.st_mtime > lastmod) - { - lastmod = buf.st_mtime; - ShouldLoadAuth = TRUE; - } - if (ShouldLoadAuth) - { - int loadauth = LoadAuthorization(); - - /* - * If the authorization file has at least one entry for this server, - * disable local host access. (loadauth > 0) - * - * If there are zero entries (either initially or when the - * authorization file is later reloaded), or if a valid - * authorization file was never loaded, enable local host access. - * (loadauth == 0 || !loaded) - * - * If the authorization file was loaded initially (with valid - * entries for this server), and reloading it later fails, don't - * change anything. (loadauth == -1 && loaded) - */ - - if (loadauth > 0) - { - DisableLocalHost(); /* got at least one */ - loaded = TRUE; - } - else if (loadauth == 0 || !loaded) - EnableLocalHost (); - } - if (name_length) { - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0) - { - return (*protocols[i].Check) (data_length, data, client, reason); - } - *reason = "Protocol not supported by server\n"; - } - } else *reason = "No protocol specified\n"; - return (XID) ~0L; -} - -void -ResetAuthorization (void) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) - if (protocols[i].Reset) - (*protocols[i].Reset)(); - ShouldLoadAuth = TRUE; -} - -XID -AuthorizationToID ( - unsigned short name_length, - char *name, - unsigned short data_length, - char *data) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].ToID) - { - return (*protocols[i].ToID) (data_length, data); - } - } - return (XID) ~0L; -} - -int -AuthorizationFromID ( - XID id, - unsigned short *name_lenp, - char **namep, - unsigned short *data_lenp, - char **datap) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].FromID && - (*protocols[i].FromID) (id, data_lenp, datap)) { - *name_lenp = protocols[i].name_length; - *namep = protocols[i].name; - return 1; - } - } - return 0; -} - -int -RemoveAuthorization ( - unsigned short name_length, - char *name, - unsigned short data_length, - char *data) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].Remove) - { - return (*protocols[i].Remove) (data_length, data); - } - } - return 0; -} - -int -AddAuthorization (unsigned name_length, char *name, unsigned data_length, char *data) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].Add) - { - return (*protocols[i].Add) (data_length, data, FakeClientID(0)); - } - } - return 0; -} - -#ifdef XCSECURITY - -XID -GenerateAuthorization( - unsigned name_length, - char *name, - unsigned data_length, - char *data, - unsigned *data_length_return, - char **data_return) -{ - int i; - - for (i = 0; i < NUM_AUTHORIZATION; i++) { - if (protocols[i].name_length == name_length && - memcmp (protocols[i].name, name, (int) name_length) == 0 && - protocols[i].Generate) - { - return (*protocols[i].Generate) (data_length, data, - FakeClientID(0), data_length_return, data_return); - } - } - return -1; -} - -/* A random number generator that is more unpredictable - than that shipped with some systems. - This code is taken from the C standard. */ - -static unsigned long int next = 1; - -static int -xdm_rand(void) -{ - next = next * 1103515245 + 12345; - return (unsigned int)(next/65536) % 32768; -} - -static void -xdm_srand(unsigned int seed) -{ - next = seed; -} - -void -GenerateRandomData (int len, char *buf) -{ - static int seed; - int value; - int i; - - seed += GetTimeInMillis(); - xdm_srand (seed); - for (i = 0; i < len; i++) - { - value = xdm_rand (); - buf[i] ^= (value & 0xff00) >> 8; - } - - /* XXX add getrusage, popen("ps -ale") */ -} - -#endif /* XCSECURITY */ diff --git a/nx-X11/programs/Xserver/os/connection.c.NX.original b/nx-X11/programs/Xserver/os/connection.c.NX.original deleted file mode 100644 index e3319b338..000000000 --- a/nx-X11/programs/Xserver/os/connection.c.NX.original +++ /dev/null @@ -1,1424 +0,0 @@ -/* $Xorg: connection.c,v 1.6 2001/02/09 02:05:23 xorgcvs Exp $ */ -/*********************************************************** - -Copyright 1987, 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $XFree86: xc/programs/Xserver/os/connection.c,v 3.64 2003/10/07 22:50:42 herrb Exp $ */ -/***************************************************************** - * Stuff to create connections --- OS dependent - * - * EstablishNewConnections, CreateWellKnownSockets, ResetWellKnownSockets, - * CloseDownConnection, CheckConnections, AddEnabledDevice, - * RemoveEnabledDevice, OnlyListToOneClient, - * ListenToAllClients, - * - * (WaitForSomething is in its own file) - * - * In this implementation, a client socket table is not kept. - * Instead, what would be the index into the table is just the - * file descriptor of the socket. This won't work for if the - * socket ids aren't small nums (0 - 2^8) - * - *****************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef WIN32 -#include -#endif -#include -#include -#define XSERV_t -#define TRANS_SERVER -#define TRANS_REOPEN -#include -#include -#include -#include -#include - -#ifndef WIN32 -#if defined(Lynx) -#include -#else -#include -#endif - -#ifdef hpux -#include -#include -#endif - -#if defined(DGUX) -#include -#include -#include -#include -#include -#include -#include -#include -#endif - - -#ifdef AIXV3 -#include -#endif - -#ifdef __UNIXOS2__ -#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t) -extern __const__ int _nfiles; -#endif - -#if defined(TCPCONN) || defined(STREAMSCONN) -# include -# include -# if !defined(hpux) -# ifdef apollo -# ifndef NO_TCP_H -# include -# endif -# else -# ifdef CSRG_BASED -# include -# endif -# ifndef __UNIXOS2__ -# include -# endif -# endif -# endif -# include -#endif - -#if !defined(__UNIXOS2__) -#ifndef Lynx -#include -#else -#include -#endif -#endif -#endif /* WIN32 */ -#include "misc.h" /* for typedef of pointer */ -#include "osdep.h" -#include -#include "opaque.h" -#include "dixstruct.h" -#ifdef XAPPGROUP -#include -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef LBX -#include "colormapst.h" -#include "propertyst.h" -#include "lbxserve.h" -#include "osdep.h" -#endif - -#ifdef X_NOT_POSIX -#define Pid_t int -#else -#define Pid_t pid_t -#endif - -#ifdef DNETCONN -#include -#endif /* DNETCONN */ - -int lastfdesc; /* maximum file descriptor */ - -fd_set WellKnownConnections; /* Listener mask */ -fd_set EnabledDevices; /* mask for input devices that are on */ -fd_set AllSockets; /* select on this */ -fd_set AllClients; /* available clients */ -fd_set LastSelectMask; /* mask returned from last select call */ -fd_set ClientsWithInput; /* clients with FULL requests in buffer */ -fd_set ClientsWriteBlocked; /* clients who cannot receive output */ -fd_set OutputPending; /* clients with reply/event data ready to go */ -int MaxClients = 0; -Bool NewOutputPending; /* not yet attempted to write some new output */ -Bool AnyClientsWriteBlocked; /* true if some client blocked on write */ - -Bool RunFromSmartParent; /* send SIGUSR1 to parent process */ -Bool PartialNetwork; /* continue even if unable to bind all addrs */ -static Pid_t ParentProcess; -#ifdef __UNIXOS2__ -Pid_t GetPPID(Pid_t pid); -#endif - -static Bool debug_conns = FALSE; - -fd_set IgnoredClientsWithInput; -static fd_set GrabImperviousClients; -static fd_set SavedAllClients; -static fd_set SavedAllSockets; -static fd_set SavedClientsWithInput; -int GrabInProgress = 0; - -#if !defined(WIN32) -int *ConnectionTranslation = NULL; -#else -/* - * On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is - * not even a known maximum value, so use something quite arbitrary for now. - * Do storage is a hash table of size 256. Collisions are handled in a linked - * list. - */ - -#undef MAXSOCKS -#define MAXSOCKS 500 -#undef MAXSELECT -#define MAXSELECT 500 -#define MAXFD 500 - -struct _ct_node { - struct _ct_node *next; - int key; - int value; -}; - -struct _ct_node *ct_head[256]; - -void InitConnectionTranslation(void) -{ - bzero(ct_head, sizeof(ct_head)); -} - -int GetConnectionTranslation(int conn) -{ - struct _ct_node *node = ct_head[conn & 0xff]; - while (node != NULL) - { - if (node->key == conn) - return node->value; - node = node->next; - } - return 0; -} - -void SetConnectionTranslation(int conn, int client) -{ - struct _ct_node **node = ct_head + (conn & 0xff); - if (client == 0) /* remove entry */ - { - while (*node != NULL) - { - if ((*node)->key == conn) - { - struct _ct_node *temp = *node; - *node = (*node)->next; - free(temp); - return; - } - node = &((*node)->next); - } - return; - } else - { - while (*node != NULL) - { - if ((*node)->key == conn) - { - (*node)->value = client; - return; - } - node = &((*node)->next); - } - *node = (struct _ct_node*)xalloc(sizeof(struct _ct_node)); - (*node)->next = NULL; - (*node)->key = conn; - (*node)->value = client; - return; - } -} - -void ClearConnectionTranslation(void) -{ - unsigned i; - for (i = 0; i < 256; i++) - { - struct _ct_node *node = ct_head[i]; - while (node != NULL) - { - struct _ct_node *temp = node; - node = node->next; - xfree(temp); - } - } -} -#endif - -XtransConnInfo *ListenTransConns = NULL; -int *ListenTransFds = NULL; -int ListenTransCount; - -static void ErrorConnMax(XtransConnInfo /* trans_conn */); - -#ifndef LBX -static -void CloseDownFileDescriptor( - OsCommPtr /*oc*/ -); -#endif - - -static XtransConnInfo -lookup_trans_conn (int fd) -{ - if (ListenTransFds) - { - int i; - for (i = 0; i < ListenTransCount; i++) - if (ListenTransFds[i] == fd) - return ListenTransConns[i]; - } - - return (NULL); -} - -/* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */ - -void -InitConnectionLimits(void) -{ - lastfdesc = -1; - -#ifndef __CYGWIN__ - -#ifndef __UNIXOS2__ - -#if !defined(XNO_SYSCONF) && defined(_SC_OPEN_MAX) - lastfdesc = sysconf(_SC_OPEN_MAX) - 1; -#endif - -#ifdef HAS_GETDTABLESIZE - if (lastfdesc < 0) - lastfdesc = getdtablesize() - 1; -#endif - -#ifdef _NFILE - if (lastfdesc < 0) - lastfdesc = _NFILE - 1; -#endif - -#else /* __UNIXOS2__ */ - lastfdesc = _nfiles - 1; -#endif - -#endif /* __CYGWIN__ */ - - /* This is the fallback */ - if (lastfdesc < 0) - lastfdesc = MAXSOCKS; - - if (lastfdesc > MAXSELECT) - lastfdesc = MAXSELECT; - - if (lastfdesc > MAXCLIENTS) - { - lastfdesc = MAXCLIENTS; - if (debug_conns) - ErrorF( "REACHED MAXIMUM CLIENTS LIMIT %d\n", MAXCLIENTS); - } - MaxClients = lastfdesc; - -#ifdef DEBUG - ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients); -#endif - -#if !defined(WIN32) - ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1)); -#else - InitConnectionTranslation(); -#endif -} - - -/***************** - * CreateWellKnownSockets - * At initialization, create the sockets to listen on for new clients. - *****************/ - -void -CreateWellKnownSockets(void) -{ - int i; - int partial; - char port[20]; - OsSigHandlerPtr handler; - - FD_ZERO(&AllSockets); - FD_ZERO(&AllClients); - FD_ZERO(&LastSelectMask); - FD_ZERO(&ClientsWithInput); - -#if !defined(WIN32) - for (i=0; i= 0) && - (ListenTransCount >= 1)) - { - if (!PartialNetwork && partial) - { - FatalError ("Failed to establish all listening sockets"); - } - else - { - ListenTransFds = (int *) xalloc (ListenTransCount * sizeof (int)); - - for (i = 0; i < ListenTransCount; i++) - { - int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]); - - ListenTransFds[i] = fd; - FD_SET (fd, &WellKnownConnections); - - if (!_XSERVTransIsLocal (ListenTransConns[i])) - { - DefineSelf (fd); - } - } - } - } - - if (!XFD_ANYSET (&WellKnownConnections)) - FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running"); -#if !defined(WIN32) - OsSignal (SIGPIPE, SIG_IGN); - OsSignal (SIGHUP, AutoResetServer); -#endif - OsSignal (SIGINT, GiveUp); - OsSignal (SIGTERM, GiveUp); - XFD_COPYSET (&WellKnownConnections, &AllSockets); - ResetHosts(display); - /* - * Magic: If SIGUSR1 was set to SIG_IGN when - * the server started, assume that either - * - * a- The parent process is ignoring SIGUSR1 - * - * or - * - * b- The parent process is expecting a SIGUSR1 - * when the server is ready to accept connections - * - * In the first case, the signal will be harmless, - * in the second case, the signal will be quite - * useful - */ -#if !defined(WIN32) - handler = OsSignal (SIGUSR1, SIG_IGN); - if ( handler == SIG_IGN) - RunFromSmartParent = TRUE; - OsSignal(SIGUSR1, handler); - ParentProcess = getppid (); -#ifdef __UNIXOS2__ - /* - * fg030505: under OS/2, xinit is not the parent process but - * the "grant parent" process of the server because execvpe() - * presents us an additional process number; - * GetPPID(pid) is part of libemxfix - */ - ParentProcess = GetPPID (ParentProcess); -#endif /* __UNIXOS2__ */ - if (RunFromSmartParent) { - if (ParentProcess > 1) { - kill (ParentProcess, SIGUSR1); - } - } -#endif -#ifdef XDMCP - XdmcpInit (); -#endif -} - -#ifdef NX_TRANS_SOCKET - -/* - * The following block is now defined also - * under Cygwin to support this environment. - */ - -#ifndef __DARWIN__ - -/* - * This is defined in Xtranssock.c and must - * be called explicitly as it doesn't share - * a pointer in the transport function table. - */ - -extern void _XSERVTransSocketRejectConnection(XtransConnInfo); - -void -RejectWellKnownSockets () -{ - int i; - - for (i = 0; i < ListenTransCount; i++) - { - _XSERVTransSocketRejectConnection(ListenTransConns[i]); - } -} - -#endif /* #ifndef __DARWIN__ */ - -#else /* #ifdef NX_TRANS_SOCKET */ - -void -RejectWellKnownSockets () -{ -} - -#endif /* #ifdef NX_TRANS_SOCKET */ - -void -ResetWellKnownSockets (void) -{ - int i; - - ResetOsBuffers(); - - for (i = 0; i < ListenTransCount; i++) - { - int status = _XSERVTransResetListener (ListenTransConns[i]); - - if (status != TRANS_RESET_NOOP) - { - if (status == TRANS_RESET_FAILURE) - { - /* - * ListenTransConns[i] freed by xtrans. - * Remove it from out list. - */ - - FD_CLR (ListenTransFds[i], &WellKnownConnections); - ListenTransFds[i] = ListenTransFds[ListenTransCount - 1]; - ListenTransConns[i] = ListenTransConns[ListenTransCount - 1]; - ListenTransCount -= 1; - i -= 1; - } - else if (status == TRANS_RESET_NEW_FD) - { - /* - * A new file descriptor was allocated (the old one was closed) - */ - - int newfd = _XSERVTransGetConnectionNumber (ListenTransConns[i]); - - FD_CLR (ListenTransFds[i], &WellKnownConnections); - ListenTransFds[i] = newfd; - FD_SET(newfd, &WellKnownConnections); - } - } - } - - ResetAuthorization (); - ResetHosts(display); - /* - * See above in CreateWellKnownSockets about SIGUSR1 - */ -#if !defined(WIN32) - if (RunFromSmartParent) { - if (ParentProcess > 1) { - kill (ParentProcess, SIGUSR1); - } - } -#endif - /* - * restart XDMCP - */ -#ifdef XDMCP - XdmcpReset (); -#endif -} - -void -CloseWellKnownConnections(void) -{ - int i; - - for (i = 0; i < ListenTransCount; i++) - _XSERVTransClose (ListenTransConns[i]); -} - -static void -AuthAudit (ClientPtr client, Bool letin, - struct sockaddr *saddr, int len, - unsigned int proto_n, char *auth_proto, int auth_id) -{ - char addr[128]; - char *out = addr; - - if (!((OsCommPtr)client->osPrivate)->trans_conn) { - strcpy(addr, "LBX proxy at "); - out += strlen(addr); - } - if (!len) - strcpy(out, "local host"); - else - switch (saddr->sa_family) - { - case AF_UNSPEC: -#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) - case AF_UNIX: -#endif - strcpy(out, "local host"); - break; -#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) - case AF_INET: - sprintf(out, "IP %s", - inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr)); - break; -#if defined(IPv6) && defined(AF_INET6) - case AF_INET6: { - char ipaddr[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, &((struct sockaddr_in6 *) saddr)->sin6_addr, - ipaddr, sizeof(ipaddr)); - sprintf(out, "IP %s", ipaddr); - } - break; -#endif -#endif -#ifdef DNETCONN - case AF_DECnet: - sprintf(out, "DN %s", - dnet_ntoa(&((struct sockaddr_dn *) saddr)->sdn_add)); - break; -#endif - default: - strcpy(out, "unknown address"); - } - - if (proto_n) - AuditF("client %d %s from %s\n Auth name: %.*s ID: %d\n", - client->index, letin ? "connected" : "rejected", addr, - (int)proto_n, auth_proto, auth_id); - else - AuditF("client %d %s from %s\n", - client->index, letin ? "connected" : "rejected", addr); -} - -XID -AuthorizationIDOfClient(ClientPtr client) -{ - if (client->osPrivate) - return ((OsCommPtr)client->osPrivate)->auth_id; - else - return None; -} - - -/***************************************************************** - * ClientAuthorized - * - * Sent by the client at connection setup: - * typedef struct _xConnClientPrefix { - * CARD8 byteOrder; - * BYTE pad; - * CARD16 majorVersion, minorVersion; - * CARD16 nbytesAuthProto; - * CARD16 nbytesAuthString; - * } xConnClientPrefix; - * - * It is hoped that eventually one protocol will be agreed upon. In the - * mean time, a server that implements a different protocol than the - * client expects, or a server that only implements the host-based - * mechanism, will simply ignore this information. - * - *****************************************************************/ - -char * -ClientAuthorized(ClientPtr client, - unsigned int proto_n, char *auth_proto, - unsigned int string_n, char *auth_string) -{ - OsCommPtr priv; - Xtransaddr *from = NULL; - int family; - int fromlen; - XID auth_id; - char *reason = NULL; - XtransConnInfo trans_conn; - int restore_trans_conn = 0; - ClientPtr lbxpc = NULL; - - priv = (OsCommPtr)client->osPrivate; - trans_conn = priv->trans_conn; - -#ifdef LBX - if (!trans_conn) { - /* - * Since trans_conn is NULL, this must be a proxy's client for - * which we have NO address. Therefore, we will temporarily - * set the client's trans_conn to the proxy's trans_conn and - * after CheckAuthorization the client's trans_conn will be - * restored. - * - * If XDM-AUTHORIZATION-1 is being used, CheckAuthorization - * will eventually call XdmAuthorizationValidate and this - * later function may use the client's trans_conn to get the - * client's address. Since a XDM-AUTH-1 auth string includes - * the client's address, this address is compared to the address - * in the client's trans_conn. If the proxy and client are - * on the same host, the comparison will fail; otherwise the - * comparison will fail and the client will not be authorized - * to connect to the server. - * - * The basis for this additional code is to prevent a - * NULL pointer dereference of the client's trans_conn. - * The fundamental problem - the fact that the client's - * trans_conn is NULL - is because the NewClient - * request in version 1.0 of the LBX protocol does not - * send the client's address to the server. When the - * spec is changed and the client's address is sent to - * server in the NewClient request, this additional code - * should be removed. - * - * See defect number XWSog08218 for more information. - */ - lbxpc = LbxProxyClient(priv->proxy); - trans_conn = ((OsCommPtr)lbxpc->osPrivate)->trans_conn; - priv->trans_conn = trans_conn; - restore_trans_conn = 1; - } -#endif - - auth_id = CheckAuthorization (proto_n, auth_proto, - string_n, auth_string, client, &reason); - -#ifdef LBX - if (! priv->trans_conn) { - if (auth_id == (XID) ~0L && !GetAccessControl()) - auth_id = ((OsCommPtr)lbxpc->osPrivate)->auth_id; -#ifdef XCSECURITY - else if (auth_id != (XID) ~0L && !SecuritySameLevel(lbxpc, auth_id)) { - auth_id = (XID) ~0L; - reason = "Client trust level differs from that of LBX Proxy"; - } -#endif - } -#endif - if (auth_id == (XID) ~0L) - { - if ( -#ifdef XCSECURITY - (proto_n == 0 || - strncmp (auth_proto, XSecurityAuthorizationName, proto_n) != 0) && -#endif - _XSERVTransGetPeerAddr (trans_conn, - &family, &fromlen, &from) != -1) - { - if ( -#ifdef LBX - !trans_conn || -#endif - InvalidHost ((struct sockaddr *) from, fromlen, client)) - AuthAudit(client, FALSE, (struct sockaddr *) from, - fromlen, proto_n, auth_proto, auth_id); - else - { - auth_id = (XID) 0; - if (auditTrailLevel > 1) - AuthAudit(client, TRUE, - (struct sockaddr *) from, fromlen, - proto_n, auth_proto, auth_id); - } - - xfree ((char *) from); - } - - if (auth_id == (XID) ~0L) { -#ifdef LBX - /* - * Restore client's trans_conn state - */ - if (restore_trans_conn) { - priv->trans_conn = NULL; - } -#endif - if (reason) - return reason; - else - return "Client is not authorized to connect to Server"; - } - } - else if (auditTrailLevel > 1) - { - if (_XSERVTransGetPeerAddr (trans_conn, - &family, &fromlen, &from) != -1) - { - AuthAudit(client, TRUE, (struct sockaddr *) from, fromlen, - proto_n, auth_proto, auth_id); - - xfree ((char *) from); - } - } - priv->auth_id = auth_id; - priv->conn_time = 0; - -#ifdef XDMCP - /* indicate to Xdmcp protocol that we've opened new client */ - XdmcpOpenDisplay(priv->fd); -#endif /* XDMCP */ -#ifdef XAPPGROUP - if (ClientStateCallback) - XagCallClientStateChange (client); -#endif - /* At this point, if the client is authorized to change the access control - * list, we should getpeername() information, and add the client to - * the selfhosts list. It's not really the host machine, but the - * true purpose of the selfhosts list is to see who may change the - * access control list. - */ -#ifdef LBX - if (restore_trans_conn) { - priv->trans_conn = NULL; - } -#endif - return((char *)NULL); -} - -static ClientPtr -#ifdef LBX -AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time, - int (*Flush)( - ClientPtr /*who*/, OsCommPtr /*oc*/, - char * /*extraBuf*/, int /*extraCount*/), - void (*Close)( - ClientPtr /*client*/), - LbxProxyPtr proxy) -#else -AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time) -#endif -{ - OsCommPtr oc; - ClientPtr client; - - if ( -#ifdef LBX - trans_conn && -#endif -#ifndef WIN32 - fd >= lastfdesc -#else - XFD_SETCOUNT(&AllClients) >= MaxClients -#endif - ) - return NullClient; - oc = (OsCommPtr)xalloc(sizeof(OsCommRec)); - if (!oc) - return NullClient; - oc->trans_conn = trans_conn; - oc->fd = fd; - oc->input = (ConnectionInputPtr)NULL; - oc->output = (ConnectionOutputPtr)NULL; - oc->auth_id = None; - oc->conn_time = conn_time; -#ifdef LBX - oc->proxy = proxy; - oc->Flush = Flush; - oc->Close = Close; - oc->largereq = (ConnectionInputPtr) NULL; -#endif - if (!(client = NextAvailableClient((pointer)oc))) - { - xfree (oc); - return NullClient; - } -#ifdef LBX - if (trans_conn) -#endif - { -#if !defined(WIN32) - ConnectionTranslation[fd] = client->index; -#else - SetConnectionTranslation(fd, client->index); -#endif - if (GrabInProgress) - { - FD_SET(fd, &SavedAllClients); - FD_SET(fd, &SavedAllSockets); - } - else - { - FD_SET(fd, &AllClients); - FD_SET(fd, &AllSockets); - } - } - -#ifdef DEBUG - ErrorF("AllocNewConnection: client index = %d, socket fd = %d\n", - client->index, fd); -#endif - - return client; -} - -#ifdef LBX - -int -ClientConnectionNumber (ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr) client->osPrivate; - - return oc->fd; -} - -ClientPtr -AllocLbxClientConnection (ClientPtr client, LbxProxyPtr proxy) -{ - OsCommPtr oc = (OsCommPtr) client->osPrivate; - - return AllocNewConnection ((XtransConnInfo)NULL, oc->fd, GetTimeInMillis(), - LbxFlushClient, LbxCloseClient, proxy); -} - -void -LbxProxyConnection (ClientPtr client, LbxProxyPtr proxy) -{ - OsCommPtr oc = (OsCommPtr) client->osPrivate; - - FlushClient(client, oc, (char *)NULL, 0); - oc->proxy = proxy; - oc->Flush = LbxFlushClient; - oc->Close = LbxCloseClient; - LbxPrimeInput(client, proxy); -} - -#endif - -/***************** - * EstablishNewConnections - * If anyone is waiting on listened sockets, accept them. - * Returns a mask with indices of new clients. Updates AllClients - * and AllSockets. - *****************/ - -/*ARGSUSED*/ -Bool -EstablishNewConnections(ClientPtr clientUnused, pointer closure) -{ - fd_set readyconnections; /* set of listeners that are ready */ - int curconn; /* fd of listener that's ready */ - register int newconn; /* fd of new client */ - CARD32 connect_time; - register int i; - register ClientPtr client; - register OsCommPtr oc; - fd_set tmask; - - XFD_ANDSET (&tmask, (fd_set*)closure, &WellKnownConnections); - XFD_COPYSET(&tmask, &readyconnections); - if (!XFD_ANYSET(&readyconnections)) - return TRUE; - connect_time = GetTimeInMillis(); - /* kill off stragglers */ - for (i=1; iosPrivate); - if ((oc && (oc->conn_time != 0) && - (connect_time - oc->conn_time) >= TimeOutValue) || - (client->noClientException != Success && !client->clientGone)) - CloseDownClient(client); - } - } -#ifndef WIN32 - for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) - { - while (readyconnections.fds_bits[i]) -#else - for (i = 0; i < XFD_SETCOUNT(&readyconnections); i++) -#endif - { - XtransConnInfo trans_conn, new_trans_conn; - int status; - -#ifndef WIN32 - curconn = ffs (readyconnections.fds_bits[i]) - 1; - readyconnections.fds_bits[i] &= ~((fd_mask)1 << curconn); - curconn += (i * (sizeof(fd_mask)*8)); -#else - curconn = XFD_FD(&readyconnections, i); -#endif - - if ((trans_conn = lookup_trans_conn (curconn)) == NULL) - continue; - - if ((new_trans_conn = _XSERVTransAccept (trans_conn, &status)) == NULL) - continue; - - newconn = _XSERVTransGetConnectionNumber (new_trans_conn); - - if (newconn < lastfdesc) - { - int clientid; -#if !defined(WIN32) - clientid = ConnectionTranslation[newconn]; -#else - clientid = GetConnectionTranslation(newconn); -#endif - if(clientid && (client = clients[clientid])) - CloseDownClient(client); - } - - _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1); - - if (!AllocNewConnection (new_trans_conn, newconn, connect_time -#ifdef LBX - , StandardFlushClient, - CloseDownFileDescriptor, (LbxProxyPtr)NULL -#endif - )) - { - ErrorConnMax(new_trans_conn); - _XSERVTransClose(new_trans_conn); - } - } -#ifndef WIN32 - } -#endif - return TRUE; -} - -#define NOROOM "Maximum number of clients reached" - -/************ - * ErrorConnMax - * Fail a connection due to lack of client or file descriptor space - ************/ - -static void -ErrorConnMax(XtransConnInfo trans_conn) -{ - int fd = _XSERVTransGetConnectionNumber (trans_conn); - xConnSetupPrefix csp; - char pad[3]; - struct iovec iov[3]; - char byteOrder = 0; - int whichbyte = 1; - struct timeval waittime; - fd_set mask; - - /* if these seems like a lot of trouble to go to, it probably is */ - waittime.tv_sec = BOTIMEOUT / MILLI_PER_SECOND; - waittime.tv_usec = (BOTIMEOUT % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - FD_ZERO(&mask); - FD_SET(fd, &mask); - (void)Select(fd + 1, &mask, NULL, NULL, &waittime); - /* try to read the byte-order of the connection */ - (void)_XSERVTransRead(trans_conn, &byteOrder, 1); - if ((byteOrder == 'l') || (byteOrder == 'B')) - { - csp.success = xFalse; - csp.lengthReason = sizeof(NOROOM) - 1; - csp.length = (sizeof(NOROOM) + 2) >> 2; - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (((*(char *) &whichbyte) && (byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (byteOrder == 'l'))) - { - swaps(&csp.majorVersion, whichbyte); - swaps(&csp.minorVersion, whichbyte); - swaps(&csp.length, whichbyte); - } - iov[0].iov_len = sz_xConnSetupPrefix; - iov[0].iov_base = (char *) &csp; - iov[1].iov_len = csp.lengthReason; - iov[1].iov_base = NOROOM; - iov[2].iov_len = (4 - (csp.lengthReason & 3)) & 3; - iov[2].iov_base = pad; - (void)_XSERVTransWritev(trans_conn, iov, 3); - } -} - -/************ - * CloseDownFileDescriptor: - * Remove this file descriptor and it's I/O buffers, etc. - ************/ - -#ifdef LBX -void -CloseDownFileDescriptor(ClientPtr client) -#else -static void -CloseDownFileDescriptor(OsCommPtr oc) -#endif -{ -#ifdef LBX - OsCommPtr oc = (OsCommPtr) client->osPrivate; -#endif - int connection = oc->fd; - - if (oc->trans_conn) { - _XSERVTransDisconnect(oc->trans_conn); - _XSERVTransClose(oc->trans_conn); - } -#ifndef LBX - FreeOsBuffers(oc); - xfree(oc); -#endif -#ifndef WIN32 - ConnectionTranslation[connection] = 0; -#else - SetConnectionTranslation(connection, 0); -#endif - FD_CLR(connection, &AllSockets); - FD_CLR(connection, &AllClients); - FD_CLR(connection, &ClientsWithInput); - FD_CLR(connection, &GrabImperviousClients); - if (GrabInProgress) - { - FD_CLR(connection, &SavedAllSockets); - FD_CLR(connection, &SavedAllClients); - FD_CLR(connection, &SavedClientsWithInput); - } - FD_CLR(connection, &ClientsWriteBlocked); - if (!XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; - FD_CLR(connection, &OutputPending); -} - -/***************** - * CheckConnections - * Some connection has died, go find which one and shut it down - * The file descriptor has been closed, but is still in AllClients. - * If would truly be wonderful if select() would put the bogus - * file descriptors in the exception mask, but nooooo. So we have - * to check each and every socket individually. - *****************/ - -void -CheckConnections(void) -{ -#ifndef WIN32 - fd_mask mask; -#endif - fd_set tmask; - int curclient, curoff; - int i; - struct timeval notime; - int r; -#ifdef WIN32 - fd_set savedAllClients; -#endif - - notime.tv_sec = 0; - notime.tv_usec = 0; - -#ifndef WIN32 - for (i=0; iosPrivate; - - if (oc->output && oc->output->count) - FlushClient(client, oc, (char *)NULL, 0); -#ifdef XDMCP - XdmcpCloseDisplay(oc->fd); -#endif -#ifndef LBX - CloseDownFileDescriptor(oc); -#else - (*oc->Close) (client); - FreeOsBuffers(oc); - xfree(oc); -#endif - client->osPrivate = (pointer)NULL; - if (auditTrailLevel > 1) - AuditF("client %d disconnected\n", client->index); -} - -void -AddEnabledDevice(int fd) -{ - FD_SET(fd, &EnabledDevices); - FD_SET(fd, &AllSockets); - if (GrabInProgress) - FD_SET(fd, &SavedAllSockets); -} - -void -RemoveEnabledDevice(int fd) -{ - FD_CLR(fd, &EnabledDevices); - FD_CLR(fd, &AllSockets); - if (GrabInProgress) - FD_CLR(fd, &SavedAllSockets); -} - -/***************** - * OnlyListenToOneClient: - * Only accept requests from one client. Continue to handle new - * connections, but don't take any protocol requests from the new - * ones. Note that if GrabInProgress is set, EstablishNewConnections - * needs to put new clients into SavedAllSockets and SavedAllClients. - * Note also that there is no timeout for this in the protocol. - * This routine is "undone" by ListenToAllClients() - *****************/ - -void -OnlyListenToOneClient(ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; - - if (! GrabInProgress) - { - XFD_COPYSET(&ClientsWithInput, &SavedClientsWithInput); - XFD_ANDSET(&ClientsWithInput, - &ClientsWithInput, &GrabImperviousClients); - if (FD_ISSET(connection, &SavedClientsWithInput)) - { - FD_CLR(connection, &SavedClientsWithInput); - FD_SET(connection, &ClientsWithInput); - } - XFD_UNSET(&SavedClientsWithInput, &GrabImperviousClients); - XFD_COPYSET(&AllSockets, &SavedAllSockets); - XFD_COPYSET(&AllClients, &SavedAllClients); - XFD_UNSET(&AllSockets, &AllClients); - XFD_ANDSET(&AllClients, &AllClients, &GrabImperviousClients); - FD_SET(connection, &AllClients); - XFD_ORSET(&AllSockets, &AllSockets, &AllClients); - GrabInProgress = client->index; - } -} - -/**************** - * ListenToAllClients: - * Undoes OnlyListentToOneClient() - ****************/ - -void -ListenToAllClients(void) -{ - if (GrabInProgress) - { - XFD_ORSET(&AllSockets, &AllSockets, &SavedAllSockets); - XFD_ORSET(&AllClients, &AllClients, &SavedAllClients); - XFD_ORSET(&ClientsWithInput, &ClientsWithInput, &SavedClientsWithInput); - GrabInProgress = 0; - } -} - -/**************** - * IgnoreClient - * Removes one client from input masks. - * Must have cooresponding call to AttendClient. - ****************/ - -void -IgnoreClient (ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; -#ifdef LBX - LbxClientPtr lbxClient = LbxClient(client); -#endif - - isItTimeToYield = TRUE; -#ifdef LBX - if (lbxClient) { - lbxClient->ignored = TRUE; - return; - } -#endif - if (!GrabInProgress || FD_ISSET(connection, &AllClients)) - { - if (FD_ISSET (connection, &ClientsWithInput)) - FD_SET(connection, &IgnoredClientsWithInput); - else - FD_CLR(connection, &IgnoredClientsWithInput); - FD_CLR(connection, &ClientsWithInput); - FD_CLR(connection, &AllSockets); - FD_CLR(connection, &AllClients); - FD_CLR(connection, &LastSelectMask); - } - else - { - if (FD_ISSET (connection, &SavedClientsWithInput)) - FD_SET(connection, &IgnoredClientsWithInput); - else - FD_CLR(connection, &IgnoredClientsWithInput); - FD_CLR(connection, &SavedClientsWithInput); - FD_CLR(connection, &SavedAllSockets); - FD_CLR(connection, &SavedAllClients); - } -} - -/**************** - * AttendClient - * Adds one client back into the input masks. - ****************/ - -void -AttendClient (ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; -#ifdef LBX - LbxClientPtr lbxClient = LbxClient(client); - - if (lbxClient) { - lbxClient->ignored = FALSE; - return; - } -#endif - if (!GrabInProgress || GrabInProgress == client->index || - FD_ISSET(connection, &GrabImperviousClients)) - { - FD_SET(connection, &AllClients); - FD_SET(connection, &AllSockets); - FD_SET(connection, &LastSelectMask); - if (FD_ISSET (connection, &IgnoredClientsWithInput)) - FD_SET(connection, &ClientsWithInput); - } - else - { - FD_SET(connection, &SavedAllClients); - FD_SET(connection, &SavedAllSockets); - if (FD_ISSET(connection, &IgnoredClientsWithInput)) - FD_SET(connection, &SavedClientsWithInput); - } -} - -/* make client impervious to grabs; assume only executing client calls this */ - -void -MakeClientGrabImpervious(ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; - - FD_SET(connection, &GrabImperviousClients); - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = CLIENT_IMPERVIOUS; - CallCallbacks(&ServerGrabCallback, &grabinfo); - } -} - -/* make client pervious to grabs; assume only executing client calls this */ - -void -MakeClientGrabPervious(ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; - - FD_CLR(connection, &GrabImperviousClients); - if (GrabInProgress && (GrabInProgress != client->index)) - { - if (FD_ISSET(connection, &ClientsWithInput)) - { - FD_SET(connection, &SavedClientsWithInput); - FD_CLR(connection, &ClientsWithInput); - } - FD_CLR(connection, &AllSockets); - FD_CLR(connection, &AllClients); - isItTimeToYield = TRUE; - } - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = CLIENT_PERVIOUS; - CallCallbacks(&ServerGrabCallback, &grabinfo); - } -} - diff --git a/nx-X11/programs/Xserver/os/connection.c.X.original b/nx-X11/programs/Xserver/os/connection.c.X.original deleted file mode 100644 index 0a12c655d..000000000 --- a/nx-X11/programs/Xserver/os/connection.c.X.original +++ /dev/null @@ -1,1385 +0,0 @@ -/* $Xorg: connection.c,v 1.6 2001/02/09 02:05:23 xorgcvs Exp $ */ -/*********************************************************** - -Copyright 1987, 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $XFree86: xc/programs/Xserver/os/connection.c,v 3.64 2003/10/07 22:50:42 herrb Exp $ */ -/***************************************************************** - * Stuff to create connections --- OS dependent - * - * EstablishNewConnections, CreateWellKnownSockets, ResetWellKnownSockets, - * CloseDownConnection, CheckConnections, AddEnabledDevice, - * RemoveEnabledDevice, OnlyListToOneClient, - * ListenToAllClients, - * - * (WaitForSomething is in its own file) - * - * In this implementation, a client socket table is not kept. - * Instead, what would be the index into the table is just the - * file descriptor of the socket. This won't work for if the - * socket ids aren't small nums (0 - 2^8) - * - *****************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef WIN32 -#include -#endif -#include -#include -#define XSERV_t -#define TRANS_SERVER -#define TRANS_REOPEN -#include -#include -#include -#include -#include - -#ifndef WIN32 -#if defined(Lynx) -#include -#else -#include -#endif - -#ifdef hpux -#include -#include -#endif - -#if defined(DGUX) -#include -#include -#include -#include -#include -#include -#include -#include -#endif - - -#ifdef AIXV3 -#include -#endif - -#ifdef __UNIXOS2__ -#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t) -extern __const__ int _nfiles; -#endif - -#if defined(TCPCONN) || defined(STREAMSCONN) -# include -# include -# if !defined(hpux) -# ifdef apollo -# ifndef NO_TCP_H -# include -# endif -# else -# ifdef CSRG_BASED -# include -# endif -# ifndef __UNIXOS2__ -# include -# endif -# endif -# endif -# include -#endif - -#if !defined(__UNIXOS2__) -#ifndef Lynx -#include -#else -#include -#endif -#endif -#endif /* WIN32 */ -#include "misc.h" /* for typedef of pointer */ -#include "osdep.h" -#include -#include "opaque.h" -#include "dixstruct.h" -#ifdef XAPPGROUP -#include -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif -#ifdef LBX -#include "colormapst.h" -#include "propertyst.h" -#include "lbxserve.h" -#include "osdep.h" -#endif - -#ifdef X_NOT_POSIX -#define Pid_t int -#else -#define Pid_t pid_t -#endif - -#ifdef DNETCONN -#include -#endif /* DNETCONN */ - -int lastfdesc; /* maximum file descriptor */ - -fd_set WellKnownConnections; /* Listener mask */ -fd_set EnabledDevices; /* mask for input devices that are on */ -fd_set AllSockets; /* select on this */ -fd_set AllClients; /* available clients */ -fd_set LastSelectMask; /* mask returned from last select call */ -fd_set ClientsWithInput; /* clients with FULL requests in buffer */ -fd_set ClientsWriteBlocked; /* clients who cannot receive output */ -fd_set OutputPending; /* clients with reply/event data ready to go */ -int MaxClients = 0; -Bool NewOutputPending; /* not yet attempted to write some new output */ -Bool AnyClientsWriteBlocked; /* true if some client blocked on write */ - -Bool RunFromSmartParent; /* send SIGUSR1 to parent process */ -Bool PartialNetwork; /* continue even if unable to bind all addrs */ -static Pid_t ParentProcess; -#ifdef __UNIXOS2__ -Pid_t GetPPID(Pid_t pid); -#endif - -static Bool debug_conns = FALSE; - -fd_set IgnoredClientsWithInput; -static fd_set GrabImperviousClients; -static fd_set SavedAllClients; -static fd_set SavedAllSockets; -static fd_set SavedClientsWithInput; -int GrabInProgress = 0; - -#if !defined(WIN32) -int *ConnectionTranslation = NULL; -#else -/* - * On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is - * not even a known maximum value, so use something quite arbitrary for now. - * Do storage is a hash table of size 256. Collisions are handled in a linked - * list. - */ - -#undef MAXSOCKS -#define MAXSOCKS 500 -#undef MAXSELECT -#define MAXSELECT 500 -#define MAXFD 500 - -struct _ct_node { - struct _ct_node *next; - int key; - int value; -}; - -struct _ct_node *ct_head[256]; - -void InitConnectionTranslation(void) -{ - bzero(ct_head, sizeof(ct_head)); -} - -int GetConnectionTranslation(int conn) -{ - struct _ct_node *node = ct_head[conn & 0xff]; - while (node != NULL) - { - if (node->key == conn) - return node->value; - node = node->next; - } - return 0; -} - -void SetConnectionTranslation(int conn, int client) -{ - struct _ct_node **node = ct_head + (conn & 0xff); - if (client == 0) /* remove entry */ - { - while (*node != NULL) - { - if ((*node)->key == conn) - { - struct _ct_node *temp = *node; - *node = (*node)->next; - free(temp); - return; - } - node = &((*node)->next); - } - return; - } else - { - while (*node != NULL) - { - if ((*node)->key == conn) - { - (*node)->value = client; - return; - } - node = &((*node)->next); - } - *node = (struct _ct_node*)xalloc(sizeof(struct _ct_node)); - (*node)->next = NULL; - (*node)->key = conn; - (*node)->value = client; - return; - } -} - -void ClearConnectionTranslation(void) -{ - unsigned i; - for (i = 0; i < 256; i++) - { - struct _ct_node *node = ct_head[i]; - while (node != NULL) - { - struct _ct_node *temp = node; - node = node->next; - xfree(temp); - } - } -} -#endif - -XtransConnInfo *ListenTransConns = NULL; -int *ListenTransFds = NULL; -int ListenTransCount; - -static void ErrorConnMax(XtransConnInfo /* trans_conn */); - -#ifndef LBX -static -void CloseDownFileDescriptor( - OsCommPtr /*oc*/ -); -#endif - - -static XtransConnInfo -lookup_trans_conn (int fd) -{ - if (ListenTransFds) - { - int i; - for (i = 0; i < ListenTransCount; i++) - if (ListenTransFds[i] == fd) - return ListenTransConns[i]; - } - - return (NULL); -} - -/* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */ - -void -InitConnectionLimits(void) -{ - lastfdesc = -1; - -#ifndef __CYGWIN__ - -#ifndef __UNIXOS2__ - -#if !defined(XNO_SYSCONF) && defined(_SC_OPEN_MAX) - lastfdesc = sysconf(_SC_OPEN_MAX) - 1; -#endif - -#ifdef HAS_GETDTABLESIZE - if (lastfdesc < 0) - lastfdesc = getdtablesize() - 1; -#endif - -#ifdef _NFILE - if (lastfdesc < 0) - lastfdesc = _NFILE - 1; -#endif - -#else /* __UNIXOS2__ */ - lastfdesc = _nfiles - 1; -#endif - -#endif /* __CYGWIN__ */ - - /* This is the fallback */ - if (lastfdesc < 0) - lastfdesc = MAXSOCKS; - - if (lastfdesc > MAXSELECT) - lastfdesc = MAXSELECT; - - if (lastfdesc > MAXCLIENTS) - { - lastfdesc = MAXCLIENTS; - if (debug_conns) - ErrorF( "REACHED MAXIMUM CLIENTS LIMIT %d\n", MAXCLIENTS); - } - MaxClients = lastfdesc; - -#ifdef DEBUG - ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients); -#endif - -#if !defined(WIN32) - ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1)); -#else - InitConnectionTranslation(); -#endif -} - - -/***************** - * CreateWellKnownSockets - * At initialization, create the sockets to listen on for new clients. - *****************/ - -void -CreateWellKnownSockets(void) -{ - int i; - int partial; - char port[20]; - OsSigHandlerPtr handler; - - FD_ZERO(&AllSockets); - FD_ZERO(&AllClients); - FD_ZERO(&LastSelectMask); - FD_ZERO(&ClientsWithInput); - -#if !defined(WIN32) - for (i=0; i= 0) && - (ListenTransCount >= 1)) - { - if (!PartialNetwork && partial) - { - FatalError ("Failed to establish all listening sockets"); - } - else - { - ListenTransFds = (int *) xalloc (ListenTransCount * sizeof (int)); - - for (i = 0; i < ListenTransCount; i++) - { - int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]); - - ListenTransFds[i] = fd; - FD_SET (fd, &WellKnownConnections); - - if (!_XSERVTransIsLocal (ListenTransConns[i])) - { - DefineSelf (fd); - } - } - } - } - - if (!XFD_ANYSET (&WellKnownConnections)) - FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running"); -#if !defined(WIN32) - OsSignal (SIGPIPE, SIG_IGN); - OsSignal (SIGHUP, AutoResetServer); -#endif - OsSignal (SIGINT, GiveUp); - OsSignal (SIGTERM, GiveUp); - XFD_COPYSET (&WellKnownConnections, &AllSockets); - ResetHosts(display); - /* - * Magic: If SIGUSR1 was set to SIG_IGN when - * the server started, assume that either - * - * a- The parent process is ignoring SIGUSR1 - * - * or - * - * b- The parent process is expecting a SIGUSR1 - * when the server is ready to accept connections - * - * In the first case, the signal will be harmless, - * in the second case, the signal will be quite - * useful - */ -#if !defined(WIN32) - handler = OsSignal (SIGUSR1, SIG_IGN); - if ( handler == SIG_IGN) - RunFromSmartParent = TRUE; - OsSignal(SIGUSR1, handler); - ParentProcess = getppid (); -#ifdef __UNIXOS2__ - /* - * fg030505: under OS/2, xinit is not the parent process but - * the "grant parent" process of the server because execvpe() - * presents us an additional process number; - * GetPPID(pid) is part of libemxfix - */ - ParentProcess = GetPPID (ParentProcess); -#endif /* __UNIXOS2__ */ - if (RunFromSmartParent) { - if (ParentProcess > 1) { - kill (ParentProcess, SIGUSR1); - } - } -#endif -#ifdef XDMCP - XdmcpInit (); -#endif -} - -void -ResetWellKnownSockets (void) -{ - int i; - - ResetOsBuffers(); - - for (i = 0; i < ListenTransCount; i++) - { - int status = _XSERVTransResetListener (ListenTransConns[i]); - - if (status != TRANS_RESET_NOOP) - { - if (status == TRANS_RESET_FAILURE) - { - /* - * ListenTransConns[i] freed by xtrans. - * Remove it from out list. - */ - - FD_CLR (ListenTransFds[i], &WellKnownConnections); - ListenTransFds[i] = ListenTransFds[ListenTransCount - 1]; - ListenTransConns[i] = ListenTransConns[ListenTransCount - 1]; - ListenTransCount -= 1; - i -= 1; - } - else if (status == TRANS_RESET_NEW_FD) - { - /* - * A new file descriptor was allocated (the old one was closed) - */ - - int newfd = _XSERVTransGetConnectionNumber (ListenTransConns[i]); - - FD_CLR (ListenTransFds[i], &WellKnownConnections); - ListenTransFds[i] = newfd; - FD_SET(newfd, &WellKnownConnections); - } - } - } - - ResetAuthorization (); - ResetHosts(display); - /* - * See above in CreateWellKnownSockets about SIGUSR1 - */ -#if !defined(WIN32) - if (RunFromSmartParent) { - if (ParentProcess > 1) { - kill (ParentProcess, SIGUSR1); - } - } -#endif - /* - * restart XDMCP - */ -#ifdef XDMCP - XdmcpReset (); -#endif -} - -void -CloseWellKnownConnections(void) -{ - int i; - - for (i = 0; i < ListenTransCount; i++) - _XSERVTransClose (ListenTransConns[i]); -} - -static void -AuthAudit (ClientPtr client, Bool letin, - struct sockaddr *saddr, int len, - unsigned int proto_n, char *auth_proto, int auth_id) -{ - char addr[128]; - char *out = addr; - - if (!((OsCommPtr)client->osPrivate)->trans_conn) { - strcpy(addr, "LBX proxy at "); - out += strlen(addr); - } - if (!len) - strcpy(out, "local host"); - else - switch (saddr->sa_family) - { - case AF_UNSPEC: -#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) - case AF_UNIX: -#endif - strcpy(out, "local host"); - break; -#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) - case AF_INET: - sprintf(out, "IP %s", - inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr)); - break; -#if defined(IPv6) && defined(AF_INET6) - case AF_INET6: { - char ipaddr[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, &((struct sockaddr_in6 *) saddr)->sin6_addr, - ipaddr, sizeof(ipaddr)); - sprintf(out, "IP %s", ipaddr); - } - break; -#endif -#endif -#ifdef DNETCONN - case AF_DECnet: - sprintf(out, "DN %s", - dnet_ntoa(&((struct sockaddr_dn *) saddr)->sdn_add)); - break; -#endif - default: - strcpy(out, "unknown address"); - } - - if (proto_n) - AuditF("client %d %s from %s\n Auth name: %.*s ID: %d\n", - client->index, letin ? "connected" : "rejected", addr, - (int)proto_n, auth_proto, auth_id); - else - AuditF("client %d %s from %s\n", - client->index, letin ? "connected" : "rejected", addr); -} - -XID -AuthorizationIDOfClient(ClientPtr client) -{ - if (client->osPrivate) - return ((OsCommPtr)client->osPrivate)->auth_id; - else - return None; -} - - -/***************************************************************** - * ClientAuthorized - * - * Sent by the client at connection setup: - * typedef struct _xConnClientPrefix { - * CARD8 byteOrder; - * BYTE pad; - * CARD16 majorVersion, minorVersion; - * CARD16 nbytesAuthProto; - * CARD16 nbytesAuthString; - * } xConnClientPrefix; - * - * It is hoped that eventually one protocol will be agreed upon. In the - * mean time, a server that implements a different protocol than the - * client expects, or a server that only implements the host-based - * mechanism, will simply ignore this information. - * - *****************************************************************/ - -char * -ClientAuthorized(ClientPtr client, - unsigned int proto_n, char *auth_proto, - unsigned int string_n, char *auth_string) -{ - OsCommPtr priv; - Xtransaddr *from = NULL; - int family; - int fromlen; - XID auth_id; - char *reason = NULL; - XtransConnInfo trans_conn; - int restore_trans_conn = 0; - ClientPtr lbxpc = NULL; - - priv = (OsCommPtr)client->osPrivate; - trans_conn = priv->trans_conn; - -#ifdef LBX - if (!trans_conn) { - /* - * Since trans_conn is NULL, this must be a proxy's client for - * which we have NO address. Therefore, we will temporarily - * set the client's trans_conn to the proxy's trans_conn and - * after CheckAuthorization the client's trans_conn will be - * restored. - * - * If XDM-AUTHORIZATION-1 is being used, CheckAuthorization - * will eventually call XdmAuthorizationValidate and this - * later function may use the client's trans_conn to get the - * client's address. Since a XDM-AUTH-1 auth string includes - * the client's address, this address is compared to the address - * in the client's trans_conn. If the proxy and client are - * on the same host, the comparison will fail; otherwise the - * comparison will fail and the client will not be authorized - * to connect to the server. - * - * The basis for this additional code is to prevent a - * NULL pointer dereference of the client's trans_conn. - * The fundamental problem - the fact that the client's - * trans_conn is NULL - is because the NewClient - * request in version 1.0 of the LBX protocol does not - * send the client's address to the server. When the - * spec is changed and the client's address is sent to - * server in the NewClient request, this additional code - * should be removed. - * - * See defect number XWSog08218 for more information. - */ - lbxpc = LbxProxyClient(priv->proxy); - trans_conn = ((OsCommPtr)lbxpc->osPrivate)->trans_conn; - priv->trans_conn = trans_conn; - restore_trans_conn = 1; - } -#endif - - auth_id = CheckAuthorization (proto_n, auth_proto, - string_n, auth_string, client, &reason); - -#ifdef LBX - if (! priv->trans_conn) { - if (auth_id == (XID) ~0L && !GetAccessControl()) - auth_id = ((OsCommPtr)lbxpc->osPrivate)->auth_id; -#ifdef XCSECURITY - else if (auth_id != (XID) ~0L && !SecuritySameLevel(lbxpc, auth_id)) { - auth_id = (XID) ~0L; - reason = "Client trust level differs from that of LBX Proxy"; - } -#endif - } -#endif - if (auth_id == (XID) ~0L) - { - if ( -#ifdef XCSECURITY - (proto_n == 0 || - strncmp (auth_proto, XSecurityAuthorizationName, proto_n) != 0) && -#endif - _XSERVTransGetPeerAddr (trans_conn, - &family, &fromlen, &from) != -1) - { - if ( -#ifdef LBX - !trans_conn || -#endif - InvalidHost ((struct sockaddr *) from, fromlen, client)) - AuthAudit(client, FALSE, (struct sockaddr *) from, - fromlen, proto_n, auth_proto, auth_id); - else - { - auth_id = (XID) 0; - if (auditTrailLevel > 1) - AuthAudit(client, TRUE, - (struct sockaddr *) from, fromlen, - proto_n, auth_proto, auth_id); - } - - xfree ((char *) from); - } - - if (auth_id == (XID) ~0L) { -#ifdef LBX - /* - * Restore client's trans_conn state - */ - if (restore_trans_conn) { - priv->trans_conn = NULL; - } -#endif - if (reason) - return reason; - else - return "Client is not authorized to connect to Server"; - } - } - else if (auditTrailLevel > 1) - { - if (_XSERVTransGetPeerAddr (trans_conn, - &family, &fromlen, &from) != -1) - { - AuthAudit(client, TRUE, (struct sockaddr *) from, fromlen, - proto_n, auth_proto, auth_id); - - xfree ((char *) from); - } - } - priv->auth_id = auth_id; - priv->conn_time = 0; - -#ifdef XDMCP - /* indicate to Xdmcp protocol that we've opened new client */ - XdmcpOpenDisplay(priv->fd); -#endif /* XDMCP */ -#ifdef XAPPGROUP - if (ClientStateCallback) - XagCallClientStateChange (client); -#endif - /* At this point, if the client is authorized to change the access control - * list, we should getpeername() information, and add the client to - * the selfhosts list. It's not really the host machine, but the - * true purpose of the selfhosts list is to see who may change the - * access control list. - */ -#ifdef LBX - if (restore_trans_conn) { - priv->trans_conn = NULL; - } -#endif - return((char *)NULL); -} - -static ClientPtr -#ifdef LBX -AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time, - int (*Flush)( - ClientPtr /*who*/, OsCommPtr /*oc*/, - char * /*extraBuf*/, int /*extraCount*/), - void (*Close)( - ClientPtr /*client*/), - LbxProxyPtr proxy) -#else -AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time) -#endif -{ - OsCommPtr oc; - ClientPtr client; - - if ( -#ifdef LBX - trans_conn && -#endif -#ifndef WIN32 - fd >= lastfdesc -#else - XFD_SETCOUNT(&AllClients) >= MaxClients -#endif - ) - return NullClient; - oc = (OsCommPtr)xalloc(sizeof(OsCommRec)); - if (!oc) - return NullClient; - oc->trans_conn = trans_conn; - oc->fd = fd; - oc->input = (ConnectionInputPtr)NULL; - oc->output = (ConnectionOutputPtr)NULL; - oc->auth_id = None; - oc->conn_time = conn_time; -#ifdef LBX - oc->proxy = proxy; - oc->Flush = Flush; - oc->Close = Close; - oc->largereq = (ConnectionInputPtr) NULL; -#endif - if (!(client = NextAvailableClient((pointer)oc))) - { - xfree (oc); - return NullClient; - } -#ifdef LBX - if (trans_conn) -#endif - { -#if !defined(WIN32) - ConnectionTranslation[fd] = client->index; -#else - SetConnectionTranslation(fd, client->index); -#endif - if (GrabInProgress) - { - FD_SET(fd, &SavedAllClients); - FD_SET(fd, &SavedAllSockets); - } - else - { - FD_SET(fd, &AllClients); - FD_SET(fd, &AllSockets); - } - } - -#ifdef DEBUG - ErrorF("AllocNewConnection: client index = %d, socket fd = %d\n", - client->index, fd); -#endif - - return client; -} - -#ifdef LBX - -int -ClientConnectionNumber (ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr) client->osPrivate; - - return oc->fd; -} - -ClientPtr -AllocLbxClientConnection (ClientPtr client, LbxProxyPtr proxy) -{ - OsCommPtr oc = (OsCommPtr) client->osPrivate; - - return AllocNewConnection ((XtransConnInfo)NULL, oc->fd, GetTimeInMillis(), - LbxFlushClient, LbxCloseClient, proxy); -} - -void -LbxProxyConnection (ClientPtr client, LbxProxyPtr proxy) -{ - OsCommPtr oc = (OsCommPtr) client->osPrivate; - - FlushClient(client, oc, (char *)NULL, 0); - oc->proxy = proxy; - oc->Flush = LbxFlushClient; - oc->Close = LbxCloseClient; - LbxPrimeInput(client, proxy); -} - -#endif - -/***************** - * EstablishNewConnections - * If anyone is waiting on listened sockets, accept them. - * Returns a mask with indices of new clients. Updates AllClients - * and AllSockets. - *****************/ - -/*ARGSUSED*/ -Bool -EstablishNewConnections(ClientPtr clientUnused, pointer closure) -{ - fd_set readyconnections; /* set of listeners that are ready */ - int curconn; /* fd of listener that's ready */ - register int newconn; /* fd of new client */ - CARD32 connect_time; - register int i; - register ClientPtr client; - register OsCommPtr oc; - fd_set tmask; - - XFD_ANDSET (&tmask, (fd_set*)closure, &WellKnownConnections); - XFD_COPYSET(&tmask, &readyconnections); - if (!XFD_ANYSET(&readyconnections)) - return TRUE; - connect_time = GetTimeInMillis(); - /* kill off stragglers */ - for (i=1; iosPrivate); - if ((oc && (oc->conn_time != 0) && - (connect_time - oc->conn_time) >= TimeOutValue) || - (client->noClientException != Success && !client->clientGone)) - CloseDownClient(client); - } - } -#ifndef WIN32 - for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) - { - while (readyconnections.fds_bits[i]) -#else - for (i = 0; i < XFD_SETCOUNT(&readyconnections); i++) -#endif - { - XtransConnInfo trans_conn, new_trans_conn; - int status; - -#ifndef WIN32 - curconn = ffs (readyconnections.fds_bits[i]) - 1; - readyconnections.fds_bits[i] &= ~((fd_mask)1 << curconn); - curconn += (i * (sizeof(fd_mask)*8)); -#else - curconn = XFD_FD(&readyconnections, i); -#endif - - if ((trans_conn = lookup_trans_conn (curconn)) == NULL) - continue; - - if ((new_trans_conn = _XSERVTransAccept (trans_conn, &status)) == NULL) - continue; - - newconn = _XSERVTransGetConnectionNumber (new_trans_conn); - - if (newconn < lastfdesc) - { - int clientid; -#if !defined(WIN32) - clientid = ConnectionTranslation[newconn]; -#else - clientid = GetConnectionTranslation(newconn); -#endif - if(clientid && (client = clients[clientid])) - CloseDownClient(client); - } - - _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1); - - if (!AllocNewConnection (new_trans_conn, newconn, connect_time -#ifdef LBX - , StandardFlushClient, - CloseDownFileDescriptor, (LbxProxyPtr)NULL -#endif - )) - { - ErrorConnMax(new_trans_conn); - _XSERVTransClose(new_trans_conn); - } - } -#ifndef WIN32 - } -#endif - return TRUE; -} - -#define NOROOM "Maximum number of clients reached" - -/************ - * ErrorConnMax - * Fail a connection due to lack of client or file descriptor space - ************/ - -static void -ErrorConnMax(XtransConnInfo trans_conn) -{ - int fd = _XSERVTransGetConnectionNumber (trans_conn); - xConnSetupPrefix csp; - char pad[3]; - struct iovec iov[3]; - char byteOrder = 0; - int whichbyte = 1; - struct timeval waittime; - fd_set mask; - - /* if these seems like a lot of trouble to go to, it probably is */ - waittime.tv_sec = BOTIMEOUT / MILLI_PER_SECOND; - waittime.tv_usec = (BOTIMEOUT % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - FD_ZERO(&mask); - FD_SET(fd, &mask); - (void)Select(fd + 1, &mask, NULL, NULL, &waittime); - /* try to read the byte-order of the connection */ - (void)_XSERVTransRead(trans_conn, &byteOrder, 1); - if ((byteOrder == 'l') || (byteOrder == 'B')) - { - csp.success = xFalse; - csp.lengthReason = sizeof(NOROOM) - 1; - csp.length = (sizeof(NOROOM) + 2) >> 2; - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (((*(char *) &whichbyte) && (byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (byteOrder == 'l'))) - { - swaps(&csp.majorVersion, whichbyte); - swaps(&csp.minorVersion, whichbyte); - swaps(&csp.length, whichbyte); - } - iov[0].iov_len = sz_xConnSetupPrefix; - iov[0].iov_base = (char *) &csp; - iov[1].iov_len = csp.lengthReason; - iov[1].iov_base = NOROOM; - iov[2].iov_len = (4 - (csp.lengthReason & 3)) & 3; - iov[2].iov_base = pad; - (void)_XSERVTransWritev(trans_conn, iov, 3); - } -} - -/************ - * CloseDownFileDescriptor: - * Remove this file descriptor and it's I/O buffers, etc. - ************/ - -#ifdef LBX -void -CloseDownFileDescriptor(ClientPtr client) -#else -static void -CloseDownFileDescriptor(OsCommPtr oc) -#endif -{ -#ifdef LBX - OsCommPtr oc = (OsCommPtr) client->osPrivate; -#endif - int connection = oc->fd; - - if (oc->trans_conn) { - _XSERVTransDisconnect(oc->trans_conn); - _XSERVTransClose(oc->trans_conn); - } -#ifndef LBX - FreeOsBuffers(oc); - xfree(oc); -#endif -#ifndef WIN32 - ConnectionTranslation[connection] = 0; -#else - SetConnectionTranslation(connection, 0); -#endif - FD_CLR(connection, &AllSockets); - FD_CLR(connection, &AllClients); - FD_CLR(connection, &ClientsWithInput); - FD_CLR(connection, &GrabImperviousClients); - if (GrabInProgress) - { - FD_CLR(connection, &SavedAllSockets); - FD_CLR(connection, &SavedAllClients); - FD_CLR(connection, &SavedClientsWithInput); - } - FD_CLR(connection, &ClientsWriteBlocked); - if (!XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; - FD_CLR(connection, &OutputPending); -} - -/***************** - * CheckConnections - * Some connection has died, go find which one and shut it down - * The file descriptor has been closed, but is still in AllClients. - * If would truly be wonderful if select() would put the bogus - * file descriptors in the exception mask, but nooooo. So we have - * to check each and every socket individually. - *****************/ - -void -CheckConnections(void) -{ -#ifndef WIN32 - fd_mask mask; -#endif - fd_set tmask; - int curclient, curoff; - int i; - struct timeval notime; - int r; -#ifdef WIN32 - fd_set savedAllClients; -#endif - - notime.tv_sec = 0; - notime.tv_usec = 0; - -#ifndef WIN32 - for (i=0; iosPrivate; - - if (oc->output && oc->output->count) - FlushClient(client, oc, (char *)NULL, 0); -#ifdef XDMCP - XdmcpCloseDisplay(oc->fd); -#endif -#ifndef LBX - CloseDownFileDescriptor(oc); -#else - (*oc->Close) (client); - FreeOsBuffers(oc); - xfree(oc); -#endif - client->osPrivate = (pointer)NULL; - if (auditTrailLevel > 1) - AuditF("client %d disconnected\n", client->index); -} - -void -AddEnabledDevice(int fd) -{ - FD_SET(fd, &EnabledDevices); - FD_SET(fd, &AllSockets); - if (GrabInProgress) - FD_SET(fd, &SavedAllSockets); -} - -void -RemoveEnabledDevice(int fd) -{ - FD_CLR(fd, &EnabledDevices); - FD_CLR(fd, &AllSockets); - if (GrabInProgress) - FD_CLR(fd, &SavedAllSockets); -} - -/***************** - * OnlyListenToOneClient: - * Only accept requests from one client. Continue to handle new - * connections, but don't take any protocol requests from the new - * ones. Note that if GrabInProgress is set, EstablishNewConnections - * needs to put new clients into SavedAllSockets and SavedAllClients. - * Note also that there is no timeout for this in the protocol. - * This routine is "undone" by ListenToAllClients() - *****************/ - -void -OnlyListenToOneClient(ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; - - if (! GrabInProgress) - { - XFD_COPYSET(&ClientsWithInput, &SavedClientsWithInput); - XFD_ANDSET(&ClientsWithInput, - &ClientsWithInput, &GrabImperviousClients); - if (FD_ISSET(connection, &SavedClientsWithInput)) - { - FD_CLR(connection, &SavedClientsWithInput); - FD_SET(connection, &ClientsWithInput); - } - XFD_UNSET(&SavedClientsWithInput, &GrabImperviousClients); - XFD_COPYSET(&AllSockets, &SavedAllSockets); - XFD_COPYSET(&AllClients, &SavedAllClients); - XFD_UNSET(&AllSockets, &AllClients); - XFD_ANDSET(&AllClients, &AllClients, &GrabImperviousClients); - FD_SET(connection, &AllClients); - XFD_ORSET(&AllSockets, &AllSockets, &AllClients); - GrabInProgress = client->index; - } -} - -/**************** - * ListenToAllClients: - * Undoes OnlyListentToOneClient() - ****************/ - -void -ListenToAllClients(void) -{ - if (GrabInProgress) - { - XFD_ORSET(&AllSockets, &AllSockets, &SavedAllSockets); - XFD_ORSET(&AllClients, &AllClients, &SavedAllClients); - XFD_ORSET(&ClientsWithInput, &ClientsWithInput, &SavedClientsWithInput); - GrabInProgress = 0; - } -} - -/**************** - * IgnoreClient - * Removes one client from input masks. - * Must have cooresponding call to AttendClient. - ****************/ - -void -IgnoreClient (ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; -#ifdef LBX - LbxClientPtr lbxClient = LbxClient(client); -#endif - - isItTimeToYield = TRUE; -#ifdef LBX - if (lbxClient) { - lbxClient->ignored = TRUE; - return; - } -#endif - if (!GrabInProgress || FD_ISSET(connection, &AllClients)) - { - if (FD_ISSET (connection, &ClientsWithInput)) - FD_SET(connection, &IgnoredClientsWithInput); - else - FD_CLR(connection, &IgnoredClientsWithInput); - FD_CLR(connection, &ClientsWithInput); - FD_CLR(connection, &AllSockets); - FD_CLR(connection, &AllClients); - FD_CLR(connection, &LastSelectMask); - } - else - { - if (FD_ISSET (connection, &SavedClientsWithInput)) - FD_SET(connection, &IgnoredClientsWithInput); - else - FD_CLR(connection, &IgnoredClientsWithInput); - FD_CLR(connection, &SavedClientsWithInput); - FD_CLR(connection, &SavedAllSockets); - FD_CLR(connection, &SavedAllClients); - } -} - -/**************** - * AttendClient - * Adds one client back into the input masks. - ****************/ - -void -AttendClient (ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; -#ifdef LBX - LbxClientPtr lbxClient = LbxClient(client); - - if (lbxClient) { - lbxClient->ignored = FALSE; - return; - } -#endif - if (!GrabInProgress || GrabInProgress == client->index || - FD_ISSET(connection, &GrabImperviousClients)) - { - FD_SET(connection, &AllClients); - FD_SET(connection, &AllSockets); - FD_SET(connection, &LastSelectMask); - if (FD_ISSET (connection, &IgnoredClientsWithInput)) - FD_SET(connection, &ClientsWithInput); - } - else - { - FD_SET(connection, &SavedAllClients); - FD_SET(connection, &SavedAllSockets); - if (FD_ISSET(connection, &IgnoredClientsWithInput)) - FD_SET(connection, &SavedClientsWithInput); - } -} - -/* make client impervious to grabs; assume only executing client calls this */ - -void -MakeClientGrabImpervious(ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; - - FD_SET(connection, &GrabImperviousClients); - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = CLIENT_IMPERVIOUS; - CallCallbacks(&ServerGrabCallback, &grabinfo); - } -} - -/* make client pervious to grabs; assume only executing client calls this */ - -void -MakeClientGrabPervious(ClientPtr client) -{ - OsCommPtr oc = (OsCommPtr)client->osPrivate; - int connection = oc->fd; - - FD_CLR(connection, &GrabImperviousClients); - if (GrabInProgress && (GrabInProgress != client->index)) - { - if (FD_ISSET(connection, &ClientsWithInput)) - { - FD_SET(connection, &SavedClientsWithInput); - FD_CLR(connection, &ClientsWithInput); - } - FD_CLR(connection, &AllSockets); - FD_CLR(connection, &AllClients); - isItTimeToYield = TRUE; - } - - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = CLIENT_PERVIOUS; - CallCallbacks(&ServerGrabCallback, &grabinfo); - } -} - diff --git a/nx-X11/programs/Xserver/os/log.c.NX.original b/nx-X11/programs/Xserver/os/log.c.NX.original deleted file mode 100644 index 04e24b8df..000000000 --- a/nx-X11/programs/Xserver/os/log.c.NX.original +++ /dev/null @@ -1,716 +0,0 @@ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, -Copyright 1994 Quarterdeck Office Systems. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital and -Quarterdeck not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE. - -*/ - -/* - * Copyright (c) 1997-2003 by The XFree86 Project, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of the copyright holder(s) - * and author(s) shall not be used in advertising or otherwise to promote - * the sale, use or other dealings in this Software without prior written - * authorization from the copyright holder(s) and author(s). - */ - -/* $XFree86: xc/programs/Xserver/os/log.c,v 1.6 2003/11/07 13:45:27 tsi Exp $ */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include /* for malloc() */ -#include - -#include "site.h" -#include "opaque.h" - -#ifdef WIN32 -#include -#define getpid(x) _getpid(x) -#endif - -#ifdef NX_TRANS_SOCKET - -#include "NX.h" - -#endif - -#ifdef DDXOSVERRORF -void (*OsVendorVErrorFProc)(const char *, va_list args) = NULL; -#ifdef NX_TRANS_EXIT -int OsVendorVErrorFFatal = 0; -#endif -#endif - -static FILE *logFile = NULL; -static Bool logFlush = FALSE; -static Bool logSync = FALSE; -static int logVerbosity = DEFAULT_LOG_VERBOSITY; -static int logFileVerbosity = DEFAULT_LOG_FILE_VERBOSITY; - -/* Buffer to information logged before the log file is opened. */ -static char *saveBuffer = NULL; -static int bufferSize = 0, bufferUnused = 0, bufferPos = 0; -static Bool needBuffer = TRUE; - -/* Prefix strings for log messages. */ -#ifndef X_UNKNOWN_STRING -#define X_UNKNOWN_STRING "(\?\?)" -#endif -#ifndef X_PROBE_STRING -#define X_PROBE_STRING "(--)" -#endif -#ifndef X_CONFIG_STRING -#define X_CONFIG_STRING "(**)" -#endif -#ifndef X_DEFAULT_STRING -#define X_DEFAULT_STRING "(==)" -#endif -#ifndef X_CMDLINE_STRING -#define X_CMDLINE_STRING "(++)" -#endif -#ifndef X_NOTICE_STRING -#define X_NOTICE_STRING "(!!)" -#endif -#ifndef X_ERROR_STRING -#define X_ERROR_STRING "(EE)" -#endif -#ifndef X_WARNING_STRING -#define X_WARNING_STRING "(WW)" -#endif -#ifndef X_INFO_STRING -#define X_INFO_STRING "(II)" -#endif -#ifndef X_NOT_IMPLEMENTED_STRING -#define X_NOT_IMPLEMENTED_STRING "(NI)" -#endif - -/* - * LogInit is called to start logging to a file. It is also called (with - * NULL arguments) when logging to a file is not wanted. It must always be - * called, otherwise log messages will continue to accumulate in a buffer. - * - * %s, if present in the fname or backup strings, is expanded to the display - * string. - */ - -const char * -LogInit(const char *fname, const char *backup) -{ - char *logFileName = NULL; - - if (fname && *fname) { - /* xalloc() can't be used yet. */ - logFileName = malloc(strlen(fname) + strlen(display) + 1); - if (!logFileName) - FatalError("Cannot allocate space for the log file name\n"); - sprintf(logFileName, fname, display); - - if (backup && *backup) { - struct stat buf; - - if (!stat(logFileName, &buf) && S_ISREG(buf.st_mode)) { - char *suffix; - char *oldLog; - - oldLog = malloc(strlen(logFileName) + strlen(backup) + - strlen(display) + 1); - suffix = malloc(strlen(backup) + strlen(display) + 1); - if (!oldLog || !suffix) - FatalError("Cannot allocate space for the log file name\n"); - sprintf(suffix, backup, display); - sprintf(oldLog, "%s%s", logFileName, suffix); - free(suffix); -#ifdef __UNIXOS2__ - remove(oldLog); -#endif - if (rename(logFileName, oldLog) == -1) { - FatalError("Cannot move old log file (\"%s\" to \"%s\"\n", - logFileName, oldLog); - } - free(oldLog); - } - } - if ((logFile = fopen(logFileName, "w")) == NULL) - FatalError("Cannot open log file \"%s\"\n", logFileName); - setvbuf(logFile, NULL, _IONBF, 0); - - /* Flush saved log information. */ - if (saveBuffer && bufferSize > 0) { - fwrite(saveBuffer, bufferPos, 1, logFile); - fflush(logFile); -#ifndef WIN32 - fsync(fileno(logFile)); -#endif - } - } - - /* - * Unconditionally free the buffer, and flag that the buffer is no longer - * needed. - */ - if (saveBuffer && bufferSize > 0) { - free(saveBuffer); /* Must be free(), not xfree() */ - saveBuffer = NULL; - bufferSize = 0; - } - needBuffer = FALSE; - - return logFileName; -} - -void -LogClose() -{ - if (logFile) { - fclose(logFile); - logFile = NULL; - } -} - -Bool -LogSetParameter(LogParameter param, int value) -{ - switch (param) { - case XLOG_FLUSH: - logFlush = value ? TRUE : FALSE; - return TRUE; - case XLOG_SYNC: - logSync = value ? TRUE : FALSE; - return TRUE; - case XLOG_VERBOSITY: - logVerbosity = value; - return TRUE; - case XLOG_FILE_VERBOSITY: - logFileVerbosity = value; - return TRUE; - default: - return FALSE; - } -} - -/* This function does the actual log message writes. */ - -void -LogVWrite(int verb, const char *f, va_list args) -{ - static char tmpBuffer[1024]; - int len = 0; - - /* - * Since a va_list can only be processed once, write the string to a - * buffer, and then write the buffer out to the appropriate output - * stream(s). - */ - if (verb < 0 || logFileVerbosity >= verb || logVerbosity >= verb) { - vsnprintf(tmpBuffer, sizeof(tmpBuffer), f, args); -#ifdef NX_TRANS_EXIT - /* - * Beautify the message. Make the - * first letter uppercase. - */ - - *tmpBuffer = toupper(*tmpBuffer); - - /* - * Remove the trailing newline. - */ - - if (strlen(tmpBuffer) > 0 && - *(tmpBuffer + strlen(tmpBuffer) - 1) == '\n') { - *(tmpBuffer + strlen(tmpBuffer) - 1) = '\0'; - } - - /* - * Remove the trailing full-stop. - */ - - if (strlen(tmpBuffer) > 0 && - *(tmpBuffer + strlen(tmpBuffer) - 1) == '.') { - *(tmpBuffer + strlen(tmpBuffer) - 1) = '\0'; - } -#endif /* #ifdef NX_TRANS_EXIT */ - len = strlen(tmpBuffer); - } - if ((verb < 0 || logVerbosity >= verb) && len > 0) - fwrite(tmpBuffer, len, 1, stderr); - if ((verb < 0 || logFileVerbosity >= verb) && len > 0) { - if (logFile) { - fwrite(tmpBuffer, len, 1, logFile); - if (logFlush) { - fflush(logFile); -#ifndef WIN32 - if (logSync) - fsync(fileno(logFile)); -#endif - } - } else if (needBuffer) { - /* - * Note, this code is used before OsInit() has been called, so - * xalloc() and friends can't be used. - */ - if (len > bufferUnused) { - bufferSize += 1024; - bufferUnused += 1024; - if (saveBuffer) - saveBuffer = realloc(saveBuffer, bufferSize); - else - saveBuffer = malloc(bufferSize); - if (!saveBuffer) - FatalError("realloc() failed while saving log messages\n"); - } - bufferUnused -= len; - memcpy(saveBuffer + bufferPos, tmpBuffer, len); - bufferPos += len; - } - } -} - -void -LogWrite(int verb, const char *f, ...) -{ - va_list args; - - va_start(args, f); - LogVWrite(verb, f, args); - va_end(args); -} - -void -LogVMessageVerb(MessageType type, int verb, const char *format, va_list args) -{ - const char *s = X_UNKNOWN_STRING; - char *tmpBuf = NULL; - - /* Ignore verbosity for X_ERROR */ - if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) { - switch (type) { - case X_PROBED: - s = X_PROBE_STRING; - break; - case X_CONFIG: - s = X_CONFIG_STRING; - break; - case X_DEFAULT: - s = X_DEFAULT_STRING; - break; - case X_CMDLINE: - s = X_CMDLINE_STRING; - break; - case X_NOTICE: - s = X_NOTICE_STRING; - break; - case X_ERROR: - s = X_ERROR_STRING; - if (verb > 0) - verb = 0; - break; - case X_WARNING: - s = X_WARNING_STRING; - break; - case X_INFO: - s = X_INFO_STRING; - break; - case X_NOT_IMPLEMENTED: - s = X_NOT_IMPLEMENTED_STRING; - break; - case X_UNKNOWN: - s = X_UNKNOWN_STRING; - break; - case X_NONE: - s = NULL; - break; - } - - /* - * Prefix the format string with the message type. We do it this way - * so that LogVWrite() is only called once per message. - */ - if (s) { - tmpBuf = malloc(strlen(format) + strlen(s) + 1 + 1); - /* Silently return if malloc fails here. */ - if (!tmpBuf) - return; - sprintf(tmpBuf, "%s ", s); - strcat(tmpBuf, format); - LogVWrite(verb, tmpBuf, args); - free(tmpBuf); - } else - LogVWrite(verb, format, args); - } -} - -/* Log message with verbosity level specified. */ -void -LogMessageVerb(MessageType type, int verb, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - LogVMessageVerb(type, verb, format, ap); - va_end(ap); -} - -/* Log a message with the standard verbosity level of 1. */ -void -LogMessage(MessageType type, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - LogVMessageVerb(type, 1, format, ap); - va_end(ap); -} - -#ifdef __GNUC__ -void AbortServer(void) __attribute__((noreturn)); -#endif - -void -AbortServer(void) -{ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST) - fprintf(stderr, "AbortServer: Going to abort the current server.\n"); -#endif - OsCleanup(TRUE); - AbortDDX(); - fflush(stderr); - if (CoreDump) - abort(); -#ifdef NX_TRANS_EXIT -#ifdef NX_TRANS_TEST - fprintf(stderr, "AbortServer: Going to clean up NX resources and exit.\n"); -#endif - NXTransExit(1); -#else /* #ifdef NX_TRANS_EXIT */ - exit (1); -#endif -} - -#ifndef AUDIT_PREFIX -#define AUDIT_PREFIX "AUDIT: %s: %ld %s: " -#endif -#ifndef AUDIT_TIMEOUT -#define AUDIT_TIMEOUT ((CARD32)(120 * 1000)) /* 2 mn */ -#endif - -static int nrepeat = 0; -static int oldlen = -1; -static OsTimerPtr auditTimer = NULL; - -void -FreeAuditTimer(void) -{ - if (auditTimer != NULL) { - /* Force output of pending messages */ - TimerForce(auditTimer); - TimerFree(auditTimer); - auditTimer = NULL; - } -} - -static char * -AuditPrefix(void) -{ - time_t tm; - char *autime, *s; - char *tmpBuf; - int len; - - time(&tm); - autime = ctime(&tm); - if ((s = strchr(autime, '\n'))) - *s = '\0'; - if ((s = strrchr(argvGlobal[0], '/'))) - s++; - else - s = argvGlobal[0]; - len = strlen(AUDIT_PREFIX) + strlen(autime) + 10 + strlen(s) + 1; - tmpBuf = malloc(len); - if (!tmpBuf) - return NULL; - snprintf(tmpBuf, len, AUDIT_PREFIX, autime, (unsigned long)getpid(), s); - return tmpBuf; -} - -void -AuditF(const char * f, ...) -{ - va_list args; - - va_start(args, f); - - VAuditF(f, args); - va_end(args); -} - -static CARD32 -AuditFlush(OsTimerPtr timer, CARD32 now, pointer arg) -{ - char *prefix; - - if (nrepeat > 0) { - prefix = AuditPrefix(); - ErrorF("%slast message repeated %d times\n", - prefix != NULL ? prefix : "", nrepeat); - nrepeat = 0; - if (prefix != NULL) - free(prefix); - return AUDIT_TIMEOUT; - } else { - /* if the timer expires without anything to print, flush the message */ - oldlen = -1; - return 0; - } -} - -void -VAuditF(const char *f, va_list args) -{ - char *prefix; - char buf[1024]; - int len; - static char oldbuf[1024]; - - prefix = AuditPrefix(); - len = vsnprintf(buf, sizeof(buf), f, args); - -#if 1 - /* XXX Compressing duplicated messages is temporarily disabled to - * work around bugzilla 964: - * https://freedesktop.org/bugzilla/show_bug.cgi?id=964 - */ - ErrorF("%s%s", prefix != NULL ? prefix : "", buf); - oldlen = -1; - nrepeat = 0; -#else - if (len == oldlen && strcmp(buf, oldbuf) == 0) { - /* Message already seen */ - nrepeat++; - } else { - /* new message */ - if (auditTimer != NULL) - TimerForce(auditTimer); - ErrorF("%s%s", prefix != NULL ? prefix : "", buf); - strlcpy(oldbuf, buf, sizeof(oldbuf)); - oldlen = len; - nrepeat = 0; - auditTimer = TimerSet(auditTimer, 0, AUDIT_TIMEOUT, AuditFlush, NULL); - } -#endif - if (prefix != NULL) - free(prefix); -} - -void -FatalError(const char *f, ...) -{ - va_list args; - static Bool beenhere = FALSE; - -#ifdef NX_TRANS_EXIT - if (beenhere) { - fprintf(stderr, "Error: Aborting session with fatal error function reentered.\n"); - } - else { - /* - * Tell to the log function that this - * is a fatal error. - */ - - OsVendorVErrorFFatal = 1; - - fprintf(stderr, "Error: Aborting session with '"); - - va_start(args, f); - VErrorF(f, args); - va_end(args); - - fprintf(stderr, "'.\n"); - } -#else /* #ifdef NX_TRANS_EXIT */ - if (beenhere) - ErrorF("\nFatalError re-entered, aborting\n"); - else - ErrorF("\nFatal server error:\n"); - - va_start(args, f); - VErrorF(f, args); - va_end(args); - ErrorF("\n"); -#endif /* #ifdef NX_TRANS_EXIT */ -#ifdef DDXOSFATALERROR - if (!beenhere) - OsVendorFatalError(); -#endif -#ifdef ABORTONFATALERROR - abort(); -#endif - if (!beenhere) { - beenhere = TRUE; - AbortServer(); - } else - abort(); - /*NOTREACHED*/ -} - -void -VErrorF(const char *f, va_list args) -{ -#ifdef DDXOSVERRORF - if (OsVendorVErrorFProc) - OsVendorVErrorFProc(f, args); - else - LogVWrite(-1, f, args); -#else - LogVWrite(-1, f, args); -#endif -} - -void -ErrorF(const char * f, ...) -{ - va_list args; - - va_start(args, f); - VErrorF(f, args); - va_end(args); -} - -/* A perror() workalike. */ - -#ifndef NEED_STRERROR -#ifdef SYSV -#if !defined(ISC) || defined(ISC202) || defined(ISC22) -#define NEED_STRERROR -#endif -#endif -#endif - -#if defined(NEED_STRERROR) && !defined(strerror) -extern char *sys_errlist[]; -extern int sys_nerr; -#define strerror(n) \ - ((n) >= 0 && (n) < sys_nerr) ? sys_errlist[(n)] : "unknown error" -#endif - -void -Error(char *str) -{ - char *err = NULL; - int saveErrno = errno; - - if (str) { - err = malloc(strlen(strerror(saveErrno)) + strlen(str) + 2 + 1); - if (!err) - return; - sprintf(err, "%s: ", str); - strcat(err, strerror(saveErrno)); - LogWrite(-1, err); - } else - LogWrite(-1, strerror(saveErrno)); -} - -void -LogPrintMarkers() -{ - /* Show what the message marker symbols mean. */ - ErrorF("Markers: "); - LogMessageVerb(X_PROBED, -1, "probed, "); - LogMessageVerb(X_CONFIG, -1, "from config file, "); - LogMessageVerb(X_DEFAULT, -1, "default setting,\n\t"); - LogMessageVerb(X_CMDLINE, -1, "from command line, "); - LogMessageVerb(X_NOTICE, -1, "notice, "); - LogMessageVerb(X_INFO, -1, "informational,\n\t"); - LogMessageVerb(X_WARNING, -1, "warning, "); - LogMessageVerb(X_ERROR, -1, "error, "); - LogMessageVerb(X_NOT_IMPLEMENTED, -1, "not implemented, "); - LogMessageVerb(X_UNKNOWN, -1, "unknown.\n"); -} - diff --git a/nx-X11/programs/Xserver/os/log.c.X.original b/nx-X11/programs/Xserver/os/log.c.X.original deleted file mode 100644 index 4bebbe784..000000000 --- a/nx-X11/programs/Xserver/os/log.c.X.original +++ /dev/null @@ -1,633 +0,0 @@ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, -Copyright 1994 Quarterdeck Office Systems. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital and -Quarterdeck not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE. - -*/ - -/* - * Copyright (c) 1997-2003 by The XFree86 Project, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of the copyright holder(s) - * and author(s) shall not be used in advertising or otherwise to promote - * the sale, use or other dealings in this Software without prior written - * authorization from the copyright holder(s) and author(s). - */ - -/* $XFree86: xc/programs/Xserver/os/log.c,v 1.6 2003/11/07 13:45:27 tsi Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include /* for malloc() */ -#include - -#include "site.h" -#include "opaque.h" - -#ifdef WIN32 -#include -#define getpid(x) _getpid(x) -#endif - - -#ifdef DDXOSVERRORF -void (*OsVendorVErrorFProc)(const char *, va_list args) = NULL; -#endif - -static FILE *logFile = NULL; -static Bool logFlush = FALSE; -static Bool logSync = FALSE; -static int logVerbosity = DEFAULT_LOG_VERBOSITY; -static int logFileVerbosity = DEFAULT_LOG_FILE_VERBOSITY; - -/* Buffer to information logged before the log file is opened. */ -static char *saveBuffer = NULL; -static int bufferSize = 0, bufferUnused = 0, bufferPos = 0; -static Bool needBuffer = TRUE; - -/* Prefix strings for log messages. */ -#ifndef X_UNKNOWN_STRING -#define X_UNKNOWN_STRING "(\?\?)" -#endif -#ifndef X_PROBE_STRING -#define X_PROBE_STRING "(--)" -#endif -#ifndef X_CONFIG_STRING -#define X_CONFIG_STRING "(**)" -#endif -#ifndef X_DEFAULT_STRING -#define X_DEFAULT_STRING "(==)" -#endif -#ifndef X_CMDLINE_STRING -#define X_CMDLINE_STRING "(++)" -#endif -#ifndef X_NOTICE_STRING -#define X_NOTICE_STRING "(!!)" -#endif -#ifndef X_ERROR_STRING -#define X_ERROR_STRING "(EE)" -#endif -#ifndef X_WARNING_STRING -#define X_WARNING_STRING "(WW)" -#endif -#ifndef X_INFO_STRING -#define X_INFO_STRING "(II)" -#endif -#ifndef X_NOT_IMPLEMENTED_STRING -#define X_NOT_IMPLEMENTED_STRING "(NI)" -#endif - -/* - * LogInit is called to start logging to a file. It is also called (with - * NULL arguments) when logging to a file is not wanted. It must always be - * called, otherwise log messages will continue to accumulate in a buffer. - * - * %s, if present in the fname or backup strings, is expanded to the display - * string. - */ - -const char * -LogInit(const char *fname, const char *backup) -{ - char *logFileName = NULL; - - if (fname && *fname) { - /* xalloc() can't be used yet. */ - logFileName = malloc(strlen(fname) + strlen(display) + 1); - if (!logFileName) - FatalError("Cannot allocate space for the log file name\n"); - sprintf(logFileName, fname, display); - - if (backup && *backup) { - struct stat buf; - - if (!stat(logFileName, &buf) && S_ISREG(buf.st_mode)) { - char *suffix; - char *oldLog; - - oldLog = malloc(strlen(logFileName) + strlen(backup) + - strlen(display) + 1); - suffix = malloc(strlen(backup) + strlen(display) + 1); - if (!oldLog || !suffix) - FatalError("Cannot allocate space for the log file name\n"); - sprintf(suffix, backup, display); - sprintf(oldLog, "%s%s", logFileName, suffix); - free(suffix); -#ifdef __UNIXOS2__ - remove(oldLog); -#endif - if (rename(logFileName, oldLog) == -1) { - FatalError("Cannot move old log file (\"%s\" to \"%s\"\n", - logFileName, oldLog); - } - free(oldLog); - } - } - if ((logFile = fopen(logFileName, "w")) == NULL) - FatalError("Cannot open log file \"%s\"\n", logFileName); - setvbuf(logFile, NULL, _IONBF, 0); - - /* Flush saved log information. */ - if (saveBuffer && bufferSize > 0) { - fwrite(saveBuffer, bufferPos, 1, logFile); - fflush(logFile); -#ifndef WIN32 - fsync(fileno(logFile)); -#endif - } - } - - /* - * Unconditionally free the buffer, and flag that the buffer is no longer - * needed. - */ - if (saveBuffer && bufferSize > 0) { - free(saveBuffer); /* Must be free(), not xfree() */ - saveBuffer = NULL; - bufferSize = 0; - } - needBuffer = FALSE; - - return logFileName; -} - -void -LogClose() -{ - if (logFile) { - fclose(logFile); - logFile = NULL; - } -} - -Bool -LogSetParameter(LogParameter param, int value) -{ - switch (param) { - case XLOG_FLUSH: - logFlush = value ? TRUE : FALSE; - return TRUE; - case XLOG_SYNC: - logSync = value ? TRUE : FALSE; - return TRUE; - case XLOG_VERBOSITY: - logVerbosity = value; - return TRUE; - case XLOG_FILE_VERBOSITY: - logFileVerbosity = value; - return TRUE; - default: - return FALSE; - } -} - -/* This function does the actual log message writes. */ - -void -LogVWrite(int verb, const char *f, va_list args) -{ - static char tmpBuffer[1024]; - int len = 0; - - /* - * Since a va_list can only be processed once, write the string to a - * buffer, and then write the buffer out to the appropriate output - * stream(s). - */ - if (verb < 0 || logFileVerbosity >= verb || logVerbosity >= verb) { - vsnprintf(tmpBuffer, sizeof(tmpBuffer), f, args); - len = strlen(tmpBuffer); - } - if ((verb < 0 || logVerbosity >= verb) && len > 0) - fwrite(tmpBuffer, len, 1, stderr); - if ((verb < 0 || logFileVerbosity >= verb) && len > 0) { - if (logFile) { - fwrite(tmpBuffer, len, 1, logFile); - if (logFlush) { - fflush(logFile); -#ifndef WIN32 - if (logSync) - fsync(fileno(logFile)); -#endif - } - } else if (needBuffer) { - /* - * Note, this code is used before OsInit() has been called, so - * xalloc() and friends can't be used. - */ - if (len > bufferUnused) { - bufferSize += 1024; - bufferUnused += 1024; - if (saveBuffer) - saveBuffer = realloc(saveBuffer, bufferSize); - else - saveBuffer = malloc(bufferSize); - if (!saveBuffer) - FatalError("realloc() failed while saving log messages\n"); - } - bufferUnused -= len; - memcpy(saveBuffer + bufferPos, tmpBuffer, len); - bufferPos += len; - } - } -} - -void -LogWrite(int verb, const char *f, ...) -{ - va_list args; - - va_start(args, f); - LogVWrite(verb, f, args); - va_end(args); -} - -void -LogVMessageVerb(MessageType type, int verb, const char *format, va_list args) -{ - const char *s = X_UNKNOWN_STRING; - char *tmpBuf = NULL; - - /* Ignore verbosity for X_ERROR */ - if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) { - switch (type) { - case X_PROBED: - s = X_PROBE_STRING; - break; - case X_CONFIG: - s = X_CONFIG_STRING; - break; - case X_DEFAULT: - s = X_DEFAULT_STRING; - break; - case X_CMDLINE: - s = X_CMDLINE_STRING; - break; - case X_NOTICE: - s = X_NOTICE_STRING; - break; - case X_ERROR: - s = X_ERROR_STRING; - if (verb > 0) - verb = 0; - break; - case X_WARNING: - s = X_WARNING_STRING; - break; - case X_INFO: - s = X_INFO_STRING; - break; - case X_NOT_IMPLEMENTED: - s = X_NOT_IMPLEMENTED_STRING; - break; - case X_UNKNOWN: - s = X_UNKNOWN_STRING; - break; - case X_NONE: - s = NULL; - break; - } - - /* - * Prefix the format string with the message type. We do it this way - * so that LogVWrite() is only called once per message. - */ - if (s) { - tmpBuf = malloc(strlen(format) + strlen(s) + 1 + 1); - /* Silently return if malloc fails here. */ - if (!tmpBuf) - return; - sprintf(tmpBuf, "%s ", s); - strcat(tmpBuf, format); - LogVWrite(verb, tmpBuf, args); - free(tmpBuf); - } else - LogVWrite(verb, format, args); - } -} - -/* Log message with verbosity level specified. */ -void -LogMessageVerb(MessageType type, int verb, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - LogVMessageVerb(type, verb, format, ap); - va_end(ap); -} - -/* Log a message with the standard verbosity level of 1. */ -void -LogMessage(MessageType type, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - LogVMessageVerb(type, 1, format, ap); - va_end(ap); -} - -#ifdef __GNUC__ -void AbortServer(void) __attribute__((noreturn)); -#endif - -void -AbortServer(void) -{ - OsCleanup(TRUE); - AbortDDX(); - fflush(stderr); - if (CoreDump) - abort(); - exit (1); -} - -#ifndef AUDIT_PREFIX -#define AUDIT_PREFIX "AUDIT: %s: %ld %s: " -#endif -#ifndef AUDIT_TIMEOUT -#define AUDIT_TIMEOUT ((CARD32)(120 * 1000)) /* 2 mn */ -#endif - -static int nrepeat = 0; -static int oldlen = -1; -static OsTimerPtr auditTimer = NULL; - -void -FreeAuditTimer(void) -{ - if (auditTimer != NULL) { - /* Force output of pending messages */ - TimerForce(auditTimer); - TimerFree(auditTimer); - auditTimer = NULL; - } -} - -static char * -AuditPrefix(void) -{ - time_t tm; - char *autime, *s; - char *tmpBuf; - int len; - - time(&tm); - autime = ctime(&tm); - if ((s = strchr(autime, '\n'))) - *s = '\0'; - if ((s = strrchr(argvGlobal[0], '/'))) - s++; - else - s = argvGlobal[0]; - len = strlen(AUDIT_PREFIX) + strlen(autime) + 10 + strlen(s) + 1; - tmpBuf = malloc(len); - if (!tmpBuf) - return NULL; - snprintf(tmpBuf, len, AUDIT_PREFIX, autime, (unsigned long)getpid(), s); - return tmpBuf; -} - -void -AuditF(const char * f, ...) -{ - va_list args; - - va_start(args, f); - - VAuditF(f, args); - va_end(args); -} - -static CARD32 -AuditFlush(OsTimerPtr timer, CARD32 now, pointer arg) -{ - char *prefix; - - if (nrepeat > 0) { - prefix = AuditPrefix(); - ErrorF("%slast message repeated %d times\n", - prefix != NULL ? prefix : "", nrepeat); - nrepeat = 0; - if (prefix != NULL) - free(prefix); - return AUDIT_TIMEOUT; - } else { - /* if the timer expires without anything to print, flush the message */ - oldlen = -1; - return 0; - } -} - -void -VAuditF(const char *f, va_list args) -{ - char *prefix; - char buf[1024]; - int len; - static char oldbuf[1024]; - - prefix = AuditPrefix(); - len = vsnprintf(buf, sizeof(buf), f, args); - -#if 1 - /* XXX Compressing duplicated messages is temporarily disabled to - * work around bugzilla 964: - * https://freedesktop.org/bugzilla/show_bug.cgi?id=964 - */ - ErrorF("%s%s", prefix != NULL ? prefix : "", buf); - oldlen = -1; - nrepeat = 0; -#else - if (len == oldlen && strcmp(buf, oldbuf) == 0) { - /* Message already seen */ - nrepeat++; - } else { - /* new message */ - if (auditTimer != NULL) - TimerForce(auditTimer); - ErrorF("%s%s", prefix != NULL ? prefix : "", buf); - strlcpy(oldbuf, buf, sizeof(oldbuf)); - oldlen = len; - nrepeat = 0; - auditTimer = TimerSet(auditTimer, 0, AUDIT_TIMEOUT, AuditFlush, NULL); - } -#endif - if (prefix != NULL) - free(prefix); -} - -void -FatalError(const char *f, ...) -{ - va_list args; - static Bool beenhere = FALSE; - - if (beenhere) - ErrorF("\nFatalError re-entered, aborting\n"); - else - ErrorF("\nFatal server error:\n"); - - va_start(args, f); - VErrorF(f, args); - va_end(args); - ErrorF("\n"); -#ifdef DDXOSFATALERROR - if (!beenhere) - OsVendorFatalError(); -#endif -#ifdef ABORTONFATALERROR - abort(); -#endif - if (!beenhere) { - beenhere = TRUE; - AbortServer(); - } else - abort(); - /*NOTREACHED*/ -} - -void -VErrorF(const char *f, va_list args) -{ -#ifdef DDXOSVERRORF - if (OsVendorVErrorFProc) - OsVendorVErrorFProc(f, args); - else - LogVWrite(-1, f, args); -#else - LogVWrite(-1, f, args); -#endif -} - -void -ErrorF(const char * f, ...) -{ - va_list args; - - va_start(args, f); - VErrorF(f, args); - va_end(args); -} - -/* A perror() workalike. */ - -#ifndef NEED_STRERROR -#ifdef SYSV -#if !defined(ISC) || defined(ISC202) || defined(ISC22) -#define NEED_STRERROR -#endif -#endif -#endif - -#if defined(NEED_STRERROR) && !defined(strerror) -extern char *sys_errlist[]; -extern int sys_nerr; -#define strerror(n) \ - ((n) >= 0 && (n) < sys_nerr) ? sys_errlist[(n)] : "unknown error" -#endif - -void -Error(char *str) -{ - char *err = NULL; - int saveErrno = errno; - - if (str) { - err = malloc(strlen(strerror(saveErrno)) + strlen(str) + 2 + 1); - if (!err) - return; - sprintf(err, "%s: ", str); - strcat(err, strerror(saveErrno)); - LogWrite(-1, err); - } else - LogWrite(-1, strerror(saveErrno)); -} - -void -LogPrintMarkers() -{ - /* Show what the message marker symbols mean. */ - ErrorF("Markers: "); - LogMessageVerb(X_PROBED, -1, "probed, "); - LogMessageVerb(X_CONFIG, -1, "from config file, "); - LogMessageVerb(X_DEFAULT, -1, "default setting,\n\t"); - LogMessageVerb(X_CMDLINE, -1, "from command line, "); - LogMessageVerb(X_NOTICE, -1, "notice, "); - LogMessageVerb(X_INFO, -1, "informational,\n\t"); - LogMessageVerb(X_WARNING, -1, "warning, "); - LogMessageVerb(X_ERROR, -1, "error, "); - LogMessageVerb(X_NOT_IMPLEMENTED, -1, "not implemented, "); - LogMessageVerb(X_UNKNOWN, -1, "unknown.\n"); -} - diff --git a/nx-X11/programs/Xserver/os/oscolor.c.NX.original b/nx-X11/programs/Xserver/os/oscolor.c.NX.original deleted file mode 100644 index cf79857f4..000000000 --- a/nx-X11/programs/Xserver/os/oscolor.c.NX.original +++ /dev/null @@ -1,483 +0,0 @@ -/* $XFree86: xc/programs/Xserver/os/oscolor.c,v 3.10 2003/07/16 01:39:03 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: oscolor.c,v 1.4 2001/02/09 02:05:23 xorgcvs Exp $ */ - -#ifdef NX_TRANS_SOCKET - -#include -#include -#include - -static char* nxAltRgbPaths[] = {"/usr/NX/share/rgb", "/usr/share/X11/rgb", "/etc/X11/rgb"}; -static char _NXRgbPath[1024]; - -#endif - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifndef USE_RGB_TXT - -#ifdef NDBM -#include -#else -#ifdef SVR4 -#include -#else -#include -#endif -#endif -#include "rgb.h" -#include "os.h" -#include "opaque.h" - -/* Note that we are assuming there is only one database for all the screens. */ - -#ifdef NDBM -DBM *rgb_dbm = (DBM *)NULL; -#else -int rgb_dbm = 0; -#endif - -extern void CopyISOLatin1Lowered( - unsigned char * /*dest*/, - unsigned char * /*source*/, - int /*length*/); - -int -OsInitColors(void) -{ - if (!rgb_dbm) - { -#ifdef NDBM - rgb_dbm = dbm_open(rgbPath, 0, 0); -#else - if (dbminit(rgbPath) == 0) - rgb_dbm = 1; -#endif - if (!rgb_dbm) { - ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath ); - return FALSE; - } - } - return TRUE; -} - -/*ARGSUSED*/ -int -OsLookupColor(int screen, char *name, unsigned int len, - unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) -{ - datum dbent; - RGB rgb; - char buf[64]; - char *lowername; - - if(!rgb_dbm) - return(0); - - /* we use xalloc here so that we can compile with cc without alloca - * when otherwise using gcc */ - if (len < sizeof(buf)) - lowername = buf; - else if (!(lowername = (char *)xalloc(len + 1))) - return(0); - CopyISOLatin1Lowered ((unsigned char *) lowername, (unsigned char *) name, - (int)len); - - dbent.dptr = lowername; - dbent.dsize = len; -#ifdef NDBM - dbent = dbm_fetch(rgb_dbm, dbent); -#else - dbent = fetch (dbent); -#endif - - if (len >= sizeof(buf)) - xfree(lowername); - - if(dbent.dptr) - { - memmove((char *) &rgb, dbent.dptr, sizeof (RGB)); - *pred = rgb.red; - *pgreen = rgb.green; - *pblue = rgb.blue; - return (1); - } - return(0); -} - -#else /* USE_RGB_TXT */ - - -/* - * The dbm routines are a porting hassle. This implementation will do - * the same thing by reading the rgb.txt file directly, which is much - * more portable. - */ - -#include -#include "os.h" -#include "opaque.h" - -#define HASHSIZE 511 - -typedef struct _dbEntry * dbEntryPtr; -typedef struct _dbEntry { - dbEntryPtr link; - unsigned short red; - unsigned short green; - unsigned short blue; - char name[1]; /* some compilers complain if [0] */ -} dbEntry; - - -extern void CopyISOLatin1Lowered( - unsigned char * /*dest*/, - unsigned char * /*source*/, - int /*length*/); - -static dbEntryPtr hashTab[HASHSIZE]; - -#ifdef NX_TRANS_SOCKET - -static int NXVerifyRgbPath(char *path) -{ - int size; - char *rgbPath; - struct stat rgbFileStat; - - /* - * Check if rgb file is present. - */ - - size = strlen(path) + strlen(".txt") + 1; - - rgbPath = (char *) ALLOCATE_LOCAL(size + 1); - - strcpy(rgbPath, path); - - #ifdef NX_TRANS_TEST - fprintf(stderr, "NXVerifyRgbPath: Looking for [%s] file.\n", - rgbPath); - #endif - - if (stat(rgbPath, &rgbFileStat) != 0) - { - - #ifdef NX_TRANS_TEST - fprintf(stderr, "NXVerifyRgbPath: Can't find the rgb file [%s].\n", - rgbPath); - #endif - - strcat(rgbPath, ".txt"); - - #ifdef NX_TRANS_TEST - fprintf(stderr, "NXVerifyRgbPath: Looking for [%s] file.\n", - rgbPath); - #endif - - if (stat(rgbPath, &rgbFileStat) != 0) - { - - #ifdef NX_TRANS_TEST - fprintf(stderr, "NXVerifyRgbPath: Can't find the rgb file [%s].\n", - rgbPath); - #endif - - DEALLOCATE_LOCAL(rgbPath); - - return 0; - } - } - - #ifdef NX_TRANS_TEST - fprintf(stderr, "NXVerifyRgbPath: rgb path [%s] is valid.\n", - path); - #endif - - DEALLOCATE_LOCAL(rgbPath); - - return 1; -} - -static const char *_NXGetRgbPath(const char *path) -{ - const char *systemEnv; - char rgbPath[1024]; - int numAltRgbPaths; - int i; - - /* - * Check the environment only once. - */ - - if (*_NXRgbPath != '\0') - { - return _NXRgbPath; - } - - systemEnv = getenv("NX_SYSTEM"); - - if (systemEnv != NULL && *systemEnv != '\0') - { - if (strlen(systemEnv) + strlen("/share/rgb") + 1 > 1024) - { - - #ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetRgbPath: WARNING! Maximum length of rgb file path exceeded.\n"); - #endif - - goto _NXGetRgbPathError; - } - - strcpy(rgbPath, systemEnv); - strcat(rgbPath, "/share/rgb"); - - if (NXVerifyRgbPath(rgbPath) == 1) - { - strcpy(_NXRgbPath, systemEnv); - strcat(_NXRgbPath, "/share/rgb"); - - #ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetRgbPath: Using rgb file path [%s].\n", - _NXRgbPath); - #endif - - return _NXRgbPath; - } - } - - numAltRgbPaths = sizeof(nxAltRgbPaths) / sizeof(*nxAltRgbPaths); - - for (i = 0; i < numAltRgbPaths; i++) - { - if (NXVerifyRgbPath(nxAltRgbPaths[i]) == 1) - { - if (strlen(nxAltRgbPaths[i]) + 1 > 1024) - { - #ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetRgbPath: WARNING! Maximum length of rgb file path exceeded.\n"); - #endif - - goto _NXGetRgbPathError; - } - - strcpy(_NXRgbPath, nxAltRgbPaths[i]); - - #ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetRgbPath: Using rgb file path [%s].\n", - _NXRgbPath); - #endif - - return _NXRgbPath; - } - } - -_NXGetRgbPathError: - - strcpy(_NXRgbPath, path); - - #ifdef NX_TRANS_TEST - fprintf(stderr, "_NXGetRgbPath: Using default rgb file path [%s].\n", - _NXRgbPath); - #endif - - return _NXRgbPath; -} - -#endif - -static dbEntryPtr -lookup(char *name, int len, Bool create) -{ - unsigned int h = 0, g; - dbEntryPtr entry, *prev = NULL; - char *str = name; - - if (!(name = (char*)ALLOCATE_LOCAL(len +1))) return NULL; - CopyISOLatin1Lowered((unsigned char *)name, (unsigned char *)str, len); - name[len] = '\0'; - - for(str = name; *str; str++) { - h = (h << 4) + *str; - if ((g = h) & 0xf0000000) h ^= (g >> 24); - h &= g; - } - h %= HASHSIZE; - - if ( (entry = hashTab[h]) ) - { - for( ; entry; prev = (dbEntryPtr*)entry, entry = entry->link ) - if (! strcmp(name, entry->name) ) break; - } - else - prev = &(hashTab[h]); - - if (!entry && create && (entry = (dbEntryPtr)xalloc(sizeof(dbEntry) +len))) - { - *prev = entry; - entry->link = NULL; - strcpy( entry->name, name ); - } - - DEALLOCATE_LOCAL(name); - - return entry; -} - - -Bool -OsInitColors(void) -{ - FILE *rgb; - char *path; - char line[BUFSIZ]; - char name[BUFSIZ]; - int red, green, blue, lineno = 0; - dbEntryPtr entry; - - static Bool was_here = FALSE; - - if (!was_here) - { -#ifndef __UNIXOS2__ -#ifdef NX_TRANS_SOCKET - /* - * Add the trailing '.txt' if a - * 'rgb' file is not found. - */ - - struct stat statbuf; - - path = (char*)ALLOCATE_LOCAL(strlen(_NXGetRgbPath(rgbPath)) + 5); - strcpy(path, _NXGetRgbPath(rgbPath)); - - if (stat(path, &statbuf) != 0) - { - strcat(path, ".txt"); - } -#else - path = (char*)ALLOCATE_LOCAL(strlen(rgbPath) +5); - strcpy(path, rgbPath); - strcat(path, ".txt"); -#endif -#else - char *tmp = (char*)__XOS2RedirRoot(rgbPath); - path = (char*)ALLOCATE_LOCAL(strlen(tmp) +5); - strcpy(path, tmp); - strcat(path, ".txt"); -#endif - if (!(rgb = fopen(path, "r"))) - { -#ifdef NX_TRANS_SOCKET - ErrorF( "Couldn't open RGB_DB '%s'\n", _NXGetRgbPath(rgbPath)); -#else - ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath ); -#endif - DEALLOCATE_LOCAL(path); - return FALSE; - } - - while(fgets(line, sizeof(line), rgb)) - { - lineno++; -#ifndef __UNIXOS2__ - if (sscanf(line,"%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4) -#else - if (sscanf(line,"%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4) -#endif - { - if (red >= 0 && red <= 0xff && - green >= 0 && green <= 0xff && - blue >= 0 && blue <= 0xff) - { - if ((entry = lookup(name, strlen(name), TRUE))) - { - entry->red = (red * 65535) / 255; - entry->green = (green * 65535) / 255; - entry->blue = (blue * 65535) / 255; - } - } - else - ErrorF("Value out of range: %s:%d\n", path, lineno); - } - else if (*line && *line != '#' && *line != '!') - ErrorF("Syntax Error: %s:%d\n", path, lineno); - } - - fclose(rgb); - DEALLOCATE_LOCAL(path); - - was_here = TRUE; - } - - return TRUE; -} - - - -Bool -OsLookupColor(int screen, char *name, unsigned int len, - unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) -{ - dbEntryPtr entry; - - if ((entry = lookup(name, len, FALSE))) - { - *pred = entry->red; - *pgreen = entry->green; - *pblue = entry->blue; - return TRUE; - } - - return FALSE; -} - -#endif /* USE_RGB_TXT */ diff --git a/nx-X11/programs/Xserver/os/oscolor.c.X.original b/nx-X11/programs/Xserver/os/oscolor.c.X.original deleted file mode 100644 index fdbde7906..000000000 --- a/nx-X11/programs/Xserver/os/oscolor.c.X.original +++ /dev/null @@ -1,303 +0,0 @@ -/* $XFree86: xc/programs/Xserver/os/oscolor.c,v 3.10 2003/07/16 01:39:03 dawes Exp $ */ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -/* $Xorg: oscolor.c,v 1.4 2001/02/09 02:05:23 xorgcvs Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifndef USE_RGB_TXT - -#ifdef NDBM -#include -#else -#ifdef SVR4 -#include -#else -#include -#endif -#endif -#include "rgb.h" -#include "os.h" -#include "opaque.h" - -/* Note that we are assuming there is only one database for all the screens. */ - -#ifdef NDBM -DBM *rgb_dbm = (DBM *)NULL; -#else -int rgb_dbm = 0; -#endif - -extern void CopyISOLatin1Lowered( - unsigned char * /*dest*/, - unsigned char * /*source*/, - int /*length*/); - -int -OsInitColors(void) -{ - if (!rgb_dbm) - { -#ifdef NDBM - rgb_dbm = dbm_open(rgbPath, 0, 0); -#else - if (dbminit(rgbPath) == 0) - rgb_dbm = 1; -#endif - if (!rgb_dbm) { - ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath ); - return FALSE; - } - } - return TRUE; -} - -/*ARGSUSED*/ -int -OsLookupColor(int screen, char *name, unsigned int len, - unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) -{ - datum dbent; - RGB rgb; - char buf[64]; - char *lowername; - - if(!rgb_dbm) - return(0); - - /* we use xalloc here so that we can compile with cc without alloca - * when otherwise using gcc */ - if (len < sizeof(buf)) - lowername = buf; - else if (!(lowername = (char *)xalloc(len + 1))) - return(0); - CopyISOLatin1Lowered ((unsigned char *) lowername, (unsigned char *) name, - (int)len); - - dbent.dptr = lowername; - dbent.dsize = len; -#ifdef NDBM - dbent = dbm_fetch(rgb_dbm, dbent); -#else - dbent = fetch (dbent); -#endif - - if (len >= sizeof(buf)) - xfree(lowername); - - if(dbent.dptr) - { - memmove((char *) &rgb, dbent.dptr, sizeof (RGB)); - *pred = rgb.red; - *pgreen = rgb.green; - *pblue = rgb.blue; - return (1); - } - return(0); -} - -#else /* USE_RGB_TXT */ - - -/* - * The dbm routines are a porting hassle. This implementation will do - * the same thing by reading the rgb.txt file directly, which is much - * more portable. - */ - -#include -#include "os.h" -#include "opaque.h" - -#define HASHSIZE 511 - -typedef struct _dbEntry * dbEntryPtr; -typedef struct _dbEntry { - dbEntryPtr link; - unsigned short red; - unsigned short green; - unsigned short blue; - char name[1]; /* some compilers complain if [0] */ -} dbEntry; - - -extern void CopyISOLatin1Lowered( - unsigned char * /*dest*/, - unsigned char * /*source*/, - int /*length*/); - -static dbEntryPtr hashTab[HASHSIZE]; - - -static dbEntryPtr -lookup(char *name, int len, Bool create) -{ - unsigned int h = 0, g; - dbEntryPtr entry, *prev = NULL; - char *str = name; - - if (!(name = (char*)ALLOCATE_LOCAL(len +1))) return NULL; - CopyISOLatin1Lowered((unsigned char *)name, (unsigned char *)str, len); - name[len] = '\0'; - - for(str = name; *str; str++) { - h = (h << 4) + *str; - if ((g = h) & 0xf0000000) h ^= (g >> 24); - h &= g; - } - h %= HASHSIZE; - - if ( (entry = hashTab[h]) ) - { - for( ; entry; prev = (dbEntryPtr*)entry, entry = entry->link ) - if (! strcmp(name, entry->name) ) break; - } - else - prev = &(hashTab[h]); - - if (!entry && create && (entry = (dbEntryPtr)xalloc(sizeof(dbEntry) +len))) - { - *prev = entry; - entry->link = NULL; - strcpy( entry->name, name ); - } - - DEALLOCATE_LOCAL(name); - - return entry; -} - - -Bool -OsInitColors(void) -{ - FILE *rgb; - char *path; - char line[BUFSIZ]; - char name[BUFSIZ]; - int red, green, blue, lineno = 0; - dbEntryPtr entry; - - static Bool was_here = FALSE; - - if (!was_here) - { -#ifndef __UNIXOS2__ - path = (char*)ALLOCATE_LOCAL(strlen(rgbPath) +5); - strcpy(path, rgbPath); - strcat(path, ".txt"); -#else - char *tmp = (char*)__XOS2RedirRoot(rgbPath); - path = (char*)ALLOCATE_LOCAL(strlen(tmp) +5); - strcpy(path, tmp); - strcat(path, ".txt"); -#endif - if (!(rgb = fopen(path, "r"))) - { - ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath ); - DEALLOCATE_LOCAL(path); - return FALSE; - } - - while(fgets(line, sizeof(line), rgb)) - { - lineno++; -#ifndef __UNIXOS2__ - if (sscanf(line,"%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4) -#else - if (sscanf(line,"%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4) -#endif - { - if (red >= 0 && red <= 0xff && - green >= 0 && green <= 0xff && - blue >= 0 && blue <= 0xff) - { - if ((entry = lookup(name, strlen(name), TRUE))) - { - entry->red = (red * 65535) / 255; - entry->green = (green * 65535) / 255; - entry->blue = (blue * 65535) / 255; - } - } - else - ErrorF("Value out of range: %s:%d\n", path, lineno); - } - else if (*line && *line != '#' && *line != '!') - ErrorF("Syntax Error: %s:%d\n", path, lineno); - } - - fclose(rgb); - DEALLOCATE_LOCAL(path); - - was_here = TRUE; - } - - return TRUE; -} - - - -Bool -OsLookupColor(int screen, char *name, unsigned int len, - unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) -{ - dbEntryPtr entry; - - if ((entry = lookup(name, len, FALSE))) - { - *pred = entry->red; - *pgreen = entry->green; - *pblue = entry->blue; - return TRUE; - } - - return FALSE; -} - -#endif /* USE_RGB_TXT */ diff --git a/nx-X11/programs/Xserver/os/utils.c.NX.original b/nx-X11/programs/Xserver/os/utils.c.NX.original deleted file mode 100644 index 7e626542e..000000000 --- a/nx-X11/programs/Xserver/os/utils.c.NX.original +++ /dev/null @@ -1,2440 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/os/utils.c,v 1.21 2005/11/08 06:33:30 jkj Exp $ */ -/* $Xorg: utils.c,v 1.5 2001/02/09 02:05:24 xorgcvs Exp $ */ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, -Copyright 1994 Quarterdeck Office Systems. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital and -Quarterdeck not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE. - -*/ -/* $XFree86: xc/programs/Xserver/os/utils.c,v 3.96 2004/01/07 04:16:37 dawes Exp $ */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef __CYGWIN__ -#include -#include -#endif - -#if defined(WIN32) && !defined(__CYGWIN__) -#include -#endif -#include -#include -#include "misc.h" -#include -#include -#include "input.h" -#include "dixfont.h" -#include "osdep.h" -#ifdef X_POSIX_C_SOURCE -#define _POSIX_C_SOURCE X_POSIX_C_SOURCE -#include -#undef _POSIX_C_SOURCE -#else -#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE) -#include -#else -#define _POSIX_SOURCE -#include -#undef _POSIX_SOURCE -#endif -#endif -#ifndef WIN32 -#include -#endif -#if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4) -#include -#endif -#include -#include -#include /* for isspace */ -#include - -#if defined(DGUX) -#include -#include -#endif - -#include /* for malloc() */ - -#if defined(TCPCONN) || defined(STREAMSCONN) -# ifndef WIN32 -# include -# endif -#endif - -#include "opaque.h" - -#ifdef SMART_SCHEDULE -#include "dixstruct.h" -#endif - -#ifdef XKB -#include -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif - -#ifdef RENDER -#include "picture.h" -#endif - -#ifdef XPRINT -#include "DiPrint.h" -#endif - -Bool noTestExtensions; -#ifdef BIGREQS -Bool noBigReqExtension = FALSE; -#endif -#ifdef COMPOSITE -/* COMPOSITE is disabled by default for now until the - * interface is stable */ -Bool noCompositeExtension = TRUE; -#endif -#ifdef DAMAGE -Bool noDamageExtension = FALSE; -#endif -#ifdef DBE -Bool noDbeExtension = FALSE; -#endif -#ifdef DPSEXT -Bool noDPSExtension = FALSE; -#endif -#ifdef DPMSExtension -Bool noDPMSExtension = FALSE; -#endif -#ifdef EVI -Bool noEVIExtension = FALSE; -#endif -#ifdef FONTCACHE -Bool noFontCacheExtension = FALSE; -#endif -#ifdef GLXEXT -Bool noGlxExtension = FALSE; -#endif -#ifdef LBX -Bool noLbxExtension = FALSE; -#endif -#ifdef SCREENSAVER -Bool noScreenSaverExtension = FALSE; -#endif -#ifdef MITSHM -Bool noMITShmExtension = FALSE; -#endif -#ifdef MITMISC -Bool noMITMiscExtension = FALSE; -#endif -#ifdef MULTIBUFFER -Bool noMultibufferExtension = FALSE; -#endif -#ifdef RANDR -Bool noRRExtension = FALSE; -#endif -#ifdef RENDER -Bool noRenderExtension = FALSE; -#endif -#ifdef SHAPE -Bool noShapeExtension = FALSE; -#endif -#ifdef XCSECURITY -Bool noSecurityExtension = FALSE; -#endif -#ifdef XSYNC -Bool noSyncExtension = FALSE; -#endif -#ifdef TOGCUP -Bool noXcupExtension = FALSE; -#endif -#ifdef RES -Bool noResExtension = FALSE; -#endif -#ifdef XAPPGROUP -Bool noXagExtension = FALSE; -#endif -#ifdef XCMISC -Bool noXCMiscExtension = FALSE; -#endif -#ifdef XEVIE -/* Xevie is disabled by default for now until the - * interface is stable */ -Bool noXevieExtension = TRUE; -#endif -#ifdef XF86BIGFONT -Bool noXFree86BigfontExtension = FALSE; -#endif -#ifdef XFreeXDGA -Bool noXFree86DGAExtension = FALSE; -#endif -#ifdef XF86DRI -Bool noXFree86DRIExtension = FALSE; -#endif -#ifdef XF86MISC -Bool noXFree86MiscExtension = FALSE; -#endif -#ifdef XF86VIDMODE -Bool noXFree86VidModeExtension = FALSE; -#endif -#ifdef XFIXES -Bool noXFixesExtension = FALSE; -#endif -/* |noXkbExtension| is defined in xc/programs/Xserver/xkb/xkbInit.c */ -#ifdef PANORAMIX -/* Xinerama is disabled by default unless enabled via +xinerama */ -Bool noPanoramiXExtension = TRUE; -#endif -#ifdef XINPUT -Bool noXInputExtension = FALSE; -#endif -#ifdef XIDLE -Bool noXIdleExtension = FALSE; -#endif -#ifdef XV -Bool noXvExtension = FALSE; -#endif - -#define X_INCLUDE_NETDB_H -#include - -#include - -#ifdef NX_TRANS_SOCKET - -#include "NX.h" -#include "NXvars.h" - -#endif - -#ifdef NX_TRANS_EXIT - -void (*OsVendorStartRedirectErrorFProc)() = NULL; -void (*OsVendorEndRedirectErrorFProc)() = NULL; - -#endif - -Bool CoreDump; - -#ifdef PANORAMIX -Bool PanoramiXVisibilityNotifySent = FALSE; -Bool PanoramiXMapped = FALSE; -Bool PanoramiXWindowExposureSent = FALSE; -Bool PanoramiXOneExposeRequest = FALSE; -Bool PanoramiXExtensionDisabledHack = FALSE; -#endif - -int auditTrailLevel = 1; - -Bool Must_have_memory = FALSE; - -#ifdef AIXV3 -int SyncOn = 0; -extern int SelectWaitTime; -#endif - -#ifdef DEBUG -#ifndef SPECIAL_MALLOC -#define MEMBUG -#endif -#endif - -#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED) -#define HAS_SAVED_IDS_AND_SETEUID -#endif - -#ifdef MEMBUG -#define MEM_FAIL_SCALE 100000 -long Memory_fail = 0; -#include /* for random() */ -#endif - -#ifdef sgi -int userdefinedfontpath = 0; -#endif /* sgi */ - -char *dev_tty_from_init = NULL; /* since we need to parse it anyway */ - -extern char dispatchExceptionAtReset; - -/* Extension enable/disable in miinitext.c */ -extern Bool EnableDisableExtension(char *name, Bool enable); -extern void EnableDisableExtensionError(char *name, Bool enable); - -OsSigHandlerPtr -OsSignal(sig, handler) - int sig; - OsSigHandlerPtr handler; -{ -#ifdef X_NOT_POSIX - return signal(sig, handler); -#else - struct sigaction act, oact; - - sigemptyset(&act.sa_mask); - if (handler != SIG_IGN) - sigaddset(&act.sa_mask, sig); - act.sa_flags = 0; - act.sa_handler = handler; - sigaction(sig, &act, &oact); - return oact.sa_handler; -#endif -} - -#ifdef SERVER_LOCK -/* - * Explicit support for a server lock file like the ones used for UUCP. - * For architectures with virtual terminals that can run more than one - * server at a time. This keeps the servers from stomping on each other - * if the user forgets to give them different display numbers. - */ -#ifndef __UNIXOS2__ -#define LOCK_DIR "/tmp" -#endif -#define LOCK_TMP_PREFIX "/.tX" -#define LOCK_PREFIX "/.X" -#define LOCK_SUFFIX "-lock" - -#if defined(DGUX) -#include -#include -#endif - -#ifdef __UNIXOS2__ -#define link rename -#endif - -#ifndef PATH_MAX -#ifndef Lynx -#include -#else -#include -#endif -#ifndef PATH_MAX -#ifdef MAXPATHLEN -#define PATH_MAX MAXPATHLEN -#else -#define PATH_MAX 1024 -#endif -#endif -#endif - -static Bool StillLocking = FALSE; -static char LockFile[PATH_MAX]; -static Bool nolock = FALSE; - -/* - * LockServer -- - * Check if the server lock file exists. If so, check if the PID - * contained inside is valid. If so, then die. Otherwise, create - * the lock file containing the PID. - */ -void -LockServer(void) -{ - char tmp[PATH_MAX], pid_str[12]; - int lfd, i, haslock, l_pid, t; - char *tmppath = NULL; - int len; - char port[20]; - - if (nolock) return; - /* - * Path names - */ -#ifndef __UNIXOS2__ - tmppath = LOCK_DIR; -#else - /* OS/2 uses TMP directory, must also prepare for 8.3 names */ - tmppath = getenv("TMP"); - if (!tmppath) - FatalError("No TMP dir found\n"); -#endif - - sprintf(port, "%d", atoi(display)); - len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) : - strlen(LOCK_TMP_PREFIX); - len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1; - if (len > sizeof(LockFile)) - FatalError("Display name `%s' is too long\n", port); - (void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port); - (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port); - - /* - * Create a temporary file containing our PID. Attempt three times - * to create the file. - */ - StillLocking = TRUE; - i = 0; - do { - i++; - lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644); - if (lfd < 0) - sleep(2); - else - break; - } while (i < 3); - if (lfd < 0) { - unlink(tmp); - i = 0; - do { - i++; - lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644); - if (lfd < 0) - sleep(2); - else - break; - } while (i < 3); - } - if (lfd < 0) - FatalError("Could not create lock file in %s\n", tmp); - (void) sprintf(pid_str, "%10ld\n", (long)getpid()); - (void) write(lfd, pid_str, 11); -#ifndef __UNIXOS2__ -#ifndef USE_CHMOD - (void) fchmod(lfd, 0444); -#else - (void) chmod(tmp, 0444); -#endif -#endif - (void) close(lfd); - - /* - * OK. Now the tmp file exists. Try three times to move it in place - * for the lock. - */ - i = 0; - haslock = 0; - while ((!haslock) && (i++ < 3)) { - haslock = (link(tmp,LockFile) == 0); - if (haslock) { - /* - * We're done. - */ - break; - } - else { - /* - * Read the pid from the existing file - */ - lfd = open(LockFile, O_RDONLY); - if (lfd < 0) { - unlink(tmp); - FatalError("Can't read lock file %s\n", LockFile); - } - pid_str[0] = '\0'; - if (read(lfd, pid_str, 11) != 11) { - /* - * Bogus lock file. - */ - unlink(LockFile); - close(lfd); - continue; - } - pid_str[11] = '\0'; - sscanf(pid_str, "%d", &l_pid); - close(lfd); - - /* - * Now try to kill the PID to see if it exists. - */ - errno = 0; - t = kill(l_pid, 0); - if ((t< 0) && (errno == ESRCH)) { - /* - * Stale lock file. - */ - unlink(LockFile); - continue; - } - else if (((t < 0) && (errno == EPERM)) || (t == 0)) { - /* - * Process is still active. - */ - unlink(tmp); - FatalError("Server is already active for display %s\n%s %s\n%s\n", - port, "\tIf this server is no longer running, remove", - LockFile, "\tand start again."); - } - } - } - unlink(tmp); - if (!haslock) - FatalError("Could not create server lock file: %s\n", LockFile); - StillLocking = FALSE; -} - -/* - * UnlockServer -- - * Remove the server lock file. - */ -void -UnlockServer(void) -{ - if (nolock) return; - - if (!StillLocking){ - -#ifdef __UNIXOS2__ - (void) chmod(LockFile,S_IREAD|S_IWRITE); -#endif /* __UNIXOS2__ */ - (void) unlink(LockFile); - } -} -#endif /* SERVER_LOCK */ - -/* Force connections to close on SIGHUP from init */ - -/*ARGSUSED*/ -SIGVAL -AutoResetServer (int sig) -{ - int olderrno = errno; - - dispatchException |= DE_RESET; - isItTimeToYield = TRUE; -#ifdef GPROF - chdir ("/tmp"); - exit (0); -#endif -#if defined(SYSV) && defined(X_NOT_POSIX) - OsSignal (SIGHUP, AutoResetServer); -#endif - errno = olderrno; -} - -/* Force connections to close and then exit on SIGTERM, SIGINT */ - -/*ARGSUSED*/ -SIGVAL -GiveUp(int sig) -{ - int olderrno = errno; - -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST) - fprintf(stderr, "GiveUp: Called with signal [%d].\n", sig); -#endif - - dispatchException |= DE_TERMINATE; - isItTimeToYield = TRUE; -#if defined(SYSV) && defined(X_NOT_POSIX) - if (sig) - OsSignal(sig, SIG_IGN); -#endif - errno = olderrno; -} - -#ifndef DDXTIME -CARD32 -GetTimeInMillis(void) -{ - struct timeval tp; - - X_GETTIMEOFDAY(&tp); - return(tp.tv_sec * 1000) + (tp.tv_usec / 1000); -} -#endif - -void -AdjustWaitForDelay (pointer waitTime, unsigned long newdelay) -{ - static struct timeval delay_val; - struct timeval **wt = (struct timeval **) waitTime; - unsigned long olddelay; - - if (*wt == NULL) - { - delay_val.tv_sec = newdelay / 1000; - delay_val.tv_usec = 1000 * (newdelay % 1000); - *wt = &delay_val; - } - else - { - olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000; - if (newdelay < olddelay) - { - (*wt)->tv_sec = newdelay / 1000; - (*wt)->tv_usec = 1000 * (newdelay % 1000); - } - } -} - -void UseMsg(void) -{ -#if !defined(AIXrt) && !defined(AIX386) - ErrorF("use: X [:] [option]\n"); - ErrorF("-a # mouse acceleration (pixels)\n"); - ErrorF("-ac disable access control restrictions\n"); -#ifdef MEMBUG - ErrorF("-alloc int chance alloc should fail\n"); -#endif - ErrorF("-audit int set audit trail level\n"); - ErrorF("-auth file select authorization file\n"); - ErrorF("bc enable bug compatibility\n"); - ErrorF("-br create root window with black background\n"); - ErrorF("+bs enable any backing store support\n"); - ErrorF("-bs disable any backing store support\n"); - ErrorF("-c turns off key-click\n"); - ErrorF("c # key-click volume (0-100)\n"); - ErrorF("-cc int default color visual class\n"); - ErrorF("-co file color database file\n"); -#ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS - ErrorF("-config file read options from file\n"); -#endif - ErrorF("-core generate core dump on fatal error\n"); - ErrorF("-dpi int screen resolution in dots per inch\n"); -#ifdef DPMSExtension - ErrorF("dpms enables VESA DPMS monitor control\n"); - ErrorF("-dpms disables VESA DPMS monitor control\n"); -#endif - ErrorF("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n"); - ErrorF("-f # bell base (0-100)\n"); - ErrorF("-fc string cursor font\n"); - ErrorF("-fn string default font name\n"); - ErrorF("-fp string default font path\n"); - ErrorF("-help prints message with these options\n"); - ErrorF("-I ignore all remaining arguments\n"); -#ifdef RLIMIT_DATA - ErrorF("-ld int limit data space to N Kb\n"); -#endif -#ifdef RLIMIT_NOFILE - ErrorF("-lf int limit number of open files to N\n"); -#endif -#ifdef RLIMIT_STACK - ErrorF("-ls int limit stack space to N Kb\n"); -#endif -#ifdef SERVER_LOCK - ErrorF("-nolock disable the locking mechanism\n"); -#endif -#ifndef NOLOGOHACK - ErrorF("-logo enable logo in screen saver\n"); - ErrorF("nologo disable logo in screen saver\n"); -#endif - ErrorF("-nolisten string don't listen on protocol\n"); - ErrorF("-noreset don't reset after last client exists\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"); - ErrorF("-nopn reject failure to listen on all ports\n"); - ErrorF("-r turns off auto-repeat\n"); - ErrorF("r turns on auto-repeat \n"); -#ifdef RENDER - ErrorF("-render [default|mono|gray|color] set render color alloc policy\n"); -#endif - ErrorF("-s # screen-saver timeout (minutes)\n"); -#ifdef XCSECURITY - ErrorF("-sp file security policy file\n"); -#endif -#ifdef XPRINT - PrinterUseMsg(); -#endif - ErrorF("-su disable any save under support\n"); - ErrorF("-t # mouse threshold (pixels)\n"); - ErrorF("-terminate terminate at server reset\n"); - ErrorF("-to # connection time out\n"); - ErrorF("-tst disable testing extensions\n"); - ErrorF("ttyxx server started from init on /dev/ttyxx\n"); - ErrorF("v video blanking for screen-saver\n"); - ErrorF("-v screen-saver without video blanking\n"); - ErrorF("-wm WhenMapped default backing-store\n"); - ErrorF("-x string loads named extension at init time \n"); - ErrorF("-maxbigreqsize set maximal bigrequest size \n"); -#ifdef PANORAMIX - ErrorF("+xinerama Enable XINERAMA extension\n"); - ErrorF("-xinerama Disable XINERAMA extension\n"); -#endif -#ifdef SMART_SCHEDULE - ErrorF("-dumbSched Disable smart scheduling, enable old behavior\n"); - ErrorF("-schedInterval int Set scheduler interval in msec\n"); -#endif - ErrorF("+extension name Enable extension\n"); - ErrorF("-extension name Disable extension\n"); -#ifdef XDMCP - XdmcpUseMsg(); -#endif -#endif /* !AIXrt && ! AIX386 */ -#ifdef XKB - XkbUseMsg(); -#endif - ddxUseMsg(); -} - -/* This function performs a rudimentary sanity check - * on the display name passed in on the command-line, - * since this string is used to generate filenames. - * It is especially important that the display name - * not contain a "/" and not start with a "-". - * --kvajk - */ -static int -VerifyDisplayName(const char *d) -{ - if ( d == (char *)0 ) return( 0 ); /* null */ - if ( *d == '\0' ) return( 0 ); /* empty */ - if ( *d == '-' ) return( 0 ); /* could be confused for an option */ - if ( *d == '.' ) return( 0 ); /* must not equal "." or ".." */ - if ( strchr(d, '/') != (char *)0 ) return( 0 ); /* very important!!! */ - return( 1 ); -} - -/* - * This function is responsible for doing initalisation of any global - * variables at an very early point of server startup (even before - * |ProcessCommandLine()|. - */ -void InitGlobals(void) -{ - ddxInitGlobals(); -} - - -/* - * This function parses the command line. Handles device-independent fields - * and allows ddx to handle additional fields. It is not allowed to modify - * argc or any of the strings pointed to by argv. - */ -void -ProcessCommandLine(int argc, char *argv[]) -{ - int i, skip; - - defaultKeyboardControl.autoRepeat = TRUE; - -#ifdef NO_PART_NET - PartialNetwork = FALSE; -#else - PartialNetwork = TRUE; -#endif - - for ( i = 1; i < argc; i++ ) - { - /* call ddx first, so it can peek/override if it wants */ - if((skip = ddxProcessArgument(argc, argv, i))) - { - i += (skip - 1); - } - else if(argv[i][0] == ':') - { - /* initialize display */ - display = argv[i]; - display++; - if( ! VerifyDisplayName( display ) ) { - ErrorF("Bad display name: %s\n", display); - UseMsg(); - FatalError("Bad display name, exiting: %s\n", display); - } - } - else if ( strcmp( argv[i], "-a") == 0) - { - if(++i < argc) - defaultPointerControl.num = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-ac") == 0) - { - defeatAccessControl = TRUE; - } -#ifdef MEMBUG - else if ( strcmp( argv[i], "-alloc") == 0) - { - if(++i < argc) - Memory_fail = atoi(argv[i]); - else - UseMsg(); - } -#endif - else if ( strcmp( argv[i], "-audit") == 0) - { - if(++i < argc) - auditTrailLevel = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-auth") == 0) - { - if(++i < argc) - InitAuthorization (argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "bc") == 0) - permitOldBugs = TRUE; - else if ( strcmp( argv[i], "-br") == 0) - blackRoot = TRUE; - else if ( strcmp( argv[i], "+bs") == 0) - enableBackingStore = TRUE; - else if ( strcmp( argv[i], "-bs") == 0) - disableBackingStore = TRUE; - else if ( strcmp( argv[i], "c") == 0) - { - if(++i < argc) - defaultKeyboardControl.click = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-c") == 0) - { - defaultKeyboardControl.click = 0; - } - else if ( strcmp( argv[i], "-cc") == 0) - { - if(++i < argc) - defaultColorVisualClass = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-co") == 0) - { - if(++i < argc) - rgbPath = argv[i]; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-core") == 0) - CoreDump = TRUE; - else if ( strcmp( argv[i], "-dpi") == 0) - { - if(++i < argc) - monitorResolution = atoi(argv[i]); - else - UseMsg(); - } -#ifdef DPMSExtension - else if ( strcmp( argv[i], "dpms") == 0) - DPMSEnabledSwitch = TRUE; - else if ( strcmp( argv[i], "-dpms") == 0) - DPMSDisabledSwitch = TRUE; -#endif - else if ( strcmp( argv[i], "-deferglyphs") == 0) - { - if(++i >= argc || !ParseGlyphCachingMode(argv[i])) - UseMsg(); - } - else if ( strcmp( argv[i], "-f") == 0) - { - if(++i < argc) - defaultKeyboardControl.bell = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-fc") == 0) - { - if(++i < argc) - defaultCursorFont = argv[i]; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-fn") == 0) - { - if(++i < argc) - defaultTextFont = argv[i]; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-fp") == 0) - { - if(++i < argc) - { -#ifdef sgi - userdefinedfontpath = 1; -#endif /* sgi */ - defaultFontPath = argv[i]; - } - else - UseMsg(); - } - else if ( strcmp( argv[i], "-help") == 0) - { - UseMsg(); - exit(0); - } -#ifdef XKB - else if ( (skip=XkbProcessArguments(argc,argv,i))!=0 ) { - if (skip>0) - i+= skip-1; - else UseMsg(); - } -#endif -#ifdef RLIMIT_DATA - else if ( strcmp( argv[i], "-ld") == 0) - { - if(++i < argc) - { - limitDataSpace = atoi(argv[i]); - if (limitDataSpace > 0) - limitDataSpace *= 1024; - } - else - UseMsg(); - } -#endif -#ifdef RLIMIT_NOFILE - else if ( strcmp( argv[i], "-lf") == 0) - { - if(++i < argc) - limitNoFile = atoi(argv[i]); - else - UseMsg(); - } -#endif -#ifdef RLIMIT_STACK - else if ( strcmp( argv[i], "-ls") == 0) - { - if(++i < argc) - { - limitStackSpace = atoi(argv[i]); - if (limitStackSpace > 0) - limitStackSpace *= 1024; - } - else - UseMsg(); - } -#endif -#ifdef SERVER_LOCK - else if ( strcmp ( argv[i], "-nolock") == 0) - { -#if !defined(WIN32) && !defined(__UNIXOS2__) && !defined(__CYGWIN__) - if (getuid() != 0) - ErrorF("Warning: the -nolock option can only be used by root\n"); - else -#endif - nolock = TRUE; - } -#endif -#ifndef NOLOGOHACK - else if ( strcmp( argv[i], "-logo") == 0) - { - logoScreenSaver = 1; - } - else if ( strcmp( argv[i], "nologo") == 0) - { - logoScreenSaver = 0; - } -#endif - else if ( strcmp( argv[i], "-nolisten") == 0) - { - if(++i < argc) { - if (_XSERVTransNoListen(argv[i])) - FatalError ("Failed to disable listen for %s transport", - argv[i]); - } else - UseMsg(); - } - else if ( strcmp( argv[i], "-noreset") == 0) - { - dispatchExceptionAtReset = 0; - } - else if ( strcmp( argv[i], "-reset") == 0) - { - dispatchExceptionAtReset = DE_RESET; - } - else if ( strcmp( argv[i], "-p") == 0) - { - if(++i < argc) - defaultScreenSaverInterval = ((CARD32)atoi(argv[i])) * - MILLI_PER_MIN; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-pn") == 0) - PartialNetwork = TRUE; - else if ( strcmp( argv[i], "-nopn") == 0) - PartialNetwork = FALSE; - else if ( strcmp( argv[i], "r") == 0) - defaultKeyboardControl.autoRepeat = TRUE; - else if ( strcmp( argv[i], "-r") == 0) - defaultKeyboardControl.autoRepeat = FALSE; - else if ( strcmp( argv[i], "-s") == 0) - { - if(++i < argc) - defaultScreenSaverTime = ((CARD32)atoi(argv[i])) * - MILLI_PER_MIN; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-su") == 0) - disableSaveUnders = TRUE; - else if ( strcmp( argv[i], "-t") == 0) - { - if(++i < argc) - defaultPointerControl.threshold = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-terminate") == 0) - { - dispatchExceptionAtReset = DE_TERMINATE; - } - else if ( strcmp( argv[i], "-to") == 0) - { - if(++i < argc) - TimeOutValue = ((CARD32)atoi(argv[i])) * MILLI_PER_SECOND; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-tst") == 0) - { - noTestExtensions = TRUE; - } - else if ( strcmp( argv[i], "v") == 0) - defaultScreenSaverBlanking = PreferBlanking; - else if ( strcmp( argv[i], "-v") == 0) - defaultScreenSaverBlanking = DontPreferBlanking; - else if ( strcmp( argv[i], "-wm") == 0) - defaultBackingStore = WhenMapped; - else if ( strcmp( argv[i], "-maxbigreqsize") == 0) { - if(++i < argc) { - long reqSizeArg = atol(argv[i]); - - /* Request size > 128MB does not make much sense... */ - if( reqSizeArg > 0L && reqSizeArg < 128L ) { - maxBigRequestSize = (reqSizeArg * 1048576L) - 1L; - } - else - { - UseMsg(); - } - } - else - { - UseMsg(); - } - } -#ifdef PANORAMIX - else if ( strcmp( argv[i], "+xinerama") == 0){ - noPanoramiXExtension = FALSE; - } - else if ( strcmp( argv[i], "-xinerama") == 0){ - noPanoramiXExtension = TRUE; - } - else if ( strcmp( argv[i], "-disablexineramaextension") == 0){ - PanoramiXExtensionDisabledHack = TRUE; - } -#endif - else if ( strcmp( argv[i], "-x") == 0) - { - if(++i >= argc) - UseMsg(); - /* For U**x, which doesn't support dynamic loading, there's nothing - * to do when we see a -x. Either the extension is linked in or - * it isn't */ - } - else if ( strcmp( argv[i], "-I") == 0) - { - /* ignore all remaining arguments */ - break; - } - else if (strncmp (argv[i], "tty", 3) == 0) - { - /* just in case any body is interested */ - dev_tty_from_init = argv[i]; - } -#ifdef XDMCP - else if ((skip = XdmcpOptions(argc, argv, i)) != i) - { - i = skip - 1; - } -#endif -#ifdef XPRINT - else if ((skip = PrinterOptions(argc, argv, i)) != i) - { - i = skip - 1; - } -#endif -#ifdef XCSECURITY - else if ((skip = XSecurityOptions(argc, argv, i)) != i) - { - i = skip - 1; - } -#endif -#ifdef AIXV3 - else if ( strcmp( argv[i], "-timeout") == 0) - { - if(++i < argc) - SelectWaitTime = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-sync") == 0) - { - SyncOn++; - } -#endif -#ifdef SMART_SCHEDULE - else if ( strcmp( argv[i], "-dumbSched") == 0) - { - SmartScheduleDisable = TRUE; - } - else if ( strcmp( argv[i], "-schedInterval") == 0) - { - if (++i < argc) - { - SmartScheduleInterval = atoi(argv[i]); - SmartScheduleSlice = SmartScheduleInterval; - } - else - UseMsg(); - } - else if ( strcmp( argv[i], "-schedMax") == 0) - { - if (++i < argc) - { - SmartScheduleMaxSlice = atoi(argv[i]); - } - else - UseMsg(); - } -#endif -#ifdef RENDER - else if ( strcmp( argv[i], "-render" ) == 0) - { - if (++i < argc) - { - int policy = PictureParseCmapPolicy (argv[i]); - - if (policy != PictureCmapPolicyInvalid) - PictureCmapPolicy = policy; - else - UseMsg (); - } - else - UseMsg (); - } -#endif - else if ( strcmp( argv[i], "+extension") == 0) - { - if (++i < argc) - { - if (!EnableDisableExtension(argv[i], TRUE)) - EnableDisableExtensionError(argv[i], TRUE); - } - else - UseMsg(); - } - else if ( strcmp( argv[i], "-extension") == 0) - { - if (++i < argc) - { - if (!EnableDisableExtension(argv[i], FALSE)) - EnableDisableExtensionError(argv[i], FALSE); - } - else - UseMsg(); - } - else - { - ErrorF("Unrecognized option: %s\n", argv[i]); - UseMsg(); - FatalError("Unrecognized option: %s\n", argv[i]); - } - } -} - -#ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS -static void -InsertFileIntoCommandLine( - int *resargc, char ***resargv, - int prefix_argc, char **prefix_argv, - char *filename, - int suffix_argc, char **suffix_argv) -{ - struct stat st; - FILE *f; - char *p; - char *q; - int insert_argc; - char *buf; - int len; - int i; - - f = fopen(filename, "r"); - if (!f) - FatalError("Can't open option file %s\n", filename); - - fstat(fileno(f), &st); - - buf = (char *) xalloc((unsigned) st.st_size + 1); - if (!buf) - FatalError("Out of Memory\n"); - - len = fread(buf, 1, (unsigned) st.st_size, f); - - fclose(f); - - if (len < 0) - FatalError("Error reading option file %s\n", filename); - - buf[len] = '\0'; - - p = buf; - q = buf; - insert_argc = 0; - - while (*p) - { - while (isspace(*p)) - p++; - if (!*p) - break; - if (*p == '#') - { - while (*p && *p != '\n') - p++; - } else - { - while (*p && !isspace(*p)) - *q++ = *p++; - /* Since p and q might still be pointing at the same place, we */ - /* need to step p over the whitespace now before we add the null. */ - if (*p) - p++; - *q++ = '\0'; - insert_argc++; - } - } - - buf = (char *) xrealloc(buf, q - buf); - if (!buf) - FatalError("Out of memory reallocing option buf\n"); - - *resargc = prefix_argc + insert_argc + suffix_argc; - *resargv = (char **) xalloc((*resargc + 1) * sizeof(char *)); - if (!*resargv) - FatalError("Out of Memory\n"); - - memcpy(*resargv, prefix_argv, prefix_argc * sizeof(char *)); - - p = buf; - for (i = 0; i < insert_argc; i++) - { - (*resargv)[prefix_argc + i] = p; - p += strlen(p) + 1; - } - - memcpy(*resargv + prefix_argc + insert_argc, - suffix_argv, suffix_argc * sizeof(char *)); - - (*resargv)[*resargc] = NULL; -} /* end InsertFileIntoCommandLine */ - - -void -ExpandCommandLine(int *pargc, char ***pargv) -{ - int i; - -#if !defined(WIN32) && !defined(__UNIXOS2__) && !defined(__CYGWIN__) - if (getuid() != geteuid()) - return; -#endif - - for (i = 1; i < *pargc; i++) - { - if ( (0 == strcmp((*pargv)[i], "-config")) && (i < (*pargc - 1)) ) - { - InsertFileIntoCommandLine(pargc, pargv, - i, *pargv, - (*pargv)[i+1], /* filename */ - *pargc - i - 2, *pargv + i + 2); - i--; - } - } -} /* end ExpandCommandLine */ -#endif - -/* Implement a simple-minded font authorization scheme. The authorization - name is "hp-hostname-1", the contents are simply the host name. */ -int -set_font_authorizations(char **authorizations, int *authlen, pointer client) -{ -#define AUTHORIZATION_NAME "hp-hostname-1" -#if defined(TCPCONN) || defined(STREAMSCONN) - static char *result = NULL; - static char *p = NULL; - - if (p == NULL) - { - char hname[1024], *hnameptr; - unsigned int len; -#if defined(IPv6) && defined(AF_INET6) - struct addrinfo hints, *ai = NULL; -#else - struct hostent *host; -#ifdef XTHREADS_NEEDS_BYNAMEPARAMS - _Xgethostbynameparams hparams; -#endif -#endif - - gethostname(hname, 1024); -#if defined(IPv6) && defined(AF_INET6) - bzero(&hints, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - if (getaddrinfo(hname, NULL, &hints, &ai) == 0) { - hnameptr = ai->ai_canonname; - } else { - hnameptr = hname; - } -#else - host = _XGethostbyname(hname, hparams); - if (host == NULL) - hnameptr = hname; - else - hnameptr = host->h_name; -#endif - - len = strlen(hnameptr) + 1; - result = xalloc(len + sizeof(AUTHORIZATION_NAME) + 4); - - p = result; - *p++ = sizeof(AUTHORIZATION_NAME) >> 8; - *p++ = sizeof(AUTHORIZATION_NAME) & 0xff; - *p++ = (len) >> 8; - *p++ = (len & 0xff); - - memmove(p, AUTHORIZATION_NAME, sizeof(AUTHORIZATION_NAME)); - p += sizeof(AUTHORIZATION_NAME); - memmove(p, hnameptr, len); - p += len; -#if defined(IPv6) && defined(AF_INET6) - if (ai) { - freeaddrinfo(ai); - } -#endif - } - *authlen = p - result; - *authorizations = result; - return 1; -#else /* TCPCONN */ - return 0; -#endif /* TCPCONN */ -} - -/* XALLOC -- X's internal memory allocator. Why does it return unsigned - * long * instead of the more common char *? Well, if you read K&R you'll - * see they say that alloc must return a pointer "suitable for conversion" - * to whatever type you really want. In a full-blown generic allocator - * there's no way to solve the alignment problems without potentially - * wasting lots of space. But we have a more limited problem. We know - * we're only ever returning pointers to structures which will have to - * be long word aligned. So we are making a stronger guarantee. It might - * have made sense to make Xalloc return char * to conform with people's - * expectations of malloc, but this makes lint happier. - */ - -#ifndef INTERNAL_MALLOC - -void * -Xalloc(unsigned long amount) -{ - register pointer ptr; - - if ((long)amount <= 0) { - return (unsigned long *)NULL; - } - /* aligned extra on long word boundary */ - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); -#ifdef MEMBUG - if (!Must_have_memory && Memory_fail && - ((random() % MEM_FAIL_SCALE) < Memory_fail)) - return (unsigned long *)NULL; -#endif - if ((ptr = (pointer)malloc(amount))) { - return (unsigned long *)ptr; - } - if (Must_have_memory) - FatalError("Out of memory"); - return (unsigned long *)NULL; -} - -/***************** - * XNFalloc - * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory - *****************/ - -void * -XNFalloc(unsigned long amount) -{ - register pointer ptr; - - if ((long)amount <= 0) - { - return (unsigned long *)NULL; - } - /* aligned extra on long word boundary */ - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - ptr = (pointer)malloc(amount); - if (!ptr) - { - FatalError("Out of memory"); - } - return ((unsigned long *)ptr); -} - -/***************** - * Xcalloc - *****************/ - -void * -Xcalloc(unsigned long amount) -{ - unsigned long *ret; - - ret = Xalloc (amount); - if (ret) - bzero ((char *) ret, (int) amount); - return ret; -} - -/***************** - * XNFcalloc - *****************/ - -void * -XNFcalloc(unsigned long amount) -{ - unsigned long *ret; - - ret = Xalloc (amount); - if (ret) - bzero ((char *) ret, (int) amount); - else if ((long)amount > 0) - FatalError("Out of memory"); - return ret; -} - -/***************** - * Xrealloc - *****************/ - -void * -Xrealloc(pointer ptr, unsigned long amount) -{ -#ifdef MEMBUG - if (!Must_have_memory && Memory_fail && - ((random() % MEM_FAIL_SCALE) < Memory_fail)) - return (unsigned long *)NULL; -#endif - if ((long)amount <= 0) - { - if (ptr && !amount) - free(ptr); - return (unsigned long *)NULL; - } - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - if (ptr) - ptr = (pointer)realloc((char *)ptr, amount); - else - ptr = (pointer)malloc(amount); - if (ptr) - return (unsigned long *)ptr; - if (Must_have_memory) - FatalError("Out of memory"); - return (unsigned long *)NULL; -} - -/***************** - * XNFrealloc - * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory - *****************/ - -void * -XNFrealloc(pointer ptr, unsigned long amount) -{ - if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL) - { - if ((long)amount > 0) - FatalError( "Out of memory" ); - } - return ((unsigned long *)ptr); -} - -/***************** - * Xfree - * calls free - *****************/ - -void -Xfree(pointer ptr) -{ - if (ptr) - free((char *)ptr); -} - -void -OsInitAllocator (void) -{ -#ifdef MEMBUG - static int been_here; - - /* Check the memory system after each generation */ - if (been_here) - CheckMemory (); - else - been_here = 1; -#endif -} -#endif /* !INTERNAL_MALLOC */ - - -char * -Xstrdup(const char *s) -{ - char *sd; - - if (s == NULL) - return NULL; - - sd = (char *)Xalloc(strlen(s) + 1); - if (sd != NULL) - strcpy(sd, s); - return sd; -} - - -char * -XNFstrdup(const char *s) -{ - char *sd; - - if (s == NULL) - return NULL; - - sd = (char *)XNFalloc(strlen(s) + 1); - strcpy(sd, s); - return sd; -} - -#ifdef SMART_SCHEDULE - -unsigned long SmartScheduleIdleCount; -Bool SmartScheduleIdle; -Bool SmartScheduleTimerStopped; - -#ifdef SIGVTALRM -#define SMART_SCHEDULE_POSSIBLE -#endif - -#ifdef SMART_SCHEDULE_POSSIBLE -#define SMART_SCHEDULE_SIGNAL SIGALRM -#define SMART_SCHEDULE_TIMER ITIMER_REAL -#endif - -#ifdef NX_TRANS_SOCKET -void -SmartScheduleStopTimer (void) -#else -static void -SmartScheduleStopTimer (void) -#endif -{ -#ifdef SMART_SCHEDULE_POSSIBLE - struct itimerval timer; - - #ifdef NX_TRANS_TEST - fprintf(stderr, "SmartScheduleStopTimer: Stopping timer.\n"); - #endif - - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_usec = 0; - timer.it_value.tv_sec = 0; - timer.it_value.tv_usec = 0; - (void) setitimer (ITIMER_REAL, &timer, 0); - SmartScheduleTimerStopped = TRUE; -#endif -} - -Bool -SmartScheduleStartTimer (void) -{ -#ifdef SMART_SCHEDULE_POSSIBLE - struct itimerval timer; - - #ifdef NX_TRANS_SOCKET - - if (SmartScheduleDisable) - { - return FALSE; - } - - #endif - - #ifdef NX_TRANS_TEST - fprintf(stderr, "SmartScheduleStartTimer: Starting timer with [%ld] ms.\n", - SmartScheduleInterval); - #endif - - SmartScheduleTimerStopped = FALSE; - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_usec = SmartScheduleInterval * 1000; - timer.it_value.tv_sec = 0; - timer.it_value.tv_usec = SmartScheduleInterval * 1000; - return setitimer (ITIMER_REAL, &timer, 0) >= 0; -#endif - return FALSE; -} - -#ifdef SMART_SCHEDULE_POSSIBLE -static void -SmartScheduleTimer (int sig) -{ - int olderrno = errno; - - SmartScheduleTime += SmartScheduleInterval; - - #ifdef NX_TRANS_TEST - fprintf(stderr, "SmartScheduleTimer: Got timer with time [%ld] ms.\n", - SmartScheduleTime); - #endif - - if (SmartScheduleIdle) - { - SmartScheduleStopTimer (); - } - errno = olderrno; -} -#endif - -Bool -SmartScheduleInit (void) -{ -#ifdef SMART_SCHEDULE_POSSIBLE - struct sigaction act; - - if (SmartScheduleDisable) - return TRUE; - - #ifdef NX_TRANS_TEST - fprintf(stderr, "SmartScheduleInit: Initializing the smart scheduler.\n"); - #endif - - bzero ((char *) &act, sizeof(struct sigaction)); - - /* Set up the timer signal function */ - act.sa_handler = SmartScheduleTimer; - sigemptyset (&act.sa_mask); - sigaddset (&act.sa_mask, SMART_SCHEDULE_SIGNAL); - if (sigaction (SMART_SCHEDULE_SIGNAL, &act, 0) < 0) - { - perror ("sigaction for smart scheduler"); - return FALSE; - } - /* Set up the virtual timer */ - if (!SmartScheduleStartTimer ()) - { - perror ("scheduling timer"); - return FALSE; - } - /* stop the timer and wait for WaitForSomething to start it */ - SmartScheduleStopTimer (); - return TRUE; -#else - return FALSE; -#endif -} -#endif - -#ifdef SIG_BLOCK -static sigset_t PreviousSignalMask; -static int BlockedSignalCount; -#endif - -void -OsBlockSignals (void) -{ -#ifdef SIG_BLOCK - if (BlockedSignalCount++ == 0) - { - sigset_t set; - - sigemptyset (&set); -#ifdef SIGALRM - sigaddset (&set, SIGALRM); -#endif -#ifdef SIGVTALRM - sigaddset (&set, SIGVTALRM); -#endif -#ifdef SIGWINCH - sigaddset (&set, SIGWINCH); -#endif -#ifdef SIGIO - sigaddset (&set, SIGIO); -#endif -#ifdef SIGTSTP - sigaddset (&set, SIGTSTP); -#endif -#ifdef SIGTTIN - sigaddset (&set, SIGTTIN); -#endif -#ifdef SIGTTOU - sigaddset (&set, SIGTTOU); -#endif -#ifdef SIGCHLD - sigaddset (&set, SIGCHLD); -#endif - sigprocmask (SIG_BLOCK, &set, &PreviousSignalMask); - } -#endif -} - -void -OsReleaseSignals (void) -{ -#ifdef SIG_BLOCK - if (--BlockedSignalCount == 0) - { - sigprocmask (SIG_SETMASK, &PreviousSignalMask, 0); - } -#endif -} - -#if !defined(WIN32) && !defined(__UNIXOS2__) -/* - * "safer" versions of system(3), popen(3) and pclose(3) which give up - * all privs before running a command. - * - * This is based on the code in FreeBSD 2.2 libc. - * - * XXX It'd be good to redirect stderr so that it ends up in the log file - * as well. As it is now, xkbcomp messages don't end up in the log file. - */ - -int -System(char *command) -{ - int pid, p; -#ifdef SIGCHLD - void (*csig)(int); -#endif - int status; - - if (!command) - return(1); - -#ifdef SIGCHLD - csig = signal(SIGCHLD, SIG_DFL); -#endif - -#ifdef DEBUG - ErrorF("System: `%s'\n", command); -#endif - -#ifdef NX_TRANS_EXIT - if (OsVendorStartRedirectErrorFProc != NULL) { - OsVendorStartRedirectErrorFProc(); - } -#endif - switch (pid = fork()) { - case -1: /* error */ - p = -1; - case 0: /* child */ - if (setgid(getgid()) == -1) - _exit(127); - if (setuid(getuid()) == -1) - _exit(127); - execl("/bin/sh", "sh", "-c", command, (char *)NULL); - _exit(127); - default: /* parent */ - do { - p = waitpid(pid, &status, 0); - } while (p == -1 && errno == EINTR); - - } -#ifdef NX_TRANS_EXIT - if (OsVendorEndRedirectErrorFProc != NULL) { - OsVendorEndRedirectErrorFProc(); - } -#endif - -#ifdef SIGCHLD - signal(SIGCHLD, csig); -#endif - - return p == -1 ? -1 : status; -} - -static struct pid { - struct pid *next; - FILE *fp; - int pid; -} *pidlist; - -pointer -Popen(char *command, char *type) -{ - struct pid *cur; - FILE *iop; - int pdes[2], pid; - - if (command == NULL || type == NULL) - return NULL; - - if ((*type != 'r' && *type != 'w') || type[1]) - return NULL; - - if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) - return NULL; - - if (pipe(pdes) < 0) { - xfree(cur); - return NULL; - } - -#ifdef NX_TRANS_EXIT - if (OsVendorStartRedirectErrorFProc != NULL) { - OsVendorStartRedirectErrorFProc(); - } - OsBlockSignals (); -#endif - switch (pid = fork()) { - case -1: /* error */ - close(pdes[0]); - close(pdes[1]); - xfree(cur); -#ifdef NX_TRANS_EXIT - if (OsVendorEndRedirectErrorFProc != NULL) { - OsVendorEndRedirectErrorFProc(); - } - OsReleaseSignals (); -#endif - return NULL; - case 0: /* child */ - if (setgid(getgid()) == -1) - _exit(127); - if (setuid(getuid()) == -1) - _exit(127); - if (*type == 'r') { - if (pdes[1] != 1) { - /* stdout */ - dup2(pdes[1], 1); - close(pdes[1]); - } - close(pdes[0]); - } else { - if (pdes[0] != 0) { - /* stdin */ - dup2(pdes[0], 0); - close(pdes[0]); - } - close(pdes[1]); - } - - #ifdef NX_TRANS_SOCKET - - /* - * Check if the child process should not - * use the parent's libraries. - */ - - if (_NXUnsetLibraryPath) - { - #ifndef __sun - - unsetenv ("LD_LIBRARY_PATH"); - - #else - - extern char **environ; - - char **ep = environ; - - ep = environ; - - while (*ep) - { - if (!strncmp("LD_LIBRARY_PATH=", *ep, strlen("LD_LIBRARY_PATH="))) - { - break; - } - - *ep++; - } - - while (*ep) - { - *ep = *(ep + 1); - ep++; - } - - #endif - } - - #endif - - #ifdef NX_TRANS_EXIT - OsReleaseSignals (); - #endif - - execl("/bin/sh", "sh", "-c", command, (char *)NULL); - _exit(127); - } - -#ifndef NX_TRANS_EXIT - /* Avoid EINTR during stdio calls */ - OsBlockSignals (); -#endif - - /* parent */ - if (*type == 'r') { - iop = fdopen(pdes[0], type); - close(pdes[1]); - } else { - iop = fdopen(pdes[1], type); - close(pdes[0]); - } - - cur->fp = iop; - cur->pid = pid; - cur->next = pidlist; - pidlist = cur; - -#ifdef DEBUG - ErrorF("Popen: `%s', fp = %p\n", command, iop); -#endif - - return iop; -} - -/* fopen that drops privileges */ -pointer -Fopen(char *file, char *type) -{ - FILE *iop; -#ifndef HAS_SAVED_IDS_AND_SETEUID - struct pid *cur; - int pdes[2], pid; - - if (file == NULL || type == NULL) - return NULL; - - if ((*type != 'r' && *type != 'w') || type[1]) - return NULL; - - if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) - return NULL; - - if (pipe(pdes) < 0) { - xfree(cur); - return NULL; - } - - switch (pid = fork()) { - case -1: /* error */ - close(pdes[0]); - close(pdes[1]); - xfree(cur); - return NULL; - case 0: /* child */ - if (setgid(getgid()) == -1) - _exit(127); - if (setuid(getuid()) == -1) - _exit(127); - if (*type == 'r') { - if (pdes[1] != 1) { - /* stdout */ - dup2(pdes[1], 1); - close(pdes[1]); - } - close(pdes[0]); - } else { - if (pdes[0] != 0) { - /* stdin */ - dup2(pdes[0], 0); - close(pdes[0]); - } - close(pdes[1]); - } - execl("/bin/cat", "cat", file, (char *)NULL); - _exit(127); - } - - /* Avoid EINTR during stdio calls */ - OsBlockSignals (); - - /* parent */ - if (*type == 'r') { - iop = fdopen(pdes[0], type); - close(pdes[1]); - } else { - iop = fdopen(pdes[1], type); - close(pdes[0]); - } - - cur->fp = iop; - cur->pid = pid; - cur->next = pidlist; - pidlist = cur; - -#ifdef DEBUG - ErrorF("Popen: `%s', fp = %p\n", command, iop); -#endif - - return iop; -#else - int ruid, euid; - - ruid = getuid(); - euid = geteuid(); - - if (seteuid(ruid) == -1) { - return NULL; - } - iop = fopen(file, type); - - if (seteuid(euid) == -1) { - fclose(iop); - return NULL; - } - return iop; -#endif /* HAS_SAVED_IDS_AND_SETEUID */ -} - -int -Pclose(pointer iop) -{ - struct pid *cur, *last; - int pstat; - int pid; - -#ifdef DEBUG - ErrorF("Pclose: fp = %p\n", iop); -#endif - - fclose(iop); - - for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) - if (cur->fp == iop) - break; - if (cur == NULL) - return -1; - - do { - pid = waitpid(cur->pid, &pstat, 0); - } while (pid == -1 && errno == EINTR); - - if (last == NULL) - pidlist = cur->next; - else - last->next = cur->next; - xfree(cur); - - /* allow EINTR again */ - OsReleaseSignals (); - -#ifdef NX_TRANS_EXIT - if (OsVendorEndRedirectErrorFProc != NULL) { - OsVendorEndRedirectErrorFProc(); - } -#endif - return pid == -1 ? -1 : pstat; -} - -int -Fclose(pointer iop) -{ -#ifdef HAS_SAVED_IDS_AND_SETEUID - return fclose(iop); -#else - return Pclose(iop); -#endif -} - -#endif /* !WIN32 && !__UNIXOS2__ */ - - -/* - * CheckUserParameters: check for long command line arguments and long - * environment variables. By default, these checks are only done when - * the server's euid != ruid. In 3.3.x, these checks were done in an - * external wrapper utility. - */ - -/* Consider LD* variables insecure? */ -#ifndef REMOVE_ENV_LD -#define REMOVE_ENV_LD 1 -#endif - -/* Remove long environment variables? */ -#ifndef REMOVE_LONG_ENV -#define REMOVE_LONG_ENV 1 -#endif - -/* - * Disallow stdout or stderr as pipes? It's possible to block the X server - * when piping stdout+stderr to a pipe. - * - * Don't enable this because it looks like it's going to cause problems. - */ -#ifndef NO_OUTPUT_PIPES -#define NO_OUTPUT_PIPES 0 -#endif - - -/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */ -#ifndef CHECK_EUID -#ifndef WIN32 -#define CHECK_EUID 1 -#else -#define CHECK_EUID 0 -#endif -#endif - -/* - * Maybe the locale can be faked to make isprint(3) report that everything - * is printable? Avoid it by default. - */ -#ifndef USE_ISPRINT -#define USE_ISPRINT 0 -#endif - -#define MAX_ARG_LENGTH 128 -#define MAX_ENV_LENGTH 256 -#define MAX_ENV_PATH_LENGTH 2048 /* Limit for *PATH and TERMCAP */ - -#if USE_ISPRINT -#include -#define checkPrintable(c) isprint(c) -#else -#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f) -#endif - -enum BadCode { - NotBad = 0, - UnsafeArg, - ArgTooLong, - UnprintableArg, - EnvTooLong, - OutputIsPipe, - InternalError -}; - -#if defined(VENDORSUPPORT) -#define BUGADDRESS VENDORSUPPORT -#elif defined(BUILDERADDR) -#define BUGADDRESS BUILDERADDR -#else -#define BUGADDRESS "xorg@freedesktop.org" -#endif - -#define ARGMSG \ - "\nIf the arguments used are valid, and have been rejected incorrectly\n" \ - "please send details of the arguments and why they are valid to\n" \ - "%s. In the meantime, you can start the Xserver as\n" \ - "the \"super user\" (root).\n" - -#define ENVMSG \ - "\nIf the environment is valid, and have been rejected incorrectly\n" \ - "please send details of the environment and why it is valid to\n" \ - "%s. In the meantime, you can start the Xserver as\n" \ - "the \"super user\" (root).\n" - -void -CheckUserParameters(int argc, char **argv, char **envp) -{ - enum BadCode bad = NotBad; - int i = 0, j; - char *a, *e = NULL; -#if defined(__QNX__) && !defined(__QNXNTO__) - char cmd_name[64]; -#endif - -#if CHECK_EUID - if (geteuid() == 0 && getuid() != geteuid()) -#endif - { - /* Check each argv[] */ - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-fp") == 0) - { - i++; /* continue with next argument. skip the length check */ - if (i >= argc) - break; - } else - { - if (strlen(argv[i]) > MAX_ARG_LENGTH) { - bad = ArgTooLong; - break; - } - } - a = argv[i]; - while (*a) { - if (checkPrintable(*a) == 0) { - bad = UnprintableArg; - break; - } - a++; - } - if (bad) - break; - } - if (!bad) { - /* Check each envp[] */ - for (i = 0; envp[i]; i++) { - - /* Check for bad environment variables and values */ -#if REMOVE_ENV_LD - while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) { -#ifdef ENVDEBUG - ErrorF("CheckUserParameters: removing %s from the " - "environment\n", strtok(envp[i], "=")); -#endif - for (j = i; envp[j]; j++) { - envp[j] = envp[j+1]; - } - } -#endif - if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) { -#if REMOVE_LONG_ENV -#ifdef ENVDEBUG - ErrorF("CheckUserParameters: removing %s from the " - "environment\n", strtok(envp[i], "=")); -#endif - for (j = i; envp[j]; j++) { - envp[j] = envp[j+1]; - } - i--; -#else - char *eq; - int len; - - eq = strchr(envp[i], '='); - if (!eq) - continue; - len = eq - envp[i]; - e = malloc(len + 1); - if (!e) { - bad = InternalError; - break; - } - strncpy(e, envp[i], len); - e[len] = 0; - if (len >= 4 && - (strcmp(e + len - 4, "PATH") == 0 || - strcmp(e, "TERMCAP") == 0)) { - if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) { - bad = EnvTooLong; - break; - } else { - free(e); - } - } else { - bad = EnvTooLong; - break; - } -#endif - } - } - } -#if NO_OUTPUT_PIPES - if (!bad) { - struct stat buf; - - if (fstat(fileno(stdout), &buf) == 0 && S_ISFIFO(buf.st_mode)) - bad = OutputIsPipe; - if (fstat(fileno(stderr), &buf) == 0 && S_ISFIFO(buf.st_mode)) - bad = OutputIsPipe; - } -#endif - } - switch (bad) { - case NotBad: - return; - case UnsafeArg: - ErrorF("Command line argument number %d is unsafe\n", i); - ErrorF(ARGMSG, BUGADDRESS); - break; - case ArgTooLong: - ErrorF("Command line argument number %d is too long\n", i); - ErrorF(ARGMSG, BUGADDRESS); - break; - case UnprintableArg: - ErrorF("Command line argument number %d contains unprintable" - " characters\n", i); - ErrorF(ARGMSG, BUGADDRESS); - break; - case EnvTooLong: - ErrorF("Environment variable `%s' is too long\n", e); - ErrorF(ENVMSG, BUGADDRESS); - break; - case OutputIsPipe: - ErrorF("Stdout and/or stderr is a pipe\n"); - break; - case InternalError: - ErrorF("Internal Error\n"); - break; - default: - ErrorF("Unknown error\n"); - ErrorF(ARGMSG, BUGADDRESS); - ErrorF(ENVMSG, BUGADDRESS); - break; - } - FatalError("X server aborted because of unsafe environment\n"); -} - -/* - * CheckUserAuthorization: check if the user is allowed to start the - * X server. This usually means some sort of PAM checking, and it is - * usually only done for setuid servers (uid != euid). - */ - -#ifdef USE_PAM -#include -#include -#include -#endif /* USE_PAM */ - -void -CheckUserAuthorization(void) -{ -#ifdef USE_PAM - static struct pam_conv conv = { - misc_conv, - NULL - }; - - pam_handle_t *pamh = NULL; - struct passwd *pw; - int retval; - - if (getuid() != geteuid()) { - pw = getpwuid(getuid()); - if (pw == NULL) - FatalError("getpwuid() failed for uid %d\n", getuid()); - - retval = pam_start("xserver", pw->pw_name, &conv, &pamh); - if (retval != PAM_SUCCESS) - FatalError("pam_start() failed.\n" - "\tMissing or mangled PAM config file or module?\n"); - - retval = pam_authenticate(pamh, 0); - if (retval != PAM_SUCCESS) { - pam_end(pamh, retval); - FatalError("PAM authentication failed, cannot start X server.\n" - "\tPerhaps you do not have console ownership?\n"); - } - - retval = pam_acct_mgmt(pamh, 0); - if (retval != PAM_SUCCESS) { - pam_end(pamh, retval); - FatalError("PAM authentication failed, cannot start X server.\n" - "\tPerhaps you do not have console ownership?\n"); - } - - /* this is not a session, so do not do session management */ - pam_end(pamh, PAM_SUCCESS); - } -#endif -} - -#ifdef __SCO__ -#include - -static void -lockit (int fd, short what) -{ - struct flock lck; - - lck.l_whence = 0; - lck.l_start = 0; - lck.l_len = 1; - lck.l_type = what; - - (void)fcntl (fd, F_SETLKW, &lck); -} - -/* SCO OpenServer 5 lacks pread/pwrite. Emulate them. */ -ssize_t -pread (int fd, void *buf, size_t nbytes, off_t offset) -{ - off_t saved; - ssize_t ret; - - lockit (fd, F_RDLCK); - saved = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - ret = read (fd, buf, nbytes); - lseek (fd, saved, SEEK_SET); - lockit (fd, F_UNLCK); - - return ret; -} - -ssize_t -pwrite (int fd, const void *buf, size_t nbytes, off_t offset) -{ - off_t saved; - ssize_t ret; - - lockit (fd, F_WRLCK); - saved = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - ret = write (fd, buf, nbytes); - lseek (fd, saved, SEEK_SET); - lockit (fd, F_UNLCK); - - return ret; -} -#endif /* __SCO__ */ diff --git a/nx-X11/programs/Xserver/os/utils.c.X.original b/nx-X11/programs/Xserver/os/utils.c.X.original deleted file mode 100644 index b0a806fd7..000000000 --- a/nx-X11/programs/Xserver/os/utils.c.X.original +++ /dev/null @@ -1,2296 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/os/utils.c,v 1.21 2005/11/08 06:33:30 jkj Exp $ */ -/* $Xorg: utils.c,v 1.5 2001/02/09 02:05:24 xorgcvs Exp $ */ -/* - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, -Copyright 1994 Quarterdeck Office Systems. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital and -Quarterdeck not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE. - -*/ -/* $XFree86: xc/programs/Xserver/os/utils.c,v 3.96 2004/01/07 04:16:37 dawes Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef __CYGWIN__ -#include -#include -#endif - -#if defined(WIN32) && !defined(__CYGWIN__) -#include -#endif -#include -#include -#include "misc.h" -#include -#include -#include "input.h" -#include "dixfont.h" -#include "osdep.h" -#ifdef X_POSIX_C_SOURCE -#define _POSIX_C_SOURCE X_POSIX_C_SOURCE -#include -#undef _POSIX_C_SOURCE -#else -#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE) -#include -#else -#define _POSIX_SOURCE -#include -#undef _POSIX_SOURCE -#endif -#endif -#ifndef WIN32 -#include -#endif -#if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4) -#include -#endif -#include -#include -#include /* for isspace */ -#include - -#if defined(DGUX) -#include -#include -#endif - -#include /* for malloc() */ - -#if defined(TCPCONN) || defined(STREAMSCONN) -# ifndef WIN32 -# include -# endif -#endif - -#include "opaque.h" - -#ifdef SMART_SCHEDULE -#include "dixstruct.h" -#endif - -#ifdef XKB -#include -#endif -#ifdef XCSECURITY -#define _SECURITY_SERVER -#include -#endif - -#ifdef RENDER -#include "picture.h" -#endif - -#ifdef XPRINT -#include "DiPrint.h" -#endif - -Bool noTestExtensions; -#ifdef BIGREQS -Bool noBigReqExtension = FALSE; -#endif -#ifdef COMPOSITE -/* COMPOSITE is disabled by default for now until the - * interface is stable */ -Bool noCompositeExtension = TRUE; -#endif -#ifdef DAMAGE -Bool noDamageExtension = FALSE; -#endif -#ifdef DBE -Bool noDbeExtension = FALSE; -#endif -#ifdef DPSEXT -Bool noDPSExtension = FALSE; -#endif -#ifdef DPMSExtension -Bool noDPMSExtension = FALSE; -#endif -#ifdef EVI -Bool noEVIExtension = FALSE; -#endif -#ifdef FONTCACHE -Bool noFontCacheExtension = FALSE; -#endif -#ifdef GLXEXT -Bool noGlxExtension = FALSE; -#endif -#ifdef LBX -Bool noLbxExtension = FALSE; -#endif -#ifdef SCREENSAVER -Bool noScreenSaverExtension = FALSE; -#endif -#ifdef MITSHM -Bool noMITShmExtension = FALSE; -#endif -#ifdef MITMISC -Bool noMITMiscExtension = FALSE; -#endif -#ifdef MULTIBUFFER -Bool noMultibufferExtension = FALSE; -#endif -#ifdef RANDR -Bool noRRExtension = FALSE; -#endif -#ifdef RENDER -Bool noRenderExtension = FALSE; -#endif -#ifdef SHAPE -Bool noShapeExtension = FALSE; -#endif -#ifdef XCSECURITY -Bool noSecurityExtension = FALSE; -#endif -#ifdef XSYNC -Bool noSyncExtension = FALSE; -#endif -#ifdef TOGCUP -Bool noXcupExtension = FALSE; -#endif -#ifdef RES -Bool noResExtension = FALSE; -#endif -#ifdef XAPPGROUP -Bool noXagExtension = FALSE; -#endif -#ifdef XCMISC -Bool noXCMiscExtension = FALSE; -#endif -#ifdef XEVIE -/* Xevie is disabled by default for now until the - * interface is stable */ -Bool noXevieExtension = TRUE; -#endif -#ifdef XF86BIGFONT -Bool noXFree86BigfontExtension = FALSE; -#endif -#ifdef XFreeXDGA -Bool noXFree86DGAExtension = FALSE; -#endif -#ifdef XF86DRI -Bool noXFree86DRIExtension = FALSE; -#endif -#ifdef XF86MISC -Bool noXFree86MiscExtension = FALSE; -#endif -#ifdef XF86VIDMODE -Bool noXFree86VidModeExtension = FALSE; -#endif -#ifdef XFIXES -Bool noXFixesExtension = FALSE; -#endif -/* |noXkbExtension| is defined in xc/programs/Xserver/xkb/xkbInit.c */ -#ifdef PANORAMIX -/* Xinerama is disabled by default unless enabled via +xinerama */ -Bool noPanoramiXExtension = TRUE; -#endif -#ifdef XINPUT -Bool noXInputExtension = FALSE; -#endif -#ifdef XIDLE -Bool noXIdleExtension = FALSE; -#endif -#ifdef XV -Bool noXvExtension = FALSE; -#endif - -#define X_INCLUDE_NETDB_H -#include - -#include - -Bool CoreDump; - -#ifdef PANORAMIX -Bool PanoramiXVisibilityNotifySent = FALSE; -Bool PanoramiXMapped = FALSE; -Bool PanoramiXWindowExposureSent = FALSE; -Bool PanoramiXOneExposeRequest = FALSE; -Bool PanoramiXExtensionDisabledHack = FALSE; -#endif - -int auditTrailLevel = 1; - -Bool Must_have_memory = FALSE; - -#ifdef AIXV3 -int SyncOn = 0; -extern int SelectWaitTime; -#endif - -#ifdef DEBUG -#ifndef SPECIAL_MALLOC -#define MEMBUG -#endif -#endif - -#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED) -#define HAS_SAVED_IDS_AND_SETEUID -#endif - -#ifdef MEMBUG -#define MEM_FAIL_SCALE 100000 -long Memory_fail = 0; -#include /* for random() */ -#endif - -#ifdef sgi -int userdefinedfontpath = 0; -#endif /* sgi */ - -char *dev_tty_from_init = NULL; /* since we need to parse it anyway */ - -extern char dispatchExceptionAtReset; - -/* Extension enable/disable in miinitext.c */ -extern Bool EnableDisableExtension(char *name, Bool enable); -extern void EnableDisableExtensionError(char *name, Bool enable); - -OsSigHandlerPtr -OsSignal(sig, handler) - int sig; - OsSigHandlerPtr handler; -{ -#ifdef X_NOT_POSIX - return signal(sig, handler); -#else - struct sigaction act, oact; - - sigemptyset(&act.sa_mask); - if (handler != SIG_IGN) - sigaddset(&act.sa_mask, sig); - act.sa_flags = 0; - act.sa_handler = handler; - sigaction(sig, &act, &oact); - return oact.sa_handler; -#endif -} - -#ifdef SERVER_LOCK -/* - * Explicit support for a server lock file like the ones used for UUCP. - * For architectures with virtual terminals that can run more than one - * server at a time. This keeps the servers from stomping on each other - * if the user forgets to give them different display numbers. - */ -#ifndef __UNIXOS2__ -#define LOCK_DIR "/tmp" -#endif -#define LOCK_TMP_PREFIX "/.tX" -#define LOCK_PREFIX "/.X" -#define LOCK_SUFFIX "-lock" - -#if defined(DGUX) -#include -#include -#endif - -#ifdef __UNIXOS2__ -#define link rename -#endif - -#ifndef PATH_MAX -#ifndef Lynx -#include -#else -#include -#endif -#ifndef PATH_MAX -#ifdef MAXPATHLEN -#define PATH_MAX MAXPATHLEN -#else -#define PATH_MAX 1024 -#endif -#endif -#endif - -static Bool StillLocking = FALSE; -static char LockFile[PATH_MAX]; -static Bool nolock = FALSE; - -/* - * LockServer -- - * Check if the server lock file exists. If so, check if the PID - * contained inside is valid. If so, then die. Otherwise, create - * the lock file containing the PID. - */ -void -LockServer(void) -{ - char tmp[PATH_MAX], pid_str[12]; - int lfd, i, haslock, l_pid, t; - char *tmppath = NULL; - int len; - char port[20]; - - if (nolock) return; - /* - * Path names - */ -#ifndef __UNIXOS2__ - tmppath = LOCK_DIR; -#else - /* OS/2 uses TMP directory, must also prepare for 8.3 names */ - tmppath = getenv("TMP"); - if (!tmppath) - FatalError("No TMP dir found\n"); -#endif - - sprintf(port, "%d", atoi(display)); - len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) : - strlen(LOCK_TMP_PREFIX); - len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1; - if (len > sizeof(LockFile)) - FatalError("Display name `%s' is too long\n", port); - (void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port); - (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port); - - /* - * Create a temporary file containing our PID. Attempt three times - * to create the file. - */ - StillLocking = TRUE; - i = 0; - do { - i++; - lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644); - if (lfd < 0) - sleep(2); - else - break; - } while (i < 3); - if (lfd < 0) { - unlink(tmp); - i = 0; - do { - i++; - lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644); - if (lfd < 0) - sleep(2); - else - break; - } while (i < 3); - } - if (lfd < 0) - FatalError("Could not create lock file in %s\n", tmp); - (void) sprintf(pid_str, "%10ld\n", (long)getpid()); - (void) write(lfd, pid_str, 11); -#ifndef __UNIXOS2__ -#ifndef USE_CHMOD - (void) fchmod(lfd, 0444); -#else - (void) chmod(tmp, 0444); -#endif -#endif - (void) close(lfd); - - /* - * OK. Now the tmp file exists. Try three times to move it in place - * for the lock. - */ - i = 0; - haslock = 0; - while ((!haslock) && (i++ < 3)) { - haslock = (link(tmp,LockFile) == 0); - if (haslock) { - /* - * We're done. - */ - break; - } - else { - /* - * Read the pid from the existing file - */ - lfd = open(LockFile, O_RDONLY); - if (lfd < 0) { - unlink(tmp); - FatalError("Can't read lock file %s\n", LockFile); - } - pid_str[0] = '\0'; - if (read(lfd, pid_str, 11) != 11) { - /* - * Bogus lock file. - */ - unlink(LockFile); - close(lfd); - continue; - } - pid_str[11] = '\0'; - sscanf(pid_str, "%d", &l_pid); - close(lfd); - - /* - * Now try to kill the PID to see if it exists. - */ - errno = 0; - t = kill(l_pid, 0); - if ((t< 0) && (errno == ESRCH)) { - /* - * Stale lock file. - */ - unlink(LockFile); - continue; - } - else if (((t < 0) && (errno == EPERM)) || (t == 0)) { - /* - * Process is still active. - */ - unlink(tmp); - FatalError("Server is already active for display %s\n%s %s\n%s\n", - port, "\tIf this server is no longer running, remove", - LockFile, "\tand start again."); - } - } - } - unlink(tmp); - if (!haslock) - FatalError("Could not create server lock file: %s\n", LockFile); - StillLocking = FALSE; -} - -/* - * UnlockServer -- - * Remove the server lock file. - */ -void -UnlockServer(void) -{ - if (nolock) return; - - if (!StillLocking){ - -#ifdef __UNIXOS2__ - (void) chmod(LockFile,S_IREAD|S_IWRITE); -#endif /* __UNIXOS2__ */ - (void) unlink(LockFile); - } -} -#endif /* SERVER_LOCK */ - -/* Force connections to close on SIGHUP from init */ - -/*ARGSUSED*/ -SIGVAL -AutoResetServer (int sig) -{ - int olderrno = errno; - - dispatchException |= DE_RESET; - isItTimeToYield = TRUE; -#ifdef GPROF - chdir ("/tmp"); - exit (0); -#endif -#if defined(SYSV) && defined(X_NOT_POSIX) - OsSignal (SIGHUP, AutoResetServer); -#endif - errno = olderrno; -} - -/* Force connections to close and then exit on SIGTERM, SIGINT */ - -/*ARGSUSED*/ -SIGVAL -GiveUp(int sig) -{ - int olderrno = errno; - - dispatchException |= DE_TERMINATE; - isItTimeToYield = TRUE; -#if defined(SYSV) && defined(X_NOT_POSIX) - if (sig) - OsSignal(sig, SIG_IGN); -#endif - errno = olderrno; -} - -#ifndef DDXTIME -CARD32 -GetTimeInMillis(void) -{ - struct timeval tp; - - X_GETTIMEOFDAY(&tp); - return(tp.tv_sec * 1000) + (tp.tv_usec / 1000); -} -#endif - -void -AdjustWaitForDelay (pointer waitTime, unsigned long newdelay) -{ - static struct timeval delay_val; - struct timeval **wt = (struct timeval **) waitTime; - unsigned long olddelay; - - if (*wt == NULL) - { - delay_val.tv_sec = newdelay / 1000; - delay_val.tv_usec = 1000 * (newdelay % 1000); - *wt = &delay_val; - } - else - { - olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000; - if (newdelay < olddelay) - { - (*wt)->tv_sec = newdelay / 1000; - (*wt)->tv_usec = 1000 * (newdelay % 1000); - } - } -} - -void UseMsg(void) -{ -#if !defined(AIXrt) && !defined(AIX386) - ErrorF("use: X [:] [option]\n"); - ErrorF("-a # mouse acceleration (pixels)\n"); - ErrorF("-ac disable access control restrictions\n"); -#ifdef MEMBUG - ErrorF("-alloc int chance alloc should fail\n"); -#endif - ErrorF("-audit int set audit trail level\n"); - ErrorF("-auth file select authorization file\n"); - ErrorF("bc enable bug compatibility\n"); - ErrorF("-br create root window with black background\n"); - ErrorF("+bs enable any backing store support\n"); - ErrorF("-bs disable any backing store support\n"); - ErrorF("-c turns off key-click\n"); - ErrorF("c # key-click volume (0-100)\n"); - ErrorF("-cc int default color visual class\n"); - ErrorF("-co file color database file\n"); -#ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS - ErrorF("-config file read options from file\n"); -#endif - ErrorF("-core generate core dump on fatal error\n"); - ErrorF("-dpi int screen resolution in dots per inch\n"); -#ifdef DPMSExtension - ErrorF("dpms enables VESA DPMS monitor control\n"); - ErrorF("-dpms disables VESA DPMS monitor control\n"); -#endif - ErrorF("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n"); - ErrorF("-f # bell base (0-100)\n"); - ErrorF("-fc string cursor font\n"); - ErrorF("-fn string default font name\n"); - ErrorF("-fp string default font path\n"); - ErrorF("-help prints message with these options\n"); - ErrorF("-I ignore all remaining arguments\n"); -#ifdef RLIMIT_DATA - ErrorF("-ld int limit data space to N Kb\n"); -#endif -#ifdef RLIMIT_NOFILE - ErrorF("-lf int limit number of open files to N\n"); -#endif -#ifdef RLIMIT_STACK - ErrorF("-ls int limit stack space to N Kb\n"); -#endif -#ifdef SERVER_LOCK - ErrorF("-nolock disable the locking mechanism\n"); -#endif -#ifndef NOLOGOHACK - ErrorF("-logo enable logo in screen saver\n"); - ErrorF("nologo disable logo in screen saver\n"); -#endif - ErrorF("-nolisten string don't listen on protocol\n"); - ErrorF("-noreset don't reset after last client exists\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"); - ErrorF("-nopn reject failure to listen on all ports\n"); - ErrorF("-r turns off auto-repeat\n"); - ErrorF("r turns on auto-repeat \n"); -#ifdef RENDER - ErrorF("-render [default|mono|gray|color] set render color alloc policy\n"); -#endif - ErrorF("-s # screen-saver timeout (minutes)\n"); -#ifdef XCSECURITY - ErrorF("-sp file security policy file\n"); -#endif -#ifdef XPRINT - PrinterUseMsg(); -#endif - ErrorF("-su disable any save under support\n"); - ErrorF("-t # mouse threshold (pixels)\n"); - ErrorF("-terminate terminate at server reset\n"); - ErrorF("-to # connection time out\n"); - ErrorF("-tst disable testing extensions\n"); - ErrorF("ttyxx server started from init on /dev/ttyxx\n"); - ErrorF("v video blanking for screen-saver\n"); - ErrorF("-v screen-saver without video blanking\n"); - ErrorF("-wm WhenMapped default backing-store\n"); - ErrorF("-x string loads named extension at init time \n"); - ErrorF("-maxbigreqsize set maximal bigrequest size \n"); -#ifdef PANORAMIX - ErrorF("+xinerama Enable XINERAMA extension\n"); - ErrorF("-xinerama Disable XINERAMA extension\n"); -#endif -#ifdef SMART_SCHEDULE - ErrorF("-dumbSched Disable smart scheduling, enable old behavior\n"); - ErrorF("-schedInterval int Set scheduler interval in msec\n"); -#endif - ErrorF("+extension name Enable extension\n"); - ErrorF("-extension name Disable extension\n"); -#ifdef XDMCP - XdmcpUseMsg(); -#endif -#endif /* !AIXrt && ! AIX386 */ -#ifdef XKB - XkbUseMsg(); -#endif - ddxUseMsg(); -} - -/* This function performs a rudimentary sanity check - * on the display name passed in on the command-line, - * since this string is used to generate filenames. - * It is especially important that the display name - * not contain a "/" and not start with a "-". - * --kvajk - */ -static int -VerifyDisplayName(const char *d) -{ - if ( d == (char *)0 ) return( 0 ); /* null */ - if ( *d == '\0' ) return( 0 ); /* empty */ - if ( *d == '-' ) return( 0 ); /* could be confused for an option */ - if ( *d == '.' ) return( 0 ); /* must not equal "." or ".." */ - if ( strchr(d, '/') != (char *)0 ) return( 0 ); /* very important!!! */ - return( 1 ); -} - -/* - * This function is responsible for doing initalisation of any global - * variables at an very early point of server startup (even before - * |ProcessCommandLine()|. - */ -void InitGlobals(void) -{ - ddxInitGlobals(); -} - - -/* - * This function parses the command line. Handles device-independent fields - * and allows ddx to handle additional fields. It is not allowed to modify - * argc or any of the strings pointed to by argv. - */ -void -ProcessCommandLine(int argc, char *argv[]) -{ - int i, skip; - - defaultKeyboardControl.autoRepeat = TRUE; - -#ifdef NO_PART_NET - PartialNetwork = FALSE; -#else - PartialNetwork = TRUE; -#endif - - for ( i = 1; i < argc; i++ ) - { - /* call ddx first, so it can peek/override if it wants */ - if((skip = ddxProcessArgument(argc, argv, i))) - { - i += (skip - 1); - } - else if(argv[i][0] == ':') - { - /* initialize display */ - display = argv[i]; - display++; - if( ! VerifyDisplayName( display ) ) { - ErrorF("Bad display name: %s\n", display); - UseMsg(); - FatalError("Bad display name, exiting: %s\n", display); - } - } - else if ( strcmp( argv[i], "-a") == 0) - { - if(++i < argc) - defaultPointerControl.num = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-ac") == 0) - { - defeatAccessControl = TRUE; - } -#ifdef MEMBUG - else if ( strcmp( argv[i], "-alloc") == 0) - { - if(++i < argc) - Memory_fail = atoi(argv[i]); - else - UseMsg(); - } -#endif - else if ( strcmp( argv[i], "-audit") == 0) - { - if(++i < argc) - auditTrailLevel = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-auth") == 0) - { - if(++i < argc) - InitAuthorization (argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "bc") == 0) - permitOldBugs = TRUE; - else if ( strcmp( argv[i], "-br") == 0) - blackRoot = TRUE; - else if ( strcmp( argv[i], "+bs") == 0) - enableBackingStore = TRUE; - else if ( strcmp( argv[i], "-bs") == 0) - disableBackingStore = TRUE; - else if ( strcmp( argv[i], "c") == 0) - { - if(++i < argc) - defaultKeyboardControl.click = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-c") == 0) - { - defaultKeyboardControl.click = 0; - } - else if ( strcmp( argv[i], "-cc") == 0) - { - if(++i < argc) - defaultColorVisualClass = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-co") == 0) - { - if(++i < argc) - rgbPath = argv[i]; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-core") == 0) - CoreDump = TRUE; - else if ( strcmp( argv[i], "-dpi") == 0) - { - if(++i < argc) - monitorResolution = atoi(argv[i]); - else - UseMsg(); - } -#ifdef DPMSExtension - else if ( strcmp( argv[i], "dpms") == 0) - DPMSEnabledSwitch = TRUE; - else if ( strcmp( argv[i], "-dpms") == 0) - DPMSDisabledSwitch = TRUE; -#endif - else if ( strcmp( argv[i], "-deferglyphs") == 0) - { - if(++i >= argc || !ParseGlyphCachingMode(argv[i])) - UseMsg(); - } - else if ( strcmp( argv[i], "-f") == 0) - { - if(++i < argc) - defaultKeyboardControl.bell = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-fc") == 0) - { - if(++i < argc) - defaultCursorFont = argv[i]; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-fn") == 0) - { - if(++i < argc) - defaultTextFont = argv[i]; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-fp") == 0) - { - if(++i < argc) - { -#ifdef sgi - userdefinedfontpath = 1; -#endif /* sgi */ - defaultFontPath = argv[i]; - } - else - UseMsg(); - } - else if ( strcmp( argv[i], "-help") == 0) - { - UseMsg(); - exit(0); - } -#ifdef XKB - else if ( (skip=XkbProcessArguments(argc,argv,i))!=0 ) { - if (skip>0) - i+= skip-1; - else UseMsg(); - } -#endif -#ifdef RLIMIT_DATA - else if ( strcmp( argv[i], "-ld") == 0) - { - if(++i < argc) - { - limitDataSpace = atoi(argv[i]); - if (limitDataSpace > 0) - limitDataSpace *= 1024; - } - else - UseMsg(); - } -#endif -#ifdef RLIMIT_NOFILE - else if ( strcmp( argv[i], "-lf") == 0) - { - if(++i < argc) - limitNoFile = atoi(argv[i]); - else - UseMsg(); - } -#endif -#ifdef RLIMIT_STACK - else if ( strcmp( argv[i], "-ls") == 0) - { - if(++i < argc) - { - limitStackSpace = atoi(argv[i]); - if (limitStackSpace > 0) - limitStackSpace *= 1024; - } - else - UseMsg(); - } -#endif -#ifdef SERVER_LOCK - else if ( strcmp ( argv[i], "-nolock") == 0) - { -#if !defined(WIN32) && !defined(__UNIXOS2__) && !defined(__CYGWIN__) - if (getuid() != 0) - ErrorF("Warning: the -nolock option can only be used by root\n"); - else -#endif - nolock = TRUE; - } -#endif -#ifndef NOLOGOHACK - else if ( strcmp( argv[i], "-logo") == 0) - { - logoScreenSaver = 1; - } - else if ( strcmp( argv[i], "nologo") == 0) - { - logoScreenSaver = 0; - } -#endif - else if ( strcmp( argv[i], "-nolisten") == 0) - { - if(++i < argc) { - if (_XSERVTransNoListen(argv[i])) - FatalError ("Failed to disable listen for %s transport", - argv[i]); - } else - UseMsg(); - } - else if ( strcmp( argv[i], "-noreset") == 0) - { - dispatchExceptionAtReset = 0; - } - else if ( strcmp( argv[i], "-reset") == 0) - { - dispatchExceptionAtReset = DE_RESET; - } - else if ( strcmp( argv[i], "-p") == 0) - { - if(++i < argc) - defaultScreenSaverInterval = ((CARD32)atoi(argv[i])) * - MILLI_PER_MIN; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-pn") == 0) - PartialNetwork = TRUE; - else if ( strcmp( argv[i], "-nopn") == 0) - PartialNetwork = FALSE; - else if ( strcmp( argv[i], "r") == 0) - defaultKeyboardControl.autoRepeat = TRUE; - else if ( strcmp( argv[i], "-r") == 0) - defaultKeyboardControl.autoRepeat = FALSE; - else if ( strcmp( argv[i], "-s") == 0) - { - if(++i < argc) - defaultScreenSaverTime = ((CARD32)atoi(argv[i])) * - MILLI_PER_MIN; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-su") == 0) - disableSaveUnders = TRUE; - else if ( strcmp( argv[i], "-t") == 0) - { - if(++i < argc) - defaultPointerControl.threshold = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-terminate") == 0) - { - dispatchExceptionAtReset = DE_TERMINATE; - } - else if ( strcmp( argv[i], "-to") == 0) - { - if(++i < argc) - TimeOutValue = ((CARD32)atoi(argv[i])) * MILLI_PER_SECOND; - else - UseMsg(); - } - else if ( strcmp( argv[i], "-tst") == 0) - { - noTestExtensions = TRUE; - } - else if ( strcmp( argv[i], "v") == 0) - defaultScreenSaverBlanking = PreferBlanking; - else if ( strcmp( argv[i], "-v") == 0) - defaultScreenSaverBlanking = DontPreferBlanking; - else if ( strcmp( argv[i], "-wm") == 0) - defaultBackingStore = WhenMapped; - else if ( strcmp( argv[i], "-maxbigreqsize") == 0) { - if(++i < argc) { - long reqSizeArg = atol(argv[i]); - - /* Request size > 128MB does not make much sense... */ - if( reqSizeArg > 0L && reqSizeArg < 128L ) { - maxBigRequestSize = (reqSizeArg * 1048576L) - 1L; - } - else - { - UseMsg(); - } - } - else - { - UseMsg(); - } - } -#ifdef PANORAMIX - else if ( strcmp( argv[i], "+xinerama") == 0){ - noPanoramiXExtension = FALSE; - } - else if ( strcmp( argv[i], "-xinerama") == 0){ - noPanoramiXExtension = TRUE; - } - else if ( strcmp( argv[i], "-disablexineramaextension") == 0){ - PanoramiXExtensionDisabledHack = TRUE; - } -#endif - else if ( strcmp( argv[i], "-x") == 0) - { - if(++i >= argc) - UseMsg(); - /* For U**x, which doesn't support dynamic loading, there's nothing - * to do when we see a -x. Either the extension is linked in or - * it isn't */ - } - else if ( strcmp( argv[i], "-I") == 0) - { - /* ignore all remaining arguments */ - break; - } - else if (strncmp (argv[i], "tty", 3) == 0) - { - /* just in case any body is interested */ - dev_tty_from_init = argv[i]; - } -#ifdef XDMCP - else if ((skip = XdmcpOptions(argc, argv, i)) != i) - { - i = skip - 1; - } -#endif -#ifdef XPRINT - else if ((skip = PrinterOptions(argc, argv, i)) != i) - { - i = skip - 1; - } -#endif -#ifdef XCSECURITY - else if ((skip = XSecurityOptions(argc, argv, i)) != i) - { - i = skip - 1; - } -#endif -#ifdef AIXV3 - else if ( strcmp( argv[i], "-timeout") == 0) - { - if(++i < argc) - SelectWaitTime = atoi(argv[i]); - else - UseMsg(); - } - else if ( strcmp( argv[i], "-sync") == 0) - { - SyncOn++; - } -#endif -#ifdef SMART_SCHEDULE - else if ( strcmp( argv[i], "-dumbSched") == 0) - { - SmartScheduleDisable = TRUE; - } - else if ( strcmp( argv[i], "-schedInterval") == 0) - { - if (++i < argc) - { - SmartScheduleInterval = atoi(argv[i]); - SmartScheduleSlice = SmartScheduleInterval; - } - else - UseMsg(); - } - else if ( strcmp( argv[i], "-schedMax") == 0) - { - if (++i < argc) - { - SmartScheduleMaxSlice = atoi(argv[i]); - } - else - UseMsg(); - } -#endif -#ifdef RENDER - else if ( strcmp( argv[i], "-render" ) == 0) - { - if (++i < argc) - { - int policy = PictureParseCmapPolicy (argv[i]); - - if (policy != PictureCmapPolicyInvalid) - PictureCmapPolicy = policy; - else - UseMsg (); - } - else - UseMsg (); - } -#endif - else if ( strcmp( argv[i], "+extension") == 0) - { - if (++i < argc) - { - if (!EnableDisableExtension(argv[i], TRUE)) - EnableDisableExtensionError(argv[i], TRUE); - } - else - UseMsg(); - } - else if ( strcmp( argv[i], "-extension") == 0) - { - if (++i < argc) - { - if (!EnableDisableExtension(argv[i], FALSE)) - EnableDisableExtensionError(argv[i], FALSE); - } - else - UseMsg(); - } - else - { - ErrorF("Unrecognized option: %s\n", argv[i]); - UseMsg(); - FatalError("Unrecognized option: %s\n", argv[i]); - } - } -} - -#ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS -static void -InsertFileIntoCommandLine( - int *resargc, char ***resargv, - int prefix_argc, char **prefix_argv, - char *filename, - int suffix_argc, char **suffix_argv) -{ - struct stat st; - FILE *f; - char *p; - char *q; - int insert_argc; - char *buf; - int len; - int i; - - f = fopen(filename, "r"); - if (!f) - FatalError("Can't open option file %s\n", filename); - - fstat(fileno(f), &st); - - buf = (char *) xalloc((unsigned) st.st_size + 1); - if (!buf) - FatalError("Out of Memory\n"); - - len = fread(buf, 1, (unsigned) st.st_size, f); - - fclose(f); - - if (len < 0) - FatalError("Error reading option file %s\n", filename); - - buf[len] = '\0'; - - p = buf; - q = buf; - insert_argc = 0; - - while (*p) - { - while (isspace(*p)) - p++; - if (!*p) - break; - if (*p == '#') - { - while (*p && *p != '\n') - p++; - } else - { - while (*p && !isspace(*p)) - *q++ = *p++; - /* Since p and q might still be pointing at the same place, we */ - /* need to step p over the whitespace now before we add the null. */ - if (*p) - p++; - *q++ = '\0'; - insert_argc++; - } - } - - buf = (char *) xrealloc(buf, q - buf); - if (!buf) - FatalError("Out of memory reallocing option buf\n"); - - *resargc = prefix_argc + insert_argc + suffix_argc; - *resargv = (char **) xalloc((*resargc + 1) * sizeof(char *)); - if (!*resargv) - FatalError("Out of Memory\n"); - - memcpy(*resargv, prefix_argv, prefix_argc * sizeof(char *)); - - p = buf; - for (i = 0; i < insert_argc; i++) - { - (*resargv)[prefix_argc + i] = p; - p += strlen(p) + 1; - } - - memcpy(*resargv + prefix_argc + insert_argc, - suffix_argv, suffix_argc * sizeof(char *)); - - (*resargv)[*resargc] = NULL; -} /* end InsertFileIntoCommandLine */ - - -void -ExpandCommandLine(int *pargc, char ***pargv) -{ - int i; - -#if !defined(WIN32) && !defined(__UNIXOS2__) && !defined(__CYGWIN__) - if (getuid() != geteuid()) - return; -#endif - - for (i = 1; i < *pargc; i++) - { - if ( (0 == strcmp((*pargv)[i], "-config")) && (i < (*pargc - 1)) ) - { - InsertFileIntoCommandLine(pargc, pargv, - i, *pargv, - (*pargv)[i+1], /* filename */ - *pargc - i - 2, *pargv + i + 2); - i--; - } - } -} /* end ExpandCommandLine */ -#endif - -/* Implement a simple-minded font authorization scheme. The authorization - name is "hp-hostname-1", the contents are simply the host name. */ -int -set_font_authorizations(char **authorizations, int *authlen, pointer client) -{ -#define AUTHORIZATION_NAME "hp-hostname-1" -#if defined(TCPCONN) || defined(STREAMSCONN) - static char *result = NULL; - static char *p = NULL; - - if (p == NULL) - { - char hname[1024], *hnameptr; - unsigned int len; -#if defined(IPv6) && defined(AF_INET6) - struct addrinfo hints, *ai = NULL; -#else - struct hostent *host; -#ifdef XTHREADS_NEEDS_BYNAMEPARAMS - _Xgethostbynameparams hparams; -#endif -#endif - - gethostname(hname, 1024); -#if defined(IPv6) && defined(AF_INET6) - bzero(&hints, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - if (getaddrinfo(hname, NULL, &hints, &ai) == 0) { - hnameptr = ai->ai_canonname; - } else { - hnameptr = hname; - } -#else - host = _XGethostbyname(hname, hparams); - if (host == NULL) - hnameptr = hname; - else - hnameptr = host->h_name; -#endif - - len = strlen(hnameptr) + 1; - result = xalloc(len + sizeof(AUTHORIZATION_NAME) + 4); - - p = result; - *p++ = sizeof(AUTHORIZATION_NAME) >> 8; - *p++ = sizeof(AUTHORIZATION_NAME) & 0xff; - *p++ = (len) >> 8; - *p++ = (len & 0xff); - - memmove(p, AUTHORIZATION_NAME, sizeof(AUTHORIZATION_NAME)); - p += sizeof(AUTHORIZATION_NAME); - memmove(p, hnameptr, len); - p += len; -#if defined(IPv6) && defined(AF_INET6) - if (ai) { - freeaddrinfo(ai); - } -#endif - } - *authlen = p - result; - *authorizations = result; - return 1; -#else /* TCPCONN */ - return 0; -#endif /* TCPCONN */ -} - -/* XALLOC -- X's internal memory allocator. Why does it return unsigned - * long * instead of the more common char *? Well, if you read K&R you'll - * see they say that alloc must return a pointer "suitable for conversion" - * to whatever type you really want. In a full-blown generic allocator - * there's no way to solve the alignment problems without potentially - * wasting lots of space. But we have a more limited problem. We know - * we're only ever returning pointers to structures which will have to - * be long word aligned. So we are making a stronger guarantee. It might - * have made sense to make Xalloc return char * to conform with people's - * expectations of malloc, but this makes lint happier. - */ - -#ifndef INTERNAL_MALLOC - -void * -Xalloc(unsigned long amount) -{ - register pointer ptr; - - if ((long)amount <= 0) { - return (unsigned long *)NULL; - } - /* aligned extra on long word boundary */ - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); -#ifdef MEMBUG - if (!Must_have_memory && Memory_fail && - ((random() % MEM_FAIL_SCALE) < Memory_fail)) - return (unsigned long *)NULL; -#endif - if ((ptr = (pointer)malloc(amount))) { - return (unsigned long *)ptr; - } - if (Must_have_memory) - FatalError("Out of memory"); - return (unsigned long *)NULL; -} - -/***************** - * XNFalloc - * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory - *****************/ - -void * -XNFalloc(unsigned long amount) -{ - register pointer ptr; - - if ((long)amount <= 0) - { - return (unsigned long *)NULL; - } - /* aligned extra on long word boundary */ - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - ptr = (pointer)malloc(amount); - if (!ptr) - { - FatalError("Out of memory"); - } - return ((unsigned long *)ptr); -} - -/***************** - * Xcalloc - *****************/ - -void * -Xcalloc(unsigned long amount) -{ - unsigned long *ret; - - ret = Xalloc (amount); - if (ret) - bzero ((char *) ret, (int) amount); - return ret; -} - -/***************** - * XNFcalloc - *****************/ - -void * -XNFcalloc(unsigned long amount) -{ - unsigned long *ret; - - ret = Xalloc (amount); - if (ret) - bzero ((char *) ret, (int) amount); - else if ((long)amount > 0) - FatalError("Out of memory"); - return ret; -} - -/***************** - * Xrealloc - *****************/ - -void * -Xrealloc(pointer ptr, unsigned long amount) -{ -#ifdef MEMBUG - if (!Must_have_memory && Memory_fail && - ((random() % MEM_FAIL_SCALE) < Memory_fail)) - return (unsigned long *)NULL; -#endif - if ((long)amount <= 0) - { - if (ptr && !amount) - free(ptr); - return (unsigned long *)NULL; - } - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - if (ptr) - ptr = (pointer)realloc((char *)ptr, amount); - else - ptr = (pointer)malloc(amount); - if (ptr) - return (unsigned long *)ptr; - if (Must_have_memory) - FatalError("Out of memory"); - return (unsigned long *)NULL; -} - -/***************** - * XNFrealloc - * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory - *****************/ - -void * -XNFrealloc(pointer ptr, unsigned long amount) -{ - if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL) - { - if ((long)amount > 0) - FatalError( "Out of memory" ); - } - return ((unsigned long *)ptr); -} - -/***************** - * Xfree - * calls free - *****************/ - -void -Xfree(pointer ptr) -{ - if (ptr) - free((char *)ptr); -} - -void -OsInitAllocator (void) -{ -#ifdef MEMBUG - static int been_here; - - /* Check the memory system after each generation */ - if (been_here) - CheckMemory (); - else - been_here = 1; -#endif -} -#endif /* !INTERNAL_MALLOC */ - - -char * -Xstrdup(const char *s) -{ - char *sd; - - if (s == NULL) - return NULL; - - sd = (char *)Xalloc(strlen(s) + 1); - if (sd != NULL) - strcpy(sd, s); - return sd; -} - - -char * -XNFstrdup(const char *s) -{ - char *sd; - - if (s == NULL) - return NULL; - - sd = (char *)XNFalloc(strlen(s) + 1); - strcpy(sd, s); - return sd; -} - -#ifdef SMART_SCHEDULE - -unsigned long SmartScheduleIdleCount; -Bool SmartScheduleIdle; -Bool SmartScheduleTimerStopped; - -#ifdef SIGVTALRM -#define SMART_SCHEDULE_POSSIBLE -#endif - -#ifdef SMART_SCHEDULE_POSSIBLE -#define SMART_SCHEDULE_SIGNAL SIGALRM -#define SMART_SCHEDULE_TIMER ITIMER_REAL -#endif - -static void -SmartScheduleStopTimer (void) -{ -#ifdef SMART_SCHEDULE_POSSIBLE - struct itimerval timer; - - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_usec = 0; - timer.it_value.tv_sec = 0; - timer.it_value.tv_usec = 0; - (void) setitimer (ITIMER_REAL, &timer, 0); - SmartScheduleTimerStopped = TRUE; -#endif -} - -Bool -SmartScheduleStartTimer (void) -{ -#ifdef SMART_SCHEDULE_POSSIBLE - struct itimerval timer; - - SmartScheduleTimerStopped = FALSE; - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_usec = SmartScheduleInterval * 1000; - timer.it_value.tv_sec = 0; - timer.it_value.tv_usec = SmartScheduleInterval * 1000; - return setitimer (ITIMER_REAL, &timer, 0) >= 0; -#endif - return FALSE; -} - -#ifdef SMART_SCHEDULE_POSSIBLE -static void -SmartScheduleTimer (int sig) -{ - int olderrno = errno; - - SmartScheduleTime += SmartScheduleInterval; - if (SmartScheduleIdle) - { - SmartScheduleStopTimer (); - } - errno = olderrno; -} -#endif - -Bool -SmartScheduleInit (void) -{ -#ifdef SMART_SCHEDULE_POSSIBLE - struct sigaction act; - - if (SmartScheduleDisable) - return TRUE; - - bzero ((char *) &act, sizeof(struct sigaction)); - - /* Set up the timer signal function */ - act.sa_handler = SmartScheduleTimer; - sigemptyset (&act.sa_mask); - sigaddset (&act.sa_mask, SMART_SCHEDULE_SIGNAL); - if (sigaction (SMART_SCHEDULE_SIGNAL, &act, 0) < 0) - { - perror ("sigaction for smart scheduler"); - return FALSE; - } - /* Set up the virtual timer */ - if (!SmartScheduleStartTimer ()) - { - perror ("scheduling timer"); - return FALSE; - } - /* stop the timer and wait for WaitForSomething to start it */ - SmartScheduleStopTimer (); - return TRUE; -#else - return FALSE; -#endif -} -#endif - -#ifdef SIG_BLOCK -static sigset_t PreviousSignalMask; -static int BlockedSignalCount; -#endif - -void -OsBlockSignals (void) -{ -#ifdef SIG_BLOCK - if (BlockedSignalCount++ == 0) - { - sigset_t set; - - sigemptyset (&set); -#ifdef SIGALRM - sigaddset (&set, SIGALRM); -#endif -#ifdef SIGVTALRM - sigaddset (&set, SIGVTALRM); -#endif -#ifdef SIGWINCH - sigaddset (&set, SIGWINCH); -#endif -#ifdef SIGIO - sigaddset (&set, SIGIO); -#endif -#ifdef SIGTSTP - sigaddset (&set, SIGTSTP); -#endif -#ifdef SIGTTIN - sigaddset (&set, SIGTTIN); -#endif -#ifdef SIGTTOU - sigaddset (&set, SIGTTOU); -#endif -#ifdef SIGCHLD - sigaddset (&set, SIGCHLD); -#endif - sigprocmask (SIG_BLOCK, &set, &PreviousSignalMask); - } -#endif -} - -void -OsReleaseSignals (void) -{ -#ifdef SIG_BLOCK - if (--BlockedSignalCount == 0) - { - sigprocmask (SIG_SETMASK, &PreviousSignalMask, 0); - } -#endif -} - -#if !defined(WIN32) && !defined(__UNIXOS2__) -/* - * "safer" versions of system(3), popen(3) and pclose(3) which give up - * all privs before running a command. - * - * This is based on the code in FreeBSD 2.2 libc. - * - * XXX It'd be good to redirect stderr so that it ends up in the log file - * as well. As it is now, xkbcomp messages don't end up in the log file. - */ - -int -System(char *command) -{ - int pid, p; -#ifdef SIGCHLD - void (*csig)(int); -#endif - int status; - - if (!command) - return(1); - -#ifdef SIGCHLD - csig = signal(SIGCHLD, SIG_DFL); -#endif - -#ifdef DEBUG - ErrorF("System: `%s'\n", command); -#endif - - switch (pid = fork()) { - case -1: /* error */ - p = -1; - case 0: /* child */ - if (setgid(getgid()) == -1) - _exit(127); - if (setuid(getuid()) == -1) - _exit(127); - execl("/bin/sh", "sh", "-c", command, (char *)NULL); - _exit(127); - default: /* parent */ - do { - p = waitpid(pid, &status, 0); - } while (p == -1 && errno == EINTR); - - } - -#ifdef SIGCHLD - signal(SIGCHLD, csig); -#endif - - return p == -1 ? -1 : status; -} - -static struct pid { - struct pid *next; - FILE *fp; - int pid; -} *pidlist; - -pointer -Popen(char *command, char *type) -{ - struct pid *cur; - FILE *iop; - int pdes[2], pid; - - if (command == NULL || type == NULL) - return NULL; - - if ((*type != 'r' && *type != 'w') || type[1]) - return NULL; - - if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) - return NULL; - - if (pipe(pdes) < 0) { - xfree(cur); - return NULL; - } - - switch (pid = fork()) { - case -1: /* error */ - close(pdes[0]); - close(pdes[1]); - xfree(cur); - return NULL; - case 0: /* child */ - if (setgid(getgid()) == -1) - _exit(127); - if (setuid(getuid()) == -1) - _exit(127); - if (*type == 'r') { - if (pdes[1] != 1) { - /* stdout */ - dup2(pdes[1], 1); - close(pdes[1]); - } - close(pdes[0]); - } else { - if (pdes[0] != 0) { - /* stdin */ - dup2(pdes[0], 0); - close(pdes[0]); - } - close(pdes[1]); - } - execl("/bin/sh", "sh", "-c", command, (char *)NULL); - _exit(127); - } - - /* Avoid EINTR during stdio calls */ - OsBlockSignals (); - - /* parent */ - if (*type == 'r') { - iop = fdopen(pdes[0], type); - close(pdes[1]); - } else { - iop = fdopen(pdes[1], type); - close(pdes[0]); - } - - cur->fp = iop; - cur->pid = pid; - cur->next = pidlist; - pidlist = cur; - -#ifdef DEBUG - ErrorF("Popen: `%s', fp = %p\n", command, iop); -#endif - - return iop; -} - -/* fopen that drops privileges */ -pointer -Fopen(char *file, char *type) -{ - FILE *iop; -#ifndef HAS_SAVED_IDS_AND_SETEUID - struct pid *cur; - int pdes[2], pid; - - if (file == NULL || type == NULL) - return NULL; - - if ((*type != 'r' && *type != 'w') || type[1]) - return NULL; - - if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) - return NULL; - - if (pipe(pdes) < 0) { - xfree(cur); - return NULL; - } - - switch (pid = fork()) { - case -1: /* error */ - close(pdes[0]); - close(pdes[1]); - xfree(cur); - return NULL; - case 0: /* child */ - if (setgid(getgid()) == -1) - _exit(127); - if (setuid(getuid()) == -1) - _exit(127); - if (*type == 'r') { - if (pdes[1] != 1) { - /* stdout */ - dup2(pdes[1], 1); - close(pdes[1]); - } - close(pdes[0]); - } else { - if (pdes[0] != 0) { - /* stdin */ - dup2(pdes[0], 0); - close(pdes[0]); - } - close(pdes[1]); - } - execl("/bin/cat", "cat", file, (char *)NULL); - _exit(127); - } - - /* Avoid EINTR during stdio calls */ - OsBlockSignals (); - - /* parent */ - if (*type == 'r') { - iop = fdopen(pdes[0], type); - close(pdes[1]); - } else { - iop = fdopen(pdes[1], type); - close(pdes[0]); - } - - cur->fp = iop; - cur->pid = pid; - cur->next = pidlist; - pidlist = cur; - -#ifdef DEBUG - ErrorF("Popen: `%s', fp = %p\n", command, iop); -#endif - - return iop; -#else - int ruid, euid; - - ruid = getuid(); - euid = geteuid(); - - if (seteuid(ruid) == -1) { - return NULL; - } - iop = fopen(file, type); - - if (seteuid(euid) == -1) { - fclose(iop); - return NULL; - } - return iop; -#endif /* HAS_SAVED_IDS_AND_SETEUID */ -} - -int -Pclose(pointer iop) -{ - struct pid *cur, *last; - int pstat; - int pid; - -#ifdef DEBUG - ErrorF("Pclose: fp = %p\n", iop); -#endif - - fclose(iop); - - for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) - if (cur->fp == iop) - break; - if (cur == NULL) - return -1; - - do { - pid = waitpid(cur->pid, &pstat, 0); - } while (pid == -1 && errno == EINTR); - - if (last == NULL) - pidlist = cur->next; - else - last->next = cur->next; - xfree(cur); - - /* allow EINTR again */ - OsReleaseSignals (); - - return pid == -1 ? -1 : pstat; -} - -int -Fclose(pointer iop) -{ -#ifdef HAS_SAVED_IDS_AND_SETEUID - return fclose(iop); -#else - return Pclose(iop); -#endif -} - -#endif /* !WIN32 && !__UNIXOS2__ */ - - -/* - * CheckUserParameters: check for long command line arguments and long - * environment variables. By default, these checks are only done when - * the server's euid != ruid. In 3.3.x, these checks were done in an - * external wrapper utility. - */ - -/* Consider LD* variables insecure? */ -#ifndef REMOVE_ENV_LD -#define REMOVE_ENV_LD 1 -#endif - -/* Remove long environment variables? */ -#ifndef REMOVE_LONG_ENV -#define REMOVE_LONG_ENV 1 -#endif - -/* - * Disallow stdout or stderr as pipes? It's possible to block the X server - * when piping stdout+stderr to a pipe. - * - * Don't enable this because it looks like it's going to cause problems. - */ -#ifndef NO_OUTPUT_PIPES -#define NO_OUTPUT_PIPES 0 -#endif - - -/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */ -#ifndef CHECK_EUID -#ifndef WIN32 -#define CHECK_EUID 1 -#else -#define CHECK_EUID 0 -#endif -#endif - -/* - * Maybe the locale can be faked to make isprint(3) report that everything - * is printable? Avoid it by default. - */ -#ifndef USE_ISPRINT -#define USE_ISPRINT 0 -#endif - -#define MAX_ARG_LENGTH 128 -#define MAX_ENV_LENGTH 256 -#define MAX_ENV_PATH_LENGTH 2048 /* Limit for *PATH and TERMCAP */ - -#if USE_ISPRINT -#include -#define checkPrintable(c) isprint(c) -#else -#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f) -#endif - -enum BadCode { - NotBad = 0, - UnsafeArg, - ArgTooLong, - UnprintableArg, - EnvTooLong, - OutputIsPipe, - InternalError -}; - -#if defined(VENDORSUPPORT) -#define BUGADDRESS VENDORSUPPORT -#elif defined(BUILDERADDR) -#define BUGADDRESS BUILDERADDR -#else -#define BUGADDRESS "xorg@freedesktop.org" -#endif - -#define ARGMSG \ - "\nIf the arguments used are valid, and have been rejected incorrectly\n" \ - "please send details of the arguments and why they are valid to\n" \ - "%s. In the meantime, you can start the Xserver as\n" \ - "the \"super user\" (root).\n" - -#define ENVMSG \ - "\nIf the environment is valid, and have been rejected incorrectly\n" \ - "please send details of the environment and why it is valid to\n" \ - "%s. In the meantime, you can start the Xserver as\n" \ - "the \"super user\" (root).\n" - -void -CheckUserParameters(int argc, char **argv, char **envp) -{ - enum BadCode bad = NotBad; - int i = 0, j; - char *a, *e = NULL; -#if defined(__QNX__) && !defined(__QNXNTO__) - char cmd_name[64]; -#endif - -#if CHECK_EUID - if (geteuid() == 0 && getuid() != geteuid()) -#endif - { - /* Check each argv[] */ - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-fp") == 0) - { - i++; /* continue with next argument. skip the length check */ - if (i >= argc) - break; - } else - { - if (strlen(argv[i]) > MAX_ARG_LENGTH) { - bad = ArgTooLong; - break; - } - } - a = argv[i]; - while (*a) { - if (checkPrintable(*a) == 0) { - bad = UnprintableArg; - break; - } - a++; - } - if (bad) - break; - } - if (!bad) { - /* Check each envp[] */ - for (i = 0; envp[i]; i++) { - - /* Check for bad environment variables and values */ -#if REMOVE_ENV_LD - while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) { -#ifdef ENVDEBUG - ErrorF("CheckUserParameters: removing %s from the " - "environment\n", strtok(envp[i], "=")); -#endif - for (j = i; envp[j]; j++) { - envp[j] = envp[j+1]; - } - } -#endif - if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) { -#if REMOVE_LONG_ENV -#ifdef ENVDEBUG - ErrorF("CheckUserParameters: removing %s from the " - "environment\n", strtok(envp[i], "=")); -#endif - for (j = i; envp[j]; j++) { - envp[j] = envp[j+1]; - } - i--; -#else - char *eq; - int len; - - eq = strchr(envp[i], '='); - if (!eq) - continue; - len = eq - envp[i]; - e = malloc(len + 1); - if (!e) { - bad = InternalError; - break; - } - strncpy(e, envp[i], len); - e[len] = 0; - if (len >= 4 && - (strcmp(e + len - 4, "PATH") == 0 || - strcmp(e, "TERMCAP") == 0)) { - if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) { - bad = EnvTooLong; - break; - } else { - free(e); - } - } else { - bad = EnvTooLong; - break; - } -#endif - } - } - } -#if NO_OUTPUT_PIPES - if (!bad) { - struct stat buf; - - if (fstat(fileno(stdout), &buf) == 0 && S_ISFIFO(buf.st_mode)) - bad = OutputIsPipe; - if (fstat(fileno(stderr), &buf) == 0 && S_ISFIFO(buf.st_mode)) - bad = OutputIsPipe; - } -#endif - } - switch (bad) { - case NotBad: - return; - case UnsafeArg: - ErrorF("Command line argument number %d is unsafe\n", i); - ErrorF(ARGMSG, BUGADDRESS); - break; - case ArgTooLong: - ErrorF("Command line argument number %d is too long\n", i); - ErrorF(ARGMSG, BUGADDRESS); - break; - case UnprintableArg: - ErrorF("Command line argument number %d contains unprintable" - " characters\n", i); - ErrorF(ARGMSG, BUGADDRESS); - break; - case EnvTooLong: - ErrorF("Environment variable `%s' is too long\n", e); - ErrorF(ENVMSG, BUGADDRESS); - break; - case OutputIsPipe: - ErrorF("Stdout and/or stderr is a pipe\n"); - break; - case InternalError: - ErrorF("Internal Error\n"); - break; - default: - ErrorF("Unknown error\n"); - ErrorF(ARGMSG, BUGADDRESS); - ErrorF(ENVMSG, BUGADDRESS); - break; - } - FatalError("X server aborted because of unsafe environment\n"); -} - -/* - * CheckUserAuthorization: check if the user is allowed to start the - * X server. This usually means some sort of PAM checking, and it is - * usually only done for setuid servers (uid != euid). - */ - -#ifdef USE_PAM -#include -#include -#include -#endif /* USE_PAM */ - -void -CheckUserAuthorization(void) -{ -#ifdef USE_PAM - static struct pam_conv conv = { - misc_conv, - NULL - }; - - pam_handle_t *pamh = NULL; - struct passwd *pw; - int retval; - - if (getuid() != geteuid()) { - pw = getpwuid(getuid()); - if (pw == NULL) - FatalError("getpwuid() failed for uid %d\n", getuid()); - - retval = pam_start("xserver", pw->pw_name, &conv, &pamh); - if (retval != PAM_SUCCESS) - FatalError("pam_start() failed.\n" - "\tMissing or mangled PAM config file or module?\n"); - - retval = pam_authenticate(pamh, 0); - if (retval != PAM_SUCCESS) { - pam_end(pamh, retval); - FatalError("PAM authentication failed, cannot start X server.\n" - "\tPerhaps you do not have console ownership?\n"); - } - - retval = pam_acct_mgmt(pamh, 0); - if (retval != PAM_SUCCESS) { - pam_end(pamh, retval); - FatalError("PAM authentication failed, cannot start X server.\n" - "\tPerhaps you do not have console ownership?\n"); - } - - /* this is not a session, so do not do session management */ - pam_end(pamh, PAM_SUCCESS); - } -#endif -} - -#ifdef __SCO__ -#include - -static void -lockit (int fd, short what) -{ - struct flock lck; - - lck.l_whence = 0; - lck.l_start = 0; - lck.l_len = 1; - lck.l_type = what; - - (void)fcntl (fd, F_SETLKW, &lck); -} - -/* SCO OpenServer 5 lacks pread/pwrite. Emulate them. */ -ssize_t -pread (int fd, void *buf, size_t nbytes, off_t offset) -{ - off_t saved; - ssize_t ret; - - lockit (fd, F_RDLCK); - saved = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - ret = read (fd, buf, nbytes); - lseek (fd, saved, SEEK_SET); - lockit (fd, F_UNLCK); - - return ret; -} - -ssize_t -pwrite (int fd, const void *buf, size_t nbytes, off_t offset) -{ - off_t saved; - ssize_t ret; - - lockit (fd, F_WRLCK); - saved = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - ret = write (fd, buf, nbytes); - lseek (fd, saved, SEEK_SET); - lockit (fd, F_UNLCK); - - return ret; -} -#endif /* __SCO__ */ diff --git a/nx-X11/programs/Xserver/os/xdmcp.c.NX.original b/nx-X11/programs/Xserver/os/xdmcp.c.NX.original deleted file mode 100644 index 032d58f15..000000000 --- a/nx-X11/programs/Xserver/os/xdmcp.c.NX.original +++ /dev/null @@ -1,1710 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/os/xdmcp.c,v 1.10 2005/07/03 08:53:52 daniels Exp $ */ -/* $Xorg: xdmcp.c,v 1.4 2001/01/31 13:37:19 pookie Exp $ */ -/* - * Copyright 1989 Network Computing Devices, Inc., Mountain View, California. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of N.C.D. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. N.C.D. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - */ -/* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.31 2003/12/30 21:24:32 herrb Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef WIN32 -#include -#endif - -#include - -#if !defined(WIN32) -#ifndef Lynx -#include -#include -#else -#include -#endif -#include -#include -#endif - -#include -#include -#include -#include -#include "misc.h" -#include -#include "osdep.h" -#include "input.h" -#include "dixstruct.h" -#include "opaque.h" - -#if defined(DGUX) -#include -#include -#endif - -#ifdef STREAMSCONN -#include -#include -#include -#endif - -#ifndef NX_TRANS_SOCKET - -#define NX_TRANS_SOCKET -#define NX_TRANS_TEST - -#endif - -#ifdef XDMCP -#undef REQUEST - -#ifdef XDMCP_NO_IPV6 -#undef IPv6 -#endif - -#include - -#define X_INCLUDE_NETDB_H -#include - -#ifdef NX_TRANS_SOCKET - -xdmcp_states XdmcpState; - -int XdmcpStartTime; -int XdmcpTimeOutRtx; - -#endif - -extern char *defaultDisplayClass; - -static int xdmcpSocket, sessionSocket; -static xdmcp_states state; -#if defined(IPv6) && defined(AF_INET6) -static int xdmcpSocket6; -static struct sockaddr_storage req_sockaddr; -#else -static struct sockaddr_in req_sockaddr; -#endif -static int req_socklen; -static CARD32 SessionID; -static CARD32 timeOutTime; -static int timeOutRtx; -static CARD32 defaultKeepaliveDormancy = XDM_DEF_DORMANCY; -static CARD32 keepaliveDormancy = XDM_DEF_DORMANCY; -static CARD16 DisplayNumber; -static xdmcp_states XDM_INIT_STATE = XDM_OFF; -#ifdef HASXDMAUTH -static char *xdmAuthCookie; -#endif - -static XdmcpBuffer buffer; - -#if defined(IPv6) && defined(AF_INET6) - -static struct addrinfo *mgrAddr; -static struct addrinfo *mgrAddrFirst; - -#define SOCKADDR_TYPE struct sockaddr_storage -#define SOCKADDR_FAMILY(s) ((struct sockaddr *)&(s))->sa_family - -#ifdef BSD44SOCKETS -#define SOCKLEN_FIELD(s) ((struct sockaddr *)&(s))->sa_len -#define SOCKLEN_TYPE unsigned char -#else -#define SOCKLEN_TYPE unsigned int -#endif - -#else - -#define SOCKADDR_TYPE struct sockaddr_in -#define SOCKADDR_FAMILY(s) (s).sin_family - -#ifdef BSD44SOCKETS -#define SOCKLEN_FIELD(s) (s).sin_len -#define SOCKLEN_TYPE unsigned char -#else -#define SOCKLEN_TYPE size_t -#endif - -#endif - -static SOCKADDR_TYPE ManagerAddress; -static SOCKADDR_TYPE FromAddress; - -#ifdef SOCKLEN_FIELD -#define ManagerAddressLen SOCKLEN_FIELD(ManagerAddress) -#define FromAddressLen SOCKLEN_FIELD(FromAddress) -#else -static SOCKLEN_TYPE ManagerAddressLen, FromAddressLen; -#endif - -#if defined(IPv6) && defined(AF_INET6) -static struct multicastinfo { - struct multicastinfo *next; - struct addrinfo *ai; - int hops; -} *mcastlist; -#endif - -static void XdmcpAddHost( - struct sockaddr *from, - int fromlen, - ARRAY8Ptr AuthenticationName, - ARRAY8Ptr hostname, - ARRAY8Ptr status); - -static void XdmcpSelectHost( - struct sockaddr *host_sockaddr, - int host_len, - ARRAY8Ptr AuthenticationName); - -static void get_xdmcp_sock(void); - -static void send_query_msg(void); - -static void recv_willing_msg( - struct sockaddr * /*from*/, - int /*fromlen*/, - unsigned /*length*/); - -static void send_request_msg(void); - -static void recv_accept_msg(unsigned /*length*/); - -static void recv_decline_msg(unsigned /*length*/); - -static void send_manage_msg(void); - -static void recv_refuse_msg(unsigned /*length*/); - -static void recv_failed_msg(unsigned /*length*/); - -static void send_keepalive_msg(void); - -static void recv_alive_msg(unsigned /*length*/); - -static void XdmcpFatal( - char * /*type*/, - ARRAY8Ptr /*status*/); - -static void XdmcpWarning(char * /*str*/); - -static void get_manager_by_name( - int /*argc*/, - char ** /*argv*/, - int /*i*/); - -static void get_fromaddr_by_name(int /*argc*/, char ** /*argv*/, int /*i*/); - -#if defined(IPv6) && defined(AF_INET6) -static int get_mcast_options(int /*argc*/, char ** /*argv*/, int /*i*/); -#endif - -static void receive_packet(int /*socketfd*/); - -static void send_packet(void); - -extern void XdmcpDeadSession(char * /*reason*/); - -static void timeout(void); - -static void restart(void); - -static void XdmcpBlockHandler( - pointer /*data*/, - struct timeval ** /*wt*/, - pointer /*LastSelectMask*/); - -static void XdmcpWakeupHandler( - pointer /*data*/, - int /*i*/, - pointer /*LastSelectMask*/); - -void XdmcpRegisterManufacturerDisplayID( - char * /*name*/, - int /*length*/); - - -static unsigned short xdm_udp_port = XDM_UDP_PORT; -static Bool OneSession = FALSE; -static const char *xdm_from = NULL; - -void -XdmcpUseMsg (void) -{ - ErrorF("-query host-name contact named host for XDMCP\n"); - ErrorF("-broadcast broadcast for XDMCP\n"); -#if defined(IPv6) && defined(AF_INET6) - ErrorF("-multicast [addr [hops]] IPv6 multicast for XDMCP\n"); -#endif - ErrorF("-indirect host-name contact named host for indirect XDMCP\n"); - ErrorF("-port port-num UDP port number to send messages to\n"); - ErrorF("-from local-address specify the local address to connect from\n"); - ErrorF("-once Terminate server after one session\n"); - ErrorF("-class display-class specify display class to send in manage\n"); -#ifdef HASXDMAUTH - ErrorF("-cookie xdm-auth-bits specify the magic cookie for XDMCP\n"); -#endif - ErrorF("-displayID display-id manufacturer display ID for request\n"); -} - -int -XdmcpOptions(int argc, char **argv, int i) -{ - if (strcmp(argv[i], "-query") == 0) { - get_manager_by_name(argc, argv, i++); - XDM_INIT_STATE = XDM_QUERY; - AccessUsingXdmcp (); - return (i + 1); - } - if (strcmp(argv[i], "-broadcast") == 0) { - XDM_INIT_STATE = XDM_BROADCAST; - AccessUsingXdmcp (); - return (i + 1); - } -#if defined(IPv6) && defined(AF_INET6) - if (strcmp(argv[i], "-multicast") == 0) { - i = get_mcast_options(argc, argv, ++i); - XDM_INIT_STATE = XDM_MULTICAST; - AccessUsingXdmcp (); - return (i + 1); - } -#endif - if (strcmp(argv[i], "-indirect") == 0) { - get_manager_by_name(argc, argv, i++); - XDM_INIT_STATE = XDM_INDIRECT; - AccessUsingXdmcp (); - return (i + 1); - } - if (strcmp(argv[i], "-port") == 0) { - if (++i == argc) { - FatalError("Xserver: missing port number in command line\n"); - } - xdm_udp_port = (unsigned short) atoi(argv[i]); - return (i + 1); - } - if (strcmp(argv[i], "-from") == 0) { - get_fromaddr_by_name(argc, argv, ++i); - return (i + 1); - } - if (strcmp(argv[i], "-once") == 0) { - OneSession = TRUE; - return (i + 1); - } - if (strcmp(argv[i], "-class") == 0) { - if (++i == argc) { - FatalError("Xserver: missing class name in command line\n"); - } - defaultDisplayClass = argv[i]; - return (i + 1); - } -#ifdef HASXDMAUTH - if (strcmp(argv[i], "-cookie") == 0) { - if (++i == argc) { - FatalError("Xserver: missing cookie data in command line\n"); - } - xdmAuthCookie = argv[i]; - return (i + 1); - } -#endif - if (strcmp(argv[i], "-displayID") == 0) { - if (++i == argc) { - FatalError("Xserver: missing displayID in command line\n"); - } - XdmcpRegisterManufacturerDisplayID (argv[i], strlen (argv[i])); - return (i + 1); - } - return (i); -} - -/* - * This section is a collection of routines for - * registering server-specific data with the XDMCP - * state machine. - */ - - -/* - * Save all broadcast addresses away so BroadcastQuery - * packets get sent everywhere - */ - -#define MAX_BROADCAST 10 - -/* This stays sockaddr_in since IPv6 doesn't support broadcast */ -static struct sockaddr_in BroadcastAddresses[MAX_BROADCAST]; -static int NumBroadcastAddresses; - -void -XdmcpRegisterBroadcastAddress (struct sockaddr_in *addr) -{ - struct sockaddr_in *bcast; - if (NumBroadcastAddresses >= MAX_BROADCAST) - return; - bcast = &BroadcastAddresses[NumBroadcastAddresses++]; - bzero (bcast, sizeof (struct sockaddr_in)); -#ifdef BSD44SOCKETS - bcast->sin_len = addr->sin_len; -#endif - bcast->sin_family = addr->sin_family; - bcast->sin_port = htons (xdm_udp_port); - bcast->sin_addr = addr->sin_addr; -} - -/* - * Each authentication type is registered here; Validator - * will be called to check all access attempts using - * the specified authentication type - */ - -static ARRAYofARRAY8 AuthenticationNames, AuthenticationDatas; -typedef struct _AuthenticationFuncs { - ValidatorFunc Validator; - GeneratorFunc Generator; - AddAuthorFunc AddAuth; -} AuthenticationFuncsRec, *AuthenticationFuncsPtr; - -static AuthenticationFuncsPtr AuthenticationFuncsList; - -void -XdmcpRegisterAuthentication ( - char *name, - int namelen, - char *data, - int datalen, - ValidatorFunc Validator, - GeneratorFunc Generator, - AddAuthorFunc AddAuth) -{ - int i; - ARRAY8 AuthenticationName, AuthenticationData; - static AuthenticationFuncsPtr newFuncs; - - if (!XdmcpAllocARRAY8 (&AuthenticationName, namelen)) - return; - if (!XdmcpAllocARRAY8 (&AuthenticationData, datalen)) - { - XdmcpDisposeARRAY8 (&AuthenticationName); - return; - } - for (i = 0; i < namelen; i++) - AuthenticationName.data[i] = name[i]; - for (i = 0; i < datalen; i++) - AuthenticationData.data[i] = data[i]; - if (!(XdmcpReallocARRAYofARRAY8 (&AuthenticationNames, - AuthenticationNames.length + 1) && - XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas, - AuthenticationDatas.length + 1) && - (newFuncs = (AuthenticationFuncsPtr) xalloc ( - (AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec))))) - { - XdmcpDisposeARRAY8 (&AuthenticationName); - XdmcpDisposeARRAY8 (&AuthenticationData); - return; - } - for (i = 0; i < AuthenticationNames.length - 1; i++) - newFuncs[i] = AuthenticationFuncsList[i]; - newFuncs[AuthenticationNames.length-1].Validator = Validator; - newFuncs[AuthenticationNames.length-1].Generator = Generator; - newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth; - xfree (AuthenticationFuncsList); - AuthenticationFuncsList = newFuncs; - AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName; - AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData; -} - -/* - * Select the authentication type to be used; this is - * set by the manager of the host to be connected to. - */ - -ARRAY8 noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0}; -ARRAY8 noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0}; -ARRAY8Ptr AuthenticationName = &noAuthenticationName; -ARRAY8Ptr AuthenticationData = &noAuthenticationData; -AuthenticationFuncsPtr AuthenticationFuncs; - -void -XdmcpSetAuthentication (ARRAY8Ptr name) -{ - int i; - - for (i = 0; i < AuthenticationNames.length; i++) - if (XdmcpARRAY8Equal (&AuthenticationNames.data[i], name)) - { - AuthenticationName = &AuthenticationNames.data[i]; - AuthenticationData = &AuthenticationDatas.data[i]; - AuthenticationFuncs = &AuthenticationFuncsList[i]; - break; - } -} - -/* - * Register the host address for the display - */ - -static ARRAY16 ConnectionTypes; -static ARRAYofARRAY8 ConnectionAddresses; -static long xdmcpGeneration; - -void -XdmcpRegisterConnection ( - int type, - char *address, - int addrlen) -{ - int i; - CARD8 *newAddress; - - if (xdmcpGeneration != serverGeneration) - { - XdmcpDisposeARRAY16 (&ConnectionTypes); - XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses); - xdmcpGeneration = serverGeneration; - } - if (xdm_from != NULL) { /* Only register the requested address */ - const void *regAddr = address; - const void *fromAddr = NULL; - int regAddrlen = addrlen; - - if (addrlen == sizeof(struct in_addr)) { - if (SOCKADDR_FAMILY(FromAddress) == AF_INET) { - fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; - } -#if defined(IPv6) && defined(AF_INET6) - else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET6) && - IN6_IS_ADDR_V4MAPPED( - &((struct sockaddr_in6 *)&FromAddress)->sin6_addr)) { - fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr.s6_addr[12]; - } -#endif - } -#if defined(IPv6) && defined(AF_INET6) - else if (addrlen == sizeof(struct in6_addr)) { - if (SOCKADDR_FAMILY(FromAddress) == AF_INET6) { - fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr; - } else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET) && - IN6_IS_ADDR_V4MAPPED((struct in6_addr *) address)) { - fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; - regAddr = &((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr[12]; - regAddrlen = sizeof(struct in_addr); - } - } -#endif - if (fromAddr && memcmp(regAddr, fromAddr, regAddrlen) != 0) { - return; - } - } - newAddress = (CARD8 *) xalloc (addrlen * sizeof (CARD8)); - if (!newAddress) - return; - if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1)) - { - xfree (newAddress); - return; - } - if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses, - ConnectionAddresses.length + 1)) - { - xfree (newAddress); - return; - } - ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type; - for (i = 0; i < addrlen; i++) - newAddress[i] = address[i]; - ConnectionAddresses.data[ConnectionAddresses.length-1].data = newAddress; - ConnectionAddresses.data[ConnectionAddresses.length-1].length = addrlen; -} - -/* - * Register an Authorization Name. XDMCP advertises this list - * to the manager. - */ - -static ARRAYofARRAY8 AuthorizationNames; - -void -XdmcpRegisterAuthorizations (void) -{ - XdmcpDisposeARRAYofARRAY8 (&AuthorizationNames); - RegisterAuthorizations (); -} - -void -XdmcpRegisterAuthorization (char *name, int namelen) -{ - ARRAY8 authName; - int i; - - authName.data = (CARD8 *) xalloc (namelen * sizeof (CARD8)); - if (!authName.data) - return; - if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1)) - { - xfree (authName.data); - return; - } - for (i = 0; i < namelen; i++) - authName.data[i] = (CARD8) name[i]; - authName.length = namelen; - AuthorizationNames.data[AuthorizationNames.length-1] = authName; -} - -/* - * Register the DisplayClass string - */ - -ARRAY8 DisplayClass; - -void -XdmcpRegisterDisplayClass (char *name, int length) -{ - int i; - - XdmcpDisposeARRAY8 (&DisplayClass); - if (!XdmcpAllocARRAY8 (&DisplayClass, length)) - return; - for (i = 0; i < length; i++) - DisplayClass.data[i] = (CARD8) name[i]; -} - -/* - * Register the Manufacturer display ID - */ - -ARRAY8 ManufacturerDisplayID; - -void -XdmcpRegisterManufacturerDisplayID (char *name, int length) -{ - int i; - - XdmcpDisposeARRAY8 (&ManufacturerDisplayID); - if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length)) - return; - for (i = 0; i < length; i++) - ManufacturerDisplayID.data[i] = (CARD8) name[i]; -} - -/* - * initialize XDMCP; create the socket, compute the display - * number, set up the state machine - */ - -void -XdmcpInit(void) -{ -#ifdef NX_TRANS_SOCKET - - XdmcpStartTime = GetTimeInMillis(); - -#endif - - state = XDM_INIT_STATE; -#ifdef HASXDMAUTH - if (xdmAuthCookie) - XdmAuthenticationInit (xdmAuthCookie, strlen (xdmAuthCookie)); -#endif - if (state != XDM_OFF) - { - XdmcpRegisterAuthorizations(); - XdmcpRegisterDisplayClass (defaultDisplayClass, strlen (defaultDisplayClass)); - AccessUsingXdmcp(); - RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler, - (pointer) 0); - timeOutRtx = 0; - DisplayNumber = (CARD16) atoi(display); - get_xdmcp_sock(); - send_packet(); - } -} - -void -XdmcpReset (void) -{ - state = XDM_INIT_STATE; - if (state != XDM_OFF) - { - RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler, - (pointer) 0); - timeOutRtx = 0; - send_packet(); - } -} - -/* - * Called whenever a new connection is created; notices the - * first connection and saves it to terminate the session - * when it is closed - */ - -void -XdmcpOpenDisplay(int sock) -{ - if (state != XDM_AWAIT_MANAGE_RESPONSE) - return; - state = XDM_RUN_SESSION; - sessionSocket = sock; -} - -void -XdmcpCloseDisplay(int sock) -{ - if ((state != XDM_RUN_SESSION && state != XDM_AWAIT_ALIVE_RESPONSE) - || sessionSocket != sock) - return; - state = XDM_INIT_STATE; - if (OneSession) - dispatchException |= DE_TERMINATE; - else - dispatchException |= DE_RESET; - isItTimeToYield = TRUE; -} - -/* - * called before going to sleep, this routine - * may modify the timeout value about to be sent - * to select; in this way XDMCP can do appropriate things - * dynamically while starting up - */ - -/*ARGSUSED*/ -static void -XdmcpBlockHandler( - pointer data, /* unused */ - struct timeval **wt, - pointer pReadmask) -{ - fd_set *LastSelectMask = (fd_set*)pReadmask; - CARD32 millisToGo; - - if (state == XDM_OFF) - return; - FD_SET(xdmcpSocket, LastSelectMask); -#if defined(IPv6) && defined(AF_INET6) - if (xdmcpSocket6 >= 0) - FD_SET(xdmcpSocket6, LastSelectMask); -#endif - if (timeOutTime == 0) - return; - millisToGo = timeOutTime - GetTimeInMillis(); - if ((int) millisToGo < 0) - millisToGo = 0; - AdjustWaitForDelay (wt, millisToGo); -} - -/* - * called after select returns; this routine will - * recognise when XDMCP packets await and - * process them appropriately - */ - -/*ARGSUSED*/ -static void -XdmcpWakeupHandler( - pointer data, /* unused */ - int i, - pointer pReadmask) -{ - fd_set* LastSelectMask = (fd_set*)pReadmask; - fd_set devicesReadable; - -#ifdef NX_TRANS_SOCKET - - XdmcpState = state; - XdmcpTimeOutRtx = timeOutRtx; - -#endif - - if (state == XDM_OFF) - return; - if (i > 0) - { - if (FD_ISSET(xdmcpSocket, LastSelectMask)) - { - receive_packet(xdmcpSocket); - FD_CLR(xdmcpSocket, LastSelectMask); - } -#if defined(IPv6) && defined(AF_INET6) - if (xdmcpSocket6 >= 0 && FD_ISSET(xdmcpSocket6, LastSelectMask)) - { - receive_packet(xdmcpSocket6); - FD_CLR(xdmcpSocket6, LastSelectMask); - } -#endif - XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices); - if (XFD_ANYSET(&devicesReadable)) - { - if (state == XDM_AWAIT_USER_INPUT) - restart(); - else if (state == XDM_RUN_SESSION) - keepaliveDormancy = defaultKeepaliveDormancy; - } - if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION) - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; - } - else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) - { - if (state == XDM_RUN_SESSION) - { - state = XDM_KEEPALIVE; - send_packet(); - } - else - timeout(); - } -} - -/* - * This routine should be called from the routine that drives the - * user's host menu when the user selects a host - */ - -static void -XdmcpSelectHost( - struct sockaddr *host_sockaddr, - int host_len, - ARRAY8Ptr AuthenticationName) -{ - state = XDM_START_CONNECTION; - memmove(&req_sockaddr, host_sockaddr, host_len); - req_socklen = host_len; - XdmcpSetAuthentication (AuthenticationName); - send_packet(); -} - -/* - * !!! this routine should be replaced by a routine that adds - * the host to the user's host menu. the current version just - * selects the first host to respond with willing message. - */ - -/*ARGSUSED*/ -static void -XdmcpAddHost( - struct sockaddr *from, - int fromlen, - ARRAY8Ptr AuthenticationName, - ARRAY8Ptr hostname, - ARRAY8Ptr status) -{ - XdmcpSelectHost(from, fromlen, AuthenticationName); -} - -/* - * A message is queued on the socket; read it and - * do the appropriate thing - */ - -ARRAY8 UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" }; - -static void -receive_packet(int socketfd) -{ -#if defined(IPv6) && defined(AF_INET6) - struct sockaddr_storage from; -#else - struct sockaddr_in from; -#endif - int fromlen = sizeof(from); - XdmcpHeader header; - - /* read message off socket */ - if (!XdmcpFill (socketfd, &buffer, (XdmcpNetaddr) &from, &fromlen)) - return; - - /* reset retransmission backoff */ - timeOutRtx = 0; - - if (!XdmcpReadHeader (&buffer, &header)) - return; - - if (header.version != XDM_PROTOCOL_VERSION) - return; - - switch (header.opcode) { - case WILLING: - recv_willing_msg((struct sockaddr *) &from, fromlen, header.length); - break; - case UNWILLING: - XdmcpFatal("Manager unwilling", &UnwillingMessage); - break; - case ACCEPT: - recv_accept_msg(header.length); - break; - case DECLINE: - recv_decline_msg(header.length); - break; - case REFUSE: - recv_refuse_msg(header.length); - break; - case FAILED: - recv_failed_msg(header.length); - break; - case ALIVE: - recv_alive_msg(header.length); - break; - } -} - -/* - * send the appropriate message given the current state - */ - -static void -send_packet(void) -{ - int rtx; - switch (state) { - case XDM_QUERY: - case XDM_BROADCAST: - case XDM_INDIRECT: -#if defined(IPv6) && defined(AF_INET6) - case XDM_MULTICAST: -#endif - send_query_msg(); - break; - case XDM_START_CONNECTION: - send_request_msg(); - break; - case XDM_MANAGE: - send_manage_msg(); - break; - case XDM_KEEPALIVE: - send_keepalive_msg(); - break; - default: - break; - } - rtx = (XDM_MIN_RTX << timeOutRtx); - if (rtx > XDM_MAX_RTX) - rtx = XDM_MAX_RTX; - timeOutTime = GetTimeInMillis() + rtx * 1000; -} - -/* - * The session is declared dead for some reason; too many - * timeouts, or Keepalive failure. - */ - -void -XdmcpDeadSession (char *reason) -{ - ErrorF ("XDM: %s, declaring session dead\n", reason); - state = XDM_INIT_STATE; - isItTimeToYield = TRUE; - dispatchException |= DE_RESET; - timeOutTime = 0; - timeOutRtx = 0; - send_packet(); -} - -/* - * Timeout waiting for an XDMCP response. - */ - -static void -timeout(void) -{ - timeOutRtx++; - if (state == XDM_AWAIT_ALIVE_RESPONSE && timeOutRtx >= XDM_KA_RTX_LIMIT ) - { - XdmcpDeadSession ("too many keepalive retransmissions"); - return; - } - else if (timeOutRtx >= XDM_RTX_LIMIT) - { - /* Quit if "-once" specified, otherwise reset and try again. */ - if (OneSession) { - dispatchException |= DE_TERMINATE; - ErrorF("XDM: too many retransmissions\n"); - } else { - XdmcpDeadSession("too many retransmissions"); - } - return; - } - -#if defined(IPv6) && defined(AF_INET6) - if (state == XDM_COLLECT_QUERY || state == XDM_COLLECT_INDIRECT_QUERY) { - /* Try next address */ - for (mgrAddr = mgrAddr->ai_next; ; mgrAddr = mgrAddr->ai_next) { - if (mgrAddr == NULL) { - mgrAddr = mgrAddrFirst; - } - if (mgrAddr->ai_family == AF_INET - || mgrAddr->ai_family == AF_INET6) - break; - } -#ifndef SIN6_LEN - ManagerAddressLen = mgrAddr->ai_addrlen; -#endif - memcpy(&ManagerAddress, mgrAddr->ai_addr, mgrAddr->ai_addrlen); - } -#endif - - switch (state) { - case XDM_COLLECT_QUERY: - state = XDM_QUERY; - break; - case XDM_COLLECT_BROADCAST_QUERY: - state = XDM_BROADCAST; - break; -#if defined(IPv6) && defined(AF_INET6) - case XDM_COLLECT_MULTICAST_QUERY: - state = XDM_MULTICAST; - break; -#endif - case XDM_COLLECT_INDIRECT_QUERY: - state = XDM_INDIRECT; - break; - case XDM_AWAIT_REQUEST_RESPONSE: - state = XDM_START_CONNECTION; - break; - case XDM_AWAIT_MANAGE_RESPONSE: - state = XDM_MANAGE; - break; - case XDM_AWAIT_ALIVE_RESPONSE: - state = XDM_KEEPALIVE; - break; - default: - break; - } - send_packet(); -} - -static void -restart(void) -{ - state = XDM_INIT_STATE; - timeOutRtx = 0; - send_packet(); -} - -int -XdmcpCheckAuthentication ( - ARRAY8Ptr Name, - ARRAY8Ptr Data, - int packet_type) -{ - return (XdmcpARRAY8Equal (Name, AuthenticationName) && - (AuthenticationName->length == 0 || - (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type))); -} - -int -XdmcpAddAuthorization ( - ARRAY8Ptr name, - ARRAY8Ptr data) -{ - AddAuthorFunc AddAuth; - - if (AuthenticationFuncs && AuthenticationFuncs->AddAuth) - AddAuth = AuthenticationFuncs->AddAuth; - else - AddAuth = AddAuthorization; - return (*AddAuth) ((unsigned short)name->length, - (char *)name->data, - (unsigned short)data->length, - (char *)data->data); -} - -/* - * from here to the end of this file are routines private - * to the state machine. - */ - -static void -get_xdmcp_sock(void) -{ -#ifdef STREAMSCONN - struct netconfig *nconf; - - if ((xdmcpSocket = t_open("/dev/udp", O_RDWR, 0)) < 0) { - XdmcpWarning("t_open() of /dev/udp failed"); - return; - } - - if( t_bind(xdmcpSocket,NULL,NULL) < 0 ) { - XdmcpWarning("UDP socket creation failed"); - t_error("t_bind(xdmcpSocket) failed" ); - t_close(xdmcpSocket); - return; - } - - /* - * This part of the code looks contrived. It will actually fit in nicely - * when the CLTS part of Xtrans is implemented. - */ - - if( (nconf=getnetconfigent("udp")) == NULL ) { - XdmcpWarning("UDP socket creation failed: getnetconfigent()"); - t_unbind(xdmcpSocket); - t_close(xdmcpSocket); - return; - } - - if( netdir_options(nconf, ND_SET_BROADCAST, xdmcpSocket, NULL) ) { - XdmcpWarning("UDP set broadcast option failed: netdir_options()"); - freenetconfigent(nconf); - t_unbind(xdmcpSocket); - t_close(xdmcpSocket); - return; - } - - freenetconfigent(nconf); -#else - int soopts = 1; - -#if defined(IPv6) && defined(AF_INET6) - if ((xdmcpSocket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) - XdmcpWarning("INET6 UDP socket creation failed"); -#endif - if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - XdmcpWarning("UDP socket creation failed"); -#ifdef SO_BROADCAST - else if (setsockopt(xdmcpSocket, SOL_SOCKET, SO_BROADCAST, (char *)&soopts, - sizeof(soopts)) < 0) - XdmcpWarning("UDP set broadcast socket-option failed"); -#endif /* SO_BROADCAST */ - if (xdmcpSocket >= 0 && xdm_from != NULL) { - if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress, - FromAddressLen) < 0) { - FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from); - } - } -#endif /* STREAMSCONN */ -} - -static void -send_query_msg(void) -{ - XdmcpHeader header; - Bool broadcast = FALSE; -#if defined(IPv6) && defined(AF_INET6) - Bool multicast = FALSE; -#endif - int i; - int socketfd = xdmcpSocket; - - header.version = XDM_PROTOCOL_VERSION; - switch(state){ - case XDM_QUERY: - header.opcode = (CARD16) QUERY; - state = XDM_COLLECT_QUERY; - break; - case XDM_BROADCAST: - header.opcode = (CARD16) BROADCAST_QUERY; - state = XDM_COLLECT_BROADCAST_QUERY; - broadcast = TRUE; - break; -#if defined(IPv6) && defined(AF_INET6) - case XDM_MULTICAST: - header.opcode = (CARD16) BROADCAST_QUERY; - state = XDM_COLLECT_MULTICAST_QUERY; - multicast = TRUE; - break; -#endif - case XDM_INDIRECT: - header.opcode = (CARD16) INDIRECT_QUERY; - state = XDM_COLLECT_INDIRECT_QUERY; - break; - default: - break; - } - header.length = 1; - for (i = 0; i < AuthenticationNames.length; i++) - header.length += 2 + AuthenticationNames.data[i].length; - - XdmcpWriteHeader (&buffer, &header); - XdmcpWriteARRAYofARRAY8 (&buffer, &AuthenticationNames); - if (broadcast) - { - int i; - - for (i = 0; i < NumBroadcastAddresses; i++) - XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &BroadcastAddresses[i], - sizeof (struct sockaddr_in)); - } -#if defined(IPv6) && defined(AF_INET6) - else if (multicast) - { - struct multicastinfo *mcl; - struct addrinfo *ai; - - for (mcl = mcastlist; mcl != NULL; mcl = mcl->next) { - for (ai = mcl->ai ; ai != NULL; ai = ai->ai_next) { - if (ai->ai_family == AF_INET) { - unsigned char hopflag = (unsigned char) mcl->hops; - socketfd = xdmcpSocket; - setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL, - &hopflag, sizeof(hopflag)); - } else if (ai->ai_family == AF_INET6) { - int hopflag6 = mcl->hops; - socketfd = xdmcpSocket6; - setsockopt(socketfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, - &hopflag6, sizeof(hopflag6)); - } else { - continue; - } - XdmcpFlush (socketfd, &buffer, - (XdmcpNetaddr) ai->ai_addr, ai->ai_addrlen); - break; - } - } - } -#endif - else - { -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress, - ManagerAddressLen); - } -} - -static void -recv_willing_msg( - struct sockaddr *from, - int fromlen, - unsigned length) -{ - ARRAY8 authenticationName; - ARRAY8 hostname; - ARRAY8 status; - - authenticationName.data = 0; - hostname.data = 0; - status.data = 0; - if (XdmcpReadARRAY8 (&buffer, &authenticationName) && - XdmcpReadARRAY8 (&buffer, &hostname) && - XdmcpReadARRAY8 (&buffer, &status)) - { - if (length == 6 + authenticationName.length + - hostname.length + status.length) - { - switch (state) - { - case XDM_COLLECT_QUERY: - XdmcpSelectHost(from, fromlen, &authenticationName); - break; - case XDM_COLLECT_BROADCAST_QUERY: -#if defined(IPv6) && defined(AF_INET6) - case XDM_COLLECT_MULTICAST_QUERY: -#endif - case XDM_COLLECT_INDIRECT_QUERY: - XdmcpAddHost(from, fromlen, &authenticationName, &hostname, &status); - break; - default: - break; - } - } - } - XdmcpDisposeARRAY8 (&authenticationName); - XdmcpDisposeARRAY8 (&hostname); - XdmcpDisposeARRAY8 (&status); -} - -static void -send_request_msg(void) -{ - XdmcpHeader header; - int length; - int i; - CARD16 XdmcpConnectionType; - ARRAY8 authenticationData; - int socketfd = xdmcpSocket; - - switch (SOCKADDR_FAMILY(ManagerAddress)) - { - case AF_INET: XdmcpConnectionType=FamilyInternet; break; -#if defined(IPv6) && defined(AF_INET6) - case AF_INET6: XdmcpConnectionType=FamilyInternet6; break; -#endif - default: XdmcpConnectionType=0xffff; break; - } - - header.version = XDM_PROTOCOL_VERSION; - header.opcode = (CARD16) REQUEST; - - length = 2; /* display number */ - length += 1 + 2 * ConnectionTypes.length; /* connection types */ - length += 1; /* connection addresses */ - for (i = 0; i < ConnectionAddresses.length; i++) - length += 2 + ConnectionAddresses.data[i].length; - authenticationData.length = 0; - authenticationData.data = 0; - if (AuthenticationFuncs) - { - (*AuthenticationFuncs->Generator) (AuthenticationData, - &authenticationData, - REQUEST); - } - length += 2 + AuthenticationName->length; /* authentication name */ - length += 2 + authenticationData.length; /* authentication data */ - length += 1; /* authorization names */ - for (i = 0; i < AuthorizationNames.length; i++) - length += 2 + AuthorizationNames.data[i].length; - length += 2 + ManufacturerDisplayID.length; /* display ID */ - header.length = length; - - if (!XdmcpWriteHeader (&buffer, &header)) - { - XdmcpDisposeARRAY8 (&authenticationData); - return; - } - XdmcpWriteCARD16 (&buffer, DisplayNumber); - XdmcpWriteCARD8 (&buffer, ConnectionTypes.length); - - /* The connection array is send reordered, so that connections of */ - /* the same address type as the XDMCP manager connection are send */ - /* first. This works around a bug in xdm. mario@klebsch.de */ - for (i = 0; i < (int)ConnectionTypes.length; i++) - if (ConnectionTypes.data[i]==XdmcpConnectionType) - XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]); - for (i = 0; i < (int)ConnectionTypes.length; i++) - if (ConnectionTypes.data[i]!=XdmcpConnectionType) - XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]); - - XdmcpWriteCARD8 (&buffer, ConnectionAddresses.length); - for (i = 0; i < (int)ConnectionAddresses.length; i++) - if ( (i=ConnectionTypes.length) || - (ConnectionTypes.data[i]!=XdmcpConnectionType) ) - XdmcpWriteARRAY8 (&buffer, &ConnectionAddresses.data[i]); - - XdmcpWriteARRAY8 (&buffer, AuthenticationName); - XdmcpWriteARRAY8 (&buffer, &authenticationData); - XdmcpDisposeARRAY8 (&authenticationData); - XdmcpWriteARRAYofARRAY8 (&buffer, &AuthorizationNames); - XdmcpWriteARRAY8 (&buffer, &ManufacturerDisplayID); -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - if (XdmcpFlush (socketfd, &buffer, - (XdmcpNetaddr) &req_sockaddr, req_socklen)) - state = XDM_AWAIT_REQUEST_RESPONSE; -} - -static void -recv_accept_msg(unsigned length) -{ - CARD32 AcceptSessionID; - ARRAY8 AcceptAuthenticationName, AcceptAuthenticationData; - ARRAY8 AcceptAuthorizationName, AcceptAuthorizationData; - - if (state != XDM_AWAIT_REQUEST_RESPONSE) - return; - AcceptAuthenticationName.data = 0; - AcceptAuthenticationData.data = 0; - AcceptAuthorizationName.data = 0; - AcceptAuthorizationData.data = 0; - if (XdmcpReadCARD32 (&buffer, &AcceptSessionID) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationName) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationData) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationName) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationData)) - { - if (length == 12 + AcceptAuthenticationName.length + - AcceptAuthenticationData.length + - AcceptAuthorizationName.length + - AcceptAuthorizationData.length) - { - if (!XdmcpCheckAuthentication (&AcceptAuthenticationName, - &AcceptAuthenticationData, ACCEPT)) - { - XdmcpFatal ("Authentication Failure", &AcceptAuthenticationName); - } - /* permit access control manipulations from this host */ - AugmentSelf (&req_sockaddr, req_socklen); - /* if the authorization specified in the packet fails - * to be acceptable, enable the local addresses - */ - if (!XdmcpAddAuthorization (&AcceptAuthorizationName, - &AcceptAuthorizationData)) - { - AddLocalHosts (); - } - SessionID = AcceptSessionID; - state = XDM_MANAGE; - send_packet(); - } - } - XdmcpDisposeARRAY8 (&AcceptAuthenticationName); - XdmcpDisposeARRAY8 (&AcceptAuthenticationData); - XdmcpDisposeARRAY8 (&AcceptAuthorizationName); - XdmcpDisposeARRAY8 (&AcceptAuthorizationData); -} - -static void -recv_decline_msg(unsigned length) -{ - ARRAY8 status, DeclineAuthenticationName, DeclineAuthenticationData; - - status.data = 0; - DeclineAuthenticationName.data = 0; - DeclineAuthenticationData.data = 0; - if (XdmcpReadARRAY8 (&buffer, &status) && - XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationName) && - XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationData)) - { - if (length == 6 + status.length + - DeclineAuthenticationName.length + - DeclineAuthenticationData.length && - XdmcpCheckAuthentication (&DeclineAuthenticationName, - &DeclineAuthenticationData, DECLINE)) - { - XdmcpFatal ("Session declined", &status); - } - } - XdmcpDisposeARRAY8 (&status); - XdmcpDisposeARRAY8 (&DeclineAuthenticationName); - XdmcpDisposeARRAY8 (&DeclineAuthenticationData); -} - -static void -send_manage_msg(void) -{ - XdmcpHeader header; - int socketfd = xdmcpSocket; - - header.version = XDM_PROTOCOL_VERSION; - header.opcode = (CARD16) MANAGE; - header.length = 8 + DisplayClass.length; - - if (!XdmcpWriteHeader (&buffer, &header)) - return; - XdmcpWriteCARD32 (&buffer, SessionID); - XdmcpWriteCARD16 (&buffer, DisplayNumber); - XdmcpWriteARRAY8 (&buffer, &DisplayClass); - state = XDM_AWAIT_MANAGE_RESPONSE; -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); -} - -static void -recv_refuse_msg(unsigned length) -{ - CARD32 RefusedSessionID; - - if (state != XDM_AWAIT_MANAGE_RESPONSE) - return; - if (length != 4) - return; - if (XdmcpReadCARD32 (&buffer, &RefusedSessionID)) - { - if (RefusedSessionID == SessionID) - { - state = XDM_START_CONNECTION; - send_packet(); - } - } -} - -static void -recv_failed_msg(unsigned length) -{ - CARD32 FailedSessionID; - ARRAY8 status; - - if (state != XDM_AWAIT_MANAGE_RESPONSE) - return; - status.data = 0; - if (XdmcpReadCARD32 (&buffer, &FailedSessionID) && - XdmcpReadARRAY8 (&buffer, &status)) - { - if (length == 6 + status.length && - SessionID == FailedSessionID) - { - XdmcpFatal ("Session failed", &status); - } - } - XdmcpDisposeARRAY8 (&status); -} - -static void -send_keepalive_msg(void) -{ - XdmcpHeader header; - int socketfd = xdmcpSocket; - - header.version = XDM_PROTOCOL_VERSION; - header.opcode = (CARD16) KEEPALIVE; - header.length = 6; - - XdmcpWriteHeader (&buffer, &header); - XdmcpWriteCARD16 (&buffer, DisplayNumber); - XdmcpWriteCARD32 (&buffer, SessionID); - - state = XDM_AWAIT_ALIVE_RESPONSE; -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); -} - -static void -recv_alive_msg (unsigned length) -{ - CARD8 SessionRunning; - CARD32 AliveSessionID; - - if (state != XDM_AWAIT_ALIVE_RESPONSE) - return; - if (length != 5) - return; - if (XdmcpReadCARD8 (&buffer, &SessionRunning) && - XdmcpReadCARD32 (&buffer, &AliveSessionID)) - { - if (SessionRunning && AliveSessionID == SessionID) - { - /* backoff dormancy period */ - state = XDM_RUN_SESSION; - if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) > - keepaliveDormancy * 1000) - { - keepaliveDormancy <<= 1; - if (keepaliveDormancy > XDM_MAX_DORMANCY) - keepaliveDormancy = XDM_MAX_DORMANCY; - } - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; - } - else - { - XdmcpDeadSession ("Alive response indicates session dead"); - } - } -} - -static void -XdmcpFatal ( - char *type, - ARRAY8Ptr status) -{ - FatalError ("XDMCP fatal error: %s %*.*s\n", type, - status->length, status->length, status->data); -} - -static void -XdmcpWarning(char *str) -{ - ErrorF("XDMCP warning: %s\n", str); -} - -static void -get_addr_by_name( - char * argtype, - char * namestr, - int port, - int socktype, - SOCKADDR_TYPE *addr, - SOCKLEN_TYPE *addrlen -#if defined(IPv6) && defined(AF_INET6) - , - struct addrinfo **aip, - struct addrinfo **aifirstp -#endif - ) -{ -#if defined(IPv6) && defined(AF_INET6) - struct addrinfo *ai; - struct addrinfo hints; - char portstr[6]; - char *pport = portstr; - int gaierr; - - bzero(&hints, sizeof(hints)); - hints.ai_socktype = socktype; - - if (port == 0) { - pport = NULL; - } else if (port > 0 && port < 65535) { - sprintf(portstr, "%d", port); - } else { - FatalError("Xserver: port out of range: %d\n", port); - } - - if (*aifirstp != NULL) { - freeaddrinfo(*aifirstp); - *aifirstp = NULL; - } - - if ((gaierr = getaddrinfo(namestr, pport, &hints, aifirstp)) == 0) { - for (ai = *aifirstp; ai != NULL; ai = ai->ai_next) { - if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) - break; - } - if ((ai == NULL) || (ai->ai_addrlen > sizeof(SOCKADDR_TYPE))) { - FatalError ("Xserver: %s host %s not on supported network type\n", - argtype, namestr); - } else { - *aip = ai; - *addrlen = ai->ai_addrlen; - memcpy(addr, ai->ai_addr, ai->ai_addrlen); - } - } else { - FatalError("Xserver: %s: %s %s\n", gai_strerror(gaierr), argtype, namestr); - } -#else - struct hostent *hep; -#ifdef XTHREADS_NEEDS_BYNAMEPARAMS - _Xgethostbynameparams hparams; -#endif -#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) - _XSERVTransWSAStartup(); -#endif - if (!(hep = _XGethostbyname(namestr, hparams))) - { - FatalError("Xserver: %s unknown host: %s\n", argtype, namestr); - } - if (hep->h_length == sizeof (struct in_addr)) - { - memmove(&addr->sin_addr, hep->h_addr, hep->h_length); - *addrlen = sizeof(struct sockaddr_in); - addr->sin_family = AF_INET; - addr->sin_port = htons (port); - } - else - { - FatalError("Xserver: %s host on strange network %s\n", argtype, namestr); - } -#endif -} - -static void -get_manager_by_name( - int argc, - char **argv, - int i) -{ - - if ((i + 1) == argc) - { - FatalError("Xserver: missing %s host name in command line\n", argv[i]); - } - - get_addr_by_name(argv[i], argv[i+1], xdm_udp_port, SOCK_DGRAM, - &ManagerAddress, &ManagerAddressLen -#if defined(IPv6) && defined(AF_INET6) - , &mgrAddr, &mgrAddrFirst -#endif - ); -} - - -static void -get_fromaddr_by_name( - int argc, - char **argv, - int i) -{ -#if defined(IPv6) && defined(AF_INET6) - struct addrinfo *ai = NULL; - struct addrinfo *aifirst = NULL; -#endif - if (i == argc) - { - FatalError("Xserver: missing -from host name in command line\n"); - } - get_addr_by_name("-from", argv[i], 0, 0, &FromAddress, &FromAddressLen -#if defined(IPv6) && defined(AF_INET6) - , &ai, &aifirst -#endif - ); - xdm_from = argv[i]; -} - - -#if defined(IPv6) && defined(AF_INET6) -static int -get_mcast_options(argc, argv, i) - int argc, i; - char **argv; -{ - char *address = XDM_DEFAULT_MCAST_ADDR6; - int hopcount = 1; - struct addrinfo hints; - char portstr[6]; - int gaierr; - struct addrinfo *ai, *firstai; - - if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { - address = argv[i++]; - if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { - hopcount = strtol(argv[i++], NULL, 10); - if ((hopcount < 1) || (hopcount > 255)) { - FatalError("Xserver: multicast hop count out of range: %d\n", - hopcount); - } - } - } - - if (xdm_udp_port > 0 && xdm_udp_port < 65535) { - sprintf(portstr, "%d", xdm_udp_port); - } else { - FatalError("Xserver: port out of range: %d\n", xdm_udp_port); - } - bzero(&hints, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; - - if ((gaierr = getaddrinfo(address, portstr, &hints, &firstai)) == 0) { - for (ai = firstai; ai != NULL; ai = ai->ai_next) { - if (((ai->ai_family == AF_INET) && - IN_MULTICAST(((struct sockaddr_in *) ai->ai_addr) - ->sin_addr.s_addr)) - || ((ai->ai_family == AF_INET6) && - IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *) ai->ai_addr) - ->sin6_addr))) - break; - } - if (ai == NULL) { - FatalError ("Xserver: address not supported multicast type %s\n", - address); - } else { - struct multicastinfo *mcastinfo, *mcl; - - mcastinfo = malloc(sizeof(struct multicastinfo)); - mcastinfo->next = NULL; - mcastinfo->ai = firstai; - mcastinfo->hops = hopcount; - - if (mcastlist == NULL) { - mcastlist = mcastinfo; - } else { - for (mcl = mcastlist; mcl->next != NULL; mcl = mcl->next) { - /* Do nothing - just find end of list */ - } - mcl->next = mcastinfo; - } - } - } else { - FatalError("Xserver: %s: %s\n", gai_strerror(gaierr), address); - } - return i; -} -#endif - -#else -static int xdmcp_non_empty; /* avoid complaint by ranlib */ -#endif /* XDMCP */ diff --git a/nx-X11/programs/Xserver/os/xdmcp.c.X.original b/nx-X11/programs/Xserver/os/xdmcp.c.X.original deleted file mode 100644 index 19a62a56b..000000000 --- a/nx-X11/programs/Xserver/os/xdmcp.c.X.original +++ /dev/null @@ -1,1681 +0,0 @@ -/* $XdotOrg: xc/programs/Xserver/os/xdmcp.c,v 1.10 2005/07/03 08:53:52 daniels Exp $ */ -/* $Xorg: xdmcp.c,v 1.4 2001/01/31 13:37:19 pookie Exp $ */ -/* - * Copyright 1989 Network Computing Devices, Inc., Mountain View, California. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of N.C.D. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. N.C.D. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - */ -/* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.31 2003/12/30 21:24:32 herrb Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef WIN32 -#include -#endif - -#include - -#if !defined(WIN32) -#ifndef Lynx -#include -#include -#else -#include -#endif -#include -#include -#endif - -#include -#include -#include -#include -#include "misc.h" -#include -#include "osdep.h" -#include "input.h" -#include "dixstruct.h" -#include "opaque.h" - -#if defined(DGUX) -#include -#include -#endif - -#ifdef STREAMSCONN -#include -#include -#include -#endif - -#ifdef XDMCP -#undef REQUEST - -#ifdef XDMCP_NO_IPV6 -#undef IPv6 -#endif - -#include - -#define X_INCLUDE_NETDB_H -#include - -extern char *defaultDisplayClass; - -static int xdmcpSocket, sessionSocket; -static xdmcp_states state; -#if defined(IPv6) && defined(AF_INET6) -static int xdmcpSocket6; -static struct sockaddr_storage req_sockaddr; -#else -static struct sockaddr_in req_sockaddr; -#endif -static int req_socklen; -static CARD32 SessionID; -static CARD32 timeOutTime; -static int timeOutRtx; -static CARD32 defaultKeepaliveDormancy = XDM_DEF_DORMANCY; -static CARD32 keepaliveDormancy = XDM_DEF_DORMANCY; -static CARD16 DisplayNumber; -static xdmcp_states XDM_INIT_STATE = XDM_OFF; -#ifdef HASXDMAUTH -static char *xdmAuthCookie; -#endif - -static XdmcpBuffer buffer; - -#if defined(IPv6) && defined(AF_INET6) - -static struct addrinfo *mgrAddr; -static struct addrinfo *mgrAddrFirst; - -#define SOCKADDR_TYPE struct sockaddr_storage -#define SOCKADDR_FAMILY(s) ((struct sockaddr *)&(s))->sa_family - -#ifdef BSD44SOCKETS -#define SOCKLEN_FIELD(s) ((struct sockaddr *)&(s))->sa_len -#define SOCKLEN_TYPE unsigned char -#else -#define SOCKLEN_TYPE unsigned int -#endif - -#else - -#define SOCKADDR_TYPE struct sockaddr_in -#define SOCKADDR_FAMILY(s) (s).sin_family - -#ifdef BSD44SOCKETS -#define SOCKLEN_FIELD(s) (s).sin_len -#define SOCKLEN_TYPE unsigned char -#else -#define SOCKLEN_TYPE size_t -#endif - -#endif - -static SOCKADDR_TYPE ManagerAddress; -static SOCKADDR_TYPE FromAddress; - -#ifdef SOCKLEN_FIELD -#define ManagerAddressLen SOCKLEN_FIELD(ManagerAddress) -#define FromAddressLen SOCKLEN_FIELD(FromAddress) -#else -static SOCKLEN_TYPE ManagerAddressLen, FromAddressLen; -#endif - -#if defined(IPv6) && defined(AF_INET6) -static struct multicastinfo { - struct multicastinfo *next; - struct addrinfo *ai; - int hops; -} *mcastlist; -#endif - -static void XdmcpAddHost( - struct sockaddr *from, - int fromlen, - ARRAY8Ptr AuthenticationName, - ARRAY8Ptr hostname, - ARRAY8Ptr status); - -static void XdmcpSelectHost( - struct sockaddr *host_sockaddr, - int host_len, - ARRAY8Ptr AuthenticationName); - -static void get_xdmcp_sock(void); - -static void send_query_msg(void); - -static void recv_willing_msg( - struct sockaddr * /*from*/, - int /*fromlen*/, - unsigned /*length*/); - -static void send_request_msg(void); - -static void recv_accept_msg(unsigned /*length*/); - -static void recv_decline_msg(unsigned /*length*/); - -static void send_manage_msg(void); - -static void recv_refuse_msg(unsigned /*length*/); - -static void recv_failed_msg(unsigned /*length*/); - -static void send_keepalive_msg(void); - -static void recv_alive_msg(unsigned /*length*/); - -static void XdmcpFatal( - char * /*type*/, - ARRAY8Ptr /*status*/); - -static void XdmcpWarning(char * /*str*/); - -static void get_manager_by_name( - int /*argc*/, - char ** /*argv*/, - int /*i*/); - -static void get_fromaddr_by_name(int /*argc*/, char ** /*argv*/, int /*i*/); - -#if defined(IPv6) && defined(AF_INET6) -static int get_mcast_options(int /*argc*/, char ** /*argv*/, int /*i*/); -#endif - -static void receive_packet(int /*socketfd*/); - -static void send_packet(void); - -extern void XdmcpDeadSession(char * /*reason*/); - -static void timeout(void); - -static void restart(void); - -static void XdmcpBlockHandler( - pointer /*data*/, - struct timeval ** /*wt*/, - pointer /*LastSelectMask*/); - -static void XdmcpWakeupHandler( - pointer /*data*/, - int /*i*/, - pointer /*LastSelectMask*/); - -void XdmcpRegisterManufacturerDisplayID( - char * /*name*/, - int /*length*/); - - -static unsigned short xdm_udp_port = XDM_UDP_PORT; -static Bool OneSession = FALSE; -static const char *xdm_from = NULL; - -void -XdmcpUseMsg (void) -{ - ErrorF("-query host-name contact named host for XDMCP\n"); - ErrorF("-broadcast broadcast for XDMCP\n"); -#if defined(IPv6) && defined(AF_INET6) - ErrorF("-multicast [addr [hops]] IPv6 multicast for XDMCP\n"); -#endif - ErrorF("-indirect host-name contact named host for indirect XDMCP\n"); - ErrorF("-port port-num UDP port number to send messages to\n"); - ErrorF("-from local-address specify the local address to connect from\n"); - ErrorF("-once Terminate server after one session\n"); - ErrorF("-class display-class specify display class to send in manage\n"); -#ifdef HASXDMAUTH - ErrorF("-cookie xdm-auth-bits specify the magic cookie for XDMCP\n"); -#endif - ErrorF("-displayID display-id manufacturer display ID for request\n"); -} - -int -XdmcpOptions(int argc, char **argv, int i) -{ - if (strcmp(argv[i], "-query") == 0) { - get_manager_by_name(argc, argv, i++); - XDM_INIT_STATE = XDM_QUERY; - AccessUsingXdmcp (); - return (i + 1); - } - if (strcmp(argv[i], "-broadcast") == 0) { - XDM_INIT_STATE = XDM_BROADCAST; - AccessUsingXdmcp (); - return (i + 1); - } -#if defined(IPv6) && defined(AF_INET6) - if (strcmp(argv[i], "-multicast") == 0) { - i = get_mcast_options(argc, argv, ++i); - XDM_INIT_STATE = XDM_MULTICAST; - AccessUsingXdmcp (); - return (i + 1); - } -#endif - if (strcmp(argv[i], "-indirect") == 0) { - get_manager_by_name(argc, argv, i++); - XDM_INIT_STATE = XDM_INDIRECT; - AccessUsingXdmcp (); - return (i + 1); - } - if (strcmp(argv[i], "-port") == 0) { - if (++i == argc) { - FatalError("Xserver: missing port number in command line\n"); - } - xdm_udp_port = (unsigned short) atoi(argv[i]); - return (i + 1); - } - if (strcmp(argv[i], "-from") == 0) { - get_fromaddr_by_name(argc, argv, ++i); - return (i + 1); - } - if (strcmp(argv[i], "-once") == 0) { - OneSession = TRUE; - return (i + 1); - } - if (strcmp(argv[i], "-class") == 0) { - if (++i == argc) { - FatalError("Xserver: missing class name in command line\n"); - } - defaultDisplayClass = argv[i]; - return (i + 1); - } -#ifdef HASXDMAUTH - if (strcmp(argv[i], "-cookie") == 0) { - if (++i == argc) { - FatalError("Xserver: missing cookie data in command line\n"); - } - xdmAuthCookie = argv[i]; - return (i + 1); - } -#endif - if (strcmp(argv[i], "-displayID") == 0) { - if (++i == argc) { - FatalError("Xserver: missing displayID in command line\n"); - } - XdmcpRegisterManufacturerDisplayID (argv[i], strlen (argv[i])); - return (i + 1); - } - return (i); -} - -/* - * This section is a collection of routines for - * registering server-specific data with the XDMCP - * state machine. - */ - - -/* - * Save all broadcast addresses away so BroadcastQuery - * packets get sent everywhere - */ - -#define MAX_BROADCAST 10 - -/* This stays sockaddr_in since IPv6 doesn't support broadcast */ -static struct sockaddr_in BroadcastAddresses[MAX_BROADCAST]; -static int NumBroadcastAddresses; - -void -XdmcpRegisterBroadcastAddress (struct sockaddr_in *addr) -{ - struct sockaddr_in *bcast; - if (NumBroadcastAddresses >= MAX_BROADCAST) - return; - bcast = &BroadcastAddresses[NumBroadcastAddresses++]; - bzero (bcast, sizeof (struct sockaddr_in)); -#ifdef BSD44SOCKETS - bcast->sin_len = addr->sin_len; -#endif - bcast->sin_family = addr->sin_family; - bcast->sin_port = htons (xdm_udp_port); - bcast->sin_addr = addr->sin_addr; -} - -/* - * Each authentication type is registered here; Validator - * will be called to check all access attempts using - * the specified authentication type - */ - -static ARRAYofARRAY8 AuthenticationNames, AuthenticationDatas; -typedef struct _AuthenticationFuncs { - ValidatorFunc Validator; - GeneratorFunc Generator; - AddAuthorFunc AddAuth; -} AuthenticationFuncsRec, *AuthenticationFuncsPtr; - -static AuthenticationFuncsPtr AuthenticationFuncsList; - -void -XdmcpRegisterAuthentication ( - char *name, - int namelen, - char *data, - int datalen, - ValidatorFunc Validator, - GeneratorFunc Generator, - AddAuthorFunc AddAuth) -{ - int i; - ARRAY8 AuthenticationName, AuthenticationData; - static AuthenticationFuncsPtr newFuncs; - - if (!XdmcpAllocARRAY8 (&AuthenticationName, namelen)) - return; - if (!XdmcpAllocARRAY8 (&AuthenticationData, datalen)) - { - XdmcpDisposeARRAY8 (&AuthenticationName); - return; - } - for (i = 0; i < namelen; i++) - AuthenticationName.data[i] = name[i]; - for (i = 0; i < datalen; i++) - AuthenticationData.data[i] = data[i]; - if (!(XdmcpReallocARRAYofARRAY8 (&AuthenticationNames, - AuthenticationNames.length + 1) && - XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas, - AuthenticationDatas.length + 1) && - (newFuncs = (AuthenticationFuncsPtr) xalloc ( - (AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec))))) - { - XdmcpDisposeARRAY8 (&AuthenticationName); - XdmcpDisposeARRAY8 (&AuthenticationData); - return; - } - for (i = 0; i < AuthenticationNames.length - 1; i++) - newFuncs[i] = AuthenticationFuncsList[i]; - newFuncs[AuthenticationNames.length-1].Validator = Validator; - newFuncs[AuthenticationNames.length-1].Generator = Generator; - newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth; - xfree (AuthenticationFuncsList); - AuthenticationFuncsList = newFuncs; - AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName; - AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData; -} - -/* - * Select the authentication type to be used; this is - * set by the manager of the host to be connected to. - */ - -ARRAY8 noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0}; -ARRAY8 noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0}; -ARRAY8Ptr AuthenticationName = &noAuthenticationName; -ARRAY8Ptr AuthenticationData = &noAuthenticationData; -AuthenticationFuncsPtr AuthenticationFuncs; - -void -XdmcpSetAuthentication (ARRAY8Ptr name) -{ - int i; - - for (i = 0; i < AuthenticationNames.length; i++) - if (XdmcpARRAY8Equal (&AuthenticationNames.data[i], name)) - { - AuthenticationName = &AuthenticationNames.data[i]; - AuthenticationData = &AuthenticationDatas.data[i]; - AuthenticationFuncs = &AuthenticationFuncsList[i]; - break; - } -} - -/* - * Register the host address for the display - */ - -static ARRAY16 ConnectionTypes; -static ARRAYofARRAY8 ConnectionAddresses; -static long xdmcpGeneration; - -void -XdmcpRegisterConnection ( - int type, - char *address, - int addrlen) -{ - int i; - CARD8 *newAddress; - - if (xdmcpGeneration != serverGeneration) - { - XdmcpDisposeARRAY16 (&ConnectionTypes); - XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses); - xdmcpGeneration = serverGeneration; - } - if (xdm_from != NULL) { /* Only register the requested address */ - const void *regAddr = address; - const void *fromAddr = NULL; - int regAddrlen = addrlen; - - if (addrlen == sizeof(struct in_addr)) { - if (SOCKADDR_FAMILY(FromAddress) == AF_INET) { - fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; - } -#if defined(IPv6) && defined(AF_INET6) - else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET6) && - IN6_IS_ADDR_V4MAPPED( - &((struct sockaddr_in6 *)&FromAddress)->sin6_addr)) { - fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr.s6_addr[12]; - } -#endif - } -#if defined(IPv6) && defined(AF_INET6) - else if (addrlen == sizeof(struct in6_addr)) { - if (SOCKADDR_FAMILY(FromAddress) == AF_INET6) { - fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr; - } else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET) && - IN6_IS_ADDR_V4MAPPED((struct in6_addr *) address)) { - fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; - regAddr = &((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr[12]; - regAddrlen = sizeof(struct in_addr); - } - } -#endif - if (fromAddr && memcmp(regAddr, fromAddr, regAddrlen) != 0) { - return; - } - } - newAddress = (CARD8 *) xalloc (addrlen * sizeof (CARD8)); - if (!newAddress) - return; - if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1)) - { - xfree (newAddress); - return; - } - if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses, - ConnectionAddresses.length + 1)) - { - xfree (newAddress); - return; - } - ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type; - for (i = 0; i < addrlen; i++) - newAddress[i] = address[i]; - ConnectionAddresses.data[ConnectionAddresses.length-1].data = newAddress; - ConnectionAddresses.data[ConnectionAddresses.length-1].length = addrlen; -} - -/* - * Register an Authorization Name. XDMCP advertises this list - * to the manager. - */ - -static ARRAYofARRAY8 AuthorizationNames; - -void -XdmcpRegisterAuthorizations (void) -{ - XdmcpDisposeARRAYofARRAY8 (&AuthorizationNames); - RegisterAuthorizations (); -} - -void -XdmcpRegisterAuthorization (char *name, int namelen) -{ - ARRAY8 authName; - int i; - - authName.data = (CARD8 *) xalloc (namelen * sizeof (CARD8)); - if (!authName.data) - return; - if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1)) - { - xfree (authName.data); - return; - } - for (i = 0; i < namelen; i++) - authName.data[i] = (CARD8) name[i]; - authName.length = namelen; - AuthorizationNames.data[AuthorizationNames.length-1] = authName; -} - -/* - * Register the DisplayClass string - */ - -ARRAY8 DisplayClass; - -void -XdmcpRegisterDisplayClass (char *name, int length) -{ - int i; - - XdmcpDisposeARRAY8 (&DisplayClass); - if (!XdmcpAllocARRAY8 (&DisplayClass, length)) - return; - for (i = 0; i < length; i++) - DisplayClass.data[i] = (CARD8) name[i]; -} - -/* - * Register the Manufacturer display ID - */ - -ARRAY8 ManufacturerDisplayID; - -void -XdmcpRegisterManufacturerDisplayID (char *name, int length) -{ - int i; - - XdmcpDisposeARRAY8 (&ManufacturerDisplayID); - if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length)) - return; - for (i = 0; i < length; i++) - ManufacturerDisplayID.data[i] = (CARD8) name[i]; -} - -/* - * initialize XDMCP; create the socket, compute the display - * number, set up the state machine - */ - -void -XdmcpInit(void) -{ - state = XDM_INIT_STATE; -#ifdef HASXDMAUTH - if (xdmAuthCookie) - XdmAuthenticationInit (xdmAuthCookie, strlen (xdmAuthCookie)); -#endif - if (state != XDM_OFF) - { - XdmcpRegisterAuthorizations(); - XdmcpRegisterDisplayClass (defaultDisplayClass, strlen (defaultDisplayClass)); - AccessUsingXdmcp(); - RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler, - (pointer) 0); - timeOutRtx = 0; - DisplayNumber = (CARD16) atoi(display); - get_xdmcp_sock(); - send_packet(); - } -} - -void -XdmcpReset (void) -{ - state = XDM_INIT_STATE; - if (state != XDM_OFF) - { - RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler, - (pointer) 0); - timeOutRtx = 0; - send_packet(); - } -} - -/* - * Called whenever a new connection is created; notices the - * first connection and saves it to terminate the session - * when it is closed - */ - -void -XdmcpOpenDisplay(int sock) -{ - if (state != XDM_AWAIT_MANAGE_RESPONSE) - return; - state = XDM_RUN_SESSION; - sessionSocket = sock; -} - -void -XdmcpCloseDisplay(int sock) -{ - if ((state != XDM_RUN_SESSION && state != XDM_AWAIT_ALIVE_RESPONSE) - || sessionSocket != sock) - return; - state = XDM_INIT_STATE; - if (OneSession) - dispatchException |= DE_TERMINATE; - else - dispatchException |= DE_RESET; - isItTimeToYield = TRUE; -} - -/* - * called before going to sleep, this routine - * may modify the timeout value about to be sent - * to select; in this way XDMCP can do appropriate things - * dynamically while starting up - */ - -/*ARGSUSED*/ -static void -XdmcpBlockHandler( - pointer data, /* unused */ - struct timeval **wt, - pointer pReadmask) -{ - fd_set *LastSelectMask = (fd_set*)pReadmask; - CARD32 millisToGo; - - if (state == XDM_OFF) - return; - FD_SET(xdmcpSocket, LastSelectMask); -#if defined(IPv6) && defined(AF_INET6) - if (xdmcpSocket6 >= 0) - FD_SET(xdmcpSocket6, LastSelectMask); -#endif - if (timeOutTime == 0) - return; - millisToGo = timeOutTime - GetTimeInMillis(); - if ((int) millisToGo < 0) - millisToGo = 0; - AdjustWaitForDelay (wt, millisToGo); -} - -/* - * called after select returns; this routine will - * recognise when XDMCP packets await and - * process them appropriately - */ - -/*ARGSUSED*/ -static void -XdmcpWakeupHandler( - pointer data, /* unused */ - int i, - pointer pReadmask) -{ - fd_set* LastSelectMask = (fd_set*)pReadmask; - fd_set devicesReadable; - - if (state == XDM_OFF) - return; - if (i > 0) - { - if (FD_ISSET(xdmcpSocket, LastSelectMask)) - { - receive_packet(xdmcpSocket); - FD_CLR(xdmcpSocket, LastSelectMask); - } -#if defined(IPv6) && defined(AF_INET6) - if (xdmcpSocket6 >= 0 && FD_ISSET(xdmcpSocket6, LastSelectMask)) - { - receive_packet(xdmcpSocket6); - FD_CLR(xdmcpSocket6, LastSelectMask); - } -#endif - XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices); - if (XFD_ANYSET(&devicesReadable)) - { - if (state == XDM_AWAIT_USER_INPUT) - restart(); - else if (state == XDM_RUN_SESSION) - keepaliveDormancy = defaultKeepaliveDormancy; - } - if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION) - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; - } - else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) - { - if (state == XDM_RUN_SESSION) - { - state = XDM_KEEPALIVE; - send_packet(); - } - else - timeout(); - } -} - -/* - * This routine should be called from the routine that drives the - * user's host menu when the user selects a host - */ - -static void -XdmcpSelectHost( - struct sockaddr *host_sockaddr, - int host_len, - ARRAY8Ptr AuthenticationName) -{ - state = XDM_START_CONNECTION; - memmove(&req_sockaddr, host_sockaddr, host_len); - req_socklen = host_len; - XdmcpSetAuthentication (AuthenticationName); - send_packet(); -} - -/* - * !!! this routine should be replaced by a routine that adds - * the host to the user's host menu. the current version just - * selects the first host to respond with willing message. - */ - -/*ARGSUSED*/ -static void -XdmcpAddHost( - struct sockaddr *from, - int fromlen, - ARRAY8Ptr AuthenticationName, - ARRAY8Ptr hostname, - ARRAY8Ptr status) -{ - XdmcpSelectHost(from, fromlen, AuthenticationName); -} - -/* - * A message is queued on the socket; read it and - * do the appropriate thing - */ - -ARRAY8 UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" }; - -static void -receive_packet(int socketfd) -{ -#if defined(IPv6) && defined(AF_INET6) - struct sockaddr_storage from; -#else - struct sockaddr_in from; -#endif - int fromlen = sizeof(from); - XdmcpHeader header; - - /* read message off socket */ - if (!XdmcpFill (socketfd, &buffer, (XdmcpNetaddr) &from, &fromlen)) - return; - - /* reset retransmission backoff */ - timeOutRtx = 0; - - if (!XdmcpReadHeader (&buffer, &header)) - return; - - if (header.version != XDM_PROTOCOL_VERSION) - return; - - switch (header.opcode) { - case WILLING: - recv_willing_msg((struct sockaddr *) &from, fromlen, header.length); - break; - case UNWILLING: - XdmcpFatal("Manager unwilling", &UnwillingMessage); - break; - case ACCEPT: - recv_accept_msg(header.length); - break; - case DECLINE: - recv_decline_msg(header.length); - break; - case REFUSE: - recv_refuse_msg(header.length); - break; - case FAILED: - recv_failed_msg(header.length); - break; - case ALIVE: - recv_alive_msg(header.length); - break; - } -} - -/* - * send the appropriate message given the current state - */ - -static void -send_packet(void) -{ - int rtx; - switch (state) { - case XDM_QUERY: - case XDM_BROADCAST: - case XDM_INDIRECT: -#if defined(IPv6) && defined(AF_INET6) - case XDM_MULTICAST: -#endif - send_query_msg(); - break; - case XDM_START_CONNECTION: - send_request_msg(); - break; - case XDM_MANAGE: - send_manage_msg(); - break; - case XDM_KEEPALIVE: - send_keepalive_msg(); - break; - default: - break; - } - rtx = (XDM_MIN_RTX << timeOutRtx); - if (rtx > XDM_MAX_RTX) - rtx = XDM_MAX_RTX; - timeOutTime = GetTimeInMillis() + rtx * 1000; -} - -/* - * The session is declared dead for some reason; too many - * timeouts, or Keepalive failure. - */ - -void -XdmcpDeadSession (char *reason) -{ - ErrorF ("XDM: %s, declaring session dead\n", reason); - state = XDM_INIT_STATE; - isItTimeToYield = TRUE; - dispatchException |= DE_RESET; - timeOutTime = 0; - timeOutRtx = 0; - send_packet(); -} - -/* - * Timeout waiting for an XDMCP response. - */ - -static void -timeout(void) -{ - timeOutRtx++; - if (state == XDM_AWAIT_ALIVE_RESPONSE && timeOutRtx >= XDM_KA_RTX_LIMIT ) - { - XdmcpDeadSession ("too many keepalive retransmissions"); - return; - } - else if (timeOutRtx >= XDM_RTX_LIMIT) - { - /* Quit if "-once" specified, otherwise reset and try again. */ - if (OneSession) { - dispatchException |= DE_TERMINATE; - ErrorF("XDM: too many retransmissions\n"); - } else { - XdmcpDeadSession("too many retransmissions"); - } - return; - } - -#if defined(IPv6) && defined(AF_INET6) - if (state == XDM_COLLECT_QUERY || state == XDM_COLLECT_INDIRECT_QUERY) { - /* Try next address */ - for (mgrAddr = mgrAddr->ai_next; ; mgrAddr = mgrAddr->ai_next) { - if (mgrAddr == NULL) { - mgrAddr = mgrAddrFirst; - } - if (mgrAddr->ai_family == AF_INET - || mgrAddr->ai_family == AF_INET6) - break; - } -#ifndef SIN6_LEN - ManagerAddressLen = mgrAddr->ai_addrlen; -#endif - memcpy(&ManagerAddress, mgrAddr->ai_addr, mgrAddr->ai_addrlen); - } -#endif - - switch (state) { - case XDM_COLLECT_QUERY: - state = XDM_QUERY; - break; - case XDM_COLLECT_BROADCAST_QUERY: - state = XDM_BROADCAST; - break; -#if defined(IPv6) && defined(AF_INET6) - case XDM_COLLECT_MULTICAST_QUERY: - state = XDM_MULTICAST; - break; -#endif - case XDM_COLLECT_INDIRECT_QUERY: - state = XDM_INDIRECT; - break; - case XDM_AWAIT_REQUEST_RESPONSE: - state = XDM_START_CONNECTION; - break; - case XDM_AWAIT_MANAGE_RESPONSE: - state = XDM_MANAGE; - break; - case XDM_AWAIT_ALIVE_RESPONSE: - state = XDM_KEEPALIVE; - break; - default: - break; - } - send_packet(); -} - -static void -restart(void) -{ - state = XDM_INIT_STATE; - timeOutRtx = 0; - send_packet(); -} - -int -XdmcpCheckAuthentication ( - ARRAY8Ptr Name, - ARRAY8Ptr Data, - int packet_type) -{ - return (XdmcpARRAY8Equal (Name, AuthenticationName) && - (AuthenticationName->length == 0 || - (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type))); -} - -int -XdmcpAddAuthorization ( - ARRAY8Ptr name, - ARRAY8Ptr data) -{ - AddAuthorFunc AddAuth; - - if (AuthenticationFuncs && AuthenticationFuncs->AddAuth) - AddAuth = AuthenticationFuncs->AddAuth; - else - AddAuth = AddAuthorization; - return (*AddAuth) ((unsigned short)name->length, - (char *)name->data, - (unsigned short)data->length, - (char *)data->data); -} - -/* - * from here to the end of this file are routines private - * to the state machine. - */ - -static void -get_xdmcp_sock(void) -{ -#ifdef STREAMSCONN - struct netconfig *nconf; - - if ((xdmcpSocket = t_open("/dev/udp", O_RDWR, 0)) < 0) { - XdmcpWarning("t_open() of /dev/udp failed"); - return; - } - - if( t_bind(xdmcpSocket,NULL,NULL) < 0 ) { - XdmcpWarning("UDP socket creation failed"); - t_error("t_bind(xdmcpSocket) failed" ); - t_close(xdmcpSocket); - return; - } - - /* - * This part of the code looks contrived. It will actually fit in nicely - * when the CLTS part of Xtrans is implemented. - */ - - if( (nconf=getnetconfigent("udp")) == NULL ) { - XdmcpWarning("UDP socket creation failed: getnetconfigent()"); - t_unbind(xdmcpSocket); - t_close(xdmcpSocket); - return; - } - - if( netdir_options(nconf, ND_SET_BROADCAST, xdmcpSocket, NULL) ) { - XdmcpWarning("UDP set broadcast option failed: netdir_options()"); - freenetconfigent(nconf); - t_unbind(xdmcpSocket); - t_close(xdmcpSocket); - return; - } - - freenetconfigent(nconf); -#else - int soopts = 1; - -#if defined(IPv6) && defined(AF_INET6) - if ((xdmcpSocket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) - XdmcpWarning("INET6 UDP socket creation failed"); -#endif - if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - XdmcpWarning("UDP socket creation failed"); -#ifdef SO_BROADCAST - else if (setsockopt(xdmcpSocket, SOL_SOCKET, SO_BROADCAST, (char *)&soopts, - sizeof(soopts)) < 0) - XdmcpWarning("UDP set broadcast socket-option failed"); -#endif /* SO_BROADCAST */ - if (xdmcpSocket >= 0 && xdm_from != NULL) { - if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress, - FromAddressLen) < 0) { - FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from); - } - } -#endif /* STREAMSCONN */ -} - -static void -send_query_msg(void) -{ - XdmcpHeader header; - Bool broadcast = FALSE; -#if defined(IPv6) && defined(AF_INET6) - Bool multicast = FALSE; -#endif - int i; - int socketfd = xdmcpSocket; - - header.version = XDM_PROTOCOL_VERSION; - switch(state){ - case XDM_QUERY: - header.opcode = (CARD16) QUERY; - state = XDM_COLLECT_QUERY; - break; - case XDM_BROADCAST: - header.opcode = (CARD16) BROADCAST_QUERY; - state = XDM_COLLECT_BROADCAST_QUERY; - broadcast = TRUE; - break; -#if defined(IPv6) && defined(AF_INET6) - case XDM_MULTICAST: - header.opcode = (CARD16) BROADCAST_QUERY; - state = XDM_COLLECT_MULTICAST_QUERY; - multicast = TRUE; - break; -#endif - case XDM_INDIRECT: - header.opcode = (CARD16) INDIRECT_QUERY; - state = XDM_COLLECT_INDIRECT_QUERY; - break; - default: - break; - } - header.length = 1; - for (i = 0; i < AuthenticationNames.length; i++) - header.length += 2 + AuthenticationNames.data[i].length; - - XdmcpWriteHeader (&buffer, &header); - XdmcpWriteARRAYofARRAY8 (&buffer, &AuthenticationNames); - if (broadcast) - { - int i; - - for (i = 0; i < NumBroadcastAddresses; i++) - XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &BroadcastAddresses[i], - sizeof (struct sockaddr_in)); - } -#if defined(IPv6) && defined(AF_INET6) - else if (multicast) - { - struct multicastinfo *mcl; - struct addrinfo *ai; - - for (mcl = mcastlist; mcl != NULL; mcl = mcl->next) { - for (ai = mcl->ai ; ai != NULL; ai = ai->ai_next) { - if (ai->ai_family == AF_INET) { - unsigned char hopflag = (unsigned char) mcl->hops; - socketfd = xdmcpSocket; - setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL, - &hopflag, sizeof(hopflag)); - } else if (ai->ai_family == AF_INET6) { - int hopflag6 = mcl->hops; - socketfd = xdmcpSocket6; - setsockopt(socketfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, - &hopflag6, sizeof(hopflag6)); - } else { - continue; - } - XdmcpFlush (socketfd, &buffer, - (XdmcpNetaddr) ai->ai_addr, ai->ai_addrlen); - break; - } - } - } -#endif - else - { -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress, - ManagerAddressLen); - } -} - -static void -recv_willing_msg( - struct sockaddr *from, - int fromlen, - unsigned length) -{ - ARRAY8 authenticationName; - ARRAY8 hostname; - ARRAY8 status; - - authenticationName.data = 0; - hostname.data = 0; - status.data = 0; - if (XdmcpReadARRAY8 (&buffer, &authenticationName) && - XdmcpReadARRAY8 (&buffer, &hostname) && - XdmcpReadARRAY8 (&buffer, &status)) - { - if (length == 6 + authenticationName.length + - hostname.length + status.length) - { - switch (state) - { - case XDM_COLLECT_QUERY: - XdmcpSelectHost(from, fromlen, &authenticationName); - break; - case XDM_COLLECT_BROADCAST_QUERY: -#if defined(IPv6) && defined(AF_INET6) - case XDM_COLLECT_MULTICAST_QUERY: -#endif - case XDM_COLLECT_INDIRECT_QUERY: - XdmcpAddHost(from, fromlen, &authenticationName, &hostname, &status); - break; - default: - break; - } - } - } - XdmcpDisposeARRAY8 (&authenticationName); - XdmcpDisposeARRAY8 (&hostname); - XdmcpDisposeARRAY8 (&status); -} - -static void -send_request_msg(void) -{ - XdmcpHeader header; - int length; - int i; - CARD16 XdmcpConnectionType; - ARRAY8 authenticationData; - int socketfd = xdmcpSocket; - - switch (SOCKADDR_FAMILY(ManagerAddress)) - { - case AF_INET: XdmcpConnectionType=FamilyInternet; break; -#if defined(IPv6) && defined(AF_INET6) - case AF_INET6: XdmcpConnectionType=FamilyInternet6; break; -#endif - default: XdmcpConnectionType=0xffff; break; - } - - header.version = XDM_PROTOCOL_VERSION; - header.opcode = (CARD16) REQUEST; - - length = 2; /* display number */ - length += 1 + 2 * ConnectionTypes.length; /* connection types */ - length += 1; /* connection addresses */ - for (i = 0; i < ConnectionAddresses.length; i++) - length += 2 + ConnectionAddresses.data[i].length; - authenticationData.length = 0; - authenticationData.data = 0; - if (AuthenticationFuncs) - { - (*AuthenticationFuncs->Generator) (AuthenticationData, - &authenticationData, - REQUEST); - } - length += 2 + AuthenticationName->length; /* authentication name */ - length += 2 + authenticationData.length; /* authentication data */ - length += 1; /* authorization names */ - for (i = 0; i < AuthorizationNames.length; i++) - length += 2 + AuthorizationNames.data[i].length; - length += 2 + ManufacturerDisplayID.length; /* display ID */ - header.length = length; - - if (!XdmcpWriteHeader (&buffer, &header)) - { - XdmcpDisposeARRAY8 (&authenticationData); - return; - } - XdmcpWriteCARD16 (&buffer, DisplayNumber); - XdmcpWriteCARD8 (&buffer, ConnectionTypes.length); - - /* The connection array is send reordered, so that connections of */ - /* the same address type as the XDMCP manager connection are send */ - /* first. This works around a bug in xdm. mario@klebsch.de */ - for (i = 0; i < (int)ConnectionTypes.length; i++) - if (ConnectionTypes.data[i]==XdmcpConnectionType) - XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]); - for (i = 0; i < (int)ConnectionTypes.length; i++) - if (ConnectionTypes.data[i]!=XdmcpConnectionType) - XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]); - - XdmcpWriteCARD8 (&buffer, ConnectionAddresses.length); - for (i = 0; i < (int)ConnectionAddresses.length; i++) - if ( (i=ConnectionTypes.length) || - (ConnectionTypes.data[i]!=XdmcpConnectionType) ) - XdmcpWriteARRAY8 (&buffer, &ConnectionAddresses.data[i]); - - XdmcpWriteARRAY8 (&buffer, AuthenticationName); - XdmcpWriteARRAY8 (&buffer, &authenticationData); - XdmcpDisposeARRAY8 (&authenticationData); - XdmcpWriteARRAYofARRAY8 (&buffer, &AuthorizationNames); - XdmcpWriteARRAY8 (&buffer, &ManufacturerDisplayID); -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - if (XdmcpFlush (socketfd, &buffer, - (XdmcpNetaddr) &req_sockaddr, req_socklen)) - state = XDM_AWAIT_REQUEST_RESPONSE; -} - -static void -recv_accept_msg(unsigned length) -{ - CARD32 AcceptSessionID; - ARRAY8 AcceptAuthenticationName, AcceptAuthenticationData; - ARRAY8 AcceptAuthorizationName, AcceptAuthorizationData; - - if (state != XDM_AWAIT_REQUEST_RESPONSE) - return; - AcceptAuthenticationName.data = 0; - AcceptAuthenticationData.data = 0; - AcceptAuthorizationName.data = 0; - AcceptAuthorizationData.data = 0; - if (XdmcpReadCARD32 (&buffer, &AcceptSessionID) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationName) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationData) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationName) && - XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationData)) - { - if (length == 12 + AcceptAuthenticationName.length + - AcceptAuthenticationData.length + - AcceptAuthorizationName.length + - AcceptAuthorizationData.length) - { - if (!XdmcpCheckAuthentication (&AcceptAuthenticationName, - &AcceptAuthenticationData, ACCEPT)) - { - XdmcpFatal ("Authentication Failure", &AcceptAuthenticationName); - } - /* permit access control manipulations from this host */ - AugmentSelf (&req_sockaddr, req_socklen); - /* if the authorization specified in the packet fails - * to be acceptable, enable the local addresses - */ - if (!XdmcpAddAuthorization (&AcceptAuthorizationName, - &AcceptAuthorizationData)) - { - AddLocalHosts (); - } - SessionID = AcceptSessionID; - state = XDM_MANAGE; - send_packet(); - } - } - XdmcpDisposeARRAY8 (&AcceptAuthenticationName); - XdmcpDisposeARRAY8 (&AcceptAuthenticationData); - XdmcpDisposeARRAY8 (&AcceptAuthorizationName); - XdmcpDisposeARRAY8 (&AcceptAuthorizationData); -} - -static void -recv_decline_msg(unsigned length) -{ - ARRAY8 status, DeclineAuthenticationName, DeclineAuthenticationData; - - status.data = 0; - DeclineAuthenticationName.data = 0; - DeclineAuthenticationData.data = 0; - if (XdmcpReadARRAY8 (&buffer, &status) && - XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationName) && - XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationData)) - { - if (length == 6 + status.length + - DeclineAuthenticationName.length + - DeclineAuthenticationData.length && - XdmcpCheckAuthentication (&DeclineAuthenticationName, - &DeclineAuthenticationData, DECLINE)) - { - XdmcpFatal ("Session declined", &status); - } - } - XdmcpDisposeARRAY8 (&status); - XdmcpDisposeARRAY8 (&DeclineAuthenticationName); - XdmcpDisposeARRAY8 (&DeclineAuthenticationData); -} - -static void -send_manage_msg(void) -{ - XdmcpHeader header; - int socketfd = xdmcpSocket; - - header.version = XDM_PROTOCOL_VERSION; - header.opcode = (CARD16) MANAGE; - header.length = 8 + DisplayClass.length; - - if (!XdmcpWriteHeader (&buffer, &header)) - return; - XdmcpWriteCARD32 (&buffer, SessionID); - XdmcpWriteCARD16 (&buffer, DisplayNumber); - XdmcpWriteARRAY8 (&buffer, &DisplayClass); - state = XDM_AWAIT_MANAGE_RESPONSE; -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); -} - -static void -recv_refuse_msg(unsigned length) -{ - CARD32 RefusedSessionID; - - if (state != XDM_AWAIT_MANAGE_RESPONSE) - return; - if (length != 4) - return; - if (XdmcpReadCARD32 (&buffer, &RefusedSessionID)) - { - if (RefusedSessionID == SessionID) - { - state = XDM_START_CONNECTION; - send_packet(); - } - } -} - -static void -recv_failed_msg(unsigned length) -{ - CARD32 FailedSessionID; - ARRAY8 status; - - if (state != XDM_AWAIT_MANAGE_RESPONSE) - return; - status.data = 0; - if (XdmcpReadCARD32 (&buffer, &FailedSessionID) && - XdmcpReadARRAY8 (&buffer, &status)) - { - if (length == 6 + status.length && - SessionID == FailedSessionID) - { - XdmcpFatal ("Session failed", &status); - } - } - XdmcpDisposeARRAY8 (&status); -} - -static void -send_keepalive_msg(void) -{ - XdmcpHeader header; - int socketfd = xdmcpSocket; - - header.version = XDM_PROTOCOL_VERSION; - header.opcode = (CARD16) KEEPALIVE; - header.length = 6; - - XdmcpWriteHeader (&buffer, &header); - XdmcpWriteCARD16 (&buffer, DisplayNumber); - XdmcpWriteCARD32 (&buffer, SessionID); - - state = XDM_AWAIT_ALIVE_RESPONSE; -#if defined(IPv6) && defined(AF_INET6) - if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) - socketfd = xdmcpSocket6; -#endif - XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); -} - -static void -recv_alive_msg (unsigned length) -{ - CARD8 SessionRunning; - CARD32 AliveSessionID; - - if (state != XDM_AWAIT_ALIVE_RESPONSE) - return; - if (length != 5) - return; - if (XdmcpReadCARD8 (&buffer, &SessionRunning) && - XdmcpReadCARD32 (&buffer, &AliveSessionID)) - { - if (SessionRunning && AliveSessionID == SessionID) - { - /* backoff dormancy period */ - state = XDM_RUN_SESSION; - if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) > - keepaliveDormancy * 1000) - { - keepaliveDormancy <<= 1; - if (keepaliveDormancy > XDM_MAX_DORMANCY) - keepaliveDormancy = XDM_MAX_DORMANCY; - } - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; - } - else - { - XdmcpDeadSession ("Alive response indicates session dead"); - } - } -} - -static void -XdmcpFatal ( - char *type, - ARRAY8Ptr status) -{ - FatalError ("XDMCP fatal error: %s %*.*s\n", type, - status->length, status->length, status->data); -} - -static void -XdmcpWarning(char *str) -{ - ErrorF("XDMCP warning: %s\n", str); -} - -static void -get_addr_by_name( - char * argtype, - char * namestr, - int port, - int socktype, - SOCKADDR_TYPE *addr, - SOCKLEN_TYPE *addrlen -#if defined(IPv6) && defined(AF_INET6) - , - struct addrinfo **aip, - struct addrinfo **aifirstp -#endif - ) -{ -#if defined(IPv6) && defined(AF_INET6) - struct addrinfo *ai; - struct addrinfo hints; - char portstr[6]; - char *pport = portstr; - int gaierr; - - bzero(&hints, sizeof(hints)); - hints.ai_socktype = socktype; - - if (port == 0) { - pport = NULL; - } else if (port > 0 && port < 65535) { - sprintf(portstr, "%d", port); - } else { - FatalError("Xserver: port out of range: %d\n", port); - } - - if (*aifirstp != NULL) { - freeaddrinfo(*aifirstp); - *aifirstp = NULL; - } - - if ((gaierr = getaddrinfo(namestr, pport, &hints, aifirstp)) == 0) { - for (ai = *aifirstp; ai != NULL; ai = ai->ai_next) { - if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) - break; - } - if ((ai == NULL) || (ai->ai_addrlen > sizeof(SOCKADDR_TYPE))) { - FatalError ("Xserver: %s host %s not on supported network type\n", - argtype, namestr); - } else { - *aip = ai; - *addrlen = ai->ai_addrlen; - memcpy(addr, ai->ai_addr, ai->ai_addrlen); - } - } else { - FatalError("Xserver: %s: %s %s\n", gai_strerror(gaierr), argtype, namestr); - } -#else - struct hostent *hep; -#ifdef XTHREADS_NEEDS_BYNAMEPARAMS - _Xgethostbynameparams hparams; -#endif -#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) - _XSERVTransWSAStartup(); -#endif - if (!(hep = _XGethostbyname(namestr, hparams))) - { - FatalError("Xserver: %s unknown host: %s\n", argtype, namestr); - } - if (hep->h_length == sizeof (struct in_addr)) - { - memmove(&addr->sin_addr, hep->h_addr, hep->h_length); - *addrlen = sizeof(struct sockaddr_in); - addr->sin_family = AF_INET; - addr->sin_port = htons (port); - } - else - { - FatalError("Xserver: %s host on strange network %s\n", argtype, namestr); - } -#endif -} - -static void -get_manager_by_name( - int argc, - char **argv, - int i) -{ - - if ((i + 1) == argc) - { - FatalError("Xserver: missing %s host name in command line\n", argv[i]); - } - - get_addr_by_name(argv[i], argv[i+1], xdm_udp_port, SOCK_DGRAM, - &ManagerAddress, &ManagerAddressLen -#if defined(IPv6) && defined(AF_INET6) - , &mgrAddr, &mgrAddrFirst -#endif - ); -} - - -static void -get_fromaddr_by_name( - int argc, - char **argv, - int i) -{ -#if defined(IPv6) && defined(AF_INET6) - struct addrinfo *ai = NULL; - struct addrinfo *aifirst = NULL; -#endif - if (i == argc) - { - FatalError("Xserver: missing -from host name in command line\n"); - } - get_addr_by_name("-from", argv[i], 0, 0, &FromAddress, &FromAddressLen -#if defined(IPv6) && defined(AF_INET6) - , &ai, &aifirst -#endif - ); - xdm_from = argv[i]; -} - - -#if defined(IPv6) && defined(AF_INET6) -static int -get_mcast_options(argc, argv, i) - int argc, i; - char **argv; -{ - char *address = XDM_DEFAULT_MCAST_ADDR6; - int hopcount = 1; - struct addrinfo hints; - char portstr[6]; - int gaierr; - struct addrinfo *ai, *firstai; - - if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { - address = argv[i++]; - if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { - hopcount = strtol(argv[i++], NULL, 10); - if ((hopcount < 1) || (hopcount > 255)) { - FatalError("Xserver: multicast hop count out of range: %d\n", - hopcount); - } - } - } - - if (xdm_udp_port > 0 && xdm_udp_port < 65535) { - sprintf(portstr, "%d", xdm_udp_port); - } else { - FatalError("Xserver: port out of range: %d\n", xdm_udp_port); - } - bzero(&hints, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; - - if ((gaierr = getaddrinfo(address, portstr, &hints, &firstai)) == 0) { - for (ai = firstai; ai != NULL; ai = ai->ai_next) { - if (((ai->ai_family == AF_INET) && - IN_MULTICAST(((struct sockaddr_in *) ai->ai_addr) - ->sin_addr.s_addr)) - || ((ai->ai_family == AF_INET6) && - IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *) ai->ai_addr) - ->sin6_addr))) - break; - } - if (ai == NULL) { - FatalError ("Xserver: address not supported multicast type %s\n", - address); - } else { - struct multicastinfo *mcastinfo, *mcl; - - mcastinfo = malloc(sizeof(struct multicastinfo)); - mcastinfo->next = NULL; - mcastinfo->ai = firstai; - mcastinfo->hops = hopcount; - - if (mcastlist == NULL) { - mcastlist = mcastinfo; - } else { - for (mcl = mcastlist; mcl->next != NULL; mcl = mcl->next) { - /* Do nothing - just find end of list */ - } - mcl->next = mcastinfo; - } - } - } else { - FatalError("Xserver: %s: %s\n", gai_strerror(gaierr), address); - } - return i; -} -#endif - -#else -static int xdmcp_non_empty; /* avoid complaint by ranlib */ -#endif /* XDMCP */ diff --git a/nx-X11/programs/Xserver/os/xprintf.c.NX.original b/nx-X11/programs/Xserver/os/xprintf.c.NX.original deleted file mode 100644 index 54bbeefe2..000000000 --- a/nx-X11/programs/Xserver/os/xprintf.c.NX.original +++ /dev/null @@ -1,163 +0,0 @@ -/* - * printf routines which xalloc their buffer - */ -/* - * Copyright (c) 2004 Alexander Gottwald - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name(s) of the above copyright - * holders shall not be used in advertising or otherwise to promote the sale, - * use or other dealings in this Software without prior written authorization. - */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include -#include - -#ifndef va_copy -# ifdef __va_copy -# define va_copy __va_copy -# else -# error "no working va_copy was found" -# endif -#endif - -#ifdef NX_TRANS_SOCKET - -#define PANIC -#define WARNING -#undef TEST -#undef DEBUG - -#define START_SIZE 256 -#define END_SIZE 2048 - -char * -Xvprintf(const char *format, va_list va) -{ - char *ret; - char *newret; - int size; - int r; - - size = 0; - - for (;;) - { - if (size == 0) - { - ret = (char *)malloc(START_SIZE); - if (ret == NULL) - return NULL; - size = START_SIZE; - } - else if (size < END_SIZE && - (newret = (char *) realloc(ret, 2 * size)) != NULL) - { - ret = newret; - size = 2 * size; - } - else - { - free(ret); - return NULL; - } - - r = vsnprintf(ret, size, format, va); - - if (r == -1 || r == size || r > size || r == size - 1) - { - continue; - } - else - { - ret[r] = 0; - return ret; - } - } -} - -#else - -char * -Xvprintf(const char *format, va_list va) -{ - char *ret; - int size; - va_list va2; - - va_copy(va2, va); - size = vsnprintf(NULL, 0, format, va2); - va_end(va2); - - ret = (char *)Xalloc(size + 1); - if (ret == NULL) - return NULL; - - vsnprintf(ret, size + 1, format, va); - ret[size] = 0; - return ret; -} - -#endif - -char *Xprintf(const char *format, ...) -{ - char *ret; - va_list va; - va_start(va, format); - ret = Xvprintf(format, va); - va_end(va); - return ret; -} - -char * -XNFvprintf(const char *format, va_list va) -{ - char *ret; - int size; - va_list va2; - - va_copy(va2, va); - size = vsnprintf(NULL, 0, format, va2); - va_end(va2); - - ret = (char *)XNFalloc(size + 1); - if (ret == NULL) - return NULL; - - vsnprintf(ret, size + 1, format, va); - ret[size] = 0; - return ret; -} - -char *XNFprintf(const char *format, ...) -{ - char *ret; - va_list va; - va_start(va, format); - ret = XNFvprintf(format, va); - va_end(va); - return ret; -} diff --git a/nx-X11/programs/Xserver/os/xprintf.c.X.original b/nx-X11/programs/Xserver/os/xprintf.c.X.original deleted file mode 100644 index 07eaa1f58..000000000 --- a/nx-X11/programs/Xserver/os/xprintf.c.X.original +++ /dev/null @@ -1,104 +0,0 @@ -/* - * printf routines which xalloc their buffer - */ -/* - * Copyright (c) 2004 Alexander Gottwald - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name(s) of the above copyright - * holders shall not be used in advertising or otherwise to promote the sale, - * use or other dealings in this Software without prior written authorization. - */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include -#include - -#ifndef va_copy -# ifdef __va_copy -# define va_copy __va_copy -# else -# error "no working va_copy was found" -# endif -#endif - -char * -Xvprintf(const char *format, va_list va) -{ - char *ret; - int size; - va_list va2; - - va_copy(va2, va); - size = vsnprintf(NULL, 0, format, va2); - va_end(va2); - - ret = (char *)Xalloc(size + 1); - if (ret == NULL) - return NULL; - - vsnprintf(ret, size + 1, format, va); - ret[size] = 0; - return ret; -} - -char *Xprintf(const char *format, ...) -{ - char *ret; - va_list va; - va_start(va, format); - ret = Xvprintf(format, va); - va_end(va); - return ret; -} - -char * -XNFvprintf(const char *format, va_list va) -{ - char *ret; - int size; - va_list va2; - - va_copy(va2, va); - size = vsnprintf(NULL, 0, format, va2); - va_end(va2); - - ret = (char *)XNFalloc(size + 1); - if (ret == NULL) - return NULL; - - vsnprintf(ret, size + 1, format, va); - ret[size] = 0; - return ret; -} - -char *XNFprintf(const char *format, ...) -{ - char *ret; - va_list va; - va_start(va, format); - ret = XNFvprintf(format, va); - va_end(va); - return ret; -} diff --git a/nx-X11/programs/Xserver/randr.X.original/Imakefile b/nx-X11/programs/Xserver/randr.X.original/Imakefile deleted file mode 100644 index 73b0dfbba..000000000 --- a/nx-X11/programs/Xserver/randr.X.original/Imakefile +++ /dev/null @@ -1,18 +0,0 @@ -XCOMM $XFree86: xc/programs/Xserver/randr/Imakefile,v 1.1 2001/05/23 03:29:44 keithp Exp $ -#include - - SRCS = randr.c mirandr.c - - OBJS = randr.o mirandr.o - - INCLUDES = -I../include -I../mi -I../../../include/fonts \ - -I../fb -I../hw/kdrive -I$(EXTINCSRC) -I$(XINCLUDESRC) \ - -I$(FONTINCSRC) -I../render - LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln - -NormalLibraryTarget(randr,$(OBJS)) -NormalLibraryObjectRule() -LintLibraryTarget(randr,$(SRCS)) -NormalLintTarget($(SRCS)) - -DependTarget() diff --git a/nx-X11/programs/Xserver/randr.X.original/mirandr.c b/nx-X11/programs/Xserver/randr.X.original/mirandr.c deleted file mode 100644 index b1e19a746..000000000 --- a/nx-X11/programs/Xserver/randr.X.original/mirandr.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/randr/mirandr.c,v 1.5 2001/06/04 09:45:40 keithp Exp $ - * - * Copyright © 2000, Compaq Computer Corporation, - * Copyright © 2002, Hewlett Packard, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Compaq or HP not be used in advertising - * or publicity pertaining to distribution of the software without specific, - * written prior permission. HP makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HP - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc. - */ - - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "scrnintstr.h" -#include "mi.h" -#include -#include "randrstr.h" -#include - -/* - * This function assumes that only a single depth can be - * displayed at a time, but that all visuals of that depth - * can be displayed simultaneously. It further assumes that - * only a single size is available. Hardware providing - * additional capabilties should use different code. - * XXX what to do here.... - */ - -Bool -miRRGetInfo (ScreenPtr pScreen, Rotation *rotations) -{ - int i; - Bool setConfig = FALSE; - - *rotations = RR_Rotate_0; - for (i = 0; i < pScreen->numDepths; i++) - { - if (pScreen->allowedDepths[i].numVids) - { - RRScreenSizePtr pSize; - - pSize = RRRegisterSize (pScreen, - pScreen->width, - pScreen->height, - pScreen->mmWidth, - pScreen->mmHeight); - if (!pSize) - return FALSE; - if (!setConfig) - { - RRSetCurrentConfig (pScreen, RR_Rotate_0, 0, pSize); - setConfig = TRUE; - } - } - } - return TRUE; -} - -/* - * Any hardware that can actually change anything will need something - * different here - */ -Bool -miRRSetConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize) -{ - return TRUE; -} - - -Bool -miRandRInit (ScreenPtr pScreen) -{ - rrScrPrivPtr rp; - - if (!RRScreenInit (pScreen)) - return FALSE; - rp = rrGetScrPriv(pScreen); - rp->rrGetInfo = miRRGetInfo; - rp->rrSetConfig = miRRSetConfig; - return TRUE; -} diff --git a/nx-X11/programs/Xserver/randr.X.original/randr.c b/nx-X11/programs/Xserver/randr.X.original/randr.c deleted file mode 100644 index 3911a3498..000000000 --- a/nx-X11/programs/Xserver/randr.X.original/randr.c +++ /dev/null @@ -1,1319 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/randr/randr.c,v 1.21tsi Exp $ - * - * Copyright © 2000, Compaq Computer Corporation, - * Copyright © 2002, Hewlett Packard, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Compaq or HP not be used in advertising - * or publicity pertaining to distribution of the software without specific, - * written prior permission. HP makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HP - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc. - */ - - -#define NEED_REPLIES -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include -#include "misc.h" -#include "os.h" -#include "dixstruct.h" -#include "resource.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "extnsionst.h" -#include "servermd.h" -#include -#include -#include "randrstr.h" -#ifdef RENDER -#include /* we share subpixel order information */ -#include "picturestr.h" -#endif -#include -#ifdef EXTMODULE -#include "xf86_ansic.h" -#endif - -/* From render.h */ -#ifndef SubPixelUnknown -#define SubPixelUnknown 0 -#endif - -#define RR_VALIDATE -int RRGeneration; -int RRNScreens; - -static int ProcRRQueryVersion (ClientPtr pClient); -static int ProcRRDispatch (ClientPtr pClient); -static int SProcRRDispatch (ClientPtr pClient); -static int SProcRRQueryVersion (ClientPtr pClient); - -#define wrap(priv,real,mem,func) {\ - priv->mem = real->mem; \ - real->mem = func; \ -} - -#define unwrap(priv,real,mem) {\ - real->mem = priv->mem; \ -} - -#if 0 -static CARD8 RRReqCode; -static int RRErrBase; -#endif -static int RREventBase; -static RESTYPE ClientType, EventType; /* resource types for event masks */ -static int RRClientPrivateIndex; - -typedef struct _RRTimes { - TimeStamp setTime; - TimeStamp configTime; -} RRTimesRec, *RRTimesPtr; - -typedef struct _RRClient { - int major_version; - int minor_version; -/* RRTimesRec times[0]; */ -} RRClientRec, *RRClientPtr; - -/* - * each window has a list of clients requesting - * RRNotify events. Each client has a resource - * for each window it selects RRNotify input for, - * this resource is used to delete the RRNotifyRec - * entry from the per-window queue. - */ - -typedef struct _RREvent *RREventPtr; - -typedef struct _RREvent { - RREventPtr next; - ClientPtr client; - WindowPtr window; - XID clientResource; - int mask; -} RREventRec; - -int rrPrivIndex = -1; - -#define GetRRClient(pClient) ((RRClientPtr) (pClient)->devPrivates[RRClientPrivateIndex].ptr) -#define rrClientPriv(pClient) RRClientPtr pRRClient = GetRRClient(pClient) - -static Bool -RRClientKnowsRates (ClientPtr pClient) -{ - rrClientPriv(pClient); - - return (pRRClient->major_version > 1 || - (pRRClient->major_version == 1 && pRRClient->minor_version >= 1)); -} - -static void -RRClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - rrClientPriv(pClient); - RRTimesPtr pTimes = (RRTimesPtr) (pRRClient + 1); - int i; - - pRRClient->major_version = 0; - pRRClient->minor_version = 0; - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - rrScrPriv(pScreen); - - if (pScrPriv) - { - pTimes[i].setTime = pScrPriv->lastSetTime; - pTimes[i].configTime = pScrPriv->lastConfigTime; - } - } -} - -static void -RRResetProc (ExtensionEntry *extEntry) -{ -} - -static Bool -RRCloseScreen (int i, ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - - unwrap (pScrPriv, pScreen, CloseScreen); - if (pScrPriv->pSizes) - xfree (pScrPriv->pSizes); - xfree (pScrPriv); - RRNScreens -= 1; /* ok, one fewer screen with RandR running */ - return (*pScreen->CloseScreen) (i, pScreen); -} - -static void -SRRScreenChangeNotifyEvent(xRRScreenChangeNotifyEvent *from, - xRRScreenChangeNotifyEvent *to) -{ - to->type = from->type; - to->rotation = from->rotation; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->configTimestamp, to->configTimestamp); - cpswapl(from->root, to->root); - cpswapl(from->window, to->window); - cpswaps(from->sizeID, to->sizeID); - cpswaps(from->widthInPixels, to->widthInPixels); - cpswaps(from->heightInPixels, to->heightInPixels); - cpswaps(from->widthInMillimeters, to->widthInMillimeters); - cpswaps(from->heightInMillimeters, to->heightInMillimeters); - cpswaps(from->subpixelOrder, to->subpixelOrder); -} - -Bool RRScreenInit(ScreenPtr pScreen) -{ - rrScrPrivPtr pScrPriv; - - if (RRGeneration != serverGeneration) - { - if ((rrPrivIndex = AllocateScreenPrivateIndex()) < 0) - return FALSE; - RRGeneration = serverGeneration; - } - - pScrPriv = (rrScrPrivPtr) xalloc (sizeof (rrScrPrivRec)); - if (!pScrPriv) - return FALSE; - - SetRRScreen(pScreen, pScrPriv); - - /* - * Calling function best set these function vectors - */ - pScrPriv->rrSetConfig = 0; - pScrPriv->rrGetInfo = 0; - /* - * This value doesn't really matter -- any client must call - * GetScreenInfo before reading it which will automatically update - * the time - */ - pScrPriv->lastSetTime = currentTime; - pScrPriv->lastConfigTime = currentTime; - - wrap (pScrPriv, pScreen, CloseScreen, RRCloseScreen); - - pScrPriv->rotations = RR_Rotate_0; - - pScrPriv->nSizes = 0; - pScrPriv->nSizesInUse = 0; - pScrPriv->pSizes = 0; - - pScrPriv->rotation = RR_Rotate_0; - pScrPriv->size = -1; - - RRNScreens += 1; /* keep count of screens that implement randr */ - return TRUE; -} - -/*ARGSUSED*/ -static int -RRFreeClient (pointer data, XID id) -{ - RREventPtr pRREvent; - WindowPtr pWin; - RREventPtr *pHead, pCur, pPrev; - - pRREvent = (RREventPtr) data; - pWin = pRREvent->window; - pHead = (RREventPtr *) LookupIDByType(pWin->drawable.id, EventType); - if (pHead) { - pPrev = 0; - for (pCur = *pHead; pCur && pCur != pRREvent; pCur=pCur->next) - pPrev = pCur; - if (pCur) - { - if (pPrev) - pPrev->next = pRREvent->next; - else - *pHead = pRREvent->next; - } - } - xfree ((pointer) pRREvent); - return 1; -} - -/*ARGSUSED*/ -static int -RRFreeEvents (pointer data, XID id) -{ - RREventPtr *pHead, pCur, pNext; - - pHead = (RREventPtr *) data; - for (pCur = *pHead; pCur; pCur = pNext) { - pNext = pCur->next; - FreeResource (pCur->clientResource, ClientType); - xfree ((pointer) pCur); - } - xfree ((pointer) pHead); - return 1; -} - -void -RRExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (RRNScreens == 0) return; - - RRClientPrivateIndex = AllocateClientPrivateIndex (); - if (!AllocateClientPrivate (RRClientPrivateIndex, - sizeof (RRClientRec) + - screenInfo.numScreens * sizeof (RRTimesRec))) - return; - if (!AddCallback (&ClientStateCallback, RRClientCallback, 0)) - return; - - ClientType = CreateNewResourceType(RRFreeClient); - if (!ClientType) - return; - EventType = CreateNewResourceType(RRFreeEvents); - if (!EventType) - return; - extEntry = AddExtension (RANDR_NAME, RRNumberEvents, RRNumberErrors, - ProcRRDispatch, SProcRRDispatch, - RRResetProc, StandardMinorOpcode); - if (!extEntry) - return; -#if 0 - RRReqCode = (CARD8) extEntry->base; - RRErrBase = extEntry->errorBase; -#endif - RREventBase = extEntry->eventBase; - EventSwapVector[RREventBase + RRScreenChangeNotify] = (EventSwapPtr) - SRRScreenChangeNotifyEvent; - - return; -} - -static int -TellChanged (WindowPtr pWin, pointer value) -{ - RREventPtr *pHead, pRREvent; - ClientPtr client; - xRRScreenChangeNotifyEvent se; - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv(pScreen); - RRScreenSizePtr pSize; - WindowPtr pRoot = WindowTable[pScreen->myNum]; - - pHead = (RREventPtr *) LookupIDByType (pWin->drawable.id, EventType); - if (!pHead) - return WT_WALKCHILDREN; - - se.type = RRScreenChangeNotify + RREventBase; - se.rotation = (CARD8) pScrPriv->rotation; - se.timestamp = pScrPriv->lastSetTime.milliseconds; - se.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - se.root = pRoot->drawable.id; - se.window = pWin->drawable.id; -#ifdef RENDER - se.subpixelOrder = PictureGetSubpixelOrder (pScreen); -#else - se.subpixelOrder = SubPixelUnknown; -#endif - if (pScrPriv->size >= 0) - { - pSize = &pScrPriv->pSizes[pScrPriv->size]; - se.sizeID = pSize->id; - se.widthInPixels = pSize->width; - se.heightInPixels = pSize->height; - se.widthInMillimeters = pSize->mmWidth; - se.heightInMillimeters = pSize->mmHeight; - } - else - { - /* - * This "shouldn't happen", but a broken DDX can - * forget to set the current configuration on GetInfo - */ - se.sizeID = 0xffff; - se.widthInPixels = 0; - se.heightInPixels = 0; - se.widthInMillimeters = 0; - se.heightInMillimeters = 0; - } - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) - { - client = pRREvent->client; - if (client == serverClient || client->clientGone) - continue; - se.sequenceNumber = client->sequence; - if(pRREvent->mask & RRScreenChangeNotifyMask) - WriteEventsToClient (client, 1, (xEvent *) &se); - } - return WT_WALKCHILDREN; -} - -static Bool -RRGetInfo (ScreenPtr pScreen) -{ - rrScrPriv (pScreen); - int i, j, k, l; - Bool changed; - Rotation rotations; - RRScreenSizePtr pSize; - RRScreenRatePtr pRate; - - for (i = 0; i < pScrPriv->nSizes; i++) - { - pSize = &pScrPriv->pSizes[i]; - pSize->oldReferenced = pSize->referenced; - pSize->referenced = FALSE; - for (k = 0; k < pSize->nRates; k++) - { - pRate = &pSize->pRates[k]; - pRate->oldReferenced = pRate->referenced; - pRate->referenced = FALSE; - } - } - if (!(*pScrPriv->rrGetInfo) (pScreen, &rotations)) - return FALSE; - - changed = FALSE; - - /* - * Check whether anything changed and simultaneously generate - * the protocol id values for the objects - */ - if (rotations != pScrPriv->rotations) - { - pScrPriv->rotations = rotations; - changed = TRUE; - } - - j = 0; - for (i = 0; i < pScrPriv->nSizes; i++) - { - pSize = &pScrPriv->pSizes[i]; - if (pSize->oldReferenced != pSize->referenced) - changed = TRUE; - if (pSize->referenced) - pSize->id = j++; - l = 0; - for (k = 0; k < pSize->nRates; k++) - { - pRate = &pSize->pRates[k]; - if (pRate->oldReferenced != pRate->referenced) - changed = TRUE; - if (pRate->referenced) - l++; - } - pSize->nRatesInUse = l; - } - pScrPriv->nSizesInUse = j; - if (changed) - { - UpdateCurrentTime (); - pScrPriv->lastConfigTime = currentTime; - WalkTree (pScreen, TellChanged, (pointer) pScreen); - } - return TRUE; -} - -static void -RRSendConfigNotify (ScreenPtr pScreen) -{ - WindowPtr pWin = WindowTable[pScreen->myNum]; - xEvent event; - - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = 0; - event.u.configureNotify.y = 0; - - /* XXX xinerama stuff ? */ - - event.u.configureNotify.width = pWin->drawable.width; - event.u.configureNotify.height = pWin->drawable.height; - event.u.configureNotify.borderWidth = wBorderWidth (pWin); - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); -} - -static int -ProcRRQueryVersion (ClientPtr client) -{ - xRRQueryVersionReply rep; - register int n; - REQUEST(xRRQueryVersionReq); - rrClientPriv(client); - - REQUEST_SIZE_MATCH(xRRQueryVersionReq); - pRRClient->major_version = stuff->majorVersion; - pRRClient->minor_version = stuff->minorVersion; - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = RANDR_MAJOR; - rep.minorVersion = RANDR_MINOR; - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.majorVersion, n); - swapl(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xRRQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - - -extern char *ConnectionInfo; - -static int padlength[4] = {0, 3, 2, 1}; - -static void -RREditConnectionInfo (ScreenPtr pScreen) -{ - xConnSetup *connSetup; - char *vendor; - xPixmapFormat *formats; - xWindowRoot *root; - xDepth *depth; - xVisualType *visual; - int screen = 0; - int d; - - connSetup = (xConnSetup *) ConnectionInfo; - vendor = (char *) connSetup + sizeof (xConnSetup); - formats = (xPixmapFormat *) ((char *) vendor + - connSetup->nbytesVendor + - padlength[connSetup->nbytesVendor & 3]); - root = (xWindowRoot *) ((char *) formats + - sizeof (xPixmapFormat) * screenInfo.numPixmapFormats); - while (screen != pScreen->myNum) - { - depth = (xDepth *) ((char *) root + - sizeof (xWindowRoot)); - for (d = 0; d < root->nDepths; d++) - { - visual = (xVisualType *) ((char *) depth + - sizeof (xDepth)); - depth = (xDepth *) ((char *) visual + - depth->nVisuals * sizeof (xVisualType)); - } - root = (xWindowRoot *) ((char *) depth); - screen++; - } - root->pixWidth = pScreen->width; - root->pixHeight = pScreen->height; - root->mmWidth = pScreen->mmWidth; - root->mmHeight = pScreen->mmHeight; -} - -static int -ProcRRGetScreenInfo (ClientPtr client) -{ - REQUEST(xRRGetScreenInfoReq); - xRRGetScreenInfoReply rep; - WindowPtr pWin; - int n; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - - REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - - if (!pWin) - return BadWindow; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; - if (!pScrPriv) - { - rep.type = X_Reply; - rep.setOfRotations = RR_Rotate_0;; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nSizes = 0; - rep.sizeID = 0; - rep.rotation = RR_Rotate_0; - rep.rate = 0; - rep.nrateEnts = 0; - extra = 0; - extraLen = 0; - } - else - { - int i, j; - xScreenSizes *size; - CARD16 *rates; - CARD8 *data8; - Bool has_rate = RRClientKnowsRates (client); - - RRGetInfo (pScreen); - - rep.type = X_Reply; - rep.setOfRotations = pScrPriv->rotations; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.rotation = pScrPriv->rotation; - rep.nSizes = pScrPriv->nSizesInUse; - rep.rate = pScrPriv->rate; - rep.nrateEnts = 0; - if (has_rate) - { - for (i = 0; i < pScrPriv->nSizes; i++) - { - RRScreenSizePtr pSize = &pScrPriv->pSizes[i]; - if (pSize->referenced) - { - rep.nrateEnts += (1 + pSize->nRatesInUse); - } - } - } - - if (pScrPriv->size >= 0) - rep.sizeID = pScrPriv->pSizes[pScrPriv->size].id; - else - return BadImplementation; - - extraLen = (rep.nSizes * sizeof (xScreenSizes) + - rep.nrateEnts * sizeof (CARD16)); - - extra = (CARD8 *) xalloc (extraLen); - if (!extra) - return BadAlloc; - /* - * First comes the size information - */ - size = (xScreenSizes *) extra; - rates = (CARD16 *) (size + rep.nSizes); - for (i = 0; i < pScrPriv->nSizes; i++) - { - RRScreenSizePtr pSize = &pScrPriv->pSizes[i]; - if (pSize->referenced) - { - size->widthInPixels = pSize->width; - size->heightInPixels = pSize->height; - size->widthInMillimeters = pSize->mmWidth; - size->heightInMillimeters = pSize->mmHeight; - if (client->swapped) - { - swaps (&size->widthInPixels, n); - swaps (&size->heightInPixels, n); - swaps (&size->widthInMillimeters, n); - swaps (&size->heightInMillimeters, n); - } - size++; - if (has_rate) - { - *rates = pSize->nRatesInUse; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - for (j = 0; j < pSize->nRates; j++) - { - RRScreenRatePtr pRate = &pSize->pRates[j]; - if (pRate->referenced) - { - *rates = pRate->rate; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - } - } - } - } - } - data8 = (CARD8 *) rates; - - if (data8 - (CARD8 *) extra != extraLen) - FatalError ("RRGetScreenInfo bad extra len %ld != %ld\n", - (unsigned long)(data8 - (CARD8 *) extra), extraLen); - rep.length = (extraLen + 3) >> 2; - } - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swaps(&rep.rotation, n); - swaps(&rep.nSizes, n); - swaps(&rep.sizeID, n); - swaps(&rep.rate, n); - swaps(&rep.nrateEnts, n); - } - WriteToClient(client, sizeof(xRRGetScreenInfoReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - return (client->noClientException); -} - -static int -ProcRRSetScreenConfig (ClientPtr client) -{ - REQUEST(xRRSetScreenConfigReq); - xRRSetScreenConfigReply rep; - DrawablePtr pDraw; - int n; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - TimeStamp configTime; - TimeStamp time; - RRScreenSizePtr pSize; - int i; - Rotation rotation; - int rate; - short oldWidth, oldHeight; - Bool has_rate; - - UpdateCurrentTime (); - - if (RRClientKnowsRates (client)) - { - REQUEST_SIZE_MATCH (xRRSetScreenConfigReq); - has_rate = TRUE; - } - else - { - REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq); - has_rate = FALSE; - } - - SECURITY_VERIFY_DRAWABLE(pDraw, stuff->drawable, client, - SecurityWriteAccess); - - pScreen = pDraw->pScreen; - - pScrPriv = rrGetScrPriv(pScreen); - - time = ClientTimeToServerTime(stuff->timestamp); - configTime = ClientTimeToServerTime(stuff->configTimestamp); - - oldWidth = pScreen->width; - oldHeight = pScreen->height; - - if (!pScrPriv) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - if (!RRGetInfo (pScreen)) - return BadAlloc; - - /* - * if the client's config timestamp is not the same as the last config - * timestamp, then the config information isn't up-to-date and - * can't even be validated - */ - if (CompareTimeStamps (configTime, pScrPriv->lastConfigTime) != 0) - { - rep.status = RRSetConfigInvalidConfigTime; - goto sendReply; - } - - /* - * Search for the requested size - */ - pSize = 0; - for (i = 0; i < pScrPriv->nSizes; i++) - { - pSize = &pScrPriv->pSizes[i]; - if (pSize->referenced && pSize->id == stuff->sizeID) - { - break; - } - } - if (i == pScrPriv->nSizes) - { - /* - * Invalid size ID - */ - client->errorValue = stuff->sizeID; - return BadValue; - } - - /* - * Validate requested rotation - */ - rotation = (Rotation) stuff->rotation; - - /* test the rotation bits only! */ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_90: - case RR_Rotate_180: - case RR_Rotate_270: - break; - default: - /* - * Invalid rotation - */ - client->errorValue = stuff->rotation; - return BadValue; - } - - if ((~pScrPriv->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - client->errorValue = stuff->rotation; - return BadMatch; - } - - /* - * Validate requested refresh - */ - if (has_rate) - rate = (int) stuff->rate; - else - rate = 0; - - if (rate) - { - for (i = 0; i < pSize->nRates; i++) - { - RRScreenRatePtr pRate = &pSize->pRates[i]; - if (pRate->referenced && pRate->rate == rate) - break; - } - if (i == pSize->nRates) - { - /* - * Invalid rate - */ - client->errorValue = rate; - return BadValue; - } - } - - /* - * Make sure the requested set-time is not older than - * the last set-time - */ - if (CompareTimeStamps (time, pScrPriv->lastSetTime) < 0) - { - rep.status = RRSetConfigInvalidTime; - goto sendReply; - } - - /* - * call out to ddx routine to effect the change - */ - if (!(*pScrPriv->rrSetConfig) (pScreen, rotation, rate, - pSize)) - { - /* - * unknown DDX failure, report to client - */ - rep.status = RRSetConfigFailed; - goto sendReply; - } - - /* - * set current extension configuration pointers - */ - RRSetCurrentConfig (pScreen, rotation, rate, pSize); - - /* - * Deliver ScreenChangeNotify events whenever - * the configuration is updated - */ - WalkTree (pScreen, TellChanged, (pointer) pScreen); - - /* - * Deliver ConfigureNotify events when root changes - * pixel size - */ - if (oldWidth != pScreen->width || oldHeight != pScreen->height) - RRSendConfigNotify (pScreen); - RREditConnectionInfo (pScreen); - - /* - * Fix pointer bounds and location - */ - ScreenRestructured (pScreen); - pScrPriv->lastSetTime = time; - - /* - * Report Success - */ - rep.status = RRSetConfigSuccess; - -sendReply: - - rep.type = X_Reply; - /* rep.status has already been filled in */ - rep.length = 0; - rep.sequenceNumber = client->sequence; - - rep.newTimestamp = pScrPriv->lastSetTime.milliseconds; - rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - - if (client->swapped) - { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.newTimestamp, n); - swapl(&rep.newConfigTimestamp, n); - swapl(&rep.root, n); - } - WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *)&rep); - - return (client->noClientException); -} - -int -RRSetScreenConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize) -{ - rrScrPrivPtr pScrPriv; - int i; - short oldWidth, oldHeight; - - pScrPriv = rrGetScrPriv(pScreen); - - oldWidth = pScreen->width; - oldHeight = pScreen->height; - - if (!RRGetInfo (pScreen)) - return BadAlloc; - - /* - * Validate requested rotation - */ - - /* test the rotation bits only! */ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_90: - case RR_Rotate_180: - case RR_Rotate_270: - break; - default: - /* - * Invalid rotation - */ - return BadValue; - } - - if ((~pScrPriv->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - return BadMatch; - } - - /* - * Validate requested refresh - */ - if (rate) - { - for (i = 0; i < pSize->nRates; i++) - { - RRScreenRatePtr pRate = &pSize->pRates[i]; - if (pRate->referenced && pRate->rate == rate) - break; - } - if (i == pSize->nRates) - { - /* - * Invalid rate - */ - return BadValue; - } - } - - /* - * call out to ddx routine to effect the change - */ - if (!(*pScrPriv->rrSetConfig) (pScreen, rotation, rate, - pSize)) - { - /* - * unknown DDX failure, report to client - */ - return BadImplementation; - } - - /* - * set current extension configuration pointers - */ - RRSetCurrentConfig (pScreen, rotation, rate, pSize); - - /* - * Deliver ScreenChangeNotify events whenever - * the configuration is updated - */ - WalkTree (pScreen, TellChanged, (pointer) pScreen); - - /* - * Deliver ConfigureNotify events when root changes - * pixel size - */ - if (oldWidth != pScreen->width || oldHeight != pScreen->height) - RRSendConfigNotify (pScreen); - RREditConnectionInfo (pScreen); - - /* - * Fix pointer bounds and location - */ - ScreenRestructured (pScreen); - - return Success; -} - -static int -ProcRRSelectInput (ClientPtr client) -{ - REQUEST(xRRSelectInputReq); - rrClientPriv(client); - RRTimesPtr pTimes; - WindowPtr pWin; - RREventPtr pRREvent, pNewRREvent, *pHead; - XID clientResource; - - REQUEST_SIZE_MATCH(xRRSelectInputReq); - pWin = SecurityLookupWindow (stuff->window, client, SecurityWriteAccess); - if (!pWin) - return BadWindow; - pHead = (RREventPtr *)SecurityLookupIDByType(client, - pWin->drawable.id, EventType, - SecurityWriteAccess); - - if (stuff->enable & (RRScreenChangeNotifyMask)) - { - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv (pScreen); - - if (pHead) - { - /* check for existing entry. */ - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) - if (pRREvent->client == client) - return Success; - } - - /* build the entry */ - pNewRREvent = (RREventPtr) xalloc (sizeof (RREventRec)); - if (!pNewRREvent) - return BadAlloc; - pNewRREvent->next = 0; - pNewRREvent->client = client; - pNewRREvent->window = pWin; - pNewRREvent->mask = stuff->enable; - /* - * add a resource that will be deleted when - * the client goes away - */ - clientResource = FakeClientID (client->index); - pNewRREvent->clientResource = clientResource; - if (!AddResource (clientResource, ClientType, (pointer)pNewRREvent)) - return BadAlloc; - /* - * create a resource to contain a pointer to the list - * of clients selecting input. This must be indirect as - * the list may be arbitrarily rearranged which cannot be - * done through the resource database. - */ - if (!pHead) - { - pHead = (RREventPtr *) xalloc (sizeof (RREventPtr)); - if (!pHead || - !AddResource (pWin->drawable.id, EventType, (pointer)pHead)) - { - FreeResource (clientResource, RT_NONE); - return BadAlloc; - } - *pHead = 0; - } - pNewRREvent->next = *pHead; - *pHead = pNewRREvent; - /* - * Now see if the client needs an event - */ - if (pScrPriv) - { - pTimes = &((RRTimesPtr) (pRRClient + 1))[pScreen->myNum]; - if (CompareTimeStamps (pTimes->setTime, - pScrPriv->lastSetTime) != 0 || - CompareTimeStamps (pTimes->configTime, - pScrPriv->lastConfigTime) != 0) - { - TellChanged (pWin, (pointer) pScreen); - } - } - } - else if (stuff->enable == xFalse) - { - /* delete the interest */ - if (pHead) { - pNewRREvent = 0; - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) { - if (pRREvent->client == client) - break; - pNewRREvent = pRREvent; - } - if (pRREvent) { - FreeResource (pRREvent->clientResource, ClientType); - if (pNewRREvent) - pNewRREvent->next = pRREvent->next; - else - *pHead = pRREvent->next; - xfree (pRREvent); - } - } - } - else - { - client->errorValue = stuff->enable; - return BadValue; - } - return Success; -} - - -static int -ProcRRDispatch (ClientPtr client) -{ - REQUEST(xReq); - switch (stuff->data) - { - case X_RRQueryVersion: - return ProcRRQueryVersion(client); - case X_RRSetScreenConfig: - return ProcRRSetScreenConfig(client); - case X_RRSelectInput: - return ProcRRSelectInput(client); - case X_RRGetScreenInfo: - return ProcRRGetScreenInfo(client); - default: - return BadRequest; - } -} - -static int -SProcRRQueryVersion (ClientPtr client) -{ - register int n; - REQUEST(xRRQueryVersionReq); - - swaps(&stuff->length, n); - swapl(&stuff->majorVersion, n); - swapl(&stuff->minorVersion, n); - return ProcRRQueryVersion(client); -} - -static int -SProcRRGetScreenInfo (ClientPtr client) -{ - register int n; - REQUEST(xRRGetScreenInfoReq); - - swaps(&stuff->length, n); - swapl(&stuff->window, n); - return ProcRRGetScreenInfo(client); -} - -static int -SProcRRSetScreenConfig (ClientPtr client) -{ - register int n; - REQUEST(xRRSetScreenConfigReq); - - if (RRClientKnowsRates (client)) - { - REQUEST_SIZE_MATCH (xRRSetScreenConfigReq); - swaps (&stuff->rate, n); - } - else - { - REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq); - } - - swaps(&stuff->length, n); - swapl(&stuff->drawable, n); - swapl(&stuff->timestamp, n); - swaps(&stuff->sizeID, n); - swaps(&stuff->rotation, n); - return ProcRRSetScreenConfig(client); -} - -static int -SProcRRSelectInput (ClientPtr client) -{ - register int n; - REQUEST(xRRSelectInputReq); - - swaps(&stuff->length, n); - swapl(&stuff->window, n); - return ProcRRSelectInput(client); -} - - -static int -SProcRRDispatch (ClientPtr client) -{ - REQUEST(xReq); - switch (stuff->data) - { - case X_RRQueryVersion: - return SProcRRQueryVersion(client); - case X_RRSetScreenConfig: - return SProcRRSetScreenConfig(client); - case X_RRSelectInput: - return SProcRRSelectInput(client); - case X_RRGetScreenInfo: - return SProcRRGetScreenInfo(client); - default: - return BadRequest; - } -} - - -static Bool -RRScreenSizeMatches (RRScreenSizePtr a, - RRScreenSizePtr b) -{ - if (a->width != b->width) - return FALSE; - if (a->height != b->height) - return FALSE; - if (a->mmWidth != b->mmWidth) - return FALSE; - if (a->mmHeight != b->mmHeight) - return FALSE; - return TRUE; -} - -RRScreenSizePtr -RRRegisterSize (ScreenPtr pScreen, - short width, - short height, - short mmWidth, - short mmHeight) -{ - rrScrPriv (pScreen); - int i; - RRScreenSize tmp; - RRScreenSizePtr pNew; - - if (!pScrPriv) - return 0; - - tmp.width = width; - tmp.height= height; - tmp.mmWidth = mmWidth; - tmp.mmHeight = mmHeight; - tmp.pRates = 0; - tmp.nRates = 0; - tmp.nRatesInUse = 0; - tmp.referenced = TRUE; - tmp.oldReferenced = FALSE; - for (i = 0; i < pScrPriv->nSizes; i++) - if (RRScreenSizeMatches (&tmp, &pScrPriv->pSizes[i])) - { - pScrPriv->pSizes[i].referenced = TRUE; - return &pScrPriv->pSizes[i]; - } - pNew = xrealloc (pScrPriv->pSizes, - (pScrPriv->nSizes + 1) * sizeof (RRScreenSize)); - if (!pNew) - return 0; - pNew[pScrPriv->nSizes++] = tmp; - pScrPriv->pSizes = pNew; - return &pNew[pScrPriv->nSizes-1]; -} - -Bool RRRegisterRate (ScreenPtr pScreen, - RRScreenSizePtr pSize, - int rate) -{ - rrScrPriv(pScreen); - int i; - RRScreenRatePtr pNew, pRate; - - if (!pScrPriv) - return FALSE; - - for (i = 0; i < pSize->nRates; i++) - { - pRate = &pSize->pRates[i]; - if (pRate->rate == rate) - { - pRate->referenced = TRUE; - return TRUE; - } - } - - pNew = xrealloc (pSize->pRates, - (pSize->nRates + 1) * sizeof (RRScreenRate)); - if (!pNew) - return FALSE; - pRate = &pNew[pSize->nRates++]; - pRate->rate = rate; - pRate->referenced = TRUE; - pRate->oldReferenced = FALSE; - pSize->pRates = pNew; - return TRUE; -} - -void -RRSetCurrentConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize) -{ - rrScrPriv (pScreen); - - if (!pScrPriv) - return; - - pScrPriv->rotation = rotation; - pScrPriv->size = pSize - pScrPriv->pSizes; - pScrPriv->rate = rate; -} diff --git a/nx-X11/programs/Xserver/randr.X.original/randrstr.h b/nx-X11/programs/Xserver/randr.X.original/randrstr.h deleted file mode 100644 index cd4ce3846..000000000 --- a/nx-X11/programs/Xserver/randr.X.original/randrstr.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * $XFree86: xc/programs/Xserver/randr/randrstr.h,v 1.5 2002/09/29 23:39:45 keithp Exp $ - * - * Copyright © 2000 Compaq Computer Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Compaq not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Compaq makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * COMPAQ DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL COMPAQ BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifndef _RANDRSTR_H_ -#define _RANDRSTR_H_ - -#include - -typedef struct _rrScreenRate { - int rate; - Bool referenced; - Bool oldReferenced; -} RRScreenRate, *RRScreenRatePtr; - -typedef struct _rrScreenSize { - int id; - short width, height; - short mmWidth, mmHeight; - RRScreenRatePtr pRates; - int nRates; - int nRatesInUse; - Bool referenced; - Bool oldReferenced; -} RRScreenSize, *RRScreenSizePtr; - -typedef Bool (*RRSetConfigProcPtr) (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize); - -typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation *rotations); -typedef Bool (*RRCloseScreenProcPtr) ( int i, ScreenPtr pscreen); - -typedef struct _rrScrPriv { - RRSetConfigProcPtr rrSetConfig; - RRGetInfoProcPtr rrGetInfo; - - TimeStamp lastSetTime; /* last changed by client */ - TimeStamp lastConfigTime; /* possible configs changed */ - RRCloseScreenProcPtr CloseScreen; - - /* - * Configuration information - */ - Rotation rotations; - - int nSizes; - int nSizesInUse; - RRScreenSizePtr pSizes; - - /* - * Current state - */ - Rotation rotation; - int size; - int rate; -} rrScrPrivRec, *rrScrPrivPtr; - -extern int rrPrivIndex; - -#define rrGetScrPriv(pScr) ((rrScrPrivPtr) (pScr)->devPrivates[rrPrivIndex].ptr) -#define rrScrPriv(pScr) rrScrPrivPtr pScrPriv = rrGetScrPriv(pScr) -#define SetRRScreen(s,p) ((s)->devPrivates[rrPrivIndex].ptr = (pointer) (p)) - -/* Initialize the extension */ -void -RRExtensionInit (void); - -/* - * Then, register the specific size with the screen - */ - -RRScreenSizePtr -RRRegisterSize (ScreenPtr pScreen, - short width, - short height, - short mmWidth, - short mmHeight); - -Bool RRRegisterRate (ScreenPtr pScreen, - RRScreenSizePtr pSize, - int rate); - -/* - * Finally, set the current configuration of the screen - */ - -void -RRSetCurrentConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize); - -Bool RRScreenInit(ScreenPtr pScreen); - -int -RRSetScreenConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize); - -Bool -miRandRInit (ScreenPtr pScreen); - -Bool -miRRGetInfo (ScreenPtr pScreen, Rotation *rotations); - -Bool -miRRSetConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr size); - -Bool -miRRGetScreenInfo (ScreenPtr pScreen); - -#endif /* _RANDRSTR_H_ */ diff --git a/nx-X11/programs/Xserver/randr/Imakefile.NX.original b/nx-X11/programs/Xserver/randr/Imakefile.NX.original deleted file mode 100644 index 2eff07fee..000000000 --- a/nx-X11/programs/Xserver/randr/Imakefile.NX.original +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ -XCOMM $XFree86: xc/programs/Xserver/randr/Imakefile,v 1.1 2001/05/23 03:29:44 keithp Exp $ -#include - - SRCS = mirandr.c randr.c rrcrtc.c rrdispatch.c rrinfo.c rrmode.c rroutput.c rrpointer.c rrproperty.c rrscreen.c rrsdispatch.c rrxinerama.c - - OBJS = mirandr.o randr.o rrcrtc.o rrdispatch.o rrinfo.o rrmode.o rroutput.o rrpointer.o rrproperty.o rrscreen.o rrsdispatch.o rrxinerama.o - - INCLUDES = -I../include -I../mi -I../../../include/fonts \ - -I../fb -I../hw/kdrive -I$(EXTINCSRC) -I$(XINCLUDESRC) \ - -I$(FONTINCSRC) -I../render - LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln - - DEFINES = -DNXAGENT_SERVER - -NormalLibraryTarget(randr,$(OBJS)) -NormalLibraryObjectRule() -LintLibraryTarget(randr,$(SRCS)) -NormalLintTarget($(SRCS)) - -DependTarget() diff --git a/nx-X11/programs/Xserver/randr/Imakefile.X.original b/nx-X11/programs/Xserver/randr/Imakefile.X.original deleted file mode 100644 index e69de29bb..000000000 diff --git a/nx-X11/programs/Xserver/randr/panoramiXproto.h.NX.original b/nx-X11/programs/Xserver/randr/panoramiXproto.h.NX.original deleted file mode 100644 index 6b27c56eb..000000000 --- a/nx-X11/programs/Xserver/randr/panoramiXproto.h.NX.original +++ /dev/null @@ -1,192 +0,0 @@ -/* $Xorg: panoramiXproto.h,v 1.4 2000/08/18 04:05:45 coskrey Exp $ */ -/***************************************************************** -Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, -BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Digital Equipment Corporation -shall not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from Digital -Equipment Corporation. -******************************************************************/ -/* $XFree86: xc/include/extensions/panoramiXproto.h,v 3.5 2000/03/01 01:04:21 dawes Exp $ */ - -/* THIS IS NOT AN X PROJECT TEAM SPECIFICATION */ - -#ifndef _PANORAMIXPROTO_H_ -#define _PANORAMIXPROTO_H_ - -#define PANORAMIX_PROTOCOL_NAME "XINERAMA" - -#define X_PanoramiXQueryVersion 0 -#define X_PanoramiXGetState 1 -#define X_PanoramiXGetScreenCount 2 -#define X_PanoramiXGetScreenSize 3 - -#define X_XineramaIsActive 4 -#define X_XineramaQueryScreens 5 - -typedef struct _PanoramiXQueryVersion { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXQueryVersion */ - CARD16 length B16; - CARD8 clientMajor; - CARD8 clientMinor; - CARD16 unused B16; -} xPanoramiXQueryVersionReq; - -#define sz_xPanoramiXQueryVersionReq 8 - -typedef struct { - CARD8 type; /* must be X_Reply */ - CARD8 pad1; /* unused */ - CARD16 sequenceNumber B16; /* last sequence number */ - CARD32 length B32; /* 0 */ - CARD16 majorVersion B16; - CARD16 minorVersion B16; - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ - CARD32 pad4 B32; /* unused */ - CARD32 pad5 B32; /* unused */ - CARD32 pad6 B32; /* unused */ -} xPanoramiXQueryVersionReply; - -#define sz_xPanoramiXQueryVersionReply 32 - - -typedef struct _PanoramiXGetState { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXGetState */ - CARD16 length B16; - CARD32 window B32; -} xPanoramiXGetStateReq; -#define sz_xPanoramiXGetStateReq 8 - -typedef struct { - BYTE type; - BYTE state; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 window B32; - CARD32 pad1 B32; /* unused */ - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ - CARD32 pad4 B32; /* unused */ - CARD32 pad5 B32; /* unused */ -} xPanoramiXGetStateReply; - -#define sz_panoramiXGetStateReply 32 - -typedef struct _PanoramiXGetScreenCount { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXGetScreenCount */ - CARD16 length B16; - CARD32 window B32; -} xPanoramiXGetScreenCountReq; -#define sz_xPanoramiXGetScreenCountReq 8 - -typedef struct { - BYTE type; - BYTE ScreenCount; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 window B32; - CARD32 pad1 B32; /* unused */ - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ - CARD32 pad4 B32; /* unused */ - CARD32 pad5 B32; /* unused */ -} xPanoramiXGetScreenCountReply; -#define sz_panoramiXGetScreenCountReply 32 - -typedef struct _PanoramiXGetScreenSize { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXGetState */ - CARD16 length B16; - CARD32 window B32; - CARD32 screen B32; -} xPanoramiXGetScreenSizeReq; -#define sz_xPanoramiXGetScreenSizeReq 12 - -typedef struct { - BYTE type; - CARD8 pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 width B32; - CARD32 height B32; - CARD32 window B32; - CARD32 screen B32; - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ -} xPanoramiXGetScreenSizeReply; -#define sz_panoramiXGetScreenSizeReply 32 - -/************ Alternate protocol ******************/ - -typedef struct { - CARD8 reqType; - CARD8 panoramiXReqType; - CARD16 length B16; -} xXineramaIsActiveReq; -#define sz_xXineramaIsActiveReq 4 - -typedef struct { - BYTE type; - CARD8 pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 state B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xXineramaIsActiveReply; -#define sz_XineramaIsActiveReply 32 - - -typedef struct { - CARD8 reqType; - CARD8 panoramiXReqType; - CARD16 length B16; -} xXineramaQueryScreensReq; -#define sz_xXineramaQueryScreensReq 4 - -typedef struct { - BYTE type; - CARD8 pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 number B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xXineramaQueryScreensReply; -#define sz_XineramaQueryScreensReply 32 - -typedef struct { - INT16 x_org B16; - INT16 y_org B16; - CARD16 width B16; - CARD16 height B16; -} xXineramaScreenInfo; -#define sz_XineramaScreenInfo 8 - -#endif diff --git a/nx-X11/programs/Xserver/randr/panoramiXproto.h.X.original b/nx-X11/programs/Xserver/randr/panoramiXproto.h.X.original deleted file mode 100644 index e69de29bb..000000000 diff --git a/nx-X11/programs/Xserver/randr/randr.c.NX.original b/nx-X11/programs/Xserver/randr/randr.c.NX.original deleted file mode 100644 index 81df406a6..000000000 --- a/nx-X11/programs/Xserver/randr/randr.c.NX.original +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright © 2000 Compaq Computer Corporation - * Copyright © 2002 Hewlett-Packard Company - * Copyright © 2006 Intel Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - * - * Author: Jim Gettys, Hewlett-Packard Company, Inc. - * Keith Packard, Intel Corporation - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#define NEED_REPLIES -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "randrstr.h" - -/* From render.h */ -#ifndef SubPixelUnknown -#define SubPixelUnknown 0 -#endif - -#define RR_VALIDATE -static int RRNScreens; - -#define wrap(priv,real,mem,func) {\ - priv->mem = real->mem; \ - real->mem = func; \ -} - -#define unwrap(priv,real,mem) {\ - real->mem = priv->mem; \ -} - -static int ProcRRDispatch (ClientPtr pClient); -static int SProcRRDispatch (ClientPtr pClient); - -int RREventBase; -int RRErrorBase; -RESTYPE RRClientType, RREventType; /* resource types for event masks */ - -#ifndef NXAGENT_SERVER -DevPrivateKey RRClientPrivateKey = &RRClientPrivateKey; -DevPrivateKey rrPrivKey = &rrPrivKey; -#else -int RRClientPrivateIndex; -int rrPrivIndex = -1; -#endif - -static void -RRClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - rrClientPriv(pClient); - RRTimesPtr pTimes = (RRTimesPtr) (pRRClient + 1); - int i; - - pRRClient->major_version = 0; - pRRClient->minor_version = 0; - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - rrScrPriv(pScreen); - - if (pScrPriv) - { - pTimes[i].setTime = pScrPriv->lastSetTime; - pTimes[i].configTime = pScrPriv->lastConfigTime; - } - } -} - -static void -RRResetProc (ExtensionEntry *extEntry) -{ -} - -static Bool -RRCloseScreen (int i, ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - int j; - - unwrap (pScrPriv, pScreen, CloseScreen); - for (j = pScrPriv->numCrtcs - 1; j >= 0; j--) - RRCrtcDestroy (pScrPriv->crtcs[j]); - for (j = pScrPriv->numOutputs - 1; j >= 0; j--) - RROutputDestroy (pScrPriv->outputs[j]); - - xfree (pScrPriv); - RRNScreens -= 1; /* ok, one fewer screen with RandR running */ - return (*pScreen->CloseScreen) (i, pScreen); -} - -static void -SRRScreenChangeNotifyEvent(xRRScreenChangeNotifyEvent *from, - xRRScreenChangeNotifyEvent *to) -{ - to->type = from->type; - to->rotation = from->rotation; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->configTimestamp, to->configTimestamp); - cpswapl(from->root, to->root); - cpswapl(from->window, to->window); - cpswaps(from->sizeID, to->sizeID); - cpswaps(from->widthInPixels, to->widthInPixels); - cpswaps(from->heightInPixels, to->heightInPixels); - cpswaps(from->widthInMillimeters, to->widthInMillimeters); - cpswaps(from->heightInMillimeters, to->heightInMillimeters); - cpswaps(from->subpixelOrder, to->subpixelOrder); -} - -static void -SRRCrtcChangeNotifyEvent(xRRCrtcChangeNotifyEvent *from, - xRRCrtcChangeNotifyEvent *to) -{ - to->type = from->type; - to->subCode = from->subCode; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->window, to->window); - cpswapl(from->crtc, to->crtc); - cpswapl(from->mode, to->mode); - cpswapl(from->window, to->window); - cpswaps(from->rotation, to->rotation); - cpswaps(from->x, to->x); - cpswaps(from->y, to->y); - cpswaps(from->width, to->width); - cpswaps(from->height, to->height); -} - -static void -SRROutputChangeNotifyEvent(xRROutputChangeNotifyEvent *from, - xRROutputChangeNotifyEvent *to) -{ - to->type = from->type; - to->subCode = from->subCode; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->configTimestamp, to->configTimestamp); - cpswapl(from->window, to->window); - cpswapl(from->output, to->output); - cpswapl(from->crtc, to->crtc); - cpswapl(from->mode, to->mode); - cpswaps(from->rotation, to->rotation); -} - -static void -SRROutputPropertyNotifyEvent(xRROutputPropertyNotifyEvent *from, - xRROutputPropertyNotifyEvent *to) -{ - to->type = from->type; - to->subCode = from->subCode; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->window, to->window); - cpswapl(from->output, to->output); - cpswapl(from->atom, to->atom); - cpswapl(from->timestamp, to->timestamp); -} - -static void -SRRNotifyEvent (xEvent *from, - xEvent *to) -{ - switch (from->u.u.detail) { - case RRNotify_CrtcChange: - SRRCrtcChangeNotifyEvent ((xRRCrtcChangeNotifyEvent *) from, - (xRRCrtcChangeNotifyEvent *) to); - break; - case RRNotify_OutputChange: - SRROutputChangeNotifyEvent ((xRROutputChangeNotifyEvent *) from, - (xRROutputChangeNotifyEvent *) to); - break; - case RRNotify_OutputProperty: - SRROutputPropertyNotifyEvent ((xRROutputPropertyNotifyEvent *) from, - (xRROutputPropertyNotifyEvent *) to); - break; - default: - break; - } -} - -static int RRGeneration; - -Bool RRInit (void) -{ - if (RRGeneration != serverGeneration) - { - #ifdef NXAGENT_SERVER - if ((rrPrivIndex = AllocateScreenPrivateIndex()) < 0) - return FALSE; - #endif - if (!RRModeInit ()) - return FALSE; - if (!RRCrtcInit ()) - return FALSE; - if (!RROutputInit ()) - return FALSE; - RRGeneration = serverGeneration; - } - return TRUE; -} - -Bool RRScreenInit(ScreenPtr pScreen) -{ - rrScrPrivPtr pScrPriv; - - if (!RRInit ()) - return FALSE; - - pScrPriv = (rrScrPrivPtr) xcalloc (1, sizeof (rrScrPrivRec)); - if (!pScrPriv) - return FALSE; - - SetRRScreen(pScreen, pScrPriv); - - /* - * Calling function best set these function vectors - */ - pScrPriv->rrGetInfo = 0; - pScrPriv->maxWidth = pScrPriv->minWidth = pScreen->width; - pScrPriv->maxHeight = pScrPriv->minHeight = pScreen->height; - - pScrPriv->width = pScreen->width; - pScrPriv->height = pScreen->height; - pScrPriv->mmWidth = pScreen->mmWidth; - pScrPriv->mmHeight = pScreen->mmHeight; -#if RANDR_12_INTERFACE - pScrPriv->rrScreenSetSize = NULL; - pScrPriv->rrCrtcSet = NULL; - pScrPriv->rrCrtcSetGamma = NULL; -#endif -#if RANDR_10_INTERFACE - pScrPriv->rrSetConfig = 0; - pScrPriv->rotations = RR_Rotate_0; - pScrPriv->reqWidth = pScreen->width; - pScrPriv->reqHeight = pScreen->height; - pScrPriv->nSizes = 0; - pScrPriv->pSizes = NULL; - pScrPriv->rotation = RR_Rotate_0; - pScrPriv->rate = 0; - pScrPriv->size = 0; -#endif - - /* - * This value doesn't really matter -- any client must call - * GetScreenInfo before reading it which will automatically update - * the time - */ - pScrPriv->lastSetTime = currentTime; - pScrPriv->lastConfigTime = currentTime; - - wrap (pScrPriv, pScreen, CloseScreen, RRCloseScreen); - - pScrPriv->numOutputs = 0; - pScrPriv->outputs = NULL; - pScrPriv->numCrtcs = 0; - pScrPriv->crtcs = NULL; - - RRNScreens += 1; /* keep count of screens that implement randr */ - return TRUE; -} - -/*ARGSUSED*/ -static int -RRFreeClient (pointer data, XID id) -{ - RREventPtr pRREvent; - WindowPtr pWin; - RREventPtr *pHead, pCur, pPrev; - - pRREvent = (RREventPtr) data; - pWin = pRREvent->window; - pHead = (RREventPtr *) LookupIDByType(pWin->drawable.id, RREventType); - if (pHead) { - pPrev = 0; - for (pCur = *pHead; pCur && pCur != pRREvent; pCur=pCur->next) - pPrev = pCur; - if (pCur) - { - if (pPrev) - pPrev->next = pRREvent->next; - else - *pHead = pRREvent->next; - } - } - xfree ((pointer) pRREvent); - return 1; -} - -/*ARGSUSED*/ -static int -RRFreeEvents (pointer data, XID id) -{ - RREventPtr *pHead, pCur, pNext; - - pHead = (RREventPtr *) data; - for (pCur = *pHead; pCur; pCur = pNext) { - pNext = pCur->next; - FreeResource (pCur->clientResource, RRClientType); - xfree ((pointer) pCur); - } - xfree ((pointer) pHead); - return 1; -} - -void -RRExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (RRNScreens == 0) return; - - #ifndef NXAGENT_SERVER - if (!dixRequestPrivate(RRClientPrivateKey, - sizeof (RRClientRec) + - screenInfo.numScreens * sizeof (RRTimesRec))) - return; - #else - RRClientPrivateIndex = AllocateClientPrivateIndex (); - if (!AllocateClientPrivate (RRClientPrivateIndex, - sizeof (RRClientRec) + - screenInfo.numScreens * sizeof (RRTimesRec))) - return; - #endif - if (!AddCallback (&ClientStateCallback, RRClientCallback, 0)) - return; - - RRClientType = CreateNewResourceType(RRFreeClient); - if (!RRClientType) - return; - RREventType = CreateNewResourceType(RRFreeEvents); - if (!RREventType) - return; - extEntry = AddExtension (RANDR_NAME, RRNumberEvents, RRNumberErrors, - ProcRRDispatch, SProcRRDispatch, - RRResetProc, StandardMinorOpcode); - if (!extEntry) - return; - RRErrorBase = extEntry->errorBase; - RREventBase = extEntry->eventBase; - EventSwapVector[RREventBase + RRScreenChangeNotify] = (EventSwapPtr) - SRRScreenChangeNotifyEvent; - EventSwapVector[RREventBase + RRNotify] = (EventSwapPtr) - SRRNotifyEvent; -#ifdef PANORAMIX - RRXineramaExtensionInit(); -#endif -} - -static int -TellChanged (WindowPtr pWin, pointer value) -{ - RREventPtr *pHead, pRREvent; - ClientPtr client; - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv(pScreen); - int i; - - pHead = (RREventPtr *) LookupIDByType (pWin->drawable.id, RREventType); - if (!pHead) - return WT_WALKCHILDREN; - - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) - { - client = pRREvent->client; - if (client == serverClient || client->clientGone) - continue; - - if (pRREvent->mask & RRScreenChangeNotifyMask) - RRDeliverScreenEvent (client, pWin, pScreen); - - if (pRREvent->mask & RRCrtcChangeNotifyMask) - { - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - if (crtc->changed) - RRDeliverCrtcEvent (client, pWin, crtc); - } - } - - if (pRREvent->mask & RROutputChangeNotifyMask) - { - for (i = 0; i < pScrPriv->numOutputs; i++) - { - RROutputPtr output = pScrPriv->outputs[i]; - if (output->changed) - RRDeliverOutputEvent (client, pWin, output); - } - } - } - return WT_WALKCHILDREN; -} - -/* - * Something changed; send events and adjust pointer position - */ -void -RRTellChanged (ScreenPtr pScreen) -{ - rrScrPriv (pScreen); - int i; - - if (pScrPriv->changed) - { - UpdateCurrentTime (); - if (pScrPriv->configChanged) - { - pScrPriv->lastConfigTime = currentTime; - pScrPriv->configChanged = FALSE; - } - pScrPriv->changed = FALSE; - WalkTree (pScreen, TellChanged, (pointer) pScreen); - for (i = 0; i < pScrPriv->numOutputs; i++) - pScrPriv->outputs[i]->changed = FALSE; - for (i = 0; i < pScrPriv->numCrtcs; i++) - pScrPriv->crtcs[i]->changed = FALSE; - if (pScrPriv->layoutChanged) - { - pScrPriv->layoutChanged = FALSE; - RRPointerScreenConfigured (pScreen); - RRSendConfigNotify (pScreen); - } - } -} - -/* - * Return the first output which is connected to an active CRTC - * Used in emulating 1.0 behaviour - */ -RROutputPtr -RRFirstOutput (ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - RROutputPtr output; - int i, j; - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - for (j = 0; j < pScrPriv->numOutputs; j++) - { - output = pScrPriv->outputs[j]; - if (output->crtc == crtc) - return output; - } - } - return NULL; -} - -CARD16 -RRVerticalRefresh (xRRModeInfo *mode) -{ - CARD32 refresh; - CARD32 dots = mode->hTotal * mode->vTotal; - if (!dots) - return 0; - refresh = (mode->dotClock + dots/2) / dots; - if (refresh > 0xffff) - refresh = 0xffff; - return (CARD16) refresh; -} - -static int -ProcRRDispatch (ClientPtr client) -{ - REQUEST(xReq); - if (stuff->data >= RRNumberRequests || !ProcRandrVector[stuff->data]) - return BadRequest; - return (*ProcRandrVector[stuff->data]) (client); -} - -static int -SProcRRDispatch (ClientPtr client) -{ - REQUEST(xReq); - if (stuff->data >= RRNumberRequests || !ProcRandrVector[stuff->data]) - return BadRequest; - return (*SProcRandrVector[stuff->data]) (client); -} - diff --git a/nx-X11/programs/Xserver/randr/randr.c.X.original b/nx-X11/programs/Xserver/randr/randr.c.X.original deleted file mode 100644 index bc2b995d2..000000000 --- a/nx-X11/programs/Xserver/randr/randr.c.X.original +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright © 2000 Compaq Computer Corporation - * Copyright © 2002 Hewlett-Packard Company - * Copyright © 2006 Intel Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - * - * Author: Jim Gettys, Hewlett-Packard Company, Inc. - * Keith Packard, Intel Corporation - */ - -#define NEED_REPLIES -#define NEED_EVENTS -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "randrstr.h" - -/* From render.h */ -#ifndef SubPixelUnknown -#define SubPixelUnknown 0 -#endif - -#define RR_VALIDATE -static int RRNScreens; - -#define wrap(priv,real,mem,func) {\ - priv->mem = real->mem; \ - real->mem = func; \ -} - -#define unwrap(priv,real,mem) {\ - real->mem = priv->mem; \ -} - -static int ProcRRDispatch (ClientPtr pClient); -static int SProcRRDispatch (ClientPtr pClient); - -int RREventBase; -int RRErrorBase; -RESTYPE RRClientType, RREventType; /* resource types for event masks */ -DevPrivateKey RRClientPrivateKey = &RRClientPrivateKey; - -DevPrivateKey rrPrivKey = &rrPrivKey; - -static void -RRClientCallback (CallbackListPtr *list, - pointer closure, - pointer data) -{ - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - rrClientPriv(pClient); - RRTimesPtr pTimes = (RRTimesPtr) (pRRClient + 1); - int i; - - pRRClient->major_version = 0; - pRRClient->minor_version = 0; - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - rrScrPriv(pScreen); - - if (pScrPriv) - { - pTimes[i].setTime = pScrPriv->lastSetTime; - pTimes[i].configTime = pScrPriv->lastConfigTime; - } - } -} - -static void -RRResetProc (ExtensionEntry *extEntry) -{ -} - -static Bool -RRCloseScreen (int i, ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - int j; - - unwrap (pScrPriv, pScreen, CloseScreen); - for (j = pScrPriv->numCrtcs - 1; j >= 0; j--) - RRCrtcDestroy (pScrPriv->crtcs[j]); - for (j = pScrPriv->numOutputs - 1; j >= 0; j--) - RROutputDestroy (pScrPriv->outputs[j]); - - xfree (pScrPriv); - RRNScreens -= 1; /* ok, one fewer screen with RandR running */ - return (*pScreen->CloseScreen) (i, pScreen); -} - -static void -SRRScreenChangeNotifyEvent(xRRScreenChangeNotifyEvent *from, - xRRScreenChangeNotifyEvent *to) -{ - to->type = from->type; - to->rotation = from->rotation; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->configTimestamp, to->configTimestamp); - cpswapl(from->root, to->root); - cpswapl(from->window, to->window); - cpswaps(from->sizeID, to->sizeID); - cpswaps(from->widthInPixels, to->widthInPixels); - cpswaps(from->heightInPixels, to->heightInPixels); - cpswaps(from->widthInMillimeters, to->widthInMillimeters); - cpswaps(from->heightInMillimeters, to->heightInMillimeters); - cpswaps(from->subpixelOrder, to->subpixelOrder); -} - -static void -SRRCrtcChangeNotifyEvent(xRRCrtcChangeNotifyEvent *from, - xRRCrtcChangeNotifyEvent *to) -{ - to->type = from->type; - to->subCode = from->subCode; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->window, to->window); - cpswapl(from->crtc, to->crtc); - cpswapl(from->mode, to->mode); - cpswapl(from->window, to->window); - cpswaps(from->rotation, to->rotation); - cpswaps(from->x, to->x); - cpswaps(from->y, to->y); - cpswaps(from->width, to->width); - cpswaps(from->height, to->height); -} - -static void -SRROutputChangeNotifyEvent(xRROutputChangeNotifyEvent *from, - xRROutputChangeNotifyEvent *to) -{ - to->type = from->type; - to->subCode = from->subCode; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->timestamp, to->timestamp); - cpswapl(from->configTimestamp, to->configTimestamp); - cpswapl(from->window, to->window); - cpswapl(from->output, to->output); - cpswapl(from->crtc, to->crtc); - cpswapl(from->mode, to->mode); - cpswaps(from->rotation, to->rotation); -} - -static void -SRROutputPropertyNotifyEvent(xRROutputPropertyNotifyEvent *from, - xRROutputPropertyNotifyEvent *to) -{ - to->type = from->type; - to->subCode = from->subCode; - cpswaps(from->sequenceNumber, to->sequenceNumber); - cpswapl(from->window, to->window); - cpswapl(from->output, to->output); - cpswapl(from->atom, to->atom); - cpswapl(from->timestamp, to->timestamp); -} - -static void -SRRNotifyEvent (xEvent *from, - xEvent *to) -{ - switch (from->u.u.detail) { - case RRNotify_CrtcChange: - SRRCrtcChangeNotifyEvent ((xRRCrtcChangeNotifyEvent *) from, - (xRRCrtcChangeNotifyEvent *) to); - break; - case RRNotify_OutputChange: - SRROutputChangeNotifyEvent ((xRROutputChangeNotifyEvent *) from, - (xRROutputChangeNotifyEvent *) to); - break; - case RRNotify_OutputProperty: - SRROutputPropertyNotifyEvent ((xRROutputPropertyNotifyEvent *) from, - (xRROutputPropertyNotifyEvent *) to); - break; - default: - break; - } -} - -static int RRGeneration; - -Bool RRInit (void) -{ - if (RRGeneration != serverGeneration) - { - if (!RRModeInit ()) - return FALSE; - if (!RRCrtcInit ()) - return FALSE; - if (!RROutputInit ()) - return FALSE; - RRGeneration = serverGeneration; - } - return TRUE; -} - -Bool RRScreenInit(ScreenPtr pScreen) -{ - rrScrPrivPtr pScrPriv; - - if (!RRInit ()) - return FALSE; - - pScrPriv = (rrScrPrivPtr) xcalloc (1, sizeof (rrScrPrivRec)); - if (!pScrPriv) - return FALSE; - - SetRRScreen(pScreen, pScrPriv); - - /* - * Calling function best set these function vectors - */ - pScrPriv->rrGetInfo = 0; - pScrPriv->maxWidth = pScrPriv->minWidth = pScreen->width; - pScrPriv->maxHeight = pScrPriv->minHeight = pScreen->height; - - pScrPriv->width = pScreen->width; - pScrPriv->height = pScreen->height; - pScrPriv->mmWidth = pScreen->mmWidth; - pScrPriv->mmHeight = pScreen->mmHeight; -#if RANDR_12_INTERFACE - pScrPriv->rrScreenSetSize = NULL; - pScrPriv->rrCrtcSet = NULL; - pScrPriv->rrCrtcSetGamma = NULL; -#endif -#if RANDR_10_INTERFACE - pScrPriv->rrSetConfig = 0; - pScrPriv->rotations = RR_Rotate_0; - pScrPriv->reqWidth = pScreen->width; - pScrPriv->reqHeight = pScreen->height; - pScrPriv->nSizes = 0; - pScrPriv->pSizes = NULL; - pScrPriv->rotation = RR_Rotate_0; - pScrPriv->rate = 0; - pScrPriv->size = 0; -#endif - - /* - * This value doesn't really matter -- any client must call - * GetScreenInfo before reading it which will automatically update - * the time - */ - pScrPriv->lastSetTime = currentTime; - pScrPriv->lastConfigTime = currentTime; - - wrap (pScrPriv, pScreen, CloseScreen, RRCloseScreen); - - pScrPriv->numOutputs = 0; - pScrPriv->outputs = NULL; - pScrPriv->numCrtcs = 0; - pScrPriv->crtcs = NULL; - - RRNScreens += 1; /* keep count of screens that implement randr */ - return TRUE; -} - -/*ARGSUSED*/ -static int -RRFreeClient (pointer data, XID id) -{ - RREventPtr pRREvent; - WindowPtr pWin; - RREventPtr *pHead, pCur, pPrev; - - pRREvent = (RREventPtr) data; - pWin = pRREvent->window; - pHead = (RREventPtr *) LookupIDByType(pWin->drawable.id, RREventType); - if (pHead) { - pPrev = 0; - for (pCur = *pHead; pCur && pCur != pRREvent; pCur=pCur->next) - pPrev = pCur; - if (pCur) - { - if (pPrev) - pPrev->next = pRREvent->next; - else - *pHead = pRREvent->next; - } - } - xfree ((pointer) pRREvent); - return 1; -} - -/*ARGSUSED*/ -static int -RRFreeEvents (pointer data, XID id) -{ - RREventPtr *pHead, pCur, pNext; - - pHead = (RREventPtr *) data; - for (pCur = *pHead; pCur; pCur = pNext) { - pNext = pCur->next; - FreeResource (pCur->clientResource, RRClientType); - xfree ((pointer) pCur); - } - xfree ((pointer) pHead); - return 1; -} - -void -RRExtensionInit (void) -{ - ExtensionEntry *extEntry; - - if (RRNScreens == 0) return; - - if (!dixRequestPrivate(RRClientPrivateKey, - sizeof (RRClientRec) + - screenInfo.numScreens * sizeof (RRTimesRec))) - return; - if (!AddCallback (&ClientStateCallback, RRClientCallback, 0)) - return; - - RRClientType = CreateNewResourceType(RRFreeClient); - if (!RRClientType) - return; - RREventType = CreateNewResourceType(RRFreeEvents); - if (!RREventType) - return; - extEntry = AddExtension (RANDR_NAME, RRNumberEvents, RRNumberErrors, - ProcRRDispatch, SProcRRDispatch, - RRResetProc, StandardMinorOpcode); - if (!extEntry) - return; - RRErrorBase = extEntry->errorBase; - RREventBase = extEntry->eventBase; - EventSwapVector[RREventBase + RRScreenChangeNotify] = (EventSwapPtr) - SRRScreenChangeNotifyEvent; - EventSwapVector[RREventBase + RRNotify] = (EventSwapPtr) - SRRNotifyEvent; -#ifdef PANORAMIX - RRXineramaExtensionInit(); -#endif -} - -static int -TellChanged (WindowPtr pWin, pointer value) -{ - RREventPtr *pHead, pRREvent; - ClientPtr client; - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv(pScreen); - int i; - - pHead = (RREventPtr *) LookupIDByType (pWin->drawable.id, RREventType); - if (!pHead) - return WT_WALKCHILDREN; - - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) - { - client = pRREvent->client; - if (client == serverClient || client->clientGone) - continue; - - if (pRREvent->mask & RRScreenChangeNotifyMask) - RRDeliverScreenEvent (client, pWin, pScreen); - - if (pRREvent->mask & RRCrtcChangeNotifyMask) - { - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - if (crtc->changed) - RRDeliverCrtcEvent (client, pWin, crtc); - } - } - - if (pRREvent->mask & RROutputChangeNotifyMask) - { - for (i = 0; i < pScrPriv->numOutputs; i++) - { - RROutputPtr output = pScrPriv->outputs[i]; - if (output->changed) - RRDeliverOutputEvent (client, pWin, output); - } - } - } - return WT_WALKCHILDREN; -} - -/* - * Something changed; send events and adjust pointer position - */ -void -RRTellChanged (ScreenPtr pScreen) -{ - rrScrPriv (pScreen); - int i; - - if (pScrPriv->changed) - { - UpdateCurrentTime (); - if (pScrPriv->configChanged) - { - pScrPriv->lastConfigTime = currentTime; - pScrPriv->configChanged = FALSE; - } - pScrPriv->changed = FALSE; - WalkTree (pScreen, TellChanged, (pointer) pScreen); - for (i = 0; i < pScrPriv->numOutputs; i++) - pScrPriv->outputs[i]->changed = FALSE; - for (i = 0; i < pScrPriv->numCrtcs; i++) - pScrPriv->crtcs[i]->changed = FALSE; - if (pScrPriv->layoutChanged) - { - pScrPriv->layoutChanged = FALSE; - RRPointerScreenConfigured (pScreen); - RRSendConfigNotify (pScreen); - } - } -} - -/* - * Return the first output which is connected to an active CRTC - * Used in emulating 1.0 behaviour - */ -RROutputPtr -RRFirstOutput (ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - RROutputPtr output; - int i, j; - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - for (j = 0; j < pScrPriv->numOutputs; j++) - { - output = pScrPriv->outputs[j]; - if (output->crtc == crtc) - return output; - } - } - return NULL; -} - -CARD16 -RRVerticalRefresh (xRRModeInfo *mode) -{ - CARD32 refresh; - CARD32 dots = mode->hTotal * mode->vTotal; - if (!dots) - return 0; - refresh = (mode->dotClock + dots/2) / dots; - if (refresh > 0xffff) - refresh = 0xffff; - return (CARD16) refresh; -} - -static int -ProcRRDispatch (ClientPtr client) -{ - REQUEST(xReq); - if (stuff->data >= RRNumberRequests || !ProcRandrVector[stuff->data]) - return BadRequest; - return (*ProcRandrVector[stuff->data]) (client); -} - -static int -SProcRRDispatch (ClientPtr client) -{ - REQUEST(xReq); - if (stuff->data >= RRNumberRequests || !ProcRandrVector[stuff->data]) - return BadRequest; - return (*SProcRandrVector[stuff->data]) (client); -} - diff --git a/nx-X11/programs/Xserver/randr/randr.h.NX.original b/nx-X11/programs/Xserver/randr/randr.h.NX.original deleted file mode 100644 index 17e6ef9f6..000000000 --- a/nx-X11/programs/Xserver/randr/randr.h.NX.original +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright © 2000 Compaq Computer Corporation - * Copyright © 2002 Hewlett Packard Company - * Copyright © 2006 Intel Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - * - * Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc. - * Keith Packard, Intel Corporation - */ - -#ifndef _RANDR_H_ -#define _RANDR_H_ - -typedef unsigned short Rotation; -typedef unsigned short SizeID; -typedef unsigned short SubpixelOrder; -typedef unsigned short Connection; -typedef unsigned short XRandrRotation; -typedef unsigned short XRandrSizeID; -typedef unsigned short XRandrSubpixelOrder; -typedef unsigned long XRandrModeFlags; - -#define RANDR_NAME "RANDR" -#define RANDR_MAJOR 1 -#define RANDR_MINOR 2 - -#define RRNumberErrors 3 -#define RRNumberEvents 2 -#define RRNumberRequests 25 - -#define X_RRQueryVersion 0 -/* we skip 1 to make old clients fail pretty immediately */ -#define X_RROldGetScreenInfo 1 -#define X_RR1_0SetScreenConfig 2 -/* V1.0 apps share the same set screen config request id */ -#define X_RRSetScreenConfig 2 -#define X_RROldScreenChangeSelectInput 3 -/* 3 used to be ScreenChangeSelectInput; deprecated */ -#define X_RRSelectInput 4 -#define X_RRGetScreenInfo 5 - -/* V1.2 additions */ -#define X_RRGetScreenSizeRange 6 -#define X_RRSetScreenSize 7 -#define X_RRGetScreenResources 8 -#define X_RRGetOutputInfo 9 -#define X_RRListOutputProperties 10 -#define X_RRQueryOutputProperty 11 -#define X_RRConfigureOutputProperty 12 -#define X_RRChangeOutputProperty 13 -#define X_RRDeleteOutputProperty 14 -#define X_RRGetOutputProperty 15 -#define X_RRCreateMode 16 -#define X_RRDestroyMode 17 -#define X_RRAddOutputMode 18 -#define X_RRDeleteOutputMode 19 -#define X_RRGetCrtcInfo 20 -#define X_RRSetCrtcConfig 21 -#define X_RRGetCrtcGammaSize 22 -#define X_RRGetCrtcGamma 23 -#define X_RRSetCrtcGamma 24 - -/* Event selection bits */ -#define RRScreenChangeNotifyMask (1L << 0) -/* V1.2 additions */ -#define RRCrtcChangeNotifyMask (1L << 1) -#define RROutputChangeNotifyMask (1L << 2) -#define RROutputPropertyNotifyMask (1L << 3) - -/* Event codes */ -#define RRScreenChangeNotify 0 -/* V1.2 additions */ -#define RRNotify 1 -/* RRNotify Subcodes */ -#define RRNotify_CrtcChange 0 -#define RRNotify_OutputChange 1 -#define RRNotify_OutputProperty 2 - -/* used in the rotation field; rotation and reflection in 0.1 proto. */ -#define RR_Rotate_0 1 -#define RR_Rotate_90 2 -#define RR_Rotate_180 4 -#define RR_Rotate_270 8 - -/* new in 1.0 protocol, to allow reflection of screen */ - -#define RR_Reflect_X 16 -#define RR_Reflect_Y 32 - -#define RRSetConfigSuccess 0 -#define RRSetConfigInvalidConfigTime 1 -#define RRSetConfigInvalidTime 2 -#define RRSetConfigFailed 3 - -/* new in 1.2 protocol */ - -#define RR_HSyncPositive 0x00000001 -#define RR_HSyncNegative 0x00000002 -#define RR_VSyncPositive 0x00000004 -#define RR_VSyncNegative 0x00000008 -#define RR_Interlace 0x00000010 -#define RR_DoubleScan 0x00000020 -#define RR_CSync 0x00000040 -#define RR_CSyncPositive 0x00000080 -#define RR_CSyncNegative 0x00000100 -#define RR_HSkewPresent 0x00000200 -#define RR_BCast 0x00000400 -#define RR_PixelMultiplex 0x00000800 -#define RR_DoubleClock 0x00001000 -#define RR_ClockDivideBy2 0x00002000 - -#define RR_Connected 0 -#define RR_Disconnected 1 -#define RR_UnknownConnection 2 - -#define BadRROutput 0 -#define BadRRCrtc 1 -#define BadRRMode 2 - -/* Conventional RandR output properties */ - -#define RR_PROPERTY_RANDR_EDID "RANDR_EDID" - -#endif /* _RANDR_H_ */ diff --git a/nx-X11/programs/Xserver/randr/randr.h.X.original b/nx-X11/programs/Xserver/randr/randr.h.X.original deleted file mode 100644 index e69de29bb..000000000 diff --git a/nx-X11/programs/Xserver/randr/randrproto.h.NX.original b/nx-X11/programs/Xserver/randr/randrproto.h.NX.original deleted file mode 100644 index 7d5c139e9..000000000 --- a/nx-X11/programs/Xserver/randr/randrproto.h.NX.original +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Copyright © 2000 Compaq Computer Corporation - * Copyright © 2002 Hewlett-Packard Company - * Copyright © 2006 Intel Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - * - * Author: Jim Gettys, Hewlett-Packard Company, Inc. - * Keith Packard, Intel Corporation - */ - -/* note that RANDR 1.0 is incompatible with version 0.0, or 0.1 */ -/* V1.0 removes depth switching from the protocol */ -#ifndef _XRANDRP_H_ -#define _XRANDRP_H_ - -/*#include */ -#include "randr.h" - -#define Window CARD32 -#define Drawable CARD32 -#define Font CARD32 -#define Pixmap CARD32 -#define Cursor CARD32 -#define Colormap CARD32 -#define GContext CARD32 -#define Atom CARD32 -#define Time CARD32 -#define KeyCode CARD8 -#define KeySym CARD32 -#define RROutput CARD32 -#define RRMode CARD32 -#define RRCrtc CARD32 -#define RRModeFlags CARD32 - -#define Rotation CARD16 -#define SizeID CARD16 -#define SubpixelOrder CARD16 - -/* - * data structures - */ - -typedef struct { - CARD16 widthInPixels B16; - CARD16 heightInPixels B16; - CARD16 widthInMillimeters B16; - CARD16 heightInMillimeters B16; -} xScreenSizes; -#define sz_xScreenSizes 8 - -/* - * requests and replies - */ - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - CARD32 majorVersion B32; - CARD32 minorVersion B32; -} xRRQueryVersionReq; -#define sz_xRRQueryVersionReq 12 - -typedef struct { - BYTE type; /* X_Reply */ - BYTE pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 majorVersion B32; - CARD32 minorVersion B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xRRQueryVersionReply; -#define sz_xRRQueryVersionReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Window window B32; -} xRRGetScreenInfoReq; -#define sz_xRRGetScreenInfoReq 8 - -/* - * the xRRScreenInfoReply structure is followed by: - * - * the size information - */ - - -typedef struct { - BYTE type; /* X_Reply */ - BYTE setOfRotations; - CARD16 sequenceNumber B16; - CARD32 length B32; - Window root B32; - Time timestamp B32; - Time configTimestamp B32; - CARD16 nSizes B16; - SizeID sizeID B16; - Rotation rotation B16; - CARD16 rate B16; - CARD16 nrateEnts B16; - CARD16 pad B16; -} xRRGetScreenInfoReply; -#define sz_xRRGetScreenInfoReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Drawable drawable B32; - Time timestamp B32; - Time configTimestamp B32; - SizeID sizeID B16; - Rotation rotation B16; -} xRR1_0SetScreenConfigReq; -#define sz_xRR1_0SetScreenConfigReq 20 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Drawable drawable B32; - Time timestamp B32; - Time configTimestamp B32; - SizeID sizeID B16; - Rotation rotation B16; - CARD16 rate B16; - CARD16 pad B16; -} xRRSetScreenConfigReq; -#define sz_xRRSetScreenConfigReq 24 - -typedef struct { - BYTE type; /* X_Reply */ - CARD8 status; - CARD16 sequenceNumber B16; - CARD32 length B32; - Time newTimestamp B32; - Time newConfigTimestamp B32; - Window root; - CARD16 subpixelOrder B16; - CARD16 pad4 B16; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xRRSetScreenConfigReply; -#define sz_xRRSetScreenConfigReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Window window B32; - CARD16 enable B16; - CARD16 pad2 B16; -} xRRSelectInputReq; -#define sz_xRRSelectInputReq 12 - -/* - * Additions for version 1.2 - */ - -typedef struct _xRRModeInfo { - RRMode id B32; - CARD16 width B16; - CARD16 height B16; - CARD32 dotClock B32; - CARD16 hSyncStart B16; - CARD16 hSyncEnd B16; - CARD16 hTotal B16; - CARD16 hSkew B16; - CARD16 vSyncStart B16; - CARD16 vSyncEnd B16; - CARD16 vTotal B16; - CARD16 nameLength B16; - RRModeFlags modeFlags B32; -} xRRModeInfo; -#define sz_xRRModeInfo 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Window window B32; -} xRRGetScreenSizeRangeReq; -#define sz_xRRGetScreenSizeRangeReq 8 - -typedef struct { - BYTE type; /* X_Reply */ - CARD8 pad; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 minWidth B16; - CARD16 minHeight B16; - CARD16 maxWidth B16; - CARD16 maxHeight B16; - CARD32 pad0 B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; -} xRRGetScreenSizeRangeReply; -#define sz_xRRGetScreenSizeRangeReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Window window B32; - CARD16 width B16; - CARD16 height B16; - CARD32 widthInMillimeters B32; - CARD32 heightInMillimeters B32; -} xRRSetScreenSizeReq; -#define sz_xRRSetScreenSizeReq 20 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Window window B32; -} xRRGetScreenResourcesReq; -#define sz_xRRGetScreenResourcesReq 8 - -typedef struct { - BYTE type; - CARD8 pad; - CARD16 sequenceNumber B16; - CARD32 length B32; - Time timestamp B32; - Time configTimestamp B32; - CARD16 nCrtcs B16; - CARD16 nOutputs B16; - CARD16 nModes B16; - CARD16 nbytesNames B16; - CARD32 pad1 B32; - CARD32 pad2 B32; -} xRRGetScreenResourcesReply; -#define sz_xRRGetScreenResourcesReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - Time configTimestamp B32; -} xRRGetOutputInfoReq; -#define sz_xRRGetOutputInfoReq 12 - -typedef struct { - BYTE type; - CARD8 status; - CARD16 sequenceNumber B16; - CARD32 length B32; - Time timestamp B32; - RRCrtc crtc B32; - CARD32 mmWidth B32; - CARD32 mmHeight B32; - CARD8 connection; - CARD8 subpixelOrder; - CARD16 nCrtcs B16; - CARD16 nModes B16; - CARD16 nPreferred B16; - CARD16 nClones B16; - CARD16 nameLength B16; -} xRRGetOutputInfoReply; -#define sz_xRRGetOutputInfoReply 36 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; -} xRRListOutputPropertiesReq; -#define sz_xRRListOutputPropertiesReq 8 - -typedef struct { - BYTE type; - CARD8 pad0; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 nAtoms B16; - CARD16 pad1 B16; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xRRListOutputPropertiesReply; -#define sz_xRRListOutputPropertiesReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - Atom property B32; -} xRRQueryOutputPropertyReq; -#define sz_xRRQueryOutputPropertyReq 12 - -typedef struct { - BYTE type; - BYTE pad0; - CARD16 sequenceNumber B16; - CARD32 length B32; - BOOL pending; - BOOL range; - BOOL immutable; - BYTE pad1; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xRRQueryOutputPropertyReply; -#define sz_xRRQueryOutputPropertyReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - Atom property B32; - BOOL pending; - BOOL range; - CARD16 pad B16; -} xRRConfigureOutputPropertyReq; -#define sz_xRRConfigureOutputPropertyReq 16 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - Atom property B32; - Atom type B32; - CARD8 format; - CARD8 mode; - CARD16 pad; - CARD32 nUnits B32; -} xRRChangeOutputPropertyReq; -#define sz_xRRChangeOutputPropertyReq 24 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - Atom property B32; -} xRRDeleteOutputPropertyReq; -#define sz_xRRDeleteOutputPropertyReq 12 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - Atom property B32; - Atom type B32; - CARD32 longOffset B32; - CARD32 longLength B32; -#ifdef __cplusplus - BOOL _delete; -#else - BOOL delete; -#endif - BOOL pending; - CARD16 pad1 B16; -} xRRGetOutputPropertyReq; -#define sz_xRRGetOutputPropertyReq 28 - -typedef struct { - BYTE type; - CARD8 format; - CARD16 sequenceNumber B16; - CARD32 length B32; - Atom propertyType B32; - CARD32 bytesAfter B32; - CARD32 nItems B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; -} xRRGetOutputPropertyReply; -#define sz_xRRGetOutputPropertyReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - Window window B32; - xRRModeInfo modeInfo; -} xRRCreateModeReq; -#define sz_xRRCreateModeReq 40 - -typedef struct { - BYTE type; - CARD8 pad0; - CARD16 sequenceNumber B16; - CARD32 length B32; - RRMode mode B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xRRCreateModeReply; -#define sz_xRRCreateModeReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RRMode mode B32; -} xRRDestroyModeReq; -#define sz_xRRDestroyModeReq 8 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - RRMode mode B32; -} xRRAddOutputModeReq; -#define sz_xRRAddOutputModeReq 12 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RROutput output B32; - RRMode mode B32; -} xRRDeleteOutputModeReq; -#define sz_xRRDeleteOutputModeReq 12 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RRCrtc crtc B32; - Time configTimestamp B32; -} xRRGetCrtcInfoReq; -#define sz_xRRGetCrtcInfoReq 12 - -typedef struct { - BYTE type; - CARD8 status; - CARD16 sequenceNumber B16; - CARD32 length B32; - Time timestamp B32; - INT16 x B16; - INT16 y B16; - CARD16 width B16; - CARD16 height B16; - RRMode mode B32; - Rotation rotation B16; - Rotation rotations B16; - CARD16 nOutput B16; - CARD16 nPossibleOutput B16; -} xRRGetCrtcInfoReply; -#define sz_xRRGetCrtcInfoReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RRCrtc crtc B32; - Time timestamp B32; - Time configTimestamp B32; - INT16 x B16; - INT16 y B16; - RRMode mode B32; - Rotation rotation B16; - CARD16 pad B16; -} xRRSetCrtcConfigReq; -#define sz_xRRSetCrtcConfigReq 28 - -typedef struct { - BYTE type; - CARD8 status; - CARD16 sequenceNumber B16; - CARD32 length B32; - Time newTimestamp B32; - CARD32 pad1 B32; - CARD32 pad2 B16; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xRRSetCrtcConfigReply; -#define sz_xRRSetCrtcConfigReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RRCrtc crtc B32; -} xRRGetCrtcGammaSizeReq; -#define sz_xRRGetCrtcGammaSizeReq 8 - -typedef struct { - BYTE type; - CARD8 status; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 size B16; - CARD16 pad1 B16; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xRRGetCrtcGammaSizeReply; -#define sz_xRRGetCrtcGammaSizeReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RRCrtc crtc B32; -} xRRGetCrtcGammaReq; -#define sz_xRRGetCrtcGammaReq 8 - -typedef struct { - BYTE type; - CARD8 status; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 size B16; - CARD16 pad1 B16; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xRRGetCrtcGammaReply; -#define sz_xRRGetCrtcGammaReply 32 - -typedef struct { - CARD8 reqType; - CARD8 randrReqType; - CARD16 length B16; - RRCrtc crtc B32; - CARD16 size B16; - CARD16 pad1 B16; -} xRRSetCrtcGammaReq; -#define sz_xRRSetCrtcGammaReq 12 - -/* - * event - */ -typedef struct { - CARD8 type; /* always evBase + ScreenChangeNotify */ - CARD8 rotation; /* new rotation */ - CARD16 sequenceNumber B16; - Time timestamp B32; /* time screen was changed */ - Time configTimestamp B32; /* time config data was changed */ - Window root B32; /* root window */ - Window window B32; /* window requesting notification */ - SizeID sizeID B16; /* new size ID */ - CARD16 subpixelOrder B16; /* subpixel order */ - CARD16 widthInPixels B16; /* new size */ - CARD16 heightInPixels B16; - CARD16 widthInMillimeters B16; - CARD16 heightInMillimeters B16; -} xRRScreenChangeNotifyEvent; -#define sz_xRRScreenChangeNotifyEvent 32 - -typedef struct { - CARD8 type; /* always evBase + RRNotify */ - CARD8 subCode; /* RRNotify_CrtcChange */ - CARD16 sequenceNumber B16; - Time timestamp B32; /* time crtc was changed */ - Window window B32; /* window requesting notification */ - RRCrtc crtc B32; /* affected CRTC */ - RRMode mode B32; /* current mode */ - CARD16 rotation B16; /* rotation and reflection */ - CARD16 pad1 B16; /* unused */ - INT16 x B16; /* new location */ - INT16 y B16; - CARD16 width B16; /* new size */ - CARD16 height B16; -} xRRCrtcChangeNotifyEvent; -#define sz_xRRCrtcChangeNotifyEvent 32 - -typedef struct { - CARD8 type; /* always evBase + RRNotify */ - CARD8 subCode; /* RRNotify_OutputChange */ - CARD16 sequenceNumber B16; - Time timestamp B32; /* time crtc was changed */ - Time configTimestamp B32; /* time crtc was changed */ - Window window B32; /* window requesting notification */ - RROutput output B32; /* affected output */ - RRCrtc crtc B32; /* current crtc */ - RRMode mode B32; /* current mode */ - CARD16 rotation B16; /* rotation and reflection */ - CARD8 connection; /* connection status */ - CARD8 subpixelOrder; /* subpixel order */ -} xRROutputChangeNotifyEvent; -#define sz_xRROutputChangeNotifyEvent 32 - -typedef struct { - CARD8 type; /* always evBase + RRNotify */ - CARD8 subCode; /* RRNotify_OutputProperty */ - CARD16 sequenceNumber B16; - Window window B32; /* window requesting notification */ - RROutput output B32; /* affected output */ - Atom atom B32; /* property name */ - Time timestamp B32; /* time crtc was changed */ - CARD8 state; /* NewValue or Deleted */ - CARD8 pad1; - CARD16 pad2 B16; - CARD32 pad3 B32; - CARD32 pad4 B32; -} xRROutputPropertyNotifyEvent; -#define sz_xRROutputPropertyNotifyEvent 32 - -#undef RRModeFlags -#undef RRCrtc -#undef RRMode -#undef RROutput -#undef RRMode -#undef RRCrtc -#undef Drawable -#undef Window -#undef Font -#undef Pixmap -#undef Cursor -#undef Colormap -#undef GContext -#undef Atom -#undef Time -#undef KeyCode -#undef KeySym -#undef Rotation -#undef SizeID -#undef SubpixelOrder - -#endif /* _XRANDRP_H_ */ diff --git a/nx-X11/programs/Xserver/randr/randrproto.h.X.original b/nx-X11/programs/Xserver/randr/randrproto.h.X.original deleted file mode 100644 index e69de29bb..000000000 diff --git a/nx-X11/programs/Xserver/randr/registry.h.NX.original b/nx-X11/programs/Xserver/randr/registry.h.NX.original deleted file mode 100644 index 29e5fdfd3..000000000 --- a/nx-X11/programs/Xserver/randr/registry.h.NX.original +++ /dev/null @@ -1,64 +0,0 @@ -/*********************************************************** - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************/ - -#ifndef DIX_REGISTRY_H -#define DIX_REGISTRY_H - -/* - * Result returned from any unsuccessful lookup - */ -#define XREGISTRY_UNKNOWN "" - -#ifdef XREGISTRY - -#include "resource.h" -#include "extnsionst.h" - -/* Internal string registry - for auditing, debugging, security, etc. */ - -/* - * Registration functions. The name string is not copied, so it must - * not be a stack variable. - */ -void RegisterResourceName(RESTYPE type, char *name); -void RegisterExtensionNames(ExtensionEntry *ext); - -/* - * Lookup functions. The returned string must not be modified or freed. - */ -const char *LookupMajorName(int major); -const char *LookupRequestName(int major, int minor); -const char *LookupEventName(int event); -const char *LookupErrorName(int error); -const char *LookupResourceName(RESTYPE rtype); - -/* - * Setup and teardown - */ -void dixResetRegistry(void); - -#else /* XREGISTRY */ - -/* Define calls away when the registry is not being built. */ - -#define RegisterResourceName(a, b) { ; } -#define RegisterExtensionNames(a) { ; } - -#define LookupMajorName(a) XREGISTRY_UNKNOWN -#define LookupRequestName(a, b) XREGISTRY_UNKNOWN -#define LookupEventName(a) XREGISTRY_UNKNOWN -#define LookupErrorName(a) XREGISTRY_UNKNOWN -#define LookupResourceName(a) XREGISTRY_UNKNOWN - -#define dixResetRegistry() { ; } - -#endif /* XREGISTRY */ -#endif /* DIX_REGISTRY_H */ diff --git a/nx-X11/programs/Xserver/randr/registry.h.X.original b/nx-X11/programs/Xserver/randr/registry.h.X.original deleted file mode 100644 index e69de29bb..000000000 diff --git a/nx-X11/programs/Xserver/randr/rrcrtc.c.NX.original b/nx-X11/programs/Xserver/randr/rrcrtc.c.NX.original deleted file mode 100644 index fb82a80df..000000000 --- a/nx-X11/programs/Xserver/randr/rrcrtc.c.NX.original +++ /dev/null @@ -1,984 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#include "randrstr.h" -#include "swaprep.h" -#include "registry.h" - -RESTYPE RRCrtcType; - -/* - * Notify the CRTC of some change - */ -void -RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged) -{ - ScreenPtr pScreen = crtc->pScreen; - - crtc->changed = TRUE; - if (pScreen) - { - rrScrPriv(pScreen); - - pScrPriv->changed = TRUE; - /* - * Send ConfigureNotify on any layout change - */ - if (layoutChanged) - pScrPriv->layoutChanged = TRUE; - } -} - -/* - * Create a CRTC - */ -RRCrtcPtr -RRCrtcCreate (ScreenPtr pScreen, void *devPrivate) -{ - RRCrtcPtr crtc; - RRCrtcPtr *crtcs; - rrScrPrivPtr pScrPriv; - - if (!RRInit()) - return NULL; - - pScrPriv = rrGetScrPriv(pScreen); - - /* make space for the crtc pointer */ - if (pScrPriv->numCrtcs) - crtcs = xrealloc (pScrPriv->crtcs, - (pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr)); - else - crtcs = xalloc (sizeof (RRCrtcPtr)); - if (!crtcs) - return FALSE; - pScrPriv->crtcs = crtcs; - - crtc = xcalloc (1, sizeof (RRCrtcRec)); - if (!crtc) - return NULL; - crtc->id = FakeClientID (0); - crtc->pScreen = pScreen; - crtc->mode = NULL; - crtc->x = 0; - crtc->y = 0; - crtc->rotation = RR_Rotate_0; - crtc->rotations = RR_Rotate_0; - crtc->outputs = NULL; - crtc->numOutputs = 0; - crtc->gammaSize = 0; - crtc->gammaRed = crtc->gammaBlue = crtc->gammaGreen = NULL; - crtc->changed = FALSE; - crtc->devPrivate = devPrivate; - - if (!AddResource (crtc->id, RRCrtcType, (pointer) crtc)) - return NULL; - - /* attach the screen and crtc together */ - crtc->pScreen = pScreen; - pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc; - - return crtc; -} - -/* - * Set the allowed rotations on a CRTC - */ -void -RRCrtcSetRotations (RRCrtcPtr crtc, Rotation rotations) -{ - crtc->rotations = rotations; -} - -/* - * Notify the extension that the Crtc has been reconfigured, - * the driver calls this whenever it has updated the mode - */ -Bool -RRCrtcNotify (RRCrtcPtr crtc, - RRModePtr mode, - int x, - int y, - Rotation rotation, - int numOutputs, - RROutputPtr *outputs) -{ - int i, j; - - /* - * Check to see if any of the new outputs were - * not in the old list and mark them as changed - */ - for (i = 0; i < numOutputs; i++) - { - for (j = 0; j < crtc->numOutputs; j++) - if (outputs[i] == crtc->outputs[j]) - break; - if (j == crtc->numOutputs) - { - outputs[i]->crtc = crtc; - RROutputChanged (outputs[i], FALSE); - RRCrtcChanged (crtc, FALSE); - } - } - /* - * Check to see if any of the old outputs are - * not in the new list and mark them as changed - */ - for (j = 0; j < crtc->numOutputs; j++) - { - for (i = 0; i < numOutputs; i++) - if (outputs[i] == crtc->outputs[j]) - break; - if (i == numOutputs) - { - if (crtc->outputs[j]->crtc == crtc) - crtc->outputs[j]->crtc = NULL; - RROutputChanged (crtc->outputs[j], FALSE); - RRCrtcChanged (crtc, FALSE); - } - } - /* - * Reallocate the crtc output array if necessary - */ - if (numOutputs != crtc->numOutputs) - { - RROutputPtr *newoutputs; - - if (numOutputs) - { - if (crtc->numOutputs) - newoutputs = xrealloc (crtc->outputs, - numOutputs * sizeof (RROutputPtr)); - else - newoutputs = xalloc (numOutputs * sizeof (RROutputPtr)); - if (!newoutputs) - return FALSE; - } - else - { - if (crtc->outputs) - xfree (crtc->outputs); - newoutputs = NULL; - } - crtc->outputs = newoutputs; - crtc->numOutputs = numOutputs; - } - /* - * Copy the new list of outputs into the crtc - */ - memcpy (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)); - /* - * Update remaining crtc fields - */ - if (mode != crtc->mode) - { - if (crtc->mode) - RRModeDestroy (crtc->mode); - crtc->mode = mode; - if (mode != NULL) - mode->refcnt++; - RRCrtcChanged (crtc, TRUE); - } - if (x != crtc->x) - { - crtc->x = x; - RRCrtcChanged (crtc, TRUE); - } - if (y != crtc->y) - { - crtc->y = y; - RRCrtcChanged (crtc, TRUE); - } - if (rotation != crtc->rotation) - { - crtc->rotation = rotation; - RRCrtcChanged (crtc, TRUE); - } - return TRUE; -} - -void -RRDeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv (pScreen); - xRRCrtcChangeNotifyEvent ce; - RRModePtr mode = crtc->mode; - - ce.type = RRNotify + RREventBase; - ce.subCode = RRNotify_CrtcChange; - ce.sequenceNumber = client->sequence; - ce.timestamp = pScrPriv->lastSetTime.milliseconds; - ce.window = pWin->drawable.id; - ce.crtc = crtc->id; - ce.rotation = crtc->rotation; - if (mode) - { - ce.mode = mode->mode.id; - ce.x = crtc->x; - ce.y = crtc->y; - ce.width = mode->mode.width; - ce.height = mode->mode.height; - } - else - { - ce.mode = None; - ce.x = 0; - ce.y = 0; - ce.width = 0; - ce.height = 0; - } - WriteEventsToClient (client, 1, (xEvent *) &ce); -} - -static Bool -RRCrtcPendingProperties (RRCrtcPtr crtc) -{ - ScreenPtr pScreen = crtc->pScreen; - rrScrPriv(pScreen); - int o; - - for (o = 0; o < pScrPriv->numOutputs; o++) - { - RROutputPtr output = pScrPriv->outputs[o]; - if (output->crtc == crtc && output->pendingProperties) - return TRUE; - } - return FALSE; -} - -/* - * Request that the Crtc be reconfigured - */ -Bool -RRCrtcSet (RRCrtcPtr crtc, - RRModePtr mode, - int x, - int y, - Rotation rotation, - int numOutputs, - RROutputPtr *outputs) -{ - ScreenPtr pScreen = crtc->pScreen; - Bool ret = FALSE; - rrScrPriv(pScreen); - - /* See if nothing changed */ - if (crtc->mode == mode && - crtc->x == x && - crtc->y == y && - crtc->rotation == rotation && - crtc->numOutputs == numOutputs && - !memcmp (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)) && - !RRCrtcPendingProperties (crtc)) - { - ret = TRUE; - } - else - { -#if RANDR_12_INTERFACE - if (pScrPriv->rrCrtcSet) - { - ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y, - rotation, numOutputs, outputs); - } - else -#endif - { -#if RANDR_10_INTERFACE - if (pScrPriv->rrSetConfig) - { - RRScreenSize size; - RRScreenRate rate; - - if (!mode) - { - RRCrtcNotify (crtc, NULL, x, y, rotation, 0, NULL); - ret = TRUE; - } - else - { - size.width = mode->mode.width; - size.height = mode->mode.height; - if (outputs[0]->mmWidth && outputs[0]->mmHeight) - { - size.mmWidth = outputs[0]->mmWidth; - size.mmHeight = outputs[0]->mmHeight; - } - else - { - size.mmWidth = pScreen->mmWidth; - size.mmHeight = pScreen->mmHeight; - } - size.nRates = 1; - rate.rate = RRVerticalRefresh (&mode->mode); - size.pRates = &rate; - ret = (*pScrPriv->rrSetConfig) (pScreen, rotation, rate.rate, &size); - /* - * Old 1.0 interface tied screen size to mode size - */ - if (ret) - { - RRCrtcNotify (crtc, mode, x, y, rotation, 1, outputs); - RRScreenSizeNotify (pScreen); - } - } - } -#endif - } - if (ret) - { - int o; - RRTellChanged (pScreen); - - for (o = 0; o < numOutputs; o++) - RRPostPendingProperties (outputs[o]); - } - } - return ret; -} - -/* - * Destroy a Crtc at shutdown - */ -void -RRCrtcDestroy (RRCrtcPtr crtc) -{ - FreeResource (crtc->id, 0); -} - -static int -RRCrtcDestroyResource (pointer value, XID pid) -{ - RRCrtcPtr crtc = (RRCrtcPtr) value; - ScreenPtr pScreen = crtc->pScreen; - - if (pScreen) - { - rrScrPriv(pScreen); - int i; - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - if (pScrPriv->crtcs[i] == crtc) - { - memmove (pScrPriv->crtcs + i, pScrPriv->crtcs + i + 1, - (pScrPriv->numCrtcs - (i + 1)) * sizeof (RRCrtcPtr)); - --pScrPriv->numCrtcs; - break; - } - } - } - if (crtc->gammaRed) - xfree (crtc->gammaRed); - if (crtc->mode) - RRModeDestroy (crtc->mode); - xfree (crtc); - return 1; -} - -/* - * Request that the Crtc gamma be changed - */ - -Bool -RRCrtcGammaSet (RRCrtcPtr crtc, - CARD16 *red, - CARD16 *green, - CARD16 *blue) -{ - Bool ret = TRUE; -#if RANDR_12_INTERFACE - ScreenPtr pScreen = crtc->pScreen; -#endif - - memcpy (crtc->gammaRed, red, crtc->gammaSize * sizeof (CARD16)); - memcpy (crtc->gammaGreen, green, crtc->gammaSize * sizeof (CARD16)); - memcpy (crtc->gammaBlue, blue, crtc->gammaSize * sizeof (CARD16)); -#if RANDR_12_INTERFACE - if (pScreen) - { - rrScrPriv(pScreen); - if (pScrPriv->rrCrtcSetGamma) - ret = (*pScrPriv->rrCrtcSetGamma) (pScreen, crtc); - } -#endif - return ret; -} - -/* - * Notify the extension that the Crtc gamma has been changed - * The driver calls this whenever it has changed the gamma values - * in the RRCrtcRec - */ - -Bool -RRCrtcGammaNotify (RRCrtcPtr crtc) -{ - return TRUE; /* not much going on here */ -} - -/** - * Returns the width/height that the crtc scans out from the framebuffer - */ -void -RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height) -{ - if (crtc->mode == NULL) { - *width = 0; - *height = 0; - return; - } - - switch (crtc->rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_180: - *width = crtc->mode->mode.width; - *height = crtc->mode->mode.height; - break; - case RR_Rotate_90: - case RR_Rotate_270: - *width = crtc->mode->mode.height; - *height = crtc->mode->mode.width; - break; - } -} - -/* - * Set the size of the gamma table at server startup time - */ - -Bool -RRCrtcGammaSetSize (RRCrtcPtr crtc, - int size) -{ - CARD16 *gamma; - - if (size == crtc->gammaSize) - return TRUE; - if (size) - { - gamma = xalloc (size * 3 * sizeof (CARD16)); - if (!gamma) - return FALSE; - } - else - gamma = NULL; - if (crtc->gammaRed) - xfree (crtc->gammaRed); - crtc->gammaRed = gamma; - crtc->gammaGreen = gamma + size; - crtc->gammaBlue = gamma + size*2; - crtc->gammaSize = size; - return TRUE; -} - -/* - * Initialize crtc type - */ -Bool -RRCrtcInit (void) -{ - RRCrtcType = CreateNewResourceType (RRCrtcDestroyResource); - if (!RRCrtcType) - return FALSE; - RegisterResourceName (RRCrtcType, "CRTC"); - return TRUE; -} - -int -ProcRRGetCrtcInfo (ClientPtr client) -{ - REQUEST(xRRGetCrtcInfoReq); - xRRGetCrtcInfoReply rep; - RRCrtcPtr crtc; - CARD8 *extra; - unsigned long extraLen; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - RRModePtr mode; - RROutput *outputs; - RROutput *possible; - int i, j, k, n; - int width, height; - - REQUEST_SIZE_MATCH(xRRGetCrtcInfoReq); - crtc = LookupCrtc(client, stuff->crtc, DixReadAccess); - - if (!crtc) - return RRErrorBase + BadRRCrtc; - - /* All crtcs must be associated with screens before client - * requests are processed - */ - pScreen = crtc->pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - mode = crtc->mode; - - rep.type = X_Reply; - rep.status = RRSetConfigSuccess; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.x = crtc->x; - rep.y = crtc->y; - RRCrtcGetScanoutSize (crtc, &width, &height); - rep.width = width; - rep.height = height; - rep.mode = mode ? mode->mode.id : 0; - rep.rotation = crtc->rotation; - rep.rotations = crtc->rotations; - rep.nOutput = crtc->numOutputs; - k = 0; - for (i = 0; i < pScrPriv->numOutputs; i++) - for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++) - if (pScrPriv->outputs[i]->crtcs[j] == crtc) - k++; - rep.nPossibleOutput = k; - - rep.length = rep.nOutput + rep.nPossibleOutput; - - extraLen = rep.length << 2; - if (extraLen) - { - extra = xalloc (extraLen); - if (!extra) - return BadAlloc; - } - else - extra = NULL; - - outputs = (RROutput *) extra; - possible = (RROutput *) (outputs + rep.nOutput); - - for (i = 0; i < crtc->numOutputs; i++) - { - outputs[i] = crtc->outputs[i]->id; - if (client->swapped) - swapl (&outputs[i], n); - } - k = 0; - for (i = 0; i < pScrPriv->numOutputs; i++) - for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++) - if (pScrPriv->outputs[i]->crtcs[j] == crtc) - { - possible[k] = pScrPriv->outputs[i]->id; - if (client->swapped) - swapl (&possible[k], n); - k++; - } - - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swaps(&rep.x, n); - swaps(&rep.y, n); - swaps(&rep.width, n); - swaps(&rep.height, n); - swapl(&rep.mode, n); - swaps(&rep.rotation, n); - swaps(&rep.rotations, n); - swaps(&rep.nOutput, n); - swaps(&rep.nPossibleOutput, n); - } - WriteToClient(client, sizeof(xRRGetCrtcInfoReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - - return client->noClientException; -} - -int -ProcRRSetCrtcConfig (ClientPtr client) -{ - REQUEST(xRRSetCrtcConfigReq); - xRRSetCrtcConfigReply rep; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - RRCrtcPtr crtc; - RRModePtr mode; - int numOutputs; - RROutputPtr *outputs = NULL; - RROutput *outputIds; - TimeStamp configTime; - TimeStamp time; - Rotation rotation; - int i, j; - - REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq); - numOutputs = (stuff->length - (SIZEOF (xRRSetCrtcConfigReq) >> 2)); - - crtc = LookupIDByType (stuff->crtc, RRCrtcType); - if (!crtc) - { - client->errorValue = stuff->crtc; - return RRErrorBase + BadRRCrtc; - } - if (stuff->mode == None) - { - mode = NULL; - if (numOutputs > 0) - return BadMatch; - } - else - { - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - if (numOutputs == 0) - return BadMatch; - } - if (numOutputs) - { - outputs = xalloc (numOutputs * sizeof (RROutputPtr)); - if (!outputs) - return BadAlloc; - } - else - outputs = NULL; - - outputIds = (RROutput *) (stuff + 1); - for (i = 0; i < numOutputs; i++) - { - outputs[i] = (RROutputPtr) LookupIDByType (outputIds[i], RROutputType); - if (!outputs[i]) - { - client->errorValue = outputIds[i]; - if (outputs) - xfree (outputs); - return RRErrorBase + BadRROutput; - } - /* validate crtc for this output */ - for (j = 0; j < outputs[i]->numCrtcs; j++) - if (outputs[i]->crtcs[j] == crtc) - break; - if (j == outputs[i]->numCrtcs) - { - if (outputs) - xfree (outputs); - return BadMatch; - } - /* validate mode for this output */ - for (j = 0; j < outputs[i]->numModes + outputs[i]->numUserModes; j++) - { - RRModePtr m = (j < outputs[i]->numModes ? - outputs[i]->modes[j] : - outputs[i]->userModes[j - outputs[i]->numModes]); - if (m == mode) - break; - } - if (j == outputs[i]->numModes + outputs[i]->numUserModes) - { - if (outputs) - xfree (outputs); - return BadMatch; - } - } - /* validate clones */ - for (i = 0; i < numOutputs; i++) - { - for (j = 0; j < numOutputs; j++) - { - int k; - if (i == j) - continue; - for (k = 0; k < outputs[i]->numClones; k++) - { - if (outputs[i]->clones[k] == outputs[j]) - break; - } - if (k == outputs[i]->numClones) - { - if (outputs) - xfree (outputs); - return BadMatch; - } - } - } - - pScreen = crtc->pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - time = ClientTimeToServerTime(stuff->timestamp); - configTime = ClientTimeToServerTime(stuff->configTimestamp); - - if (!pScrPriv) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - -#if 0 - /* - * if the client's config timestamp is not the same as the last config - * timestamp, then the config information isn't up-to-date and - * can't even be validated - */ - if (CompareTimeStamps (configTime, pScrPriv->lastConfigTime) != 0) - { - rep.status = RRSetConfigInvalidConfigTime; - goto sendReply; - } -#endif - - /* - * Validate requested rotation - */ - rotation = (Rotation) stuff->rotation; - - /* test the rotation bits only! */ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_90: - case RR_Rotate_180: - case RR_Rotate_270: - break; - default: - /* - * Invalid rotation - */ - client->errorValue = stuff->rotation; - if (outputs) - xfree (outputs); - return BadValue; - } - - if (mode) - { - if ((~crtc->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - client->errorValue = stuff->rotation; - if (outputs) - xfree (outputs); - return BadMatch; - } - -#ifdef RANDR_12_INTERFACE - /* - * Check screen size bounds if the DDX provides a 1.2 interface - * for setting screen size. Else, assume the CrtcSet sets - * the size along with the mode - */ - if (pScrPriv->rrScreenSetSize) - { - int source_width = mode->mode.width; - int source_height = mode->mode.height; - - if ((rotation & 0xf) == RR_Rotate_90 || (rotation & 0xf) == RR_Rotate_270) - { - source_width = mode->mode.height; - source_height = mode->mode.width; - } - if (stuff->x + source_width > pScreen->width) - { - client->errorValue = stuff->x; - if (outputs) - xfree (outputs); - return BadValue; - } - - if (stuff->y + source_height > pScreen->height) - { - client->errorValue = stuff->y; - if (outputs) - xfree (outputs); - return BadValue; - } - } -#endif - } - - /* - * Make sure the requested set-time is not older than - * the last set-time - */ - if (CompareTimeStamps (time, pScrPriv->lastSetTime) < 0) - { - rep.status = RRSetConfigInvalidTime; - goto sendReply; - } - - if (!RRCrtcSet (crtc, mode, stuff->x, stuff->y, - rotation, numOutputs, outputs)) - { - rep.status = RRSetConfigFailed; - goto sendReply; - } - #ifdef NXAGENT_SERVER /* Bug 21987 */ - pScrPriv->lastSetTime = time; - #endif - rep.status = RRSetConfigSuccess; - -sendReply: - if (outputs) - xfree (outputs); - - rep.type = X_Reply; - /* rep.status has already been filled in */ - rep.length = 0; - rep.sequenceNumber = client->sequence; - #ifndef NXAGENT_SERVER /* Bug 21987 */ - rep.newTimestamp = pScrPriv->lastConfigTime.milliseconds; - #else - rep.newTimestamp = pScrPriv->lastSetTime.milliseconds; - #endif - - if (client->swapped) - { - int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.newTimestamp, n); - } - WriteToClient(client, sizeof(xRRSetCrtcConfigReply), (char *)&rep); - - return client->noClientException; -} - -int -ProcRRGetCrtcGammaSize (ClientPtr client) -{ - REQUEST(xRRGetCrtcGammaSizeReq); - xRRGetCrtcGammaSizeReply reply; - RRCrtcPtr crtc; - int n; - - REQUEST_SIZE_MATCH(xRRGetCrtcGammaSizeReq); - crtc = LookupCrtc (client, stuff->crtc, DixReadAccess); - if (!crtc) - return RRErrorBase + BadRRCrtc; - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = 0; - reply.size = crtc->gammaSize; - if (client->swapped) { - swaps (&reply.sequenceNumber, n); - swapl (&reply.length, n); - swaps (&reply.size, n); - } - WriteToClient (client, sizeof (xRRGetCrtcGammaSizeReply), (char *) &reply); - return client->noClientException; -} - -int -ProcRRGetCrtcGamma (ClientPtr client) -{ - REQUEST(xRRGetCrtcGammaReq); - xRRGetCrtcGammaReply reply; - RRCrtcPtr crtc; - int n; - unsigned long len; - char *extra; - - REQUEST_SIZE_MATCH(xRRGetCrtcGammaReq); - crtc = LookupCrtc (client, stuff->crtc, DixReadAccess); - if (!crtc) - return RRErrorBase + BadRRCrtc; - - len = crtc->gammaSize * 3 * 2; - - if (crtc->gammaSize) { - extra = xalloc(len); - if (!extra) - return BadAlloc; - } - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = (len + 3) >> 2; - reply.size = crtc->gammaSize; - if (client->swapped) { - swaps (&reply.sequenceNumber, n); - swapl (&reply.length, n); - swaps (&reply.size, n); - } - WriteToClient (client, sizeof (xRRGetCrtcGammaReply), (char *) &reply); - if (crtc->gammaSize) - { - memcpy(extra, crtc->gammaRed, len); - client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; - WriteSwappedDataToClient (client, len, extra); - xfree(extra); - } - return client->noClientException; -} - -int -ProcRRSetCrtcGamma (ClientPtr client) -{ - REQUEST(xRRSetCrtcGammaReq); - RRCrtcPtr crtc; - unsigned long len; - CARD16 *red, *green, *blue; - - REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq); - crtc = LookupCrtc (client, stuff->crtc, DixWriteAccess); - if (!crtc) - return RRErrorBase + BadRRCrtc; - - len = client->req_len - (sizeof (xRRSetCrtcGammaReq) >> 2); - if (len < (stuff->size * 3 + 1) >> 1) - return BadLength; - - if (stuff->size != crtc->gammaSize) - return BadMatch; - - red = (CARD16 *) (stuff + 1); - green = red + crtc->gammaSize; - blue = green + crtc->gammaSize; - - RRCrtcGammaSet (crtc, red, green, blue); - - return Success; -} - diff --git a/nx-X11/programs/Xserver/randr/rrcrtc.c.X.original b/nx-X11/programs/Xserver/randr/rrcrtc.c.X.original deleted file mode 100644 index ec65a040e..000000000 --- a/nx-X11/programs/Xserver/randr/rrcrtc.c.X.original +++ /dev/null @@ -1,960 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "randrstr.h" -#include "swaprep.h" -#include "registry.h" - -RESTYPE RRCrtcType; - -/* - * Notify the CRTC of some change - */ -void -RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged) -{ - ScreenPtr pScreen = crtc->pScreen; - - crtc->changed = TRUE; - if (pScreen) - { - rrScrPriv(pScreen); - - pScrPriv->changed = TRUE; - /* - * Send ConfigureNotify on any layout change - */ - if (layoutChanged) - pScrPriv->layoutChanged = TRUE; - } -} - -/* - * Create a CRTC - */ -RRCrtcPtr -RRCrtcCreate (ScreenPtr pScreen, void *devPrivate) -{ - RRCrtcPtr crtc; - RRCrtcPtr *crtcs; - rrScrPrivPtr pScrPriv; - - if (!RRInit()) - return NULL; - - pScrPriv = rrGetScrPriv(pScreen); - - /* make space for the crtc pointer */ - if (pScrPriv->numCrtcs) - crtcs = xrealloc (pScrPriv->crtcs, - (pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr)); - else - crtcs = xalloc (sizeof (RRCrtcPtr)); - if (!crtcs) - return FALSE; - pScrPriv->crtcs = crtcs; - - crtc = xcalloc (1, sizeof (RRCrtcRec)); - if (!crtc) - return NULL; - crtc->id = FakeClientID (0); - crtc->pScreen = pScreen; - crtc->mode = NULL; - crtc->x = 0; - crtc->y = 0; - crtc->rotation = RR_Rotate_0; - crtc->rotations = RR_Rotate_0; - crtc->outputs = NULL; - crtc->numOutputs = 0; - crtc->gammaSize = 0; - crtc->gammaRed = crtc->gammaBlue = crtc->gammaGreen = NULL; - crtc->changed = FALSE; - crtc->devPrivate = devPrivate; - - if (!AddResource (crtc->id, RRCrtcType, (pointer) crtc)) - return NULL; - - /* attach the screen and crtc together */ - crtc->pScreen = pScreen; - pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc; - - return crtc; -} - -/* - * Set the allowed rotations on a CRTC - */ -void -RRCrtcSetRotations (RRCrtcPtr crtc, Rotation rotations) -{ - crtc->rotations = rotations; -} - -/* - * Notify the extension that the Crtc has been reconfigured, - * the driver calls this whenever it has updated the mode - */ -Bool -RRCrtcNotify (RRCrtcPtr crtc, - RRModePtr mode, - int x, - int y, - Rotation rotation, - int numOutputs, - RROutputPtr *outputs) -{ - int i, j; - - /* - * Check to see if any of the new outputs were - * not in the old list and mark them as changed - */ - for (i = 0; i < numOutputs; i++) - { - for (j = 0; j < crtc->numOutputs; j++) - if (outputs[i] == crtc->outputs[j]) - break; - if (j == crtc->numOutputs) - { - outputs[i]->crtc = crtc; - RROutputChanged (outputs[i], FALSE); - RRCrtcChanged (crtc, FALSE); - } - } - /* - * Check to see if any of the old outputs are - * not in the new list and mark them as changed - */ - for (j = 0; j < crtc->numOutputs; j++) - { - for (i = 0; i < numOutputs; i++) - if (outputs[i] == crtc->outputs[j]) - break; - if (i == numOutputs) - { - if (crtc->outputs[j]->crtc == crtc) - crtc->outputs[j]->crtc = NULL; - RROutputChanged (crtc->outputs[j], FALSE); - RRCrtcChanged (crtc, FALSE); - } - } - /* - * Reallocate the crtc output array if necessary - */ - if (numOutputs != crtc->numOutputs) - { - RROutputPtr *newoutputs; - - if (numOutputs) - { - if (crtc->numOutputs) - newoutputs = xrealloc (crtc->outputs, - numOutputs * sizeof (RROutputPtr)); - else - newoutputs = xalloc (numOutputs * sizeof (RROutputPtr)); - if (!newoutputs) - return FALSE; - } - else - { - if (crtc->outputs) - xfree (crtc->outputs); - newoutputs = NULL; - } - crtc->outputs = newoutputs; - crtc->numOutputs = numOutputs; - } - /* - * Copy the new list of outputs into the crtc - */ - memcpy (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)); - /* - * Update remaining crtc fields - */ - if (mode != crtc->mode) - { - if (crtc->mode) - RRModeDestroy (crtc->mode); - crtc->mode = mode; - if (mode != NULL) - mode->refcnt++; - RRCrtcChanged (crtc, TRUE); - } - if (x != crtc->x) - { - crtc->x = x; - RRCrtcChanged (crtc, TRUE); - } - if (y != crtc->y) - { - crtc->y = y; - RRCrtcChanged (crtc, TRUE); - } - if (rotation != crtc->rotation) - { - crtc->rotation = rotation; - RRCrtcChanged (crtc, TRUE); - } - return TRUE; -} - -void -RRDeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv (pScreen); - xRRCrtcChangeNotifyEvent ce; - RRModePtr mode = crtc->mode; - - ce.type = RRNotify + RREventBase; - ce.subCode = RRNotify_CrtcChange; - ce.sequenceNumber = client->sequence; - ce.timestamp = pScrPriv->lastSetTime.milliseconds; - ce.window = pWin->drawable.id; - ce.crtc = crtc->id; - ce.rotation = crtc->rotation; - if (mode) - { - ce.mode = mode->mode.id; - ce.x = crtc->x; - ce.y = crtc->y; - ce.width = mode->mode.width; - ce.height = mode->mode.height; - } - else - { - ce.mode = None; - ce.x = 0; - ce.y = 0; - ce.width = 0; - ce.height = 0; - } - WriteEventsToClient (client, 1, (xEvent *) &ce); -} - -static Bool -RRCrtcPendingProperties (RRCrtcPtr crtc) -{ - ScreenPtr pScreen = crtc->pScreen; - rrScrPriv(pScreen); - int o; - - for (o = 0; o < pScrPriv->numOutputs; o++) - { - RROutputPtr output = pScrPriv->outputs[o]; - if (output->crtc == crtc && output->pendingProperties) - return TRUE; - } - return FALSE; -} - -/* - * Request that the Crtc be reconfigured - */ -Bool -RRCrtcSet (RRCrtcPtr crtc, - RRModePtr mode, - int x, - int y, - Rotation rotation, - int numOutputs, - RROutputPtr *outputs) -{ - ScreenPtr pScreen = crtc->pScreen; - Bool ret = FALSE; - rrScrPriv(pScreen); - - /* See if nothing changed */ - if (crtc->mode == mode && - crtc->x == x && - crtc->y == y && - crtc->rotation == rotation && - crtc->numOutputs == numOutputs && - !memcmp (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)) && - !RRCrtcPendingProperties (crtc)) - { - ret = TRUE; - } - else - { -#if RANDR_12_INTERFACE - if (pScrPriv->rrCrtcSet) - { - ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y, - rotation, numOutputs, outputs); - } - else -#endif - { -#if RANDR_10_INTERFACE - if (pScrPriv->rrSetConfig) - { - RRScreenSize size; - RRScreenRate rate; - - if (!mode) - { - RRCrtcNotify (crtc, NULL, x, y, rotation, 0, NULL); - ret = TRUE; - } - else - { - size.width = mode->mode.width; - size.height = mode->mode.height; - if (outputs[0]->mmWidth && outputs[0]->mmHeight) - { - size.mmWidth = outputs[0]->mmWidth; - size.mmHeight = outputs[0]->mmHeight; - } - else - { - size.mmWidth = pScreen->mmWidth; - size.mmHeight = pScreen->mmHeight; - } - size.nRates = 1; - rate.rate = RRVerticalRefresh (&mode->mode); - size.pRates = &rate; - ret = (*pScrPriv->rrSetConfig) (pScreen, rotation, rate.rate, &size); - /* - * Old 1.0 interface tied screen size to mode size - */ - if (ret) - { - RRCrtcNotify (crtc, mode, x, y, rotation, 1, outputs); - RRScreenSizeNotify (pScreen); - } - } - } -#endif - } - if (ret) - { - int o; - RRTellChanged (pScreen); - - for (o = 0; o < numOutputs; o++) - RRPostPendingProperties (outputs[o]); - } - } - return ret; -} - -/* - * Destroy a Crtc at shutdown - */ -void -RRCrtcDestroy (RRCrtcPtr crtc) -{ - FreeResource (crtc->id, 0); -} - -static int -RRCrtcDestroyResource (pointer value, XID pid) -{ - RRCrtcPtr crtc = (RRCrtcPtr) value; - ScreenPtr pScreen = crtc->pScreen; - - if (pScreen) - { - rrScrPriv(pScreen); - int i; - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - if (pScrPriv->crtcs[i] == crtc) - { - memmove (pScrPriv->crtcs + i, pScrPriv->crtcs + i + 1, - (pScrPriv->numCrtcs - (i + 1)) * sizeof (RRCrtcPtr)); - --pScrPriv->numCrtcs; - break; - } - } - } - if (crtc->gammaRed) - xfree (crtc->gammaRed); - if (crtc->mode) - RRModeDestroy (crtc->mode); - xfree (crtc); - return 1; -} - -/* - * Request that the Crtc gamma be changed - */ - -Bool -RRCrtcGammaSet (RRCrtcPtr crtc, - CARD16 *red, - CARD16 *green, - CARD16 *blue) -{ - Bool ret = TRUE; -#if RANDR_12_INTERFACE - ScreenPtr pScreen = crtc->pScreen; -#endif - - memcpy (crtc->gammaRed, red, crtc->gammaSize * sizeof (CARD16)); - memcpy (crtc->gammaGreen, green, crtc->gammaSize * sizeof (CARD16)); - memcpy (crtc->gammaBlue, blue, crtc->gammaSize * sizeof (CARD16)); -#if RANDR_12_INTERFACE - if (pScreen) - { - rrScrPriv(pScreen); - if (pScrPriv->rrCrtcSetGamma) - ret = (*pScrPriv->rrCrtcSetGamma) (pScreen, crtc); - } -#endif - return ret; -} - -/* - * Notify the extension that the Crtc gamma has been changed - * The driver calls this whenever it has changed the gamma values - * in the RRCrtcRec - */ - -Bool -RRCrtcGammaNotify (RRCrtcPtr crtc) -{ - return TRUE; /* not much going on here */ -} - -/** - * Returns the width/height that the crtc scans out from the framebuffer - */ -void -RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height) -{ - if (crtc->mode == NULL) { - *width = 0; - *height = 0; - return; - } - - switch (crtc->rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_180: - *width = crtc->mode->mode.width; - *height = crtc->mode->mode.height; - break; - case RR_Rotate_90: - case RR_Rotate_270: - *width = crtc->mode->mode.height; - *height = crtc->mode->mode.width; - break; - } -} - -/* - * Set the size of the gamma table at server startup time - */ - -Bool -RRCrtcGammaSetSize (RRCrtcPtr crtc, - int size) -{ - CARD16 *gamma; - - if (size == crtc->gammaSize) - return TRUE; - if (size) - { - gamma = xalloc (size * 3 * sizeof (CARD16)); - if (!gamma) - return FALSE; - } - else - gamma = NULL; - if (crtc->gammaRed) - xfree (crtc->gammaRed); - crtc->gammaRed = gamma; - crtc->gammaGreen = gamma + size; - crtc->gammaBlue = gamma + size*2; - crtc->gammaSize = size; - return TRUE; -} - -/* - * Initialize crtc type - */ -Bool -RRCrtcInit (void) -{ - RRCrtcType = CreateNewResourceType (RRCrtcDestroyResource); - if (!RRCrtcType) - return FALSE; - RegisterResourceName (RRCrtcType, "CRTC"); - return TRUE; -} - -int -ProcRRGetCrtcInfo (ClientPtr client) -{ - REQUEST(xRRGetCrtcInfoReq); - xRRGetCrtcInfoReply rep; - RRCrtcPtr crtc; - CARD8 *extra; - unsigned long extraLen; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - RRModePtr mode; - RROutput *outputs; - RROutput *possible; - int i, j, k, n; - int width, height; - - REQUEST_SIZE_MATCH(xRRGetCrtcInfoReq); - crtc = LookupCrtc(client, stuff->crtc, DixReadAccess); - - if (!crtc) - return RRErrorBase + BadRRCrtc; - - /* All crtcs must be associated with screens before client - * requests are processed - */ - pScreen = crtc->pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - mode = crtc->mode; - - rep.type = X_Reply; - rep.status = RRSetConfigSuccess; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.x = crtc->x; - rep.y = crtc->y; - RRCrtcGetScanoutSize (crtc, &width, &height); - rep.width = width; - rep.height = height; - rep.mode = mode ? mode->mode.id : 0; - rep.rotation = crtc->rotation; - rep.rotations = crtc->rotations; - rep.nOutput = crtc->numOutputs; - k = 0; - for (i = 0; i < pScrPriv->numOutputs; i++) - for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++) - if (pScrPriv->outputs[i]->crtcs[j] == crtc) - k++; - rep.nPossibleOutput = k; - - rep.length = rep.nOutput + rep.nPossibleOutput; - - extraLen = rep.length << 2; - if (extraLen) - { - extra = xalloc (extraLen); - if (!extra) - return BadAlloc; - } - else - extra = NULL; - - outputs = (RROutput *) extra; - possible = (RROutput *) (outputs + rep.nOutput); - - for (i = 0; i < crtc->numOutputs; i++) - { - outputs[i] = crtc->outputs[i]->id; - if (client->swapped) - swapl (&outputs[i], n); - } - k = 0; - for (i = 0; i < pScrPriv->numOutputs; i++) - for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++) - if (pScrPriv->outputs[i]->crtcs[j] == crtc) - { - possible[k] = pScrPriv->outputs[i]->id; - if (client->swapped) - swapl (&possible[k], n); - k++; - } - - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swaps(&rep.x, n); - swaps(&rep.y, n); - swaps(&rep.width, n); - swaps(&rep.height, n); - swapl(&rep.mode, n); - swaps(&rep.rotation, n); - swaps(&rep.rotations, n); - swaps(&rep.nOutput, n); - swaps(&rep.nPossibleOutput, n); - } - WriteToClient(client, sizeof(xRRGetCrtcInfoReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - - return client->noClientException; -} - -int -ProcRRSetCrtcConfig (ClientPtr client) -{ - REQUEST(xRRSetCrtcConfigReq); - xRRSetCrtcConfigReply rep; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - RRCrtcPtr crtc; - RRModePtr mode; - int numOutputs; - RROutputPtr *outputs = NULL; - RROutput *outputIds; - TimeStamp configTime; - TimeStamp time; - Rotation rotation; - int i, j; - - REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq); - numOutputs = (stuff->length - (SIZEOF (xRRSetCrtcConfigReq) >> 2)); - - crtc = LookupIDByType (stuff->crtc, RRCrtcType); - if (!crtc) - { - client->errorValue = stuff->crtc; - return RRErrorBase + BadRRCrtc; - } - if (stuff->mode == None) - { - mode = NULL; - if (numOutputs > 0) - return BadMatch; - } - else - { - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - if (numOutputs == 0) - return BadMatch; - } - if (numOutputs) - { - outputs = xalloc (numOutputs * sizeof (RROutputPtr)); - if (!outputs) - return BadAlloc; - } - else - outputs = NULL; - - outputIds = (RROutput *) (stuff + 1); - for (i = 0; i < numOutputs; i++) - { - outputs[i] = (RROutputPtr) LookupIDByType (outputIds[i], RROutputType); - if (!outputs[i]) - { - client->errorValue = outputIds[i]; - if (outputs) - xfree (outputs); - return RRErrorBase + BadRROutput; - } - /* validate crtc for this output */ - for (j = 0; j < outputs[i]->numCrtcs; j++) - if (outputs[i]->crtcs[j] == crtc) - break; - if (j == outputs[i]->numCrtcs) - { - if (outputs) - xfree (outputs); - return BadMatch; - } - /* validate mode for this output */ - for (j = 0; j < outputs[i]->numModes + outputs[i]->numUserModes; j++) - { - RRModePtr m = (j < outputs[i]->numModes ? - outputs[i]->modes[j] : - outputs[i]->userModes[j - outputs[i]->numModes]); - if (m == mode) - break; - } - if (j == outputs[i]->numModes + outputs[i]->numUserModes) - { - if (outputs) - xfree (outputs); - return BadMatch; - } - } - /* validate clones */ - for (i = 0; i < numOutputs; i++) - { - for (j = 0; j < numOutputs; j++) - { - int k; - if (i == j) - continue; - for (k = 0; k < outputs[i]->numClones; k++) - { - if (outputs[i]->clones[k] == outputs[j]) - break; - } - if (k == outputs[i]->numClones) - { - if (outputs) - xfree (outputs); - return BadMatch; - } - } - } - - pScreen = crtc->pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - time = ClientTimeToServerTime(stuff->timestamp); - configTime = ClientTimeToServerTime(stuff->configTimestamp); - - if (!pScrPriv) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - -#if 0 - /* - * if the client's config timestamp is not the same as the last config - * timestamp, then the config information isn't up-to-date and - * can't even be validated - */ - if (CompareTimeStamps (configTime, pScrPriv->lastConfigTime) != 0) - { - rep.status = RRSetConfigInvalidConfigTime; - goto sendReply; - } -#endif - - /* - * Validate requested rotation - */ - rotation = (Rotation) stuff->rotation; - - /* test the rotation bits only! */ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_90: - case RR_Rotate_180: - case RR_Rotate_270: - break; - default: - /* - * Invalid rotation - */ - client->errorValue = stuff->rotation; - if (outputs) - xfree (outputs); - return BadValue; - } - - if (mode) - { - if ((~crtc->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - client->errorValue = stuff->rotation; - if (outputs) - xfree (outputs); - return BadMatch; - } - -#ifdef RANDR_12_INTERFACE - /* - * Check screen size bounds if the DDX provides a 1.2 interface - * for setting screen size. Else, assume the CrtcSet sets - * the size along with the mode - */ - if (pScrPriv->rrScreenSetSize) - { - int source_width = mode->mode.width; - int source_height = mode->mode.height; - - if ((rotation & 0xf) == RR_Rotate_90 || (rotation & 0xf) == RR_Rotate_270) - { - source_width = mode->mode.height; - source_height = mode->mode.width; - } - if (stuff->x + source_width > pScreen->width) - { - client->errorValue = stuff->x; - if (outputs) - xfree (outputs); - return BadValue; - } - - if (stuff->y + source_height > pScreen->height) - { - client->errorValue = stuff->y; - if (outputs) - xfree (outputs); - return BadValue; - } - } -#endif - } - - /* - * Make sure the requested set-time is not older than - * the last set-time - */ - if (CompareTimeStamps (time, pScrPriv->lastSetTime) < 0) - { - rep.status = RRSetConfigInvalidTime; - goto sendReply; - } - - if (!RRCrtcSet (crtc, mode, stuff->x, stuff->y, - rotation, numOutputs, outputs)) - { - rep.status = RRSetConfigFailed; - goto sendReply; - } - rep.status = RRSetConfigSuccess; - -sendReply: - if (outputs) - xfree (outputs); - - rep.type = X_Reply; - /* rep.status has already been filled in */ - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.newTimestamp = pScrPriv->lastConfigTime.milliseconds; - - if (client->swapped) - { - int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.newTimestamp, n); - } - WriteToClient(client, sizeof(xRRSetCrtcConfigReply), (char *)&rep); - - return client->noClientException; -} - -int -ProcRRGetCrtcGammaSize (ClientPtr client) -{ - REQUEST(xRRGetCrtcGammaSizeReq); - xRRGetCrtcGammaSizeReply reply; - RRCrtcPtr crtc; - int n; - - REQUEST_SIZE_MATCH(xRRGetCrtcGammaSizeReq); - crtc = LookupCrtc (client, stuff->crtc, DixReadAccess); - if (!crtc) - return RRErrorBase + BadRRCrtc; - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = 0; - reply.size = crtc->gammaSize; - if (client->swapped) { - swaps (&reply.sequenceNumber, n); - swapl (&reply.length, n); - swaps (&reply.size, n); - } - WriteToClient (client, sizeof (xRRGetCrtcGammaSizeReply), (char *) &reply); - return client->noClientException; -} - -int -ProcRRGetCrtcGamma (ClientPtr client) -{ - REQUEST(xRRGetCrtcGammaReq); - xRRGetCrtcGammaReply reply; - RRCrtcPtr crtc; - int n; - unsigned long len; - char *extra; - - REQUEST_SIZE_MATCH(xRRGetCrtcGammaReq); - crtc = LookupCrtc (client, stuff->crtc, DixReadAccess); - if (!crtc) - return RRErrorBase + BadRRCrtc; - - len = crtc->gammaSize * 3 * 2; - - if (crtc->gammaSize) { - extra = xalloc(len); - if (!extra) - return BadAlloc; - } - - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.length = (len + 3) >> 2; - reply.size = crtc->gammaSize; - if (client->swapped) { - swaps (&reply.sequenceNumber, n); - swapl (&reply.length, n); - swaps (&reply.size, n); - } - WriteToClient (client, sizeof (xRRGetCrtcGammaReply), (char *) &reply); - if (crtc->gammaSize) - { - memcpy(extra, crtc->gammaRed, len); - client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; - WriteSwappedDataToClient (client, len, extra); - xfree(extra); - } - return client->noClientException; -} - -int -ProcRRSetCrtcGamma (ClientPtr client) -{ - REQUEST(xRRSetCrtcGammaReq); - RRCrtcPtr crtc; - unsigned long len; - CARD16 *red, *green, *blue; - - REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq); - crtc = LookupCrtc (client, stuff->crtc, DixWriteAccess); - if (!crtc) - return RRErrorBase + BadRRCrtc; - - len = client->req_len - (sizeof (xRRSetCrtcGammaReq) >> 2); - if (len < (stuff->size * 3 + 1) >> 1) - return BadLength; - - if (stuff->size != crtc->gammaSize) - return BadMatch; - - red = (CARD16 *) (stuff + 1); - green = red + crtc->gammaSize; - blue = green + crtc->gammaSize; - - RRCrtcGammaSet (crtc, red, green, blue); - - return Success; -} - diff --git a/nx-X11/programs/Xserver/randr/rrdispatch.c.X.original b/nx-X11/programs/Xserver/randr/rrdispatch.c.X.original deleted file mode 100644 index 5525427f6..000000000 --- a/nx-X11/programs/Xserver/randr/rrdispatch.c.X.original +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "randrstr.h" - -#define SERVER_RANDR_MAJOR 1 -#define SERVER_RANDR_MINOR 2 - -Bool -RRClientKnowsRates (ClientPtr pClient) -{ - rrClientPriv(pClient); - - return (pRRClient->major_version > 1 || - (pRRClient->major_version == 1 && pRRClient->minor_version >= 1)); -} - -static int -ProcRRQueryVersion (ClientPtr client) -{ - xRRQueryVersionReply rep; - register int n; - REQUEST(xRRQueryVersionReq); - rrClientPriv(client); - - REQUEST_SIZE_MATCH(xRRQueryVersionReq); - pRRClient->major_version = stuff->majorVersion; - pRRClient->minor_version = stuff->minorVersion; - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - /* - * Report the current version; the current - * spec says they're all compatible after 1.0 - */ - rep.majorVersion = SERVER_RANDR_MAJOR; - rep.minorVersion = SERVER_RANDR_MINOR; - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.majorVersion, n); - swapl(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xRRQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -static int -ProcRRSelectInput (ClientPtr client) -{ - REQUEST(xRRSelectInputReq); - rrClientPriv(client); - RRTimesPtr pTimes; - WindowPtr pWin; - RREventPtr pRREvent, *pHead; - XID clientResource; - int rc; - - REQUEST_SIZE_MATCH(xRRSelectInputReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess); - if (rc != Success) - return rc; - pHead = (RREventPtr *)SecurityLookupIDByType(client, - pWin->drawable.id, RREventType, - DixWriteAccess); - - if (stuff->enable & (RRScreenChangeNotifyMask| - RRCrtcChangeNotifyMask| - RROutputChangeNotifyMask)) - { - ScreenPtr pScreen = pWin->drawable.pScreen; - rrScrPriv (pScreen); - - pRREvent = NULL; - if (pHead) - { - /* check for existing entry. */ - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) - if (pRREvent->client == client) - break; - } - - if (!pRREvent) - { - /* build the entry */ - pRREvent = (RREventPtr) xalloc (sizeof (RREventRec)); - if (!pRREvent) - return BadAlloc; - pRREvent->next = 0; - pRREvent->client = client; - pRREvent->window = pWin; - pRREvent->mask = stuff->enable; - /* - * add a resource that will be deleted when - * the client goes away - */ - clientResource = FakeClientID (client->index); - pRREvent->clientResource = clientResource; - if (!AddResource (clientResource, RRClientType, (pointer)pRREvent)) - return BadAlloc; - /* - * create a resource to contain a pointer to the list - * of clients selecting input. This must be indirect as - * the list may be arbitrarily rearranged which cannot be - * done through the resource database. - */ - if (!pHead) - { - pHead = (RREventPtr *) xalloc (sizeof (RREventPtr)); - if (!pHead || - !AddResource (pWin->drawable.id, RREventType, (pointer)pHead)) - { - FreeResource (clientResource, RT_NONE); - return BadAlloc; - } - *pHead = 0; - } - pRREvent->next = *pHead; - *pHead = pRREvent; - } - /* - * Now see if the client needs an event - */ - if (pScrPriv && (pRREvent->mask & RRScreenChangeNotifyMask)) - { - pTimes = &((RRTimesPtr) (pRRClient + 1))[pScreen->myNum]; - if (CompareTimeStamps (pTimes->setTime, - pScrPriv->lastSetTime) != 0 || - CompareTimeStamps (pTimes->configTime, - pScrPriv->lastConfigTime) != 0) - { - RRDeliverScreenEvent (client, pWin, pScreen); - } - } - } - else if (stuff->enable == 0) - { - /* delete the interest */ - if (pHead) { - RREventPtr pNewRREvent = 0; - for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) { - if (pRREvent->client == client) - break; - pNewRREvent = pRREvent; - } - if (pRREvent) { - FreeResource (pRREvent->clientResource, RRClientType); - if (pNewRREvent) - pNewRREvent->next = pRREvent->next; - else - *pHead = pRREvent->next; - xfree (pRREvent); - } - } - } - else - { - client->errorValue = stuff->enable; - return BadValue; - } - return Success; -} - -int (*ProcRandrVector[RRNumberRequests])(ClientPtr) = { - ProcRRQueryVersion, /* 0 */ -/* we skip 1 to make old clients fail pretty immediately */ - NULL, /* 1 ProcRandrOldGetScreenInfo */ -/* V1.0 apps share the same set screen config request id */ - ProcRRSetScreenConfig, /* 2 */ - NULL, /* 3 ProcRandrOldScreenChangeSelectInput */ -/* 3 used to be ScreenChangeSelectInput; deprecated */ - ProcRRSelectInput, /* 4 */ - ProcRRGetScreenInfo, /* 5 */ -/* V1.2 additions */ - ProcRRGetScreenSizeRange, /* 6 */ - ProcRRSetScreenSize, /* 7 */ - ProcRRGetScreenResources, /* 8 */ - ProcRRGetOutputInfo, /* 9 */ - ProcRRListOutputProperties, /* 10 */ - ProcRRQueryOutputProperty, /* 11 */ - ProcRRConfigureOutputProperty, /* 12 */ - ProcRRChangeOutputProperty, /* 13 */ - ProcRRDeleteOutputProperty, /* 14 */ - ProcRRGetOutputProperty, /* 15 */ - ProcRRCreateMode, /* 16 */ - ProcRRDestroyMode, /* 17 */ - ProcRRAddOutputMode, /* 18 */ - ProcRRDeleteOutputMode, /* 19 */ - ProcRRGetCrtcInfo, /* 20 */ - ProcRRSetCrtcConfig, /* 21 */ - ProcRRGetCrtcGammaSize, /* 22 */ - ProcRRGetCrtcGamma, /* 23 */ - ProcRRSetCrtcGamma, /* 24 */ -}; - diff --git a/nx-X11/programs/Xserver/randr/rrmode.c.NX.original b/nx-X11/programs/Xserver/randr/rrmode.c.NX.original deleted file mode 100644 index 62c01485a..000000000 --- a/nx-X11/programs/Xserver/randr/rrmode.c.NX.original +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#include "randrstr.h" -#include "registry.h" - -RESTYPE RRModeType; - -static Bool -RRModeEqual (xRRModeInfo *a, xRRModeInfo *b) -{ - if (a->width != b->width) return FALSE; - if (a->height != b->height) return FALSE; - if (a->dotClock != b->dotClock) return FALSE; - if (a->hSyncStart != b->hSyncStart) return FALSE; - if (a->hSyncEnd != b->hSyncEnd) return FALSE; - if (a->hTotal != b->hTotal) return FALSE; - if (a->hSkew != b->hSkew) return FALSE; - if (a->vSyncStart != b->vSyncStart) return FALSE; - if (a->vSyncEnd != b->vSyncEnd) return FALSE; - if (a->vTotal != b->vTotal) return FALSE; - if (a->nameLength != b->nameLength) return FALSE; - if (a->modeFlags != b->modeFlags) return FALSE; - return TRUE; -} - -/* - * Keep a list so it's easy to find modes in the resource database. - */ -static int num_modes; -static RRModePtr *modes; - -static RRModePtr -RRModeCreate (xRRModeInfo *modeInfo, - const char *name, - ScreenPtr userScreen) -{ - RRModePtr mode, *newModes; - - if (!RRInit ()) - return NULL; - - mode = xalloc (sizeof (RRModeRec) + modeInfo->nameLength + 1); - if (!mode) - return NULL; - mode->refcnt = 1; - mode->mode = *modeInfo; - mode->name = (char *) (mode + 1); - memcpy (mode->name, name, modeInfo->nameLength); - mode->name[modeInfo->nameLength] = '\0'; - mode->userScreen = userScreen; - - if (num_modes) - newModes = xrealloc (modes, (num_modes + 1) * sizeof (RRModePtr)); - else - newModes = xalloc (sizeof (RRModePtr)); - - if (!newModes) - { - xfree (mode); - return NULL; - } - - mode->mode.id = FakeClientID(0); - if (!AddResource (mode->mode.id, RRModeType, (pointer) mode)) - return NULL; - modes = newModes; - modes[num_modes++] = mode; - - /* - * give the caller a reference to this mode - */ - ++mode->refcnt; - return mode; -} - -static RRModePtr -RRModeFindByName (const char *name, - CARD16 nameLength) -{ - int i; - RRModePtr mode; - - for (i = 0; i < num_modes; i++) - { - mode = modes[i]; - if (mode->mode.nameLength == nameLength && - !memcmp (name, mode->name, nameLength)) - { - return mode; - } - } - return NULL; -} - -RRModePtr -RRModeGet (xRRModeInfo *modeInfo, - const char *name) -{ - int i; - - for (i = 0; i < num_modes; i++) - { - RRModePtr mode = modes[i]; - if (RRModeEqual (&mode->mode, modeInfo) && - !memcmp (name, mode->name, modeInfo->nameLength)) - { - ++mode->refcnt; - return mode; - } - } - - return RRModeCreate (modeInfo, name, NULL); -} - -static RRModePtr -RRModeCreateUser (ScreenPtr pScreen, - xRRModeInfo *modeInfo, - const char *name, - int *error) -{ - RRModePtr mode; - - mode = RRModeFindByName (name, modeInfo->nameLength); - if (mode) - { - *error = BadName; - return NULL; - } - - mode = RRModeCreate (modeInfo, name, pScreen); - if (!mode) - { - *error = BadAlloc; - return NULL; - } - *error = Success; - return mode; -} - -RRModePtr * -RRModesForScreen (ScreenPtr pScreen, int *num_ret) -{ - rrScrPriv(pScreen); - int o, c, m; - RRModePtr *screen_modes; - int num_screen_modes = 0; - - screen_modes = xalloc ((num_modes ? num_modes : 1) * sizeof (RRModePtr)); - if (!screen_modes) - return NULL; - - /* - * Add modes from all outputs - */ - for (o = 0; o < pScrPriv->numOutputs; o++) - { - RROutputPtr output = pScrPriv->outputs[o]; - int m, n; - - for (m = 0; m < output->numModes + output->numUserModes; m++) - { - RRModePtr mode = (m < output->numModes ? - output->modes[m] : - output->userModes[m-output->numModes]); - for (n = 0; n < num_screen_modes; n++) - if (screen_modes[n] == mode) - break; - if (n == num_screen_modes) - screen_modes[num_screen_modes++] = mode; - } - } - /* - * Add modes from all crtcs. The goal is to - * make sure all available and active modes - * are visible to the client - */ - for (c = 0; c < pScrPriv->numCrtcs; c++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[c]; - RRModePtr mode = crtc->mode; - int n; - - if (!mode) continue; - for (n = 0; n < num_screen_modes; n++) - if (screen_modes[n] == mode) - break; - if (n == num_screen_modes) - screen_modes[num_screen_modes++] = mode; - } - /* - * Add all user modes for this screen - */ - for (m = 0; m < num_modes; m++) - { - RRModePtr mode = modes[m]; - int n; - - if (mode->userScreen != pScreen) - continue; - for (n = 0; n < num_screen_modes; n++) - if (screen_modes[n] == mode) - break; - if (n == num_screen_modes) - screen_modes[num_screen_modes++] = mode; - } - - *num_ret = num_screen_modes; - return screen_modes; -} - -void -RRModeDestroy (RRModePtr mode) -{ - int m; - - if (--mode->refcnt > 0) - return; - for (m = 0; m < num_modes; m++) - { - if (modes[m] == mode) - { - memmove (modes + m, modes + m + 1, - (num_modes - m - 1) * sizeof (RRModePtr)); - num_modes--; - if (!num_modes) - { - xfree (modes); - modes = NULL; - } - break; - } - } - - xfree (mode); -} - -static int -RRModeDestroyResource (pointer value, XID pid) -{ - RRModeDestroy ((RRModePtr) value); - return 1; -} - -Bool -RRModeInit (void) -{ - assert (num_modes == 0); - assert (modes == NULL); - RRModeType = CreateNewResourceType (RRModeDestroyResource); - if (!RRModeType) - return FALSE; - RegisterResourceName (RRModeType, "MODE"); - return TRUE; -} - -int -ProcRRCreateMode (ClientPtr client) -{ - REQUEST(xRRCreateModeReq); - xRRCreateModeReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - xRRModeInfo *modeInfo; - long units_after; - char *name; - int error, rc; - RRModePtr mode; - - REQUEST_AT_LEAST_SIZE (xRRCreateModeReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - modeInfo = &stuff->modeInfo; - name = (char *) (stuff + 1); - units_after = (stuff->length - (sizeof (xRRCreateModeReq) >> 2)); - - /* check to make sure requested name fits within the data provided */ - if ((int) (modeInfo->nameLength + 3) >> 2 > units_after) - return BadLength; - - mode = RRModeCreateUser (pScreen, modeInfo, name, &error); - if (!mode) - return error; - - rep.type = X_Reply; - rep.pad0 = 0; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.mode = mode->mode.id; - if (client->swapped) - { - int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.mode, n); - } - WriteToClient(client, sizeof(xRRCreateModeReply), (char *)&rep); - - return client->noClientException; -} - -int -ProcRRDestroyMode (ClientPtr client) -{ - REQUEST(xRRDestroyModeReq); - RRModePtr mode; - - REQUEST_SIZE_MATCH(xRRDestroyModeReq); - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - if (!mode->userScreen) - return BadMatch; - if (mode->refcnt > 1) - return BadAccess; - FreeResource (stuff->mode, 0); - return Success; -} - -int -ProcRRAddOutputMode (ClientPtr client) -{ - REQUEST(xRRAddOutputModeReq); - RRModePtr mode; - RROutputPtr output; - - REQUEST_SIZE_MATCH(xRRAddOutputModeReq); - output = LookupOutput(client, stuff->output, DixReadAccess); - - if (!output) - { - client->errorValue = stuff->output; - return RRErrorBase + BadRROutput; - } - - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - - return RROutputAddUserMode (output, mode); -} - -int -ProcRRDeleteOutputMode (ClientPtr client) -{ - REQUEST(xRRDeleteOutputModeReq); - RRModePtr mode; - RROutputPtr output; - - REQUEST_SIZE_MATCH(xRRDeleteOutputModeReq); - output = LookupOutput(client, stuff->output, DixReadAccess); - - if (!output) - { - client->errorValue = stuff->output; - return RRErrorBase + BadRROutput; - } - - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - - return RROutputDeleteUserMode (output, mode); -} diff --git a/nx-X11/programs/Xserver/randr/rrmode.c.X.original b/nx-X11/programs/Xserver/randr/rrmode.c.X.original deleted file mode 100644 index d5072084a..000000000 --- a/nx-X11/programs/Xserver/randr/rrmode.c.X.original +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "randrstr.h" -#include "registry.h" - -RESTYPE RRModeType; - -static Bool -RRModeEqual (xRRModeInfo *a, xRRModeInfo *b) -{ - if (a->width != b->width) return FALSE; - if (a->height != b->height) return FALSE; - if (a->dotClock != b->dotClock) return FALSE; - if (a->hSyncStart != b->hSyncStart) return FALSE; - if (a->hSyncEnd != b->hSyncEnd) return FALSE; - if (a->hTotal != b->hTotal) return FALSE; - if (a->hSkew != b->hSkew) return FALSE; - if (a->vSyncStart != b->vSyncStart) return FALSE; - if (a->vSyncEnd != b->vSyncEnd) return FALSE; - if (a->vTotal != b->vTotal) return FALSE; - if (a->nameLength != b->nameLength) return FALSE; - if (a->modeFlags != b->modeFlags) return FALSE; - return TRUE; -} - -/* - * Keep a list so it's easy to find modes in the resource database. - */ -static int num_modes; -static RRModePtr *modes; - -static RRModePtr -RRModeCreate (xRRModeInfo *modeInfo, - const char *name, - ScreenPtr userScreen) -{ - RRModePtr mode, *newModes; - - if (!RRInit ()) - return NULL; - - mode = xalloc (sizeof (RRModeRec) + modeInfo->nameLength + 1); - if (!mode) - return NULL; - mode->refcnt = 1; - mode->mode = *modeInfo; - mode->name = (char *) (mode + 1); - memcpy (mode->name, name, modeInfo->nameLength); - mode->name[modeInfo->nameLength] = '\0'; - mode->userScreen = userScreen; - - if (num_modes) - newModes = xrealloc (modes, (num_modes + 1) * sizeof (RRModePtr)); - else - newModes = xalloc (sizeof (RRModePtr)); - - if (!newModes) - { - xfree (mode); - return NULL; - } - - mode->mode.id = FakeClientID(0); - if (!AddResource (mode->mode.id, RRModeType, (pointer) mode)) - return NULL; - modes = newModes; - modes[num_modes++] = mode; - - /* - * give the caller a reference to this mode - */ - ++mode->refcnt; - return mode; -} - -static RRModePtr -RRModeFindByName (const char *name, - CARD16 nameLength) -{ - int i; - RRModePtr mode; - - for (i = 0; i < num_modes; i++) - { - mode = modes[i]; - if (mode->mode.nameLength == nameLength && - !memcmp (name, mode->name, nameLength)) - { - return mode; - } - } - return NULL; -} - -RRModePtr -RRModeGet (xRRModeInfo *modeInfo, - const char *name) -{ - int i; - - for (i = 0; i < num_modes; i++) - { - RRModePtr mode = modes[i]; - if (RRModeEqual (&mode->mode, modeInfo) && - !memcmp (name, mode->name, modeInfo->nameLength)) - { - ++mode->refcnt; - return mode; - } - } - - return RRModeCreate (modeInfo, name, NULL); -} - -static RRModePtr -RRModeCreateUser (ScreenPtr pScreen, - xRRModeInfo *modeInfo, - const char *name, - int *error) -{ - RRModePtr mode; - - mode = RRModeFindByName (name, modeInfo->nameLength); - if (mode) - { - *error = BadName; - return NULL; - } - - mode = RRModeCreate (modeInfo, name, pScreen); - if (!mode) - { - *error = BadAlloc; - return NULL; - } - *error = Success; - return mode; -} - -RRModePtr * -RRModesForScreen (ScreenPtr pScreen, int *num_ret) -{ - rrScrPriv(pScreen); - int o, c, m; - RRModePtr *screen_modes; - int num_screen_modes = 0; - - screen_modes = xalloc ((num_modes ? num_modes : 1) * sizeof (RRModePtr)); - if (!screen_modes) - return NULL; - - /* - * Add modes from all outputs - */ - for (o = 0; o < pScrPriv->numOutputs; o++) - { - RROutputPtr output = pScrPriv->outputs[o]; - int m, n; - - for (m = 0; m < output->numModes + output->numUserModes; m++) - { - RRModePtr mode = (m < output->numModes ? - output->modes[m] : - output->userModes[m-output->numModes]); - for (n = 0; n < num_screen_modes; n++) - if (screen_modes[n] == mode) - break; - if (n == num_screen_modes) - screen_modes[num_screen_modes++] = mode; - } - } - /* - * Add modes from all crtcs. The goal is to - * make sure all available and active modes - * are visible to the client - */ - for (c = 0; c < pScrPriv->numCrtcs; c++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[c]; - RRModePtr mode = crtc->mode; - int n; - - if (!mode) continue; - for (n = 0; n < num_screen_modes; n++) - if (screen_modes[n] == mode) - break; - if (n == num_screen_modes) - screen_modes[num_screen_modes++] = mode; - } - /* - * Add all user modes for this screen - */ - for (m = 0; m < num_modes; m++) - { - RRModePtr mode = modes[m]; - int n; - - if (mode->userScreen != pScreen) - continue; - for (n = 0; n < num_screen_modes; n++) - if (screen_modes[n] == mode) - break; - if (n == num_screen_modes) - screen_modes[num_screen_modes++] = mode; - } - - *num_ret = num_screen_modes; - return screen_modes; -} - -void -RRModeDestroy (RRModePtr mode) -{ - int m; - - if (--mode->refcnt > 0) - return; - for (m = 0; m < num_modes; m++) - { - if (modes[m] == mode) - { - memmove (modes + m, modes + m + 1, - (num_modes - m - 1) * sizeof (RRModePtr)); - num_modes--; - if (!num_modes) - { - xfree (modes); - modes = NULL; - } - break; - } - } - - xfree (mode); -} - -static int -RRModeDestroyResource (pointer value, XID pid) -{ - RRModeDestroy ((RRModePtr) value); - return 1; -} - -Bool -RRModeInit (void) -{ - assert (num_modes == 0); - assert (modes == NULL); - RRModeType = CreateNewResourceType (RRModeDestroyResource); - if (!RRModeType) - return FALSE; - RegisterResourceName (RRModeType, "MODE"); - return TRUE; -} - -int -ProcRRCreateMode (ClientPtr client) -{ - REQUEST(xRRCreateModeReq); - xRRCreateModeReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - xRRModeInfo *modeInfo; - long units_after; - char *name; - int error, rc; - RRModePtr mode; - - REQUEST_AT_LEAST_SIZE (xRRCreateModeReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - modeInfo = &stuff->modeInfo; - name = (char *) (stuff + 1); - units_after = (stuff->length - (sizeof (xRRCreateModeReq) >> 2)); - - /* check to make sure requested name fits within the data provided */ - if ((int) (modeInfo->nameLength + 3) >> 2 > units_after) - return BadLength; - - mode = RRModeCreateUser (pScreen, modeInfo, name, &error); - if (!mode) - return error; - - rep.type = X_Reply; - rep.pad0 = 0; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.mode = mode->mode.id; - if (client->swapped) - { - int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.mode, n); - } - WriteToClient(client, sizeof(xRRCreateModeReply), (char *)&rep); - - return client->noClientException; -} - -int -ProcRRDestroyMode (ClientPtr client) -{ - REQUEST(xRRDestroyModeReq); - RRModePtr mode; - - REQUEST_SIZE_MATCH(xRRDestroyModeReq); - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - if (!mode->userScreen) - return BadMatch; - if (mode->refcnt > 1) - return BadAccess; - FreeResource (stuff->mode, 0); - return Success; -} - -int -ProcRRAddOutputMode (ClientPtr client) -{ - REQUEST(xRRAddOutputModeReq); - RRModePtr mode; - RROutputPtr output; - - REQUEST_SIZE_MATCH(xRRAddOutputModeReq); - output = LookupOutput(client, stuff->output, DixReadAccess); - - if (!output) - { - client->errorValue = stuff->output; - return RRErrorBase + BadRROutput; - } - - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - - return RROutputAddUserMode (output, mode); -} - -int -ProcRRDeleteOutputMode (ClientPtr client) -{ - REQUEST(xRRDeleteOutputModeReq); - RRModePtr mode; - RROutputPtr output; - - REQUEST_SIZE_MATCH(xRRDeleteOutputModeReq); - output = LookupOutput(client, stuff->output, DixReadAccess); - - if (!output) - { - client->errorValue = stuff->output; - return RRErrorBase + BadRROutput; - } - - mode = LookupIDByType (stuff->mode, RRModeType); - if (!mode) - { - client->errorValue = stuff->mode; - return RRErrorBase + BadRRMode; - } - - return RROutputDeleteUserMode (output, mode); -} diff --git a/nx-X11/programs/Xserver/randr/rrscreen.c.NX.original b/nx-X11/programs/Xserver/randr/rrscreen.c.NX.original deleted file mode 100644 index 9b3935e03..000000000 --- a/nx-X11/programs/Xserver/randr/rrscreen.c.NX.original +++ /dev/null @@ -1,1030 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#include "randrstr.h" - -extern char *ConnectionInfo; - -static int padlength[4] = {0, 3, 2, 1}; - -static CARD16 -RR10CurrentSizeID (ScreenPtr pScreen); - -/* - * Edit connection information block so that new clients - * see the current screen size on connect - */ -static void -RREditConnectionInfo (ScreenPtr pScreen) -{ - xConnSetup *connSetup; - char *vendor; - xPixmapFormat *formats; - xWindowRoot *root; - xDepth *depth; - xVisualType *visual; - int screen = 0; - int d; - - connSetup = (xConnSetup *) ConnectionInfo; - vendor = (char *) connSetup + sizeof (xConnSetup); - formats = (xPixmapFormat *) ((char *) vendor + - connSetup->nbytesVendor + - padlength[connSetup->nbytesVendor & 3]); - root = (xWindowRoot *) ((char *) formats + - sizeof (xPixmapFormat) * screenInfo.numPixmapFormats); - while (screen != pScreen->myNum) - { - depth = (xDepth *) ((char *) root + - sizeof (xWindowRoot)); - for (d = 0; d < root->nDepths; d++) - { - visual = (xVisualType *) ((char *) depth + - sizeof (xDepth)); - depth = (xDepth *) ((char *) visual + - depth->nVisuals * sizeof (xVisualType)); - } - root = (xWindowRoot *) ((char *) depth); - screen++; - } - root->pixWidth = pScreen->width; - root->pixHeight = pScreen->height; - root->mmWidth = pScreen->mmWidth; - root->mmHeight = pScreen->mmHeight; -} - -void -RRSendConfigNotify (ScreenPtr pScreen) -{ - WindowPtr pWin = WindowTable[pScreen->myNum]; - xEvent event; - - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = 0; - event.u.configureNotify.y = 0; - - /* XXX xinerama stuff ? */ - - event.u.configureNotify.width = pWin->drawable.width; - event.u.configureNotify.height = pWin->drawable.height; - event.u.configureNotify.borderWidth = wBorderWidth (pWin); - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); -} - -void -RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) -{ - rrScrPriv (pScreen); - xRRScreenChangeNotifyEvent se; - RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL; - WindowPtr pRoot = WindowTable[pScreen->myNum]; - - se.type = RRScreenChangeNotify + RREventBase; - se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0); - se.timestamp = pScrPriv->lastSetTime.milliseconds; - se.sequenceNumber = client->sequence; - se.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - se.root = pRoot->drawable.id; - se.window = pWin->drawable.id; -#ifdef RENDER - se.subpixelOrder = PictureGetSubpixelOrder (pScreen); -#else - se.subpixelOrder = SubPixelUnknown; -#endif - - se.sequenceNumber = client->sequence; - se.sizeID = RR10CurrentSizeID (pScreen); - - if (se.rotation & (RR_Rotate_90 | RR_Rotate_270)) { - se.widthInPixels = pScreen->height; - se.heightInPixels = pScreen->width; - se.widthInMillimeters = pScreen->mmHeight; - se.heightInMillimeters = pScreen->mmWidth; - } else { - se.widthInPixels = pScreen->width; - se.heightInPixels = pScreen->height; - se.widthInMillimeters = pScreen->mmWidth; - se.heightInMillimeters = pScreen->mmHeight; - } - - WriteEventsToClient (client, 1, (xEvent *) &se); -} - -/* - * Notify the extension that the screen size has been changed. - * The driver is responsible for calling this whenever it has changed - * the size of the screen - */ -void -RRScreenSizeNotify (ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - /* - * Deliver ConfigureNotify events when root changes - * pixel size - */ - if (pScrPriv->width == pScreen->width && - pScrPriv->height == pScreen->height && - pScrPriv->mmWidth == pScreen->mmWidth && - pScrPriv->mmHeight == pScreen->mmHeight) - return; - - pScrPriv->width = pScreen->width; - pScrPriv->height = pScreen->height; - pScrPriv->mmWidth = pScreen->mmWidth; - pScrPriv->mmHeight = pScreen->mmHeight; - pScrPriv->changed = TRUE; -/* pScrPriv->sizeChanged = TRUE; */ - - RRTellChanged (pScreen); - RRSendConfigNotify (pScreen); - RREditConnectionInfo (pScreen); - - RRPointerScreenConfigured (pScreen); - /* - * Fix pointer bounds and location - */ - ScreenRestructured (pScreen); -} - -/* - * Request that the screen be resized - */ -Bool -RRScreenSizeSet (ScreenPtr pScreen, - CARD16 width, - CARD16 height, - CARD32 mmWidth, - CARD32 mmHeight) -{ - rrScrPriv(pScreen); - -#if RANDR_12_INTERFACE - if (pScrPriv->rrScreenSetSize) - { - return (*pScrPriv->rrScreenSetSize) (pScreen, - width, height, - mmWidth, mmHeight); - } -#endif -#if RANDR_10_INTERFACE - if (pScrPriv->rrSetConfig) - { - return TRUE; /* can't set size separately */ - } -#endif - return FALSE; -} - -/* - * Retrieve valid screen size range - */ -int -ProcRRGetScreenSizeRange (ClientPtr client) -{ - REQUEST(xRRGetScreenSizeRangeReq); - xRRGetScreenSizeRangeReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - int rc; - - REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - rep.type = X_Reply; - rep.pad = 0; - rep.sequenceNumber = client->sequence; - rep.length = 0; - - if (pScrPriv) - { - if (!RRGetInfo (pScreen)) - return BadAlloc; - rep.minWidth = pScrPriv->minWidth; - rep.minHeight = pScrPriv->minHeight; - rep.maxWidth = pScrPriv->maxWidth; - rep.maxHeight = pScrPriv->maxHeight; - } - else - { - rep.maxWidth = rep.minWidth = pScreen->width; - rep.maxHeight = rep.minHeight = pScreen->height; - } - if (client->swapped) - { - int n; - - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.minWidth, n); - swaps(&rep.minHeight, n); - swaps(&rep.maxWidth, n); - swaps(&rep.maxHeight, n); - } - WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), (char *)&rep); - return (client->noClientException); -} - -int -ProcRRSetScreenSize (ClientPtr client) -{ - REQUEST(xRRSetScreenSizeReq); - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - int i, rc; - - REQUEST_SIZE_MATCH(xRRSetScreenSizeReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) - { - client->errorValue = stuff->width; - return BadValue; - } - if (stuff->height < pScrPriv->minHeight || - pScrPriv->maxHeight < stuff->height) - { - client->errorValue = stuff->height; - return BadValue; - } - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - RRModePtr mode = crtc->mode; - if (mode) - { - int source_width = mode->mode.width; - int source_height = mode->mode.height; - Rotation rotation = crtc->rotation; - - if (rotation == RR_Rotate_90 || rotation == RR_Rotate_270) - { - source_width = mode->mode.height; - source_height = mode->mode.width; - } - - if (crtc->x + source_width > stuff->width || - crtc->y + source_height > stuff->height) - return BadMatch; - } - } - if (stuff->widthInMillimeters == 0 || stuff->heightInMillimeters == 0) - { - client->errorValue = 0; - return BadValue; - } - if (!RRScreenSizeSet (pScreen, - stuff->width, stuff->height, - stuff->widthInMillimeters, - stuff->heightInMillimeters)) - { - return BadMatch; - } - return Success; -} - -int -ProcRRGetScreenResources (ClientPtr client) -{ - REQUEST(xRRGetScreenResourcesReq); - xRRGetScreenResourcesReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - int i, n, rc; - RRCrtc *crtcs; - RROutput *outputs; - xRRModeInfo *modeinfos; - CARD8 *names; - - REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; - - if (pScrPriv) - if (!RRGetInfo (pScreen)) - return BadAlloc; - - if (!pScrPriv) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nCrtcs = 0; - rep.nOutputs = 0; - rep.nModes = 0; - rep.nbytesNames = 0; - extra = NULL; - extraLen = 0; - } - else - { - RRModePtr *modes; - int num_modes; - - modes = RRModesForScreen (pScreen, &num_modes); - if (!modes) - return BadAlloc; - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.nCrtcs = pScrPriv->numCrtcs; - rep.nOutputs = pScrPriv->numOutputs; - rep.nModes = num_modes; - rep.nbytesNames = 0; - - for (i = 0; i < num_modes; i++) - rep.nbytesNames += modes[i]->mode.nameLength; - - rep.length = (pScrPriv->numCrtcs + - pScrPriv->numOutputs + - num_modes * (SIZEOF(xRRModeInfo) >> 2) + - ((rep.nbytesNames + 3) >> 2)); - - extraLen = rep.length << 2; - if (extraLen) - { - extra = xalloc (extraLen); - if (!extra) - { - xfree (modes); - return BadAlloc; - } - } - else - extra = NULL; - - crtcs = (RRCrtc *) extra; - outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs); - modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs); - names = (CARD8 *) (modeinfos + num_modes); - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - crtcs[i] = pScrPriv->crtcs[i]->id; - if (client->swapped) - swapl (&crtcs[i], n); - } - - for (i = 0; i < pScrPriv->numOutputs; i++) - { - outputs[i] = pScrPriv->outputs[i]->id; - if (client->swapped) - swapl (&outputs[i], n); - } - - for (i = 0; i < num_modes; i++) - { - RRModePtr mode = modes[i]; - modeinfos[i] = mode->mode; - if (client->swapped) - { - swapl (&modeinfos[i].id, n); - swaps (&modeinfos[i].width, n); - swaps (&modeinfos[i].height, n); - swapl (&modeinfos[i].dotClock, n); - swaps (&modeinfos[i].hSyncStart, n); - swaps (&modeinfos[i].hSyncEnd, n); - swaps (&modeinfos[i].hTotal, n); - swaps (&modeinfos[i].hSkew, n); - swaps (&modeinfos[i].vSyncStart, n); - swaps (&modeinfos[i].vSyncEnd, n); - swaps (&modeinfos[i].vTotal, n); - swaps (&modeinfos[i].nameLength, n); - swapl (&modeinfos[i].modeFlags, n); - } - memcpy (names, mode->name, - mode->mode.nameLength); - names += mode->mode.nameLength; - } - xfree (modes); - assert (((((char *) names - (char *) extra) + 3) >> 2) == rep.length); - } - - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swapl(&rep.configTimestamp, n); - swaps(&rep.nCrtcs, n); - swaps(&rep.nOutputs, n); - swaps(&rep.nModes, n); - swaps(&rep.nbytesNames, n); - } - WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - return client->noClientException; -} - -typedef struct _RR10Data { - RRScreenSizePtr sizes; - int nsize; - int nrefresh; - int size; - CARD16 refresh; -} RR10DataRec, *RR10DataPtr; - -/* - * Convert 1.2 monitor data into 1.0 screen data - */ -static RR10DataPtr -RR10GetData (ScreenPtr pScreen, RROutputPtr output) -{ - RR10DataPtr data; - RRScreenSizePtr size; - int nmode = output->numModes + output->numUserModes; - int o, os, l, r; - RRScreenRatePtr refresh; - CARD16 vRefresh; - RRModePtr mode; - Bool *used; - - /* Make sure there is plenty of space for any combination */ - data = malloc (sizeof (RR10DataRec) + - sizeof (RRScreenSize) * nmode + - sizeof (RRScreenRate) * nmode + - sizeof (Bool) * nmode); - if (!data) - return NULL; - size = (RRScreenSizePtr) (data + 1); - refresh = (RRScreenRatePtr) (size + nmode); - used = (Bool *) (refresh + nmode); - memset (used, '\0', sizeof (Bool) * nmode); - data->sizes = size; - data->nsize = 0; - data->nrefresh = 0; - data->size = 0; - data->refresh = 0; - - /* - * find modes not yet listed - */ - for (o = 0; o < output->numModes + output->numUserModes; o++) - { - if (used[o]) continue; - - if (o < output->numModes) - mode = output->modes[o]; - else - mode = output->userModes[o - output->numModes]; - - l = data->nsize; - size[l].id = data->nsize; - size[l].width = mode->mode.width; - size[l].height = mode->mode.height; - if (output->mmWidth && output->mmHeight) { - size[l].mmWidth = output->mmWidth; - size[l].mmHeight = output->mmHeight; - } else { - size[l].mmWidth = pScreen->mmWidth; - size[l].mmHeight = pScreen->mmHeight; - } - size[l].nRates = 0; - size[l].pRates = &refresh[data->nrefresh]; - data->nsize++; - - /* - * Find all modes with matching size - */ - for (os = o; os < output->numModes + output->numUserModes; os++) - { - if (os < output->numModes) - mode = output->modes[os]; - else - mode = output->userModes[os - output->numModes]; - if (mode->mode.width == size[l].width && - mode->mode.height == size[l].height) - { - vRefresh = RRVerticalRefresh (&mode->mode); - used[os] = TRUE; - - for (r = 0; r < size[l].nRates; r++) - if (vRefresh == size[l].pRates[r].rate) - break; - if (r == size[l].nRates) - { - size[l].pRates[r].rate = vRefresh; - size[l].pRates[r].mode = mode; - size[l].nRates++; - data->nrefresh++; - } - if (mode == output->crtc->mode) - { - data->size = l; - data->refresh = vRefresh; - } - } - } - } - return data; -} - -int -ProcRRGetScreenInfo (ClientPtr client) -{ - REQUEST(xRRGetScreenInfoReq); - xRRGetScreenInfoReply rep; - WindowPtr pWin; - int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - RROutputPtr output; - - REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; - - if (pScrPriv) - if (!RRGetInfo (pScreen)) - return BadAlloc; - - output = RRFirstOutput (pScreen); - - if (!pScrPriv || !output) - { - rep.type = X_Reply; - rep.setOfRotations = RR_Rotate_0;; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nSizes = 0; - rep.sizeID = 0; - rep.rotation = RR_Rotate_0; - rep.rate = 0; - rep.nrateEnts = 0; - extra = 0; - extraLen = 0; - } - else - { - int i, j; - xScreenSizes *size; - CARD16 *rates; - CARD8 *data8; - Bool has_rate = RRClientKnowsRates (client); - RR10DataPtr pData; - RRScreenSizePtr pSize; - - pData = RR10GetData (pScreen, output); - if (!pData) - return BadAlloc; - - rep.type = X_Reply; - rep.setOfRotations = output->crtc->rotations; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.rotation = output->crtc->rotation; - rep.nSizes = pData->nsize; - rep.nrateEnts = pData->nrefresh + pData->nsize; - rep.sizeID = pData->size; - rep.rate = pData->refresh; - - extraLen = (rep.nSizes * sizeof (xScreenSizes) + - rep.nrateEnts * sizeof (CARD16)); - - if (extraLen) - { - extra = (CARD8 *) xalloc (extraLen); - if (!extra) - { - xfree (pData); - return BadAlloc; - } - } - else - extra = NULL; - - /* - * First comes the size information - */ - size = (xScreenSizes *) extra; - rates = (CARD16 *) (size + rep.nSizes); - for (i = 0; i < pData->nsize; i++) - { - pSize = &pData->sizes[i]; - size->widthInPixels = pSize->width; - size->heightInPixels = pSize->height; - size->widthInMillimeters = pSize->mmWidth; - size->heightInMillimeters = pSize->mmHeight; - if (client->swapped) - { - swaps (&size->widthInPixels, n); - swaps (&size->heightInPixels, n); - swaps (&size->widthInMillimeters, n); - swaps (&size->heightInMillimeters, n); - } - size++; - if (has_rate) - { - *rates = pSize->nRates; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - for (j = 0; j < pSize->nRates; j++) - { - *rates = pSize->pRates[j].rate; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - } - } - } - xfree (pData); - - data8 = (CARD8 *) rates; - - if (data8 - (CARD8 *) extra != extraLen) - FatalError ("RRGetScreenInfo bad extra len %ld != %ld\n", - (unsigned long)(data8 - (CARD8 *) extra), extraLen); - rep.length = (extraLen + 3) >> 2; - } - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swaps(&rep.rotation, n); - swaps(&rep.nSizes, n); - swaps(&rep.sizeID, n); - swaps(&rep.rate, n); - swaps(&rep.nrateEnts, n); - } - WriteToClient(client, sizeof(xRRGetScreenInfoReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - return (client->noClientException); -} - -int -ProcRRSetScreenConfig (ClientPtr client) -{ - REQUEST(xRRSetScreenConfigReq); - xRRSetScreenConfigReply rep; - DrawablePtr pDraw; - int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - TimeStamp time; - int i; - Rotation rotation; - int rate; - Bool has_rate; - RROutputPtr output; - RRCrtcPtr crtc; - RRModePtr mode; - RR10DataPtr pData = NULL; - RRScreenSizePtr pSize; - int width, height; - - UpdateCurrentTime (); - - if (RRClientKnowsRates (client)) - { - REQUEST_SIZE_MATCH (xRRSetScreenConfigReq); - has_rate = TRUE; - } - else - { - REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq); - has_rate = FALSE; - } - - #ifndef NXAGENT_SERVER - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); - #else - pDraw = SecurityLookupDrawable(stuff->drawable, client, SecurityWriteAccess); - rc = pDraw ? Success : BadDrawable; - #endif - if (rc != Success) - return rc; - - pScreen = pDraw->pScreen; - - pScrPriv = rrGetScrPriv(pScreen); - - time = ClientTimeToServerTime(stuff->timestamp); - - if (!pScrPriv) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - if (!RRGetInfo (pScreen)) - return BadAlloc; - - output = RRFirstOutput (pScreen); - if (!output) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - - crtc = output->crtc; - - /* - * If the client's config timestamp is not the same as the last config - * timestamp, then the config information isn't up-to-date and - * can't even be validated. - * - * Note that the client only knows about the milliseconds part of the - * timestamp, so using CompareTimeStamps here would cause randr to suddenly - * stop working after several hours have passed (freedesktop bug #6502). - */ - if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) - { - rep.status = RRSetConfigInvalidConfigTime; - goto sendReply; - } - - pData = RR10GetData (pScreen, output); - if (!pData) - return BadAlloc; - - if (stuff->sizeID >= pData->nsize) - { - /* - * Invalid size ID - */ - client->errorValue = stuff->sizeID; - xfree (pData); - return BadValue; - } - pSize = &pData->sizes[stuff->sizeID]; - - /* - * Validate requested rotation - */ - rotation = (Rotation) stuff->rotation; - - /* test the rotation bits only! */ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_90: - case RR_Rotate_180: - case RR_Rotate_270: - break; - default: - /* - * Invalid rotation - */ - client->errorValue = stuff->rotation; - xfree (pData); - return BadValue; - } - - if ((~crtc->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - client->errorValue = stuff->rotation; - xfree (pData); - return BadMatch; - } - - /* - * Validate requested refresh - */ - if (has_rate) - rate = (int) stuff->rate; - else - rate = 0; - - if (rate) - { - for (i = 0; i < pSize->nRates; i++) - { - if (pSize->pRates[i].rate == rate) - break; - } - if (i == pSize->nRates) - { - /* - * Invalid rate - */ - client->errorValue = rate; - xfree (pData); - return BadValue; - } - mode = pSize->pRates[i].mode; - } - else - mode = pSize->pRates[0].mode; - - /* - * Make sure the requested set-time is not older than - * the last set-time - */ - if (CompareTimeStamps (time, pScrPriv->lastSetTime) < 0) - { - rep.status = RRSetConfigInvalidTime; - goto sendReply; - } - - /* - * If the screen size is changing, adjust all of the other outputs - * to fit the new size, mirroring as much as possible - */ - width = mode->mode.width; - height = mode->mode.height; - if (rotation & (RR_Rotate_90|RR_Rotate_270)) - { - width = mode->mode.height; - height = mode->mode.width; - } - if (width != pScreen->width || height != pScreen->height) - { - int c; - - for (c = 0; c < pScrPriv->numCrtcs; c++) - { - if (!RRCrtcSet (pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0, - 0, NULL)) - { - rep.status = RRSetConfigFailed; - /* XXX recover from failure */ - goto sendReply; - } - } - if (!RRScreenSizeSet (pScreen, width, height, - pScreen->mmWidth, pScreen->mmHeight)) - { - rep.status = RRSetConfigFailed; - /* XXX recover from failure */ - goto sendReply; - } - } - - if (!RRCrtcSet (crtc, mode, 0, 0, stuff->rotation, 1, &output)) - rep.status = RRSetConfigFailed; - #ifndef NXAGENT_SERVER /* Bug 21987 */ - else - rep.status = RRSetConfigSuccess; - #else - else { - rep.status = RRSetConfigSuccess; - pScrPriv->lastSetTime = time; - } - #endif - - /* - * XXX Configure other crtcs to mirror as much as possible - */ - -sendReply: - - if (pData) - xfree (pData); - - rep.type = X_Reply; - /* rep.status has already been filled in */ - rep.length = 0; - rep.sequenceNumber = client->sequence; - - rep.newTimestamp = pScrPriv->lastSetTime.milliseconds; - rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - - if (client->swapped) - { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.newTimestamp, n); - swapl(&rep.newConfigTimestamp, n); - swapl(&rep.root, n); - } - WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *)&rep); - - return (client->noClientException); -} - -static CARD16 -RR10CurrentSizeID (ScreenPtr pScreen) -{ - CARD16 sizeID = 0xffff; - RROutputPtr output = RRFirstOutput (pScreen); - - if (output) - { - RR10DataPtr data = RR10GetData (pScreen, output); - if (data) - { - int i; - for (i = 0; i < data->nsize; i++) - if (data->sizes[i].width == pScreen->width && - data->sizes[i].height == pScreen->height) - { - sizeID = (CARD16) i; - break; - } - xfree (data); - } - } - return sizeID; -} diff --git a/nx-X11/programs/Xserver/randr/rrscreen.c.X.original b/nx-X11/programs/Xserver/randr/rrscreen.c.X.original deleted file mode 100644 index f39197337..000000000 --- a/nx-X11/programs/Xserver/randr/rrscreen.c.X.original +++ /dev/null @@ -1,981 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "randrstr.h" - -extern char *ConnectionInfo; - -static int padlength[4] = {0, 3, 2, 1}; - -static CARD16 -RR10CurrentSizeID (ScreenPtr pScreen); - -/* - * Edit connection information block so that new clients - * see the current screen size on connect - */ -static void -RREditConnectionInfo (ScreenPtr pScreen) -{ - xConnSetup *connSetup; - char *vendor; - xPixmapFormat *formats; - xWindowRoot *root; - xDepth *depth; - xVisualType *visual; - int screen = 0; - int d; - - connSetup = (xConnSetup *) ConnectionInfo; - vendor = (char *) connSetup + sizeof (xConnSetup); - formats = (xPixmapFormat *) ((char *) vendor + - connSetup->nbytesVendor + - padlength[connSetup->nbytesVendor & 3]); - root = (xWindowRoot *) ((char *) formats + - sizeof (xPixmapFormat) * screenInfo.numPixmapFormats); - while (screen != pScreen->myNum) - { - depth = (xDepth *) ((char *) root + - sizeof (xWindowRoot)); - for (d = 0; d < root->nDepths; d++) - { - visual = (xVisualType *) ((char *) depth + - sizeof (xDepth)); - depth = (xDepth *) ((char *) visual + - depth->nVisuals * sizeof (xVisualType)); - } - root = (xWindowRoot *) ((char *) depth); - screen++; - } - root->pixWidth = pScreen->width; - root->pixHeight = pScreen->height; - root->mmWidth = pScreen->mmWidth; - root->mmHeight = pScreen->mmHeight; -} - -void -RRSendConfigNotify (ScreenPtr pScreen) -{ - WindowPtr pWin = WindowTable[pScreen->myNum]; - xEvent event; - - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = 0; - event.u.configureNotify.y = 0; - - /* XXX xinerama stuff ? */ - - event.u.configureNotify.width = pWin->drawable.width; - event.u.configureNotify.height = pWin->drawable.height; - event.u.configureNotify.borderWidth = wBorderWidth (pWin); - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); -} - -void -RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) -{ - rrScrPriv (pScreen); - xRRScreenChangeNotifyEvent se; - RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL; - WindowPtr pRoot = WindowTable[pScreen->myNum]; - - se.type = RRScreenChangeNotify + RREventBase; - se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0); - se.timestamp = pScrPriv->lastSetTime.milliseconds; - se.sequenceNumber = client->sequence; - se.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - se.root = pRoot->drawable.id; - se.window = pWin->drawable.id; -#ifdef RENDER - se.subpixelOrder = PictureGetSubpixelOrder (pScreen); -#else - se.subpixelOrder = SubPixelUnknown; -#endif - - se.sequenceNumber = client->sequence; - se.sizeID = RR10CurrentSizeID (pScreen); - - if (se.rotation & (RR_Rotate_90 | RR_Rotate_270)) { - se.widthInPixels = pScreen->height; - se.heightInPixels = pScreen->width; - se.widthInMillimeters = pScreen->mmHeight; - se.heightInMillimeters = pScreen->mmWidth; - } else { - se.widthInPixels = pScreen->width; - se.heightInPixels = pScreen->height; - se.widthInMillimeters = pScreen->mmWidth; - se.heightInMillimeters = pScreen->mmHeight; - } - - WriteEventsToClient (client, 1, (xEvent *) &se); -} - -/* - * Notify the extension that the screen size has been changed. - * The driver is responsible for calling this whenever it has changed - * the size of the screen - */ -void -RRScreenSizeNotify (ScreenPtr pScreen) -{ - rrScrPriv(pScreen); - /* - * Deliver ConfigureNotify events when root changes - * pixel size - */ - if (pScrPriv->width == pScreen->width && - pScrPriv->height == pScreen->height && - pScrPriv->mmWidth == pScreen->mmWidth && - pScrPriv->mmHeight == pScreen->mmHeight) - return; - - pScrPriv->width = pScreen->width; - pScrPriv->height = pScreen->height; - pScrPriv->mmWidth = pScreen->mmWidth; - pScrPriv->mmHeight = pScreen->mmHeight; - pScrPriv->changed = TRUE; -/* pScrPriv->sizeChanged = TRUE; */ - - RRTellChanged (pScreen); - RRSendConfigNotify (pScreen); - RREditConnectionInfo (pScreen); - - RRPointerScreenConfigured (pScreen); - /* - * Fix pointer bounds and location - */ - ScreenRestructured (pScreen); -} - -/* - * Request that the screen be resized - */ -Bool -RRScreenSizeSet (ScreenPtr pScreen, - CARD16 width, - CARD16 height, - CARD32 mmWidth, - CARD32 mmHeight) -{ - rrScrPriv(pScreen); - -#if RANDR_12_INTERFACE - if (pScrPriv->rrScreenSetSize) - { - return (*pScrPriv->rrScreenSetSize) (pScreen, - width, height, - mmWidth, mmHeight); - } -#endif -#if RANDR_10_INTERFACE - if (pScrPriv->rrSetConfig) - { - return TRUE; /* can't set size separately */ - } -#endif - return FALSE; -} - -/* - * Retrieve valid screen size range - */ -int -ProcRRGetScreenSizeRange (ClientPtr client) -{ - REQUEST(xRRGetScreenSizeRangeReq); - xRRGetScreenSizeRangeReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - int rc; - - REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - - rep.type = X_Reply; - rep.pad = 0; - rep.sequenceNumber = client->sequence; - rep.length = 0; - - if (pScrPriv) - { - if (!RRGetInfo (pScreen)) - return BadAlloc; - rep.minWidth = pScrPriv->minWidth; - rep.minHeight = pScrPriv->minHeight; - rep.maxWidth = pScrPriv->maxWidth; - rep.maxHeight = pScrPriv->maxHeight; - } - else - { - rep.maxWidth = rep.minWidth = pScreen->width; - rep.maxHeight = rep.minHeight = pScreen->height; - } - if (client->swapped) - { - int n; - - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.minWidth, n); - swaps(&rep.minHeight, n); - swaps(&rep.maxWidth, n); - swaps(&rep.maxHeight, n); - } - WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), (char *)&rep); - return (client->noClientException); -} - -int -ProcRRSetScreenSize (ClientPtr client) -{ - REQUEST(xRRSetScreenSizeReq); - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - int i, rc; - - REQUEST_SIZE_MATCH(xRRSetScreenSizeReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) - { - client->errorValue = stuff->width; - return BadValue; - } - if (stuff->height < pScrPriv->minHeight || - pScrPriv->maxHeight < stuff->height) - { - client->errorValue = stuff->height; - return BadValue; - } - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - RRModePtr mode = crtc->mode; - if (mode) - { - int source_width = mode->mode.width; - int source_height = mode->mode.height; - Rotation rotation = crtc->rotation; - - if (rotation == RR_Rotate_90 || rotation == RR_Rotate_270) - { - source_width = mode->mode.height; - source_height = mode->mode.width; - } - - if (crtc->x + source_width > stuff->width || - crtc->y + source_height > stuff->height) - return BadMatch; - } - } - if (stuff->widthInMillimeters == 0 || stuff->heightInMillimeters == 0) - { - client->errorValue = 0; - return BadValue; - } - if (!RRScreenSizeSet (pScreen, - stuff->width, stuff->height, - stuff->widthInMillimeters, - stuff->heightInMillimeters)) - { - return BadMatch; - } - return Success; -} - -int -ProcRRGetScreenResources (ClientPtr client) -{ - REQUEST(xRRGetScreenResourcesReq); - xRRGetScreenResourcesReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - int i, n, rc; - RRCrtc *crtcs; - RROutput *outputs; - xRRModeInfo *modeinfos; - CARD8 *names; - - REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; - - if (pScrPriv) - if (!RRGetInfo (pScreen)) - return BadAlloc; - - if (!pScrPriv) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nCrtcs = 0; - rep.nOutputs = 0; - rep.nModes = 0; - rep.nbytesNames = 0; - extra = NULL; - extraLen = 0; - } - else - { - RRModePtr *modes; - int num_modes; - - modes = RRModesForScreen (pScreen, &num_modes); - if (!modes) - return BadAlloc; - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.nCrtcs = pScrPriv->numCrtcs; - rep.nOutputs = pScrPriv->numOutputs; - rep.nModes = num_modes; - rep.nbytesNames = 0; - - for (i = 0; i < num_modes; i++) - rep.nbytesNames += modes[i]->mode.nameLength; - - rep.length = (pScrPriv->numCrtcs + - pScrPriv->numOutputs + - num_modes * (SIZEOF(xRRModeInfo) >> 2) + - ((rep.nbytesNames + 3) >> 2)); - - extraLen = rep.length << 2; - if (extraLen) - { - extra = xalloc (extraLen); - if (!extra) - { - xfree (modes); - return BadAlloc; - } - } - else - extra = NULL; - - crtcs = (RRCrtc *) extra; - outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs); - modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs); - names = (CARD8 *) (modeinfos + num_modes); - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - crtcs[i] = pScrPriv->crtcs[i]->id; - if (client->swapped) - swapl (&crtcs[i], n); - } - - for (i = 0; i < pScrPriv->numOutputs; i++) - { - outputs[i] = pScrPriv->outputs[i]->id; - if (client->swapped) - swapl (&outputs[i], n); - } - - for (i = 0; i < num_modes; i++) - { - RRModePtr mode = modes[i]; - modeinfos[i] = mode->mode; - if (client->swapped) - { - swapl (&modeinfos[i].id, n); - swaps (&modeinfos[i].width, n); - swaps (&modeinfos[i].height, n); - swapl (&modeinfos[i].dotClock, n); - swaps (&modeinfos[i].hSyncStart, n); - swaps (&modeinfos[i].hSyncEnd, n); - swaps (&modeinfos[i].hTotal, n); - swaps (&modeinfos[i].hSkew, n); - swaps (&modeinfos[i].vSyncStart, n); - swaps (&modeinfos[i].vSyncEnd, n); - swaps (&modeinfos[i].vTotal, n); - swaps (&modeinfos[i].nameLength, n); - swapl (&modeinfos[i].modeFlags, n); - } - memcpy (names, mode->name, - mode->mode.nameLength); - names += mode->mode.nameLength; - } - xfree (modes); - assert (((((char *) names - (char *) extra) + 3) >> 2) == rep.length); - } - - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swapl(&rep.configTimestamp, n); - swaps(&rep.nCrtcs, n); - swaps(&rep.nOutputs, n); - swaps(&rep.nModes, n); - swaps(&rep.nbytesNames, n); - } - WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - return client->noClientException; -} - -typedef struct _RR10Data { - RRScreenSizePtr sizes; - int nsize; - int nrefresh; - int size; - CARD16 refresh; -} RR10DataRec, *RR10DataPtr; - -/* - * Convert 1.2 monitor data into 1.0 screen data - */ -static RR10DataPtr -RR10GetData (ScreenPtr pScreen, RROutputPtr output) -{ - RR10DataPtr data; - RRScreenSizePtr size; - int nmode = output->numModes + output->numUserModes; - int o, os, l, r; - RRScreenRatePtr refresh; - CARD16 vRefresh; - RRModePtr mode; - Bool *used; - - /* Make sure there is plenty of space for any combination */ - data = malloc (sizeof (RR10DataRec) + - sizeof (RRScreenSize) * nmode + - sizeof (RRScreenRate) * nmode + - sizeof (Bool) * nmode); - if (!data) - return NULL; - size = (RRScreenSizePtr) (data + 1); - refresh = (RRScreenRatePtr) (size + nmode); - used = (Bool *) (refresh + nmode); - memset (used, '\0', sizeof (Bool) * nmode); - data->sizes = size; - data->nsize = 0; - data->nrefresh = 0; - data->size = 0; - data->refresh = 0; - - /* - * find modes not yet listed - */ - for (o = 0; o < output->numModes + output->numUserModes; o++) - { - if (used[o]) continue; - - if (o < output->numModes) - mode = output->modes[o]; - else - mode = output->userModes[o - output->numModes]; - - l = data->nsize; - size[l].id = data->nsize; - size[l].width = mode->mode.width; - size[l].height = mode->mode.height; - if (output->mmWidth && output->mmHeight) { - size[l].mmWidth = output->mmWidth; - size[l].mmHeight = output->mmHeight; - } else { - size[l].mmWidth = pScreen->mmWidth; - size[l].mmHeight = pScreen->mmHeight; - } - size[l].nRates = 0; - size[l].pRates = &refresh[data->nrefresh]; - data->nsize++; - - /* - * Find all modes with matching size - */ - for (os = o; os < output->numModes + output->numUserModes; os++) - { - if (os < output->numModes) - mode = output->modes[os]; - else - mode = output->userModes[os - output->numModes]; - if (mode->mode.width == size[l].width && - mode->mode.height == size[l].height) - { - vRefresh = RRVerticalRefresh (&mode->mode); - used[os] = TRUE; - - for (r = 0; r < size[l].nRates; r++) - if (vRefresh == size[l].pRates[r].rate) - break; - if (r == size[l].nRates) - { - size[l].pRates[r].rate = vRefresh; - size[l].pRates[r].mode = mode; - size[l].nRates++; - data->nrefresh++; - } - if (mode == output->crtc->mode) - { - data->size = l; - data->refresh = vRefresh; - } - } - } - } - return data; -} - -int -ProcRRGetScreenInfo (ClientPtr client) -{ - REQUEST(xRRGetScreenInfoReq); - xRRGetScreenInfoReply rep; - WindowPtr pWin; - int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - RROutputPtr output; - - REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; - - if (pScrPriv) - if (!RRGetInfo (pScreen)) - return BadAlloc; - - output = RRFirstOutput (pScreen); - - if (!pScrPriv || !output) - { - rep.type = X_Reply; - rep.setOfRotations = RR_Rotate_0;; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nSizes = 0; - rep.sizeID = 0; - rep.rotation = RR_Rotate_0; - rep.rate = 0; - rep.nrateEnts = 0; - extra = 0; - extraLen = 0; - } - else - { - int i, j; - xScreenSizes *size; - CARD16 *rates; - CARD8 *data8; - Bool has_rate = RRClientKnowsRates (client); - RR10DataPtr pData; - RRScreenSizePtr pSize; - - pData = RR10GetData (pScreen, output); - if (!pData) - return BadAlloc; - - rep.type = X_Reply; - rep.setOfRotations = output->crtc->rotations; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.rotation = output->crtc->rotation; - rep.nSizes = pData->nsize; - rep.nrateEnts = pData->nrefresh + pData->nsize; - rep.sizeID = pData->size; - rep.rate = pData->refresh; - - extraLen = (rep.nSizes * sizeof (xScreenSizes) + - rep.nrateEnts * sizeof (CARD16)); - - if (extraLen) - { - extra = (CARD8 *) xalloc (extraLen); - if (!extra) - { - xfree (pData); - return BadAlloc; - } - } - else - extra = NULL; - - /* - * First comes the size information - */ - size = (xScreenSizes *) extra; - rates = (CARD16 *) (size + rep.nSizes); - for (i = 0; i < pData->nsize; i++) - { - pSize = &pData->sizes[i]; - size->widthInPixels = pSize->width; - size->heightInPixels = pSize->height; - size->widthInMillimeters = pSize->mmWidth; - size->heightInMillimeters = pSize->mmHeight; - if (client->swapped) - { - swaps (&size->widthInPixels, n); - swaps (&size->heightInPixels, n); - swaps (&size->widthInMillimeters, n); - swaps (&size->heightInMillimeters, n); - } - size++; - if (has_rate) - { - *rates = pSize->nRates; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - for (j = 0; j < pSize->nRates; j++) - { - *rates = pSize->pRates[j].rate; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - } - } - } - xfree (pData); - - data8 = (CARD8 *) rates; - - if (data8 - (CARD8 *) extra != extraLen) - FatalError ("RRGetScreenInfo bad extra len %ld != %ld\n", - (unsigned long)(data8 - (CARD8 *) extra), extraLen); - rep.length = (extraLen + 3) >> 2; - } - if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swaps(&rep.rotation, n); - swaps(&rep.nSizes, n); - swaps(&rep.sizeID, n); - swaps(&rep.rate, n); - swaps(&rep.nrateEnts, n); - } - WriteToClient(client, sizeof(xRRGetScreenInfoReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); - } - return (client->noClientException); -} - -int -ProcRRSetScreenConfig (ClientPtr client) -{ - REQUEST(xRRSetScreenConfigReq); - xRRSetScreenConfigReply rep; - DrawablePtr pDraw; - int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - TimeStamp time; - int i; - Rotation rotation; - int rate; - Bool has_rate; - RROutputPtr output; - RRCrtcPtr crtc; - RRModePtr mode; - RR10DataPtr pData = NULL; - RRScreenSizePtr pSize; - int width, height; - - UpdateCurrentTime (); - - if (RRClientKnowsRates (client)) - { - REQUEST_SIZE_MATCH (xRRSetScreenConfigReq); - has_rate = TRUE; - } - else - { - REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq); - has_rate = FALSE; - } - - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); - if (rc != Success) - return rc; - - pScreen = pDraw->pScreen; - - pScrPriv = rrGetScrPriv(pScreen); - - time = ClientTimeToServerTime(stuff->timestamp); - - if (!pScrPriv) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - if (!RRGetInfo (pScreen)) - return BadAlloc; - - output = RRFirstOutput (pScreen); - if (!output) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; - } - - crtc = output->crtc; - - /* - * If the client's config timestamp is not the same as the last config - * timestamp, then the config information isn't up-to-date and - * can't even be validated. - * - * Note that the client only knows about the milliseconds part of the - * timestamp, so using CompareTimeStamps here would cause randr to suddenly - * stop working after several hours have passed (freedesktop bug #6502). - */ - if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) - { - rep.status = RRSetConfigInvalidConfigTime; - goto sendReply; - } - - pData = RR10GetData (pScreen, output); - if (!pData) - return BadAlloc; - - if (stuff->sizeID >= pData->nsize) - { - /* - * Invalid size ID - */ - client->errorValue = stuff->sizeID; - xfree (pData); - return BadValue; - } - pSize = &pData->sizes[stuff->sizeID]; - - /* - * Validate requested rotation - */ - rotation = (Rotation) stuff->rotation; - - /* test the rotation bits only! */ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_90: - case RR_Rotate_180: - case RR_Rotate_270: - break; - default: - /* - * Invalid rotation - */ - client->errorValue = stuff->rotation; - xfree (pData); - return BadValue; - } - - if ((~crtc->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - client->errorValue = stuff->rotation; - xfree (pData); - return BadMatch; - } - - /* - * Validate requested refresh - */ - if (has_rate) - rate = (int) stuff->rate; - else - rate = 0; - - if (rate) - { - for (i = 0; i < pSize->nRates; i++) - { - if (pSize->pRates[i].rate == rate) - break; - } - if (i == pSize->nRates) - { - /* - * Invalid rate - */ - client->errorValue = rate; - xfree (pData); - return BadValue; - } - mode = pSize->pRates[i].mode; - } - else - mode = pSize->pRates[0].mode; - - /* - * Make sure the requested set-time is not older than - * the last set-time - */ - if (CompareTimeStamps (time, pScrPriv->lastSetTime) < 0) - { - rep.status = RRSetConfigInvalidTime; - goto sendReply; - } - - /* - * If the screen size is changing, adjust all of the other outputs - * to fit the new size, mirroring as much as possible - */ - width = mode->mode.width; - height = mode->mode.height; - if (rotation & (RR_Rotate_90|RR_Rotate_270)) - { - width = mode->mode.height; - height = mode->mode.width; - } - if (width != pScreen->width || height != pScreen->height) - { - int c; - - for (c = 0; c < pScrPriv->numCrtcs; c++) - { - if (!RRCrtcSet (pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0, - 0, NULL)) - { - rep.status = RRSetConfigFailed; - /* XXX recover from failure */ - goto sendReply; - } - } - if (!RRScreenSizeSet (pScreen, width, height, - pScreen->mmWidth, pScreen->mmHeight)) - { - rep.status = RRSetConfigFailed; - /* XXX recover from failure */ - goto sendReply; - } - } - - if (!RRCrtcSet (crtc, mode, 0, 0, stuff->rotation, 1, &output)) - rep.status = RRSetConfigFailed; - else - rep.status = RRSetConfigSuccess; - - /* - * XXX Configure other crtcs to mirror as much as possible - */ - -sendReply: - - if (pData) - xfree (pData); - - rep.type = X_Reply; - /* rep.status has already been filled in */ - rep.length = 0; - rep.sequenceNumber = client->sequence; - - rep.newTimestamp = pScrPriv->lastSetTime.milliseconds; - rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - - if (client->swapped) - { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.newTimestamp, n); - swapl(&rep.newConfigTimestamp, n); - swapl(&rep.root, n); - } - WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *)&rep); - - return (client->noClientException); -} - -static CARD16 -RR10CurrentSizeID (ScreenPtr pScreen) -{ - CARD16 sizeID = 0xffff; - RROutputPtr output = RRFirstOutput (pScreen); - - if (output) - { - RR10DataPtr data = RR10GetData (pScreen, output); - if (data) - { - int i; - for (i = 0; i < data->nsize; i++) - if (data->sizes[i].width == pScreen->width && - data->sizes[i].height == pScreen->height) - { - sizeID = (CARD16) i; - break; - } - xfree (data); - } - } - return sizeID; -} diff --git a/nx-X11/programs/Xserver/randr/rrxinerama.c.NX.original b/nx-X11/programs/Xserver/randr/rrxinerama.c.NX.original deleted file mode 100644 index 9f11279db..000000000 --- a/nx-X11/programs/Xserver/randr/rrxinerama.c.NX.original +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -/* - * This Xinerama implementation comes from the SiS driver which has - * the following notice: - */ -/* - * SiS driver main code - * - * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1) Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2) Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3) The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Author: Thomas Winischhofer - * - driver entirely rewritten since 2001, only basic structure taken from - * old code (except sis_dri.c, sis_shadow.c, sis_accel.c and parts of - * sis_dga.c; these were mostly taken over; sis_dri.c was changed for - * new versions of the DRI layer) - * - * This notice covers the entire driver code unless indicated otherwise. - * - * Formerly based on code which was - * Copyright (C) 1998, 1999 by Alan Hourihane, Wigan, England. - * Written by: - * Alan Hourihane , - * Mike Chapman , - * Juanjo Santamarta , - * Mitani Hiroshi , - * David Thomas . - */ - -/**************************************************************************/ -/* */ -/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ -/* */ -/* NX-X11, NX protocol compression and NX extensions to this software */ -/* are copyright of NoMachine. Redistribution and use of the present */ -/* software is allowed according to terms specified in the file LICENSE */ -/* which comes in the source distribution. */ -/* */ -/* Check http://www.nomachine.com/licensing.html for applicability. */ -/* */ -/* NX and NoMachine are trademarks of Medialogic S.p.A. */ -/* */ -/* All rights reserved. */ -/* */ -/**************************************************************************/ - -#include "randrstr.h" -#include "swaprep.h" -#ifndef NXAGENT_SERVER -#include -#else -#include "panoramiXproto.h" -#endif - -#define RR_XINERAMA_MAJOR_VERSION 1 -#define RR_XINERAMA_MINOR_VERSION 1 - -/* Xinerama is not multi-screen capable; just report about screen 0 */ -#define RR_XINERAMA_SCREEN 0 - -static int ProcRRXineramaQueryVersion(ClientPtr client); -static int ProcRRXineramaGetState(ClientPtr client); -static int ProcRRXineramaGetScreenCount(ClientPtr client); -static int ProcRRXineramaGetScreenSize(ClientPtr client); -static int ProcRRXineramaIsActive(ClientPtr client); -static int ProcRRXineramaQueryScreens(ClientPtr client); -static int SProcRRXineramaDispatch(ClientPtr client); - -/* Proc */ - -int -ProcRRXineramaQueryVersion(ClientPtr client) -{ - xPanoramiXQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = RR_XINERAMA_MAJOR_VERSION; - rep.minorVersion = RR_XINERAMA_MINOR_VERSION; - if(client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -int -ProcRRXineramaGetState(ClientPtr client) -{ - REQUEST(xPanoramiXGetStateReq); - WindowPtr pWin; - xPanoramiXGetStateReply rep; - register int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - Bool active = FALSE; - - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if(rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - if (pScrPriv) - { - /* XXX do we need more than this? */ - active = TRUE; - } - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.state = active; - rep.window = stuff->window; - if(client->swapped) { - swaps (&rep.sequenceNumber, n); - swapl (&rep.length, n); - swapl (&rep.window, n); - } - WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *)&rep); - return client->noClientException; -} - -static Bool -RRXineramaCrtcActive (RRCrtcPtr crtc) -{ - return crtc->mode != NULL && crtc->numOutputs > 0; -} - -static int -RRXineramaScreenCount (ScreenPtr pScreen) -{ - int i, n; - - n = 0; - if (rrGetScrPriv (pScreen)) - { - rrScrPriv(pScreen); - for (i = 0; i < pScrPriv->numCrtcs; i++) - if (RRXineramaCrtcActive (pScrPriv->crtcs[i])) - n++; - } - return n; -} - -static Bool -RRXineramaScreenActive (ScreenPtr pScreen) -{ - return RRXineramaScreenCount (pScreen) > 0; -} - -int -ProcRRXineramaGetScreenCount(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenCountReq); - WindowPtr pWin; - xPanoramiXGetScreenCountReply rep; - register int n, rc; - - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.ScreenCount = RRXineramaScreenCount (pWin->drawable.pScreen); - rep.window = stuff->window; - if(client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.window, n); - } - WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *)&rep); - return client->noClientException; -} - -int -ProcRRXineramaGetScreenSize(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenSizeReq); - WindowPtr pWin, pRoot; - ScreenPtr pScreen; - xPanoramiXGetScreenSizeReply rep; - register int n, rc; - - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - #else - pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); - rc = pWin ? Success : BadWindow; - #endif - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pRoot = WindowTable[pScreen->myNum]; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.width = pRoot->drawable.width; - rep.height = pRoot->drawable.height; - rep.window = stuff->window; - rep.screen = stuff->screen; - if(client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.width, n); - swapl(&rep.height, n); - swapl(&rep.window, n); - swapl(&rep.screen, n); - } - WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep); - return client->noClientException; -} - -int -ProcRRXineramaIsActive(ClientPtr client) -{ - xXineramaIsActiveReply rep; - - REQUEST_SIZE_MATCH(xXineramaIsActiveReq); - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.state = RRXineramaScreenActive (screenInfo.screens[RR_XINERAMA_SCREEN]); - if(client->swapped) { - register int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.state, n); - } - WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep); - return client->noClientException; -} - -int -ProcRRXineramaQueryScreens(ClientPtr client) -{ - xXineramaQueryScreensReply rep; - ScreenPtr pScreen = screenInfo.screens[RR_XINERAMA_SCREEN]; - - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - - if (RRXineramaScreenActive (pScreen)) - { - rrScrPriv(pScreen); - if (pScrPriv->numCrtcs == 0 || pScrPriv->numOutputs == 0) - RRGetInfo (pScreen); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.number = RRXineramaScreenCount (pScreen); - rep.length = rep.number * sz_XineramaScreenInfo >> 2; - if(client->swapped) { - register int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.number, n); - } - WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *)&rep); - - if(rep.number) { - rrScrPriv(pScreen); - xXineramaScreenInfo scratch; - int i; - - for(i = 0; i < pScrPriv->numCrtcs; i++) { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - if (RRXineramaCrtcActive (crtc)) - { - int width, height; - RRCrtcGetScanoutSize (crtc, &width, &height); - scratch.x_org = crtc->x; - scratch.y_org = crtc->y; - scratch.width = width; - scratch.height = height; - if(client->swapped) { - register int n; - swaps(&scratch.x_org, n); - swaps(&scratch.y_org, n); - swaps(&scratch.width, n); - swaps(&scratch.height, n); - } - WriteToClient(client, sz_XineramaScreenInfo, (char *)&scratch); - } - } - } - - return client->noClientException; -} - -static int -ProcRRXineramaDispatch(ClientPtr client) -{ - REQUEST(xReq); - switch (stuff->data) { - case X_PanoramiXQueryVersion: - return ProcRRXineramaQueryVersion(client); - case X_PanoramiXGetState: - return ProcRRXineramaGetState(client); - case X_PanoramiXGetScreenCount: - return ProcRRXineramaGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return ProcRRXineramaGetScreenSize(client); - case X_XineramaIsActive: - return ProcRRXineramaIsActive(client); - case X_XineramaQueryScreens: - return ProcRRXineramaQueryScreens(client); - } - return BadRequest; -} - -/* SProc */ - -static int -SProcRRXineramaQueryVersion (ClientPtr client) -{ - REQUEST(xPanoramiXQueryVersionReq); - register int n; - swaps(&stuff->length,n); - REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq); - return ProcRRXineramaQueryVersion(client); -} - -static int -SProcRRXineramaGetState(ClientPtr client) -{ - REQUEST(xPanoramiXGetStateReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - swapl (&stuff->window, n); - return ProcRRXineramaGetState(client); -} - -static int -SProcRRXineramaGetScreenCount(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenCountReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - swapl (&stuff->window, n); - return ProcRRXineramaGetScreenCount(client); -} - -static int -SProcRRXineramaGetScreenSize(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenSizeReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - swapl (&stuff->window, n); - swapl (&stuff->screen, n); - return ProcRRXineramaGetScreenSize(client); -} - -static int -SProcRRXineramaIsActive(ClientPtr client) -{ - REQUEST(xXineramaIsActiveReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXineramaIsActiveReq); - return ProcRRXineramaIsActive(client); -} - -static int -SProcRRXineramaQueryScreens(ClientPtr client) -{ - REQUEST(xXineramaQueryScreensReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - return ProcRRXineramaQueryScreens(client); -} - -int -SProcRRXineramaDispatch(ClientPtr client) -{ - REQUEST(xReq); - switch (stuff->data) { - case X_PanoramiXQueryVersion: - return SProcRRXineramaQueryVersion(client); - case X_PanoramiXGetState: - return SProcRRXineramaGetState(client); - case X_PanoramiXGetScreenCount: - return SProcRRXineramaGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return SProcRRXineramaGetScreenSize(client); - case X_XineramaIsActive: - return SProcRRXineramaIsActive(client); - case X_XineramaQueryScreens: - return SProcRRXineramaQueryScreens(client); - } - return BadRequest; -} - -static void -RRXineramaResetProc(ExtensionEntry* extEntry) -{ -} - -void -RRXineramaExtensionInit(void) -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return; -#endif - - /* - * Xinerama isn't capable enough to have multiple protocol screens each - * with their own output geometry. So if there's more than one protocol - * screen, just don't even try. - */ - if (screenInfo.numScreens > 1) - return; - - (void) AddExtension(PANORAMIX_PROTOCOL_NAME, 0,0, - ProcRRXineramaDispatch, - SProcRRXineramaDispatch, - RRXineramaResetProc, - StandardMinorOpcode); -} diff --git a/nx-X11/programs/Xserver/randr/rrxinerama.c.X.original b/nx-X11/programs/Xserver/randr/rrxinerama.c.X.original deleted file mode 100644 index e6acd5e57..000000000 --- a/nx-X11/programs/Xserver/randr/rrxinerama.c.X.original +++ /dev/null @@ -1,454 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -/* - * This Xinerama implementation comes from the SiS driver which has - * the following notice: - */ -/* - * SiS driver main code - * - * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1) Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2) Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3) The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Author: Thomas Winischhofer - * - driver entirely rewritten since 2001, only basic structure taken from - * old code (except sis_dri.c, sis_shadow.c, sis_accel.c and parts of - * sis_dga.c; these were mostly taken over; sis_dri.c was changed for - * new versions of the DRI layer) - * - * This notice covers the entire driver code unless indicated otherwise. - * - * Formerly based on code which was - * Copyright (C) 1998, 1999 by Alan Hourihane, Wigan, England. - * Written by: - * Alan Hourihane , - * Mike Chapman , - * Juanjo Santamarta , - * Mitani Hiroshi , - * David Thomas . - */ - -#include "randrstr.h" -#include "swaprep.h" -#include - -#define RR_XINERAMA_MAJOR_VERSION 1 -#define RR_XINERAMA_MINOR_VERSION 1 - -/* Xinerama is not multi-screen capable; just report about screen 0 */ -#define RR_XINERAMA_SCREEN 0 - -static int ProcRRXineramaQueryVersion(ClientPtr client); -static int ProcRRXineramaGetState(ClientPtr client); -static int ProcRRXineramaGetScreenCount(ClientPtr client); -static int ProcRRXineramaGetScreenSize(ClientPtr client); -static int ProcRRXineramaIsActive(ClientPtr client); -static int ProcRRXineramaQueryScreens(ClientPtr client); -static int SProcRRXineramaDispatch(ClientPtr client); - -/* Proc */ - -int -ProcRRXineramaQueryVersion(ClientPtr client) -{ - xPanoramiXQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = RR_XINERAMA_MAJOR_VERSION; - rep.minorVersion = RR_XINERAMA_MINOR_VERSION; - if(client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.majorVersion, n); - swaps(&rep.minorVersion, n); - } - WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - -int -ProcRRXineramaGetState(ClientPtr client) -{ - REQUEST(xPanoramiXGetStateReq); - WindowPtr pWin; - xPanoramiXGetStateReply rep; - register int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - Bool active = FALSE; - - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if(rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pScrPriv = rrGetScrPriv(pScreen); - if (pScrPriv) - { - /* XXX do we need more than this? */ - active = TRUE; - } - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.state = active; - rep.window = stuff->window; - if(client->swapped) { - swaps (&rep.sequenceNumber, n); - swapl (&rep.length, n); - swapl (&rep.window, n); - } - WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *)&rep); - return client->noClientException; -} - -static Bool -RRXineramaCrtcActive (RRCrtcPtr crtc) -{ - return crtc->mode != NULL && crtc->numOutputs > 0; -} - -static int -RRXineramaScreenCount (ScreenPtr pScreen) -{ - int i, n; - - n = 0; - if (rrGetScrPriv (pScreen)) - { - rrScrPriv(pScreen); - for (i = 0; i < pScrPriv->numCrtcs; i++) - if (RRXineramaCrtcActive (pScrPriv->crtcs[i])) - n++; - } - return n; -} - -static Bool -RRXineramaScreenActive (ScreenPtr pScreen) -{ - return RRXineramaScreenCount (pScreen) > 0; -} - -int -ProcRRXineramaGetScreenCount(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenCountReq); - WindowPtr pWin; - xPanoramiXGetScreenCountReply rep; - register int n, rc; - - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.ScreenCount = RRXineramaScreenCount (pWin->drawable.pScreen); - rep.window = stuff->window; - if(client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.window, n); - } - WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *)&rep); - return client->noClientException; -} - -int -ProcRRXineramaGetScreenSize(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenSizeReq); - WindowPtr pWin, pRoot; - ScreenPtr pScreen; - xPanoramiXGetScreenSizeReply rep; - register int n, rc; - - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pRoot = WindowTable[pScreen->myNum]; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.width = pRoot->drawable.width; - rep.height = pRoot->drawable.height; - rep.window = stuff->window; - rep.screen = stuff->screen; - if(client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.width, n); - swapl(&rep.height, n); - swapl(&rep.window, n); - swapl(&rep.screen, n); - } - WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep); - return client->noClientException; -} - -int -ProcRRXineramaIsActive(ClientPtr client) -{ - xXineramaIsActiveReply rep; - - REQUEST_SIZE_MATCH(xXineramaIsActiveReq); - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.state = RRXineramaScreenActive (screenInfo.screens[RR_XINERAMA_SCREEN]); - if(client->swapped) { - register int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.state, n); - } - WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep); - return client->noClientException; -} - -int -ProcRRXineramaQueryScreens(ClientPtr client) -{ - xXineramaQueryScreensReply rep; - ScreenPtr pScreen = screenInfo.screens[RR_XINERAMA_SCREEN]; - - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - - if (RRXineramaScreenActive (pScreen)) - { - rrScrPriv(pScreen); - if (pScrPriv->numCrtcs == 0 || pScrPriv->numOutputs == 0) - RRGetInfo (pScreen); - } - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.number = RRXineramaScreenCount (pScreen); - rep.length = rep.number * sz_XineramaScreenInfo >> 2; - if(client->swapped) { - register int n; - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.number, n); - } - WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *)&rep); - - if(rep.number) { - rrScrPriv(pScreen); - xXineramaScreenInfo scratch; - int i; - - for(i = 0; i < pScrPriv->numCrtcs; i++) { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - if (RRXineramaCrtcActive (crtc)) - { - int width, height; - RRCrtcGetScanoutSize (crtc, &width, &height); - scratch.x_org = crtc->x; - scratch.y_org = crtc->y; - scratch.width = width; - scratch.height = height; - if(client->swapped) { - register int n; - swaps(&scratch.x_org, n); - swaps(&scratch.y_org, n); - swaps(&scratch.width, n); - swaps(&scratch.height, n); - } - WriteToClient(client, sz_XineramaScreenInfo, (char *)&scratch); - } - } - } - - return client->noClientException; -} - -static int -ProcRRXineramaDispatch(ClientPtr client) -{ - REQUEST(xReq); - switch (stuff->data) { - case X_PanoramiXQueryVersion: - return ProcRRXineramaQueryVersion(client); - case X_PanoramiXGetState: - return ProcRRXineramaGetState(client); - case X_PanoramiXGetScreenCount: - return ProcRRXineramaGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return ProcRRXineramaGetScreenSize(client); - case X_XineramaIsActive: - return ProcRRXineramaIsActive(client); - case X_XineramaQueryScreens: - return ProcRRXineramaQueryScreens(client); - } - return BadRequest; -} - -/* SProc */ - -static int -SProcRRXineramaQueryVersion (ClientPtr client) -{ - REQUEST(xPanoramiXQueryVersionReq); - register int n; - swaps(&stuff->length,n); - REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq); - return ProcRRXineramaQueryVersion(client); -} - -static int -SProcRRXineramaGetState(ClientPtr client) -{ - REQUEST(xPanoramiXGetStateReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - swapl (&stuff->window, n); - return ProcRRXineramaGetState(client); -} - -static int -SProcRRXineramaGetScreenCount(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenCountReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - swapl (&stuff->window, n); - return ProcRRXineramaGetScreenCount(client); -} - -static int -SProcRRXineramaGetScreenSize(ClientPtr client) -{ - REQUEST(xPanoramiXGetScreenSizeReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - swapl (&stuff->window, n); - swapl (&stuff->screen, n); - return ProcRRXineramaGetScreenSize(client); -} - -static int -SProcRRXineramaIsActive(ClientPtr client) -{ - REQUEST(xXineramaIsActiveReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXineramaIsActiveReq); - return ProcRRXineramaIsActive(client); -} - -static int -SProcRRXineramaQueryScreens(ClientPtr client) -{ - REQUEST(xXineramaQueryScreensReq); - register int n; - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - return ProcRRXineramaQueryScreens(client); -} - -int -SProcRRXineramaDispatch(ClientPtr client) -{ - REQUEST(xReq); - switch (stuff->data) { - case X_PanoramiXQueryVersion: - return SProcRRXineramaQueryVersion(client); - case X_PanoramiXGetState: - return SProcRRXineramaGetState(client); - case X_PanoramiXGetScreenCount: - return SProcRRXineramaGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return SProcRRXineramaGetScreenSize(client); - case X_XineramaIsActive: - return SProcRRXineramaIsActive(client); - case X_XineramaQueryScreens: - return SProcRRXineramaQueryScreens(client); - } - return BadRequest; -} - -static void -RRXineramaResetProc(ExtensionEntry* extEntry) -{ -} - -void -RRXineramaExtensionInit(void) -{ -#ifdef PANORAMIX - if(!noPanoramiXExtension) - return; -#endif - - /* - * Xinerama isn't capable enough to have multiple protocol screens each - * with their own output geometry. So if there's more than one protocol - * screen, just don't even try. - */ - if (screenInfo.numScreens > 1) - return; - - (void) AddExtension(PANORAMIX_PROTOCOL_NAME, 0,0, - ProcRRXineramaDispatch, - SProcRRXineramaDispatch, - RRXineramaResetProc, - StandardMinorOpcode); -} diff --git a/nx-X11/programs/Xserver/render/renderedge.c.NX.original b/nx-X11/programs/Xserver/render/renderedge.c.NX.original deleted file mode 100644 index f095038e5..000000000 --- a/nx-X11/programs/Xserver/render/renderedge.c.NX.original +++ /dev/null @@ -1,202 +0,0 @@ -/* - * $Id: renderedge.c,v 1.4 2005/07/03 07:02:08 daniels Exp $ - * - * Copyright © 2004 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "renderedge.h" - -/* - * Compute the smallest value no less than y which is on a - * grid row - */ - -xFixed -RenderSampleCeilY (xFixed y, int n) -{ - xFixed f = xFixedFrac(y); - xFixed i = xFixedFloor(y); - - f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); - if (f > Y_FRAC_LAST(n)) - { - f = Y_FRAC_FIRST(n); - i += xFixed1; - } - return (i | f); -} - -#define _div(a,b) ((a) >= 0 ? (a) / (b) : -((-(a) + (b) - 1) / (b))) - -/* - * Compute the largest value no greater than y which is on a - * grid row - */ -xFixed -RenderSampleFloorY (xFixed y, int n) -{ - xFixed f = xFixedFrac(y); - xFixed i = xFixedFloor (y); - - f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); - if (f < Y_FRAC_FIRST(n)) - { - f = Y_FRAC_LAST(n); - i -= xFixed1; - } - return (i | f); -} - -/* - * Step an edge by any amount (including negative values) - */ -void -RenderEdgeStep (RenderEdge *e, int n) -{ - xFixed_48_16 ne; - - e->x += n * e->stepx; - - ne = e->e + n * (xFixed_48_16) e->dx; - - if (n >= 0) - { - if (ne > 0) - { - int nx = (ne + e->dy - 1) / e->dy; - e->e = ne - nx * (xFixed_48_16) e->dy; - e->x += nx * e->signdx; - } - } - else - { - if (ne <= -e->dy) - { - int nx = (-ne) / e->dy; - e->e = ne + nx * (xFixed_48_16) e->dy; - e->x -= nx * e->signdx; - } - } -} - -/* - * A private routine to initialize the multi-step - * elements of an edge structure - */ -static void -_RenderEdgeMultiInit (RenderEdge *e, int n, xFixed *stepx_p, xFixed *dx_p) -{ - xFixed stepx; - xFixed_48_16 ne; - - ne = n * (xFixed_48_16) e->dx; - stepx = n * e->stepx; - if (ne > 0) - { - int nx = ne / e->dy; - ne -= nx * e->dy; - stepx += nx * e->signdx; - } - *dx_p = ne; - *stepx_p = stepx; -} - -/* - * Initialize one edge structure given the line endpoints and a - * starting y value - */ -void -RenderEdgeInit (RenderEdge *e, - int n, - xFixed y_start, - xFixed x_top, - xFixed y_top, - xFixed x_bot, - xFixed y_bot) -{ - xFixed dx, dy; - - e->x = x_top; - e->e = 0; - dx = x_bot - x_top; - dy = y_bot - y_top; - e->dy = dy; - e->dx = 0; - if (dy) - { - if (dx >= 0) - { - e->signdx = 1; - e->stepx = dx / dy; - e->dx = dx % dy; - e->e = -dy; - } - else - { - e->signdx = -1; - e->stepx = -(-dx / dy); - e->dx = -dx % dy; - e->e = 0; - } - - _RenderEdgeMultiInit (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small); - _RenderEdgeMultiInit (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big); - } - RenderEdgeStep (e, y_start - y_top); -} - -/* - * Initialize one edge structure given a line, starting y value - * and a pixel offset for the line - */ -void -RenderLineFixedEdgeInit (RenderEdge *e, - int n, - xFixed y, - xLineFixed *line, - int x_off, - int y_off) -{ - xFixed x_off_fixed = IntToxFixed(x_off); - xFixed y_off_fixed = IntToxFixed(y_off); - xPointFixed *top, *bot; - - if (line->p1.y <= line->p2.y) - { - top = &line->p1; - bot = &line->p2; - } - else - { - top = &line->p2; - bot = &line->p1; - } - RenderEdgeInit (e, n, y, - top->x + x_off_fixed, - top->y + y_off_fixed, - bot->x + x_off_fixed, - bot->y + y_off_fixed); -} - diff --git a/nx-X11/programs/Xserver/render/renderedge.c.X.original b/nx-X11/programs/Xserver/render/renderedge.c.X.original deleted file mode 100644 index b4031944d..000000000 --- a/nx-X11/programs/Xserver/render/renderedge.c.X.original +++ /dev/null @@ -1,201 +0,0 @@ -/* - * $Id: renderedge.c,v 1.4 2005/07/03 07:02:08 daniels Exp $ - * - * Copyright © 2004 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "renderedge.h" - -/* - * Compute the smallest value no less than y which is on a - * grid row - */ - -xFixed -RenderSampleCeilY (xFixed y, int n) -{ - xFixed f = xFixedFrac(y); - xFixed i = xFixedFloor(y); - - f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); - if (f > Y_FRAC_LAST(n)) - { - f = Y_FRAC_FIRST(n); - i += xFixed1; - } - return (i | f); -} - -#define _div(a,b) ((a) >= 0 ? (a) / (b) : -((-(a) + (b) - 1) / (b))) - -/* - * Compute the largest value no greater than y which is on a - * grid row - */ -xFixed -RenderSampleFloorY (xFixed y, int n) -{ - xFixed f = xFixedFrac(y); - xFixed i = xFixedFloor (y); - - f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); - if (f < Y_FRAC_FIRST(n)) - { - f = Y_FRAC_LAST(n); - i -= xFixed1; - } - return (i | f); -} - -/* - * Step an edge by any amount (including negative values) - */ -void -RenderEdgeStep (RenderEdge *e, int n) -{ - xFixed_48_16 ne; - - e->x += n * e->stepx; - - ne = e->e + n * (xFixed_48_16) e->dx; - - if (n >= 0) - { - if (ne > 0) - { - int nx = (ne + e->dy - 1) / e->dy; - e->e = ne - nx * (xFixed_48_16) e->dy; - e->x += nx * e->signdx; - } - } - else - { - if (ne <= -e->dy) - { - int nx = (-ne) / e->dy; - e->e = ne + nx * (xFixed_48_16) e->dy; - e->x -= nx * e->signdx; - } - } -} - -/* - * A private routine to initialize the multi-step - * elements of an edge structure - */ -static void -_RenderEdgeMultiInit (RenderEdge *e, int n, xFixed *stepx_p, xFixed *dx_p) -{ - xFixed stepx; - xFixed_48_16 ne; - - ne = n * (xFixed_48_16) e->dx; - stepx = n * e->stepx; - if (ne > 0) - { - int nx = ne / e->dy; - ne -= nx * e->dy; - stepx += nx * e->signdx; - } - *dx_p = ne; - *stepx_p = stepx; -} - -/* - * Initialize one edge structure given the line endpoints and a - * starting y value - */ -void -RenderEdgeInit (RenderEdge *e, - int n, - xFixed y_start, - xFixed x_top, - xFixed y_top, - xFixed x_bot, - xFixed y_bot) -{ - xFixed dx, dy; - - e->x = x_top; - e->e = 0; - dx = x_bot - x_top; - dy = y_bot - y_top; - e->dy = dy; - if (dy) - { - if (dx >= 0) - { - e->signdx = 1; - e->stepx = dx / dy; - e->dx = dx % dy; - e->e = -dy; - } - else - { - e->signdx = -1; - e->stepx = -(-dx / dy); - e->dx = -dx % dy; - e->e = 0; - } - - _RenderEdgeMultiInit (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small); - _RenderEdgeMultiInit (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big); - } - RenderEdgeStep (e, y_start - y_top); -} - -/* - * Initialize one edge structure given a line, starting y value - * and a pixel offset for the line - */ -void -RenderLineFixedEdgeInit (RenderEdge *e, - int n, - xFixed y, - xLineFixed *line, - int x_off, - int y_off) -{ - xFixed x_off_fixed = IntToxFixed(x_off); - xFixed y_off_fixed = IntToxFixed(y_off); - xPointFixed *top, *bot; - - if (line->p1.y <= line->p2.y) - { - top = &line->p1; - bot = &line->p2; - } - else - { - top = &line->p2; - bot = &line->p1; - } - RenderEdgeInit (e, n, y, - top->x + x_off_fixed, - top->y + y_off_fixed, - bot->x + x_off_fixed, - bot->y + y_off_fixed); -} - diff --git a/nx-X11/programs/Xserver/xfixes/cursor.c.NX.original b/nx-X11/programs/Xserver/xfixes/cursor.c.NX.original deleted file mode 100755 index f6895d193..000000000 --- a/nx-X11/programs/Xserver/xfixes/cursor.c.NX.original +++ /dev/null @@ -1,754 +0,0 @@ -/* - * $Id: cursor.c,v 1.6 2005/07/03 07:37:35 daniels Exp $ - * - * Copyright © 2002 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "xfixesint.h" -#include "scrnintstr.h" -#include "cursorstr.h" -#include "dixevents.h" -#include "servermd.h" -#include "inputstr.h" -#include "windowstr.h" - -static RESTYPE CursorClientType; -static RESTYPE CursorWindowType; -static int CursorScreenPrivateIndex = -1; -static int CursorGeneration; -static CursorPtr CursorCurrent; - -#define VERIFY_CURSOR(pCursor, cursor, client, access) { \ - pCursor = (CursorPtr)SecurityLookupIDByType((client), (cursor), \ - RT_CURSOR, (access)); \ - if (!pCursor) { \ - (client)->errorValue = (cursor); \ - return BadCursor; \ - } \ -} - -/* - * There is a global list of windows selecting for cursor events - */ - -typedef struct _CursorEvent *CursorEventPtr; - -typedef struct _CursorEvent { - CursorEventPtr next; - CARD32 eventMask; - ClientPtr pClient; - WindowPtr pWindow; - XID clientResource; -} CursorEventRec; - -static CursorEventPtr cursorEvents; - -/* - * Wrap DisplayCursor to catch cursor change events - */ - -typedef struct _CursorScreen { - DisplayCursorProcPtr DisplayCursor; - CloseScreenProcPtr CloseScreen; -} CursorScreenRec, *CursorScreenPtr; - -#define GetCursorScreen(s) ((CursorScreenPtr) ((s)->devPrivates[CursorScreenPrivateIndex].ptr)) -#define GetCursorScreenIfSet(s) ((CursorScreenPrivateIndex != -1) ? GetCursorScreen(s) : NULL) -#define SetCursorScreen(s,p) ((s)->devPrivates[CursorScreenPrivateIndex].ptr = (pointer) (p)) -#define Wrap(as,s,elt,func) (((as)->elt = (s)->elt), (s)->elt = func) -#define Unwrap(as,s,elt) ((s)->elt = (as)->elt) - -static Bool -CursorDisplayCursor (ScreenPtr pScreen, - CursorPtr pCursor) -{ - CursorScreenPtr cs = GetCursorScreen(pScreen); - Bool ret; - - Unwrap (cs, pScreen, DisplayCursor); - ret = (*pScreen->DisplayCursor) (pScreen, pCursor); - if (pCursor != CursorCurrent) - { - CursorEventPtr e; - - CursorCurrent = pCursor; - for (e = cursorEvents; e; e = e->next) - { - if ((e->eventMask & XFixesDisplayCursorNotifyMask) && - !e->pClient->clientGone) - { - xXFixesCursorNotifyEvent ev; - ev.type = XFixesEventBase + XFixesCursorNotify; - ev.subtype = XFixesDisplayCursorNotify; - ev.sequenceNumber = e->pClient->sequence; - ev.window = e->pWindow->drawable.id; - ev.cursorSerial = pCursor->serialNumber; - ev.timestamp = currentTime.milliseconds; - ev.name = pCursor->name; - WriteEventsToClient (e->pClient, 1, (xEvent *) &ev); - } - } - } - Wrap (cs, pScreen, DisplayCursor, CursorDisplayCursor); - return ret; -} - -static Bool -CursorCloseScreen (int index, ScreenPtr pScreen) -{ - CursorScreenPtr cs = GetCursorScreen (pScreen); - Bool ret; - - Unwrap (cs, pScreen, CloseScreen); - Unwrap (cs, pScreen, DisplayCursor); - ret = (*pScreen->CloseScreen) (index, pScreen); - xfree (cs); - if (index == 0) - CursorScreenPrivateIndex = -1; - return ret; -} - -#define CursorAllEvents (XFixesDisplayCursorNotifyMask) - -static int -XFixesSelectCursorInput (ClientPtr pClient, - WindowPtr pWindow, - CARD32 eventMask) -{ - CursorEventPtr *prev, e; - - for (prev = &cursorEvents; (e = *prev); prev = &e->next) - { - if (e->pClient == pClient && - e->pWindow == pWindow) - { - break; - } - } - if (!eventMask) - { - if (e) - { - FreeResource (e->clientResource, 0); - } - return Success; - } - if (!e) - { - e = (CursorEventPtr) xalloc (sizeof (CursorEventRec)); - if (!e) - return BadAlloc; - - e->next = 0; - e->pClient = pClient; - e->pWindow = pWindow; - e->clientResource = FakeClientID(pClient->index); - - /* - * Add a resource hanging from the window to - * catch window destroy - */ - if (!LookupIDByType(pWindow->drawable.id, CursorWindowType)) - if (!AddResource (pWindow->drawable.id, CursorWindowType, - (pointer) pWindow)) - { - xfree (e); - return BadAlloc; - } - - if (!AddResource (e->clientResource, CursorClientType, (pointer) e)) - return BadAlloc; - - *prev = e; - } - e->eventMask = eventMask; - return Success; -} - -int -ProcXFixesSelectCursorInput (ClientPtr client) -{ - REQUEST (xXFixesSelectCursorInputReq); - WindowPtr pWin; - - REQUEST_SIZE_MATCH (xXFixesSelectCursorInputReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (stuff->eventMask & ~CursorAllEvents) - { - client->errorValue = stuff->eventMask; - return( BadValue ); - } - return XFixesSelectCursorInput (client, pWin, stuff->eventMask); -} - -static int -GetBit (unsigned char *line, int x) -{ - unsigned char mask; - - if (screenInfo.bitmapBitOrder == LSBFirst) - mask = (1 << (x & 7)); - else - mask = (0x80 >> (x & 7)); - /* XXX assumes byte order is host byte order */ - line += (x >> 3); - if (*line & mask) - return 1; - return 0; -} - -int -SProcXFixesSelectCursorInput (ClientPtr client) -{ - register int n; - REQUEST(xXFixesSelectCursorInputReq); - - swaps(&stuff->length, n); - swapl(&stuff->window, n); - swapl(&stuff->eventMask, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -void -SXFixesCursorNotifyEvent (xXFixesCursorNotifyEvent *from, - xXFixesCursorNotifyEvent *to) -{ - to->type = from->type; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->window, to->window); - cpswapl (from->cursorSerial, to->cursorSerial); - cpswapl (from->timestamp, to->timestamp); - cpswapl (from->name, to->name); -} - -static void -CopyCursorToImage (CursorPtr pCursor, CARD32 *image) -{ - int width = pCursor->bits->width; - int height = pCursor->bits->height; - int npixels = width * height; - -#ifdef ARGB_CURSOR - if (pCursor->bits->argb) - memcpy (image, pCursor->bits->argb, npixels * sizeof (CARD32)); - else -#endif - { - unsigned char *srcLine = pCursor->bits->source; - unsigned char *mskLine = pCursor->bits->mask; - int stride = BitmapBytePad (width); - int x, y; - CARD32 fg, bg; - - fg = (0xff000000 | - ((pCursor->foreRed & 0xff00) << 8) | - (pCursor->foreGreen & 0xff00) | - (pCursor->foreBlue >> 8)); - bg = (0xff000000 | - ((pCursor->backRed & 0xff00) << 8) | - (pCursor->backGreen & 0xff00) | - (pCursor->backBlue >> 8)); - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - if (GetBit (mskLine, x)) - { - if (GetBit (srcLine, x)) - *image++ = fg; - else - *image++ = bg; - } - else - *image++ = 0; - } - srcLine += stride; - mskLine += stride; - } - } -} - -int -ProcXFixesGetCursorImage (ClientPtr client) -{ -/* REQUEST(xXFixesGetCursorImageReq); */ - xXFixesGetCursorImageReply *rep; - CursorPtr pCursor; - CARD32 *image; - int npixels; - int width, height; - int x, y; - - REQUEST_SIZE_MATCH(xXFixesGetCursorImageReq); - pCursor = CursorCurrent; - if (!pCursor) - return BadCursor; - GetSpritePosition (&x, &y); - width = pCursor->bits->width; - height = pCursor->bits->height; - npixels = width * height; - rep = xalloc (sizeof (xXFixesGetCursorImageReply) + - npixels * sizeof (CARD32)); - if (!rep) - return BadAlloc; - - rep->type = X_Reply; - rep->sequenceNumber = client->sequence; - rep->length = npixels; - rep->width = width; - rep->height = height; - rep->x = x; - rep->y = y; - rep->xhot = pCursor->bits->xhot; - rep->yhot = pCursor->bits->yhot; - rep->cursorSerial = pCursor->serialNumber; - - image = (CARD32 *) (rep + 1); - CopyCursorToImage (pCursor, image); - if (client->swapped) - { - int n; - swaps (&rep->sequenceNumber, n); - swapl (&rep->length, n); - swaps (&rep->x, n); - swaps (&rep->y, n); - swaps (&rep->width, n); - swaps (&rep->height, n); - swaps (&rep->xhot, n); - swaps (&rep->yhot, n); - swapl (&rep->cursorSerial, n); - SwapLongs (image, npixels); - } - (void) WriteToClient(client, sizeof (xXFixesGetCursorImageReply) + - (npixels << 2), (char *) rep); - xfree (rep); - return client->noClientException; -} - -int -SProcXFixesGetCursorImage (ClientPtr client) -{ - int n; - REQUEST(xXFixesGetCursorImageReq); - swaps (&stuff->length, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -int -ProcXFixesSetCursorName (ClientPtr client) -{ - CursorPtr pCursor; - char *tchar; - REQUEST(xXFixesSetCursorNameReq); - Atom atom; - - REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq); - VERIFY_CURSOR(pCursor, stuff->cursor, client, SecurityWriteAccess); - tchar = (char *) &stuff[1]; - atom = MakeAtom (tchar, stuff->nbytes, TRUE); - if (atom == BAD_RESOURCE) - return BadAlloc; - - pCursor->name = atom; - return(client->noClientException); -} - -int -SProcXFixesSetCursorName (ClientPtr client) -{ - int n; - REQUEST(xXFixesSetCursorNameReq); - - swaps (&stuff->length, n); - REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq); - swapl (&stuff->cursor, n); - swaps (&stuff->nbytes, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -int -ProcXFixesGetCursorName (ClientPtr client) -{ - CursorPtr pCursor; - xXFixesGetCursorNameReply reply; - REQUEST(xXFixesGetCursorNameReq); - char *str; - int len; - - REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq); - VERIFY_CURSOR(pCursor, stuff->cursor, client, SecurityReadAccess); - if (pCursor->name) - str = NameForAtom (pCursor->name); - else - str = ""; - len = strlen (str); - - reply.type = X_Reply; - reply.length = (len + 3) >> 2; - reply.sequenceNumber = client->sequence; - reply.atom = pCursor->name; - reply.nbytes = len; - if (client->swapped) - { - int n; - swaps (&reply.sequenceNumber, n); - swapl (&reply.length, n); - swapl (&reply.atom, n); - swaps (&reply.nbytes, n); - } - WriteReplyToClient(client, sizeof(xXFixesGetCursorNameReply), &reply); - (void)WriteToClient(client, len, str); - - return(client->noClientException); -} - -int -SProcXFixesGetCursorName (ClientPtr client) -{ - int n; - REQUEST(xXFixesSetCursorNameReq); - - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq); - swapl (&stuff->cursor, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -int -ProcXFixesGetCursorImageAndName (ClientPtr client) -{ -/* REQUEST(xXFixesGetCursorImageAndNameReq); */ - xXFixesGetCursorImageAndNameReply *rep; - CursorPtr pCursor; - CARD32 *image; - int npixels; - char *name; - int nbytes, nbytesRound; - int width, height; - int x, y; - - REQUEST_SIZE_MATCH(xXFixesGetCursorImageAndNameReq); - pCursor = CursorCurrent; - if (!pCursor) - return BadCursor; - GetSpritePosition (&x, &y); - width = pCursor->bits->width; - height = pCursor->bits->height; - npixels = width * height; - name = pCursor->name ? NameForAtom (pCursor->name) : ""; - nbytes = strlen (name); - nbytesRound = (nbytes + 3) & ~3; - rep = xalloc (sizeof (xXFixesGetCursorImageAndNameReply) + - npixels * sizeof (CARD32) + nbytesRound); - if (!rep) - return BadAlloc; - - rep->type = X_Reply; - rep->sequenceNumber = client->sequence; - rep->length = npixels + (nbytesRound >> 2); - rep->width = width; - rep->height = height; - rep->x = x; - rep->y = y; - rep->xhot = pCursor->bits->xhot; - rep->yhot = pCursor->bits->yhot; - rep->cursorSerial = pCursor->serialNumber; - rep->cursorName = pCursor->name; - rep->nbytes = nbytes; - - image = (CARD32 *) (rep + 1); - CopyCursorToImage (pCursor, image); - memcpy ((image + npixels), name, nbytes); - if (client->swapped) - { - int n; - swaps (&rep->sequenceNumber, n); - swapl (&rep->length, n); - swaps (&rep->x, n); - swaps (&rep->y, n); - swaps (&rep->width, n); - swaps (&rep->height, n); - swaps (&rep->xhot, n); - swaps (&rep->yhot, n); - swapl (&rep->cursorSerial, n); - swapl (&rep->cursorName, n); - swaps (&rep->nbytes, n); - SwapLongs (image, npixels); - } - (void) WriteToClient(client, sizeof (xXFixesGetCursorImageAndNameReply) + - (npixels << 2) + nbytesRound, (char *) rep); - xfree (rep); - return client->noClientException; -} - -int -SProcXFixesGetCursorImageAndName (ClientPtr client) -{ - int n; - REQUEST(xXFixesGetCursorImageAndNameReq); - swaps (&stuff->length, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -/* - * Find every cursor reference in the system, ask testCursor - * whether it should be replaced with a reference to pCursor. - */ - -typedef Bool (*TestCursorFunc) (CursorPtr pOld, pointer closure); - -typedef struct { - RESTYPE type; - TestCursorFunc testCursor; - CursorPtr pNew; - pointer closure; -} ReplaceCursorLookupRec, *ReplaceCursorLookupPtr; - -static const RESTYPE CursorRestypes[] = { - RT_WINDOW, RT_PASSIVEGRAB, RT_CURSOR -}; - -#define NUM_CURSOR_RESTYPES (sizeof (CursorRestypes) / sizeof (CursorRestypes[0])) - -static Bool -ReplaceCursorLookup (pointer value, XID id, pointer closure) -{ - ReplaceCursorLookupPtr rcl = (ReplaceCursorLookupPtr) closure; - WindowPtr pWin; - GrabPtr pGrab; - CursorPtr pCursor = 0, *pCursorRef = 0; - XID cursor = 0; - - switch (rcl->type) { - case RT_WINDOW: - pWin = (WindowPtr) value; - if (pWin->optional) - { - pCursorRef = &pWin->optional->cursor; - pCursor = *pCursorRef; - } - break; - case RT_PASSIVEGRAB: - pGrab = (GrabPtr) value; - pCursorRef = &pGrab->cursor; - pCursor = *pCursorRef; - break; - case RT_CURSOR: - pCursorRef = 0; - pCursor = (CursorPtr) value; - cursor = id; - break; - } - if (pCursor && pCursor != rcl->pNew) - { - if ((*rcl->testCursor) (pCursor, rcl->closure)) - { - rcl->pNew->refcnt++; - /* either redirect reference or update resource database */ - if (pCursorRef) - *pCursorRef = rcl->pNew; - else - ChangeResourceValue (id, RT_CURSOR, rcl->pNew); - FreeCursor (pCursor, cursor); - } - } - return FALSE; /* keep walking */ -} - -static void -ReplaceCursor (CursorPtr pCursor, - TestCursorFunc testCursor, - pointer closure) -{ - int clientIndex; - int resIndex; - ReplaceCursorLookupRec rcl; - - /* - * Cursors exist only in the resource database, windows and grabs. - * All of these are always pointed at by the resource database. Walk - * the whole thing looking for cursors - */ - rcl.testCursor = testCursor; - rcl.pNew = pCursor; - rcl.closure = closure; - - /* for each client */ - for (clientIndex = 0; clientIndex < currentMaxClients; clientIndex++) - { - if (!clients[clientIndex]) - continue; - for (resIndex = 0; resIndex < NUM_CURSOR_RESTYPES; resIndex++) - { - rcl.type = CursorRestypes[resIndex]; - /* - * This function walks the entire client resource database - */ - LookupClientResourceComplex (clients[clientIndex], - rcl.type, - ReplaceCursorLookup, - (pointer) &rcl); - } - } - /* this "knows" that WindowHasNewCursor doesn't depend on it's argument */ - WindowHasNewCursor (WindowTable[0]); -} - -static Bool -TestForCursor (CursorPtr pCursor, pointer closure) -{ - return (pCursor == (CursorPtr) closure); -} - -int -ProcXFixesChangeCursor (ClientPtr client) -{ - CursorPtr pSource, pDestination; - REQUEST(xXFixesChangeCursorReq); - - REQUEST_SIZE_MATCH(xXFixesChangeCursorReq); - VERIFY_CURSOR (pSource, stuff->source, client, SecurityReadAccess); - VERIFY_CURSOR (pDestination, stuff->destination, client, SecurityWriteAccess); - - ReplaceCursor (pSource, TestForCursor, (pointer) pDestination); - return (client->noClientException); -} - -int -SProcXFixesChangeCursor (ClientPtr client) -{ - int n; - REQUEST(xXFixesChangeCursorReq); - - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXFixesChangeCursorReq); - swapl (&stuff->source, n); - swapl (&stuff->destination, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -static Bool -TestForCursorName (CursorPtr pCursor, pointer closure) -{ - return (pCursor->name == (Atom) closure); -} - -int -ProcXFixesChangeCursorByName (ClientPtr client) -{ - CursorPtr pSource; - Atom name; - char *tchar; - REQUEST(xXFixesChangeCursorByNameReq); - - REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes); - VERIFY_CURSOR(pSource, stuff->source, client, SecurityReadAccess); - tchar = (char *) &stuff[1]; - name = MakeAtom (tchar, stuff->nbytes, FALSE); - if (name) - ReplaceCursor (pSource, TestForCursorName, (pointer) name); - return (client->noClientException); -} - -int -SProcXFixesChangeCursorByName (ClientPtr client) -{ - int n; - REQUEST(xXFixesChangeCursorByNameReq); - - swaps (&stuff->length, n); - REQUEST_AT_LEAST_SIZE (xXFixesChangeCursorByNameReq); - swapl (&stuff->source, n); - swaps (&stuff->nbytes, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -static int -CursorFreeClient (pointer data, XID id) -{ - CursorEventPtr old = (CursorEventPtr) data; - CursorEventPtr *prev, e; - - for (prev = &cursorEvents; (e = *prev); prev = &e->next) - { - if (e == old) - { - *prev = e->next; - xfree (e); - break; - } - } - return 1; -} - -static int -CursorFreeWindow (pointer data, XID id) -{ - WindowPtr pWindow = (WindowPtr) data; - CursorEventPtr e, next; - - for (e = cursorEvents; e; e = next) - { - next = e->next; - if (e->pWindow == pWindow) - { - FreeResource (e->clientResource, 0); - } - } - return 1; -} - -Bool -XFixesCursorInit (void) -{ - int i; - - if (CursorGeneration != serverGeneration) - { - CursorScreenPrivateIndex = AllocateScreenPrivateIndex (); - if (CursorScreenPrivateIndex < 0) - return FALSE; - CursorGeneration = serverGeneration; - } - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - CursorScreenPtr cs; - - cs = (CursorScreenPtr) xalloc (sizeof (CursorScreenRec)); - if (!cs) - return FALSE; - Wrap (cs, pScreen, CloseScreen, CursorCloseScreen); - Wrap (cs, pScreen, DisplayCursor, CursorDisplayCursor); - SetCursorScreen (pScreen, cs); - } - CursorClientType = CreateNewResourceType(CursorFreeClient); - CursorWindowType = CreateNewResourceType(CursorFreeWindow); - return CursorClientType && CursorWindowType; -} - diff --git a/nx-X11/programs/Xserver/xfixes/cursor.c.X.original b/nx-X11/programs/Xserver/xfixes/cursor.c.X.original deleted file mode 100755 index bcc1ab962..000000000 --- a/nx-X11/programs/Xserver/xfixes/cursor.c.X.original +++ /dev/null @@ -1,753 +0,0 @@ -/* - * $Id: cursor.c,v 1.6 2005/07/03 07:37:35 daniels Exp $ - * - * Copyright © 2002 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "xfixesint.h" -#include "scrnintstr.h" -#include "cursorstr.h" -#include "dixevents.h" -#include "servermd.h" -#include "inputstr.h" -#include "windowstr.h" - -static RESTYPE CursorClientType; -static RESTYPE CursorWindowType; -static int CursorScreenPrivateIndex = -1; -static int CursorGeneration; -static CursorPtr CursorCurrent; - -#define VERIFY_CURSOR(pCursor, cursor, client, access) { \ - pCursor = (CursorPtr)SecurityLookupIDByType((client), (cursor), \ - RT_CURSOR, (access)); \ - if (!pCursor) { \ - (client)->errorValue = (cursor); \ - return BadCursor; \ - } \ -} - -/* - * There is a global list of windows selecting for cursor events - */ - -typedef struct _CursorEvent *CursorEventPtr; - -typedef struct _CursorEvent { - CursorEventPtr next; - CARD32 eventMask; - ClientPtr pClient; - WindowPtr pWindow; - XID clientResource; -} CursorEventRec; - -static CursorEventPtr cursorEvents; - -/* - * Wrap DisplayCursor to catch cursor change events - */ - -typedef struct _CursorScreen { - DisplayCursorProcPtr DisplayCursor; - CloseScreenProcPtr CloseScreen; -} CursorScreenRec, *CursorScreenPtr; - -#define GetCursorScreen(s) ((CursorScreenPtr) ((s)->devPrivates[CursorScreenPrivateIndex].ptr)) -#define GetCursorScreenIfSet(s) ((CursorScreenPrivateIndex != -1) ? GetCursorScreen(s) : NULL) -#define SetCursorScreen(s,p) ((s)->devPrivates[CursorScreenPrivateIndex].ptr = (pointer) (p)) -#define Wrap(as,s,elt,func) (((as)->elt = (s)->elt), (s)->elt = func) -#define Unwrap(as,s,elt) ((s)->elt = (as)->elt) - -static Bool -CursorDisplayCursor (ScreenPtr pScreen, - CursorPtr pCursor) -{ - CursorScreenPtr cs = GetCursorScreen(pScreen); - Bool ret; - - Unwrap (cs, pScreen, DisplayCursor); - ret = (*pScreen->DisplayCursor) (pScreen, pCursor); - if (pCursor != CursorCurrent) - { - CursorEventPtr e; - - CursorCurrent = pCursor; - for (e = cursorEvents; e; e = e->next) - { - if (e->eventMask & XFixesDisplayCursorNotifyMask) - { - xXFixesCursorNotifyEvent ev; - ev.type = XFixesEventBase + XFixesCursorNotify; - ev.subtype = XFixesDisplayCursorNotify; - ev.sequenceNumber = e->pClient->sequence; - ev.window = e->pWindow->drawable.id; - ev.cursorSerial = pCursor->serialNumber; - ev.timestamp = currentTime.milliseconds; - ev.name = pCursor->name; - WriteEventsToClient (e->pClient, 1, (xEvent *) &ev); - } - } - } - Wrap (cs, pScreen, DisplayCursor, CursorDisplayCursor); - return ret; -} - -static Bool -CursorCloseScreen (int index, ScreenPtr pScreen) -{ - CursorScreenPtr cs = GetCursorScreen (pScreen); - Bool ret; - - Unwrap (cs, pScreen, CloseScreen); - Unwrap (cs, pScreen, DisplayCursor); - ret = (*pScreen->CloseScreen) (index, pScreen); - xfree (cs); - if (index == 0) - CursorScreenPrivateIndex = -1; - return ret; -} - -#define CursorAllEvents (XFixesDisplayCursorNotifyMask) - -static int -XFixesSelectCursorInput (ClientPtr pClient, - WindowPtr pWindow, - CARD32 eventMask) -{ - CursorEventPtr *prev, e; - - for (prev = &cursorEvents; (e = *prev); prev = &e->next) - { - if (e->pClient == pClient && - e->pWindow == pWindow) - { - break; - } - } - if (!eventMask) - { - if (e) - { - FreeResource (e->clientResource, 0); - } - return Success; - } - if (!e) - { - e = (CursorEventPtr) xalloc (sizeof (CursorEventRec)); - if (!e) - return BadAlloc; - - e->next = 0; - e->pClient = pClient; - e->pWindow = pWindow; - e->clientResource = FakeClientID(pClient->index); - - /* - * Add a resource hanging from the window to - * catch window destroy - */ - if (!LookupIDByType(pWindow->drawable.id, CursorWindowType)) - if (!AddResource (pWindow->drawable.id, CursorWindowType, - (pointer) pWindow)) - { - xfree (e); - return BadAlloc; - } - - if (!AddResource (e->clientResource, CursorClientType, (pointer) e)) - return BadAlloc; - - *prev = e; - } - e->eventMask = eventMask; - return Success; -} - -int -ProcXFixesSelectCursorInput (ClientPtr client) -{ - REQUEST (xXFixesSelectCursorInputReq); - WindowPtr pWin; - - REQUEST_SIZE_MATCH (xXFixesSelectCursorInputReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (stuff->eventMask & ~CursorAllEvents) - { - client->errorValue = stuff->eventMask; - return( BadValue ); - } - return XFixesSelectCursorInput (client, pWin, stuff->eventMask); -} - -static int -GetBit (unsigned char *line, int x) -{ - unsigned char mask; - - if (screenInfo.bitmapBitOrder == LSBFirst) - mask = (1 << (x & 7)); - else - mask = (0x80 >> (x & 7)); - /* XXX assumes byte order is host byte order */ - line += (x >> 3); - if (*line & mask) - return 1; - return 0; -} - -int -SProcXFixesSelectCursorInput (ClientPtr client) -{ - register int n; - REQUEST(xXFixesSelectCursorInputReq); - - swaps(&stuff->length, n); - swapl(&stuff->window, n); - swapl(&stuff->eventMask, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -void -SXFixesCursorNotifyEvent (xXFixesCursorNotifyEvent *from, - xXFixesCursorNotifyEvent *to) -{ - to->type = from->type; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->window, to->window); - cpswapl (from->cursorSerial, to->cursorSerial); - cpswapl (from->timestamp, to->timestamp); - cpswapl (from->name, to->name); -} - -static void -CopyCursorToImage (CursorPtr pCursor, CARD32 *image) -{ - int width = pCursor->bits->width; - int height = pCursor->bits->height; - int npixels = width * height; - -#ifdef ARGB_CURSOR - if (pCursor->bits->argb) - memcpy (image, pCursor->bits->argb, npixels * sizeof (CARD32)); - else -#endif - { - unsigned char *srcLine = pCursor->bits->source; - unsigned char *mskLine = pCursor->bits->mask; - int stride = BitmapBytePad (width); - int x, y; - CARD32 fg, bg; - - fg = (0xff000000 | - ((pCursor->foreRed & 0xff00) << 8) | - (pCursor->foreGreen & 0xff00) | - (pCursor->foreBlue >> 8)); - bg = (0xff000000 | - ((pCursor->backRed & 0xff00) << 8) | - (pCursor->backGreen & 0xff00) | - (pCursor->backBlue >> 8)); - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - if (GetBit (mskLine, x)) - { - if (GetBit (srcLine, x)) - *image++ = fg; - else - *image++ = bg; - } - else - *image++ = 0; - } - srcLine += stride; - mskLine += stride; - } - } -} - -int -ProcXFixesGetCursorImage (ClientPtr client) -{ -/* REQUEST(xXFixesGetCursorImageReq); */ - xXFixesGetCursorImageReply *rep; - CursorPtr pCursor; - CARD32 *image; - int npixels; - int width, height; - int x, y; - - REQUEST_SIZE_MATCH(xXFixesGetCursorImageReq); - pCursor = CursorCurrent; - if (!pCursor) - return BadCursor; - GetSpritePosition (&x, &y); - width = pCursor->bits->width; - height = pCursor->bits->height; - npixels = width * height; - rep = xalloc (sizeof (xXFixesGetCursorImageReply) + - npixels * sizeof (CARD32)); - if (!rep) - return BadAlloc; - - rep->type = X_Reply; - rep->sequenceNumber = client->sequence; - rep->length = npixels; - rep->width = width; - rep->height = height; - rep->x = x; - rep->y = y; - rep->xhot = pCursor->bits->xhot; - rep->yhot = pCursor->bits->yhot; - rep->cursorSerial = pCursor->serialNumber; - - image = (CARD32 *) (rep + 1); - CopyCursorToImage (pCursor, image); - if (client->swapped) - { - int n; - swaps (&rep->sequenceNumber, n); - swapl (&rep->length, n); - swaps (&rep->x, n); - swaps (&rep->y, n); - swaps (&rep->width, n); - swaps (&rep->height, n); - swaps (&rep->xhot, n); - swaps (&rep->yhot, n); - swapl (&rep->cursorSerial, n); - SwapLongs (image, npixels); - } - (void) WriteToClient(client, sizeof (xXFixesGetCursorImageReply) + - (npixels << 2), (char *) rep); - xfree (rep); - return client->noClientException; -} - -int -SProcXFixesGetCursorImage (ClientPtr client) -{ - int n; - REQUEST(xXFixesGetCursorImageReq); - swaps (&stuff->length, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -int -ProcXFixesSetCursorName (ClientPtr client) -{ - CursorPtr pCursor; - char *tchar; - REQUEST(xXFixesSetCursorNameReq); - Atom atom; - - REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq); - VERIFY_CURSOR(pCursor, stuff->cursor, client, SecurityWriteAccess); - tchar = (char *) &stuff[1]; - atom = MakeAtom (tchar, stuff->nbytes, TRUE); - if (atom == BAD_RESOURCE) - return BadAlloc; - - pCursor->name = atom; - return(client->noClientException); -} - -int -SProcXFixesSetCursorName (ClientPtr client) -{ - int n; - REQUEST(xXFixesSetCursorNameReq); - - swaps (&stuff->length, n); - REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq); - swapl (&stuff->cursor, n); - swaps (&stuff->nbytes, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -int -ProcXFixesGetCursorName (ClientPtr client) -{ - CursorPtr pCursor; - xXFixesGetCursorNameReply reply; - REQUEST(xXFixesGetCursorNameReq); - char *str; - int len; - - REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq); - VERIFY_CURSOR(pCursor, stuff->cursor, client, SecurityReadAccess); - if (pCursor->name) - str = NameForAtom (pCursor->name); - else - str = ""; - len = strlen (str); - - reply.type = X_Reply; - reply.length = (len + 3) >> 2; - reply.sequenceNumber = client->sequence; - reply.atom = pCursor->name; - reply.nbytes = len; - if (client->swapped) - { - int n; - swaps (&reply.sequenceNumber, n); - swapl (&reply.length, n); - swapl (&reply.atom, n); - swaps (&reply.nbytes, n); - } - WriteReplyToClient(client, sizeof(xXFixesGetCursorNameReply), &reply); - (void)WriteToClient(client, len, str); - - return(client->noClientException); -} - -int -SProcXFixesGetCursorName (ClientPtr client) -{ - int n; - REQUEST(xXFixesSetCursorNameReq); - - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq); - swapl (&stuff->cursor, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -int -ProcXFixesGetCursorImageAndName (ClientPtr client) -{ -/* REQUEST(xXFixesGetCursorImageAndNameReq); */ - xXFixesGetCursorImageAndNameReply *rep; - CursorPtr pCursor; - CARD32 *image; - int npixels; - char *name; - int nbytes, nbytesRound; - int width, height; - int x, y; - - REQUEST_SIZE_MATCH(xXFixesGetCursorImageAndNameReq); - pCursor = CursorCurrent; - if (!pCursor) - return BadCursor; - GetSpritePosition (&x, &y); - width = pCursor->bits->width; - height = pCursor->bits->height; - npixels = width * height; - name = pCursor->name ? NameForAtom (pCursor->name) : ""; - nbytes = strlen (name); - nbytesRound = (nbytes + 3) & ~3; - rep = xalloc (sizeof (xXFixesGetCursorImageAndNameReply) + - npixels * sizeof (CARD32) + nbytesRound); - if (!rep) - return BadAlloc; - - rep->type = X_Reply; - rep->sequenceNumber = client->sequence; - rep->length = npixels + (nbytesRound >> 2); - rep->width = width; - rep->height = height; - rep->x = x; - rep->y = y; - rep->xhot = pCursor->bits->xhot; - rep->yhot = pCursor->bits->yhot; - rep->cursorSerial = pCursor->serialNumber; - rep->cursorName = pCursor->name; - rep->nbytes = nbytes; - - image = (CARD32 *) (rep + 1); - CopyCursorToImage (pCursor, image); - memcpy ((image + npixels), name, nbytes); - if (client->swapped) - { - int n; - swaps (&rep->sequenceNumber, n); - swapl (&rep->length, n); - swaps (&rep->x, n); - swaps (&rep->y, n); - swaps (&rep->width, n); - swaps (&rep->height, n); - swaps (&rep->xhot, n); - swaps (&rep->yhot, n); - swapl (&rep->cursorSerial, n); - swapl (&rep->cursorName, n); - swaps (&rep->nbytes, n); - SwapLongs (image, npixels); - } - (void) WriteToClient(client, sizeof (xXFixesGetCursorImageAndNameReply) + - (npixels << 2) + nbytesRound, (char *) rep); - xfree (rep); - return client->noClientException; -} - -int -SProcXFixesGetCursorImageAndName (ClientPtr client) -{ - int n; - REQUEST(xXFixesGetCursorImageAndNameReq); - swaps (&stuff->length, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -/* - * Find every cursor reference in the system, ask testCursor - * whether it should be replaced with a reference to pCursor. - */ - -typedef Bool (*TestCursorFunc) (CursorPtr pOld, pointer closure); - -typedef struct { - RESTYPE type; - TestCursorFunc testCursor; - CursorPtr pNew; - pointer closure; -} ReplaceCursorLookupRec, *ReplaceCursorLookupPtr; - -static const RESTYPE CursorRestypes[] = { - RT_WINDOW, RT_PASSIVEGRAB, RT_CURSOR -}; - -#define NUM_CURSOR_RESTYPES (sizeof (CursorRestypes) / sizeof (CursorRestypes[0])) - -static Bool -ReplaceCursorLookup (pointer value, XID id, pointer closure) -{ - ReplaceCursorLookupPtr rcl = (ReplaceCursorLookupPtr) closure; - WindowPtr pWin; - GrabPtr pGrab; - CursorPtr pCursor = 0, *pCursorRef = 0; - XID cursor = 0; - - switch (rcl->type) { - case RT_WINDOW: - pWin = (WindowPtr) value; - if (pWin->optional) - { - pCursorRef = &pWin->optional->cursor; - pCursor = *pCursorRef; - } - break; - case RT_PASSIVEGRAB: - pGrab = (GrabPtr) value; - pCursorRef = &pGrab->cursor; - pCursor = *pCursorRef; - break; - case RT_CURSOR: - pCursorRef = 0; - pCursor = (CursorPtr) value; - cursor = id; - break; - } - if (pCursor && pCursor != rcl->pNew) - { - if ((*rcl->testCursor) (pCursor, rcl->closure)) - { - rcl->pNew->refcnt++; - /* either redirect reference or update resource database */ - if (pCursorRef) - *pCursorRef = rcl->pNew; - else - ChangeResourceValue (id, RT_CURSOR, rcl->pNew); - FreeCursor (pCursor, cursor); - } - } - return FALSE; /* keep walking */ -} - -static void -ReplaceCursor (CursorPtr pCursor, - TestCursorFunc testCursor, - pointer closure) -{ - int clientIndex; - int resIndex; - ReplaceCursorLookupRec rcl; - - /* - * Cursors exist only in the resource database, windows and grabs. - * All of these are always pointed at by the resource database. Walk - * the whole thing looking for cursors - */ - rcl.testCursor = testCursor; - rcl.pNew = pCursor; - rcl.closure = closure; - - /* for each client */ - for (clientIndex = 0; clientIndex < currentMaxClients; clientIndex++) - { - if (!clients[clientIndex]) - continue; - for (resIndex = 0; resIndex < NUM_CURSOR_RESTYPES; resIndex++) - { - rcl.type = CursorRestypes[resIndex]; - /* - * This function walks the entire client resource database - */ - LookupClientResourceComplex (clients[clientIndex], - rcl.type, - ReplaceCursorLookup, - (pointer) &rcl); - } - } - /* this "knows" that WindowHasNewCursor doesn't depend on it's argument */ - WindowHasNewCursor (WindowTable[0]); -} - -static Bool -TestForCursor (CursorPtr pCursor, pointer closure) -{ - return (pCursor == (CursorPtr) closure); -} - -int -ProcXFixesChangeCursor (ClientPtr client) -{ - CursorPtr pSource, pDestination; - REQUEST(xXFixesChangeCursorReq); - - REQUEST_SIZE_MATCH(xXFixesChangeCursorReq); - VERIFY_CURSOR (pSource, stuff->source, client, SecurityReadAccess); - VERIFY_CURSOR (pDestination, stuff->destination, client, SecurityWriteAccess); - - ReplaceCursor (pSource, TestForCursor, (pointer) pDestination); - return (client->noClientException); -} - -int -SProcXFixesChangeCursor (ClientPtr client) -{ - int n; - REQUEST(xXFixesChangeCursorReq); - - swaps (&stuff->length, n); - REQUEST_SIZE_MATCH(xXFixesChangeCursorReq); - swapl (&stuff->source, n); - swapl (&stuff->destination, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -static Bool -TestForCursorName (CursorPtr pCursor, pointer closure) -{ - return (pCursor->name == (Atom) closure); -} - -int -ProcXFixesChangeCursorByName (ClientPtr client) -{ - CursorPtr pSource; - Atom name; - char *tchar; - REQUEST(xXFixesChangeCursorByNameReq); - - REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes); - VERIFY_CURSOR(pSource, stuff->source, client, SecurityReadAccess); - tchar = (char *) &stuff[1]; - name = MakeAtom (tchar, stuff->nbytes, FALSE); - if (name) - ReplaceCursor (pSource, TestForCursorName, (pointer) name); - return (client->noClientException); -} - -int -SProcXFixesChangeCursorByName (ClientPtr client) -{ - int n; - REQUEST(xXFixesChangeCursorByNameReq); - - swaps (&stuff->length, n); - REQUEST_AT_LEAST_SIZE (xXFixesChangeCursorByNameReq); - swapl (&stuff->source, n); - swaps (&stuff->nbytes, n); - return (*ProcXFixesVector[stuff->xfixesReqType]) (client); -} - -static int -CursorFreeClient (pointer data, XID id) -{ - CursorEventPtr old = (CursorEventPtr) data; - CursorEventPtr *prev, e; - - for (prev = &cursorEvents; (e = *prev); prev = &e->next) - { - if (e == old) - { - *prev = e->next; - xfree (e); - break; - } - } - return 1; -} - -static int -CursorFreeWindow (pointer data, XID id) -{ - WindowPtr pWindow = (WindowPtr) data; - CursorEventPtr e, next; - - for (e = cursorEvents; e; e = next) - { - next = e->next; - if (e->pWindow == pWindow) - { - FreeResource (e->clientResource, 0); - } - } - return 1; -} - -Bool -XFixesCursorInit (void) -{ - int i; - - if (CursorGeneration != serverGeneration) - { - CursorScreenPrivateIndex = AllocateScreenPrivateIndex (); - if (CursorScreenPrivateIndex < 0) - return FALSE; - CursorGeneration = serverGeneration; - } - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - CursorScreenPtr cs; - - cs = (CursorScreenPtr) xalloc (sizeof (CursorScreenRec)); - if (!cs) - return FALSE; - Wrap (cs, pScreen, CloseScreen, CursorCloseScreen); - Wrap (cs, pScreen, DisplayCursor, CursorDisplayCursor); - SetCursorScreen (pScreen, cs); - } - CursorClientType = CreateNewResourceType(CursorFreeClient); - CursorWindowType = CreateNewResourceType(CursorFreeWindow); - return CursorClientType && CursorWindowType; -} - diff --git a/nx-X11/programs/Xserver/xfixes/select.c.NX.original b/nx-X11/programs/Xserver/xfixes/select.c.NX.original deleted file mode 100755 index c72e19e9a..000000000 --- a/nx-X11/programs/Xserver/xfixes/select.c.NX.original +++ /dev/null @@ -1,281 +0,0 @@ -/* - * $Id: select.c,v 1.6 2005/07/03 07:37:35 daniels Exp $ - * - * Copyright © 2002 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "xfixesint.h" - -static RESTYPE SelectionClientType, SelectionWindowType; -static Bool SelectionCallbackRegistered = FALSE; - -/* - * There is a global list of windows selecting for selection events - * on every selection. This should be plenty efficient for the - * expected usage, if it does become a problem, it should be easily - * replaced with a hash table of some kind keyed off the selection atom - */ - -typedef struct _SelectionEvent *SelectionEventPtr; - -typedef struct _SelectionEvent { - SelectionEventPtr next; - Atom selection; - CARD32 eventMask; - ClientPtr pClient; - WindowPtr pWindow; - XID clientResource; -} SelectionEventRec; - -static SelectionEventPtr selectionEvents; - -static void -XFixesSelectionCallback (CallbackListPtr *callbacks, pointer data, pointer args) -{ - SelectionEventPtr e; - SelectionInfoRec *info = (SelectionInfoRec *) args; - Selection *selection = info->selection; - int subtype; - CARD32 eventMask; - - switch (info->kind) { - case SelectionSetOwner: - subtype = XFixesSetSelectionOwnerNotify; - eventMask = XFixesSetSelectionOwnerNotifyMask; - break; - case SelectionWindowDestroy: - subtype = XFixesSelectionWindowDestroyNotify; - eventMask = XFixesSelectionWindowDestroyNotifyMask; - break; - case SelectionClientClose: - subtype = XFixesSelectionClientCloseNotify; - eventMask = XFixesSelectionClientCloseNotifyMask; - break; - default: - return; - } - for (e = selectionEvents; e; e = e->next) - { - if (e->selection == selection->selection && - (e->eventMask & eventMask) && - !e->pClient->clientGone) - { - xXFixesSelectionNotifyEvent ev; - - ev.type = XFixesEventBase + XFixesSelectionNotify; - ev.subtype = subtype; - ev.sequenceNumber = e->pClient->sequence; - ev.window = e->pWindow->drawable.id; - if (subtype == XFixesSetSelectionOwnerNotify) - ev.owner = selection->window; - else - ev.owner = 0; - ev.selection = e->selection; - ev.timestamp = currentTime.milliseconds; - ev.selectionTimestamp = selection->lastTimeChanged.milliseconds; - WriteEventsToClient (e->pClient, 1, (xEvent *) &ev); - } - } -} - -static Bool -CheckSelectionCallback (void) -{ - if (selectionEvents) - { - if (!SelectionCallbackRegistered) - { - if (!AddCallback (&SelectionCallback, XFixesSelectionCallback, NULL)) - return FALSE; - SelectionCallbackRegistered = TRUE; - } - } - else - { - if (SelectionCallbackRegistered) - { - DeleteCallback (&SelectionCallback, XFixesSelectionCallback, NULL); - SelectionCallbackRegistered = FALSE; - } - } - return TRUE; -} - -#define SelectionAllEvents (XFixesSetSelectionOwnerNotifyMask |\ - XFixesSelectionWindowDestroyNotifyMask |\ - XFixesSelectionClientCloseNotifyMask) - -static int -XFixesSelectSelectionInput (ClientPtr pClient, - Atom selection, - WindowPtr pWindow, - CARD32 eventMask) -{ - SelectionEventPtr *prev, e; - - for (prev = &selectionEvents; (e = *prev); prev = &e->next) - { - if (e->selection == selection && - e->pClient == pClient && - e->pWindow == pWindow) - { - break; - } - } - if (!eventMask) - { - if (e) - { - FreeResource (e->clientResource, 0); - } - return Success; - } - if (!e) - { - e = (SelectionEventPtr) xalloc (sizeof (SelectionEventRec)); - if (!e) - return BadAlloc; - - e->next = 0; - e->selection = selection; - e->pClient = pClient; - e->pWindow = pWindow; - e->clientResource = FakeClientID(pClient->index); - - /* - * Add a resource hanging from the window to - * catch window destroy - */ - if (!LookupIDByType(pWindow->drawable.id, SelectionWindowType)) - if (!AddResource (pWindow->drawable.id, SelectionWindowType, - (pointer) pWindow)) - { - xfree (e); - return BadAlloc; - } - - if (!AddResource (e->clientResource, SelectionClientType, (pointer) e)) - return BadAlloc; - - *prev = e; - if (!CheckSelectionCallback ()) - { - FreeResource (e->clientResource, 0); - return BadAlloc; - } - } - e->eventMask = eventMask; - return Success; -} - -int -ProcXFixesSelectSelectionInput (ClientPtr client) -{ - REQUEST (xXFixesSelectSelectionInputReq); - WindowPtr pWin; - - REQUEST_SIZE_MATCH (xXFixesSelectSelectionInputReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (stuff->eventMask & ~SelectionAllEvents) - { - client->errorValue = stuff->eventMask; - return( BadValue ); - } - return XFixesSelectSelectionInput (client, stuff->selection, - pWin, stuff->eventMask); -} - -int -SProcXFixesSelectSelectionInput (ClientPtr client) -{ - register int n; - REQUEST(xXFixesSelectSelectionInputReq); - - swaps(&stuff->length, n); - swapl(&stuff->window, n); - swapl(&stuff->selection, n); - swapl(&stuff->eventMask, n); - return ProcXFixesSelectSelectionInput(client); -} - -void -SXFixesSelectionNotifyEvent (xXFixesSelectionNotifyEvent *from, - xXFixesSelectionNotifyEvent *to) -{ - to->type = from->type; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->window, to->window); - cpswapl (from->owner, to->owner); - cpswapl (from->selection, to->selection); - cpswapl (from->timestamp, to->timestamp); - cpswapl (from->selectionTimestamp, to->selectionTimestamp); -} - -static int -SelectionFreeClient (pointer data, XID id) -{ - SelectionEventPtr old = (SelectionEventPtr) data; - SelectionEventPtr *prev, e; - - for (prev = &selectionEvents; (e = *prev); prev = &e->next) - { - if (e == old) - { - *prev = e->next; - xfree (e); - CheckSelectionCallback (); - break; - } - } - return 1; -} - -static int -SelectionFreeWindow (pointer data, XID id) -{ - WindowPtr pWindow = (WindowPtr) data; - SelectionEventPtr e, next; - - for (e = selectionEvents; e; e = next) - { - next = e->next; - if (e->pWindow == pWindow) - { - FreeResource (e->clientResource, 0); - } - } - return 1; -} - -Bool -XFixesSelectionInit (void) -{ - SelectionClientType = CreateNewResourceType(SelectionFreeClient); - SelectionWindowType = CreateNewResourceType(SelectionFreeWindow); - return SelectionClientType && SelectionWindowType; -} diff --git a/nx-X11/programs/Xserver/xfixes/select.c.X.original b/nx-X11/programs/Xserver/xfixes/select.c.X.original deleted file mode 100755 index 6a28da93b..000000000 --- a/nx-X11/programs/Xserver/xfixes/select.c.X.original +++ /dev/null @@ -1,279 +0,0 @@ -/* - * $Id: select.c,v 1.6 2005/07/03 07:37:35 daniels Exp $ - * - * Copyright © 2002 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "xfixesint.h" - -static RESTYPE SelectionClientType, SelectionWindowType; -static Bool SelectionCallbackRegistered = FALSE; - -/* - * There is a global list of windows selecting for selection events - * on every selection. This should be plenty efficient for the - * expected usage, if it does become a problem, it should be easily - * replaced with a hash table of some kind keyed off the selection atom - */ - -typedef struct _SelectionEvent *SelectionEventPtr; - -typedef struct _SelectionEvent { - SelectionEventPtr next; - Atom selection; - CARD32 eventMask; - ClientPtr pClient; - WindowPtr pWindow; - XID clientResource; -} SelectionEventRec; - -static SelectionEventPtr selectionEvents; - -static void -XFixesSelectionCallback (CallbackListPtr *callbacks, pointer data, pointer args) -{ - SelectionEventPtr e; - SelectionInfoRec *info = (SelectionInfoRec *) args; - Selection *selection = info->selection; - int subtype; - CARD32 eventMask; - - switch (info->kind) { - case SelectionSetOwner: - subtype = XFixesSetSelectionOwnerNotify; - eventMask = XFixesSetSelectionOwnerNotifyMask; - break; - case SelectionWindowDestroy: - subtype = XFixesSelectionWindowDestroyNotify; - eventMask = XFixesSelectionWindowDestroyNotifyMask; - break; - case SelectionClientClose: - subtype = XFixesSelectionClientCloseNotify; - eventMask = XFixesSelectionClientCloseNotifyMask; - break; - default: - return; - } - for (e = selectionEvents; e; e = e->next) - { - if (e->selection == selection->selection && (e->eventMask & eventMask)) - { - xXFixesSelectionNotifyEvent ev; - - ev.type = XFixesEventBase + XFixesSelectionNotify; - ev.subtype = subtype; - ev.sequenceNumber = e->pClient->sequence; - ev.window = e->pWindow->drawable.id; - if (subtype == XFixesSetSelectionOwnerNotify) - ev.owner = selection->window; - else - ev.owner = 0; - ev.selection = e->selection; - ev.timestamp = currentTime.milliseconds; - ev.selectionTimestamp = selection->lastTimeChanged.milliseconds; - WriteEventsToClient (e->pClient, 1, (xEvent *) &ev); - } - } -} - -static Bool -CheckSelectionCallback (void) -{ - if (selectionEvents) - { - if (!SelectionCallbackRegistered) - { - if (!AddCallback (&SelectionCallback, XFixesSelectionCallback, NULL)) - return FALSE; - SelectionCallbackRegistered = TRUE; - } - } - else - { - if (SelectionCallbackRegistered) - { - DeleteCallback (&SelectionCallback, XFixesSelectionCallback, NULL); - SelectionCallbackRegistered = FALSE; - } - } - return TRUE; -} - -#define SelectionAllEvents (XFixesSetSelectionOwnerNotifyMask |\ - XFixesSelectionWindowDestroyNotifyMask |\ - XFixesSelectionClientCloseNotifyMask) - -static int -XFixesSelectSelectionInput (ClientPtr pClient, - Atom selection, - WindowPtr pWindow, - CARD32 eventMask) -{ - SelectionEventPtr *prev, e; - - for (prev = &selectionEvents; (e = *prev); prev = &e->next) - { - if (e->selection == selection && - e->pClient == pClient && - e->pWindow == pWindow) - { - break; - } - } - if (!eventMask) - { - if (e) - { - FreeResource (e->clientResource, 0); - } - return Success; - } - if (!e) - { - e = (SelectionEventPtr) xalloc (sizeof (SelectionEventRec)); - if (!e) - return BadAlloc; - - e->next = 0; - e->selection = selection; - e->pClient = pClient; - e->pWindow = pWindow; - e->clientResource = FakeClientID(pClient->index); - - /* - * Add a resource hanging from the window to - * catch window destroy - */ - if (!LookupIDByType(pWindow->drawable.id, SelectionWindowType)) - if (!AddResource (pWindow->drawable.id, SelectionWindowType, - (pointer) pWindow)) - { - xfree (e); - return BadAlloc; - } - - if (!AddResource (e->clientResource, SelectionClientType, (pointer) e)) - return BadAlloc; - - *prev = e; - if (!CheckSelectionCallback ()) - { - FreeResource (e->clientResource, 0); - return BadAlloc; - } - } - e->eventMask = eventMask; - return Success; -} - -int -ProcXFixesSelectSelectionInput (ClientPtr client) -{ - REQUEST (xXFixesSelectSelectionInputReq); - WindowPtr pWin; - - REQUEST_SIZE_MATCH (xXFixesSelectSelectionInputReq); - pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client, - SecurityReadAccess); - if (!pWin) - return(BadWindow); - if (stuff->eventMask & ~SelectionAllEvents) - { - client->errorValue = stuff->eventMask; - return( BadValue ); - } - return XFixesSelectSelectionInput (client, stuff->selection, - pWin, stuff->eventMask); -} - -int -SProcXFixesSelectSelectionInput (ClientPtr client) -{ - register int n; - REQUEST(xXFixesSelectSelectionInputReq); - - swaps(&stuff->length, n); - swapl(&stuff->window, n); - swapl(&stuff->selection, n); - swapl(&stuff->eventMask, n); - return ProcXFixesSelectSelectionInput(client); -} - -void -SXFixesSelectionNotifyEvent (xXFixesSelectionNotifyEvent *from, - xXFixesSelectionNotifyEvent *to) -{ - to->type = from->type; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->window, to->window); - cpswapl (from->owner, to->owner); - cpswapl (from->selection, to->selection); - cpswapl (from->timestamp, to->timestamp); - cpswapl (from->selectionTimestamp, to->selectionTimestamp); -} - -static int -SelectionFreeClient (pointer data, XID id) -{ - SelectionEventPtr old = (SelectionEventPtr) data; - SelectionEventPtr *prev, e; - - for (prev = &selectionEvents; (e = *prev); prev = &e->next) - { - if (e == old) - { - *prev = e->next; - xfree (e); - CheckSelectionCallback (); - break; - } - } - return 1; -} - -static int -SelectionFreeWindow (pointer data, XID id) -{ - WindowPtr pWindow = (WindowPtr) data; - SelectionEventPtr e, next; - - for (e = selectionEvents; e; e = next) - { - next = e->next; - if (e->pWindow == pWindow) - { - FreeResource (e->clientResource, 0); - } - } - return 1; -} - -Bool -XFixesSelectionInit (void) -{ - SelectionClientType = CreateNewResourceType(SelectionFreeClient); - SelectionWindowType = CreateNewResourceType(SelectionFreeWindow); - return SelectionClientType && SelectionWindowType; -} diff --git a/nx-X11/programs/Xserver/xkb/Imakefile.NX.original b/nx-X11/programs/Xserver/xkb/Imakefile.NX.original deleted file mode 100644 index a718545b1..000000000 --- a/nx-X11/programs/Xserver/xkb/Imakefile.NX.original +++ /dev/null @@ -1,106 +0,0 @@ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/xkb/Imakefile,v 3.21 2002/12/09 23:00:42 dawes Exp $ - -#define SGIHyperOpt -#include - -#ifdef SGIArchitecture -EXTRA_ALLOC_DEFINES = -DFORCE_ALLOCA -#endif - -#if BuildXInputExt -XKBXI_SRCS = xkbPrOtherEv.c -XKBXI_OBJS = xkbPrOtherEv.o -#endif - -#ifdef DfltDisableXKB -XKB_DISABLE = -DXKB_DFLT_DISABLED=1 -#else -XKB_DISABLE = -DXKB_DFLT_DISABLED=0 -#endif - -XKB_DDXDEFS = XkbServerDefines - -#if defined(NXAgentServer) && NXAgentServer -NX_DEFINES = -DNXAGENT_SERVER -#endif - -#if (defined(XF86Server) && XF86Server) || (defined(XorgServer) && XorgServer) -XF86INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) - XF86_OBJS = xf86KillSrv.o xf86VT.o xf86Private.o -#endif - - DDX_SRCS = ddxBeep.c ddxCtrls.c ddxFakeBtn.c ddxFakeMtn.c ddxInit.c \ - ddxKeyClick.c ddxKillSrv.c ddxLEDs.c ddxVT.c ddxLoad.c \ - ddxList.c ddxConfig.c ddxDevBtn.c ddxPrivate.c xkbconfig.c - DDX_OBJS = ddxBeep.o ddxCtrls.o ddxFakeBtn.o ddxFakeMtn.o ddxInit.o \ - ddxKeyClick.o ddxKillSrv.o ddxLEDs.o ddxVT.o ddxLoad.o \ - ddxList.o ddxConfig.o ddxDevBtn.o ddxPrivate.o xkbconfig.o - SRCS = xkb.c xkbUtils.c xkbEvents.c xkbAccessX.c xkbSwap.c \ - xkbLEDs.c xkbInit.c xkbActions.c xkbPrKeyEv.c \ - xkmread.c xkbtext.c xkbfmisc.c xkberrs.c xkbout.c maprules.c \ - XKBMisc.c XKBMAlloc.c XKBAlloc.c XKBGAlloc.c \ - $(XKBXI_SRCS) $(DDX_SRCS) - OBJS = xkb.o xkbUtils.o xkbEvents.o xkbAccessX.o xkbSwap.o \ - xkbLEDs.o xkbInit.o xkbActions.o xkbPrKeyEv.o \ - xkmread.o xkbtext.o xkbfmisc.o xkberrs.o xkbout.o maprules.o \ - XKBMisc.o XKBMAlloc.o XKBAlloc.o XKBGAlloc.o \ - $(XKBXI_OBJS) $(DDX_OBJS) - INCLUDES = -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/Xext \ - -I$(SERVERSRC)/mi $(XF86INCLUDES) - LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln - -DEFINES = -DXKB_IN_SERVER $(EXTRA_ALLOC_DEFINES) $(XKB_DDXDEFS) $(NX_DEFINES) -XKB_DEFINES = -DXKB_BASE_DIRECTORY=\"$(LIBDIR)/xkb\" $(XKB_DISABLE) - -NormalLibraryObjectRule() -NormalLibraryTarget(xkb,$(OBJS)) -LintLibraryTarget(xkb,$(SRCS)) -NormalLintTarget($(SRCS)) - -#if (defined(XF86Server) && XF86Server) || (defined(XorgServer) && XorgServer) -ObjectFromSpecialSource(xf86KillSrv,ddxKillSrv,-DXF86DDXACTIONS) -ObjectFromSpecialSource(xf86VT,ddxVT,-DXF86DDXACTIONS) -ObjectFromSpecialSource(xf86Private,ddxPrivate,-DXF86DDXACTIONS) -AllTarget($(XF86_OBJS)) -#endif - -SpecialCObjectRule(xkbInit,$(ICONFIGFILES),$(XKB_DEFINES)) - -LinkSourceFile(maprules.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkmread.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkbtext.c,$(XKBFILELIBSRC)) -XCOMM avoid clash between XKBMisc.c and xkbmisc.c on NT -LinkFile(xkbfmisc.c,$(XKBFILELIBSRC)/xkbmisc.c) -LinkSourceFile(xkberrs.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkbconfig.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkbout.c,$(XKBFILELIBSRC)) -LinkSourceFile(XKBMisc.c,$(XLIBSRC)) -LinkSourceFile(XKBMAlloc.c,$(XLIBSRC)) -LinkSourceFile(XKBAlloc.c,$(XLIBSRC)) -LinkSourceFile(XKBGAlloc.c,$(XLIBSRC)) - -LinkSourceFile(modinit.h,../Xext/extmod) - -#if BuildLibraries -#if UseConfDirForXkb -LinkConfDirectory(xkb,.,xkb,.) -ODIR = $(CONFDIR) -#else -ODIR = $(LIBDIR) -#endif -#ifdef VarDbDirectory -NDIR = $(VARDBDIR) -#else -NDIR = $(CONFDIR) -#endif -#if !UseConfDirForXkb || defined(VarDbDirectory) -LinkConfDirectoryLong(xkb,xkb,compiled,compiled,$(ODIR),$(NDIR)) -#endif -#endif - -DependTarget() diff --git a/nx-X11/programs/Xserver/xkb/Imakefile.X.original b/nx-X11/programs/Xserver/xkb/Imakefile.X.original deleted file mode 100644 index a91f8ff86..000000000 --- a/nx-X11/programs/Xserver/xkb/Imakefile.X.original +++ /dev/null @@ -1,102 +0,0 @@ -XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ - - - - -XCOMM $XFree86: xc/programs/Xserver/xkb/Imakefile,v 3.21 2002/12/09 23:00:42 dawes Exp $ - -#define SGIHyperOpt -#include - -#ifdef SGIArchitecture -EXTRA_ALLOC_DEFINES = -DFORCE_ALLOCA -#endif - -#if BuildXInputExt -XKBXI_SRCS = xkbPrOtherEv.c -XKBXI_OBJS = xkbPrOtherEv.o -#endif - -#ifdef DfltDisableXKB -XKB_DISABLE = -DXKB_DFLT_DISABLED=1 -#else -XKB_DISABLE = -DXKB_DFLT_DISABLED=0 -#endif - -XKB_DDXDEFS = XkbServerDefines - -#if (defined(XF86Server) && XF86Server) || (defined(XorgServer) && XorgServer) -XF86INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) - XF86_OBJS = xf86KillSrv.o xf86VT.o xf86Private.o -#endif - - DDX_SRCS = ddxBeep.c ddxCtrls.c ddxFakeBtn.c ddxFakeMtn.c ddxInit.c \ - ddxKeyClick.c ddxKillSrv.c ddxLEDs.c ddxVT.c ddxLoad.c \ - ddxList.c ddxConfig.c ddxDevBtn.c ddxPrivate.c xkbconfig.c - DDX_OBJS = ddxBeep.o ddxCtrls.o ddxFakeBtn.o ddxFakeMtn.o ddxInit.o \ - ddxKeyClick.o ddxKillSrv.o ddxLEDs.o ddxVT.o ddxLoad.o \ - ddxList.o ddxConfig.o ddxDevBtn.o ddxPrivate.o xkbconfig.o - SRCS = xkb.c xkbUtils.c xkbEvents.c xkbAccessX.c xkbSwap.c \ - xkbLEDs.c xkbInit.c xkbActions.c xkbPrKeyEv.c \ - xkmread.c xkbtext.c xkbfmisc.c xkberrs.c xkbout.c maprules.c \ - XKBMisc.c XKBMAlloc.c XKBAlloc.c XKBGAlloc.c \ - $(XKBXI_SRCS) $(DDX_SRCS) - OBJS = xkb.o xkbUtils.o xkbEvents.o xkbAccessX.o xkbSwap.o \ - xkbLEDs.o xkbInit.o xkbActions.o xkbPrKeyEv.o \ - xkmread.o xkbtext.o xkbfmisc.o xkberrs.o xkbout.o maprules.o \ - XKBMisc.o XKBMAlloc.o XKBAlloc.o XKBGAlloc.o \ - $(XKBXI_OBJS) $(DDX_OBJS) - INCLUDES = -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/Xext \ - -I$(SERVERSRC)/mi $(XF86INCLUDES) - LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln - -DEFINES = -DXKB_IN_SERVER $(EXTRA_ALLOC_DEFINES) $(XKB_DDXDEFS) -XKB_DEFINES = -DXKB_BASE_DIRECTORY=\"$(LIBDIR)/xkb\" $(XKB_DISABLE) - -NormalLibraryObjectRule() -NormalLibraryTarget(xkb,$(OBJS)) -LintLibraryTarget(xkb,$(SRCS)) -NormalLintTarget($(SRCS)) - -#if (defined(XF86Server) && XF86Server) || (defined(XorgServer) && XorgServer) -ObjectFromSpecialSource(xf86KillSrv,ddxKillSrv,-DXF86DDXACTIONS) -ObjectFromSpecialSource(xf86VT,ddxVT,-DXF86DDXACTIONS) -ObjectFromSpecialSource(xf86Private,ddxPrivate,-DXF86DDXACTIONS) -AllTarget($(XF86_OBJS)) -#endif - -SpecialCObjectRule(xkbInit,$(ICONFIGFILES),$(XKB_DEFINES)) - -LinkSourceFile(maprules.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkmread.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkbtext.c,$(XKBFILELIBSRC)) -XCOMM avoid clash between XKBMisc.c and xkbmisc.c on NT -LinkFile(xkbfmisc.c,$(XKBFILELIBSRC)/xkbmisc.c) -LinkSourceFile(xkberrs.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkbconfig.c,$(XKBFILELIBSRC)) -LinkSourceFile(xkbout.c,$(XKBFILELIBSRC)) -LinkSourceFile(XKBMisc.c,$(XLIBSRC)) -LinkSourceFile(XKBMAlloc.c,$(XLIBSRC)) -LinkSourceFile(XKBAlloc.c,$(XLIBSRC)) -LinkSourceFile(XKBGAlloc.c,$(XLIBSRC)) - -LinkSourceFile(modinit.h,../Xext/extmod) - -#if BuildLibraries -#if UseConfDirForXkb -LinkConfDirectory(xkb,.,xkb,.) -ODIR = $(CONFDIR) -#else -ODIR = $(LIBDIR) -#endif -#ifdef VarDbDirectory -NDIR = $(VARDBDIR) -#else -NDIR = $(CONFDIR) -#endif -#if !UseConfDirForXkb || defined(VarDbDirectory) -LinkConfDirectoryLong(xkb,xkb,compiled,compiled,$(ODIR),$(NDIR)) -#endif -#endif - -DependTarget() diff --git a/nx-X11/programs/Xserver/xkb/ddxKillSrv.c.NX.original b/nx-X11/programs/Xserver/xkb/ddxKillSrv.c.NX.original deleted file mode 100644 index b78dc420d..000000000 --- a/nx-X11/programs/Xserver/xkb/ddxKillSrv.c.NX.original +++ /dev/null @@ -1,69 +0,0 @@ -/* $Xorg: ddxKillSrv.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */ -/************************************************************ -Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. - -Permission to use, copy, modify, and distribute this -software and its documentation for any purpose and without -fee is hereby granted, provided that the above copyright -notice appear in all copies and that both that copyright -notice and this permission notice appear in supporting -documentation, and that the name of Silicon Graphics not be -used in advertising or publicity pertaining to distribution -of the software without specific prior written permission. -Silicon Graphics makes no representation about the suitability -of this software for any purpose. It is provided "as is" -without any express or implied warranty. - -SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON -GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH -THE USE OR PERFORMANCE OF THIS SOFTWARE. - -********************************************************/ -/* $XFree86: xc/programs/Xserver/xkb/ddxKillSrv.c,v 1.3 2002/11/23 19:27:50 tsi Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#define NEED_EVENTS 1 -#include -#include -#include -#include "inputstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include - -#ifdef XF86DDXACTIONS -#include "xf86.h" -#endif - -int -XkbDDXTerminateServer(DeviceIntPtr dev,KeyCode key,XkbAction *act) -{ -#ifdef NXAGENT_SERVER - - return 0; - -#else - -#ifdef XF86DDXACTIONS - xf86ProcessActionEvent(ACTION_TERMINATE, NULL); -#else - GiveUp(1); -#endif - return 0; - -#endif /* NXAGENT_SERVER */ -} diff --git a/nx-X11/programs/Xserver/xkb/ddxKillSrv.c.X.original b/nx-X11/programs/Xserver/xkb/ddxKillSrv.c.X.original deleted file mode 100644 index ee0acb028..000000000 --- a/nx-X11/programs/Xserver/xkb/ddxKillSrv.c.X.original +++ /dev/null @@ -1,61 +0,0 @@ -/* $Xorg: ddxKillSrv.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */ -/************************************************************ -Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. - -Permission to use, copy, modify, and distribute this -software and its documentation for any purpose and without -fee is hereby granted, provided that the above copyright -notice appear in all copies and that both that copyright -notice and this permission notice appear in supporting -documentation, and that the name of Silicon Graphics not be -used in advertising or publicity pertaining to distribution -of the software without specific prior written permission. -Silicon Graphics makes no representation about the suitability -of this software for any purpose. It is provided "as is" -without any express or implied warranty. - -SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON -GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH -THE USE OR PERFORMANCE OF THIS SOFTWARE. - -********************************************************/ -/* $XFree86: xc/programs/Xserver/xkb/ddxKillSrv.c,v 1.3 2002/11/23 19:27:50 tsi Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#define NEED_EVENTS 1 -#include -#include -#include -#include "inputstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include - -#ifdef XF86DDXACTIONS -#include "xf86.h" -#endif - -int -XkbDDXTerminateServer(DeviceIntPtr dev,KeyCode key,XkbAction *act) -{ -#ifdef XF86DDXACTIONS - xf86ProcessActionEvent(ACTION_TERMINATE, NULL); -#else - GiveUp(1); -#endif - return 0; -} diff --git a/nx-X11/programs/Xserver/xkb/ddxLoad.c.NX.original b/nx-X11/programs/Xserver/xkb/ddxLoad.c.NX.original deleted file mode 100644 index e69d95670..000000000 --- a/nx-X11/programs/Xserver/xkb/ddxLoad.c.NX.original +++ /dev/null @@ -1,970 +0,0 @@ -/* $Xorg: ddxLoad.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */ -/************************************************************ -Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. - -Permission to use, copy, modify, and distribute this -software and its documentation for any purpose and without -fee is hereby granted, provided that the above copyright -notice appear in all copies and that both that copyright -notice and this permission notice appear in supporting -documentation, and that the name of Silicon Graphics not be -used in advertising or publicity pertaining to distribution -of the software without specific prior written permission. -Silicon Graphics makes no representation about the suitability -of this software for any purpose. It is provided "as is" -without any express or implied warranty. - -SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON -GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH -THE USE OR PERFORMANCE OF THIS SOFTWARE. - -********************************************************/ -/* $XFree86: xc/programs/Xserver/xkb/ddxLoad.c,v 3.35 2003/10/02 13:30:12 eich Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XKB_CONFIG_H -#include -#endif - -#include -#include -#include -#define NEED_EVENTS 1 -#include -#include -#include -#include -#include -#include "inputstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#define XKBSRV_NEED_FILE_FUNCS -#include -#include -#include "xkb.h" - -#if defined(CSRG_BASED) || defined(linux) || defined(__sgi) || defined(AIXV3) || defined(__osf__) || defined(__GNU__) -#include -#endif - -#ifndef PATH_MAX -#ifdef MAXPATHLEN -#define PATH_MAX MAXPATHLEN -#else -#define PATH_MAX 1024 -#endif -#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\"" -#define POST_ERROR_MSG2 "\"End of messages from xkbcomp\"" - -#if defined(__UNIXOS2__) || defined(WIN32) -#define PATHSEPARATOR "\\" -#else -#define PATHSEPARATOR "/" -#endif - -#ifdef WIN32 - -#include -const char* -Win32TempDir() -{ - static char buffer[PATH_MAX]; - if (GetTempPath(sizeof(buffer), buffer)) - { - int len; - buffer[sizeof(buffer)-1] = 0; - len = strlen(buffer); - if (len > 0) - if (buffer[len-1] == '\\') - buffer[len-1] = 0; - return buffer; - } - if (getenv("TEMP") != NULL) - return getenv("TEMP"); - else if (getenv("TMP") != NULL) - return getenv("TEMP"); - else - return "/tmp"; -} - -int -Win32System(const char *cmdline) -{ - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD dwExitCode; - char *cmd = xstrdup(cmdline); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) - { - LPVOID buffer; - if (!FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &buffer, - 0, - NULL )) - { - ErrorF("Starting '%s' failed!\n", cmdline); - } - else - { - ErrorF("Starting '%s' failed: %s", cmdline, (char *)buffer); - LocalFree(buffer); - } - - xfree(cmd); - return -1; - } - /* Wait until child process exits. */ - WaitForSingleObject( pi.hProcess, INFINITE ); - - GetExitCodeProcess( pi.hProcess, &dwExitCode); - - /* Close process and thread handles. */ - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - xfree(cmd); - - return dwExitCode; -} -#undef System -#define System(x) Win32System(x) -#endif - -#ifdef MAKE_XKM_OUTPUT_DIR -/* Borrow trans_mkdir from Xtransutil.c to more safely make directories */ -# undef X11_t -# define TRANS_SERVER -# define PRMSG(lvl,x,a,b,c) \ - if (lvl <= 1) { LogMessage(X_ERROR,x,a,b,c); } else ((void)0) -# include -# ifndef XKM_OUTPUT_DIR_MODE -# define XKM_OUTPUT_DIR_MODE 0755 -# endif -#endif - -#ifdef NXAGENT_SERVER - -#define NX_XKB_BASE_DIRECTORY "/usr/lib/X11/xkb" -#define NX_XKB_ALTERNATE_BASE_DIRECTORY "/usr/share/X11/xkb" -#define NX_KEYMAP_DIR_FILE "keymap.dir" -#define NX_ALT_XKBCOMP_PATH "/usr/bin" - -static char _NXXkbBasePath[PATH_MAX]; -static char _NXXkbCompPath[PATH_MAX]; - -static int NXVerifyXkbBaseDirectory(const char *dirPath) -{ - int size; - char *keymapDirFilePath; - struct stat keymapDirFileStat; - - /* - * If keymap.dir file - * is not present into - * Xkb Base Directory, - * we suppose that the - * path is not valid. - */ - - size = strlen(dirPath) + strlen("/") + - strlen(NX_KEYMAP_DIR_FILE) + 1; - - if ((keymapDirFilePath = malloc((size + 1) * sizeof(char))) == NULL) - { - FatalError("NXVerifyXkbBaseDirectory: malloc failed.\n"); - } - - strcpy(keymapDirFilePath, dirPath); - strcat(keymapDirFilePath, "/"); - strcat(keymapDirFilePath, NX_KEYMAP_DIR_FILE); - - #ifdef TEST - fprintf(stderr, "NXVerifyXkbBaseDirectory: Looking for [%s] file.\n", - keymapDirFilePath); - #endif - - if (stat(keymapDirFilePath, &keymapDirFileStat) != 0) - { - - #ifdef TEST - fprintf(stderr, "NXVerifyXkbBaseDirectory: Can't find the keymap.dir file [%s].\n", - keymapDirFilePath); - #endif - - free(keymapDirFilePath); - - return 0; - } - - #ifdef TEST - fprintf(stderr, "NXVerifyXkbBaseDirectory: Xkb Base Directory [%s] is valid.\n", - dirPath); - #endif - - free(keymapDirFilePath); - - return 1; -} - -/* - * This function returns the directory - * containing the configuration files. - * This directory is referred by Xkb- - * BaseDirectory variable (generally - * it contains the hardcoded path at - * compile time). If the directory - * does not exist, the function will - * try a set of well known directories. - */ - -char *_NXGetXkbBasePath(const char *path) -{ - /* - * Check the xkb base directory only once. - */ - - if (*_NXXkbBasePath != '\0') - { - return _NXXkbBasePath; - } - - if (NXVerifyXkbBaseDirectory(XkbBaseDirectory) == 1) - { - if (strlen(XkbBaseDirectory) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: WARNING! Maximum length of xkb base path exceeded.\n"); - #endif - - goto _NXGetXkbBasePathError; - } - - strcpy(_NXXkbBasePath, XkbBaseDirectory); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: Using NX xkb base directory path [%s].\n", - _NXXkbBasePath); - #endif - - return _NXXkbBasePath; - } - - if (NXVerifyXkbBaseDirectory(NX_XKB_BASE_DIRECTORY) == 1) - { - if (strlen(NX_XKB_BASE_DIRECTORY) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: WARNING! Maximum length of xkb base path exceeded.\n"); - #endif - - goto _NXGetXkbBasePathError; - } - - strcpy(_NXXkbBasePath, NX_XKB_BASE_DIRECTORY); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: Using NX xkb base directory path [%s].\n", - _NXXkbBasePath); - #endif - - return _NXXkbBasePath; - } - - if (NXVerifyXkbBaseDirectory(NX_XKB_ALTERNATE_BASE_DIRECTORY) == 1) - { - if (strlen(NX_XKB_ALTERNATE_BASE_DIRECTORY) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: WARNING! Maximum length of xkb base path exceeded.\n"); - #endif - - goto _NXGetXkbBasePathError; - } - - strcpy(_NXXkbBasePath, NX_XKB_ALTERNATE_BASE_DIRECTORY); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: Using NX xkb base directory path [%s].\n", - _NXXkbBasePath); - #endif - - return _NXXkbBasePath; - } - -_NXGetXkbBasePathError: - - if (strlen(path) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: WARNING! Maximum length of xkb base path exceeded.\n"); - #endif - } - - strcpy(_NXXkbBasePath, path); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbBasePath: Using default xkb base path [%s].\n", - _NXXkbBasePath); - #endif - - return _NXXkbBasePath; -} - -static int NXVerifyXkbCompPath(char *path) -{ - char *xkbCompPath; - int xkbCompPathSize; - struct stat xkbCompPathStat; - - if (path == NULL) - { - return 0; - } - - xkbCompPathSize = strlen(path) + strlen("/") + - strlen("xkbcomp") + 1; - - if ((xkbCompPath = malloc((xkbCompPathSize + 1) * sizeof(char))) == NULL) - { - FatalError("NXVerifyXkbCompPath: WARNING! malloc failed.\n"); - - return 0; - } - - strcpy(xkbCompPath, path); - strcat(xkbCompPath, "/"); - strcat(xkbCompPath, "xkbcomp"); - - if (stat(xkbCompPath, &xkbCompPathStat) != 0) - { - #ifdef NX_TRANS_TEST - fprintf(stderr, "NXVerifyXkbCompPath: WARNING! Failed to stat xkbcomp path [%s].\n", - xkbCompPath); - #endif - - free(xkbCompPath); - - return 0; - } - - free(xkbCompPath); - - return 1; -} - -/* - * This function returns the directory - * containing the xkbcomp executable. - * The function will first try to locate - * the executable in the hardcoded path - * (the same path as the "base" xkb one) - * and, if the xkbcomp file couldn't be - * found, the function will not include - * an explicit path and will rely on the - * PATH environment to list the directory. - */ - -char *_NXGetXkbCompPath(const char *path) -{ - - char * xkbCompPath; - - /* - * Check the xkbcomp executable - * directory only once. - */ - - if (*_NXXkbCompPath != '\0') - { - return _NXXkbCompPath; - } - - xkbCompPath = _NXGetXkbBasePath(path); - - if (NXVerifyXkbCompPath(xkbCompPath) == 1) - { - if (strlen(xkbCompPath) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbCompPath: WARNING! Maximum length of xkbcomp path exceeded.\n"); - #endif - - goto _NXGetXkbCompPathError; - } - - strcpy(_NXXkbCompPath, xkbCompPath); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbCompPath: Using xkbcomp path [%s].\n", - _NXXkbCompPath); - #endif - - return _NXXkbCompPath; - } - - xkbCompPath = NX_ALT_XKBCOMP_PATH; - - if (NXVerifyXkbCompPath(xkbCompPath) == 1) - { - if (strlen(xkbCompPath) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbCompPath: WARNING! Maximum length of xkbcomp path exceeded.\n"); - #endif - - goto _NXGetXkbCompPathError; - } - - strcpy(_NXXkbCompPath, xkbCompPath); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbCompPath: Using NX xkbcomp path [%s].\n", - _NXXkbCompPath); - #endif - - return _NXXkbCompPath; - } - -_NXGetXkbCompPathError: - - if (strlen(path) + 1 > PATH_MAX) - { - #ifdef TEST - fprintf(stderr, "_NXGetXkbCompPath: WARNING! Maximum length of xkbcomp path exceeded.\n"); - #endif - } - - strcpy(_NXXkbCompPath, path); - - #ifdef TEST - fprintf(stderr, "_NXGetXkbCompPath: Using default xkbcomp path [%s].\n", - _NXXkbCompPath); - #endif - - return _NXXkbCompPath; -} - -#endif - -static void -OutputDirectory( - char* outdir, - size_t size) -{ -#ifndef WIN32 - if (getuid() == 0 && (strlen(XKM_OUTPUT_DIR) < size) -#ifdef MAKE_XKM_OUTPUT_DIR - && (trans_mkdir(XKM_OUTPUT_DIR, XKM_OUTPUT_DIR_MODE) == 0) -#endif - ) - { - /* if server running as root it *may* be able to write */ - /* FIXME: check whether directory is writable at all */ - (void) strcpy (outdir, XKM_OUTPUT_DIR); - } else -#endif -#ifdef _PATH_VARTMP - if ((strlen(_PATH_VARTMP) + 1) < size) - { - (void) strcpy (outdir, _PATH_VARTMP); - if (outdir[strlen(outdir) - 1] != '/') /* Hi IBM, Digital */ - (void) strcat (outdir, "/"); - } else -#endif -#ifdef WIN32 - if (strlen(Win32TempDir()) + 1 < size) - { - (void) strcpy(outdir, Win32TempDir()); - (void) strcat(outdir, "\\"); - } else -#endif - if (strlen("/tmp/") < size) - { - (void) strcpy (outdir, "/tmp/"); - } -} - -Bool -XkbDDXCompileNamedKeymap( XkbDescPtr xkb, - XkbComponentNamesPtr names, - char * nameRtrn, - int nameRtrnLen) -{ -char *cmd = NULL,file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile; - - if (names->keymap==NULL) - return False; - strncpy(file,names->keymap,PATH_MAX); file[PATH_MAX-1]= '\0'; - if ((map= strrchr(file,'('))!=NULL) { - char *tmp; - if ((tmp= strrchr(map,')'))!=NULL) { - *map++= '\0'; - *tmp= '\0'; - } - else { - map= NULL; - } - } - if ((outFile= strrchr(file,'/'))!=NULL) - outFile= _XkbDupString(&outFile[1]); - else outFile= _XkbDupString(file); - XkbEnsureSafeMapName(outFile); - OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); - -#ifdef NXAGENT_SERVER - - if (_NXGetXkbCompPath(XkbBaseDirectory) != NULL) - { - -#else - - if (XkbBaseDirectory!=NULL) { - -#endif - -#ifndef __UNIXOS2__ - -#ifdef NXAGENT_SERVER - char *xkbbasedir = _NXGetXkbBasePath(XkbBaseDirectory); - char *xkbbindir = _NXGetXkbCompPath(XkbBinDirectory); -#else - char *xkbbasedir = XkbBaseDirectory; - char *xkbbindir = XkbBinDirectory; -#endif - -#else - /* relocate the basedir and replace the slashes with backslashes */ -#ifdef NXAGENT_SERVER - char *xkbbasedir = (char*)__XOS2RedirRoot(_NXGetXkbBasePath(XkbBaseDirectory)); - char *xkbbindir = (char*)__XOS2RedirRoot(_NXGetXkbCompPath(XkbBinDirectory)); -#else - char *xkbbasedir = (char*)__XOS2RedirRoot(XkbBaseDirectory); - char *xkbbindir = (char*)__XOS2RedirRoot(XkbBinDirectory); -#endif - int i; - - for (i=0; i10)?10:(int)xkbDebugFlags)), - xkbbasedir,(map?"-m ":""),(map?map:""), - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file, - xkm_output_dir,outFile); - } - else { - cmd = Xprintf("xkbcomp -w %d -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"", - ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), - (map?"-m ":""),(map?map:""), - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file, - xkm_output_dir,outFile); - } -#ifdef DEBUG - if (xkbDebugFlags) { - ErrorF("XkbDDXCompileNamedKeymap compiling keymap using:\n"); - ErrorF(" \"cmd\"\n"); - } -#endif -#ifdef DEBUG_CMD - ErrorF("xkb executes: %s\n",cmd); -#endif - if (System(cmd)==0) { - if (nameRtrn) { - strncpy(nameRtrn,outFile,nameRtrnLen); - nameRtrn[nameRtrnLen-1]= '\0'; - } - if (outFile!=NULL) - _XkbFree(outFile); - if (cmd!=NULL) - xfree(cmd); - return True; - } -#ifdef DEBUG - ErrorF("Error compiling keymap (%s)\n",names->keymap); -#endif - if (outFile!=NULL) - _XkbFree(outFile); - if (cmd!=NULL) - xfree(cmd); - return False; -} - -Bool -XkbDDXCompileKeymapByNames( XkbDescPtr xkb, - XkbComponentNamesPtr names, - unsigned want, - unsigned need, - char * nameRtrn, - int nameRtrnLen) -{ -FILE * out; -char *buf = NULL, keymap[PATH_MAX],xkm_output_dir[PATH_MAX]; - -#ifdef WIN32 -char tmpname[PATH_MAX]; -#endif - if ((names->keymap==NULL)||(names->keymap[0]=='\0')) { - sprintf(keymap,"server-%s",display); - } - else { - if (strlen(names->keymap) > PATH_MAX - 1) { - ErrorF("name of keymap (%s) exceeds max length\n", names->keymap); - return False; - } - strcpy(keymap,names->keymap); - } - - XkbEnsureSafeMapName(keymap); - OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); -#ifdef WIN32 - strcpy(tmpname, Win32TempDir()); - strcat(tmpname, "\\xkb_XXXXXX"); - (void) mktemp(tmpname); -#endif - -#ifdef NXAGENT_SERVER - if (_NXGetXkbCompPath(XkbBaseDirectory)!=NULL) { -#else - if (XkbBaseDirectory!=NULL) { -#endif - -#ifndef WIN32 - char *xkmfile = "-"; -#else - /* 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 *xkmfile = tmpname; -#endif -#ifndef __UNIXOS2__ -#ifdef NXAGENT_SERVER - char *xkbbasedir = _NXGetXkbBasePath(XkbBaseDirectory); - char *xkbbindir = _NXGetXkbCompPath(XkbBinDirectory); -#else - char *xkbbasedir = XkbBaseDirectory; - char *xkbbindir = XkbBinDirectory; -#endif -#else - int i; -#ifdef NXAGENT_SERVER - char *xkbbasedir = (char*)__XOS2RedirRoot(_NXGetXkbBasePath(XkbBaseDirectory)); - char *xkbbindir = (char*)__XOS2RedirRoot(_NXGetXkbCompPath(XkbBinDirectory)); -#else - char *xkbbasedir = (char*)__XOS2RedirRoot(XkbBaseDirectory); - char *xkbbindir = (char*)__XOS2RedirRoot(XkbBinDirectory); -#endif - for (i=0; i10)?10:(int)xkbDebugFlags)), - xkbbasedir, xkmfile, - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1, - xkm_output_dir,keymap); - } - else { -#ifndef WIN32 - char *xkmfile = "-"; -#else - char *xkmfile = tmpname; -#endif - buf = Xprintf( - "xkbcomp -w %d -xkm \"%s\" -em1 %s -emp %s -eml %s \"%s%s.xkm\"", - ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), - xkmfile, - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1, - xkm_output_dir,keymap); - } - - #ifdef TEST - if (buf != NULL) - fprintf(stderr, "XkbDDXCompileKeymapByNames: " - "Executing command [%s].\n", buf); - else - fprintf(stderr, "XkbDDXCompileKeymapByNames: " - "Callin Popen() with null command.\n"); - #endif - -#ifndef WIN32 - out= Popen(buf,"w"); -#else - out= fopen(tmpname, "w"); -#endif - - if (out!=NULL) { -#ifdef DEBUG - if (xkbDebugFlags) { - ErrorF("XkbDDXCompileKeymapByNames compiling keymap:\n"); - XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need); - } -#endif - XkbWriteXKBKeymapForNames(out,names,NULL,xkb,want,need); -#ifndef WIN32 -#ifdef __sun - if (Pclose(out) != 0) - { - ErrorF("Warning: Spurious failure reported in Pclose() runnning 'xkbcomp'.\n"); - } - if (1) -#else - if (Pclose(out)==0) -#endif -#else - if (fclose(out)==0 && System(buf) >= 0) -#endif - { -#ifdef DEBUG_CMD - ErrorF("xkb executes: %s\n",buf); - ErrorF("xkbcomp input:\n"); - XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need); - ErrorF("end xkbcomp input\n"); -#endif - if (nameRtrn) { - strncpy(nameRtrn,keymap,nameRtrnLen); - nameRtrn[nameRtrnLen-1]= '\0'; - } -#if defined(Lynx) && defined(__i386__) && defined(NEED_POPEN_WORKAROUND) - /* somehow popen/pclose is broken on LynxOS AT 2.3.0/2.4.0! - * the problem usually shows up with XF86Setup - * this hack waits at max 5 seconds after pclose() returns - * for the output of the xkbcomp output file. - * I didn't manage to get a patch in time for the 3.2 release - */ - { - int i; - char name[PATH_MAX]; -#ifdef NXAGENT_SERVER - if (_NXGetXkbCompPath(XkbBaseDirectory)!=NULL) - sprintf(name,"%s/%s%s.xkm", _NXGetXkbCompPath(XkbBaseDirectory) - ,xkm_output_dir, keymap); -#else - if (XkbBaseDirectory!=NULL) - sprintf(name,"%s/%s%s.xkm", XkbBaseDirectory - ,xkm_output_dir, keymap); -#endif - else - sprintf(name,"%s%s.xkm", xkm_output_dir, keymap); - for (i = 0; i < 10; i++) { - if (access(name, 0) == 0) break; - usleep(500000); - } -#ifdef DEBUG - if (i) ErrorF(">>>> Waited %d times for %s\n", i, name); -#endif - } -#endif - if (buf != NULL) - xfree (buf); - return True; - } -#ifdef DEBUG - else - ErrorF("Error compiling keymap (%s)\n",keymap); -#endif -#ifdef WIN32 - /* remove the temporary file */ - unlink(tmpname); -#endif - } -#ifdef DEBUG - else { -#ifndef WIN32 - ErrorF("Could not invoke keymap compiler\n"); -#else - ErrorF("Could not open file %s\n", tmpname); -#endif - } -#endif - if (nameRtrn) - nameRtrn[0]= '\0'; - if (buf != NULL) - xfree (buf); - return False; -} - -FILE * -XkbDDXOpenConfigFile(char *mapName,char *fileNameRtrn,int fileNameRtrnLen) -{ -char buf[PATH_MAX],xkm_output_dir[PATH_MAX]; -FILE * file; - - buf[0]= '\0'; - if (mapName!=NULL) { - OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); - if ((XkbBaseDirectory!=NULL)&&(xkm_output_dir[0]!='/') -#ifdef WIN32 - &&(!isalpha(xkm_output_dir[0]) || xkm_output_dir[1]!=':') -#endif - ) { - if (strlen(XkbBaseDirectory)+strlen(xkm_output_dir) - +strlen(mapName)+6 <= PATH_MAX) - { - sprintf(buf,"%s/%s%s.xkm",XkbBaseDirectory, - xkm_output_dir,mapName); - } - } - else if (strlen(xkm_output_dir)+strlen(mapName)+5 <= PATH_MAX) - sprintf(buf,"%s%s.xkm",xkm_output_dir,mapName); - if (buf[0] != '\0') - file= fopen(buf,"rb"); - else file= NULL; - } - else file= NULL; - if ((fileNameRtrn!=NULL)&&(fileNameRtrnLen>0)) { - strncpy(fileNameRtrn,buf,fileNameRtrnLen); - buf[fileNameRtrnLen-1]= '\0'; - } - return file; -} - -unsigned -XkbDDXLoadKeymapByNames( DeviceIntPtr keybd, - XkbComponentNamesPtr names, - unsigned want, - unsigned need, - XkbFileInfo * finfoRtrn, - char * nameRtrn, - int nameRtrnLen) -{ -XkbDescPtr xkb; -FILE * file; -char fileName[PATH_MAX]; -unsigned missing; - - bzero(finfoRtrn,sizeof(XkbFileInfo)); - if ((keybd==NULL)||(keybd->key==NULL)||(keybd->key->xkbInfo==NULL)) - xkb= NULL; - else xkb= keybd->key->xkbInfo->desc; - if ((names->keycodes==NULL)&&(names->types==NULL)&& - (names->compat==NULL)&&(names->symbols==NULL)&& - (names->geometry==NULL)) { - if (names->keymap==NULL) { - bzero(finfoRtrn,sizeof(XkbFileInfo)); - if (xkb && XkbDetermineFileType(finfoRtrn,XkbXKMFile,NULL) && - ((finfoRtrn->defined&need)==need) ) { - finfoRtrn->xkb= xkb; - nameRtrn[0]= '\0'; - return finfoRtrn->defined; - } - return 0; - } - else if (!XkbDDXCompileNamedKeymap(xkb,names,nameRtrn,nameRtrnLen)) { -#ifdef NOISY - ErrorF("Couldn't compile keymap file\n"); -#endif - return 0; - } - } - else if (!XkbDDXCompileKeymapByNames(xkb,names,want,need, - nameRtrn,nameRtrnLen)){ -#ifdef NOISY - ErrorF("Couldn't compile keymap file\n"); -#endif - return 0; - } - file= XkbDDXOpenConfigFile(nameRtrn,fileName,PATH_MAX); - if (file==NULL) { - LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",fileName); - return 0; - } - missing= XkmReadFile(file,need,want,finfoRtrn); - if (finfoRtrn->xkb==NULL) { - LogMessage(X_ERROR, "Error loading keymap %s\n",fileName); - fclose(file); - (void) unlink (fileName); - return 0; - } -#ifdef DEBUG - else if (xkbDebugFlags) { - ErrorF("Loaded %s, defined=0x%x\n",fileName,finfoRtrn->defined); - } -#endif - fclose(file); - (void) unlink (fileName); - return (need|want)&(~missing); -} - -Bool -XkbDDXNamesFromRules( DeviceIntPtr keybd, - char * rules_name, - XkbRF_VarDefsPtr defs, - XkbComponentNamesPtr names) -{ -char buf[PATH_MAX]; -FILE * file; -Bool complete; -XkbRF_RulesPtr rules; - - if (!rules_name) - return False; - if (XkbBaseDirectory==NULL) { - if (strlen(rules_name)+7 > PATH_MAX) - return False; - sprintf(buf,"rules/%s",rules_name); - } - else { - if (strlen(XkbBaseDirectory)+strlen(rules_name)+8 > PATH_MAX) - return False; - sprintf(buf,"%s/rules/%s",XkbBaseDirectory,rules_name); - } - if ((file= fopen(buf,"r"))==NULL) - return False; - if ((rules= XkbRF_Create(0,0))==NULL) { - fclose(file); - return False; - } - if (!XkbRF_LoadRules(file,rules)) { - fclose(file); - XkbRF_Free(rules,True); - return False; - } - bzero((char *)names,sizeof(XkbComponentNamesRec)); - complete= XkbRF_GetComponents(rules,defs,names); - fclose(file); - XkbRF_Free(rules,True); - return complete; -} - - diff --git a/nx-X11/programs/Xserver/xkb/ddxLoad.c.X.original b/nx-X11/programs/Xserver/xkb/ddxLoad.c.X.original deleted file mode 100644 index e355b1796..000000000 --- a/nx-X11/programs/Xserver/xkb/ddxLoad.c.X.original +++ /dev/null @@ -1,604 +0,0 @@ -/* $Xorg: ddxLoad.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */ -/************************************************************ -Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. - -Permission to use, copy, modify, and distribute this -software and its documentation for any purpose and without -fee is hereby granted, provided that the above copyright -notice appear in all copies and that both that copyright -notice and this permission notice appear in supporting -documentation, and that the name of Silicon Graphics not be -used in advertising or publicity pertaining to distribution -of the software without specific prior written permission. -Silicon Graphics makes no representation about the suitability -of this software for any purpose. It is provided "as is" -without any express or implied warranty. - -SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON -GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH -THE USE OR PERFORMANCE OF THIS SOFTWARE. - -********************************************************/ -/* $XFree86: xc/programs/Xserver/xkb/ddxLoad.c,v 3.35 2003/10/02 13:30:12 eich Exp $ */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XKB_CONFIG_H -#include -#endif - -#include -#include -#define NEED_EVENTS 1 -#include -#include -#include -#include -#include -#include "inputstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#define XKBSRV_NEED_FILE_FUNCS -#include -#include -#include "xkb.h" - -#if defined(CSRG_BASED) || defined(linux) || defined(__sgi) || defined(AIXV3) || defined(__osf__) || defined(__GNU__) -#include -#endif - -#ifndef PATH_MAX -#ifdef MAXPATHLEN -#define PATH_MAX MAXPATHLEN -#else -#define PATH_MAX 1024 -#endif -#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\"" -#define POST_ERROR_MSG2 "\"End of messages from xkbcomp\"" - -#if defined(__UNIXOS2__) || defined(WIN32) -#define PATHSEPARATOR "\\" -#else -#define PATHSEPARATOR "/" -#endif - -#ifdef WIN32 - -#include -const char* -Win32TempDir() -{ - static char buffer[PATH_MAX]; - if (GetTempPath(sizeof(buffer), buffer)) - { - int len; - buffer[sizeof(buffer)-1] = 0; - len = strlen(buffer); - if (len > 0) - if (buffer[len-1] == '\\') - buffer[len-1] = 0; - return buffer; - } - if (getenv("TEMP") != NULL) - return getenv("TEMP"); - else if (getenv("TMP") != NULL) - return getenv("TEMP"); - else - return "/tmp"; -} - -int -Win32System(const char *cmdline) -{ - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD dwExitCode; - char *cmd = xstrdup(cmdline); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) - { - LPVOID buffer; - if (!FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &buffer, - 0, - NULL )) - { - ErrorF("Starting '%s' failed!\n", cmdline); - } - else - { - ErrorF("Starting '%s' failed: %s", cmdline, (char *)buffer); - LocalFree(buffer); - } - - xfree(cmd); - return -1; - } - /* Wait until child process exits. */ - WaitForSingleObject( pi.hProcess, INFINITE ); - - GetExitCodeProcess( pi.hProcess, &dwExitCode); - - /* Close process and thread handles. */ - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - xfree(cmd); - - return dwExitCode; -} -#undef System -#define System(x) Win32System(x) -#endif - -#ifdef MAKE_XKM_OUTPUT_DIR -/* Borrow trans_mkdir from Xtransutil.c to more safely make directories */ -# undef X11_t -# define TRANS_SERVER -# define PRMSG(lvl,x,a,b,c) \ - if (lvl <= 1) { LogMessage(X_ERROR,x,a,b,c); } else ((void)0) -# include -# ifndef XKM_OUTPUT_DIR_MODE -# define XKM_OUTPUT_DIR_MODE 0755 -# endif -#endif - -static void -OutputDirectory( - char* outdir, - size_t size) -{ -#ifndef WIN32 - if (getuid() == 0 && (strlen(XKM_OUTPUT_DIR) < size) -#ifdef MAKE_XKM_OUTPUT_DIR - && (trans_mkdir(XKM_OUTPUT_DIR, XKM_OUTPUT_DIR_MODE) == 0) -#endif - ) - { - /* if server running as root it *may* be able to write */ - /* FIXME: check whether directory is writable at all */ - (void) strcpy (outdir, XKM_OUTPUT_DIR); - } else -#endif -#ifdef _PATH_VARTMP - if ((strlen(_PATH_VARTMP) + 1) < size) - { - (void) strcpy (outdir, _PATH_VARTMP); - if (outdir[strlen(outdir) - 1] != '/') /* Hi IBM, Digital */ - (void) strcat (outdir, "/"); - } else -#endif -#ifdef WIN32 - if (strlen(Win32TempDir()) + 1 < size) - { - (void) strcpy(outdir, Win32TempDir()); - (void) strcat(outdir, "\\"); - } else -#endif - if (strlen("/tmp/") < size) - { - (void) strcpy (outdir, "/tmp/"); - } -} - -Bool -XkbDDXCompileNamedKeymap( XkbDescPtr xkb, - XkbComponentNamesPtr names, - char * nameRtrn, - int nameRtrnLen) -{ -char *cmd = NULL,file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile; - - if (names->keymap==NULL) - return False; - strncpy(file,names->keymap,PATH_MAX); file[PATH_MAX-1]= '\0'; - if ((map= strrchr(file,'('))!=NULL) { - char *tmp; - if ((tmp= strrchr(map,')'))!=NULL) { - *map++= '\0'; - *tmp= '\0'; - } - else { - map= NULL; - } - } - if ((outFile= strrchr(file,'/'))!=NULL) - outFile= _XkbDupString(&outFile[1]); - else outFile= _XkbDupString(file); - XkbEnsureSafeMapName(outFile); - OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); - - if (XkbBaseDirectory!=NULL) { -#ifndef __UNIXOS2__ - char *xkbbasedir = XkbBaseDirectory; - char *xkbbindir = XkbBinDirectory; -#else - /* relocate the basedir and replace the slashes with backslashes */ - char *xkbbasedir = (char*)__XOS2RedirRoot(XkbBaseDirectory); - char *xkbbindir = (char*)__XOS2RedirRoot(XkbBinDirectory); - int i; - - for (i=0; i10)?10:(int)xkbDebugFlags)), - xkbbasedir,(map?"-m ":""),(map?map:""), - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file, - xkm_output_dir,outFile); - } - else { - cmd = Xprintf("xkbcomp -w %d -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"", - ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), - (map?"-m ":""),(map?map:""), - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file, - xkm_output_dir,outFile); - } -#ifdef DEBUG - if (xkbDebugFlags) { - ErrorF("XkbDDXCompileNamedKeymap compiling keymap using:\n"); - ErrorF(" \"cmd\"\n"); - } -#endif -#ifdef DEBUG_CMD - ErrorF("xkb executes: %s\n",cmd); -#endif - if (System(cmd)==0) { - if (nameRtrn) { - strncpy(nameRtrn,outFile,nameRtrnLen); - nameRtrn[nameRtrnLen-1]= '\0'; - } - if (outFile!=NULL) - _XkbFree(outFile); - if (cmd!=NULL) - xfree(cmd); - return True; - } -#ifdef DEBUG - ErrorF("Error compiling keymap (%s)\n",names->keymap); -#endif - if (outFile!=NULL) - _XkbFree(outFile); - if (cmd!=NULL) - xfree(cmd); - return False; -} - -Bool -XkbDDXCompileKeymapByNames( XkbDescPtr xkb, - XkbComponentNamesPtr names, - unsigned want, - unsigned need, - char * nameRtrn, - int nameRtrnLen) -{ -FILE * out; -char *buf = NULL, keymap[PATH_MAX],xkm_output_dir[PATH_MAX]; - -#ifdef WIN32 -char tmpname[PATH_MAX]; -#endif - if ((names->keymap==NULL)||(names->keymap[0]=='\0')) { - sprintf(keymap,"server-%s",display); - } - else { - if (strlen(names->keymap) > PATH_MAX - 1) { - ErrorF("name of keymap (%s) exceeds max length\n", names->keymap); - return False; - } - strcpy(keymap,names->keymap); - } - - XkbEnsureSafeMapName(keymap); - OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); -#ifdef WIN32 - strcpy(tmpname, Win32TempDir()); - strcat(tmpname, "\\xkb_XXXXXX"); - (void) mktemp(tmpname); -#endif - if (XkbBaseDirectory!=NULL) { -#ifndef WIN32 - char *xkmfile = "-"; -#else - /* 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 *xkmfile = tmpname; -#endif -#ifndef __UNIXOS2__ - char *xkbbasedir = XkbBaseDirectory; - char *xkbbindir = XkbBinDirectory; -#else - int i; - char *xkbbasedir = (char*)__XOS2RedirRoot(XkbBaseDirectory); - char *xkbbindir = (char*)__XOS2RedirRoot(XkbBinDirectory); - for (i=0; i10)?10:(int)xkbDebugFlags)), - xkbbasedir, xkmfile, - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1, - xkm_output_dir,keymap); - } - else { -#ifndef WIN32 - char *xkmfile = "-"; -#else - char *xkmfile = tmpname; -#endif - buf = Xprintf( - "xkbcomp -w %d -xkm \"%s\" -em1 %s -emp %s -eml %s \"%s%s.xkm\"", - ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), - xkmfile, - PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1, - xkm_output_dir,keymap); - } - -#ifndef WIN32 - out= Popen(buf,"w"); -#else - out= fopen(tmpname, "w"); -#endif - - if (out!=NULL) { -#ifdef DEBUG - if (xkbDebugFlags) { - ErrorF("XkbDDXCompileKeymapByNames compiling keymap:\n"); - XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need); - } -#endif - XkbWriteXKBKeymapForNames(out,names,NULL,xkb,want,need); -#ifndef WIN32 - if (Pclose(out)==0) -#else - if (fclose(out)==0 && System(buf) >= 0) -#endif - { -#ifdef DEBUG_CMD - ErrorF("xkb executes: %s\n",buf); - ErrorF("xkbcomp input:\n"); - XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need); - ErrorF("end xkbcomp input\n"); -#endif - if (nameRtrn) { - strncpy(nameRtrn,keymap,nameRtrnLen); - nameRtrn[nameRtrnLen-1]= '\0'; - } -#if defined(Lynx) && defined(__i386__) && defined(NEED_POPEN_WORKAROUND) - /* somehow popen/pclose is broken on LynxOS AT 2.3.0/2.4.0! - * the problem usually shows up with XF86Setup - * this hack waits at max 5 seconds after pclose() returns - * for the output of the xkbcomp output file. - * I didn't manage to get a patch in time for the 3.2 release - */ - { - int i; - char name[PATH_MAX]; - if (XkbBaseDirectory!=NULL) - sprintf(name,"%s/%s%s.xkm", XkbBaseDirectory - ,xkm_output_dir, keymap); - else - sprintf(name,"%s%s.xkm", xkm_output_dir, keymap); - for (i = 0; i < 10; i++) { - if (access(name, 0) == 0) break; - usleep(500000); - } -#ifdef DEBUG - if (i) ErrorF(">>>> Waited %d times for %s\n", i, name); -#endif - } -#endif - if (buf != NULL) - xfree (buf); - return True; - } -#ifdef DEBUG - else - ErrorF("Error compiling keymap (%s)\n",keymap); -#endif -#ifdef WIN32 - /* remove the temporary file */ - unlink(tmpname); -#endif - } -#ifdef DEBUG - else { -#ifndef WIN32 - ErrorF("Could not invoke keymap compiler\n"); -#else - ErrorF("Could not open file %s\n", tmpname); -#endif - } -#endif - if (nameRtrn) - nameRtrn[0]= '\0'; - if (buf != NULL) - xfree (buf); - return False; -} - -FILE * -XkbDDXOpenConfigFile(char *mapName,char *fileNameRtrn,int fileNameRtrnLen) -{ -char buf[PATH_MAX],xkm_output_dir[PATH_MAX]; -FILE * file; - - buf[0]= '\0'; - if (mapName!=NULL) { - OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); - if ((XkbBaseDirectory!=NULL)&&(xkm_output_dir[0]!='/') -#ifdef WIN32 - &&(!isalpha(xkm_output_dir[0]) || xkm_output_dir[1]!=':') -#endif - ) { - if (strlen(XkbBaseDirectory)+strlen(xkm_output_dir) - +strlen(mapName)+6 <= PATH_MAX) - { - sprintf(buf,"%s/%s%s.xkm",XkbBaseDirectory, - xkm_output_dir,mapName); - } - } - else if (strlen(xkm_output_dir)+strlen(mapName)+5 <= PATH_MAX) - sprintf(buf,"%s%s.xkm",xkm_output_dir,mapName); - if (buf[0] != '\0') - file= fopen(buf,"rb"); - else file= NULL; - } - else file= NULL; - if ((fileNameRtrn!=NULL)&&(fileNameRtrnLen>0)) { - strncpy(fileNameRtrn,buf,fileNameRtrnLen); - buf[fileNameRtrnLen-1]= '\0'; - } - return file; -} - -unsigned -XkbDDXLoadKeymapByNames( DeviceIntPtr keybd, - XkbComponentNamesPtr names, - unsigned want, - unsigned need, - XkbFileInfo * finfoRtrn, - char * nameRtrn, - int nameRtrnLen) -{ -XkbDescPtr xkb; -FILE * file; -char fileName[PATH_MAX]; -unsigned missing; - - bzero(finfoRtrn,sizeof(XkbFileInfo)); - if ((keybd==NULL)||(keybd->key==NULL)||(keybd->key->xkbInfo==NULL)) - xkb= NULL; - else xkb= keybd->key->xkbInfo->desc; - if ((names->keycodes==NULL)&&(names->types==NULL)&& - (names->compat==NULL)&&(names->symbols==NULL)&& - (names->geometry==NULL)) { - if (names->keymap==NULL) { - bzero(finfoRtrn,sizeof(XkbFileInfo)); - if (xkb && XkbDetermineFileType(finfoRtrn,XkbXKMFile,NULL) && - ((finfoRtrn->defined&need)==need) ) { - finfoRtrn->xkb= xkb; - nameRtrn[0]= '\0'; - return finfoRtrn->defined; - } - return 0; - } - else if (!XkbDDXCompileNamedKeymap(xkb,names,nameRtrn,nameRtrnLen)) { -#ifdef NOISY - ErrorF("Couldn't compile keymap file\n"); -#endif - return 0; - } - } - else if (!XkbDDXCompileKeymapByNames(xkb,names,want,need, - nameRtrn,nameRtrnLen)){ -#ifdef NOISY - ErrorF("Couldn't compile keymap file\n"); -#endif - return 0; - } - file= XkbDDXOpenConfigFile(nameRtrn,fileName,PATH_MAX); - if (file==NULL) { - LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",fileName); - return 0; - } - missing= XkmReadFile(file,need,want,finfoRtrn); - if (finfoRtrn->xkb==NULL) { - LogMessage(X_ERROR, "Error loading keymap %s\n",fileName); - fclose(file); - (void) unlink (fileName); - return 0; - } -#ifdef DEBUG - else if (xkbDebugFlags) { - ErrorF("Loaded %s, defined=0x%x\n",fileName,finfoRtrn->defined); - } -#endif - fclose(file); - (void) unlink (fileName); - return (need|want)&(~missing); -} - -Bool -XkbDDXNamesFromRules( DeviceIntPtr keybd, - char * rules_name, - XkbRF_VarDefsPtr defs, - XkbComponentNamesPtr names) -{ -char buf[PATH_MAX]; -FILE * file; -Bool complete; -XkbRF_RulesPtr rules; - - if (!rules_name) - return False; - if (XkbBaseDirectory==NULL) { - if (strlen(rules_name)+7 > PATH_MAX) - return False; - sprintf(buf,"rules/%s",rules_name); - } - else { - if (strlen(XkbBaseDirectory)+strlen(rules_name)+8 > PATH_MAX) - return False; - sprintf(buf,"%s/rules/%s",XkbBaseDirectory,rules_name); - } - if ((file= fopen(buf,"r"))==NULL) - return False; - if ((rules= XkbRF_Create(0,0))==NULL) { - fclose(file); - return False; - } - if (!XkbRF_LoadRules(file,rules)) { - fclose(file); - XkbRF_Free(rules,True); - return False; - } - bzero((char *)names,sizeof(XkbComponentNamesRec)); - complete= XkbRF_GetComponents(rules,defs,names); - fclose(file); - XkbRF_Free(rules,True); - return complete; -} - - diff --git a/nx-X11/programs/Xserver/xkb/xkbDflts.h.NX.original b/nx-X11/programs/Xserver/xkb/xkbDflts.h.NX.original deleted file mode 100644 index e0b54c55b..000000000 --- a/nx-X11/programs/Xserver/xkb/xkbDflts.h.NX.original +++ /dev/null @@ -1,524 +0,0 @@ -/* $Xorg: xkbDflts.h,v 1.3 2000/08/17 19:53:47 cpqbld Exp $ */ -/* $XFree86: xc/programs/Xserver/xkb/xkbDflts.h,v 1.2 2001/10/28 03:34:20 tsi Exp $ */ -/* This file generated automatically by xkbcomp */ -/* DO NOT EDIT */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifndef DEFAULT_H -#define DEFAULT_H 1 - -#ifndef XKB_IN_SERVER -#define GET_ATOM(d,s) XInternAtom(d,s,0) -#define DPYTYPE Display * -#else -#define GET_ATOM(d,s) MakeAtom(s,strlen(s),1) -#define DPYTYPE char * -#endif -#define NUM_KEYS 1 - -#define vmod_NumLock 0 -#define vmod_Alt 1 -#define vmod_LevelThree 2 -#define vmod_AltGr 3 -#define vmod_ScrollLock 4 - -#define vmod_NumLockMask (1<<0) -#define vmod_AltMask (1<<1) -#define vmod_LevelThreeMask (1<<2) -#define vmod_AltGrMask (1<<3) -#define vmod_ScrollLockMask (1<<4) - -/* types name is "default" */ -static Atom lnames_ONE_LEVEL[1]; - -static XkbKTMapEntryRec map_TWO_LEVEL[1]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } } -}; -static Atom lnames_TWO_LEVEL[2]; - -static XkbKTMapEntryRec map_ALPHABETIC[2]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } }, - { 1, 0, { LockMask, LockMask, 0 } } -}; -static XkbModsRec preserve_ALPHABETIC[2]= { - { 0, 0, 0 }, - { LockMask, LockMask, 0 } -}; -static Atom lnames_ALPHABETIC[2]; - -static XkbKTMapEntryRec map_KEYPAD[2]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } }, - { 0, 1, { 0, 0, vmod_NumLockMask } } -}; -static Atom lnames_KEYPAD[2]; - -static XkbKTMapEntryRec map_PC_BREAK[1]= { - { 1, 1, { ControlMask, ControlMask, 0 } } -}; -static Atom lnames_PC_BREAK[2]; - -static XkbKTMapEntryRec map_PC_SYSRQ[1]= { - { 0, 1, { 0, 0, vmod_AltMask } } -}; -static Atom lnames_PC_SYSRQ[2]; - -static XkbKTMapEntryRec map_CTRL_ALT[1]= { - { 0, 1, { ControlMask, ControlMask, vmod_AltMask } } -}; -static Atom lnames_CTRL_ALT[2]; - -static XkbKTMapEntryRec map_THREE_LEVEL[3]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } }, - { 0, 2, { 0, 0, vmod_LevelThreeMask } }, - { 0, 2, { ShiftMask, ShiftMask, vmod_LevelThreeMask } } -}; -static Atom lnames_THREE_LEVEL[3]; - -static XkbKTMapEntryRec map_SHIFT_ALT[1]= { - { 0, 1, { ShiftMask, ShiftMask, vmod_AltMask } } -}; -static Atom lnames_SHIFT_ALT[2]; - -static XkbKeyTypeRec dflt_types[]= { - { - { 0, 0, 0 }, - 1, - 0, NULL, NULL, - None, lnames_ONE_LEVEL - }, - { - { ShiftMask, ShiftMask, 0 }, - 2, - 1, map_TWO_LEVEL, NULL, - None, lnames_TWO_LEVEL - }, - { - { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, - 2, - 2, map_ALPHABETIC, preserve_ALPHABETIC, - None, lnames_ALPHABETIC - }, - { - { ShiftMask, ShiftMask, vmod_NumLockMask }, - 2, - 2, map_KEYPAD, NULL, - None, lnames_KEYPAD - }, - { - { ControlMask, ControlMask, 0 }, - 2, - 1, map_PC_BREAK, NULL, - None, lnames_PC_BREAK - }, - { - { 0, 0, vmod_AltMask }, - 2, - 1, map_PC_SYSRQ, NULL, - None, lnames_PC_SYSRQ - }, - { - { ControlMask, ControlMask, vmod_AltMask }, - 2, - 1, map_CTRL_ALT, NULL, - None, lnames_CTRL_ALT - }, - { - { ShiftMask, ShiftMask, vmod_LevelThreeMask }, - 3, - 3, map_THREE_LEVEL, NULL, - None, lnames_THREE_LEVEL - }, - { - { ShiftMask, ShiftMask, vmod_AltMask }, - 2, - 1, map_SHIFT_ALT, NULL, - None, lnames_SHIFT_ALT - } -}; -#define num_dflt_types (sizeof(dflt_types)/sizeof(XkbKeyTypeRec)) - - -static void -initTypeNames(DPYTYPE dpy) -{ - dflt_types[0].name= GET_ATOM(dpy,"ONE_LEVEL"); - lnames_ONE_LEVEL[0]= GET_ATOM(dpy,"Any"); - dflt_types[1].name= GET_ATOM(dpy,"TWO_LEVEL"); - lnames_TWO_LEVEL[0]= GET_ATOM(dpy,"Base"); - lnames_TWO_LEVEL[1]= GET_ATOM(dpy,"Shift"); - dflt_types[2].name= GET_ATOM(dpy,"ALPHABETIC"); - lnames_ALPHABETIC[0]= GET_ATOM(dpy,"Base"); - lnames_ALPHABETIC[1]= GET_ATOM(dpy,"Caps"); - dflt_types[3].name= GET_ATOM(dpy,"KEYPAD"); - lnames_KEYPAD[0]= GET_ATOM(dpy,"Base"); - lnames_KEYPAD[1]= GET_ATOM(dpy,"Number"); - dflt_types[4].name= GET_ATOM(dpy,"PC_BREAK"); - lnames_PC_BREAK[0]= GET_ATOM(dpy,"Base"); - lnames_PC_BREAK[1]= GET_ATOM(dpy,"Control"); - dflt_types[5].name= GET_ATOM(dpy,"PC_SYSRQ"); - lnames_PC_SYSRQ[0]= GET_ATOM(dpy,"Base"); - lnames_PC_SYSRQ[1]= GET_ATOM(dpy,"Alt"); - dflt_types[6].name= GET_ATOM(dpy,"CTRL+ALT"); - lnames_CTRL_ALT[0]= GET_ATOM(dpy,"Base"); - lnames_CTRL_ALT[1]= GET_ATOM(dpy,"Ctrl+Alt"); - dflt_types[7].name= GET_ATOM(dpy,"THREE_LEVEL"); - lnames_THREE_LEVEL[0]= GET_ATOM(dpy,"Base"); - lnames_THREE_LEVEL[1]= GET_ATOM(dpy,"Shift"); - lnames_THREE_LEVEL[2]= GET_ATOM(dpy,"Level3"); - dflt_types[8].name= GET_ATOM(dpy,"SHIFT+ALT"); - lnames_SHIFT_ALT[0]= GET_ATOM(dpy,"Base"); - lnames_SHIFT_ALT[1]= GET_ATOM(dpy,"Shift+Alt"); -} -/* compat name is "default" */ -static XkbSymInterpretRec dfltSI[69]= { - { XK_ISO_Level2_Latch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_Exactly, ShiftMask, - 255, - { XkbSA_LatchMods, { 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Eisu_Shift, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Eisu_toggle, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Kana_Shift, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Kana_Lock, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Shift_Lock, 0x0000, - XkbSI_AnyOf, ShiftMask|LockMask, - 255, - { XkbSA_LockMods, { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Num_Lock, 0x0000, - XkbSI_AnyOf, 0xff, - 0, - { XkbSA_LockMods, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_Alt_L, 0x0000, - XkbSI_AnyOf, 0xff, - 1, - { XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Alt_R, 0x0000, - XkbSI_AnyOf, 0xff, - 1, - { XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Scroll_Lock, 0x0000, - XkbSI_AnyOf, 0xff, - 4, - { XkbSA_LockMods, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Lock, 0x0000, - XkbSI_AnyOf, 0xff, - 255, - { XkbSA_ISOLock, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Level3_Shift, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOf, 0xff, - 2, - { XkbSA_SetMods, { 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 } } }, - { XK_ISO_Level3_Latch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOf, 0xff, - 2, - { XkbSA_LatchMods, { 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 } } }, - { XK_Mode_switch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_SetGroup, { 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_1, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_End, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_2, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_Down, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_3, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_Next, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_4, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Left, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_6, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Right, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_7, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_Home, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_8, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_Up, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_9, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_Prior, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_5, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Begin, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_F1, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Divide, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_F2, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Multiply, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_F3, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Subtract, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Separator, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Add, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_0, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Insert, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Decimal, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Delete, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button_Dflt, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button1, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button2, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button3, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick_Dflt, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick1, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick2, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick3, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag_Dflt, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag1, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag2, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag3, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_EnableKeys, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00 } } }, - { XK_Pointer_Accelerate, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00 } } }, - { XK_Pointer_DfltBtnNext, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DfltBtnPrev, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_AccessX_Enable, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 } } }, - -#ifndef NX_TRANS_SOCKET - - /* - * Make sure that the server can't be killed - * by pressing this key-sequence. - */ - - { XK_Terminate_Server, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_Terminate, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - -#endif - - { XK_ISO_Group_Latch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_LatchGroup, { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Next_Group, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_LockGroup, { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Prev_Group, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_LockGroup, { 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_First_Group, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockGroup, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Last_Group, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockGroup, { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { NoSymbol, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_LockMods, { 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { NoSymbol, 0x0000, - XkbSI_AnyOf, 0xff, - 255, - { XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } -}; -#define num_dfltSI (sizeof(dfltSI)/sizeof(XkbSymInterpretRec)) - -static XkbCompatMapRec compatMap= { - dfltSI, - { /* group compatibility */ - { 0, 0, 0 }, - { 0, 0, vmod_AltGrMask }, - { 0, 0, vmod_AltGrMask }, - { 0, 0, vmod_AltGrMask } - }, - num_dfltSI, num_dfltSI -}; - -static XkbIndicatorRec indicators= { - 0x0, - { - { 0x80, 0, 0x00, XkbIM_UseEffective, { LockMask, LockMask, 0 }, 0 }, - { 0x80, 0, 0x00, XkbIM_UseEffective, { 0, 0, vmod_NumLockMask }, 0 }, - { 0x80, 0, 0x00, XkbIM_UseLocked, { ShiftMask, ShiftMask, 0 }, 0 }, - { 0x80, 0, 0x00, 0, { 0, 0, 0 }, XkbMouseKeysMask }, - { 0x80, 0, 0x00, XkbIM_UseLocked, { 0, 0, vmod_ScrollLockMask }, 0 }, - { 0x80, XkbIM_UseEffective, 0xfe, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 } - } -}; -static void -initIndicatorNames(DPYTYPE dpy,XkbDescPtr xkb) -{ - xkb->names->indicators[ 0]= GET_ATOM(dpy,"Caps Lock"); - xkb->names->indicators[ 1]= GET_ATOM(dpy,"Num Lock"); - xkb->names->indicators[ 2]= GET_ATOM(dpy,"Shift Lock"); - xkb->names->indicators[ 3]= GET_ATOM(dpy,"Mouse Keys"); - xkb->names->indicators[ 4]= GET_ATOM(dpy,"Scroll Lock"); - xkb->names->indicators[ 5]= GET_ATOM(dpy,"Group 2"); -} -#endif /* DEFAULT_H */ diff --git a/nx-X11/programs/Xserver/xkb/xkbDflts.h.X.original b/nx-X11/programs/Xserver/xkb/xkbDflts.h.X.original deleted file mode 100644 index e3dd9cdda..000000000 --- a/nx-X11/programs/Xserver/xkb/xkbDflts.h.X.original +++ /dev/null @@ -1,513 +0,0 @@ -/* $Xorg: xkbDflts.h,v 1.3 2000/08/17 19:53:47 cpqbld Exp $ */ -/* $XFree86: xc/programs/Xserver/xkb/xkbDflts.h,v 1.2 2001/10/28 03:34:20 tsi Exp $ */ -/* This file generated automatically by xkbcomp */ -/* DO NOT EDIT */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifndef DEFAULT_H -#define DEFAULT_H 1 - -#ifndef XKB_IN_SERVER -#define GET_ATOM(d,s) XInternAtom(d,s,0) -#define DPYTYPE Display * -#else -#define GET_ATOM(d,s) MakeAtom(s,strlen(s),1) -#define DPYTYPE char * -#endif -#define NUM_KEYS 1 - -#define vmod_NumLock 0 -#define vmod_Alt 1 -#define vmod_LevelThree 2 -#define vmod_AltGr 3 -#define vmod_ScrollLock 4 - -#define vmod_NumLockMask (1<<0) -#define vmod_AltMask (1<<1) -#define vmod_LevelThreeMask (1<<2) -#define vmod_AltGrMask (1<<3) -#define vmod_ScrollLockMask (1<<4) - -/* types name is "default" */ -static Atom lnames_ONE_LEVEL[1]; - -static XkbKTMapEntryRec map_TWO_LEVEL[1]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } } -}; -static Atom lnames_TWO_LEVEL[2]; - -static XkbKTMapEntryRec map_ALPHABETIC[2]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } }, - { 1, 0, { LockMask, LockMask, 0 } } -}; -static XkbModsRec preserve_ALPHABETIC[2]= { - { 0, 0, 0 }, - { LockMask, LockMask, 0 } -}; -static Atom lnames_ALPHABETIC[2]; - -static XkbKTMapEntryRec map_KEYPAD[2]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } }, - { 0, 1, { 0, 0, vmod_NumLockMask } } -}; -static Atom lnames_KEYPAD[2]; - -static XkbKTMapEntryRec map_PC_BREAK[1]= { - { 1, 1, { ControlMask, ControlMask, 0 } } -}; -static Atom lnames_PC_BREAK[2]; - -static XkbKTMapEntryRec map_PC_SYSRQ[1]= { - { 0, 1, { 0, 0, vmod_AltMask } } -}; -static Atom lnames_PC_SYSRQ[2]; - -static XkbKTMapEntryRec map_CTRL_ALT[1]= { - { 0, 1, { ControlMask, ControlMask, vmod_AltMask } } -}; -static Atom lnames_CTRL_ALT[2]; - -static XkbKTMapEntryRec map_THREE_LEVEL[3]= { - { 1, 1, { ShiftMask, ShiftMask, 0 } }, - { 0, 2, { 0, 0, vmod_LevelThreeMask } }, - { 0, 2, { ShiftMask, ShiftMask, vmod_LevelThreeMask } } -}; -static Atom lnames_THREE_LEVEL[3]; - -static XkbKTMapEntryRec map_SHIFT_ALT[1]= { - { 0, 1, { ShiftMask, ShiftMask, vmod_AltMask } } -}; -static Atom lnames_SHIFT_ALT[2]; - -static XkbKeyTypeRec dflt_types[]= { - { - { 0, 0, 0 }, - 1, - 0, NULL, NULL, - None, lnames_ONE_LEVEL - }, - { - { ShiftMask, ShiftMask, 0 }, - 2, - 1, map_TWO_LEVEL, NULL, - None, lnames_TWO_LEVEL - }, - { - { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, - 2, - 2, map_ALPHABETIC, preserve_ALPHABETIC, - None, lnames_ALPHABETIC - }, - { - { ShiftMask, ShiftMask, vmod_NumLockMask }, - 2, - 2, map_KEYPAD, NULL, - None, lnames_KEYPAD - }, - { - { ControlMask, ControlMask, 0 }, - 2, - 1, map_PC_BREAK, NULL, - None, lnames_PC_BREAK - }, - { - { 0, 0, vmod_AltMask }, - 2, - 1, map_PC_SYSRQ, NULL, - None, lnames_PC_SYSRQ - }, - { - { ControlMask, ControlMask, vmod_AltMask }, - 2, - 1, map_CTRL_ALT, NULL, - None, lnames_CTRL_ALT - }, - { - { ShiftMask, ShiftMask, vmod_LevelThreeMask }, - 3, - 3, map_THREE_LEVEL, NULL, - None, lnames_THREE_LEVEL - }, - { - { ShiftMask, ShiftMask, vmod_AltMask }, - 2, - 1, map_SHIFT_ALT, NULL, - None, lnames_SHIFT_ALT - } -}; -#define num_dflt_types (sizeof(dflt_types)/sizeof(XkbKeyTypeRec)) - - -static void -initTypeNames(DPYTYPE dpy) -{ - dflt_types[0].name= GET_ATOM(dpy,"ONE_LEVEL"); - lnames_ONE_LEVEL[0]= GET_ATOM(dpy,"Any"); - dflt_types[1].name= GET_ATOM(dpy,"TWO_LEVEL"); - lnames_TWO_LEVEL[0]= GET_ATOM(dpy,"Base"); - lnames_TWO_LEVEL[1]= GET_ATOM(dpy,"Shift"); - dflt_types[2].name= GET_ATOM(dpy,"ALPHABETIC"); - lnames_ALPHABETIC[0]= GET_ATOM(dpy,"Base"); - lnames_ALPHABETIC[1]= GET_ATOM(dpy,"Caps"); - dflt_types[3].name= GET_ATOM(dpy,"KEYPAD"); - lnames_KEYPAD[0]= GET_ATOM(dpy,"Base"); - lnames_KEYPAD[1]= GET_ATOM(dpy,"Number"); - dflt_types[4].name= GET_ATOM(dpy,"PC_BREAK"); - lnames_PC_BREAK[0]= GET_ATOM(dpy,"Base"); - lnames_PC_BREAK[1]= GET_ATOM(dpy,"Control"); - dflt_types[5].name= GET_ATOM(dpy,"PC_SYSRQ"); - lnames_PC_SYSRQ[0]= GET_ATOM(dpy,"Base"); - lnames_PC_SYSRQ[1]= GET_ATOM(dpy,"Alt"); - dflt_types[6].name= GET_ATOM(dpy,"CTRL+ALT"); - lnames_CTRL_ALT[0]= GET_ATOM(dpy,"Base"); - lnames_CTRL_ALT[1]= GET_ATOM(dpy,"Ctrl+Alt"); - dflt_types[7].name= GET_ATOM(dpy,"THREE_LEVEL"); - lnames_THREE_LEVEL[0]= GET_ATOM(dpy,"Base"); - lnames_THREE_LEVEL[1]= GET_ATOM(dpy,"Shift"); - lnames_THREE_LEVEL[2]= GET_ATOM(dpy,"Level3"); - dflt_types[8].name= GET_ATOM(dpy,"SHIFT+ALT"); - lnames_SHIFT_ALT[0]= GET_ATOM(dpy,"Base"); - lnames_SHIFT_ALT[1]= GET_ATOM(dpy,"Shift+Alt"); -} -/* compat name is "default" */ -static XkbSymInterpretRec dfltSI[69]= { - { XK_ISO_Level2_Latch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_Exactly, ShiftMask, - 255, - { XkbSA_LatchMods, { 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Eisu_Shift, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Eisu_toggle, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Kana_Shift, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Kana_Lock, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Shift_Lock, 0x0000, - XkbSI_AnyOf, ShiftMask|LockMask, - 255, - { XkbSA_LockMods, { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Num_Lock, 0x0000, - XkbSI_AnyOf, 0xff, - 0, - { XkbSA_LockMods, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_Alt_L, 0x0000, - XkbSI_AnyOf, 0xff, - 1, - { XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Alt_R, 0x0000, - XkbSI_AnyOf, 0xff, - 1, - { XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Scroll_Lock, 0x0000, - XkbSI_AnyOf, 0xff, - 4, - { XkbSA_LockMods, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Lock, 0x0000, - XkbSI_AnyOf, 0xff, - 255, - { XkbSA_ISOLock, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Level3_Shift, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOf, 0xff, - 2, - { XkbSA_SetMods, { 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 } } }, - { XK_ISO_Level3_Latch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOf, 0xff, - 2, - { XkbSA_LatchMods, { 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 } } }, - { XK_Mode_switch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_SetGroup, { 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_1, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_End, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_2, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_Down, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_3, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_Next, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 } } }, - { XK_KP_4, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Left, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_6, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Right, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_7, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_Home, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_8, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_Up, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_9, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_Prior, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00 } } }, - { XK_KP_5, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Begin, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_F1, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Divide, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_F2, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Multiply, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_F3, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Subtract, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Separator, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Add, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_0, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Insert, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Decimal, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_KP_Delete, 0x0001, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button_Dflt, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button1, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button2, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Button3, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick_Dflt, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick1, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick2, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DblClick3, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_PtrBtn, { 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag_Dflt, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag1, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag2, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_Drag3, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockPtrBtn, { 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_EnableKeys, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00 } } }, - { XK_Pointer_Accelerate, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00 } } }, - { XK_Pointer_DfltBtnNext, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_Pointer_DfltBtnPrev, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_SetPtrDflt, { 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_AccessX_Enable, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 } } }, - { XK_Terminate_Server, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_Terminate, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Group_Latch, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_LatchGroup, { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Next_Group, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_LockGroup, { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Prev_Group, 0x0000, - XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff, - 3, - { XkbSA_LockGroup, { 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_First_Group, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockGroup, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { XK_ISO_Last_Group, 0x0000, - XkbSI_AnyOfOrNone, 0xff, - 255, - { XkbSA_LockGroup, { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, - { NoSymbol, 0x0000, - XkbSI_Exactly, LockMask, - 255, - { XkbSA_LockMods, { 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 } } }, - { NoSymbol, 0x0000, - XkbSI_AnyOf, 0xff, - 255, - { XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } -}; -#define num_dfltSI (sizeof(dfltSI)/sizeof(XkbSymInterpretRec)) - -static XkbCompatMapRec compatMap= { - dfltSI, - { /* group compatibility */ - { 0, 0, 0 }, - { 0, 0, vmod_AltGrMask }, - { 0, 0, vmod_AltGrMask }, - { 0, 0, vmod_AltGrMask } - }, - num_dfltSI, num_dfltSI -}; - -static XkbIndicatorRec indicators= { - 0x0, - { - { 0x80, 0, 0x00, XkbIM_UseEffective, { LockMask, LockMask, 0 }, 0 }, - { 0x80, 0, 0x00, XkbIM_UseEffective, { 0, 0, vmod_NumLockMask }, 0 }, - { 0x80, 0, 0x00, XkbIM_UseLocked, { ShiftMask, ShiftMask, 0 }, 0 }, - { 0x80, 0, 0x00, 0, { 0, 0, 0 }, XkbMouseKeysMask }, - { 0x80, 0, 0x00, XkbIM_UseLocked, { 0, 0, vmod_ScrollLockMask }, 0 }, - { 0x80, XkbIM_UseEffective, 0xfe, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 }, - { 0x00, 0, 0x00, 0, { 0, 0, 0 }, 0 } - } -}; -static void -initIndicatorNames(DPYTYPE dpy,XkbDescPtr xkb) -{ - xkb->names->indicators[ 0]= GET_ATOM(dpy,"Caps Lock"); - xkb->names->indicators[ 1]= GET_ATOM(dpy,"Num Lock"); - xkb->names->indicators[ 2]= GET_ATOM(dpy,"Shift Lock"); - xkb->names->indicators[ 3]= GET_ATOM(dpy,"Mouse Keys"); - xkb->names->indicators[ 4]= GET_ATOM(dpy,"Scroll Lock"); - xkb->names->indicators[ 5]= GET_ATOM(dpy,"Group 2"); -} -#endif /* DEFAULT_H */ -- cgit v1.2.3