icewm.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. --- src/aapm.cc.orig Sat Jan 4 01:25:45 2003
  2. +++ src/aapm.cc Mon Jan 6 19:00:50 2003
  3. @@ -26,6 +26,13 @@
  4. #include <string.h>
  5. #include <stdio.h>
  6. +#ifdef __FreeBSD__
  7. +#include <sys/file.h>
  8. +#include <sys/ioctl.h>
  9. +#include <sys/types.h>
  10. +#include <machine/apm_bios.h>
  11. +#endif
  12. +
  13. YColor *YApm::apmBg = 0;
  14. YColor *YApm::apmFg = 0;
  15. YFont *YApm::apmFont = 0;
  16. @@ -47,8 +54,12 @@
  17. void ApmStr(char *s, bool Tool) {
  18. +#ifdef __FreeBSD__
  19. + struct apm_info ai;
  20. +#else
  21. char buf[80];
  22. - int len, i, fd = open("/proc/apm", O_RDONLY);
  23. +#endif
  24. + int len, i, fd = open(APMDEV, O_RDONLY);
  25. char driver[16];
  26. char apmver[16];
  27. int apmflags;
  28. @@ -60,9 +71,27 @@
  29. char units[16];
  30. if (fd == -1) {
  31. + static int error = 0;
  32. + if (!error)
  33. + perror("Can't open the apm device");
  34. + error = 1;
  35. return ;
  36. }
  37. -
  38. +#ifdef __FreeBSD__
  39. + if (ioctl(fd,APMIO_GETINFO, &ai) == -1)
  40. + {
  41. + static int error = 0;
  42. + if (!error)
  43. + perror("Can't ioctl the apm device");
  44. + error = 1;
  45. + close(fd);
  46. + return;
  47. + }
  48. + close(fd);
  49. + BATlife = ai.ai_batt_life;
  50. + ACstatus = ai.ai_acline ;
  51. + BATflag = ai.ai_batt_stat == 3 ? 8 : 0;
  52. +#else
  53. len = read(fd, buf, sizeof(buf) - 1);
  54. close(fd);
  55. @@ -76,10 +105,11 @@
  56. static int error = 1;
  57. if (error) {
  58. error = 0;
  59. - warn(_("/proc/apm - unknown format (%d)"), i);
  60. + warn(_("%s - unknown format (%d)"), APMDEV, i);
  61. }
  62. return ;
  63. }
  64. +#endif
  65. if (BATlife == -1)
  66. BATlife = 0;
  67. --- src/apppstatus.cc.orig Sat Mar 17 00:17:37 2001
  68. +++ src/apppstatus.cc Thu Apr 5 22:45:29 2001
  69. @@ -270,6 +270,7 @@
  70. return isUpIsdn();
  71. #endif
  72. +#ifndef __FreeBSD__
  73. char buffer[32 * sizeof(struct ifreq)];
  74. struct ifconf ifc;
  75. struct ifreq *ifr;
  76. @@ -301,6 +302,38 @@
  77. }
  78. close(s);
  79. +
  80. +#else // __FreeBSD__
  81. + // FreeBSD code by Ronald Klop <ronald@cs.vu.nl>
  82. + struct ifmibdata ifmd;
  83. + size_t ifmd_size=sizeof(ifmibdata);
  84. + int nr_network_devs;
  85. + size_t int_size=sizeof(int);
  86. + int name[6];
  87. + name[0] = CTL_NET;
  88. + name[1] = PF_LINK;
  89. + name[2] = NETLINK_GENERIC;
  90. + name[3] = IFMIB_IFDATA;
  91. + name[5] = IFDATA_GENERAL;
  92. +
  93. + if(sysctlbyname("net.link.generic.system.ifcount",&nr_network_devs,
  94. + &int_size,(void*)0,0) == -1) {
  95. + printf("%s@%d: %s\n",__FILE__,__LINE__,strerror(errno));
  96. + } else {
  97. + for(int i=1;i<=nr_network_devs;i++) {
  98. + name[4] = i; /* row of the ifmib table */
  99. +
  100. + if(sysctl(name, 6, &ifmd, &ifmd_size, (void *)0, 0) == -1) {
  101. + printf(_("%s@%d: %s\n"),__FILE__,__LINE__,strerror(errno));
  102. + continue;
  103. + }
  104. +
  105. + if (strcmp(ifmd.ifmd_name, netDevice) == 0 && (ifmd.ifmd_flags & IFF_RUNNING)) {
  106. + return true;
  107. + }
  108. + }
  109. + }
  110. +#endif // __FreeBSD__
  111. return false;
  112. #endif // if 0
  113. }
  114. --- src/ylocale.cc.orig Tue Oct 9 23:54:04 2001
  115. +++ src/ylocale.cc Wed Feb 20 17:32:28 2002
  116. @@ -18,7 +18,9 @@
  117. #ifdef CONFIG_I18N
  118. #include <errno.h>
  119. +#if __FreeBSD__ >= 5
  120. #include <langinfo.h>
  121. +#endif
  122. #include <locale.h>
  123. #include <stdlib.h>
  124. #include <string.h>
  125. @@ -31,6 +33,41 @@
  126. YLocale * YLocale::locale(NULL);
  127. #endif
  128. +#ifdef CONFIG_I18N
  129. +#if __FreeBSD__ < 5
  130. +#undef CONFIG_NL_CODESETS
  131. +#define CONFIG_NL_CODESETS 0
  132. +char* icewm_nl_langinfo(void* item) {
  133. + char* mylocale = setlocale(LC_ALL, "");
  134. +
  135. + if( mylocale == NULL || *mylocale == '\0' )
  136. + return NULL;
  137. +
  138. + if( strncmp(mylocale, "ja", strlen("ja")) == 0 ) {
  139. + return strdup("EUC-JP");
  140. + } if( strncmp(mylocale, "zh_TW", strlen("zh_TW")) == 0 ) {
  141. + return strdup("BIG5");
  142. + } if( strncmp(mylocale, "ko", strlen("ko")) == 0 ) {
  143. + return strdup("EUC-KR");
  144. + } if( strncmp(mylocale, "ru", strlen("ru")) == 0 ) {
  145. + return "KOI8-R";
  146. + } if( strncmp(mylocale, "ro", strlen("ro")) == 0 ) {
  147. + return "ISO-8859-2";
  148. + } if( strncmp(mylocale, "hr", strlen("hr")) == 0 ) {
  149. + return "ISO-8859-2";
  150. + } if( strncmp(mylocale, "hu", strlen("hu")) == 0 ) {
  151. + return "ISO-8859-2";
  152. + } if( strncmp(mylocale, "pl", strlen("pl")) == 0 ) {
  153. + return "ISO-8859-2";
  154. + } if( strncmp(mylocale, "lt", strlen("lt")) == 0 ) {
  155. + return "ISO-8859-13";
  156. + }
  157. +
  158. + return NULL;
  159. +}
  160. +#endif
  161. +#endif /* CONFIG_I18N */
  162. +
  163. #ifndef CONFIG_I18N
  164. YLocale::YLocale(char const * ) {
  165. #else
  166. @@ -45,8 +82,12 @@
  167. char const * codeset("");
  168. int const codesetItems[] = { CONFIG_NL_CODESETS };
  169. +#if __FreeBSD__ >= 5
  170. for (int const * csi(codesetItems); *csi &&
  171. NULL != (codeset = nl_langinfo(*csi)) && '\0' == *codeset; ++csi);
  172. +#else
  173. + codeset = icewm_nl_langinfo(NULL);
  174. +#endif
  175. if (NULL == codeset || '\0' == *codeset) {
  176. warn(_("Failed to determinate the current locale's codeset. "
  177. --- src/sysdep.h.orig Tue Oct 9 23:54:03 2001
  178. +++ src/sysdep.h Wed Feb 20 15:22:43 2002
  179. @@ -57,7 +57,9 @@
  180. #ifdef CONFIG_I18N
  181. #include <locale.h>
  182. +#if __FreeBSD__ >= 5
  183. #include <langinfo.h>
  184. +#endif
  185. #endif
  186. #endif
  187. --- src/acpustatus.cc.orig Sun Mar 9 04:37:52 2003
  188. +++ src/acpustatus.cc Thu Apr 24 05:09:50 2003
  189. @@ -26,7 +26,16 @@
  190. #include "intl.h"
  191. -#if (defined(linux) || defined(HAVE_KSTAT_H))
  192. +#if (defined(linux) || defined(HAVE_KSTAT_H) || defined(__FreeBSD__))
  193. +
  194. +#ifdef __FreeBSD__
  195. +#include <fcntl.h>
  196. +#include <kvm.h>
  197. +#include <nlist.h>
  198. +#include <sys/dkstat.h>
  199. +#include <sys/resource.h>
  200. +#include <devstat.h>
  201. +#endif
  202. #define UPDATE_INTERVAL 500
  203. @@ -49,13 +58,42 @@
  204. color[IWM_SYS] = new YColor(clrCpuSys);
  205. color[IWM_IDLE] = *clrCpuIdle
  206. ? new YColor(clrCpuIdle) : NULL;
  207. -
  208. +#ifdef __FreeBSD__
  209. + color[IWM_INTR] = new YColor(clrCpuIntr);
  210. + for (unsigned int i = 0; i < taskBarCPUSamples; i++) {
  211. + cpu[i][IWM_USER] = cpu[i][IWM_NICE] =
  212. + cpu[i][IWM_SYS] = cpu[i][IWM_INTR] = 0;
  213. + cpu[i][IWM_IDLE] = 1;
  214. + }
  215. + setSize(taskBarCPUSamples, 20);
  216. + last_cpu[IWM_USER] = last_cpu[IWM_NICE] = last_cpu[IWM_SYS] =
  217. + last_cpu[IWM_IDLE] = last_cpu[IWM_INTR] = 0;
  218. + if( setegid( 2 ) == 0 ) {
  219. + char errbuf[_POSIX2_LINE_MAX];
  220. + kd = kvm_openfiles( NULL, NULL, NULL, O_RDONLY, errbuf );
  221. + setegid( getgid() );
  222. + if( kd == NULL )
  223. + fprintf( stderr, "kvm_openfiles: %s\n", errbuf );
  224. + else {
  225. + memset( namelist, 0, sizeof(namelist) );
  226. + namelist[0].n_name = (char*)("_cp_time");
  227. + if( kvm_nlist( kd, namelist ) != 0 ) {
  228. + kvm_close( kd );
  229. + kd = NULL;
  230. + }
  231. + }
  232. + } else {
  233. + fprintf( stderr, "can't setegid(2), I'm not a setgid exec ?\n" );
  234. + kd = NULL;
  235. + }
  236. +#else
  237. for (int i(0); i < taskBarCPUSamples; i++) {
  238. cpu[i][IWM_USER] = cpu[i][IWM_NICE] = cpu[i][IWM_SYS] = 0;
  239. cpu[i][IWM_IDLE] = 1;
  240. }
  241. setSize(taskBarCPUSamples, 20);
  242. last_cpu[IWM_USER] = last_cpu[IWM_NICE] = last_cpu[IWM_SYS] = last_cpu[IWM_IDLE] = 0;
  243. +#endif
  244. getStatus();
  245. updateStatus();
  246. updateToolTip();
  247. @@ -70,6 +108,13 @@
  248. delete color[IWM_NICE]; color[IWM_NICE] = 0;
  249. delete color[IWM_SYS]; color[IWM_SYS] = 0;
  250. delete color[IWM_IDLE]; color[IWM_IDLE] = 0;
  251. +#ifdef __FreeBSD__
  252. + delete color[IWM_INTR]; color[IWM_INTR] = 0;
  253. + if( kd != NULL ) {
  254. + kvm_close( kd );
  255. + kd = NULL;
  256. + }
  257. +#endif
  258. }
  259. void CPUStatus::paint(Graphics &g, const YRect &/*r*/) {
  260. @@ -80,13 +125,34 @@
  261. int nice = cpu[i][IWM_NICE];
  262. int sys = cpu[i][IWM_SYS];
  263. int idle = cpu[i][IWM_IDLE];
  264. +#ifdef __FreeBSD__
  265. + int intr = cpu[i][IWM_INTR];
  266. + int total = user + sys + intr + nice + idle;
  267. + int totald = total;
  268. +#else
  269. int total = user + sys + nice + idle;
  270. +#endif
  271. int y = height() - 1;
  272. if (total > 0) {
  273. +#ifdef __FreeBSD__
  274. + if (intr) {
  275. + totald -= intr;
  276. + n = (h * totald) / total; // check rounding
  277. + if (n >= y) n = y;
  278. + g.setColor(color[IWM_INTR]);
  279. + g.drawLine(i, y, i, n);
  280. + y = n - 1;
  281. + }
  282. +#endif
  283. if (sys) {
  284. +#ifdef __FreeBSD__
  285. + totald -= nice;
  286. + n = (h * totald)/ total;
  287. +#else
  288. n = (h * (total - sys)) / total; // check rounding
  289. +#endif
  290. if (n >= y) n = y;
  291. g.setColor(color[IWM_SYS]);
  292. g.drawLine(i, y, i, n);
  293. @@ -102,7 +168,12 @@
  294. }
  295. if (user) {
  296. +#ifdef __FreeBSD__
  297. + totald -= user;
  298. + n = (h * totald)/ total;
  299. +#else
  300. n = (h * (total - sys - nice - user))/ total;
  301. +#endif
  302. if (n >= y) n = y;
  303. g.setColor(color[IWM_USER]);
  304. g.drawLine(i, y, i, n);
  305. @@ -152,6 +223,14 @@
  306. sprintf(load, _("CPU Load: %3.2f %3.2f %3.2f, %d processes."),
  307. l1, l5, l15, sys.procs);
  308. setToolTip(load);
  309. +#elif defined(__FreeBSD__)
  310. + char load[31]; // enough for "CPU Load: 999.99 999.99 999.99\0"
  311. + double loadavg[3];
  312. + if( kd != NULL && kvm_getloadavg( kd, loadavg, 3 ) != 3 )
  313. + return;
  314. + snprintf(load, sizeof(load), "CPU Load: %3.2f %3.2f %3.2f",
  315. + loadavg[0], loadavg[1], loadavg[2]);
  316. + setToolTip(load);
  317. #endif
  318. }
  319. @@ -169,13 +248,43 @@
  320. cpu[i - 1][IWM_NICE] = cpu[i][IWM_NICE];
  321. cpu[i - 1][IWM_SYS] = cpu[i][IWM_SYS];
  322. cpu[i - 1][IWM_IDLE] = cpu[i][IWM_IDLE];
  323. +#ifdef __FreeBSD__
  324. + cpu[i - 1][IWM_INTR] = cpu[i][IWM_INTR];
  325. +#endif
  326. }
  327. getStatus(),
  328. repaint();
  329. }
  330. void CPUStatus::getStatus() {
  331. -#ifdef linux
  332. +#ifdef __FreeBSD__
  333. +
  334. + cpu[taskBarCPUSamples-1][IWM_USER] = 0;
  335. + cpu[taskBarCPUSamples-1][IWM_NICE] = 0;
  336. + cpu[taskBarCPUSamples-1][IWM_SYS] = 0;
  337. + cpu[taskBarCPUSamples-1][IWM_INTR] = 0;
  338. + cpu[taskBarCPUSamples-1][IWM_IDLE] = 0;
  339. +
  340. + if( kd == NULL ) return;
  341. +
  342. + long cp_time[CPUSTATES];
  343. + int c = sizeof( cp_time );
  344. + if (kvm_read(kd, namelist[0].n_value, &cp_time, c) != c)
  345. + return;
  346. +
  347. + long cur[IWM_STATES];
  348. + cur[IWM_USER] = cp_time[CP_USER];
  349. + cur[IWM_NICE] = cp_time[CP_NICE];
  350. + cur[IWM_SYS] = cp_time[CP_SYS];
  351. + cur[IWM_INTR] = cp_time[CP_INTR];
  352. + cur[IWM_IDLE] = cp_time[CP_IDLE];
  353. +
  354. + for (int i = 0; i < IWM_STATES; i++) {
  355. + cpu[taskBarCPUSamples-1][i] = cur[i] - last_cpu[i];
  356. + last_cpu[i] = cur[i];
  357. + }
  358. +
  359. +#elif defined(linux)
  360. char *p, buf[128];
  361. long cur[IWM_STATES];
  362. int len, fd = open("/proc/stat", O_RDONLY);
  363. @@ -209,8 +318,8 @@
  364. cpu[taskBarCPUSamples-1][IWM_USER], cpu[taskBarCPUSamples-1][IWM_NICE],
  365. cpu[taskBarCPUSamples-1][IWM_SYS], cpu[taskBarCPUSamples-1][IDLE]);
  366. #endif
  367. -#endif /* linux */
  368. -#ifdef HAVE_KSTAT_H
  369. +
  370. +#elif defined(HAVE_KSTAT_H)
  371. #ifdef HAVE_OLD_KSTAT
  372. #define ui32 ul
  373. #endif
  374. --- src/acpustatus.h.orig Sun Mar 9 04:37:52 2003
  375. +++ src/acpustatus.h Sun Apr 13 12:02:47 2003
  376. @@ -1,19 +1,29 @@
  377. #ifndef __CPUSTATUS_H
  378. #define __CPUSTATUS_H
  379. -#if defined(linux) || defined(HAVE_KSTAT_H)
  380. +#if (defined(linux) || defined(HAVE_KSTAT_H)) || defined (__FreeBSD__)
  381. #ifdef HAVE_KSTAT_H
  382. #include <kstat.h>
  383. #include <sys/sysinfo.h>
  384. #endif /* have_kstat_h */
  385. +#ifdef __FreeBSD__
  386. +#include <kvm.h>
  387. +#include <nlist.h>
  388. +#endif
  389. #define IWM_USER (0)
  390. #define IWM_NICE (1)
  391. #define IWM_SYS (2)
  392. +#ifdef __FreeBSD__
  393. +#define IWM_INTR (3)
  394. +#define IWM_IDLE (4)
  395. +#define IWM_STATES (5)
  396. +#else
  397. #define IWM_IDLE (3)
  398. #define IWM_STATES (4)
  399. +#endif
  400. #include "ywindow.h"
  401. #include "ytimer.h"
  402. @@ -38,6 +48,10 @@
  403. long last_cpu[IWM_STATES];
  404. YColor *color[IWM_STATES];
  405. YTimer *fUpdateTimer;
  406. +#ifdef __FreeBSD__
  407. + struct nlist namelist[2];
  408. + kvm_t *kd;
  409. +#endif
  410. };
  411. #else
  412. #undef CONFIG_APPLET_CPU_STATUS
  413. --- src/default.h.orig Thu May 16 14:00:02 2002
  414. +++ src/default.h Tue May 28 04:44:02 2002
  415. @@ -455,6 +455,7 @@
  416. XSV(const char *, clrLabelText, "rgb:00/00/00")
  417. XSV(const char *, clrCpuUser, "rgb:00/FF/00")
  418. XSV(const char *, clrCpuSys, "rgb:FF/00/00")
  419. +XSV(const char *, clrCpuIntr, "rgb:FF/FF/00")
  420. XSV(const char *, clrCpuNice, "rgb:00/00/FF")
  421. XSV(const char *, clrCpuIdle, "rgb:00/00/00")
  422. XSV(const char *, clrNetSend, "rgb:FF/FF/00")
  423. @@ -837,6 +838,7 @@
  424. #ifdef CONFIG_APPLET_CPU_STATUS
  425. OSV("ColorCPUStatusUser", &clrCpuUser, "User load on the CPU monitor"),
  426. OSV("ColorCPUStatusSystem", &clrCpuSys, "System load on the CPU monitor"),
  427. + OSV("ColorCPUStatusInterrupts", &clrCpuIntr, "Interrupts on the CPU monitor"),
  428. OSV("ColorCPUStatusNice", &clrCpuNice, "Nice load on the CPU monitor"),
  429. OSV("ColorCPUStatusIdle", &clrCpuIdle, "Idle (non) load on the CPU monitor, leave empty to force transparency"),
  430. #endif
  431. --- src/wmapp.cc.orig Sun Mar 9 04:37:52 2003
  432. +++ src/wmapp.cc Sun Apr 13 00:09:19 2003
  433. @@ -1503,6 +1503,9 @@
  434. #endif
  435. int main(int argc, char **argv) {
  436. +#ifdef __FreeBSD__
  437. + setegid( getgid() );
  438. +#endif
  439. YLocale locale;
  440. #ifndef NO_CONFIGURE
  441. --- src/wmclient.h.orig Tue Mar 26 14:29:05 2002
  442. +++ src/wmclient.h Tue Mar 26 14:29:13 2002
  443. @@ -5,6 +5,8 @@
  444. #include "ymenu.h"
  445. #include "MwmUtil.h"
  446. +#include <X11/Xutil.h>
  447. +
  448. class YFrameWindow;
  449. class WindowListItem;