pax_global_header00006660000000000000000000000064116506075120014515gustar00rootroot0000000000000052 comment=7c0f397e0a4a4627f8f8988e9c7c5bd541818fc6 procmeter3-3.5d/000077500000000000000000000000001165060751200136135ustar00rootroot00000000000000procmeter3-3.5d/.procmeterrc000077700000000000000000000000001165060751200204042procmeterrcustar00rootroot00000000000000procmeter3-3.5d/ANNOUNCE000066400000000000000000000105501165060751200147450ustar00rootroot00000000000000 PROCMETER V3.5d =============== The ProcMeter program itself is a framework on which a number of modules (plugins) are loaded. More modules can be written as required to perform more monitoring and informational functions. The statistics that are displayed are grouped by module, with a menu allowing selection of module and a sub-menu for each output available for that module. APM Advanced Power Management information. These outputs are only available if you have configured the kernel to have the APM feature. Biff Monitors the e-mail inbox (in /var/spool/mail/ or /var/mail/) and indicates the number of e-mails that are waiting and the size. Date_Time The current date and time and the amount of time since the system was last booted. DiskUsage Shows the percentage of the disk that is used and the amount of free space for each of the local disks that it finds are mounted or can be mounted when the program starts. LogFile Monitors the size and number of lines and the rate of increase of these in a set of log files. Memory The amount of memory that is used for programs, buffers, cache and the amount that is free. Network The network devices and the amount of traffic on each of them. It will automatically pick up available devices when it starts. Processes The load average and the number of processes running and starting. ProcMeter Information about the procmeter program itself. Sensors Information from hardware sensors for temperature and fan speed (simple version with fixed scaling). FanSpeed Information from hardware sensors for fan speed (requires libsensors library installed but does read sensors.conf file for system customisation). Temperature Information from hardware sensors for temperature (requires libsensors library installed but does read sensors.conf file for system customisation). Voltage Information from hardware sensors for voltages (requires libsensors library installed but does read sensors.conf file for system customisation). Statistics Low level system statistics. For example CPU usage, disk usage, swapping and paging. VM_Statistics Low level system statistics about virtual memory (swaping and paging) for kernel version 2.5 where the information has moved from the Statistics section. Stat-CPU Statistics about individual CPU usage including support for SMP machines. Stat-Disk Statistics about individual disk usage (bytes read and written), with version 2.6 kernels individual partition information is included. Stat-Intr Statistics about individual interrupts. Uname The system information from the uname program, hostname and Linux kernel version. Wireless Information about wireless network devices. It will automatically pick up available devices when it starts. Longrun For systems with the Transmeta Crueso processor, information about longrun. Will not work unless the kernel is compiled with CPUID support, and /dev/cpu/0/cpuid must be readable by procmeter. ACPI Advanced Configuration and Power Interface information. These outputs are only available if you have enabled ACPI in the Linux kernel and you have the appropriate hardware. ACPI can report various information about a system's battery, and may also have thermal outputs available. CPUInfo Information about the CPUs in the system, currently only the CPU speed in MHz. Changes ------- Since version 3.5c: Bug Fixes Remove gcc-4.4 compilation warnings. Make error messages consistent. Fix several errors in manual pages. Don't crash if /proc/interrupts has very long lines. New features Added an option to limit the number of interrupts listed. Allow installation of stripped executables. Availability ------------ Web page: http://www.gedanken.demon.co.uk/procmeter3/ Author & Copyright ------------------ This program is copyright Andrew M. Bishop 1994-2011 (amb@gedanken.demon.co.uk) and distributed under GPL. email: amb@gedanken.demon.co.uk [Please put procmeter in the subject line] procmeter3-3.5d/COPYING000066400000000000000000000431151165060751200146520ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111 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., 59 Temple Place, Suite 330, Boston, MA 02111 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. procmeter3-3.5d/ChangeLog000066400000000000000000001432201165060751200153670ustar00rootroot000000000000002011-10-03 Andrew M. Bishop Version 3.5d released. 2011-10-03 [r341-343] Andrew M. Bishop * ANNOUNCE: Update for version 3.5d. * LSM: Update for version 3.5d. * FILES, NEWS: Update for version 3.5d. 2011-05-21 [r340] Andrew M. Bishop * Makefile, modules/Makefile: Add an 'install-strip' target, use the force option when creating symlinks (patch from Mike Liang). Make the GTK-2 version the default link for gprocmeter3 if both are built (rather than making none). 2011-01-08 [r339] Andrew M. Bishop * modules/stat-intr.c, man/procmeter3_modules.1, procmeterrc: Use the "options" parameter in the configuration file to limit the number of interrupts processed. 2011-01-08 [r338] Andrew M. Bishop * modules/stat-intr.c: Fix parsing of /proc/interrupts. 2011-01-08 [r337] Andrew M. Bishop * module.c: If realloc() fails then free the memory as well as returning NULL (change prompted by Joey Hess). 2010-12-31 [r336] Andrew M. Bishop * modules/stat-intr.c: Remove the CVS $Header$ line. 2010-12-31 [r335] Andrew M. Bishop * modules/stat-intr.c: Don't crash if the /proc/interrupts file has very long lines (based on patch from Joey Hess). 2010-12-24 Andrew M. Bishop Changed version control environment from RCS to CVS to SVN. 2010-12-24 [r324] Andrew M. Bishop * procmeter.h: Check-in file to allow transition to CVS then SVN. 2010-07-03 [r321-323] Andrew M. Bishop * man/procmeter3_modules.1: Fixes for several groff errors [patch from Wences Rene Arana Fuentes via Debian package maintainer]. * Makefile: Fix directory for manpages following FHS [patch from Wences Rene Arana Fuentes via Debian package maintainer]. * man/procmeter3-lcd.1, man/procmeter3.1, man/procmeterrc.5, man/gprocmeter3.1, man/procmeter3-log.1: Fixes for several groff errors [patch from Wences Rene Arana Fuentes via Debian package maintainer]. 2010-02-28 [r320] Andrew M. Bishop * modules/longrun.c, gtk1/window.c, gtk2/window.c, xaw/run.c, modules/acpi.c, module.c, xaw/window.c, gtk1/run.c, gtk2/run.c: Make error messages format consistent. 2010-02-28 [r319] Andrew M. Bishop * modules/longrun.c, module.c, modules/apm.c, modules/loadavg.c, lcd/window.c: Updated code to remove unused return value warnings from gcc-4.4 on Ubuntu (list of warnings from Mike T. Liang). 2010-02-20 Andrew M. Bishop Version 3.5c released. 2010-02-20 [r318] Andrew M. Bishop * NEWS: Updated for version 3.5c. 2010-02-20 [r316-317] Andrew M. Bishop * README, procmeter.h: Updated for version 3.5c. * modules/Makefile: Include special libsensors compilation/linking features. 2010-02-20 [r315] Andrew M. Bishop * modules/libsensors-fan.c (added), modules/libsensors-volt.c (added), modules/libsensors-temp.c (added), modules/check-no-libsensors.sh (added): Initial revision 2010-02-20 [r313-314] Andrew M. Bishop * modules/sensors.c: Fixed directory searching. Print warning that module is old and recommend the new Temperature or Fanspeed module instead. * man/procmeter3_modules.1: Updated with libsensors based modules. 2009-12-07 [r312] Andrew M. Bishop * gtk1/menus.c, gtk2/menus.c, xaw/menus.c: Remove 64-bit compilation warnings (patch by Mike T. Liang) as well as fix usage of Boolean/integer data type. 2009-12-01 [r310-311] Andrew M. Bishop * module.c: Sort the module menu into alphabetical order (patch by Mike T. Liang). * Makefile: Pass the LD and CC variables down to the sub-Makefiles (patch inspired by Mike T. Liang). 2009-04-21 [r309] Andrew M. Bishop * modules/df.c: Fix to handle disks over 2 TB. 2008-12-07 [r308] Andrew M. Bishop * modules/stat-disk.c: Ignore the 'whole disk' type entries when counting the total disk accesses, just count the partitions. 2008-10-23 Andrew M. Bishop Version 3.5b released. 2008-10-23 [r307] Andrew M. Bishop * NEWS: Update for version 3.5b. 2008-10-10 [r306] Andrew M. Bishop * man/procmeterrc.5, lcd/window.c: The LCD priority parameter is now a string, not an integer. 2008-09-07 [r305] Andrew M. Bishop * xaw/menus.c: Be more careful with comparisons of different data types. 2008-07-23 [r304] Andrew M. Bishop * procmeterrc: Change the startup section to have text, graph and bar chart as well as a comment referring to 'ProcMeter3 --help'. 2008-05-05 [r303] Andrew M. Bishop * modules/biff.c, modules/stat.c, modules/loadavg.c, modules/apm.c, procmeterrc.c, module.c, modules/vmstat.c, modules/logfile.c, Makefile, modules/netdev.c, modules/stat-intr.c, modules/df.c, modules/meminfo.c, modules/sensors.c, modules/wireless.c, procmeter.h, modules/stat-cpu.c, modules/cpuinfo.c, modules/stat-disk.c: Provide a function fgets_realloc() that all modules can call instead of fgets. This avoids any buffer overrun that might occur with fgets(), removes the need for deciding buffer sizes in advance and handles some file format changes. 2008-05-05 [r302] Andrew M. Bishop * man/procmeter3.1, README, gtk1/window.c, gtk2/window.c, man/gprocmeter3.1, xaw/window.c: Add Extended Window Manager Hints command line option (based on GTK2 patch from Wolfgang Kroener). 2008-05-04 [r301] Andrew M. Bishop * modules/stat-intr.c, modules/stat.c: Increase the buffer size for reading /proc/interrupts. 2008-04-27 [r300] Andrew M. Bishop * gtk1/widgets/PMBar.c, gtk2/widgets/PMBar.c, xaw/widgets/PMGraph.c, xaw/widgets/PMBar.c, lcd/window.c, gtk1/widgets/PMGraph.c, gtk2/widgets/PMGraph.c: Ensure that graph-min and graph-max get updated correctly. 2008-04-13 [r299] Andrew M. Bishop * module.c: Set the locale to "C" to avoid problems parsing numbers (patch from Wolfgang Kroener). 2007-12-28 [r298] Andrew M. Bishop * modules/acpi.c: Patch from Joey Hess. 2007-12-20 [r297] Andrew M. Bishop * module.c: Don't ignore the first two directory entries, they might not be '.' and '..'. 2007-12-16 Andrew M. Bishop Version 3.5a Released. 2007-12-16 [r296] Andrew M. Bishop * NEWS: Updated for version 3.5a. 2007-12-16 [r295] Andrew M. Bishop * procmeter.h: Updated for version 3.5a. 2007-12-15 [r293-294] Andrew M. Bishop * man/procmeter3-lcd.1, man/procmeter3.1, man/procmeterrc.5, man/gprocmeter3.1, man/procmeter3_modules.1, man/procmeter3-log.1: Updates to the manual pages, mainly for the new program names in version 3.5. * modules/acpi.c, modules/acpi.h: Patch from Joey Hess for the following: - Deal with batteries that report they're charged to greater than their max capacity. - Patch from Christian Schäfer to add support for using on acpi systems with no batteries. - guard against potential division by zero. - fix an off-by-one - minor bug fix to acpi code, don't skip over dotfiles 2007-11-24 [r292] Andrew M. Bishop * gtk1/window.c, gtk2/window.c: Set minimum size for graph window. Make main window resize like Xaw version depending on contents or when user requests a resize. 2007-11-21 [r290-291] Andrew M. Bishop * gtk2/widgets/PMBar.c, gtk2/widgets/PMText.c, gtk2/widgets/PMGeneric.c, gtk2/widgets/PMGraph.c: Handle the widget being destroyed more than once (a new GTK 'feature'). * gtk1/window.c, gtk2/window.c: Make sure that the right mouse button menu appears even if there are no outputs displayed. 2007-11-21 [r289] Andrew M. Bishop * Makefile: Only create the link from procmeter3-xaw to procmeter3 if it doesn't already exist. 2007-11-20 [r288] Andrew M. Bishop * procmeter.c, procmeter.h, NEWS: Updated to version 3.5. 2007-09-27 [r287] Andrew M. Bishop * README: Update README for version 3.5. 2007-09-26 [r286] Andrew M. Bishop * Makefile, modules/Makefile: Added DESTDIR option for installation location. 2007-09-26 [r284-285] Andrew M. Bishop * man/procmeter3-gtk1.1 (added), man/procmeter3-gtk2.1 (added), man/procmeter3-xaw.1 (added): Initial revision * Makefile: Rename executables for each version named after the source directory. Create symbolic links procmeter3-xaw -> procmeter3 and procmeter3-gtk[12] -> gprocmeter3. Change the installation targets appropriately for the renamed executables. 2007-09-26 [r283] Andrew M. Bishop * gtk1/Makefile, gtk2/Makefile, xaw/Makefile: Rename executables for each version named after the source directory. 2007-09-20 [r282] Andrew M. Bishop * gtk2/window.c: Fix the window resizing (different from GTK1). 2007-09-19 [r281] Andrew M. Bishop * gtk2/widgets/PMBar.c (added), gtk2/window.c (added), gtk2/widgets/PMGraph.h (added), gtk2/resources.c (added), gtk2/bitmap.c (added), gtk2/widgets/PMBar.h (added), gtk2/window.h (added), gtk2/widgets/PMGeneric.c (added), gtk2 (added), gtk2/widgets/PMGeneric.h (added), gtk2/widgets (added), gtk2/menus.c (added), gtk2/widgets/PMText.c (added), gtk2/Makefile (added), gtk2/widgets/PMText.h (added), gtk2/widgets/Makefile (added), gtk2/run.c (added), gtk2/widgets/PMGraph.c (added): Initial revision 2007-09-19 [r278-280] Andrew M. Bishop * gtk1/run.c: Change to look more like GTK2 version. * gtk1/Makefile, gtk1/widgets/Makefile: Makefile specifically labelled as being for GTK1. * Makefile: Make both GTK1 and GTK2 versions. 2007-09-09 Andrew M. Bishop Version 3.4g Released. 2007-09-09 [r277] Andrew M. Bishop * README, procmeter.h, NEWS: Update to version 3.4g. 2007-09-07 [r276] Andrew M. Bishop * modules/sensors.c: Use new sensors directory /sys/class/hwmon* in kernel 2.6.22 (patch from Harry G. Clayton). 2007-08-25 [r275] Andrew M. Bishop * modules/netdev.c: Change to use long long values (patch from Jacob Mandelson). 2007-08-21 [r274] Andrew M. Bishop * modules/cpuinfo.c: Fix memory allocation problem. 2007-08-10 [r273] Andrew M. Bishop * modules/stat-cpu.c: Fixed bugs with array overwriting on mult-CPU machines and mis-allocation of memory on older kernels. 2007-06-21 [r272] Andrew M. Bishop * README: Add note about being GTK 1 only. 2007-06-06 [r271] Andrew M. Bishop * modules/acpi.c: Fix the battery discharge rate statistics (mA not mW) (patch from Joey Hess). 2007-05-15 [r270] Andrew M. Bishop * modules/acpi.c: Update for kernel version 2.6.21 (patch from Joey Hess). 2007-04-17 [r269] Andrew M. Bishop * modules/datetime.c: Set the default updates for the date to be 60 seconds (so that it only takes 1 minute after unsuspending to show correct time). The uptime is now accurately described as the time that the system has been running for and not the time since boot (counter stops when suspended). 2007-02-16 [r266-268] Andrew M. Bishop * procmeter.h, NEWS: Update to version 3.4f. * modules/acpi.c: Limit string length when reading from /proc/. * modules/df.c: Use longer strings for reading /proc/mounts. 2006-07-23 [r265] Andrew M. Bishop * modules/biff.c: Check the file contents if the timestamp or size have changed. 2006-05-18 [r264] Andrew M. Bishop * gtk1/Makefile: Check for GTK1 libraries before trying to compile. 2006-04-29 Andrew M. Bishop Version 3.4e Released. 2006-04-29 [r262-263] Andrew M. Bishop * NEWS: Update to version 3.4e. * man/procmeter3_modules.1: Add the CPUInfo module. 2006-04-29 [r261] Andrew M. Bishop * procmeter.h: Update to version 3.4e. 2006-04-13 [r260] Andrew M. Bishop * modules/cpuinfo.c: Replace ' ' with '_' in output name. 2006-03-21 [r259] Andrew M. Bishop * modules/cpuinfo.c (added): Initial revision 2006-03-11 [r258] Andrew M. Bishop * modules/acpi.c: Update to synchronise code with wmbattery/sleepd (patch from Joey Hess). 2005-11-19 [r257] Andrew M. Bishop * procmeterp.h: Make the label long enough to contain the string inserted when loading the module. 2005-11-05 [r256] Andrew M. Bishop * man/procmeter3-lcd.1, man/procmeterrc.5, man/gprocmeter3.1, man/procmeter3_modules.1, man/procmeter3-log.1: Spell check and small updates. 2005-10-15 [r255] Andrew M. Bishop * modules/longrun.c, modules/netdev.c, gtk1/bitmap.c, modules/wireless.c, modules/vmstat.c, xaw/bitmap.c: Remove gcc-4.0 signed/unsigned pointer warnings. 2005-06-14 [r254] Andrew M. Bishop * modules/df.c, procmeterrc: Set the default scaling to 20% and 5 divisions. 2005-06-06 [r252-253] Andrew M. Bishop * modules/stat.c: Handle, but don't display, the new CPU statistics (iowait, irq, softirq and steal). * modules/stat-cpu.c: Added in the new CPU statistics (iowait, irq, softirq and steal). 2005-05-06 [r251] Andrew M. Bishop * modules/acpi.c: Fix a bug in acpi.c that made it not read the info file and thus, not work. See Debian bug #307278 (patch from Joey Hess). 2005-04-30 Andrew M. Bishop Version 3.4d Released. 2005-04-30 [r250] Andrew M. Bishop * procmeter.h, NEWS: Update to version 3.4d. 2005-04-30 [r248-249] Andrew M. Bishop * modules/stat-intr.c, modules/stat-cpu.c, modules/stat-disk.c: Change variables from 'long' to 'long long' (inspired by changes to stat.c). * modules/stat.c: Change variables from 'long' to 'long long' (Patch from ). 2005-02-07 [r247] Andrew M. Bishop * modules/stat-disk.c: Added /dev/mapper support (patch from ). 2004-12-11 [r246] Andrew M. Bishop * modules/acpi.c: More changes from Joey Hess for the ACPI module for kernel 2.6. 2004-11-28 [r245] Andrew M. Bishop * modules/acpi.c: Apply fixes from my branch version back into Joey's version. 2004-11-28 [r244] Andrew M. Bishop * modules/acpi.c, modules/acpi.h: Update from Joey Hess for ACPI functions. o Use the proper new-style acpi string when looking for ac adaptor status. o Base battery charge calculations for ACPI on design capacity, instead of last full capacity. Some batteries may exceed previous last full on their next charging, and this also lets you see when you have a damaged battery that is not fully charging. o If acpi battery charging state is unknown, but the rate is 0, then the battery is charged and on AC power, and the unknown state can be ignored. Analysis and patch by "TeXitoi". o Sort devices returned by readdir in acpi, since the order can be random. o Make acpi code put -1 in the time remaining field if the "present rate" is 0. o Set the cutoff point for old acpi to 20020214 (was 20020208). o Added support for ACPI version 20030109 (2.5 kernel), and generally support for changing ACPI strings across versions. 2004-11-28 [r243] Andrew M. Bishop * modules/acpi.h: Update to handle version 2.6 kernel. 2004-09-07 [r241] Andrew M. Bishop * man/procmeterrc.5: Make 'startup section' a sub-heading. 2004-09-05 Andrew M. Bishop Version 3.4c Released. 2004-09-05 [r239-240] Andrew M. Bishop * procmeter.h, NEWS: Updated for version 3.4c. * gtk1/window.c: Make sure setting grid-min and grid-max works. 2004-05-17 [r238] Andrew M. Bishop * modules/sensors.c: Handle kernel 2.6.x better. 2004-05-15 [r237] Andrew M. Bishop * gtk1/widgets/PMGraph.c: Fix bug that stopped grid_max being set. 2004-04-25 Andrew M. Bishop Version 3.4b Released. 2004-04-25 [r236] Andrew M. Bishop * procmeter.h, NEWS: Update for version 3.4b. 2004-04-04 [r235] Andrew M. Bishop * man/procmeter3_modules.1: Update with information about kernel 2.6 changes. 2004-04-03 [r231-234] Andrew M. Bishop * modules/stat-disk.c: Make sure current & previous values are reset (don't use them when checking file contents). For kernel 2.6.x use the file /proc/diskstats instead of /proc/stat. * modules/stat.c: Make sure current & previous values are reset (don't use them when checking file contents). Handle missing disk line in kernel 2.6.x. * modules/stat-intr.c, modules/vmstat.c, modules/stat-cpu.c: Make sure current & previous values are reset (don't use them when checking file contents). * modules/wireless.c: Fix bug in header detection and make sure current & previous values are reset. 2004-03-27 [r230] Andrew M. Bishop * modules/meminfo.c: Update to work with version 2.6.x kernels. 2004-03-19 [r229] Andrew M. Bishop * modules/sensors.c: Update to work with version 2.6.x kernels. 2004-01-04 [r228] Andrew M. Bishop * modules/wireless.c: Handle different header line for hostap wireless driver (patch from Joey Hess). 2003-06-28 Andrew M. Bishop Version 3.4a Released. 2003-06-28 [r227] Andrew M. Bishop * NEWS: Updated for version 3.4a. 2003-06-28 [r226] Andrew M. Bishop * procmeter.h: Updated for version 3.4a. 2003-06-21 [r222-225] Andrew M. Bishop * man/procmeter3_modules.1: Allow an options parameter to stat-disk to specify extra disk devices. * modules/stat-disk.c: Allow an options parameter to specify extra disk devices. Handle the order of disks changing at run-time. * procmeter.c: Fix memory corruption bug. * modules/longrun.c, gtk1/widgets/PMBar.c, gtk1/widgets/PMText.c, modules/datetime.c, gtk1/widgets/PMGeneric.c, gtk1/widgets/PMGraph.c: Include . 2003-05-10 [r221] Andrew M. Bishop * modules/meminfo.c: Handle more than 4 GB of memory (patch from Jan Christiaan van Winkel). 2003-04-12 [r220] Andrew M. Bishop * log/window.c: Flush stdout after printing each line. 2003-04-06 [r219] Andrew M. Bishop * man/procmeter3-lcd.1: Corrected description in manual page. 2003-03-24 [r218] Andrew M. Bishop * modules/biff.c: Don't change the atime of the mailbox (patch from Tim Connors). 2003-02-23 [r217] Andrew M. Bishop * modules/stat-intr.c: Fix for crashing when adding an interrupt graph. 2003-01-17 [r216] Andrew M. Bishop * Makefile: Don't overwrite the procmeterrc file if it already exists, but do always copy the procmeterrc.install file. 2003-01-12 Andrew M. Bishop Version 3.4 Released. 2003-01-12 [r215] Andrew M. Bishop * NEWS: Updated for version 3.4. 2002-12-08 [r213-214] Andrew M. Bishop * man/procmeter3_modules.1: Updates to the DateTime module. * modules/datetime.c: Add new time outputs that don't include the timezone. Use strftime() for all the time to text conversions. 2002-12-08 [r212] Andrew M. Bishop * lcd/window.c: Fix some out-by-one errors in text positioning. 2002-12-07 [r206-211] Andrew M. Bishop * modules/template.c: Remove PROCMETER_NAME_LEN from the comments. Don't fix the string lengths in the code. * modules/uname.c, modules/netdev.c, modules/sensors.c, modules/stat-cpu.c, modules/logfile.c, modules/stat-disk.c: Remove PROCMETER_NAME_LEN from the comments. Modify the snprintf() usage to use PROCMETER_NAME_LEN+1. * modules/df.c: Remove PROCMETER_NAME_LEN from the comments. Use snprintf() to generate the names. * modules/acpi.c: Rename some outputs to take account of longer names possible. * modules/longrun.c, modules/stat-intr.c, modules/biff.c, modules/meminfo.c, modules/stat.c, modules/datetime.c, modules/apm.c, modules/loadavg.c, modules/wireless.c, modules/vmstat.c, modules/procmeter.c: Remove PROCMETER_NAME_LEN from the comments. 2002-12-07 [r202-205] Andrew M. Bishop * gtk1/menus.c, gtk1/window.c, xaw/window.c, xaw/menus.c: Size strings based on the #define value. * procmeter.c: Handle the longer name output when displaying the '-h' information. * procmeter.h: Add #defines for the maximum length of the text string and the graph units. * module.c: Change PROCMETER_NAME_LEN for PROCMETER_NAME_LEN+1. 2002-12-01 [r200-201] Andrew M. Bishop * README, procmeter.h: Updated to version 3.4. * procmeterp.h: Renamed no-x to log. 2002-12-01 [r199] Andrew M. Bishop * lcd/window.c: Finished the graph and bar chart outputs. 2002-12-01 [r198] Andrew M. Bishop * procmeterrc.c: Don't crash if the .procmeterrc file cannot be read. 2002-11-30 [r195-197] Andrew M. Bishop * Makefile: Added procmeter3-lcd, renamed procmeter3-no-x to procmeter3-log. Added the extra manual pages. * lcd/Makefile (added), lcd (added), lcd/window.c (added): Initial revision * log/Makefile, log/window.c: Updated now that it is no-longer called 'no-x' but is 'log'. 2002-11-30 [r191-194] Andrew M. Bishop * man/procmeter3-lcd.1 (added), man/procmeter3_modules.1 (added): Initial revision * man/procmeterrc.5: Renamed procmeter3-no-x to procmeter3-log. Added the LCD section to the procmeterrc file description. * man/procmeter3-log.1: Removed the modules to a separate manual page. Renamed procmeter3-no-x to procmeter3-log. * man/procmeter3.1, man/gprocmeter3.1: Removed the modules to a separate manual page. 2002-11-29 [r190] Andrew M. Bishop * log/Makefile: Remove unneeded widget.o entry. 2002-11-09 [r189] Andrew M. Bishop * man/procmeter3.1, man/gprocmeter3.1, man/procmeter3-log.1: Added a description of the VM statistics. 2002-11-09 [r187-188] Andrew M. Bishop * modules/vmstat.c (added): Initial revision * modules/stat-intr.c, modules/stat.c, modules/stat-cpu.c, modules/stat-disk.c: Updated to be more robust and handle kernel version 2.5.x with no VM stats in /proc/stat. 2002-11-03 [r186] Andrew M. Bishop * modules/apm.c: Fix the parsing of /proc/apm where the version number contains letters. 2002-10-27 [r185] Andrew M. Bishop * modules/longrun.c: Update for glibc v2.3.x (from Joey Hess). 2002-08-24 [r184] Andrew M. Bishop * Makefile: Added an extra variable to set the man pages directory. 2002-08-10 Andrew M. Bishop Version 3.3b Released. 2002-08-10 [r183] Andrew M. Bishop * NEWS: Updated for version 3.3b. 2002-07-07 [r182] Andrew M. Bishop * modules/netdev.c: Use of uninitialised memory (found by valgrind). 2002-07-06 [r181] Andrew M. Bishop * module.c: Fix potential pointer problem (patch inspired by Nix). 2002-07-06 [r180] Andrew M. Bishop * procmeterrc.c: Avoid walking off the start of the line on completely blank lines (patch from Nix). 2002-06-30 [r178-179] Andrew M. Bishop * Makefile: Make the clean target go into the no-x directory. * modules/acpi.c: Remove an ACPI potential crash (patch from Joey Hess). 2002-06-16 [r175-177] Andrew M. Bishop * Makefile: Make the RC_PATH Makefile variable and CPP definition a pathname and not a filename. Install the procmeterrc.install file in all cases and also as procmeterrc if not existing. * procmeterp.h, procmeterrc.c: Make the RC_PATH Makefile variable and CPP definition a pathname and not a filename. * modules/Makefile: Remove the RC_PATH variable, it is not used. 2002-06-04 [r172-174] Andrew M. Bishop * Makefile: Delete the executables when doing 'make distclean'. * gtk1/window.c, modules/uname.c, modules/biff.c, modules/stat.c, modules/template.c, modules/acpi.c, modules/loadavg.c, modules/apm.c, procmeterp.h, module.c, modules/logfile.c, modules/longrun.c, modules/netdev.c, modules/stat-intr.c, modules/meminfo.c, modules/sensors.c, modules/datetime.c, procmeter.h, modules/wireless.c, xaw/window.c, modules/procmeter.c, modules/stat-cpu.c, modules/stat-disk.c: Make the length of the output name be a compile time variable rather than a hard-coded constant. * modules/df.c: Make the length of the output name be a compile time variable rather than a hard-coded constant. Handle NFS mounted disks. 2002-06-04 [r163-171] Andrew M. Bishop * Makefile: Added procmeter3-no-x program. * procmeter.c: Move common code here, change names of functions to start, stop X windows part. * procmeterp.h: Add prototypes for the moved code and wrapper functions for widget updates. Change prototypes/names of functions to start, stop X windows part. * module.c: Initialise all parts of the Output and Module structures. * gtk1/window.c, xaw/window.c: Remove the common parts to ../procmeter.c and add wrapper functions for widget updates. * gtk1/window.h, xaw/window.h: Add prototypes for Resize() and MoveOutput(). * gtk1/menus.c: Don't try and do anything if X has not been initialised (e.g. gprocmeter3 -h). * xaw/menus.c: Don't try and do anything if X has not been initialised (e.g. procmeter3 -h). * log/Makefile (added), log (added), no-x (added), no-x/run.c (added), no-x/menus.c (added), log/window.c (added): Initial revision 2002-06-04 [r162] Andrew M. Bishop * modules/longrun.c: Add some more details to the description of the module. 2002-06-04 [r161] Andrew M. Bishop * modules/longrun.c, modules/wireless.c: Remove the error messages for people who don't have this unusual hardware (same as other modules). 2002-06-03 [r159-160] Andrew M. Bishop * man/procmeter3-log.1 (added): Initial revision * man/gprocmeter3.1: Updated the manual page to include the changes from procmeter3.1. 2002-06-02 [r158] Andrew M. Bishop * modules/acpi.c: Fix for /proc/acpi with no status file in it (From Joey Hess). 2002-04-20 [r156-157] Andrew M. Bishop * modules/acpi.c: Bug fix if there is no battery info (from Joey Hess). * man/procmeter3.1: Manual page update for ACPI module (from Joey Hess). 2002-04-20 [r155] Andrew M. Bishop * modules/netdev.c: Handle the cases of device statistics going to zero and wrapping around separately. 2002-04-14 [r154] Andrew M. Bishop * README: Add acknowledgement of the Joey Hess contributed modules. 2002-04-14 [r153] Andrew M. Bishop * modules/longrun.c (added), modules/acpi.c (added), modules/acpi.h (added): Initial revision 2002-04-14 [r152] Andrew M. Bishop * modules/datetime.c: Small type declaration tidy-up. 2002-04-14 [r151] Andrew M. Bishop * man/procmeter3.1: Added documentation for the wireless andd longrun modules. 2002-01-26 [r150] Andrew M. Bishop * modules/wireless.c: Ignore bogus results from kernel and calculate it ourselves. (patch from Joey Hess). 2002-01-20 [r149] Andrew M. Bishop * modules/wireless.c: Handle more bogus values from card. (patch from Joey Hess). 2001-12-16 [r148] Andrew M. Bishop * modules/df.c: Updated to allow NFS mounts to appear. 2001-12-02 [r147] Andrew M. Bishop * modules/wireless.c: Handle bogus values from card. (patch from Joey Hess). 2001-12-02 [r146] Andrew M. Bishop * modules/wireless.c (added): Initial revision (file from Joey Hess). 2001-11-11 [r145] Andrew M. Bishop * modules/datetime.c: Added in a 12 hour clock option. (patch from Joey Hess). 2001-07-22 [r144] Andrew M. Bishop * modules/df.c: Fix DF free giving multiples of 1024 blocks instead of finer granularity. 2001-07-08 [r143] Andrew M. Bishop * modules/stat.c: Fix disk statistics. 2001-05-27 Andrew M. Bishop Version 3.3a Released. 2001-05-27 [r142] Andrew M. Bishop * procmeter.h, NEWS: Updated to version 3.3a. 2001-04-15 [r141] Andrew M. Bishop * modules/netdev.c: Clear the network statistics in case the device is removed from the file. 2001-02-21 [r140] Andrew M. Bishop * modules/stat-disk.c: Updated the kernel 2.4 disk statistics. 2001-02-14 [r139] Andrew M. Bishop * modules/stat.c: Updated the kernel 2.4 disk statistics. 2001-02-02 [r138] Andrew M. Bishop * Makefile: Fix the installation directory. 2001-01-05 Andrew M. Bishop Version 3.3 Released. 2001-01-05 [r137] Andrew M. Bishop * NEWS: Updated to version 3.3. 2001-01-05 [r132-136] Andrew M. Bishop * README: Update with information about gprocmeter3. * Makefile: Allow compilation of the programs individually. Improve the installation procedure. * procmeterrc: Updated with a note about the options that don't work with GTK. * man/gprocmeter3.1 (added): Initial revision * man/procmeter3.1, man/procmeterrc.5: Updated the manual pages. 2001-01-04 [r129-131] Andrew M. Bishop * xaw/widgets/PMGeneric.c, xaw/widgets/PMGenericP.h, xaw/widgets/PMGraph.c, xaw/widgets/PMBar.c, xaw/widgets/PMText.c: Update the generic widget to match GTK widgets. Change the variable name for the widget to match GTK widgets. * gtk1/widgets/PMBar.c, gtk1/widgets/PMText.c, gtk1/widgets/PMGeneric.c, gtk1/widgets/PMGraph.c: Change some function names to match the Xaw widgets. * Makefile: Pass the LDFLAGS into the xaw and gtk sub-directories. 2000-12-16 [r127-128] Andrew M. Bishop * xaw/widgets/PMGeneric.c, xaw/widgets/PMGraph.c, xaw/widgets/PMBar.c, xaw/widgets/PMText.c, xaw/widgets/PMGraph.h, xaw/widgets/PMBar.h, xaw/widgets/PMText.h: Change some functions to get commonality with GTK version. * xaw/widgets/Makefile: Makefile improvements. 2000-12-16 [r126] Andrew M. Bishop * xaw/Makefile (added): Initial revision 2000-12-16 [r122-125] Andrew M. Bishop * xaw/window.c: Change the name of the files. Use display as an extern variable and not pane. Change some functions to match the GTK version. * xaw/run.c: Change the name of the files. Use display as an extern variable and not pane. * xaw/menus.c: Change the name of the files. Make some small changes to match up with the GTK version. * xaw/resources.c, xaw/bitmap.c, xaw/window.h: Change the name of the files. 2000-12-16 [r121] Andrew M. Bishop * gtk1/widgets/PMBar.c (added), gtk1/window.c (added), gtk1/widgets/PMGraph.h (added), gtk1/resources.c (added), gtk1/widgets/PMBar.h (added), gtk1/window.h (added), gtk1/bitmap.c (added), gtk1/widgets/PMGeneric.c (added), gtk1 (added), gtk1/widgets/PMGeneric.h (added), gtk1/widgets (added), gtk1/menus.c (added), gtk1/widgets/PMText.c (added), gtk1/Makefile (added), gtk1/widgets/PMText.h (added), gtk1/widgets/Makefile (added), gtk1/widgets/PMGraph.c (added), gtk1/run.c (added): Initial revision 2000-12-16 [r119-120] Andrew M. Bishop * modules/Makefile: Some makefile improvements. * procmeterrc.c: Removed a gcc compilation warning. 2000-12-16 [r117-118] Andrew M. Bishop * procmeterp.h: Updated the comments to include the new file names. * procmeter.h: Updated to version 3.3. 2000-12-16 [r116] Andrew M. Bishop * Makefile: Added gtk, moved xaw parts to sub-directory. 2000-12-13 Andrew M. Bishop Version 3.2b Released. 2000-12-13 [r114-115] Andrew M. Bishop * procmeter.h, NEWS: Updated to version 3.2b. * modules/stat-intr.c, modules/stat.c, modules/stat-cpu.c, modules/stat-disk.c: Fix for change to version 2.4 kernel format. 2000-10-22 Andrew M. Bishop Version 3.2a Released. 2000-10-22 [r113] Andrew M. Bishop * procmeter.h, NEWS: Updated for version 3.2a. 2000-10-22 [r110-112] Andrew M. Bishop * procmeterrc.c: Remove a gcc compilation warning. * procmeter.c: Update the usage information. * modules/stat.c, modules/stat-disk.c: Make work with kernel 2.4.0. 2000-03-21 [r109] Andrew M. Bishop * man/procmeter3.1: Make more clear about the command line options. 2000-01-23 [r108] Andrew M. Bishop * xaw/widgets/PMGeneric.c, xaw/widgets/PMText.c: Use a default font if the user specified one does not exist. 1999-12-16 [r107] Andrew M. Bishop * procmeterrc.c: Close the .procmeterrc file after reading from it. 1999-12-12 Andrew M. Bishop Version 3.2 Released. 1999-12-12 [r106] Andrew M. Bishop * NEWS: Updated to version 3.2. 1999-12-12 [r105] Andrew M. Bishop * modules/df.c: Removed problems with recognising mounts in /etc/fstab that can't be monitored. 1999-12-08 [r104] Andrew M. Bishop * procmeter.c: Updated the usage information. 1999-12-06 [r102-103] Andrew M. Bishop * README: Updated to version 3.2. * man/procmeter3.1, procmeter.c, man/procmeterrc.5, procmeterp.h, procmeterrc.c: Allow command line options to override the .procmeterrc file. The sections and parameters in the .procmeterrc file are not case sensitive. 1999-12-05 [r101] Andrew M. Bishop * xaw/run.c: Set the display environment variable before forking. 1999-12-05 [r100] Andrew M. Bishop * modules/sensors.c: Check for more files in the /proc/sys/dev/sensors directories. 1999-12-04 [r97-99] Andrew M. Bishop * xaw/run.c: Fix bug with memory allocation. * procmeter.c, procmeterrc.c, procmeterp.h: Free the procmeterrc file memory at the end. * module.c: Free the memory for the run command. 1999-12-04 [r96] Andrew M. Bishop * modules/sensors.c: Updated the Unload() function to make memory cleanup safer. 1999-12-03 [r95] Andrew M. Bishop * modules/netdev.c, modules/df.c, modules/datetime.c, modules/stat-cpu.c, modules/logfile.c: Updated the Unload() function to make memory cleanup safer. 1999-11-30 [r93-94] Andrew M. Bishop * xaw/run.c (added): Initial revision * Makefile, man/procmeterrc.5, procmeterrc, module.c, procmeterp.h, xaw/menus.c: Add in simplified method of specifying programs to run. 1999-10-05 [r90-92] Andrew M. Bishop * man/procmeterrc.5: Add a note about grid-min and bar charts. * xaw/window.c: Resize the widget in the same way as the graph. * xaw/widgets/PMBar.c, xaw/widgets/PMBarP.h: Add a rolling average over the last 8 samples. 1999-10-04 [r89] Andrew M. Bishop * modules/logfile.c: Bug fix for bar output changes. 1999-09-30 [r88] Andrew M. Bishop * man/procmeterrc.5: Added a bar chart widget. 1999-09-30 [r87] Andrew M. Bishop * xaw/widgets/PMBar.c (added), xaw/widgets/PMBar.h (added), xaw/widgets/PMBarP.h (added): Initial revision 1999-09-29 [r86] Andrew M. Bishop * man/procmeter3.1, modules/template.c, modules/stat.c, modules/loadavg.c, xaw/menus.c, modules/logfile.c, Makefile, modules/stat-intr.c, modules/netdev.c, procmeter.c, xaw/widgets/Makefile, modules/df.c, modules/meminfo.c, modules/sensors.c, procmeter.h, xaw/window.c, modules/stat-cpu.c, modules/stat-disk.c, xaw/bitmap.c, xaw/window.h: Added a bar chart widget. 1999-09-29 [r85] Andrew M. Bishop * xaw/widgets/SubMenus.c: Bug fix for menu popup failures. 1999-09-28 [r83-84] Andrew M. Bishop * xaw/menus.c: Add a third level of menus to select the type of output. * xaw/widgets/SubMenus.c: Fix problems with deep sub menus. 1999-09-27 [r80-82] Andrew M. Bishop * xaw/widgets/SubMenus.c (added), xaw/widgets/SubMenus.h (added): Initial revision * xaw/widgets/Makefile: Add the SubMenus file. * Makefile, xaw/menus.c: Abstract the submenu operations in new files widgets/SubMenus.[ch]. 1999-09-24 [r78-79] Andrew M. Bishop * xaw/menus.c: Add a delete option to the function menu. * module.c: Allow the update interval to be specified globally in the resources section of the config file. 1999-09-24 [r77] Andrew M. Bishop * man/procmeterrc.5: Allow the update interval to be specified globally in the resources section of the config file. 1999-09-24 [r76] Andrew M. Bishop * man/procmeterrc.5, module.c, procmeterp.h, xaw/menus.c, xaw/window.c: Allow the labels on the outputs to be changed. 1999-09-24 [r75] Andrew M. Bishop * module.c: Don't change to the library directory when running. 1999-08-31 [r72-74] Andrew M. Bishop * xaw/resources.c, xaw/window.h: Simpler parsing of config file options. * xaw/window.c: Better handling of colour options in the config file. * xaw/menus.c: Better handling of colour options in the config file. Force the dialog box labels to be flat even with Xaw3d. 1999-08-30 [r71] Andrew M. Bishop * procmeterrc: Changed the white background to almost-white to work better with Xaw3d. 1999-08-22 Andrew M. Bishop Version 3.1c Released. 1999-08-22 [r70] Andrew M. Bishop * procmeter.h, NEWS: Updated to version 3.1c. 1999-07-28 [r69] Andrew M. Bishop * man/procmeter3.1: Added in the sensors module. 1999-07-28 [r68] Andrew M. Bishop * modules/sensors.c (added): Initial revision 1999-07-06 [r67] Andrew M. Bishop * modules/stat-cpu.c: Fix for SMP machines. 1999-06-19 Andrew M. Bishop Version 3.1b Released. 1999-06-19 [r66] Andrew M. Bishop * procmeter.h, NEWS: Updated to version 3.1b. 1999-06-19 [r65] Andrew M. Bishop * modules/netdev.c, modules/stat-intr.c, modules/stat.c, modules/stat-disk.c: Ensure that negative outputs never appear (ppp0 start/stop or 32bit wrap around). 1999-06-19 [r64] Andrew M. Bishop * procmeter.c: List the available formats (graph or text) in the '-h' output. 1999-06-19 [r63] Andrew M. Bishop * man/procmeter3.1, man/procmeterrc.5: Improve the manual page documentation. 1999-05-20 [r62] Andrew M. Bishop * Makefile: Change the XINCLUDE path to use X11R6. 1999-04-18 Andrew M. Bishop Version 3.1a Released. 1999-04-18 [r61] Andrew M. Bishop * procmeter.h, NEWS: Updated to version 3.1a. 1999-04-18 [r59-60] Andrew M. Bishop * modules/netdev.c: Fixed problems with newer kernels and bytecounts. * modules/Makefile: Added -Wall to CFLAGS. 1999-04-17 [r58] Andrew M. Bishop * xaw/widgets/Makefile: Added the include path for the X include files. 1999-03-14 [r57] Andrew M. Bishop * xaw/widgets/PMGraph.c: Bug fix with resizing the window. 1999-03-07 [r56] Andrew M. Bishop * Makefile: Change the X library path. 1999-03-06 Andrew M. Bishop Version 3.1 Released. 1999-03-06 [r55] Andrew M. Bishop * NEWS: Updated to version 3.1. 1999-03-06 [r54] Andrew M. Bishop * modules/netdev.c: Fix bug with byte and packet outputs confusion. 1999-03-03 [r53] Andrew M. Bishop * xaw/window.c: Add a new startup section with an order option instead of the start-text/graph options. 1999-03-03 [r52] Andrew M. Bishop * man/procmeterrc.5, procmeterrc: Add a new startup section with an order option instead of the start-text/graph options. 1999-03-03 [r51] Andrew M. Bishop * man/procmeter3.1: Add in the multiple CPU, disk and interrupt outputs. 1999-03-03 [r49-50] Andrew M. Bishop * modules/stat-intr.c (added), modules/stat-cpu.c (added), modules/stat-disk.c (added): Initial revision * modules/stat.c: Increase the buffer length for interrupts in kernel version 2.2.2. 1999-02-24 [r48] Andrew M. Bishop * modules/meminfo.c: Add in a memory available option which is the free memory plus the disk cache. 1999-02-23 [r47] Andrew M. Bishop * modules/netdev.c: Add in the number of bytes per second on the network interfaces. 1999-02-16 [r46] Andrew M. Bishop * xaw/widgets/PMGraph.c: Bug fix for grid_max. 1999-02-13 [r42-45] Andrew M. Bishop * man/procmeterrc.5, module.c, xaw/menus.c, xaw/window.c: Allow the grid-max, update and graph-scale parameters to be user specified in the .procmeterrc file. * modules/netdev.c, modules/df.c, modules/meminfo.c, modules/stat.c, modules/template.c, modules/README, modules/loadavg.c, procmeter.h, modules/procmeter.c, modules/logfile.c: Change the graph_units parameter to allow different graph_scale values to be user specified. * xaw/widgets/PMGraph.c, xaw/widgets/PMGraph.h, xaw/widgets/PMGraphP.h: Allow the maximum number of grid lines to be specified. * Makefile: Rename the default .procmeterrc to procmeterrc since system defaults don't normally have a '.'. 1999-02-12 [r41] Andrew M. Bishop * man/procmeterrc.5: Rename the default .procmeterrc to procmeterrc since system defaults don't normally have a '.'. 1999-02-09 [r40] Andrew M. Bishop * xaw/menus.c: Add a configuration file option to specify a program to run from the menu. Change the popping up of menus to make sure they are on screen. 1999-02-09 [r39] Andrew M. Bishop * procmeterrc: More information and preconfigured options. 1999-02-09 [r38] Andrew M. Bishop * modules/datetime.c: Make the text for the uptime display centre better. 1999-02-09 [r37] Andrew M. Bishop * man/procmeterrc.5: Add a configuration file option to specify a program to run from the menu. 1999-02-09 [r36] Andrew M. Bishop * procmeter.c, module.c, procmeterp.h: Add a configuration file option to specify a program to run from the menu. 1999-02-07 [r35] Andrew M. Bishop * xaw/window.c: Allow the output displays to be moved around while running. 1999-02-07 [r34] Andrew M. Bishop * Makefile, modules/Makefile, procmeterp.h: Updated the way that the paths are specified and compiled into the program. 1999-02-07 [r33] Andrew M. Bishop * procmeterp.h, xaw/menus.c: Allow the output displays to be moved around while running. 1999-02-06 [r32] Andrew M. Bishop * xaw/menus.c: Add more information to the properties display window. 1998-10-24 Andrew M. Bishop Version 3.0a Released. 1998-10-24 [r26-31] Andrew M. Bishop * NEWS (added): Initial revision * procmeter.h: Updated to version 3.0a. * README: More information about the Internet resources. * man/procmeter3.1: A slight re-order of the information. * procmeter.c: Format the 'procmeter3 -h' output nicely. * modules/uname.c: Remove a trailing newline from the text description string. 1998-10-24 [r20-25] Andrew M. Bishop * procmeterrc: Default to having the version number visible. * xaw/window.c: Use an inclusive OR not and exclusive or when adding the default graphs. * xaw/widgets/PMGraph.c: Left align the graph title to leave more room for the units label. * modules/uname.c: Truncate the hostname to the host part. * modules/meminfo.c: Make the units label on the graph consistent. * modules/netdev.c, modules/df.c, modules/logfile.c: Ensure that the module starts without an error if there are no outputs. 1998-10-09 Andrew M. Bishop Version 3.0 Released. 1998-10-09 [r19] Andrew M. Bishop * modules/apm.c: Ignore the APM version number (until I can find what the differences are). 1998-09-26 [r17-18] Andrew M. Bishop * xaw/widgets/PMGraph.c: Don't draw the graph units label if there is no generic label. * xaw/menus.c: Ensure that the menus popup in the correct place first time. 1998-09-26 [r11-16] Andrew M. Bishop * modules/df.c (added), modules/logfile.c (added): Initial revision * man/procmeter3.1: Add the LogFile and DiskUsage modules. * xaw/window.c: Clamp the graph values to 0<=x<=65535. * modules/biff.c: Change in line counting. * modules/netdev.c, module.c: Bug fix in options parsing. * Makefile: Improve the makefile. 1998-09-22 [r10] Andrew M. Bishop * modules/netdev.c: Don't add the same device more than once. 1998-09-22 [r9] Andrew M. Bishop * modules/netdev.c, modules/stat.c, modules/loadavg.c, modules/procmeter.c: Fix some typos. 1998-09-22 [r8] Andrew M. Bishop * modules/meminfo.c: Changed Mem_Swap to Swap_Free and Swap_Used. 1998-09-21 [r7] Andrew M. Bishop * modules/biff.c (added): Initial revision 1998-09-21 [r5-6] Andrew M. Bishop * man/procmeter3.1: Added the biff module. * modules/README: Clarification of the Initialise() function. 1998-09-19 Andrew M. Bishop Version 3.0-beta released. 1998-09-19 [r3-4] Andrew M. Bishop * procmeterrc (added): Initial revision * Makefile, modules/Makefile, procmeterp.h: Fix the make install problems. 1998-09-19 [r2] Andrew M. Bishop * README (added), man/procmeter3.1 (added), modules/uname.c (added), xaw/widgets/PMGeneric.c (added), xaw (added), xaw/widgets/PMGeneric.h (added), modules/template.c (added), modules/stat.c (added), xaw/widgets (added), modules/loadavg.c (added), modules/apm.c (added), module.c (added), xaw/menus.c (added), xaw/widgets/PMText.c (added), xaw/widgets/PMText.h (added), procmeter.c (added), xaw/widgets/Makefile (added), xaw/widgets/PMGraph.c (added), modules/Makefile (added), procmeter.h (added), xaw/window.c (added), xaw/widgets/PMGraph.h (added), xaw/resources.c (added), xaw/bitmap.c (added), xaw/window.h (added), man/procmeterrc.5 (added), modules/README (added), procmeterp.h (added), procmeterrc.c (added), modules (added), xaw/widgets/PMGraphP.h (added), man (added), Makefile (added), modules/netdev.c (added), modules/meminfo.c (added), xaw/widgets/PMGenericP.h (added), modules/datetime.c (added), modules/procmeter.c (added), xaw/widgets/PMTextP.h (added): Initial revision procmeter3-3.5d/LSM000066400000000000000000000017351165060751200141770ustar00rootroot00000000000000Begin3 Title: Procmeter3 - Linux system monitoring program Version: 3.5d [Oct-03-11] Entered-date: 03OCT11 Description: Displays in a series of graph (using X windows) statistics about the system status (amount of CPU, memory, disk accesses, IP packets) and user level information (date, time, mailbox size). Uses the /proc filesystem and other sources of information. Compiles with either the Athena or GTK widget set. Other versions can log to a file or display on a small LCD screen. Keywords: Linux X-Windows proc meter cpu load packet memory clock biff Author: amb@gedanken.demon.co.uk Maintained-by: amb@gedanken.demon.co.uk Primary-site: http://www.gedanken.demon.co.uk/download-procmeter 145 kB procmeter3-3.5c.tgz Alternate-site: http://gedanken.org.uk/software/procmeter3 Original-site: Platforms: Linux X-Windows Copying-policy: GPL End procmeter3-3.5d/Makefile000066400000000000000000000143051165060751200152560ustar00rootroot00000000000000# # ProcMeter - A system monitoring program for Linux - Version 3.5d. # # Makefile. # # Written by Andrew M. Bishop # # This file Copyright 1994-2011 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Paths # INSTDIR - the default root directory for the package INSTDIR=/usr/local # MANDIR - the directory to install man pages to MANDIR=$(INSTDIR)/share/man # LIB_PATH - the root dir for library files LIB_PATH=$(INSTDIR)/lib/X11/ProcMeter3 # MOD_PATH - the path modules are stored in MOD_PATH=$(LIB_PATH)/modules # RC_PATH - file the procmeterrc is stored in RC_PATH=$(LIB_PATH) # Programs CC=gcc LD=gcc # Program options CFLAGS=-g -O2 -Wall LDFLAGS=-rdynamic PATHDEFS=-DINSTDIR=\"$(INSTDIR)\" -DLIB_PATH=\"$(LIB_PATH)\" \ -DMOD_PATH=\"$(MOD_PATH)\" -DRC_PATH=\"$(RC_PATH)\" # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) ######## all : procmeter3-xaw procmeter3-gtk1 procmeter3-gtk2 procmeter3-log procmeter3-lcd ######## procmeter3-xaw : obj procmeter3.modules procmeterrc.install procmeter3-gtk1 : obj procmeter3.modules procmeterrc.install procmeter3-gtk2 : obj procmeter3.modules procmeterrc.install procmeter3-log : obj procmeter3.modules procmeterrc.install procmeter3-lcd : obj procmeter3.modules procmeterrc.install ######## obj : $(OBJ) %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(PATHDEFS) procmeter.o : procmeter.c procmeterp.h procmeter.h module.o : module.c procmeterp.h procmeter.h procmeterrc.o : procmeterrc.c procmeterp.h procmeter.h ######## .PHONY : procmeter3.modules procmeter3.modules : $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" -C modules ######## procmeter3-xaw : $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" -C xaw [ -f procmeter3 ] || ln -s procmeter3-xaw procmeter3 procmeter3-gtk1 : $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" -C gtk1 procmeter3-gtk2 : $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" -C gtk2 procmeter3-log : $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" -C log procmeter3-lcd : $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" -C lcd ######## .PHONY : procmeterrc procmeterrc.install: procmeterrc Makefile sed -e "s%path=modules%path=$(MOD_PATH)%" < procmeterrc > procmeterrc.install ######## .PHONY : clean distclean clean : -rm -f *.o *~ core procmeterrc.install $(MAKE) -C modules clean $(MAKE) -C xaw clean $(MAKE) -C gtk1 clean $(MAKE) -C gtk2 clean $(MAKE) -C log clean $(MAKE) -C lcd clean distclean : clean -rm -f procmeter3-xaw procmeter3-gtk1 procmeter3-gtk2 procmeter3-log procmeter3-lcd -rm -f procmeter3 gprocmeter3 $(MAKE) -C modules distclean ######## .PHONY : install install-strip install : @[ -f procmeter3-xaw ] || [ -f procmeter3-gtk1 ] || [ -f procmeter3-gtk2 ] || [ -f procmeter3-log ] || [ -f procmeter3-lcd ] || \ (echo "*** Run 'make all' or 'make procmeter3-xaw' or 'make procmeter3-gtk1' or 'make procmeter3-gtk2' or 'make procmeter3-log' or 'make procmeter3-lcd' first." ; exit 1) install -d $(DESTDIR)$(LIB_PATH) install -d $(DESTDIR)$(MOD_PATH) install -d $(DESTDIR)$(RC_PATH) # $(MAKE) -C modules install STRIP=$(STRIP) INSTDIR=$(INSTDIR) MOD_PATH=$(MOD_PATH) LIB_PATH=$(LIB_PATH) # install -d $(DESTDIR)$(INSTDIR)/bin [ ! -f procmeter3-xaw ] || install $(STRIP) -m 755 procmeter3-xaw $(DESTDIR)$(INSTDIR)/bin @[ -f procmeter3-xaw ] || (echo "" ; echo "*** The procmeter3-xaw program has not been installed (it does not exist)." ; echo "") [ ! -f procmeter3-xaw ] || ln -sf procmeter3-xaw $(DESTDIR)$(INSTDIR)/bin/procmeter3 [ ! -f procmeter3-gtk1 ] || install $(STRIP) -m 755 procmeter3-gtk1 $(DESTDIR)$(INSTDIR)/bin @[ -f procmeter3-gtk1 ] || (echo "" ; echo "*** The procmeter3-gtk1 program has not been installed (it does not exist)." ; echo "") [ ! -f procmeter3-gtk2 ] || install $(STRIP) -m 755 procmeter3-gtk2 $(DESTDIR)$(INSTDIR)/bin @[ -f procmeter3-gtk2 ] || (echo "" ; echo "*** The procmeter3-gtk2 program has not been installed (it does not exist)." ; echo "") [ -f procmeter3-gtk2 ] || [ ! -f procmeter3-gtk1 ] || ln -sf procmeter3-gtk1 $(DESTDIR)$(INSTDIR)/bin/gprocmeter3 [ ! -f procmeter3-gtk2 ] || ln -sf procmeter3-gtk2 $(DESTDIR)$(INSTDIR)/bin/gprocmeter3 [ ! -f procmeter3-log ] || install $(STRIP) -m 755 procmeter3-log $(DESTDIR)$(INSTDIR)/bin @[ -f procmeter3-log ] || (echo "" ; echo "*** The procmeter3-log program has not been installed (it does not exist)." ; echo "") [ ! -f procmeter3-lcd ] || install $(STRIP) -m 755 procmeter3-lcd $(DESTDIR)$(INSTDIR)/bin @[ -f procmeter3-lcd ] || (echo "" ; echo "*** The procmeter3-lcd program has not been installed (it does not exist)." ; echo "") # install -d $(DESTDIR)$(MANDIR)/man1 install -d $(DESTDIR)$(MANDIR)/man5 [ ! -f procmeter3-xaw ] || install -m 644 man/procmeter3-xaw.1 man/procmeter3.1 $(DESTDIR)$(MANDIR)/man1 [ ! -f procmeter3-log ] || install -m 644 man/procmeter3-log.1 $(DESTDIR)$(MANDIR)/man1 [ ! -f procmeter3-lcd ] || install -m 644 man/procmeter3-lcd.1 $(DESTDIR)$(MANDIR)/man1 [ ! -f procmeter3-gtk1 ] || install -m 644 man/procmeter3-gtk1.1 man/gprocmeter3.1 $(DESTDIR)$(MANDIR)/man1 [ ! -f procmeter3-gtk2 ] || install -m 644 man/procmeter3-gtk2.1 man/gprocmeter3.1 $(DESTDIR)$(MANDIR)/man1 install -m 644 man/procmeterrc.5 $(DESTDIR)$(MANDIR)/man5 install -m 644 man/procmeter3_modules.1 $(DESTDIR)$(MANDIR)/man1 # [ ! -f $(DESTDIR)$(RC_PATH)/.procmeterrc ] || mv $(DESTDIR)$(RC_PATH)/.procmeterrc $(DESTDIR)$(RC_PATH)/procmeterrc @[ ! -f $(DESTDIR)$(RC_PATH)/procmeterrc ] || (echo "" ; echo "*** The $(DESTDIR)$(RC_PATH)/procmeterrc file has not been installed (it already exists)." ; echo "") [ -f $(DESTDIR)$(RC_PATH)/procmeterrc ] || install -m 644 procmeterrc.install $(DESTDIR)$(RC_PATH)/procmeterrc install -m 644 procmeterrc.install $(DESTDIR)$(RC_PATH) # install -d $(DESTDIR)$(LIB_PATH)/include install -m 644 procmeter.h $(DESTDIR)$(LIB_PATH)/include install-strip : $(MAKE) install STRIP=-s procmeter3-3.5d/NEWS000066400000000000000000000314301165060751200143130ustar00rootroot00000000000000Version 3.5d of ProcMeter3 released : Mon Oct 3 18:00:00 2011 ------------------------------------------------------------- Bug Fixes Remove gcc-4.4 compilation warnings. Make error messages consistent. Fix several errors in manual pages. Don't crash if /proc/interrupts has very long lines. New features Added an option to limit the number of interrupts listed. Allow installation of stripped executables. Version 3.5c of ProcMeter3 released : Sat Feb 20 14:00:00 2010 -------------------------------------------------------------- Bug Fixes Remove 64-bit compilation warnings and fix variable type mismatch. Fixed df module to handle disks bigger than 2TB. Fixed sensors module to handle new directory format. Pass top-level Makefile variables down to sub directories. New features Sort the module menu into alphabetical order. New modules FanSpeed, Temperature & Voltage - Improved hardware sensors (see below). **** NOTE **** The new hardware sensor modules require the use of the libsensors library. The advantage is that it reads the system sensors.conf file (which can contain customisation of scaling and names - essential for some sensors). The existing "Sensors" module raises a warning when used and the module will be removed in a future version of the program. **** NOTE **** Version 3.5b of ProcMeter3 released : Thu Oct 23 19:30:00 2008 -------------------------------------------------------------- Bug Fixes Be more careful looking for modules (check '.' and '..'). Set the locale to "C" to avoid problems parsing numbers. Ensure that graph-min and graph-max options are used properly. Extended the line buffer size for parsing /proc/interrupts. Remove fixed size line buffers in modules (realloc more space as needed). Allow LCD version to specify priority as a string or numeric value. New Features Extended Window Manager Hints can be specified with a -w option. Increase the number of interrupts possible in stat-intr. Version 3.5a of ProcMeter3 released : Sun Dec 16 15:00:00 2007 -------------------------------------------------------------- Bug Fixes Stop the GTK2 version crashing when displayed items are removed. Make sure that the right mouse button menu works with no outputs displayed. Make the GTK1 and GTK2 version windows resize themselves like Xaw version. Updates to manual pages to reflect new executable names. Bug fixes for ACPI module. Version 3.5 of ProcMeter3 released : Tue Nov 20 19:30:00 2007 ------------------------------------------------------------- New features Added a gtk2 version of ProcMeter3. Renamed the executables but added backwards compatibility links. Added DESTDIR option to Makefiles. **** IMPORTANT **** The Xaw version is now named procmeter3-xaw instead of procmeter3. A symbolic link to the original name will still be created and installed. The GTK1 version is now named procmeter3-gtk1 instead of gprocmeter3. The GTK2 version is named procmeter3-gtk2. If only one or the other GTK version is compiled then a link will be created to it from the name gprocmeter3. **** IMPORTANT **** Version 3.4g of ProcMeter3 released : Sun Sep 9 15:30:00 2007 ------------------------------------------------------------- Bug fixes: Quicker default update of the date displays (useful after suspending). Uptime now accurately shows system running time even after suspend. Fix ACPI battery discharge rates. Fix for crashes with stat-cpu outputs on multi-CPU machines. Change to use longer integer values for netdev outputs. Search other places for hardware sensors information. Version 3.4f of ProcMeter3 released : Fri Feb 16 09:45:00 2007 -------------------------------------------------------------- Bug fixes: The biff module re-reads the inbox if the size or timestamp change. The df module uses longer strings for reading from /proc/mounts. Version 3.4e of ProcMeter3 released : Sat Apr 29 16:00:00 2006 -------------------------------------------------------------- Bug fixes: Fix some spelling mistakes in the manual pages. Change the default scaling for the DiskUsage outputs to 5 grid lines of 20%. Fix some gcc-4.x compilation warnings. Fix some ACPI module bugs. New or changed modules: Add in the new CPU statistics (iowait, irq, softirq and steal). Add in a display of the CPU clock speed. Version 3.4d of ProcMeter3 released : Sat Apr 30 16:00:00 2005 -------------------------------------------------------------- Bug fixes: Updated ACPI support to handle kernel version 2.6. Added support for /dev/mapper in disk statistics. Change to using 64-bit variables from /proc/stat. Version 3.4c of ProcMeter3 released : Sun Sep 5 14:30:00 2004 ------------------------------------------------------------- Bug fixes: Make grid-max option work for GTK version. Handle kernel 2.6.x better for hardware sensors. Version 3.4b of ProcMeter3 released : Sun Apr 25 09:10:00 2004 -------------------------------------------------------------- New or changed modules: The stat-disk module can display individual disk partitions for kernel 2.6.x. The modules stat, stat-disk, sensors and meminfo now work with kernel 2.6.x. Handle different header line for hostap wireless driver. Bug fixes: Modules that didn't work with kernel 2.6.x now do (see above). Improved some module initialisation functions. **** IMPORTANT **** For kernel version 2.6.x the disk statistics are in /proc/diskstats and not /proc/stat. All configuration references to Statistics.Disk need to be changed to Stat-Disk.Disk. Statistics.Disk -> Stat-Disk.Disk **** IMPORTANT **** Version 3.4a of ProcMeter3 released : Sat Jun 28 20:00:00 2003 -------------------------------------------------------------- New or changed modules: The stat-disk module allows specifying a list of extra devices in config file. The biff module does not change the access time of the mailbox. Bug fixes: The biff module does not change the access time of the mailbox file. The memory module handles more than 4 GB of memory. The stat-intr module does not crash when interrupt graphs are added. Installation using 'make install' does not overwrite existing procmeterrc file. Memory corruption problem fixed. Version 3.4 of ProcMeter3 released : Sun Jan 12 10:00:00 2003 ------------------------------------------------------------- New output format: Using the LCD driver daemon from http://lcdproc.omnipotent.net. New or changed modules: The length of the module names and output names has been increased. Virtual Memory statistics (for kernel V2.5, swap and page only). Added new DateTime outputs that show the time without the timezone. Changed the DateTime outputs to display the weekday in the current locale. Longer names allow to show DiskUsage outputs for mountpoints with long names. Fix the parsing of /proc/apm where the version number contains letters. Documentation changes: Added a new manual page for the modules (shared among all programs). Bug fixes: Doesn't crash if the --rc=... file doesn't exist. Use snprintf() in more places to avoid buffer overflow. **** IMPORTANT **** The name of the text only output version of the program is now procmeter3-log and not procmeter3-no-x like in the previous version. **** IMPORTANT **** The Linux kernel version 2.5.x has removed some information from /proc/stat and placed it into /proc/vmstat. This means that procmeterrc files need to be updated for these kernel versions if displaying swap and page statistics. **** IMPORTANT **** The longer names mean that some of the procmeterrc entries need to be changed. ACPI.Thermal_Stat -> ACPI.Thermal_State ACPI.Batt_ChrgTm -> ACPI.Batt_ChargeTime DiskUsage.DF_Used_/export -> DiskUsage.DF_Used_/export/name (In the case of DiskUsage.DF_Used_... and DiskUsage.DF_Free_... the first 16 characters of the mount point are used and not just the first 7). **** IMPORTANT **** The new DateTime outputs for the current time don't contain the timezone by default. To reproduce the behaviour of earlier versions make the following changes. DateTime.Time_HM -> DateTime.Time_HM_TZ DateTime.Time_HMS -> DateTime.Time_HMS_TZ **** IMPORTANT **** Version 3.3b of ProcMeter3 released : Sat Aug 10 16:45:00 2002 -------------------------------------------------------------- New modules: Transmeta Crusoe longrun performance level (contributed by Joey Hess). Wireless network link quality and signal, noise levels (contrib by Joey Hess). Temperatures and battery status from the ACPI interface (contrib by Joey Hess). New output format: Text only output for logging to a file. New features: NFS mounts can appear in df outputs. 12 hour clock option for data and time. Bug fixes: Fix for disk statistics kernel version detection. Version 3.3a of ProcMeter3 released : Sun May 27 08:45:00 2001 -------------------------------------------------------------- Bug fixes: Better handling of kernel version 2.4.x. Version 3.3 of ProcMeter3 released : Fri Jan 5 20:00:00 2001 ------------------------------------------------------------ Now compiles with GTK or Athena Widgets. GTK version is mostly working, not quite same configurability as Athena. Version 3.2b of ProcMeter3 released : Wed Dec 13 17:45:00 2000 -------------------------------------------------------------- Bug fixes: Handle kernel version 2.4.0 with changed format for /proc/stat. Version 3.2a of ProcMeter3 released : Sun Oct 22 16:30:00 2000 -------------------------------------------------------------- Bug fixes: Use a default font if the user specified one fails. Handle kernel version 2.4.0 with new format for /proc/stat. Version 3.2 of ProcMeter3 released : Sun Dec 12 14:15:00 1999 ------------------------------------------------------------- Bug fixes: Better handling of colour options. Improve appearance with Xaw3d. Don't change to the library directory when running. The .procmeterrc file sections and parameter names are not case sensitive. Better memory handling for unloading modules. Modules: Added more sensor directories to the lm78 sensors module. Fix the df module to remove mountpoints that can't be monitored. Configuration: Allow the label that is displayed for each output to be user configurable. Allow the update interval be specified globally in the resources section. Simplify the way that commands to run on the functions menu can be specified. Allow command line options to override the .procmeterrc options. Display: Add a delete option to the function menu. Add a third level of menus to select the output format. Add a new Widget type, a bar chart widget. Version 3.1c of ProcMeter3 released : Sun Aug 22 13:00:00 1999 -------------------------------------------------------------- Bug fixes: stat-cpu module SMP problems fixed. Outputs: Support for hardware sensors (lm78) patch from http://www.netroedge.com/~lm78/ Version 3.1b of ProcMeter3 released : Sat Jun 19 17:30:00 1999 -------------------------------------------------------------- Bug fixes: Makefile fixes. Documentation Improved the two manual pages. Improve the output of 'procmeter3 -h' to show graph/text availability. Version 3.1a of ProcMeter3 released : Sun Apr 18 10:15:00 1999 -------------------------------------------------------------- Bug fixes: Stopped core dump when window is resized. Network stats work properly with newer kernels. Makefile fixes. Version 3.1 of ProcMeter3 released : Sat Mar 6 15:00:00 1999 ------------------------------------------------------------ Bug fixes: Works with kernel version 2.2.2 with extra long interrupts line. Procmeterrc file: Improve the information and examples in the default procmeterrc file. Rename the system default .procmeterrc file to procmeterrc. Allow the startup order of the outputs to be specified. Remove the startup-text and startup-graph options. Display: Add more information to the properties display window. Allow the output displays to be moved around while running. Configuration: Include the option to specify a program to run from the output menus. Allow the graph scale and maximum number of grid lines be user specifiable. Allow the update interval of the outputs to be user specifiable. Outputs: Add in the number of bytes per second on each network interface. Add new statistics for individual CPUs on SMP machines. Add new statistics for individual disks. Add new statistics for individual interrupts. Version 3.0a of ProcMeter3 released : Sat Oct 24 13:15:00 1998 -------------------------------------------------------------- Bug fixes: Logfile module starts without error message. Fix graph units for meminfo module. Truncate hostnames to the host part or 15 characters. Move the graph labels to be left aligned to allow more room for units label. Use command line and .procmeterrc startup options with inclusive OR and not exclusive OR. Version 3.0 of ProcMeter3 released : Fri Oct 09 15:10:00 1998 ------------------------------------------------------------- procmeter3-3.5d/README000066400000000000000000000067261165060751200145060ustar00rootroot00000000000000 PROCMETER V3.5 ============== A system monitoring program for Linux. Usage: procmeter3-xaw [-h] -w hint [--rc=] [--...] ... procmeter3-gtk1 [-h] -w hint [--rc=] [--...] ... procmeter3-gtk2 [-h] -w hint [--rc=] [--...] ... procmeter3-log [-h] [--rc=] [--...] ... procmeter3-lcd [-h] [--rc=] [--...] ... -h Print out a help message. -w Set an Extended Window Manager Hint. --rc= Specify an alternative .procemterrc file. --... Command line options to set .procmeterrc options. ... Options, use the '-h' option to list the possibilities. Compilation ----------- Edit the Makefile to set the paths for installation (INSTDIR). To compile all possible versions (using GTK1 and/or GTK2 if available) then use: make all To compile a specific version or versions then specify the names of the versions that are required. The possible version names are: procmeter3-xaw - Traditional Athena Widgets version. procmeter3-gtk1 - GTK1 version. procmeter3-gtk2 - GTK2 version. procmeter3-log - Non-GUI data-logging version. procmeter3-lcd - Not an X Window system GUI version but using small LCD device with LCDproc server (http://lcdproc.omnipotent.net). For example to compile the Athena version and the GTK2 version use the command: make procmeter3-xaw procmeter3-gtk2 Installation ------------ To install all files in the default locations just use: make install To install all of the files into a directory tree that is rooted somewhere other than the usual place (e.g. in /tmp/procmeter3) use the DESTDIR option: make install DESTDIR=/tmp/procmeter3 Usage ----- The manual pages procmeter3-xaw(1), procmeter3-gtk1(1), procmeter3-gtk2(1), procmeter3-log(1) and procmeter3-lcd(1) give more details on how to use the programs. The manual page procmeter3_modules(1) describes the different data display modules that are available. The manual page procmeterrc(5) describes the format of the configuration file that is used by all versions of the program. More Information ---------------- There is a ProcMeter3 web-page that contains the latest information http://www.gedanken.demon.co.uk/procmeter3/ There is also a ProcMeter announcements mailing list; send an e-mail to procmeter-announce-request@gedanken.demon.co.uk with the phrase 'subscribe' in the body. Author & Copyright ------------------ Andrew M. Bishop Procmeter Version 3.0 Written August - September 1998 Procmeter Version 3.1 Written February - March 1999 Procmeter Version 3.2 Written August - December 1999 Procmeter Version 3.3 Written August 2000 - November 2002 Procmeter Version 3.4 Written November 2002 - September 2007 Procmeter Version 3.5 Written September 2007 - email: amb@gedanken.demon.co.uk [Please put procmeter in the subject line] This program is Copyright Andrew M. Bishop 1994-2010 and distributed under GPL. Some modules were written by Joey Hess , a long time supporter of the program: wireless, longrun and acpi. The GTK2 code for Extended Window Manager Hints as well as an updated manual page came from Wolfgang Kroener along with other bug fixes (e.g. GTK2 grid-min handling). The FanSpeed, Temperature & Voltage modules were provided by Mike T. Liang along with several bug fixes and some other new features. procmeter3-3.5d/contrib/000077500000000000000000000000001165060751200152535ustar00rootroot00000000000000procmeter3-3.5d/contrib/README000066400000000000000000000015411165060751200161340ustar00rootroot00000000000000 ProcMeter3 - Contributed files ============================== These are some miscellaneous files that are useful with procmeter but do not form part of the program itself. Those that were not written by myself have the author or contributor noted in the description. procmeter3-3.3a.spec -------------------- (By Christopher Barton cpbarton@uiuc.edu) This is a .spec file for building ProcMeter3 RPMs (written for version 3.3a). procmeter3-3.4a.spec -------------------- (By matthias brill ) This is an alternative .spec file for building ProcMeter3 RPMs (written for version 3.4a). procmeter3-3.4a2.spec -------------------- (By Tarun@rallydevelopment.com) This is a .spec file for building ProcMeter3 RPMs (an update for version 3.4a based on the version 3.3a one above). procmeter3-3.5d/contrib/procmeter3-3.3a.spec000066400000000000000000000034561165060751200206640ustar00rootroot00000000000000Summary: A modular, graphical, system monitoring program. Name: procmeter3 Version: 3.3a Release: 1 URL: http://www.gedanken.demon.co.uk/procmeter3/ Copyright: GPL Group: Applications/System Source: ftp://ftp.demon.co.uk/pub/unix/linux/X11/xutils/%{name}-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-root %description The ProcMeter program itself is a framework on which a number of modules (plugins) are loaded. More modules can be written as required to perform more monitoring and informational functions. Displays in a series of graph (using X windows) statistics about the system status (amount of CPU, memory, disk accesses, IP packets) and user level information (date, time, mailbox size). Uses the /proc filesystem and other sources of information. Compiles with either the Athena or GTK widget set. %prep %setup -q %build make CFLAGS="$RPM_OPT_FLAGS" \ INSTDIR=%{_prefix} LIB_PATH=%{_libdir}/X11/ProcMeter3 \ MOD_PATH=%{_libdir}/X11/ProcMeter3/modules \ RC_PATH=%{_libdir}/X11/ProcMeter3 %install [ $RPM_BUILD_ROOT != "/" ] && rm -rf $RPM_BUILD_ROOT make INSTDIR=$RPM_BUILD_ROOT/%{_prefix} \ LIB_PATH=$RPM_BUILD_ROOT/%{_libdir}/X11/ProcMeter3 \ MOD_PATH=$RPM_BUILD_ROOT/%{_libdir}/X11/ProcMeter3/modules \ RC_PATH=$RPM_BUILD_ROOT/%{_libdir}/X11/ProcMeter3 \ install mkdir -p $RPM_BUILD_ROOT/%{_mandir} mv $RPM_BUILD_ROOT/%{_prefix}/man/* $RPM_BUILD_ROOT/%{_mandir} %clean [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %doc ANNOUNCE ChangeLog LSM NEWS README %{_bindir}/* %{_libdir}/X11/ProcMeter3/example/* %{_libdir}/X11/ProcMeter3/include/* %{_libdir}/X11/ProcMeter3/modules/* %{_libdir}/X11/ProcMeter3/procmeterrc %{_mandir}/man1/* %{_mandir}/man5/* %changelog * Mon Mar 11 2002 Christopher Barton 3.3a-1 - Initial package procmeter3-3.5d/contrib/procmeter3-3.4a.spec000066400000000000000000000041071165060751200206570ustar00rootroot00000000000000%define name procmeter3 %define version 3.4a %define release 1 Summary: ProcMeter3 - Linux system monitoring program. Name: %{name} Version: %{version} Release: %{release} Copyright: GPL Group: Applications/System Source: %{name}-%{version}.tgz URL: http://www.gedanken.demon.co.uk/procmeter3/ Packager: thias BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot %description Displays in a series of graph (using X windows) statistics about the system status (amount of CPU, memory, disk accesses, IP packets) and user level information (date, time, mailbox size). %prep %setup # separate the READMEs %{__cp} modules/README modules/README.modules # adjust the Makefile %{__mv} Makefile Makefile.default %{__cat} Makefile.default \ | %{__sed} -e "s#^INSTDIR=.*#INSTDIR=%{_prefix}#" \ | %{__sed} -e "s#^MANDIR=.*#MANDIR=%{_mandir}#" \ | %{__sed} -e "s#^LIB_PATH=.*#LIB_PATH=%{_datadir}/procmeter3#" \ > Makefile %build %{__make} %install %{__rm} -rf $RPM_BUILD_ROOT %{__mkdir} -p $RPM_BUILD_ROOT%{_bindir} %{__mkdir} -p $RPM_BUILD_ROOT%{_mandir}/{man1,man5} %{__mkdir} -p $RPM_BUILD_ROOT%{_includedir} %{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/procmeter3/modules # binaries %{__install} -m 755 procmeter3 $RPM_BUILD_ROOT%{_bindir} %{__install} -m 755 gprocmeter3 $RPM_BUILD_ROOT%{_bindir} %{__install} -m 755 procmeter3-log $RPM_BUILD_ROOT%{_bindir} %{__install} -m 755 procmeter3-lcd $RPM_BUILD_ROOT%{_bindir} # manual pages %{__install} -m 644 man/*.1 $RPM_BUILD_ROOT%{_mandir}/man1 %{__install} -m 644 man/*.5 $RPM_BUILD_ROOT%{_mandir}/man5 # rc file %{__install} -m 644 procmeterrc.install $RPM_BUILD_ROOT%{_datadir}/procmeter3/procmeterrc # header file %{__install} -m 644 procmeter.h $RPM_BUILD_ROOT%{_includedir} # modules %{__install} -m 755 modules/*.so $RPM_BUILD_ROOT%{_datadir}/procmeter3/modules %clean %{__rm} -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %{_bindir}/* %{_mandir}/man*/* %{_datadir}/procmeter3 %{_includedir}/procmeter.h %doc ANNOUNCE LSM NEWS README ChangeLog %doc modules/README.modules modules/template.c procmeter3-3.5d/contrib/procmeter3-3.4a2.spec000066400000000000000000000035771165060751200207530ustar00rootroot00000000000000Summary: A modular, graphical, system monitoring program. Name: procmeter3 Version: 3.4a Release: 1 URL: http://www.gedanken.demon.co.uk/procmeter3/ Copyright: GPL Group: Applications/System Source: ftp://ftp.demon.co.uk/pub/unix/linux/X11/xutils/%{name}-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-root %description The ProcMeter program itself is a framework on which a number of modules (plugins) are loaded. More modules can be written as required to perform more monitoring and informational functions. Displays in a series of graph (using X windows) statistics about the system status (amount of CPU, memory, disk accesses, IP packets) and user level information (date, time, mailbox size). Uses the /proc filesystem and other sources of information. Compiles with either the Athena or GTK widget set. %prep %setup -q %build make CFLAGS="$RPM_OPT_FLAGS" \ INSTDIR=%{_prefix} LIB_PATH=%{_libdir}/X11/ProcMeter3 \ MOD_PATH=%{_libdir}/X11/ProcMeter3/modules \ RC_PATH=%{_libdir}/X11/ProcMeter3 %install [ $RPM_BUILD_ROOT != "/" ] && rm -rf $RPM_BUILD_ROOT make INSTDIR=$RPM_BUILD_ROOT/%{_prefix} \ LIB_PATH=$RPM_BUILD_ROOT/%{_libdir}/X11/ProcMeter3 \ MOD_PATH=$RPM_BUILD_ROOT/%{_libdir}/X11/ProcMeter3/modules \ RC_PATH=$RPM_BUILD_ROOT/%{_libdir}/X11/ProcMeter3 \ install mkdir -p $RPM_BUILD_ROOT/%{_mandir} mv $RPM_BUILD_ROOT/%{_prefix}/man/* $RPM_BUILD_ROOT/%{_mandir} %clean [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %doc ANNOUNCE ChangeLog LSM NEWS README %{_bindir}/* %{_libdir}/X11/ProcMeter3/example/* %{_libdir}/X11/ProcMeter3/include/* %{_libdir}/X11/ProcMeter3/modules/* %{_libdir}/X11/ProcMeter3/procmeterrc %{_libdir}/X11/ProcMeter3/procmeterrc.install %{_mandir}/man1/* %{_mandir}/man5/* %changelog * Mon Mar 11 2002 Christopher Barton 3.3a-1 - Initial package procmeter3-3.5d/gtk1/000077500000000000000000000000001165060751200144615ustar00rootroot00000000000000procmeter3-3.5d/gtk1/Makefile000066400000000000000000000042211165060751200161200ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/gtk1/Makefile,v 1.4 2007-09-26 18:31:46 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.5. # # Makefile for gtk1 parts. # # Written by Andrew M. Bishop # # This file Copyright 1994-2007 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options CFLAGS=-g -O2 -Wall LDFLAGS= X_CFLAGS=`gtk-config --cflags` X_LDFLAGS=`gtk-config --libs` # Check for GTK1 development libraries and headers HAVE_GTK1:=$(shell gtk-config --version) ifdef HAVE_GTK1 ALL=all-gtk1 else ALL=all-no-gtk1 endif # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) PSRC=$(wildcard ../*.c) POBJ=$(foreach f,$(PSRC),$(addsuffix .o,$(basename $f))) WSRC=$(wildcard widgets/*.c) WOBJ=$(foreach f,$(WSRC),$(addsuffix .o,$(basename $f))) ######## all : $(ALL) all-no-gtk1 : @echo "ProcMeter:" @echo "ProcMeter: GTK1 is not installed (gtk-config could not be found)." @echo "ProcMeter: Cannot compile procmeter3-gtk1 program." @echo "ProcMeter:" all-gtk1 : $(OBJ) procmeter.widget \ ../procmeter3-gtk1 ######## ../procmeter3-gtk1 : $(OBJ) procmeter.widget procmeter.main $(LD) $(OBJ) $(WOBJ) $(POBJ) -o $@ -ldl $(LDFLAGS) $(X_LDFLAGS) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(X_CFLAGS) -I.. bitmap.o : bitmap.c ../procmeterp.h ../procmeter.h window.h resources.o : resources.c ../procmeterp.h ../procmeter.h window.h menus.o : menus.c ../procmeterp.h ../procmeter.h window.h window.o : window.c ../procmeterp.h ../procmeter.h window.h run.o : run.c ../procmeterp.h ../procmeter.h window.h ######## .PHONY : procmeter.widget procmeter.widget : $(MAKE) CFLAGS="$(CFLAGS)" X_CFLAGS="$(X_CFLAGS)" -C widgets ######## .PHONY : procmeter.main $(POBJ) : procmeter.main procmeter.main : $(MAKE) CFLAGS="$(CFLAGS)" -C .. obj ######## .PHONY : clean clean : -rm -f *.o *~ core $(MAKE) -C widgets clean ######## .PHONY : install install : procmeter3-3.5d/gtk1/bitmap.c000066400000000000000000000036551165060751200161120ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/bitmap.c,v 1.2 2005-10-15 18:16:46 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.4e. X Window Bitmaps. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include "window.h" #define circle_width 8 #define circle_height 8 static char circle_bits[] = { 0x00, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x00}; #define graph_width 16 #define graph_height 8 static char graph_bits[] = { 0x00, 0x00, 0x42, 0x00, 0xa2, 0x41, 0x12, 0x22, 0x0e, 0x1c, 0x02, 0x00, 0xfe, 0x7f, 0x00, 0x00}; #define text_width 16 #define text_height 8 static char text_bits[] = { 0x00, 0x00, 0xcc, 0x31, 0x52, 0x4a, 0xd2, 0x09, 0x5e, 0x0a, 0x52, 0x4a, 0xd2, 0x31, 0x00, 0x00}; #define bar_width 16 #define bar_height 8 static char bar_bits[] = { 0x01, 0x00, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0x01, 0x00, 0x49, 0x92, 0xff, 0xff}; GdkPixmap *CircleBitmap; GdkPixmap *GraphBitmap; GdkPixmap *TextBitmap; GdkPixmap *BarBitmap; /*++++++++++++++++++++++++++++++++++++++ Initialise the Bitmaps. GtkWidget *w A window to start with. ++++++++++++++++++++++++++++++++++++++*/ void CreateBitmaps(GtkWidget *w) { CircleBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,circle_bits,circle_width,circle_height); GraphBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,graph_bits,graph_width,graph_height); TextBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,text_bits,text_width,text_height); BarBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,bar_bits,bar_width,bar_height); } procmeter3-3.5d/gtk1/menus.c000066400000000000000000000554131165060751200157640ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/menus.c,v 1.4 2009-12-07 20:01:23 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5c. X Window menus (GTK version). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2009 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include "window.h" #include "procmeterp.h" /*+ The orientation of the windows. +*/ extern int vertical; /*+ The pane that contains all of the outputs. +*/ extern GtkWidget *pane; /* Local functions */ static void MenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void ModuleMenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void OutputMenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void FunctionsMenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void SelectOutputMenuCallback(gpointer clientData); static void SelectFunctionsMenuCallback(gpointer clientData); static void PropertiesDialogDoneCallback(GtkWidget *w,gpointer data); static gint PropertiesDialogCloseCallback(GtkWidget *w,GdkEvent *event,gpointer data); /* Menu widgets */ static GtkWidget *module_menu; static GtkWidget *functions_menu,*properties_dialog; static GtkWidget *func_run; static GtkWidget *prop_modname,*prop_moddesc, *prop_outname,*prop_outdesc, *prop_label,*prop_type,*prop_interval,*prop_scale; static gboolean properties_popped_up=FALSE; static gint doing_move=0; /*+ The output that was used for the Functions menu. +*/ static Output function_output; /*++++++++++++++++++++++++++++++++++++++ Initialise the menus. GtkWidget *parent The parent widget that the menu belongs to. ++++++++++++++++++++++++++++++++++++++*/ void CreateMenus(GtkWidget *parent) { GtkWidget *menulabel; GtkWidget *menuline; GtkWidget *func_prop,*func_above,*func_below,*func_delete; GtkWidget *prop_form,*prop_form1,*prop_form2, *prop_modlabel,*prop_outlabel, *prop_lbllabel,*prop_typlabel,*prop_intlabel,*prop_scllabel, *prop_done; // char *string; /* Sort out the resources in advance. */ // if((string=GetProcMeterRC("resources","menu-foreground"))) // {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} // // if((string=GetProcMeterRC("resources","menu-background"))) // {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} // // if((string=GetProcMeterRC("resources","menu-font"))) // {XtSetArg(args[nargs],XtNfont,StringToFont(string));nargs++;} /* The module menu */ module_menu=gtk_menu_new(); menulabel=gtk_menu_item_new_with_label("Modules"); gtk_widget_set_sensitive(GTK_WIDGET(menulabel),FALSE); gtk_menu_append(GTK_MENU(module_menu),menulabel); gtk_widget_show(GTK_WIDGET(menulabel)); menuline=gtk_menu_item_new(); gtk_menu_append(GTK_MENU(module_menu),menuline); gtk_widget_show(GTK_WIDGET(menuline)); /* The functions menu */ functions_menu=gtk_menu_new(); menulabel=gtk_menu_item_new_with_label("Functions"); gtk_widget_set_sensitive(GTK_WIDGET(menulabel),FALSE); gtk_menu_append(GTK_MENU(functions_menu),menulabel); gtk_widget_show(GTK_WIDGET(menulabel)); menuline=gtk_menu_item_new(); gtk_menu_append(GTK_MENU(functions_menu),menuline); gtk_widget_show(GTK_WIDGET(menuline)); /* The functions menu items */ func_prop=gtk_menu_item_new_with_label("Properties"); gtk_menu_append(GTK_MENU(functions_menu),func_prop); gtk_widget_show(GTK_WIDGET(func_prop)); gtk_signal_connect_object(GTK_OBJECT(func_prop),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)0); func_above=gtk_menu_item_new_with_label(vertical?"Move To Above":"Move To Left Of"); gtk_menu_append(GTK_MENU(functions_menu),func_above); gtk_widget_show(GTK_WIDGET(func_above)); gtk_signal_connect_object(GTK_OBJECT(func_above),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)1); func_below=gtk_menu_item_new_with_label(vertical?"Move To Below":"Move To Right Of"); gtk_menu_append(GTK_MENU(functions_menu),func_below); gtk_widget_show(GTK_WIDGET(func_below)); gtk_signal_connect_object(GTK_OBJECT(func_below),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)2); func_delete=gtk_menu_item_new_with_label("Delete"); gtk_menu_append(GTK_MENU(functions_menu),func_delete); gtk_widget_show(GTK_WIDGET(func_delete)); gtk_signal_connect_object(GTK_OBJECT(func_delete),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)3); func_run=gtk_menu_item_new_with_label("Run"); gtk_menu_append(GTK_MENU(functions_menu),func_run); gtk_widget_show(GTK_WIDGET(func_run)); gtk_signal_connect_object(GTK_OBJECT(func_run),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)4); /* The properties_dialog */ properties_dialog=gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(properties_dialog),"ProcMeter Properties"); gtk_widget_set_usize(GTK_WIDGET(properties_dialog),300,400); /* The properties dialog elements. */ prop_form=gtk_hbox_new(FALSE,0); prop_modlabel=gtk_label_new("Module: "); gtk_label_set_justify(GTK_LABEL(prop_modlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_modlabel,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_modlabel)); prop_modname=gtk_label_new("NNNNNNNNNNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_modname),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_modname,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_modname)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_form,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_form)); prop_moddesc=gtk_text_new(NULL,NULL); gtk_text_set_editable(GTK_TEXT(prop_moddesc),FALSE); gtk_text_set_word_wrap(GTK_TEXT(prop_moddesc),TRUE); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_moddesc,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(prop_moddesc),250,100); gtk_widget_show(GTK_WIDGET(prop_moddesc)); prop_form=gtk_hbox_new(FALSE,0); prop_outlabel=gtk_label_new("Output: "); gtk_label_set_justify(GTK_LABEL(prop_outlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_outlabel,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_outlabel)); prop_outname=gtk_label_new("NNNNNNNNNNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_outname),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_outname,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_outname)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_form,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_form)); prop_outdesc=gtk_text_new(NULL,NULL); gtk_text_set_editable(GTK_TEXT(prop_outdesc),FALSE); gtk_text_set_word_wrap(GTK_TEXT(prop_outdesc),TRUE); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_outdesc,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(prop_outdesc),250,100); gtk_widget_show(GTK_WIDGET(prop_outdesc)); prop_form=gtk_hbox_new(FALSE,0); prop_form1=gtk_vbox_new(TRUE,0); prop_lbllabel=gtk_label_new("Label:"); gtk_label_set_justify(GTK_LABEL(prop_lbllabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_lbllabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_lbllabel)); prop_typlabel=gtk_label_new("Type:"); gtk_label_set_justify(GTK_LABEL(prop_typlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_typlabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_typlabel)); prop_intlabel=gtk_label_new("Interval:"); gtk_label_set_justify(GTK_LABEL(prop_intlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_intlabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_intlabel)); prop_scllabel=gtk_label_new("Grid Spacing:"); gtk_label_set_justify(GTK_LABEL(prop_scllabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_scllabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_scllabel)); gtk_box_pack_start(GTK_BOX(prop_form),prop_form1,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_form1)); prop_form2=gtk_vbox_new(TRUE,0); prop_label=gtk_label_new("NNNNNNNNNNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_label),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_label,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_label)); prop_type=gtk_label_new("NNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_type),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_type,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_type)); prop_interval=gtk_label_new("NNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_interval),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_interval,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_interval)); prop_scale=gtk_label_new("NNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_scale),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_scale,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_scale)); gtk_box_pack_start(GTK_BOX(prop_form),prop_form2,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_form2)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_form,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_form)); prop_done=gtk_button_new_with_label("Done"); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->action_area),prop_done,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_done)); gtk_signal_connect_object(GTK_OBJECT(prop_done),"clicked", GTK_SIGNAL_FUNC(PropertiesDialogDoneCallback),NULL); /* Fixup the properties dialog box */ gtk_signal_connect_object(GTK_OBJECT(properties_dialog),"delete_event", GTK_SIGNAL_FUNC(PropertiesDialogCloseCallback),NULL); } /*++++++++++++++++++++++++++++++++++++++ Add a specified module to the menus. Module module The module to add. ++++++++++++++++++++++++++++++++++++++*/ void AddModuleToMenu(Module module) { int i; GtkWidget *menulabel,*menuline,*submenu=NULL,*menuitem=NULL; ProcMeterOutput *prevoutput=NULL; char *string; /* Return if pane widget is not initialised (e.g. gprocmeter3 -h). */ if(!pane) return; /* Sort out the resources in advance. */ // if(((string=GetProcMeterRC(module->module->name,"menu-foreground")) || // (string=GetProcMeterRC("resources","menu-foreground")))) // {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} // // if(((string=GetProcMeterRC(module->module->name,"menu-background")) || // (string=GetProcMeterRC("resources","menu-background")))) // {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} // // if(((string=GetProcMeterRC(module->module->name,"menu-font")) || // (string=GetProcMeterRC("resources","menu-font")))) // {XtSetArg(args[nargs],XtNfont,StringToFont(string));nargs++;} /* Create a new menu. */ module->submenu_widget=gtk_menu_new(); menulabel=gtk_menu_item_new_with_label(module->module->name); gtk_widget_set_sensitive(GTK_WIDGET(menulabel),FALSE); gtk_menu_append(GTK_MENU(module->submenu_widget),menulabel); gtk_widget_show(GTK_WIDGET(menulabel)); menuline=gtk_menu_item_new(); gtk_menu_append(GTK_MENU(module->submenu_widget),menuline); gtk_widget_show(GTK_WIDGET(menuline)); /* Add an entry to the module menu */ module->menu_item_widget=gtk_menu_item_new_with_label(module->module->name); gtk_menu_append(GTK_MENU(module_menu),module->menu_item_widget); gtk_widget_show(GTK_WIDGET(module->menu_item_widget)); gtk_menu_item_set_submenu(GTK_MENU_ITEM(module->menu_item_widget),module->submenu_widget); /* Add entries to it for each output. */ for(i=0;module->outputs[i];i++) { GtkWidget *sme; // GdkPixmap *bitmap=CircleBitmap; if(module->outputs[i]->output!=prevoutput) { menuitem=gtk_menu_item_new_with_label(module->outputs[i]->output->name); gtk_menu_append(GTK_MENU(module->submenu_widget),menuitem); gtk_widget_show(GTK_WIDGET(menuitem)); // if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-foreground")) || // (string=GetProcMeterRC(module->module->name,"menu-foreground")) || // (string=GetProcMeterRC("resources","menu-foreground")))) // XtVaSetValues(menuitem,XtNforeground,StringToPixel(string),NULL); // // if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-font")) || // (string=GetProcMeterRC(module->module->name,"menu-font")) || // (string=GetProcMeterRC("resources","menu-font")))) // XtVaSetValues(menuitem,XtNfont,StringToFont(string),NULL); submenu=gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem),submenu); prevoutput=module->outputs[i]->output; } // if(module->outputs[i]->type==PROCMETER_GRAPH) // bitmap=GraphBitmap; // else if(module->outputs[i]->type==PROCMETER_TEXT) // bitmap=TextBitmap; // else if(module->outputs[i]->type==PROCMETER_BAR) // bitmap=BarBitmap; string=""; if(module->outputs[i]->type==PROCMETER_GRAPH) string="Graph"; else if(module->outputs[i]->type==PROCMETER_TEXT) string="Text"; else if(module->outputs[i]->type==PROCMETER_BAR) string="Bar"; sme=gtk_check_menu_item_new_with_label(string); gtk_menu_append(GTK_MENU(submenu),sme); gtk_widget_show(GTK_WIDGET(sme)); gtk_signal_connect_object(GTK_OBJECT(sme),"activate", GTK_SIGNAL_FUNC(SelectOutputMenuCallback),(gpointer)module->outputs[i]); // if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-foreground")) || // (string=GetProcMeterRC(module->module->name,"menu-foreground")) || // (string=GetProcMeterRC("resources","menu-foreground")))) // XtVaSetValues(sme,XtNforeground,StringToPixel(string),NULL); module->outputs[i]->menu_item_widget=sme; module->outputs[i]->output_widget=NULL; } } /*++++++++++++++++++++++++++++++++++++++ Add the menus to the right mouse button of the output. GtkWidget *widget The widget itself. Module module The module that this widget belongs to. ++++++++++++++++++++++++++++++++++++++*/ void AddMenuToOutput(GtkWidget *widget,Module module) { /* Return if pane widget is not initialised (e.g. gprocmeter3 -h). */ if(!pane) return; gtk_signal_connect(GTK_OBJECT(widget),"button_press_event", GTK_SIGNAL_FUNC(MenuStart),module?module->module->name:NULL); } /*++++++++++++++++++++++++++++++++++++++ Remove a specified module from the menus. Module module The module to remove. ++++++++++++++++++++++++++++++++++++++*/ void RemoveModuleFromMenu(Module module) { /* Return if pane widget is not initialised (e.g. gprocmeter3 -h). */ if(!pane) return; gtk_widget_destroy(GTK_WIDGET(module->submenu_widget)); gtk_object_destroy(GTK_OBJECT(module->menu_item_widget)); } /*++++++++++++++++++++++++++++++++++++++ Destroy all of the menus. ++++++++++++++++++++++++++++++++++++++*/ void DestroyMenus(void) { gtk_widget_destroy(GTK_WIDGET(module_menu)); gtk_widget_destroy(GTK_WIDGET(functions_menu)); gtk_widget_destroy(GTK_WIDGET(properties_dialog)); } /*++++++++++++++++++++++++++++++++++++++ The callback that is called by the output being selected on the output menu. gpointer clientData The client data from the callback. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void SelectOutputMenuCallback(gpointer clientData) { Output output=(Output)clientData; AddRemoveOutput(output); } /*++++++++++++++++++++++++++++++++++++++ The callback that is called by the output being selected on the output menu. gpointer clientData The client data from the callback. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void SelectFunctionsMenuCallback(gpointer clientData) { if(clientData==(gpointer)0) /* Properties */ { gtk_widget_show(GTK_WIDGET(properties_dialog)); properties_popped_up=TRUE; } else if(clientData==(gpointer)1 || clientData==(gpointer)2) /* Above / Below */ { doing_move=(glong)clientData; gdk_pointer_grab(GTK_WIDGET(pane)->window,TRUE,GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK,GDK_NONE,gdk_cursor_new(GDK_HAND1),GDK_CURRENT_TIME); } else if(clientData==(gpointer)3) /* Delete */ { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(function_output->menu_item_widget),FALSE); } else if(clientData==(gpointer)4) /* Run */ { if(function_output->menu_run.flag) RunProgram(&function_output->menu_run); } } /*++++++++++++++++++++++++++++++++++++++ The callback for the done button on the properties dialog box. GtkWidget *w The widget that the callback came from. gpointer data The data from the callback. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void PropertiesDialogDoneCallback(GtkWidget *w,gpointer data) { gtk_widget_hide(GTK_WIDGET(properties_dialog)); properties_popped_up=FALSE; } /*++++++++++++++++++++++++++++++++++++++ The callback for the window manager close on the dialog. GtkWidget *w The widget that caused the event. GdkEvent *event The event information. gpointer data Not used. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static gint PropertiesDialogCloseCallback(GtkWidget *w,GdkEvent *event,gpointer data) { gtk_widget_hide(GTK_WIDGET(properties_dialog)); properties_popped_up=FALSE; return(TRUE); } /*++++++++++++++++++++++++++++++++++++++ Start one of the popup menus. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void MenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { if(event->type!=GDK_BUTTON_PRESS) return; if(event->button.button==1 && data) FunctionsMenuStart(w,event,data); else if(event->button.button==2 && data) OutputMenuStart(w,event,data); else if(event->button.button==3) ModuleMenuStart(w,event,data); } /*++++++++++++++++++++++++++++++++++++++ Start the Module menu. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void ModuleMenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { gtk_menu_popup(GTK_MENU(module_menu),NULL,NULL,NULL,NULL,event->button.button,event->button.time); } /*++++++++++++++++++++++++++++++++++++++ Start one of the Output menus. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void OutputMenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { static Module *modulep=NULL; for(modulep=Modules;*modulep;modulep++) if(!strcmp((*modulep)->module->name,data)) gtk_menu_popup(GTK_MENU((*modulep)->submenu_widget),NULL,NULL,NULL,NULL,event->button.button,event->button.time); } /*++++++++++++++++++++++++++++++++++++++ Start the properties menu. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void FunctionsMenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { static Output *outputp=NULL; static Module *modulep=NULL; char string[24]; for(modulep=Modules;*modulep;modulep++) if(!strcmp((*modulep)->module->name,data)) { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(w==(*outputp)->output_widget) break; break; } if(doing_move) { gdk_pointer_ungrab(GDK_CURRENT_TIME); MoveOutput(function_output,*outputp,doing_move); doing_move=0; return; } if(!*modulep || !*outputp) return; function_output=*outputp; if((*outputp)->menu_run.flag) { char *r=(*outputp)->menu_run.command; strncpy(string,"Run '",16); strncpy(string+5,r,8); if(strlen(r)>8) strcat(string," ...'"); else strcat(string,"'"); // XtVaSetValues(func_run,XtNlabel,string,NULL); gtk_widget_set_sensitive(GTK_WIDGET(func_run),TRUE); } else { // XtVaSetValues(func_run,XtNlabel,"Run",NULL); gtk_widget_set_sensitive(GTK_WIDGET(func_run),FALSE); } /* Set up the properties window. */ gtk_label_set_text(GTK_LABEL(prop_modname),(*modulep)->module->name); gtk_text_set_point(GTK_TEXT(prop_moddesc),0); gtk_text_forward_delete(GTK_TEXT(prop_moddesc),gtk_text_get_length(GTK_TEXT(prop_moddesc))); gtk_text_insert(GTK_TEXT(prop_moddesc),NULL,NULL,NULL, (*modulep)->module->description,strlen((*modulep)->module->description)); gtk_label_set_text(GTK_LABEL(prop_outname),(*outputp)->output->name); gtk_text_set_point(GTK_TEXT(prop_outdesc),0); gtk_text_forward_delete(GTK_TEXT(prop_outdesc),gtk_text_get_length(GTK_TEXT(prop_outdesc))); gtk_text_insert(GTK_TEXT(prop_outdesc),NULL,NULL,NULL, (*outputp)->output->description,strlen((*outputp)->output->description)); gtk_label_set_text(GTK_LABEL(prop_label),(*outputp)->label); if((*outputp)->type==PROCMETER_GRAPH) gtk_label_set_text(GTK_LABEL(prop_type),"Graph"); else if((*outputp)->type==PROCMETER_TEXT) gtk_label_set_text(GTK_LABEL(prop_type),"Text"); else if((*outputp)->type==PROCMETER_BAR) gtk_label_set_text(GTK_LABEL(prop_type),"Bar"); if((*outputp)->output->interval) sprintf(string,"%d s",(*outputp)->output->interval); else strcpy(string,"Never"); gtk_label_set_text(GTK_LABEL(prop_interval),string); if((*outputp)->type&(PROCMETER_GRAPH|PROCMETER_BAR)) { char str[PROCMETER_UNITS_LEN+1]; snprintf(str,PROCMETER_UNITS_LEN+1,(*outputp)->output->graph_units,(*outputp)->output->graph_scale); if(*str=='(') strcpy(string,str+1); else strcpy(string,str); if(string[strlen(string)-1]==')') string[strlen(string)-1]=0; gtk_label_set_text(GTK_LABEL(prop_scale),string); } else { gtk_label_set_text(GTK_LABEL(prop_scale),"n/a"); } if(!properties_popped_up) gtk_menu_popup(GTK_MENU(functions_menu),NULL,NULL,NULL,NULL,event->button.button,event->button.time); } procmeter3-3.5d/gtk1/resources.c000066400000000000000000000047301165060751200166430ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/resources.c,v 1.1 2000-12-16 16:35:43 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3. X Window resource conversions. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include "window.h" #include "procmeterp.h" /*++++++++++++++++++++++++++++++++++++++ Convert a string to a font structure. GdkFont *StringToFont Returns a pointer to a font structure. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ GdkFont *StringToFont(char *string) { return(gdk_font_load(string)); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a pixel. GdkColor StringToPixel Returns a GdkColor value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ GdkColor StringToPixel(char *string) { static GdkColor color; gdk_color_parse(string,&color); gdk_colormap_alloc_color(gdk_colormap_get_system(),&color,FALSE,TRUE); return(color); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a Boolean. gboolean StringToBoolean Returns a Boolean value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ gboolean StringToBoolean(char *string) { gboolean b; if(!strcasecmp(string,"true") || !strcasecmp(string,"yes") || !strcasecmp(string,"1")) b=TRUE; else b=FALSE; return(b); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to an integer int StringToInt Returns an integer value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ int StringToInt(char *string) { int i; if(sscanf(string,"%d",&i)!=1) i=0; return(i); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a label position. int StringToLabelPosition Returns an integer value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ int StringToLabelPosition(char *string) { int i; if(!strcasecmp(string,"top")) i=1; else if(!strcasecmp(string,"bottom")) i=-1; else i=0; return(i); } procmeter3-3.5d/gtk1/run.c000066400000000000000000000071551165060751200154410ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/run.c,v 1.3 2010-02-28 10:21:50 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. Run external programs. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1999-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include "procmeterp.h" /*+ The toplevel widget. +*/ extern GtkWidget *toplevel; /*++++++++++++++++++++++++++++++++++++++ Parse the command from the config file to be run. char *string The string to be parsed. RunOption *run Contains the parsed result. ++++++++++++++++++++++++++++++++++++++*/ void ParseRunCommand(char *string,RunOption *run) { int offset; char *l,*r; run->flag=RUN_NONE; run->command=NULL; if(!string) return; if(!strncmp("XBeep",string,5)) {offset=5; run->flag=RUN_XBELL;} else if(!strncmp("Shell",string,5)) {offset=5; run->flag=RUN_SHELL;} else if(!strncmp("XTermWait",string,9)) {offset=9; run->flag=RUN_XTERM_WAIT;} else if(!strncmp("XTerm",string,5)) {offset=5; run->flag=RUN_XTERM;} else {offset=0; run->flag=RUN_SHELL;} l=string+offset; r=string+strlen(string)-1; while(isspace(*l)) l++; if(offset && *l!='(') { fprintf(stderr,"ProcMeter: Cannot parse run command '%s'\n",string); run->flag=RUN_NONE; return; } else if(offset) l++; while(isspace(*l)) l++; while(isspace(*r)) r--; if(offset && *r!=')') { fprintf(stderr,"ProcMeter: Cannot parse run command '%s'\n",string); run->flag=RUN_NONE; return; } else if(offset) r--; while(isspace(*r)) r--; if(rcommand=(char*)malloc(r-l+2); strncpy(run->command,l,r-l+1); *(run->command+(r-l)+1)=0; } /*++++++++++++++++++++++++++++++++++++++ Run a program. RunOption *run The information about the program to run. ++++++++++++++++++++++++++++++++++++++*/ void RunProgram(RunOption *run) { if(run->flag==RUN_NONE || !run->command) return; if(run->flag==RUN_XBELL) XBell(GDK_WINDOW_XDISPLAY(toplevel->window),0); else { pid_t pid=fork(); if(pid==-1) fprintf(stderr,"ProcMeter: Cannot fork child process %s\n",strerror(errno)); else if(pid==0) { char *string,*displayname,*displayenv; displayname=XDisplayString(GDK_WINDOW_XDISPLAY(toplevel->window)); displayenv=(char*)malloc(strlen(displayname)+10); sprintf(displayenv,"DISPLAY=%s",displayname); putenv(displayenv); /* close the X connection */ close(ConnectionNumber(GDK_WINDOW_XDISPLAY(toplevel->window))); switch(run->flag) { default: case RUN_SHELL: execl("/bin/sh","/bin/sh","-c",run->command,NULL); break; case RUN_XTERM: execlp("xterm","xterm","-title","ProcMeter3","-e","/bin/sh","-c",run->command,NULL); break; case RUN_XTERM_WAIT: string=(char*)malloc(strlen(run->command)+64); sprintf(string,"( %s ) ; echo -n 'Press Return to exit' ; read x",run->command); execlp("xterm","xterm","-title","ProcMeter3","-e","/bin/sh","-c",string,NULL); break; } /* Never reached */ exit(1); } } } procmeter3-3.5d/gtk1/widgets/000077500000000000000000000000001165060751200161275ustar00rootroot00000000000000procmeter3-3.5d/gtk1/widgets/Makefile000066400000000000000000000022001165060751200175610ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/gtk1/widgets/Makefile,v 1.2 2007-09-19 19:02:45 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.5. # # Makefile for gtk1 widgets. # # Written by Andrew M. Bishop # # This file Copyright 1998-2007 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options (overridden by main Makefile) CFLAGS=-g -O2 -Wall X_CFLAGS=`gtk-config --cflags` # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) ######## all : $(OBJ) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(X_CFLAGS) -I../.. PMGeneric.o : PMGeneric.c PMGeneric.h PMGraph.o : PMGraph.c PMGraph.h PMGeneric.h ../../procmeter.h PMText.o : PMText.c PMText.h PMGeneric.h PMBar.o : PMBar.c PMBar.h PMGeneric.h ../../procmeter.h SubMenus.o : SubMenus.c SubMenus.h ######## .PHONY : clean clean : -rm -f *.o *~ core ######## .PHONY : install install : procmeter3-3.5d/gtk1/widgets/PMBar.c000066400000000000000000000346611165060751200172460ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMBar.c,v 1.4 2008-04-27 15:21:30 amb Exp $ ProcMeter Bar Widget Source file (for ProcMeter3 3.5b). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" #include "PMBar.h" #include "procmeter.h" static void procmeterbar_class_init(ProcMeterBarClass *class); static void procmeterbar_init(ProcMeterBar *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void BarResize(ProcMeterBar *pmw); static void BarUpdate(ProcMeterBar *pmw,gboolean all); static char *empty_string=""; static ProcMeterGenericClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint gtk_procmeterbar_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmeterbar_get_type(void) { static guint pmw_type = 0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterBar", sizeof(ProcMeterBar), sizeof(ProcMeterBarClass), (GtkClassInitFunc) procmeterbar_class_init, (GtkObjectInitFunc) procmeterbar_init, (GtkArgSetFunc) NULL, (GtkArgGetFunc) NULL}; pmw_type=gtk_type_unique(gtk_procmetergeneric_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterBarClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmeterbar_class_init(ProcMeterBarClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=BarResize; class->update=BarUpdate; parent_class=gtk_type_class(gtk_procmetergeneric_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterBar *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmeterbar_init(ProcMeterBar *pmw) { int i; g_return_if_fail(pmw!=NULL); /* The grid parts. */ pmw->grid_units=empty_string; pmw->grid_gc=NULL; pmw->grid_drawn=1; pmw->grid_min=1; pmw->grid_max=0; pmw->grid_num=pmw->grid_min; /* The data parts. */ for(i=0;idata)/sizeof(pmw->data[0]);i++) pmw->data[i]=0; pmw->data_index=0; pmw->data_sum=0; /* The rest of the sizing. */ BarResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmeterbar_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmeterbar_new(void) { ProcMeterBar *pmw; pmw=gtk_type_new(gtk_procmeterbar_get_type()); return(GTK_WIDGET(pmw)); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterBar *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(object)); pmw=GTK_PROCMETERBAR(object); if(pmw->grid_gc) gdk_gc_destroy(pmw->grid_gc); if(pmw->grid_units!=empty_string) free(pmw->grid_units); if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterBar *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERBAR(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->generic.body_bg_set) gdk_window_set_background(widget->window,&pmw->generic.body_bg_color); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterBar *pmw; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERBAR(widget); requisition->height=20+pmw->generic.label_height; requisition->width=50; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterBar *pmw=GTK_PROCMETERBAR(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); BarResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Bar Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterBar *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERBAR(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERBAR(widget); BarUpdate(pmw,TRUE); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterBar *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void BarResize(ProcMeterBar *pmw) { GdkFont *label_font; g_return_if_fail(pmw!=NULL); (parent_class->resize)(&pmw->generic); pmw->generic.label_x=2; /* The grid parts. */ label_font=pmw->generic.label_font?pmw->generic.label_font:pmw->generic.widget.style->font; pmw->grid_units_x=pmw->generic.widget.allocation.width-gdk_string_width(label_font,pmw->grid_units); pmw->grid_maxvis=pmw->generic.widget.allocation.width/3; if(pmw->generic.label_pos==ProcMeterLabelTop) pmw->generic.body_start=pmw->generic.label_height; else pmw->generic.body_start=0; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterBar *pmw The Widget to update. gboolean all Indicates if it all is to be updated including the generic parts. ++++++++++++++++++++++++++++++++++++++*/ static void BarUpdate(ProcMeterBar *pmw,gboolean all) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->generic.widget)) { GdkGC *grid_gc=pmw->grid_gc?pmw->grid_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkGC *body_gc=pmw->generic.body_gc?pmw->generic.body_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkFont *label_font=pmw->generic.label_font?pmw->generic.label_font:pmw->generic.widget.style->font; int i; int scale=PROCMETER_GRAPH_SCALE*pmw->grid_num; gshort pos; gshort top_average_bottom,bottom_average_top,average_size; if(all) { (parent_class->update)(&pmw->generic); if(pmw->generic.label_pos!=ProcMeterLabelNone) gdk_draw_string(pmw->generic.widget.window,label_font,pmw->generic.label_gc, pmw->grid_units_x,pmw->generic.label_y, pmw->grid_units); } else gdk_window_clear_area(pmw->generic.widget.window, 0,pmw->generic.body_start, pmw->generic.widget.allocation.width,pmw->generic.body_height); pos=pmw->data_sum*pmw->generic.widget.allocation.width/(scale*2); top_average_bottom=pmw->generic.body_start+2*(pmw->generic.body_height>>3); bottom_average_top=pmw->generic.body_start+pmw->generic.body_height-2*(pmw->generic.body_height>>3); average_size=pmw->generic.body_height>>3; gdk_draw_rectangle(pmw->generic.widget.window,body_gc,1, pos-average_size,top_average_bottom-average_size, average_size ,average_size); gdk_draw_rectangle(pmw->generic.widget.window,body_gc,1, pos-average_size,bottom_average_top, average_size ,average_size); pos=pmw->data[pmw->data_index]*pmw->generic.widget.allocation.width/scale; gdk_draw_rectangle(pmw->generic.widget.window,body_gc,1, 0 ,top_average_bottom+1, pos,bottom_average_top-top_average_bottom-2); if(pmw->grid_drawn==1) for(i=1;igrid_num;i++) { pos=i*pmw->generic.widget.allocation.width/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, pos,pmw->generic.body_start, pos,pmw->generic.body_height+pmw->generic.body_start); } else if(pmw->grid_drawn==-1) { pos=pmw->grid_maxvis*pmw->generic.widget.allocation.width/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, pos,pmw->generic.body_start, pos,pmw->generic.body_height+pmw->generic.body_start); } } } /*++++++++++++++++++++++++++++++++++++++ Set the grid colour of the Widget. ProcMeterBar *pmw The widget to set. GdkColor grid_color The grid. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridColour(ProcMeterBar *pmw,GdkColor grid_color) { pmw->grid_color=grid_color; if(pmw->grid_gc) gdk_gc_set_foreground(pmw->grid_gc,&pmw->grid_color); else { GdkGCValues values; values.foreground=pmw->grid_color; pmw->grid_gc=gdk_gc_new_with_values(pmw->generic.widget.parent->window,&values,GDK_GC_FOREGROUND); } BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the minimum number of grid lines in the Widget. ProcMeterBar *pmw The Widget to set. gint grid_min The minimum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridMin(ProcMeterBar *pmw,gint grid_min) { if(grid_min<0) { pmw->grid_min=-grid_min; pmw->grid_drawn=0; } else if(grid_min>0) { pmw->grid_min=grid_min; pmw->grid_drawn=1; } else /* if(grid_min==0) */ { pmw->grid_min=1; pmw->grid_drawn=1; } if(grid_min>pmw->grid_max && pmw->grid_max) pmw->grid_min=pmw->grid_max; if(pmw->grid_min>=pmw->grid_num) pmw->grid_num=pmw->grid_min; BarResize(pmw); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the maximum number of grid lines in the Widget. ProcMeterBar *pmw The Widget to set. gint grid_max The maximum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridMax(ProcMeterBar *pmw,gint grid_max) { if(grid_max<0) pmw->grid_max=0; else pmw->grid_max=grid_max; if(grid_max && grid_maxgrid_min) pmw->grid_max=pmw->grid_min; BarResize(pmw); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the grid units for the widget ProcMeterBar *pmw The widget to set. gchar *units The grid units. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridUnits(ProcMeterBar *pmw,gchar *units) { if(pmw->grid_units!=empty_string) free(pmw->grid_units); pmw->grid_units=(char*)malloc(strlen(units)+1); strcpy(pmw->grid_units,units); BarResize(pmw); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Add a data point to the ProcMeter Bar Widget. ProcMeterBar *pmw The ProcMeter Bar Widget. gushort datum The data point to add. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarAddDatum(ProcMeterBar *pmw,gushort datum) { int new_grid_num; gushort old_datum; pmw->data_index++; if(pmw->data_index==8) pmw->data_index=0; old_datum=pmw->data[pmw->data_index]; pmw->data[pmw->data_index]=datum; pmw->data_sum=(pmw->data_sum>>1)+datum-(old_datum>>8); if((pmw->data_sum/2)>datum) new_grid_num=((pmw->data_sum/2)+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; else new_grid_num=(datum+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numgrid_min) new_grid_num=pmw->grid_min; if(pmw->grid_max && new_grid_num>pmw->grid_max) new_grid_num=pmw->grid_max; if(new_grid_num!=pmw->grid_num) { pmw->grid_num=new_grid_num; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; } BarUpdate(pmw,TRUE); } procmeter3-3.5d/gtk1/widgets/PMBar.h000066400000000000000000000053771165060751200172550ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMBar.h,v 1.1 2000-12-16 16:38:15 amb Exp $ ProcMeter Bar Widget include file (for ProcMeter3 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMBAR_H #define PMBAR_H /*+ To stop multiple inclusions. +*/ #include #include #include "PMGeneric.h" #define GTK_TYPE_PROCMETERBAR (gtk_procmeterbar_get_type()) #define GTK_PROCMETERBAR(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERBAR,ProcMeterBar) #define GTK_PROCMETERBAR_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERBAR,ProcMeterBarClass) #define GTK_IS_PROCMETERBAR(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERBAR) typedef struct _ProcMeterBar ProcMeterBar; typedef struct _ProcMeterBarClass ProcMeterBarClass; struct _ProcMeterBar { ProcMeterGeneric generic; gchar* grid_units; /*+ The number of things per grid line. +*/ gushort grid_units_x; /*+ The position of the grid units. +*/ GdkColor grid_color; /*+ The grid lines colour. +*/ GdkGC* grid_gc; /*+ The graphics context for the grid lines. +*/ gint grid_min; /*+ The minimum number of grid lines. +*/ gint grid_max; /*+ The maximum number of grid lines. +*/ gint grid_maxvis; /*+ The maximum number of grid lines before removing them. +*/ gint grid_drawn; /*+ If 1 then draw as normal, if 0 never draw, if -1 draw only one line. +*/ gint grid_num; /*+ The actual number of grid lines. +*/ gushort data[8]; /*+ The data for the bar. +*/ gushort data_index; /*+ A pointer into the array +*/ gulong data_sum; /*+ The average value of the last 10 data points. +*/ }; struct _ProcMeterBarClass { ProcMeterGenericClass parent_class; void (*resize)(ProcMeterBar *pmw); void (*update)(ProcMeterBar *pmw,gboolean all); }; guint gtk_procmeterbar_get_type(void); GtkWidget* gtk_procmeterbar_new(void); /* Public functions */ void ProcMeterBarSetGridColour(ProcMeterBar *pmw,GdkColor grid_color); void ProcMeterBarSetGridMin(ProcMeterBar *pmw,gint grid_min); void ProcMeterBarSetGridMax(ProcMeterBar *pmw,gint grid_max); void ProcMeterBarSetGridUnits(ProcMeterBar *pmw,gchar *units); void ProcMeterBarAddDatum(ProcMeterBar *pmw,gushort datum); #endif /* PMBAR_H */ procmeter3-3.5d/gtk1/widgets/PMGeneric.c000066400000000000000000000316641165060751200201160ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMGeneric.c,v 1.3 2003-06-21 18:38:56 amb Exp $ ProcMeter Generic Widget Source file (for ProcMeter 3.4a). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000,10,02,03 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" static void procmetergeneric_class_init(ProcMeterGenericClass *class); static void procmetergeneric_init(ProcMeterGeneric *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static void GenericResize(ProcMeterGeneric *pmw); static void GenericUpdate(ProcMeterGeneric *pmw); static char *empty_string=""; static GtkWidgetClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint procmetergeneric_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmetergeneric_get_type(void) { static guint pmw_type=0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterGeneric", sizeof(ProcMeterGeneric), sizeof(ProcMeterGenericClass), (GtkClassInitFunc)procmetergeneric_class_init, (GtkObjectInitFunc)procmetergeneric_init, (GtkArgSetFunc) NULL, (GtkArgGetFunc) NULL}; pmw_type=gtk_type_unique(gtk_widget_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterGenericClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergeneric_class_init(ProcMeterGenericClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=GenericResize; class->update=GenericUpdate; parent_class=gtk_type_class(gtk_widget_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmetergeneric_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmetergeneric_new(void) { ProcMeterGeneric *new; new=gtk_type_new(gtk_procmetergeneric_get_type()); return(GTK_WIDGET(new)); } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterGeneric *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergeneric_init(ProcMeterGeneric *pmw) { g_return_if_fail(pmw!=NULL); /* The body parts. */ pmw->body_gc=NULL; pmw->body_bg_set=FALSE; /* The label parts. */ pmw->label_pos=ProcMeterLabelBottom; pmw->label_string=empty_string; pmw->label_font=NULL; pmw->label_gc=NULL; /* The rest of the sizing. */ GenericResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterGeneric *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(object)); pmw=GTK_PROCMETERGENERIC(object); if(pmw->label_string!=empty_string) free(pmw->label_string); if(pmw->body_gc) gdk_gc_destroy(pmw->body_gc); if(pmw->label_gc) gdk_gc_destroy(pmw->label_gc); if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterGeneric *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERGENERIC(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->body_bg_set) gdk_window_set_background(widget->window,&pmw->body_bg_color); GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterGeneric *pmw; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERGENERIC(widget); requisition->height=10+pmw->label_height; requisition->width=50; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterGeneric *pmw=GTK_PROCMETERGENERIC(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); GenericResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Generic Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterGeneric *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERGENERIC(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERGENERIC(widget); GenericUpdate(pmw); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterGeneric *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void GenericResize(ProcMeterGeneric *pmw) { g_return_if_fail(pmw!=NULL); /* The label parts. */ if(pmw->label_pos) { GdkFont *label_font=pmw->label_font?pmw->label_font:pmw->widget.style->font; pmw->label_height=label_font->ascent+label_font->descent+2; pmw->label_x=(pmw->widget.allocation.width-gdk_string_width(label_font,pmw->label_string))/2; if(pmw->label_pos==ProcMeterLabelTop) pmw->label_y=pmw->label_height-1-label_font->descent; else pmw->label_y=pmw->widget.allocation.height-label_font->descent; } else { pmw->label_height=0; pmw->label_x=0; pmw->label_y=0; } /* The body parts. */ pmw->body_height=pmw->widget.allocation.height-pmw->label_height; if(pmw->label_pos==ProcMeterLabelTop) pmw->body_start=pmw->label_height; else pmw->body_start=0; } /*++++++++++++++++++++++++++++++++++++++ Update the display of the generic part of the widget. ProcMeterGeneric *pmw The Widget to update. ++++++++++++++++++++++++++++++++++++++*/ static void GenericUpdate(ProcMeterGeneric *pmw) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->widget)) { GdkFont *label_font=pmw->label_font?pmw->label_font:pmw->widget.style->font; GdkGC *label_gc=pmw->label_gc?pmw->label_gc:pmw->widget.style->fg_gc[GTK_STATE_NORMAL]; gdk_window_clear(pmw->widget.window); if(pmw->label_pos) { gdk_draw_string(pmw->widget.window,label_font,label_gc, pmw->label_x,pmw->label_y, pmw->label_string); if(pmw->label_pos==ProcMeterLabelTop) gdk_draw_line(pmw->widget.window,label_gc, 0 ,pmw->label_height-1, pmw->widget.allocation.width,pmw->label_height-1); else gdk_draw_line(pmw->widget.window,label_gc, 0 ,pmw->body_height, pmw->widget.allocation.width,pmw->body_height); } } } /*++++++++++++++++++++++++++++++++++++++ Set the body colours of the Widget. ProcMeterGeneric *pmw The widget to set. GdkColor body_bg_color The body background. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetBackgroundColour(ProcMeterGeneric *pmw,GdkColor body_bg_color) { pmw->body_bg_color=body_bg_color; pmw->body_bg_set=TRUE; if(pmw->widget.window) gdk_window_set_background(pmw->widget.window,&pmw->body_bg_color); if(pmw->body_gc) gdk_gc_set_background(pmw->body_gc,&pmw->body_bg_color); else { GdkGCValues values; values.background=pmw->body_bg_color; pmw->body_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_BACKGROUND); } if(pmw->label_gc) gdk_gc_set_background(pmw->label_gc,&pmw->body_bg_color); else { GdkGCValues values; values.background=pmw->body_bg_color; pmw->label_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_BACKGROUND); } GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the body colours of the Widget. ProcMeterGeneric *pmw The widget to set. GdkColor body_fg_color The body foreground. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetForegroundColour(ProcMeterGeneric *pmw,GdkColor body_fg_color) { pmw->body_fg_color=body_fg_color; if(pmw->body_gc) gdk_gc_set_foreground(pmw->body_gc,&pmw->body_fg_color); else { GdkGCValues values; values.foreground=pmw->body_fg_color; pmw->body_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_FOREGROUND); } GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the label colour of the Widget. ProcMeterGeneric *pmw The widget to set. GdkColor label_color The label foreground. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabelColour(ProcMeterGeneric *pmw,GdkColor label_color) { pmw->label_color=label_color; if(pmw->label_gc) gdk_gc_set_foreground(pmw->label_gc,&pmw->label_color); else { GdkGCValues values; values.foreground=pmw->label_color; pmw->label_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_FOREGROUND); } GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the label position of the Widget. ProcMeterGeneric *pmw The widget to set. int label_position The position of the label. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabelPosition(ProcMeterGeneric *pmw,int label_position) { if((label_position==ProcMeterLabelTop) || (label_position==ProcMeterLabelNone) || (label_position==ProcMeterLabelBottom)) { pmw->label_pos=label_position; GenericResize(pmw); GenericUpdate(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Set the label font for the widget ProcMeterGeneric *pmw The widget to set. GdkFont *font The font to use. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabelFont(ProcMeterGeneric *pmw,GdkFont *font) { pmw->label_font=font; GenericResize(pmw); GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the label for the widget ProcMeterGeneric *pmw The widget to set. gchar *label The name of the label. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabel(ProcMeterGeneric *pmw,gchar *label) { pmw->label_string=(char*)malloc(strlen(label)+1); strcpy(pmw->label_string,label); GenericUpdate(pmw); } procmeter3-3.5d/gtk1/widgets/PMGeneric.h000066400000000000000000000061331165060751200201140ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMGeneric.h,v 1.1 2000-12-16 16:38:36 amb Exp $ ProcMeter Generic Widget include file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGENERIC_H #define PMGENERIC_H /*+ To stop multiple inclusions. +*/ #include #include #include #define GTK_TYPE_PROCMETERGENERIC (gtk_procmetergeneric_get_type()) #define GTK_PROCMETERGENERIC(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERGENERIC,ProcMeterGeneric) #define GTK_PROCMETERGENERIC_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERGENERIC,ProcMeterGenericClass) #define GTK_IS_PROCMETERGENERIC(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERGENERIC) typedef struct _ProcMeterGeneric ProcMeterGeneric; typedef struct _ProcMeterGenericClass ProcMeterGenericClass; struct _ProcMeterGeneric { GtkWidget widget; GdkColor body_bg_color; /*+ The body background colour. +*/ gboolean body_bg_set; /*+ A flag to indicate if the background has been set. +*/ GdkColor body_fg_color; /*+ The body foreground colour. +*/ GdkGC* body_gc; /*+ The graphics context for the body. +*/ gushort body_height; /*+ The height of the body part. +*/ gushort body_start; /*+ The start position of the body part. +*/ gchar* label_string; /*+ The label for the Widget. +*/ GdkColor label_color; /*+ The label colour. +*/ GdkGC* label_gc; /*+ The graphics context for the label. +*/ gint label_pos; /*+ The position of the label. +*/ GdkFont* label_font; /*+ The font for the label. +*/ gushort label_height; /*+ The height of the label. +*/ gushort label_x,label_y; /*+ The position of the label. +*/ }; struct _ProcMeterGenericClass { GtkWidgetClass parent_class; void (*resize)(ProcMeterGeneric *pmw); void (*update)(ProcMeterGeneric *pmw); }; guint gtk_procmetergeneric_get_type(void); GtkWidget* gtk_procmetergeneric_new(void); /* The options for label placement */ #define ProcMeterLabelTop 1 #define ProcMeterLabelNone 0 #define ProcMeterLabelBottom -1 /* Public functions */ void ProcMeterGenericSetForegroundColour(ProcMeterGeneric *pmw,GdkColor body_fg_color); void ProcMeterGenericSetBackgroundColour(ProcMeterGeneric *pmw,GdkColor body_bg_color); void ProcMeterGenericSetLabelColour(ProcMeterGeneric *pmw,GdkColor label_color); void ProcMeterGenericSetLabelPosition(ProcMeterGeneric *pmw,int label_position); void ProcMeterGenericSetLabelFont(ProcMeterGeneric *pmw,GdkFont *font); void ProcMeterGenericSetLabel(ProcMeterGeneric *pmw,gchar *label); #endif /* PMGENERIC_H */ procmeter3-3.5d/gtk1/widgets/PMGraph.c000066400000000000000000000435121165060751200175760ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMGraph.c,v 1.5 2008-04-27 15:21:30 amb Exp $ ProcMeter Graph Widget Source file (for ProcMeter3 3.5b). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" #include "PMGraph.h" #include "procmeter.h" static void procmetergraph_class_init(ProcMeterGraphClass *class); static void procmetergraph_init(ProcMeterGraph *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void GraphResize(ProcMeterGraph *pmw); static void GraphUpdate(ProcMeterGraph *pmw,gboolean all); static char *empty_string=""; static ProcMeterGenericClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint gtk_procmetergraph_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmetergraph_get_type(void) { static guint pmw_type = 0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterGraph", sizeof(ProcMeterGraph), sizeof(ProcMeterGraphClass), (GtkClassInitFunc) procmetergraph_class_init, (GtkObjectInitFunc) procmetergraph_init, (GtkArgSetFunc) NULL, (GtkArgGetFunc) NULL}; pmw_type=gtk_type_unique(gtk_procmetergeneric_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterGraphClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergraph_class_init(ProcMeterGraphClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=GraphResize; class->update=GraphUpdate; parent_class=gtk_type_class(gtk_procmetergeneric_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterGraph *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergraph_init(ProcMeterGraph *pmw) { g_return_if_fail(pmw!=NULL); /* The grid parts. */ pmw->grid_units=empty_string; pmw->grid_gc=NULL; pmw->grid_drawn=1; pmw->grid_min=1; pmw->grid_max=0; pmw->grid_num=pmw->grid_min; /* The data parts. */ pmw->data_num=10; pmw->data=(gushort*)calloc(pmw->data_num,sizeof(gushort)); pmw->data_max=0; pmw->data_index=0; /* The rest of the sizing. */ GraphResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmetergraph_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmetergraph_new(void) { ProcMeterGraph *pmw; pmw=gtk_type_new(gtk_procmetergraph_get_type()); return(GTK_WIDGET(pmw)); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterGraph *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(object)); pmw=GTK_PROCMETERGRAPH(object); if(pmw->grid_gc) gdk_gc_destroy(pmw->grid_gc); if(pmw->grid_units!=empty_string) free(pmw->grid_units); free(pmw->data); if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterGraph *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERGRAPH(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->generic.body_bg_set) gdk_window_set_background(widget->window,&pmw->generic.body_bg_color); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterGraph *pmw; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERGRAPH(widget); requisition->height=20+pmw->generic.label_height; requisition->width=50; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterGraph *pmw=GTK_PROCMETERGRAPH(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); GraphResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Graph Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterGraph *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERGRAPH(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERGRAPH(widget); GraphUpdate(pmw,TRUE); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterGraph *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void GraphResize(ProcMeterGraph *pmw) { GdkFont *label_font; g_return_if_fail(pmw!=NULL); (parent_class->resize)(&pmw->generic); if(pmw->data_num!=pmw->generic.widget.allocation.width) { int i,old_num=pmw->data_num; gushort* old_data=pmw->data; pmw->data_num=pmw->generic.widget.allocation.width; pmw->data=(gushort*)calloc(pmw->data_num,sizeof(gushort)); if(pmw->data_numdata_num; else i=old_num; for(;i>0;i--) pmw->data[(-i+pmw->data_num)%pmw->data_num]=old_data[(pmw->data_index-i+old_num)%old_num]; pmw->data_index=0; free(old_data); for(i=pmw->data_max=0;idata_num;i++) if(pmw->data[i]>pmw->data_max) pmw->data_max=pmw->data[i]; pmw->grid_num=(pmw->data_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(pmw->grid_numgrid_min) pmw->grid_num=pmw->grid_min; if(pmw->grid_max && pmw->grid_num>pmw->grid_max) pmw->grid_num=pmw->grid_max; } pmw->generic.label_x=2; /* The grid parts. */ label_font=pmw->generic.label_font?pmw->generic.label_font:pmw->generic.widget.style->font; pmw->grid_units_x=pmw->generic.widget.allocation.width-gdk_string_width(label_font,pmw->grid_units); pmw->grid_maxvis=pmw->generic.body_height/3; if(pmw->generic.label_pos==ProcMeterLabelTop) pmw->generic.body_start=pmw->generic.label_height; else pmw->generic.body_start=0; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterGraph *pmw The Widget to update. gboolean all Indicates if the whole widget is to be updated. ++++++++++++++++++++++++++++++++++++++*/ static void GraphUpdate(ProcMeterGraph *pmw,gboolean all) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->generic.widget)) { GdkGC *grid_gc=pmw->grid_gc?pmw->grid_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkGC *body_gc=pmw->generic.body_gc?pmw->generic.body_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkFont *label_font=pmw->generic.label_font?pmw->generic.label_font:pmw->generic.widget.style->font; int i; int scale=PROCMETER_GRAPH_SCALE*pmw->grid_num; gushort val; gshort pos; if(all) { (parent_class->update)(&pmw->generic); if(pmw->generic.label_pos!=ProcMeterLabelNone) gdk_draw_string(pmw->generic.widget.window,label_font,pmw->generic.label_gc, pmw->grid_units_x,pmw->generic.label_y, pmw->grid_units); for(i=0;idata_num;i++) { val=pmw->data[(i+pmw->data_index)%pmw->data_num]; pos=val*pmw->generic.body_height/scale; if(pmw->line_solid) gdk_draw_line(pmw->generic.widget.window,body_gc, i,pmw->generic.body_height+pmw->generic.body_start, i,pmw->generic.body_height+pmw->generic.body_start-pos); else if(i) { gushort oldval=pmw->data[(i-1+pmw->data_index)%pmw->data_num]; gshort oldpos=oldval*pmw->generic.body_height/scale; gdk_draw_line(pmw->generic.widget.window,body_gc, i,pmw->generic.body_height+pmw->generic.body_start-oldpos, i,pmw->generic.body_height+pmw->generic.body_start-pos); } } if(pmw->grid_drawn==1) for(i=1;igrid_num;i++) { pos=i*pmw->generic.body_height/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, 0 ,pmw->generic.body_height+pmw->generic.body_start-pos, pmw->generic.widget.allocation.width,pmw->generic.body_height+pmw->generic.body_start-pos); } else if(pmw->grid_drawn==-1) { pos=pmw->grid_maxvis*pmw->generic.body_height/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, 0 ,pmw->generic.body_height+pmw->generic.body_start-pos, pmw->generic.widget.allocation.width,pmw->generic.body_height+pmw->generic.body_start-pos); } } else { val=pmw->data[(pmw->data_num-1+pmw->data_index)%pmw->data_num]; pos=val*pmw->generic.body_height/scale; gdk_window_copy_area(pmw->generic.widget.window,grid_gc, 0,pmw->generic.body_start, pmw->generic.widget.window, 1,pmw->generic.body_start, pmw->generic.widget.allocation.width-1,pmw->generic.body_height); gdk_window_clear_area(pmw->generic.widget.window, pmw->generic.widget.allocation.width-1,pmw->generic.body_start, 1,pmw->generic.body_height); if(pmw->line_solid) gdk_draw_line(pmw->generic.widget.window,body_gc, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start-pos); else { gushort oldval=pmw->data[(pmw->data_num-2+pmw->data_index)%pmw->data_num]; gshort oldpos=oldval*pmw->generic.body_height/scale; gdk_draw_line(pmw->generic.widget.window,body_gc, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start-oldpos, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start-pos); } if(pmw->grid_drawn==1) for(i=1;igrid_num;i++) { pos=i*pmw->generic.body_height/pmw->grid_num; gdk_draw_point(pmw->generic.widget.window,grid_gc, pmw->generic.widget.allocation.width-1,pmw->generic.body_height+pmw->generic.body_start-pos); } else if(pmw->grid_drawn==-1) { pos=pmw->grid_maxvis*pmw->generic.body_height/pmw->grid_num; gdk_draw_point(pmw->generic.widget.window,grid_gc, pmw->generic.widget.allocation.width-1,pmw->generic.body_height+pmw->generic.body_start-pos); } } } } /*++++++++++++++++++++++++++++++++++++++ Set the grid colour of the Widget. ProcMeterGraph *pmw The widget to set. GdkColor grid_color The grid. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridColour(ProcMeterGraph *pmw,GdkColor grid_color) { pmw->grid_color=grid_color; if(pmw->grid_gc) gdk_gc_set_foreground(pmw->grid_gc,&pmw->grid_color); else { GdkGCValues values; values.foreground=pmw->grid_color; pmw->grid_gc=gdk_gc_new_with_values(pmw->generic.widget.parent->window,&values,GDK_GC_FOREGROUND); } GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the minimum number of grid lines in the Widget. ProcMeterGraph *pmw The Widget to set. gint grid_min The minimum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridMin(ProcMeterGraph *pmw,gint grid_min) { if(grid_min<0) { pmw->grid_min=-grid_min; pmw->grid_drawn=0; } else if(grid_min>0) { pmw->grid_min=grid_min; pmw->grid_drawn=1; } else /* if(grid_min==0) */ { pmw->grid_min=1; pmw->grid_drawn=1; } if(grid_min>pmw->grid_max && pmw->grid_max) pmw->grid_min=pmw->grid_max; if(pmw->grid_min>=pmw->grid_num) pmw->grid_num=pmw->grid_min; GraphResize(pmw); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the maximum number of grid lines in the Widget. ProcMeterGraph *pmw The Widget to set. gint grid_max The maximum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridMax(ProcMeterGraph *pmw,gint grid_max) { if(grid_max<0) pmw->grid_max=0; else pmw->grid_max=grid_max; if(grid_max && grid_maxgrid_min) pmw->grid_max=pmw->grid_min; GraphResize(pmw); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the graph to solid or line. ProcMeterGraph *pmw The Widget to set. gboolean solid The solidity of the graph. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetSolid(ProcMeterGraph *pmw,gboolean solid) { pmw->line_solid=solid; GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the grid units for the widget ProcMeterGraph *pmw The widget to set. gchar *units The grid units. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridUnits(ProcMeterGraph *pmw,gchar *units) { if(pmw->grid_units!=empty_string) free(pmw->grid_units); pmw->grid_units=(char*)malloc(strlen(units)+1); strcpy(pmw->grid_units,units); GraphResize(pmw); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Add a data point to the ProcMeter Graph Widget. ProcMeterGraph *pmw The ProcMeter Graph Widget. gushort datum The data point to add. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphAddDatum(ProcMeterGraph *pmw,gushort datum) { gushort old_datum,new_data_max=pmw->data_max; int i; old_datum=pmw->data[pmw->data_index]; pmw->data[pmw->data_index]=datum; pmw->data_index=(pmw->data_index+1)%pmw->data_num; if(datum>new_data_max) new_data_max=datum; else if(old_datum==new_data_max) for(i=new_data_max=0;idata_num;i++) if(pmw->data[i]>new_data_max) new_data_max=pmw->data[i]; if(new_data_max!=pmw->data_max) { int new_grid_num=(new_data_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numgrid_min) new_grid_num=pmw->grid_min; if(pmw->grid_max && new_grid_num>pmw->grid_max) new_grid_num=pmw->grid_max; pmw->data_max=new_data_max; if(new_grid_num!=pmw->grid_num) { pmw->grid_num=new_grid_num; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; GraphUpdate(pmw,TRUE); } } GraphUpdate(pmw,FALSE); } procmeter3-3.5d/gtk1/widgets/PMGraph.h000066400000000000000000000060541165060751200176030ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMGraph.h,v 1.1 2000-12-16 16:39:02 amb Exp $ ProcMeter Graph Widget include file (for ProcMeter3 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGRAPH_H #define PMGRAPH_H /*+ To stop multiple inclusions. +*/ #include #include #include "PMGeneric.h" #define GTK_TYPE_PROCMETERGRAPH (gtk_procmetergraph_get_type()) #define GTK_PROCMETERGRAPH(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERGRAPH,ProcMeterGraph) #define GTK_PROCMETERGRAPH_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERGRAPH,ProcMeterGraphClass) #define GTK_IS_PROCMETERGRAPH(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERGRAPH) typedef struct _ProcMeterGraph ProcMeterGraph; typedef struct _ProcMeterGraphClass ProcMeterGraphClass; struct _ProcMeterGraph { ProcMeterGeneric generic; gchar* grid_units; /*+ The number of things per grid line. +*/ gushort grid_units_x; /*+ The position of the grid units. +*/ GdkColor grid_color; /*+ The grid lines colour. +*/ GdkGC* grid_gc; /*+ The graphics context for the grid lines. +*/ gint grid_min; /*+ The minimum number of grid lines. +*/ gint grid_max; /*+ The maximum number of grid lines. +*/ gint grid_maxvis; /*+ The maximum number of grid lines before removing them. +*/ gint grid_drawn; /*+ If 1 then draw as normal, if 0 never draw, if -1 draw only one line. +*/ gint grid_num; /*+ The actual number of grid lines. +*/ gboolean line_solid; /*+ True if the area under the graph is to be filled. +*/ gushort* data; /*+ The data for the graph. +*/ gushort data_max; /*+ The maximum data value. +*/ guint data_num; /*+ The number of data points. +*/ gint data_index; /*+ An index into the array for the new value. +*/ }; struct _ProcMeterGraphClass { ProcMeterGenericClass parent_class; void (*resize)(ProcMeterGraph *pmw); void (*update)(ProcMeterGraph *pmw,gboolean all); }; guint gtk_procmetergraph_get_type(void); GtkWidget* gtk_procmetergraph_new(void); /* Public functions */ void ProcMeterGraphSetGridColour(ProcMeterGraph *pmw,GdkColor grid_color); void ProcMeterGraphSetGridMin(ProcMeterGraph *pmw,gint grid_min); void ProcMeterGraphSetGridMax(ProcMeterGraph *pmw,gint grid_max); void ProcMeterGraphSetGridUnits(ProcMeterGraph *pmw,gchar *units); void ProcMeterGraphSetSolid(ProcMeterGraph *pmw,gboolean solid); void ProcMeterGraphAddDatum(ProcMeterGraph *pmw,gushort datum); #endif /* PMGRAPH_H */ procmeter3-3.5d/gtk1/widgets/PMText.c000066400000000000000000000232341165060751200174600ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMText.c,v 1.3 2003-06-21 18:39:05 amb Exp $ ProcMeter Text Widget Source file (for ProcMeter 3.4a). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000,01,02,03 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" #include "PMText.h" static void procmetertext_class_init (ProcMeterTextClass *class); static void procmetertext_init(ProcMeterText *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static void TextResize(ProcMeterText *pmw); static void TextUpdate(ProcMeterText *pmw,gboolean all); static char *empty_string=""; static ProcMeterGenericClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint gtk_procmetertext_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmetertext_get_type(void) { static guint pmw_type = 0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterText", sizeof(ProcMeterText), sizeof(ProcMeterTextClass), (GtkClassInitFunc) procmetertext_class_init, (GtkObjectInitFunc) procmetertext_init, (GtkArgSetFunc) NULL, (GtkArgGetFunc) NULL}; pmw_type=gtk_type_unique(gtk_procmetergeneric_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterTextClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetertext_class_init(ProcMeterTextClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=TextResize; class->update=TextUpdate; parent_class=gtk_type_class(gtk_procmetergeneric_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterText *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetertext_init(ProcMeterText *pmw) { g_return_if_fail(pmw!=NULL); /* The text parts. */ pmw->text_string=empty_string; pmw->text_font=NULL; /* The rest of the sizing. */ TextResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmetertext_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmetertext_new(void) { ProcMeterText *pmw; pmw=gtk_type_new(gtk_procmetertext_get_type()); return(GTK_WIDGET(pmw)); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterText *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(object)); pmw=GTK_PROCMETERTEXT(object); if(pmw->text_string!=empty_string) free(pmw->text_string); if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterText *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERTEXT(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->generic.body_bg_set) gdk_window_set_background(widget->window,&pmw->generic.body_bg_color); TextUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterText *pmw; GdkFont *text_font; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERTEXT(widget); text_font=pmw->text_font?pmw->text_font:pmw->generic.widget.style->font; requisition->width=gdk_string_width(text_font,"NNNNNNNNNNNNNNN"); requisition->height=text_font->ascent+text_font->descent+2+pmw->generic.label_height; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterText *pmw=GTK_PROCMETERTEXT(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); TextResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Text Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterText *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERTEXT(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERTEXT(widget); TextUpdate(pmw,TRUE); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterText *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void TextResize(ProcMeterText *pmw) { GdkFont *text_font; g_return_if_fail(pmw!=NULL); (parent_class->resize)(&pmw->generic); /* The text parts. */ text_font=pmw->text_font?pmw->text_font:pmw->generic.widget.style->font; pmw->text_x=(pmw->generic.widget.allocation.width-gdk_string_width(text_font,pmw->text_string))/2; pmw->text_y=pmw->generic.body_start+1+text_font->ascent; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterText *pmw The Widget to update. gboolean all Indicates if the whole widget is to be updated. ++++++++++++++++++++++++++++++++++++++*/ static void TextUpdate(ProcMeterText *pmw,gboolean all) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->generic.widget)) { GdkGC *body_gc=pmw->generic.body_gc?pmw->generic.body_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkFont *text_font=pmw->text_font?pmw->text_font:pmw->generic.widget.style->font; if(all) (parent_class->update)(&pmw->generic); else gdk_window_clear_area(pmw->generic.widget.window, 0,pmw->generic.body_start, pmw->generic.widget.allocation.width,pmw->generic.body_height); gdk_draw_string(pmw->generic.widget.window,text_font,body_gc, pmw->text_x,pmw->text_y, pmw->text_string); } } /*++++++++++++++++++++++++++++++++++++++ Set the text font for the widget ProcMeterText *pmw The widget to set. GdkFont *font The font to use. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterTextSetFont(ProcMeterText *pmw,GdkFont *font) { pmw->text_font=font; TextResize(pmw); TextUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Change the data displayed in the ProcMeter Text Widget. ProcMeterText *pmw The ProcMeter Text Widget. char *text The new string to display. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterTextChangeData(ProcMeterText *pmw,char *text) { if(pmw->text_string!=empty_string) free(pmw->text_string); pmw->text_string=(char*)malloc(strlen(text)+1); strcpy(pmw->text_string,text); pmw->text_x=(pmw->generic.widget.allocation.width-gdk_string_width(pmw->text_font,pmw->text_string))/2; TextUpdate(pmw,FALSE); } procmeter3-3.5d/gtk1/widgets/PMText.h000066400000000000000000000035121165060751200174620ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/widgets/PMText.h,v 1.1 2000-12-16 16:39:18 amb Exp $ ProcMeter Text Widget include file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMTEXT_H #define PMTEXT_H /*+ To stop multiple inclusions. +*/ #include #include #include "PMGeneric.h" #define GTK_TYPE_PROCMETERTEXT (gtk_procmetertext_get_type()) #define GTK_PROCMETERTEXT(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERTEXT,ProcMeterText) #define GTK_PROCMETERTEXT_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERTEXT,ProcMeterTextClass) #define GTK_IS_PROCMETERTEXT(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERTEXT) typedef struct _ProcMeterText ProcMeterText; typedef struct _ProcMeterTextClass ProcMeterTextClass; struct _ProcMeterText { ProcMeterGeneric generic; gchar* text_string; /*+ The text for the Widget. +*/ GdkFont* text_font; /*+ The font for the text. +*/ gushort text_x,text_y; /*+ The position of the text. +*/ }; struct _ProcMeterTextClass { ProcMeterGenericClass parent_class; void (*resize)(ProcMeterText *pmw); void (*update)(ProcMeterText *pmw,gboolean all); }; guint gtk_procmetertext_get_type(void); GtkWidget* gtk_procmetertext_new(void); /* Public functions */ void ProcMeterTextSetFont(ProcMeterText *pmw,GdkFont *font); void ProcMeterTextChangeData(ProcMeterText *pmt,char *data); #endif /* PMTEXT_H */ procmeter3-3.5d/gtk1/window.c000066400000000000000000000445201165060751200161410ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/window.c,v 1.9 2010-02-28 10:21:56 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. X Windows interface. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1997-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include "widgets/PMGeneric.h" #include "widgets/PMGraph.h" #include "widgets/PMText.h" #include "widgets/PMBar.h" #include "procmeter.h" #include "procmeterp.h" #include "window.h" #define MINHEIGHT 30 #define MINWIDTH 60 static gint SleepCallback(gpointer p); static void ResizePaneCallback(GtkWidget *w,GdkEventConfigure *event); static gint CloseCallback(GtkWidget *w,GdkEvent *event,gpointer data); static void add_EWMH(char *name); /*+ The toplevel widget. +*/ GtkWidget *toplevel; /*+ The pane that contains all of the outputs. +*/ GtkWidget *pane=NULL; /*+ If the meters are aligned vertically. +*/ int vertical=1; /*+ A flag that is set to true when we are told to quit. +*/ extern int quit; /*+ Set to true when we are sleeping waiting for a timeout. +*/ static int sleeping; /*+ A list of the outputs that are currently visible. +*/ static Output *displayed=NULL; static int ndisplayed=0; /*+ A flag to indicate that we are still initialising and not to resize. +*/ static int initialising=1; /*++++++++++++++++++++++++++++++++++++++ Start the X-Windows & GTK part. int *argc The number of command line arguments. char **argv The actual command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void Start(int *argc,char **argv) { static char procmeter_version[]="ProcMeter V" PROCMETER_VERSION; char *string; GtkWidget *event_box; int i,j=0; if((string=GetProcMeterRC("resources","horizontal")) && StringToBoolean(string)) vertical=0; /* Initialise the display */ gtk_init(argc,&argv); toplevel=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(toplevel),procmeter_version); gtk_window_set_policy(GTK_WINDOW(toplevel),TRUE,TRUE,TRUE); /* Create the bitmaps */ CreateBitmaps(toplevel); /* Create the menu widgets */ CreateMenus(toplevel); /* Create the pane widget */ event_box=gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(toplevel),event_box); gtk_widget_show(event_box); if(vertical) pane=gtk_vbox_new(FALSE,0); else pane=gtk_hbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(pane),2); gtk_container_add(GTK_CONTAINER(event_box),pane); gtk_widget_show(GTK_WIDGET(pane)); gtk_signal_connect(GTK_OBJECT(toplevel),"configure_event", GTK_SIGNAL_FUNC(ResizePaneCallback),NULL); AddMenuToOutput(event_box,NULL); /* Show the widgets */ gtk_widget_show(GTK_WIDGET(toplevel)); /* Parse the -geometry and -w flag */ for(i=1;i<*argc;i++) if((!strcmp(argv[i],"-geometry")) && (i+1<=*argc)) { int x,y,w,h; i++;j+=2; if(sscanf(argv[i],"%dx%d%d%d",&w,&h,&x,&y)==4) { gtk_widget_set_usize(GTK_WIDGET(toplevel),w,h); if(x<0) x=gdk_screen_width()-w+x; if(y<0) y=gdk_screen_height()-h+y; gtk_widget_set_uposition(GTK_WIDGET(toplevel),x,y); } else if(sscanf(argv[i],"%dx%d",&w,&h)==2) gtk_widget_set_usize(GTK_WIDGET(toplevel),w,h); else fprintf(stderr,"ProcMeter: Cannot parse -geometry option: '%s'\n",argv[i]); } else if((!strcmp(argv[i],"-w")) && (i+1<=*argc)) { char *token; i++;j+=2; token=strtok(argv[i],","); while(token) { if(!strcmp(token,"above")) add_EWMH("_NET_WM_STATE_ABOVE"); else if(!strcmp(token,"below")) add_EWMH("_NET_WM_STATE_BELOW"); else if(!strcmp(token,"skip_taskbar")) add_EWMH("_NET_WM_STATE_SKIP_TASKBAR"); else if(!strcmp(token,"skip_pager")) add_EWMH("_NET_WM_STATE_SKIP_PAGER"); else if(!strcmp(token,"sticky")) add_EWMH("_NET_WM_STATE_STICKY"); else fprintf(stderr,"ProcMeter: Cannot parse -w option: '%s'\n",token); token = strtok(NULL,","); } } if(j>0) { for(i=j;i<*argc;i++) argv[i-j]=argv[i]; *argc-=j; } /* Put an action on the window manager close button */ gtk_signal_connect(GTK_OBJECT(toplevel),"delete_event", GTK_SIGNAL_FUNC(CloseCallback),NULL); } /*++++++++++++++++++++++++++++++++++++++ Stop the X-Windows & GTK part. ++++++++++++++++++++++++++++++++++++++*/ void Stop(void) { DestroyMenus(); gtk_main_quit(); } /*++++++++++++++++++++++++++++++++++++++ Sleep for the specified interval in seconds. time_t until The time to sleep until. ++++++++++++++++++++++++++++++++++++++*/ void Sleep(time_t until) { struct timeval now; int delay; /* Before we sleep the first time, resize the window. */ if(initialising) { Resize(); initialising=0; } /* Sleep */ gettimeofday(&now,NULL); delay=1000*(until-now.tv_sec)-now.tv_usec/1000; if(delay>0) { gint id=gtk_timeout_add(delay,(GtkFunction)SleepCallback,NULL); sleeping=1; while(sleeping) { struct timeval now2; gtk_main_iteration(); gettimeofday(&now2,NULL); if(now2.tv_secoutput_widget) { int i,found=0; gtk_widget_destroy(GTK_WIDGET(output->output_widget)); output->output_widget=NULL; for(i=0;ioutputs;*outputp;outputp++) if(output==*outputp) { module=*modulep; break; } if(module) break; } if(output->type==PROCMETER_GRAPH) { w=gtk_procmetergraph_new(); gtk_box_pack_start(GTK_BOX(pane),w,TRUE,TRUE,0); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-foreground")) || (string=GetProcMeterRC(module->module->name,"grid-foreground")) || (string=GetProcMeterRC("resources","grid-foreground")))) ProcMeterGraphSetGridColour(GTK_PROCMETERGRAPH(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"graph-solid")) || (string=GetProcMeterRC(module->module->name,"graph-solid")) || (string=GetProcMeterRC("resources","graph-solid")))) ProcMeterGraphSetSolid(GTK_PROCMETERGRAPH(w),StringToBoolean(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-max")) || (string=GetProcMeterRC(module->module->name,"grid-max")) || (string=GetProcMeterRC("resources","grid-max")))) ProcMeterGraphSetGridMax(GTK_PROCMETERGRAPH(w),StringToInt(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) ProcMeterGraphSetGridMin(GTK_PROCMETERGRAPH(w),StringToInt(string)); if(vertical) gtk_widget_set_usize(GTK_WIDGET(w),-1,MINHEIGHT); else gtk_widget_set_usize(GTK_WIDGET(w),MINWIDTH,-1); sprintf(str,output->output->graph_units,output->output->graph_scale); ProcMeterGraphSetGridUnits(GTK_PROCMETERGRAPH(w),str); } else if(output->type==PROCMETER_TEXT) { w=gtk_procmetertext_new(); gtk_box_pack_start(GTK_BOX(pane),w,FALSE,TRUE,0); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"text-font")) || (string=GetProcMeterRC(module->module->name,"text-font")) || (string=GetProcMeterRC("resources","text-font")))) ProcMeterTextSetFont(GTK_PROCMETERTEXT(w),StringToFont(string)); } else if(output->type==PROCMETER_BAR) { w=gtk_procmeterbar_new(); gtk_box_pack_start(GTK_BOX(pane),w,TRUE,TRUE,0); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-foreground")) || (string=GetProcMeterRC(module->module->name,"grid-foreground")) || (string=GetProcMeterRC("resources","grid-foreground")))) ProcMeterBarSetGridColour(GTK_PROCMETERBAR(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) ProcMeterBarSetGridMin(GTK_PROCMETERBAR(w),StringToInt(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-max")) || (string=GetProcMeterRC(module->module->name,"grid-max")) || (string=GetProcMeterRC("resources","grid-max")))) ProcMeterBarSetGridMax(GTK_PROCMETERBAR(w),StringToInt(string)); sprintf(str,output->output->graph_units,output->output->graph_scale); ProcMeterBarSetGridUnits(GTK_PROCMETERBAR(w),str); } /* Generic */ ProcMeterGenericSetLabel(GTK_PROCMETERGENERIC(w),(gchar*)output->label); /* Resources */ if(((string=GetProcMeterRC2(module->module->name,output->output->name,"foreground")) || (string=GetProcMeterRC(module->module->name,"foreground")) || (string=GetProcMeterRC("resources","foreground")))) ProcMeterGenericSetForegroundColour(GTK_PROCMETERGENERIC(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"background")) || (string=GetProcMeterRC(module->module->name,"background")) || (string=GetProcMeterRC("resources","background")))) ProcMeterGenericSetBackgroundColour(GTK_PROCMETERGENERIC(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-font")) || (string=GetProcMeterRC(module->module->name,"label-font")) || (string=GetProcMeterRC("resources","label-font")))) ProcMeterGenericSetLabelFont(GTK_PROCMETERGENERIC(w),StringToFont(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-foreground")) || (string=GetProcMeterRC(module->module->name,"label-foreground")) || (string=GetProcMeterRC("resources","label-foreground")) || (string=GetProcMeterRC2(module->module->name,output->output->name,"foreground")) || (string=GetProcMeterRC(module->module->name,"foreground")) || (string=GetProcMeterRC("resources","foreground")))) ProcMeterGenericSetLabelColour(GTK_PROCMETERGENERIC(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-position")) || (string=GetProcMeterRC(module->module->name,"label-position")) || (string=GetProcMeterRC("resources","label-position")))) ProcMeterGenericSetLabelPosition(GTK_PROCMETERGENERIC(w),StringToLabelPosition(string)); AddMenuToOutput(w,module); gtk_widget_show(GTK_WIDGET(w)); gtk_signal_handler_block_by_data(GTK_OBJECT(output->menu_item_widget),output); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(output->menu_item_widget),TRUE); gtk_signal_handler_unblock_by_data(GTK_OBJECT(output->menu_item_widget),output); output->output_widget=w; output->first=2; displayed=(Output*)realloc((void*)displayed,sizeof(Output)*(ndisplayed+1)); displayed[ndisplayed]=output; ndisplayed++; } Resize(); } /*++++++++++++++++++++++++++++++++++++++ Update a graph output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateGraph(Output output,short value) { ProcMeterGraphAddDatum(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Update a text output. Output output The output to update. char *value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateText(Output output,char *value) { ProcMeterTextChangeData(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Update a bar output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateBar(Output output,short value) { ProcMeterBarAddDatum(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Move an output. Output output1 The output to be moved. Output output2 The one that the output is to be moved above or below. int direction The direction to move the output (up=1 or down=2). ++++++++++++++++++++++++++++++++++++++*/ void MoveOutput(Output output1,Output output2,int direction) { int i,i1=-1,i2=-1; for(i=0;ioutput_widget),i2); Resize(); if(direction==1 && i2>i1) { for(i=i1;ii2) { for(i=i1;i>i2;i--) displayed[i]=displayed[i-1]; displayed[i2]=output1; } else if(direction==2 && i2>i1) { for(i=i1;ii2) */ { for(i=i1;i>i2;i--) displayed[i]=displayed[i-1]; displayed[i2+1]=output1; } } /*++++++++++++++++++++++++++++++++++++++ Resize the pane. ++++++++++++++++++++++++++++++++++++++*/ void Resize(void) { gushort psize,size; gint width,height; int gsize,msize; int i,ngraphs=0; if(initialising) return; if(!ndisplayed) return; gdk_window_get_size(GTK_WIDGET(toplevel)->window,&width,&height); if(vertical) psize=height; else psize=width; msize=0; gsize=psize; for(i=0;ioutput_widget),&request); if(vertical) min_size=request.height; else min_size=request.width; if(displayed[i]->type==PROCMETER_GRAPH) ngraphs++; else if(displayed[i]->type==PROCMETER_TEXT) gsize-=min_size; else if(displayed[i]->type==PROCMETER_BAR) ngraphs++; msize+=min_size; if(i) msize+=2,gsize-=2; /* separator between panes */ } if(msize>psize || (ngraphs==0 && msize!=psize)) { if(vertical) height=msize; else width=msize; gtk_widget_set_usize(GTK_WIDGET(toplevel),0,0); gdk_window_resize(GTK_WIDGET(toplevel)->window,width,height); gtk_widget_set_usize(GTK_WIDGET(pane),width,height); gtk_container_resize_children(GTK_CONTAINER(pane)); return; } for(i=0;itype==PROCMETER_GRAPH || displayed[i]->type==PROCMETER_BAR) { size=gsize/ngraphs; gsize-=size; ngraphs--; if(vertical) height=size; else width=size; } else { GtkRequisition request; gtk_widget_size_request(GTK_WIDGET(displayed[i]->output_widget),&request); if(vertical) height=request.height; else width=request.width; } //gtk_widget_set_usize(GTK_WIDGET(displayed[i]->output_widget),width,height); } } /*++++++++++++++++++++++++++++++++++++++ The function called by the timeout to terminate the sleep. gint SleepCallback Returns true to repeat the timer. gpointer p Not used. This function is only ever called from the gtk event loop. ++++++++++++++++++++++++++++++++++++++*/ static gint SleepCallback(gpointer p) { sleeping=0; return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ A callback that is activated by a resize event on the parent pane. GtkWidget *w The widget that caused the callback. GdkEventConfigure *event Not used. This function is only ever called from the gtk event loop. ++++++++++++++++++++++++++++++++++++++*/ static void ResizePaneCallback(GtkWidget *w,GdkEventConfigure *event) { Resize(); } /*++++++++++++++++++++++++++++++++++++++ A callback that is activated by a close window event on the toplevel window. gint CloseCallback returns a value that indicates if the toplevel window is not to be destroyed. GtkWidget *w The widget that caused the event. GdkEvent *event The event information. gpointer data Not used. This function is only ever called from the GTK event handler. ++++++++++++++++++++++++++++++++++++++*/ static gint CloseCallback(GtkWidget *w,GdkEvent *event,gpointer data) { quit=1; return(TRUE); } /*++++++++++++++++++++++++++++++++++++++ Adds an Extended Window Manager Hint to the window. char *name The name of the hint to add. ++++++++++++++++++++++++++++++++++++++*/ static void add_EWMH(char *name) { XEvent event; Display *display=GDK_WINDOW_XDISPLAY(toplevel->window); event.xclient.type=ClientMessage; event.xclient.serial=0; event.xclient.send_event=True; event.xclient.message_type=XInternAtom(display,"_NET_WM_STATE",False); event.xclient.window=GDK_WINDOW_XWINDOW(GTK_WIDGET(toplevel)->window); event.xclient.format=32; event.xclient.data.l[0]=1; /* add */ event.xclient.data.l[1]=XInternAtom(display,name,False); event.xclient.data.l[2]=0; event.xclient.data.l[3]=0; event.xclient.data.l[4]=0; XSendEvent(display,DefaultRootWindow(display),False,SubstructureRedirectMask|SubstructureNotifyMask,&event); } procmeter3-3.5d/gtk1/window.h000066400000000000000000000024771165060751200161530ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk1/window.h,v 1.2 2002-06-04 12:52:27 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3b. Global X windows header file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef WINDOW_H #define WINDOW_H /*+ To stop multiple inclusions. +*/ #include "procmeterp.h" /* In window.c */ void MoveOutput(Output output1,Output output2,int direction); void Resize(void); /* In menus.c */ void CreateMenus(GtkWidget *parent); void DestroyMenus(void); void AddMenuToOutput(GtkWidget *widget,Module module); /* In resources.c */ GdkFont *StringToFont(char *string); GdkColor StringToPixel(char *string); gboolean StringToBoolean(char *string); int StringToInt(char *string); int StringToLabelPosition(char *string); /* In bitmap.c */ extern GdkPixmap *CircleBitmap; extern GdkPixmap *TextBitmap; extern GdkPixmap *GraphBitmap; extern GdkPixmap *BarBitmap; void CreateBitmaps(GtkWidget *w); #endif /* WINDOW_H */ procmeter3-3.5d/gtk2/000077500000000000000000000000001165060751200144625ustar00rootroot00000000000000procmeter3-3.5d/gtk2/Makefile000066400000000000000000000042561165060751200161310ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/gtk2/Makefile,v 1.2 2007-09-26 18:31:46 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.5. # # Makefile for gtk2 parts. # # Written by Andrew M. Bishop # # This file Copyright 1994-2007 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options CFLAGS=-g -O2 -Wall LDFLAGS= X_CFLAGS=`pkg-config --cflags gtk+-2.0` X_LDFLAGS=`pkg-config --libs gtk+-2.0` # Check for GTK2 development libraries and headers HAVE_GTK2:=$(shell pkg-config --modversion gtk+-2.0) ifdef HAVE_GTK2 ALL=all-gtk2 else ALL=all-no-gtk2 endif # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) PSRC=$(wildcard ../*.c) POBJ=$(foreach f,$(PSRC),$(addsuffix .o,$(basename $f))) WSRC=$(wildcard widgets/*.c) WOBJ=$(foreach f,$(WSRC),$(addsuffix .o,$(basename $f))) ######## all : $(ALL) all-no-gtk2 : @echo "ProcMeter:" @echo "ProcMeter: GTK2 is not installed (pkg-config could not find it)." @echo "ProcMeter: Cannot compile procmeter3-gtk2 program." @echo "ProcMeter:" all-gtk2 : $(OBJ) procmeter.widget \ ../procmeter3-gtk2 ######## ../procmeter3-gtk2 : $(OBJ) procmeter.widget procmeter.main $(LD) $(OBJ) $(WOBJ) $(POBJ) -o $@ -ldl $(LDFLAGS) $(X_LDFLAGS) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(X_CFLAGS) -I.. bitmap.o : bitmap.c ../procmeterp.h ../procmeter.h window.h resources.o : resources.c ../procmeterp.h ../procmeter.h window.h menus.o : menus.c ../procmeterp.h ../procmeter.h window.h window.o : window.c ../procmeterp.h ../procmeter.h window.h run.o : run.c ../procmeterp.h ../procmeter.h window.h ######## .PHONY : procmeter.widget procmeter.widget : $(MAKE) CFLAGS="$(CFLAGS)" X_CFLAGS="$(X_CFLAGS)" -C widgets ######## .PHONY : procmeter.main $(POBJ) : procmeter.main procmeter.main : $(MAKE) CFLAGS="$(CFLAGS)" -C .. obj ######## .PHONY : clean clean : -rm -f *.o *~ core $(MAKE) -C widgets clean ######## .PHONY : install install : procmeter3-3.5d/gtk2/bitmap.c000066400000000000000000000036551165060751200161130ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/bitmap.c,v 1.1 2007-09-19 19:06:27 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.4e. X Window Bitmaps. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include "window.h" #define circle_width 8 #define circle_height 8 static char circle_bits[] = { 0x00, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x00}; #define graph_width 16 #define graph_height 8 static char graph_bits[] = { 0x00, 0x00, 0x42, 0x00, 0xa2, 0x41, 0x12, 0x22, 0x0e, 0x1c, 0x02, 0x00, 0xfe, 0x7f, 0x00, 0x00}; #define text_width 16 #define text_height 8 static char text_bits[] = { 0x00, 0x00, 0xcc, 0x31, 0x52, 0x4a, 0xd2, 0x09, 0x5e, 0x0a, 0x52, 0x4a, 0xd2, 0x31, 0x00, 0x00}; #define bar_width 16 #define bar_height 8 static char bar_bits[] = { 0x01, 0x00, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0x01, 0x00, 0x49, 0x92, 0xff, 0xff}; GdkPixmap *CircleBitmap; GdkPixmap *GraphBitmap; GdkPixmap *TextBitmap; GdkPixmap *BarBitmap; /*++++++++++++++++++++++++++++++++++++++ Initialise the Bitmaps. GtkWidget *w A window to start with. ++++++++++++++++++++++++++++++++++++++*/ void CreateBitmaps(GtkWidget *w) { CircleBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,circle_bits,circle_width,circle_height); GraphBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,graph_bits,graph_width,graph_height); TextBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,text_bits,text_width,text_height); BarBitmap=gdk_bitmap_create_from_data(GTK_WIDGET(w)->window,bar_bits,bar_width,bar_height); } procmeter3-3.5d/gtk2/menus.c000066400000000000000000000556131165060751200157670ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/menus.c,v 1.2 2009-12-07 20:01:04 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5c. X Window menus (GTK version). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2009 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include "window.h" #include "procmeterp.h" /*+ The orientation of the windows. +*/ extern int vertical; /*+ The pane that contains all of the outputs. +*/ extern GtkWidget *pane; /* Local functions */ static void MenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void ModuleMenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void OutputMenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void FunctionsMenuStart(GtkWidget *w,GdkEvent *event,gpointer data); static void SelectOutputMenuCallback(gpointer clientData); static void SelectFunctionsMenuCallback(gpointer clientData); static void PropertiesDialogDoneCallback(GtkWidget *w,gpointer data); static gint PropertiesDialogCloseCallback(GtkWidget *w,GdkEvent *event,gpointer data); /* Menu widgets */ static GtkWidget *module_menu; static GtkWidget *functions_menu,*properties_dialog; static GtkWidget *func_run; static GtkWidget *prop_modname,*prop_moddesc, *prop_outname,*prop_outdesc, *prop_label,*prop_type,*prop_interval,*prop_scale; static GtkTextBuffer *prop_moddesc_text,*prop_outdesc_text; static gboolean properties_popped_up=FALSE; static gint doing_move=0; /*+ The output that was used for the Functions menu. +*/ static Output function_output; /*++++++++++++++++++++++++++++++++++++++ Initialise the menus. GtkWidget *parent The parent widget that the menu belongs to. ++++++++++++++++++++++++++++++++++++++*/ void CreateMenus(GtkWidget *parent) { GtkWidget *menulabel; GtkWidget *menuline; GtkWidget *func_prop,*func_above,*func_below,*func_delete; GtkWidget *prop_form,*prop_form1,*prop_form2, *prop_modlabel,*prop_outlabel, *prop_lbllabel,*prop_typlabel,*prop_intlabel,*prop_scllabel, *prop_done; // char *string; /* Sort out the resources in advance. */ // if((string=GetProcMeterRC("resources","menu-foreground"))) // {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} // // if((string=GetProcMeterRC("resources","menu-background"))) // {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} // // if((string=GetProcMeterRC("resources","menu-font"))) // {XtSetArg(args[nargs],XtNfont,StringToFont(string));nargs++;} /* The module menu */ module_menu=gtk_menu_new(); menulabel=gtk_menu_item_new_with_label("Modules"); gtk_widget_set_sensitive(GTK_WIDGET(menulabel),FALSE); gtk_menu_append(GTK_MENU(module_menu),menulabel); gtk_widget_show(GTK_WIDGET(menulabel)); menuline=gtk_menu_item_new(); gtk_menu_append(GTK_MENU(module_menu),menuline); gtk_widget_show(GTK_WIDGET(menuline)); /* The functions menu */ functions_menu=gtk_menu_new(); menulabel=gtk_menu_item_new_with_label("Functions"); gtk_widget_set_sensitive(GTK_WIDGET(menulabel),FALSE); gtk_menu_append(GTK_MENU(functions_menu),menulabel); gtk_widget_show(GTK_WIDGET(menulabel)); menuline=gtk_menu_item_new(); gtk_menu_append(GTK_MENU(functions_menu),menuline); gtk_widget_show(GTK_WIDGET(menuline)); /* The functions menu items */ func_prop=gtk_menu_item_new_with_label("Properties"); gtk_menu_append(GTK_MENU(functions_menu),func_prop); gtk_widget_show(GTK_WIDGET(func_prop)); gtk_signal_connect_object(GTK_OBJECT(func_prop),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)0); func_above=gtk_menu_item_new_with_label(vertical?"Move To Above":"Move To Left Of"); gtk_menu_append(GTK_MENU(functions_menu),func_above); gtk_widget_show(GTK_WIDGET(func_above)); gtk_signal_connect_object(GTK_OBJECT(func_above),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)1); func_below=gtk_menu_item_new_with_label(vertical?"Move To Below":"Move To Right Of"); gtk_menu_append(GTK_MENU(functions_menu),func_below); gtk_widget_show(GTK_WIDGET(func_below)); gtk_signal_connect_object(GTK_OBJECT(func_below),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)2); func_delete=gtk_menu_item_new_with_label("Delete"); gtk_menu_append(GTK_MENU(functions_menu),func_delete); gtk_widget_show(GTK_WIDGET(func_delete)); gtk_signal_connect_object(GTK_OBJECT(func_delete),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)3); func_run=gtk_menu_item_new_with_label("Run"); gtk_menu_append(GTK_MENU(functions_menu),func_run); gtk_widget_show(GTK_WIDGET(func_run)); gtk_signal_connect_object(GTK_OBJECT(func_run),"activate", GTK_SIGNAL_FUNC(SelectFunctionsMenuCallback),(gpointer)4); /* The properties_dialog */ properties_dialog=gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(properties_dialog),"ProcMeter Properties"); gtk_widget_set_usize(GTK_WIDGET(properties_dialog),300,400); /* The properties dialog elements. */ prop_form=gtk_hbox_new(FALSE,0); prop_modlabel=gtk_label_new("Module: "); gtk_label_set_justify(GTK_LABEL(prop_modlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_modlabel,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_modlabel)); prop_modname=gtk_label_new("NNNNNNNNNNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_modname),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_modname,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_modname)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_form,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_form)); prop_moddesc=gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(prop_moddesc),FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(prop_moddesc),GTK_WRAP_WORD); prop_moddesc_text=gtk_text_buffer_new(NULL); gtk_text_view_set_buffer(GTK_TEXT_VIEW(prop_moddesc),GTK_TEXT_BUFFER(prop_moddesc_text)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_moddesc,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(prop_moddesc),250,100); gtk_widget_show(GTK_WIDGET(prop_moddesc)); prop_form=gtk_hbox_new(FALSE,0); prop_outlabel=gtk_label_new("Output: "); gtk_label_set_justify(GTK_LABEL(prop_outlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_outlabel,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_outlabel)); prop_outname=gtk_label_new("NNNNNNNNNNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_outname),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form),prop_outname,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_outname)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_form,FALSE,FALSE,0); gtk_widget_show(GTK_WIDGET(prop_form)); prop_outdesc=gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(prop_outdesc),FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(prop_outdesc),GTK_WRAP_WORD); prop_outdesc_text=gtk_text_buffer_new(NULL); gtk_text_view_set_buffer(GTK_TEXT_VIEW(prop_outdesc),GTK_TEXT_BUFFER(prop_outdesc_text)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_outdesc,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(prop_outdesc),250,100); gtk_widget_show(GTK_WIDGET(prop_outdesc)); prop_form=gtk_hbox_new(FALSE,0); prop_form1=gtk_vbox_new(TRUE,0); prop_lbllabel=gtk_label_new("Label:"); gtk_label_set_justify(GTK_LABEL(prop_lbllabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_lbllabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_lbllabel)); prop_typlabel=gtk_label_new("Type:"); gtk_label_set_justify(GTK_LABEL(prop_typlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_typlabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_typlabel)); prop_intlabel=gtk_label_new("Interval:"); gtk_label_set_justify(GTK_LABEL(prop_intlabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_intlabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_intlabel)); prop_scllabel=gtk_label_new("Grid Spacing:"); gtk_label_set_justify(GTK_LABEL(prop_scllabel),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form1),prop_scllabel,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_scllabel)); gtk_box_pack_start(GTK_BOX(prop_form),prop_form1,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_form1)); prop_form2=gtk_vbox_new(TRUE,0); prop_label=gtk_label_new("NNNNNNNNNNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_label),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_label,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_label)); prop_type=gtk_label_new("NNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_type),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_type,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_type)); prop_interval=gtk_label_new("NNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_interval),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_interval,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_interval)); prop_scale=gtk_label_new("NNNNNNN"); gtk_label_set_justify(GTK_LABEL(prop_scale),GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(prop_form2),prop_scale,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_scale)); gtk_box_pack_start(GTK_BOX(prop_form),prop_form2,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_form2)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->vbox),prop_form,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_form)); prop_done=gtk_button_new_with_label("Done"); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(properties_dialog)->action_area),prop_done,TRUE,TRUE,0); gtk_widget_show(GTK_WIDGET(prop_done)); gtk_signal_connect_object(GTK_OBJECT(prop_done),"clicked", GTK_SIGNAL_FUNC(PropertiesDialogDoneCallback),NULL); /* Fixup the properties dialog box */ gtk_signal_connect_object(GTK_OBJECT(properties_dialog),"delete_event", GTK_SIGNAL_FUNC(PropertiesDialogCloseCallback),NULL); } /*++++++++++++++++++++++++++++++++++++++ Add a specified module to the menus. Module module The module to add. ++++++++++++++++++++++++++++++++++++++*/ void AddModuleToMenu(Module module) { int i; GtkWidget *menulabel,*menuline,*submenu=NULL,*menuitem=NULL; ProcMeterOutput *prevoutput=NULL; char *string; /* Return if pane widget is not initialised (e.g. gprocmeter3 -h). */ if(!pane) return; /* Sort out the resources in advance. */ // if(((string=GetProcMeterRC(module->module->name,"menu-foreground")) || // (string=GetProcMeterRC("resources","menu-foreground")))) // {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} // // if(((string=GetProcMeterRC(module->module->name,"menu-background")) || // (string=GetProcMeterRC("resources","menu-background")))) // {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} // // if(((string=GetProcMeterRC(module->module->name,"menu-font")) || // (string=GetProcMeterRC("resources","menu-font")))) // {XtSetArg(args[nargs],XtNfont,StringToFont(string));nargs++;} /* Create a new menu. */ module->submenu_widget=gtk_menu_new(); menulabel=gtk_menu_item_new_with_label(module->module->name); gtk_widget_set_sensitive(GTK_WIDGET(menulabel),FALSE); gtk_menu_append(GTK_MENU(module->submenu_widget),menulabel); gtk_widget_show(GTK_WIDGET(menulabel)); menuline=gtk_menu_item_new(); gtk_menu_append(GTK_MENU(module->submenu_widget),menuline); gtk_widget_show(GTK_WIDGET(menuline)); /* Add an entry to the module menu */ module->menu_item_widget=gtk_menu_item_new_with_label(module->module->name); gtk_menu_append(GTK_MENU(module_menu),module->menu_item_widget); gtk_widget_show(GTK_WIDGET(module->menu_item_widget)); gtk_menu_item_set_submenu(GTK_MENU_ITEM(module->menu_item_widget),module->submenu_widget); /* Add entries to it for each output. */ for(i=0;module->outputs[i];i++) { GtkWidget *sme; // GdkPixmap *bitmap=CircleBitmap; if(module->outputs[i]->output!=prevoutput) { menuitem=gtk_menu_item_new_with_label(module->outputs[i]->output->name); gtk_menu_append(GTK_MENU(module->submenu_widget),menuitem); gtk_widget_show(GTK_WIDGET(menuitem)); // if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-foreground")) || // (string=GetProcMeterRC(module->module->name,"menu-foreground")) || // (string=GetProcMeterRC("resources","menu-foreground")))) // XtVaSetValues(menuitem,XtNforeground,StringToPixel(string),NULL); // // if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-font")) || // (string=GetProcMeterRC(module->module->name,"menu-font")) || // (string=GetProcMeterRC("resources","menu-font")))) // XtVaSetValues(menuitem,XtNfont,StringToFont(string),NULL); submenu=gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem),submenu); prevoutput=module->outputs[i]->output; } // if(module->outputs[i]->type==PROCMETER_GRAPH) // bitmap=GraphBitmap; // else if(module->outputs[i]->type==PROCMETER_TEXT) // bitmap=TextBitmap; // else if(module->outputs[i]->type==PROCMETER_BAR) // bitmap=BarBitmap; string=""; if(module->outputs[i]->type==PROCMETER_GRAPH) string="Graph"; else if(module->outputs[i]->type==PROCMETER_TEXT) string="Text"; else if(module->outputs[i]->type==PROCMETER_BAR) string="Bar"; sme=gtk_check_menu_item_new_with_label(string); gtk_menu_append(GTK_MENU(submenu),sme); gtk_widget_show(GTK_WIDGET(sme)); gtk_signal_connect_object(GTK_OBJECT(sme),"activate", GTK_SIGNAL_FUNC(SelectOutputMenuCallback),(gpointer)module->outputs[i]); // if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-foreground")) || // (string=GetProcMeterRC(module->module->name,"menu-foreground")) || // (string=GetProcMeterRC("resources","menu-foreground")))) // XtVaSetValues(sme,XtNforeground,StringToPixel(string),NULL); module->outputs[i]->menu_item_widget=sme; module->outputs[i]->output_widget=NULL; } } /*++++++++++++++++++++++++++++++++++++++ Add the menus to the right mouse button of the output. GtkWidget *widget The widget itself. Module module The module that this widget belongs to. ++++++++++++++++++++++++++++++++++++++*/ void AddMenuToOutput(GtkWidget *widget,Module module) { /* Return if pane widget is not initialised (e.g. gprocmeter3 -h). */ if(!pane) return; gtk_signal_connect(GTK_OBJECT(widget),"button_press_event", GTK_SIGNAL_FUNC(MenuStart),module?module->module->name:NULL); } /*++++++++++++++++++++++++++++++++++++++ Remove a specified module from the menus. Module module The module to remove. ++++++++++++++++++++++++++++++++++++++*/ void RemoveModuleFromMenu(Module module) { /* Return if pane widget is not initialised (e.g. gprocmeter3 -h). */ if(!pane) return; gtk_widget_destroy(GTK_WIDGET(module->submenu_widget)); gtk_object_destroy(GTK_OBJECT(module->menu_item_widget)); } /*++++++++++++++++++++++++++++++++++++++ Destroy all of the menus. ++++++++++++++++++++++++++++++++++++++*/ void DestroyMenus(void) { gtk_widget_destroy(GTK_WIDGET(module_menu)); gtk_widget_destroy(GTK_WIDGET(functions_menu)); gtk_widget_destroy(GTK_WIDGET(properties_dialog)); } /*++++++++++++++++++++++++++++++++++++++ The callback that is called by the output being selected on the output menu. gpointer clientData The client data from the callback. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void SelectOutputMenuCallback(gpointer clientData) { Output output=(Output)clientData; AddRemoveOutput(output); } /*++++++++++++++++++++++++++++++++++++++ The callback that is called by the output being selected on the output menu. gpointer clientData The client data from the callback. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void SelectFunctionsMenuCallback(gpointer clientData) { if(clientData==(gpointer)0) /* Properties */ { gtk_widget_show(GTK_WIDGET(properties_dialog)); properties_popped_up=TRUE; } else if(clientData==(gpointer)1 || clientData==(gpointer)2) /* Above / Below */ { doing_move=(glong)clientData; gdk_pointer_grab(GTK_WIDGET(pane)->window,TRUE,GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK,NULL,gdk_cursor_new(GDK_HAND1),GDK_CURRENT_TIME); } else if(clientData==(gpointer)3) /* Delete */ { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(function_output->menu_item_widget),FALSE); } else if(clientData==(gpointer)4) /* Run */ { if(function_output->menu_run.flag) RunProgram(&function_output->menu_run); } } /*++++++++++++++++++++++++++++++++++++++ The callback for the done button on the properties dialog box. GtkWidget *w The widget that the callback came from. gpointer data The data from the callback. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void PropertiesDialogDoneCallback(GtkWidget *w,gpointer data) { gtk_widget_hide(GTK_WIDGET(properties_dialog)); properties_popped_up=FALSE; } /*++++++++++++++++++++++++++++++++++++++ The callback for the window manager close on the dialog. GtkWidget *w The widget that caused the event. GdkEvent *event The event information. gpointer data Not used. This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static gint PropertiesDialogCloseCallback(GtkWidget *w,GdkEvent *event,gpointer data) { gtk_widget_hide(GTK_WIDGET(properties_dialog)); properties_popped_up=FALSE; return(TRUE); } /*++++++++++++++++++++++++++++++++++++++ Start one of the popup menus. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void MenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { if(event->type!=GDK_BUTTON_PRESS) return; if(event->button.button==1 && data) FunctionsMenuStart(w,event,data); else if(event->button.button==2 && data) OutputMenuStart(w,event,data); else if(event->button.button==3) ModuleMenuStart(w,event,data); } /*++++++++++++++++++++++++++++++++++++++ Start the Module menu. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void ModuleMenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { gtk_menu_popup(GTK_MENU(module_menu),NULL,NULL,NULL,NULL,event->button.button,event->button.time); } /*++++++++++++++++++++++++++++++++++++++ Start one of the Output menus. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void OutputMenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { static Module *modulep=NULL; for(modulep=Modules;*modulep;modulep++) if(!strcmp((*modulep)->module->name,data)) gtk_menu_popup(GTK_MENU((*modulep)->submenu_widget),NULL,NULL,NULL,NULL,event->button.button,event->button.time); } /*++++++++++++++++++++++++++++++++++++++ Start the properties menu. GtkWidget *w The widget that caused it. GdkEvent *event The event that caused it. gpointer data The name of the module (or NULL for the pane). This function is only ever called from the GTK event loop. ++++++++++++++++++++++++++++++++++++++*/ static void FunctionsMenuStart(GtkWidget *w,GdkEvent *event,gpointer data) { static Output *outputp=NULL; static Module *modulep=NULL; char string[24]; for(modulep=Modules;*modulep;modulep++) if(!strcmp((*modulep)->module->name,data)) { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(w==(*outputp)->output_widget) break; break; } if(doing_move) { gdk_pointer_ungrab(GDK_CURRENT_TIME); MoveOutput(function_output,*outputp,doing_move); doing_move=0; return; } if(!*modulep || !*outputp) return; function_output=*outputp; if((*outputp)->menu_run.flag) { char *r=(*outputp)->menu_run.command; strncpy(string,"Run '",16); strncpy(string+5,r,8); if(strlen(r)>8) strcat(string," ...'"); else strcat(string,"'"); // XtVaSetValues(func_run,XtNlabel,string,NULL); gtk_widget_set_sensitive(GTK_WIDGET(func_run),TRUE); } else { // XtVaSetValues(func_run,XtNlabel,"Run",NULL); gtk_widget_set_sensitive(GTK_WIDGET(func_run),FALSE); } /* Set up the properties window. */ gtk_label_set_text(GTK_LABEL(prop_modname),(*modulep)->module->name); gtk_text_buffer_set_text(GTK_TEXT_BUFFER(prop_moddesc_text), (*modulep)->module->description,strlen((*modulep)->module->description)); gtk_label_set_text(GTK_LABEL(prop_outname),(*outputp)->output->name); gtk_text_buffer_set_text(GTK_TEXT_BUFFER(prop_outdesc_text), (*modulep)->module->description,strlen((*modulep)->module->description)); gtk_label_set_text(GTK_LABEL(prop_label),(*outputp)->label); if((*outputp)->type==PROCMETER_GRAPH) gtk_label_set_text(GTK_LABEL(prop_type),"Graph"); else if((*outputp)->type==PROCMETER_TEXT) gtk_label_set_text(GTK_LABEL(prop_type),"Text"); else if((*outputp)->type==PROCMETER_BAR) gtk_label_set_text(GTK_LABEL(prop_type),"Bar"); if((*outputp)->output->interval) sprintf(string,"%d s",(*outputp)->output->interval); else strcpy(string,"Never"); gtk_label_set_text(GTK_LABEL(prop_interval),string); if((*outputp)->type&(PROCMETER_GRAPH|PROCMETER_BAR)) { char str[PROCMETER_UNITS_LEN+1]; snprintf(str,PROCMETER_UNITS_LEN+1,(*outputp)->output->graph_units,(*outputp)->output->graph_scale); if(*str=='(') strcpy(string,str+1); else strcpy(string,str); if(string[strlen(string)-1]==')') string[strlen(string)-1]=0; gtk_label_set_text(GTK_LABEL(prop_scale),string); } else { gtk_label_set_text(GTK_LABEL(prop_scale),"n/a"); } if(!properties_popped_up) gtk_menu_popup(GTK_MENU(functions_menu),NULL,NULL,NULL,NULL,event->button.button,event->button.time); } procmeter3-3.5d/gtk2/resources.c000066400000000000000000000047301165060751200166440ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/resources.c,v 1.1 2007-09-19 19:06:43 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3. X Window resource conversions. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include "window.h" #include "procmeterp.h" /*++++++++++++++++++++++++++++++++++++++ Convert a string to a font structure. GdkFont *StringToFont Returns a pointer to a font structure. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ GdkFont *StringToFont(char *string) { return(gdk_font_load(string)); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a pixel. GdkColor StringToPixel Returns a GdkColor value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ GdkColor StringToPixel(char *string) { static GdkColor color; gdk_color_parse(string,&color); gdk_colormap_alloc_color(gdk_colormap_get_system(),&color,FALSE,TRUE); return(color); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a Boolean. gboolean StringToBoolean Returns a Boolean value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ gboolean StringToBoolean(char *string) { gboolean b; if(!strcasecmp(string,"true") || !strcasecmp(string,"yes") || !strcasecmp(string,"1")) b=TRUE; else b=FALSE; return(b); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to an integer int StringToInt Returns an integer value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ int StringToInt(char *string) { int i; if(sscanf(string,"%d",&i)!=1) i=0; return(i); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a label position. int StringToLabelPosition Returns an integer value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ int StringToLabelPosition(char *string) { int i; if(!strcasecmp(string,"top")) i=1; else if(!strcasecmp(string,"bottom")) i=-1; else i=0; return(i); } procmeter3-3.5d/gtk2/run.c000066400000000000000000000072121165060751200154340ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/run.c,v 1.2 2010-02-28 10:22:03 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. Run external programs. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1999-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include "procmeterp.h" /*+ The toplevel widget. +*/ extern GtkWidget *toplevel; /*++++++++++++++++++++++++++++++++++++++ Parse the command from the config file to be run. char *string The string to be parsed. RunOption *run Contains the parsed result. ++++++++++++++++++++++++++++++++++++++*/ void ParseRunCommand(char *string,RunOption *run) { int offset; char *l,*r; run->flag=RUN_NONE; run->command=NULL; if(!string) return; if(!strncmp("XBeep",string,5)) {offset=5; run->flag=RUN_XBELL;} else if(!strncmp("Shell",string,5)) {offset=5; run->flag=RUN_SHELL;} else if(!strncmp("XTermWait",string,9)) {offset=9; run->flag=RUN_XTERM_WAIT;} else if(!strncmp("XTerm",string,5)) {offset=5; run->flag=RUN_XTERM;} else {offset=0; run->flag=RUN_SHELL;} l=string+offset; r=string+strlen(string)-1; while(isspace(*l)) l++; if(offset && *l!='(') { fprintf(stderr,"ProcMeter: Cannot parse run command '%s'\n",string); run->flag=RUN_NONE; return; } else if(offset) l++; while(isspace(*l)) l++; while(isspace(*r)) r--; if(offset && *r!=')') { fprintf(stderr,"ProcMeter: Cannot parse run command '%s'\n",string); run->flag=RUN_NONE; return; } else if(offset) r--; while(isspace(*r)) r--; if(rcommand=(char*)malloc(r-l+2); strncpy(run->command,l,r-l+1); *(run->command+(r-l)+1)=0; } /*++++++++++++++++++++++++++++++++++++++ Run a program. RunOption *run The information about the program to run. ++++++++++++++++++++++++++++++++++++++*/ void RunProgram(RunOption *run) { if(run->flag==RUN_NONE || !run->command) return; if(run->flag==RUN_XBELL) XBell(GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(toplevel)),0); else { pid_t pid=fork(); if(pid==-1) fprintf(stderr,"ProcMeter: Cannot fork child process %s\n",strerror(errno)); else if(pid==0) { char *string,*displayname,*displayenv; displayname=XDisplayString(GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(toplevel))); displayenv=(char*)malloc(strlen(displayname)+10); sprintf(displayenv,"DISPLAY=%s",displayname); putenv(displayenv); /* close the X connection */ close(ConnectionNumber(gtk_widget_get_display(toplevel))); switch(run->flag) { default: case RUN_SHELL: execl("/bin/sh","/bin/sh","-c",run->command,NULL); break; case RUN_XTERM: execlp("xterm","xterm","-title","ProcMeter3","-e","/bin/sh","-c",run->command,NULL); break; case RUN_XTERM_WAIT: string=(char*)malloc(strlen(run->command)+64); sprintf(string,"( %s ) ; echo -n 'Press Return to exit' ; read x",run->command); execlp("xterm","xterm","-title","ProcMeter3","-e","/bin/sh","-c",string,NULL); break; } /* Never reached */ exit(1); } } } procmeter3-3.5d/gtk2/widgets/000077500000000000000000000000001165060751200161305ustar00rootroot00000000000000procmeter3-3.5d/gtk2/widgets/Makefile000066400000000000000000000022111165060751200175640ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/gtk2/widgets/Makefile,v 1.1 2007-09-19 19:03:46 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.5. # # Makefile for gtk2 widgets. # # Written by Andrew M. Bishop # # This file Copyright 1998-2007 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options (overridden by main Makefile) CFLAGS=-g -O2 -Wall X_CFLAGS=`pkg-config --cflags gtk+-2.0` # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) ######## all : $(OBJ) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(X_CFLAGS) -I../.. PMGeneric.o : PMGeneric.c PMGeneric.h PMGraph.o : PMGraph.c PMGraph.h PMGeneric.h ../../procmeter.h PMText.o : PMText.c PMText.h PMGeneric.h PMBar.o : PMBar.c PMBar.h PMGeneric.h ../../procmeter.h SubMenus.o : SubMenus.c SubMenus.h ######## .PHONY : clean clean : -rm -f *.o *~ core ######## .PHONY : install install : procmeter3-3.5d/gtk2/widgets/PMBar.c000066400000000000000000000351031165060751200172370ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMBar.c,v 1.3 2008-04-27 15:21:30 amb Exp $ ProcMeter Bar Widget Source file (for ProcMeter3 3.5b). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" #include "PMBar.h" #include "procmeter.h" static void procmeterbar_class_init(ProcMeterBarClass *class); static void procmeterbar_init(ProcMeterBar *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void BarResize(ProcMeterBar *pmw); static void BarUpdate(ProcMeterBar *pmw,gboolean all); static char *empty_string=""; static ProcMeterGenericClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint gtk_procmeterbar_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmeterbar_get_type(void) { static guint pmw_type = 0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterBar", sizeof(ProcMeterBar), sizeof(ProcMeterBarClass), (GtkClassInitFunc) procmeterbar_class_init, (GtkObjectInitFunc) procmeterbar_init, (gpointer) NULL, (gpointer) NULL, (GtkClassInitFunc) NULL}; pmw_type=gtk_type_unique(gtk_procmetergeneric_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterBarClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmeterbar_class_init(ProcMeterBarClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=BarResize; class->update=BarUpdate; parent_class=gtk_type_class(gtk_procmetergeneric_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterBar *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmeterbar_init(ProcMeterBar *pmw) { int i; g_return_if_fail(pmw!=NULL); /* The grid parts. */ pmw->grid_units=empty_string; pmw->grid_gc=NULL; pmw->grid_drawn=1; pmw->grid_min=1; pmw->grid_max=0; pmw->grid_num=pmw->grid_min; /* The data parts. */ for(i=0;idata)/sizeof(pmw->data[0]);i++) pmw->data[i]=0; pmw->data_index=0; pmw->data_sum=0; /* The rest of the sizing. */ BarResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmeterbar_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmeterbar_new(void) { ProcMeterBar *pmw; pmw=gtk_type_new(gtk_procmeterbar_get_type()); return(GTK_WIDGET(pmw)); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterBar *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(object)); pmw=GTK_PROCMETERBAR(object); if(pmw->grid_gc) { gdk_gc_destroy(pmw->grid_gc); pmw->grid_gc=NULL; } if(pmw->grid_units!=empty_string) { free(pmw->grid_units); pmw->grid_units=empty_string; } if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterBar *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERBAR(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->generic.body_bg_set) gdk_window_set_background(widget->window,&pmw->generic.body_bg_color); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterBar *pmw; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERBAR(widget); requisition->height=20+pmw->generic.label_height; requisition->width=50; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERBAR(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterBar *pmw=GTK_PROCMETERBAR(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); BarResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Bar Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterBar *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERBAR(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERBAR(widget); BarUpdate(pmw,TRUE); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterBar *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void BarResize(ProcMeterBar *pmw) { GdkFont *label_font; g_return_if_fail(pmw!=NULL); (parent_class->resize)(&pmw->generic); pmw->generic.label_x=2; /* The grid parts. */ label_font=pmw->generic.label_font?pmw->generic.label_font:gtk_style_get_font(pmw->generic.widget.style); pmw->grid_units_x=pmw->generic.widget.allocation.width-gdk_string_width(label_font,pmw->grid_units); pmw->grid_maxvis=pmw->generic.widget.allocation.width/3; if(pmw->generic.label_pos==ProcMeterLabelTop) pmw->generic.body_start=pmw->generic.label_height; else pmw->generic.body_start=0; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterBar *pmw The Widget to update. gboolean all Indicates if it all is to be updated including the generic parts. ++++++++++++++++++++++++++++++++++++++*/ static void BarUpdate(ProcMeterBar *pmw,gboolean all) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->generic.widget)) { GdkGC *grid_gc=pmw->grid_gc?pmw->grid_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkGC *body_gc=pmw->generic.body_gc?pmw->generic.body_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkFont *label_font=pmw->generic.label_font?pmw->generic.label_font:gtk_style_get_font(pmw->generic.widget.style); int i; int scale=PROCMETER_GRAPH_SCALE*pmw->grid_num; gshort pos; gshort top_average_bottom,bottom_average_top,average_size; if(all) { (parent_class->update)(&pmw->generic); if(pmw->generic.label_pos!=ProcMeterLabelNone) gdk_draw_string(pmw->generic.widget.window,label_font,pmw->generic.label_gc, pmw->grid_units_x,pmw->generic.label_y, pmw->grid_units); } else gdk_window_clear_area(pmw->generic.widget.window, 0,pmw->generic.body_start, pmw->generic.widget.allocation.width,pmw->generic.body_height); pos=pmw->data_sum*pmw->generic.widget.allocation.width/(scale*2); top_average_bottom=pmw->generic.body_start+2*(pmw->generic.body_height>>3); bottom_average_top=pmw->generic.body_start+pmw->generic.body_height-2*(pmw->generic.body_height>>3); average_size=pmw->generic.body_height>>3; gdk_draw_rectangle(pmw->generic.widget.window,body_gc,1, pos-average_size,top_average_bottom-average_size, average_size ,average_size); gdk_draw_rectangle(pmw->generic.widget.window,body_gc,1, pos-average_size,bottom_average_top, average_size ,average_size); pos=pmw->data[pmw->data_index]*pmw->generic.widget.allocation.width/scale; gdk_draw_rectangle(pmw->generic.widget.window,body_gc,1, 0 ,top_average_bottom+1, pos,bottom_average_top-top_average_bottom-2); if(pmw->grid_drawn==1) for(i=1;igrid_num;i++) { pos=i*pmw->generic.widget.allocation.width/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, pos,pmw->generic.body_start, pos,pmw->generic.body_height+pmw->generic.body_start); } else if(pmw->grid_drawn==-1) { pos=pmw->grid_maxvis*pmw->generic.widget.allocation.width/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, pos,pmw->generic.body_start, pos,pmw->generic.body_height+pmw->generic.body_start); } } } /*++++++++++++++++++++++++++++++++++++++ Set the grid colour of the Widget. ProcMeterBar *pmw The widget to set. GdkColor grid_color The grid. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridColour(ProcMeterBar *pmw,GdkColor grid_color) { pmw->grid_color=grid_color; if(pmw->grid_gc) gdk_gc_set_foreground(pmw->grid_gc,&pmw->grid_color); else { GdkGCValues values; values.foreground=pmw->grid_color; pmw->grid_gc=gdk_gc_new_with_values(pmw->generic.widget.parent->window,&values,GDK_GC_FOREGROUND); } BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the minimum number of grid lines in the Widget. ProcMeterBar *pmw The Widget to set. gint grid_min The minimum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridMin(ProcMeterBar *pmw,gint grid_min) { if(grid_min<0) { pmw->grid_min=-grid_min; pmw->grid_drawn=0; } else if(grid_min>0) { pmw->grid_min=grid_min; pmw->grid_drawn=1; } else /* if(grid_min==0) */ { pmw->grid_min=1; pmw->grid_drawn=1; } if(grid_min>pmw->grid_max && pmw->grid_max) pmw->grid_min=pmw->grid_max; if(pmw->grid_min>=pmw->grid_num) pmw->grid_num=pmw->grid_min; BarResize(pmw); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the maximum number of grid lines in the Widget. ProcMeterBar *pmw The Widget to set. gint grid_max The maximum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridMax(ProcMeterBar *pmw,gint grid_max) { if(grid_max<0) pmw->grid_max=0; else pmw->grid_max=grid_max; if(grid_max && grid_maxgrid_min) pmw->grid_max=pmw->grid_min; BarResize(pmw); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the grid units for the widget ProcMeterBar *pmw The widget to set. gchar *units The grid units. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarSetGridUnits(ProcMeterBar *pmw,gchar *units) { if(pmw->grid_units!=empty_string) free(pmw->grid_units); pmw->grid_units=(char*)malloc(strlen(units)+1); strcpy(pmw->grid_units,units); BarResize(pmw); BarUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Add a data point to the ProcMeter Bar Widget. ProcMeterBar *pmw The ProcMeter Bar Widget. gushort datum The data point to add. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarAddDatum(ProcMeterBar *pmw,gushort datum) { int new_grid_num; gushort old_datum; pmw->data_index++; if(pmw->data_index==8) pmw->data_index=0; old_datum=pmw->data[pmw->data_index]; pmw->data[pmw->data_index]=datum; pmw->data_sum=(pmw->data_sum>>1)+datum-(old_datum>>8); if((pmw->data_sum/2)>datum) new_grid_num=((pmw->data_sum/2)+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; else new_grid_num=(datum+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numgrid_min) new_grid_num=pmw->grid_min; if(pmw->grid_max && new_grid_num>pmw->grid_max) new_grid_num=pmw->grid_max; if(new_grid_num!=pmw->grid_num) { pmw->grid_num=new_grid_num; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; } BarUpdate(pmw,TRUE); } procmeter3-3.5d/gtk2/widgets/PMBar.h000066400000000000000000000053771165060751200172560ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMBar.h,v 1.1 2007-09-19 19:04:34 amb Exp $ ProcMeter Bar Widget include file (for ProcMeter3 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMBAR_H #define PMBAR_H /*+ To stop multiple inclusions. +*/ #include #include #include "PMGeneric.h" #define GTK_TYPE_PROCMETERBAR (gtk_procmeterbar_get_type()) #define GTK_PROCMETERBAR(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERBAR,ProcMeterBar) #define GTK_PROCMETERBAR_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERBAR,ProcMeterBarClass) #define GTK_IS_PROCMETERBAR(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERBAR) typedef struct _ProcMeterBar ProcMeterBar; typedef struct _ProcMeterBarClass ProcMeterBarClass; struct _ProcMeterBar { ProcMeterGeneric generic; gchar* grid_units; /*+ The number of things per grid line. +*/ gushort grid_units_x; /*+ The position of the grid units. +*/ GdkColor grid_color; /*+ The grid lines colour. +*/ GdkGC* grid_gc; /*+ The graphics context for the grid lines. +*/ gint grid_min; /*+ The minimum number of grid lines. +*/ gint grid_max; /*+ The maximum number of grid lines. +*/ gint grid_maxvis; /*+ The maximum number of grid lines before removing them. +*/ gint grid_drawn; /*+ If 1 then draw as normal, if 0 never draw, if -1 draw only one line. +*/ gint grid_num; /*+ The actual number of grid lines. +*/ gushort data[8]; /*+ The data for the bar. +*/ gushort data_index; /*+ A pointer into the array +*/ gulong data_sum; /*+ The average value of the last 10 data points. +*/ }; struct _ProcMeterBarClass { ProcMeterGenericClass parent_class; void (*resize)(ProcMeterBar *pmw); void (*update)(ProcMeterBar *pmw,gboolean all); }; guint gtk_procmeterbar_get_type(void); GtkWidget* gtk_procmeterbar_new(void); /* Public functions */ void ProcMeterBarSetGridColour(ProcMeterBar *pmw,GdkColor grid_color); void ProcMeterBarSetGridMin(ProcMeterBar *pmw,gint grid_min); void ProcMeterBarSetGridMax(ProcMeterBar *pmw,gint grid_max); void ProcMeterBarSetGridUnits(ProcMeterBar *pmw,gchar *units); void ProcMeterBarAddDatum(ProcMeterBar *pmw,gushort datum); #endif /* PMBAR_H */ procmeter3-3.5d/gtk2/widgets/PMGeneric.c000066400000000000000000000321551165060751200201130ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMGeneric.c,v 1.2 2007-11-21 19:57:18 amb Exp $ ProcMeter Generic Widget Source file (for ProcMeter 3.5a). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000,10,02,03,07 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" static void procmetergeneric_class_init(ProcMeterGenericClass *class); static void procmetergeneric_init(ProcMeterGeneric *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static void GenericResize(ProcMeterGeneric *pmw); static void GenericUpdate(ProcMeterGeneric *pmw); static char *empty_string=""; static GtkWidgetClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint procmetergeneric_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmetergeneric_get_type(void) { static guint pmw_type=0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterGeneric", sizeof(ProcMeterGeneric), sizeof(ProcMeterGenericClass), (GtkClassInitFunc)procmetergeneric_class_init, (GtkObjectInitFunc)procmetergeneric_init, (gpointer) NULL, (gpointer) NULL, (GtkClassInitFunc) NULL}; pmw_type=gtk_type_unique(gtk_widget_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterGenericClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergeneric_class_init(ProcMeterGenericClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=GenericResize; class->update=GenericUpdate; parent_class=gtk_type_class(gtk_widget_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmetergeneric_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmetergeneric_new(void) { ProcMeterGeneric *new; new=gtk_type_new(gtk_procmetergeneric_get_type()); return(GTK_WIDGET(new)); } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterGeneric *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergeneric_init(ProcMeterGeneric *pmw) { g_return_if_fail(pmw!=NULL); /* The body parts. */ pmw->body_gc=NULL; pmw->body_bg_set=FALSE; /* The label parts. */ pmw->label_pos=ProcMeterLabelBottom; pmw->label_string=empty_string; pmw->label_font=NULL; pmw->label_gc=NULL; /* The rest of the sizing. */ GenericResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterGeneric *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(object)); pmw=GTK_PROCMETERGENERIC(object); if(pmw->label_string!=empty_string) { free(pmw->label_string); pmw->label_string=empty_string; } if(pmw->body_gc) { gdk_gc_destroy(pmw->body_gc); pmw->body_gc=NULL; } if(pmw->label_gc) { gdk_gc_destroy(pmw->label_gc); pmw->label_gc=NULL; } if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterGeneric *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERGENERIC(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->body_bg_set) gdk_window_set_background(widget->window,&pmw->body_bg_color); GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterGeneric *pmw; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERGENERIC(widget); requisition->height=10+pmw->label_height; requisition->width=50; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGENERIC(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterGeneric *pmw=GTK_PROCMETERGENERIC(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); GenericResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Generic Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterGeneric *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERGENERIC(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERGENERIC(widget); GenericUpdate(pmw); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterGeneric *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void GenericResize(ProcMeterGeneric *pmw) { g_return_if_fail(pmw!=NULL); /* The label parts. */ if(pmw->label_pos) { GdkFont *label_font=pmw->label_font?pmw->label_font:gtk_style_get_font(pmw->widget.style); pmw->label_height=label_font->ascent+label_font->descent+2; pmw->label_x=(pmw->widget.allocation.width-gdk_string_width(label_font,pmw->label_string))/2; if(pmw->label_pos==ProcMeterLabelTop) pmw->label_y=pmw->label_height-1-label_font->descent; else pmw->label_y=pmw->widget.allocation.height-label_font->descent; } else { pmw->label_height=0; pmw->label_x=0; pmw->label_y=0; } /* The body parts. */ pmw->body_height=pmw->widget.allocation.height-pmw->label_height; if(pmw->label_pos==ProcMeterLabelTop) pmw->body_start=pmw->label_height; else pmw->body_start=0; } /*++++++++++++++++++++++++++++++++++++++ Update the display of the generic part of the widget. ProcMeterGeneric *pmw The Widget to update. ++++++++++++++++++++++++++++++++++++++*/ static void GenericUpdate(ProcMeterGeneric *pmw) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->widget)) { GdkFont *label_font=pmw->label_font?pmw->label_font:gtk_style_get_font(pmw->widget.style); GdkGC *label_gc=pmw->label_gc?pmw->label_gc:pmw->widget.style->fg_gc[GTK_STATE_NORMAL]; gdk_window_clear(pmw->widget.window); if(pmw->label_pos) { gdk_draw_string(pmw->widget.window,label_font,label_gc, pmw->label_x,pmw->label_y, pmw->label_string); if(pmw->label_pos==ProcMeterLabelTop) gdk_draw_line(pmw->widget.window,label_gc, 0 ,pmw->label_height-1, pmw->widget.allocation.width,pmw->label_height-1); else gdk_draw_line(pmw->widget.window,label_gc, 0 ,pmw->body_height, pmw->widget.allocation.width,pmw->body_height); } } } /*++++++++++++++++++++++++++++++++++++++ Set the body colours of the Widget. ProcMeterGeneric *pmw The widget to set. GdkColor body_bg_color The body background. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetBackgroundColour(ProcMeterGeneric *pmw,GdkColor body_bg_color) { pmw->body_bg_color=body_bg_color; pmw->body_bg_set=TRUE; if(pmw->widget.window) gdk_window_set_background(pmw->widget.window,&pmw->body_bg_color); if(pmw->body_gc) gdk_gc_set_background(pmw->body_gc,&pmw->body_bg_color); else { GdkGCValues values; values.background=pmw->body_bg_color; pmw->body_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_BACKGROUND); } if(pmw->label_gc) gdk_gc_set_background(pmw->label_gc,&pmw->body_bg_color); else { GdkGCValues values; values.background=pmw->body_bg_color; pmw->label_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_BACKGROUND); } GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the body colours of the Widget. ProcMeterGeneric *pmw The widget to set. GdkColor body_fg_color The body foreground. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetForegroundColour(ProcMeterGeneric *pmw,GdkColor body_fg_color) { pmw->body_fg_color=body_fg_color; if(pmw->body_gc) gdk_gc_set_foreground(pmw->body_gc,&pmw->body_fg_color); else { GdkGCValues values; values.foreground=pmw->body_fg_color; pmw->body_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_FOREGROUND); } GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the label colour of the Widget. ProcMeterGeneric *pmw The widget to set. GdkColor label_color The label foreground. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabelColour(ProcMeterGeneric *pmw,GdkColor label_color) { pmw->label_color=label_color; if(pmw->label_gc) gdk_gc_set_foreground(pmw->label_gc,&pmw->label_color); else { GdkGCValues values; values.foreground=pmw->label_color; pmw->label_gc=gdk_gc_new_with_values(pmw->widget.parent->window,&values,GDK_GC_FOREGROUND); } GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the label position of the Widget. ProcMeterGeneric *pmw The widget to set. int label_position The position of the label. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabelPosition(ProcMeterGeneric *pmw,int label_position) { if((label_position==ProcMeterLabelTop) || (label_position==ProcMeterLabelNone) || (label_position==ProcMeterLabelBottom)) { pmw->label_pos=label_position; GenericResize(pmw); GenericUpdate(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Set the label font for the widget ProcMeterGeneric *pmw The widget to set. GdkFont *font The font to use. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabelFont(ProcMeterGeneric *pmw,GdkFont *font) { pmw->label_font=font; GenericResize(pmw); GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Set the label for the widget ProcMeterGeneric *pmw The widget to set. gchar *label The name of the label. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGenericSetLabel(ProcMeterGeneric *pmw,gchar *label) { pmw->label_string=(char*)malloc(strlen(label)+1); strcpy(pmw->label_string,label); GenericUpdate(pmw); } procmeter3-3.5d/gtk2/widgets/PMGeneric.h000066400000000000000000000061331165060751200201150ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMGeneric.h,v 1.1 2007-09-19 19:04:59 amb Exp $ ProcMeter Generic Widget include file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGENERIC_H #define PMGENERIC_H /*+ To stop multiple inclusions. +*/ #include #include #include #define GTK_TYPE_PROCMETERGENERIC (gtk_procmetergeneric_get_type()) #define GTK_PROCMETERGENERIC(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERGENERIC,ProcMeterGeneric) #define GTK_PROCMETERGENERIC_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERGENERIC,ProcMeterGenericClass) #define GTK_IS_PROCMETERGENERIC(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERGENERIC) typedef struct _ProcMeterGeneric ProcMeterGeneric; typedef struct _ProcMeterGenericClass ProcMeterGenericClass; struct _ProcMeterGeneric { GtkWidget widget; GdkColor body_bg_color; /*+ The body background colour. +*/ gboolean body_bg_set; /*+ A flag to indicate if the background has been set. +*/ GdkColor body_fg_color; /*+ The body foreground colour. +*/ GdkGC* body_gc; /*+ The graphics context for the body. +*/ gushort body_height; /*+ The height of the body part. +*/ gushort body_start; /*+ The start position of the body part. +*/ gchar* label_string; /*+ The label for the Widget. +*/ GdkColor label_color; /*+ The label colour. +*/ GdkGC* label_gc; /*+ The graphics context for the label. +*/ gint label_pos; /*+ The position of the label. +*/ GdkFont* label_font; /*+ The font for the label. +*/ gushort label_height; /*+ The height of the label. +*/ gushort label_x,label_y; /*+ The position of the label. +*/ }; struct _ProcMeterGenericClass { GtkWidgetClass parent_class; void (*resize)(ProcMeterGeneric *pmw); void (*update)(ProcMeterGeneric *pmw); }; guint gtk_procmetergeneric_get_type(void); GtkWidget* gtk_procmetergeneric_new(void); /* The options for label placement */ #define ProcMeterLabelTop 1 #define ProcMeterLabelNone 0 #define ProcMeterLabelBottom -1 /* Public functions */ void ProcMeterGenericSetForegroundColour(ProcMeterGeneric *pmw,GdkColor body_fg_color); void ProcMeterGenericSetBackgroundColour(ProcMeterGeneric *pmw,GdkColor body_bg_color); void ProcMeterGenericSetLabelColour(ProcMeterGeneric *pmw,GdkColor label_color); void ProcMeterGenericSetLabelPosition(ProcMeterGeneric *pmw,int label_position); void ProcMeterGenericSetLabelFont(ProcMeterGeneric *pmw,GdkFont *font); void ProcMeterGenericSetLabel(ProcMeterGeneric *pmw,gchar *label); #endif /* PMGENERIC_H */ procmeter3-3.5d/gtk2/widgets/PMGraph.c000066400000000000000000000440141165060751200175750ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMGraph.c,v 1.3 2008-04-27 15:21:30 amb Exp $ ProcMeter Graph Widget Source file (for ProcMeter3 3.5b). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" #include "PMGraph.h" #include "procmeter.h" static void procmetergraph_class_init(ProcMeterGraphClass *class); static void procmetergraph_init(ProcMeterGraph *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void GraphResize(ProcMeterGraph *pmw); static void GraphUpdate(ProcMeterGraph *pmw,gboolean all); static char *empty_string=""; static ProcMeterGenericClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint gtk_procmetergraph_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmetergraph_get_type(void) { static guint pmw_type = 0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterGraph", sizeof(ProcMeterGraph), sizeof(ProcMeterGraphClass), (GtkClassInitFunc) procmetergraph_class_init, (GtkObjectInitFunc) procmetergraph_init, (gpointer) NULL, (gpointer) NULL, (GtkClassInitFunc) NULL}; pmw_type=gtk_type_unique(gtk_procmetergeneric_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterGraphClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergraph_class_init(ProcMeterGraphClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=GraphResize; class->update=GraphUpdate; parent_class=gtk_type_class(gtk_procmetergeneric_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterGraph *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetergraph_init(ProcMeterGraph *pmw) { g_return_if_fail(pmw!=NULL); /* The grid parts. */ pmw->grid_units=empty_string; pmw->grid_gc=NULL; pmw->grid_drawn=1; pmw->grid_min=1; pmw->grid_max=0; pmw->grid_num=pmw->grid_min; /* The data parts. */ pmw->data_num=10; pmw->data=(gushort*)calloc(pmw->data_num,sizeof(gushort)); pmw->data_max=0; pmw->data_index=0; /* The rest of the sizing. */ GraphResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmetergraph_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmetergraph_new(void) { ProcMeterGraph *pmw; pmw=gtk_type_new(gtk_procmetergraph_get_type()); return(GTK_WIDGET(pmw)); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterGraph *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(object)); pmw=GTK_PROCMETERGRAPH(object); if(pmw->grid_gc) { gdk_gc_destroy(pmw->grid_gc); pmw->grid_gc=NULL; } if(pmw->grid_units!=empty_string) { free(pmw->grid_units); pmw->grid_units=empty_string; } if(pmw->data) { free(pmw->data); pmw->data=NULL; } if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterGraph *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERGRAPH(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->generic.body_bg_set) gdk_window_set_background(widget->window,&pmw->generic.body_bg_color); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterGraph *pmw; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERGRAPH(widget); requisition->height=20+pmw->generic.label_height; requisition->width=50; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERGRAPH(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterGraph *pmw=GTK_PROCMETERGRAPH(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); GraphResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Graph Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterGraph *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERGRAPH(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERGRAPH(widget); GraphUpdate(pmw,TRUE); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterGraph *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void GraphResize(ProcMeterGraph *pmw) { GdkFont *label_font; g_return_if_fail(pmw!=NULL); (parent_class->resize)(&pmw->generic); if(pmw->data_num!=pmw->generic.widget.allocation.width) { int i,old_num=pmw->data_num; gushort* old_data=pmw->data; pmw->data_num=pmw->generic.widget.allocation.width; pmw->data=(gushort*)calloc(pmw->data_num,sizeof(gushort)); if(pmw->data_numdata_num; else i=old_num; for(;i>0;i--) pmw->data[(-i+pmw->data_num)%pmw->data_num]=old_data[(pmw->data_index-i+old_num)%old_num]; pmw->data_index=0; free(old_data); for(i=pmw->data_max=0;idata_num;i++) if(pmw->data[i]>pmw->data_max) pmw->data_max=pmw->data[i]; pmw->grid_num=(pmw->data_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(pmw->grid_numgrid_min) pmw->grid_num=pmw->grid_min; if(pmw->grid_max && pmw->grid_num>pmw->grid_max) pmw->grid_num=pmw->grid_max; } pmw->generic.label_x=2; /* The grid parts. */ label_font=pmw->generic.label_font?pmw->generic.label_font:gtk_style_get_font(pmw->generic.widget.style); pmw->grid_units_x=pmw->generic.widget.allocation.width-gdk_string_width(label_font,pmw->grid_units); pmw->grid_maxvis=pmw->generic.body_height/3; if(pmw->generic.label_pos==ProcMeterLabelTop) pmw->generic.body_start=pmw->generic.label_height; else pmw->generic.body_start=0; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterGraph *pmw The Widget to update. gboolean all Indicates if the whole widget is to be updated. ++++++++++++++++++++++++++++++++++++++*/ static void GraphUpdate(ProcMeterGraph *pmw,gboolean all) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->generic.widget)) { GdkGC *grid_gc=pmw->grid_gc?pmw->grid_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkGC *body_gc=pmw->generic.body_gc?pmw->generic.body_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkFont *label_font=pmw->generic.label_font?pmw->generic.label_font:gtk_style_get_font(pmw->generic.widget.style); int i; int scale=PROCMETER_GRAPH_SCALE*pmw->grid_num; gushort val; gshort pos; if(all) { (parent_class->update)(&pmw->generic); if(pmw->generic.label_pos!=ProcMeterLabelNone) gdk_draw_string(pmw->generic.widget.window,label_font,pmw->generic.label_gc, pmw->grid_units_x,pmw->generic.label_y, pmw->grid_units); for(i=0;idata_num;i++) { val=pmw->data[(i+pmw->data_index)%pmw->data_num]; pos=val*pmw->generic.body_height/scale; if(pmw->line_solid) gdk_draw_line(pmw->generic.widget.window,body_gc, i,pmw->generic.body_height+pmw->generic.body_start, i,pmw->generic.body_height+pmw->generic.body_start-pos); else if(i) { gushort oldval=pmw->data[(i-1+pmw->data_index)%pmw->data_num]; gshort oldpos=oldval*pmw->generic.body_height/scale; gdk_draw_line(pmw->generic.widget.window,body_gc, i,pmw->generic.body_height+pmw->generic.body_start-oldpos, i,pmw->generic.body_height+pmw->generic.body_start-pos); } } if(pmw->grid_drawn==1) for(i=1;igrid_num;i++) { pos=i*pmw->generic.body_height/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, 0 ,pmw->generic.body_height+pmw->generic.body_start-pos, pmw->generic.widget.allocation.width,pmw->generic.body_height+pmw->generic.body_start-pos); } else if(pmw->grid_drawn==-1) { pos=pmw->grid_maxvis*pmw->generic.body_height/pmw->grid_num; gdk_draw_line(pmw->generic.widget.window,grid_gc, 0 ,pmw->generic.body_height+pmw->generic.body_start-pos, pmw->generic.widget.allocation.width,pmw->generic.body_height+pmw->generic.body_start-pos); } } else { val=pmw->data[(pmw->data_num-1+pmw->data_index)%pmw->data_num]; pos=val*pmw->generic.body_height/scale; gdk_window_copy_area(pmw->generic.widget.window,grid_gc, 0,pmw->generic.body_start, pmw->generic.widget.window, 1,pmw->generic.body_start, pmw->generic.widget.allocation.width-1,pmw->generic.body_height); gdk_window_clear_area(pmw->generic.widget.window, pmw->generic.widget.allocation.width-1,pmw->generic.body_start, 1,pmw->generic.body_height); if(pmw->line_solid) gdk_draw_line(pmw->generic.widget.window,body_gc, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start-pos); else { gushort oldval=pmw->data[(pmw->data_num-2+pmw->data_index)%pmw->data_num]; gshort oldpos=oldval*pmw->generic.body_height/scale; gdk_draw_line(pmw->generic.widget.window,body_gc, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start-oldpos, (pmw->data_num-1),pmw->generic.body_height+pmw->generic.body_start-pos); } if(pmw->grid_drawn==1) for(i=1;igrid_num;i++) { pos=i*pmw->generic.body_height/pmw->grid_num; gdk_draw_point(pmw->generic.widget.window,grid_gc, pmw->generic.widget.allocation.width-1,pmw->generic.body_height+pmw->generic.body_start-pos); } else if(pmw->grid_drawn==-1) { pos=pmw->grid_maxvis*pmw->generic.body_height/pmw->grid_num; gdk_draw_point(pmw->generic.widget.window,grid_gc, pmw->generic.widget.allocation.width-1,pmw->generic.body_height+pmw->generic.body_start-pos); } } } } /*++++++++++++++++++++++++++++++++++++++ Set the grid colour of the Widget. ProcMeterGraph *pmw The widget to set. GdkColor grid_color The grid. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridColour(ProcMeterGraph *pmw,GdkColor grid_color) { pmw->grid_color=grid_color; if(pmw->grid_gc) gdk_gc_set_foreground(pmw->grid_gc,&pmw->grid_color); else { GdkGCValues values; values.foreground=pmw->grid_color; pmw->grid_gc=gdk_gc_new_with_values(pmw->generic.widget.parent->window,&values,GDK_GC_FOREGROUND); } GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the minimum number of grid lines in the Widget. ProcMeterGraph *pmw The Widget to set. gint grid_min The minimum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridMin(ProcMeterGraph *pmw,gint grid_min) { if(grid_min<0) { pmw->grid_min=-grid_min; pmw->grid_drawn=0; } else if(grid_min>0) { pmw->grid_min=grid_min; pmw->grid_drawn=1; } else /* if(grid_min==0) */ { pmw->grid_min=1; pmw->grid_drawn=1; } if(grid_min>pmw->grid_max && pmw->grid_max) pmw->grid_min=pmw->grid_max; if(pmw->grid_min>=pmw->grid_num) pmw->grid_num=pmw->grid_min; GraphResize(pmw); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the maximum number of grid lines in the Widget. ProcMeterGraph *pmw The Widget to set. gint grid_max The maximum number of lines. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridMax(ProcMeterGraph *pmw,gint grid_max) { if(grid_max<0) pmw->grid_max=0; else pmw->grid_max=grid_max; if(grid_max && grid_maxgrid_min) pmw->grid_max=pmw->grid_min; GraphResize(pmw); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the graph to solid or line. ProcMeterGraph *pmw The Widget to set. gboolean solid The solidity of the graph. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetSolid(ProcMeterGraph *pmw,gboolean solid) { pmw->line_solid=solid; GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Set the grid units for the widget ProcMeterGraph *pmw The widget to set. gchar *units The grid units. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphSetGridUnits(ProcMeterGraph *pmw,gchar *units) { if(pmw->grid_units!=empty_string) free(pmw->grid_units); pmw->grid_units=(char*)malloc(strlen(units)+1); strcpy(pmw->grid_units,units); GraphResize(pmw); GraphUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Add a data point to the ProcMeter Graph Widget. ProcMeterGraph *pmw The ProcMeter Graph Widget. gushort datum The data point to add. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphAddDatum(ProcMeterGraph *pmw,gushort datum) { gushort old_datum,new_data_max=pmw->data_max; int i; old_datum=pmw->data[pmw->data_index]; pmw->data[pmw->data_index]=datum; pmw->data_index=(pmw->data_index+1)%pmw->data_num; if(datum>new_data_max) new_data_max=datum; else if(old_datum==new_data_max) for(i=new_data_max=0;idata_num;i++) if(pmw->data[i]>new_data_max) new_data_max=pmw->data[i]; if(new_data_max!=pmw->data_max) { int new_grid_num=(new_data_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numgrid_min) new_grid_num=pmw->grid_min; if(pmw->grid_max && new_grid_num>pmw->grid_max) new_grid_num=pmw->grid_max; pmw->data_max=new_data_max; if(new_grid_num!=pmw->grid_num) { pmw->grid_num=new_grid_num; if(pmw->grid_num>pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=-1; if(pmw->grid_num<=pmw->grid_maxvis && pmw->grid_drawn) pmw->grid_drawn=1; GraphUpdate(pmw,TRUE); } } GraphUpdate(pmw,FALSE); } procmeter3-3.5d/gtk2/widgets/PMGraph.h000066400000000000000000000060541165060751200176040ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMGraph.h,v 1.1 2007-09-19 19:05:17 amb Exp $ ProcMeter Graph Widget include file (for ProcMeter3 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGRAPH_H #define PMGRAPH_H /*+ To stop multiple inclusions. +*/ #include #include #include "PMGeneric.h" #define GTK_TYPE_PROCMETERGRAPH (gtk_procmetergraph_get_type()) #define GTK_PROCMETERGRAPH(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERGRAPH,ProcMeterGraph) #define GTK_PROCMETERGRAPH_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERGRAPH,ProcMeterGraphClass) #define GTK_IS_PROCMETERGRAPH(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERGRAPH) typedef struct _ProcMeterGraph ProcMeterGraph; typedef struct _ProcMeterGraphClass ProcMeterGraphClass; struct _ProcMeterGraph { ProcMeterGeneric generic; gchar* grid_units; /*+ The number of things per grid line. +*/ gushort grid_units_x; /*+ The position of the grid units. +*/ GdkColor grid_color; /*+ The grid lines colour. +*/ GdkGC* grid_gc; /*+ The graphics context for the grid lines. +*/ gint grid_min; /*+ The minimum number of grid lines. +*/ gint grid_max; /*+ The maximum number of grid lines. +*/ gint grid_maxvis; /*+ The maximum number of grid lines before removing them. +*/ gint grid_drawn; /*+ If 1 then draw as normal, if 0 never draw, if -1 draw only one line. +*/ gint grid_num; /*+ The actual number of grid lines. +*/ gboolean line_solid; /*+ True if the area under the graph is to be filled. +*/ gushort* data; /*+ The data for the graph. +*/ gushort data_max; /*+ The maximum data value. +*/ guint data_num; /*+ The number of data points. +*/ gint data_index; /*+ An index into the array for the new value. +*/ }; struct _ProcMeterGraphClass { ProcMeterGenericClass parent_class; void (*resize)(ProcMeterGraph *pmw); void (*update)(ProcMeterGraph *pmw,gboolean all); }; guint gtk_procmetergraph_get_type(void); GtkWidget* gtk_procmetergraph_new(void); /* Public functions */ void ProcMeterGraphSetGridColour(ProcMeterGraph *pmw,GdkColor grid_color); void ProcMeterGraphSetGridMin(ProcMeterGraph *pmw,gint grid_min); void ProcMeterGraphSetGridMax(ProcMeterGraph *pmw,gint grid_max); void ProcMeterGraphSetGridUnits(ProcMeterGraph *pmw,gchar *units); void ProcMeterGraphSetSolid(ProcMeterGraph *pmw,gboolean solid); void ProcMeterGraphAddDatum(ProcMeterGraph *pmw,gushort datum); #endif /* PMGRAPH_H */ procmeter3-3.5d/gtk2/widgets/PMText.c000066400000000000000000000234371165060751200174660ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMText.c,v 1.2 2007-11-21 19:57:18 amb Exp $ ProcMeter Text Widget Source file (for ProcMeter 3.5a). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000,01,02,03,07 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include "PMGeneric.h" #include "PMText.h" static void procmetertext_class_init (ProcMeterTextClass *class); static void procmetertext_init(ProcMeterText *pmw); static void destroy(GtkObject *object); static void realize(GtkWidget *widget); static gint expose(GtkWidget *widget,GdkEventExpose *event); static void size_request(GtkWidget *widget,GtkRequisition *requisition); static void size_allocate(GtkWidget *widget,GtkAllocation *allocation); static void TextResize(ProcMeterText *pmw); static void TextUpdate(ProcMeterText *pmw,gboolean all); static char *empty_string=""; static ProcMeterGenericClass *parent_class=NULL; /*++++++++++++++++++++++++++++++++++++++ Returns the type of a Widget. guint gtk_procmetertext_get_type Returns a unique pointer to the Widget type. ++++++++++++++++++++++++++++++++++++++*/ guint gtk_procmetertext_get_type(void) { static guint pmw_type = 0; if(!pmw_type) { GtkTypeInfo pmw_info={"ProcMeterText", sizeof(ProcMeterText), sizeof(ProcMeterTextClass), (GtkClassInitFunc) procmetertext_class_init, (GtkObjectInitFunc) procmetertext_init, (gpointer) NULL, (gpointer) NULL, (GtkClassInitFunc) NULL}; pmw_type=gtk_type_unique(gtk_procmetergeneric_get_type(),&pmw_info); } return(pmw_type); } /*++++++++++++++++++++++++++++++++++++++ Initialise the Widget class ProcMeterTextClass *class The class of widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetertext_class_init(ProcMeterTextClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; g_return_if_fail(class!=NULL); object_class=(GtkObjectClass*)class; widget_class=(GtkWidgetClass*)class; class->resize=TextResize; class->update=TextUpdate; parent_class=gtk_type_class(gtk_procmetergeneric_get_type()); object_class->destroy=destroy; widget_class->realize=realize; widget_class->expose_event=expose; widget_class->size_request=size_request; widget_class->size_allocate=size_allocate; } /*++++++++++++++++++++++++++++++++++++++ Initialise an instance of the Widget ProcMeterText *pmw The Widget to initialise. ++++++++++++++++++++++++++++++++++++++*/ static void procmetertext_init(ProcMeterText *pmw) { g_return_if_fail(pmw!=NULL); /* The text parts. */ pmw->text_string=empty_string; pmw->text_font=NULL; /* The rest of the sizing. */ TextResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Create a new Widget. GtkWidget* gtk_procmetertext_new Returns the new widgets. ++++++++++++++++++++++++++++++++++++++*/ GtkWidget* gtk_procmetertext_new(void) { ProcMeterText *pmw; pmw=gtk_type_new(gtk_procmetertext_get_type()); return(GTK_WIDGET(pmw)); } /*++++++++++++++++++++++++++++++++++++++ Destroy a Widget GtkObject *object The widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void destroy(GtkObject *object) { ProcMeterText *pmw; g_return_if_fail(object!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(object)); pmw=GTK_PROCMETERTEXT(object); if(pmw->text_string!=empty_string) { free(pmw->text_string); pmw->text_string=empty_string; } if(GTK_OBJECT_CLASS(parent_class)->destroy) (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); } /*++++++++++++++++++++++++++++++++++++++ Realize a widget. GtkWidget *widget The widget to realize. ++++++++++++++++++++++++++++++++++++++*/ static void realize(GtkWidget *widget) { ProcMeterText *pmw; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(widget)); GTK_WIDGET_SET_FLAGS(widget,GTK_REALIZED); pmw=GTK_PROCMETERTEXT(widget); attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; attributes.width=widget->allocation.width; attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; attributes.window_type=GDK_WINDOW_CHILD; attributes.event_mask=gtk_widget_get_events(widget)|GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK; attributes.visual=gtk_widget_get_visual(widget); attributes.colormap=gtk_widget_get_colormap(widget); attributes_mask=GDK_WA_X|GDK_WA_Y|GDK_WA_VISUAL|GDK_WA_COLORMAP; widget->window=gdk_window_new(widget->parent->window,&attributes,attributes_mask); widget->style=gtk_style_attach(widget->style,widget->window); gdk_window_set_user_data(widget->window,widget); gtk_style_set_background(widget->style,widget->window,GTK_STATE_ACTIVE); if(pmw->generic.body_bg_set) gdk_window_set_background(widget->window,&pmw->generic.body_bg_color); TextUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Choose the size that the widget wants to be. GtkWidget *widget The widget to be resized. GtkRequisition *requisition Returns the request for the size. ++++++++++++++++++++++++++++++++++++++*/ static void size_request(GtkWidget *widget,GtkRequisition *requisition) { ProcMeterText *pmw; GdkFont *text_font; g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(widget)); g_return_if_fail(requisition!=NULL); pmw=GTK_PROCMETERTEXT(widget); text_font=pmw->text_font?pmw->text_font:gtk_style_get_font(pmw->generic.widget.style); requisition->width=gdk_string_width(text_font,"NNNNNNNNNNNNNNN"); requisition->height=text_font->ascent+text_font->descent+2+pmw->generic.label_height; } /*++++++++++++++++++++++++++++++++++++++ Change to the size that has been specified by the container. GtkWidget *widget The widget that has been resized. GtkAllocation *allocation The size information. ++++++++++++++++++++++++++++++++++++++*/ static void size_allocate(GtkWidget *widget,GtkAllocation *allocation) { g_return_if_fail(widget!=NULL); g_return_if_fail(GTK_IS_PROCMETERTEXT(widget)); g_return_if_fail(allocation!=NULL); widget->allocation=*allocation; if(GTK_WIDGET_REALIZED(widget)) { ProcMeterText *pmw=GTK_PROCMETERTEXT(widget); gdk_window_move_resize(widget->window, allocation->x,allocation->y, allocation->width,allocation->height); TextResize(pmw); } } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Text Widget. gint expose Returns false GtkWidget *widget The Widget to redisplay. GdkEventExpose *event The event that caused the redisplay. ++++++++++++++++++++++++++++++++++++++*/ static gint expose(GtkWidget *widget,GdkEventExpose *event) { ProcMeterText *pmw; g_return_val_if_fail(widget!=NULL,FALSE); g_return_val_if_fail(GTK_IS_PROCMETERTEXT(widget),FALSE); g_return_val_if_fail(event!=NULL,FALSE); if(event->count>0) return(FALSE); pmw=GTK_PROCMETERTEXT(widget); TextUpdate(pmw,TRUE); return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterText *pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void TextResize(ProcMeterText *pmw) { GdkFont *text_font; g_return_if_fail(pmw!=NULL); (parent_class->resize)(&pmw->generic); /* The text parts. */ text_font=pmw->text_font?pmw->text_font:gtk_style_get_font(pmw->generic.widget.style); pmw->text_x=(pmw->generic.widget.allocation.width-gdk_string_width(text_font,pmw->text_string))/2; pmw->text_y=pmw->generic.body_start+1+text_font->ascent; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterText *pmw The Widget to update. gboolean all Indicates if the whole widget is to be updated. ++++++++++++++++++++++++++++++++++++++*/ static void TextUpdate(ProcMeterText *pmw,gboolean all) { g_return_if_fail(pmw!=NULL); if(GTK_WIDGET_VISIBLE(&pmw->generic.widget)) { GdkGC *body_gc=pmw->generic.body_gc?pmw->generic.body_gc:pmw->generic.widget.style->fg_gc[GTK_STATE_NORMAL]; GdkFont *text_font=pmw->text_font?pmw->text_font:gtk_style_get_font(pmw->generic.widget.style); if(all) (parent_class->update)(&pmw->generic); else gdk_window_clear_area(pmw->generic.widget.window, 0,pmw->generic.body_start, pmw->generic.widget.allocation.width,pmw->generic.body_height); gdk_draw_string(pmw->generic.widget.window,text_font,body_gc, pmw->text_x,pmw->text_y, pmw->text_string); } } /*++++++++++++++++++++++++++++++++++++++ Set the text font for the widget ProcMeterText *pmw The widget to set. GdkFont *font The font to use. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterTextSetFont(ProcMeterText *pmw,GdkFont *font) { pmw->text_font=font; TextResize(pmw); TextUpdate(pmw,TRUE); } /*++++++++++++++++++++++++++++++++++++++ Change the data displayed in the ProcMeter Text Widget. ProcMeterText *pmw The ProcMeter Text Widget. char *text The new string to display. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterTextChangeData(ProcMeterText *pmw,char *text) { if(pmw->text_string!=empty_string) free(pmw->text_string); pmw->text_string=(char*)malloc(strlen(text)+1); strcpy(pmw->text_string,text); pmw->text_x=(pmw->generic.widget.allocation.width-gdk_string_width(pmw->text_font,pmw->text_string))/2; TextUpdate(pmw,FALSE); } procmeter3-3.5d/gtk2/widgets/PMText.h000066400000000000000000000035121165060751200174630ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/widgets/PMText.h,v 1.1 2007-09-19 19:05:37 amb Exp $ ProcMeter Text Widget include file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMTEXT_H #define PMTEXT_H /*+ To stop multiple inclusions. +*/ #include #include #include "PMGeneric.h" #define GTK_TYPE_PROCMETERTEXT (gtk_procmetertext_get_type()) #define GTK_PROCMETERTEXT(obj) GTK_CHECK_CAST((obj),GTK_TYPE_PROCMETERTEXT,ProcMeterText) #define GTK_PROCMETERTEXT_CLASS(klass) GTK_CHECK_CLASS_CAST((klass),GTK_TYPE_PROCMETERTEXT,ProcMeterTextClass) #define GTK_IS_PROCMETERTEXT(obj) GTK_CHECK_TYPE((obj),GTK_TYPE_PROCMETERTEXT) typedef struct _ProcMeterText ProcMeterText; typedef struct _ProcMeterTextClass ProcMeterTextClass; struct _ProcMeterText { ProcMeterGeneric generic; gchar* text_string; /*+ The text for the Widget. +*/ GdkFont* text_font; /*+ The font for the text. +*/ gushort text_x,text_y; /*+ The position of the text. +*/ }; struct _ProcMeterTextClass { ProcMeterGenericClass parent_class; void (*resize)(ProcMeterText *pmw); void (*update)(ProcMeterText *pmw,gboolean all); }; guint gtk_procmetertext_get_type(void); GtkWidget* gtk_procmetertext_new(void); /* Public functions */ void ProcMeterTextSetFont(ProcMeterText *pmw,GdkFont *font); void ProcMeterTextChangeData(ProcMeterText *pmt,char *data); #endif /* PMTEXT_H */ procmeter3-3.5d/gtk2/window.c000066400000000000000000000432361165060751200161450ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/window.c,v 1.6 2010-02-28 10:22:07 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. X Windows interface. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1997-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include "widgets/PMGeneric.h" #include "widgets/PMGraph.h" #include "widgets/PMText.h" #include "widgets/PMBar.h" #include "procmeter.h" #include "procmeterp.h" #include "window.h" #define MINHEIGHT 30 #define MINWIDTH 60 static gint SleepCallback(gpointer p); static void ResizePaneCallback(GtkWidget *w,GdkEventConfigure *event); static gint CloseCallback(GtkWidget *w,GdkEvent *event,gpointer data); /*+ The toplevel widget. +*/ GtkWidget *toplevel; /*+ The pane that contains all of the outputs. +*/ GtkWidget *pane=NULL; /*+ If the meters are aligned vertically. +*/ int vertical=1; /*+ A flag that is set to true when we are told to quit. +*/ extern int quit; /*+ Set to true when we are sleeping waiting for a timeout. +*/ static int sleeping; /*+ A list of the outputs that are currently visible. +*/ static Output *displayed=NULL; static int ndisplayed=0; /*+ A flag to indicate that we are still initialising and not to resize. +*/ static int initialising=1; /*++++++++++++++++++++++++++++++++++++++ Start the X-Windows & GTK part. int *argc The number of command line arguments. char **argv The actual command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void Start(int *argc,char **argv) { static char procmeter_version[]="ProcMeter V" PROCMETER_VERSION; char *string; GtkWidget *event_box; int i,j=0; if((string=GetProcMeterRC("resources","horizontal")) && StringToBoolean(string)) vertical=0; /* Initialise the display */ gtk_init(argc,&argv); toplevel=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(toplevel),procmeter_version); gtk_window_set_resizable(GTK_WINDOW(toplevel),TRUE); /* Create the bitmaps */ CreateBitmaps(toplevel); /* Create the menu widgets */ CreateMenus(toplevel); /* Create the pane widget */ event_box=gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(toplevel),event_box); gtk_widget_show(event_box); if(vertical) pane=gtk_vbox_new(FALSE,0); else pane=gtk_hbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(pane),2); gtk_container_add(GTK_CONTAINER(event_box),pane); gtk_widget_show(GTK_WIDGET(pane)); gtk_signal_connect(GTK_OBJECT(toplevel),"configure_event", GTK_SIGNAL_FUNC(ResizePaneCallback),NULL); AddMenuToOutput(event_box,NULL); /* Parse the -geometry and -w flag */ for(i=1;i<*argc;i++) if((!strcmp(argv[i],"-geometry")) && (i+1<=*argc)) { int x,y,w,h; i++;j+=2; if(sscanf(argv[i],"%dx%d%d%d",&w,&h,&x,&y)==4) { gtk_widget_set_size_request(GTK_WIDGET(toplevel),w,h); if(x<0) x=gdk_screen_width()-w+x; if(y<0) y=gdk_screen_height()-h+y; gtk_window_move(GTK_WINDOW(toplevel),x,y); } else if(sscanf(argv[i],"%dx%d",&w,&h)==2) gtk_widget_set_size_request(GTK_WIDGET(toplevel),w,h); else fprintf(stderr,"ProcMeter: Cannot parse -geometry option: '%s'\n",argv[i]); } else if((!strcmp(argv[i],"-w")) && (i+1<=*argc)) { char *token; i++;j+=2; token=strtok(argv[i],","); while(token) { if(!strcmp(token,"above")) gtk_window_set_keep_above(GTK_WINDOW(toplevel),TRUE); else if(!strcmp(token,"below")) gtk_window_set_keep_below(GTK_WINDOW(toplevel),TRUE); else if(!strcmp(token,"skip_taskbar")) gtk_window_set_skip_taskbar_hint(GTK_WINDOW(toplevel),TRUE); else if(!strcmp(token,"skip_pager")) gtk_window_set_skip_pager_hint(GTK_WINDOW(toplevel),TRUE); else if(!strcmp(token,"sticky")) gtk_window_stick(GTK_WINDOW(toplevel)); else fprintf(stderr,"ProcMeter: Cannot parse -w option: '%s'\n",token); token = strtok(NULL,","); } } if(j>0) { for(i=j;i<*argc;i++) argv[i-j]=argv[i]; *argc-=j; } /* Show the widgets */ gtk_widget_show(GTK_WIDGET(toplevel)); /* Put an action on the window manager close button */ gtk_signal_connect(GTK_OBJECT(toplevel),"delete_event", GTK_SIGNAL_FUNC(CloseCallback),NULL); } /*++++++++++++++++++++++++++++++++++++++ Stop the X-Windows & GTK part. ++++++++++++++++++++++++++++++++++++++*/ void Stop(void) { DestroyMenus(); gtk_main_quit(); } /*++++++++++++++++++++++++++++++++++++++ Sleep for the specified interval in seconds. time_t until The time to sleep until. ++++++++++++++++++++++++++++++++++++++*/ void Sleep(time_t until) { struct timeval now; int delay; /* Before we sleep the first time, resize the window. */ if(initialising) { Resize(); initialising=0; } /* Sleep */ gettimeofday(&now,NULL); delay=1000*(until-now.tv_sec)-now.tv_usec/1000; if(delay>0) { gint id=gtk_timeout_add(delay,(GtkFunction)SleepCallback,NULL); sleeping=1; while(sleeping) { struct timeval now2; gtk_main_iteration(); gettimeofday(&now2,NULL); if(now2.tv_secoutput_widget) { int i,found=0; gtk_widget_destroy(GTK_WIDGET(output->output_widget)); output->output_widget=NULL; for(i=0;ioutputs;*outputp;outputp++) if(output==*outputp) { module=*modulep; break; } if(module) break; } if(output->type==PROCMETER_GRAPH) { w=gtk_procmetergraph_new(); gtk_box_pack_start(GTK_BOX(pane),w,TRUE,TRUE,0); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-foreground")) || (string=GetProcMeterRC(module->module->name,"grid-foreground")) || (string=GetProcMeterRC("resources","grid-foreground")))) ProcMeterGraphSetGridColour(GTK_PROCMETERGRAPH(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"graph-solid")) || (string=GetProcMeterRC(module->module->name,"graph-solid")) || (string=GetProcMeterRC("resources","graph-solid")))) ProcMeterGraphSetSolid(GTK_PROCMETERGRAPH(w),StringToBoolean(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-max")) || (string=GetProcMeterRC(module->module->name,"grid-max")) || (string=GetProcMeterRC("resources","grid-max")))) ProcMeterGraphSetGridMax(GTK_PROCMETERGRAPH(w),StringToInt(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) ProcMeterGraphSetGridMin(GTK_PROCMETERGRAPH(w),StringToInt(string)); if(vertical) gtk_widget_set_size_request(GTK_WIDGET(w),-1,MINHEIGHT); else gtk_widget_set_size_request(GTK_WIDGET(w),MINWIDTH,-1); sprintf(str,output->output->graph_units,output->output->graph_scale); ProcMeterGraphSetGridUnits(GTK_PROCMETERGRAPH(w),str); } else if(output->type==PROCMETER_TEXT) { w=gtk_procmetertext_new(); gtk_box_pack_start(GTK_BOX(pane),w,FALSE,TRUE,0); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"text-font")) || (string=GetProcMeterRC(module->module->name,"text-font")) || (string=GetProcMeterRC("resources","text-font")))) ProcMeterTextSetFont(GTK_PROCMETERTEXT(w),StringToFont(string)); } else if(output->type==PROCMETER_BAR) { w=gtk_procmeterbar_new(); gtk_box_pack_start(GTK_BOX(pane),w,TRUE,TRUE,0); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-foreground")) || (string=GetProcMeterRC(module->module->name,"grid-foreground")) || (string=GetProcMeterRC("resources","grid-foreground")))) ProcMeterBarSetGridColour(GTK_PROCMETERBAR(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) ProcMeterBarSetGridMin(GTK_PROCMETERBAR(w),StringToInt(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-max")) || (string=GetProcMeterRC(module->module->name,"grid-max")) || (string=GetProcMeterRC("resources","grid-max")))) ProcMeterBarSetGridMax(GTK_PROCMETERBAR(w),StringToInt(string)); sprintf(str,output->output->graph_units,output->output->graph_scale); ProcMeterBarSetGridUnits(GTK_PROCMETERBAR(w),str); } /* Generic */ ProcMeterGenericSetLabel(GTK_PROCMETERGENERIC(w),(gchar*)output->label); /* Resources */ if(((string=GetProcMeterRC2(module->module->name,output->output->name,"foreground")) || (string=GetProcMeterRC(module->module->name,"foreground")) || (string=GetProcMeterRC("resources","foreground")))) ProcMeterGenericSetForegroundColour(GTK_PROCMETERGENERIC(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"background")) || (string=GetProcMeterRC(module->module->name,"background")) || (string=GetProcMeterRC("resources","background")))) ProcMeterGenericSetBackgroundColour(GTK_PROCMETERGENERIC(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-font")) || (string=GetProcMeterRC(module->module->name,"label-font")) || (string=GetProcMeterRC("resources","label-font")))) ProcMeterGenericSetLabelFont(GTK_PROCMETERGENERIC(w),StringToFont(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-foreground")) || (string=GetProcMeterRC(module->module->name,"label-foreground")) || (string=GetProcMeterRC("resources","label-foreground")) || (string=GetProcMeterRC2(module->module->name,output->output->name,"foreground")) || (string=GetProcMeterRC(module->module->name,"foreground")) || (string=GetProcMeterRC("resources","foreground")))) ProcMeterGenericSetLabelColour(GTK_PROCMETERGENERIC(w),StringToPixel(string)); if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-position")) || (string=GetProcMeterRC(module->module->name,"label-position")) || (string=GetProcMeterRC("resources","label-position")))) ProcMeterGenericSetLabelPosition(GTK_PROCMETERGENERIC(w),StringToLabelPosition(string)); AddMenuToOutput(w,module); gtk_widget_show(GTK_WIDGET(w)); gtk_signal_handler_block_by_data(GTK_OBJECT(output->menu_item_widget),output); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(output->menu_item_widget),TRUE); gtk_signal_handler_unblock_by_data(GTK_OBJECT(output->menu_item_widget),output); output->output_widget=w; output->first=2; displayed=(Output*)realloc((void*)displayed,sizeof(Output)*(ndisplayed+1)); displayed[ndisplayed]=output; ndisplayed++; } Resize(); } /*++++++++++++++++++++++++++++++++++++++ Update a graph output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateGraph(Output output,short value) { ProcMeterGraphAddDatum(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Update a text output. Output output The output to update. char *value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateText(Output output,char *value) { ProcMeterTextChangeData(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Update a bar output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateBar(Output output,short value) { ProcMeterBarAddDatum(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Move an output. Output output1 The output to be moved. Output output2 The one that the output is to be moved above or below. int direction The direction to move the output (up=1 or down=2). ++++++++++++++++++++++++++++++++++++++*/ void MoveOutput(Output output1,Output output2,int direction) { int i,i1=-1,i2=-1; for(i=0;ioutput_widget),i2); Resize(); if(direction==1 && i2>i1) { for(i=i1;ii2) { for(i=i1;i>i2;i--) displayed[i]=displayed[i-1]; displayed[i2]=output1; } else if(direction==2 && i2>i1) { for(i=i1;ii2) */ { for(i=i1;i>i2;i--) displayed[i]=displayed[i-1]; displayed[i2+1]=output1; } } /*++++++++++++++++++++++++++++++++++++++ Resize the pane. ++++++++++++++++++++++++++++++++++++++*/ void Resize(void) { gushort psize,size; gint width,height; int gsize,msize; int i,ngraphs=0; if(initialising) return; if(!ndisplayed) return; gdk_window_get_size(GTK_WIDGET(toplevel)->window,&width,&height); if(vertical) psize=height; else psize=width; msize=0; gsize=psize; for(i=0;ioutput_widget),&request); if(vertical) min_size=request.height; else min_size=request.width; if(displayed[i]->type==PROCMETER_GRAPH) ngraphs++; else if(displayed[i]->type==PROCMETER_TEXT) gsize-=min_size; else if(displayed[i]->type==PROCMETER_BAR) ngraphs++; msize+=min_size; if(i) msize+=2,gsize-=2; /* separator between panes */ } if(msize>psize || (ngraphs==0 && msize!=psize)) { if(vertical) height=msize; else width=msize; gtk_widget_set_size_request(GTK_WIDGET(toplevel),0,0); gtk_window_resize(GTK_WINDOW(toplevel),width,height); gdk_window_resize(GTK_WIDGET(toplevel)->window,width,height); gtk_widget_set_size_request(GTK_WIDGET(pane),width,height); gtk_container_resize_children(GTK_CONTAINER(pane)); return; } for(i=0;itype==PROCMETER_GRAPH || displayed[i]->type==PROCMETER_BAR) { size=gsize/ngraphs; gsize-=size; ngraphs--; if(vertical) height=size; else width=size; } else { GtkRequisition request; gtk_widget_size_request(GTK_WIDGET(displayed[i]->output_widget),&request); if(vertical) height=request.height; else width=request.width; } //gtk_widget_set_size_request(GTK_WIDGET(displayed[i]->output_widget),width,height); } gtk_container_resize_children(GTK_CONTAINER(pane)); } /*++++++++++++++++++++++++++++++++++++++ The function called by the timeout to terminate the sleep. gint SleepCallback Returns true to repeat the timer. gpointer p Not used. This function is only ever called from the gtk event loop. ++++++++++++++++++++++++++++++++++++++*/ static gint SleepCallback(gpointer p) { sleeping=0; return(FALSE); } /*++++++++++++++++++++++++++++++++++++++ A callback that is activated by a resize event on the parent pane. GtkWidget *w The widget that caused the callback. GdkEventConfigure *event Not used. This function is only ever called from the gtk event loop. ++++++++++++++++++++++++++++++++++++++*/ static void ResizePaneCallback(GtkWidget *w,GdkEventConfigure *event) { Resize(); } /*++++++++++++++++++++++++++++++++++++++ A callback that is activated by a close window event on the toplevel window. gint CloseCallback returns a value that indicates if the toplevel window is not to be destroyed. GtkWidget *w The widget that caused the event. GdkEvent *event The event information. gpointer data Not used. This function is only ever called from the GTK event handler. ++++++++++++++++++++++++++++++++++++++*/ static gint CloseCallback(GtkWidget *w,GdkEvent *event,gpointer data) { quit=1; return(TRUE); } procmeter3-3.5d/gtk2/window.h000066400000000000000000000024771165060751200161540ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/gtk2/window.h,v 1.1 2007-09-19 19:07:24 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3b. Global X windows header file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef WINDOW_H #define WINDOW_H /*+ To stop multiple inclusions. +*/ #include "procmeterp.h" /* In window.c */ void MoveOutput(Output output1,Output output2,int direction); void Resize(void); /* In menus.c */ void CreateMenus(GtkWidget *parent); void DestroyMenus(void); void AddMenuToOutput(GtkWidget *widget,Module module); /* In resources.c */ GdkFont *StringToFont(char *string); GdkColor StringToPixel(char *string); gboolean StringToBoolean(char *string); int StringToInt(char *string); int StringToLabelPosition(char *string); /* In bitmap.c */ extern GdkPixmap *CircleBitmap; extern GdkPixmap *TextBitmap; extern GdkPixmap *GraphBitmap; extern GdkPixmap *BarBitmap; void CreateBitmaps(GtkWidget *w); #endif /* WINDOW_H */ procmeter3-3.5d/lcd/000077500000000000000000000000001165060751200143555ustar00rootroot00000000000000procmeter3-3.5d/lcd/Makefile000066400000000000000000000024611165060751200160200ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/lcd/Makefile,v 1.1 2002-11-30 19:22:37 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.4. # # Makefile for LCD driver part. # # Written by Andrew M. Bishop # # This file Copyright 1994,95,96,97,98,99,2000,02 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options CFLAGS=-g -O2 -Wall LDFLAGS= # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) PSRC=$(wildcard ../*.c) POBJ=$(foreach f,$(PSRC),$(addsuffix .o,$(basename $f))) ######## all : $(OBJ) \ ../procmeter3-lcd ######## ../procmeter3-lcd : $(OBJ) procmeter.main $(LD) $(OBJ) $(POBJ) -o $@ -ldl $(LDFLAGS) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ -I.. window.o : window.c ../procmeterp.h ../procmeter.h menu.o : menu.c ../procmeterp.h ../procmeter.h run.o : run.c ../procmeterp.h ../procmeter.h ######## .PHONY : procmeter.main $(POBJ) : procmeter.main procmeter.main : $(MAKE) CFLAGS="$(CFLAGS)" -C .. obj ######## .PHONY : clean clean : -rm -f *.o *~ core ######## .PHONY : install install : procmeter3-3.5d/lcd/menus.c000077700000000000000000000000001165060751200202322../no-x/menus.custar00rootroot00000000000000procmeter3-3.5d/lcd/run.c000077700000000000000000000000001165060751200173642../no-x/run.custar00rootroot00000000000000procmeter3-3.5d/lcd/window.c000066400000000000000000000427041165060751200160370ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/lcd/window.c,v 1.6 2010-02-28 10:07:46 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. LCD driver daemon interface. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1997-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include "procmeter.h" #include "procmeterp.h" #define DEBUG 0 /*+ A fake widget for graphs. +*/ typedef struct _LCD_Graph { unsigned int grid_min; /*+ The minimum number of graph grid lines. +*/ unsigned int grid_num; /*+ The current number of graph grid lines. +*/ unsigned short* data; /*+ The data for the graph. +*/ unsigned int data_num; /*+ The number of data points. +*/ int data_index; /*+ An index into the array for the new value. +*/ unsigned short* bars; /*+ The bars for the graph. +*/ unsigned int bars_num; /*+ The number of bars. +*/ unsigned short bar_max; /*+ The maximum data value. +*/ } LCD_Graph; /*+ A fake widget for text outputs. +*/ typedef struct _LCD_Text { int dummy; /*+ Not used. +*/ } LCD_Text; /*+ A fake widget for bar charts. +*/ typedef struct _LCD_Bar { unsigned int grid_min; /*+ The minimum number of bar grid lines. +*/ unsigned int grid_num; /*+ The current number of bar grid lines. +*/ unsigned short data[8]; /*+ The data for the bar. +*/ unsigned short data_index; /*+ A pointer into the array +*/ unsigned long data_sum; /*+ The average value of the last 8 data points. +*/ } LCD_Bar; /* Local functions */ void CreateGraph(Output output); void CreateText(Output output); void CreateBar(Output output); void send_command(char *format, ...); /*+ A list of the outputs that are currently visible. +*/ static Output *displayed=NULL; static int ndisplayed=0; /*+ The file descriptor of the socket for talking to the server. +*/ static int server; /* Variables to hold the screen information. */ static int LCD_screen_width=20; /*+ The width of the LCD in characters +*/ static int LCD_screen_height=4; /*+ The height of the LCD in characters +*/ static int LCD_char_width=5; /*+ The width of the character in pixels +*/ static int LCD_char_height=8; /*+ The height of the character in pixels +*/ static int LCD_duration=8; /*+ How long each display stays on screen. +*/ static char *LCD_priority=NULL; /*+ The display priority for each display. +*/ /*++++++++++++++++++++++++++++++++++++++ Start the LCD driver daemon connection. int *argc The number of command line arguments. char **argv The actual command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void Start(int *argc,char **argv) { char *string; char *host; int port=0; char reply[128],*p; int replylen; struct sockaddr_in sockaddr; struct hostent* hp; /* Get the host and port number */ string=GetProcMeterRC("LCD","host"); if(string) host=string; else host="localhost"; string=GetProcMeterRC("LCD","port"); if(string) port=atoi(string); if(port<=0 || port>65535) port=13666; fprintf(stderr,"ProcMeter: Connecting to LCDd on %s:%d.\n",host,port); string=GetProcMeterRC("LCD","duration"); if(string) LCD_duration=atoi(string); string=GetProcMeterRC("LCD","priority"); if(string) { LCD_priority=(char*)malloc(strlen(string)+1); strcpy(LCD_priority,string); } /* Make the socket connection */ sockaddr.sin_family=AF_INET; sockaddr.sin_port=htons((unsigned short)port); hp=gethostbyname(host); if(!hp) { unsigned long int addr=inet_addr(host); if(addr!=-1) hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET); if(!hp) { fprintf(stderr,"ProcMeter: Cannot get host information for '%s'.\n",host); exit(1); } } memcpy((char*)&sockaddr.sin_addr,(char*)hp->h_addr,sizeof(sockaddr.sin_addr)); server=socket(PF_INET,SOCK_STREAM,0); if(server==-1) { fprintf(stderr,"ProcMeter: Failed to create socket.\n"); exit(1); } if(connect(server,(struct sockaddr*)&sockaddr,sizeof(sockaddr))==-1) { fprintf(stderr,"ProcMeter: Failed to connect socket to '%s' port '%d'.\n",host,port); exit(1); } /* Say hello and parse the result */ if(write(server,"hello\n",sizeof("hello"))!=sizeof("hello")) { fprintf(stderr,"ProcMeter: Failed to write socket to '%s' port '%d'.\n",host,port); exit(1); } replylen=read(server,reply,128); reply[replylen-1]=0; fprintf(stderr,"ProcMeter: LCDd says '%s'.\n",reply); if(!(p=strstr(reply," wid "))) { fprintf(stderr,"ProcMeter: Cannot parse screen width from LCDd reply.\n"); exit(1); } LCD_screen_width=atoi(p+4); if(!(p=strstr(reply," hgt "))) { fprintf(stderr,"ProcMeter: Cannot parse screen height from LCDd reply.\n"); exit(1); } LCD_screen_height=atoi(p+4); if(!(p=strstr(reply," cellwid "))) { fprintf(stderr,"ProcMeter: Cannot parse character width from LCDd reply.\n"); exit(1); } LCD_char_width=atoi(p+8); if(!(p=strstr(reply," cellhgt "))) { fprintf(stderr,"ProcMeter: Cannot parse character height from LCDd reply.\n"); exit(1); } LCD_char_height=atoi(p+8); send_command("client_set -name ProcMeter3"); } /*++++++++++++++++++++++++++++++++++++++ Stop the LCD driver daemon connection. ++++++++++++++++++++++++++++++++++++++*/ void Stop(void) { close(server); } /*++++++++++++++++++++++++++++++++++++++ Sleep for the specified interval in seconds. time_t until The time to sleep until. ++++++++++++++++++++++++++++++++++++++*/ void Sleep(time_t until) { struct timeval now; struct timespec delay; /* Sleep */ gettimeofday(&now,NULL); delay.tv_sec=until-now.tv_sec-1; delay.tv_nsec=1000*(1000000-now.tv_usec); if(delay.tv_sec>=0) nanosleep(&delay,NULL); } /*++++++++++++++++++++++++++++++++++++++ Add or remove an output Output output The output to be added or removed. ++++++++++++++++++++++++++++++++++++++*/ void AddRemoveOutput(Output output) { if(output->output_widget) { int i,found=0; if(output->type==PROCMETER_GRAPH) { LCD_Graph *graph=(LCD_Graph*)output->output_widget; free(graph->data); free(graph->bars); } free(output->output_widget); output->output_widget=NULL; for(i=0;itype==PROCMETER_GRAPH) output->output_widget=(void*)malloc(sizeof(LCD_Graph)); else if(output->type==PROCMETER_TEXT) output->output_widget=(void*)malloc(sizeof(LCD_Text)); else if(output->type==PROCMETER_BAR) output->output_widget=(void*)malloc(sizeof(LCD_Bar)); output->first=2; displayed=(Output*)realloc((void*)displayed,sizeof(Output)*(ndisplayed+1)); displayed[ndisplayed]=output; ndisplayed++; if(output->type==PROCMETER_GRAPH) CreateGraph(output); else if(output->type==PROCMETER_TEXT) CreateText(output); else if(output->type==PROCMETER_BAR) CreateBar(output); } } /*++++++++++++++++++++++++++++++++++++++ Create a graph output Output output The output to create. ++++++++++++++++++++++++++++++++++++++*/ void CreateGraph(Output output) { char *string; LCD_Graph *graph=(LCD_Graph*)output->output_widget; int i; Output *outputp; Module *modulep,module=NULL; for(modulep=Modules;*modulep;modulep++) { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(output==*outputp) { module=*modulep; break; } if(module) break; } if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) graph->grid_min=atoi(string); else graph->grid_min=1; graph->grid_num=-1; /* force update */ graph->bars_num=LCD_screen_width-4; graph->bars=(unsigned short*)calloc(graph->bars_num,sizeof(unsigned short)); graph->bar_max=-1; /* force update */ graph->data_num=graph->bars_num*LCD_char_width; graph->data=(unsigned short*)calloc(graph->data_num,sizeof(unsigned short)); graph->data_index=0; send_command("screen_add %s_g",output->output->name); send_command("screen_set %s_g -name {%s}",output->output->name,output->output->name); send_command("screen_set %s_g -duration %d",output->output->name,LCD_duration); if(LCD_priority) send_command("screen_set %s_g -priority %s",output->output->name,LCD_priority); send_command("widget_add %s_g title title",output->output->name); send_command("widget_set %s_g title {%s}",output->output->name,output->label); send_command("widget_add %s_g min string",output->output->name); send_command("widget_set %s_g min %d %d { 0}",output->output->name,graph->bars_num+1,LCD_screen_height); send_command("widget_add %s_g max string",output->output->name); send_command("widget_set %s_g max %d 2 { ?}",output->output->name,graph->bars_num+1); for(i=1;i<=LCD_screen_width;i++) { send_command("widget_add %s_g %d vbar",output->output->name,i); send_command("widget_set %s_g %d %d %d 0",output->output->name,i,i,LCD_screen_height); } } /*++++++++++++++++++++++++++++++++++++++ Create a text output Output output The output to create. ++++++++++++++++++++++++++++++++++++++*/ void CreateText(Output output) { send_command("screen_add %s_t",output->output->name); send_command("screen_set %s_t -name {%s}",output->output->name,output->output->name); send_command("screen_set %s_t -duration %d",output->output->name,LCD_duration); if(LCD_priority) send_command("screen_set %s_t -priority %s",output->output->name,LCD_priority); send_command("widget_add %s_t title title",output->output->name); send_command("widget_set %s_t title {%s}",output->output->name,output->label); send_command("widget_add %s_t value string",output->output->name); send_command("widget_set %s_t value %d %d ?",output->output->name,LCD_screen_width/2,1+LCD_screen_height/2); } /*++++++++++++++++++++++++++++++++++++++ Create a bar output Output output The output to create. ++++++++++++++++++++++++++++++++++++++*/ void CreateBar(Output output) { LCD_Bar *bar=(LCD_Bar*)output->output_widget; char *string; Output *outputp; Module *modulep,module=NULL; int i; for(modulep=Modules;*modulep;modulep++) { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(output==*outputp) { module=*modulep; break; } if(module) break; } if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) bar->grid_min=atoi(string); else bar->grid_min=1; bar->grid_num=-1; /* force update */ for(i=0;i<8;i++) bar->data[i]=0; bar->data_sum=0; bar->data_index=0; send_command("screen_add %s_b",output->output->name); send_command("screen_set %s_b -name {%s}",output->output->name,output->output->name); send_command("screen_set %s_b -duration %d",output->output->name,LCD_duration); if(LCD_priority) send_command("screen_set %s_b -priority %s",output->output->name,LCD_priority); send_command("widget_add %s_b title title",output->output->name); send_command("widget_set %s_b title {%s}",output->output->name,output->label); send_command("widget_add %s_b value hbar",output->output->name); send_command("widget_set %s_b value 1 %d 0",output->output->name,1+LCD_screen_height/2); send_command("widget_add %s_b min string",output->output->name); if(LCD_screen_height>2) send_command("widget_set %s_b min 1 %d 0",output->output->name,LCD_screen_height); send_command("widget_add %s_b max string",output->output->name); send_command("widget_set %s_b max %d %d { ?}",output->output->name,LCD_screen_width-4,LCD_screen_height); send_command("widget_add %s_b average string",output->output->name); if(LCD_screen_height>2) send_command("widget_set %s_b average 1 2 { }",output->output->name); } /*++++++++++++++++++++++++++++++++++++++ Update a graph output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateGraph(Output output,short value) { LCD_Graph *graph=(LCD_Graph*)output->output_widget; unsigned short bar_max=0,scale1,scale2; int i; /* Add the new data point */ graph->data[graph->data_index]=value; graph->data_index=(graph->data_index+1)%graph->data_num; /* Calculate the individual vertical bars */ for(i=0;ibars_num;i++) { int j,sum=0; for(j=0;jdata_index+i*LCD_char_width+j)%graph->data_num; sum+=graph->data[index]; } graph->bars[i]=sum/LCD_char_width; if(graph->bars[i]>bar_max) bar_max=graph->bars[i]; } /* Update the vertical scaling */ if(bar_max!=graph->bar_max) { int new_grid_num=(bar_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; int maxval; char maxstr[5]; if(new_grid_numgrid_min) new_grid_num=graph->grid_min; graph->bar_max=bar_max; if(new_grid_num!=graph->grid_num) graph->grid_num=new_grid_num; maxval=graph->grid_num*output->output->graph_scale; if(maxval<1000) sprintf(maxstr,"%3d",maxval); else if(maxval<1000000) sprintf(maxstr,"%3dk",maxval/1000); else sprintf(maxstr,"%3dM",maxval/1000000); send_command("widget_set %s_g max %d 2 {%s}",output->output->name,graph->bars_num+1,maxstr); } /* Set the values */ scale1=(LCD_screen_height-1)*LCD_char_height; scale2=PROCMETER_GRAPH_SCALE*graph->grid_num; for(i=0;ibars_num;i++) { short height; if(scale2>0) height=graph->bars[i]*scale1/scale2; else height=0; send_command("widget_set %s_g %d %d %d %d",output->output->name,i+1,i+1,LCD_screen_height,height); } } /*++++++++++++++++++++++++++++++++++++++ Update a text output. Output output The output to update. char *value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateText(Output output,char *value) { int len=strlen(value); int x=(LCD_screen_width-len)/2; send_command("widget_set %s_t value %d %d {%s}",output->output->name,x+1,1+LCD_screen_height/2,value); } /*++++++++++++++++++++++++++++++++++++++ Update a bar output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateBar(Output output,short value) { LCD_Bar *bar=(LCD_Bar*)output->output_widget; unsigned short old_value,new_grid_num,length,scale1,scale2; /* Add the new data point */ bar->data_index++; if(bar->data_index==8) bar->data_index=0; old_value=bar->data[bar->data_index]; bar->data[bar->data_index]=value; bar->data_sum=(bar->data_sum>>1)+value-(old_value>>8); /* Update the number of grid lines */ if((bar->data_sum/2)>value) new_grid_num=((bar->data_sum/2)+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; else new_grid_num=(value+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numgrid_min) new_grid_num=bar->grid_min; if(new_grid_num!=bar->grid_num) { int maxval; char maxstr[5]; bar->grid_num=new_grid_num; maxval=bar->grid_num*output->output->graph_scale; if(maxval<1000) sprintf(maxstr,"%3d",maxval); else if(maxval<1000000) sprintf(maxstr,"%3dk",maxval/1000); else sprintf(maxstr,"%3dM",maxval/1000000); send_command("widget_set %s_b max %d %d {%s}",output->output->name,LCD_screen_width-4,LCD_screen_height,maxstr); } /* Set the values */ if(LCD_screen_height==2) scale1=(LCD_screen_width-4)*LCD_char_width; else scale1=LCD_screen_width*LCD_char_width; scale2=PROCMETER_GRAPH_SCALE*bar->grid_num; length=value*scale1/scale2; send_command("widget_set %s_b value 1 %d %d",output->output->name,1+LCD_screen_height/2,length); if(LCD_screen_height>2) { length=bar->data_sum*scale1/(scale2*2*LCD_char_width); send_command("widget_set %s_b average %d 2 v",output->output->name,length+1); } } /*++++++++++++++++++++++++++++++++++++++ Write a string to the LCDproc server. char *format The format string. ... The other arguments. ++++++++++++++++++++++++++++++++++++++*/ void send_command(char *format, ...) { static char buffer[256]; int len; struct timeval tv; fd_set readfd; va_list ap; va_start(ap,format); len=vsprintf(buffer,format,ap); va_end(ap); buffer[len]='\n'; #if DEBUG buffer[len+1]=0; printf("-> %s",buffer); #endif if(write(server,buffer,len+1)!=len+1) { fprintf(stderr,"ProcMeter: Failed to write socket.\n"); exit(1); } usleep(100); FD_ZERO(&readfd); FD_SET(server,&readfd); tv.tv_sec=tv.tv_usec=0; if(select(server+1,&readfd,NULL,NULL,&tv)==0) return; len=read(server,buffer,255); buffer[len]=0; #if DEBUG printf("<- %s",buffer); #endif return; } procmeter3-3.5d/log/000077500000000000000000000000001165060751200143745ustar00rootroot00000000000000procmeter3-3.5d/log/Makefile000066400000000000000000000024631165060751200160410ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/log/Makefile,v 1.3 2002-11-30 19:20:54 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.4. # # Makefile for logging to a file. # # Written by Andrew M. Bishop # # This file Copyright 1994,95,96,97,98,99,2000,02 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options CFLAGS=-g -O2 -Wall LDFLAGS= # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) PSRC=$(wildcard ../*.c) POBJ=$(foreach f,$(PSRC),$(addsuffix .o,$(basename $f))) ######## all : $(OBJ) \ ../procmeter3-log ######## ../procmeter3-log : $(OBJ) procmeter.main $(LD) $(OBJ) $(POBJ) -o $@ -ldl $(LDFLAGS) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ -I.. window.o : window.c ../procmeterp.h ../procmeter.h menu.o : menu.c ../procmeterp.h ../procmeter.h run.o : run.c ../procmeterp.h ../procmeter.h ######## .PHONY : procmeter.main $(POBJ) : procmeter.main procmeter.main : $(MAKE) CFLAGS="$(CFLAGS)" -C .. obj ######## .PHONY : clean clean : -rm -f *.o *~ core ######## .PHONY : install install : procmeter3-3.5d/log/menus.c000077700000000000000000000000001165060751200202512../no-x/menus.custar00rootroot00000000000000procmeter3-3.5d/log/run.c000077700000000000000000000000001165060751200174032../no-x/run.custar00rootroot00000000000000procmeter3-3.5d/log/window.c000066400000000000000000000124211165060751200160470ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/log/window.c,v 1.3 2003-04-12 13:05:41 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3c. Log to a file output. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1997,98,99,2000,02 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" #include "procmeterp.h" /* Local functions */ static void output_labels(void); static void output_data(time_t now); /*+ A list of the outputs that are currently visible. +*/ static Output *displayed=NULL; static int ndisplayed=0; static short *new_data=NULL; static short *graph_data=NULL; static char **text_data=NULL; /*+ A flag to indicate that we are still initialising and not to output anything. +*/ static int initialising=1; /*++++++++++++++++++++++++++++++++++++++ Start the logging to a file. int *argc The number of command line arguments. char **argv The actual command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void Start(int *argc,char **argv) { /* Do nothing since we have nothing to initialise. */ } /*++++++++++++++++++++++++++++++++++++++ Stop the logging to a file. ++++++++++++++++++++++++++++++++++++++*/ void Stop(void) { /* Do nothing since we have nothing to finalise. */ } /*++++++++++++++++++++++++++++++++++++++ Sleep for the specified interval in seconds. time_t until The time to sleep until. ++++++++++++++++++++++++++++++++++++++*/ void Sleep(time_t until) { struct timeval now; struct timespec delay; /* Before we sleep the first time, output the labels. */ if(initialising) { output_labels(); initialising=0; } else if(!displayed[0]->first) output_data(until); /* Sleep */ gettimeofday(&now,NULL); delay.tv_sec=until-now.tv_sec-1; delay.tv_nsec=1000*(1000000-now.tv_usec); if(delay.tv_sec>=0) { nanosleep(&delay,NULL); } } /*++++++++++++++++++++++++++++++++++++++ Add or remove an output Output output The output to be added or removed. ++++++++++++++++++++++++++++++++++++++*/ void AddRemoveOutput(Output output) { if(output->output_widget) { int i,found=0; output->output_widget=NULL; for(i=0;ioutput_widget=(void*)1; output->first=2; displayed=(Output*)realloc((void*)displayed,sizeof(Output)*(ndisplayed+1)); displayed[ndisplayed]=output; ndisplayed++; new_data=(short*)realloc((void*)new_data,sizeof(short)*ndisplayed); graph_data=(short*)realloc((void*)graph_data,sizeof(short)*ndisplayed); text_data=(char**)realloc((void*)text_data,sizeof(char*)*ndisplayed); } } /*++++++++++++++++++++++++++++++++++++++ Update a graph output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateGraph(Output output,short value) { int i; for(i=0;ioutputs;*outputp;outputp++) if(displayed[i]==*outputp) { module=*modulep; break; } if(module) break; } printf("\t"); printf("%s.%s",module->module->name,displayed[i]->output->name); } printf("\n"); fflush(stdout); } /*++++++++++++++++++++++++++++++++++++++ Output the data for the selected outputs. time_t now The current time. ++++++++++++++++++++++++++++++++++++++*/ static void output_data(time_t now) { int i; printf("%ld",(long)now); for(i=0;i[,]] .I [\-\-rc=] [\-\-...] .I [...] .I [GTK \ program \ options] .SH DESCRIPTION .I ProcMeter Displays one or more pieces of information about the operating system and other resources. Most of the information that is displayed comes from the /proc filesystem. The program is modular and very configurable. .SH OPTIONS The command line options are described below. .TP .BR \-h Provides a help message listing the available outputs. This will be different for different computers depending on the Linux kernel version that is being used and the hardware/software that is configured. .TP .BR \-w Gives Extended Window Manager hints (EWMH) to change the way that the Window Manager treats the ProcMeter3 window. Implemented hints are: above, below, skip_pager, skip_taskbar, sticky. You can give more than one hint separated by commas (e. g. \-w above,skip_taskbar,sticky), or use \-w multiple times (e. g. \-w above \-w sticky). .BR .TP .BR \-\-rc= Load the specified .B .procmeterrc file in stead of the searching in the usual places. .TP .BR \-\-... A list of configuration file options that will override the values in the .B .procmeterrc file. The format of these options is (for example) .I \-\-resources.background=grey50 which is equivalent to the entry in the .procmeterrc file of [resources] background = grey50 All spaces around the equal sign must be removed and if spaces are required in the value on the right hand side then quotes must be used around the entire command line option. .TP .BR ... A list of names of outputs that are to be displayed. This can include any of the outputs that are available (see the \-h option). For the CPU usage is in a module named .B Statistics with an output named .B CPU and there are graph (\-g), text (\-t) and bar (\-b) options. To display the CPU usage graph you would use the command line option .B Statistics.CPU-g .TP .BR GTK \ program \ options The standard set of GTK program options. These include .B --display to set the display to use. .TP .BR X \ window \ options The only standard X Windows program option that is accepted is .B -geometry to set the size of the window. .SH USAGE When started the program will display all of the requested information in a set of output panels (vertically aligned by default). Each output can be either a graph, text or bar, and can have a label indicating what it represents. The outputs that are displayed are those from the command line and those from the .B .procmeterrc configuration file. .LP The left mouse button will produce a menu of options that are specific to the output that is selected. The .B Properties option on this menu will give more detailed information about the origin and meaning of the information that is displayed. When the properties information window is displayed, clicking on another output will change the displayed information. The .B Move to Above and .B Move to Below options allow the output to be moved around in the window. Selecting one of these options will change the mouse cursor to a hand, use this to select another output. The output that was selected first will be moved to above or below the output that was selected second. The .B Run option on the menu (which may not be available on all outputs) will run the specified command. This may be to display a list of running processes, show the amount of free memory or disk space for example. This menu option is configurable in the .B .procmeterrc file. .LP The right mouse button will produce a set of menus that list the modules that are available and for each of them the available set of outputs. There are three types of output, text and two graphical outputs, these are indicated in the sub-menus by icons. Selecting one of the outputs from a sub-menu will cause that output to be displayed if it is not already visible. If it is currently displayed then it will be disabled. Those that are currently displayed are indicated by a marker to the left in the sub-menu. When the output is added to the window it will be placed at the bottom, use the left mouse button to move it if required. .LP The middle mouse button will display the sub-menu that is associated with the module for the output that is selected. This is one of sub-menus that are found with the right mouse button. .SH MODULES The modules that are available for gprocmeter3, procmeter3-gtk1 and procmeter3-gtk2 are described in the procmeter3_modules(1) manual page. .SH SEE ALSO procmeterrc(5) procmeter3_modules(1) .SH AUTHOR Andrew M. Bishop 1998-2008 procmeter3-3.5d/man/procmeter3-gtk1.1000066400000000000000000000000271165060751200173760ustar00rootroot00000000000000.so man1/gprocmeter3.1 procmeter3-3.5d/man/procmeter3-gtk2.1000066400000000000000000000000271165060751200173770ustar00rootroot00000000000000.so man1/gprocmeter3.1 procmeter3-3.5d/man/procmeter3-lcd.1000066400000000000000000000051531165060751200172770ustar00rootroot00000000000000.\" $Header: /home/amb/CVS/procmeter3/man/procmeter3-lcd.1,v 1.5 2010-07-03 12:55:30 amb Exp $ .\" .\" ProcMeter - A system monitoring program for Linux - Version 3.5d. .\" .\" Manual page for procmeter3-lcd program. .\" .\" Written by Andrew M. Bishop .\" .\" This file Copyright 1998-2010 Andrew M. Bishop .\" It may be distributed under the GNU Public License, version 2, or .\" any higher version. See section COPYING of the GNU Public license .\" for conditions under which this file may be redistributed. .\" .TH PROCMETER3-LCD 1 "July 3, 2010" .SH NAME procmeter3-lcd \- A system monitoring program with LCDproc display. .SH SYNOPSIS .B procmeter3-lcd .I [\-h|\-\-help] .I [\-\-rc=] [\-\-...] .I [...] .SH DESCRIPTION .I ProcMeter Displays one or more pieces of information about the operating system and other resources. Most of the information that is displayed comes from the /proc filesystem. The program is modular and very configurable. .SH OPTIONS The command line options are described below. .TP .BR \-h Provides a help message listing the available outputs. This will be different for different computers depending on the Linux kernel version that is being used and the hardware/software that is configured. .TP .BR \-\-rc= Load the specified .B .procmeterrc file in stead of the searching in the usual places. .TP .BR \-\-... A list of configuration file options that will override the values in the .B .procmeterrc file. The format of these options is (for example) .I \-\-LCD.host=localhost which is equivalent to the entry in the .procmeterrc file of [LCD] host = localhost All spaces around the equal sign must be removed and if spaces are required in the value on the right hand side then quotes must be used around the entire command line option. .TP .BR ... A list of names of outputs that are to be displayed. This can include any of the outputs that are available (see the \-h option). For the CPU usage is in a module named .B Statistics with an output named .B CPU and there are graph (\-g), text (\-t) and bar (\-b) options. To display the CPU usage graph you would use the command line option .B Statistics.CPU-g .SH USAGE When started the program will display on an attached LCD display using the LCDd daemon program (from http://lcdproc.omnipotent.net). The outputs that are displayed are those from the command line and those from the .B .procmeterrc configuration file. .SH MODULES The modules that are available for procmeter3-lcd are described in the procmeter3_modules(1) manual page. .SH SEE ALSO procmeterrc(5) procmeter3_modules(1) .SH AUTHOR Andrew M. Bishop 1998-2007 procmeter3-3.5d/man/procmeter3-log.1000066400000000000000000000053361165060751200173210ustar00rootroot00000000000000.\" $Header: /home/amb/CVS/procmeter3/man/procmeter3-log.1,v 1.6 2010-07-03 12:55:30 amb Exp $ .\" .\" ProcMeter - A system monitoring program for Linux - Version 3.5d. .\" .\" Manual page for procmeter3-log program. .\" .\" Written by Andrew M. Bishop .\" .\" This file Copyright 1998-2010 Andrew M. Bishop .\" It may be distributed under the GNU Public License, version 2, or .\" any higher version. See section COPYING of the GNU Public license .\" for conditions under which this file may be redistributed. .\" .TH PROCMETER3-LOG 1 "July 3, 2010" .SH NAME procmeter3-log \- A system monitoring / logging program. .SH SYNOPSIS .B procmeter3-log .I [\-h|\-\-help] .I [\-\-rc=] [\-\-...] .I [...] .SH DESCRIPTION .I ProcMeter Displays one or more pieces of information about the operating system and other resources. Most of the information that is displayed comes from the /proc filesystem. The program is modular and very configurable. .SH OPTIONS The command line options are described below. .TP .BR \-h Provides a help message listing the available outputs. This will be different for different computers depending on the Linux kernel version that is being used and the hardware/software that is configured. .TP .BR \-\-rc= Load the specified .B .procmeterrc file in stead of the searching in the usual places. .TP .BR \-\-... A list of configuration file options that will override the values in the .B .procmeterrc file. The format of these options is (for example) .I \-\-library.path=/usr/local/procmeter3 which is equivalent to the entry in the .procmeterrc file of [library] path = /usr/local/procmeter3 All spaces around the equal sign must be removed and if spaces are required in the value on the right hand side then quotes must be used around the entire command line option. .TP .BR ... A list of names of outputs that are to be displayed. This can include any of the outputs that are available (see the \-h option). For the CPU usage is in a module named .B Statistics with an output named .B CPU and there are graph (\-g), text (\-t) and bar (\-b) options. Since this version of the program does not display anything, but logs the data to a file it does not matter which one is chosen. To store the CPU usage data you would use the command line option .B Statistics.CPU-t .SH USAGE When started the program will log all of the requested information on the standard output (stdout). The outputs that are displayed are those from the command line and those from the .B .procmeterrc configuration file. .SH MODULES The modules that are available for procmeter3-log are described in the procmeter3_modules(1) manual page. .SH SEE ALSO procmeterrc(5) procmeter3_modules(1) .SH AUTHOR Andrew M. Bishop 1998-2007 procmeter3-3.5d/man/procmeter3-xaw.1000066400000000000000000000000261165060751200173260ustar00rootroot00000000000000.so man1/procmeter3.1 procmeter3-3.5d/man/procmeter3.1000066400000000000000000000126041165060751200165360ustar00rootroot00000000000000.\" $Header: /home/amb/CVS/procmeter3/man/procmeter3.1,v 1.18 2010-07-03 12:55:30 amb Exp $ .\" .\" ProcMeter - A system monitoring program for Linux - Version 3.5d. .\" .\" Manual page for procmeter3 program. .\" .\" Written by Andrew M. Bishop .\" .\" This file Copyright 1998-2010 Andrew M. Bishop .\" It may be distributed under the GNU Public License, version 2, or .\" any higher version. See section COPYING of the GNU Public license .\" for conditions under which this file may be redistributed. .\" .TH PROCMETER3 1 "July 3, 2010" .SH NAME procmeter3, procmeter3-xaw \- A user friendly system monitoring program. .SH SYNOPSIS .B procmeter3|procmeter3-xaw .I [\-w [,]] .I [\-h|\-\-help] .I [\-\-rc=] [\-\-...] .I [...] .I [X \ windows \ options] .SH DESCRIPTION .I ProcMeter Displays one or more pieces of information about the operating system and other resources. Most of the information that is displayed comes from the /proc filesystem. The program is modular and very configurable. .SH OPTIONS The command line options are described below. .TP .BR \-h Provides a help message listing the available outputs. This will be different for different computers depending on the Linux kernel version that is being used and the hardware/software that is configured. .TP .BR \-w Gives Extended Window Manager hints (EWMH) to change the way that the Window Manager treats the ProcMeter3 window. Implemented hints are: above, below, skip_pager, skip_taskbar, sticky. You can give more than one hint separated by commas (e. g. \-w above,skip_taskbar,sticky), or use \-w multiple times (e. g. \-w above \-w sticky). .BR .TP .BR \-\-rc= Load the specified .B .procmeterrc file in stead of the searching in the usual places. .TP .BR \-\-... A list of configuration file options that will override the values in the .B .procmeterrc file. The format of these options is (for example) .I \-\-resources.background=grey50 which is equivalent to the entry in the .procmeterrc file of [resources] background = grey50 All spaces around the equal sign must be removed and if spaces are required in the value on the right hand side then quotes must be used around the entire command line option. .TP .BR ... A list of names of outputs that are to be displayed. This can include any of the outputs that are available (see the \-h option). For the CPU usage is in a module named .B Statistics with an output named .B CPU and there are graph (\-g), text (\-t) and bar (\-b) options. To display the CPU usage graph you would use the command line option .B Statistics.CPU-g .TP .BR X \ windows \ options The standard set of X Windows program options, see X(1) for information. These include .B -geometry to set the size of the window, .B -display to set the display and other general X window options. .SH USAGE When started the program will display all of the requested information in a set of output panels (vertically aligned by default). Each output can be either a graph, text or bar, and can have a label indicating what it represents. The outputs that are displayed are those from the command line and those from the .B .procmeterrc configuration file. .LP The left mouse button will produce a menu of options that are specific to the output that is selected. The .B Properties option on this menu will give more detailed information about the origin and meaning of the information that is displayed. When the properties information window is displayed, clicking on another output will change the displayed information. The .B Move to Above and .B Move to Below options allow the output to be moved around in the window. Selecting one of these options will change the mouse cursor to a hand, use this to select another output. The output that was selected first will be moved to above or below the output that was selected second. The .B Run option on the menu (which may not be available on all outputs) will run the specified command. This may be to display a list of running processes, show the amount of free memory or disk space for example. This menu option is configurable in the .B .procmeterrc file. .LP The right mouse button will produce a set of menus that list the modules that are available and for each of them the available set of outputs. There are three types of output, text and two graphical outputs, these are indicated in the sub-menus by icons. Selecting one of the outputs from a sub-menu will cause that output to be displayed if it is not already visible. If it is currently displayed then it will be disabled. Those that are currently displayed are indicated by a marker to the left in the sub-menu. When the output is added to the window it will be placed at the bottom, use the left mouse button to move it if required. .LP The middle mouse button will display the sub-menu that is associated with the module for the output that is selected. This is one of sub-menus that are found with the right mouse button. .SH MODULES The modules that are available for procmeter3 and procmeter3-xaw are described in the procmeter3_modules(1) manual page. .SH X RESOURCES As with all X Window programs X resources can be used. For this version of ProcMeter (compared to previous versions) this is not the default method of configuring the program. The file $HOME/.procmeterrc contains the configuration information. .SH SEE ALSO X(1) procmeterrc(5) procmeter3_modules(1) .SH AUTHOR Andrew M. Bishop 1998-2008 procmeter3-3.5d/man/procmeter3_modules.1000066400000000000000000000156251165060751200202740ustar00rootroot00000000000000.\" ProcMeter - A system monitoring program for Linux - Version 3.5d. .\" .\" Manual page for ProcMeter modules. .\" .\" Written by Andrew M. Bishop .\" .\" This file Copyright 1998-2011 Andrew M. Bishop .\" It may be distributed under the GNU Public License, version 2, or .\" any higher version. See section COPYING of the GNU Public license .\" for conditions under which this file may be redistributed. .\" .TH PROCMETER3_MODULES 1 "July 3, 2010" .SH NAME procmeter3_modules \- The modules that are used by the procmeter3, procmeter3-xaw, gprocmeter3, procmeter3-gtk1, procmeter3-gtk2, procmeter3-log and procmeter3-lcd programs. .SH DESCRIPTION The ProcMeter3 programs provide a framework that allows displaying of information in various formats. The collection of the data to be displayed is performed by a set of loadable modules. .SH MODULES The modules that are provided with the program are the following: .TP .BR APM Advanced Power Management information. These outputs are only available if you have configured the Linux kernel to have the APM feature and you have the appropriate hardware. The outputs can tell you the amount of time remaining and the state of charge of the battery. .TP .BR Biff Monitors the e-mail inbox (in .B /var/spool/mail/ or .B /var/mail/ ) and indicates the number of e-mails that are waiting and the size of the inbox. The .I options parameter in the .B .procmeterrc file can be used to specify an alternate filename to use for the inbox. .TP .BR Date_Time The current date and time and the amount of time since the system was last booted. Different outputs are available that allow the format of the date and time information to be changed. For the time outputs the .I options parameter in the .B .procmeterrc file can be set to 12 to indicate that a 12 hour format with AM/PM is to be used. .TP .BR DiskUsage Shows the percentage of the disk that is used and the amount of free space for each of the local disks that it finds are mounted or can be mounted when the program starts. Extra disks can be passed as options using the .I options parameter in the .B .procmeterrc file to contain a space separated list of mount points. .TP .BR LogFile Monitors the size and number of lines and the rate of increase of the size or number of lines in a set of log files. The .I options parameter in the .B .procmeterrc file contains a space separated list of log file names. .TP .BR Memory The amount of memory that is used for programs, buffers, cache and the amount that is free. This is the same information that is available from the .B free program, but is available here as a graph, bar or as text. .TP .BR Network The network devices and the amount of traffic on each of them. It will automatically pick up available devices when it starts. To specify others use the .I options parameter in the .B .procmeterrc configuration file which is a space separated list of device names. .TP .BR Processes The load average and the number of processes running and starting. .TP .BR ProcMeter Information about the procmeter program itself. .TP .BR Sensors Information from hardware sensors for temperature and fan speed (simple version with fixed scaling). .TP .BR FanSpeed Information from hardware sensors for fan speed (requires libsensors library installed but does read sensors.conf file for system customisation). The .I options parameter in the .B .procmeterrc file can be used to specify an alternate sensors configuration filename to use instead of the default. If this is used then it must be used in each of the FanSpeed, Temperature and Voltage modules. .TP .BR Temperature Information from hardware sensors for temperature (requires libsensors library installed but does read sensors.conf file for system customisation). The .I options parameter in the .B .procmeterrc file can be used to specify an alternate sensors configuration filename to use instead of the default. If this is used then it must be used in each of the FanSpeed, Temperature and Voltage modules. .TP .BR Voltage Information from hardware sensors for voltages (requires libsensors library installed but does read sensors.conf file for system customisation). The .I options parameter in the .B .procmeterrc file can be used to specify an alternate sensors configuration filename to use instead of the default. If this is used then it must be used in each of the FanSpeed, Temperature and Voltage modules. .TP .BR Statistics Low level system statistics. For example CPU usage, context switches, interrupts, disk usage (before kernel 2.6), swapping and paging (before kernel 2.6). .TP .BR Stat-CPU More detailed statistics about individual CPU usage including individual CPU usage for SMP machines. .TP .BR Stat-Disk More detailed statistics about individual disk usage read and write. For older Linux kernels (before version 2.4) there is only support for up to 4 disks (this limit is set by the kernel and not by ProcMeter). For version 2.4 or later kernels the limit is removed and the disk names are picked up when the program starts. For version 2.6 or later kernels individual partitions are available. To force other disks to be listed use the .I options parameter in the .B .procmeterrc configuration file which is a space separated list of device names (e.g. /dev/fd0). .TP .BR Stat-Intr More detailed statistics about individual interrupts including support for up to 256 interrupts. If fewer interrupts are wanted then the .I options parameter in the .B .procmeterrc configuration file can be set to the maximum number to display. .TP .BR Uname The system information, hostname and Linux kernel version, the same as the output of the .B uname program. .TP .BR Wireless Information about wireless network devices. It will automatically pick up available devices when it starts. To specify others use the .I options parameter in the .B .procmeterrc configuration file which is a space separated list of device names. .TP .BR Longrun For systems with the Transmeta Crueso processor, information about longrun. Will not work unless the kernel is compiled with CPUID support, and /dev/cpu/0/cpuid must be readable by ProcMeter. (Allow regular users to access the cpuid device at your own risk!) .TP .BR ACPI Advanced Configuration and Power Interface information. These outputs are only available if you have enabled ACPI in the Linux kernel and you have the appropriate hardware. ACPI can report various information about a system's battery, and may also have thermal outputs available. .TP .BR VM_Statistics Low level system statistics about virtual memory (swapping and paging) for kernel version 2.6 where the information has moved from the Statistics section. .TP .BR CPUInfo Information about the CPUs in the system, currently only the CPU speed in MHz. .SH SEE ALSO procmeter3(1), procmeter3-xaw(1), gprocmeter3(1), procmeter3-gtk1(1), procmeter3-gtk2(1), procmeter3-log(1), procmeter3-lcd(1), procmeterrc(5). .LP biff(1) free(1) uname(1) .SH AUTHOR Andrew M. Bishop 1998-2007 procmeter3-3.5d/man/procmeterrc.5000066400000000000000000000232071165060751200170050ustar00rootroot00000000000000.\" $Header: /home/amb/CVS/procmeter3/man/procmeterrc.5,v 1.19 2010-07-03 12:55:31 amb Exp $ .\" .\" ProcMeter - A system monitoring program for Linux - Version 3.5d. .\" .\" Manual page for .procmeterrc file .\" .\" Written by Andrew M. Bishop .\" .\" This file Copyright 1998-2010 Andrew M. Bishop .\" It may be distributed under the GNU Public License, version 2, or .\" any higher version. See section COPYING of the GNU Public license .\" for conditions under which this file may be redistributed. .\" .TH PROCMETERRC 5 "July 3, 2010" .SH NAME procmetetrc \- The procmeterrc configuration file for procmeter3, procmeter3-xaw, gprocmeter3, procmeter3-gtk1, procmeter3-gtk2, procmeter3-log and procmeter3-lcd programs. .SH SYNOPSIS This file contains the run-time options for the procmeter3, procmeter3-xaw, gprocmeter3, procmeter3-gtk1, procmeter3-gtk2, procmeter3-log and procmeter3-lcd programs. These include the outputs that are displayed, the colours and fonts that are used (for X window outputs), the LCDproc server (for the procmeter-lcd version) and other program options. .SH DESCRIPTION The resources for ProcMeter version 3.x are stored in the .procmeterrc file instead of using X resources. This gives more flexibility and allows for much simpler customisation. .LP When the procmeter3, procmeter3-xaw, gprocmeter3, procmeter3-gtk1, procmeter3-gtk2, procmeter3-log or procmeter3-lcd programs start the .B .procmeterrc file is searched for in the current directory, the current users home directory or the system default installation directory (named procmeterrc). The file is used from the first one of these locations that matches. .LP The format of the .B .procmeterrc file is a number of sections with the section names marked in '[]'. As well as the fixed sections (described below) there is a section for each module that is named using the name that the module reports itself to be. There are then further sections for each of the possible outputs of each module. The names of the sections and parameters are not case sensitive although the values that they are given may be. Lines beginning with the characters ';' or '#' are comments and continuation using the '\\' character at the end of a line is allowed. .LP Below is listed the resource values and the sections of the .B .procmeterrc file that they can exist in. .SH library SECTION This section contains the information about the ProcMeter modules that are available. This applies to all versions of the program. .TP .BR path=... The pathname of the library that contains the compiled ProcMeter modules. (defaults to the program's compiled-in installation location). .TP .BR others=... A list of other modules to be loaded (full pathnames separated by spaces). .LP .SH startup SECTION This section controls how the ProcMeter window should look when the program is started. .TP .BR order=... A list of the outputs that are to be started up in the order that they are to be displayed (separated by spaces). If command line options are also specified then they appear after those specified here. .SH resources SECTION This section contains the general program display resources. Not all of the options apply to all of the versions of the program. Specific versions that the options apply to are specified below. .TP .BR horizontal=... A Boolean to indicate that the outputs are stacked horizontally instead of the default which is vertically. (For X versions of procmeter3 only.) .TP .BR background=... The colour to use as the default background for all outputs. (An X11 colour name or an RGB value in hex as #RRGGBB.) (For X versions of procmeter3 only.) .TP .BR foreground=... The colour to use as the default foreground for all outputs. (An X11 colour name or an RGB value in hex as #RRGGBB.) (For X versions of procmeter3 only.) .TP .BR label-font=... The font to use for the label that describes the output. (An X11 font name.) (For X versions of procmeter3 only.) .TP .BR label-foreground=... The colour to use as the foreground for the label. (An X11 colour name or an RGB value in hex as #RRGGBB.) (For X versions of procmeter3 only.) .TP .BR label-position=... The position of the label relative to the body of the output. (Either top, bottom or none.) (For X versions of procmeter3 only.) .TP .BR grid-foreground=... The colour to use for the grid lines. (An X11 colour name or an RGB value in hex as #RRGGBB.) (For X versions of procmeter3 only.) .TP .BR graph-solid=... A boolean to indicate if the graph should be solid (the default) or a single line. (yes or no, true or false, 0 or 1.) (For X versions of procmeter3 only.) .TP .BR grid-min=... The minimum number of grid lines to display on a graph or bar chart. (An integer.) (For X and LCD versions of procmeter3 only.) This is particularly important with the bar chart because with this set too low the bar will always be the same length on screen and the number of grid lines will change with the data. .TP .BR grid-max=... The maximum number of grid lines to display on a graph or bar chart. (An integer.) (For X and LCD versions of procmeter3 only.) .TP .BR text-font=... The font to use for the textual outputs. (An X11 font name.) (For X versions of procmeter3 only.) .TP .BR menu-foreground=... The colour to use as the foreground for the menus. (An X11 colour name or an RGB value in hex as #RRGGBB.) (For procmeter3 and procmeter3-xaw only.) .TP .BR menu-background=... The colour to use as the background for the menus. (An X11 colour name or an RGB value in hex as #RRGGBB.) (For procmeter3 and procmeter3-xaw only.) (The background of all items on the same menu must be the same due to the Xaw Widget set used.) .TP .BR menu-font=... The font to use for the menus. (An X11 font name.) (For procmeter3 and procmeter3-xaw only.) .TP .BR update=... The update interval for the output in seconds (an integer). .LP .SH LCD SECTION This section contains parameters that are only used by the procmeter3-lcd version of the program. .TP .BR host=... The name of the host that the LCDd daemon is running on. .TP .BR port=... The port number that the LCDd daemon is running on. .TP .BR duration=... The length of time that all of the ProcMeter outputs are displayed on the LCD display for before cycling to the next. .TP .BR priority=... The priority of all of the ProcMeter outputs when they are displayed on the LCD display. This values should be a numeric value for LCDd verions before 0.5 or priority names for later versions. Using numeric values will likely fail for LCDd versions after 0.5 due to a bug in LCDd. The safest solution is not to use this option unless you are sure what value to use. .SH MODULE SECTION The name of the section is the name of the ProcMeter module (see the help, procmeter3 \-h), for example: .I ProcMeter .LP These can contain any of the resource values which will then apply to all outputs of this module. There are also extra options that can be applied to the module and as defaults for the all of the outputs of that module. .TP .BR options=... A string containing options that are passed to the module at startup, different modules have different options, see the procmeter3_modules(1) manual page. .TP .BR graph-scale=... The scaling of the graph or bar chart, the number of units between each of the grid lines (an integer). .TP .BR run=... A string that specifies a program that can be run by selecting it from the menu for the left mouse button. (For X versions of procmeter3 only.) The way that the command is run can be specified using one of the following abbreviations; .B XTerm( .I command .B ) to run .I command in an .B xterm then exit. .B XTermWait( .I command .B ) to run .I command in an .B xterm and wait for user input before exiting. .B Shell( .I command .B ) to run .I command in an .B shell and exit. This last one is equivalent to using none of these abbreviations. .LP .SH OUTPUT SECTION The name of the section is the name of the ProcMeter output (see the help, procmeter3 \-h), for example: .I ProcMeter.Version .LP The output sections can contain any of the resource or module options (except \'options') which will then apply only to the specified output. There are also options that can only be applied to individual outputs. .TP .BR label=... Changes the default label for the output to the specified string. .SH EXAMPLE Below is an example .B .procmeterrc file, it is a much reduced version of the system default procmeterrc file. [startup] # ProcMeter version, clock, CPU graph, load text order=ProcMeter.Version Date_Time.Time_HM \\ Statistics.CPU-g Processes.Load-t [resources] # The outputs, black on white foreground = black background = white # A large-medium size text font. text-font = 8x13 # Solid graphs with at least 5 grid lines in grey. graph-solid = yes grid-min = 5 grid-foreground = grey50 # Black on white output labels, small font, below the data. label-font = 5x7 label-foreground = black label-position = bottom # Black on white menu items in a small-medium size font. menu-foreground = black menu-background = white menu-font = 7x13 [ProcMeter.Version] # A smaller font than normal with no label. text-font = 6x10 label-position = none [Statistics] [Statistics.CPU] # The minimum number of grid lines, they are 20% each. grid-min = 5 [Processes] run = XTerm(top) [Network] # To pick up extra devices not automatically recognised. #options=ppp0 slip0 .SH FILES .B ./.procmeterrc .LP .B ~/.procmeterrc .LP .B /usr/local/lib/X11/ProcMeter3/procmeterrc or .B /usr/lib/X11/ProcMeter3/procmeterrc .SH SEE ALSO procmeter3(1), procmeter3-xaw(1), gprocmeter3(1), procmeter3-gtk1(1), procmeter3-gtk2(1), procmeter3-log(1), procmeter3-lcd(1), procmeter3_modules(1). .SH AUTHOR Andrew M. Bishop 1998-2007 procmeter3-3.5d/module.c000066400000000000000000000234731165060751200152550ustar00rootroot00000000000000/*************************************** ProcMeter - A system monitoring program for Linux - Version 3.5d. Module handling functions. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2011 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include #include #include "procmeter.h" #include "procmeterp.h" /*+ The list of all of the modules. +*/ Module *Modules=NULL; /*++++++++++++++++++++++++++++++++++++++ Load in all of the modules in the library directory. ++++++++++++++++++++++++++++++++++++++*/ void LoadAllModules(void) { DIR *dir; struct dirent* ent; struct stat buf; char lib[PATH_MAX+1],*libp; char *library; int i; Modules=(Module*)malloc(16*sizeof(Module)); *Modules=NULL; /* set LC_NUMERIC to C, else 0.1 in /proc/loadavg may not be parsed */ setlocale(LC_NUMERIC, "C"); /* Load the library modules */ if(!(library=GetProcMeterRC("library","path"))) library=MOD_PATH; strcpy(lib,library); libp=lib+strlen(lib)-1; if(*libp!='/') *++libp='/'; *++libp=0; if(stat(library,&buf) || !S_ISDIR(buf.st_mode)) { fprintf(stderr,"ProcMeter: The library directory '%s' does not exist or is not a directory.\n",library); exit(1); } dir=opendir(library); if(!dir) { fprintf(stderr,"ProcMeter: The library directory '%s' cannot be opened.\n",library); exit(1); } while((ent=readdir(dir))) if(!strcmp(ent->d_name+strlen(ent->d_name)-3,".so")) { strcpy(libp,ent->d_name); LoadModule(lib); } closedir(dir); /* Load the other modules. */ if((library=GetProcMeterRC("library","others"))) { char *l=library; if(!getcwd(lib,PATH_MAX)) { fprintf(stderr,"ProcMeter: Cannot get current directory name.\n"); exit(1); } libp=lib+strlen(lib)-1; if(*libp!='/') *++libp='/'; *++libp=0; while(*l && *l==' ') l++; while(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; if(*l=='/') LoadModule(l); else { strcpy(libp,l); LoadModule(lib); } *r=pr; while(*r && *r==' ') r++; if(!*r) break; l=r; } } /* Add to the menus */ for(i=0;Modules[i];i++) AddModuleToMenu(Modules[i]); } /*++++++++++++++++++++++++++++++++++++++ Unload all of the modules. ++++++++++++++++++++++++++++++++++++++*/ void UnloadAllModules(void) { while(*Modules) { UnloadModule(*Modules); } free(Modules); } /*++++++++++++++++++++++++++++++++++++++ Load the specified module. Module LoadModule Returns a pointer to the new module structure, or NULL on error. char* filename The filename of the module to load. ++++++++++++++++++++++++++++++++++++++*/ Module LoadModule(char* filename) { ProcMeterModule *(*Load)(void); ProcMeterOutput **(*Initialise)(char *),**outputs,*output; Module new=NULL; int noutputs,i,m,c; new=(Module)malloc(sizeof(struct _Module)); new->filename=(char*)malloc(strlen(filename)+1); strcpy(new->filename,filename); new->dlhandle=dlopen(filename,RTLD_NOW); if(!new->dlhandle) { fprintf(stderr,"ProcMeter: Cannot open the module '%s' : %s\n",new->filename,dlerror()); free(new->filename); free(new); return(NULL); } /* Get the Load() function and call it */ Load=dlsym(new->dlhandle,"Load"); if(!Load) { fprintf(stderr,"ProcMeter: Cannot get the symbol 'Load' from '%s' : %s\n",new->filename,dlerror()); dlclose(new->dlhandle); free(new->filename); free(new); return(NULL); } if(!(new->module=(*Load)())) { fprintf(stderr,"ProcMeter: Error calling 'Load()' in module '%s'\n",new->filename); dlclose(new->dlhandle); free(new->filename); free(new); return(NULL); } for(m=-1,i=0;Modules[i];i++) if(!(c=strcmp(Modules[i]->module->name,new->module->name))) { fprintf(stderr,"ProcMeter: Duplicate module name '%s' ignoring '%s'.\n",new->module->name,new->filename); dlclose(new->dlhandle); free(new->filename); free(new); return(NULL); } else if(c<0) m=i; /* Get the Intialise() fuction and call it. */ Initialise=dlsym(new->dlhandle,"Initialise"); if(!Initialise) { fprintf(stderr,"ProcMeter: Cannot get the symbol 'Initialise' from '%s' : %s\n",new->filename,dlerror()); dlclose(new->dlhandle); free(new->filename); free(new); return(NULL); } if(!(outputs=(*Initialise)(GetProcMeterRC(new->module->name,"options")))) { fprintf(stderr,"ProcMeter: Error Calling 'Initialise()' in module '%s'\n",new->filename); dlclose(new->dlhandle); free(new->filename); free(new); return(NULL); } /* Get the Update() function. */ new->Update=dlsym(new->dlhandle,"Update"); if(!new->Update) { fprintf(stderr,"ProcMeter: Cannot get the symbol 'Update' from '%s' : %s\n",new->filename,dlerror()); dlclose(new->dlhandle); free(new->filename); free(new); return(NULL); } /* Insert the new module. */ Modules=(Module*)realloc((void*)Modules,(i+2)*sizeof(Module)); memmove(Modules+m+2, Modules+m+1, (i-m)*sizeof(Module)); Modules[m+1]=new; /* Add the outputs */ for(noutputs=0,i=0,output=outputs[i];output;output=outputs[++i]) { int t=output->type; while(t) { if(t&1) noutputs++; t>>=1; } } new->outputs=(Output*)malloc((noutputs+1)*sizeof(Output)); new->outputs[noutputs]=NULL; for(noutputs=0,i=0,output=outputs[i];output;output=outputs[++i]) { int t=1; while(t<=output->type) { if(output->type&t) { char *string; if((string=GetProcMeterRC2(new->module->name,output->name,"update")) || (string=GetProcMeterRC(new->module->name,"update")) || (string=GetProcMeterRC("resources","update"))) output->interval=atoi(string); if((string=GetProcMeterRC2(new->module->name,output->name,"graph-scale")) || (string=GetProcMeterRC(new->module->name,"graph-scale"))) output->graph_scale=atoi(string); new->outputs[noutputs]=(Output)malloc(sizeof(struct _Output)); new->outputs[noutputs]->output=output; new->outputs[noutputs]->type=t; new->outputs[noutputs]->first=0; new->outputs[noutputs]->menu_item_widget=NULL; new->outputs[noutputs]->output_widget=NULL; if(!(string=GetProcMeterRC2(new->module->name,output->name,"run"))) string=GetProcMeterRC(new->module->name,"run"); ParseRunCommand(string,&new->outputs[noutputs]->menu_run); if(!(string=GetProcMeterRC2(new->module->name,output->name,"label"))) { static char newstr[PROCMETER_NAME_LEN+1]; int i; for(i=0;output->name[i];i++) if(output->name[i]=='_') newstr[i]=' '; else newstr[i]=output->name[i]; newstr[i]=0; string=newstr; } strncpy(new->outputs[noutputs]->label,string,PROCMETER_NAME_LEN+1); new->outputs[noutputs]->label[PROCMETER_NAME_LEN]=0; noutputs++; } t<<=1; } } new->menu_item_widget=NULL; new->submenu_widget=NULL; return(new); } /*++++++++++++++++++++++++++++++++++++++ Unload a module when we exit. Module module The module that is to be unloaded. ++++++++++++++++++++++++++++++++++++++*/ void UnloadModule(Module module) { void (*Unload)(void); Module *modules; RemoveModuleFromMenu(module); Unload=dlsym(module->dlhandle,"Unload"); if(Unload) (*Unload)(); dlclose(module->dlhandle); /* Shuffle the modules down and tidy up. */ modules=Modules; while(*modules) { if(*modules==module) while(*modules) { *modules=*(modules+1); modules++; } else modules++; } if(module->outputs) { int i; Output output; for(output=module->outputs[i=0];output;output=module->outputs[++i]) { if(output->menu_run.command) free(output->menu_run.command); free(output); } free(module->outputs); } free(module->filename); free(module); } #define INCSIZE 256 /*+ The buffer increment size +*/ /*++++++++++++++++++++++++++++++++++++++ Call fgets and realloc the buffer as needed to get a whole line. char *fgets_realloc Returns the modified buffer (NULL at the end of the file). char **buffer A pointer to the location of the buffer (pointer to NULL to intialise a new one). size_t *length A pointer to the current length of the buffer or the intial length if buffer is NULL. FILE *file The file to read from. ++++++++++++++++++++++++++++++++++++++*/ char *fgets_realloc(char **buffer,size_t *length,FILE *file) { int n=0; char *buf; if(!*buffer) { if(!*length) *length=INCSIZE; *buffer=(char*)malloc(*length); if(!*buffer) {*length=0;return(NULL);} } while((buf=fgets(*buffer+n,*length-n,file))) { int s=strlen(buf); n+=s; if((*buffer)[n-1]=='\n') break; else { char *newbuffer; *length+=INCSIZE; newbuffer=(char*)realloc(*buffer,*length); if(!newbuffer) {free(*buffer);*buffer=NULL;*length=0;return(NULL);} else *buffer=newbuffer; } } if(!buf) {**buffer=0;return(NULL);} else return(*buffer); } procmeter3-3.5d/modules/000077500000000000000000000000001165060751200152635ustar00rootroot00000000000000procmeter3-3.5d/modules/Makefile000066400000000000000000000030531165060751200167240ustar00rootroot00000000000000# # ProcMeter - A system monitoring program for Linux - Version 3.5d. # # Makefile for the modules. # # Written by Andrew M. Bishop # # This file Copyright 1994-2011 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Paths (overridden by main Makefile) INSTDIR=/usr/local LIB_PATH=$(INSTDIR)/lib/X11/ProcMeter3 MOD_PATH=$(LIB_PATH)/modules # Programs CC=gcc LD=gcc # Program options (overridden by main Makefile) CFLAGS=-g -O2 -Wall LDFLAGS= # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) LIB=$(foreach f,$(SRC),$(addsuffix .so,$(basename $f))) ######## all : $(OBJ) $(LIB) ######## libsensors-%.o:libsensors-%.c ./check-no-libsensors.sh '$(CC)' '$(CFLAGS)' || $(CC) -c $(CFLAGS) $< -o $@ -I.. -fPIC libsensors-%.so:libsensors-%.o [ ! -f $< ] || $(LD) $(LDFLAGS) $< -lsensors -o $@ -shared %.o:%.c ../procmeter.h $(CC) -c $(CFLAGS) $< -o $@ -I.. -fPIC %.so:%.o $(LD) $(LDFLAGS) $< -o $@ -shared ######## .PHONY : clean distclean clean : -rm -f *.o *~ core distclean : clean -rm -f *.so ######## .PHONY : install install : install -d $(DESTDIR)$(MOD_PATH) install -d $(DESTDIR)$(LIB_PATH)/example for module in *.so ; do \ [ $$module = template.so ] || install $(STRIP) -m 755 $$module $(DESTDIR)$(MOD_PATH) ;\ done install -m 644 README $(DESTDIR)$(LIB_PATH)/example install -m 644 template.c $(DESTDIR)$(LIB_PATH)/example procmeter3-3.5d/modules/README000066400000000000000000000053521165060751200161500ustar00rootroot00000000000000 ProcMeter - Version 3.1 - Modules ================================= In version 3.x of ProcMeter the different outputs (graphs or text) are implemented as loadable modules. Version 3.1 changes ------------------- The graph_units field is now a printf string that is filled in at run time with the value of the graph_scale field. Interface --------- To be used in ProcMeter they must follow a few simple rules that allows the ProcMeter program load them and interact with them. 1) The Load() function. There must be a function with the following prototype: ProcMeterModule *Load(void); This function will be the first one in the module that is called. It will only be called once, if it does not exist then the module will not be loaded. The purpose of the function is to initialise the module and return information to the main program so that the initialisation can proceed. 2) The Initialise() function There must be a function with the following prototype: ProcMeterOutput **Initialise(char *options); This function will be called once only, following the Load() function. The purpose of the module is to initialise all of the outputs and return the information about them to the main program as a NULL terminated array. The 'options' parameter is a string that is taken from the .procmeterrc file for the module. 3) The Update() function There must be a function with the following prototype: int Update(time_t now,ProcMeterOutput *output); This function is called each time that one of the outputs needs to be updated. The parameter 'now' is the current time and may be the same on different calls to the function or it may be higher, it never decreases. The 'output' parameter is a pointer to one of the outputs that were returned in the Initialise() function. This output is to have its information filled in (both text and graph if appropriate). If the Update function is succesful it should return 0, if there is an error it should set the output values to a suitable value and return -1. 4) The Unload() function There can be a function with the following prototype: void Unload(void); If it exists then it is called after all of the other functions, before the module is unloaded. It is only ever called once. Compilation ----------- The module must be compiled to be a loadable object. If the source file name is template.c then the following commands will do that. gcc -c -O template.c -o template.o -I.. -fPIC ld template.o -o template.so -shared Example ------- As an example the file template.c is a very simple example of a module. It can be used as the basis for other modules since the basic file structure is present. Andrew M. Bishop 12th Feb 1999 procmeter3-3.5d/modules/acpi.c000066400000000000000000000615751165060751200163610ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/acpi.c,v 1.17 2010-02-28 10:22:11 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. ACPI source file. ******************/ /****************** Written by Joey Hess. This file Copyright 2001-2007 Joey Hess It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #define ACPI_THERMAL 1 /****************** Begin acpi.c **********************************/ /* * A not-yet-general-purpose ACPI library, by Joey Hess */ #include #include #include #include #include #include #ifdef ACPI_APM #include "apm.h" #endif #include #include #include #include "acpi.h" #define PROC_ACPI "/proc/acpi" #define ACPI_MAXITEM 8 int acpi_batt_count = 0; /* Filenames of the battery info files for each system battery. */ char acpi_batt_info[ACPI_MAXITEM][128]; /* Filenames of the battery status files for each system battery. */ char acpi_batt_status[ACPI_MAXITEM][128]; /* Stores battery capacity, or 0 if the battery is absent. */ int acpi_batt_capacity[ACPI_MAXITEM]; int acpi_ac_count = 0; char acpi_ac_adapter_info[ACPI_MAXITEM][128]; char acpi_ac_adapter_status[ACPI_MAXITEM][128]; /* These are the strings used in the ACPI shipped with the 2.4 kernels */ char *acpi_labels_old[] = { "info", "status", "battery", "ac_adapter", "on-line", "Design Capacity:", "Present:", "Remaining Capacity:", "Present Rate:", "State:", #if ACPI_THERMAL "thermal", #endif "Status:", NULL }; /* These are the strings used in ACPI in the 2.5 kernels, circa version * 20020214 */ char *acpi_labels_20020214[] = { "info", "state", "battery", "ac_adapter", "on-line", "design capacity:", "present:", "remaining capacity:", "present rate:", "charging state:", #if ACPI_THERMAL "thermal_zone", #endif "state:", "last full capacity:", NULL }; char **acpi_labels = NULL; #if ACPI_THERMAL int acpi_thermal_count = 0; char acpi_thermal_info[ACPI_MAXITEM][128]; char acpi_thermal_status[ACPI_MAXITEM][128]; #endif /* Read in an entire ACPI proc file (well, the first 1024 bytes anyway), and * return a statically allocated array containing it. */ inline char *get_acpi_file (const char *file) { int fd; int end; static char buf[1024]; fd = open(file, O_RDONLY); if (fd == -1) return NULL; end = read(fd, buf, sizeof(buf)); buf[end-1] = '\0'; close(fd); return buf; } /* Given a buffer holding an acpi file, searches for the given key in it, * and returns the numeric value. 0 is returned on failure. */ inline int scan_acpi_num (const char *buf, const char *key) { char *ptr; int ret; if ((ptr = strstr(buf, key))) { if (sscanf(ptr + strlen(key), "%d", &ret) == 1) return ret; } return 0; } /* Given a buffer holding an acpi file, searches for the given key in it, * and returns its value in a statically allocated string. */ inline char *scan_acpi_value (const char *buf, const char *key) { char *ptr; static char ret[256]; if ((ptr = strstr(buf, key))) { if (sscanf(ptr + strlen(key), "%255s", ret) == 1) return ret; } return NULL; } /* Read an ACPI proc file, pull out the requested piece of information, and * return it (statically allocated string). Returns NULL on error, This is * the slow, dumb way, fine for initialization or if only one value is needed * from a file, slow if called many times. */ char *get_acpi_value (const char *file, const char *key) { char *buf = get_acpi_file(file); if (! buf) return NULL; return scan_acpi_value(buf, key); } /* Returns the maximum capacity of a battery. * * Note that this returns the highest possible capacity for the battery, * even if it can no longer charge that fully. So normally it uses the * design capacity. While the last full capacity of the battery should * never exceed the design capacity, some silly hardware might report * that it does. So if the last full capacity is greater, it will be * returned. */ int get_acpi_batt_capacity(int battery) { int dcap, lcap; char *s; s=get_acpi_value(acpi_batt_info[battery], acpi_labels[label_design_capacity]); if (s == NULL) dcap=0; /* battery not present */ else dcap=atoi(s); /* This is ACPI's broken way of saying that there is no battery. */ if (dcap == 655350) return 0; s=get_acpi_value(acpi_batt_info[battery], acpi_labels[label_last_full_capacity]); if (s != NULL) { lcap=atoi(s); if (lcap > dcap) return lcap; } return dcap; } /* Comparison function for qsort. */ int _acpi_compare_strings (const void *a, const void *b) { const char **pa = (const char **)a; const char **pb = (const char **)b; return strcasecmp((const char *)*pa, (const char *)*pb); } /* Find something (batteries, ac adpaters, etc), and set up a string array * to hold the paths to info and status files of the things found. * Returns the number of items found. */ int find_items (char *itemname, char infoarray[ACPI_MAXITEM][128], char statusarray[ACPI_MAXITEM][128]) { DIR *dir; struct dirent *ent; int num_devices=0; int i; char **devices = malloc(ACPI_MAXITEM * sizeof(char *)); char pathname[128]; sprintf(pathname,PROC_ACPI "/%s",itemname); dir = opendir(pathname); if (dir == NULL) return 0; while ((ent = readdir(dir))) { if (!strcmp(".", ent->d_name) || !strcmp("..", ent->d_name)) continue; devices[num_devices]=strdup(ent->d_name); num_devices++; if (num_devices >= ACPI_MAXITEM) break; } closedir(dir); /* Sort, since readdir can return in any order. /proc/ does * sometimes list BATT2 before BATT1. */ qsort(devices, num_devices, sizeof(char *), _acpi_compare_strings); for (i = 0; i < num_devices; i++) { sprintf(infoarray[i], PROC_ACPI "/%s/%s/%s", itemname, devices[i], acpi_labels[label_info]); sprintf(statusarray[i], PROC_ACPI "/%s/%s/%s", itemname, devices[i], acpi_labels[label_status]); free(devices[i]); } return num_devices; } /* Find batteries, return the number, and set acpi_batt_count to it as well. */ int find_batteries(void) { int i; acpi_batt_count = find_items(acpi_labels[label_battery], acpi_batt_info, acpi_batt_status); for (i = 0; i < acpi_batt_count; i++) acpi_batt_capacity[i] = get_acpi_batt_capacity(i); return acpi_batt_count; } /* Find AC power adapters, return the number found, and set acpi_ac_count to it * as well. */ int find_ac_adapters(void) { acpi_ac_count = find_items(acpi_labels[label_ac_adapter], acpi_ac_adapter_info, acpi_ac_adapter_status); return acpi_ac_count; } #if ACPI_THERMAL /* Find thermal information sources, return the number found, and set * thermal_count to it as well. */ int find_thermal(void) { acpi_thermal_count = find_items(acpi_labels[label_thermal], acpi_thermal_info, acpi_thermal_status); return acpi_thermal_count; } #endif /* Returns true if the system is on ac power. Call find_ac_adapters first. */ int on_ac_power (void) { int i; for (i = 0; i < acpi_ac_count; i++) { char *online=get_acpi_value(acpi_ac_adapter_status[i], acpi_labels[label_ac_state]); if (online && strcmp(acpi_labels[label_online], online) == 0) return 1; else return 0; } return 0; } /* See if we have ACPI support and check version. Also find batteries and * ac power adapters. */ int acpi_supported (void) { char *version; DIR *dir; int num; if (!(dir = opendir(PROC_ACPI))) { return 0; } closedir(dir); /* If kernel is 2.6.21 or newer, version is in /sys/module/acpi/parameters/acpica_version */ version = get_acpi_file("/sys/module/acpi/parameters/acpica_version"); if (version == NULL) { version = get_acpi_value(PROC_ACPI "/info", "ACPI-CA Version:"); if (version == NULL) { /* 2.5 kernel acpi */ version = get_acpi_value(PROC_ACPI "/info", "version:"); } } if (version == NULL) { return 0; } num = atoi(version); if (num < ACPI_VERSION) { fprintf(stderr, "ProcMeter(%s): ACPI subsystem %s too is old, consider upgrading to %i.\n",__FILE__, version, ACPI_VERSION); return 0; } else if (num >= 20020214) { acpi_labels = acpi_labels_20020214; } else { acpi_labels = acpi_labels_old; } find_batteries(); find_ac_adapters(); #if ACPI_THERMAL find_thermal(); #endif return 1; } #ifdef ACPI_APM /* Read ACPI info on a given power adapter and battery, and fill the passed * apm_info struct. */ int acpi_read (int battery, apm_info *info) { char *buf, *state; if (acpi_batt_count == 0) { info->battery_percentage = 0; info->battery_time = 0; info->battery_status = BATTERY_STATUS_ABSENT; acpi_batt_capacity[battery] = 0; /* Where else would the power come from, eh? ;-) */ info->ac_line_status = 1; return 0; } /* Internally it's zero indexed. */ battery--; buf = get_acpi_file(acpi_batt_status[battery]); if (buf == NULL) { fprintf(stderr, "ProcMeter(%s): Unable to read %s\n",__FILE__, acpi_batt_status[battery]); exit(1); } info->ac_line_status = 0; info->battery_flags = 0; info->using_minutes = 1; /* Work out if the battery is present, and what percentage of full * it is and how much time is left. */ if (strcmp(scan_acpi_value(buf, acpi_labels[label_present]), "yes") == 0) { int pcap = scan_acpi_num(buf, acpi_labels[label_remaining_capacity]); int rate = scan_acpi_num(buf, acpi_labels[label_present_rate]); if (rate) { /* time remaining = (current_capacity / discharge rate) */ info->battery_time = (float) pcap / (float) rate * 60; } else { char *rate_s = scan_acpi_value(buf, acpi_labels[label_present_rate]); if (! rate_s) { /* Time remaining unknown. */ info->battery_time = 0; } else { /* a zero or unknown in the file; time * unknown so use a negative one to * indicate this */ info->battery_time = -1; } } state = scan_acpi_value(buf, acpi_labels[label_charging_state]); if (state) { if (state[0] == 'd') { /* discharging */ info->battery_status = BATTERY_STATUS_CHARGING; /* Expensive ac power check used here * because AC power might be on even if a * battery is discharging in some cases. */ info->ac_line_status = on_ac_power(); } else if (state[0] == 'c' && state[1] == 'h') { /* charging */ info->battery_status = BATTERY_STATUS_CHARGING; info->ac_line_status = 1; info->battery_flags = info->battery_flags | BATTERY_FLAGS_CHARGING; if (rate) info->battery_time = -1 * (float) (acpi_batt_capacity[battery] - pcap) / (float) rate * 60; else info->battery_time = 0; if (abs(info->battery_time) < 0.5) info->battery_time = 0; } else if (state[0] == 'o') { /* ok */ /* charged, on ac power */ info->battery_status = BATTERY_STATUS_HIGH; info->ac_line_status = 1; } else if (state[0] == 'c') { /* not charging, so must be critical */ info->battery_status = BATTERY_STATUS_CRITICAL; /* Expensive ac power check used here * because AC power might be on even if a * battery is critical in some cases. */ info->ac_line_status = on_ac_power(); } else if (rate == 0) { /* if rate is null, battery charged, on * ac power */ info->battery_status = BATTERY_STATUS_HIGH; info->ac_line_status = 1; } else { fprintf(stderr, "ProcMeter(%s): Unknown battery state: %s\n", __FILE__, state); } } else { /* Battery state unknown. */ info->battery_status = BATTERY_STATUS_ABSENT; } if (acpi_batt_capacity[battery] == 0) { /* The battery was absent, and now is present. * Well, it might be a different battery. So * re-probe the battery. */ /* NOTE that this invalidates buf. No accesses of * buf below this point! */ acpi_batt_capacity[battery] = get_acpi_batt_capacity(battery); } else if (pcap > acpi_batt_capacity[battery]) { /* Battery is somehow charged to greater than max * capacity. Rescan for a new max capacity. */ find_batteries(); } if (pcap && acpi_batt_capacity[battery]) { /* percentage = (current_capacity / max capacity) * 100 */ info->battery_percentage = (float) pcap / (float) acpi_batt_capacity[battery] * 100; } else { info->battery_percentage = -1; } } else { info->battery_percentage = 0; info->battery_time = 0; info->battery_status = BATTERY_STATUS_ABSENT; acpi_batt_capacity[battery] = 0; if (acpi_batt_count == 0) { /* Where else would the power come from, eh? ;-) */ info->ac_line_status = 1; } else { /* Expensive ac power check. */ info->ac_line_status = on_ac_power(); } } return 0; } #endif /****************** End acpi.c ************************************/ #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The template for ACPI thermal info. +*/ #define N_THERMAL_OUTPUTS 2 ProcMeterOutput _thermal_outputs[N_THERMAL_OUTPUTS]= { /*+ Temp. +*/ { /* char name[]; */ "Thermal%i", /* char *description; */ "Temperature output %i.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "unknown", /* filled out later */ }, /*+ Status +*/ { /* char name[]; */ "Thermal%i_State", /* char *description; */ "State of thermal outputs %i.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a", } }; /*+ The template for ACPI battery info. +*/ #define N_BATT_OUTPUTS 5 ProcMeterOutput _batt_outputs[N_BATT_OUTPUTS]= { /*+ Battery charge percent. +*/ { /* char name[]; */ "Batt%i_Charge", /* char *description; */ "The percent that battery %i is charged.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0%", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_Units[]; */ "(%d%%)" }, /*+ Rate of charge/discharge. +*/ { /* char name[]; */ "Batt%i_Rate", /* char *description; */ "The present rate of battery %i discharge or charge, in mA.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 mA", /* long graph_value; */ 0, /* short graph_scale; */ 1000, /* char graph_Units[]; */ "(%d mA)" }, /*+ The battery status output +*/ { /* char name[]; */ "Batt%i_Status", /* char *description; */ "The estimated status of the battery, one of the states unknown, critical, low or high", /* char type; */ PROCMETER_TEXT, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a", }, /*+ The battery remaining time output. +*/ { /* char name[]; */ "Batt%i_Time", /* char *description; */ "The current estimated lifetime remaining for battery %i.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 30, /* char graph_units[]; */ "(%d min)" }, /*+ The time till charge. +*/ { /* char name[]; */ "Batt%i_ChargeTime", /* char *description; */ "The current estimated time until battery %i is fully charged.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 30, /* char graph_units[]; */ "(%d min)" } }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The battery outputs +*/ ProcMeterOutput *batt_outputs=NULL; /*+ The thermal outputs +*/ ProcMeterOutput *thermal_outputs=NULL; /* Use celcius or farenheight? */ int use_celcius = 1; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "ACPI", /* char *description; */ "ACPI information [From /proc/acpi]. These outputs are only available if you have configured the kernel " "with ACPI support. " "(Use 'options=C' or 'options=F' in the configuration file to specify preferred units of temperature.)" }; static int last_batt_update[ACPI_MAXITEM]; static int last_thermal_update[ACPI_MAXITEM]; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { int i, j; int n=0; /* Parse options. */ if(options) { char *l=options; while(*l && *l==' ') l++; if(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; if (strcmp(l, "C") == 0) { use_celcius=1; } else if (strcmp(l, "F") == 0) { use_celcius=0; } else { fprintf(stderr,"ProcMeter(%s): unknown options \"%s\"\n",__FILE__, l); } } } outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; if (! acpi_supported()) return outputs; /* Iterate over the batteries and thermal information sources and set up * outputs for both. */ outputs=(ProcMeterOutput**)realloc((void*)outputs,(N_BATT_OUTPUTS * acpi_batt_count + N_THERMAL_OUTPUTS * acpi_thermal_count + 1)*sizeof(ProcMeterOutput*)); batt_outputs=(ProcMeterOutput*)realloc((void*)batt_outputs, acpi_batt_count * N_BATT_OUTPUTS * sizeof(ProcMeterOutput)); for (i = 0; i < acpi_batt_count; i++) { last_batt_update[i] = 0; for (j = 0; j < N_BATT_OUTPUTS; j++) { int index = i * N_BATT_OUTPUTS + j; batt_outputs[index] = _batt_outputs[j]; sprintf(batt_outputs[index].name, _batt_outputs[j].name, i + 1); batt_outputs[index].description=(char*)malloc(strlen(_batt_outputs[j].description)+8); sprintf(batt_outputs[index].description,_batt_outputs[j].description,i + 1); outputs[n++]=&batt_outputs[index]; } } thermal_outputs=(ProcMeterOutput*)realloc((void*)thermal_outputs, acpi_thermal_count * N_THERMAL_OUTPUTS * sizeof(ProcMeterOutput)); for (i = 0; i < acpi_thermal_count; i++) { last_thermal_update[i] = 0; for (j = 0; j < N_THERMAL_OUTPUTS; j++) { int index = i * N_THERMAL_OUTPUTS + j; thermal_outputs[index] = _thermal_outputs[j]; sprintf(thermal_outputs[index].name, _thermal_outputs[j].name, i + 1); thermal_outputs[index].description=(char*)malloc(strlen(_thermal_outputs[j].description)+8); sprintf(thermal_outputs[index].description,_thermal_outputs[j].description,i + 1); if (j == 0) { /* Fill in units. */ sprintf(thermal_outputs[index].graph_units,"%%d%s", use_celcius ? "C" : "F"); /* The scale needs to be larger, for farenheight. */ if (! use_celcius) thermal_outputs[index].graph_scale = 20; } outputs[n++]=&thermal_outputs[index]; } } outputs[n] = NULL; return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now, ProcMeterOutput *output) { char *buf; int index = output - batt_outputs; /* Is this a battery or a thermal output? */ if (index >= 0 && index < acpi_batt_count * N_BATT_OUTPUTS) { /* Battery. */ index = (output - batt_outputs) / N_BATT_OUTPUTS; /* Only update every ten seconds, because acpi has a lot of * overhead, both here and in the kernel to generate those pretty * proc files. It also doesn't change very fast.. */ if (now - last_batt_update[index] >= 10) { float percent = 0, timeleft = 0, timefull = 0; int rate = 0, pcap = 0; char *status; last_batt_update[index] = now; buf = get_acpi_file(acpi_batt_status[index]); if (! buf) return(-1); if (strcmp(scan_acpi_value(buf, acpi_labels[label_present]), "yes") == 0) { pcap = scan_acpi_num(buf, acpi_labels[label_remaining_capacity]); rate = scan_acpi_num(buf, acpi_labels[label_present_rate]); if (rate) { /* time remaining till empty = current_capacity / discharge rate) */ timeleft = (float) pcap / (float) rate * 60; } else { char *rate_s = scan_acpi_value(buf, acpi_labels[label_present_rate]); /* If the battery is not present, ACPI may * still say it is but sets rate to unknown * (on my picturebook, anyway). I don't * know if this is the correct way to do * it. */ if (rate_s && strcmp(rate_s, "unknown") == 0) { goto NOBATT; } } /* time remaining till full */ timefull = (float)(acpi_batt_capacity[index] - pcap) / (float) rate * 60; /* Status. */ status = scan_acpi_value(buf, acpi_labels[label_charging_state]); sprintf(batt_outputs[index + 2].text_value, "%s", status); if (strcmp(status, "charging") == 0) { /* Kill time left until empty. */ batt_outputs[index + 3].graph_value = PROCMETER_GRAPH_FLOATING(0); sprintf(batt_outputs[index + 3].text_value,"n/a"); /* Time left till full. */ batt_outputs[index + 4].graph_value = PROCMETER_GRAPH_FLOATING(timefull/batt_outputs[index + 4].graph_scale); sprintf(batt_outputs[index + 4].text_value,"%i:%02i", (int) timefull / 60, (int) timefull % 60); } else { /* Time left till empty. */ batt_outputs[index + 3].graph_value = PROCMETER_GRAPH_FLOATING(timeleft/batt_outputs[index + 3].graph_scale); sprintf(batt_outputs[index + 3].text_value,"%i:%02i", (int) timeleft / 60, (int) timeleft % 60); /* Kill time left until full. */ batt_outputs[index + 4].graph_value = PROCMETER_GRAPH_FLOATING(0); sprintf(batt_outputs[index + 4].text_value,"n/a"); } if (acpi_batt_capacity[index] == 0) { /* The battery was absent, and now is * present. Well, it might be a different * battery. So re-probe the battery. */ /* NOTE that this invalidates buf. */ acpi_batt_capacity[index] = get_acpi_batt_capacity(index); } if (pcap) { /* percentage = (current_capacity / last_full_capacity) * 100 */ percent = (float) pcap / (float) acpi_batt_capacity[index] * 100; } else { percent = 0; } } else { NOBATT: acpi_batt_capacity[index] = 0; /* Kill time left until empty. */ batt_outputs[index + 3].graph_value = PROCMETER_GRAPH_FLOATING(0); sprintf(batt_outputs[index + 3].text_value,"n/a"); /* Kill time left till full. */ batt_outputs[index + 4].graph_value = PROCMETER_GRAPH_FLOATING(0); sprintf(batt_outputs[index + 4].text_value,"n/a"); } /* Percent charged. */ batt_outputs[index + 0].graph_value = PROCMETER_GRAPH_FLOATING(percent/batt_outputs[index + 0].graph_scale); sprintf(batt_outputs[index + 0].text_value,"%.0f%%", percent); /* Charge/discharge rate. */ batt_outputs[index + 1].graph_value = PROCMETER_GRAPH_FLOATING((float)rate/batt_outputs[index + 1].graph_scale); sprintf(batt_outputs[index + 1].text_value,"%i mA", rate); } return(0); } else { /* Thermal */ index = (output - thermal_outputs) / N_THERMAL_OUTPUTS; if (now - last_thermal_update[index] >= 10) { float temp; char *state; last_thermal_update[index] = now; buf = get_acpi_file(acpi_thermal_status[index]); if (! buf) return(-1); /* Acpi reports in dK. */ temp = (float) scan_acpi_num(buf, "temperature:") / 100; if (! use_celcius) temp = temp * 1.8 + 32; thermal_outputs[index + 0].graph_value=PROCMETER_GRAPH_FLOATING(temp/thermal_outputs[index + 0].graph_scale); sprintf(thermal_outputs[index + 0].text_value," %.2f %s", temp, use_celcius ? "C" : "F"); state = scan_acpi_value(buf, "state:"); if (! state) sprintf(thermal_outputs[index + 1].text_value, "unknown"); else sprintf(thermal_outputs[index + 1].text_value, "%s", state); } return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(batt_outputs) { for(i=0; i < acpi_batt_count * N_BATT_OUTPUTS; i++) free(batt_outputs[i].description); free(batt_outputs); } if(thermal_outputs) { for(i=0; i < acpi_thermal_count * N_THERMAL_OUTPUTS; i++) free(thermal_outputs[i].description); free(thermal_outputs); } if(outputs) free(outputs); } procmeter3-3.5d/modules/acpi.h000066400000000000000000000036321165060751200163540ustar00rootroot00000000000000/* * A not-yet-general-purpose ACPI library, by Joey Hess */ /* Define ACPI_THERMAL to make the library support finding info about thermal * sources. */ //#define ACPI_THERMAL 1 /* Define ACPI_APM to get the acpi_read function, which is like apm_read. */ //#define ACPI_APM 1 /* The lowest version of ACPI proc files supported. */ #define ACPI_VERSION 20011018 /* The number of acpi items of each class supported. */ #define ACPI_MAXITEM 8 int acpi_supported (void); #ifdef ACPI_APM int acpi_read (int battery, apm_info *info); #endif char *get_acpi_file (const char *file); int scan_acpi_num (const char *buf, const char *key); char *scan_acpi_value (const char *buf, const char *key); char *get_acpi_value (const char *file, const char *key); int get_acpi_batt_capacity(int battery); extern int acpi_batt_count; /* Filenames of the battery info files for each system battery. */ extern char acpi_batt_info[ACPI_MAXITEM][128]; /* Filenames of the battery status files for each system battery. */ extern char acpi_batt_status[ACPI_MAXITEM][128]; /* Stores battery capacity, or 0 if the battery is absent. */ extern int acpi_batt_capacity[ACPI_MAXITEM]; extern int acpi_ac_count; extern char acpi_ac_adapter_info[ACPI_MAXITEM][128]; extern char acpi_ac_adapter_status[ACPI_MAXITEM][128]; #if ACPI_THERMAL extern int acpi_thermal_count; extern char acpi_thermal_info[ACPI_MAXITEM][128]; extern char acpi_thermal_status[ACPI_MAXITEM][128]; #endif /* This enum is used to index into the acpi_labels */ enum acpi_labels_items { label_info, label_status, label_battery, label_ac_adapter, label_online, label_design_capacity, label_present, label_remaining_capacity, label_present_rate, label_charging_state, #if ACPI_THERMAL label_thermal, #endif label_ac_state, label_last_full_capacity, }; /* This is set to point to a list of strings used for the given acpi * * version. */ extern char **acpi_labels; procmeter3-3.5d/modules/apm.c000066400000000000000000000133361165060751200162120ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/apm.c,v 1.7 2010-02-28 10:08:00 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. Advanced Power Management module source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The battery status output +*/ ProcMeterOutput batt_status_output= { /* char name[]; */ "Battery_Status", /* char *description; */ "The estimated status of the battery, one of the states unknown, critical, low or high " "and whether it is currently being charged or not.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The battery life output. +*/ ProcMeterOutput batt_life_output= { /* char name[]; */ "Battery_Life", /* char *description; */ "The current estimated fraction of the battery life that remains.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The battery remaining time output. +*/ ProcMeterOutput batt_remain_output= { /* char name[]; */ "Battery_Time", /* char *description; */ "The current estimated battery lifetime remaining in minutes or seconds.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[4]; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "APM", /* char *description; */ "Advanced Power Management information. These outputs are only available if you have " "configured the kernel to have the APM feature. [From /proc/apm]", }; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n; for(n=0;ntext_value,"high"); else if(status&0x02) /* low */ sprintf(output->text_value,"low"); else if(status&0x04) /* critical */ sprintf(output->text_value,"critical"); else /* other means unknown */ sprintf(output->text_value,"unknown"); if(status&0x08) /* charging */ strcat(output->text_value," (chg)"); return(0); } else if(output==&batt_life_output) { if(life==-1) strcpy(output->text_value,"unknown"); else sprintf(output->text_value,"%3ld%%",life); return(0); } else if(output==&batt_remain_output) { if(remain==-1) strcpy(output->text_value,"unknown"); else sprintf(output->text_value,"%ld %s",remain,remainunits); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { } procmeter3-3.5d/modules/biff.c000066400000000000000000000125011165060751200163340ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/biff.c,v 1.7 2008-05-05 18:45:17 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Mail inbox monitor. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The number of e-mails output. +*/ ProcMeterOutput count_output= { /* char name[]; */ "Inbox_Count", /* char *description; */ "The number of mail messages that are in the inbox.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 15, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The size of the mailbox output. +*/ ProcMeterOutput size_output= { /* char name[]; */ "Inbox_Size", /* char *description; */ "The size of the mail inbox.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 15, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[]= { &count_output, &size_output, NULL }; /*+ The null outputs. +*/ ProcMeterOutput *null_outputs[]= { NULL }; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Biff", /* char *description; */ "Monitors the size and number of e-mails that are waiting in the UNIX email inbox '%s'.", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* The name of the file to monitor */ static char *filename=NULL; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { char *str; struct stat buf; if(options) { filename=options; if(stat(filename,&buf)) fprintf(stderr,"ProcMeter(%s): Cannot stat the file '%s', continuing anyway.\n",__FILE__,filename); } else { static char location[40]; struct passwd *pw=getpwuid(getuid()); if(!pw) {fprintf(stderr,"ProcMeter(%s): Cannot get username information.\n",__FILE__);return(null_outputs);} sprintf(location,"/var/spool/mail/%s",pw->pw_name); if(stat(location,&buf)) { fprintf(stderr,"ProcMeter(%s): Cannot stat the file '%s' trying another.\n",__FILE__,location); sprintf(location,"/var/mail/%s",pw->pw_name); if(stat(location,&buf)) { fprintf(stderr,"ProcMeter(%s): Cannot stat the file '%s', continuing with first choice.\n",__FILE__,location); sprintf(location,"/var/spool/mail/%s",pw->pw_name); } } filename=location; } str=module.description; module.description=(char*)malloc(strlen(str)+strlen(filename)+1); sprintf(module.description,str,filename); Update(1,NULL); return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static time_t last=0,mtime=0,atime=0; static int count,size; struct utimbuf utimebuf; if(now!=last) { struct stat buf; if(stat(filename,&buf)) { count=size=0; mtime=atime=0; } else { if(mtime!=buf.st_mtime || atime!=buf.st_atime || size!=buf.st_size) { FILE *f=fopen(filename,"r"); count=0; if(f) { while(fgets_realloc(&line,&length,f)) if(!strncmp("From ",line,5)) count++; fclose(f); } mtime=buf.st_mtime; atime=buf.st_atime; size=buf.st_size; utimebuf.actime=atime; utimebuf.modtime=mtime; utime(filename,&utimebuf); } } last=now; } if(output==&count_output) { sprintf(output->text_value,"%d emails",count); return(0); } else if(output==&size_output) { sprintf(output->text_value,"%d KB",size/1024); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { if(filename) free(module.description); if(line) free(line); } procmeter3-3.5d/modules/check-no-libsensors.sh000077500000000000000000000006261165060751200214760ustar00rootroot00000000000000#!/bin/sh CC=$1 CFLAGS=$2 cat < libsensors-test.c #include #if (SENSORS_API_VERSION & 0xf00) != 0x400 #error #endif EOF $CC -c $CFLAGS libsensors-test.c -o libsensors-test.o 2> /dev/null rm libsensors-test.c if [ -f libsensors-test.o ]; then rm libsensors-test.o exit 1 else echo "libsensors does not appear to be installed - skipping compilation." exit 0 fi procmeter3-3.5d/modules/cpuinfo.c000066400000000000000000000125721165060751200171010ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/cpuinfo.c,v 1.4 2008-05-05 18:45:17 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. CPU information. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" #define CPU_SPEED 0 #define NOUTPUTS 1 /* The interface information. */ /*+ The normal outputs +*/ ProcMeterOutput _output= /*+ The cpu speed output +*/ { /* char name[]; */ "CPU_Speed", /* char *description; */ "The speed of the CPU in MHz.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0", /* long graph_value; */ 0, /* short graph_scale; */ 500, /* char graph_units[]; */ "(%d)" }; /*+ The outputs with multiple CPUs +*/ ProcMeterOutput _smp_output= /*+ The total cpu output +*/ { /* char name[]; */ "CPU%d_Speed", /* char *description; */ "The speed of the CPU number %d in MHz.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0", /* long graph_value; */ 0, /* short graph_scale; */ 500, /* char graph_units[]; */ "(%d)" }; /*+ The outputs (with single or multiple CPUs). +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "CPUInfo", /* char *description; */ "CPU Information. [From /proc/cpuinfo]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* The current and previous information */ static float *current,*previous,*values[2]={NULL,NULL}; /*+ The number of CPUs. +*/ static int ncpus=0; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int i; /* Verify the statistics from /proc/stat */ f=fopen("/proc/cpuinfo","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/cpuinfo'.\n",__FILE__); else { if(!fgets_realloc(&line,&length,f)) /* cpu */ fprintf(stderr,"ProcMeter(%s): Could not read '/proc/cpuinfo'.\n",__FILE__); else { int count; do { if(sscanf(line,"processor : %d",&count)==1) ncpus++; } while(fgets_realloc(&line,&length,f)); } fclose(f); } /* Create the outputs */ outputs=(ProcMeterOutput**)malloc((ncpus+1)*sizeof(ProcMeterOutput*)); outputs[ncpus]=NULL; values[0]=(float*)malloc(ncpus*sizeof(float)); values[1]=(float*)malloc(ncpus*sizeof(float)); current=values[0]; previous=values[1]; if(ncpus==1) { outputs[0]=(ProcMeterOutput*)malloc(sizeof(ProcMeterOutput)); *outputs[0]=_output; } else for(i=0;iname,PROCMETER_NAME_LEN+1,_smp_output.name,i); outputs[i]->description=(char*)malloc(strlen(_smp_output.description)+8); sprintf(outputs[i]->description,_smp_output.description,i); } return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static time_t last=0; int i; /* Get the statistics from /proc/cpuinfo */ if(now!=last) { FILE *f; float *temp; temp=current; current=previous; previous=temp; f=fopen("/proc/cpuinfo","r"); if(!f) return(-1); i=0; while(fgets_realloc(&line,&length,f)) { float speed; if(sscanf(line,"cpu MHz : %f",&speed)==1) { current[i]=speed; i++; } } fclose(f); last=now; } for(i=0;igraph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.1f MHz",value); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(ncpus>1) for(i=0;idescription); for(i=0;i #include #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The current date output with year. +*/ ProcMeterOutput date_dmy_output= { /* char name[]; */ "Date_DMY", /* char *description; */ "The current date in the local timezone; day of week, day of month, month, year.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The current date output. +*/ ProcMeterOutput date_dm_output= { /* char name[]; */ "Date_DM", /* char *description; */ "The current date in the local timezone; day of week, day of month, month.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The current time output with seconds. +*/ ProcMeterOutput time_hms_output= { /* char name[]; */ "Time_HMS", /* char *description; */ "The current time in the local timezone; hours, minutes and seconds.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The current time output with seconds, with timezone. +*/ ProcMeterOutput time_hms_tz_output= { /* char name[]; */ "Time_HMS_TZ", /* char *description; */ "The current time in the local timezone; hours, minutes, seconds and timezone.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The current time output, without seconds. +*/ ProcMeterOutput time_hm_output= { /* char name[]; */ "Time_HM", /* char *description; */ "The current time in the local timezone; hours and minutes.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The current time output, without seconds, with timezone. +*/ ProcMeterOutput time_hm_tz_output= { /* char name[]; */ "Time_HM_TZ", /* char *description; */ "The current time in the local timezone; hours, minutes and timezone.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The current uptime output +*/ ProcMeterOutput uptime_dhm_output= { /* char name[]; */ "Uptime_DHM", /* char *description; */ "The amount of time that the system has been running for; days, hours and minutes.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 60, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[]= { &date_dmy_output, &date_dm_output, &time_hms_output, &time_hms_tz_output, &time_hm_output, &time_hm_tz_output, NULL, /* Insert uptime_dhm_output here if /proc/uptime exists. */ NULL }; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Date_Time", /* char *description; */ "The current date and time and the amount of time the system has been running.", }; static int twelve_hour = 0; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; f=fopen("/proc/uptime","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/uptime'.\n",__FILE__); else { time_t uptime; if(fscanf(f,"%ld",&uptime)!=1) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/uptime'.\n",__FILE__); else outputs[sizeof(outputs)/sizeof(outputs[0])-2]=&uptime_dhm_output; fclose(f); } if (options && strcmp(options, "12") == 0) twelve_hour = 1; return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput* output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput* output) { if(output==&uptime_dhm_output) { FILE *f; time_t uptime; int hours,days,mins; f=fopen("/proc/uptime","r"); if(!f) return(-1); if(fscanf(f,"%ld",&uptime)!=1) return(-1); fclose(f); days =uptime/(24*3600); hours=(uptime%(24*3600))/3600; mins =(uptime%3600)/60; sprintf(output->text_value,"%dD %2dH %2dM",days,hours,mins); } else { struct tm *tim; tim=localtime(&now); if(tim->tm_isdst<0) tim=gmtime(&now); if(output==&date_dmy_output) { strftime(output->text_value,PROCMETER_TEXT_LEN,"%a %e %b %Y",tim); } else if(output==&date_dm_output) { strftime(output->text_value,PROCMETER_TEXT_LEN,"%a %e %b",tim); } else if(output==&time_hms_output) { if(twelve_hour) strftime(output->text_value,PROCMETER_TEXT_LEN,"%I:%M:%S %p",tim); else strftime(output->text_value,PROCMETER_TEXT_LEN,"%H:%M:%S",tim); } else if(output==&time_hms_tz_output) { if(twelve_hour) strftime(output->text_value,PROCMETER_TEXT_LEN,"%I:%M:%S %p %Z",tim); else strftime(output->text_value,PROCMETER_TEXT_LEN,"%H:%M:%S %Z",tim); } else if(output==&time_hm_output) { if(twelve_hour) strftime(output->text_value,PROCMETER_TEXT_LEN,"%I:%M %p",tim); else strftime(output->text_value,PROCMETER_TEXT_LEN,"%H:%M",tim); } else if(output==&time_hm_tz_output) { if(twelve_hour) strftime(output->text_value,PROCMETER_TEXT_LEN,"%I:%M %p %Z",tim); else strftime(output->text_value,PROCMETER_TEXT_LEN,"%H:%M %Z",tim); } else return(-1); } return(0); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { } procmeter3-3.5d/modules/df.c000066400000000000000000000202061165060751200160200ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/df.c,v 1.14 2009-04-21 17:26:58 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Disk capacity monitoring source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2009 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The template for the disk outputs +*/ ProcMeterOutput _outputs[2]= { /*+ The percentage used space +*/ { /* char name[]; */ "DF_Used_%s", /* char *description; */ "The percentage of the %s device mounted on %s that is occupied with files. " "(This can exceed 100%% on UNIX format drives due to the reserved minimum free space.)", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 10, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The amount of free space +*/ { /* char name[]; */ "DF_Free_%s", /* char *description; */ "The amount of space on the %s device mounted on %s that is available for non-root use. " "(This can be negative on UNIX format drives since it does not include the reserved minimum free space.)", /* char type; */ PROCMETER_TEXT, /* short interval; */ 10, /* char text_value[]; */ "0 MB", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" } }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "DiskUsage", /* char *description; */ "The fraction of the disk that is occupied and the amount of space available." }; /* The line buffer */ static char *line=NULL; static size_t length=128; /* The information about the disks */ static int ndisks=0; static char **disk=NULL; static int *mounted; /* A function to add a disk */ static void add_disk(char *dev,char *mnt); /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; /* Use the devices in /proc/mounts */ f=fopen("/proc/mounts","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/mounts'.\n",__FILE__); else { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/mounts'.\n",__FILE__); else do { char device[65],mount[65]; if(sscanf(line,"%64s %64s",device,mount)==2) if(strcmp(mount,"none") && *mount=='/' && (*device=='/' || strstr(device, ":/"))) add_disk(device,mount); } while(fgets_realloc(&line,&length,f)); fclose(f); } /* Use the devices in /etc/fstab */ f=fopen("/etc/fstab","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/etc/fstab'.\n",__FILE__); else { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/etc/fstab'.\n",__FILE__); else do { char device[65],mount[65]; if(*line=='#') continue; if(sscanf(line,"%64s %64s",device,mount)==2) if(strcmp(mount,"none") && *mount=='/' && (*device=='/' || strstr(device, ":/"))) add_disk(device,mount); } while(fgets_realloc(&line,&length,f)); fclose(f); } /* Get the other options */ if(options) { char *l=options; while(*l && *l==' ') l++; while(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; add_disk("(unknown device)",l); *r=pr; while(*r && *r==' ') r++; if(!*r) break; l=r; } } return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Add a new disk to the list. char *dev The name of the device to add. char *mnt The mount point for the device. ++++++++++++++++++++++++++++++++++++++*/ static void add_disk(char *dev,char *mnt) { int i,j; for(i=0;iname,PROCMETER_NAME_LEN+1,_outputs[i].name,mnt); outputs[j]->description=(char*)malloc(strlen(dev)+strlen(mnt)+strlen(_outputs[i].description)+4); sprintf(outputs[j]->description,_outputs[i].description,dev,mnt); } disk=(char**)realloc((void*)disk,(ndisks+1)*sizeof(char*)); mounted=(int*)realloc((void*)mounted,(ndisks+1)*sizeof(int)); disk[ndisks]=(char*)malloc(strlen(mnt)+1); strcpy(disk[ndisks],mnt); ndisks++; outputs[j]=NULL; } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static time_t last=0; int i; /* Get the mounted disks from /proc/mounts */ if(now!=last) { FILE *f; for(i=0;igraph_value=0; strcpy(output->text_value,"not found"); } else if(statfs(disk[i/2],&buf)) { output->graph_value=0; strcpy(output->text_value,"statfs error"); } else { if(i%2) { long long avail=(buf.f_bavail>>5)*(buf.f_bsize>>5); sprintf(output->text_value,"%.1f MB",avail/1024.0); } else { double frac=100.0*(double)(buf.f_blocks-buf.f_bfree)/(double)(buf.f_blocks-buf.f_bfree+buf.f_bavail); output->graph_value=PROCMETER_GRAPH_FLOATING(frac/output->graph_scale); sprintf(output->text_value,"%.1f %%",frac); } } return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(outputs) { for(i=0;outputs[i];i++) { free(outputs[i]->description); free(outputs[i]); } free(outputs); } if(ndisks) { for(i=0;i #include #include #include #include #include #include "procmeter.h" #if !defined(SENSORS_API_VERSION) || (SENSORS_API_VERSION & 0xf00) != 0x400 #error "This module requires libsensors version 3" #else /* The interface information. */ /*+ The template output +*/ ProcMeterOutput template_output= { /* char name[]; */ "unknown", #if defined(FANSPEED) /* char *description; */ "Fan speed. [From %s %s]", #elif defined(TEMPERATURE) /* char *description; */ "Temperature. [From %s %s]", #elif defined(VOLTAGE) /* char *description; */ "Voltage level. [From %s %s]", #else #error Undefined module. #endif /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, #if defined(FANSPEED) /* short graph_scale; */ 1000, /* char graph_units[]; */ "(%d RPM)" #elif defined(TEMPERATURE) /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d C)" #elif defined(VOLTAGE) /* short graph_scale; */ 1, /* char graph_units[]; */ "(%d V)" #else #error Undefined module. #endif }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { #if defined(FANSPEED) /* char name[]; */ "FanSpeed", #elif defined(TEMPERATURE) /* char name[]; */ "Temperature", #elif defined(VOLTAGE) /* char name[]; */ "Voltage", #else #error Undefined module. #endif /* char *description; */ "Hardware sensor information from libsensors.", }; typedef struct { char *description; const sensors_chip_name *chip; char *label; int number; } Sensor; int count; Sensor *sensorv; ProcMeterOutput *outputv; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { int error; int i=0; /* Uninitialized libsensors will report no detected chips. */ if (!sensors_get_detected_chips(NULL, &i)) { FILE *input=NULL; if (options) { input=fopen(options, "r"); if (!input) { fprintf(stderr,"ProcMeter(%s): %s: %s\n", FILE__, options, strerror(errno)); } } error=sensors_init(input); if (input) fclose(input); if (error) { fprintf(stderr,"ProcMeter(%s): %s\n", FILE__, sensors_strerror(error)); sensors_cleanup(); } } const sensors_chip_name *chip; for (count=0, i=0; (chip=sensors_get_detected_chips(NULL, &i));) { char name[1024]; error=sensors_snprintf_chip_name(name, sizeof(name), chip); if (error<0) { fprintf(stderr,"ProcMeter(%s): %s\n", FILE__, sensors_strerror(error)); strcpy(name, "unknown"); } const sensors_feature *feature; int f=0; while ((feature=sensors_get_features(chip, &f))) { const sensors_subfeature *subfeature; #if defined(FANSPEED) if (feature->type!=SENSORS_FEATURE_FAN) continue; subfeature=sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_FAN_INPUT); #elif defined(TEMPERATURE) if (feature->type!=SENSORS_FEATURE_TEMP) continue; subfeature=sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_INPUT); #elif defined(VOLTAGE) if (feature->type==SENSORS_FEATURE_IN) { subfeature=sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_IN_INPUT); } else if (feature->type==SENSORS_FEATURE_VID) { subfeature=sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_VID); } else { continue; } #else #error Undefined module. #endif if (!subfeature) continue; char *label=sensors_get_label(chip, feature); char *description=malloc(strlen(template_output.description)+strlen(name)+strlen(label)); sprintf(description, template_output.description, name, label); char *s; while ((s=strchr(label, ' '))) *s='_'; if (!count) sensorv=malloc(sizeof(*sensorv)); else sensorv=realloc(sensorv, (count+1)*sizeof(*sensorv)); sensorv[count].description=description; sensorv[count].chip=chip; sensorv[count].label=label; sensorv[count].number=subfeature->number; ++count; } } if (count) outputv=malloc(count*sizeof(*outputv)); outputs=malloc((count+1)*sizeof(*outputs)); outputs[count]=0; for (i=0; i=count)) return -1; double value; int error=sensors_get_value(sensorv[i].chip, sensorv[i].number, &value); if (error<0) { fprintf(stderr,"ProcMeter(%s): %s\n", FILE__, sensors_strerror(error)); return -1; } #if defined(FANSPEED) sprintf(output->text_value, "%.0lf RPM", value); #elif defined(TEMPERATURE) sprintf(output->text_value, "%.1lf C", value); #elif defined(VOLTAGE) sprintf(output->text_value, "%.3lf V", value); #else #error Undefined module. #endif output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); return 0; } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { free(outputs); int i; for (i=0; i #include #include "procmeter.h" /* The interface information. */ /*+ The load average output +*/ ProcMeterOutput loadavg_output= { /* char name[]; */ "Load", /* char *description; */ "The system load, a rolling average of the number of processes running.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 1, /* char graph_units[]; */ "(%d)" }; /*+ The number of processes output. +*/ ProcMeterOutput processes_output= { /* char name[]; */ "Processes", /* char *description; */ "The number of processes that exist in the system.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d)" }; /*+ The number of forks per second output. +*/ ProcMeterOutput forks_output= { /* char name[]; */ "Forks", /* char *description; */ "The number of new processes that start per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 5, /* char graph_units[]; */ "(%d/s)" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[4]; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Processes", /* char *description; */ "The load average and the number of processes running and starting. [From /proc/loadavg]", }; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n; for(n=0;n ~1.2.0? */ loadavg_available=processes_available=forks_available=1; else if(sscanf(line,"%lf %*f %*f %*d/%ld",&d,&p1)==2) /* kernel version > ~1.2.0 */ loadavg_available=processes_available=1; else if(sscanf(line,"%lf",&d)==1) /* kernel version < ~1.2.0 */ loadavg_available=1; else fprintf(stderr,"ProcMeter(%s): Unexpected line in '/proc/loadavg'.\n",__FILE__); if(loadavg_available) outputs[n++]=&loadavg_output; if(processes_available) outputs[n++]=&processes_output; if(forks_available) outputs[n++]=&forks_output; } if(line) free(line); fclose(f); } return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static time_t last=0; static float l,delta_p; static long n,p=0; /* Get the statistics from /proc/loadavg */ if(last!=now) { FILE *f; long p2; f=fopen("/proc/loadavg","r"); if(!f) return(-1); if(fscanf(f,"%f %*f %*f %*d/%ld %ld",&l,&n,&p2)!=3) return(-1); fclose(f); if(last && p) { while(p2text_value,"%.2f",l); output->graph_value=PROCMETER_GRAPH_FLOATING(l/output->graph_scale); return(0); } else if(output==&processes_output) { sprintf(output->text_value,"%ld",n); output->graph_value=PROCMETER_GRAPH_FLOATING((double)n/output->graph_scale); return(0); } else if(output==&forks_output) { sprintf(output->text_value,"%.1f",delta_p); output->graph_value=PROCMETER_GRAPH_FLOATING(delta_p/output->graph_scale); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { } procmeter3-3.5d/modules/logfile.c000066400000000000000000000207271165060751200170600ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/logfile.c,v 1.9 2008-05-05 18:45:35 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. A log file monitoring source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The template for the log file +*/ ProcMeterOutput _outputs[4]= { /*+ The size in bytes +*/ { /* char name[]; */ "Log_Size_%s", /* char *description; */ "The size of the log file '%s' in KBytes.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 KB", /* long graph_value; */ 0, /* short graph_scale; */ 100, /* char graph_units[]; */ "(%dKB)" }, /*+ The rate of change of size in bytes +*/ { /* char name[]; */ "Log_Grow_%s", /* char *description; */ "The rate at which the size of the log file '%s' is increasing in KBytes/second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 KB/s", /* long graph_value; */ 0, /* short graph_scale; */ 1, /* char graph_units[]; */ "(%dK/s)" }, /*+ The number of lines +*/ { /* char name[]; */ "Log_Line_%s", /* char *description; */ "The number of lines in the log file '%s'.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 lines", /* long graph_value; */ 0, /* short graph_scale; */ 100, /* char graph_units[]; */ "(%d)" }, /*+ The rate of change of number of lines +*/ { /* char name[]; */ "Log_Rate_%s", /* char *description; */ "The number of lines by which the log file '%s' is increasing per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 lines/s", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d/s)" } }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "LogFile", /* char *description; */ "The size and number of lines in the specified log files. " "(Use 'options= ' in the configuration file to specify the files.)" }; /* The files to monitor and the information about them */ static int nfiles=0; static char **file=NULL; static long *last=NULL; static long *mtime=NULL; static long *size=NULL; static long *grow=NULL; static long *line=NULL; static long *rate=NULL; /* Add a file to be monitored */ static void add_file(char *fil); /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; /* Get the options */ if(options) { char *l=options; while(*l && *l==' ') l++; while(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; add_file(l); *r=pr; while(*r && *r==' ') r++; if(!*r) break; l=r; } } return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Add a new file to the list. char *fil The name of the file to add. ++++++++++++++++++++++++++++++++++++++*/ static void add_file(char *fil) { int i,j; char *slash,*lastslash=fil-1; for(i=0;iname, PROCMETER_NAME_LEN+1, _outputs[i].name, lastslash+1); outputs[j]->description=(char*)malloc(strlen(fil)+strlen(_outputs[i].description)+4); sprintf(outputs[j]->description,_outputs[i].description,fil); } file =(char**)realloc((void*)file ,(nfiles+1)*sizeof(char*)); last =(long *)realloc((void*)last ,(nfiles+1)*sizeof(long)); mtime=(long *)realloc((void*)mtime,(nfiles+1)*sizeof(long)); size =(long *)realloc((void*)size ,(nfiles+1)*sizeof(long)); grow =(long *)realloc((void*)grow ,(nfiles+1)*sizeof(long)); line =(long *)realloc((void*)line ,(nfiles+1)*sizeof(long)); rate =(long *)realloc((void*)rate ,(nfiles+1)*sizeof(long)); file[nfiles]=(char*)malloc(strlen(fil)+1); strcpy(file[nfiles],fil); last[nfiles]=mtime[nfiles]=size[nfiles]=grow[nfiles]=line[nfiles]=rate[nfiles]=0; nfiles++; outputs[j]=NULL; } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { int i; for(i=0;outputs[i];i++) if(output==outputs[i]) { if(last[i/4]!=now) { struct stat buf; if(stat(file[i/4],&buf)) mtime[i/4]=size[i/4]=grow[i/4]=line[i/4]=rate[i/4]=0; else { int lines=0; if(buf.st_sizesize[i/4]) { FILE *f=fopen(file[i/4],"r"); char buffer[2048]; int nread,byte; if(f) { fseek(f,size[i/4],SEEK_SET); while((nread=fread(buffer,1,2048,f))>0) for(byte=0;bytegraph_value=PROCMETER_GRAPH_FLOATING((double)size[i/4]/(1024.0*output->graph_scale)); sprintf(output->text_value,"%.1f KB",(double)size[i/4]/1024); break; case 1: output->graph_value=PROCMETER_GRAPH_FLOATING((double)grow[i/4]/(1024.0*output->graph_scale)); sprintf(output->text_value,"%.2f KB/s",(double)grow[i/4]/1024); break; case 2: output->graph_value=PROCMETER_GRAPH_FLOATING((double)line[i/4]/output->graph_scale); sprintf(output->text_value,"%.0f lines",(double)line[i/4]); break; case 3: output->graph_value=PROCMETER_GRAPH_FLOATING((double)rate[i/4]/output->graph_scale); sprintf(output->text_value,"%.0f lines/s",(double)rate[i/4]); break; } return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(outputs) { for(i=0;outputs[i];i++) { free(outputs[i]->description); free(outputs[i]); } free(outputs); } if(file) { for(i=0;i #include #include #include #include #include #include #define __USE_FILE_OFFSET64 /* we should use 64 bit offset for pread */ #include #include "procmeter.h" /* The canonical source for these defines is longrun.c in the longrun * utility. */ #define CPUID_DEVICE "/dev/cpu/0/cpuid" #define CPUID_TMx86_LONGRUN_STATUS 0x80860007 #define CPUID_TMx86_VENDOR_ID 0x80860000 #define CPUID_TMx86_PROCESSOR_INFO 0x80860001 #define CPUID_TMx86_FEATURE_LONGRUN(x) ((x) & 0x02) static int cpuid_fd = 0; static void read_cpuid(loff_t address, int *eax, int *ebx, int *ecx, int *edx) { uint32_t data[4]; if (pread(cpuid_fd, &data, 16, address) != 16) { perror("error reading"); } if (eax) *eax = data[0]; if (ebx) *ebx = data[1]; if (ecx) *ecx = data[2]; if (edx) *edx = data[3]; } /* The interface information. */ /*+ The template for the longrun devices +*/ ProcMeterOutput _outputs[1]= { { /* char name[]; */ "Longrun", /* char *description; */ "current longrun performance level", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, }; static int ndevices=0; static unsigned long *current=NULL,*previous=NULL; static char **device=NULL; static void add_device(void); /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Longrun", /* char *description; */ "Transmeta Crusoe longrun information. " "Only available if using a Transmeta Crusoe CPU that supports it and the kernel was compiled with CONFIG_X86_CPUID=y." }; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { int eax, ebx, ecx, edx; outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; if ((cpuid_fd = open(CPUID_DEVICE, O_RDONLY)) < 0) { /* Don't bother giving an error message for 99% of systems. */ // fprintf(stderr, "ProcMeter(%s): Cannot open " CPUID_DEVICE ". make sure your kernel was compiled with CONFIG_X86_CPUID=y, and make sure the device is readable\n", __FILE__); return outputs; } /* See if longrun is supported by this system. */ read_cpuid(CPUID_TMx86_VENDOR_ID, &eax, &ebx, &ecx, &edx); if (ebx != 0x6e617254 || ecx != 0x55504361 || edx != 0x74656d73) { fprintf(stderr, "ProcMeter(%s): Not a Transmeta x86 CPU.\n", __FILE__); return outputs; } read_cpuid(CPUID_TMx86_PROCESSOR_INFO, &eax, &ebx, &ecx, &edx); if (!CPUID_TMx86_FEATURE_LONGRUN(edx)) { fprintf(stderr, "ProcMeter(%s): Longrun unsupported.\n", __FILE__); return outputs; } add_device(); current =(unsigned long*)malloc(sizeof(long)*ndevices); previous=(unsigned long*)malloc(sizeof(long)*ndevices); return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Add a new device to the list. Currently we just support one CPU, so no parameters. ++++++++++++++++++++++++++++++++++++++*/ static void add_device(void) { int nstats=1; int i; outputs=(ProcMeterOutput**)realloc((void*)outputs,(ndevices+nstats+1)*sizeof(ProcMeterOutput*)); device=(char**)realloc((void*)device,(ndevices+nstats+1)*sizeof(char*)); for(i=0;nstats;nstats--) { outputs[ndevices]=(ProcMeterOutput*)malloc(sizeof(ProcMeterOutput)); device[ndevices]=(char*)malloc(1); *outputs[ndevices]=_outputs[i]; outputs[ndevices]->description=(char*)malloc(strlen(_outputs[i].description)+4); strcpy(outputs[ndevices]->description,_outputs[i].description); strcpy(device[ndevices],"0"); ndevices++; i++; } outputs[ndevices]=NULL; } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { int percent; read_cpuid(CPUID_TMx86_LONGRUN_STATUS, 0, 0, &percent, 0); output[0].graph_value=PROCMETER_GRAPH_FLOATING(percent/output[0].graph_scale); sprintf(output->text_value,"%i %%",percent); return(0); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(outputs) { for(i=0;outputs[i];i++) { free(outputs[i]->description); free(outputs[i]); } free(outputs); } if(current) free(current); if(previous) free(previous); if(device) { for(i=0;i #include #include #include "procmeter.h" #define MEM_FREE 0 #define MEM_USED 1 #define MEM_BUFF 2 #define MEM_CACHE 3 #define MEM_AVAIL 4 #define SWAP_FREE 5 #define SWAP_USED 6 #define N_OUTPUTS 7 #define MEM_TOTAL 7 #define SWAP_TOTAL 8 #define N_LINES 9 /* The interface information. */ ProcMeterOutput _outputs[N_OUTPUTS]= { /*+ The mem free output +*/ { /* char name[]; */ "Mem_Free", /* char *description; */ "The amount of memory that is free, completely unused, wasted.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" }, /*+ The mem used output +*/ { /* char name[]; */ "Mem_Used", /* char *description; */ "The amount of memory that is used, excluding cache and buffers.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" }, /*+ The mem buff output +*/ { /* char name[]; */ "Mem_Buff", /* char *description; */ "The amount of memory that is used in buffers.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" }, /*+ The mem cache output +*/ { /* char name[]; */ "Mem_Cache", /* char *description; */ "The amount of memory that is used for disk cache.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" }, /*+ The mem avail output +*/ { /* char name[]; */ "Mem_Avail", /* char *description; */ "The amount of memory that is available for programs, free plus cache.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" }, /*+ The mem swap free output +*/ { /* char name[]; */ "Swap_Free", /* char *description; */ "The amount of memory that is free in the swap space.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" }, /*+ The mem swap used output +*/ { /* char name[]; */ "Swap_Used", /* char *description; */ "The amount of memory that is used in the swap space.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dMB)" } }; /*+ The outputs. +*/ ProcMeterOutput *outputs[N_OUTPUTS+1]; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Memory", /* char *description; */ "The amount of memory that is used for programs, buffers, cache and the amount that is free. " "[From /proc/meminfo]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* The estimated kernel version based on the format of the file */ static int proc_meminfo_V2_1_41=0; /* The contents of the file when parsed */ static int contents[20]; static int available[N_LINES]; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n; for(n=0;n<=N_OUTPUTS;n++) outputs[n]=NULL; for(n=0;n ~2.0.0 */ strncmp(line,"MemTotal:",9)) /* kernel version > ~2.1.41 */ fprintf(stderr,"ProcMeter(%s): Unexpected first line in '/proc/meminfo'.\n",__FILE__); else { unsigned long long mem_tot,mem_free,mem_used,mem_buff,mem_cache,swap_tot,swap_free,swap_used; int i; proc_meminfo_V2_1_41=!strncmp(line,"MemTotal:",9); if(proc_meminfo_V2_1_41) { int lineno; for(lineno=(sizeof(contents)/sizeof(contents[0]))-1;lineno>=0;lineno--) contents[lineno]=0; lineno=1; do { if(sscanf(line,"MemTotal: %llu",&mem_tot)==1) contents[lineno]=MEM_TOTAL,available[MEM_TOTAL]=1; else if(sscanf(line,"MemFree: %llu",&mem_free)==1) contents[lineno]=MEM_FREE,available[MEM_FREE]=1; else if(sscanf(line,"Buffers: %llu",&mem_buff)==1) contents[lineno]=MEM_BUFF,available[MEM_BUFF]=1; else if(sscanf(line,"Cached: %llu",&mem_cache)==1) contents[lineno]=MEM_CACHE,available[MEM_CACHE]=1; else if(sscanf(line,"SwapTotal: %llu",&swap_tot)==1) contents[lineno]=SWAP_TOTAL,available[SWAP_TOTAL]=1; else if(sscanf(line,"SwapFree: %llu",&swap_free)==1) contents[lineno]=SWAP_FREE,available[SWAP_FREE]=1; } while(fgets_realloc(&line,&length,f) && ++lineno<(sizeof(contents)/sizeof(contents[0]))); if(available[MEM_TOTAL] && available[MEM_FREE]) available[MEM_USED]=1; if(available[SWAP_TOTAL] && available[SWAP_FREE]) available[SWAP_USED]=1; if(!available[MEM_TOTAL]) fprintf(stderr,"ProcMeter(%s): Did not find 'MemTotal' line in '/proc/meminfo'.\n",__FILE__); if(!available[MEM_FREE]) fprintf(stderr,"ProcMeter(%s): Did not find 'MemFree' line in '/proc/meminfo'.\n",__FILE__); if(!available[MEM_BUFF]) fprintf(stderr,"ProcMeter(%s): Did not find 'Buffers' line in '/proc/meminfo'.\n",__FILE__); if(!available[MEM_CACHE]) fprintf(stderr,"ProcMeter(%s): Did not find 'Cached' line in '/proc/meminfo'.\n",__FILE__); if(!available[SWAP_TOTAL]) fprintf(stderr,"ProcMeter(%s): Did not find 'SwapTotal' line in '/proc/meminfo'.\n",__FILE__); if(!available[SWAP_FREE]) fprintf(stderr,"ProcMeter(%s): Did not find 'SwapFree' line in '/proc/meminfo'.\n",__FILE__); } else { fgets_realloc(&line,&length,f); if(sscanf(line,"Mem: %llu %llu %llu %*u %llu %llu",&mem_tot,&mem_free,&mem_used,&mem_buff,&mem_cache)==5) available[MEM_FREE]=available[MEM_USED]=available[MEM_BUFF]=available[MEM_CACHE]=1; else if(sscanf(line,"Mem: %llu %llu %llu %*u %llu",&mem_tot,&mem_free,&mem_used,&mem_buff)==4) available[MEM_FREE]=available[MEM_USED]=available[MEM_BUFF]=1; else fprintf(stderr,"ProcMeter(%s): Unexpected 'Mem' line in '/proc/meminfo'.\n",__FILE__); fgets_realloc(&line,&length,f); if(sscanf(line,"Swap: %llu %llu",&swap_tot,&swap_used)==2) available[SWAP_FREE]=available[SWAP_USED]=1; else fprintf(stderr,"ProcMeter(%s): Unexpected 'Swap' line in '/proc/meminfo'.\n",__FILE__); mem_tot>>=10; } if(available[MEM_FREE] && available[MEM_CACHE]) available[MEM_AVAIL]=1; if(available[MEM_FREE]) { long mem_scale=1; mem_tot>>=14; while(mem_tot) {mem_tot>>=1; mem_scale<<=1;} for(i=0;i>=10; mem_used >>=10; mem_buff >>=10; mem_cache>>=10; swap_free>>=10; swap_used>>=10; } mem_avail=mem_free+mem_cache; if(available[MEM_BUFF]) mem_used-=mem_buff; if(available[MEM_CACHE]) mem_used-=mem_cache; fclose(f); last=now; } if(output==&_outputs[MEM_FREE]) { sprintf(output->text_value,"%.3f MB",(double)mem_free/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(mem_free>>10)/output->graph_scale); return(0); } else if(output==&_outputs[MEM_USED]) { sprintf(output->text_value,"%.3f MB",(double)mem_used/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(mem_used>>10)/output->graph_scale); return(0); } else if(output==&_outputs[MEM_BUFF]) { sprintf(output->text_value,"%.3f MB",(double)mem_buff/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(mem_buff>>10)/output->graph_scale); return(0); } else if(output==&_outputs[MEM_CACHE]) { sprintf(output->text_value,"%.3f MB",(double)mem_cache/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(mem_cache>>10)/output->graph_scale); return(0); } else if(output==&_outputs[MEM_AVAIL]) { sprintf(output->text_value,"%.3f MB",(double)mem_avail/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(mem_avail>>10)/output->graph_scale); return(0); } else if(output==&_outputs[SWAP_FREE]) { sprintf(output->text_value,"%.3f MB",(double)swap_free/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(swap_free>>10)/output->graph_scale); return(0); } else if(output==&_outputs[SWAP_USED]) { sprintf(output->text_value,"%.3f MB",(double)swap_used/1024.0); output->graph_value=PROCMETER_GRAPH_FLOATING((double)(swap_used>>10)/output->graph_scale); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { if(line) free(line); } procmeter3-3.5d/modules/netdev.c000066400000000000000000000330531165060751200167200ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/netdev.c,v 1.20 2008-05-05 18:45:35 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Network devices traffic source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The template for the network devices +*/ ProcMeterOutput _outputs[6]= { /*+ The total packets +*/ { /* char name[]; */ "Pkt_%s", /* char *description; */ "The total number of packets per second on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%d/s)" }, /*+ The total bytes +*/ { /* char name[]; */ "Byte_%s", /* char *description; */ "The total number of bytes per second on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 kB/s", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dkB/s)" }, /*+ The transmitted packets +*/ { /* char name[]; */ "Pkt_Tx_%s", /* char *description; */ "The number of packets transmitted per second on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%d/s)" }, /*+ The transmitted bytes +*/ { /* char name[]; */ "Byte_Tx_%s", /* char *description; */ "The number of bytes transmitted per second on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 kB/s", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dkB/s)" }, /*+ The received packets +*/ { /* char name[]; */ "Pkt_Rx_%s", /* char *description; */ "The number of packets received per second on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%d/s)" }, /*+ The received bytes +*/ { /* char name[]; */ "Byte_Rx_%s", /* char *description; */ "The number of bytes received per second on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 kB/s", /* long graph_value; */ 0, /* short graph_scale; */ 0, /* calculated later */ /* char graph_units[]; */ "(%dkB/s)" } }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Network", /* char *description; */ "The network devices and the amount of traffic on each of them. [From /proc/net/dev] " "(Use 'options=ppp0' in the configuration file to specify extra network devices." }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* The format to use to read the data depending on the kernel version */ static char *proc_net_dev_format=NULL; static char *proc_net_dev_format1="%llu %*u %*u %*u %*u %llu"; /* kernel version < ~2.1.28 */ static char *proc_net_dev_format2="%llu %llu %*u %*u %*u %*u %llu %llu"; /* ~2.1.28 < kernel version < ~2.1.80 (two possiblities) */ static char *proc_net_dev_format3="%llu %llu %*u %*u %*u %*u %*u %*u %llu %llu"; /* ~2.1.91 < kernel version */ /* The information about the network devices */ static int ndevices=0; static unsigned long *current=NULL,*previous=NULL; static char **device=NULL; /* A function to add a new device */ static void add_device(char *dev); /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; /* Verify the statistics from /proc/net/dev */ f=fopen("/proc/net/dev","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/net/dev'.\n",__FILE__); else { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/net/dev'.\n",__FILE__); else if(strcmp(line,"Inter-| Receive | Transmit\n") && /* kernel version < ~2.1.80 */ strcmp(line,"Inter-| Receive | Transmit\n") && /* ~2.1.80 < kernel version > ~2.1.91 */ strcmp(line,"Inter-| Receive | Transmit\n")) /* ~2.1.91 < kernel version */ fprintf(stderr,"ProcMeter(%s): Unexpected header line 1 in '/proc/net/dev'.\n",__FILE__); else { fgets_realloc(&line,&length,f); if(strcmp(line," face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n") && /* kernel version < ~2.1.28 */ strcmp(line," face |bytes packets errs drop fifo frame|bytes packets errs drop fifo colls carrier\n") && /* ~2.1.28 < kernel version < ~2.1.80 */ strcmp(line," face |bytes packets errs drop fifo frame|bytes packets errs drop fifo colls carrier multicast\n") && /* ~2.1.80 < kernel version < ~2.1.91 */ strcmp(line," face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n")) /* ~2.1.91 < kernel version */ fprintf(stderr,"ProcMeter(%s): Unexpected header line 2 in '/proc/net/dev'.\n",__FILE__); else { if(!strcmp(line," face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n")) proc_net_dev_format=proc_net_dev_format1; /* kernel version < ~2.1.28 */ else if(!strcmp(line," face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n")) proc_net_dev_format=proc_net_dev_format3; /* ~2.1.91 < kernel version */ else proc_net_dev_format=proc_net_dev_format2; /* ~2.1.28 < kernel version < ~2.1.80 (two possiblities) */ while(fgets_realloc(&line,&length,f)) { int i; char *dev=line; long long rxp=0,txp=0,rxb=0,txb=0; for(;*dev==' ';dev++) ; for(i=strlen(line);i>6 && line[i]!=':';i--); line[i++]=0; if(!strcmp(&line[i]," No statistics available.\n") || (proc_net_dev_format==proc_net_dev_format1 && sscanf(&line[i],proc_net_dev_format,&rxp,&txp)==2) || (proc_net_dev_format!=proc_net_dev_format1 && sscanf(&line[i],proc_net_dev_format,&rxb,&rxp,&txb,&txp)==4)) add_device(dev); } } } fclose(f); } /* Get the other options */ if(options) { char *l=options; while(*l && *l==' ') l++; while(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; add_device(l); *r=pr; while(*r && *r==' ') r++; if(!*r) break; l=r; } } current =(unsigned long*)calloc(sizeof(long),ndevices); previous=(unsigned long*)calloc(sizeof(long),ndevices); return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Add a new device to the list. char *dev The name of the device to add. ++++++++++++++++++++++++++++++++++++++*/ static void add_device(char *dev) { int pscale,bscale,nstats; int i; for(i=0;iname, PROCMETER_NAME_LEN+1, _outputs[i].name, dev); outputs[ndevices]->description=(char*)malloc(strlen(dev)+strlen(_outputs[i].description)+4); sprintf(outputs[ndevices]->description,_outputs[i].description,dev); if(i%2) outputs[ndevices]->graph_scale=bscale; else outputs[ndevices]->graph_scale=pscale; strcpy(device[ndevices],dev); ndevices++; if(proc_net_dev_format==proc_net_dev_format1) i+=2; else i++; } outputs[ndevices]=NULL; } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static time_t last=0; int j; /* Get the statistics from /proc/net/dev */ if(now!=last) { FILE *f; unsigned long *temp; temp=current; current=previous; previous=temp; for(j=0;outputs[j];j++) current[j]=0; f=fopen("/proc/net/dev","r"); if(!f) return(-1); fgets_realloc(&line,&length,f); fgets_realloc(&line,&length,f); while(fgets_realloc(&line,&length,f)) { int i; long long rxp=0,txp=0,rxb=0,txb=0; char *dev=line; for(;*dev==' ';dev++) ; for(i=strlen(line);i>6 && line[i]!=':';i--); line[i++]=0; if(proc_net_dev_format==proc_net_dev_format1) sscanf(&line[i],proc_net_dev_format,&rxp,&txp); else sscanf(&line[i],proc_net_dev_format,&rxb,&rxp,&txb,&txp); for(j=0;outputs[j];j++) if(!strcmp(device[j],dev)) { if(proc_net_dev_format==proc_net_dev_format1 && outputs[j+1] && !strcmp(device[j+1],dev)) { current[ j]=rxp+txp; current[++j]=txp; current[++j]=rxp; } else if(proc_net_dev_format!=proc_net_dev_format1 && outputs[j+2] && !strcmp(device[j+2],dev)) { current[ j]=rxp+txp; current[++j]=rxb+txb; current[++j]=txp; current[++j]=txb; current[++j]=rxp; current[++j]=rxb; } else if(proc_net_dev_format==proc_net_dev_format1) current[j]=txp; else /* proc_net_dev_format!=proc_net_dev_format1 */ { current[ j]=txp; current[++j]=txb; } break; } } fclose(f); last=now; } for(j=0;outputs[j];j++) if(output==outputs[j]) { double value; if(current[j]==0) /* stopped ppp0 device */ value=0.0; else if(previous[j]>current[j]) /* wrap around of 32 bit counter */ value=(4.294967296e9-(double)(previous[j]-current[j]))/output->interval; else value=(double)(current[j]-previous[j])/output->interval; if(proc_net_dev_format!=proc_net_dev_format1 && j%2) value/=1024.0; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); if(proc_net_dev_format!=proc_net_dev_format1 && j%2) sprintf(output->text_value,"%.1f kB/s",value); else sprintf(output->text_value,"%.0f /s",value); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(outputs) { for(i=0;outputs[i];i++) { free(outputs[i]->description); free(outputs[i]); } free(outputs); } if(current) free(current); if(previous) free(previous); if(device) { for(i=0;i #include #include "procmeter.h" /* The interface information. */ /*+ The version output +*/ ProcMeterOutput version_output= { /* char name[]; */ "Version", /* char *description; */ "The version of procmeter that is running.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 0, /* char text_value[]; */ "ProcMeter V" PROCMETER_VERSION, /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[]= { &version_output, NULL }; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "ProcMeter", /* char *description; */ "Information about the procmeter program itself.", }; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { if(output==&version_output) return(0); return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { } procmeter3-3.5d/modules/sensors.c000066400000000000000000000310431165060751200171240ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/sensors.c,v 1.11 2010-02-20 13:32:10 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Temperature indicators for Mainboard and CPU Based on loadavg.c, stat-cpu.c by Andrew M. Bishop ******************/ /****************** Written by Matt Kemner, Andrew M. Bishop This file Copyright 1999, 2010 Matt Kemner, Andrew M. Bishop parts of it are Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The mainboard temperature output. +*/ ProcMeterOutput _temp_output= { /* char name[]; */ "Temp%d", /* char *description; */ "Temperature sensor number %d [from %s].", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d C)" }; /*+ The mainboard fan output. +*/ ProcMeterOutput _fan_output= { /* char name[]; */ "Fan%d", /* char *description; */ "Fan speed sensor number %d [from %s].", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "unknown", /* long graph_value; */ 0, /* short graph_scale; */ 1000, /* char graph_units[]; */ "(%d rpm)" }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Sensors", /* char *description; */ "Hardware status information, temperature, fan speed etc." " (Requires lm_sensors patch from http://www.netroedge.com/~lm78/ or version 2.6 kernel).", }; /* The line buffer */ static char *line=NULL; static size_t length=64; /*+ The temperature outputs. +*/ ProcMeterOutput *temp_outputs=NULL; /*+ The fan outputs. +*/ ProcMeterOutput *fan_outputs=NULL; /*+ The names of the files containing the temperature information. +*/ static char **temp_filename=NULL; /*+ The names of the files containing the fan speed information. +*/ static char **fan_filename=NULL; /*+ The number of temperature sensors. +*/ static int ntemps=0; /*+ The number of fan speed sensors. +*/ static int nfans=0; /*+ A flag to indicate if it is kernel version 2.6.0 or later +*/ int kernel_2_6_0=0; /* Functions to find and add a temperature monitor or a fan */ static void search_directory(const char *dirname); static void add_temperature(char *filename); static void add_fan(char *filename); /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { DIR *d1; struct dirent *ent1; char *dirstart=NULL; int kernel_2_6_22=0; int n=0,i; /* Find the directory with the sensor information in it. */ if((d1=opendir("/proc/sys/dev/sensors"))) /* kernel < 2.6.0 */ { dirstart="/proc/sys/dev/sensors"; kernel_2_6_0=0; } else if((d1=opendir("/sys/class/hwmon"))) /* kernel >= 2.6.22 */ { dirstart="/sys/class/hwmon"; kernel_2_6_22=1; kernel_2_6_0=1; } else if((d1=opendir("/sys/bus/i2c/devices"))) /* kernel >= 2.6.0 */ { dirstart="/sys/bus/i2c/devices"; kernel_2_6_0=1; } if(d1) { char dirname[64]; while((ent1=readdir(d1))) { if(!strcmp(ent1->d_name,".")) continue; if(!strcmp(ent1->d_name,"..")) continue; if(kernel_2_6_22) /* kernel >= 2.6.22 */ { sprintf(dirname,"%s/%s/%s",dirstart,ent1->d_name,"device"); search_directory(dirname); } sprintf(dirname,"%s/%s",dirstart,ent1->d_name); search_directory(dirname); } closedir(d1); } outputs=(ProcMeterOutput**)malloc((1+ntemps+nfans)*sizeof(ProcMeterOutput*)); for(i=0;id_name,".")) continue; if(!strcmp(ent2->d_name,"..")) continue; sprintf(filename,"%s/%s",dirname,ent2->d_name); if(stat(filename,&buf)!=0 || !S_ISREG(buf.st_mode)) continue; if(!strncmp(ent2->d_name,"temp",4)) { if(!ent2->d_name[4]) add_temperature(filename); else if(isdigit(ent2->d_name[4]) && !ent2->d_name[5]) /* kernel < 2.6.0 */ add_temperature(filename); else if(isdigit(ent2->d_name[4]) && !strcmp(ent2->d_name+5,"_input")) /* kernel >= 2.6.0 */ add_temperature(filename); else if(!strncmp(ent2->d_name+5,"_input",6) && isdigit(ent2->d_name[10]) && !ent2->d_name[11]) /* kernel >= 2.6.0 */ add_temperature(filename); } else if(!strcmp(ent2->d_name,"remote_temp")) add_temperature(filename); else if(!strncmp(ent2->d_name,"fan",3)) { if(!ent2->d_name[3]) add_fan(filename); else if(isdigit(ent2->d_name[3]) && !ent2->d_name[4]) /* kernel < 2.6.0 */ add_fan(filename); else if(isdigit(ent2->d_name[3]) && !strcmp(ent2->d_name+4,"_input")) /* kernel >= 2.6.0 */ add_fan(filename); else if(!strncmp(ent2->d_name+4,"_input",6) && isdigit(ent2->d_name[9]) && !ent2->d_name[10]) /* kernel >= 2.6.0 */ add_fan(filename); } } closedir(d2); } } } /*++++++++++++++++++++++++++++++++++++++ Add a temperature output to the module. char *filename The name of the file. ++++++++++++++++++++++++++++++++++++++*/ static void add_temperature(char *filename) { FILE *f; f=fopen(filename,"r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '%s'.\n",__FILE__,filename); else { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '%s'.\n",__FILE__,filename); else { double t1,t2,t3; if(!kernel_2_6_0 && sscanf(line,"%lf %lf %lf",&t1,&t2,&t3)!=3) fprintf(stderr,"ProcMeter(%s): Unexpected line in '%s'.\n",__FILE__,filename); else if(kernel_2_6_0 && sscanf(line,"%lf",&t1)!=1) fprintf(stderr,"ProcMeter(%s): Unexpected line in '%s'.\n",__FILE__,filename); else { temp_filename=(char**)realloc((void*)temp_filename,(ntemps+1)*sizeof(char*)); temp_filename[ntemps]=(char*)malloc(strlen(filename)+1); strcpy(temp_filename[ntemps],filename); temp_outputs=(ProcMeterOutput*)realloc((void*)temp_outputs,(ntemps+1)*sizeof(ProcMeterOutput)); temp_outputs[ntemps]=_temp_output; snprintf(temp_outputs[ntemps].name, PROCMETER_NAME_LEN+1, _temp_output.name, ntemps); temp_outputs[ntemps].description=(char*)malloc(strlen(_temp_output.description)+8+strlen(filename)); sprintf(temp_outputs[ntemps].description,_temp_output.description,ntemps,filename); ntemps++; } } fclose(f); } } /*++++++++++++++++++++++++++++++++++++++ Add a fan speed output to the module. char *filename The name of the file. ++++++++++++++++++++++++++++++++++++++*/ static void add_fan(char *filename) { FILE *f; f=fopen(filename,"r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '%s'.\n",__FILE__,filename); else { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '%s'.\n",__FILE__,filename); else { int f1,f2; if(!kernel_2_6_0 && sscanf(line,"%d %d",&f1,&f2)!=2) fprintf(stderr,"ProcMeter(%s): Unexpected line in '%s'.\n",__FILE__,filename); else if(kernel_2_6_0 && sscanf(line,"%d",&f1)!=1) fprintf(stderr,"ProcMeter(%s): Unexpected line in '%s'.\n",__FILE__,filename); else { fan_filename=(char**)realloc((void*)fan_filename,(nfans+1)*sizeof(char*)); fan_filename[nfans]=(char*)malloc(strlen(filename)+1); strcpy(fan_filename[nfans],filename); fan_outputs=(ProcMeterOutput*)realloc((void*)fan_outputs,(nfans+1)*sizeof(ProcMeterOutput)); fan_outputs[nfans]=_fan_output; snprintf(fan_outputs[nfans].name, PROCMETER_NAME_LEN, _fan_output.name, nfans); fan_outputs[nfans].description=(char*)malloc(strlen(_fan_output.description)+8+strlen(filename)); sprintf(fan_outputs[nfans].description,_fan_output.description,nfans,filename); nfans++; } } fclose(f); } } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static int warn_temp=1,warn_fan=1; int i; /* Get the temperature statistics */ for(i=0;itext_value,"%.1f C",temp); output->graph_value=PROCMETER_GRAPH_FLOATING(temp/output->graph_scale); return(0); } } /* Get the fan speed statistics */ for(i=0;itext_value,"%d rpm",fan); output->graph_value=PROCMETER_GRAPH_FLOATING((double)fan/output->graph_scale); return(0); } } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; for(i=0;i #include #include #include "procmeter.h" #define CPU 0 #define CPU_USER 1 #define CPU_NICE 2 #define CPU_SYS 3 #define CPU_IDLE 4 #define CPU_IOWAIT 5 #define CPU_IRQ 6 #define CPU_SOFTIRQ 7 #define CPU_STEAL 8 #define N_OUTPUTS_24 5 #define N_OUTPUTS_26 9 /* The interface information. */ /*+ The normal outputs +*/ ProcMeterOutput _outputs[N_OUTPUTS_26]= { /*+ The total cpu output +*/ { /* char name[]; */ "CPU", /* char *description; */ "The total fraction of the time that the CPU is busy.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The user cpu output +*/ { /* char name[]; */ "CPU_User", /* char *description; */ "The fraction of the time that the CPU is processing user level code (applications).", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The nice cpu output +*/ { /* char name[]; */ "CPU_Nice", /* char *description; */ "The fraction of the time that the CPU is running processes that run at a lowered priority.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The system cpu output +*/ { /* char name[]; */ "CPU_System", /* char *description; */ "The fraction of the time that the CPU is processing system level code (kernel).", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The idle cpu output +*/ { /* char name[]; */ "CPU_Idle", /* char *description; */ "The fraction of the time that the CPU is idle.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The iowait cpu output +*/ { /* char name[]; */ "CPU_IOWait", /* char *description; */ "The fraction of the time that the CPU is waiting for IO.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The irq cpu output +*/ { /* char name[]; */ "CPU_IRQ", /* char *description; */ "The fraction of the time that the CPU is waiting for IRQs.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The softirq cpu output +*/ { /* char name[]; */ "CPU_SoftIRQ", /* char *description; */ "The fraction of the time that the CPU is ???.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The steal cpu output +*/ { /* char name[]; */ "CPU_Steal", /* char *description; */ "The fraction of the time that the CPU is ???.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" } }; /*+ The outputs with multiple CPUs +*/ ProcMeterOutput _smp_outputs[N_OUTPUTS_26]= { /*+ The total cpu output +*/ { /* char name[]; */ "CPU%d", /* char *description; */ "The total fraction of the time that the CPU number %d is busy.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The user cpu output +*/ { /* char name[]; */ "CPU%d_User", /* char *description; */ "The fraction of the time that the CPU number %d is processing user level code (applications).", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The nice cpu output +*/ { /* char name[]; */ "CPU%d_Nice", /* char *description; */ "The fraction of the time that the CPU number %d is running processes that run at a lowered priority.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The system cpu output +*/ { /* char name[]; */ "CPU%d_System", /* char *description; */ "The fraction of the time that the CPU number %d is processing system level code (kernel).", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The idle cpu output +*/ { /* char name[]; */ "CPU%d_Idle", /* char *description; */ "The fraction of the time that the CPU number %d is idle.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The iowait cpu output +*/ { /* char name[]; */ "CPU%d_IOWait", /* char *description; */ "The fraction of the time that the CPU number %d is waiting for IO.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The irq cpu output +*/ { /* char name[]; */ "CPU%d_IRQ", /* char *description; */ "The fraction of the time that the CPU number %d is waiting for IRQs.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The softirq cpu output +*/ { /* char name[]; */ "CPU%d_SoftIRQ", /* char *description; */ "The fraction of the time that the CPU number %d is ???.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The steal cpu output +*/ { /* char name[]; */ "CPU%d_Steal", /* char *description; */ "The fraction of the time that the CPU number %d is ???.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" } }; /*+ The extra outputs with multiple CPUs +*/ ProcMeterOutput *smp_outputs=NULL; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Stat-CPU", /* char *description; */ "CPU usage statistics. [From /proc/stat]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* The current and previous values read from the file */ static unsigned long long *current,*previous,values[2][N_OUTPUTS_26]; static unsigned long long *smp_current,*smp_previous,*smp_values[2]={NULL,NULL}; /*+ The number of CPUs (or 0 for only 1!). +*/ static int ncpus=0; /*+ A flag to indicate that this is kernel v2.6 and has 8 CPU counters. +*/ static int kernel_26=0; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n=0; outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; current=values[0]; previous=values[1]; /* Verify the statistics from /proc/stat */ f=fopen("/proc/stat","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/stat'.\n",__FILE__); else { if(!fgets_realloc(&line,&length,f)) /* cpu */ fprintf(stderr,"ProcMeter(%s): Could not read '/proc/stat'.\n",__FILE__); else { unsigned long long d1,d2,d3,d4,d5,d6,d7,d8; if(sscanf(line,"cpu %llu %llu %llu %llu %llu %llu %llu %llu",&d1,&d2,&d3,&d4,&d5,&d6,&d7,&d8)==8) kernel_26=1; if(kernel_26 || sscanf(line,"cpu %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) { int i,n_outputs; if(kernel_26) n_outputs=N_OUTPUTS_26; else n_outputs=N_OUTPUTS_24; /* cpu or disk or page */ while(fgets_realloc(&line,&length,f) && line[0]=='c' && line[1]=='p' && line[2]=='u') /* kernel version > ~2.1.84 */ { int ncpu; if((kernel_26 && sscanf(line,"cpu%d %llu %llu %llu %llu %llu %llu %llu %llu",&ncpu,&d1,&d2,&d3,&d4,&d5,&d6,&d7,&d8)==9) || sscanf(line,"cpu%d %llu %llu %llu %llu",&ncpu,&d1,&d2,&d3,&d4)==5) { ncpus++; smp_values[0]=(unsigned long long*)realloc((void*)smp_values[0],ncpus*N_OUTPUTS_26*sizeof(unsigned long long)); smp_values[1]=(unsigned long long*)realloc((void*)smp_values[1],ncpus*N_OUTPUTS_26*sizeof(unsigned long long)); smp_current=smp_values[0]; smp_previous=smp_values[1]; smp_outputs=(ProcMeterOutput*)realloc((void*)smp_outputs,ncpus*n_outputs*sizeof(ProcMeterOutput)); for(i=0;i ~2.1.84 */ { int ncpu,offset; unsigned long long cpu_user,cpu_nice,cpu_sys,cpu_idle,cpu_iowait,cpu_irq,cpu_softirq,cpu_steal; sscanf(line,"cpu%d %llu %llu %llu %llu %llu %llu %llu %llu",&ncpu,&cpu_user,&cpu_nice,&cpu_sys,&cpu_idle, &cpu_iowait,&cpu_irq,&cpu_softirq,&cpu_steal); offset=ncpu*N_OUTPUTS_26; smp_current[CPU_USER +offset]=cpu_user; smp_current[CPU_NICE +offset]=cpu_nice; smp_current[CPU_SYS +offset]=cpu_sys; smp_current[CPU_IDLE +offset]=cpu_idle; smp_current[CPU_IOWAIT +offset]=cpu_iowait; smp_current[CPU_IRQ +offset]=cpu_irq; smp_current[CPU_SOFTIRQ+offset]=cpu_softirq; smp_current[CPU_STEAL +offset]=cpu_steal; smp_current[CPU+offset]=smp_current[CPU_USER+offset]+smp_current[CPU_NICE+offset]+smp_current[CPU_SYS+offset]; if(kernel_26) smp_current[CPU+offset]+=smp_current[CPU_IOWAIT+offset]+smp_current[CPU_IRQ+offset]+smp_current[CPU_SOFTIRQ+offset]+smp_current[CPU_STEAL+offset]; } fclose(f); last=now; } if(kernel_26) n_outputs=N_OUTPUTS_26; else n_outputs=N_OUTPUTS_24; for(i=0;i100.0) value=100.0; else if(value<0.0) value=0.0; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f %%",value); return(0); } for(i=0;i100.0) value=100.0; else if(value<0.0) value=0.0; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f %%",value); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { if(ncpus) { int i,n_outputs; if(kernel_26) n_outputs=N_OUTPUTS_26; else n_outputs=N_OUTPUTS_24; for(i=0;i #include #include #include #include #include #include #include #include #include "procmeter.h" #define DISK 0 #define DISK_READ 1 #define DISK_WRITE 2 #define N_OUTPUTS 3 /* The interface information. */ /*+ The total disk statistics +*/ ProcMeterOutput _outputs[N_OUTPUTS]= { /*+ The disk blocks accessed per second +*/ { /* char name[]; */ "Disk", /* char *description; */ "The total number of disk blocks that are accessed per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks read per second +*/ { /* char name[]; */ "Disk_Read", /* char *description; */ "The number of disk blocks that are read per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks write per second +*/ { /* char name[]; */ "Disk_Write", /* char *description; */ "The number of disk blocks that are written per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" } }; /*+ The per disk statistics for kernels older than 2.4.0 +*/ ProcMeterOutput _disk_outputs_pre_240[N_OUTPUTS]= { /*+ The disk blocks accessed per second +*/ { /* char name[]; */ "Disk%d", /* char *description; */ "The total number of disk blocks that are accessed per second on disk %d.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks read per second +*/ { /* char name[]; */ "Disk%d_Read", /* char *description; */ "The number of disk blocks that are read per second on disk %d.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks write per second +*/ { /* char name[]; */ "Disk%d_Write", /* char *description; */ "The number of disk blocks that are written per second on disk %d.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" } }; /*+ The per disk statistics +*/ ProcMeterOutput _disk_outputs[N_OUTPUTS]= { /*+ The disk blocks accessed per second +*/ { /* char name[]; */ "Disk_%s", /* char *description; */ "The total number of disk blocks that are accessed per second on disk %s.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks read per second +*/ { /* char name[]; */ "Disk_%s_R", /* char *description; */ "The number of disk blocks that are read per second on disk %s.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks write per second +*/ { /* char name[]; */ "Disk_%s_W", /* char *description; */ "The number of disk blocks that are written per second on disk %s.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" } }; /*+ The extra outputs with multiple disks +*/ ProcMeterOutput *disk_outputs=NULL; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Stat-Disk", /* char *description; */ "Disk usage statistics. [From /proc/diskstats or /proc/stat]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* The current and previous information about the disk */ static unsigned long long *current,*previous,*values[2]; /* The information about the disks */ static int ndisks=4; static unsigned *majors=NULL,*minors=NULL,*indexes=NULL; /* The estimated kernel version based on the file format */ static int kernel_version_130=0; static int kernel_version_240=0; static int kernel_version_260=0; /* A function to add a disk */ static int add_disk(char *devname); /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; disk_outputs=(ProcMeterOutput*)malloc((N_OUTPUTS*ndisks)*sizeof(ProcMeterOutput)); outputs=(ProcMeterOutput**)malloc((N_OUTPUTS*(ndisks+1)+1)*sizeof(ProcMeterOutput*)); outputs[0]=NULL; /* Check for /proc/diskstats in kernel 2.6.x */ f=fopen("/proc/diskstats","r"); if(!f) { /* Verify the statistics from /proc/stat */ f=fopen("/proc/stat","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/stat'.\n",__FILE__); else { /* cpu */ if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/stat'.\n",__FILE__); else { while(fgets_realloc(&line,&length,f)) /* cpu or disk or page or swap or intr or disk_io */ if(line[0]=='d' && line[1]=='i' && line[2]=='s' && line[3]=='k') break; if(!line[0]) fprintf(stderr,"ProcMeter(%s): Unexpected 'disk' line in '/proc/stat'.\n" " expected: 'disk ...' or 'disk_io ...'\n" " found: EOF\n",__FILE__); else if(!strncmp(line,"disk ",5)) /* kernel version < ~2.4.0-test4 */ { unsigned long long d1,d2,d3,d4; if(sscanf(line,"disk %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) { int i,j; int read_avail=0,write_avail=0; int n=0; /* disk_* or page */ while(fgets_realloc(&line,&length,f) && line[0]=='d') /* kernel version > ~1.3.0 */ { if(sscanf(line,"disk_rblk %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) read_avail=1; if(sscanf(line,"disk_wblk %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) write_avail=1; } if(read_avail && write_avail) kernel_version_130=1; for(i=0;i ~2.4.0-test4 */ { int maj,min,idx,num=8,nm,nr; unsigned long long d1,d2,d3,d4,d5; DIR *devdir,*devdiscsdir,*devmapperdir; char devname[PATH_MAX]; struct dirent *ent; struct stat buf; kernel_version_240=1; ndisks=0; devdir=opendir("/dev"); devdiscsdir=opendir("/dev/discs"); devmapperdir=opendir("/dev/mapper"); while((nr=sscanf(line+num," (%d,%d):(%llu,%llu,%llu,%llu,%llu)%n",&maj,&idx,&d1,&d2,&d3,&d4,&d5,&nm))==7 || (nr=sscanf(line+num," (%d,%d):(%llu,%llu,%llu,%llu)%n",&maj,&idx,&d1,&d2,&d3,&d4,&nm))==6) { int done=0; num+=nm; kernel_version_240=nr; /* This switch statement is the inverse of the one in /usr/include/linux/genhd.h */ switch (maj) { case DAC960_MAJOR+0: min=idx<<3; break; case SCSI_DISK0_MAJOR: min=idx<<4; break; case IDE0_MAJOR: /* same as HD_MAJOR */ case XT_DISK_MAJOR: min=idx<<6; break; case IDE1_MAJOR: min=(idx-2)<<6; break; default: min=0; } if(devmapperdir) { rewinddir(devmapperdir); while((ent=readdir(devmapperdir))) { sprintf(devname,"/dev/mapper/%s",ent->d_name); if(!lstat(devname,&buf) && S_ISBLK(buf.st_mode) && !S_ISLNK(buf.st_mode) && major(buf.st_rdev)==maj && minor(buf.st_rdev)==min) done=add_disk(devname); } } if(!done && devdiscsdir) { rewinddir(devdiscsdir); while((ent=readdir(devdiscsdir))) { sprintf(devname,"/dev/discs/%s/disc",ent->d_name); if(!lstat(devname,&buf) && S_ISBLK(buf.st_mode) && !S_ISLNK(buf.st_mode) && major(buf.st_rdev)==maj && minor(buf.st_rdev)==min) done=add_disk(devname); } } if(!done && devdir) { rewinddir(devdir); while((ent=readdir(devdir))) { sprintf(devname,"/dev/%s",ent->d_name); if(!lstat(devname,&buf) && S_ISBLK(buf.st_mode) && !S_ISLNK(buf.st_mode) && major(buf.st_rdev)==maj && minor(buf.st_rdev)==min) done=add_disk(devname); } } if(!done) { fprintf(stderr,"ProcMeter(%s): Cannot find disk in /dev, /dev/mapper, or /dev/discs for device %d:%d in '/proc/stat'.\n",__FILE__,maj,min); continue; } } if(devdir) closedir(devdir); if(devdiscsdir) closedir(devdiscsdir); } else fprintf(stderr,"ProcMeter(%s): Unexpected 'disk' line in '/proc/stat'.\n" " expected: 'disk ...' or 'disk_io ...'\n" " found: %s",__FILE__,line); } fclose(f); } } else /* Found /proc/diskstats in kernel 2.6.x */ { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/diskstats'.\n",__FILE__); else { int maj,min,nr; unsigned long long d1,d2,d3,d4,d5; DIR *devdir,*devdiscsdir,*devmapperdir; char devname[PATH_MAX]; struct dirent *ent; struct stat buf; kernel_version_260=1; ndisks=0; devdir=opendir("/dev"); devdiscsdir=opendir("/dev/discs"); devmapperdir=opendir("/dev/mapper"); do { int done=0; nr=sscanf(line,"%d %d %*s %llu %llu %llu %llu %llu",&maj,&min,&d1,&d2,&d3,&d4,&d5); if(nr<6) break; if(devmapperdir) { rewinddir(devmapperdir); while((ent=readdir(devmapperdir))) { sprintf(devname,"/dev/mapper/%s",ent->d_name); if(!lstat(devname,&buf) && S_ISBLK(buf.st_mode) && !S_ISLNK(buf.st_mode) && major(buf.st_rdev)==maj && minor(buf.st_rdev)==min) done=add_disk(devname); } } if(!done && devdiscsdir) { rewinddir(devdiscsdir); while((ent=readdir(devdiscsdir))) { sprintf(devname,"/dev/discs/%s/disc",ent->d_name); if(!lstat(devname,&buf) && S_ISBLK(buf.st_mode) && !S_ISLNK(buf.st_mode) && major(buf.st_rdev)==maj && minor(buf.st_rdev)==min) done=add_disk(devname); } } if(!done && devdir) { rewinddir(devdir); while((ent=readdir(devdir))) { sprintf(devname,"/dev/%s",ent->d_name); if(!lstat(devname,&buf) && S_ISBLK(buf.st_mode) && !S_ISLNK(buf.st_mode) && major(buf.st_rdev)==maj && minor(buf.st_rdev)==min) done=add_disk(devname); } } if(!done) { fprintf(stderr,"ProcMeter(%s): Cannot find disk in /dev, /dev/mapper, or /dev/discs for device %d:%d in '/proc/diskstats'.\n",__FILE__,maj,min); continue; } } while(fgets_realloc(&line,&length,f)); if(devdir) closedir(devdir); if(devdiscsdir) closedir(devdiscsdir); } } /* Add in the options from the config file. */ if(options && (kernel_version_240 || kernel_version_260)) { char *l=options; while(*l && *l==' ') l++; while(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; if(!add_disk(l)) fprintf(stderr,"ProcMeter(%s): Cannot find device for disk %s.\n",__FILE__,l); *r=pr; while(*r && *r==' ') r++; if(!*r) break; l=r; } } if(kernel_version_240 || kernel_version_260) { int i,j,n=0; for(i=0;i ~2.4.0-test4). int add_disk Returns 1 if a disk was added. char *devname The name of the device to add. ++++++++++++++++++++++++++++++++++++++*/ static int add_disk(char *devname) { struct stat buf; char *diskname=devname+strlen(devname); int maj,min,idx=0,i; if(stat(devname,&buf) || !S_ISBLK(buf.st_mode)) return(0); maj=major(buf.st_rdev); min=minor(buf.st_rdev); /* This switch statement is the one in /usr/include/linux/genhd.h for kernels < 2.6.0 */ if(kernel_version_240) switch (maj) { case DAC960_MAJOR+0: idx = (min & 0x00f8) >> 3; break; case SCSI_DISK0_MAJOR: idx = (min & 0x00f0) >> 4; break; case IDE0_MAJOR: /* same as HD_MAJOR */ case XT_DISK_MAJOR: idx = (min & 0x0040) >> 6; break; case IDE1_MAJOR: idx = ((min & 0x0040) >> 6) + 2; break; default: idx=0; } while(diskname>devname && *diskname!='/') diskname--; if(diskname==devname) return(0); diskname++; majors =(unsigned*)realloc((void*)majors ,(ndisks+1)*sizeof(unsigned)); minors =(unsigned*)realloc((void*)minors ,(ndisks+1)*sizeof(unsigned)); indexes=(unsigned*)realloc((void*)indexes,(ndisks+1)*sizeof(unsigned)); if(ndisks>=3) { disk_outputs=(ProcMeterOutput*)realloc((void*)disk_outputs,(N_OUTPUTS*(ndisks+1))*sizeof(ProcMeterOutput)); outputs=(ProcMeterOutput**)realloc((void*)outputs,(N_OUTPUTS*(ndisks+1+1)+1)*sizeof(ProcMeterOutput*)); } for(i=0;i=SCSI_DISK1_MAJOR && maj<=SCSI_DISK7_MAJOR) || (maj>=SCSI_DISK8_MAJOR && maj<=SCSI_DISK15_MAJOR)) && (min%16)==0) || (maj==XT_DISK_MAJOR && (min%64)==0) || (maj==14 && (min%64)==0) || (maj==MFM_ACORN_MAJOR && (min%64)==0) || (maj==ACSI_MAJOR && (min%16)==0) || (maj==PS2ESDI_MAJOR && (min%64)==0) || (maj==44 && (min%16)==0) || (maj==45 && (min%16)==0) || (maj>=48 && maj<=55 && (min%8)==0) || (maj>=COMPAQ_SMART2_MAJOR && maj<=COMPAQ_SMART2_MAJOR7 && (min%16)==0) || (maj>=I2O_MAJOR && maj<=(I2O_MAJOR+7) && (min%16)==0) || (maj==92 && (min%16)==0) || (maj==UBD_MAJOR && (min%16)==0) || (maj==101 && (min%16)==0) || (maj==102 && (min%16)==0) || (maj>=COMPAQ_CISS_MAJOR && maj<=COMPAQ_CISS_MAJOR7 && (min%16)==0) || (maj==VIODASD_MAJOR && (min%8)==0) || (maj==ATARAID_MAJOR && (min%16)==0) || (maj>=136 && maj<=143 && (min%8)==0) || (maj==153 && (min%16)==0) || (maj>=160 && maj<=161 && (min%32)==0) || (maj==XENVBD_MAJOR && (min%16)==0)) ; else { current[DISK_READ] +=dr; current[DISK_WRITE]+=dw; } } current[DISK]=current[DISK_READ]+current[DISK_WRITE]; fclose(f); } else { f=fopen("/proc/stat","r"); if(!f) return(-1); while(fgets_realloc(&line,&length,f)) /* cpu or disk or page or swap or intr or disk_io */ if(line[0]=='d' && line[1]=='i' && line[2]=='s' && line[3]=='k') break; if(!kernel_version_240) /* kernel version < ~2.4.0-test4 */ { if(!kernel_version_130) { sscanf(line,"disk %llu %llu %llu %llu",¤t[N_OUTPUTS*1+DISK],¤t[N_OUTPUTS*2+DISK], ¤t[N_OUTPUTS*3+DISK],¤t[N_OUTPUTS*4+DISK]); current[DISK]=current[N_OUTPUTS*1+DISK]+current[N_OUTPUTS*2+DISK]+ current[N_OUTPUTS*3+DISK]+current[N_OUTPUTS*4+DISK]; } /* disk_* or page */ while(fgets_realloc(&line,&length,f) && line[0]=='d') /* kernel version > ~1.3.0 */ { if(sscanf(line,"disk_rblk %llu %llu %llu %llu",¤t[N_OUTPUTS*1+DISK_READ],¤t[N_OUTPUTS*2+DISK_READ], ¤t[N_OUTPUTS*3+DISK_READ],¤t[N_OUTPUTS*4+DISK_READ])==4) current[DISK_READ]=current[N_OUTPUTS*1+DISK_READ]+current[N_OUTPUTS*2+DISK_READ]+ current[N_OUTPUTS*3+DISK_READ]+current[N_OUTPUTS*4+DISK_READ]; if(sscanf(line,"disk_wblk %llu %llu %llu %llu",¤t[N_OUTPUTS*1+DISK_WRITE],¤t[N_OUTPUTS*2+DISK_WRITE], ¤t[N_OUTPUTS*3+DISK_WRITE],¤t[N_OUTPUTS*4+DISK_WRITE])==4) current[DISK_WRITE]=current[N_OUTPUTS*1+DISK_WRITE]+current[N_OUTPUTS*2+DISK_WRITE]+ current[N_OUTPUTS*3+DISK_WRITE]+current[N_OUTPUTS*4+DISK_WRITE]; } if(kernel_version_130) { int j; for(j=1;j<=ndisks;j++) current[N_OUTPUTS*j+DISK]=current[N_OUTPUTS*j+DISK_READ]+current[N_OUTPUTS*j+DISK_WRITE]; current[DISK]=current[DISK_READ]+current[DISK_WRITE]; } } else /* kernel version > ~2.4.0-test4 */ { int num=8,nm,nr=0; int j; current[DISK_READ]=0; current[DISK_WRITE]=0; while(1) { unsigned maj,idx; unsigned long long d1,d3; if(kernel_version_240==6) nr=sscanf(line+num," (%d,%d):(%*u,%llu,%*u,%llu)%n",&maj,&idx,&d1,&d3,&nm); else if(kernel_version_240==7) nr=sscanf(line+num," (%d,%d):(%*u,%llu,%*u,%llu,%*u)%n",&maj,&idx,&d1,&d3,&nm); if(nr!=4) break; for(j=0;jcurrent[i]) value=0.0; else value=(double)(current[i]-previous[i])/output->interval; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f /s",value); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i,j; for(i=0;i #include #include #include "procmeter.h" #define N_INTR 256 /* The interface information. */ /*+ The total statistics +*/ ProcMeterOutput _output= { /* char name[]; */ "Interrupts", /* char *description; */ "The total number of hardware interrupts per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 100, /* char graph_units[]; */ "(%d/s)" }; /*+ The per interrupt statistics +*/ ProcMeterOutput _intr_output= { /* char name[]; */ "Interrupt%d", /* char *description; */ "The number of hardware interrupts number %d (%s) per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 100, /* char graph_units[]; */ "(%d/s)" }; /*+ The extra outputs with multiple interrupts +*/ ProcMeterOutput intr_outputs[N_INTR]; /*+ The outputs. +*/ ProcMeterOutput *outputs[N_INTR+1+1]; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Stat-Intr", /* char *description; */ "Interrupt statistics. [From /proc/stat]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /*+ The number of interrupts. +*/ static int nintr=0; /* The current and previous information about the interrupts */ static unsigned long long *current,*previous,values[2][N_INTR+1]; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n; int n_intr=N_INTR; if(options) if(sscanf(options,"%d",&n)==1 && n>0 && ncurrent[i]) value=0.0; else value=(double)(current[i]-previous[i])/output->interval; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f /s",value); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; for(i=0;i #include #include #include "procmeter.h" #define CPU 0 #define CPU_USER 1 #define CPU_NICE 2 #define CPU_SYS 3 #define CPU_IDLE 4 #define DISK 5 #define DISK_READ 6 #define DISK_WRITE 7 #define SWAP 8 #define SWAP_IN 9 #define SWAP_OUT 10 #define PAGE 11 #define PAGE_IN 12 #define PAGE_OUT 13 #define CONTEXT 14 #define INTR 15 #define N_OUTPUTS 16 /* The interface information. */ /*+ The statistics +*/ ProcMeterOutput _outputs[N_OUTPUTS]= { /*+ The total cpu output +*/ { /* char name[]; */ "CPU", /* char *description; */ "The total fraction of the time that the CPU is busy.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The user cpu output +*/ { /* char name[]; */ "CPU_User", /* char *description; */ "The fraction of the time that the CPU is processing user level code (applications).", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The nice cpu output +*/ { /* char name[]; */ "CPU_Nice", /* char *description; */ "The fraction of the time that the CPU is running processes that run at a lowered priority.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The system cpu output +*/ { /* char name[]; */ "CPU_System", /* char *description; */ "The fraction of the time that the CPU is processing system level code (kernel).", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The idle cpu output +*/ { /* char name[]; */ "CPU_Idle", /* char *description; */ "The fraction of the time that the CPU is idle.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 %", /* long graph_value; */ 0, /* short graph_scale; */ 20, /* char graph_units[]; */ "(%d%%)" }, /*+ The disk blocks accessed per second +*/ { /* char name[]; */ "Disk", /* char *description; */ "The total number of disk blocks accessed per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks read per second +*/ { /* char name[]; */ "Disk_Read", /* char *description; */ "The total number of disk blocks that are read per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The disk blocks write per second +*/ { /* char name[]; */ "Disk_Write", /* char *description; */ "The total number of disk blocks that are written per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 25, /* char graph_units[]; */ "(%d/s)" }, /*+ The swap blocks accessed per second +*/ { /* char name[]; */ "Swap", /* char *description; */ "The total number of swap space blocks accessed per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The swap blocks in per second +*/ { /* char name[]; */ "Swap_In", /* char *description; */ "The number of swap space blocks that are read in per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The swap blocks out per second +*/ { /* char name[]; */ "Swap_Out", /* char *description; */ "The number of swap space blocks that are written out per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The page blocks accessed per second +*/ { /* char name[]; */ "Page", /* char *description; */ "The number of paged blocks accessed per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The page blocks in per second +*/ { /* char name[]; */ "Page_In", /* char *description; */ "The number of paged blocks that are read in per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The page blocks out per second +*/ { /* char name[]; */ "Page_Out", /* char *description; */ "The number of paged blocks that are dumped out per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The number of context switches per second +*/ { /* char name[]; */ "Context", /* char *description; */ "The number of context switches between running processes per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 100, /* char graph_units[]; */ "(%d/s)" }, /*+ The number of interrupts per second +*/ { /* char name[]; */ "Interrupts", /* char *description; */ "The number of hardware interrupts per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 100, /* char graph_units[]; */ "(%d/s)" } }; /*+ The outputs. +*/ ProcMeterOutput *outputs[N_OUTPUTS+1]; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Statistics", /* char *description; */ "Low level system statistics. [From /proc/stat]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* Information about the availability and the current and previous values */ static int available[N_OUTPUTS]; static unsigned long long *current,*previous,values[2][N_OUTPUTS]; /*+ A flag to indicate that this is kernel v2.4 and has many disk IO counters. +*/ static int kernel_version_240=0; /*+ A flag to indicate that this is kernel v2.6 and has 8 CPU counters. +*/ static int kernel_26=0; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n; outputs[0]=NULL; for(n=0;n ~2.1.84 */ ; if(!strncmp(line,"disk ",5)) /* kernel version < ~2.4.0-test4 */ { unsigned long long d1,d2,d3,d4; if(sscanf(line,"disk %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) available[DISK]=1; else fprintf(stderr,"ProcMeter(%s): Unexpected 'disk' line in '/proc/stat'.\n" " expected: 'disk %%llu %%llu %%llu %%llu'\n" " found: %s",__FILE__,line); /* disk_* or page */ while(fgets_realloc(&line,&length,f) && line[0]=='d') /* kernel version > ~1.3.0 */ { if(sscanf(line,"disk_rblk %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) available[DISK_READ]=1; if(sscanf(line,"disk_wblk %llu %llu %llu %llu",&d1,&d2,&d3,&d4)==4) available[DISK_WRITE]=1; } } if(!strncmp(line,"page",4)) /* kernel version < ~2.5.30 */ { if(sscanf(line,"page %llu %llu",&d1,&d2)==2) { available[PAGE]=available[PAGE_IN]=available[PAGE_OUT]=1; fgets_realloc(&line,&length,f); /* swap or intr */ } else fprintf(stderr,"ProcMeter(%s): Unexpected 'page' line in '/proc/stat'.\n" " expected: 'page %%llu %%llu'\n" " found: %s",__FILE__,line); if(sscanf(line,"swap %llu %llu",&d1,&d2)==2) { available[SWAP]=available[SWAP_IN]=available[SWAP_OUT]=1; fgets_realloc(&line,&length,f); /* intr */ } else fprintf(stderr,"ProcMeter(%s): Unexpected 'swap' line in '/proc/stat'.\n" " expected: 'swap %%llu %%llu'\n" " found: %s",__FILE__,line); } if(sscanf(line,"intr %llu",&d1)==1) { available[INTR]=1; fgets_realloc(&line,&length,f); /* disk_io or ctxt */ } else fprintf(stderr,"ProcMeter(%s): Unexpected 'intr' line in '/proc/stat'.\n" " expected: 'intr %%llu ...'\n" " found: %s",__FILE__,line); if(!strncmp(line,"disk_io: ",9)) /* kernel version > ~2.4.0-test4 */ { int maj,idx,num=8,nm,nr; unsigned long long d0,d1,d2,d3,d4; kernel_version_240=1; while((nr=sscanf(line+num," (%d,%d):(%llu,%llu,%llu,%llu,%llu)%n",&maj,&idx,&d0,&d1,&d2,&d3,&d4,&nm))==7 || (nr=sscanf(line+num," (%d,%d):(%llu,%llu,%llu,%llu)%n",&maj,&idx,&d0,&d1,&d2,&d3,&nm))==6) { num+=nm; kernel_version_240=nr; available[DISK]=1; available[DISK_READ]=1; available[DISK_WRITE]=1; } fgets_realloc(&line,&length,f); /* ctxt */ } if(sscanf(line,"ctxt %llu",&d1)==1) available[CONTEXT]=1; else fprintf(stderr,"ProcMeter(%s): Unexpected 'ctxt' line in '/proc/stat'.\n" " expected: 'ctxt %%llu'\n" " found: %s",__FILE__,line); for(i=0;i ~2.1.84 */ ; if(available[DISK] && !kernel_version_240) /* kernel version < ~2.4.0-test4 */ { unsigned long long d0,d1,d2,d3; if(available[DISK]) {sscanf(line,"disk %llu %llu %llu %llu",&d0,&d1,&d2,&d3);current[DISK]=d0+d1+d2+d3;} /* disk_* or page */ while(fgets_realloc(&line,&length,f) && line[0]=='d') /* kernel version > ~1.3.x */ { if(available[DISK_READ]) if(sscanf(line,"disk_rblk %llu %llu %llu %llu",&d0,&d1,&d2,&d3)==4) {current[DISK_READ]=d0+d1+d2+d3;} if(available[DISK_WRITE]) if(sscanf(line,"disk_wblk %llu %llu %llu %llu",&d0,&d1,&d2,&d3)==4) {current[DISK_WRITE]=d0+d1+d2+d3;} } } if(available[PAGE]) { sscanf(line,"page %llu %llu",¤t[PAGE_IN],¤t[PAGE_OUT]); fgets_realloc(&line,&length,f); /* swap */ } if(available[SWAP]) { sscanf(line,"swap %llu %llu",¤t[SWAP_IN],¤t[SWAP_OUT]); fgets_realloc(&line,&length,f); /* intr */ } if(available[INTR]) { sscanf(line,"intr %llu",¤t[INTR]); fgets_realloc(&line,&length,f); /* disk_io or ctxt */ } if(kernel_version_240 && available[DISK]) /* kernel version > ~2.4.0-test4 */ { int num=8,nm,nr=0; unsigned long long d1,d3; current[DISK_READ]=0; current[DISK_WRITE]=0; if(available[DISK]) while(1) { if(kernel_version_240==6) nr=sscanf(line+num," (%*d,%*d):(%*u,%llu,%*u,%llu)%n",&d1,&d3,&nm); else if(kernel_version_240==7) nr=sscanf(line+num," (%*d,%*d):(%*u,%llu,%*u,%llu,%*u)%n",&d1,&d3,&nm); if(nr!=2) break; current[DISK_READ] +=d1; current[DISK_WRITE]+=d3; num+=nm; } if(available[DISK]) current[DISK]=current[DISK_READ]+current[DISK_WRITE]; fgets_realloc(&line,&length,f); /* ctxt */ } if(available[CONTEXT]) sscanf(line,"ctxt %llu",¤t[CONTEXT]); if(available[CPU]) { current[CPU]=current[CPU_USER]+current[CPU_NICE]+current[CPU_SYS]; if(kernel_26) current[CPU]+=cpu_iowait+cpu_irq+cpu_softirq+cpu_steal; } if(available[PAGE]) current[PAGE]=current[PAGE_IN]+current[PAGE_OUT]; if(available[SWAP]) current[SWAP]=current[SWAP_IN]+current[SWAP_OUT]; fclose(f); last=now; } for(i=0;i100.0) value=100.0; else if(value<0.0) value=0.0; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f %%",value); break; default: if(previous[i]>current[i]) value=0.0; else value=(double)(current[i]-previous[i])/output->interval; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f /s",value); } return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { if(line) free(line); } procmeter3-3.5d/modules/template.c000066400000000000000000000063641165060751200172530ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/template.c,v 1.5 2002-12-07 19:41:00 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.4. Module template source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99,2002 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The graph output +*/ ProcMeterOutput graph_output= { /* char name[]; */ "Example_Graph", /* char *description; */ "An example graph to show how it works", /* char type; */ PROCMETER_GRAPH|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "n/a", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d)" }; /*+ The text output. +*/ ProcMeterOutput text_output= { /* char name[]; */ "Example_Text", /* char *description; */ "An example text field to show how it works", /* char type; */ PROCMETER_TEXT, /* short interval; */ 10, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[]= { &graph_output, &text_output, NULL }; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Template", /* char *description; */ "A source code template of the sort of module that ProcMeter can use.", }; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { if(output==&graph_output) { int result=now%100; output->graph_value=PROCMETER_GRAPH_FLOATING((double)result/output->graph_scale); return(0); } else if(output==&text_output) { static char result1[]="Example Output"; static char result2[]="ProcMeter"; if(now%60) strcpy(output->text_value,result1); else strcpy(output->text_value,result2); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { } procmeter3-3.5d/modules/uname.c000066400000000000000000000075151165060751200165440ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/uname.c,v 1.5 2002-12-07 19:40:25 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.4. Uname system information module source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,2002 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The hostname output. +*/ ProcMeterOutput hostname_output= { /* char name[]; */ "Hostname", /* char *description; */ "The canonical name of the computer.", /* char type; */ PROCMETER_TEXT, /* short interval; */ 0, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The kernel version output. +*/ ProcMeterOutput kernelversion_output= { /* char name[]; */ "Kernel_Version", /* char *description; */ "The kernel version that is running (%s).", /* char type; */ PROCMETER_TEXT, /* short interval; */ 0, /* char text_value[]; */ "unknown", /* long graph_value; */ -1, /* short graph_scale; */ 0, /* char graph_units[]; */ "n/a" }; /*+ The outputs. +*/ ProcMeterOutput *outputs[]= { &hostname_output, &kernelversion_output, NULL }; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Uname", /* char *description; */ "The system information from the uname program.", }; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { char *format,line[128]; struct utsname buf; FILE *f; strcpy(line,"unknown"); f=fopen("/proc/version","r"); if(!f) fprintf(stderr,"ProcMeter(%s): Could not open '/proc/version'\n",__FILE__); else { if(!fgets(line,128,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/version'\n",__FILE__); else line[strlen(line)-1]=0; fclose(f); } format=kernelversion_output.description; kernelversion_output.description=(char*)malloc(strlen(format)+strlen(line)); sprintf(kernelversion_output.description,format,line); if(uname(&buf)) fprintf(stderr,"ProcMeter(%s): Error calling uname()\n",__FILE__); else { char *p; snprintf(hostname_output.text_value, PROCMETER_NAME_LEN+1, "%s", buf.nodename); snprintf(kernelversion_output.text_value, PROCMETER_NAME_LEN+1, "%s", buf.release); p=hostname_output.text_value; while(*p && *p!='.') p++; *p=0; } return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. void *Update Returns the value (int or char*). time_t now The current time. ProcMeterOutput* output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput* output) { return(0); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { free(kernelversion_output.description); } procmeter3-3.5d/modules/vmstat.c000066400000000000000000000172151165060751200167530ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/vmstat.c,v 1.5 2008-05-05 18:45:36 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Low level system VM statistics source file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" #define PAGE 0 #define PAGE_IN 1 #define PAGE_OUT 2 #define SWAP 3 #define SWAP_IN 4 #define SWAP_OUT 5 #define N_OUTPUTS 6 /* The interface information. */ /*+ The statistics +*/ ProcMeterOutput _outputs[N_OUTPUTS]= { /*+ The page blocks accessed per second +*/ { /* char name[]; */ "Page", /* char *description; */ "The number of paged blocks accessed per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The page blocks in per second +*/ { /* char name[]; */ "Page_In", /* char *description; */ "The number of paged blocks that are read in per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The page blocks out per second +*/ { /* char name[]; */ "Page_Out", /* char *description; */ "The number of paged blocks that are dumped out per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The swap blocks accessed per second +*/ { /* char name[]; */ "Swap", /* char *description; */ "The total number of swap space blocks accessed per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The swap blocks in per second +*/ { /* char name[]; */ "Swap_In", /* char *description; */ "The number of swap space blocks that are read in per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" }, /*+ The swap blocks out per second +*/ { /* char name[]; */ "Swap_Out", /* char *description; */ "The number of swap space blocks that are written out per second.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0 /s", /* long graph_value; */ 0, /* short graph_scale; */ 50, /* char graph_units[]; */ "(%d/s)" } }; /*+ The outputs. +*/ ProcMeterOutput *outputs[N_OUTPUTS+1]; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "VM_Statistics", /* char *description; */ "Low level system virtual memory statistics. [From /proc/vmstat]", }; /* The line buffer */ static char *line=NULL; static size_t length=0; /* Information about the availability and the current and previous values */ static int available[N_OUTPUTS]; static unsigned long *current,*previous,values[2][N_OUTPUTS]; /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; int n; outputs[0]=NULL; for(n=0;ncurrent[i]) value=0.0; else value=(double)(current[i]-previous[i])/output->interval; output->graph_value=PROCMETER_GRAPH_FLOATING(value/output->graph_scale); sprintf(output->text_value,"%.0f /s",value); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { if(line) free(line); } procmeter3-3.5d/modules/wireless.c000066400000000000000000000222371165060751200172720ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/modules/wireless.c,v 1.11 2008-05-05 18:45:36 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Wireless network devices info source file. ******************/ /****************** Written by Joey Hess (with heavy borrowing from netdev.c) Original file Copyright 2001 Joey Hess Parts of this file Copyright 2001-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "procmeter.h" /* The interface information. */ /*+ The template for the network devices +*/ ProcMeterOutput _outputs[3]= { /*+ Link quality +*/ { /* char name[]; */ "Link_%s", /* char *description; */ "The link quality on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d dBm)" }, /*+ Signal level +*/ { /* char name[]; */ "Signal_%s", /* char *description; */ "The signal level on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d dBm)" }, /*+ Noise level +*/ { /* char name[]; */ "Noise_%s", /* char *description; */ "The noise level on the %s network interface.", /* char type; */ PROCMETER_GRAPH|PROCMETER_TEXT|PROCMETER_BAR, /* short interval; */ 1, /* char text_value[]; */ "0", /* long graph_value; */ 0, /* short graph_scale; */ 10, /* char graph_units[]; */ "(%d dBm)" } }; /*+ The outputs. +*/ ProcMeterOutput **outputs=NULL; /*+ The module. +*/ ProcMeterModule module= { /* char name[]; */ "Wireless", /* char *description; */ "The wireless network devices and link quality data on each of them. [From /proc/net/wireless] " "(Use 'options=eth0' in the configuration file to specify extra wireless devices." }; /* Whether there is a dot after each status int depends on whether the value * was updated since last read. */ static char *proc_net_wireless_format="%*i %i%*1[. ] %i%*1[. ] %i"; /* The line buffer */ static char *line=NULL; static size_t length=0; /* Information about the devices and the current and previous values */ static int ndevices=0; static unsigned long *current=NULL,*previous=NULL; static char **device=NULL; /* Add a new device */ static void add_device(char *dev); /*++++++++++++++++++++++++++++++++++++++ Load the module. ProcMeterModule *Load Returns the module information. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterModule *Load(void) { return(&module); } /*++++++++++++++++++++++++++++++++++++++ Initialise the module, creating the outputs as required. ProcMeterOutput **Initialise Returns a NULL terminated list of outputs. char *options The options string for the module from the .procmeterrc file. ++++++++++++++++++++++++++++++++++++++*/ ProcMeterOutput **Initialise(char *options) { FILE *f; outputs=(ProcMeterOutput**)malloc(sizeof(ProcMeterOutput*)); outputs[0]=NULL; /* Verify the statistics from /proc/net/dev */ f=fopen("/proc/net/wireless","r"); if(!f) ; /* Don't bother giving an error message for 99% of systems. */ else { if(!fgets_realloc(&line,&length,f)) fprintf(stderr,"ProcMeter(%s): Could not read '/proc/net/wireless'.\n",__FILE__); else if(strcmp(line,"Inter-| sta-| Quality | Discarded packets | Missed\n") == 0 && strcmp(line,"Inter-| sta-| Quality | Discarded packets | Missed | WE\n") == 0) fprintf(stderr,"ProcMeter(%s): Unexpected header line 1 in '/proc/net/wireless'.\n",__FILE__); else { fgets_realloc(&line,&length,f); if(strcmp(line," face | tus | link level noise | nwid crypt frag retry misc | beacon\n") == 0 && strcmp(line," face | tus | link level noise | nwid crypt frag retry misc | beacon | 16\n") == 0) fprintf(stderr,"ProcMeter(%s): Unexpected header line 2 in '/proc/net/wireless'.\n",__FILE__); else { while(fgets_realloc(&line,&length,f)) { int i; char *dev=line; int link=0, level=0, noise=0; for(;*dev==' ';dev++) ; for(i=strlen(line);i>6 && line[i]!=':';i--); line[i++]=0; if(sscanf(&line[i],proc_net_wireless_format,&link,&level,&noise)==3) add_device(dev); } } } fclose(f); } /* Get the other options */ if(options) { char *l=options; while(*l && *l==' ') l++; while(*l) { char *r=l,pr; while(*r && *r!=' ') r++; pr=*r; *r=0; add_device(l); *r=pr; while(*r && *r==' ') r++; if(!*r) break; l=r; } } current =(unsigned long*)calloc(sizeof(long),ndevices); previous=(unsigned long*)calloc(sizeof(long),ndevices); return(outputs); } /*++++++++++++++++++++++++++++++++++++++ Add a new device to the list. char *dev The name of the device to add. ++++++++++++++++++++++++++++++++++++++*/ static void add_device(char *dev) { int nstats=3; int i; for(i=0;iname,_outputs[i].name,dev); outputs[ndevices]->description=(char*)malloc(strlen(dev)+strlen(_outputs[i].description)+4); sprintf(outputs[ndevices]->description,_outputs[i].description,dev); strcpy(device[ndevices],dev); ndevices++; i++; } outputs[ndevices]=NULL; } /*++++++++++++++++++++++++++++++++++++++ Perform an update on one of the statistics. int Update Returns 0 if OK, else -1. time_t now The current time. ProcMeterOutput *output The output that the value is wanted for. ++++++++++++++++++++++++++++++++++++++*/ int Update(time_t now,ProcMeterOutput *output) { static time_t last=0; int j; /* Get the statistics from /proc/net/dev */ if(now!=last) { FILE *f; unsigned long *temp; temp=current; current=previous; previous=temp; for(j=0;outputs[j];j++) current[j]=0; f=fopen("/proc/net/wireless","r"); if(!f) return(-1); fgets_realloc(&line,&length,f); fgets_realloc(&line,&length,f); while(fgets_realloc(&line,&length,f)) { int i; signed int link=0; int level=0, noise=0; char *dev=line; for(;*dev==' ';dev++) ; for(i=strlen(line);i>6 && line[i]!=':';i--); line[i++]=0; sscanf(&line[i],proc_net_wireless_format,&link,&level,&noise); /* The kernel (2.4.17) misreports negative link values due to * underflow, so ignore what it reports for now, and calculate * link from level and noise. */ link = level - noise; if (link < 0) link = 0; for(j=0;outputs[j];j++) if(!strcmp(device[j],dev)) { current[ j]=link; /* FIXME This is not really right. * Subtracting this constant should only be done if * the stats are in dBm. If they are in relative values, no * substraction should be done. However, to find that out * would require a complex ioctl, and I have no cards that * use this latter style of reporting. */ current[++j]=level - 0x100; current[++j]=noise - 0x100; break; } } fclose(f); last=now; } for(j=0;outputs[j];j++) if(output==outputs[j]) { float val = (float)((float)(abs(current[j]))/output->graph_scale); output->graph_value=PROCMETER_GRAPH_FLOATING(val); sprintf(output->text_value,"%li dBm",current[j]); return(0); } return(-1); } /*++++++++++++++++++++++++++++++++++++++ Tidy up and prepare to have the module unloaded. ++++++++++++++++++++++++++++++++++++++*/ void Unload(void) { int i; if(outputs) { for(i=0;outputs[i];i++) { free(outputs[i]->description); free(outputs[i]); } free(outputs); } if(current) free(current); if(previous) free(previous); if(device) { for(i=0;iflag=RUN_NONE; run->command=NULL; } procmeter3-3.5d/procmeter.c000066400000000000000000000305601165060751200157630ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/procmeter.c,v 1.13 2007-11-20 18:59:35 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5. Main program. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2007 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include "procmeter.h" #include "procmeterp.h" static char *get_substring(char **start,int length); static void sigexit(int signum); static void sigchild(int signum); /*+ The signal to tell us to exit. +*/ int quit=0; /*+ Indicates that help mode is wanted. +*/ static int help=0; int main(int argc,char **argv) { time_t now,now2; struct sigaction action; int i; /* Handle signals */ /* SIGINT, SIGQUIT, SIGTERM */ action.sa_handler = sigexit; sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGINT); /* Block all of them */ sigaddset(&action.sa_mask, SIGQUIT); sigaddset(&action.sa_mask, SIGTERM); sigaddset(&action.sa_mask, SIGCHLD); action.sa_flags = 0; if(sigaction(SIGINT, &action, NULL) != 0) fprintf(stderr,"ProcMeter: Cannot install SIGINT handler.\n"); if(sigaction(SIGQUIT, &action, NULL) != 0) fprintf(stderr,"ProcMeter: Cannot install SIGQUIT handler.\n"); if(sigaction(SIGTERM, &action, NULL) != 0) fprintf(stderr,"ProcMeter: Cannot install SIGTERM handler.\n"); /* SIGCHILD */ action.sa_handler = sigchild; sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGINT); /* Block all of them */ sigaddset(&action.sa_mask, SIGQUIT); sigaddset(&action.sa_mask, SIGTERM); action.sa_flags = 0; if(sigaction(SIGCHLD, &action, NULL) != 0) fprintf(stderr,"ProcMeter: Cannot install SIGCHLD handler.\n"); /* Parse the command line. */ for(i=1;i(now+4) || now2<(now-4)) now=now2+1; else now=now+1; /* Wait for a while */ Sleep(now); /* Update the outputs */ UpdateOutputs(now); } while(!quit); } else { static char double_underline[]="==============================="; static char underline[]="-------------------------------"; Module *modulep; Output *outputp; printf("\nProcMeter Version %s\n%s\n\n",PROCMETER_VERSION,&double_underline[sizeof(double_underline)-18-sizeof(PROCMETER_VERSION)]); printf("An efficient modular system monitoring program for Linux.\n"); printf("(c) Andrew M. Bishop 1998-2007 [amb@gedanken.demon.co.uk]\n\n"); printf("Usage: ProcMeter [-h] [--rc=] [--...] [...]\n\n"); printf("To specify the displayed outputs use .[-g|-t|-b] where module\n" "and output come from the list below and '-g', '-t' and '-b' choose graph, text\n" "or bar format. e.g. procmeter3 Statistics.CPU-g Processes.Load-t\n"); for(modulep=Modules;*modulep;modulep++) { ProcMeterOutput *last=NULL; char *p=(*modulep)->module->description; printf("\n\n%s\n%s\n\n",(*modulep)->module->name,&underline[sizeof(underline)-1-strlen((*modulep)->module->name)]); while(p) printf("%s\n",get_substring(&p,80)); if(*(*modulep)->outputs) printf("\n"); for(outputp=(*modulep)->outputs;*outputp;outputp++) { if(last!=(*outputp)->output) { char *p=(*outputp)->output->description; int first=1; while(p) { if(first) printf("%-*s (%c%c%c) : ",PROCMETER_NAME_LEN,(*outputp)->output->name, (*outputp)->output->type&PROCMETER_GRAPH?'G':' ', (*outputp)->output->type&PROCMETER_TEXT?'T':' ', (*outputp)->output->type&PROCMETER_BAR?'B':' '); else printf("%-*s ",PROCMETER_NAME_LEN," "); printf("%s\n",get_substring(&p,80-PROCMETER_NAME_LEN-9)); first=0; } } last=(*outputp)->output; } } } /* Tidy up and exit. */ UnloadAllModules(); FreeProcMeterRC(); if(!help) Stop(); return(0); } /*++++++++++++++++++++++++++++++++++++++ Perform the updates. time_t now The current time. ++++++++++++++++++++++++++++++++++++++*/ void UpdateOutputs(time_t now) { Module *module; Output *output; ProcMeterOutput *last=NULL; for(module=Modules;*module;module++) for(output=(*module)->outputs;*output;output++) if((*output)->output_widget && (((*output)->output->interval && !(now%(*output)->output->interval)) || (*output)->first)) { if(last!=(*output)->output) if((*module)->Update(now,(*output)->output)==-1) fprintf(stderr,"ProcMeter: Error updating %s.%s\n",(*module)->module->name,(*output)->output->name); if((*output)->first) (*output)->first--; if(!(*output)->first) { if((*output)->type==PROCMETER_GRAPH) { long value=(*output)->output->graph_value; if(value<0) value=0; if(value>65535) value=65535; UpdateGraph(*output,value); } else if((*output)->type==PROCMETER_TEXT) UpdateText(*output,(*output)->output->text_value); else if((*output)->type==PROCMETER_BAR) { long value=(*output)->output->graph_value; if(value<0) value=0; if(value>65535) value=65535; UpdateBar(*output,value); } } last=(*output)->output; } } /*++++++++++++++++++++++++++++++++++++++ Add the default outputs at startup. int argc The number of command line arguments. char **argv The command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void AddDefaultOutputs(int argc,char **argv) { Output *outputp=NULL; Module *modulep=NULL; char *string; int arg; if((string=GetProcMeterRC("startup","order"))) { char *s=string; while(*s && *s==' ') s++; while(*s) { int found=0; for(modulep=Modules;*modulep;modulep++) { if(!strncmp((*modulep)->module->name,s,strlen((*modulep)->module->name)) && s[strlen((*modulep)->module->name)]=='.') { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(!strncmp((*outputp)->output->name,&s[strlen((*modulep)->module->name)+1],strlen((*outputp)->output->name)) && (s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]=='-' || s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]==' ' || s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]==0)) { if((s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]==' ' || s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]==0) && !(*outputp)->output_widget) AddRemoveOutput(*outputp); else if(s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+2]=='g' && (*outputp)->type==PROCMETER_GRAPH && !(*outputp)->output_widget) AddRemoveOutput(*outputp); else if(s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+2]=='t' && (*outputp)->type==PROCMETER_TEXT && !(*outputp)->output_widget) AddRemoveOutput(*outputp); else if(s[strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+2]=='b' && (*outputp)->type==PROCMETER_BAR && !(*outputp)->output_widget) AddRemoveOutput(*outputp); found=1; } if(found) break; } } while(*s && *s!=' ') s++; while(*s && *s==' ') s++; } } for(arg=1;argmodule->name,argv[arg],strlen((*modulep)->module->name)) && argv[arg][strlen((*modulep)->module->name)]=='.') { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(!strncmp((*outputp)->output->name,&argv[arg][strlen((*modulep)->module->name)+1],strlen((*outputp)->output->name)) && (argv[arg][strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]=='-' || argv[arg][strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1]==0)) { if(!argv[arg][strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+1] && !(*outputp)->output_widget) AddRemoveOutput(*outputp); else if(argv[arg][strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+2]=='g' && (*outputp)->type==PROCMETER_GRAPH && !(*outputp)->output_widget) AddRemoveOutput(*outputp); else if(argv[arg][strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+2]=='t' && (*outputp)->type==PROCMETER_TEXT && !(*outputp)->output_widget) AddRemoveOutput(*outputp); else if(argv[arg][strlen((*modulep)->module->name)+strlen((*outputp)->output->name)+2]=='b' && (*outputp)->type==PROCMETER_BAR && !(*outputp)->output_widget) AddRemoveOutput(*outputp); found=1; } if(found) break; } if(!*modulep) fprintf(stderr,"ProcMeter: Unrecognised output '%s'\n",argv[arg]); } } /*++++++++++++++++++++++++++++++++++++++ Make a substring copy of the specified string. char *get_substring Returns a copy. char **start The start position in the string. int length The length of string to return. ++++++++++++++++++++++++++++++++++++++*/ static char *get_substring(char **start,int length) { static char string[81]; if(strlen(*start)>length) { char *p=*start+length; if(!isspace(*p)) { while(p>*start && !isspace(*p)) p--; if(p==*start) p=*start+length; else p++; } strncpy(string,*start,(p-*start)); string[p-*start]=0; while(*p==' ') p++; if(!*p) p=NULL; *start=p; } else { strcpy(string,*start); *start=NULL; } return(string); } /*++++++++++++++++++++++++++++++++++++++ The signal handler for the signals to tell us to exit. int signum The signal number. ++++++++++++++++++++++++++++++++++++++*/ static void sigexit(int signum) { quit=1; } /*++++++++++++++++++++++++++++++++++++++ The signal handler for the child processes terminating. int signum The signal number. ++++++++++++++++++++++++++++++++++++++*/ static void sigchild(int signum) { pid_t pid; int status; while((pid=waitpid(-1,&status,WNOHANG))>0) ; } procmeter3-3.5d/procmeter.h000066400000000000000000000054611165060751200157720ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/procmeter.h,v 1.26 2010-12-24 10:24:28 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. Global public header file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PROCMETER_H #define PROCMETER_H /*+ To stop multiple inclusions. +*/ #include #include #define PROCMETER_VERSION "3.5d" #define PROCMETER_MAJOR_VERSION 3 #define PROCMETER_MINOR_VERSION 5 #define PROCMETER_GRAPH 1 #define PROCMETER_TEXT 2 #define PROCMETER_BAR 4 /*+ The scaling factor used to get the number of grid lines. +*/ #define PROCMETER_GRAPH_SCALE 1024 /*+ A scaling function for floating point numbers. +*/ #define PROCMETER_GRAPH_FLOATING(xx) ((long)((xx)*1024)) /*+ A scaling function for integers. +*/ #define PROCMETER_GRAPH_INTEGER(xx) ((long)((xx)<<10)) /*+ The maximum length of a module or output name. +*/ #define PROCMETER_NAME_LEN 24 /*+ The maximum length of an output's text value. +*/ #define PROCMETER_TEXT_LEN 24 /*+ The maximum length of an output's unit value. +*/ #define PROCMETER_UNITS_LEN 12 /*+ The information about one of the outputs. +*/ typedef struct _ProcMeterOutput { char name[PROCMETER_NAME_LEN+1]; /*+ The name of the output. +*/ char *description; /*+ A long description of the output. +*/ char type; /*+ The type of output. +*/ short interval; /*+ The interval between updates. +*/ char text_value[PROCMETER_TEXT_LEN+1]; /*+ The textual value (if applicable). +*/ long graph_value; /*+ The graph value (if applicable). +*/ short graph_scale; /*+ The scaling factor for the graph (if applicable). +*/ char graph_units[PROCMETER_UNITS_LEN+1]; /*+ The units on the graph as a printf string (if applicable). +*/ } ProcMeterOutput; /*+ The information about one of the modules. +*/ typedef struct _ProcMeterModule { char name[PROCMETER_NAME_LEN+1]; /*+ The module's name. +*/ char *description; /*+ A long description of the module. +*/ } ProcMeterModule; /* The funtions that must be exported from the modules. */ ProcMeterModule *Load(void); ProcMeterOutput** Initialise(char *options); int Update(time_t now,ProcMeterOutput *output); void Unload(void); /* The functions available to the modules. */ char *fgets_realloc(char **buffer,size_t *length,FILE *file); #endif /* PROCMETER_H */ procmeter3-3.5d/procmeterp.h000066400000000000000000000076241165060751200161550ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/procmeterp.h,v 1.15 2005-11-19 17:25:36 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.4e. Global private header file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99,2002,05 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PROCMETERP_H #define PROCMETERP_H /*+ To stop multiple inclusions. +*/ /* The public header file. */ #include "procmeter.h" /* The file locations. */ #ifndef INSTDIR #define INSTDIR "/usr/local" #endif #ifndef LIB_PATH #define LIB_PATH INSTDIR "/lib/X11/ProcMeter3" #endif #ifndef MOD_PATH #define MOD_PATH LIB_PATH "/modules" #endif #ifndef RC_PATH #define RC_PATH LIB_PATH #endif /* The run mode options */ #define RUN_NONE 0 #define RUN_SHELL 1 #define RUN_XTERM 2 #define RUN_XTERM_WAIT 3 #define RUN_XBELL 4 /*+ The information needed to run a command. +*/ typedef struct _RunOption { char flag; /*+ The type of command to run. +*/ char *command; /*+ The pre-parsed command string. +*/ } RunOption; /* A forward definition for the Output type. */ typedef struct _Output *Output; /*+ The information about a module that is used internally. +*/ typedef struct _Module { char *filename; /*+ The filename of the module. +*/ void *dlhandle; /*+ The handle returned by dlopen(). +*/ int (*Update)(time_t,ProcMeterOutput*); /*+ The update function for the outputs in the module. +*/ ProcMeterModule *module; /*+ The module information returned by the Load() function. +*/ Output *outputs; /*+ The outputs based on those returned by the Initialise function. +*/ void *menu_item_widget; /*+ The menu item widget for the module on the main menu. +*/ void *submenu_widget; /*+ The submenu widget for the module. +*/ } *Module; /*+ The information about an output that is used internally. +*/ struct _Output { ProcMeterOutput *output; /*+ The output that this represents. +*/ char label[PROCMETER_NAME_LEN+1];/*+ The label for the output. +*/ RunOption menu_run; /*+ The function that can be run for this output. +*/ int type; /*+ The type of output. +*/ int first; /*+ Set this to true if the widget is new and needs an update. +*/ void *menu_item_widget; /*+ The menu item widget for the output on the module menu. +*/ void *output_widget; /*+ The widget for the output in the main window. +*/ }; /*+ The complete list of modules. +*/ extern Module* Modules; /* In procmeter.c */ void UpdateOutputs(time_t now); void AddDefaultOutputs(int argc,char **argv); /* In module.c */ void LoadAllModules(void); void UnloadAllModules(void); Module LoadModule(char* filename); void UnloadModule(Module module); /* In procmeterrc.c */ void LoadProcMeterRC(int *argc,char **argv); char *GetProcMeterRC(char *section,char *parameter); char *GetProcMeterRC2(char *module,char *output,char *parameter); void FreeProcMeterRC(void); /* In xaw/window.c or gtk/window.c or log/window.c or lcd/window.c */ void Start(int *argc,char **argv); void Stop(void); void Sleep(time_t until); void AddRemoveOutput(Output output); void UpdateGraph(Output output,short value); void UpdateText(Output output,char *value); void UpdateBar(Output output,short value); /* In xaw/menus.c or gtk/menus.c or no-x/menus.c */ void AddModuleToMenu(Module module); void RemoveModuleFromMenu(Module module); /* In xaw/run.c or gtk/run.c or no-x/run.c */ void ParseRunCommand(char *string,RunOption *run); void RunProgram(RunOption *run); #endif /* PROCMETERP_H */ procmeter3-3.5d/procmeterrc000066400000000000000000000051301165060751200160620ustar00rootroot00000000000000## ## The information about the library of modules. ## [library] # The location of the modules path=modules ## ## The outputs to start (formatted as .[-g|-t|-b]) ## Run 'procmeter3 --help' to get a full list of available modules. ## [startup] order=ProcMeter.Version-t \ Date_Time.Time_HM-t Date_Time.Date_DM-t \ Statistics.CPU-b \ Memory.Mem_Avail-g ## ## The global default resources, mainly X-Windows resources ## [resources] # The outputs, black on almost-white (for Xaw3d white does not work well). foreground = black background = grey80 # The text output, a large-medium size font. text-font = 8x13 # The graph output, a solid graph with at least 5 grid lines in grey. graph-solid = yes grid-min = 5 grid-foreground = grey40 # The labels on the graphs, black in a small size font below the data. label-font = 5x7 label-foreground = black label-position = bottom # The menu items, black on white in a small-medium size font (These are not used for GTK version). menu-foreground = black menu-background = grey80 menu-font = 7x13 ## ## The resources for the ProcMeter Version output. ## [ProcMeter.Version] # A smaller font than normal with no label. text-font = 6x10 label-position = none # More information about procmeter3 run = XTerm(procmeter3 -h | less) ## ## The resources for the 'Statistics' module. ## [Statistics] [Statistics.CPU] # The minimum number of grid lines, they are 20% each. grid-min = 5 ## ## The resources for the 'Processes' module. ## [Processes] # A more detailed look at the processes. run = XTerm(top) ## ## The resources for the 'Memory' module. ## [Memory] # More information about memory usage. run = XTermWait(free) ## ## The resources for the 'Date and Time' module ## [Date_Time] # No label for these since they are obvious label-position = none # A different clock. run = Shell(xclock) [Date_Time.Uptime_DHM] # This one needs a label because otherwise it is not obvious. label-position = bottom ## ## The resources for the 'Network' module ## [Network] # To pick up extra devices not automatically recognised. #options=ppp0 slip0 # Information about the network devices run = XTermWait(ifconfig -a) ## ## The resources for the 'DiskUsage' module ## [DiskUsage] # The minimum number of grid lines, they are 20% each. grid-min = 5 # Information about the disks run = XTermWait(df) ## ## The resources for the 'Stat-Intr' module ## [Stat-Intr] # To limit the number of interrupts that are processed. #options=30 ## ## The resources for the 'LogFile' module ## [LogFile] # Files to monitor #options=/var/adm/messages /var/log/syslog procmeter3-3.5d/procmeterrc.c000066400000000000000000000231051165060751200163050ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/procmeterrc.c,v 1.10 2008-05-05 18:45:17 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5b. Handle the .procmeterrc file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include "procmeter.h" #include "procmeterp.h" typedef struct _Section *Section; typedef struct _Parameter *Parameter; /*+ A section from the file. +*/ struct _Section { char *name; /*+ The name of the section. +*/ Section next; /*+ The next section; +*/ Parameter first; /*+ The first of the parameters. +*/ }; /*+ A parameter from the file. +*/ struct _Parameter { char *name; /*+ The name of the parameter. +*/ char *value; /*+ The value of the parameter. +*/ Parameter next; /*+ The next parameter. +*/ }; /*+ The first section. +*/ Section FirstSection=NULL; /*++++++++++++++++++++++++++++++++++++++ Load in the configuration file. int *argc The number of command line arguments. char **argv The command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void LoadProcMeterRC(int *argc,char **argv) { char *rcpath=NULL,*home; Section *next_section=&FirstSection; Parameter *next_parameter=NULL,prev_parameter=NULL; int i; /* Find the .procmeterrc file. */ for(i=1;i<*argc;i++) if(!strncmp(argv[i],"--rc=",5)) { rcpath=argv[i]+5; for((*argc)--;i<*argc;i++) argv[i]=argv[i+1]; } if(!rcpath) { struct stat buf; if(!stat(".procmeterrc",&buf)) rcpath=".procmeterrc"; else if((home=getenv("HOME"))) { rcpath=(char*)malloc(strlen(home)+16); strcpy(rcpath,home); strcat(rcpath,"/.procmeterrc"); if(stat(rcpath,&buf)) {free(rcpath);rcpath=NULL;} } } if(!rcpath) rcpath=RC_PATH "/procmeterrc"; /* Read the .procmeterrc file. */ if(rcpath) { FILE *rc=fopen(rcpath,"r"); char *line=NULL; size_t length=256; int continued=0; if(!rc) { fprintf(stderr,"ProcMeter: Cannot open the configuration file %s for reading.\n",rcpath); exit(1); } while(fgets_realloc(&line,&length,rc)) { char *l=line,*r=line+strlen(line)-1; while(*l==' ' || *l=='\t') l++; while(r>l && (*r=='\n' || *r=='\r' || *r==' ' || *r=='\t')) *r--=0; if(*l==';' || *l=='#' || l>=r) continue; if(*l=='[' && *r==']') { l++;*r--=0; *next_section=(Section)malloc(sizeof(struct _Section)); strcpy((*next_section)->name=(char*)malloc(strlen(l)+1),l); (*next_section)->next=NULL; (*next_section)->first=NULL; next_parameter=&(*next_section)->first; next_section=&(*next_section)->next; continued=0; } else if(continued) { continued=0; if(l[strlen(l)-1]=='\\') { continued=1; l[strlen(l)-1]=0; } prev_parameter->value=(char*)realloc((void*)prev_parameter->value,strlen(l)+strlen(prev_parameter->value)+1); strcat(prev_parameter->value,l); } else if(next_parameter) { char *equal=strchr(l,'='); if(equal) { char *lr=equal-1,*rl=equal+1; *equal=0; while(*lr==' ' || *lr=='\t') *lr--=0; while(*rl==' ' || *rl=='\t') rl++; equal=rl; } *next_parameter=(Parameter)malloc(sizeof(struct _Parameter)); strcpy((*next_parameter)->name=(char*)malloc(strlen(l)+1),l); continued=0; if(equal) { if(equal[strlen(equal)-1]=='\\') { continued=1; equal[strlen(equal)-1]=0; } strcpy((*next_parameter)->value=(char*)malloc(strlen(equal)+1),equal); } else (*next_parameter)->value=NULL; (*next_parameter)->next=NULL; prev_parameter=*next_parameter; next_parameter=&(*next_parameter)->next; } } fclose(rc); } /* Add in extra command line options. */ for(i=1;i<*argc;i++) if(!strncmp(argv[i],"--",2)) { int j; char *equal=strchr(argv[i],'='),*dot; if(equal) { char *section=argv[i]+2,*parameter,*value=equal+1; Section this_section=FirstSection; *equal=0; dot=strchr(section,'.'); if(dot) { char *dot2=strchr(dot+1,'.'); if(dot2) /* 2 dots => (module.output).parameter */ { parameter=dot2+1; *dot2=0; } else /* 1 dot => section.parameter */ { parameter=dot+1; *dot=0; } while(this_section) { if(!strcasecmp(section,this_section->name)) { Parameter this_parameter=this_section->first; while(this_parameter) { if(!strcasecmp(parameter,this_parameter->name)) { strcpy(this_parameter->value=(char*)realloc((void*)this_parameter->value,strlen(value)+1),value); break; } this_parameter=this_parameter->next; } if(!this_parameter) { Parameter new_parameter=(Parameter)malloc(sizeof(struct _Parameter)); strcpy(new_parameter->name=(char*)malloc(strlen(parameter)+1),parameter); if(value) strcpy(new_parameter->value=(char*)malloc(strlen(value)+1),value); else new_parameter->value=NULL; new_parameter->next=this_section->first; this_section->first=new_parameter; } break; } this_section=this_section->next; } if(!this_section) { Section new_section=(Section)malloc(sizeof(struct _Section)); strcpy(new_section->name=(char*)malloc(strlen(section)+1),section); new_section->first=(Parameter)malloc(sizeof(struct _Parameter)); strcpy(new_section->first->name=(char*)malloc(strlen(parameter)+1),parameter); if(value) strcpy(new_section->first->value=(char*)malloc(strlen(value)+1),value); else new_section->first->value=NULL; new_section->first->next=NULL; new_section->next=FirstSection; FirstSection=new_section; } } } for(j=i,i--,(*argc)--;j<*argc;j++) argv[j]=argv[j+1]; } } /*++++++++++++++++++++++++++++++++++++++ Return the results of a section of the configuration file. char *GetProcMeterRC Returns the result string or NULL if none. char *section The section of the config file. char *parameter The parameter in the section of the config file. ++++++++++++++++++++++++++++++++++++++*/ char *GetProcMeterRC(char *section,char *parameter) { Section this_section=FirstSection; while(this_section) { if(!strcasecmp(section,this_section->name)) { Parameter this_parameter=this_section->first; while(this_parameter) { if(!strcasecmp(parameter,this_parameter->name)) return(this_parameter->value); this_parameter=this_parameter->next; } } this_section=this_section->next; } return(NULL); } /*++++++++++++++++++++++++++++++++++++++ Get the resources for an output. char *GetProcMeterRC2 Returns the result string or NULL if none. char *module The module name (part of section name). char *output The output name (part of section name). char *parameter The parameter to search for. ++++++++++++++++++++++++++++++++++++++*/ char *GetProcMeterRC2(char *module,char *output,char *parameter) { ProcMeterModule m; ProcMeterOutput o; char section[sizeof(m.name)+sizeof(o.name)+2]; strcpy(section,module); strcat(section,"."); strcat(section,output); return(GetProcMeterRC(section,parameter)); } /*++++++++++++++++++++++++++++++++++++++ Free up the memory that is used in this module. ++++++++++++++++++++++++++++++++++++++*/ void FreeProcMeterRC(void) { Section this_section=FirstSection; while(this_section) { Section last_section=this_section; Parameter this_parameter=this_section->first; while(this_parameter) { Parameter last_parameter=this_parameter; if(this_parameter->name) free(this_parameter->name); if(this_parameter->value) free(this_parameter->value); this_parameter=this_parameter->next; free(last_parameter); } this_section=this_section->next; free(last_section->name); free(last_section); } } procmeter3-3.5d/xaw/000077500000000000000000000000001165060751200144125ustar00rootroot00000000000000procmeter3-3.5d/xaw/Makefile000066400000000000000000000035501165060751200160550ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/xaw/Makefile,v 1.2 2007-09-26 18:31:46 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.5. # # Makefile for xaw parts. # # Written by Andrew M. Bishop # # This file Copyright 1994-2007 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options CFLAGS=-g -O2 -Wall LDFLAGS= X_CFLAGS=-I/usr/X11/include -I/usr/X11R6/include X_LDFLAGS=-L/usr/X11/lib -L/usr/X11R6/lib -lXaw -lXmu -lXt -lXext -lSM -lICE -lX11 # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) PSRC=$(wildcard ../*.c) POBJ=$(foreach f,$(PSRC),$(addsuffix .o,$(basename $f))) WSRC=$(wildcard widgets/*.c) WOBJ=$(foreach f,$(WSRC),$(addsuffix .o,$(basename $f))) ######## all : $(OBJ) procmeter.widget \ ../procmeter3-xaw ######## ../procmeter3-xaw : $(OBJ) procmeter.widget procmeter.main $(LD) $(OBJ) $(WOBJ) $(POBJ) -o $@ -ldl $(LDFLAGS) $(X_LDFLAGS) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(X_CFLAGS) -I.. bitmap.o : bitmap.c ../procmeterp.h ../procmeter.h window.h resources.o : resources.c ../procmeterp.h ../procmeter.h window.h menus.o : menus.c ../procmeterp.h ../procmeter.h window.h window.o : window.c ../procmeterp.h ../procmeter.h window.h run.o : run.c ../procmeterp.h ../procmeter.h window.h ######## .PHONY : procmeter.widget procmeter.widget : $(MAKE) CFLAGS="$(CFLAGS)" X_CFLAGS="$(X_CFLAGS)" -C widgets ######## .PHONY : procmeter.main $(POBJ) : procmeter.main procmeter.main : $(MAKE) CFLAGS="$(CFLAGS)" -C .. obj ######## .PHONY : clean clean : -rm -f *.o *~ core $(MAKE) -C widgets clean ######## .PHONY : install install : procmeter3-3.5d/xaw/bitmap.c000066400000000000000000000037631165060751200160430ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/bitmap.c,v 1.4 2005-10-15 18:16:46 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.4e. X Window Bitmaps. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include "window.h" #define circle_width 8 #define circle_height 8 static char circle_bits[] = { 0x00, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x00}; #define graph_width 16 #define graph_height 8 static char graph_bits[] = { 0x00, 0x00, 0x42, 0x00, 0xa2, 0x41, 0x12, 0x22, 0x0e, 0x1c, 0x02, 0x00, 0xfe, 0x7f, 0x00, 0x00}; #define text_width 16 #define text_height 8 static char text_bits[] = { 0x00, 0x00, 0xcc, 0x31, 0x52, 0x4a, 0xd2, 0x09, 0x5e, 0x0a, 0x52, 0x4a, 0xd2, 0x31, 0x00, 0x00}; #define bar_width 16 #define bar_height 8 static char bar_bits[] = { 0x01, 0x00, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0x01, 0x00, 0x49, 0x92, 0xff, 0xff}; Pixmap CircleBitmap; Pixmap GraphBitmap; Pixmap TextBitmap; Pixmap BarBitmap; /*++++++++++++++++++++++++++++++++++++++ Initialise the Bitmaps. Widget w A widget to start with. ++++++++++++++++++++++++++++++++++++++*/ void CreateBitmaps(Widget w) { CircleBitmap=XCreateBitmapFromData(display,RootWindowOfScreen(XtScreen(w)),circle_bits,circle_width,circle_height); GraphBitmap=XCreateBitmapFromData(display,RootWindowOfScreen(XtScreen(w)),graph_bits,graph_width,graph_height); TextBitmap=XCreateBitmapFromData(display,RootWindowOfScreen(XtScreen(w)),text_bits,text_width,text_height); BarBitmap=XCreateBitmapFromData(display,RootWindowOfScreen(XtScreen(w)),bar_bits,bar_width,bar_height); } procmeter3-3.5d/xaw/menus.c000066400000000000000000000737231165060751200157210ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/menus.c,v 1.18 2009-12-07 20:00:41 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5c. X Window menus. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998-2009 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "widgets/SubMenus.h" #include "window.h" #include "procmeterp.h" /* This is already defined if using Xaw3d. */ #ifndef XtNshadowWidth #define XtNshadowWidth "shadowWidth" #endif /*+ The orientation of the windows. +*/ extern int vertical; /*+ The pane that contains all of the outputs. +*/ extern Widget pane; /* Local functions */ static void ModuleMenuStart(Widget w,XEvent *event,String *params,Cardinal *num_params); static void OutputMenuStart(Widget w,XEvent *event,String *params,Cardinal *num_params); static void FunctionsMenuStart(Widget w,XEvent *event,String *params,Cardinal *num_params); static void SelectOutputMenuCallback(Widget widget,XtPointer clientData,XtPointer callData); static void SelectFunctionsMenuCallback(Widget widget,XtPointer clientData,XtPointer callData); static void PropertiesDialogDoneCallback(Widget widget,XtPointer clientData,XtPointer callData); static void PropertiesDialogCloseCallback(Widget w,XtPointer va,XEvent* e,Boolean* vb); /* Menu widgets */ static Widget module_menu; static Widget functions_menu,properties_dialog; static Widget func_run; static Widget prop_modname,prop_moddesc, prop_outname,prop_outdesc, prop_label,prop_type,prop_interval,prop_scale; static Boolean properties_popped_up=False; static int doing_move=0; XtActionsRec MenuActions[]={{"ModuleMenuStart",ModuleMenuStart}, {"OutputMenuStart",OutputMenuStart}, {"FunctionsMenuStart",FunctionsMenuStart}}; /*+ The output that was used for the Functions menu. +*/ static Output function_output; /*++++++++++++++++++++++++++++++++++++++ Initialise the menus. Widget parent The parent widget that the menu belongs to. ++++++++++++++++++++++++++++++++++++++*/ void CreateMenus(Widget parent) { Widget menulabel; Widget menuline; Widget func_prop,func_above,func_below,func_delete; Widget prop_form, prop_modlabel,prop_outlabel, prop_lbllabel,prop_typlabel,prop_intlabel,prop_scllabel, prop_done; Dimension width,height; char *string; Arg args[3]; int nargs=0; XtVarArgsList resources=NULL; Atom close_atom; /* Add the application actions. */ XtAppAddActions(app_context,MenuActions,sizeof(MenuActions)/sizeof(MenuActions[0])); InitialiseSubMenus(app_context); /* Sort out the resources in advance, this is required for the dialog box. This is horrible because Xaw3d requires that you set the background when you create the widget because the shadows don't update if you do it later. */ if((string=GetProcMeterRC("resources","menu-foreground"))) {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} if((string=GetProcMeterRC("resources","menu-background"))) {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} if((string=GetProcMeterRC("resources","menu-font"))) {XtSetArg(args[nargs],XtNfont,StringToFont(string));nargs++;} if(nargs==1) resources=XtVaCreateArgsList(NULL, args[0].name,args[0].value, NULL); else if(nargs==2) resources=XtVaCreateArgsList(NULL, args[0].name,args[0].value, args[1].name,args[1].value, NULL); else if(nargs==3) resources=XtVaCreateArgsList(NULL, args[0].name,args[0].value, args[1].name,args[1].value, args[2].name,args[2].value, NULL); else resources=XtVaCreateArgsList(NULL, NULL); /* The module menu */ module_menu=XtVaCreatePopupShell("ModuleMenu",simpleMenuWidgetClass,parent, XtNlabel,"Modules", XtVaNestedList,resources, NULL); menulabel=XtNameToWidget(module_menu,"menuLabel"); XtSetValues(menulabel,args,nargs); menuline=XtVaCreateManagedWidget("line",smeLineObjectClass,module_menu, XtVaNestedList,resources, NULL); /* The functions menu */ functions_menu=XtVaCreatePopupShell("FunctionsMenu",simpleMenuWidgetClass,parent, XtNlabel,"Functions", XtVaNestedList,resources, NULL); menulabel=XtNameToWidget(functions_menu,"menuLabel"); XtSetValues(menulabel,args,nargs); menuline=XtVaCreateManagedWidget("line",smeLineObjectClass,functions_menu, XtVaNestedList,resources, NULL); /* The functions menu items */ func_prop=XtVaCreateManagedWidget("Properties",smeBSBObjectClass,functions_menu, XtNlabel,"Properties", XtNheight,10, XtVaNestedList,resources, NULL); XtAddCallback(func_prop,XtNcallback,SelectFunctionsMenuCallback,0); func_above=XtVaCreateManagedWidget("AboveOrLeft",smeBSBObjectClass,functions_menu, XtNlabel,vertical?"Move To Above":"Move To Left Of", XtNheight,10, XtVaNestedList,resources, NULL); XtAddCallback(func_above,XtNcallback,SelectFunctionsMenuCallback,(XtPointer)1); func_below=XtVaCreateManagedWidget("BelowOrRight",smeBSBObjectClass,functions_menu, XtNlabel,vertical?"Move To Below":"Move To Right Of", XtNheight,10, XtVaNestedList,resources, NULL); XtAddCallback(func_below,XtNcallback,SelectFunctionsMenuCallback,(XtPointer)2); func_delete=XtVaCreateManagedWidget("Delete",smeBSBObjectClass,functions_menu, XtNlabel,"Delete", XtNheight,10, XtVaNestedList,resources, NULL); XtAddCallback(func_delete,XtNcallback,SelectFunctionsMenuCallback,(XtPointer)3); func_run=XtVaCreateManagedWidget("Run",smeBSBObjectClass,functions_menu, XtNlabel,"Run", XtNheight,10, XtVaNestedList,resources, NULL); XtAddCallback(func_run,XtNcallback,SelectFunctionsMenuCallback,(XtPointer)4); /* The properties_dialog */ properties_dialog=XtVaCreatePopupShell("PropertiesDialog",topLevelShellWidgetClass,parent, XtNtitle,"ProcMeter Properties",XtNiconName,"ProcMeter Properties", XtVaNestedList,resources, NULL); prop_form=XtVaCreateManagedWidget("PropertiesForm",formWidgetClass,properties_dialog, XtNwidth,300,XtNheight,300, XtVaNestedList,resources, NULL); /* The properties dialog elements. */ prop_modlabel=XtVaCreateManagedWidget("ModuleLabel",labelWidgetClass,prop_form, XtNlabel,"Module:", XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_modname=XtVaCreateManagedWidget("ModuleName",labelWidgetClass,prop_form, XtNlabel,"NNNNNNNNNNNNNNN",XtNjustify,XtJustifyLeft, XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromHoriz,prop_modlabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_moddesc=XtVaCreateManagedWidget("ModuleDesc",asciiTextWidgetClass,prop_form, XtNheight,80,XtNwidth,240,XtNresizable,True, XtNleft,XawChainLeft,XtNright,XawChainRight,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_modlabel, XtNtype,XawAsciiString,XtNstring,"NNNNNNNNNNNNNNN", XtNwrap,XawtextWrapWord,XtNeditType,XawtextRead,XtNdisplayCaret,False, XtNscrollVertical,XawtextScrollAlways, XtVaNestedList,resources, NULL); prop_outlabel=XtVaCreateManagedWidget("OutputLabel",labelWidgetClass,prop_form, XtNlabel,"Output:", XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_moddesc, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_outname=XtVaCreateManagedWidget("OutputName",labelWidgetClass,prop_form, XtNlabel,"NNNNNNNNNNNNNNN",XtNjustify,XtJustifyLeft, XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromHoriz,prop_outlabel,XtNfromVert,prop_moddesc, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_outdesc=XtVaCreateManagedWidget("OutputDesc",asciiTextWidgetClass,prop_form, XtNheight,80,XtNwidth,240,XtNresizable,True, XtNleft,XawChainLeft,XtNright,XawChainRight,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_outlabel, XtNtype,XawAsciiString,XtNstring,"NNNNNNNNNNNNNNN", XtNwrap,XawtextWrapWord,XtNeditType,XawtextRead,XtNdisplayCaret,False, XtNscrollVertical,XawtextScrollAlways, XtVaNestedList,resources, NULL); prop_lbllabel=XtVaCreateManagedWidget("LabelLabel",labelWidgetClass,prop_form, XtNlabel,"Label:", XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_outdesc, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_typlabel=XtVaCreateManagedWidget("TypeLabel",labelWidgetClass,prop_form, XtNlabel,"Type:", XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_lbllabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_intlabel=XtVaCreateManagedWidget("IntervalLabel",labelWidgetClass,prop_form, XtNlabel,"Interval:", XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_typlabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_scllabel=XtVaCreateManagedWidget("ScaleLabel",labelWidgetClass,prop_form, XtNlabel,"Grid Spacing:", XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_intlabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_label=XtVaCreateManagedWidget("Label",labelWidgetClass,prop_form, XtNlabel,"NNNNNNNNNNNNNNNN",XtNjustify,XtJustifyLeft, XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromHoriz,prop_scllabel,XtNfromVert,prop_outdesc, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_type=XtVaCreateManagedWidget("Type",labelWidgetClass,prop_form, XtNlabel,"NNNNNNN",XtNjustify,XtJustifyLeft, XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromHoriz,prop_scllabel,XtNfromVert,prop_lbllabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_interval=XtVaCreateManagedWidget("Interval",labelWidgetClass,prop_form, XtNlabel,"NNNNNNN",XtNjustify,XtJustifyLeft, XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromHoriz,prop_scllabel,XtNfromVert,prop_typlabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_scale=XtVaCreateManagedWidget("Scale",labelWidgetClass,prop_form, XtNlabel,"NNNNNNN",XtNjustify,XtJustifyLeft, XtNleft,XawChainLeft,XtNright,XawChainLeft,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromHoriz,prop_scllabel,XtNfromVert,prop_intlabel, XtNborderWidth,0,XtNshadowWidth,0, XtVaNestedList,resources, NULL); prop_done=XtVaCreateManagedWidget("Done",commandWidgetClass,prop_form, XtNwidth,240,XtNresizable,True, XtNleft,XawChainLeft,XtNright,XawChainRight,XtNtop,XawChainTop,XtNbottom,XawChainTop, XtNfromVert,prop_scllabel, XtVaNestedList,resources, NULL); XtAddCallback(prop_done,XtNcallback,PropertiesDialogDoneCallback,0); XtFree(resources); /* Fixup the properties dialog box */ XtRealizeWidget(properties_dialog); XtVaGetValues(properties_dialog,XtNwidth,&width,XtNheight,&height,NULL); XtVaSetValues(properties_dialog,XtNminWidth,width,XtNminHeight,height,XtNmaxWidth,width,XtNmaxHeight,height,NULL); close_atom=XInternAtom(display,"WM_DELETE_WINDOW",False); XSetWMProtocols(display,XtWindow(properties_dialog),&close_atom,1); XtAddEventHandler(properties_dialog,0,True,PropertiesDialogCloseCallback,NULL); } /*++++++++++++++++++++++++++++++++++++++ Add a specified module to the menus. Module module The module to add. ++++++++++++++++++++++++++++++++++++++*/ void AddModuleToMenu(Module module) { int i; Widget menulabel,menuline,submenu=NULL,menuitem=NULL; ProcMeterOutput *prevoutput=NULL; char *string; char menuname[32]; Arg args[3]; int nargs=0; /* Return if display is not initialised (e.g. procmeter3 -h). */ if(!display) return; /* Sort out the resources in advance. */ if(((string=GetProcMeterRC(module->module->name,"menu-foreground")) || (string=GetProcMeterRC("resources","menu-foreground")))) {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC(module->module->name,"menu-background")) || (string=GetProcMeterRC("resources","menu-background")))) {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC(module->module->name,"menu-font")) || (string=GetProcMeterRC("resources","menu-font")))) {XtSetArg(args[nargs],XtNfont,StringToFont(string));nargs++;} /* Create a new menu. */ sprintf(menuname,"%sMenu",module->module->name); module->submenu_widget=XtVaCreatePopupShell(menuname,simpleMenuWidgetClass,module_menu, XtNlabel,module->module->name, NULL); XtSetValues(module->submenu_widget,args,nargs); menulabel=XtNameToWidget(module->submenu_widget,"menuLabel"); XtSetValues(menulabel,args,nargs); menuline=XtVaCreateManagedWidget("line",smeLineObjectClass,module->submenu_widget, NULL); XtSetValues(menuline,args,nargs); /* Add an entry to the module menu */ module->menu_item_widget=XtVaCreateManagedWidget(module->module->name,smeBSBObjectClass,module_menu, XtNlabel,module->module->name, XtNheight,10, NULL); XtSetValues(module->menu_item_widget,args,nargs); AddSubMenu(module->menu_item_widget,module->submenu_widget); /* Add entries to it for each output. */ for(i=0;module->outputs[i];i++) { Widget sme; Pixmap bitmap=CircleBitmap; if(module->outputs[i]->output!=prevoutput) { menuitem=XtVaCreateManagedWidget(module->outputs[i]->output->name,smeBSBObjectClass,module->submenu_widget, XtNlabel,module->outputs[i]->label, XtNheight,10, NULL); if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-foreground")) || (string=GetProcMeterRC(module->module->name,"menu-foreground")) || (string=GetProcMeterRC("resources","menu-foreground")))) XtVaSetValues(menuitem,XtNforeground,StringToPixel(string),NULL); if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-font")) || (string=GetProcMeterRC(module->module->name,"menu-font")) || (string=GetProcMeterRC("resources","menu-font")))) XtVaSetValues(menuitem,XtNfont,StringToFont(string),NULL); submenu=XtVaCreatePopupShell("Type",simpleMenuWidgetClass,module->submenu_widget, NULL); XtSetValues(submenu,args,nargs); AddSubMenu(menuitem,submenu); prevoutput=module->outputs[i]->output; } if(module->outputs[i]->type==PROCMETER_GRAPH) bitmap=GraphBitmap; else if(module->outputs[i]->type==PROCMETER_TEXT) bitmap=TextBitmap; else if(module->outputs[i]->type==PROCMETER_BAR) bitmap=BarBitmap; sme=XtVaCreateManagedWidget(module->outputs[i]->output->name,smeBSBObjectClass,submenu, XtNlabel,"", XtNleftMargin,10,XtNrightMargin,20, XtNrightBitmap,bitmap, XtNheight,10, NULL); XtAddCallback(sme,XtNcallback,SelectOutputMenuCallback,(XtPointer)module->outputs[i]); if(((string=GetProcMeterRC2(module->module->name,module->outputs[i]->output->name,"menu-foreground")) || (string=GetProcMeterRC(module->module->name,"menu-foreground")) || (string=GetProcMeterRC("resources","menu-foreground")))) XtVaSetValues(sme,XtNforeground,StringToPixel(string),NULL); module->outputs[i]->menu_item_widget=sme; module->outputs[i]->output_widget=NULL; } XtRealizeWidget(module->submenu_widget); } /*++++++++++++++++++++++++++++++++++++++ Add the menus to the right mouse button of the output. Widget widget The widget itself. Module module The module that this widget belongs to. ++++++++++++++++++++++++++++++++++++++*/ void AddMenuToOutput(Widget widget,Module module) { /* Return if display is not initialised (e.g. procmeter3 -h). */ if(!display) return; XtOverrideTranslations(widget,XtParseTranslationTable(": ModuleMenuStart()")); if(module) { char string[64]; sprintf(string,": OutputMenuStart(%s)",module->module->name); XtOverrideTranslations(widget,XtParseTranslationTable(string)); sprintf(string,": FunctionsMenuStart(%s)",module->module->name); XtOverrideTranslations(widget,XtParseTranslationTable(string)); } } /*++++++++++++++++++++++++++++++++++++++ Remove a specified module from the menus. Module module The module to remove. ++++++++++++++++++++++++++++++++++++++*/ void RemoveModuleFromMenu(Module module) { /* Return if display is not initialised (e.g. procmeter3 -h). */ if(!display) return; XtDestroyWidget(module->submenu_widget); XtDestroyWidget(module->menu_item_widget); } /*++++++++++++++++++++++++++++++++++++++ Destroy all of the menus. ++++++++++++++++++++++++++++++++++++++*/ void DestroyMenus(void) { XtDestroyWidget(module_menu); XtDestroyWidget(functions_menu); XtDestroyWidget(properties_dialog); } /*++++++++++++++++++++++++++++++++++++++ The callback that is called by the output being selected on the output menu. Widget widget The widget that the callback came from. XtPointer clientData The client data from the callback. XtPointer callData The call data from the callback. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void SelectOutputMenuCallback(Widget widget,XtPointer clientData,XtPointer callData) { Output output=(Output)clientData; AddRemoveOutput(output); } /*++++++++++++++++++++++++++++++++++++++ The callback that is called by an item being selected on the functions menu. Widget widget The widget that the callback came from. XtPointer clientData The client data from the callback. XtPointer callData The call data from the callback. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void SelectFunctionsMenuCallback(Widget widget,XtPointer clientData,XtPointer callData) { if(clientData==(XtPointer)0) /* Properties */ { Window root_return, child_return; int root_x_return, root_y_return; int win_x_return, win_y_return; unsigned int mask_return; Dimension width; XtVaGetValues(properties_dialog,XtNwidth,&width,NULL); XQueryPointer(display,XtWindow(properties_dialog),&root_return,&child_return,&root_x_return,&root_y_return,&win_x_return,&win_y_return,&mask_return); XtVaSetValues(properties_dialog,XtNx,root_x_return-width/2,XtNy,root_y_return,NULL); XtPopup(properties_dialog,XtGrabNone); properties_popped_up=True; } else if(clientData==(XtPointer)1 || clientData==(XtPointer)2) /* Above / Below */ { doing_move=(long)clientData; XtGrabPointer(pane,True,ButtonPressMask|ButtonReleaseMask,GrabModeAsync,GrabModeAsync,None,XCreateFontCursor(XtDisplay(pane),XC_hand1),CurrentTime); } else if(clientData==(XtPointer)3) /* Delete */ { AddRemoveOutput(function_output); } else if(clientData==(XtPointer)4) /* Run */ { if(function_output->menu_run.flag) RunProgram(&function_output->menu_run); } } /*++++++++++++++++++++++++++++++++++++++ The callback for the done button on the properties dialog box. Widget widget The widget that the callback came from. XtPointer clientData The client data from the callback. XtPointer callData The call data from the callback. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void PropertiesDialogDoneCallback(Widget widget,XtPointer clientData,XtPointer callData) { XtPopdown(properties_dialog); properties_popped_up=False; } /*++++++++++++++++++++++++++++++++++++++ The callback for the window manager close on the dialog. Widget w The widget that caused the callback. XtPointer va Not used. XEvent* e The event that requires action. Boolean* vb Not used. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void PropertiesDialogCloseCallback(Widget w,XtPointer va,XEvent* e,Boolean* vb) { XtPopdown(properties_dialog); properties_popped_up=False; } /*++++++++++++++++++++++++++++++++++++++ Start the Module menu. Widget w The widget that caused the event. XEvent *event The event that caused the callback. String *params The parameters from the callback. Cardinal *num_params The number of parameters. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void ModuleMenuStart(Widget w,XEvent *event,String *params,Cardinal *num_params) { PopupMenuHere(module_menu,w,event); } /*++++++++++++++++++++++++++++++++++++++ Start one of the Output menus. Widget w The widget that caused the event. XEvent *event The event that caused the callback. String *params The parameters from the callback. Cardinal *num_params The number of parameters. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void OutputMenuStart(Widget w,XEvent *event,String *params,Cardinal *num_params) { Module *modulep=NULL; for(modulep=Modules;*modulep;modulep++) if(!strcmp((*modulep)->module->name,params[0])) PopupMenuHere((*modulep)->submenu_widget,w,event); } /*++++++++++++++++++++++++++++++++++++++ Start the properties menu. Widget w The widget that caused the event. XEvent *event The event that caused the callback. String *params The parameters from the callback. Cardinal *num_params The number of parameters. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void FunctionsMenuStart(Widget w,XEvent *event,String *params,Cardinal *num_params) { static Output *outputp=NULL; static Module *modulep=NULL; char string[24]; for(modulep=Modules;*modulep;modulep++) if(!strcmp((*modulep)->module->name,params[0])) { for(outputp=(*modulep)->outputs;*outputp;outputp++) if(w==(*outputp)->output_widget) break; break; } if(doing_move) { XtUngrabPointer(pane,CurrentTime); MoveOutput(function_output,*outputp,doing_move); doing_move=0; return; } if(!*modulep || !*outputp) return; function_output=*outputp; if((*outputp)->menu_run.flag) { char *r=(*outputp)->menu_run.command; strncpy(string,"Run '",16); strncpy(string+5,r,8); if(strlen(r)>8) strcat(string," ...'"); else strcat(string,"'"); XtVaSetValues(func_run,XtNlabel,string,NULL); XtSetSensitive(func_run,True); } else { XtVaSetValues(func_run,XtNlabel,"Run",NULL); XtSetSensitive(func_run,False); } /* Set up the properties window. */ XtVaSetValues(prop_modname,XtNlabel,(*modulep)->module->name,NULL); XtVaSetValues(prop_moddesc,XtNstring,(*modulep)->module->description,NULL); XtVaSetValues(prop_outname,XtNlabel,(*outputp)->output->name,NULL); XtVaSetValues(prop_outdesc,XtNstring,(*outputp)->output->description,NULL); XtVaSetValues(prop_label,XtNlabel,(*outputp)->label,NULL); if((*outputp)->type==PROCMETER_GRAPH) XtVaSetValues(prop_type,XtNlabel,"Graph",NULL); else if((*outputp)->type==PROCMETER_TEXT) XtVaSetValues(prop_type,XtNlabel,"Text",NULL); else if((*outputp)->type==PROCMETER_BAR) XtVaSetValues(prop_type,XtNlabel,"Bar",NULL); if((*outputp)->output->interval) sprintf(string,"%d s",(*outputp)->output->interval); else strcpy(string,"Never"); XtVaSetValues(prop_interval,XtNlabel,string,NULL); if((*outputp)->type&(PROCMETER_GRAPH|PROCMETER_BAR)) { char str[PROCMETER_UNITS_LEN+1]; snprintf(str,PROCMETER_UNITS_LEN+1,(*outputp)->output->graph_units,(*outputp)->output->graph_scale); if(*str=='(') strcpy(string,str+1); else strcpy(string,str); if(string[strlen(string)-1]==')') string[strlen(string)-1]=0; XtVaSetValues(prop_scale,XtNlabel,string,NULL); XtSetSensitive(prop_scale,True); } else { XtVaSetValues(prop_scale,XtNlabel,"n/a",NULL); XtSetSensitive(prop_scale,False); } if(!properties_popped_up) PopupMenuHere(functions_menu,w,event); } procmeter3-3.5d/xaw/resources.c000066400000000000000000000050641165060751200165750ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/resources.c,v 1.3 2000-12-16 16:46:41 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3. X Window resource conversions. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include "window.h" #include "procmeterp.h" /*++++++++++++++++++++++++++++++++++++++ Convert a string to a font structure. XFontStruct *StringToFont Returns a pointer to a font structure. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ XFontStruct *StringToFont(char *string) { return(XLoadQueryFont(display,string)); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a pixel. Pixel StringToPixel Returns a Pixel value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ Pixel StringToPixel(char *string) { XColor screenColor; XColor exactColor; XAllocNamedColor(display, DefaultColormap(display,DefaultScreen(display)), string, &screenColor, &exactColor); return(screenColor.pixel); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a Boolean. Boolean StringToBoolean Returns a Boolean value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ Boolean StringToBoolean(char *string) { Boolean b; if(!strcasecmp(string,"true") || !strcasecmp(string,"yes") || !strcasecmp(string,"1")) b=True; else b=False; return(b); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to an integer int StringToInt Returns an integer value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ int StringToInt(char *string) { int i; if(sscanf(string,"%d",&i)!=1) i=0; return(i); } /*++++++++++++++++++++++++++++++++++++++ Convert a string to a label position. int StringToLabelPosition Returns an integer value. char *string The string to convert. ++++++++++++++++++++++++++++++++++++++*/ int StringToLabelPosition(char *string) { int i; if(!strcasecmp(string,"top")) i=1; else if(!strcasecmp(string,"bottom")) i=-1; else i=0; return(i); } procmeter3-3.5d/xaw/run.c000066400000000000000000000070221165060751200153630ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/run.c,v 1.5 2010-02-28 10:22:21 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.5d. Run external programs. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1999-2010 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include "procmeterp.h" /*+ The display that we are using. +*/ extern Display *display; /*++++++++++++++++++++++++++++++++++++++ Parse the command from the config file to be run. char *string The string to be parsed. RunOption *run Contains the parsed result. ++++++++++++++++++++++++++++++++++++++*/ void ParseRunCommand(char *string,RunOption *run) { int offset; char *l,*r; run->flag=RUN_NONE; run->command=NULL; if(!string) return; if(!strncmp("XBeep",string,5)) {offset=5; run->flag=RUN_XBELL;} else if(!strncmp("Shell",string,5)) {offset=5; run->flag=RUN_SHELL;} else if(!strncmp("XTermWait",string,9)) {offset=9; run->flag=RUN_XTERM_WAIT;} else if(!strncmp("XTerm",string,5)) {offset=5; run->flag=RUN_XTERM;} else {offset=0; run->flag=RUN_SHELL;} l=string+offset; r=string+strlen(string)-1; while(isspace(*l)) l++; if(offset && *l!='(') { fprintf(stderr,"ProcMeter: Cannot parse run command '%s'\n",string); run->flag=RUN_NONE; return; } else if(offset) l++; while(isspace(*l)) l++; while(isspace(*r)) r--; if(offset && *r!=')') { fprintf(stderr,"ProcMeter: Cannot parse run command '%s'\n",string); run->flag=RUN_NONE; return; } else if(offset) r--; while(isspace(*r)) r--; if(rcommand=(char*)malloc(r-l+2); strncpy(run->command,l,r-l+1); *(run->command+(r-l)+1)=0; } /*++++++++++++++++++++++++++++++++++++++ Run a program. RunOption *run The information about the program to run. ++++++++++++++++++++++++++++++++++++++*/ void RunProgram(RunOption *run) { if(run->flag==RUN_NONE || !run->command) return; if(run->flag==RUN_XBELL) XBell(display,0); else { pid_t pid=fork(); if(pid==-1) fprintf(stderr,"ProcMeter: Cannot fork child process %s\n",strerror(errno)); else if(pid==0) { char *string,*displayname,*displayenv; displayname=XDisplayString(display); displayenv=(char*)malloc(strlen(displayname)+10); sprintf(displayenv,"DISPLAY=%s",displayname); putenv(displayenv); /* close the X connection */ close(ConnectionNumber(display)); switch(run->flag) { default: case RUN_SHELL: execl("/bin/sh","/bin/sh","-c",run->command,NULL); break; case RUN_XTERM: execlp("xterm","xterm","-title","ProcMeter3","-e","/bin/sh","-c",run->command,NULL); break; case RUN_XTERM_WAIT: string=(char*)malloc(strlen(run->command)+64); sprintf(string,"( %s ) ; echo -n 'Press Return to exit' ; read x",run->command); execlp("xterm","xterm","-title","ProcMeter3","-e","/bin/sh","-c",string,NULL); break; } /* Never reached */ exit(1); } } } procmeter3-3.5d/xaw/widgets/000077500000000000000000000000001165060751200160605ustar00rootroot00000000000000procmeter3-3.5d/xaw/widgets/Makefile000066400000000000000000000023631165060751200175240ustar00rootroot00000000000000# $Header: /home/amb/CVS/procmeter3/xaw/widgets/Makefile,v 1.5 2000-12-16 17:01:20 amb Exp $ # # ProcMeter - A system monitoring program for Linux - Version 3.3. # # Makefile for athena widgets. # # Written by Andrew M. Bishop # # This file Copyright 1998,99,2000 Andrew M. Bishop # It may be distributed under the GNU Public License, version 2, or # any higher version. See section COPYING of the GNU Public license # for conditions under which this file may be redistributed. # # Programs CC=gcc LD=gcc # Program options (overridden by main Makefile) CFLAGS=-g -O2 -Wall XAW_CFLAGS=-I/usr/X11/include -I/usr/X11R6/include # Compilation targets SRC=$(wildcard *.c) OBJ=$(foreach f,$(SRC),$(addsuffix .o,$(basename $f))) ######## all : $(OBJ) ######## %.o:%.c $(CC) -c $(CFLAGS) $< -o $@ $(X_CFLAGS) -I../.. PMGeneric.o : PMGeneric.c PMGeneric.h PMGenericP.h PMGraph.o : PMGraph.c PMGraph.h PMGraphP.h PMGeneric.h PMGenericP.h ../../procmeter.h PMText.o : PMText.c PMText.h PMTextP.h PMGeneric.h PMGenericP.h PMBar.o : PMBar.c PMBar.h PMBarP.h PMGeneric.h PMGenericP.h ../../procmeter.h SubMenus.o : SubMenus.c SubMenus.h ######## .PHONY : clean clean : -rm -f *.o *~ core ######## .PHONY : install install : procmeter3-3.5d/xaw/widgets/PMBar.c000066400000000000000000000323521165060751200171720ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMBar.c,v 1.5 2008-04-27 15:21:30 amb Exp $ ProcMeter Bar Widget Source file (for ProcMeter3 3.5b). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include "PMGenericP.h" #include "PMBarP.h" #include "procmeter.h" static void Initialize(ProcMeterBarWidget request,ProcMeterBarWidget new); static void Destroy(ProcMeterBarWidget pmw); static Boolean SetValues(ProcMeterBarWidget current,ProcMeterBarWidget request,ProcMeterBarWidget new); static void Resize(ProcMeterBarWidget pmw); static void Redisplay(ProcMeterBarWidget pmw,XEvent *event,Region region); static void BarResize(ProcMeterBarWidget pmw); static void BarUpdate(ProcMeterBarWidget pmw,Boolean all); static XtResource resources[]= { /* The grid parts. */ {XtNgridUnits, XtCLabel, XtRString, sizeof(XtPointer), XtOffset(ProcMeterBarWidget,procmeter_bar.grid_units), XtRString, "" }, {XtNgridForeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffset(ProcMeterBarWidget,procmeter_bar.grid_pixel),XtRString,XtDefaultBackground}, {XtNgridMin, XtCGridMin, XtRInt, sizeof(int), XtOffset(ProcMeterBarWidget,procmeter_bar.grid_min), XtRString, "1" }, {XtNgridMax, XtCGridMax, XtRInt, sizeof(int), XtOffset(ProcMeterBarWidget,procmeter_bar.grid_max), XtRString, "0" } }; /*+ The actual ProcMeter Bar Widget Class Record. +*/ ProcMeterBarClassRec procMeterBarClassRec= { { (WidgetClass) &procMeterGenericClassRec, "ProcMeterBar", sizeof(ProcMeterBarRec), NULL, NULL, FALSE, (XtInitProc)Initialize, NULL, XtInheritRealize, NULL, 0, resources, XtNumber(resources), NULLQUARK, TRUE, XtExposeCompressMaximal|XtExposeGraphicsExpose, TRUE, TRUE, (XtWidgetProc)Destroy, (XtWidgetProc)Resize, (XtExposeProc)Redisplay, (XtSetValuesFunc)SetValues, NULL, XtInheritSetValuesAlmost, NULL, NULL, XtVersion, NULL, XtInheritTranslations, NULL, NULL, NULL, }, { NULL, NULL }, { 0 } }; /*+ The actual ProcMeter Bar Widget Class Record masquerading as a WidgetClass type. +*/ WidgetClass procMeterBarWidgetClass=(WidgetClass)&procMeterBarClassRec; /*++++++++++++++++++++++++++++++++++++++ Initialise a new ProcMeter Bar Widget. ProcMeterBarWidget request The requested parameters. ProcMeterBarWidget new The new parameters that are to be filled in. ++++++++++++++++++++++++++++++++++++++*/ static void Initialize(ProcMeterBarWidget request,ProcMeterBarWidget new) { int i; XGCValues values; /* The grid parts. */ new->procmeter_bar.grid_units=XtNewString(request->procmeter_bar.grid_units); values.foreground=new->procmeter_bar.grid_pixel; values.background=new->core.background_pixel; new->procmeter_bar.grid_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&values); if(request->procmeter_bar.grid_min<0) { new->procmeter_bar.grid_min=-request->procmeter_bar.grid_min; new->procmeter_bar.grid_drawn=0; } else if(request->procmeter_bar.grid_min>0) { new->procmeter_bar.grid_min=request->procmeter_bar.grid_min; new->procmeter_bar.grid_drawn=1; } else /* if(request->procmeter_bar.grid_min==0) */ { new->procmeter_bar.grid_min=1; new->procmeter_bar.grid_drawn=1; } if(request->procmeter_bar.grid_max<0) new->procmeter_bar.grid_max=0; else new->procmeter_bar.grid_max=request->procmeter_bar.grid_max; if(new->procmeter_bar.grid_max && new->procmeter_bar.grid_maxprocmeter_bar.grid_min) new->procmeter_bar.grid_max=new->procmeter_bar.grid_min; new->procmeter_bar.grid_num=new->procmeter_bar.grid_min; /* The data parts. */ for(i=0;iprocmeter_bar.data)/sizeof(new->procmeter_bar.data[0]);i++) new->procmeter_bar.data[i]=0; new->procmeter_bar.data_index=0; new->procmeter_bar.data_sum=0; /* The rest of the sizing. */ BarResize(new); } /*++++++++++++++++++++++++++++++++++++++ Destroy a ProcMeter Bar Widget. ProcMeterBarWidget pmw The Widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void Destroy(ProcMeterBarWidget pmw) { XtReleaseGC((Widget)pmw,pmw->procmeter_bar.grid_gc); XtFree((XtPointer)pmw->procmeter_bar.grid_units); } /*++++++++++++++++++++++++++++++++++++++ The setvalues procedure that is used to set the values internal to the Widget. Boolean SetValues Returns True if the Widget is to be redrawn. ProcMeterBarWidget current The current Widget values. ProcMeterBarWidget request The requested Widget values. ProcMeterBarWidget new The new Widget values to be set up. ++++++++++++++++++++++++++++++++++++++*/ static Boolean SetValues(ProcMeterBarWidget current,ProcMeterBarWidget request,ProcMeterBarWidget new) { Boolean redraw=False; /* The grid parts. */ if(request->procmeter_bar.grid_units!=current->procmeter_bar.grid_units) { XtFree((XtPointer)new->procmeter_bar.grid_units); new->procmeter_bar.grid_units=XtNewString(request->procmeter_bar.grid_units); redraw=True; } if(request->procmeter_bar.grid_pixel!=current->procmeter_bar.grid_pixel) { XGCValues xgcv; XGetGCValues(XtDisplay(new),new->procmeter_bar.grid_gc,GCForeground|GCBackground,&xgcv); XtReleaseGC((Widget)new,new->procmeter_bar.grid_gc); xgcv.foreground=request->procmeter_bar.grid_pixel; xgcv.background=request->core.background_pixel; new->procmeter_bar.grid_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&xgcv); redraw=True; } if(request->procmeter_bar.grid_min!=current->procmeter_bar.grid_min) { if(request->procmeter_bar.grid_min<0) { new->procmeter_bar.grid_min=-request->procmeter_bar.grid_min; new->procmeter_bar.grid_drawn=0; } else if(request->procmeter_bar.grid_min>0) { new->procmeter_bar.grid_min=request->procmeter_bar.grid_min; new->procmeter_bar.grid_drawn=1; } else /* if(request->procmeter_bar.grid_min==0) */ { new->procmeter_bar.grid_min=1; new->procmeter_bar.grid_drawn=1; } if(request->procmeter_bar.grid_min>request->procmeter_bar.grid_max && request->procmeter_bar.grid_max) new->procmeter_bar.grid_min=request->procmeter_bar.grid_max; if(new->procmeter_bar.grid_min>=new->procmeter_bar.grid_num) new->procmeter_bar.grid_num=new->procmeter_bar.grid_min; redraw=True; } if(request->procmeter_bar.grid_max!=current->procmeter_bar.grid_max) { if(request->procmeter_bar.grid_max<0) new->procmeter_bar.grid_max=0; else new->procmeter_bar.grid_max=request->procmeter_bar.grid_max; if(request->procmeter_bar.grid_max && request->procmeter_bar.grid_maxprocmeter_bar.grid_min) new->procmeter_bar.grid_max=new->procmeter_bar.grid_min; redraw=True; } if(redraw) BarResize(new); return(redraw); } /*++++++++++++++++++++++++++++++++++++++ Resize the ProcMeter Bar Widget. ProcMeterBarWidget pmw The Widget that is resized. ++++++++++++++++++++++++++++++++++++++*/ static void Resize(ProcMeterBarWidget pmw) { BarResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Widget. ProcMeterBarWidget pmw The Widget to redisplay. XEvent *event The event that caused the redisplay. Region region The region that was exposed. ++++++++++++++++++++++++++++++++++++++*/ static void Redisplay(ProcMeterBarWidget pmw,XEvent *event,Region region) { if(pmw->core.visible) BarUpdate(pmw,True); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterBarWidget pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void BarResize(ProcMeterBarWidget pmw) { (*procMeterGenericClassRec.procmeter_generic_class.resize)((ProcMeterGenericWidget)pmw); pmw->procmeter_generic.label_x=2; /* The grid parts. */ pmw->procmeter_bar.grid_units_x=pmw->core.width-XTextWidth(pmw->procmeter_generic.label_font,pmw->procmeter_bar.grid_units,(int)strlen(pmw->procmeter_bar.grid_units)); pmw->procmeter_bar.grid_maxvis=pmw->core.width/3; if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop) pmw->procmeter_generic.body_start=pmw->procmeter_generic.label_height; else pmw->procmeter_generic.body_start=0; if(pmw->procmeter_bar.grid_num>pmw->procmeter_bar.grid_maxvis && pmw->procmeter_bar.grid_drawn) pmw->procmeter_bar.grid_drawn=-1; if(pmw->procmeter_bar.grid_num<=pmw->procmeter_bar.grid_maxvis && pmw->procmeter_bar.grid_drawn) pmw->procmeter_bar.grid_drawn=1; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterBarWidget pmw The Widget to update. Boolean all Indicates if it all is to be updated including the generic parts. ++++++++++++++++++++++++++++++++++++++*/ static void BarUpdate(ProcMeterBarWidget pmw,Boolean all) { if(pmw->core.visible) { int i; int scale=PROCMETER_GRAPH_SCALE*pmw->procmeter_bar.grid_num; Position pos; Position top_average_bottom,bottom_average_top,average_size; if(all) { (*procMeterGenericClassRec.procmeter_generic_class.update)((ProcMeterGenericWidget)pmw); if(pmw->procmeter_generic.label_pos!=ProcMeterLabelNone) XDrawString(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc, pmw->procmeter_bar.grid_units_x,pmw->procmeter_generic.label_y, pmw->procmeter_bar.grid_units,(int)strlen(pmw->procmeter_bar.grid_units)); } else XClearArea(XtDisplay(pmw),XtWindow(pmw), 0 ,pmw->procmeter_generic.body_start, pmw->core.width,pmw->procmeter_generic.body_height,False); pos=pmw->procmeter_bar.data_sum*pmw->core.width/(scale*2); top_average_bottom=pmw->procmeter_generic.body_start+2*(pmw->procmeter_generic.body_height>>3); bottom_average_top=pmw->procmeter_generic.body_start+pmw->procmeter_generic.body_height-2*(pmw->procmeter_generic.body_height>>3); average_size=pmw->procmeter_generic.body_height>>3; XFillRectangle(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, pos-average_size,top_average_bottom-average_size, average_size ,average_size); XFillRectangle(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, pos-average_size,bottom_average_top, average_size ,average_size); pos=pmw->procmeter_bar.data[pmw->procmeter_bar.data_index]*pmw->core.width/scale; XFillRectangle(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, 0 ,top_average_bottom+1, pos,bottom_average_top-top_average_bottom-2); if(pmw->procmeter_bar.grid_drawn==1) for(i=1;iprocmeter_bar.grid_num;i++) { pos=i*pmw->core.width/pmw->procmeter_bar.grid_num; XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_bar.grid_gc, pos,pmw->procmeter_generic.body_start, pos,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start); } else if(pmw->procmeter_bar.grid_drawn==-1) { pos=pmw->procmeter_bar.grid_maxvis*pmw->core.width/pmw->procmeter_bar.grid_num; XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_bar.grid_gc, pos,pmw->procmeter_generic.body_start, pos,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start); } } } /*++++++++++++++++++++++++++++++++++++++ Add a data point to the ProcMeter Bar Widget. Widget w The ProcMeter Bar Widget. unsigned short datum The data point to add. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterBarAddDatum(Widget w,unsigned short datum) { ProcMeterBarWidget pmw=(ProcMeterBarWidget)w; int new_grid_num; unsigned short old_datum; pmw->procmeter_bar.data_index++; if(pmw->procmeter_bar.data_index==8) pmw->procmeter_bar.data_index=0; old_datum=pmw->procmeter_bar.data[pmw->procmeter_bar.data_index]; pmw->procmeter_bar.data[pmw->procmeter_bar.data_index]=datum; pmw->procmeter_bar.data_sum=(pmw->procmeter_bar.data_sum>>1)+datum-(old_datum>>8); if((pmw->procmeter_bar.data_sum/2)>datum) new_grid_num=((pmw->procmeter_bar.data_sum/2)+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; else new_grid_num=(datum+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numprocmeter_bar.grid_min) new_grid_num=pmw->procmeter_bar.grid_min; if(pmw->procmeter_bar.grid_max && new_grid_num>pmw->procmeter_bar.grid_max) new_grid_num=pmw->procmeter_bar.grid_max; if(new_grid_num!=pmw->procmeter_bar.grid_num) { pmw->procmeter_bar.grid_num=new_grid_num; if(pmw->procmeter_bar.grid_num>pmw->procmeter_bar.grid_maxvis && pmw->procmeter_bar.grid_drawn) pmw->procmeter_bar.grid_drawn=-1; if(pmw->procmeter_bar.grid_num<=pmw->procmeter_bar.grid_maxvis && pmw->procmeter_bar.grid_drawn) pmw->procmeter_bar.grid_drawn=1; } BarUpdate(pmw,False); } procmeter3-3.5d/xaw/widgets/PMBar.h000066400000000000000000000025171165060751200171770ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMBar.h,v 1.2 2000-12-16 17:02:11 amb Exp $ ProcMeter Bar Widget Public include file (for ProcMeter3 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMBAR_H #define PMBAR_H /*+ To stop multiple inclusions. +*/ /*+ The ProcMeter Bar Widget Class Record. +*/ extern WidgetClass procMeterBarWidgetClass; /*+ An opaque reference to the ProcMeter Bar Widget Class Record type. +*/ typedef struct _ProcMeterBarClassRec *ProcMeterBarWidgetClass; /*+ An opaque reference to the ProcMeter Bar Widget Record type. +*/ typedef struct _ProcMeterBarRec *ProcMeterBarWidget; /* The resource names */ #define XtNgridUnits "gridUnits" #define XtNgridForeground "gridForeground" #define XtNgridMin "gridMin" #define XtNgridMax "gridMax" #define XtCGridMin "GridMin" #define XtCGridMax "GridMax" /* Public functions */ void ProcMeterBarAddDatum(Widget pmw,unsigned short datum); #endif /* PMBAR_H */ procmeter3-3.5d/xaw/widgets/PMBarP.h000066400000000000000000000057001165060751200173140ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMBarP.h,v 1.2 1999-10-05 17:53:47 amb Exp $ ProcMeter Bar Widget Private header file (for ProcMeter3 3.2). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMBARP_H #define PMBARP_H /*+ To stop multiple inclusions. +*/ #include "PMBar.h" /*+ The Class Part of the Widget, shared among all instances of the ProcMeter Bar Widget. +*/ typedef struct _ProcMeterBarClassPart { int unused; /*+ Not used. +*/ } ProcMeterBarClassPart; /*+ The complete Class Record for the ProcMeter Bar Widget, includes the Core Widget Class Part. +*/ typedef struct _ProcMeterBarClassRec { CoreClassPart core_class; /*+ The Core Widget Class Part. +*/ ProcMeterGenericClassPart procmeter_generic_class; /*+ The ProcMeter Generic Widget Class Part. +*/ ProcMeterBarClassPart procmeter_bar_class; /*+ The ProcMeter Bar Widget Class Part. +*/ } ProcMeterBarClassRec; /*+ The actual Class Record for the ProcMeter Bar Widget. +*/ extern ProcMeterBarClassRec procMeterBarClassRec; /*+ The ProcMeter Bar Widget Part that is used in each of the ProcMeter Bar Widgets. +*/ typedef struct _ProcMeterBarPart { char* grid_units; /*+ The number of things per grid line (Set & Get via Xt). +*/ Dimension grid_units_x; /*+ The position of the grid units. +*/ Pixel grid_pixel; /*+ The grid lines colour (Set & Get via Xt). +*/ GC grid_gc; /*+ The graphics context for the grid lines. +*/ int grid_min; /*+ The minimum number of grid lines (Set & Get via Xt). +*/ int grid_max; /*+ The maximum number of grid lines (Set & Get via Xt). +*/ int grid_maxvis; /*+ The maximum number of grid lines before removing them. +*/ int grid_drawn; /*+ If 1 then draw as normal, if 0 never draw, if -1 draw only one line. +*/ int grid_num; /*+ The actual number of grid lines. +*/ unsigned short data[8]; /*+ The data for the bar. +*/ unsigned short data_index; /*+ A pointer into the array +*/ unsigned long data_sum; /*+ The average value of the last 10 data points. +*/ } ProcMeterBarPart; /*+ The complete Widget Record that is used per ProcMeter Bar Widget. +*/ typedef struct _ProcMeterBarRec { CorePart core; /*+ The Core Widget Part. +*/ ProcMeterGenericPart procmeter_generic; /*+ The ProcMeter Generic Widget Part. +*/ ProcMeterBarPart procmeter_bar; /*+ The ProcMeter Bar Widget Part. +*/ } ProcMeterBarRec; #endif /* PMBARP_H */ procmeter3-3.5d/xaw/widgets/PMGeneric.c000066400000000000000000000245621165060751200200460ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGeneric.c,v 1.4 2001-01-04 19:26:46 amb Exp $ ProcMeter Generic Widget Source file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include "PMGenericP.h" static void Initialize(ProcMeterGenericWidget request,ProcMeterGenericWidget new); static void Destroy(ProcMeterGenericWidget pmw); static Boolean SetValues(ProcMeterGenericWidget current,ProcMeterGenericWidget request,ProcMeterGenericWidget new); static void Resize(ProcMeterGenericWidget pmw); static void Redisplay(ProcMeterGenericWidget pmw,XEvent *event,Region region); static void GenericResize(ProcMeterGenericWidget pmw); static void GenericUpdate(ProcMeterGenericWidget pmw); static XtResource resources[]= { /* The body parts. */ {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffset(ProcMeterGenericWidget,procmeter_generic.body_pixel),XtRString,XtDefaultForeground}, /* The label parts. */ {XtNlabel, XtCLabel, XtRString, sizeof(XtPointer), XtOffset(ProcMeterGenericWidget,procmeter_generic.label_string), XtRString, "" }, {XtNlabelForeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffset(ProcMeterGenericWidget,procmeter_generic.label_pixel),XtRString,XtDefaultForeground}, {XtNlabelPosition, XtCLabelPosition, XtRInt, sizeof(int), XtOffset(ProcMeterGenericWidget,procmeter_generic.label_pos), XtRString, "-1" }, {XtNlabelFont, XtCFont, XtRFontStruct, sizeof(XFontStruct*), XtOffset(ProcMeterGenericWidget,procmeter_generic.label_font), XtRString, "-*-*-*-r-normal-sans-8-*-*-*-p-*-*-*"} }; /*+ The actual ProcMeter Generic Widget Class Record. +*/ ProcMeterGenericClassRec procMeterGenericClassRec= { { (WidgetClass) &widgetClassRec, "ProcMeterGeneric", sizeof(ProcMeterGenericRec), NULL, NULL, FALSE, (XtInitProc)Initialize, NULL, XtInheritRealize, NULL, 0, resources, XtNumber(resources), NULLQUARK, TRUE, XtExposeCompressMaximal|XtExposeGraphicsExpose, TRUE, TRUE, (XtWidgetProc)Destroy, (XtWidgetProc)Resize, (XtExposeProc)Redisplay, (XtSetValuesFunc)SetValues, NULL, XtInheritSetValuesAlmost, NULL, NULL, XtVersion, NULL, XtInheritTranslations, NULL, NULL, NULL, }, { GenericResize, GenericUpdate } }; /*+ The actual ProcMeter Generic Widget Class Record masquerading as a WidgetClass type. +*/ WidgetClass procMeterGenericWidgetClass=(WidgetClass)&procMeterGenericClassRec; /*++++++++++++++++++++++++++++++++++++++ Initialise a new ProcMeter Generic Widget. ProcMeterGenericWidget request The requested parameters. ProcMeterGenericWidget new The new parameters that are to be filled in. ++++++++++++++++++++++++++++++++++++++*/ static void Initialize(ProcMeterGenericWidget request,ProcMeterGenericWidget new) { XGCValues values; /* The core widget parts. */ if(request->core.width ==0) new->core.width=100; if(request->core.height==0) new->core.height=100; /* The body parts. */ values.foreground=new->procmeter_generic.body_pixel; values.background=new->core.background_pixel; new->procmeter_generic.body_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&values); /* The label parts. */ if((new->procmeter_generic.label_pos!=ProcMeterLabelTop) && (new->procmeter_generic.label_pos!=ProcMeterLabelNone) && (new->procmeter_generic.label_pos!=ProcMeterLabelBottom)) new->procmeter_generic.label_pos=ProcMeterLabelNone; new->procmeter_generic.label_string=XtNewString(request->procmeter_generic.label_string); if(!new->procmeter_generic.label_font) new->procmeter_generic.label_font=XLoadQueryFont(XtDisplay(new),"-*-*-*-r-normal-sans-8-*-*-*-p-*-*-*"); values.font=new->procmeter_generic.label_font->fid; values.foreground=new->procmeter_generic.label_pixel; values.background=new->core.background_pixel; new->procmeter_generic.label_gc=XtGetGC((Widget)new,GCForeground|GCBackground|GCFont,&values); /* The rest of the sizing. */ GenericResize(new); } /*++++++++++++++++++++++++++++++++++++++ Destroy a ProcMeter Generic Widget. ProcMeterGenericWidget pmw The Widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void Destroy(ProcMeterGenericWidget pmw) { XtFree((XtPointer)pmw->procmeter_generic.label_string); XtReleaseGC((Widget)pmw,pmw->procmeter_generic.body_gc); XtReleaseGC((Widget)pmw,pmw->procmeter_generic.label_gc); } /*++++++++++++++++++++++++++++++++++++++ The setvalues procedure that is used to set the values internal to the Widget. Boolean SetValues Returns True if the Widget is to be redrawn. ProcMeterGenericWidget current The current Widget values. ProcMeterGenericWidget request The requested Widget values. ProcMeterGenericWidget new The new Widget values to be set up. ++++++++++++++++++++++++++++++++++++++*/ static Boolean SetValues(ProcMeterGenericWidget current,ProcMeterGenericWidget request,ProcMeterGenericWidget new) { Boolean redraw=False; /* The body parts. */ if(request->procmeter_generic.body_pixel!=current->procmeter_generic.body_pixel) { XGCValues xgcv; XGetGCValues(XtDisplay(new),new->procmeter_generic.body_gc,GCForeground|GCBackground,&xgcv); XtReleaseGC((Widget)new,new->procmeter_generic.body_gc); xgcv.foreground=request->procmeter_generic.body_pixel; xgcv.background=request->core.background_pixel; new->procmeter_generic.body_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&xgcv); redraw=True; } /* The label parts. */ if(request->procmeter_generic.label_pos!=current->procmeter_generic.label_pos) { if((request->procmeter_generic.label_pos!=ProcMeterLabelTop) && (request->procmeter_generic.label_pos!=ProcMeterLabelNone) && (request->procmeter_generic.label_pos!=ProcMeterLabelBottom)) new->procmeter_generic.label_pos=ProcMeterLabelNone; redraw=True; } if(request->procmeter_generic.label_string!=current->procmeter_generic.label_string) { XtFree((XtPointer)new->procmeter_generic.label_string); new->procmeter_generic.label_string=XtNewString(request->procmeter_generic.label_string); redraw=True; } if((request->procmeter_generic.label_font !=current->procmeter_generic.label_font)|| (request->procmeter_generic.label_pixel!=current->procmeter_generic.label_pixel)) { XGCValues xgcv; XGetGCValues(XtDisplay(new),new->procmeter_generic.label_gc,GCForeground|GCBackground|GCFont,&xgcv); XtReleaseGC((Widget)new,new->procmeter_generic.label_gc); xgcv.font=request->procmeter_generic.label_font->fid; xgcv.foreground=request->procmeter_generic.label_pixel; xgcv.background=request->core.background_pixel; new->procmeter_generic.label_gc=XtGetGC((Widget)new,GCForeground|GCBackground|GCFont,&xgcv); redraw=True; } /* Resize if needed */ if(redraw) GenericResize(new); return(redraw); } /*++++++++++++++++++++++++++++++++++++++ Resize the ProcMeter Generic Widget. ProcMeterGenericWidget pmw The Widget that is resized. ++++++++++++++++++++++++++++++++++++++*/ static void Resize(ProcMeterGenericWidget pmw) { GenericResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Generic Widget. ProcMeterGenericWidget pmw The Widget to redisplay. XEvent *event The event that caused the redisplay. Region region The region that was exposed. ++++++++++++++++++++++++++++++++++++++*/ static void Redisplay(ProcMeterGenericWidget pmw,XEvent *event,Region region) { if(pmw->core.visible) GenericUpdate(pmw); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterGenericWidget pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void GenericResize(ProcMeterGenericWidget pmw) { /* The label parts. */ if(pmw->procmeter_generic.label_pos) { pmw->procmeter_generic.label_height=pmw->procmeter_generic.label_font->ascent+pmw->procmeter_generic.label_font->descent+2; pmw->procmeter_generic.label_x=(pmw->core.width-XTextWidth(pmw->procmeter_generic.label_font,pmw->procmeter_generic.label_string,(int)strlen(pmw->procmeter_generic.label_string)))/2; if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop) pmw->procmeter_generic.label_y=pmw->procmeter_generic.label_height-1-pmw->procmeter_generic.label_font->descent; else pmw->procmeter_generic.label_y=pmw->core.height-pmw->procmeter_generic.label_font->descent; } else { pmw->procmeter_generic.label_height=0; pmw->procmeter_generic.label_x=0; pmw->procmeter_generic.label_y=0; } /* The body parts. */ pmw->procmeter_generic.body_height=pmw->core.height-pmw->procmeter_generic.label_height; if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop) pmw->procmeter_generic.body_start=pmw->procmeter_generic.label_height; else pmw->procmeter_generic.body_start=0; } /*++++++++++++++++++++++++++++++++++++++ Update the display of the generic part of the widget. ProcMeterGenericWidget pmw The Widget to update. ++++++++++++++++++++++++++++++++++++++*/ static void GenericUpdate(ProcMeterGenericWidget pmw) { if(pmw->core.visible) { XClearWindow(XtDisplay(pmw),XtWindow(pmw)); if(pmw->procmeter_generic.label_pos) { XDrawString(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc, pmw->procmeter_generic.label_x,pmw->procmeter_generic.label_y, pmw->procmeter_generic.label_string,(int)strlen(pmw->procmeter_generic.label_string)); if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop) XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc, 0 ,pmw->procmeter_generic.label_height-1, pmw->core.width,pmw->procmeter_generic.label_height-1); else XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc, 0 ,pmw->procmeter_generic.body_height, pmw->core.width,pmw->procmeter_generic.body_height); } } } procmeter3-3.5d/xaw/widgets/PMGeneric.h000066400000000000000000000025711165060751200200470ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGeneric.h,v 1.1 1998-09-19 15:28:31 amb Exp $ ProcMeter Generic Widget Public include file (for ProcMeter 3.0). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGENERIC_H #define PMGENERIC_H /*+ To stop multiple inclusions. +*/ /*+ The ProcMeter Generic Widget Class Record. +*/ extern WidgetClass procMeterGenericWidgetClass; /*+ An opaque reference to the ProcMeter Generic Widget Class Record type. +*/ typedef struct _ProcMeterGenericClassRec *ProcMeterGenericWidgetClass; /*+ An opaque reference to the ProcMeter Generic Widget Record type. +*/ typedef struct _ProcMeterGenericRec *ProcMeterGenericWidget; /* The resource names */ #define XtNlabelForeground "labelforeground" #define XtNlabelFont "labelfont" #define XtNlabelPosition "labelPosition" #define XtCLabelPosition "LabelPosition" /* The options for label placement */ #define ProcMeterLabelTop 1 #define ProcMeterLabelNone 0 #define ProcMeterLabelBottom -1 #endif /* PMGENERIC_H */ procmeter3-3.5d/xaw/widgets/PMGenericP.h000066400000000000000000000053361165060751200201710ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGenericP.h,v 1.2 2001-01-04 19:26:46 amb Exp $ ProcMeter Generic Widget Private header file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGENERICP_H #define PMGENERICP_H /*+ To stop multiple inclusions. +*/ #include "PMGeneric.h" /*+ The Class Part of the Widget, shared among all instances of the ProcMeter Generic Widget. +*/ typedef struct _ProcMeterGenericClassPart { void (*resize)(ProcMeterGenericWidget pmw); void (*update)(ProcMeterGenericWidget pmw); } ProcMeterGenericClassPart; /*+ The complete Class Record for the ProcMeter Generic Widget, includes the Core Widget Class Part. +*/ typedef struct _ProcMeterGenericClassRec { CoreClassPart core_class; /*+ The Core Widget Class Part. +*/ ProcMeterGenericClassPart procmeter_generic_class; /*+ The ProcMeter Generic Widget Class Part. +*/ } ProcMeterGenericClassRec; /*+ The actual Class Record for the ProcMeter Generic Widget. +*/ extern ProcMeterGenericClassRec procMeterGenericClassRec; /*+ The ProcMeter Generic Widget Part that is used in each of the ProcMeter Generic Widgets. +*/ typedef struct _ProcMeterGenericPart { Pixel body_pixel; /*+ The body colour (Set & Get via Xt). +*/ GC body_gc; /*+ The graphics context for the body. +*/ Dimension body_height; /*+ The height of the body part. +*/ Dimension body_start; /*+ The start position of the body part. +*/ char* label_string; /*+ The label for the Widget (Set & Get via Xt). +*/ Pixel label_pixel; /*+ The label colour (Set & Get via Xt). +*/ GC label_gc; /*+ The graphics context for the label. +*/ int label_pos; /*+ The position of the label (Set & Get via Xt). +*/ XFontStruct* label_font; /*+ The font for the label (Set & Get via Xt). +*/ Dimension label_height; /*+ The height of the label. +*/ Dimension label_x,label_y; /*+ The position of the label. +*/ } ProcMeterGenericPart; /*+ The complete Widget Record that is used per ProcMeter Generic Widget. +*/ typedef struct _ProcMeterGenericRec { CorePart core; /*+ The Core Widget Part. +*/ ProcMeterGenericPart procmeter_generic; /*+ The ProcMeter Generic Widget Part. +*/ } ProcMeterGenericRec; #endif /* PMGENERICP_H */ procmeter3-3.5d/xaw/widgets/PMGraph.c000066400000000000000000000437571165060751200175420ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGraph.c,v 1.9 2008-04-27 15:21:30 amb Exp $ ProcMeter Graph Widget Source file (for ProcMeter3 3.5b). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996-2008 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include "PMGenericP.h" #include "PMGraphP.h" #include "procmeter.h" static void Initialize(ProcMeterGraphWidget request,ProcMeterGraphWidget new); static void Destroy(ProcMeterGraphWidget pmw); static Boolean SetValues(ProcMeterGraphWidget current,ProcMeterGraphWidget request,ProcMeterGraphWidget new); static void Resize(ProcMeterGraphWidget pmw); static void Redisplay(ProcMeterGraphWidget pmw,XEvent *event,Region region); static void GraphResize(ProcMeterGraphWidget pmw); static void GraphUpdate(ProcMeterGraphWidget pmw,Boolean all); static XtResource resources[]= { /* The line style */ {XtNsolid, XtCSolid, XtRBoolean, sizeof(Boolean), XtOffset(ProcMeterGraphWidget,procmeter_graph.line_solid), XtRString, "TRUE" }, /* The grid parts. */ {XtNgridUnits, XtCLabel, XtRString, sizeof(XtPointer), XtOffset(ProcMeterGraphWidget,procmeter_graph.grid_units), XtRString, "" }, {XtNgridForeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffset(ProcMeterGraphWidget,procmeter_graph.grid_pixel),XtRString,XtDefaultBackground}, {XtNgridMin, XtCGridMin, XtRInt, sizeof(int), XtOffset(ProcMeterGraphWidget,procmeter_graph.grid_min), XtRString, "1" }, {XtNgridMax, XtCGridMax, XtRInt, sizeof(int), XtOffset(ProcMeterGraphWidget,procmeter_graph.grid_max), XtRString, "0" } }; /*+ The actual ProcMeter Graph Widget Class Record. +*/ ProcMeterGraphClassRec procMeterGraphClassRec= { { (WidgetClass) &procMeterGenericClassRec, "ProcMeterGraph", sizeof(ProcMeterGraphRec), NULL, NULL, FALSE, (XtInitProc)Initialize, NULL, XtInheritRealize, NULL, 0, resources, XtNumber(resources), NULLQUARK, TRUE, XtExposeCompressMaximal|XtExposeGraphicsExpose, TRUE, TRUE, (XtWidgetProc)Destroy, (XtWidgetProc)Resize, (XtExposeProc)Redisplay, (XtSetValuesFunc)SetValues, NULL, XtInheritSetValuesAlmost, NULL, NULL, XtVersion, NULL, XtInheritTranslations, NULL, NULL, NULL, }, { NULL, NULL }, { 0 } }; /*+ The actual ProcMeter Graph Widget Class Record masquerading as a WidgetClass type. +*/ WidgetClass procMeterGraphWidgetClass=(WidgetClass)&procMeterGraphClassRec; /*++++++++++++++++++++++++++++++++++++++ Initialise a new ProcMeter Graph Widget. ProcMeterGraphWidget request The requested parameters. ProcMeterGraphWidget new The new parameters that are to be filled in. ++++++++++++++++++++++++++++++++++++++*/ static void Initialize(ProcMeterGraphWidget request,ProcMeterGraphWidget new) { XGCValues values; /* The grid parts. */ new->procmeter_graph.grid_units=XtNewString(request->procmeter_graph.grid_units); values.foreground=new->procmeter_graph.grid_pixel; values.background=new->core.background_pixel; new->procmeter_graph.grid_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&values); if(request->procmeter_graph.grid_min<0) { new->procmeter_graph.grid_min=-request->procmeter_graph.grid_min; new->procmeter_graph.grid_drawn=0; } else if(request->procmeter_graph.grid_min>0) { new->procmeter_graph.grid_min=request->procmeter_graph.grid_min; new->procmeter_graph.grid_drawn=1; } else /* if(request->procmeter_graph.grid_min==0) */ { new->procmeter_graph.grid_min=1; new->procmeter_graph.grid_drawn=1; } if(request->procmeter_graph.grid_max<0) new->procmeter_graph.grid_max=0; else new->procmeter_graph.grid_max=request->procmeter_graph.grid_max; if(new->procmeter_graph.grid_max && new->procmeter_graph.grid_maxprocmeter_graph.grid_min) new->procmeter_graph.grid_max=new->procmeter_graph.grid_min; new->procmeter_graph.grid_num=new->procmeter_graph.grid_min; /* The data parts. */ new->procmeter_graph.data_num=new->core.width; new->procmeter_graph.data=(unsigned short*)XtCalloc(new->procmeter_graph.data_num,sizeof(unsigned short)); new->procmeter_graph.data_max=0; new->procmeter_graph.data_index=0; /* The rest of the sizing. */ GraphResize(new); } /*++++++++++++++++++++++++++++++++++++++ Destroy a ProcMeter Graph Widget. ProcMeterGraphWidget pmw The Widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void Destroy(ProcMeterGraphWidget pmw) { XtReleaseGC((Widget)pmw,pmw->procmeter_graph.grid_gc); XtFree((XtPointer)pmw->procmeter_graph.grid_units); XtFree((XtPointer)pmw->procmeter_graph.data); } /*++++++++++++++++++++++++++++++++++++++ The setvalues procedure that is used to set the values internal to the Widget. Boolean SetValues Returns True if the Widget is to be redrawn. ProcMeterGraphWidget current The current Widget values. ProcMeterGraphWidget request The requested Widget values. ProcMeterGraphWidget new The new Widget values to be set up. ++++++++++++++++++++++++++++++++++++++*/ static Boolean SetValues(ProcMeterGraphWidget current,ProcMeterGraphWidget request,ProcMeterGraphWidget new) { Boolean redraw=False; /* The line style */ if(request->procmeter_graph.line_solid!=current->procmeter_graph.line_solid) redraw=True; /* The grid parts. */ if(request->procmeter_graph.grid_units!=current->procmeter_graph.grid_units) { XtFree((XtPointer)new->procmeter_graph.grid_units); new->procmeter_graph.grid_units=XtNewString(request->procmeter_graph.grid_units); redraw=True; } if(request->procmeter_graph.grid_pixel!=current->procmeter_graph.grid_pixel) { XGCValues xgcv; XGetGCValues(XtDisplay(new),new->procmeter_graph.grid_gc,GCForeground|GCBackground,&xgcv); XtReleaseGC((Widget)new,new->procmeter_graph.grid_gc); xgcv.foreground=request->procmeter_graph.grid_pixel; xgcv.background=request->core.background_pixel; new->procmeter_graph.grid_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&xgcv); redraw=True; } if(request->procmeter_graph.grid_min!=current->procmeter_graph.grid_min) { if(request->procmeter_graph.grid_min<0) { new->procmeter_graph.grid_min=-request->procmeter_graph.grid_min; new->procmeter_graph.grid_drawn=0; } else if(request->procmeter_graph.grid_min>0) { new->procmeter_graph.grid_min=request->procmeter_graph.grid_min; new->procmeter_graph.grid_drawn=1; } else /* if(request->procmeter_graph.grid_min==0) */ { new->procmeter_graph.grid_min=1; new->procmeter_graph.grid_drawn=1; } if(request->procmeter_graph.grid_min>request->procmeter_graph.grid_max && request->procmeter_graph.grid_max) new->procmeter_graph.grid_min=request->procmeter_graph.grid_max; if(new->procmeter_graph.grid_min>=new->procmeter_graph.grid_num) new->procmeter_graph.grid_num=new->procmeter_graph.grid_min; redraw=True; } if(request->procmeter_graph.grid_max!=current->procmeter_graph.grid_max) { if(request->procmeter_graph.grid_max<0) new->procmeter_graph.grid_max=0; else new->procmeter_graph.grid_max=request->procmeter_graph.grid_max; if(request->procmeter_graph.grid_max && request->procmeter_graph.grid_maxprocmeter_graph.grid_min) new->procmeter_graph.grid_max=new->procmeter_graph.grid_min; redraw=True; } if(redraw) GraphResize(new); return(redraw); } /*++++++++++++++++++++++++++++++++++++++ Resize the ProcMeter Graph Widget. ProcMeterGraphWidget pmw The Widget that is resized. ++++++++++++++++++++++++++++++++++++++*/ static void Resize(ProcMeterGraphWidget pmw) { if(pmw->procmeter_graph.data_num!=pmw->core.width) { int i,old_num=pmw->procmeter_graph.data_num; unsigned short* old_data=pmw->procmeter_graph.data; pmw->procmeter_graph.data_num=pmw->core.width; pmw->procmeter_graph.data=(unsigned short*)XtCalloc(pmw->procmeter_graph.data_num,sizeof(unsigned short)); if(pmw->procmeter_graph.data_numprocmeter_graph.data_num; else i=old_num; for(;i>0;i--) pmw->procmeter_graph.data[(-i+pmw->procmeter_graph.data_num)%pmw->procmeter_graph.data_num]=old_data[(pmw->procmeter_graph.data_index-i+old_num)%old_num]; pmw->procmeter_graph.data_index=0; XtFree((XtPointer)old_data); for(i=pmw->procmeter_graph.data_max=0;iprocmeter_graph.data_num;i++) if(pmw->procmeter_graph.data[i]>pmw->procmeter_graph.data_max) pmw->procmeter_graph.data_max=pmw->procmeter_graph.data[i]; pmw->procmeter_graph.grid_num=(pmw->procmeter_graph.data_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(pmw->procmeter_graph.grid_numprocmeter_graph.grid_min) pmw->procmeter_graph.grid_num=pmw->procmeter_graph.grid_min; if(pmw->procmeter_graph.grid_max && pmw->procmeter_graph.grid_num>pmw->procmeter_graph.grid_max) pmw->procmeter_graph.grid_num=pmw->procmeter_graph.grid_max; } GraphResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Widget. ProcMeterGraphWidget pmw The Widget to redisplay. XEvent *event The event that caused the redisplay. Region region The region that was exposed. ++++++++++++++++++++++++++++++++++++++*/ static void Redisplay(ProcMeterGraphWidget pmw,XEvent *event,Region region) { if(pmw->core.visible) GraphUpdate(pmw,True); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterGraphWidget pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void GraphResize(ProcMeterGraphWidget pmw) { (*procMeterGenericClassRec.procmeter_generic_class.resize)((ProcMeterGenericWidget)pmw); pmw->procmeter_generic.label_x=2; /* The grid parts. */ pmw->procmeter_graph.grid_units_x=pmw->core.width-XTextWidth(pmw->procmeter_generic.label_font,pmw->procmeter_graph.grid_units,(int)strlen(pmw->procmeter_graph.grid_units)); pmw->procmeter_graph.grid_maxvis=pmw->procmeter_generic.body_height/3; if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop) pmw->procmeter_generic.body_start=pmw->procmeter_generic.label_height; else pmw->procmeter_generic.body_start=0; if(pmw->procmeter_graph.grid_num>pmw->procmeter_graph.grid_maxvis && pmw->procmeter_graph.grid_drawn) pmw->procmeter_graph.grid_drawn=-1; if(pmw->procmeter_graph.grid_num<=pmw->procmeter_graph.grid_maxvis && pmw->procmeter_graph.grid_drawn) pmw->procmeter_graph.grid_drawn=1; } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterGraphWidget pmw The Widget to update. Boolean all Indicates if the whole widget is to be updated. ++++++++++++++++++++++++++++++++++++++*/ static void GraphUpdate(ProcMeterGraphWidget pmw,Boolean all) { if(pmw->core.visible) { int i; int scale=PROCMETER_GRAPH_SCALE*pmw->procmeter_graph.grid_num; unsigned short val; Position pos; if(all) { (*procMeterGenericClassRec.procmeter_generic_class.update)((ProcMeterGenericWidget)pmw); if(pmw->procmeter_generic.label_pos!=ProcMeterLabelNone) XDrawString(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc, pmw->procmeter_graph.grid_units_x,pmw->procmeter_generic.label_y, pmw->procmeter_graph.grid_units,(int)strlen(pmw->procmeter_graph.grid_units)); for(i=0;iprocmeter_graph.data_num;i++) { val=pmw->procmeter_graph.data[(i+pmw->procmeter_graph.data_index)%pmw->procmeter_graph.data_num]; pos=val*pmw->procmeter_generic.body_height/scale; if(pmw->procmeter_graph.line_solid) XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, i,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start, i,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); else if(i) { unsigned short oldval=pmw->procmeter_graph.data[(i-1+pmw->procmeter_graph.data_index)%pmw->procmeter_graph.data_num]; Position oldpos=oldval*pmw->procmeter_generic.body_height/scale; XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, i,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-oldpos, i,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); } } if(pmw->procmeter_graph.grid_drawn==1) for(i=1;iprocmeter_graph.grid_num;i++) { pos=i*pmw->procmeter_generic.body_height/pmw->procmeter_graph.grid_num; XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_graph.grid_gc, 0 ,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos, pmw->core.width,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); } else if(pmw->procmeter_graph.grid_drawn==-1) { pos=pmw->procmeter_graph.grid_maxvis*pmw->procmeter_generic.body_height/pmw->procmeter_graph.grid_num; XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_graph.grid_gc, 0 ,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos, pmw->core.width,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); } } else { val=pmw->procmeter_graph.data[(pmw->procmeter_graph.data_num-1+pmw->procmeter_graph.data_index)%pmw->procmeter_graph.data_num]; pos=val*pmw->procmeter_generic.body_height/scale; XCopyArea(XtDisplay(pmw),XtWindow(pmw),XtWindow(pmw),pmw->procmeter_graph.grid_gc, 1,pmw->procmeter_generic.body_start,(unsigned)(pmw->core.width-1),pmw->procmeter_generic.body_height, 0,pmw->procmeter_generic.body_start); XClearArea(XtDisplay(pmw),XtWindow(pmw), pmw->core.width-1,pmw->procmeter_generic.body_start,1,pmw->procmeter_generic.body_height, False); if(pmw->procmeter_graph.line_solid) XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, (signed)(pmw->procmeter_graph.data_num-1),pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start, (signed)(pmw->procmeter_graph.data_num-1),pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); else { unsigned short oldval=pmw->procmeter_graph.data[(pmw->procmeter_graph.data_num-2+pmw->procmeter_graph.data_index)%pmw->procmeter_graph.data_num]; Position oldpos=oldval*pmw->procmeter_generic.body_height/scale; XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, (signed)(pmw->procmeter_graph.data_num-1),pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-oldpos, (signed)(pmw->procmeter_graph.data_num-1),pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); } if(pmw->procmeter_graph.grid_drawn==1) for(i=1;iprocmeter_graph.grid_num;i++) { pos=i*pmw->procmeter_generic.body_height/pmw->procmeter_graph.grid_num; XDrawPoint(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_graph.grid_gc, pmw->core.width-1,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); } else if(pmw->procmeter_graph.grid_drawn==-1) { pos=pmw->procmeter_graph.grid_maxvis*pmw->procmeter_generic.body_height/pmw->procmeter_graph.grid_num; XDrawPoint(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_graph.grid_gc, pmw->core.width-1,pmw->procmeter_generic.body_height+pmw->procmeter_generic.body_start-pos); } } } } /*++++++++++++++++++++++++++++++++++++++ Add a data point to the ProcMeter Graph Widget. Widget w The ProcMeter Graph Widget. unsigned short datum The data point to add. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterGraphAddDatum(Widget w,unsigned short datum) { ProcMeterGraphWidget pmw=(ProcMeterGraphWidget)w; unsigned short old_datum,new_data_max=pmw->procmeter_graph.data_max; int i; old_datum=pmw->procmeter_graph.data[pmw->procmeter_graph.data_index]; pmw->procmeter_graph.data[pmw->procmeter_graph.data_index]=datum; pmw->procmeter_graph.data_index=(pmw->procmeter_graph.data_index+1)%pmw->procmeter_graph.data_num; if(datum>new_data_max) new_data_max=datum; else if(old_datum==new_data_max) for(i=new_data_max=0;iprocmeter_graph.data_num;i++) if(pmw->procmeter_graph.data[i]>new_data_max) new_data_max=pmw->procmeter_graph.data[i]; if(new_data_max!=pmw->procmeter_graph.data_max) { int new_grid_num=(new_data_max+(PROCMETER_GRAPH_SCALE-1))/PROCMETER_GRAPH_SCALE; if(new_grid_numprocmeter_graph.grid_min) new_grid_num=pmw->procmeter_graph.grid_min; if(pmw->procmeter_graph.grid_max && new_grid_num>pmw->procmeter_graph.grid_max) new_grid_num=pmw->procmeter_graph.grid_max; pmw->procmeter_graph.data_max=new_data_max; if(new_grid_num!=pmw->procmeter_graph.grid_num) { pmw->procmeter_graph.grid_num=new_grid_num; if(pmw->procmeter_graph.grid_num>pmw->procmeter_graph.grid_maxvis && pmw->procmeter_graph.grid_drawn) pmw->procmeter_graph.grid_drawn=-1; if(pmw->procmeter_graph.grid_num<=pmw->procmeter_graph.grid_maxvis && pmw->procmeter_graph.grid_drawn) pmw->procmeter_graph.grid_drawn=1; GraphUpdate(pmw,True); } } GraphUpdate(pmw,False); } procmeter3-3.5d/xaw/widgets/PMGraph.h000066400000000000000000000026561165060751200175400ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGraph.h,v 1.3 2000-12-16 17:02:52 amb Exp $ ProcMeter Graph Widget Public include file (for ProcMeter3 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGRAPH_H #define PMGRAPH_H /*+ To stop multiple inclusions. +*/ /*+ The ProcMeter Graph Widget Class Record. +*/ extern WidgetClass procMeterGraphWidgetClass; /*+ An opaque reference to the ProcMeter Graph Widget Class Record type. +*/ typedef struct _ProcMeterGraphClassRec *ProcMeterGraphWidgetClass; /*+ An opaque reference to the ProcMeter Graph Widget Record type. +*/ typedef struct _ProcMeterGraphRec *ProcMeterGraphWidget; /* The resource names */ #define XtNsolid "solid" #define XtNgridUnits "gridUnits" #define XtNgridForeground "gridForeground" #define XtNgridMin "gridMin" #define XtNgridMax "gridMax" #define XtCSolid "Solid" #define XtCGridMin "GridMin" #define XtCGridMax "GridMax" /* Public functions */ void ProcMeterGraphAddDatum(Widget pmw,unsigned short datum); #endif /* PMGRAPH_H */ procmeter3-3.5d/xaw/widgets/PMGraphP.h000066400000000000000000000062451165060751200176560ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGraphP.h,v 1.2 1999-02-13 11:37:24 amb Exp $ ProcMeter Graph Widget Private header file (for ProcMeter3 3.1). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,99 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMGRAPHP_H #define PMGRAPHP_H /*+ To stop multiple inclusions. +*/ #include "PMGraph.h" /*+ The Class Part of the Widget, shared among all instances of the ProcMeter Graph Widget. +*/ typedef struct _ProcMeterGraphClassPart { int unused; /*+ Not used. +*/ } ProcMeterGraphClassPart; /*+ The complete Class Record for the ProcMeter Graph Widget, includes the Core Widget Class Part. +*/ typedef struct _ProcMeterGraphClassRec { CoreClassPart core_class; /*+ The Core Widget Class Part. +*/ ProcMeterGenericClassPart procmeter_generic_class; /*+ The ProcMeter Generic Widget Class Part. +*/ ProcMeterGraphClassPart procmeter_graph_class; /*+ The ProcMeter Graph Widget Class Part. +*/ } ProcMeterGraphClassRec; /*+ The actual Class Record for the ProcMeter Graph Widget. +*/ extern ProcMeterGraphClassRec procMeterGraphClassRec; /*+ The ProcMeter Graph Widget Part that is used in each of the ProcMeter Graph Widgets. +*/ typedef struct _ProcMeterGraphPart { char* grid_units; /*+ The number of things per grid line (Set & Get via Xt). +*/ Dimension grid_units_x; /*+ The position of the grid units. +*/ Pixel grid_pixel; /*+ The grid lines colour (Set & Get via Xt). +*/ GC grid_gc; /*+ The graphics context for the grid lines. +*/ int grid_min; /*+ The minimum number of grid lines (Set & Get via Xt). +*/ int grid_max; /*+ The maximum number of grid lines (Set & Get via Xt). +*/ int grid_maxvis; /*+ The maximum number of grid lines before removing them. +*/ int grid_drawn; /*+ If 1 then draw as normal, if 0 never draw, if -1 draw only one line. +*/ int grid_num; /*+ The actual number of grid lines. +*/ Boolean line_solid; /*+ True if the area under the graph is to be filled (Set & Get via Xt). +*/ unsigned short* data; /*+ The data for the graph. +*/ unsigned short data_max; /*+ The maximum data value. +*/ unsigned int data_num; /*+ The number of data points. +*/ int data_index; /*+ An index into the array for the new value. +*/ } ProcMeterGraphPart; /*+ The complete Widget Record that is used per ProcMeter Graph Widget. +*/ typedef struct _ProcMeterGraphRec { CorePart core; /*+ The Core Widget Part. +*/ ProcMeterGenericPart procmeter_generic; /*+ The ProcMeter Generic Widget Part. +*/ ProcMeterGraphPart procmeter_graph; /*+ The ProcMeter Graph Widget Part. +*/ } ProcMeterGraphRec; #endif /* PMGRAPHP_H */ procmeter3-3.5d/xaw/widgets/PMText.c000066400000000000000000000174711165060751200174170ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMText.c,v 1.4 2001-01-04 19:26:46 amb Exp $ ProcMeter Text Widget Source file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include "PMGenericP.h" #include "PMTextP.h" static void Initialize(ProcMeterTextWidget request,ProcMeterTextWidget new); static void Destroy(ProcMeterTextWidget pmw); static Boolean SetValues(ProcMeterTextWidget current,ProcMeterTextWidget request,ProcMeterTextWidget new); static void Resize(ProcMeterTextWidget pmw); static void Redisplay(ProcMeterTextWidget pmw,XEvent *event,Region region); static void TextResize(ProcMeterTextWidget pmw); static void TextUpdate(ProcMeterTextWidget pmw,Boolean all); static XtResource resources[]= { /* The text parts. */ {XtNtext, XtCLabel, XtRString, sizeof(XtPointer), XtOffset(ProcMeterTextWidget,procmeter_text.text_string), XtRString, "" }, {XtNtextFont, XtCFont, XtRFontStruct, sizeof(XFontStruct*), XtOffset(ProcMeterTextWidget,procmeter_text.text_font), XtRString, "-*-*-*-r-normal-sans-12-*-*-*-p-*-*-*"} }; /*+ The actual ProcMeter Text Widget Class Record. +*/ ProcMeterTextClassRec procMeterTextClassRec= { { (WidgetClass) &procMeterGenericClassRec, "ProcMeterText", sizeof(ProcMeterTextRec), NULL, NULL, FALSE, (XtInitProc)Initialize, NULL, XtInheritRealize, NULL, 0, resources, XtNumber(resources), NULLQUARK, TRUE, XtExposeCompressMaximal|XtExposeGraphicsExpose, TRUE, TRUE, (XtWidgetProc)Destroy, (XtWidgetProc)Resize, (XtExposeProc)Redisplay, (XtSetValuesFunc)SetValues, NULL, XtInheritSetValuesAlmost, NULL, NULL, XtVersion, NULL, XtInheritTranslations, NULL, NULL, NULL, }, { NULL, NULL }, { 0 } }; /*+ The actual ProcMeter Text Widget Class Record masquerading as a WidgetClass type. +*/ WidgetClass procMeterTextWidgetClass=(WidgetClass)&procMeterTextClassRec; /*++++++++++++++++++++++++++++++++++++++ Initialise a new ProcMeter Text Widget. ProcMeterTextWidget request The requested parameters. ProcMeterTextWidget new The new parameters that are to be filled in. ++++++++++++++++++++++++++++++++++++++*/ static void Initialize(ProcMeterTextWidget request,ProcMeterTextWidget new) { /* The text parts. */ if(!new->procmeter_text.text_font) new->procmeter_text.text_font=XLoadQueryFont(XtDisplay(new),"-*-*-*-r-normal-sans-12-*-*-*-p-*-*-*"); new->procmeter_text.text_string=XtNewString(request->procmeter_text.text_string); XSetFont(XtDisplay(new),new->procmeter_generic.body_gc,new->procmeter_text.text_font->fid); /* The rest of the sizing. */ TextResize(new); } /*++++++++++++++++++++++++++++++++++++++ Destroy a ProcMeter Text Widget. ProcMeterTextWidget pmw The Widget to destroy. ++++++++++++++++++++++++++++++++++++++*/ static void Destroy(ProcMeterTextWidget pmw) { XtFree((XtPointer)pmw->procmeter_text.text_string); } /*++++++++++++++++++++++++++++++++++++++ The setvalues procedure that is used to set the values internal to the Widget. Boolean SetValues Returns True if the Widget is to be redrawn. ProcMeterTextWidget current The current Widget values. ProcMeterTextWidget request The requested Widget values. ProcMeterTextWidget new The new Widget values to be set up. ++++++++++++++++++++++++++++++++++++++*/ static Boolean SetValues(ProcMeterTextWidget current,ProcMeterTextWidget request,ProcMeterTextWidget new) { Boolean redraw=False; /* The text parts. */ if(request->procmeter_text.text_string!=current->procmeter_text.text_string) { XtFree((XtPointer)new->procmeter_text.text_string); new->procmeter_text.text_string=XtNewString(request->procmeter_text.text_string); redraw=True; } if(request->procmeter_text.text_font!=current->procmeter_text.text_font) { XSetFont(XtDisplay(new),new->procmeter_generic.body_gc,new->procmeter_text.text_font->fid); redraw=True; } if(redraw) TextResize(new); return(redraw); } /*++++++++++++++++++++++++++++++++++++++ Resize the ProcMeter Text Widget. ProcMeterTextWidget pmw The Widget that is resized. ++++++++++++++++++++++++++++++++++++++*/ static void Resize(ProcMeterTextWidget pmw) { TextResize(pmw); } /*++++++++++++++++++++++++++++++++++++++ Redisplay the ProcMeter Widget. ProcMeterTextWidget pmw The Widget to redisplay. XEvent *event The event that caused the redisplay. Region region The region that was exposed. ++++++++++++++++++++++++++++++++++++++*/ static void Redisplay(ProcMeterTextWidget pmw,XEvent *event,Region region) { if(pmw->core.visible) TextUpdate(pmw,True); } /*++++++++++++++++++++++++++++++++++++++ Perform all of the sizing on the Widget when it is created/resized. ProcMeterTextWidget pmw The Widget to resize. ++++++++++++++++++++++++++++++++++++++*/ static void TextResize(ProcMeterTextWidget pmw) { Dimension text_width,text_height; (*procMeterGenericClassRec.procmeter_generic_class.resize)((ProcMeterGenericWidget)pmw); /* The text parts. */ text_width=XTextWidth(pmw->procmeter_text.text_font,pmw->procmeter_text.text_string,(int)strlen(pmw->procmeter_text.text_string)); text_height=pmw->procmeter_text.text_font->ascent+pmw->procmeter_text.text_font->descent+2; pmw->procmeter_text.text_x=(pmw->core.width-text_width)/2; pmw->procmeter_text.text_y=pmw->procmeter_generic.body_start+1+pmw->procmeter_text.text_font->ascent; if(XtIsSubclass(XtParent(pmw),panedWidgetClass)) { XtOrientation orient; XtVaGetValues(XtParent(pmw),XtNorientation,&orient,NULL); if(orient==XtorientVertical) XawPanedSetMinMax((Widget)pmw,text_height+pmw->procmeter_generic.label_height, text_height+pmw->procmeter_generic.label_height); else { text_width=XTextWidth(pmw->procmeter_text.text_font,"NNNNNNNNNNNNNNN",15); XawPanedSetMinMax((Widget)pmw,text_width,text_width); } } } /*++++++++++++++++++++++++++++++++++++++ Update the display. ProcMeterTextWidget pmw The Widget to update. Boolean all Indicates if the whole widget is to be updated. ++++++++++++++++++++++++++++++++++++++*/ static void TextUpdate(ProcMeterTextWidget pmw,Boolean all) { if(pmw->core.visible) { if(all) (*procMeterGenericClassRec.procmeter_generic_class.update)((ProcMeterGenericWidget)pmw); else XClearArea(XtDisplay(pmw),XtWindow(pmw), 0 ,pmw->procmeter_generic.body_start, pmw->core.width,pmw->procmeter_generic.body_height,False); XDrawString(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.body_gc, pmw->procmeter_text.text_x ,pmw->procmeter_text.text_y, pmw->procmeter_text.text_string,(int)strlen(pmw->procmeter_text.text_string)); } } /*++++++++++++++++++++++++++++++++++++++ Change the data displayed in the ProcMeter Text Widget. Widget w The ProcMeter Text Widget. char *data The new string to display. ++++++++++++++++++++++++++++++++++++++*/ void ProcMeterTextChangeData(Widget w,char *data) { ProcMeterTextWidget pmw=(ProcMeterTextWidget)w; XtFree((XtPointer)pmw->procmeter_text.text_string); pmw->procmeter_text.text_string=XtNewString(data); pmw->procmeter_text.text_x=(pmw->core.width-XTextWidth(pmw->procmeter_text.text_font,pmw->procmeter_text.text_string,(int)strlen(pmw->procmeter_text.text_string)))/2; TextUpdate(pmw,False); } procmeter3-3.5d/xaw/widgets/PMText.h000066400000000000000000000022551165060751200174160ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMText.h,v 1.2 2000-12-16 17:03:10 amb Exp $ ProcMeter Text Widget Public include file (for ProcMeter 3.3). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMTEXT_H #define PMTEXT_H /*+ To stop multiple inclusions. +*/ /*+ The ProcMeter Text Widget Class Record. +*/ extern WidgetClass procMeterTextWidgetClass; /*+ An opaque reference to the ProcMeter Text Widget Class Record type. +*/ typedef struct _ProcMeterTextClassRec *ProcMeterTextWidgetClass; /*+ An opaque reference to the ProcMeter Text Widget Record type. +*/ typedef struct _ProcMeterTextRec *ProcMeterTextWidget; /* The resource names */ #define XtNtext "text" #define XtNtextFont "textFont" /* Public functions */ void ProcMeterTextChangeData(Widget pmw,char *data); #endif /* PMTEXT_H */ procmeter3-3.5d/xaw/widgets/PMTextP.h000066400000000000000000000042531165060751200175360ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMTextP.h,v 1.1 1998-09-19 15:29:36 amb Exp $ ProcMeter Text Widget Private header file (for ProcMeter 3.0). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1996,98 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef PMTEXTP_H #define PMTEXTP_H /*+ To stop multiple inclusions. +*/ #include "PMText.h" /*+ The Class Part of the Widget, shared among all instances of the ProcMeter Text Widget. +*/ typedef struct _ProcMeterTextClassPart { int unused; /*+ Not used. +*/ } ProcMeterTextClassPart; /*+ The complete Class Record for the ProcMeter Text Widget, includes the Core Widget Class Part. +*/ typedef struct _ProcMeterTextClassRec { CoreClassPart core_class; /*+ The Core Widget Class Part. +*/ ProcMeterGenericClassPart procmeter_generic_class; /*+ The ProcMeter Generic Widget Class Part. +*/ ProcMeterTextClassPart procmeter_text_class; /*+ The ProcMeter Text Widget Class Part. +*/ } ProcMeterTextClassRec; /*+ The actual Class Record for the ProcMeter Text Widget. +*/ extern ProcMeterTextClassRec procMeterTextClassRec; /*+ The ProcMeter Text Widget Part that is used in each of the ProcMeter Text Widgets. +*/ typedef struct _ProcMeterPart { char* text_string; /*+ The text for the Widget (Set & Get via Xt). +*/ XFontStruct* text_font; /*+ The font for the text (Set & Get via Xt). +*/ Dimension text_x,text_y; /*+ The position of the text. +*/ } ProcMeterTextPart; /*+ The complete Widget Record that is used per ProcMeter Text Widget. +*/ typedef struct _ProcMeterTextRec { CorePart core; /*+ The Core Widget Part. +*/ ProcMeterGenericPart procmeter_generic; /*+ The ProcMeter Generic Widget Part. +*/ ProcMeterTextPart procmeter_text; /*+ The ProcMeter Text Widget Part. +*/ } ProcMeterTextRec; #endif /* PMTEXTP_H */ procmeter3-3.5d/xaw/widgets/SubMenus.c000066400000000000000000000133521165060751200177710ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/widgets/SubMenus.c,v 1.3 1999-09-29 16:37:30 amb Exp $ ProcMeter Extensions for Athena SubMenus (for ProcMeter 3.2). ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include #include #include #include #include "SubMenus.h" /*+ A structure to contain the menu and sub-menu relationship information. +*/ typedef struct SubMenu { Widget item; /*+ The menu item that drops the sub-menu down. +*/ Widget submenu; /*+ The drop down sub-menu. +*/ int depth; /*+ The depth of this menu in the visible submenus. +*/ } SubMenu; /*+ The klist of menu items and submenus. +*/ static SubMenu *submenus=NULL; /*+ The number of submenus. +*/ static int nsubmenus=0; /* The local functions */ static void SubMenuEvent(Widget w,XEvent *event,String *params,Cardinal *num_params); /*+ The actions we need to add for the menu item. +*/ static XtActionsRec SubMenuActions[]={{"SubMenuEvent",SubMenuEvent}}; /*++++++++++++++++++++++++++++++++++++++ Initialise the submenu actions. XtAppContext app_context ++++++++++++++++++++++++++++++++++++++*/ void InitialiseSubMenus(XtAppContext app_context) { /* Add the application actions. */ XtAppAddActions(app_context,SubMenuActions,sizeof(SubMenuActions)/sizeof(SubMenuActions[0])); } /*++++++++++++++++++++++++++++++++++++++ Adds a menu item and a submenu to the list. Widget item The menu item to add. Widget submenu The submenu to add. ++++++++++++++++++++++++++++++++++++++*/ void AddSubMenu(Widget item,Widget submenu) { /* Add the item and menu to the list. */ if(nsubmenus==0) submenus=(SubMenu*)malloc(8*sizeof(SubMenu)); else if((nsubmenus%8)==7) submenus=(SubMenu*)realloc((void*)submenus,(8+nsubmenus+1)*sizeof(SubMenu)); submenus[nsubmenus].item=item; submenus[nsubmenus].submenu=submenu; submenus[nsubmenus].depth=0; nsubmenus++; XtOverrideTranslations(XtParent(item), XtParseTranslationTable(": highlight() SubMenuEvent()\n" ": MenuPopdown() notify() unhighlight() SubMenuEvent()\n")); } /*++++++++++++++++++++++++++++++++++++++ Do something with the sub-menus when there is an interesting button event. Widget w The widget that caused the event. XEvent *event The event that caused the callback. String *params The parameters from the callback. Cardinal *num_params The number of parameters. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void SubMenuEvent(Widget w,XEvent *event,String *params,Cardinal *num_params) { static Widget lastitem=NULL; int i,depth=0; Widget item,submenu=NULL; Position root_x,root_y; Position item_y; Dimension item_width,submenu_width,submenu_height; item=XawSimpleMenuGetActiveEntry(w); for(i=0;idepth) { submenus[i].depth=0; XtPopdown(submenus[i].submenu); } lastitem=item; if(!submenu) return; for(i=0;ixbutton.y,&root_x,&root_y); root_y-=event->xbutton.y-item_y; if((DisplayHeight(XtDisplay(w),DefaultScreen(XtDisplay(w)))-submenu_height-2)xbutton.x,event->xbutton.y,&root_x,&root_y); root_y-=5; if((DisplayHeight(XtDisplay(w),DefaultScreen(XtDisplay(w)))-height-2) #include #include #include #include #include #include #include #include #include #include "widgets/PMGeneric.h" #include "widgets/PMGraph.h" #include "widgets/PMText.h" #include "widgets/PMBar.h" #include "procmeter.h" #include "procmeterp.h" #include "window.h" #define MINHEIGHT 30 #define MINWIDTH 60 static void SleepCallback(XtPointer p,XtIntervalId i); static void ResizePaneCallback(Widget w,XtPointer va,XEvent* e,Boolean* vb); static void CloseCallback(Widget w,XtPointer va,XEvent* e,Boolean* vb); static void add_EWMH(char *name); /*+ The application context. +*/ XtAppContext app_context; /*+ The display that the meter is on. +*/ Display* display=NULL; /*+ The toplevel widget. +*/ Widget toplevel; /*+ The pane that contains all of the outputs. +*/ Widget pane; /*+ If the meters are aligned vertically. +*/ int vertical=1; /*+ A flag that is set to true when we are told to quit. +*/ extern int quit; /*+ Set to true when we are sleeping waiting for a timeout. +*/ static int sleeping; /*+ A list of the outputs that are currently visible. +*/ static Output *displayed=NULL; static int ndisplayed=0; /*+ A flag to indicate that we are still initialising and not to resize. +*/ static int initialising=1; /*++++++++++++++++++++++++++++++++++++++ Start the X-Windows & Athena part. int *argc The number of command line arguments. char **argv The actual command line arguments. ++++++++++++++++++++++++++++++++++++++*/ void Start(int *argc,char **argv) { Atom close_atom; static char procmeter_version[]="ProcMeter V" PROCMETER_VERSION; char *string; int i,j=0; if((string=GetProcMeterRC("resources","horizontal")) && StringToBoolean(string)) vertical=0; /* Initialise the display */ toplevel=XtVaAppInitialize(&app_context,"ProcMeter3", NULL,(Cardinal)0,argc,argv,NULL, XtNtitle,procmeter_version, XtNiconName,procmeter_version, NULL); display=XtDisplay(toplevel); /* Create the bitmaps */ CreateBitmaps(toplevel); /* Create the menu widgets */ CreateMenus(toplevel); /* Create the pane widget */ pane=XtVaCreateManagedWidget("pane",panedWidgetClass,toplevel, XtNwidth, vertical?100:200, XtNheight,vertical?200:100, XtNinternalBorderWidth,2, XtNorientation,vertical?XtorientVertical:XtorientHorizontal, NULL); if((string=GetProcMeterRC("resources","background"))) XtVaSetValues(pane,XtNbackground,StringToPixel(string),NULL); XtAddEventHandler(pane,StructureNotifyMask,False,(XtEventHandler)ResizePaneCallback,NULL); AddMenuToOutput(pane,NULL); /* Show the widgets */ XtRealizeWidget(toplevel); XFlush(display); /* Parse the -w flag */ for(i=1;i<*argc;i++) if((!strcmp(argv[i],"-w")) && (i+1<=*argc)) { char *token; i++;j+=2; token=strtok(argv[i],","); while(token) { if(!strcmp(token,"above")) add_EWMH("_NET_WM_STATE_ABOVE"); else if(!strcmp(token,"below")) add_EWMH("_NET_WM_STATE_BELOW"); else if(!strcmp(token,"skip_taskbar")) add_EWMH("_NET_WM_STATE_SKIP_TASKBAR"); else if(!strcmp(token,"skip_pager")) add_EWMH("_NET_WM_STATE_SKIP_PAGER"); else if(!strcmp(token,"sticky")) add_EWMH("_NET_WM_STATE_STICKY"); else fprintf(stderr,"ProcMeter: Cannot parse -w option: '%s'\n",token); token = strtok(NULL,","); } } if(j>0) { for(i=j;i<*argc;i++) argv[i-j]=argv[i]; *argc-=j; } /* Put an action on the close button */ close_atom=XInternAtom(display,"WM_DELETE_WINDOW",False); XSetWMProtocols(display,XtWindow(toplevel),&close_atom,1); XtAddEventHandler(toplevel,0,True,CloseCallback,NULL); } /*++++++++++++++++++++++++++++++++++++++ Stop the X-Windows & Athena part. ++++++++++++++++++++++++++++++++++++++*/ void Stop(void) { DestroyMenus(); XCloseDisplay(display); } /*++++++++++++++++++++++++++++++++++++++ Sleep for the specified interval in seconds. time_t until The time to sleep until. ++++++++++++++++++++++++++++++++++++++*/ void Sleep(time_t until) { struct timeval now; int delay; /* Before we sleep the first time, resize the window. */ if(initialising) { Resize(); initialising=0; } /* Sleep */ gettimeofday(&now,NULL); delay=1000*(until-now.tv_sec)-now.tv_usec/1000; if(delay>0) { XtIntervalId id=XtAppAddTimeOut(app_context,(unsigned)delay,(XtTimerCallbackProc)SleepCallback,NULL); sleeping=1; while(sleeping) { struct timeval now2; XtAppProcessEvent(app_context,XtIMAll); gettimeofday(&now2,NULL); if(now2.tv_secoutput_widget) { int i,found=0; XtDestroyWidget(output->output_widget); XtVaSetValues(output->menu_item_widget,XtNleftBitmap,None,NULL); output->output_widget=NULL; for(i=0;ioutputs;*outputp;outputp++) if(output==*outputp) { module=*modulep; break; } if(module) break; } /* Resources */ if(((string=GetProcMeterRC2(module->module->name,output->output->name,"foreground")) || (string=GetProcMeterRC(module->module->name,"foreground")) || (string=GetProcMeterRC("resources","foreground")))) {XtSetArg(args[nargs],XtNforeground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"background")) || (string=GetProcMeterRC(module->module->name,"background")) || (string=GetProcMeterRC("resources","background")))) {XtSetArg(args[nargs],XtNbackground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-font")) || (string=GetProcMeterRC(module->module->name,"label-font")) || (string=GetProcMeterRC("resources","label-font")))) {XtSetArg(args[nargs],XtNlabelFont,StringToFont(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-foreground")) || (string=GetProcMeterRC(module->module->name,"label-foreground")) || (string=GetProcMeterRC("resources","label-foreground")) || (string=GetProcMeterRC2(module->module->name,output->output->name,"foreground")) || (string=GetProcMeterRC(module->module->name,"foreground")) || (string=GetProcMeterRC("resources","foreground")))) {XtSetArg(args[nargs],XtNlabelForeground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"label-position")) || (string=GetProcMeterRC(module->module->name,"label-position")) || (string=GetProcMeterRC("resources","label-position")))) {XtSetArg(args[nargs],XtNlabelPosition,StringToLabelPosition(string));nargs++;} if(output->type==PROCMETER_GRAPH) { if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-foreground")) || (string=GetProcMeterRC(module->module->name,"grid-foreground")) || (string=GetProcMeterRC("resources","grid-foreground")))) {XtSetArg(args[nargs],XtNgridForeground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"graph-solid")) || (string=GetProcMeterRC(module->module->name,"graph-solid")) || (string=GetProcMeterRC("resources","graph-solid")))) {XtSetArg(args[nargs],XtNsolid,StringToBoolean(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) {XtSetArg(args[nargs],XtNgridMin,StringToInt(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-max")) || (string=GetProcMeterRC(module->module->name,"grid-max")) || (string=GetProcMeterRC("resources","grid-max")))) {XtSetArg(args[nargs],XtNgridMax,StringToInt(string));nargs++;} if(vertical) {XtSetArg(args[nargs],XtNmin,MINHEIGHT);nargs++;} else {XtSetArg(args[nargs],XtNmin,MINWIDTH);nargs++;} XtSetArg(args[nargs],XtNlabel,output->label);nargs++; sprintf(str,output->output->graph_units,output->output->graph_scale); XtSetArg(args[nargs],XtNgridUnits,str);nargs++; XtSetArg(args[nargs],XtNallowResize,True);nargs++; XtSetArg(args[nargs],XtNshowGrip,False);nargs++; w=XtCreateManagedWidget(output->output->name,procMeterGraphWidgetClass,pane, args,nargs); } else if(output->type==PROCMETER_TEXT) { if(((string=GetProcMeterRC2(module->module->name,output->output->name,"text-font")) || (string=GetProcMeterRC(module->module->name,"text-font")) || (string=GetProcMeterRC("resources","text-font")))) {XtSetArg(args[nargs],XtNtextFont,StringToFont(string));nargs++;} XtSetArg(args[nargs],XtNlabel,output->label);nargs++; XtSetArg(args[nargs],XtNallowResize,True);nargs++; XtSetArg(args[nargs],XtNskipAdjust,True);nargs++; XtSetArg(args[nargs],XtNshowGrip,False);nargs++; w=XtCreateManagedWidget(output->output->name,procMeterTextWidgetClass,pane, args,nargs); } else if(output->type==PROCMETER_BAR) { if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-foreground")) || (string=GetProcMeterRC(module->module->name,"grid-foreground")) || (string=GetProcMeterRC("resources","grid-foreground")))) {XtSetArg(args[nargs],XtNgridForeground,StringToPixel(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-min")) || (string=GetProcMeterRC(module->module->name,"grid-min")) || (string=GetProcMeterRC("resources","grid-min")))) {XtSetArg(args[nargs],XtNgridMin,StringToInt(string));nargs++;} if(((string=GetProcMeterRC2(module->module->name,output->output->name,"grid-max")) || (string=GetProcMeterRC(module->module->name,"grid-max")) || (string=GetProcMeterRC("resources","grid-max")))) {XtSetArg(args[nargs],XtNgridMax,StringToInt(string));nargs++;} XtSetArg(args[nargs],XtNmin,MINHEIGHT);nargs++; XtSetArg(args[nargs],XtNlabel,output->label);nargs++; sprintf(str,output->output->graph_units,output->output->graph_scale); XtSetArg(args[nargs],XtNgridUnits,str);nargs++; XtSetArg(args[nargs],XtNallowResize,True);nargs++; XtSetArg(args[nargs],XtNshowGrip,False);nargs++; w=XtCreateManagedWidget(output->output->name,procMeterBarWidgetClass,pane, args,nargs); } AddMenuToOutput(w,module); XtVaSetValues(output->menu_item_widget,XtNleftBitmap,CircleBitmap,NULL); output->output_widget=w; output->first=2; displayed=(Output*)realloc((void*)displayed,sizeof(Output)*(ndisplayed+1)); displayed[ndisplayed]=output; ndisplayed++; } XawPanedSetRefigureMode(pane,True); Resize(); } /*++++++++++++++++++++++++++++++++++++++ Update a graph output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateGraph(Output output,short value) { ProcMeterGraphAddDatum(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Update a text output. Output output The output to update. char *value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateText(Output output,char *value) { ProcMeterTextChangeData(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Update a bar output. Output output The output to update. short value The new value. ++++++++++++++++++++++++++++++++++++++*/ void UpdateBar(Output output,short value) { ProcMeterBarAddDatum(output->output_widget,value); } /*++++++++++++++++++++++++++++++++++++++ Move an output. Output output1 The output to be moved. Output output2 The one that the output is to be moved above or below. int direction The direction to move the output (up=1 or down=2). ++++++++++++++++++++++++++++++++++++++*/ void MoveOutput(Output output1,Output output2,int direction) { int i,i1=-1,i2=-1; for(i=0;ioutput_widget); for(i=i2;ioutput_widget); if(direction==2) continue; } if(i!=i1) { XtUnmanageChild(displayed[i]->output_widget); XtManageChild(displayed[i]->output_widget); } } XawPanedSetRefigureMode(pane,True); Resize(); if(direction==1 && i2>i1) { for(i=i1;ii2) { for(i=i1;i>i2;i--) displayed[i]=displayed[i-1]; displayed[i2]=output1; } else if(direction==2 && i2>i1) { for(i=i1;ii2) */ { for(i=i1;i>i2;i--) displayed[i]=displayed[i-1]; displayed[i2+1]=output1; } } /*++++++++++++++++++++++++++++++++++++++ Resize the pane. ++++++++++++++++++++++++++++++++++++++*/ void Resize(void) { Dimension psize,size; int gsize,msize; int i,ngraphs=0; if(initialising) return; if(!ndisplayed) return; XtVaGetValues(pane,vertical?XtNheight:XtNwidth,&psize,NULL); msize=0; gsize=psize; for(i=0;ioutput_widget,&min_size,&max_size); if(displayed[i]->type==PROCMETER_GRAPH) ngraphs++; else if(displayed[i]->type==PROCMETER_TEXT) gsize-=min_size; else if(displayed[i]->type==PROCMETER_BAR) ngraphs++; msize+=min_size; if(i) msize+=2,gsize-=2; /* separator between panes */ } if(msize>psize || (ngraphs==0 && msize!=psize)) { XtVaSetValues(XtParent(pane),vertical?XtNheight:XtNwidth,msize,NULL); return; } for(i=0;itype==PROCMETER_GRAPH || displayed[i]->type==PROCMETER_BAR) { size=gsize/ngraphs; gsize-=size; ngraphs--; } else { continue; } XtVaSetValues(displayed[i]->output_widget,vertical?XtNheight:XtNwidth,size,NULL); } } /*++++++++++++++++++++++++++++++++++++++ The function called by the timeout to terminate the sleep. XtPointer p Not used. XtIntervalId i Not used. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void SleepCallback(XtPointer p,XtIntervalId i) { sleeping=0; } /*++++++++++++++++++++++++++++++++++++++ A callback that is activated by a resize event on the parent pane. Widget w The widget that caused the callback. XtPointer va Not used. XEvent* e The event that requires action. Boolean* vb Not used. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void ResizePaneCallback(Widget w,XtPointer va,XEvent* e,Boolean* vb) { Resize(); } /*++++++++++++++++++++++++++++++++++++++ A callback that is activated by a close window event on the toplevel window. Widget w The widget that caused the callback. XtPointer va Not used. XEvent* e The event that requires action. Boolean* vb Not used. This function is only ever called from the Xt Intrinsics routines. ++++++++++++++++++++++++++++++++++++++*/ static void CloseCallback(Widget w,XtPointer va,XEvent* e,Boolean* vb) { XClientMessageEvent *cev=(XClientMessageEvent*)e; Atom atom_type=XInternAtom(display,"WM_PROTOCOLS",False); if(atom_type==cev->message_type) { Atom atom_proto=XInternAtom(display,"WM_DELETE_WINDOW",False); if(cev->format==32 && atom_proto==(Atom)cev->data.l[0]) quit=1; } } /*++++++++++++++++++++++++++++++++++++++ Adds an Extended Window Manager Hint to the window. char *name The name of the hint to add. ++++++++++++++++++++++++++++++++++++++*/ static void add_EWMH(char *name) { XEvent event; event.xclient.type=ClientMessage; event.xclient.serial=0; event.xclient.send_event=True; event.xclient.message_type=XInternAtom(display,"_NET_WM_STATE",False); event.xclient.window=XtWindow(toplevel); event.xclient.format=32; event.xclient.data.l[0]=1; /* add */ event.xclient.data.l[1]=XInternAtom(display,name,False); event.xclient.data.l[2]=0; event.xclient.data.l[3]=0; event.xclient.data.l[4]=0; XSendEvent(display,DefaultRootWindow(display),False,SubstructureRedirectMask|SubstructureNotifyMask,&event); } procmeter3-3.5d/xaw/window.h000066400000000000000000000025401165060751200160730ustar00rootroot00000000000000/*************************************** $Header: /home/amb/CVS/procmeter3/xaw/window.h,v 1.5 2002-06-04 12:52:32 amb Exp $ ProcMeter - A system monitoring program for Linux - Version 3.3b. Global X windows header file. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1998,99,2000 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #ifndef XWINDOW_H #define XWINDOW_H /*+ To stop multiple inclusions. +*/ #include "procmeterp.h" /* In window.c */ extern Display *display; extern XtAppContext app_context; void MoveOutput(Output output1,Output output2,int direction); void Resize(void); /* In menus.c */ void CreateMenus(Widget parent); void DestroyMenus(void); void AddMenuToOutput(Widget widget,Module module); /* In resources.c */ XFontStruct *StringToFont(char *string); Pixel StringToPixel(char *string); Boolean StringToBoolean(char *string); int StringToInt(char *string); int StringToLabelPosition(char *string); /* In bitmap.c */ extern Pixmap CircleBitmap; extern Pixmap TextBitmap; extern Pixmap GraphBitmap; extern Pixmap BarBitmap; void CreateBitmaps(Widget w); #endif /* XWINDOW_H */