This source file includes following definitions.
- ATTRIBUTE_FORMAT_PRINTF
- DEFUN
- syms_of_w32cygwinx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include <stdio.h>
23
24 #include "lisp.h"
25 #include "w32common.h"
26
27 static Lisp_Object ATTRIBUTE_FORMAT_PRINTF (1, 2)
28 format_string (char const *format, ...)
29 {
30 va_list args;
31 va_start (args, format);
32 Lisp_Object str = vformat_string (format, args);
33 va_end (args);
34 return str;
35 }
36
37 DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0,
38 doc:
39
40
41
42
43
44
45
46
47
48
49 )
50 (void)
51 {
52 Lisp_Object status = Qnil;
53
54 SYSTEM_POWER_STATUS system_status;
55 if (GetSystemPowerStatus (&system_status))
56 {
57 Lisp_Object line_status, battery_status, battery_status_symbol;
58 Lisp_Object load_percentage, seconds, minutes, hours, remain;
59
60 long seconds_left = (long) system_status.BatteryLifeTime;
61
62 if (system_status.ACLineStatus == 0)
63 line_status = build_string ("off-line");
64 else if (system_status.ACLineStatus == 1)
65 line_status = build_string ("on-line");
66 else
67 line_status = build_string ("N/A");
68
69 if (system_status.BatteryFlag & 128)
70 {
71 battery_status = build_string ("N/A");
72 battery_status_symbol = empty_unibyte_string;
73 }
74 else if (system_status.BatteryFlag & 8)
75 {
76 battery_status = build_string ("charging");
77 battery_status_symbol = build_string ("+");
78 if (system_status.BatteryFullLifeTime != -1L)
79 seconds_left = system_status.BatteryFullLifeTime - seconds_left;
80 }
81 else if (system_status.BatteryFlag & 4)
82 {
83 battery_status = build_string ("critical");
84 battery_status_symbol = build_string ("!");
85 }
86 else if (system_status.BatteryFlag & 2)
87 {
88 battery_status = build_string ("low");
89 battery_status_symbol = build_string ("-");
90 }
91 else if (system_status.BatteryFlag & 1)
92 {
93 battery_status = build_string ("high");
94 battery_status_symbol = empty_unibyte_string;
95 }
96 else
97 {
98 battery_status = build_string ("medium");
99 battery_status_symbol = empty_unibyte_string;
100 }
101
102 if (system_status.BatteryLifePercent > 100)
103 load_percentage = build_string ("N/A");
104 else
105 load_percentage = format_string ("%d", system_status.BatteryLifePercent);
106
107 if (seconds_left < 0)
108 seconds = minutes = hours = remain = build_string ("N/A");
109 else
110 {
111 long m = seconds_left / 60;
112 seconds = format_string ("%ld", seconds_left);
113 minutes = format_string ("%ld", m);
114 hours = format_string ("%3.1f", seconds_left / 3600.0);
115 remain = format_string ("%ld:%02ld", m / 60, m % 60);
116 }
117
118 status = list (Fcons (make_fixnum ('L'), line_status),
119 Fcons (make_fixnum ('B'), battery_status),
120 Fcons (make_fixnum ('b'), battery_status_symbol),
121 Fcons (make_fixnum ('p'), load_percentage),
122 Fcons (make_fixnum ('s'), seconds),
123 Fcons (make_fixnum ('m'), minutes),
124 Fcons (make_fixnum ('h'), hours),
125 Fcons (make_fixnum ('t'), remain));
126 }
127 return status;
128 }
129
130 void
131 syms_of_w32cygwinx (void)
132 {
133 defsubr (&Sw32_battery_status);
134 }