| 1 |
/* |
| 2 |
|
| 3 |
Copyright 1986, 1998 The Open Group |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in |
| 12 |
all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
Except as contained in this notice, the name of The Open Group shall not be |
| 22 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 23 |
in this Software without prior written authorization from The Open Group. |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include <config.h> |
| 29 |
#endif |
| 30 |
#include <nx-X11/Xlibint.h> |
| 31 |
#include <nx-X11/Xatom.h> |
| 32 |
|
| 33 |
/* insulate predefined atom numbers from cut routines */ |
| 34 |
static const Atom n_to_atom[8] = { |
| 35 |
XA_CUT_BUFFER0, |
| 36 |
XA_CUT_BUFFER1, |
| 37 |
XA_CUT_BUFFER2, |
| 38 |
XA_CUT_BUFFER3, |
| 39 |
XA_CUT_BUFFER4, |
| 40 |
XA_CUT_BUFFER5, |
| 41 |
XA_CUT_BUFFER6, |
| 42 |
XA_CUT_BUFFER7}; |
| 43 |
|
| 44 |
int |
| 45 |
XRotateBuffers ( |
| 46 |
register Display *dpy, |
| 47 |
int rotate) |
| 48 |
{ |
| 49 |
/* XRotateWindowProperties wants a non-const Atom*, but it doesn't |
| 50 |
* modify it, so this is safe. |
| 51 |
*/ |
| 52 |
return XRotateWindowProperties(dpy, RootWindow(dpy, 0), (Atom *)n_to_atom, 8, rotate); |
| 53 |
} |
| 54 |
|
| 55 |
char *XFetchBuffer ( |
| 56 |
register Display *dpy, |
| 57 |
int *nbytes, |
| 58 |
register int buffer) |
| 59 |
{ |
| 60 |
Atom actual_type; |
| 61 |
int actual_format; |
| 62 |
unsigned long nitems; |
| 63 |
unsigned long leftover; |
| 64 |
unsigned char *data; |
| 65 |
*nbytes = 0; |
| 66 |
if ((buffer < 0) || (buffer > 7)) return (NULL); |
| 67 |
/* XXX should be (sizeof (maxint) - 1)/4 */ |
| 68 |
if (XGetWindowProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer], |
| 69 |
0L, 10000000L, False, XA_STRING, |
| 70 |
&actual_type, &actual_format, &nitems, &leftover, &data) != Success) { |
| 71 |
return (NULL); |
| 72 |
} |
| 73 |
if ( (actual_type == XA_STRING) && (actual_format != 32) ) { |
| 74 |
*nbytes = nitems; |
| 75 |
return((char *)data); |
| 76 |
} |
| 77 |
Xfree (data); |
| 78 |
return(NULL); |
| 79 |
} |
| 80 |
|
| 81 |
char *XFetchBytes ( |
| 82 |
register Display *dpy, |
| 83 |
int *nbytes) |
| 84 |
{ |
| 85 |
return (XFetchBuffer (dpy, nbytes, 0)); |
| 86 |
} |
| 87 |
|
| 88 |
int |
| 89 |
XStoreBuffer ( |
| 90 |
register Display *dpy, |
| 91 |
_Xconst char *bytes, |
| 92 |
int nbytes, |
| 93 |
register int buffer) |
| 94 |
{ |
| 95 |
if ((buffer < 0) || (buffer > 7)) return 0; |
| 96 |
return XChangeProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer], |
| 97 |
XA_STRING, 8, PropModeReplace, (_Xconst unsigned char *) bytes, nbytes); |
| 98 |
} |
| 99 |
|
| 100 |
int |
| 101 |
XStoreBytes ( |
| 102 |
register Display *dpy, |
| 103 |
_Xconst char *bytes, |
| 104 |
int nbytes) |
| 105 |
{ |
| 106 |
return XStoreBuffer (dpy, bytes, nbytes, 0); |
| 107 |
} |