interface.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* $OpenBSD: interface.c,v 1.1.1.1 2006/11/26 10:58:43 matthieu Exp $ */
  2. /*
  3. * Copyright (c) 2002 Matthieu Herrb and Niels Provos
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following
  14. * disclaimer in the documentation and/or other materials provided
  15. * with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  27. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <X11/Intrinsic.h>
  31. #include <X11/Shell.h>
  32. #include <X11/StringDefs.h>
  33. #include <X11/Xatom.h>
  34. #include <X11/Xaw/Form.h>
  35. #include <X11/Xaw/Label.h>
  36. #include <X11/Xaw/Command.h>
  37. #include <X11/Xaw/AsciiText.h>
  38. #include <X11/Xaw/Box.h>
  39. #include <X11/Xaw/MenuButton.h>
  40. #include <X11/Xaw/SmeBSB.h>
  41. #include <X11/Xaw/SimpleMenu.h>
  42. #include <time.h>
  43. #include "callbacks.h"
  44. #include "interface.h"
  45. static String formNames[] = {
  46. "title-form",
  47. "processInfo-form",
  48. "syscallInfo-form",
  49. "status-form",
  50. "errorCode-form",
  51. "specialProc-form",
  52. "buttons-form",
  53. };
  54. #define NUM_FORMS (sizeof(formNames)/sizeof(char *))
  55. XtAppContext appContext;
  56. Atom wm_delete_window;
  57. Widget forms[NUM_FORMS], errorCodeMenu, errorCodeText,
  58. filterText, filterMenu, filterPopup,
  59. wizardButton, timeline, pName,
  60. pId, policyName, syscallName, status, reviewButton;
  61. volatile Boolean done;
  62. Widget
  63. makeForm(Widget parent)
  64. {
  65. Widget form;
  66. Widget errorCodePopup, sme, w;
  67. time_t when;
  68. int i;
  69. form = XtVaCreateWidget("form", formWidgetClass, parent, NULL);
  70. for (i = 0; i < NUM_FORMS; i++) {
  71. forms[i] = XtCreateManagedWidget(formNames[i],
  72. formWidgetClass, form, NULL, 0);
  73. }
  74. XtVaCreateManagedWidget("title-label", labelWidgetClass,
  75. forms[0], NULL);
  76. when = time(NULL);
  77. timeline = XtVaCreateManagedWidget("date-label", labelWidgetClass,
  78. forms[0], NULL);
  79. XtVaCreateManagedWidget("processInfo-label", labelWidgetClass,
  80. forms[1], NULL);
  81. XtVaCreateManagedWidget("processName-label", labelWidgetClass,
  82. forms[1], NULL);
  83. pName = XtVaCreateManagedWidget("processName-value", labelWidgetClass,
  84. forms[1], NULL);
  85. XtVaCreateManagedWidget("processPid-label", labelWidgetClass,
  86. forms[1], NULL);
  87. pId = XtVaCreateManagedWidget("processPid-value", labelWidgetClass,
  88. forms[1], NULL);
  89. XtVaCreateManagedWidget("policyName-label", labelWidgetClass,
  90. forms[1], NULL);
  91. policyName = XtVaCreateManagedWidget("policyName-value",
  92. labelWidgetClass, forms[1], NULL);
  93. XtVaCreateManagedWidget("syscallInfo-label", labelWidgetClass,
  94. forms[2], NULL);
  95. syscallName = XtVaCreateManagedWidget("syscallInfo-value",
  96. labelWidgetClass, forms[2], NULL);
  97. XtVaCreateManagedWidget("filter-label", labelWidgetClass,
  98. forms[2], NULL);
  99. filterText = XtVaCreateManagedWidget("filter-text",
  100. asciiTextWidgetClass, forms[2], XtNeditType, XawtextEdit,
  101. NULL, 0);
  102. filterMenu = XtCreateManagedWidget("filter-menu-button",
  103. menuButtonWidgetClass, forms[2], NULL, 0);
  104. filterPopup = XtCreatePopupShell("filter-menu", simpleMenuWidgetClass,
  105. forms[2], NULL, 0);
  106. wizardButton = XtVaCreateManagedWidget("filter-button",
  107. commandWidgetClass, forms[2], NULL, 0);
  108. XtAddCallback(wizardButton, XtNcallback, on_wizard_clicked, NULL);
  109. XtVaCreateManagedWidget("status-label", labelWidgetClass,
  110. forms[3], NULL);
  111. status = XtVaCreateManagedWidget("status-value", labelWidgetClass,
  112. forms[3], NULL);
  113. XtVaCreateManagedWidget("errorCode-label", labelWidgetClass,
  114. forms[4], NULL);
  115. errorCodeText = XtVaCreateManagedWidget("errorCode-text",
  116. asciiTextWidgetClass, forms[4], XtNeditType, XawtextEdit,
  117. NULL, 0);
  118. errorCodeMenu = XtCreateManagedWidget("errorCode-button",
  119. menuButtonWidgetClass, forms[4], NULL, 0);
  120. errorCodePopup = XtCreatePopupShell("menu", simpleMenuWidgetClass,
  121. forms[4], NULL, 0);
  122. sme = XtCreateManagedWidget("eperm", smeBSBObjectClass,
  123. errorCodePopup, NULL, 0);
  124. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"eperm");
  125. sme = XtCreateManagedWidget("enoent", smeBSBObjectClass,
  126. errorCodePopup, NULL, 0);
  127. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"enoent");
  128. sme = XtCreateManagedWidget("einval", smeBSBObjectClass,
  129. errorCodePopup, NULL, 0);
  130. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"einval");
  131. sme = XtCreateManagedWidget("enotdir", smeBSBObjectClass,
  132. errorCodePopup, NULL, 0);
  133. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"enotdir");
  134. sme = XtCreateManagedWidget("eio", smeBSBObjectClass,
  135. errorCodePopup, NULL, 0);
  136. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"eio");
  137. sme = XtCreateManagedWidget("enxio", smeBSBObjectClass,
  138. errorCodePopup, NULL, 0);
  139. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"enxio");
  140. sme = XtCreateManagedWidget("eaccess", smeBSBObjectClass,
  141. errorCodePopup, NULL, 0);
  142. XtAddCallback(sme, XtNcallback, on_error_select, (XtPointer)"eaccess");
  143. /* Initial value */
  144. on_error_select(errorCodeMenu, "eperm", NULL);
  145. XtVaCreateManagedWidget("specialProc-label", labelWidgetClass,
  146. forms[5], NULL);
  147. w = XtVaCreateManagedWidget("kill-button", commandWidgetClass,
  148. forms[5], NULL);
  149. XtAddCallback(w, XtNcallback, on_killbutton_clicked, NULL);
  150. reviewButton = XtVaCreateManagedWidget("review-button",
  151. commandWidgetClass, forms[5], NULL);
  152. XtAddCallback(reviewButton, XtNcallback, on_reviewbutton_clicked,
  153. (XtPointer)parent);
  154. w = XtVaCreateManagedWidget("auto-button", commandWidgetClass,
  155. forms[5], NULL);
  156. XtAddCallback(w, XtNcallback, on_detachbutton_clicked, NULL);
  157. w = XtVaCreateManagedWidget("deny-button", commandWidgetClass,
  158. forms[6], NULL);
  159. XtAddCallback(w, XtNcallback, on_denyone_clicked, NULL);
  160. w = XtVaCreateManagedWidget("allow-button", commandWidgetClass,
  161. forms[6], NULL);
  162. XtAddCallback(w, XtNcallback, on_permitonce_clicked, NULL);
  163. w = XtVaCreateManagedWidget("deny-all-button", commandWidgetClass,
  164. forms[6], NULL);
  165. XtAddCallback(w, XtNcallback, on_deny_clicked, NULL);
  166. w = XtVaCreateManagedWidget("allow-all-button", commandWidgetClass,
  167. forms[6], NULL);
  168. XtAddCallback(w, XtNcallback, on_permit_clicked, NULL);
  169. XtManageChild(form);
  170. return form;
  171. }
  172. /*
  173. * Widget positionning
  174. */
  175. static void
  176. position_near(Widget shell, int x, int y)
  177. {
  178. int max_x, max_y;
  179. Dimension width, height, border;
  180. int gravity;
  181. /* some of this is copied from CenterWidgetOnPoint in Xaw/TextPop.c */
  182. XtVaGetValues(shell, XtNwidth, &width, XtNheight, &height,
  183. XtNborderWidth, &border, NULL);
  184. width += 2 * border;
  185. height += 2 * border;
  186. max_x = WidthOfScreen(XtScreen(shell));
  187. max_y = HeightOfScreen(XtScreen(shell));
  188. /* set gravity hint based on position on screen */
  189. gravity = 1;
  190. if (x > max_x/3) gravity += 1;
  191. if (x > max_x*2/3) gravity += 1;
  192. if (y > max_y/3) gravity += 3;
  193. if (y > max_y*2/3) gravity += 3;
  194. max_x -= width;
  195. max_y -= height;
  196. x -= ( (Position) width/2 );
  197. if (x < 0) x = 0;
  198. if (x > max_x) x = max_x;
  199. y -= ( (Position) height/2 );
  200. if (y < 0) y = 0;
  201. if ( y > max_y ) y = max_y;
  202. XtVaSetValues(shell, XtNx, (Position)x, XtNy, (Position)y,
  203. XtNwinGravity, gravity, NULL);
  204. }
  205. void
  206. position_near_mouse(Widget shell)
  207. {
  208. int x, y;
  209. Window root, child;
  210. int winx, winy;
  211. unsigned int mask;
  212. XQueryPointer(XtDisplay(shell), XtWindow(shell),
  213. &root, &child, &x, &y, &winx, &winy, &mask);
  214. position_near(shell, x, y);
  215. }
  216. void
  217. position_near_center(Widget shell)
  218. {
  219. position_near(shell, WidthOfScreen(XtScreen(shell))/2,
  220. HeightOfScreen(XtScreen(shell))/2);
  221. }