summaryrefslogtreecommitdiff
path: root/xcl
diff options
context:
space:
mode:
authorJamey Sharp <jamey@minilop.net>2002-04-08 09:28:51 +0000
committerJamey Sharp <jamey@minilop.net>2002-04-08 09:28:51 +0000
commit58e52a174265cd400537c72ca0b10e2e6c370593 (patch)
treea4ba4aec407e0a3e28ba3614de0a703d330283e4 /xcl
parentb46c457366bfbba074199ed36e1f9c0a78c64d8a (diff)
Disabled XPutImage. Implemented more of the Xlib interface. (Gnome `w' can
do a lot without crashing now.)
Diffstat (limited to 'xcl')
-rw-r--r--xcl/src/GrKeybd.c28
-rw-r--r--xcl/src/GrPointer.c32
-rw-r--r--xcl/src/IfEvent.c56
-rw-r--r--xcl/src/PutImage.c36
4 files changed, 134 insertions, 18 deletions
diff --git a/xcl/src/GrKeybd.c b/xcl/src/GrKeybd.c
new file mode 100644
index 0000000..de11a25
--- /dev/null
+++ b/xcl/src/GrKeybd.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2001-2002 Bart Massey and Jamey Sharp.
+ * All Rights Reserved.
+ * Portions Copyright 1986, 1998 The Open Group
+ *
+ * See the file COPYING for licensing information. */
+#include "xclint.h"
+
+int XGrabKeyboard (dpy, window, ownerEvents, pointerMode, keyboardMode, time)
+ register Display *dpy;
+ Window window;
+ Bool ownerEvents;
+ int pointerMode, keyboardMode;
+ Time time;
+{
+ register XCBConnection *c = XCBConnectionOfDisplay(dpy);
+ XCBGrabKeyboardRep *r;
+ register int status;
+
+ r = XCBGrabKeyboardReply(c, XCBGrabKeyboard(c, ownerEvents, XCLWINDOW(window), XCLTIMESTAMP(time), pointerMode, keyboardMode), 0);
+
+ /* Xlib says: "if we ever return, suppress the error" */
+ if(!r)
+ status = GrabSuccess;
+ else
+ status = r->status;
+ free(r);
+ return status;
+}
diff --git a/xcl/src/GrPointer.c b/xcl/src/GrPointer.c
new file mode 100644
index 0000000..a4b940e
--- /dev/null
+++ b/xcl/src/GrPointer.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2001-2002 Bart Massey and Jamey Sharp.
+ * All Rights Reserved.
+ * Portions Copyright 1986, 1998 The Open Group
+ *
+ * See the file COPYING for licensing information. */
+#include "xclint.h"
+
+int XGrabPointer(dpy, grab_window, owner_events, event_mask, pointer_mode,
+ keyboard_mode, confine_to, curs, time)
+ register Display *dpy;
+ Window grab_window;
+ Bool owner_events;
+ unsigned int event_mask; /* CARD16 */
+ int pointer_mode, keyboard_mode;
+ Window confine_to;
+ Cursor curs;
+ Time time;
+{
+ register XCBConnection *c = XCBConnectionOfDisplay(dpy);
+ XCBGrabPointerRep *r;
+ register int status;
+
+ r = XCBGrabPointerReply(c, XCBGrabPointer(c, owner_events, XCLWINDOW(grab_window), event_mask, pointer_mode, keyboard_mode, XCLWINDOW(confine_to), XCLCURSOR(curs), XCLTIMESTAMP(time)), 0);
+
+ /* Xlib says: "if we ever return, suppress the error" */
+ if(!r)
+ status = GrabSuccess;
+ else
+ status = r->status;
+ free(r);
+ return status;
+}
diff --git a/xcl/src/IfEvent.c b/xcl/src/IfEvent.c
new file mode 100644
index 0000000..2492f21
--- /dev/null
+++ b/xcl/src/IfEvent.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2001-2002 Bart Massey and Jamey Sharp.
+ * All Rights Reserved.
+ * Portions Copyright 1985, 1987, 1998 The Open Group
+ *
+ * See the file COPYING for licensing information. */
+#include "xclint.h"
+#include <xcb_event.h>
+
+/* It doesn't matter how this struct is packed by the compiler. */
+typedef struct
+{
+ Display *dpy;
+ Bool (*predicate)(Display*, XEvent*, char*);
+ XEvent *e;
+ char *arg;
+} IfEvent;
+
+static int MatchIfEvent(const XCBGenericEvent *l, const XCBGenericEvent *r)
+{
+ IfEvent *tw;
+ xEvent *xev;
+
+ /* FIXME: breaks encapsulation: relies on r being the queued item */
+ tw = (IfEvent *) l;
+ xev = (xEvent *) r;
+
+ if(!tw->dpy->event_vec[r->response_type & 0177](tw->dpy, tw->e, xev))
+ return 0;
+ if(!tw->predicate(tw->dpy, tw->e, tw->arg))
+ return 0;
+ return 1;
+}
+
+/* Flush output and (wait for and) return the next event matching the
+ * predicate in the queue. */
+int XIfEvent(dpy, event, predicate, arg)
+ Display *dpy;
+ Bool (*predicate)(Display*, XEvent*, char*);
+ register XEvent *event;
+ char *arg;
+{
+ register XCBConnection *c = XCBConnectionOfDisplay(dpy);
+ IfEvent earg = { dpy, predicate, event, arg };
+ XCBGenericEvent *eargp = (XCBGenericEvent *) &earg;
+ XCBGenericEvent *ret;
+
+ while(1)
+ {
+ ret = XCBEventQueueRemove(c, MatchIfEvent, eargp);
+ if(ret)
+ break;
+ XCBWait(c->handle, /* should_write */ 1);
+ }
+ free(ret);
+ return 0;
+}
diff --git a/xcl/src/PutImage.c b/xcl/src/PutImage.c
index 4d10f50..1fd9543 100644
--- a/xcl/src/PutImage.c
+++ b/xcl/src/PutImage.c
@@ -7,6 +7,9 @@
#include <X11/Xutil.h>
#include <stdio.h>
+#undef USEPUTIMAGE
+#undef USEPUTPIXEL
+
#if defined(Lynx) && defined(ROUNDUP)
#undef ROUNDUP
#endif
@@ -14,6 +17,7 @@
/* assumes pad is a power of 2 */
#define ROUNDUP(nbytes, pad) (((nbytes) + ((pad) - 1)) & ~(long)((pad) - 1))
+#ifdef USEPUTIMAGE
static unsigned char const _reverse_byte[0x100] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
@@ -540,20 +544,6 @@ static int const HalfOrderWord[12] = {
+ (((bitmap_bit_order == MSBFirst) ? 0 : 3) \
+ ((byte_order == MSBFirst) ? 0 : 6)))
-#if 0 /* not needed, ever */
-/* Cancel a GetReq operation, before doing _XSend or Data */
-
-#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
-#define UnGetReq(name)\
- dpy->bufptr -= SIZEOF(x##name##Req);\
- dpy->request--
-#else
-#define UnGetReq(name)\
- dpy->bufptr -= SIZEOF(x/**/name/**/Req);\
- dpy->request--
-#endif
-#endif
-
struct SendImageParams
{
Display *dpy;
@@ -586,8 +576,8 @@ static void SendImage(dpy, is_xyimage, p, depth)
long bytes_per_line = p->image->bytes_per_line;
long bytes_per_src_plane = bytes_per_line * p->image->height;
long bytes_per_dest_plane;
- unsigned char *src, *dest, *buf;
- unsigned char *extra = 0;
+ unsigned char *src, *dest;
+ unsigned char *buf = 0, *extra = 0;
register int j;
p->total_xoffset = (unsigned)(p->total_xoffset - p->leftPad) >> 3;
@@ -627,7 +617,7 @@ static void SendImage(dpy, is_xyimage, p, depth)
}
length = ROUNDUP(length, 4);
- if ((buf = _XAllocScratch(dpy, (unsigned long) (length))) == NULL) {
+ if ((buf = malloc(length)) == NULL) {
goto done;
}
@@ -683,6 +673,8 @@ static void SendImage(dpy, is_xyimage, p, depth)
length, buf);
done:
+ if (buf)
+ Xfree(buf);
if (extra)
Xfree(extra);
}
@@ -767,7 +759,11 @@ PutSubImage(p, req_xoffset, req_yoffset, x, y, req_width, req_height)
}
}
+#ifdef USEPUTPIXEL
extern void _XInitImageFuncPtrs();
+#endif
+
+#endif /* USEPUTIMAGE */
int XPutImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, req_width,
req_height)
@@ -779,10 +775,10 @@ int XPutImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, req_width,
unsigned int req_width, req_height;
int req_xoffset, req_yoffset;
{
+#ifdef USEPUTIMAGE
long width = req_width;
long height = req_height;
char *tmp = 0;
- XImage img;
struct SendImageParams p;
if (req_xoffset < 0) {
@@ -855,7 +851,9 @@ int XPutImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, req_width,
p.dest_bits_per_pixel = format->bits_per_pixel;
p.dest_scanline_pad = format->scanline_pad;
}
+#ifdef USEPUTPIXEL
if (p.dest_bits_per_pixel != image->bits_per_pixel) {
+ XImage img;
register long i, j;
/* XXX slow, but works */
img.width = width;
@@ -883,6 +881,7 @@ int XPutImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, req_width,
p.image = &img;
req_xoffset = req_yoffset = 0;
}
+#endif /* USEPUTPIXEL */
}
LockDisplay(dpy);
@@ -893,5 +892,6 @@ int XPutImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, req_width,
UnlockDisplay(dpy);
Xfree(tmp);
+#endif /* USEPUTIMAGE */
return 0;
}