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.
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
;
35 secondsCounter
= time(NULL
);
37 if (XPending(display
)) {
38 XNextEvent(display
, &e
);
46 j
= CheckMouseRegion(e
.xbutton
.x
, e
.xbutton
.y
);
47 /* if a cliccable region was clicked, the dockapp is redrawn */
53 /* activate screen saver on right click mouse */
54 if (e
.xbutton
.state
& Button3Mask
) {
55 XForceScreenSaver(display
,
65 tempUpdate
= ARGSDEF_TEMPUPDATE
;
67 if (update_seconds
<= secondsCounter
- batteryUpdate
) {
68 update_seconds
= secondsCounter
;
71 if (args_autoShutdown
!= AUTOSHUTDOWN_OFF
)
73 if (args_autoAlarm
!= AUTOALARM_OFF
)
77 if (update_seconds2
<= secondsCounter
- tempUpdate
) {
78 update_seconds2
= secondsCounter
;
82 if (update_seconds3
<= secondsCounter
- powerUpdate
) {
83 update_seconds3
= secondsCounter
;
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");
96 if (apple
== 1 && brightness
== 255) {
97 set_keyboard_brightness_value(0);
99 printf("Turning off keyboard backlight due to inactivity\n");
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);
111 printf("Turning on keyboard backlight\n");
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);
124 printf("Turning on keyboard backlight\n");
126 if (apple
== 1 && brightness
== 255 && get_light_sensor_value() > 3) {
127 set_keyboard_brightness_value(0);
129 printf("Enough light, turning off keyboard backlight\n");
133 /* check and redraw cpu load */
134 cpuLoad
= getCpuLoad();
137 usleep(1000 * args_cpuUpdate
);
141 void AddMouseRegion(u_int8 index
, u_int8 left
, u_int8 top
, u_int8 right
,
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
)
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
)
170 bool flashingLowBatteryCycle
;
172 void stopFlashingLowBattery(int useless
)
174 flashingLowBatteryCycle
= false;
179 void startFlashingLowBattery(pid_t childPid
)
181 bool alternate
= false;
184 while (flashingLowBatteryCycle
) {
185 /* we make the child die if the user click on the dockapp */
186 if (XPending(display
)) {
187 XNextEvent(display
, &e
);
191 kill(childPid
, SIGKILL
);
196 draw_area(64, 0, 59, 59, 2, 2);
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,
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);