patch-xbattbar_c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. $OpenBSD: patch-xbattbar_c,v 1.2 2012/04/04 02:19:16 brynet Exp $
  2. --- xbattbar.c.orig Tue Apr 3 23:30:11 2012
  3. +++ xbattbar.c Tue Apr 3 23:30:17 2012
  4. @@ -29,6 +29,9 @@ static char *ReleaseVersion="1.4.2";
  5. #include <sys/time.h>
  6. #include <signal.h>
  7. #include <stdio.h>
  8. +#include <stdlib.h>
  9. +#include <string.h>
  10. +#include <time.h>
  11. #include <unistd.h>
  12. #include <sys/file.h>
  13. #include <sys/ioctl.h>
  14. @@ -67,6 +70,8 @@ char *ONOUT_C = "olive drab";
  15. char *OFFIN_C = "blue";
  16. char *OFFOUT_C = "red";
  17. +char *clockfmt = "%+";
  18. +int displayclock = False;
  19. int alwaysontop = False;
  20. struct itimerval IntervalTimer; /* APM polling interval timer */
  21. @@ -118,7 +123,7 @@ void usage(char **argv)
  22. fprintf(stderr,
  23. "\n"
  24. "usage:\t%s [-a] [-h|v] [-p sec] [-t thickness]\n"
  25. - "\t\t[-I color] [-O color] [-i color] [-o color]\n"
  26. + "\t\t[-I color] [-O color] [-i color] [-o color] [-T time-format]\n"
  27. "\t\t[ top | bottom | left | right ]\n"
  28. "-a: always on top.\n"
  29. "-v, -h: show this message.\n"
  30. @@ -126,6 +131,7 @@ void usage(char **argv)
  31. "-p: polling interval. [def: 10 sec.]\n"
  32. "-I, -O: bar colors in AC on-line. [def: \"green\" & \"olive drab\"]\n"
  33. "-i, -o: bar colors in AC off-line. [def: \"blue\" and \"red\"]\n"
  34. + "-T: show time in popup window. [def: %%+]\n"
  35. "top, bottom, left, right: bar localtion. [def: \"bottom\"]\n",
  36. argv[0]);
  37. exit(0);
  38. @@ -223,7 +229,7 @@ main(int argc, char **argv)
  39. int ch;
  40. about_this_program();
  41. - while ((ch = getopt(argc, argv, "at:f:hI:i:O:o:p:v")) != -1)
  42. + while ((ch = getopt(argc, argv, "at:f:hI:i:O:o:p:T::v")) != -1)
  43. switch (ch) {
  44. case 'a':
  45. alwaysontop = True;
  46. @@ -251,6 +257,12 @@ main(int argc, char **argv)
  47. bi_interval = atoi(optarg);
  48. break;
  49. + case 'T':
  50. + if (optarg)
  51. + clockfmt = optarg;
  52. + displayclock = 1;
  53. + break;
  54. +
  55. case 'h':
  56. case 'v':
  57. usage(argv);
  58. @@ -339,7 +351,14 @@ void showdiagbox(void)
  59. int pixw, pixh;
  60. int boxw, boxh;
  61. char diagmsg[64];
  62. + char timemsg[64];
  63. + time_t now;
  64. + /* compose time and date message */
  65. + if (displayclock) {
  66. + time(&now);
  67. + strftime(timemsg, 64, clockfmt, localtime(&now));
  68. + }
  69. /* compose diag message and calculate its size in pixels */
  70. sprintf(diagmsg,
  71. "AC %s-line: battery level is %d%%",
  72. @@ -349,6 +368,8 @@ void showdiagbox(void)
  73. pixh = fontp->ascent + fontp->descent;
  74. boxw = pixw + DiagXMergin * 2;
  75. boxh = pixh + DiagYMergin * 2;
  76. + if (displayclock)
  77. + boxh += pixh + DiagYMergin;
  78. /* create status window */
  79. if(winstat != -1) disposediagbox();
  80. @@ -367,6 +388,11 @@ void showdiagbox(void)
  81. gcstat,
  82. DiagXMergin, fontp->ascent+DiagYMergin,
  83. diagmsg, strlen(diagmsg));
  84. + if (displayclock)
  85. + XDrawString(disp, winstat, gcstat,
  86. + boxw/2 - XTextWidth(fontp, timemsg, strlen(timemsg))/2,
  87. + 2*fontp->ascent+2*DiagYMergin,
  88. + timemsg, strlen(timemsg));
  89. }
  90. void disposediagbox(void)
  91. @@ -575,7 +601,7 @@ void battery_check(void)
  92. #endif /* __FreeBSD__ */
  93. -#ifdef __NetBSD__
  94. +#if defined(__NetBSD__) || defined(__OpenBSD__)
  95. #include <machine/apmvar.h>