2 * WMLongRun - A dockapp to monitor LongRun status
3 * Copyright (C) 2001,2002 Seiichi SATO <ssato@sh.rim.or.jp>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #if defined(HAVE_STRING_H)
28 #elif defined(HAVE_STRINGS_H)
38 #include "backdrop_on.xpm"
39 #include "backdrop_off.xpm"
40 #include "backdrop_led.xpm"
44 #define WINDOWED_BG " \tc #AEAAAE"
46 typedef enum { LIGHTON
, LIGHTOFF
} light
;
54 static char *display_name
= "";
55 static char *light_color
= NULL
;
56 static unsigned update_interval
= 500;
57 static light backlight
= LIGHTOFF
;
58 static Bool is_led_style
= False
;
60 static char *cpuid_dev
= NULL
;
61 static char *msr_dev
= NULL
;
64 static void switch_light(void);
65 static void update(void);
66 static void parse_arguments(int argc
, char **argv
);
67 static void print_help(char *prog
);
69 int main(int argc
, char **argv
)
72 XpmColorSymbol colors
[2] = { {"Back0", NULL
, 0}, {"Back1", NULL
, 0} };
75 /* Parse CommandLine */
76 parse_arguments(argc
, argv
);
78 /* Initialize Application */
79 dockapp_open_window(display_name
, PACKAGE
, SIZE
, SIZE
, argc
, argv
);
80 dockapp_set_eventmask(ButtonPressMask
);
83 colors
[0].pixel
= dockapp_getcolor(light_color
);
84 colors
[1].pixel
= dockapp_blendedcolor(light_color
, -24, -24, -24, 1.0);
88 /* change raw xpm data to pixmap */
89 if (dockapp_iswindowed
)
90 backdrop_on_xpm
[1] = backdrop_off_xpm
[1] = WINDOWED_BG
;
92 dockapp_xpm2pixmap(backdrop_on_xpm
, &backdrop_on
, &mask
, colors
,ncolor
);
93 dockapp_xpm2pixmap(backdrop_off_xpm
, &backdrop_off
, NULL
, NULL
, 0);
95 dockapp_xpm2pixmap(backdrop_led_xpm
, &backdrop_led
, &mask
, colors
, ncolor
);
97 dockapp_xpm2pixmap(parts_xpm
, &parts
, NULL
, colors
, ncolor
);
99 if (!dockapp_iswindowed
)
100 dockapp_setshape(mask
, 0, 0);
101 if (mask
) XFreePixmap(display
, mask
);
102 /* pixmap: draw area */
103 pixmap
= dockapp_XCreatePixmap(SIZE
, SIZE
);
105 /* Initialize pixmap */
106 longrun_init(cpuid_dev
, msr_dev
);
108 dockapp_set_background(pixmap
);
113 if (dockapp_nextevent_or_timeout(&event
, update_interval
)) {
117 if (!is_led_style
) { /* led does not have back-light */
122 default: /* make gcc happy */
134 /* called when mouse button pressed */
135 static void switch_light(void)
142 backlight
= LIGHTOFF
;
148 static void update(void)
150 static int percent
; /* LongRun performance level */
151 static int flags
; /* LongRun flags */
152 static int mhz
; /* LongRun frequency */
153 static int voltz
; /* LongRun voltage */
155 int digit1
= 0, digit10
= 0, digit100
= 0;
157 longrun_get_stat(&percent
, &flags
, &mhz
, &voltz
);
159 digit100
= mhz
/ 100;
160 digit10
= (mhz
- digit100
* 100) / 10;
161 digit1
= mhz
- digit100
* 100 - digit10
* 10;
165 int y_lrmode
= 0, y_gauge
= 0, y_digit
= 0;
170 dockapp_copyarea(backdrop_on
, pixmap
, 0, 0, 58, 58, 0, 0);
176 dockapp_copyarea(backdrop_off
, pixmap
, 0, 0, 58, 58, 0, 0);
180 /* longrun flags (performance or economy) */
182 case LONGRUN_FLAGS_PEFORMANCE
:
183 dockapp_copyarea(parts
, pixmap
, 24, y_lrmode
, 24, 11, 31, 5);
185 case LONGRUN_FLAGS_ECONOMY
:
186 dockapp_copyarea(parts
, pixmap
, 0, y_lrmode
, 24, 11, 5, 5);
189 break; /* make gcc happy */
192 /* draw digit (frequency) */
193 dockapp_copyarea(parts
, pixmap
, digit100
*7,y_digit
+33, 7,13, 6,22);
194 dockapp_copyarea(parts
, pixmap
, digit10
*7,y_digit
+33, 7,13, 15,22);
195 dockapp_copyarea(parts
, pixmap
, digit1
*7,y_digit
+33, 7,13, 24,22);
197 /* draw level gauge */
198 dockapp_copyarea(parts
, pixmap
, 0,y_gauge
+72, 49*percent
/100,14,5,40);
203 dockapp_copyarea(backdrop_led
, pixmap
, 0, 0, 58, 58, 0, 0);
204 /* longrun flags (performance or economy) */
206 case LONGRUN_FLAGS_PEFORMANCE
:
207 dockapp_copyarea(parts
, pixmap
, 24, 22, 24, 11, 30, 3);
209 case LONGRUN_FLAGS_ECONOMY
:
210 dockapp_copyarea(parts
, pixmap
, 0, 22, 24, 11, 3, 3);
213 break; /* make gcc happy */
216 /* draw digit (frequency) */
217 dockapp_copyarea(parts
, pixmap
, digit100
*7,59, 7,13, 4,22);
218 dockapp_copyarea(parts
, pixmap
, digit10
*7,59, 7,13, 13,22);
219 dockapp_copyarea(parts
, pixmap
, digit1
*7,59, 7,13, 22,22);
221 /* draw level gauge */
222 dockapp_copyarea(parts
, pixmap
, 0, 100, 56 * percent
/ 100, 16, 1, 41);
226 dockapp_copy2window(pixmap
);
229 static void parse_arguments(int argc
, char **argv
)
232 for (i
= 1; i
< argc
; i
++) {
233 if (!strcmp(argv
[i
], "--help") || !strcmp(argv
[i
], "-h"))
234 print_help(argv
[0]), exit(0);
236 else if (!strcmp(argv
[i
], "--version") || !strcmp(argv
[i
], "-v"))
237 printf("%s version %s\n", PACKAGE
, VERSION
), exit(0);
239 else if (!strcmp(argv
[i
], "--display") || !strcmp(argv
[i
], "-d")) {
240 display_name
= argv
[i
+ 1];
244 else if (!strcmp(argv
[i
], "--backlight")
245 || !strcmp(argv
[i
], "-bl"))
248 else if (!strcmp(argv
[i
], "--light-color")
249 || !strcmp(argv
[i
], "-lc")) {
252 "%s: error parsing argument for option %s\n",
253 argv
[0], argv
[i
]), exit(1);
254 light_color
= argv
[i
+ 1];
258 else if (!strcmp(argv
[i
], "--interval") || !strcmp(argv
[i
], "-i")) {
262 "%s: error parsing argument for option %s\n",
263 argv
[0], argv
[i
]), exit(1);
264 if (sscanf(argv
[i
+ 1], "%i", &integer
) != 1)
266 "%s: error parsing argument for option %s\n",
267 argv
[0], argv
[i
]), exit(1);
269 fprintf(stderr
, "%s: argument %s must be >=1\n",
270 argv
[0], argv
[i
]), exit(1);
271 update_interval
= integer
;
275 else if (!strcmp(argv
[i
], "--led") || !strcmp(argv
[i
], "-l"))
278 else if (!strcmp(argv
[i
], "--windowed")
279 || !strcmp(argv
[i
], "-w"))
280 dockapp_iswindowed
= True
;
282 else if (!strcmp(argv
[i
], "--broken-wm")
283 || !strcmp(argv
[i
], "-bw"))
284 dockapp_isbrokenwm
= True
;
287 else if (!strcmp(argv
[i
], "--cpuid-device")
288 || !strcmp(argv
[i
], "-cd")) {
289 cpuid_dev
= argv
[i
+ 1];
292 else if (!strcmp(argv
[i
], "--msr-device")
293 || !strcmp(argv
[i
], "-md")) {
294 msr_dev
= argv
[i
+ 1];
300 fprintf(stderr
, "%s: unrecognized option '%s'\n", argv
[0],
302 print_help(argv
[0]), exit(1);
307 static void print_help(char *prog
)
309 printf("Usage : %s [OPTIONS]\n", prog
);
311 ("WMLongRun - A dockapp to monitor the LongRun(tm) status on Crusoe(tm) processors.\n");
312 printf(" -d, --display <string> display to use\n");
313 printf(" -bl, --backlight turn on back-light\n");
314 printf(" -lc, --light-color <string> back-light color(rgb:6E/C6/3B is default)\n");
315 printf(" -i, --interval <number> number of milliseconds between updates\n");
316 printf(" (500 is default)\n");
318 printf(" -cd, --cpuid-device <device> CPUID device ('/dev/cpu/0/cpuid' is default)\n");
319 printf(" -md, --msr-device <device> MSR device ('/dev/cpu/0/msr' is default)\n");
321 printf(" -l, --led run the application with LED interface\n");
322 printf(" -h, --help show this help text and exit\n");
323 printf(" -v, --version show program version and exit\n");
324 printf(" -w, --windowed run the application in windowed mode\n");
325 printf(" -bw, --broken-wm activate broken window manager fix\n");