diff options
| author | Ken Brown | 2018-01-12 08:51:16 -0500 |
|---|---|---|
| committer | Ken Brown | 2018-01-13 13:16:47 -0500 |
| commit | 5af5df1f7c20858dab762830e1a94994ceda425b (patch) | |
| tree | 3252d74339e51877b1cc88c363ba41ee8f83bb9e /src | |
| parent | 7f52a102ad8234dbfe59a005034c7fc3e4fe538c (diff) | |
| download | emacs-5af5df1f7c20858dab762830e1a94994ceda425b.tar.gz emacs-5af5df1f7c20858dab762830e1a94994ceda425b.zip | |
Add battery support to all Cygwin builds
It already exists in the Cygwin-w32 build.
* src/w32fns.c (Fw32_battery_status): Move to...
* src/w32cygwinx: New file, to be used for functions common to
the MS Windows and Cygwin builds.
(syms_of_w32cygwinx): New function.
* src/lisp.h: Add prototype of syms_of_w32cygwinx.
* src/emacs.c (main) [HAVE_NTGUI or CYGWIN]: Call syms_of_w32cygwinx.
* src/Makefile.in (SOME_MACHINE_OBJECTS):
* configure.ac (W32_OBJ) [HAVE_W32]: Add w32cygwinx.o.
(W32_LIBS) [CYGWIN]: Set equal to "-lkernel32" in non-w32 build.
(W32_OBJ) [CYGWIN]: Set equal to "w32cygwinx.o" in non-w32 build.
* etc/NEWS: Document the new battery support.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.in | 9 | ||||
| -rw-r--r-- | src/emacs.c | 4 | ||||
| -rw-r--r-- | src/lisp.h | 5 | ||||
| -rw-r--r-- | src/w32cygwinx.c | 140 | ||||
| -rw-r--r-- | src/w32fns.c | 110 |
5 files changed, 154 insertions, 114 deletions
diff --git a/src/Makefile.in b/src/Makefile.in index 2de888ada33..c84859cb4f1 100644 --- a/src/Makefile.in +++ b/src/Makefile.in | |||
| @@ -277,11 +277,12 @@ NS_OBJC_OBJ=@NS_OBJC_OBJ@ | |||
| 277 | ## Used only for GNUstep. | 277 | ## Used only for GNUstep. |
| 278 | GNU_OBJC_CFLAGS=$(patsubst -specs=%-hardened-cc1,,@GNU_OBJC_CFLAGS@) | 278 | GNU_OBJC_CFLAGS=$(patsubst -specs=%-hardened-cc1,,@GNU_OBJC_CFLAGS@) |
| 279 | ## w32fns.o w32menu.c w32reg.o fringe.o fontset.o w32font.o w32term.o | 279 | ## w32fns.o w32menu.c w32reg.o fringe.o fontset.o w32font.o w32term.o |
| 280 | ## w32xfns.o w32select.o image.o w32uniscribe.o if HAVE_W32, else | 280 | ## w32xfns.o w32select.o image.o w32uniscribe.o w32cygwinx.o if HAVE_W32, |
| 281 | ## empty. | 281 | ## w32cygwinx.o if CYGWIN but not HAVE_W32, else empty. |
| 282 | W32_OBJ=@W32_OBJ@ | 282 | W32_OBJ=@W32_OBJ@ |
| 283 | ## -lkernel32 -luser32 -lusp10 -lgdi32 -lole32 -lcomdlg32 -lcomctl32 | 283 | ## -lkernel32 -luser32 -lusp10 -lgdi32 -lole32 -lcomdlg32 -lcomctl32 |
| 284 | ## --lwinspool if HAVE_W32, else empty. | 284 | ## -lwinspool if HAVE_W32, |
| 285 | ## -lkernel32 if CYGWIN but not HAVE_W32, else empty. | ||
| 285 | W32_LIBS=@W32_LIBS@ | 286 | W32_LIBS=@W32_LIBS@ |
| 286 | 287 | ||
| 287 | ## emacs.res if HAVE_W32 | 288 | ## emacs.res if HAVE_W32 |
| @@ -412,7 +413,7 @@ SOME_MACHINE_OBJECTS = dosfns.o msdos.o \ | |||
| 412 | xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \ | 413 | xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \ |
| 413 | fontset.o dbusbind.o cygw32.o \ | 414 | fontset.o dbusbind.o cygw32.o \ |
| 414 | nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o macfont.o \ | 415 | nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o macfont.o \ |
| 415 | w32.o w32console.o w32fns.o w32heap.o w32inevt.o w32notify.o \ | 416 | w32.o w32console.o w32cygwinx.o w32fns.o w32heap.o w32inevt.o w32notify.o \ |
| 416 | w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \ | 417 | w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \ |
| 417 | w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \ | 418 | w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \ |
| 418 | xsettings.o xgselect.o termcap.o | 419 | xsettings.o xgselect.o termcap.o |
diff --git a/src/emacs.c b/src/emacs.c index 20ced262835..84cd3ac8c8a 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -1566,6 +1566,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1566 | syms_of_fontset (); | 1566 | syms_of_fontset (); |
| 1567 | #endif /* HAVE_NTGUI */ | 1567 | #endif /* HAVE_NTGUI */ |
| 1568 | 1568 | ||
| 1569 | #if defined HAVE_NTGUI || defined CYGWIN | ||
| 1570 | syms_of_w32cygwinx (); | ||
| 1571 | #endif | ||
| 1572 | |||
| 1569 | #if defined WINDOWSNT || defined HAVE_NTGUI | 1573 | #if defined WINDOWSNT || defined HAVE_NTGUI |
| 1570 | syms_of_w32select (); | 1574 | syms_of_w32select (); |
| 1571 | #endif | 1575 | #endif |
diff --git a/src/lisp.h b/src/lisp.h index 3eb6e0d3c1d..616aea07805 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4482,6 +4482,11 @@ extern void syms_of_gfilenotify (void); | |||
| 4482 | extern void syms_of_w32notify (void); | 4482 | extern void syms_of_w32notify (void); |
| 4483 | #endif | 4483 | #endif |
| 4484 | 4484 | ||
| 4485 | #if defined HAVE_NTGUI || defined CYGWIN | ||
| 4486 | /* Defined in w32cygwinx.c. */ | ||
| 4487 | extern void syms_of_w32cygwinx (void); | ||
| 4488 | #endif | ||
| 4489 | |||
| 4485 | /* Defined in xfaces.c. */ | 4490 | /* Defined in xfaces.c. */ |
| 4486 | extern Lisp_Object Vface_alternative_font_family_alist; | 4491 | extern Lisp_Object Vface_alternative_font_family_alist; |
| 4487 | extern Lisp_Object Vface_alternative_font_registry_alist; | 4492 | extern Lisp_Object Vface_alternative_font_registry_alist; |
diff --git a/src/w32cygwinx.c b/src/w32cygwinx.c new file mode 100644 index 00000000000..8d3ae164cf6 --- /dev/null +++ b/src/w32cygwinx.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* Common functions for the Microsoft Windows and Cygwin builds. | ||
| 2 | |||
| 3 | Copyright (C) 2018 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation, either version 3 of the License, or (at | ||
| 10 | your option) any later version. | ||
| 11 | |||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | |||
| 24 | #include "lisp.h" | ||
| 25 | #include "w32common.h" | ||
| 26 | |||
| 27 | DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0, | ||
| 28 | doc: /* Get power status information from Windows system. | ||
| 29 | |||
| 30 | The following %-sequences are provided: | ||
| 31 | %L AC line status (verbose) | ||
| 32 | %B Battery status (verbose) | ||
| 33 | %b Battery status, empty means high, `-' means low, | ||
| 34 | `!' means critical, and `+' means charging | ||
| 35 | %p Battery load percentage | ||
| 36 | %s Remaining time (to charge or discharge) in seconds | ||
| 37 | %m Remaining time (to charge or discharge) in minutes | ||
| 38 | %h Remaining time (to charge or discharge) in hours | ||
| 39 | %t Remaining time (to charge or discharge) in the form `h:min' */) | ||
| 40 | (void) | ||
| 41 | { | ||
| 42 | Lisp_Object status = Qnil; | ||
| 43 | |||
| 44 | SYSTEM_POWER_STATUS system_status; | ||
| 45 | if (GetSystemPowerStatus (&system_status)) | ||
| 46 | { | ||
| 47 | Lisp_Object line_status, battery_status, battery_status_symbol; | ||
| 48 | Lisp_Object load_percentage, seconds, minutes, hours, remain; | ||
| 49 | |||
| 50 | long seconds_left = (long) system_status.BatteryLifeTime; | ||
| 51 | |||
| 52 | if (system_status.ACLineStatus == 0) | ||
| 53 | line_status = build_string ("off-line"); | ||
| 54 | else if (system_status.ACLineStatus == 1) | ||
| 55 | line_status = build_string ("on-line"); | ||
| 56 | else | ||
| 57 | line_status = build_string ("N/A"); | ||
| 58 | |||
| 59 | if (system_status.BatteryFlag & 128) | ||
| 60 | { | ||
| 61 | battery_status = build_string ("N/A"); | ||
| 62 | battery_status_symbol = empty_unibyte_string; | ||
| 63 | } | ||
| 64 | else if (system_status.BatteryFlag & 8) | ||
| 65 | { | ||
| 66 | battery_status = build_string ("charging"); | ||
| 67 | battery_status_symbol = build_string ("+"); | ||
| 68 | if (system_status.BatteryFullLifeTime != -1L) | ||
| 69 | seconds_left = system_status.BatteryFullLifeTime - seconds_left; | ||
| 70 | } | ||
| 71 | else if (system_status.BatteryFlag & 4) | ||
| 72 | { | ||
| 73 | battery_status = build_string ("critical"); | ||
| 74 | battery_status_symbol = build_string ("!"); | ||
| 75 | } | ||
| 76 | else if (system_status.BatteryFlag & 2) | ||
| 77 | { | ||
| 78 | battery_status = build_string ("low"); | ||
| 79 | battery_status_symbol = build_string ("-"); | ||
| 80 | } | ||
| 81 | else if (system_status.BatteryFlag & 1) | ||
| 82 | { | ||
| 83 | battery_status = build_string ("high"); | ||
| 84 | battery_status_symbol = empty_unibyte_string; | ||
| 85 | } | ||
| 86 | else | ||
| 87 | { | ||
| 88 | battery_status = build_string ("medium"); | ||
| 89 | battery_status_symbol = empty_unibyte_string; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (system_status.BatteryLifePercent > 100) | ||
| 93 | load_percentage = build_string ("N/A"); | ||
| 94 | else | ||
| 95 | { | ||
| 96 | char buffer[16]; | ||
| 97 | snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); | ||
| 98 | load_percentage = build_string (buffer); | ||
| 99 | } | ||
| 100 | |||
| 101 | if (seconds_left < 0) | ||
| 102 | seconds = minutes = hours = remain = build_string ("N/A"); | ||
| 103 | else | ||
| 104 | { | ||
| 105 | long m; | ||
| 106 | double h; | ||
| 107 | char buffer[16]; | ||
| 108 | snprintf (buffer, 16, "%ld", seconds_left); | ||
| 109 | seconds = build_string (buffer); | ||
| 110 | |||
| 111 | m = seconds_left / 60; | ||
| 112 | snprintf (buffer, 16, "%ld", m); | ||
| 113 | minutes = build_string (buffer); | ||
| 114 | |||
| 115 | h = seconds_left / 3600.0; | ||
| 116 | snprintf (buffer, 16, "%3.1f", h); | ||
| 117 | hours = build_string (buffer); | ||
| 118 | |||
| 119 | snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); | ||
| 120 | remain = build_string (buffer); | ||
| 121 | } | ||
| 122 | |||
| 123 | status = listn (CONSTYPE_HEAP, 8, | ||
| 124 | Fcons (make_number ('L'), line_status), | ||
| 125 | Fcons (make_number ('B'), battery_status), | ||
| 126 | Fcons (make_number ('b'), battery_status_symbol), | ||
| 127 | Fcons (make_number ('p'), load_percentage), | ||
| 128 | Fcons (make_number ('s'), seconds), | ||
| 129 | Fcons (make_number ('m'), minutes), | ||
| 130 | Fcons (make_number ('h'), hours), | ||
| 131 | Fcons (make_number ('t'), remain)); | ||
| 132 | } | ||
| 133 | return status; | ||
| 134 | } | ||
| 135 | |||
| 136 | void | ||
| 137 | syms_of_w32cygwinx (void) | ||
| 138 | { | ||
| 139 | defsubr (&Sw32_battery_status); | ||
| 140 | } | ||
diff --git a/src/w32fns.c b/src/w32fns.c index ed375cddbef..6e0b3adf160 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -9213,115 +9213,6 @@ The coordinates X and Y are interpreted in pixels relative to a position | |||
| 9213 | return Qnil; | 9213 | return Qnil; |
| 9214 | } | 9214 | } |
| 9215 | 9215 | ||
| 9216 | DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0, | ||
| 9217 | doc: /* Get power status information from Windows system. | ||
| 9218 | |||
| 9219 | The following %-sequences are provided: | ||
| 9220 | %L AC line status (verbose) | ||
| 9221 | %B Battery status (verbose) | ||
| 9222 | %b Battery status, empty means high, `-' means low, | ||
| 9223 | `!' means critical, and `+' means charging | ||
| 9224 | %p Battery load percentage | ||
| 9225 | %s Remaining time (to charge or discharge) in seconds | ||
| 9226 | %m Remaining time (to charge or discharge) in minutes | ||
| 9227 | %h Remaining time (to charge or discharge) in hours | ||
| 9228 | %t Remaining time (to charge or discharge) in the form `h:min' */) | ||
| 9229 | (void) | ||
| 9230 | { | ||
| 9231 | Lisp_Object status = Qnil; | ||
| 9232 | |||
| 9233 | SYSTEM_POWER_STATUS system_status; | ||
| 9234 | if (GetSystemPowerStatus (&system_status)) | ||
| 9235 | { | ||
| 9236 | Lisp_Object line_status, battery_status, battery_status_symbol; | ||
| 9237 | Lisp_Object load_percentage, seconds, minutes, hours, remain; | ||
| 9238 | |||
| 9239 | long seconds_left = (long) system_status.BatteryLifeTime; | ||
| 9240 | |||
| 9241 | if (system_status.ACLineStatus == 0) | ||
| 9242 | line_status = build_string ("off-line"); | ||
| 9243 | else if (system_status.ACLineStatus == 1) | ||
| 9244 | line_status = build_string ("on-line"); | ||
| 9245 | else | ||
| 9246 | line_status = build_string ("N/A"); | ||
| 9247 | |||
| 9248 | if (system_status.BatteryFlag & 128) | ||
| 9249 | { | ||
| 9250 | battery_status = build_string ("N/A"); | ||
| 9251 | battery_status_symbol = empty_unibyte_string; | ||
| 9252 | } | ||
| 9253 | else if (system_status.BatteryFlag & 8) | ||
| 9254 | { | ||
| 9255 | battery_status = build_string ("charging"); | ||
| 9256 | battery_status_symbol = build_string ("+"); | ||
| 9257 | if (system_status.BatteryFullLifeTime != -1L) | ||
| 9258 | seconds_left = system_status.BatteryFullLifeTime - seconds_left; | ||
| 9259 | } | ||
| 9260 | else if (system_status.BatteryFlag & 4) | ||
| 9261 | { | ||
| 9262 | battery_status = build_string ("critical"); | ||
| 9263 | battery_status_symbol = build_string ("!"); | ||
| 9264 | } | ||
| 9265 | else if (system_status.BatteryFlag & 2) | ||
| 9266 | { | ||
| 9267 | battery_status = build_string ("low"); | ||
| 9268 | battery_status_symbol = build_string ("-"); | ||
| 9269 | } | ||
| 9270 | else if (system_status.BatteryFlag & 1) | ||
| 9271 | { | ||
| 9272 | battery_status = build_string ("high"); | ||
| 9273 | battery_status_symbol = empty_unibyte_string; | ||
| 9274 | } | ||
| 9275 | else | ||
| 9276 | { | ||
| 9277 | battery_status = build_string ("medium"); | ||
| 9278 | battery_status_symbol = empty_unibyte_string; | ||
| 9279 | } | ||
| 9280 | |||
| 9281 | if (system_status.BatteryLifePercent > 100) | ||
| 9282 | load_percentage = build_string ("N/A"); | ||
| 9283 | else | ||
| 9284 | { | ||
| 9285 | char buffer[16]; | ||
| 9286 | snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); | ||
| 9287 | load_percentage = build_string (buffer); | ||
| 9288 | } | ||
| 9289 | |||
| 9290 | if (seconds_left < 0) | ||
| 9291 | seconds = minutes = hours = remain = build_string ("N/A"); | ||
| 9292 | else | ||
| 9293 | { | ||
| 9294 | long m; | ||
| 9295 | double h; | ||
| 9296 | char buffer[16]; | ||
| 9297 | snprintf (buffer, 16, "%ld", seconds_left); | ||
| 9298 | seconds = build_string (buffer); | ||
| 9299 | |||
| 9300 | m = seconds_left / 60; | ||
| 9301 | snprintf (buffer, 16, "%ld", m); | ||
| 9302 | minutes = build_string (buffer); | ||
| 9303 | |||
| 9304 | h = seconds_left / 3600.0; | ||
| 9305 | snprintf (buffer, 16, "%3.1f", h); | ||
| 9306 | hours = build_string (buffer); | ||
| 9307 | |||
| 9308 | snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); | ||
| 9309 | remain = build_string (buffer); | ||
| 9310 | } | ||
| 9311 | |||
| 9312 | status = listn (CONSTYPE_HEAP, 8, | ||
| 9313 | Fcons (make_number ('L'), line_status), | ||
| 9314 | Fcons (make_number ('B'), battery_status), | ||
| 9315 | Fcons (make_number ('b'), battery_status_symbol), | ||
| 9316 | Fcons (make_number ('p'), load_percentage), | ||
| 9317 | Fcons (make_number ('s'), seconds), | ||
| 9318 | Fcons (make_number ('m'), minutes), | ||
| 9319 | Fcons (make_number ('h'), hours), | ||
| 9320 | Fcons (make_number ('t'), remain)); | ||
| 9321 | } | ||
| 9322 | return status; | ||
| 9323 | } | ||
| 9324 | |||
| 9325 | 9216 | ||
| 9326 | #ifdef WINDOWSNT | 9217 | #ifdef WINDOWSNT |
| 9327 | typedef BOOL (WINAPI *GetDiskFreeSpaceExW_Proc) | 9218 | typedef BOOL (WINAPI *GetDiskFreeSpaceExW_Proc) |
| @@ -10786,7 +10677,6 @@ tip frame. */); | |||
| 10786 | defsubr (&Sw32_reconstruct_hot_key); | 10677 | defsubr (&Sw32_reconstruct_hot_key); |
| 10787 | defsubr (&Sw32_toggle_lock_key); | 10678 | defsubr (&Sw32_toggle_lock_key); |
| 10788 | defsubr (&Sw32_window_exists_p); | 10679 | defsubr (&Sw32_window_exists_p); |
| 10789 | defsubr (&Sw32_battery_status); | ||
| 10790 | defsubr (&Sw32__menu_bar_in_use); | 10680 | defsubr (&Sw32__menu_bar_in_use); |
| 10791 | #if defined WINDOWSNT && !defined HAVE_DBUS | 10681 | #if defined WINDOWSNT && !defined HAVE_DBUS |
| 10792 | defsubr (&Sw32_notification_notify); | 10682 | defsubr (&Sw32_notification_notify); |