[comp.windows.x] X11 Release 2 paint program

mikew@wyse1.wyse.com (Mike Wexler) (03/08/88)

The pain program in ./contrib/paint uses keycodes to determine
which keys are pressed.  The is not a portable technique.  I 
have modified it to use XLookupString which should be somewhat
more portable.  Anyway here are the context diffs:

*** main.c.orig	Mon Mar  7 15:18:21 1988
--- main.c	Mon Mar  7 15:19:56 1988
***************
*** 37,44 ****
  
  Display *dpy;
  
- int shiftbit = FALSE;
- 
  HandleKey(event)
    XEvent *event;
  {
--- 37,42 ----
***************
*** 48,62 ****
      static int arg = 0;
      static int argval = 1;
      static int sgn = 0;
  
!     code = event->xkey.keycode;
!     if (code == 174) {
! 	shiftbit = TRUE;
! 	return;
!     }
!     c = GetCharFromCode(code);
!     if (c >= 'a' && c <= 'z' && shiftbit)
! 	c += 'A' - 'a';
      switch (c) {
        case 'C':
  	XClearWindow(dpy, window);
--- 46,57 ----
      static int arg = 0;
      static int argval = 1;
      static int sgn = 0;
+     char temp[10];
+     KeySym tempsym;
+     XComposeStatus status;
  
!     XLookupString(event,temp,sizeof(temp),&tempsym,&status);
!     c=temp[0];
      switch (c) {
        case 'C':
  	XClearWindow(dpy, window);
***************
*** 135,147 ****
      sgn = 1;
  }
  
- HandleKeyUp(event)
-   XEvent *event;
- {
-     if (event->xkey.keycode == 174)
- 	shiftbit = FALSE;
- }
- 
  DisplayMode()
  {
      char str[500];
--- 130,135 ----
***************
*** 336,342 ****
  		    &attributes);
      XChangeProperty(dpy, window, XA_WM_NAME, XA_STRING, 8, 
  		    PropModeReplace, "Paint", 5);
!     MyXSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask
  		   | ButtonReleaseMask | ButtonMotionMask | ExposureMask);
      XMapWindow(dpy, window);
      gcvalues.foreground = foreground;
--- 324,330 ----
  		    &attributes);
      XChangeProperty(dpy, window, XA_WM_NAME, XA_STRING, 8, 
  		    PropModeReplace, "Paint", 5);
!     MyXSelectInput(dpy, window, KeyPressMask | ButtonPressMask
  		   | ButtonReleaseMask | ButtonMotionMask | ExposureMask);
      XMapWindow(dpy, window);
      gcvalues.foreground = foreground;
***************
*** 356,364 ****
  	switch(event.type) {
  	  case KeyPress:
  	    HandleKey(&event);
- 	    break;
- 	  case KeyRelease:
- 	    HandleKeyUp(&event);
  	    break;
  	  case ButtonPress:
  	    HandleButtonDown(&event);
--- 344,349 ----