From 270081ce19c72db8c2dab92ec3cae72d295e7f34 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Mon, 18 Sep 2017 06:27:05 -0400 Subject: [PATCH] wmapm: Add version 3.1 to repository. From https://ftp.openbsd.org/pub/OpenBSD/distfiles/wmapm-3.1.tar.gz --- wmapm/BUGS | 13 + wmapm/CHANGES | 98 ++++ wmapm/COPYING | 339 ++++++++++++ wmapm/HINTS | 39 ++ wmapm/INSTALL | 20 + wmapm/README | 81 +++ wmapm/TODO | 14 + wmapm/wmapm/Makefile | 29 + wmapm/wmapm/wmapm.1 | 49 ++ wmapm/wmapm/wmapm.c | 999 ++++++++++++++++++++++++++++++++++ wmapm/wmapm/wmapm.gif | Bin 0 -> 1703 bytes wmapm/wmapm/wmapm.h | 56 ++ wmapm/wmapm/wmapm_mask.xbm | 38 ++ wmapm/wmapm/wmapm_master.xpm | 171 ++++++ wmapm/wmapm/wmapm_master_LowColor.xpm | 137 +++++ wmapm/wmgeneral/wmgeneral.c | 366 +++++++++++++ wmapm/wmgeneral/wmgeneral.h | 50 ++ 17 files changed, 2499 insertions(+) create mode 100644 wmapm/BUGS create mode 100644 wmapm/CHANGES create mode 100644 wmapm/COPYING create mode 100644 wmapm/HINTS create mode 100644 wmapm/INSTALL create mode 100644 wmapm/README create mode 100644 wmapm/TODO create mode 100644 wmapm/wmapm/Makefile create mode 100644 wmapm/wmapm/wmapm.1 create mode 100644 wmapm/wmapm/wmapm.c create mode 100644 wmapm/wmapm/wmapm.gif create mode 100644 wmapm/wmapm/wmapm.h create mode 100644 wmapm/wmapm/wmapm_mask.xbm create mode 100644 wmapm/wmapm/wmapm_master.xpm create mode 100644 wmapm/wmapm/wmapm_master_LowColor.xpm create mode 100644 wmapm/wmgeneral/wmgeneral.c create mode 100644 wmapm/wmgeneral/wmgeneral.h diff --git a/wmapm/BUGS b/wmapm/BUGS new file mode 100644 index 0000000..19dcaac --- /dev/null +++ b/wmapm/BUGS @@ -0,0 +1,13 @@ +None that I know of... :) + +Please send bug reports to mghenderson@lanl.gov or jedgar@fxp.org and +describe the problem as detailed as you can. + +Note: all apm statistics are taken directly from +/proc/apm (in Linux) or /dev/apm (in FreeBSD). If +you see odd behavior with WMAPM (such as +displaying battery time remaining without a +corresponding percentage), please first check the +statistics in /proc/apm (or using your system's +'apm' program to see if the computer/kernel are +properly reporting the applicable statistics. diff --git a/wmapm/CHANGES b/wmapm/CHANGES new file mode 100644 index 0000000..6c37f50 --- /dev/null +++ b/wmapm/CHANGES @@ -0,0 +1,98 @@ +WMAPM changes. + + Version Description +--------------------------------------------------------------------------------------------- + + 3.1 -Released: Jan 11, 2000. + + Added support for time left on FreeBSD 3.x/4.x + (Chris D. Faulhaber ) + + Added support for Solaris. Works well on a SPARCbook 3GX. + Unsure of any others out there. + William M. Perry + + 3.0 -Released: December 15, 1998. + A Major overhaul performed. Changes include; + + + Added buttons to place laptop into "Suspend" (button labeled `Z') + or "Standby" (button labeled `S') mode. Buttons are separated + by status LEDs to minimize accidentally clicking on the wrong + one. I used `Z' for suspend because its like the laptop is + catching some Zs (i.e. going to sleep). + + + Replaced the 3 rectangular red/yellow/green status indicators + with 3 small round LEDs and moved them to a viewport at the + bottom between the two buttons. This array of LEDs could in future + be moved to a single LED in the main viewport to make room for + other things at this location (perhaps more buttons if apm supports + more things like truning off LCD, etc). + + + Created user-definable LowLevel and CriticalLevel thresholds. Yellow LED + comes on when Battery Percentage hits the LowLevel threshold. Red comes on + when you reach CriticalLevel threshold. + + + Made red status LED blink for extra noticability. User can define blink rate. + A BlinkRate of 0 turns off blinking. + + + Moved all of the other indicators into a single viewport above the + buttons and status LEDs. + + + Changed the red-dark-green colorbar to a banded blue LED bar that is tipped + with a color indicating capacity level. The tip color goes through + green-yellow-orange-red. A series of single-pixel dots is always present + below the bar to indicate its range. This is needed now, because + the bar is free-floating in the viewport. The single-pixel dots can be + seen easily on an LCD - the type of monitor wmapm is likely to be used. + + + Changed the `CHARGING' indicator with a single red `C' indicator at the + upper left of the APP. + + + Changed percentage indicator so that it can display 100%. (Used to only go + up to 99% max). + + + Changed time indicator to have a +/- sign depending on whether you are + charging up or draining down. (+ means you have that much battery life + left before its discharged. - means you have that much time to wait until + the battery is fully charged.) + + + Fixed a problem with very large "TimeLeft" values. If the time is greater + than the maximum time displayable 99 hours and 59 minutes, a ---:-- is + listed instead. Since the time is based on measured charge/discharge rates, + when the battery is doing neither, the time is essentially infinite. On my + (M Henderson's) laptop, the time left indicated 32766 when this happened. + FreeBSD systems should also show a ---:-- indicator. Dont have FreeBSD though + so I couldnt test it.... + + + Changed Makefile to suid the apm program. This is needed to allow users to + invoke the standby and suspend capabilities in apm. + + + Sped up the loop to catch button press and expose events. But the querying of + /proc/apm is still done about once a second... + + + Added alert feature. User can use command line option -A to turn on alerts + via wall. T1 and T2 are the time in seconds between updates for Low and Critical + status. By default the alerts are turned off. + + + Various sundry code cleanups. + + + 2.0 - Added FreeBSD support. + + 1.3 - Fixed an annoying little problem with the the meter + not properly lowering as the battery is depleted. + Also did some code cleanup, enhanced the Makefile which + now includes 'make install'. + Released 980826 + + 1.2 - Fixed bug that showed 100% battery capacity + as 90% (I never noticed since my battery seems + to max out at 98%). + Thanx to Brice Ruth for pointing out/helping fix the + 100% bug (err...feature). + Released 980731 + + 1.1 - Removed libapm dependency; tweaked some code. + Released 980729 + + 1.0 - Initial release version. + Released 980725 + diff --git a/wmapm/COPYING b/wmapm/COPYING new file mode 100644 index 0000000..a43ea21 --- /dev/null +++ b/wmapm/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/wmapm/HINTS b/wmapm/HINTS new file mode 100644 index 0000000..8fc7515 --- /dev/null +++ b/wmapm/HINTS @@ -0,0 +1,39 @@ +Hints for WMAPM + +Generic +-------------------------------------------------------------- +WMAPM supports 7 commandline options: + + -h (help); + -C (Critical Percent Threshold); + -L (Low Percent Threshold); + -b (BlinkRate for red LED); + -B (Beep Volume when at critical level); + -A ; + -display (display); + + +WindowMaker +-------------------------------------------------------------- +WindowMaker users simply drag and drop the WMAPM dock.app on +the WindowMaker Dock (preferred) or on the Fiend and select +'autolaunch' from the rightmouse button popupmenu. + + +Afterstep +-------------------------------------------------------------- +Afterstep users put the following in their .steprc +"Wharf wmapm - MaxSwallow "wmapm" wmapm &". + +Note: AfterStep's Wharf has a problem with pixmaps that are +larger than 60x60 pixels. Please tell the AfterStep authors +to fix this, this is not our fault, but a Wharf problem! + + +Other WindowManagers +-------------------------------------------------------------- +For other windowmanagers, WMAPM runs nicely as a 64x64 shaped +icon on your desktop. + + + diff --git a/wmapm/INSTALL b/wmapm/INSTALL new file mode 100644 index 0000000..93a1782 --- /dev/null +++ b/wmapm/INSTALL @@ -0,0 +1,20 @@ +Installation instructions for WMAPM. + +Requirements +-------------------------------------------------------------- + WMAPM requires the Xpm library (which should be available on +most machines with XFree86 installed). + In order to compile WMAPM using the Makefile, GNU make must +be used (FreeBSD users, the default BSD 'make' does not work). + +Installation +-------------------------------------------------------------- +1) % tar -zxvf wmapm-3.1.tar.gz +2) % cd wmapm-3.1/wmapm/ +3) % make (or gmake on most *BSD systems) +4) % make install (must be root) or simply copy and binary (and + optionally the man page) to a directory in your path. + (Makefile does an suid on apm; you must be root to do this.) +5) % wmapm & (or 'wmapm -h' for help, or 'man wmapm' for the man page) + +Be sure to read the HINTS and TODO files too! diff --git a/wmapm/README b/wmapm/README new file mode 100644 index 0000000..995c8d5 --- /dev/null +++ b/wmapm/README @@ -0,0 +1,81 @@ +WMAPM-3.1 release +-------------------------------------------------------------- +Authors....: wmapm was originally written by Chris D. Faulhaber + . Version 3.0 modifications due to + Michael G. Henderson + +Credits...: Rik Faith for his implementation + of libapm with respect to Linux APM support. + Martijm Pieterse and + Antoine Nulle for a great (and + somewhat standardised interface) which I used + as a template (wmmon.app and wmgeneral). + +Thanx to..: Brice Ruth for the corrections + pertaining to the 100% bug (err...feature). + Timecop for corrections to + fix the meter mismatch. + William M. Perry - Added Solaris support. + +Also, thanks to the following for various +bug fixes, patches and/or suggestions; + + ObiTuarY + MATSUBAYASHI 'Shaolin' Kohji" + Fumihiko Nishio + + + + +Description +-------------------------------------------------------------- +WMAPM monitors the APM statistics through the APM support in +the Linux and FreeBSD Kernels. This information, presented in +a nice visual format, can be invaluable on laptops (as I have +found in my recent/continual travels as a Field Engineer for a +small computer hardware manufacturer). + +WMAPM compiles successfully on both 2.0.x and 2.1.1xx kernels +using libc5 and libc6 (glibc2), and on FreeBSD 3.x-RELEASE/ +FreeBSD-3.x-STABLE. + +WMAPM currently provides: + + * Status of power supply (battery or AC); + * Percentage of battery remaining (numeric and meter); + * Battery charging status; + * Time left to battery depletion; + * High/Low/Critical battery status (Red/Yellow/Green); + +Files +-------------------------------------------------------------- +README This file. +INSTALL Installation instructions. +HINTS Hints about what you can do with WMAPM. +BUGS Things you don't want to know ;-) +CHANGES Description of changes. +COPYING GNU General Public License Version 2. +TODO Stuff I've planned for future WMAPM releases. + + +Bugs +-------------------------------------------------------------- +If you discover any bugs in this software, please send a +bugreport to jedgar@fxp.org and describe the problem as +as detailed as you can. + + +Copyright +-------------------------------------------------------------- +WMAPM.app is copyright (c)1998,1999 by Chris D. Faulhaber and +licensed through the GNU General Public License. Read the +COPYING file for the complete GNU license. + + +Other +-------------------------------------------------------------- +You are free to distribute this application per the GNU +General Public License; however, if this package is +distributed (through source and/or binary) in a larger +package (e.g. Linux distribution), I would appreciate a copy +(mostly to gloat as to where my apps have been distributed :). diff --git a/wmapm/TODO b/wmapm/TODO new file mode 100644 index 0000000..09e1faf --- /dev/null +++ b/wmapm/TODO @@ -0,0 +1,14 @@ +TODO list for WMAPM +-------------------------------------------------------------- + + * Work on NetBSD support. + * Add GUI to allow user to set things. + * Add ~/.wmapmrc file to store saved settings. + +Your feedback is greatly appreciated! If you have nice +suggestions, ideas, whatever, that aren't on this list, feel +free to mail them to: + + jedgar@fxp.org + +If you don't let me know... how am I suppose to know? ;-) diff --git a/wmapm/wmapm/Makefile b/wmapm/wmapm/Makefile new file mode 100644 index 0000000..8ccea80 --- /dev/null +++ b/wmapm/wmapm/Makefile @@ -0,0 +1,29 @@ +CC = gcc +CFLAGS = -O2 -Wall +INCDIR = -I/usr/X11R6/include +DESTDIR= /usr/X11R6 +LIBDIR = -L/usr/X11R6/lib +LIBS = -lXpm -lX11 -lXext +OBJS = wmapm.o \ + ../wmgeneral/wmgeneral.o + +.c.o: + $(CC) $(COPTS) -D$(shell echo `uname -s`) -c $< -o $*.o $(INCDIR) + +all: wmapm.o wmapm + +wmapm.o: wmapm_master.xpm wmapm_mask.xbm wmapm.h +wmapm: $(OBJS) + $(CC) $(COPTS) $(SYSTEM) -o wmapm $^ $(INCDIR) $(LIBDIR) $(LIBS) + +clean: + for i in $(OBJS) ; do \ + rm -f $$i; \ + done + rm -f wmapm + +install:: wmapm + install -s -m 0755 wmapm $(DESTDIR)/bin + install -m 0644 wmapm.1 $(DESTDIR)/man/man1 + chmod +s $(DESTDIR)/bin/wmapm + diff --git a/wmapm/wmapm/wmapm.1 b/wmapm/wmapm/wmapm.1 new file mode 100644 index 0000000..5dfe7f0 --- /dev/null +++ b/wmapm/wmapm/wmapm.1 @@ -0,0 +1,49 @@ +.TH WMAPM 1 "15 December 1998" +.SH NAME +WMAPM \- Dockable APM/Battery Monitor +.SH SYNOPSIS +.B wmapm +[-h] [-display display] [-C CriticalLevel] [-L LowLevel] [-b BlinkRate] [-B BeepVolume] [-A T1 T2] +.SH DESCRIPTION +.PP +WMAPM is an APM/Battery Monitor. It is used to visually display and +interpret details of APM/Battery status from the system's BIOS via +Linux and FreeBSD kernels. +.PP +WMAPM is dockable using WindowMaker and AfterStep window-managers; +under other window-managers, WMAPM appears as a nicely-sized 64x64 +application. +.PP +WMAPM provides the following information: battery or AC operation, battery +life remaining (both in percentage and bar), time left until +battery-depletion (Linux only), charging status, and battery status +(high - green, low - yellow, or critical - red) as reported by the +the APM BIOS. +.SH OPTIONS +.TP +.B \-h +Display list of command-line options. +.TP +.B \-C CriticalPercent +Set Critical threshold to specified (integer) percent. +.TP +.B \-L LowPercent +Set Low threshold to specified (integer) percent. +.TP +.B \-b BlinkRate +Set blink rate of red LED to given (float) value. +.TP +.B \-B BeepVolume +Make wmapm beep at the specified volume (integer between -100 and 100) when critical level is reached. +.TP +.B \-A Time1 Time2 +Make wmapm warn all users via wall of Low and Critical status. Time1 and Time2 are times in seconds between updates +when in Low and Critical States respectively. +.TP +.B \-display [display] +Use the designated X display. +.SH BUGS +None are known +.SH AUTHORS +Chris D. Faulhaber +Michael G. Henderson diff --git a/wmapm/wmapm/wmapm.c b/wmapm/wmapm/wmapm.c new file mode 100644 index 0000000..70f6880 --- /dev/null +++ b/wmapm/wmapm/wmapm.c @@ -0,0 +1,999 @@ +/* + * wmapm-3.1 + * + * A WindowMaker dockable application that allows laptop users + * to graphically monitor the status of their power source. + * (I.e. whether or not AC or battery is in use as well as + * how long it will take to drain or charge the battery.) + * + * Originally written (and copyrighted under GPL) by + * Chris D. Faulhaber . Version 3.0 + * is an extensively modified version of version 2.0 + * by Michael G. Henderson . + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING); if not, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * Portions of code derived from: + * apm/apmd/libapm : (c) 1996 Rickard E. Faith (r.faith@ieee.org) + * wmmon : (c) 1998 Martijn Pieterse (pieterse@xs4all.nl) and + * Antoine Nulle (warp@xs4all.nl) + * + * Thanx to Timecop for pointing out/helping to + * Toggle fix the meter mismatch. + * + */ + + + +/* + * Changes: + * + * 3.1 -Released: June 1, 1999. + * + Added support for time left on FreeBSD 3.x/4.x + * (Chris D. Faulhaber ) + * + * + * 3.01 -Released: January 3, 1999. + * + * + Added a LowColor Pixmap for the poor saps using 8-bit displays + * on laptops. There are a *lot* of laptops out there that are only + * 8-bit. Use the "-l" command-line option to invoke. + * + * + * 3.0 -Released: December 15, 1998. + * A Major overhaul performed. Changes include; + * + * + Added buttons to place laptop into "Suspend" (button labeled `Z') + * or "Standby" (button labeled `S') mode. Buttons are separated + * by status LEDs to minimize accidentally clicking on the wrong + * one. I used `Z' for suspend because its like the laptop is + * catching some Zs (i.e. going to sleep). + * + * + Replaced the 3 rectangular red/yellow/green status indicators + * with 3 small round LEDs and moved them to a viewport at the + * bottom between the two buttons. This array of LEDs could in future + * be moved to a single LED in the main viewport to make room for + * other things at this location (perhaps more buttons if apm supports + * more things like truning off LCD, etc). + * + * + Created user-definable LowLevel and CriticalLevel thresholds. Yellow LED + * comes on when Battery Percentage hits the LowLevel threshold. Red comes on + * when you reach CriticalLevel threshold. + * + * + Made red status LED blink for extra noticability. User can define blink rate. + * A BlinkRate of 0 turns off blinking. + * + * + Moved all of the other indicators into a single viewport above the + * buttons and status LEDs. + * + * + Changed the red-dark-green colorbar to a banded blue LED bar that is tipped + * with a color indicating capacity level. The tip color goes through + * green-yellow-orange-red. A series of single-pixel dots is always present + * below the bar to indicate its range. This is needed now, because + * the bar is free-floating in the viewport. The single-pixel dots can be + * seen easily on an LCD - the type of monitor wmapm is likely to be used. + * + * + Changed the `CHARGING' indicator with a single red `C' indicator at the + * upper left of the APP. + * + * + Changed percentage indicator so that it can display 100%. (Used to only go + * up to 99% max). + * + * + Changed time indicator to have a +/- sign depending on whether you are + * charging up or draining down. (+ means you have that much battery life + * left before its discharged. - means you have that much time to wait until + * the battery is fully charged.) + * + * + Fixed a problem with very large "TimeLeft" values. If the time is greater + * than the maximum time displayable 99 hours and 59 minutes, a ---:-- is + * listed instead. Since the time is based on measured charge/discharge rates, + * when the battery is doing neither, the time is essentially infinite. On my + * (M Henderson's) laptop, the time left indicated 32766 when this happened. + * FreeBSD systems should also show a ---:-- indicator. Dont have FreeBSD though + * so I couldnt test it.... + * + * + Changed Makefile to suid the apm program. This is needed to allow users to + * invoke the standby and suspend capabilities in apm. + * + * + Sped up the loop to catch button press and expose events. But the querying of + * /proc/apm is still done about once a second... + * + * + Added alert feature. User can use command line option -A to turn on alerts + * via wall. T1 and T2 are the time in seconds between updates for Low and Critical + * status. By default the alerts are turned off. + * + * + Various sundry code cleanups. + * + * + * 2.0 - Added FreeBSD support. + * + * 1.3 - Fixed an annoying little problem with the the meter + * not properly lowering as the battery is depleted. + * Also did some code cleanup, enhanced the Makefile which + * now includes 'make install'. + * Released 980826 + * + * 1.2 - Fixed bug that showed 100% battery capacity + * as 90% (I never noticed since my battery seems + * to max out at 98%). + * Thanx to Brice Ruth for pointing out/helping fix the + * 100% bug (err...feature). + * Released 980731 + * + * 1.1 - Removed libapm dependency; tweaked some code. + * Released 980729 + * + * 1.0 - Initial release version. + * Released 980725 + * + */ + + +#ifdef SunOS +#include +#include +#include +#include +#endif + + +#ifdef FreeBSD +#include +#include +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include "wmapm.h" +#include "../wmgeneral/wmgeneral.h" +#include "wmapm_master.xpm" +#include "wmapm_master_LowColor.xpm" +#include "wmapm_mask.xbm" + + + +#ifdef Linux +int apm_read(struct my_apm_info *i); +#else +# ifdef FreeBSD +int apm_read(apm_info_t temp_info); +# endif +#endif +int apm_exists(); +void ParseCMDLine(int argc, char *argv[]); +void pressEvent(XButtonEvent *xev); + + + + +int CriticalLevel = 10; +int LowLevel = 40; +float BlinkRate = 3.0; /* blinks per second */ +float UpdateRate = 0.8; /* Number of updates per second */ +int Beep = 0; /* Controls beeping when you get to CriticalLevel: Off by default */ +int Volume = 50; /* ring bell at 50% volume */ +int Alert = 0; /* Controls whether alert is sent to all users via wall: Off by default */ +int UseLowColorPixmap = 0; /* Use a lower number of colors for the poor saps on 8-bit displays -- common + on laptops! */ +float LAlertRate = 300.0; /* send alert every 5 minutes when Low */ +float CAlertRate = 120.0; /* send alert every 2 minutes when Critical */ + + + + + + + + +/* + * main + */ +int main(int argc, char *argv[]) { + + + struct my_apm_info my_cur_info; + int time_left, + hour_left, + min_left, + digit; +#ifdef FreeBSD + struct apm_info temp_info; +#endif + XEvent event; + int m, mMax, n, nMax, k, Toggle; + long int r, rMax, s, sMax; + FILE *fp; + + + + + + + + BlinkRate = 3.0; + UpdateRate = 1.0/1.25; + + + + + /* + * Parse any command line arguments. + */ + ParseCMDLine(argc, argv); + + BlinkRate = (BlinkRate >= 0.0) ? BlinkRate : -1.0*BlinkRate; + UpdateRate = (UpdateRate >= 0.0) ? UpdateRate : -1.0*UpdateRate; + + + nMax = (int)( 1.0e6/(2.0*UpdateRate*DELAY) ); + mMax = (BlinkRate > 0.0) ? (int)( 1.0e6/(2.0*BlinkRate*DELAY) ) : nMax; + rMax = (int)( LAlertRate*1.0e6/(2.0*DELAY) ); + sMax = (int)( CAlertRate*1.0e6/(2.0*DELAY) ); + + + + + + + + + + /* + * Check for APM support + */ + if (!apm_exists()) { +#ifdef Linux + fprintf(stderr, "No APM support in kernel\n"); +#else + fprintf(stderr, "Unable to access APM info\n"); +#endif + exit(1); + } + + + + + if (UseLowColorPixmap) + openXwindow(argc, argv, wmapm_master_LowColor, wmapm_mask_bits, wmapm_mask_width, wmapm_mask_height); + else + openXwindow(argc, argv, wmapm_master, wmapm_mask_bits, wmapm_mask_width, wmapm_mask_height); + + + + + /* + * Loop until we die... + */ + n = 32000; + m = 32000; + r = rMax+1; + s = sMax+1; + while(1) { + + + /* + * Only process apm info only every nMax cycles of this + * loop. We run it faster to catch the xevents like button + * presses and expose events, etc... + * + * DELAY is set at 0.00625 seconds, so process apm info + * every 1.25 seconds... + * + */ + if (n>nMax){ + + n = 0; + +#if defined(Linux) || defined(SunOS) + if (apm_read(&my_cur_info)) { +#else +# ifdef FreeBSD + if (apm_read(&temp_info)) { +# endif +#endif + fprintf(stderr, "Cannot read APM information: %i\n"); + exit(1); + } + + +#ifdef FreeBSD /* Convert status's */ + my_cur_info.ac_line_status = (int)temp_info.ai_acline; + my_cur_info.battery_status = (int)temp_info.ai_batt_stat; + my_cur_info.battery_percentage = (int)temp_info.ai_batt_life; + my_cur_info.battery_time = (int)temp_info.ai_batt_time; +#endif + + + + + + + /* + * Check AC status. + */ + switch (my_cur_info.ac_line_status) { + + case 1: + /* + * AC on-line. I.e. we are "plugged-in". + */ + copyXPMArea(68, 6, 26, 7, 31, 35); + break; + default: + /* + * AC off-line. I.e. we are using battery. + */ + copyXPMArea(68, 20, 26, 7, 31, 35); + + } + + + + + /* + * Paste up the default charge status and time + */ + copyXPMArea(104, 6, 5, 7, 6, 7); + copyXPMArea(83, 93, 41, 9, 15, 7); + + + + + + /* + * Check to see if we are charging. + */ + if ( (int)(my_cur_info.battery_status) == 3){ + + /* + * Battery Status: Charging. + */ + copyXPMArea(98, 6, 5, 7, 6, 7); + copyXPMArea(75, 81, 1, 2, 17, 9); + copyXPMArea(75, 81, 1, 2, 17, 12); + + } + + + + + + /* + * Repaint buttons. + */ + copyXPMArea(42, 106, 13, 11, 5, 48); + copyXPMArea(57, 106, 13, 11, 46, 48); + + + + + + + + + /* + * Paste up the "Time Left". This time means: + * + * If not charging: Time left before battery drains to 0% + * If charging: Time left before battery gets to maximum + * + */ +#ifdef Linux + if (my_cur_info.battery_time >= ((my_cur_info.using_minutes) ? 1440 : 86400) ) { +#else +# ifdef FreeBSD + if (my_cur_info.battery_time >= 86400) { +# endif +#endif + + /* + * If battery_time is too large, it likely means that there is + * no charging or discharging going on. So just display a "null" + * indicator (--:--). + * + */ + copyXPMArea(83, 106, 41, 9, 15, 7); + + } else if (my_cur_info.battery_time >= 0) { + +#ifdef Linux + time_left = (my_cur_info.using_minutes) ? my_cur_info.battery_time : my_cur_info.battery_time / 60; +#endif +#ifdef FreeBSD + time_left = (my_cur_info.using_minutes) ? my_cur_info.battery_time / 60 : my_cur_info.battery_time / 3600; +#endif + + hour_left = time_left / 60; + min_left = time_left % 60; + + copyXPMArea( (hour_left / 10) * 7 + 5, 93, 7, 9, 21, 7); /* Show 10's (hour) */ + copyXPMArea((hour_left % 10) * 7 + 5, 93, 7, 9, 29, 7); /* Show 1's (hour) */ + copyXPMArea(76, 93, 2, 9, 38, 7); /* colon */ + copyXPMArea((min_left / 10) * 7 + 5, 93, 7, 9, 42, 7); /* Show 10's (min) */ + copyXPMArea((min_left % 10) * 7 + 5, 93, 7, 9, 50, 7); /* Show 1's (min) */ + + } + + + + + + /* + * Do Battery Percentage. + */ + copyXPMArea(76, 81, 19, 7, 7, 34); /* Show Default % */ + copyXPMArea(66, 31, 49, 9, 7, 21); /* Show Default Meter */ + if (my_cur_info.battery_percentage == 100){ + copyXPMArea(15, 81, 1, 7, 7, 34); /* If 100%, show 100% */ + copyXPMArea( 5, 81, 6, 7, 9, 34); + copyXPMArea( 5, 81, 6, 7, 15, 34); + copyXPMArea(64, 81, 7, 7, 21, 34); /* Show '%' */ + copyXPMArea(66, 42, 49, 9, 7, 21); /* Show Meter */ + } else { + + if (my_cur_info.battery_percentage >= 10) + copyXPMArea((my_cur_info.battery_percentage / 10) * 6 + 4, 81, 6, 7, 9, 34); /* Show 10's */ + copyXPMArea((my_cur_info.battery_percentage % 10) * 6 + 4, 81, 6, 7, 15, 34); /* Show 1's */ + copyXPMArea(64, 81, 7, 7, 21, 34); /* Show '%' */ + + /* + * Show Meter + */ + k = my_cur_info.battery_percentage * 49 / 100; + copyXPMArea(66, 42, k, 9, 7, 21); + if (k%2) + copyXPMArea(66+k-1, 52, 1, 9, 7+k-1, 21); + else + copyXPMArea(66+k, 52, 1, 9, 7+k, 21); + } + + + + } else { + + /* + * Update the counter. When it hits nMax, we will + * process /proc/apm information again. + */ + ++n; + + } + + + + + /* + * This controls the 3 LEDs + */ + if (m>mMax){ + + m = 0; + + + if (( (int)(my_cur_info.battery_status) == 2) + ||( (int)(my_cur_info.battery_percentage) <= CriticalLevel )){ + + /* + * Battery Status: Critical. + * Blink the red led on/off... + */ + if (Toggle||(BlinkRate == 0.0)){ + if (Beep) XBell(display, Volume); + Toggle = 0; + copyXPMArea(95, 68, 4, 4, 24, 51); + } else{ + Toggle = 1; + copyXPMArea(75, 68, 4, 4, 24, 51); + } + copyXPMArea(81, 68, 4, 4, 30, 51); /* turn off yellow */ + copyXPMArea(87, 68, 4, 4, 36, 51); /* turn off green */ + + } else if (( (int)(my_cur_info.battery_status) == 1) + ||( (int)(my_cur_info.battery_percentage) <= LowLevel )){ + + /* + * Battery Status: Low. + */ + copyXPMArea(75, 68, 4, 4, 24, 51); /* turn off red */ + copyXPMArea(101, 68, 4, 4, 30, 51); /* turn ON yellow */ + copyXPMArea(87, 68, 4, 4, 36, 51); /* turn off green */ + + } else if (( (int)( my_cur_info.battery_status ) == 0) + ||( (int)(my_cur_info.battery_percentage) > LowLevel )){ + + /* + * Battery Status: High. + */ + copyXPMArea(75, 68, 4, 4, 24, 51); /* turn off red */ + copyXPMArea(81, 68, 4, 4, 30, 51); /* turn off yellow */ + copyXPMArea(107, 68, 4, 4, 36, 51); /* turn ON green */ + + } + + + } else { + + /* + * Update the counter. + */ + ++m; + + } + + + + + /* + * This controls Critical Alerts + */ + if (Alert){ + if (( (int)(my_cur_info.battery_status) == 2) + ||( (int)(my_cur_info.battery_percentage) <= CriticalLevel )){ + + if (s>sMax){ + + s = 0; + fp = popen("wall", "w"); + fprintf(fp, "Battery is critical!. Percent: %d\n", (int)(my_cur_info.battery_percentage)); + pclose(fp); + + } else { + + /* + * Update the counter. + */ + ++s; + + } + + } else if (( (int)(my_cur_info.battery_status) == 1) + ||( (int)(my_cur_info.battery_percentage) <= LowLevel )){ + + if (r>rMax){ + + r = 0; + fp = popen("wall", "w"); + fprintf(fp, "Battery is low. Percent: %d\n", (int)(my_cur_info.battery_percentage)); + pclose(fp); + + } else { + + /* + * Update the counter. + */ + ++r; + + } + + } + } + + + + /* + * Process any pending X events. + */ + while(XPending(display)){ + XNextEvent(display, &event); + switch(event.type){ + case Expose: + RedrawWindow(); + break; + case ButtonPress: + pressEvent(&event.xbutton); + break; + case ButtonRelease: + break; + } + } + + + + + + + /* + * Redraw and wait for next update + */ + RedrawWindow(); + usleep(DELAY); + + + } + + + +} + + + + + + + + + + + + + + + + + + + +/* + * This routine handles button presses. Pressing the 'S' button + * invokes 'apm -S' to place the machine into standby mode. And + * pressing the 'Z' buton invokes 'apm -s' to place the machine + * into suspend mode. + * + * Note: in order for users other than root to be able to run + * 'apm -s' and 'apm -S', you need to make apm suid (i.e. + * run 'chmod +s /usr/bin/apm' as root). This will allow + * 'normal' users to execute apm with root privilages. + * + */ +void pressEvent(XButtonEvent *xev){ + + int x=xev->x; + int y=xev->y; + + if(x>=5 && y>=48 && x<=17 && y<=58){ + + /* + * Standby Call. + * + * Draw button as 'pushed'. Redraw window to show it. + * Call 'apm -S' to standby. Sleep for 2 seconds so that + * the button doesnt immediately redraw back to unpressed + * before the 'apm -S' takes effect. + */ + copyXPMArea(5, 106, 13, 11, 5, 48); + RedrawWindow(); +#ifndef SunOS + system("apm -S"); +#endif + usleep(2000000L); + + } else if (x>=46 && y>=48 && x<=58 && y<=58){ + + /* + * Suspend Call. + * + * Draw button as 'pushed'. Redraw window to show it. + * Call 'apm -s' to suspend. Sleep for 2 seconds so that + * the button doesnt immediately redraw back to unpressed + * before the 'apm -s' takes effect. + */ + copyXPMArea(21, 106, 13, 11, 46, 48); + RedrawWindow(); +#ifndef SunOS + system("apm -s"); +#endif + usleep(2000000L); + + } + + return; + +} + + + + + + +/* + * apm_exists() + * - Check to see if /proc/apm exists... + * + */ +int apm_exists() +{ + + if (access(APMDEV, R_OK)) + + /* + * Cannot find /proc/apm + */ + return 0; + + else + + return 1; + +} + + + + +/* + * apm_read() + * - Read in the information found in /proc/apm... + * + */ +#ifdef Linux +int apm_read(struct my_apm_info *i){ + + FILE *str; + char units[10]; + char buffer[100]; + int retcode = 0; + + /* + * Open /proc/apm for reading + */ + if (!(str = fopen(APMDEV, "r"))) + return 1; + + + + /* + * Scan in the information.... + */ + fgets(buffer, sizeof(buffer) - 1, str); + buffer[sizeof(buffer) - 1] = '\0'; + sscanf(buffer, "%s %d.%d %x %x %x %x %d%% %d %s\n", + (char *)i->driver_version, + &i->apm_version_major, + &i->apm_version_minor, + &i->apm_flags, + &i->ac_line_status, + &i->battery_status, + &i->battery_flags, + &i->battery_percentage, + &i->battery_time, + units); + + + i->using_minutes = !strncmp(units, "min", 3) ? 1 : 0; + + + + /* + * Old Style + */ + if (i->driver_version[0] == 'B') { + strcpy((char *)i->driver_version, "pre-0.7"); + i->apm_version_major = 0; + i->apm_version_minor = 0; + i->apm_flags = 0; + i->ac_line_status = 0xff; + i->battery_status = 0xff; + i->battery_flags = 0xff; + i->battery_percentage = -1; + i->battery_time = -1; + i->using_minutes = 1; + + + + + sscanf(buffer, "BIOS version: %d.%d", &i->apm_version_major, &i->apm_version_minor); + + fgets(buffer, sizeof(buffer) - 1, str); + sscanf(buffer, "Flags: 0x%02x", &i->apm_flags); + + if (i->apm_flags & APM_32_BIT_SUPPORT) { + + fgets(buffer, sizeof(buffer) - 1, str); + fgets(buffer, sizeof(buffer) - 1, str); + + if (buffer[0] != 'P') { + + if (!strncmp(buffer+4, "off line", 8)) i->ac_line_status = 0; + else if (!strncmp(buffer+4, "on line", 7)) i->ac_line_status = 1; + else if (!strncmp(buffer+4, "on back", 7)) i->ac_line_status = 2; + + fgets(buffer, sizeof(buffer) - 1, str); + if (!strncmp(buffer+16, "high", 4)) i->battery_status = 0; + else if (!strncmp(buffer+16, "low", 3)) i->battery_status = 1; + else if (!strncmp(buffer+16, "crit", 4)) i->battery_status = 2; + else if (!strncmp(buffer+16, "charg", 5)) i->battery_status = 3; + + fgets(buffer, sizeof(buffer) - 1, str); + if (strncmp(buffer+14, "unknown", 7)) i->battery_percentage = atoi(buffer + 14); + + if (i->apm_version_major >= 1 && i->apm_version_minor >= 1) { + fgets(buffer, sizeof(buffer) - 1, str); + sscanf(buffer, "Battery flag: 0x%02x", &i->battery_flags); + fgets(buffer, sizeof(buffer) - 1, str); + if (strncmp(buffer+14, "unknown", 7)) i->battery_time = atoi(buffer + 14); + } + + + } + } + } + + + + /* + * Take care of battery percentages > 100% + */ + if (i->battery_percentage > 100) i->battery_percentage = -1; + + fclose(str); + return retcode; + +} +#else +# ifdef FreeBSD +int apm_read(apm_info_t temp_info) { + + int fd; + + if ( (fd = open(APMDEV, O_RDWR)) < 0){ + + return(1); + + } else if ( ioctl(fd, APMIO_GETINFO, temp_info) == -1 ) { + + close(fd); + return(1); + + } else { + + close(fd); + return(0); + + } + +} +# endif +#endif + +#ifdef SunOS +int apm_read(struct my_apm_info *i) { + + int fd; + battery_t info; + + memset(i,0,sizeof(*i)); + if ((fd = open(APMDEV,O_RDONLY)) < 0) { + perror("open"); + exit(1); + } + + if (ioctl(fd,BATT_STATUS,&info) < 0) return(1); + + close(fd); + + i->battery_percentage = info.capacity; + i->battery_time = info.discharge_time; + i->using_minutes = 0; + + /* convert to internal status: + * + * 0 = high + * 1 = low + * 2 = critical + * 3 = charging + */ + switch(info.status) { + case EMPTY: /* Battery has (effectively) no capacity */ + i->battery_status = 2; + break; + case LOW_CAPACITY: /* Battery has less than 25% capacity */ + i->battery_status = 1; + break; + case MED_CAPACITY: /* Battery has less than 50% capacity */ + i->battery_status = 1; + break; + case HIGH_CAPACITY: /* Battery has less than 75% capacity */ + case FULL_CAPACITY: /* Battery has more than 75% capacity */ + i->battery_status = 0; + break; + default: + i->battery_status = 2; + break; + } + + switch(info.charge) { + case DISCHARGE: /* Battery is discharging (i.e. in use) */ + i->ac_line_status = 0; + break; + case FULL_CHARGE: /* Battery is charging at its fastest rate */ + case TRICKLE_CHARGE: /* Battery is charging at a slower rate */ + default: + i->ac_line_status = 1; + break; + } + + if (i->battery_percentage > 100) i->battery_percentage = 100; + + /* Not sure what else we can fill in right now. + * Relevant information is: + * + * info.id_string = type of battery (internal, external, etc) + * info.total = total capacity (mWhrs) + */ + + return(0); + +} +#endif + + + +/* + * ParseCMDLine() + */ +void ParseCMDLine(int argc, char *argv[]) { +char *cmdline; +int i,j; +char puke[20]; + + for (i = 1; i < argc; i++) { + cmdline = argv[i]; + + if (cmdline[0] == '-') { + switch(cmdline[1]) { + case 'd': + ++i; + break; + case 'A': + Alert = 1; + LAlertRate = atof(argv[++i]); + CAlertRate = atof(argv[++i]); + break; + case 'b': + BlinkRate = atof(argv[++i]); + break; + case 'C': + CriticalLevel = atoi(argv[++i]); + break; + case 'L': + LowLevel = atoi(argv[++i]); + break; + case 'l': + UseLowColorPixmap = 1; + break; + case 'B': + Beep = 1; + Volume = atoi(argv[++i]); + break; + default: + printf("\nwmapm version: %s\n", WMAPM_VERSION); + printf("usage:\n"); + printf("\t-display \tUse alternate display.\n"); + printf("\t-l\t\t\tUse a low-color pixmap to conserve colors on 8-bit displays.\n"); + printf("\t-L \t\tDefine level at which yellow LED turns on.\n"); + printf("\t \t\tCriticalLevel takes precedence if LowLevel\tDefine level at which red LED turns on.\n"); + printf("\t-b \t\tBlink rate for red LED. (0 for no blinking.)\n"); + printf("\t-B \t\tBeep at Critical Level. Volume is between -100%% to 100%%.\n"); + printf("\t-A \t\tSend messages to users terminals when Low and critical.\n"); + printf("\t \t\tT1 is seconds between messages when Low. T2 is seconds between messages when Critical.\n"); + printf("\t-h\t\t\tDisplay help screen.\n\n"); + exit(1); + } + } + } + + +} + + + + diff --git a/wmapm/wmapm/wmapm.gif b/wmapm/wmapm/wmapm.gif new file mode 100644 index 0000000000000000000000000000000000000000..fc1fb211567dfbd1fd19f2d98c7cf1665c34c635 GIT binary patch literal 1703 zcwWWQi#uC)9LMorA_%HWu&q~8RgyF`#3hLJRD*+zxJ_6yVal=Dnq5j-x}Fx5hIUDq zL}-Ot#a61iY3u2>)>zB5Oz6QN(!YC zREnZ>86_`hzCB)1u(V>&kuWE&mj0&M zQ&{CU`2(F$5117&=*zmNs}bH)43`V%_=pFqs{|X5_Iy{R6ww9;xaa@0(`o z4ub|X&COC7HdK_qi<(~S6oaIfSUG_Ww$#glTpZR-9A{Qh zw;rS6FJ+Y3|Du~LXWfGdwjOQ73?AnhGFAN6=@s!&f{TB>y&@t!B~uxVhkE__Z#3_% zO!P^ysj@z1qfzow2V!}AxH;>%5HE@hu#)vUlReaYcgN9gn#TdIS`zjrmX5m0isxr( zj9|m7U_4*UH+LA&3@6N5;GpE z@THsRw9ihtb7tu_Bh#GF8_pJ#zMD)+qrR7VQTvCjr`?;Be&{yu;;q)%TF*Na2KFb} zi1?CYQnM4Y?~{-47lu>pGG2~k{mT5RYuiH3Q5MlncFn{!&!e+`%P)zE+dJ za)ov^p!L-xd3Y^nV5O_6wG(&FW8bwWw=8Dp^8*QKhn_XL4F!*ZT(3u;^ps`(_($9J z;DV(?OEn8XEX$j3{i4HSba}e6Wn_yy@A=XmoKPS940o;I@VnT-HU4<(n8t(7Fu;|z z$^TmRDx&K)Asci*j6J?>vBgbG8vSHfOLaua%&gYZJCyL67~lZEC)hvSdx;eH{zy&pbc+K;>m zTSyxxek6vw$jDO2fI2Vej=YtHeYuX +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "wmgeneral.h" + + /*****************/ + /* X11 Variables */ +/*****************/ + +Window Root; +int screen; +int x_fd; +int d_depth; +XSizeHints mysizehints; +XWMHints mywmhints; +Pixel back_pix, fore_pix; +char *Geometry = ""; +Window iconwin, win; +GC NormalGC; +XpmIcon wmgen; +Pixmap pixmask; + + /*****************/ + /* Mouse Regions */ +/*****************/ + +typedef struct { + int enable; + int top; + int bottom; + int left; + int right; +} MOUSE_REGION; + +#define MAX_MOUSE_REGION (8) +MOUSE_REGION mouse_region[MAX_MOUSE_REGION]; + + /***********************/ + /* Function Prototypes */ +/***********************/ + +static void GetXPM(XpmIcon *, char **); +static Pixel GetColor(char *); +void RedrawWindow(void); +void AddMouseRegion(int, int, int, int, int); +int CheckMouseRegion(int, int); + +/*******************************************************************************\ +|* read_rc_file *| +\*******************************************************************************/ + +void parse_rcfile(const char *filename, rckeys *keys) { + + char *p; + char temp[128]; + char *tokens = " :\t\n"; + FILE *fp; + int i,key; + + fp = fopen(filename, "r"); + if (fp) { + while (fgets(temp, 128, fp)) { + key = 0; + while (key >= 0 && keys[key].label) { + if ((p = strstr(temp, keys[key].label))) { + p += strlen(keys[key].label); + p += strspn(p, tokens); + if ((i = strcspn(p, "#\n"))) p[i] = 0; + free(*keys[key].var); + *keys[key].var = strdup(p); + key = -1; + } else key++; + } + } + fclose(fp); + } +} + + +/*******************************************************************************\ +|* GetXPM *| +\*******************************************************************************/ + +static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) { + + XWindowAttributes attributes; + int err; + + /* For the colormap */ + XGetWindowAttributes(display, Root, &attributes); + + wmgen->attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); + + err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap), + &(wmgen->mask), &(wmgen->attributes)); + + if (err != XpmSuccess) { + fprintf(stderr, "Not enough free colorcells.\n"); + exit(1); + } +} + +/*******************************************************************************\ +|* GetColor *| +\*******************************************************************************/ + +static Pixel GetColor(char *name) { + + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(display, Root, &attributes); + + color.pixel = 0; + if (!XParseColor(display, attributes.colormap, name, &color)) { + fprintf(stderr, "wm.app: can't parse %s.\n", name); + } else if (!XAllocColor(display, attributes.colormap, &color)) { + fprintf(stderr, "wm.app: can't allocate %s.\n", name); + } + return color.pixel; +} + +/*******************************************************************************\ +|* flush_expose *| +\*******************************************************************************/ + +static int flush_expose(Window w) { + + XEvent dummy; + int i=0; + + while (XCheckTypedWindowEvent(display, w, Expose, &dummy)) + i++; + + return i; +} + +/*******************************************************************************\ +|* RedrawWindow *| +\*******************************************************************************/ + +void RedrawWindow(void) { + + flush_expose(iconwin); + XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, + 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0); + flush_expose(win); + XCopyArea(display, wmgen.pixmap, win, NormalGC, + 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0); +} + +/*******************************************************************************\ +|* RedrawWindowXY *| +\*******************************************************************************/ + +void RedrawWindowXY(int x, int y) { + + flush_expose(iconwin); + XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, + x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0); + flush_expose(win); + XCopyArea(display, wmgen.pixmap, win, NormalGC, + x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0); +} + +/*******************************************************************************\ +|* AddMouseRegion *| +\*******************************************************************************/ + +void AddMouseRegion(int index, int left, int top, int right, int bottom) { + + if (index < MAX_MOUSE_REGION) { + mouse_region[index].enable = 1; + mouse_region[index].top = top; + mouse_region[index].left = left; + mouse_region[index].bottom = bottom; + mouse_region[index].right = right; + } +} + +/*******************************************************************************\ +|* CheckMouseRegion *| +\*******************************************************************************/ + +int CheckMouseRegion(int x, int y) { + + int i; + int found; + + found = 0; + + for (i=0; i= mouse_region[i].left && + y <= mouse_region[i].bottom && + y >= mouse_region[i].top) + found = 1; + } + if (!found) return -1; + return (i-1); +} + +/*******************************************************************************\ +|* copyXPMArea *| +\*******************************************************************************/ + +void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) { + + XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); + +} + +/*******************************************************************************\ +|* copyXBMArea *| +\*******************************************************************************/ + +void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) { + + XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); +} + + +/*******************************************************************************\ +|* setMaskXY *| +\*******************************************************************************/ + +void setMaskXY(int x, int y) { + + XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet); + XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet); +} + +/*******************************************************************************\ +|* openXwindow *| +\*******************************************************************************/ +void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) { + + unsigned int borderwidth = 1; + XClassHint classHint; + char *display_name = NULL; + char *wname = argv[0]; + XTextProperty name; + + XGCValues gcv; + unsigned long gcm; + + + int dummy=0; + int i; + + for (i=1; argv[i]; i++) { + if (!strcmp(argv[i], "-display")) + display_name = argv[i+1]; + } + + if (!(display = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s\n", + wname, XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(display); + Root = RootWindow(display, screen); + d_depth = DefaultDepth(display, screen); + x_fd = XConnectionNumber(display); + + /* Convert XPM to XImage */ + GetXPM(&wmgen, pixmap_bytes); + + /* Create a window to hold the stuff */ + mysizehints.flags = USSize | USPosition; + mysizehints.x = 0; + mysizehints.y = 0; + + back_pix = GetColor("white"); + fore_pix = GetColor("black"); + + XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, + &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + + mysizehints.width = 64; + mysizehints.height = 64; + + win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); + + iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); + + /* Activate hints */ + XSetWMNormalHints(display, win, &mysizehints); + classHint.res_name = wname; + classHint.res_class = wname; + XSetClassHint(display, win, &classHint); + + XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); + XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); + + if (XStringListToTextProperty(&wname, 1, &name) == 0) { + fprintf(stderr, "%s: can't allocate window name\n", wname); + exit(1); + } + + XSetWMName(display, win, &name); + + /* Create GC for drawing */ + + gcm = GCForeground | GCBackground | GCGraphicsExposures; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.graphics_exposures = 0; + NormalGC = XCreateGC(display, Root, gcm, &gcv); + + /* ONLYSHAPE ON */ + + pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height); + + XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet); + XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); + + /* ONLYSHAPE OFF */ + + mywmhints.initial_state = WithdrawnState; + mywmhints.icon_window = iconwin; + mywmhints.icon_x = mysizehints.x; + mywmhints.icon_y = mysizehints.y; + mywmhints.window_group = win; + mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; + + XSetWMHints(display, win, &mywmhints); + + XSetCommand(display, win, argv, argc); + XMapWindow(display, win); + +} diff --git a/wmapm/wmgeneral/wmgeneral.h b/wmapm/wmgeneral/wmgeneral.h new file mode 100644 index 0000000..55b37dd --- /dev/null +++ b/wmapm/wmgeneral/wmgeneral.h @@ -0,0 +1,50 @@ +#ifndef WMGENERAL_H_INCLUDED +#define WMGENERAL_H_INCLUDED + + /***********/ + /* Defines */ +/***********/ + +#define MAX_MOUSE_REGION (8) + + /************/ + /* Typedefs */ +/************/ + +typedef struct _rckeys rckeys; + +struct _rckeys { + const char *label; + char **var; +}; + +typedef struct { + Pixmap pixmap; + Pixmap mask; + XpmAttributes attributes; +} XpmIcon; + + /*******************/ + /* Global variable */ +/*******************/ + +Display *display; + + /***********************/ + /* Function Prototypes */ +/***********************/ + +void AddMouseRegion(int index, int left, int top, int right, int bottom); +int CheckMouseRegion(int x, int y); + +void openXwindow(int argc, char *argv[], char **, char *, int, int); +void RedrawWindow(void); +void RedrawWindowXY(int x, int y); + +void copyXPMArea(int, int, int, int, int, int); +void copyXBMArea(int, int, int, int, int, int); +void setMaskXY(int, int); + +void parse_rcfile(const char *, rckeys *); + +#endif -- 2.11.4.GIT