home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part10 / Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-21  |  4.3 KB  |  171 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_Menu_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/Menu.c,v 1.3 89/02/07 22:39:41 jkh Exp $";
  6. #endif    lint
  7.  
  8. #include "X11/copyright.h"
  9. /*
  10.  *
  11.  * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca.
  12.  *
  13.  * Copyright 1987 by Jordan Hubbard.
  14.  *
  15.  *
  16.  *                         All Rights Reserved
  17.  *
  18.  * Permission to use, copy, modify, and distribute this software and its
  19.  * documentation for any purpose and without fee is hereby granted,
  20.  * provided that the above copyright notice appear in all copies and that
  21.  * both that copyright notice and this permission notice appear in
  22.  * supporting documentation, and that the name of Ardent Computer
  23.  * Corporation or Jordan Hubbard not be used in advertising or publicity
  24.  * pertaining to distribution of the software without specific, written
  25.  * prior permission.
  26.  *
  27.  */
  28.  
  29. #include <signal.h>
  30. #include "X11/cursorfont.h"
  31.  
  32. /*
  33.  * MODIFICATION HISTORY
  34.  *
  35.  * 000 -- J.Hubbard, Ardent Computer.
  36.  *     This file bears little resemblance to its former namesake.
  37.  *    Because of massive changes to support RTL menus, the Menu()
  38.  *      function is now little more than a bootstrap for RTL.
  39.  * 1.2 -- Select_Window code fixed for icons.
  40.  */
  41.  
  42. #ifndef lint
  43. static char *sccsid = "@(#)Menu.c    3.8    1/24/86";
  44. #endif
  45.  
  46. #include "awm.h"
  47.  
  48. /*ARGSUSED*/
  49. Boolean DoMenu(window, mask, button, x, y, menu)
  50. Window window;                /* Event window. */
  51. int mask;                /* Button/key mask. */
  52. int button;                /* Button event detail. */
  53. int x, y;                /* Event mouse position. */
  54. RTLMenu menu;
  55. {
  56.      RTLPoint pos;
  57.      
  58.      Entry("DoMenu")
  59.       
  60.      pos.x = x;
  61.      pos.y = y;
  62.      if (!menu)
  63.     Leave(FALSE)
  64.      RTLMenu_Enter(menu, button, 0, window, pos);
  65.      Leave(TRUE)
  66. }
  67.  
  68. /*ARGSUSED*/
  69. Boolean DoAction(window, mask, button, x, y, menu, action)
  70. Window window;                /* Event window. */
  71. int mask;                /* Button/key mask. */
  72. int button;                /* Button event detail. */
  73. int x, y;                /* Event mouse position. */
  74. RTLMenu menu;
  75. ActionLine *action;
  76. {
  77.      char *buff, *cmd;
  78.      int status, pid, w;
  79.      void (*istat)(), (*qstat)();
  80.  
  81.      Entry("DoAction")
  82.  
  83.      switch(action->type) {
  84.      case IsText:
  85.       XStoreBytes(dpy, action->text, strlen(action->text));
  86.       break;
  87.  
  88.      case IsTextNL:
  89.       buff = (char *)malloc(strlen(action->text) + 2);
  90.       strcpy(buff, action->text);
  91.       strcat(buff, "\n");
  92.       XStoreBytes(dpy, buff, strlen(buff));
  93.       free(buff);
  94.       break;
  95.  
  96.      case IsShellCommand:
  97.       cmd = action->text;
  98.       if ((pid = fork()) == 0) {
  99.            setpgrp(0, getpid());
  100.            signal(SIGHUP, SIG_DFL);
  101.            signal(SIGQUIT, SIG_DFL);
  102.            signal(SIGINT, SIG_DFL);
  103.            execl("/bin/sh", "sh", "-c", cmd, 0);
  104.            _exit(127);
  105.       }
  106.       istat = (void (*)())signal(SIGINT, SIG_IGN);
  107.       qstat = (void (*)())signal(SIGQUIT, SIG_IGN);
  108.       while ((w = wait(&status)) != pid && w != -1);
  109.       if (w == -1)
  110.            status = -1;
  111.       signal(SIGINT, istat);
  112.       signal(SIGQUIT, qstat);
  113.       break;
  114.  
  115.      default:
  116.       fprintf(stderr, "awm: Warning: Unknown action type %d (%s) invoked\n",
  117.           action->type, action->text);
  118.       break;
  119.      }
  120. }
  121.  
  122. /*
  123.  * Routine to let user select a window using the mouse
  124.  */
  125.  
  126. Window Select_Window(x, y, button)
  127. int *x, *y, *button;
  128. {
  129.      XEvent event;
  130.      Window target_win, root;
  131.      int root_x, root_y, x2, y2;
  132.      unsigned int ptrmask;
  133.      AwmInfoPtr awi;
  134.      
  135.      Entry("Select_Window")
  136.       
  137.      /* Make the target cursor */
  138.      if (XGrabPointer( dpy, RootWindow(dpy, scr),
  139.               TRUE, (unsigned int) EVENTMASK, GrabModeAsync,
  140.               GrabModeAsync, None,
  141.               TargetCursor, CurrentTime )
  142.      != GrabSuccess ) {
  143.       fprintf(stderr, "awm (Select_Window): Can't grab the mouse.");
  144.       Leave(RootWindow(dpy, scr))
  145.      }
  146.      Snatched = TRUE;
  147.      /* Select a window */
  148.      while (TRUE) {
  149.       XPeekEvent(dpy, &event);
  150.       if (event.type != ButtonPress) {
  151.            GetButton(&event);
  152.            continue;
  153.       }
  154.           XNextEvent(dpy, &event);
  155.       XQueryPointer(dpy, RootWindow(dpy, scr), &root,
  156.             &target_win, &root_x, &root_y, &x2, &y2, &ptrmask);
  157.  
  158.       *x = root_x;
  159.       *y = root_y;
  160.       *button = event.xbutton.button;
  161.       if (target_win == 0)
  162.            target_win = event.xbutton.window;
  163.       XUngrabPointer(dpy, CurrentTime);      /* Done with pointer */
  164.       if (awi = GetAwmInfo(target_win))
  165.            if (target_win != awi->icon)
  166.                     target_win = (awi->frame) ? awi->frame : awi->client;
  167.       Snatched = FALSE;
  168.       Leave(target_win)
  169.      }
  170. }
  171.