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"
41 #include "backdrop_on_g.xpm"
42 #include "backdrop_off_g.xpm"
43 #include "backdrop_led_g.xpm"
47 #define WINDOWED_BG " \tc #AEAAAE"
49 typedef enum { LIGHTON
, LIGHTOFF
} light
;
56 Pixmap backdrop_off_g
;
57 Pixmap backdrop_led_g
;
60 static char *display_name
= "";
61 static char *light_color
= NULL
;
62 static unsigned update_interval
= 500;
63 static light backlight
= LIGHTOFF
;
64 static Bool is_led_style
= False
;
66 static char *cpuid_dev
= NULL
;
67 static char *msr_dev
= NULL
;
70 static void switch_light(void);
71 static void update(void);
72 static void parse_arguments(int argc
, char **argv
);
73 static void print_help(char *prog
);
75 int main(int argc
, char **argv
)
78 XpmColorSymbol colors
[2] = { {"Back0", NULL
, 0}, {"Back1", NULL
, 0} };
81 /* Parse CommandLine */
82 parse_arguments(argc
, argv
);
84 /* Initialize Application */
85 dockapp_open_window(display_name
, PACKAGE
, SIZE
, SIZE
, argc
, argv
);
86 dockapp_set_eventmask(ButtonPressMask
);
89 colors
[0].pixel
= dockapp_getcolor(light_color
);
90 colors
[1].pixel
= dockapp_blendedcolor(light_color
, -24, -24, -24, 1.0);
94 /* change raw xpm data to pixmap */
95 if (dockapp_iswindowed
)
96 backdrop_on_xpm
[1] = backdrop_off_xpm
[1] = WINDOWED_BG
;
97 backdrop_on_g_xpm
[1] = backdrop_off_g_xpm
[1] = WINDOWED_BG
;
99 dockapp_xpm2pixmap(backdrop_on_xpm
, &backdrop_on
, &mask
, colors
,ncolor
);
100 dockapp_xpm2pixmap(backdrop_off_xpm
, &backdrop_off
, NULL
, NULL
, 0);
101 dockapp_xpm2pixmap(backdrop_on_g_xpm
, &backdrop_on_g
, &mask
, colors
,ncolor
);
102 dockapp_xpm2pixmap(backdrop_off_g_xpm
, &backdrop_off_g
, NULL
, NULL
, 0);
104 dockapp_xpm2pixmap(backdrop_led_xpm
, &backdrop_led
, &mask
, colors
, ncolor
);
105 dockapp_xpm2pixmap(backdrop_led_g_xpm
, &backdrop_led_g
, &mask
, colors
, ncolor
);
107 dockapp_xpm2pixmap(parts_xpm
, &parts
, NULL
, colors
, ncolor
);
109 if (!dockapp_iswindowed
)
110 dockapp_setshape(mask
, 0, 0);
111 if (mask
) XFreePixmap(display
, mask
);
112 /* pixmap: draw area */
113 pixmap
= dockapp_XCreatePixmap(SIZE
, SIZE
);
115 /* Initialize pixmap */
116 longrun_init(cpuid_dev
, msr_dev
);
118 dockapp_set_background(pixmap
);
123 if (dockapp_nextevent_or_timeout(&event
, update_interval
)) {
127 if (!is_led_style
) { /* led does not have back-light */
132 default: /* make gcc happy */
144 /* called when mouse button pressed */
145 static void switch_light(void)
152 backlight
= LIGHTOFF
;
158 static void update(void)
160 static int percent
; /* LongRun performance level */
161 static int flags
; /* LongRun flags */
162 static int mhz
; /* LongRun frequency */
163 static int voltz
; /* LongRun voltage */
165 int digit1
= 0, digit10
= 0, digit100
= 0, digit1000
=0;
167 longrun_get_stat(&percent
, &flags
, &mhz
, &voltz
);
169 digit1000
= mhz
/ 1000;
170 digit100
= (mhz
- digit1000
* 1000) / 100;
171 digit10
= (mhz
- digit1000
* 1000 - digit100
* 100) / 10;
172 digit1
= mhz
- digit1000
* 1000 - digit100
* 100 - digit10
* 10;
176 int y_lrmode
= 0, y_gauge
= 0, y_digit
= 0;
182 dockapp_copyarea(backdrop_on
, pixmap
, 0, 0, 58, 58, 0, 0);
185 dockapp_copyarea(backdrop_on_g
, pixmap
, 0, 0, 58, 58, 0, 0);
193 dockapp_copyarea(backdrop_off
, pixmap
, 0, 0, 58, 58, 0, 0);
196 dockapp_copyarea(backdrop_off_g
, pixmap
, 0, 0, 58, 58, 0, 0);
201 /* longrun flags (performance or economy) */
203 case LONGRUN_FLAGS_PEFORMANCE
:
204 dockapp_copyarea(parts
, pixmap
, 24, y_lrmode
, 24, 11, 31, 5);
206 case LONGRUN_FLAGS_ECONOMY
:
207 dockapp_copyarea(parts
, pixmap
, 0, y_lrmode
, 24, 11, 5, 5);
210 break; /* make gcc happy */
213 /* draw digit (frequency) */
215 dockapp_copyarea(parts
, pixmap
, digit100
*7,y_digit
+33, 7,13, 6,22);
216 dockapp_copyarea(parts
, pixmap
, digit10
*7,y_digit
+33, 7,13, 15,22);
217 dockapp_copyarea(parts
, pixmap
, digit1
*7,y_digit
+33, 7,13, 24,22);
220 dockapp_copyarea(parts
, pixmap
, digit1000
*7,y_digit
+33, 7,13, 6,22);
221 dockapp_copyarea(parts
, pixmap
, digit100
*7,y_digit
+33, 7,13, 15,22);
222 dockapp_copyarea(parts
, pixmap
, digit10
*7,y_digit
+33, 7,13, 24,22);
224 /* draw level gauge */
225 dockapp_copyarea(parts
, pixmap
, 0,y_gauge
+72, 49*percent
/100,14,5,40);
231 dockapp_copyarea(backdrop_led
, pixmap
, 0, 0, 58, 58, 0, 0);
234 dockapp_copyarea(backdrop_led_g
, pixmap
, 0, 0, 58, 58, 0, 0);
236 /* longrun flags (performance or economy) */
238 case LONGRUN_FLAGS_PEFORMANCE
:
239 dockapp_copyarea(parts
, pixmap
, 24, 22, 24, 11, 30, 3);
241 case LONGRUN_FLAGS_ECONOMY
:
242 dockapp_copyarea(parts
, pixmap
, 0, 22, 24, 11, 3, 3);
245 break; /* make gcc happy */
248 /* draw digit (frequency) */
250 dockapp_copyarea(parts
, pixmap
, digit100
*7,59, 7,13, 4,22);
251 dockapp_copyarea(parts
, pixmap
, digit10
*7,59, 7,13, 13,22);
252 dockapp_copyarea(parts
, pixmap
, digit1
*7,59, 7,13, 22,22);
255 dockapp_copyarea(parts
, pixmap
, digit1000
*7,59, 7,13, 4,22);
256 dockapp_copyarea(parts
, pixmap
, digit100
*7,59, 7,13, 13,22);
257 dockapp_copyarea(parts
, pixmap
, digit10
*7,59, 7,13, 22,22);
259 /* draw level gauge */
260 dockapp_copyarea(parts
, pixmap
, 0, 100, 56 * percent
/ 100, 16, 1, 41);
264 dockapp_copy2window(pixmap
);
267 static void parse_arguments(int argc
, char **argv
)
270 for (i
= 1; i
< argc
; i
++) {
271 if (!strcmp(argv
[i
], "--help") || !strcmp(argv
[i
], "-h"))
272 print_help(argv
[0]), exit(0);
274 else if (!strcmp(argv
[i
], "--version") || !strcmp(argv
[i
], "-v"))
275 printf("%s version %s\n", PACKAGE
, VERSION
), exit(0);
277 else if (!strcmp(argv
[i
], "--display") || !strcmp(argv
[i
], "-d")) {
278 display_name
= argv
[i
+ 1];
282 else if (!strcmp(argv
[i
], "--backlight")
283 || !strcmp(argv
[i
], "-bl"))
286 else if (!strcmp(argv
[i
], "--light-color")
287 || !strcmp(argv
[i
], "-lc")) {
290 "%s: error parsing argument for option %s\n",
291 argv
[0], argv
[i
]), exit(1);
292 light_color
= argv
[i
+ 1];
296 else if (!strcmp(argv
[i
], "--interval") || !strcmp(argv
[i
], "-i")) {
300 "%s: error parsing argument for option %s\n",
301 argv
[0], argv
[i
]), exit(1);
302 if (sscanf(argv
[i
+ 1], "%i", &integer
) != 1)
304 "%s: error parsing argument for option %s\n",
305 argv
[0], argv
[i
]), exit(1);
307 fprintf(stderr
, "%s: argument %s must be >=1\n",
308 argv
[0], argv
[i
]), exit(1);
309 update_interval
= integer
;
313 else if (!strcmp(argv
[i
], "--led") || !strcmp(argv
[i
], "-l"))
316 else if (!strcmp(argv
[i
], "--windowed")
317 || !strcmp(argv
[i
], "-w"))
318 dockapp_iswindowed
= True
;
320 else if (!strcmp(argv
[i
], "--broken-wm")
321 || !strcmp(argv
[i
], "-bw"))
322 dockapp_isbrokenwm
= True
;
325 else if (!strcmp(argv
[i
], "--cpuid-device")
326 || !strcmp(argv
[i
], "-cd")) {
327 cpuid_dev
= argv
[i
+ 1];
330 else if (!strcmp(argv
[i
], "--msr-device")
331 || !strcmp(argv
[i
], "-md")) {
332 msr_dev
= argv
[i
+ 1];
338 fprintf(stderr
, "%s: unrecognized option '%s'\n", argv
[0],
340 print_help(argv
[0]), exit(1);
345 static void print_help(char *prog
)
347 printf("Usage : %s [OPTIONS]\n", prog
);
349 ("WMLongRun - A dockapp to monitor the LongRun(tm) status on Crusoe(tm) processors.\n");
350 printf(" -d, --display <string> display to use\n");
351 printf(" -bl, --backlight turn on back-light\n");
352 printf(" -lc, --light-color <string> back-light color(rgb:6E/C6/3B is default)\n");
353 printf(" -i, --interval <number> number of milliseconds between updates\n");
354 printf(" (500 is default)\n");
356 printf(" -cd, --cpuid-device <device> CPUID device ('/dev/cpu/0/cpuid' is default)\n");
357 printf(" -md, --msr-device <device> MSR device ('/dev/cpu/0/msr' is default)\n");
359 printf(" -l, --led run the application with LED interface\n");
360 printf(" -h, --help show this help text and exit\n");
361 printf(" -v, --version show program version and exit\n");
362 printf(" -w, --windowed run the application in windowed mode\n");
363 printf(" -bw, --broken-wm activate broken window manager fix\n");