Remove set but unused variable
[wmlaptop2.git] / src / event.c
blob75bda90520bf4ca1bdcd651c2a4bc67681144fa6
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #include "event.h"
18 #include "apple.h"
20 void event_handler()
22 u_int32 update_seconds, update_seconds2, update_seconds3;
23 u_int32 batteryUpdate = args_batteryUpdate;
24 u_int32 powerUpdate = args_powerUpdate;
25 u_int32 tempUpdate = args_tempUpdate;
26 u_int32 sessionIdle = args_sessionIdle;
27 int j, lcd_brightness = 100, brightness = 0; /* initial state assumptions: lcd 100%, keyboard 0% */
29 secondsCounter = time(NULL);
30 update_seconds = time(NULL);
31 update_seconds2 = update_seconds;
32 update_seconds3 = update_seconds;
34 while (1) {
35 secondsCounter = time(NULL);
37 if (XPending(display)) {
38 XNextEvent(display, &e);
40 switch (e.type) {
41 case Expose:
42 draw_all();
43 break;
45 case ButtonPress:
46 j = CheckMouseRegion(e.xbutton.x, e.xbutton.y);
47 /* if a cliccable region was clicked, the dockapp is redrawn */
48 if (j != -1)
49 draw_all();
50 break;
52 case ButtonRelease:
53 /* activate screen saver on right click mouse */
54 if (e.xbutton.state & Button3Mask) {
55 XForceScreenSaver(display,
56 ScreenSaverActive);
58 break;
62 if (cpuLoad > 45)
63 tempUpdate = 2;
64 else
65 tempUpdate = ARGSDEF_TEMPUPDATE;
67 if (update_seconds <= secondsCounter - batteryUpdate) {
68 update_seconds = secondsCounter;
69 print_battery();
71 if (args_autoShutdown != AUTOSHUTDOWN_OFF)
72 checkAutoShutdown();
73 if (args_autoAlarm != AUTOALARM_OFF)
74 checkAutoAlarm();
77 if (update_seconds2 <= secondsCounter - tempUpdate) {
78 update_seconds2 = secondsCounter;
79 cpuReadTemp();
82 if (update_seconds3 <= secondsCounter - powerUpdate) {
83 update_seconds3 = secondsCounter;
84 read_power();
87 if (!powerState.isCharging) {
88 if (get_session_idle_time(display) >= sessionIdle) {
89 printf("Idle more than %d secs\n", sessionIdle);
91 if (lcd_brightness != 20) {
92 system("xbacklight -set 20");
93 lcd_brightness = 20;
96 if (apple == 1 && brightness == 255) {
97 set_keyboard_brightness_value(0);
98 brightness = 0;
99 printf("Turning off keyboard backlight due to inactivity\n");
101 } else {
102 /* There's activity. Turn on lights even though on battery */
103 if (lcd_brightness != 100) {
104 system("xbacklight -set 100");
105 lcd_brightness = 100;
106 printf("Restoring backlight\n");
108 if (apple == 1 && brightness == 0 && get_light_sensor_value() <= 3) {
109 set_keyboard_brightness_value(255);
110 brightness = 255;
111 printf("Turning on keyboard backlight\n");
114 } else {
115 /* plugged in, no worries about saving power */
116 if (lcd_brightness != 100){
117 system("xbacklight -set 100");
118 lcd_brightness = 100;
119 printf("Plugged in, maximum brightness!\n");
121 if (apple == 1 && brightness == 0 && get_light_sensor_value() <= 3) {
122 set_keyboard_brightness_value(255);
123 brightness = 255;
124 printf("Turning on keyboard backlight\n");
126 if (apple == 1 && brightness == 255 && get_light_sensor_value() > 3) {
127 set_keyboard_brightness_value(0);
128 brightness = 0;
129 printf("Enough light, turning off keyboard backlight\n");
133 /* check and redraw cpu load */
134 cpuLoad = getCpuLoad();
135 cpuReadFreq();
136 draw_all();
137 usleep(1000 * args_cpuUpdate);
141 void AddMouseRegion(u_int8 index, u_int8 left, u_int8 top, u_int8 right,
142 u_int8 bottom)
144 if (index < MAX_MOUSE_REGION) {
145 mouse_region[index].top = top;
146 mouse_region[index].left = left;
147 mouse_region[index].bottom = bottom;
148 mouse_region[index].right = right;
152 u_int8 CheckMouseRegion(u_int8 x, u_int8 y)
154 register int i;
155 register bool found;
157 found = 0;
159 for (i = 0; i < MAX_MOUSE_REGION && !found; i++) {
160 if (x <= mouse_region[i].right &&
161 x >= mouse_region[i].left &&
162 y <= mouse_region[i].bottom && y >= mouse_region[i].top)
163 found = 1;
165 if (!found)
166 return -1;
167 return (i - 1);
170 bool flashingLowBatteryCycle;
172 void stopFlashingLowBattery(int useless)
174 flashingLowBatteryCycle = false;
175 wait(NULL);
176 return;
179 void startFlashingLowBattery(pid_t childPid)
181 bool alternate = false;
182 int i;
184 while (flashingLowBatteryCycle) {
185 /* we make the child die if the user click on the dockapp */
186 if (XPending(display)) {
187 XNextEvent(display, &e);
188 switch (e.type) {
189 case ButtonPress:
190 /* kill the child */
191 kill(childPid, SIGKILL);
195 if (alternate)
196 draw_area(64, 0, 59, 59, 2, 2);
197 else
198 draw_area(64, 59, 59, 59, 2, 2);
200 alternate = !alternate;
202 while (XCheckTypedWindowEvent(display, iconwin, Expose, &e)) ;
203 XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 0, 0,
204 wmgen.attributes.width, wmgen.attributes.height, 0,
206 while (XCheckTypedWindowEvent(display, win, Expose, &e)) ;
207 XCopyArea(display, wmgen.pixmap, win, NormalGC, 0, 0,
208 wmgen.attributes.width, wmgen.attributes.height, 0,
211 usleep(80000);
214 /* now i have to fill the dockapp background with black.. ugly job */
215 for (i = 2; i < 60; i += 20)
216 draw_area(64, 119, 59, 20, 2, i);
218 while (XCheckTypedWindowEvent(display, iconwin, Expose, &e)) ;
219 XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 0, 0,
220 wmgen.attributes.width, wmgen.attributes.height, 0, 0);
221 while (XCheckTypedWindowEvent(display, win, Expose, &e)) ;
222 XCopyArea(display, wmgen.pixmap, win, NormalGC, 0, 0,
223 wmgen.attributes.width, wmgen.attributes.height, 0, 0);