diff options
author | Keith Packard <keithp@keithp.com> | 2004-06-22 19:44:37 +0000 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2004-06-22 19:44:37 +0000 |
commit | 5520bc18f910664c421a1991191fb1c3290491a0 (patch) | |
tree | 2c2de75c64874775600ea53c463b5024e71671f8 | |
parent | 521828a128b58a3c3984975e7cb6f9ca2a4611d2 (diff) |
Add mouse
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | lightpipe.c | 176 |
3 files changed, 135 insertions, 49 deletions
@@ -2,6 +2,12 @@ reviewed by: <delete if not using a buddy> + * .cvsignore: + +2004-06-01 Keith Packard <keithp@keithp.com> + + reviewed by: <delete if not using a buddy> + * lightpipe.c: (main): * lpapi.c: (XLightPipeAttendWindow), (XLightPipeIgnoreWindow), (XLightPipeCheckWindow), (XLightPipeCheckAny), (XLightPipeRelease): diff --git a/configure.ac b/configure.ac index 97f8d9c..67d4e51 100644 --- a/configure.ac +++ b/configure.ac @@ -36,7 +36,7 @@ AC_LIBTOOL_WIN32_DLL AM_PROG_LIBTOOL AC_PROG_MAKE_SET -PKG_CHECK_MODULES(LIGHTPIPE, xdamage xcomposite xext x11) +PKG_CHECK_MODULES(LIGHTPIPE, xdamage xcomposite xtst xext x11) WARN_CFLAGS="" diff --git a/lightpipe.c b/lightpipe.c index 3dfc74c..8ddb04b 100644 --- a/lightpipe.c +++ b/lightpipe.c @@ -25,9 +25,12 @@ #include "lightpipe.h" #include <stdlib.h> #include <stdio.h> +#include <string.h> +#include <sys/poll.h> #include <X11/Xlib.h> #include <X11/Xatom.h> #include <X11/Xutil.h> +#include <X11/extensions/XTest.h> int main (int argc, char **argv) @@ -37,8 +40,11 @@ main (int argc, char **argv) Window window; Window new = 0; int new_width = 0, new_height = 0; - XLightPipeWindow *lpw; + XLightPipeWindow *lpw = 0; + XImage *image = 0; GC new_gc = 0; + struct pollfd fds[2]; + int nfd; if (argc != 4) { @@ -48,65 +54,139 @@ main (int argc, char **argv) } display = XOpenDisplay (argv[1]); - window = strtol (argv[2], 0, 0); + if (!strcmp (argv[2], "root")) + window = RootWindow (display, 0); + else + window = strtol (argv[2], 0, 0); XLightPipeInit (); XLightPipeAttendWindow (display, window); for (;;) { - lpw = XLightPipeCheckWindow (display, window, True); - if (!new) + if (new && XPending (new_display)) { - XWMHints *wmhints; - XSizeHints *normalhints; - XClassHint *classhint; - char *name = "lightpipe"; - new_display = XOpenDisplay (argv[3]); - new = XCreateSimpleWindow (new_display, RootWindow (new_display, - DefaultScreen (new_display)), - 0, 0, lpw->geometry.width, - lpw->geometry.height, - 0, 0, 0); - new_gc = XCreateGC (new_display, new, 0, 0); - normalhints = XAllocSizeHints (); - normalhints->flags = 0; - normalhints->x = 0; - normalhints->y = 0; - normalhints->width = lpw->geometry.width; - normalhints->height = lpw->geometry.height; + while (QLength (new_display)) + { + XEvent ev; + int x, y, w, h; - classhint = XAllocClassHint (); - classhint->res_name = "lightpipe"; - classhint->res_class = "Lightpipe"; + XNextEvent (new_display, &ev); + switch (ev.type) { + case Expose: + x = ev.xexpose.x; + y = ev.xexpose.y; + w = ev.xexpose.width; + h = ev.xexpose.height; + if (x + w > new_width) + w = new_width - x; + if (y + h > new_height) + h = new_height - y; + if (w > 0 && h > 0) + { + XPutImage (new_display, new, new_gc, + image, + x, y, + x, y, + w, h); + } + break; + case MotionNotify: + XTestFakeMotionEvent (display, 0, + ev.xmotion.x, + ev.xmotion.y, + 0); + break; + case ButtonPress: + XTestFakeButtonEvent (display, + ev.xbutton.button, + True, 0); + break; + case ButtonRelease: + XTestFakeButtonEvent (display, + ev.xbutton.button, + False, 0); + break; + } + } + } + else if (XPending (display)) + { + lpw = XLightPipeCheckWindow (display, window, True); + if (!new) + { + XWMHints *wmhints; + XSizeHints *normalhints; + XClassHint *classhint; + char *name = "lightpipe"; + new_display = XOpenDisplay (argv[3]); + new = XCreateSimpleWindow (new_display, RootWindow (new_display, + DefaultScreen (new_display)), + 0, 0, lpw->geometry.width, + lpw->geometry.height, + 0, 0, 0); + XSelectInput (new_display, new, + ExposureMask | + KeyPressMask | KeyReleaseMask | + PointerMotionMask | + ButtonPressMask | ButtonReleaseMask); + new_gc = XCreateGC (new_display, new, 0, 0); + normalhints = XAllocSizeHints (); + normalhints->flags = 0; + normalhints->x = 0; + normalhints->y = 0; + normalhints->width = lpw->geometry.width; + normalhints->height = lpw->geometry.height; + + classhint = XAllocClassHint (); + classhint->res_name = "lightpipe"; + classhint->res_class = "Lightpipe"; - wmhints = XAllocWMHints (); - wmhints->flags = InputHint; - wmhints->input = False; + wmhints = XAllocWMHints (); + wmhints->flags = InputHint; + wmhints->input = False; - Xutf8SetWMProperties (new_display, new, name, name, 0, 0, - normalhints, wmhints, classhint); - XFree (wmhints); - XFree (classhint); - XFree (normalhints); + Xutf8SetWMProperties (new_display, new, name, name, 0, 0, + normalhints, wmhints, classhint); + XFree (wmhints); + XFree (classhint); + XFree (normalhints); - XMapWindow (new_display, new); - new_width = lpw->geometry.width; - new_height = lpw->geometry.height; + XMapWindow (new_display, new); + new_width = lpw->geometry.width; + new_height = lpw->geometry.height; + } + if (new_width != lpw->geometry.width || + new_height != lpw->geometry.height) + { + new_width = lpw->geometry.width; + new_height = lpw->geometry.height; + XResizeWindow (new_display, new, new_width, new_height); + } + image = lpw->image; +#if 0 + printf ("@ %4d, %4d -> %4d x %4d\n", + lpw->damage.x, lpw->damage.y, + lpw->damage.width, lpw->damage.height); +#endif + XPutImage (new_display, new, new_gc, image, + lpw->damage.x, lpw->damage.y, + lpw->damage.x, lpw->damage.y, + lpw->damage.width, + lpw->damage.height); + XLightPipeRelease (display, lpw); } - if (new_width != lpw->geometry.width || - new_height != lpw->geometry.height) + else { - new_width = lpw->geometry.width; - new_height = lpw->geometry.height; - XResizeWindow (new_display, new, new_width, new_height); + fds[0].fd = ConnectionNumber (display); + fds[0].events = POLLIN; + nfd = 1; + if (new) + { + fds[1].fd = ConnectionNumber (new_display); + fds[0].events = POLLIN; + nfd = 2; + } + poll (fds, nfd, -1); } - XPutImage (new_display, new, new_gc, lpw->image, - lpw->damage.x, lpw->damage.y, - lpw->damage.x, lpw->damage.y, - lpw->damage.width, - lpw->damage.height); - XFlush (new_display); - XLightPipeRelease (display, lpw); - XFlush (display); } return 0; } |