Mailbox.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /* $XConsortium: Mailbox.c,v 1.64 94/04/17 20:43:26 rws Exp $ */
  2. /*
  3. Copyright (c) 1988 X Consortium
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. "Software"), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  17. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  18. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  19. OTHER DEALINGS IN THE SOFTWARE.
  20. Except as contained in this notice, the name of the X Consortium shall
  21. not be used in advertising or otherwise to promote the sale, use or
  22. other dealings in this Software without prior written authorization
  23. from the X Consortium.
  24. */
  25. /* $XFree86: xc/programs/xbiff/Mailbox.c,v 1.4 2001/08/01 00:45:02 tsi Exp $ */
  26. /*
  27. * Author: Jim Fulton, MIT X Consortium
  28. *
  29. * I recommend that you use the new mailfull and mailempty bitmaps instead of
  30. * the ugly mailboxes:
  31. *
  32. * XBiff*fullPixmap: mailfull
  33. * XBiff*emptyPixmap: mailempty
  34. */
  35. #include <X11/IntrinsicP.h> /* for toolkit stuff */
  36. #include <X11/StringDefs.h> /* for useful atom names */
  37. #include <X11/cursorfont.h> /* for cursor constants */
  38. #include <X11/Xosdefs.h> /* for X_NOT_POSIX def */
  39. #include <stdlib.h>
  40. #ifdef WIN32
  41. #include <X11/Xw32defs.h>
  42. #else
  43. #include <pwd.h> /* for getting username */
  44. #endif
  45. #include <sys/stat.h> /* for stat() ** needs types.h ***/
  46. #include <stdio.h> /* for printing error messages */
  47. #include <unistd.h>
  48. #ifndef X_NOT_POSIX
  49. #ifdef _POSIX_SOURCE
  50. # include <sys/wait.h>
  51. #else
  52. #define _POSIX_SOURCE
  53. # include <sys/wait.h>
  54. #undef _POSIX_SOURCE
  55. #endif
  56. # define waitCode(w) WEXITSTATUS(w)
  57. # define waitSig(w) WIFSIGNALED(w)
  58. typedef int waitType;
  59. # define INTWAITTYPE
  60. #else /* ! X_NOT_POSIX */
  61. #ifdef SYSV
  62. # define waitCode(w) (((w) >> 8) & 0x7f)
  63. # define waitSig(w) ((w) & 0xff)
  64. typedef int waitType;
  65. # define INTWAITTYPE
  66. #else
  67. #ifdef WIN32
  68. #include <process.h>
  69. # define INTWAITTYPE
  70. typedef int waitType;
  71. # define waitCode(w) (w)
  72. # define waitSig(w) (0)
  73. #else
  74. # include <sys/wait.h>
  75. # define waitCode(w) ((w).w_T.w_Retcode)
  76. # define waitSig(w) ((w).w_T.w_Termsig)
  77. typedef union wait waitType;
  78. #endif /* WIN32 else */
  79. #endif /* SYSV else */
  80. #endif /* ! X_NOT_POSIX else */
  81. #include <X11/bitmaps/mailfull> /* for flag up (mail present) bits */
  82. #include <X11/bitmaps/mailempty> /* for flag down (mail not here) */
  83. #include <X11/Xaw/XawInit.h>
  84. #include "MailboxP.h" /* for implementation mailbox stuff */
  85. #include <X11/Xmu/Drawing.h>
  86. #include <X11/extensions/shape.h>
  87. /*
  88. * The default user interface is to have the mailbox turn itself off whenever
  89. * the user presses a button in it. Expert users might want to make this
  90. * happen on EnterWindow. It might be nice to provide support for some sort of
  91. * exit callback so that you can do things like press q to quit.
  92. */
  93. static char defaultTranslations[] =
  94. "<ButtonPress>: unset()";
  95. static void Set (Widget gw, XEvent *event, String *params, Cardinal *nparams);
  96. static void Check(Widget gw, XEvent *event, String *params, Cardinal *nparams);
  97. static void Unset(Widget gw, XEvent *event, String *params, Cardinal *nparams);
  98. static XtActionsRec actionsList[] = {
  99. { "check", Check },
  100. { "unset", Unset },
  101. { "set", Set },
  102. };
  103. /* Initialization of defaults */
  104. #define offset(field) XtOffsetOf(MailboxRec, mailbox.field)
  105. #define goffset(field) XtOffsetOf(WidgetRec, core.field)
  106. static Dimension defDim = 48;
  107. static Pixmap nopix = None;
  108. static XtResource resources[] = {
  109. { XtNwidth, XtCWidth, XtRDimension, sizeof (Dimension),
  110. goffset (width), XtRDimension, (XtPointer)&defDim },
  111. { XtNheight, XtCHeight, XtRDimension, sizeof (Dimension),
  112. goffset (height), XtRDimension, (XtPointer)&defDim },
  113. { XtNupdate, XtCInterval, XtRInt, sizeof (int),
  114. offset (update), XtRString, "30" },
  115. { XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
  116. offset (foreground_pixel), XtRString, XtDefaultForeground },
  117. { XtNfile, XtCFile, XtRString, sizeof (String),
  118. offset (filename), XtRString, NULL },
  119. { XtNcheckCommand, XtCCheckCommand, XtRString, sizeof(char*),
  120. offset (check_command), XtRString, NULL},
  121. { XtNvolume, XtCVolume, XtRInt, sizeof(int),
  122. offset (volume), XtRString, "33"},
  123. { XtNonceOnly, XtCBoolean, XtRBoolean, sizeof(Boolean),
  124. offset (once_only), XtRImmediate, (XtPointer)False },
  125. { XtNfullPixmap, XtCPixmap, XtRBitmap, sizeof(Pixmap),
  126. offset (full.bitmap), XtRString, "flagup" },
  127. { XtNfullPixmapMask, XtCPixmapMask, XtRBitmap, sizeof(Pixmap),
  128. offset (full.mask), XtRBitmap, (XtPointer) &nopix },
  129. { XtNemptyPixmap, XtCPixmap, XtRBitmap, sizeof(Pixmap),
  130. offset (empty.bitmap), XtRString, "flagdown" },
  131. { XtNemptyPixmapMask, XtCPixmapMask, XtRBitmap, sizeof(Pixmap),
  132. offset (empty.mask), XtRBitmap, (XtPointer) &nopix },
  133. { XtNflip, XtCFlip, XtRBoolean, sizeof(Boolean),
  134. offset (flipit), XtRString, "true" },
  135. { XtNshapeWindow, XtCShapeWindow, XtRBoolean, sizeof(Boolean),
  136. offset (shapeit), XtRString, "false" },
  137. };
  138. #undef offset
  139. #undef goffset
  140. static void GetMailFile(MailboxWidget w);
  141. static void CloseDown (MailboxWidget w, int status);
  142. static void check_mailbox(MailboxWidget w, Boolean force_redraw, Boolean reset);
  143. static void redraw_mailbox (MailboxWidget w);
  144. static void beep (MailboxWidget w);
  145. static void Initialize (Widget request, Widget new,
  146. ArgList args, Cardinal *num_args);
  147. static void Realize (Widget gw, XtValueMask *valuemaskp,
  148. XSetWindowAttributes *attr);
  149. static void Destroy (Widget gw);
  150. static void Redisplay (Widget gw, XEvent *event, Region region);
  151. static Boolean SetValues (Widget gcurrent, Widget grequest, Widget gnew,
  152. ArgList args, Cardinal *num_args);
  153. MailboxClassRec mailboxClassRec = {
  154. { /* core fields */
  155. /* superclass */ (WidgetClass) &simpleClassRec,
  156. /* class_name */ "Mailbox",
  157. /* widget_size */ sizeof(MailboxRec),
  158. /* class_initialize */ XawInitializeWidgetSet,
  159. /* class_part_initialize */ NULL,
  160. /* class_inited */ FALSE,
  161. /* initialize */ Initialize,
  162. /* initialize_hook */ NULL,
  163. /* realize */ Realize,
  164. /* actions */ actionsList,
  165. /* num_actions */ XtNumber(actionsList),
  166. /* resources */ resources,
  167. /* resource_count */ XtNumber(resources),
  168. /* xrm_class */ NULLQUARK,
  169. /* compress_motion */ TRUE,
  170. /* compress_exposure */ TRUE,
  171. /* compress_enterleave */ TRUE,
  172. /* visible_interest */ FALSE,
  173. /* destroy */ Destroy,
  174. /* resize */ NULL,
  175. /* expose */ Redisplay,
  176. /* set_values */ SetValues,
  177. /* set_values_hook */ NULL,
  178. /* set_values_almost */ XtInheritSetValuesAlmost,
  179. /* get_values_hook */ NULL,
  180. /* accept_focus */ NULL,
  181. /* version */ XtVersion,
  182. /* callback_private */ NULL,
  183. /* tm_table */ defaultTranslations,
  184. /* query_geometry */ XtInheritQueryGeometry,
  185. /* display_accelerator */ XtInheritDisplayAccelerator,
  186. /* extension */ NULL
  187. },
  188. { /* simple fields */
  189. /* change_sensitive */ XtInheritChangeSensitive
  190. },
  191. { /* mailbox fields */
  192. /* ignore */ 0
  193. }
  194. };
  195. WidgetClass mailboxWidgetClass = (WidgetClass) &mailboxClassRec;
  196. /*
  197. * widget initialization
  198. */
  199. static GC get_mailbox_gc (MailboxWidget w)
  200. {
  201. XtGCMask valuemask;
  202. XGCValues xgcv;
  203. valuemask = GCForeground | GCBackground | GCFunction | GCGraphicsExposures;
  204. xgcv.foreground = w->mailbox.foreground_pixel;
  205. xgcv.background = w->core.background_pixel;
  206. xgcv.function = GXcopy;
  207. xgcv.graphics_exposures = False; /* this is Bool, not Boolean */
  208. return (XtGetGC ((Widget) w, valuemask, &xgcv));
  209. }
  210. /* ARGSUSED */
  211. static void Initialize (Widget request, Widget new,
  212. ArgList args, Cardinal *num_args)
  213. {
  214. MailboxWidget w = (MailboxWidget) new;
  215. int shape_event_base, shape_error_base;
  216. if (w->core.width <= 0) w->core.width = 1;
  217. if (w->core.height <= 0) w->core.height = 1;
  218. if (w->mailbox.shapeit && !XShapeQueryExtension (XtDisplay (w),
  219. &shape_event_base,
  220. &shape_error_base))
  221. w->mailbox.shapeit = False;
  222. w->mailbox.shape_cache.mask = None;
  223. w->mailbox.gc = get_mailbox_gc (w);
  224. w->mailbox.interval_id = (XtIntervalId) 0;
  225. w->mailbox.full.pixmap = None;
  226. w->mailbox.empty.pixmap = None;
  227. w->mailbox.flag_up = FALSE;
  228. w->mailbox.last_size = 0;
  229. if (!w->mailbox.filename) GetMailFile (w);
  230. return;
  231. }
  232. /*
  233. * action procedures
  234. */
  235. /*
  236. * pretend there is new mail; put widget in flagup state
  237. */
  238. /* ARGSUSED */
  239. static void Set (Widget gw, XEvent *event, String *params, Cardinal *nparams)
  240. {
  241. MailboxWidget w = (MailboxWidget) gw;
  242. w->mailbox.last_size = -1;
  243. check_mailbox (w, TRUE, FALSE); /* redraw, no reset */
  244. }
  245. /*
  246. * ack the existing mail; put widget in flagdown state
  247. */
  248. /* ARGSUSED */
  249. static void Unset (Widget gw, XEvent *event, String *params, Cardinal *nparams)
  250. {
  251. MailboxWidget w = (MailboxWidget) gw;
  252. check_mailbox (w, TRUE, TRUE); /* redraw, reset */
  253. }
  254. /*
  255. * look to see if there is new mail; if so, Set, else Unset
  256. */
  257. /* ARGSUSED */
  258. static void Check (Widget gw, XEvent *event, String *params, Cardinal *nparams)
  259. {
  260. MailboxWidget w = (MailboxWidget) gw;
  261. check_mailbox (w, TRUE, FALSE); /* redraw, no reset */
  262. }
  263. /* ARGSUSED */
  264. static void clock_tic (XtPointer client_data, XtIntervalId *id)
  265. {
  266. MailboxWidget w = (MailboxWidget) client_data;
  267. check_mailbox (w, FALSE, FALSE); /* no redraw, no reset */
  268. /*
  269. * and reset the timer
  270. */
  271. w->mailbox.interval_id =
  272. XtAppAddTimeOut (XtWidgetToApplicationContext((Widget) w),
  273. w->mailbox.update * 1000, clock_tic, client_data);
  274. return;
  275. }
  276. static Pixmap make_pixmap (Display *dpy, MailboxWidget w, Pixmap bitmap,
  277. int depth, Boolean flip, int *widthp, int *heightp)
  278. {
  279. Window root;
  280. int x, y;
  281. unsigned int width, height, bw, dep;
  282. unsigned long fore, back;
  283. if (!XGetGeometry (dpy, bitmap, &root, &x, &y, &width, &height, &bw, &dep))
  284. return None;
  285. *widthp = (int) width;
  286. *heightp = (int) height;
  287. if (flip) {
  288. fore = w->core.background_pixel;
  289. back = w->mailbox.foreground_pixel;
  290. } else {
  291. fore = w->mailbox.foreground_pixel;
  292. back = w->core.background_pixel;
  293. }
  294. return XmuCreatePixmapFromBitmap (dpy, w->core.window, bitmap,
  295. width, height, depth, fore, back);
  296. }
  297. static void Realize (Widget gw, XtValueMask *valuemaskp,
  298. XSetWindowAttributes *attr)
  299. {
  300. MailboxWidget w = (MailboxWidget) gw;
  301. register Display *dpy = XtDisplay (w);
  302. int depth = w->core.depth;
  303. *valuemaskp |= (CWBitGravity | CWCursor);
  304. attr->bit_gravity = ForgetGravity;
  305. attr->cursor = XCreateFontCursor (dpy, XC_top_left_arrow);
  306. (*mailboxWidgetClass->core_class.superclass->core_class.realize)
  307. (gw, valuemaskp, attr);
  308. /*
  309. * build up the pixmaps that we'll put into the image
  310. */
  311. if (w->mailbox.full.bitmap == None) {
  312. w->mailbox.full.bitmap =
  313. XCreateBitmapFromData (dpy, w->core.window, (char *) mailfull_bits,
  314. mailfull_width, mailfull_height);
  315. }
  316. if (w->mailbox.empty.bitmap == None) {
  317. w->mailbox.empty.bitmap =
  318. XCreateBitmapFromData (dpy, w->core.window, (char *) mailempty_bits,
  319. mailempty_width, mailempty_height);
  320. }
  321. w->mailbox.empty.pixmap = make_pixmap (dpy, w, w->mailbox.empty.bitmap,
  322. depth, False,
  323. &w->mailbox.empty.width,
  324. &w->mailbox.empty.height);
  325. w->mailbox.full.pixmap = make_pixmap (dpy, w, w->mailbox.full.bitmap,
  326. depth, w->mailbox.flipit,
  327. &w->mailbox.full.width,
  328. &w->mailbox.full.height);
  329. if (w->mailbox.empty.mask == None && w->mailbox.full.mask == None)
  330. w->mailbox.shapeit = False;
  331. w->mailbox.interval_id =
  332. XtAppAddTimeOut (XtWidgetToApplicationContext((Widget) w),
  333. w->mailbox.update * 1000, clock_tic, (XtPointer) w);
  334. w->mailbox.shape_cache.mask = None;
  335. check_mailbox (w, TRUE, FALSE);
  336. return;
  337. }
  338. static void Destroy (Widget gw)
  339. {
  340. MailboxWidget w = (MailboxWidget) gw;
  341. Display *dpy = XtDisplay (gw);
  342. XtFree (w->mailbox.filename);
  343. if (w->mailbox.interval_id) XtRemoveTimeOut (w->mailbox.interval_id);
  344. XtReleaseGC(gw, w->mailbox.gc);
  345. #define freepix(p) if (p) XFreePixmap (dpy, p)
  346. freepix (w->mailbox.full.bitmap); /* until cvter does ref cnt */
  347. freepix (w->mailbox.full.mask); /* until cvter does ref cnt */
  348. freepix (w->mailbox.full.pixmap);
  349. freepix (w->mailbox.empty.bitmap); /* until cvter does ref cnt */
  350. freepix (w->mailbox.empty.mask); /* until cvter does ref cnt */
  351. freepix (w->mailbox.empty.pixmap);
  352. freepix (w->mailbox.shape_cache.mask);
  353. #undef freepix
  354. }
  355. static void Redisplay (Widget gw, XEvent *event, Region region)
  356. {
  357. MailboxWidget w = (MailboxWidget) gw;
  358. check_mailbox (w, TRUE, FALSE);
  359. }
  360. static void check_mailbox (MailboxWidget w, Boolean force_redraw, Boolean reset)
  361. {
  362. long mailboxsize = 0;
  363. Boolean readSinceLastWrite = FALSE;
  364. if (w->mailbox.check_command != NULL) {
  365. waitType wait_status;
  366. int check_status;
  367. #ifdef INTWAITTYPE
  368. wait_status = system(w->mailbox.check_command);
  369. #else
  370. wait_status.w_status = system(w->mailbox.check_command);
  371. #endif
  372. check_status = waitCode(wait_status);
  373. /* error in sh checkCommand execution */
  374. if (waitSig(wait_status))
  375. check_status = 2; /* act as if there is no mail */
  376. switch (check_status) {
  377. case 0:
  378. mailboxsize = w->mailbox.last_size + 1;
  379. break;
  380. case 2:
  381. mailboxsize = 0;
  382. break;
  383. default: /* treat everything else as no change */
  384. /* case 1 is no change */
  385. mailboxsize = w->mailbox.last_size;
  386. }
  387. } else {
  388. struct stat st;
  389. if (stat (w->mailbox.filename, &st) == 0) {
  390. mailboxsize = st.st_size;
  391. readSinceLastWrite = (st.st_atime > st.st_mtime);
  392. }
  393. }
  394. /*
  395. * Now check for changes. If reset is set then we want to pretent that
  396. * there is no mail. If the mailbox is empty then we want to turn off
  397. * the flag. Otherwise if the mailbox has changed size then we want to
  398. * put the flag up, unless the mailbox has been read since the last
  399. * write.
  400. *
  401. * The cases are:
  402. * o forced reset by user DOWN
  403. * o no mailbox or empty (zero-sized) mailbox DOWN
  404. * o if read after most recent write DOWN
  405. * o same size as last time no change
  406. * o bigger than last time UP
  407. * o smaller than last time but non-zero UP
  408. *
  409. * The last two cases can be expressed as different from last
  410. * time and non-zero.
  411. */
  412. if (reset) { /* forced reset */
  413. w->mailbox.flag_up = FALSE;
  414. force_redraw = TRUE;
  415. } else if (mailboxsize == 0) { /* no mailbox or empty */
  416. w->mailbox.flag_up = FALSE;
  417. if (w->mailbox.last_size > 0) force_redraw = TRUE; /* if change */
  418. } else if (readSinceLastWrite) { /* only when checkCommand is NULL */
  419. /* mailbox has been read after most recent write */
  420. if (w->mailbox.flag_up) {
  421. w->mailbox.flag_up = FALSE;
  422. force_redraw = TRUE;
  423. }
  424. } else if (mailboxsize != w->mailbox.last_size) { /* different size */
  425. if (!w->mailbox.once_only || !w->mailbox.flag_up)
  426. beep(w);
  427. if (!w->mailbox.flag_up)
  428. force_redraw = w->mailbox.flag_up = TRUE;
  429. }
  430. w->mailbox.last_size = mailboxsize;
  431. if (force_redraw) redraw_mailbox (w);
  432. return;
  433. }
  434. /*
  435. * get user name for building mailbox
  436. */
  437. static void GetMailFile (MailboxWidget w)
  438. {
  439. char *username;
  440. char *mailpath;
  441. #ifdef WIN32
  442. if (!(username = getenv("USERNAME"))) {
  443. fprintf (stderr, "%s: unable to find a username for you.\n",
  444. "Mailbox widget");
  445. CloseDown (w, 1);
  446. }
  447. #else
  448. username = getlogin ();
  449. if (!username) {
  450. struct passwd *pw = getpwuid (getuid ());
  451. if (!pw) {
  452. fprintf (stderr, "%s: unable to find a username for you.\n",
  453. "Mailbox widget");
  454. CloseDown (w, 1);
  455. }
  456. username = pw->pw_name;
  457. }
  458. #endif
  459. if ((mailpath = getenv("MAIL"))) {
  460. w->mailbox.filename = (String) XtMalloc (strlen (mailpath) + 1);
  461. strcpy (w->mailbox.filename, mailpath);
  462. } else {
  463. w->mailbox.filename = (String) XtMalloc (strlen (MAILBOX_DIRECTORY) + 1
  464. + strlen (username) + 1);
  465. strcpy (w->mailbox.filename, MAILBOX_DIRECTORY);
  466. strcat (w->mailbox.filename, "/");
  467. strcat (w->mailbox.filename, username);
  468. }
  469. return;
  470. }
  471. static void CloseDown (MailboxWidget w, int status)
  472. {
  473. Display *dpy = XtDisplay (w);
  474. XtDestroyWidget ((Widget)w);
  475. XCloseDisplay (dpy);
  476. exit (status);
  477. }
  478. /* ARGSUSED */
  479. static Boolean SetValues (Widget gcurrent, Widget grequest, Widget gnew,
  480. ArgList args, Cardinal *num_args)
  481. {
  482. MailboxWidget current = (MailboxWidget) gcurrent;
  483. MailboxWidget new = (MailboxWidget) gnew;
  484. Boolean redisplay = FALSE;
  485. if (current->mailbox.update != new->mailbox.update) {
  486. if (current->mailbox.interval_id)
  487. XtRemoveTimeOut (current->mailbox.interval_id);
  488. new->mailbox.interval_id =
  489. XtAppAddTimeOut (XtWidgetToApplicationContext(gnew),
  490. new->mailbox.update * 1000, clock_tic,
  491. (XtPointer) gnew);
  492. }
  493. if (current->mailbox.foreground_pixel != new->mailbox.foreground_pixel ||
  494. current->core.background_pixel != new->core.background_pixel) {
  495. XtReleaseGC (gcurrent, current->mailbox.gc);
  496. new->mailbox.gc = get_mailbox_gc (new);
  497. redisplay = TRUE;
  498. }
  499. return (redisplay);
  500. }
  501. /*
  502. * drawing code
  503. */
  504. static void redraw_mailbox (MailboxWidget w)
  505. {
  506. register Display *dpy = XtDisplay (w);
  507. register Window win = XtWindow (w);
  508. register int x, y;
  509. GC gc = w->mailbox.gc;
  510. Pixel back = w->core.background_pixel;
  511. struct _mbimage *im;
  512. /* center the picture in the window */
  513. if (w->mailbox.flag_up) { /* paint the "up" position */
  514. im = &w->mailbox.full;
  515. if (w->mailbox.flipit) back = w->mailbox.foreground_pixel;
  516. } else { /* paint the "down" position */
  517. im = &w->mailbox.empty;
  518. }
  519. x = (((int)w->core.width) - im->width) / 2;
  520. y = (((int)w->core.height) - im->height) / 2;
  521. XSetWindowBackground (dpy, win, back);
  522. XClearWindow (dpy, win);
  523. XCopyArea (dpy, im->pixmap, win, gc, 0, 0, im->width, im->height, x, y);
  524. /*
  525. * XXX - temporary hack; walk up widget tree to find top most parent (which
  526. * will be a shell) and mash it to have our shape. This will be replaced
  527. * by a special shell widget.
  528. */
  529. if (w->mailbox.shapeit) {
  530. Widget parent;
  531. for (parent = (Widget) w; XtParent(parent);
  532. parent = XtParent(parent)) {
  533. x += parent->core.x + parent->core.border_width;
  534. y += parent->core.y + parent->core.border_width;
  535. }
  536. if (im->mask != w->mailbox.shape_cache.mask ||
  537. x != w->mailbox.shape_cache.x || y != w->mailbox.shape_cache.y) {
  538. XShapeCombineMask (XtDisplay(parent), XtWindow(parent),
  539. ShapeBounding, x, y, im->mask, ShapeSet);
  540. w->mailbox.shape_cache.mask = im->mask;
  541. w->mailbox.shape_cache.x = x;
  542. w->mailbox.shape_cache.y = y;
  543. }
  544. }
  545. return;
  546. }
  547. static void beep (MailboxWidget w)
  548. {
  549. XBell (XtDisplay (w), w->mailbox.volume);
  550. return;
  551. }