patch-xmine_c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. $OpenBSD: patch-xmine_c,v 1.1 2007/10/26 21:19:16 ajacoutot Exp $
  2. --- xmine.c.orig Mon Dec 26 12:31:20 1994
  3. +++ xmine.c Fri Oct 26 23:07:54 2007
  4. @@ -78,6 +78,13 @@
  5. #define GSPACEX 16
  6. #define GSPACEY 16
  7. +/* some systems might be better off with using "random()" instead of "rand()"*/
  8. +#if defined(__FreeBSD__) || defined(__OpenBSD__)
  9. +# define USE_RANDOM 1
  10. +#else
  11. +# define USE_RANDOM 0
  12. +#endif
  13. +
  14. #define SCORE_FILE "~/.xmine_scores"
  15. #define TOPMARGIN 60
  16. #define BOTMARGIN 12
  17. @@ -119,6 +126,7 @@ Widget drawarea;
  18. Display *disp;
  19. Window win;
  20. int colordisp;
  21. +Atom delw;
  22. #define COL_BLUE 0
  23. #define COL_LIMEGREEN 1
  24. @@ -239,6 +247,7 @@ void get_score_file_name P ((char *));
  25. int cant_write_score_file P ((void));
  26. void fix_size P ((void));
  27. void relax_size P ((void));
  28. +void GlobalProtoHandler P ((Widget w, XEvent *xev, String *params, Cardinal *n));
  29. Pixmap fillface;
  30. XtAppContext app;
  31. @@ -271,7 +280,7 @@ main(argc, argv)
  32. XColor unused;
  33. int i;
  34. - XtActionsRec actions[3];
  35. + XtActionsRec actions[4];
  36. String translations =
  37. "<Btn1Down>: search(down)\n\
  38. <Btn1Up>: search(up)\n\
  39. @@ -284,6 +293,8 @@ main(argc, argv)
  40. toplevel = XtVaAppInitialize(&app, "Xmine", NULL, 0,
  41. &argc, argv, fallbacks, NULL);
  42. + delw = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False);
  43. +
  44. main_w = XtVaCreateManagedWidget("main_w", boxWidgetClass, toplevel,
  45. XtNorientation, XtorientVertical,
  46. NULL);
  47. @@ -383,8 +394,14 @@ main(argc, argv)
  48. actions[1].proc = search_action;
  49. actions[2].string = "mark";
  50. actions[2].proc = mark_action;
  51. - XtAppAddActions(app, actions, 3);
  52. + actions[3].string = "GlobalProtoHandler";
  53. + actions[3].proc = GlobalProtoHandler;
  54. + XtAppAddActions(app, actions, 4);
  55. + XtOverrideTranslations(toplevel, XtParseTranslationTable(
  56. + "<Message>WM_PROTOCOLS : GlobalProtoHandler()")
  57. + );
  58. +
  59. drawing_a = XtVaCreateManagedWidget
  60. ("drawing_a",
  61. canvasWidgetClass, main_w,
  62. @@ -404,6 +421,7 @@ main(argc, argv)
  63. XtAddEventHandler(toplevel,
  64. StructureNotifyMask, False, resize_handler, 0);
  65. XtRealizeWidget(toplevel);
  66. + XSetWMProtocols(XtDisplay(toplevel), XtWindow(toplevel), &delw, 1);
  67. fillface = XCreateBitmapFromData(XtDisplay(main_w),
  68. XtWindow(main_w), fillface_bits,
  69. fillface_width, fillface_height);
  70. @@ -461,13 +479,15 @@ search_action(widget, ev, args, num_args)
  71. if (xg == armed_x && yg == armed_y) {
  72. if (!armed) {
  73. set_face(FACE_OHNO);
  74. - draw_blank_square(armed_x, armed_y, True);
  75. + if (gridview[xg][yg] == COVERED)
  76. + draw_blank_square(armed_x, armed_y, True);
  77. armed = True;
  78. }
  79. } else {
  80. if (armed) {
  81. set_face(FACE_HAPPY);
  82. - draw_button(armed_x, armed_y);
  83. + if (gridview[armed_x][armed_y] == COVERED)
  84. + draw_button(armed_x, armed_y);
  85. armed = False;
  86. }
  87. }
  88. @@ -628,11 +648,12 @@ arm_clear(x, y, armit)
  89. set_face(armit ? FACE_OHNO : FACE_HAPPY);
  90. for (dx = -1; dx <= 1; dx++)
  91. for (dy = -1; dy <= 1; dy++)
  92. - if (is_state(x+dx, y+dy, COVERED))
  93. + if (is_state(x+dx, y+dy, COVERED)) {
  94. if (armit)
  95. draw_blank_square(x+dx, y+dy, True);
  96. else
  97. draw_button(x+dx, y+dy);
  98. + }
  99. }
  100. #if NeedFunctionPrototypes
  101. @@ -911,12 +932,21 @@ layout_board(fx, fy)
  102. {
  103. int i, x, y, xd, yd, tries;
  104. +#if USE_RANDOM
  105. + srandom((unsigned) time(0));
  106. +#else
  107. srand((unsigned int) time(0));
  108. +#endif
  109. for (i = 0; i != mine_count; i++) {
  110. tries = 1000;
  111. do {
  112. +#if USE_RANDOM
  113. + x = (random()>>1) % gsizex;
  114. + y = (random()>>1) % gsizey;
  115. +#else
  116. x = (rand()>>1) % gsizex;
  117. y = (rand()>>1) % gsizey;
  118. +#endif
  119. tries--;
  120. } while (tries && (grid[x][y] ||
  121. !(x < fx-1 || x > fx+1 || y < fy-1
  122. @@ -1069,6 +1099,7 @@ winner()
  123. for (y = 0; y != gsizey; y++)
  124. if (gridview[x][y] == COVERED) {
  125. gridview[x][y] = MARKED;
  126. + marked_count++;
  127. redrawsquare(x, y);
  128. }
  129. draw_digits(0, 0);
  130. @@ -1346,6 +1377,10 @@ set_custom(dummy, closure, call_data)
  131. XtAddCallback(w, XtNcallback, dialog_ok, NULL);
  132. XtManageChild(pane);
  133. XtPopup(custom, XtGrabExclusive);
  134. + XtOverrideTranslations(custom, XtParseTranslationTable(
  135. + "<Message>WM_PROTOCOLS : GlobalProtoHandler()")
  136. + );
  137. + XSetWMProtocols(XtDisplay(custom), XtWindow(custom), &delw, 1);
  138. dialog_up = True;
  139. while (dialog_up) {
  140. XtAppProcessEvent(app, XtIMAll);
  141. @@ -1391,7 +1426,6 @@ get_text_int(w, val)
  142. str = XawDialogGetValueString(w);
  143. if (!str) return;
  144. if (atoi(str)) *val = atoi(str);
  145. - XawAsciiSourceFreeString(w);
  146. }
  147. /* ARGSUSED */
  148. @@ -1510,6 +1544,10 @@ best_times(dummy, closure, call_data)
  149. if (cant_write_score_file()) XtSetSensitive(w, False);
  150. XtManageChild(pane);
  151. XtPopup(best, XtGrabExclusive);
  152. + XtOverrideTranslations(best, XtParseTranslationTable(
  153. + "<Message>WM_PROTOCOLS : GlobalProtoHandler()")
  154. + );
  155. + XSetWMProtocols(XtDisplay(best), XtWindow(best), &delw, 1);
  156. dialog_up = True;
  157. while (dialog_up) {
  158. XtAppProcessEvent(app, XtIMAll);
  159. @@ -1554,6 +1592,10 @@ Xaw version by J%crg Wunsch", PATCHLEVEL, 0xf6 /* o-um
  160. XtAddCallback(w, XtNcallback, dialog_ok, NULL);
  161. XtManageChild(pane);
  162. XtPopup(about, XtGrabExclusive);
  163. + XtOverrideTranslations(about, XtParseTranslationTable(
  164. + "<Message>WM_PROTOCOLS : GlobalProtoHandler()")
  165. + );
  166. + XSetWMProtocols(XtDisplay(about), XtWindow(about), &delw, 1);
  167. dialog_up = True;
  168. while (dialog_up) {
  169. XtAppProcessEvent(app, XtIMAll);
  170. @@ -1659,6 +1701,10 @@ new_best(closure, id)
  171. XtManageChild(pane);
  172. XtPopup(custom, XtGrabExclusive);
  173. + XtOverrideTranslations(custom, XtParseTranslationTable(
  174. + "<Message>WM_PROTOCOLS : GlobalProtoHandler()")
  175. + );
  176. + XSetWMProtocols(XtDisplay(custom), XtWindow(custom), &delw, 1);
  177. dialog_up = True;
  178. while (dialog_up) {
  179. @@ -1672,7 +1718,6 @@ new_best(closure, id)
  180. sc->times[level] = timer;
  181. write_scores(sc);
  182. }
  183. - if (str) XawAsciiSourceFreeString(pane);
  184. best_times(NULL, NULL, NULL);
  185. }
  186. @@ -1814,3 +1859,24 @@ exit_game(dummy, closure, call_data)
  187. {
  188. exit(0);
  189. }
  190. +
  191. +#if NeedFunctionPrototypes
  192. +void
  193. +GlobalProtoHandler(Widget w, XEvent *xev, String *params, Cardinal *n)
  194. +#else
  195. +void
  196. +GlobalProtoHandler(w, xev, params, n)
  197. + Widget w;
  198. + XEvent *xev;
  199. + String *params;
  200. + Cardinal *n;
  201. +#endif
  202. +{
  203. + if(xev->xclient.data.l[0] == delw) {
  204. + if(w == toplevel)
  205. + exit(0);
  206. + else
  207. + XtPopdown(w);
  208. + }
  209. +}
  210. +