3 #include <X11/XKBlib.h>
9 static SA_Image *led_images = NULL;
10 static int num_led_images = 0;
11 static Leds_settings leds_settings;
12 static AquariumData *ad;
14 Leds_settings *leds_get_settings_ptr(void)
16 return &leds_settings;
20 Returns the turned on leds:
27 This code is based upon some lines(actually two lines :-)
28 in E-Leds by Mathias Meisfjordskar<mathiasm@ifi.uio.no>
32 static int check_kleds(void)
36 if (XkbGetIndicatorState(GDK_DISPLAY(), XkbUseCoreKbd, &states) != Success) {
37 perror("Error while reading Indicator status\n");
40 return (states & 0x7);
43 static int get_capslock(void)
45 if((check_kleds() & 1) == 1) return 1;
49 static int get_numlock(void)
51 if((check_kleds() & 2) == 2) return 1;
55 static int get_scrollock(void)
57 if((check_kleds() & 4) == 4) return 1;
62 static void do_led(int func, int colour, int show_off, int x, int y, int alpha)
70 is_on = get_capslock();
73 is_on = get_numlock();
76 is_on = get_scrollock();
84 if((!is_on && show_off) || is_on)
85 draw_pic_alpha(led_images[colour].image,
86 led_images[colour].width,
87 led_images[colour].height,
96 if(led_images == NULL)
99 for(i = 0; i < num_led_images; i++){
100 if(led_images[i].image != NULL)
101 g_object_unref(led_images[i].pixbuf);
113 char *led_files[] = {
115 "leds/bluegreen.png",
123 "leds/lightblue.png",
124 "leds/yellowgreen.png",
127 ad = aquarium_get_settings_ptr();
129 if(led_images != NULL)
132 for(num_led_images=0; led_files[num_led_images] != NULL; num_led_images++);
134 led_images = g_malloc0(sizeof(SA_Image) * num_led_images);
136 for(i = 0; i < num_led_images; i++)
137 load_image(led_files[i], &led_images[i], 2);
144 void leds_update(int beforeorafter)
149 if(beforeorafter != leds_settings.draw)
152 for(i = 0; i < 3 ; i++)
153 if(leds_settings.leds_func[i] != LEDS_OFF)
156 switch(leds_settings.horz){
161 x = ad->xmax-numleds * led_images[0].width - 2;
164 x = (ad->xmax-numleds * led_images[0].width) / 2;
170 switch(leds_settings.vert){
175 y = ad->ymax-numleds * led_images[0].height - 2;
178 y = (ad->ymax-numleds * led_images[0].height) / 2;
184 for(i = 0; i < NUMLEDS; i++)
185 do_led(leds_settings.leds_func[i],
186 leds_settings.leds_colour[i],
187 leds_settings.leds_show_off[i],
188 x + !leds_settings.vert_horz * led_images[0].width * i,
189 y + leds_settings.vert_horz * led_images[0].height * i, leds_settings.alpha);