utils/vflx11-2.0.1/vflx11.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. MAGX
  2. MAGY
  3. main
  4. usage
  5. OpenFont
  6. key_usage
  7. Loop
  8. Cmd
  9. CodePoint
  10. change_win_size
  11. Win_Init
  12. Win_Clear
  13. Win_Beep
  14. Win_PutBitmap
  15. Win_ChangeSize
  16. Win_UserCmd
  17. Win_PollUserCmd

   1 /*
   2  * vfx11 - Display characters on a X11R6 window
   3  *  by Hirotsugu Kakugawa (h.kakugawa@computer.org)
   4  *
   5  * Edition History
   6  *  24 Jan 1997  Simple version.
   7  *  25 Jan 1997  Enhanced parsing of cmd line args.
   8  *               Added key operations: '<', '>', 'm', 'g', and '?'.
   9  *  28 Jan 1997  Added '+', '-', and 'r' operations. 
  10  *  22 Mar 1997  Upgrade for VFlib 3.2
  11  *  20 May 1997  Bug fixed. (Window Clear)
  12  *   1 Sep 1998  Upgrade for VFlib 3.5
  13  */
  14 
  15 /*
  16  * Copyright (C) 1997-1998 Hirotsugu Kakugawa. 
  17  * All rights reserved.
  18  *
  19  * This program is free software; you can redistribute it and/or modify
  20  * it under the terms of the GNU General Public License as published by
  21  * the Free Software Foundation; either version 2, or (at your option)
  22  * any later version.
  23  * 
  24  * This program is distributed in the hope that it will be useful,
  25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27  * GNU General Public License for more details.
  28  * 
  29  * You should have received a copy of the GNU General Public License
  30  * along with this program; if not, write to the Free Software
  31  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  32  */
  33 
  34 
  35 #include <stdio.h>
  36 #include <stdlib.h>
  37 #include <sys/types.h>
  38 #include <X11/Xlib.h>
  39 #include <X11/Xutil.h>
  40 #include <X11/keysym.h>
  41 #include "../../src/VFlib-3_6.h"
  42 
  43 #define VFLX11_VERSION  "2.0.0"
  44 
  45 #define CMD_NOP         0
  46 #define CMD_NEXT_PAGE   1
  47 #define CMD_PREV_PAGE   2
  48 #define CMD_EXIT        3
  49 #define CMD_RESIZE      4
  50 #define CMD_FIRST_PAGE  5
  51 #define CMD_LAST_PAGE   6
  52 #define CMD_SET_MARK    7
  53 #define CMD_GOTO_MARK   8
  54 #define CMD_HELP        9
  55 #define CMD_P4PAGES    10
  56 #define CMD_N4PAGES    11
  57 #define CMD_P16PAGES   12
  58 #define CMD_N16PAGES   13
  59 #define CMD_P64PAGES   14
  60 #define CMD_N64PAGES   15
  61 #define CMD_ENLARGE    20
  62 #define CMD_SHRINK     21
  63 #define CMD_REDRAW     22
  64 #define CMD_REOPEN     23
  65 
  66 #define POLL_NOTHING    0
  67 #define POLL_EVENT      1
  68 
  69 #define ACT_NONE     0
  70 #define ACT_BREAK    1
  71 #define ACT_WINCH    2
  72 #define ACT_REDRAW   3
  73 
  74 
  75 #define DEFAULT_PIXEL_SIZE    24
  76 #define CHAR_BORDER_FACTOR    1.2
  77 
  78 int     Mode = 2;
  79 char    *FontName;
  80 double  ArgFontSize = -1;
  81 double  FontSize = -1;
  82 double  Dpi_X = 1, Dpi_Y = -1;
  83 int     OutlineMode = 0;
  84 int     Verbose = 0;
  85 double  CharBorderX = CHAR_BORDER_FACTOR;
  86 double  CharBorderY = CHAR_BORDER_FACTOR;
  87 
  88 #define CHARS_PER_LINE  16
  89 int  Font_ID;
  90 int  Page;
  91 int  PageMin, PageMax;
  92 int  StartInPage, EndInPage;
  93 int  SkipBeginInPage, SkipEndInPage;
  94 
  95 int  CharWidth, CharHeight, CharLines;
  96 int  CharWidth0, CharHeight0;
  97 double  FMagX, FMagY;
  98 int     MagX,  MagY; 
  99 #define MAG_SCALE 100.0
 100 #define MAGX()  ((double)MagX/MAG_SCALE)
     /* [<][>][^][v][top][bottom][index][help] */
 101 #define MAGY()  ((double)MagY/MAG_SCALE)
     /* [<][>][^][v][top][bottom][index][help] */
 102 
 103 int   usage(), key_usage();
 104 int   OpenFont(), Loop(), Cmd(), CodePoint();
 105 void  change_win_size();
 106 
 107 
 108 void  Win_Init(), Win_Clear(), Win_PutBitmap(), Win_Beep(), Win_ChangeSize();
 109 int   Win_UserCmd(), Win_PollUserCmd();
 110 
 111 
 112 extern  double atof();
 113 
 114 
 115 int
 116 main(argc, argv)
     /* [<][>][^][v][top][bottom][index][help] */
 117   int  argc;
 118   char **argv;
 119 {
 120   char    *vflibcap;
 121   int     na;
 122 
 123   Mode        = 2;
 124   FontName    = NULL;
 125   ArgFontSize = -1;
 126   FontSize    = -1;
 127   FMagX       = 1.0;
 128   FMagY       = 1.0;
 129   MagX        = 1 * MAG_SCALE;
 130   MagY        = 1 * MAG_SCALE;
 131   CharBorderX = CHAR_BORDER_FACTOR;
 132   CharBorderY = CHAR_BORDER_FACTOR;
 133   OutlineMode = 0;
 134 
 135   vflibcap  = NULL;
 136   for (argv++, argc--; argc > 0; argc -= na, argv += na){
 137     na = 1;
 138     if (argv[0][0] != '-'){
 139       FontName = argv[0];      
 140       continue;
 141     } else if (strcmp(argv[0], "-verbose") == 0){
 142       Verbose = 1;
 143       continue;
 144     } else if (strcmp(argv[0], "-mode1") == 0){
 145       Mode = 1;
 146       continue;
 147     } else if (strcmp(argv[0], "-mode2") == 0){
 148       Mode = 2;
 149       continue;
 150     } else if (strcmp(argv[0], "-ol") == 0){
 151       OutlineMode = 1;
 152       continue;
 153     } else if (strcmp(argv[0], "-help") == 0){
 154       usage();
 155       exit(0);
 156     } else if (strcmp(argv[0], "--help") == 0){
 157       usage();
 158       exit(0);
 159     }
 160     na = 2;
 161     if (argc < 2){
 162       usage();
 163       break;
 164     }
 165     if (strcmp(argv[0], "-f") == 0){
 166       FontName = argv[1];
 167     } else if (strcmp(argv[0], "-v") == 0){
 168       vflibcap = argv[1];
 169     } else if (strcmp(argv[0], "-p") == 0){
 170       ArgFontSize = atof(argv[1]);
 171     } else if (strcmp(argv[0], "-m") == 0){
 172       FMagX = FMagY = atof(argv[1]);
 173     } else if (strcmp(argv[0], "-mx") == 0){
 174       FMagX = atof(argv[1]);
 175     } else if (strcmp(argv[0], "-my") == 0){
 176       FMagY = atof(argv[1]);
 177     } else if (strcmp(argv[0], "-b") == 0){
 178       CharBorderX = CharBorderY = atof(argv[1]);
 179       if (CharBorderX < 0)
 180         CharBorderX = CharBorderY = CHAR_BORDER_FACTOR;
 181     } else if (strcmp(argv[0], "-bx") == 0){
 182       CharBorderX = atof(argv[1]);
 183       if (CharBorderX < 0)
 184         CharBorderX = CHAR_BORDER_FACTOR;
 185     } else if (strcmp(argv[0], "-by") == 0){
 186       CharBorderY = atof(argv[1]);
 187       if (CharBorderY < 0)
 188         CharBorderY = CHAR_BORDER_FACTOR;
 189     } else {
 190       usage();
 191     }
 192   }
 193 
 194   if (FontName == NULL)
 195     usage();
 196 
 197   if ((Mode == 2) && (OutlineMode == 1)){
 198     fprintf(stderr, "Warning: Outline mode is not supported in mode 2.\n");
 199   }
 200 
 201   if (VF_Init(vflibcap, NULL) < 0){
 202     fprintf(stderr, "Initializing VFlib: failed\n");
 203     if (vf_error == VF_ERR_NO_VFLIBCAP){
 204       if (vflibcap == NULL){
 205         fprintf(stderr, "Could not read default vflibcap file.\n");
 206       } else {
 207         fprintf(stderr, "Could not read vflibcap file: %s.\n", vflibcap);
 208       }
 209     }
 210     exit(1);
 211   }
 212 
 213   PageMin     = 0;
 214   PageMax     = 0xffff;
 215   StartInPage = 0x00;
 216   EndInPage   = 0xff;
 217   SkipBeginInPage = -1;
 218   SkipEndInPage   = -1;
 219   Font_ID = -1;
 220 
 221   if (Verbose == 1)
 222     printf("Opening font: %s\n", FontName);
 223 
 224   if (OpenFont() < 0){
 225     fprintf(stderr, "Failed to open a font: %s\n", FontName);
 226     exit(1);
 227   }
 228 
 229   Loop();
 230 
 231   return 0;
 232 }
 233 
 234 int usage()
     /* [<][>][^][v][top][bottom][index][help] */
 235 {
 236   printf("vflx11 - Display VFlib font version %s, based on VFlib %s.\n",
 237          VFLX11_VERSION, VF_GetVersion());
 238   printf("Usage: vfx11 [Options] FONT\n");
 239   printf("Options: \n");
 240   printf("   -v VFLIBCAP : vflibcap file\n");
 241   printf("   -p PIXEL    : pixel size (or point size)\n");
 242   printf("   -m MAG      : magnification\n");
 243   printf("   -mx MAG_X   : horizontal magnification\n");
 244   printf("   -my MAG_Y   : vertical magnification\n");
 245   printf("   -f FONT     : font name\n");
 246   printf("   -mode1      : open font in mode 1\n");
 247   printf("   -mode2      : open font in mode 2\n");
 248   printf("   -ol         : outline mode for mode 1\n");
 249 
 250   key_usage();
 251   printf("Example: vflx11 -v vflibcap-pcf -m 0.5 timR24.pcf\n");
 252   exit(0);
 253 }
 254 
 255 int
 256 OpenFont(void)
     /* [<][>][^][v][top][bottom][index][help] */
 257 {
 258   int  fd;
 259   char  *p;
 260 
 261   fd = -1;
 262   if (Mode == 1){
 263     if (ArgFontSize < 0)
 264       fd = VF_OpenFont1(FontName, -1, -1,       -1, FMagX, FMagY);
 265     else
 266       fd = VF_OpenFont1(FontName, -1, -1, ArgFontSize, FMagX, FMagY);
 267   } else if (Mode == 2){
 268     if (ArgFontSize < 0)
 269       fd = VF_OpenFont2(FontName,          -1, FMagX, FMagY);
 270     else
 271       fd = VF_OpenFont2(FontName, ArgFontSize, FMagX, FMagY);
 272   }
 273   
 274   if (fd < 0)
 275     return -1;
 276   
 277   if ((p = VF_GetFontProp(fd, "PIXEL_SIZE")) != NULL)
 278     FontSize = atof(p);
 279   else
 280     FontSize = DEFAULT_PIXEL_SIZE;
 281   
 282   if (Font_ID >= 0){
 283     VF_CloseFont(Font_ID);
 284     Font_ID = -1;
 285   }
 286 
 287   Font_ID = fd;
 288   
 289   if (Verbose == 1)
 290     printf("Pixel size: %d\n", (int)FontSize);
 291 
 292   return 0;
 293 }
 294 
 295 int key_usage()
     /* [<][>][^][v][top][bottom][index][help] */
 296 {
 297   printf("Key and mouse operations:\n");
 298   printf("   q (or mouse middle button)   : exit\n");
 299   printf("   b (or mouse left button)     : go to previous page\n");
 300   printf("   SPC (or mouse right button)  : go to next page\n");
 301   printf("   m        : set mark on current page\n");
 302   printf("   g        : go to marked page\n");
 303   printf("   +        : enlarge window\n");
 304   printf("   -        : shrink window\n");
 305   printf("   d        : redraw window\n");
 306   printf("   ?        : help\n");
 307 
 308   return 0;
 309 
 310 }
 311 
 312 
 313 int Loop()
     /* [<][>][^][v][top][bottom][index][help] */
 314 {
 315   VF_BITMAP  bm = NULL, bm2;
 316   VF_OUTLINE ol;
 317   int        act, nl0, nl1, c;
 318 
 319   if (MagX < 0)
 320     MagX = 1 * MAG_SCALE;
 321   if (MagY < 0)
 322     MagY = 1 * MAG_SCALE;
 323 
 324   nl0 = StartInPage/CHARS_PER_LINE;
 325   nl1 = (EndInPage+CHARS_PER_LINE-1)/CHARS_PER_LINE;
 326   CharLines  = nl1 - nl0;
 327 
 328   CharWidth  = FontSize * CharBorderX;
 329   CharHeight = FontSize * CharBorderY;
 330 
 331   Win_Init(CharWidth * CHARS_PER_LINE, CharHeight * CharLines);
 332 
 333   Page = PageMin;
 334 
 335   for (;;){
 336     Win_Clear();
 337 
 338 AGAIN:    
 339     for (c = StartInPage; c <= EndInPage; c++){
 340 
 341       if ((SkipBeginInPage <= c) && (c <= SkipEndInPage))
 342         continue;
 343 
 344       if (Win_PollUserCmd() == POLL_EVENT){
 345         if ((act = Cmd()) != ACT_NONE){
 346           if (act == ACT_WINCH) 
 347             change_win_size();
 348           Win_Clear();
 349           goto AGAIN;
 350         }
 351       }
 352 
 353       bm = NULL;
 354       if (Mode == 1){
 355         if (OutlineMode == 0){
 356           bm = VF_GetBitmap1(Font_ID, CodePoint(c), MAGX(), MAGY());
 357         } else {
 358           bm = NULL;
 359           if ((ol = VF_GetOutline(Font_ID, CodePoint(c),
 360                                   MAGX(), MAGY())) != NULL){
 361             bm = VF_OutlineToBitmap(ol, -1, -1, -1, 1.0, 1.0);
 362             VF_FreeOutline(ol);
 363           }
 364         }
 365       } else if (Mode == 2){
 366         bm = VF_GetBitmap2(Font_ID, CodePoint(c), MAGX(), MAGY());
 367       }
 368 
 369       if (bm != NULL){
 370         bm2 = VF_MinimizeBitmap(bm);
 371         if (bm2 != NULL){
 372           Win_PutBitmap(bm2, c%CHARS_PER_LINE, c/CHARS_PER_LINE - nl0, 
 373                         CharWidth, CharHeight);
 374           VF_FreeBitmap(bm2);
 375         } else {
 376           Win_PutBitmap(bm, c%CHARS_PER_LINE, c/CHARS_PER_LINE - nl0, 
 377                         CharWidth, CharHeight);
 378         }
 379         VF_FreeBitmap(bm);
 380       }
 381     }
 382 
 383     while ((act = Cmd()) == ACT_NONE)
 384       ;
 385     if (act == ACT_WINCH)
 386       change_win_size();
 387     
 388   }
 389 
 390   return 0;
 391 }
 392 
 393 int Cmd()
     /* [<][>][^][v][top][bottom][index][help] */
 394 {
 395   static int  markedPage = -100;
 396   int         temp;
 397 
 398   switch (Win_UserCmd()){
 399   default:
 400   case CMD_NOP:
 401     return ACT_NONE;
 402   case CMD_EXIT:
 403     exit(0);
 404   case CMD_PREV_PAGE:
 405     if (Page > PageMin){
 406       Page = Page - 1;
 407       return ACT_BREAK;
 408     } else 
 409       Win_Beep();
 410     break;
 411   case CMD_NEXT_PAGE:
 412     if (Page < PageMax){
 413       Page = Page + 1;
 414       return ACT_BREAK;
 415     } else
 416       Win_Beep();
 417     break;
 418   case CMD_N64PAGES:
 419     Page += 64;
 420     if (Page > PageMax)
 421       Page = PageMax;
 422     return ACT_BREAK;
 423   case CMD_P64PAGES:
 424     Page -= 64;
 425     if (Page < PageMin)
 426       Page = PageMin;
 427     return ACT_BREAK;
 428   case CMD_N16PAGES:
 429     Page += 16;
 430     if (Page > PageMax)
 431       Page = PageMax;
 432     return ACT_BREAK;
 433   case CMD_P16PAGES:
 434     Page -= 16;
 435     if (Page < PageMin)
 436       Page = PageMin;
 437     return ACT_BREAK;
 438   case CMD_N4PAGES:
 439     Page += 4;
 440     if (Page > PageMax)
 441       Page = PageMax;
 442     return ACT_BREAK;
 443   case CMD_P4PAGES:
 444     Page -= 4;
 445     if (Page < PageMin)
 446       Page = PageMin;
 447     return ACT_BREAK;
 448   case CMD_FIRST_PAGE:
 449     Page = PageMin;
 450     return ACT_BREAK;
 451   case CMD_LAST_PAGE:
 452     Page = PageMax;
 453     return ACT_BREAK;
 454   case CMD_SET_MARK:
 455     markedPage = Page;
 456     break;
 457   case CMD_GOTO_MARK:
 458     if (markedPage >= PageMin){
 459       temp = Page;
 460       Page = markedPage;
 461       markedPage = temp;
 462       return ACT_BREAK;
 463     } else
 464       Win_Beep();
 465     break;
 466   case CMD_HELP:
 467     key_usage();
 468     break;
 469   case CMD_RESIZE:
 470     return ACT_WINCH;
 471   case CMD_REDRAW:
 472     return ACT_REDRAW;
 473   case CMD_ENLARGE:
 474     MagX = MagX + 20;
 475     MagY = MagY + 20;
 476     return ACT_WINCH;
 477   case CMD_SHRINK:
 478     if ((MagX > 30) && (MagY > 30)){
 479       MagX = MagX - 20;
 480       MagY = MagY - 20;
 481     }
 482     return ACT_WINCH;
 483   case CMD_REOPEN:
 484     if (Verbose == 1)
 485       printf("Reopening font: %s\n", FontName);
 486     if (OpenFont() < 0){
 487       fprintf(stderr, "Failed to reopen a font: %s\n", FontName);
 488       exit(1);
 489     }
 490     return ACT_REDRAW;
 491   }
 492 
 493   return ACT_BREAK;
 494 }
 495 
 496 int CodePoint(c)
     /* [<][>][^][v][top][bottom][index][help] */
 497      int c;
 498 {
 499   return Page * 0x100 + c;
 500 }
 501 
 502 void
 503 change_win_size()
     /* [<][>][^][v][top][bottom][index][help] */
 504 {
 505 
 506   CharWidth  = FontSize * CharBorderX * MAGX();
 507   CharHeight = FontSize * CharBorderY * MAGY();
 508 
 509   Win_ChangeSize(CharWidth * CHARS_PER_LINE, CharHeight * CharLines);
 510 }
 511 
 512 
 513 
 514 /*------------------------*/
 515 Display               *Disp;
 516 Window                Win;
 517 XEvent                xevent, *xev = NULL;
 518 GC                    Gc;
 519 XGCValues             GcVal;
 520 XSetWindowAttributes  Att;
 521 unsigned int          WinX, WinY, WinBorder, WinDepth;
 522 char                  *DisplayName; 
 523 char                  WindowName[256];
 524 #define  WIN_BORDER  3
 525 
 526 
 527 void Win_Init(w, h)
     /* [<][>][^][v][top][bottom][index][help] */
 528      int  w, h;
 529 {
 530   if ((w > 2000) || (h > 2000)){
 531     fprintf(stderr, "Window is too large: (%dx%d)\n", w, h);
 532     exit(0);
 533   }
 534 
 535   WinX = w + WIN_BORDER * 2;
 536   WinY = h + WIN_BORDER * 2;
 537   DisplayName = NULL;
 538   Disp = XOpenDisplay(DisplayName);
 539   if (Disp == NULL){
 540     fprintf(stderr, "Can't open display\n"); 
 541     exit(1);
 542   }
 543   Win = XCreateSimpleWindow(Disp, RootWindow(Disp, 0), 
 544                             0, 0, WinX, WinY, 2,
 545                             BlackPixel(Disp, 0), WhitePixel(Disp, 0));
 546   Gc     = XCreateGC(Disp, Win, 0, 0);
 547   XSetForeground(Disp, Gc, WhitePixel(Disp, 0));
 548 
 549 /*
 550   Att.override_redirect = True;
 551   Att.backing_store     = Always;
 552   XChangeWindowAttributes(Disp, Win, CWOverrideRedirect, &Att);
 553   XChangeWindowAttributes(Disp, Win, CWBackingStore, &Att);
 554 */
 555   XSelectInput(Disp, Win, 
 556                (KeyPressMask|ButtonPressMask|ExposureMask|ConfigureNotify)); 
 557   XMapWindow(Disp, Win);
 558   Win_Clear();
 559   XFlush(Disp);
 560 }
 561 
 562 void Win_Clear()
     /* [<][>][^][v][top][bottom][index][help] */
 563 {
 564   sprintf(WindowName, "VFlib font: %s (0x%X-0x%X / %d-%d)",
 565           FontName, CodePoint(StartInPage), CodePoint(EndInPage),
 566           CodePoint(StartInPage), CodePoint(EndInPage));
 567   XStoreName(Disp, Win, WindowName);
 568   XFillRectangle(Disp, Win, Gc, 0, 0, WinX, WinY);
 569 }
 570 
 571 void Win_Beep()
     /* [<][>][^][v][top][bottom][index][help] */
 572 {
 573   XBell(Disp, 50);
 574 }
 575 
 576 void Win_PutBitmap(bm, x, y, cw, ch)
     /* [<][>][^][v][top][bottom][index][help] */
 577      VF_BITMAP  bm;
 578      int        x, y, cw, ch;
 579 {
 580   int     w, h, ix, iy, i, n;
 581   unsigned char  *xbitmap, c;
 582   Pixmap         pix;
 583   unsigned long  fg, bg;
 584   unsigned int   depth;
 585   static unsigned char bit_rev[] = {
 586     /* 0000 0001 0010 0011 0100 0101 0110 0111 */
 587       0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
 588     /* 1000 1001 1010 1011 1100 1101 1110 1111 */
 589       0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf };
 590 
 591   if (bm == NULL)
 592     return;
 593 
 594   depth = DefaultDepth(Disp, DefaultScreen(Disp));
 595   fg = BlackPixel(Disp, DefaultScreen(Disp));
 596   bg = WhitePixel(Disp, DefaultScreen(Disp));
 597 
 598   if ((w = bm->bbx_width) == 0)
 599     w = 1;
 600   if ((h = bm->bbx_height) == 0)
 601     h = 1;
 602 
 603   n = h * ((w+7)/8);
 604   if ((xbitmap = (unsigned char*)malloc(n)) == NULL){
 605     fprintf(stderr, "No Memory.\n");
 606     exit(1);
 607   }
 608   for (i = 0; i < n; i++)
 609     xbitmap[i] = 0;
 610 
 611   if ((bm->bbx_width != 0) && (bm->bbx_height != 0)){
 612     for (iy = 0; iy < bm->bbx_height; iy++){
 613       for (ix = 0; ix < (bm->bbx_width+7)/8; ix++){
 614         c = bm->bitmap[ix+iy*bm->raster];
 615         xbitmap[ix+iy*((bm->bbx_width+7)/8)]
 616           = bit_rev[(c%0x10)]*0x10 + bit_rev[(c/0x10)];
 617       }
 618     }
 619   }
 620 
 621   pix = XCreatePixmapFromBitmapData(Disp, Win, (char*)xbitmap, 
 622                                     w, h, fg, bg, depth);
 623   XCopyArea(Disp, pix, Win, Gc, 0, 0, w, h, 
 624             x*cw + bm->off_x + WIN_BORDER, 
 625             y*ch - bm->off_y + ch*0.8 + WIN_BORDER);
 626   XFreePixmap(Disp, pix);
 627   free(xbitmap);
 628 }
 629 
 630 void Win_ChangeSize(w, h)
     /* [<][>][^][v][top][bottom][index][help] */
 631 {
 632   WinX = w + WIN_BORDER * 2;
 633   WinY = h + WIN_BORDER * 2;
 634   XResizeWindow(Disp, Win, w, h);
 635 }
 636 
 637 
 638 int Win_UserCmd()
     /* [<][>][^][v][top][bottom][index][help] */
 639 {
 640   char   str[10];
 641   KeySym k;
 642 
 643   if (xev == NULL)
 644     XNextEvent(Disp, &xevent);
 645   xev = NULL;
 646 
 647   switch(xevent.type){
 648   case ButtonPress:
 649     switch (xevent.xbutton.button){
 650     case 1:
 651       return CMD_PREV_PAGE;
 652     case 2:
 653       return CMD_EXIT;
 654     case 3:
 655       return CMD_NEXT_PAGE;
 656     }
 657   case Expose:
 658     return CMD_REDRAW;
 659 #if 0
 660   case ConfigureNotify:
 661     x = xevent.xconfigure.width;
 662     y = xevent.xconfigure.height;
 663     if ((WinX != x) || (y != WinY)){
 664       WinX = x;
 665       WinY = y;
 666       return CMD_RESIZE;
 667     }
 668 #endif
 669     break;
 670   case KeyPress:
 671     if (XLookupString(&xevent.xkey, str, 10, &k, NULL) == 1){
 672       switch (k){
 673       case XK_b: case XK_B: case XK_BackSpace: case XK_Delete:
 674       case XK_j:
 675         return CMD_PREV_PAGE;
 676       case XK_space: case XK_Return: case XK_Linefeed:
 677       case XK_k:
 678         return CMD_NEXT_PAGE;
 679       case XK_bracketleft:  case XK_h:
 680         return CMD_P4PAGES;
 681       case XK_bracketright: case XK_l:
 682         return CMD_N4PAGES;
 683       case XK_braceleft:
 684         return CMD_P16PAGES;
 685       case XK_braceright:
 686         return CMD_N16PAGES;
 687       case XK_parenleft:
 688         return CMD_P64PAGES;
 689       case XK_parenright:
 690         return CMD_N64PAGES;
 691       case XK_less: 
 692         return CMD_FIRST_PAGE;
 693       case XK_greater:
 694         return CMD_LAST_PAGE;
 695       case XK_m: case XK_M:
 696         return CMD_SET_MARK;
 697       case XK_g: case XK_G:
 698         return CMD_GOTO_MARK;
 699       case XK_question: 
 700         return CMD_HELP;
 701       case XK_q: case XK_Q:
 702         return CMD_EXIT;
 703       case XK_plus:
 704         return CMD_ENLARGE;
 705       case XK_minus:
 706         return CMD_SHRINK;
 707       case XK_r:
 708         return CMD_REOPEN;
 709       case XK_d:
 710         return CMD_REDRAW;
 711       }
 712       break;
 713     }
 714   default:
 715     return CMD_NOP;
 716   }
 717   return CMD_NOP;
 718 }
 719 
 720 int Win_PollUserCmd()
     /* [<][>][^][v][top][bottom][index][help] */
 721 {
 722   int    val;
 723   char   str[10];
 724   KeySym k;
 725 
 726   val = POLL_NOTHING;
 727   xev = NULL;
 728 
 729   if (XCheckWindowEvent(Disp, Win, 
 730                         (KeyPressMask | ButtonPressMask
 731                          | ExposureMask | ConfigureNotify), 
 732                         &xevent) 
 733       == False)
 734     return POLL_NOTHING;
 735 
 736   switch(xevent.type){
 737   case Expose:
 738   case ButtonPress:
 739     val = POLL_EVENT;
 740     break;
 741 #if 0
 742   case ConfigureNotify:
 743     if ((WinX != xevent.xconfigure.width)
 744         || (WinY != xevent.xconfigure.height))
 745       val = POLL_EVENT;
 746     break;    
 747 #endif
 748   case KeyPress:
 749     if (XLookupString(&xevent.xkey, str, 10, &k, NULL) == 1)
 750       val = POLL_EVENT;
 751     break;
 752   }
 753   if (val == POLL_EVENT)
 754     xev = &xevent;
 755   return val;
 756 }
 757 
 758 /*EOF*/

/* [<][>][^][v][top][bottom][index][help] */