-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleds.c
71 lines (55 loc) · 1.87 KB
/
leds.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <X11/XKBlib.h>
#include "sal.h"
#include "config.h"
#include "image.h"
#include "window.h"
#include "aquarium.h"
static Imlib_Image led_image;
void leds_init(struct aquarium *aquarium)
{
int i;
for (i = 0; i < LEDS; i++) {
if (aquarium->leds[i] != AL_NO) {
led_image = image_load("leds.png");
break;
}
}
}
static void leds_core(struct aquarium *aquarium, int led, int pressed, int loc, int x_delta)
{
int x, y, d;
if(loc == AL_NO || !pressed)
return;
aquarium_transform(loc,
imlib_image_get_width(),
imlib_image_get_height() / LEDS,
&x, &y);
if (x > aquarium->w / 2)
d = -x_delta * imlib_image_get_width();
else
d = x_delta * imlib_image_get_width();
window_draw_blend((unsigned char *)imlib_image_get_data_for_reading_only(),
0, (imlib_image_get_height() / LEDS) * led,
imlib_image_get_width(),
imlib_image_get_height() / LEDS,
x + d, y,
128);
}
void leds_update(struct aquarium *aquarium)
{
int i, j;
unsigned int states;
if (XkbGetIndicatorState(aquarium->display,
XkbUseCoreKbd, &states) != Success) {
return;
}
imlib_context_set_image(led_image);
for (i = 0; i < LEDS; i++) {
int x_delta = 0;
for (j = 0 ; j < i; j++) {
if (aquarium->leds[j] == aquarium->leds[i])
x_delta++;
}
leds_core(aquarium, i, (states >> i) & 1, aquarium->leds[i], x_delta);
}
}