├── .gitignore ├── AUTHORS ├── COPYING ├── Makefile.am ├── README.md ├── autogen.sh ├── configure.ac ├── debian ├── changelog ├── compat ├── control ├── multiload-nandhp-common.install ├── multiload-nandhp-xfce4.install └── rules ├── generate-about-data-header.pl ├── lxpanel ├── Makefile.am └── lxpanel-multiload-plugin.c ├── multiload ├── Makefile.am ├── autoscaler.c ├── autoscaler.h ├── linux-proc.c ├── linux-proc.h ├── load-graph.c ├── load-graph.h ├── multiload.c ├── multiload.h ├── netspeed.c ├── netspeed.h ├── properties.c └── properties.h ├── po ├── POTFILES.in ├── POTFILES.skip └── cs.po └── xfce4 ├── Makefile.am ├── multiload.desktop.in.in ├── xfce4-multiload-dialogs.c ├── xfce4-multiload-dialogs.h ├── xfce4-multiload-plugin.c ├── xfce4-multiload-plugin.h ├── xfce4-multiload-settings.c └── xfce4-multiload-settings.h /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.gmo 3 | *.la 4 | *.lo 5 | *.swp 6 | *.tar.* 7 | .deps 8 | .libs 9 | ChangeLog 10 | INSTALL 11 | Makefile 12 | Makefile.in 13 | aclocal.m4 14 | autom4te.cache 15 | configure 16 | config.* 17 | build-aux 18 | intltool* 19 | libtool 20 | xfce4/*.desktop 21 | xfce4/*.desktop.in 22 | po/.intltool-merge-cache 23 | po/Makefile.in.in 24 | po/POTFILES 25 | stamp-* 26 | *-stamp 27 | about-data.h 28 | old 29 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | nandhp 2 | Martin Baulig 3 | Todd Kulesza 4 | Benoît Dejean 5 | Davyd Madeley 6 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | if HAVE_XFCE4 2 | XFCE4_DIRS = xfce4 3 | endif 4 | if HAVE_LXPANEL 5 | LXPANEL_DIRS = lxpanel 6 | endif 7 | SUBDIRS = \ 8 | multiload \ 9 | $(XFCE4_DIRS) \ 10 | $(LXPANEL_DIRS) \ 11 | po 12 | 13 | distclean-local: 14 | rm -rf *.cache *~ 15 | 16 | rpm: dist 17 | rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz 18 | @rm -f $(PACKAGE)-$(VERSION).tar.gz 19 | 20 | .PHONY: ChangeLog 21 | 22 | ChangeLog: Makefile 23 | (GIT_DIR=$(top_srcdir)/.git git log > .changelog.tmp \ 24 | && mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) \ 25 | || (touch ChangeLog; echo 'Git directory not found: installing possibly empty changelog.' >&2) 26 | 27 | dist-hook: ChangeLog 28 | 29 | BUILT_SOURCES = \ 30 | about-data.h 31 | 32 | about-data.h: AUTHORS 33 | perl $(top_srcdir)/generate-about-data-header.pl \ 34 | < $(top_srcdir)/AUTHORS > about-data.h 35 | 36 | EXTRA_DIST = \ 37 | intltool-extract.in \ 38 | intltool-merge.in \ 39 | intltool-update.in \ 40 | AUTHORS COPYING ChangeLog README.md 41 | 42 | DISTCLEANFILES = \ 43 | intltool-extract \ 44 | intltool-merge \ 45 | intltool-update 46 | 47 | # vi:set ts=8 sw=8 noet ai nocindent syntax=automake: 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | multiload-nandhp 2 | ================ 3 | 4 | multiload-nandhp is a port of the GNOME multiload applet to the Xfce4 and LXDE 5 | panels. 6 | 7 | It supports Xfce 4.6 and lxpanel 0.5.5 and above. 8 | 9 | System Requirements 10 | ------------------- 11 | 12 | - GTK+ >= 2.14.0 13 | - Cairo 14 | - LibGTop >= 2.11.92 15 | 16 | For the Xfce panel plugin: 17 | 18 | - libxfce4panel >= 4.6.0 19 | - libxfce4util >= 4.6.0 20 | - libxfce4ui-1 OR libxfcegui4 >= 4.8.0 21 | 22 | For the lxpanel plugin: 23 | 24 | - lxpanel < 0.7 25 | - libmenu-cache (Required by lxpanel) 26 | 27 | lxpanel 0.7 introduces a backwards-incompatible API change; the 28 | multiload-nandhp lxpanel plugin will need to be rewritten to support 29 | newer versions of lxpanel. 30 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Doesn't work with intltoolize 4 | # autoreconf --force --install || exit 1 5 | 6 | set -x 7 | 8 | aclocal || exit 1 9 | autoheader --force || exit 1 10 | libtoolize --copy --automake --force || exit 1 11 | intltoolize --copy --automake --force || exit 1 12 | automake --add-missing --copy --include-deps || exit 1 13 | autoconf || exit 1 14 | autoheader || exit 1 15 | 16 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.60) 2 | AC_INIT([multiload-nandhp], [0.3], [nandhp@gmail.com]) 3 | AC_CONFIG_AUX_DIR([build-aux]) 4 | AM_INIT_AUTOMAKE([1.11 -Wall -Werror no-dist-gzip dist-xz silent-rules foreign]) 5 | AM_SILENT_RULES([yes]) 6 | # AM_CONFIG_HEADER([config.h]) 7 | AM_MAINTAINER_MODE() 8 | 9 | AM_PROG_AR() 10 | 11 | LT_PREREQ([2.2.6]) 12 | LT_INIT([disable-static]) 13 | 14 | AC_PROG_CC() 15 | # Compiling sources with per-target flags requires AM_PROG_CC_C_O 16 | AM_PROG_CC_C_O() 17 | AC_PROG_LD() 18 | AC_PROG_INSTALL() 19 | AC_PROG_LIBTOOL() 20 | AC_PROG_INTLTOOL(, [no-xml]) 21 | 22 | # Environment checks from autoscan 23 | # AC_HEADER_STDC() 24 | # AC_CHECK_HEADERS([stdlib.h unistd.h locale.h stdio.h errno.h time.h string.h \ 25 | # math.h sys/types.h sys/wait.h memory.h signal.h sys/prctl.h \ 26 | # libintl.h]) 27 | # AC_CHECK_FUNCS([bind_textdomain_codeset]) 28 | AC_CHECK_HEADERS([fcntl.h libintl.h string.h unistd.h]) 29 | AC_CHECK_FUNCS([memset rint strchr]) 30 | AC_TYPE_SIZE_T() 31 | 32 | # Misc checks 33 | AC_MSG_CHECKING(whether compiler understands -Wall) 34 | old_CFLAGS="$CFLAGS" 35 | CFLAGS="$CFLAGS -Wall" 36 | AC_TRY_COMPILE([],[], 37 | AC_MSG_RESULT(yes), 38 | AC_MSG_RESULT(no) 39 | CFLAGS="$old_CFLAGS") 40 | 41 | # I18n 42 | rm -f $srcdir/po/LINGUAS 43 | for po_file in `ls $srcdir/po/*.po | sort`; 44 | do 45 | lang=`echo "$po_file" | sed "s|.*/po/\(.*\)\.po|\1|g"` 46 | echo $lang >> $srcdir/po/LINGUAS 47 | done 48 | 49 | # Set up gettext 50 | GETTEXT_PACKAGE=multiload-nandhp 51 | #AM_GNU_GETTEXT([external]) 52 | AC_SUBST(GETTEXT_PACKAGE) 53 | AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.]) 54 | 55 | AM_GLIB_GNU_GETTEXT 56 | 57 | # Dependencies 58 | AM_PATH_GTK_2_0([2.14.0],,AC_MSG_ERROR([Gtk+ 2.14.0 or higher required.])) 59 | PKG_CHECK_MODULES(CAIRO, [cairo]) 60 | AC_SUBST(CAIRO_CFLAGS) 61 | AC_SUBST(CAIRO_LIBS) 62 | PKG_CHECK_MODULES(LIBGTOP, [libgtop-2.0 >= 2.11.92]) 63 | AC_SUBST(LIBGTOP_CFLAGS) 64 | AC_SUBST(LIBGTOP_LIBS) 65 | 66 | # Xfce 67 | AC_ARG_WITH([xfce4], AS_HELP_STRING([--with-xfce4], [Build plugin for xfce4-panel]), 68 | [], [with_xfce4=check]) 69 | AS_IF([test "x$with_xfce4" != "xno"], [ 70 | pkg_modules="libxfce4util-1.0 >= 4.6.0 71 | libxfce4panel-1.0 >= 4.6.0" 72 | PKG_CHECK_MODULES(XFCE4, [$pkg_modules], [ 73 | AC_DEFINE([HAVE_XFCE4], [1], [Support for xfce4-panel]) 74 | with_xfce4=yes 75 | # Check if we have libxfce4ui or libxfcegui4 76 | PKG_CHECK_MODULES([XFCE4UI], [libxfce4ui-1 >= 4.8.0], 77 | [ 78 | AC_DEFINE([HAVE_XFCE4UI], [1], [Have libxfce4ui]) 79 | xfce_is_4_6=no 80 | ],[ 81 | PKG_CHECK_MODULES([XFCEGUI4], [libxfcegui4-1.0 >= 4.6.0], 82 | [AC_DEFINE([HAVE_XFCEGUI4], [1], [Have libxfcegui4])]) 83 | xfce_is_4_6=yes 84 | ]) 85 | ],[ 86 | if test "x$with_xfce4" != xcheck; then 87 | AC_MSG_FAILURE( 88 | [--with-xfce4 was given, but test failed]) 89 | fi 90 | with_xfce4=no 91 | ]) 92 | ]) 93 | AM_CONDITIONAL([HAVE_XFCE4], [test x$with_xfce4 = xyes]) 94 | AM_CONDITIONAL([XFCE_IS_4_6], [test x$xfce_is_4_6 = xyes]) 95 | AC_SUBST(XFCE4_CFLAGS) 96 | AC_SUBST(XFCE4_LIBS) 97 | AC_SUBST(XFCE4UI_CFLAGS) 98 | AC_SUBST(XFCE4UI_LIBS) 99 | AC_SUBST(XFCEGUI4_CFLAGS) 100 | AC_SUBST(XFCEGUI4_LIBS) 101 | 102 | # lxpanel (Disabled by default due to API change in lxpanel 0.7) 103 | AC_ARG_WITH([lxpanel], AS_HELP_STRING([--with-lxpanel], [Build plugin for lxpanel]), 104 | [], [with_lxpanel=no]) 105 | AS_IF([test "x$with_lxpanel" != "xno"], [ 106 | pkg_modules="lxpanel" 107 | # libmenu-cache is implicitly required; we will fail if it's not present. 108 | PKG_CHECK_MODULES(LXPANEL, [$pkg_modules], 109 | [ 110 | AC_DEFINE([HAVE_LXPANEL], [1], [Support for lxpanel]) 111 | with_lxpanel=yes 112 | ],[ 113 | if test "x$with_lxpanel" != xcheck; then 114 | AC_MSG_FAILURE( 115 | [--with-lxpanel was given, but test failed]) 116 | fi 117 | with_lxpanel=no 118 | ]) 119 | ]) 120 | AM_CONDITIONAL(HAVE_LXPANEL, test x$with_lxpanel = xyes) 121 | AC_SUBST(LXPANEL_CFLAGS) 122 | AC_SUBST(LXPANEL_LIBS) 123 | 124 | if test x$with_xfce4 != xyes && test x$with_lxpanel != xyes; then 125 | AC_MSG_FAILURE([No supported panels are installed and available.]) 126 | fi 127 | 128 | # Directories; for substitution into .desktop files. 129 | # From https://mail.gnome.org/archives/commits-list/2012-March/msg14085.html 130 | # Of course it's worth noting that the patch in that message was to replace 131 | # this nasty hack with an awk version that runs from the Makefile... 132 | if test "${prefix}" = "NONE"; then 133 | prefix=/usr/local 134 | fi 135 | if test "${exec_prefix}" = "NONE"; then 136 | exec_prefix=$prefix 137 | fi 138 | eval LIBDIR="$libdir" 139 | AC_SUBST([LIBDIR]) 140 | 141 | # Output files 142 | AC_CONFIG_HEADERS([config.h]) 143 | AC_CONFIG_FILES([ 144 | Makefile 145 | multiload/Makefile 146 | xfce4/Makefile 147 | xfce4/multiload.desktop.in 148 | lxpanel/Makefile 149 | po/Makefile.in 150 | ]) 151 | AC_OUTPUT 152 | 153 | echo 154 | echo "Build Configuration:" 155 | echo 156 | echo "* xfce4-panel : $with_xfce4" 157 | echo 158 | echo "* lxpanel : $with_lxpanel" 159 | echo 160 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | multiload-nandhp (0.3-nandhp0) unstable; urgency=low 2 | 3 | * New upstream release 4 | * Do not build lxpanel plugin by default due to API change 5 | 6 | -- nandhp Fri, 3 Jul 2015 20:16:20 -0600 7 | 8 | multiload-nandhp (0.2-nandhp0) unstable; urgency=low 9 | 10 | * New upstream release 11 | 12 | -- nandhp Thu, 23 Jan 2014 19:54:08 -0600 13 | 14 | multiload-nandhp (0.1-nandhp0) unstable; urgency=low 15 | 16 | * New upstream release 17 | 18 | -- nandhp Tue, 26 Jun 2012 00:00:00 -0400 19 | 20 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: multiload-nandhp 2 | Section: x11 3 | Priority: optional 4 | Maintainer: nandhp 5 | Build-Depends: debhelper (>= 7), libgtop-dev (>= 2.11.92), 6 | xfce4-panel-dev (>= 4.6.0), lxpanel, libmenu-cache-dev 7 | Homepage: https://github.com/nandhp/multiload-nandhp 8 | Vcs-Browser: https://github.com/nandhp/multiload-nandhp 9 | Vcs-Git: git://github.com/nandhp/multiload-nandhp.git 10 | 11 | Package: multiload-nandhp-xfce4 12 | Architecture: any 13 | Essential: no 14 | Depends: ${shlibs:Depends}, ${misc:Depends}, 15 | multiload-nandhp-common (=${binary:Version}) 16 | Recommends: xfce4-panel 17 | Enhances: xfce4-panel 18 | Description: system load monitor for the Xfce panel 19 | A system load monitor that graphs processor, memory, 20 | and swap space use, plus network and disk activity. 21 | . 22 | It is a port of the GNOME multiload applet to the Xfce panel. 23 | 24 | Package: multiload-nandhp-common 25 | Architecture: all 26 | Essential: no 27 | Depends: ${shlibs:Depends}, ${misc:Depends} 28 | Recommends: xfce4-panel 29 | Enhances: xfce4-panel 30 | Description: system load monitor for the panel, common files 31 | A system load monitor that graphs processor, memory, 32 | and swap space use, plus network and disk activity. 33 | . 34 | It is a port of the GNOME multiload applet. This package contains 35 | files common to all ports of the panel. 36 | -------------------------------------------------------------------------------- /debian/multiload-nandhp-common.install: -------------------------------------------------------------------------------- 1 | usr/share/locale/*/*/multiload-nandhp.mo 2 | -------------------------------------------------------------------------------- /debian/multiload-nandhp-xfce4.install: -------------------------------------------------------------------------------- 1 | usr/*/xfce4 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # Sample debian/rules that uses debhelper. 3 | # This file is public domain software, originally written by Joey Hess. 4 | # 5 | # This version is for a multibinary package. It also allows you to build any 6 | # of the binary packages independantly, via binary- targets. 7 | 8 | # Uncomment this to turn on verbose mode. 9 | #export DH_VERBOSE=1 10 | 11 | # This has to be exported to make some magic below work. 12 | export DH_OPTIONS 13 | 14 | build: build-stamp 15 | build-stamp: 16 | dh_testdir 17 | 18 | ./configure --prefix=/usr --with-xfce4 19 | $(MAKE) 20 | 21 | touch build-stamp 22 | 23 | clean: 24 | dh_testdir 25 | dh_testroot 26 | rm -f build-stamp 27 | 28 | -$(MAKE) distclean 29 | 30 | dh_clean 31 | 32 | install: DH_OPTIONS= 33 | install: build 34 | dh_testdir 35 | dh_testroot 36 | dh_prep 37 | dh_installdirs 38 | 39 | $(MAKE) prefix=`pwd`/debian/tmp/usr \ 40 | libdir=`pwd`/debian/tmp/usr/lib \ 41 | install 42 | 43 | dh_install --list-missing 44 | 45 | # This single target is used to build all the packages, all at once, or 46 | # one at a time. So keep in mind: any options passed to commands here will 47 | # affect _all_ packages. Anything you want to only affect one package 48 | # should be put in another target, such as the install target. 49 | binary-common: 50 | dh_testdir 51 | dh_testroot 52 | dh_installchangelogs 53 | dh_installdocs 54 | # dh_installexamples 55 | # dh_installmenu 56 | # dh_installdebconf 57 | # dh_installlogrotate 58 | # dh_installemacsen 59 | # dh_installcatalogs 60 | # dh_installpam 61 | # dh_installmime 62 | # dh_installinit 63 | # dh_installman 64 | # dh_installcron 65 | # dh_installinfo 66 | # dh_installwm 67 | # dh_installudev 68 | # dh_lintian 69 | # dh_bugfiles 70 | dh_strip 71 | dh_link 72 | dh_compress 73 | dh_fixperms 74 | # dh_perl 75 | dh_makeshlibs 76 | dh_installdeb 77 | dh_shlibdeps 78 | dh_gencontrol 79 | dh_md5sums 80 | dh_builddeb 81 | 82 | # Build architecture independant packages using the common target. 83 | binary-indep: build install 84 | $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common 85 | 86 | # Build architecture dependant packages using the common target. 87 | binary-arch: build install 88 | $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common 89 | 90 | # Any other binary targets build just one binary package at a time. 91 | binary-%: build install 92 | make -f debian/rules binary-common DH_OPTIONS=-p$* 93 | 94 | binary: binary-indep binary-arch 95 | .PHONY: build clean binary-indep binary-arch binary-common binary install 96 | -------------------------------------------------------------------------------- /generate-about-data-header.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | print "const gchar * const about_data_authors[] = {\n"; 4 | while () { 5 | s/[\r\n]+$//; 6 | print " \"$_\",\n" if $_; 7 | } 8 | print " NULL\n};\n\n"; 9 | 10 | # License data 11 | print "const gchar about_data_license[] =\n"; 12 | while () { 13 | s/[\r\n]+$//; 14 | print " \"$_\\n\"\n"; 15 | } 16 | print ";\n"; 17 | 18 | __END__ 19 | This program is free software; you can redistribute it and/or modify 20 | it under the terms of the GNU General Public License as published by 21 | the Free Software Foundation; either version 2 of the License, or 22 | (at your option) any later version. 23 | 24 | This program is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU General Public License for more details. 28 | 29 | You should have received a copy of the GNU General Public License along 30 | with this program; if not, write to the Free Software Foundation, Inc., 31 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 32 | -------------------------------------------------------------------------------- /lxpanel/Makefile.am: -------------------------------------------------------------------------------- 1 | # INCLUDES = 2 | AM_CPPFLAGS = \ 3 | -I$(top_srcdir) \ 4 | -I$(top_srcdir)/multiload \ 5 | -DG_LOG_DOMAIN=\"lxpanel-multiload-plugin\" \ 6 | -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ 7 | $(PLATFORM_CPPFLAGS) 8 | 9 | # 10 | # multiload plugin 11 | # 12 | plugin_LTLIBRARIES = \ 13 | multiload.la 14 | 15 | plugindir = \ 16 | $(libdir)/lxpanel/plugins 17 | 18 | multiload_la_SOURCES = \ 19 | ../about-data.h \ 20 | lxpanel-multiload-plugin.c 21 | # xfce4-multiload-plugin.h 22 | # xfce4-multiload-dialogs.c xfce4-multiload-dialogs.h 23 | # xfce4-multiload-settings.c xfce4-multiload-settings.h 24 | 25 | multiload_la_CFLAGS = \ 26 | $(GTK_CFLAGS) \ 27 | $(LXPANEL_CFLAGS) 28 | 29 | multiload_la_LDFLAGS = \ 30 | -avoid-version \ 31 | -module \ 32 | -no-undefined \ 33 | $(PLATFORM_LDFLAGS) 34 | 35 | # export-symbols-regex '^multiload_(constructor|destructor|configure|save_configuration|configuration_changed)' 36 | 37 | multiload_la_LIBADD = \ 38 | $(GTK_LIBS) \ 39 | $(LXPANEL_LIBS) \ 40 | ../multiload/multiload-core.la 41 | 42 | # vi:set ts=8 sw=8 noet ai nocindent syntax=automake: 43 | -------------------------------------------------------------------------------- /lxpanel/lxpanel-multiload-plugin.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include 3 | #endif 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "multiload/multiload.h" 16 | #include "multiload/properties.h" 17 | 18 | /* FIXME: DIRTY HACKS! The following lxpanel functions are NOT in 19 | the /usr/include/lxpanel/plugin.h header file! For a usage example, 20 | see lxpanel/src/plugins/launchbar.c 21 | */ 22 | /* Handle-right-click events. Defined in lxpanel/src/panel.h. */ 23 | extern gboolean plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Plugin *plugin); 24 | /* Trigger a save event. Defined only in lxpanel/src/configurator.c! */ 25 | void panel_config_save(Panel * panel); /* defined in */ 26 | 27 | /** BEGIN H **/ 28 | typedef struct _MultiloadLxpanelPlugin MultiloadLxpanelPlugin; 29 | 30 | /* an instance of this struct is what will be assigned to 'priv' */ 31 | struct _MultiloadLxpanelPlugin 32 | { 33 | MultiloadPlugin ma; 34 | GtkWidget *dlg; 35 | }; 36 | /** END H **/ 37 | 38 | static void 39 | multiload_read(char **fp, MultiloadPlugin *ma) 40 | { 41 | guint i, found = 0; 42 | 43 | /* Initial settings */ 44 | ma->speed = 0; 45 | ma->size = 0; 46 | for ( i = 0; i < NGRAPHS; i++ ) 47 | { 48 | /* Default visibility and colors */ 49 | ma->graph_config[i].visible = FALSE; 50 | multiload_colorconfig_default(ma, i); 51 | } 52 | 53 | if ( fp != NULL ) 54 | { 55 | line s; 56 | s.len = 1024; 57 | while ( lxpanel_get_line(fp, &s) != LINE_BLOCK_END ) 58 | { 59 | if ( s.type == LINE_VAR ) 60 | { 61 | if ( g_ascii_strcasecmp(s.t[0], "speed") == 0 ) 62 | ma->speed = atoi(s.t[1]); 63 | else if ( g_ascii_strcasecmp(s.t[0], "size") == 0 ) 64 | ma->size = atoi(s.t[1]); 65 | else 66 | { 67 | const char *suffix; /* Set by multiload_find_graph_by_name */ 68 | int i = multiload_find_graph_by_name(s.t[0], &suffix); 69 | 70 | if ( suffix == NULL || i < 0 || i >= NGRAPHS ) 71 | continue; 72 | else if ( g_ascii_strcasecmp(suffix, "Visible") == 0 ) 73 | ma->graph_config[i].visible = atoi(s.t[1]) ? TRUE : FALSE; 74 | else if ( g_ascii_strcasecmp(suffix, "Colors") == 0 ) 75 | multiload_colorconfig_unstringify(ma, i, s.t[1]); 76 | } 77 | } 78 | else 79 | { 80 | ERR ("Failed to parse config token %s\n", s.str); 81 | break; 82 | } 83 | } 84 | } 85 | 86 | /* Handle errors from atoi */ 87 | if ( ma->speed == 0 ) 88 | ma->speed = DEFAULT_SPEED; 89 | if ( ma->size == 0 ) 90 | ma->size = DEFAULT_SIZE; 91 | /* Ensure at lease one graph is visible */ 92 | for ( i = 0; i < NGRAPHS; i++ ) 93 | if ( ma->graph_config[i].visible == TRUE ) 94 | found++; 95 | if ( found == 0 ) 96 | ma->graph_config[0].visible = TRUE; 97 | } 98 | 99 | static void multiload_save_configuration(Plugin * p, FILE * fp) 100 | { 101 | MultiloadLxpanelPlugin *multiload = p->priv; 102 | MultiloadPlugin *ma = &multiload->ma; 103 | guint i; 104 | 105 | /* Write size and speed */ 106 | lxpanel_put_int (fp, "speed", ma->speed); 107 | lxpanel_put_int (fp, "size", ma->size); 108 | 109 | for ( i = 0; i < NGRAPHS; i++ ) 110 | { 111 | char *key, list[8*MAX_COLORS]; 112 | 113 | /* Visibility */ 114 | key = g_strdup_printf("%sVisible", graph_types[i].name); 115 | lxpanel_put_int (fp, key, ma->graph_config[i].visible); 116 | g_free (key); 117 | 118 | /* Save colors */ 119 | multiload_colorconfig_stringify (ma, i, list); 120 | key = g_strdup_printf("%sColors", graph_types[i].name); 121 | /* Don't use lxpanel_put_str (fp, key, list), in order to avoid a compiler 122 | warning "the address of 'list' will always evaluate as 'true'". 123 | */ 124 | lxpanel_put_line(fp, "%s=%s", key, list); 125 | g_free (key); 126 | } 127 | } 128 | 129 | static void multiload_panel_configuration_changed(Plugin *p) 130 | { 131 | MultiloadLxpanelPlugin *multiload = p->priv; 132 | 133 | /* Determine orientation and size */ 134 | GtkOrientation orientation = 135 | (p->panel->orientation == GTK_ORIENTATION_VERTICAL) ? 136 | GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; 137 | int size = (orientation == GTK_ORIENTATION_VERTICAL) ? 138 | p->panel->width : p->panel->height; 139 | if ( orientation == GTK_ORIENTATION_HORIZONTAL ) 140 | gtk_widget_set_size_request (p->pwid, -1, size); 141 | else 142 | gtk_widget_set_size_request (p->pwid, size, -1); 143 | 144 | /* Refresh the panel applet */ 145 | multiload_refresh(&(multiload->ma), orientation); 146 | } 147 | 148 | static gboolean 149 | multiload_press_event(GtkWidget *pwid, GdkEventButton *event, Plugin *p) 150 | { 151 | /* Standard right-click handling. */ 152 | if (plugin_button_press_event(pwid, event, p)) 153 | return TRUE; 154 | 155 | if (event->button == 1) /* left button */ 156 | { 157 | /* Launch system monitor */ 158 | } 159 | return TRUE; 160 | } 161 | 162 | static int 163 | multiload_constructor(Plugin *p, char **fp) 164 | { 165 | /* allocate our private structure instance */ 166 | MultiloadLxpanelPlugin *multiload = g_new0(MultiloadLxpanelPlugin, 1); 167 | p->priv = multiload; 168 | 169 | /* Initialize multiload */ 170 | multiload_init (); 171 | multiload->dlg = NULL; 172 | 173 | /* read the user settings */ 174 | multiload_read (fp, &multiload->ma); 175 | 176 | /* create a container widget */ 177 | p->pwid = gtk_event_box_new (); 178 | gtk_widget_show (p->pwid); 179 | 180 | /* Initialize the applet */ 181 | multiload->ma.container = GTK_CONTAINER(p->pwid); 182 | /* Set size request and update orientation */ 183 | multiload_panel_configuration_changed(p); 184 | 185 | g_signal_connect(p->pwid, "button-press-event", 186 | G_CALLBACK(multiload_press_event), p); 187 | /* FIXME: No way to add system monitor item to menu? */ 188 | 189 | return 1; 190 | } 191 | 192 | static void 193 | multiload_destructor(Plugin * p) 194 | { 195 | /* find our private structure instance */ 196 | MultiloadLxpanelPlugin *multiload = (MultiloadLxpanelPlugin *)p->priv; 197 | 198 | /* Destroy dialog */ 199 | if ( multiload->dlg ) 200 | { 201 | gtk_widget_destroy (multiload->dlg); 202 | multiload->dlg = NULL; 203 | } 204 | 205 | /* free private data. Panel will free pwid for us. */ 206 | g_free(multiload); 207 | } 208 | 209 | static void 210 | multiload_configure_response (GtkWidget *dialog, 211 | gint response, 212 | MultiloadLxpanelPlugin *multiload) 213 | { 214 | gboolean result; 215 | 216 | if (response == GTK_RESPONSE_HELP) 217 | { 218 | /* show help */ 219 | /* FIXME: Not all common versions of xdg-open support lxde -2012-06-25 */ 220 | result = g_spawn_command_line_async ("xdg-open --launch WebBrowser " 221 | PLUGIN_WEBSITE, NULL); 222 | 223 | if (G_UNLIKELY (result == FALSE)) 224 | g_warning (_("Unable to open the following url: %s"), PLUGIN_WEBSITE); 225 | } 226 | else 227 | { 228 | /* destroy the properties dialog */ 229 | gtk_widget_destroy (multiload->dlg); 230 | multiload->dlg = NULL; 231 | } 232 | } 233 | 234 | /* Lookup the MultiloadPlugin object from the preferences dialog. */ 235 | /* Called from multiload/properties.c */ 236 | MultiloadPlugin * 237 | multiload_configure_get_plugin (GtkWidget *widget) 238 | { 239 | GtkWidget *toplevel = gtk_widget_get_toplevel (widget); 240 | MultiloadPlugin *ma = NULL; 241 | if ( G_LIKELY (gtk_widget_is_toplevel (toplevel)) ) 242 | ma = g_object_get_data(G_OBJECT(toplevel), "MultiloadPlugin"); 243 | else 244 | g_assert_not_reached (); 245 | g_assert( ma != NULL); 246 | return ma; 247 | } 248 | 249 | static void multiload_configure(Plugin * p, GtkWindow * parent) 250 | { 251 | GtkWidget *dialog; 252 | MultiloadLxpanelPlugin *multiload = (MultiloadLxpanelPlugin *)p->priv; 253 | if ( multiload->dlg != NULL ) 254 | { 255 | gtk_widget_show_all (multiload->dlg); 256 | gtk_window_present (GTK_WINDOW (multiload->dlg)); 257 | return; 258 | } 259 | 260 | /* create the dialog */ 261 | multiload->dlg = gtk_dialog_new_with_buttons 262 | (_("Multiload"), 263 | parent, 264 | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, 265 | GTK_STOCK_HELP, GTK_RESPONSE_HELP, 266 | GTK_STOCK_CLOSE, GTK_RESPONSE_OK, 267 | NULL); 268 | dialog = multiload->dlg; 269 | 270 | /* center dialog on the screen */ 271 | gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); 272 | 273 | /* set dialog icon */ 274 | gtk_window_set_icon_name (GTK_WINDOW (dialog), 275 | "utilities-system-monitor"); 276 | 277 | /* link the dialog to the plugin, so we can destroy it when the plugin 278 | * is closed, but the dialog is still open */ 279 | g_object_set_data (G_OBJECT (dialog), 280 | "MultiloadPlugin", &multiload->ma); 281 | 282 | /* Initialize dialog widgets */ 283 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); 284 | gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); 285 | multiload_init_preferences(dialog, &multiload->ma); 286 | 287 | /* connect the reponse signal to the dialog */ 288 | g_signal_connect (G_OBJECT (dialog), "response", 289 | G_CALLBACK(multiload_configure_response), multiload); 290 | 291 | /* Magic incantation from lxpanel/src/plugins/launchbar.c */ 292 | /* Establish a callback when the dialog completes. */ 293 | g_object_weak_ref(G_OBJECT(dialog), (GWeakNotify) panel_config_save, p->panel); 294 | 295 | /* show the entire dialog */ 296 | gtk_widget_show_all (dialog); 297 | } 298 | 299 | /* Plugin descriptor. */ 300 | PluginClass multiload_plugin_class = { 301 | 302 | // this is a #define taking care of the size/version variables 303 | PLUGINCLASS_VERSIONING, 304 | 305 | // type of this plugin 306 | type : "multiload", 307 | name : N_("Multiload"), 308 | version: PACKAGE_VERSION, 309 | description : N_("A system load monitor that graphs processor, memory, " 310 | "and swap space use, plus network and disk activity."), 311 | 312 | // we can have many running at the same time 313 | one_per_system : FALSE, 314 | 315 | // can't expand this plugin 316 | expand_available : FALSE, 317 | 318 | // assigning our functions to provided pointers. 319 | constructor : multiload_constructor, 320 | destructor : multiload_destructor, 321 | config : multiload_configure, 322 | save : multiload_save_configuration, 323 | panel_configuration_changed : multiload_panel_configuration_changed 324 | }; 325 | 326 | -------------------------------------------------------------------------------- /multiload/Makefile.am: -------------------------------------------------------------------------------- 1 | # INCLUDES = 2 | AM_CPPFLAGS = \ 3 | -I$(top_srcdir) \ 4 | -I$(top_srcdir)/multiload \ 5 | -DG_LOG_DOMAIN=\"multiload-core\" \ 6 | -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ 7 | $(PLATFORM_CPPFLAGS) 8 | 9 | # 10 | # multiload plugin 11 | # 12 | noinst_LTLIBRARIES = \ 13 | multiload-core.la 14 | 15 | multiload_core_la_SOURCES = \ 16 | multiload.c multiload.h \ 17 | linux-proc.c linux-proc.h \ 18 | load-graph.c load-graph.h \ 19 | netspeed.c netspeed.h \ 20 | autoscaler.c autoscaler.h \ 21 | properties.c properties.h 22 | 23 | multiload_core_la_CFLAGS = \ 24 | $(GTK_CFLAGS) \ 25 | $(CAIRO_CFLAGS) \ 26 | $(LIBGTOP_CFLAGS) 27 | 28 | multiload_core_la_LDFLAGS = \ 29 | -avoid-version \ 30 | -module \ 31 | -no-undefined \ 32 | -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \ 33 | $(PLATFORM_LDFLAGS) 34 | 35 | multiload_core_la_LIBADD = \ 36 | $(GTK_LIBS) \ 37 | $(CAIRO_LIBS) \ 38 | $(LIBGTOP_LIBS) 39 | 40 | # vi:set ts=8 sw=8 noet ai nocindent syntax=automake: 41 | -------------------------------------------------------------------------------- /multiload/autoscaler.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "autoscaler.h" 5 | 6 | /* i wish i could have used C99 initializers instead of writing this function */ 7 | void autoscaler_init(AutoScaler *that, unsigned interval, unsigned floor) 8 | { 9 | that->update_interval = interval; 10 | that->floor = floor; 11 | that->max = 0; 12 | that->count = 0; 13 | that->last_update = 0; 14 | that->sum = 0.0f; 15 | that->last_average = 0.0f; 16 | } 17 | 18 | 19 | unsigned autoscaler_get_max(AutoScaler *that, unsigned current) 20 | { 21 | time_t now; 22 | 23 | that->sum += current; 24 | that->count++; 25 | time(&now); 26 | 27 | if((float)difftime(now, that->last_update) > that->update_interval) 28 | { 29 | float new_average = that->sum / that->count; 30 | float average; 31 | 32 | if(new_average < that->last_average) 33 | average = ((that->last_average * 0.5f) + new_average) / 1.5f; 34 | else 35 | average = new_average; 36 | 37 | that->max = average * 1.2f; 38 | 39 | that->sum = 0.0f; 40 | that->count = 0; 41 | that->last_update = now; 42 | that->last_average = average; 43 | } 44 | 45 | that->max = MAX(that->max, current); 46 | that->max = MAX(that->max, that->floor); 47 | #if 0 48 | printf("%p max = %u, current = %u, last_average = %f\n", that, that->max, current, that->last_average); 49 | #endif 50 | return that->max; 51 | } 52 | -------------------------------------------------------------------------------- /multiload/autoscaler.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUTOSCALER_H__ 2 | #define __AUTOSCALER_H__ 3 | 4 | #include 5 | #include 6 | 7 | typedef struct _AutoScaler AutoScaler; 8 | 9 | struct _AutoScaler 10 | { 11 | /* const */ unsigned update_interval; 12 | /* const */ unsigned floor; 13 | unsigned max; 14 | unsigned count; 15 | time_t last_update; 16 | float sum; 17 | float last_average; 18 | }; 19 | 20 | 21 | G_GNUC_INTERNAL void autoscaler_init(AutoScaler *that, unsigned interval, unsigned floor); 22 | 23 | G_GNUC_INTERNAL unsigned autoscaler_get_max(AutoScaler *that, unsigned current); 24 | 25 | 26 | #endif /* __AUTOSCALER_H__ */ 27 | -------------------------------------------------------------------------------- /multiload/linux-proc.c: -------------------------------------------------------------------------------- 1 | /* From wmload.c, v0.9.2, licensed under the GPL. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "linux-proc.h" 19 | #include "autoscaler.h" 20 | 21 | static const unsigned needed_cpu_flags = 22 | (1 << GLIBTOP_CPU_USER) + 23 | (1 << GLIBTOP_CPU_IDLE) + 24 | (1 << GLIBTOP_CPU_SYS) + 25 | (1 << GLIBTOP_CPU_NICE); 26 | 27 | #if 0 28 | static const unsigned needed_page_flags = 29 | (1 << GLIBTOP_SWAP_PAGEIN) + 30 | (1 << GLIBTOP_SWAP_PAGEOUT); 31 | #endif 32 | 33 | static const unsigned needed_mem_flags = 34 | (1 << GLIBTOP_MEM_USED) + 35 | (1 << GLIBTOP_MEM_FREE); 36 | 37 | static const unsigned needed_swap_flags = 38 | (1 << GLIBTOP_SWAP_USED) + 39 | (1 << GLIBTOP_SWAP_FREE); 40 | 41 | static const unsigned needed_loadavg_flags = 42 | (1 << GLIBTOP_LOADAVG_LOADAVG); 43 | 44 | static const unsigned needed_netload_flags = 45 | (1 << GLIBTOP_NETLOAD_IF_FLAGS) + 46 | (1 << GLIBTOP_NETLOAD_BYTES_TOTAL); 47 | 48 | 49 | void 50 | GetLoad (int Maximum, int data [5], LoadGraph *g) 51 | { 52 | int usr, nice, sys, iowait, free; 53 | int total; 54 | 55 | glibtop_cpu cpu; 56 | 57 | glibtop_get_cpu (&cpu); 58 | 59 | g_return_if_fail ((cpu.flags & needed_cpu_flags) == needed_cpu_flags); 60 | 61 | g->cpu_time [0] = cpu.user; 62 | g->cpu_time [1] = cpu.nice; 63 | g->cpu_time [2] = cpu.sys; 64 | g->cpu_time [3] = cpu.iowait + cpu.irq + cpu.softirq; 65 | g->cpu_time [4] = cpu.idle; 66 | 67 | if (!g->cpu_initialized) { 68 | memcpy (g->cpu_last, g->cpu_time, sizeof (g->cpu_last)); 69 | g->cpu_initialized = 1; 70 | } 71 | 72 | usr = g->cpu_time [0] - g->cpu_last [0]; 73 | nice = g->cpu_time [1] - g->cpu_last [1]; 74 | sys = g->cpu_time [2] - g->cpu_last [2]; 75 | iowait = g->cpu_time [3] - g->cpu_last [3]; 76 | free = g->cpu_time [4] - g->cpu_last [4]; 77 | 78 | total = usr + nice + sys + free + iowait; 79 | 80 | memcpy(g->cpu_last, g->cpu_time, sizeof g->cpu_last); 81 | 82 | usr = rint (Maximum * (float)(usr) / total); 83 | nice = rint (Maximum * (float)(nice) / total); 84 | sys = rint (Maximum * (float)(sys) / total); 85 | iowait = rint (Maximum * (float)(iowait) / total); 86 | free = Maximum - usr - nice - sys - iowait; 87 | 88 | data [0] = usr; 89 | data [1] = sys; 90 | data [2] = nice; 91 | data [3] = iowait; 92 | data [4] = free; 93 | } 94 | 95 | void 96 | GetDiskLoad (int Maximum, int data [3], LoadGraph *g) 97 | { 98 | static gboolean first_call = TRUE; 99 | static guint64 lastread = 0, lastwrite = 0; 100 | static AutoScaler scaler; 101 | 102 | glibtop_mountlist mountlist; 103 | glibtop_mountentry *mountentries; 104 | guint i; 105 | int max; 106 | 107 | guint64 read, write; 108 | guint64 readdiff, writediff; 109 | 110 | 111 | if(first_call) 112 | { 113 | autoscaler_init(&scaler, 60, 500); 114 | } 115 | 116 | read = write = 0; 117 | 118 | mountentries = glibtop_get_mountlist (&mountlist, FALSE); 119 | 120 | for (i = 0; i < mountlist.number; i++) 121 | { 122 | glibtop_fsusage fsusage; 123 | 124 | if (strcmp(mountentries[i].type, "smbfs") == 0 125 | || strcmp(mountentries[i].type, "nfs") == 0 126 | || strcmp(mountentries[i].type, "cifs") == 0 127 | || strcmp(mountentries[i].type, "fuse.sshfs") == 0) 128 | continue; 129 | 130 | glibtop_get_fsusage(&fsusage, mountentries[i].mountdir); 131 | read += fsusage.read; write += fsusage.write; 132 | } 133 | 134 | g_free(mountentries); 135 | 136 | readdiff = read - lastread; 137 | writediff = write - lastwrite; 138 | 139 | lastread = read; 140 | lastwrite = write; 141 | 142 | if(first_call) 143 | { 144 | first_call = FALSE; 145 | memset(data, 0, 3 * sizeof data[0]); 146 | return; 147 | } 148 | 149 | max = autoscaler_get_max(&scaler, readdiff + writediff); 150 | 151 | data[0] = (float)Maximum * readdiff / (float)max; 152 | data[1] = (float)Maximum * writediff / (float)max; 153 | data[2] = (float)Maximum - (data [0] + data[1]); 154 | } 155 | 156 | #if 0 157 | void 158 | GetPage (int Maximum, int data [3], LoadGraph *g) 159 | { 160 | static int max = 100; /* guess at maximum page rate (= in + out) */ 161 | static u_int64_t lastin = 0; 162 | static u_int64_t lastout = 0; 163 | int in, out, idle; 164 | 165 | glibtop_swap swap; 166 | 167 | glibtop_get_swap (&swap); 168 | 169 | assert ((swap.flags & needed_page_flags) == needed_page_flags); 170 | 171 | if ((lastin > 0) && (lastin < swap.pagein)) { 172 | in = swap.pagein - lastin; 173 | } 174 | else { 175 | in = 0; 176 | } 177 | lastin = swap.pagein; 178 | 179 | if ((lastout > 0) && (lastout < swap.pageout)) { 180 | out = swap.pageout - lastout; 181 | } 182 | else { 183 | out = 0; 184 | } 185 | lastout = swap.pageout; 186 | 187 | if ((in + out) > max) { 188 | /* Maximum page rate has increased. Change the scale without 189 | any indication whatsoever to the user (not a nice thing to 190 | do). */ 191 | max = in + out; 192 | } 193 | 194 | in = rint (Maximum * ((float)in / max)); 195 | out = rint (Maximum * ((float)out / max)); 196 | idle = Maximum - in - out; 197 | 198 | data [0] = in; 199 | data [1] = out; 200 | data [2] = idle; 201 | } 202 | #endif /* 0 */ 203 | 204 | void 205 | GetMemory (int Maximum, int data [5], LoadGraph *g) 206 | { 207 | int user, shared, buffer, cached; 208 | 209 | glibtop_mem mem; 210 | 211 | glibtop_get_mem (&mem); 212 | 213 | g_return_if_fail ((mem.flags & needed_mem_flags) == needed_mem_flags); 214 | 215 | user = rint (Maximum * (float)mem.user / (float)mem.total); 216 | shared = rint (Maximum * (float)mem.shared / (float)mem.total); 217 | buffer = rint (Maximum * (float)mem.buffer / (float)mem.total); 218 | cached = rint (Maximum * (float)mem.cached / (float)mem.total); 219 | 220 | data [0] = user; 221 | data [1] = shared; 222 | data [2] = buffer; 223 | data[3] = cached; 224 | data [4] = Maximum-user-shared-buffer-cached; 225 | } 226 | 227 | void 228 | GetSwap (int Maximum, int data [2], LoadGraph *g) 229 | { 230 | int used, free; 231 | 232 | glibtop_swap swap; 233 | 234 | glibtop_get_swap (&swap); 235 | g_return_if_fail ((swap.flags & needed_swap_flags) == needed_swap_flags); 236 | 237 | if (swap.total == 0) { 238 | used = 0; 239 | free = Maximum; 240 | } 241 | else { 242 | used = rint (Maximum * (float)swap.used / swap.total); 243 | free = rint (Maximum * (float)swap.free / swap.total); 244 | } 245 | 246 | data [0] = used; 247 | data [1] = Maximum - used; 248 | } 249 | 250 | void 251 | GetLoadAvg (int Maximum, int data [2], LoadGraph *g) 252 | { 253 | const float per_cpu_max_loadavg = 5.0f; 254 | float max_loadavg; 255 | float loadavg1; 256 | float used, free; 257 | 258 | glibtop_loadavg loadavg; 259 | glibtop_get_loadavg (&loadavg); 260 | 261 | g_return_if_fail ((loadavg.flags & needed_loadavg_flags) == needed_loadavg_flags); 262 | 263 | max_loadavg = per_cpu_max_loadavg * (1 + glibtop_global_server->ncpu); 264 | 265 | g->loadavg1 = loadavg.loadavg[0]; 266 | loadavg1 = MIN(loadavg.loadavg[0], max_loadavg); 267 | 268 | used = loadavg1 / max_loadavg; 269 | free = (max_loadavg - loadavg1) / max_loadavg; 270 | 271 | data [0] = rint ((float) Maximum * used); 272 | data [1] = Maximum - data[0]; 273 | } 274 | 275 | /* 276 | * Return true if a network device (identified by its name) is virtual 277 | * (ie: not corresponding to a physical device). In case it is a physical 278 | * device or unknown, returns false. 279 | */ 280 | static gboolean 281 | is_net_device_virtual(char *device) 282 | { 283 | /* 284 | * There is not definitive way to find out. On some systems (Linux 285 | * kernels ≳ 2.19 without option SYSFS_DEPRECATED), there exist a 286 | * directory /sys/devices/virtual/net which only contains virtual 287 | * devices. It's also possible to detect by the fact that virtual 288 | * devices do not have a symlink "device" in 289 | * /sys/class/net/name-of-dev/ . This second method is more complex 290 | * but more reliable. 291 | */ 292 | char path[PATH_MAX]; 293 | 294 | /* Check if /sys/class/net/name-of-dev/ exists (may be old linux kernel 295 | * or not linux at all). */ 296 | if (sprintf(path, "/sys/class/net/%s", device) < 0) 297 | return FALSE; 298 | if (access(path, F_OK) != 0) 299 | return FALSE; /* unknown */ 300 | 301 | if (sprintf(path, "/sys/class/net/%s/device", device) < 0) 302 | return FALSE; 303 | if (access(path, F_OK) != 0) 304 | return TRUE; 305 | 306 | return FALSE; 307 | } 308 | 309 | void 310 | GetNet (int Maximum, int data [4], LoadGraph *g) 311 | { 312 | enum Types { 313 | IN_COUNT = 0, 314 | OUT_COUNT = 1, 315 | LOCAL_COUNT = 2, 316 | COUNT_TYPES = 3 317 | }; 318 | 319 | static int ticks = 0; 320 | static gulong past[COUNT_TYPES] = {0}; 321 | static AutoScaler scaler; 322 | 323 | gulong present[COUNT_TYPES] = {0}; 324 | 325 | guint i; 326 | gchar **devices; 327 | glibtop_netlist netlist; 328 | 329 | 330 | if(ticks == 0) 331 | { 332 | autoscaler_init(&scaler, 60, 501); 333 | } 334 | 335 | 336 | devices = glibtop_get_netlist(&netlist); 337 | 338 | for(i = 0; i < netlist.number; ++i) 339 | { 340 | glibtop_netload netload; 341 | 342 | glibtop_get_netload(&netload, devices[i]); 343 | 344 | g_return_if_fail((netload.flags & needed_netload_flags) == needed_netload_flags); 345 | 346 | if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP))) 347 | continue; 348 | 349 | if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) { 350 | /* for loopback in and out are identical, so only count in */ 351 | present[LOCAL_COUNT] += netload.bytes_in; 352 | continue; 353 | } 354 | 355 | /* 356 | * Do not include virtual devices (VPN, PPPOE...) to avoid 357 | * counting the same throughput several times. 358 | */ 359 | if (is_net_device_virtual(devices[i])) 360 | continue; 361 | 362 | present[IN_COUNT] += netload.bytes_in; 363 | present[OUT_COUNT] += netload.bytes_out; 364 | } 365 | 366 | g_strfreev(devices); 367 | netspeed_add(g->netspeed_in, present[IN_COUNT]); 368 | netspeed_add(g->netspeed_out, present[OUT_COUNT]); 369 | 370 | if(ticks < 2) /* avoid initial spike */ 371 | { 372 | ticks++; 373 | memset(data, 0, COUNT_TYPES * sizeof data[0]); 374 | } 375 | else 376 | { 377 | int delta[COUNT_TYPES]; 378 | int max; 379 | int total = 0; 380 | 381 | for (i = 0; i < COUNT_TYPES; i++) 382 | { 383 | /* protect against weirdness */ 384 | if (present[i] >= past[i]) 385 | delta[i] = (present[i] - past[i]); 386 | else 387 | delta[i] = 0; 388 | total += delta[i]; 389 | } 390 | 391 | max = autoscaler_get_max(&scaler, total); 392 | 393 | for (i = 0; i < COUNT_TYPES; i++) 394 | data[i] = rint (Maximum * (float)delta[i] / max); 395 | } 396 | 397 | //data[4] = Maximum - data[3] - data[2] - data[1] - data[0]; 398 | data[COUNT_TYPES] = Maximum; 399 | for (i = 0; i < COUNT_TYPES; i++) 400 | data[COUNT_TYPES] -= data[i]; 401 | 402 | memcpy(past, present, sizeof past); 403 | } 404 | 405 | 406 | 407 | -------------------------------------------------------------------------------- /multiload/linux-proc.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUX_PROC_H__ 2 | #define LINUX_PROC_H__ 3 | 4 | #include 5 | 6 | G_GNUC_INTERNAL void GetLoad (int Maximum, int data [5], LoadGraph *g); 7 | G_GNUC_INTERNAL void GetDiskLoad (int Maximum, int data [3], LoadGraph *g); 8 | #if 0 9 | G_GNUC_INTERNAL void GetPage (int Maximum, int data [3], LoadGraph *g); 10 | #endif /* 0 */ 11 | G_GNUC_INTERNAL void GetMemory (int Maximum, int data [4], LoadGraph *g); 12 | G_GNUC_INTERNAL void GetSwap (int Maximum, int data [2], LoadGraph *g); 13 | G_GNUC_INTERNAL void GetLoadAvg (int Maximum, int data [2], LoadGraph *g); 14 | G_GNUC_INTERNAL void GetNet (int Maximum, int data [4], LoadGraph *g); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /multiload/load-graph.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "multiload.h" 14 | 15 | 16 | /* 17 | Shifts data right 18 | 19 | data[i+1] = data[i] 20 | 21 | data[i] are int*, so we just move the pointer, not the data. 22 | But moving data loses data[n-1], so we save data[n-1] and reuse 23 | it as new data[0]. In fact, we rotate data[]. 24 | 25 | */ 26 | 27 | static void 28 | shift_right(LoadGraph *g) 29 | { 30 | unsigned i; 31 | int* last_data; 32 | 33 | /* data[g->draw_width - 1] becomes data[0] */ 34 | last_data = g->data[g->draw_width - 1]; 35 | 36 | /* data[i+1] = data[i] */ 37 | for(i = g->draw_width - 1; i != 0; --i) 38 | g->data[i] = g->data[i-1]; 39 | 40 | g->data[0] = last_data; 41 | } 42 | 43 | 44 | /* Redraws the backing pixmap for the load graph and updates the window */ 45 | static void 46 | load_graph_draw (LoadGraph *g) 47 | { 48 | GtkStyle *style; 49 | guint i, j; 50 | cairo_t *cr; 51 | GdkColor *colors = g->multiload->graph_config[g->id].colors; 52 | 53 | /* we might get called before the configure event so that 54 | * g->disp->allocation may not have the correct size 55 | * (after the user resized the applet in the prop dialog). */ 56 | 57 | if (!g->surface) 58 | g->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 59 | g->draw_width, g->draw_height); 60 | /* Not available on GTK < 2.22 61 | gdk_window_create_similar_surface (gtk_widget_get_window (g->disp), 62 | CAIRO_CONTENT_COLOR, 63 | g->draw_width, g->draw_height); 64 | */ 65 | 66 | style = gtk_widget_get_style (g->disp); 67 | 68 | cr = cairo_create (g->surface); 69 | cairo_set_line_width (cr, 1.0); 70 | cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); 71 | 72 | for (i = 0; i < g->draw_width; i++) 73 | g->pos [i] = g->draw_height - 1; 74 | 75 | for (j = 0; j < graph_types[g->id].num_colors; j++) 76 | { 77 | gdk_cairo_set_source_color (cr, &(colors[j])); 78 | 79 | for (i = 0; i < g->draw_width; i++) { 80 | if (g->data [i][j] != 0) { 81 | cairo_move_to (cr, 82 | g->draw_width - i - 0.5, 83 | g->pos[i] + 0.5); 84 | cairo_line_to (cr, 85 | g->draw_width - i - 0.5, 86 | g->pos[i] - (g->data [i][j] - 0.5)); 87 | 88 | g->pos [i] -= g->data [i][j]; 89 | } 90 | } 91 | 92 | cairo_stroke (cr); 93 | } 94 | 95 | cairo_destroy (cr); 96 | 97 | cr = gdk_cairo_create (gtk_widget_get_window (g->disp)); 98 | cairo_set_source_surface (cr, g->surface, 0, 0); 99 | cairo_paint (cr); 100 | cairo_destroy (cr); 101 | } 102 | 103 | /* Updates the load graph when the timeout expires */ 104 | static gboolean 105 | load_graph_update (LoadGraph *g) 106 | { 107 | if (g->data == NULL) 108 | return TRUE; 109 | 110 | shift_right(g); 111 | 112 | if (g->tooltip_update) 113 | multiload_tooltip_update(g); 114 | 115 | graph_types[g->id].get_data (g->draw_height, g->data [0], g); 116 | 117 | load_graph_draw (g); 118 | return TRUE; 119 | } 120 | 121 | void 122 | load_graph_unalloc (LoadGraph *g) 123 | { 124 | guint i; 125 | 126 | if (!g->allocated) 127 | return; 128 | 129 | for (i = 0; i < g->draw_width; i++) 130 | { 131 | g_free (g->data [i]); 132 | } 133 | 134 | g_free (g->data); 135 | g_free (g->pos); 136 | 137 | g->pos = NULL; 138 | g->data = NULL; 139 | 140 | if (g->surface) { 141 | cairo_surface_destroy (g->surface); 142 | g->surface = NULL; 143 | } 144 | 145 | g->allocated = FALSE; 146 | } 147 | 148 | static void 149 | load_graph_alloc (LoadGraph *g) 150 | { 151 | guint i, num_colors = graph_types[g->id].num_colors; 152 | 153 | if (g->allocated) 154 | return; 155 | 156 | g->data = g_new0 (gint *, g->draw_width); 157 | g->pos = g_new0 (guint, g->draw_width); 158 | 159 | g->data_size = sizeof (guint) * num_colors; 160 | 161 | for (i = 0; i < g->draw_width; i++) { 162 | g->data [i] = g_malloc0 (g->data_size); 163 | } 164 | 165 | g->allocated = TRUE; 166 | } 167 | 168 | static gint 169 | load_graph_configure (GtkWidget *widget, GdkEventConfigure *event, 170 | gpointer data_ptr) 171 | { 172 | GtkAllocation allocation; 173 | LoadGraph *c = (LoadGraph *) data_ptr; 174 | 175 | load_graph_unalloc (c); 176 | 177 | gtk_widget_get_allocation (c->disp, &allocation); 178 | 179 | c->draw_width = allocation.width; 180 | c->draw_height = allocation.height; 181 | c->draw_width = MAX (c->draw_width, 1); 182 | c->draw_height = MAX (c->draw_height, 1); 183 | 184 | load_graph_alloc (c); 185 | 186 | if (!c->surface) 187 | c->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 188 | c->draw_width, c->draw_height); 189 | /* Not available on GTK < 2.22 190 | gdk_window_create_similar_surface (gtk_widget_get_window (c->disp), 191 | CAIRO_CONTENT_COLOR, 192 | c->draw_width, c->draw_height); 193 | */ 194 | 195 | gtk_widget_queue_draw (widget); 196 | 197 | return TRUE; 198 | } 199 | 200 | static gint 201 | load_graph_expose (GtkWidget *widget, GdkEventExpose *event, 202 | gpointer data_ptr) 203 | { 204 | LoadGraph *g = (LoadGraph *) data_ptr; 205 | cairo_t *cr; 206 | 207 | cr = gdk_cairo_create (event->window); 208 | 209 | cairo_set_source_surface (cr, g->surface, 0, 0); 210 | cairo_paint (cr); 211 | 212 | cairo_destroy (cr); 213 | 214 | return FALSE; 215 | } 216 | 217 | static void 218 | load_graph_destroy (GtkWidget *widget, gpointer data_ptr) 219 | { 220 | LoadGraph *g = (LoadGraph *) data_ptr; 221 | 222 | load_graph_stop (g); 223 | netspeed_delete(g->netspeed_in); 224 | netspeed_delete(g->netspeed_out); 225 | 226 | gtk_widget_destroy(widget); 227 | } 228 | 229 | static gboolean 230 | load_graph_clicked (GtkWidget *widget, GdkEventButton *event, LoadGraph *load) 231 | { 232 | /* Formerly used to have properties open to this graph. */ 233 | 234 | return FALSE; 235 | } 236 | 237 | static gboolean 238 | load_graph_enter_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) 239 | { 240 | LoadGraph *graph; 241 | graph = (LoadGraph *)data; 242 | 243 | graph->tooltip_update = TRUE; 244 | multiload_tooltip_update(graph); 245 | 246 | return TRUE; 247 | } 248 | 249 | static gboolean 250 | load_graph_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) 251 | { 252 | LoadGraph *graph; 253 | graph = (LoadGraph *)data; 254 | 255 | graph->tooltip_update = FALSE; 256 | 257 | return TRUE; 258 | } 259 | 260 | LoadGraph * 261 | load_graph_new (MultiloadPlugin *ma, guint id) 262 | { 263 | LoadGraph *g; 264 | 265 | g = g_new0 (LoadGraph, 1); 266 | g->netspeed_in = netspeed_new(g); 267 | g->netspeed_out = netspeed_new(g); 268 | g->id = id; 269 | 270 | g->tooltip_update = FALSE; 271 | g->show_frame = TRUE; 272 | g->multiload = ma; 273 | 274 | g->main_widget = gtk_vbox_new (FALSE, 0); 275 | 276 | g->box = gtk_vbox_new (FALSE, 0); 277 | 278 | if (g->show_frame) 279 | { 280 | g->frame = gtk_frame_new (NULL); 281 | gtk_frame_set_shadow_type (GTK_FRAME (g->frame), GTK_SHADOW_IN); 282 | gtk_container_add (GTK_CONTAINER (g->frame), g->box); 283 | gtk_box_pack_start (GTK_BOX (g->main_widget), g->frame, TRUE, TRUE, 0); 284 | } 285 | else 286 | { 287 | g->frame = NULL; 288 | gtk_box_pack_start (GTK_BOX (g->main_widget), g->box, TRUE, TRUE, 0); 289 | } 290 | 291 | g->timer_index = -1; 292 | 293 | load_graph_resize(g); 294 | 295 | g->disp = gtk_drawing_area_new (); 296 | gtk_widget_set_events (g->disp, GDK_EXPOSURE_MASK | 297 | GDK_ENTER_NOTIFY_MASK | 298 | GDK_LEAVE_NOTIFY_MASK | 299 | GDK_BUTTON_PRESS_MASK); 300 | 301 | g_signal_connect (G_OBJECT (g->disp), "expose_event", 302 | G_CALLBACK (load_graph_expose), g); 303 | g_signal_connect (G_OBJECT(g->disp), "configure_event", 304 | G_CALLBACK (load_graph_configure), g); 305 | g_signal_connect (G_OBJECT(g->disp), "destroy", 306 | G_CALLBACK (load_graph_destroy), g); 307 | g_signal_connect (G_OBJECT(g->disp), "button-press-event", 308 | G_CALLBACK (load_graph_clicked), g); 309 | g_signal_connect (G_OBJECT(g->disp), "enter-notify-event", 310 | G_CALLBACK(load_graph_enter_cb), g); 311 | g_signal_connect (G_OBJECT(g->disp), "leave-notify-event", 312 | G_CALLBACK(load_graph_leave_cb), g); 313 | 314 | gtk_box_pack_start (GTK_BOX (g->box), g->disp, TRUE, TRUE, 0); 315 | gtk_widget_show_all(g->box); 316 | 317 | return g; 318 | } 319 | 320 | void 321 | load_graph_resize (LoadGraph *g) 322 | { 323 | guint size = CLAMP(g->multiload->size, MIN_SIZE, MAX_SIZE); 324 | 325 | if ( g->multiload->orientation == GTK_ORIENTATION_VERTICAL ) 326 | gtk_widget_set_size_request (g->main_widget, -1, size); 327 | else /* GTK_ORIENTATION_HORIZONTAL */ 328 | gtk_widget_set_size_request (g->main_widget, size, -1); 329 | } 330 | 331 | void 332 | load_graph_start (LoadGraph *g) 333 | { 334 | guint speed = CLAMP(g->multiload->speed, MIN_SPEED, MAX_SPEED); 335 | 336 | if (g->timer_index != -1) 337 | g_source_remove (g->timer_index); 338 | 339 | g->timer_index = g_timeout_add (speed, (GSourceFunc) load_graph_update, g); 340 | } 341 | 342 | void 343 | load_graph_stop (LoadGraph *g) 344 | { 345 | if (g->timer_index != -1) 346 | g_source_remove (g->timer_index); 347 | 348 | g->timer_index = -1; 349 | } 350 | -------------------------------------------------------------------------------- /multiload/load-graph.h: -------------------------------------------------------------------------------- 1 | #ifndef LOAD_GRAPH_H__ 2 | #define LOAD_GRAPH_H__ 3 | 4 | #include "multiload.h" 5 | 6 | /* Create new load graph. */ 7 | G_GNUC_INTERNAL LoadGraph * 8 | load_graph_new (MultiloadPlugin *ma, guint id); 9 | 10 | /* (Re)size load graph. */ 11 | G_GNUC_INTERNAL void 12 | load_graph_resize (LoadGraph *g); 13 | 14 | /* Start load graph. */ 15 | G_GNUC_INTERNAL void 16 | load_graph_start (LoadGraph *g); 17 | 18 | /* Stop load graph. */ 19 | G_GNUC_INTERNAL void 20 | load_graph_stop (LoadGraph *g); 21 | 22 | /* free load graph */ 23 | G_GNUC_INTERNAL void 24 | load_graph_unalloc (LoadGraph *g); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /multiload/multiload.c: -------------------------------------------------------------------------------- 1 | /* GNOME multiload panel applet 2 | * (C) 1997 The Free Software Foundation 3 | * 4 | * Authors: Tim P. Gerla 5 | * Martin Baulig 6 | * Todd Kulesza 7 | * 8 | * With code from wmload.c, v0.9.2, apparently by Ryan Land, rland@bc1.com. 9 | * 10 | */ 11 | 12 | #include 13 | #include 14 | #include "multiload.h" 15 | 16 | /* update the tooltip to the graph's current "used" percentage */ 17 | void 18 | multiload_tooltip_update(LoadGraph *g) 19 | { 20 | gchar *tooltip_text; 21 | const gchar *name; 22 | 23 | g_assert(g); 24 | 25 | /* label the tooltip intuitively */ 26 | if ( g->id >= 0 && g->id < NGRAPHS ) 27 | name = graph_types[g->id].noninteractive_label; 28 | else 29 | g_assert_not_reached(); 30 | 31 | switch (g->id) 32 | { 33 | case GRAPH_MEMLOAD: 34 | { 35 | guint mem_user, mem_cache, user_percent, cache_percent; 36 | mem_user = g->data[0][0]; 37 | mem_cache = g->data[0][1] + g->data[0][2] + g->data[0][3]; 38 | user_percent = 100.0f * mem_user / g->draw_height; 39 | cache_percent = 100.0f * mem_cache / g->draw_height; 40 | user_percent = MIN(user_percent, 100); 41 | cache_percent = MIN(cache_percent, 100); 42 | 43 | /* xgettext: use and cache are > 1 most of the time, 44 | please assume that they always are. 45 | */ 46 | tooltip_text = g_strdup_printf(_("%s:\n" 47 | "%u%% in use by programs\n" 48 | "%u%% in use as cache"), 49 | name, 50 | user_percent, 51 | cache_percent); 52 | } 53 | break; 54 | case GRAPH_NETLOAD: 55 | { 56 | char *tx_in, *tx_out; 57 | tx_in = netspeed_get(g->netspeed_in); 58 | tx_out = netspeed_get(g->netspeed_out); 59 | /* xgettext: same as in graphic tab of g-s-m */ 60 | tooltip_text = g_strdup_printf(_("%s:\n" 61 | "Receiving %s\n" 62 | "Sending %s"), 63 | name, tx_in, tx_out); 64 | g_free(tx_in); 65 | g_free(tx_out); 66 | } 67 | break; 68 | case GRAPH_LOADAVG: 69 | tooltip_text = g_strdup_printf(_("The system load average is %0.02f"), 70 | g->loadavg1); 71 | break; 72 | default: 73 | { 74 | const char *msg; 75 | guint i, total_used, percent; 76 | guint num_colors = graph_types[g->id].num_colors; 77 | 78 | for (i = 0, total_used = 0; i < (num_colors - 1); i++) 79 | total_used += g->data[0][i]; 80 | 81 | percent = 100.0f * total_used / g->draw_height; 82 | percent = MIN(percent, 100); 83 | 84 | msg = ngettext("%s:\n" 85 | "%u%% in use", 86 | "%s:\n" 87 | "%u%% in use", 88 | percent); 89 | 90 | tooltip_text = g_strdup_printf(msg, name, percent); 91 | } 92 | break; 93 | } 94 | 95 | gtk_widget_set_tooltip_text(g->disp, tooltip_text); 96 | g_free(tooltip_text); 97 | } 98 | 99 | static void 100 | multiload_create_graphs(MultiloadPlugin *ma) 101 | { 102 | gint i; 103 | 104 | for (i = 0; i < G_N_ELEMENTS (graph_types); i++) 105 | { 106 | g_assert (graph_types[i].num_colors <= MAX_COLORS); 107 | ma->graphs[i] = load_graph_new (ma, i); 108 | } 109 | } 110 | 111 | /* remove the old graphs and rebuild them */ 112 | void 113 | multiload_refresh(MultiloadPlugin *ma, GtkOrientation orientation) 114 | { 115 | gint i; 116 | 117 | /* stop and free the old graphs */ 118 | for (i = 0; i < NGRAPHS; i++) 119 | { 120 | if (!ma->graphs[i]) 121 | continue; 122 | 123 | load_graph_stop(ma->graphs[i]); 124 | gtk_widget_destroy(ma->graphs[i]->main_widget); 125 | 126 | load_graph_unalloc(ma->graphs[i]); 127 | g_free(ma->graphs[i]); 128 | } 129 | 130 | if (ma->box) 131 | gtk_widget_destroy(ma->box); 132 | 133 | /* Can we do gtk_orientable_set_orientation? */ 134 | if ( orientation == GTK_ORIENTATION_HORIZONTAL ) 135 | ma->box = gtk_hbox_new (FALSE, 0); 136 | else 137 | ma->box = gtk_vbox_new (FALSE, 0); 138 | gtk_widget_show (ma->box); 139 | gtk_container_add (ma->container, ma->box); 140 | ma->orientation = orientation; 141 | /* We use show/hide to control graph visibility. Don't let a rouge panel 142 | * screw that up. */ 143 | gtk_widget_set_no_show_all (ma->box, TRUE); 144 | 145 | /* Create the NGRAPHS graphs, with user-configurable properties taken 146 | * from ma->graph_config. */ 147 | multiload_create_graphs (ma); 148 | 149 | /* only start and display the graphs the user has turned on */ 150 | 151 | for (i = 0; i < NGRAPHS; i++) { 152 | gtk_box_pack_start(GTK_BOX(ma->box), 153 | ma->graphs[i]->main_widget, 154 | TRUE, TRUE, 1); 155 | if (ma->graph_config[i].visible) { 156 | gtk_widget_show_all (ma->graphs[i]->main_widget); 157 | load_graph_start(ma->graphs[i]); 158 | } 159 | } 160 | 161 | return; 162 | } 163 | 164 | void 165 | multiload_init() 166 | { 167 | static int initialized = 0; 168 | if ( initialized ) 169 | return; 170 | 171 | glibtop *glt = glibtop_init(); 172 | g_assert(glt != NULL); 173 | 174 | /* Prepare graph types */ 175 | GraphType temp[] = { 176 | /* prefs_label tooltip_label name get_data num_colors */ 177 | { _("_Processor"), _("Processor"), "cpuload", GetLoad, 5, 178 | { { _("_User"), "#0072b3" }, { _("_System"), "#0092e6" }, 179 | { _("N_ice"), "#00a3ff" }, { _("I_OWait"), "#002f3d" }, 180 | { _("Idl_e"), "#000000" } } }, 181 | 182 | { _("_Memory"), _("Memory"), "memload", GetMemory, 5, 183 | { { _("_User"), "#00b35b" }, { _("_Shared"), "#00e675" }, 184 | { _("_Buffers"), "#00ff82" }, { _("Cach_ed"), "#AAF5D0" }, 185 | { _("_Free"), "#000000" } } }, 186 | 187 | { _("_Network"), _("Network"), "netload", GetNet, 4, 188 | { { _("_In"), "#fce94f" }, { _("O_ut"), "#edd400" }, 189 | { _("L_ocal"), "#c4a000" }, { _("_Background"), "#000000" } } }, 190 | 191 | { _("S_wap Space"), _("Swap Space"), "swapload", GetSwap, 2, 192 | { { _("_Used"), "#8b00c3" }, { _("_Free"), "#000000" } } }, 193 | 194 | { _("_Load"), _("Load Average"), "loadavg", GetLoadAvg, 2, 195 | { { _("A_verage"), "#d50000" }, { _("_Background"), "#000000" } } }, 196 | 197 | { _("_Disk"), _("Disk"), "diskload", GetDiskLoad, 3, 198 | { { _("_Read"), "#C65000" }, { _("Wr_ite"), "#FF6700" }, 199 | { _("_Background"), "#000000" } } } 200 | }; 201 | memcpy(&graph_types, &temp, sizeof(graph_types)); 202 | } 203 | 204 | void 205 | multiload_destroy(MultiloadPlugin *ma) 206 | { 207 | gint i; 208 | 209 | /* Stop the graphs */ 210 | for (i = 0; i < NGRAPHS; i++) 211 | { 212 | load_graph_stop(ma->graphs[i]); 213 | gtk_widget_destroy(ma->graphs[i]->main_widget); 214 | 215 | load_graph_unalloc(ma->graphs[i]); 216 | g_free(ma->graphs[i]); 217 | } 218 | 219 | return; 220 | } 221 | 222 | /* Convert a GdkColor into a string of the form "#aabbcc" Output string must 223 | have size at least 8. 224 | */ 225 | gboolean 226 | multiload_gdk_color_stringify(GdkColor* color, gchar *color_string) 227 | { 228 | int rc = snprintf(color_string, 8, "#%02X%02X%02X", 229 | color->red / 256, color->green / 256, color->blue / 256); 230 | gboolean retval = (rc == 7); 231 | g_assert(retval); 232 | return retval; 233 | } 234 | 235 | /* Convert a graph configuration into a string of the form 236 | "#aabbcc,#ddeeff,...". Output string must have size at least 8*MAX_COLORS. 237 | */ 238 | void 239 | multiload_colorconfig_stringify(MultiloadPlugin *ma, guint i, char *list) 240 | { 241 | guint ncolors = graph_types[i].num_colors, j; 242 | GdkColor *colors = ma->graph_config[i].colors; 243 | char *listpos = list; 244 | 245 | if ( G_UNLIKELY (!list) ) 246 | return; 247 | 248 | /* Create color list */ 249 | for ( j = 0; j < ncolors; j++ ) 250 | { 251 | multiload_gdk_color_stringify(&colors[j], listpos); 252 | if ( j == ncolors-1 ) 253 | listpos[7] = 0; 254 | else 255 | listpos[7] = ','; 256 | listpos += 8; 257 | } 258 | g_assert (strlen(list) == 8*ncolors-1); 259 | } 260 | 261 | /* Set the colors for graph i to the default values */ 262 | void 263 | multiload_colorconfig_default(MultiloadPlugin *ma, guint i) 264 | { 265 | guint j; 266 | for ( j = 0; j < graph_types[i].num_colors; j++ ) 267 | gdk_color_parse(graph_types[i].colors[j].default_value, 268 | &ma->graph_config[i].colors[j]); 269 | } 270 | 271 | /* Set the colors for a graph from a string, as produced by 272 | multiload_colorconfig_stringify 273 | */ 274 | void 275 | multiload_colorconfig_unstringify(MultiloadPlugin *ma, guint i, 276 | const char *list) 277 | { 278 | guint ncolors = graph_types[i].num_colors, j; 279 | GdkColor *colors = ma->graph_config[i].colors; 280 | const char *listpos = list; 281 | 282 | if ( G_UNLIKELY (!listpos) ) 283 | return multiload_colorconfig_default(ma, i); 284 | 285 | for ( j = 0; j < ncolors; j++ ) 286 | { 287 | /* Check the length of the list item. */ 288 | int pos = 0; 289 | if ( j == ncolors-1 ) 290 | pos = strlen(listpos); 291 | else 292 | pos = (int)(strchr(listpos, ',')-listpos); 293 | 294 | /* Try to parse the color */ 295 | if ( G_UNLIKELY (pos != 7) ) 296 | return multiload_colorconfig_default(ma, i); 297 | 298 | /* Extract the color into a null-terminated buffer */ 299 | char buf[8]; 300 | strncpy(buf, listpos, 7); 301 | buf[7] = 0; 302 | if ( G_UNLIKELY (gdk_color_parse(buf, &colors[j]) != TRUE) ) 303 | return multiload_colorconfig_default(ma, i); 304 | 305 | listpos += 8; 306 | } 307 | } 308 | 309 | int 310 | multiload_find_graph_by_name(const char *str, const char **suffix) 311 | { 312 | guint i; 313 | for ( i = 0; i < NGRAPHS; i++ ) 314 | { 315 | int n = strlen(graph_types[i].name); 316 | if ( strncasecmp(str, graph_types[i].name, n) == 0 ) 317 | { 318 | if ( suffix ) 319 | *suffix = str+n; 320 | return i; 321 | } 322 | } 323 | return -1; 324 | } 325 | -------------------------------------------------------------------------------- /multiload/multiload.h: -------------------------------------------------------------------------------- 1 | #ifndef __GLOBAL_H__ 2 | #define __GLOBAL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | G_BEGIN_DECLS 10 | 11 | #define PLUGIN_WEBSITE "https://github.com/nandhp/multiload-nandhp" 12 | 13 | #define NCPUSTATES 5 14 | #define NGRAPHS 6 15 | #define MAX_COLORS 5 16 | 17 | enum { 18 | GRAPH_CPULOAD = 0, 19 | GRAPH_MEMLOAD = 1, 20 | GRAPH_NETLOAD = 2, 21 | GRAPH_SWAPLOAD = 3, 22 | GRAPH_LOADAVG = 4, 23 | GRAPH_DISKLOAD = 5 24 | }; 25 | 26 | typedef struct _MultiloadPlugin MultiloadPlugin; 27 | typedef struct _LoadGraph LoadGraph; 28 | typedef void (*LoadGraphDataFunc) (int, int [], LoadGraph *); 29 | typedef struct _GraphConfig GraphConfig; 30 | typedef struct _GraphType GraphType; 31 | 32 | #include "netspeed.h" 33 | 34 | #define MIN_SIZE 10 35 | #define DEFAULT_SIZE 40 36 | #define MAX_SIZE 400 37 | 38 | #define MIN_SPEED 50 39 | #define DEFAULT_SPEED 500 40 | #define MAX_SPEED 10000 41 | 42 | struct _LoadGraph { 43 | MultiloadPlugin *multiload; 44 | 45 | guint id; 46 | guint draw_width, draw_height; 47 | 48 | guint allocated; 49 | 50 | gint **data; 51 | guint data_size; 52 | guint *pos; 53 | 54 | GtkWidget *main_widget; 55 | GtkWidget *frame, *box, *disp; 56 | cairo_surface_t *surface; 57 | int timer_index; 58 | 59 | gint show_frame; 60 | 61 | long cpu_time [NCPUSTATES]; 62 | long cpu_last [NCPUSTATES]; 63 | int cpu_initialized; 64 | 65 | double loadavg1; 66 | NetSpeed *netspeed_in; 67 | NetSpeed *netspeed_out; 68 | 69 | gboolean tooltip_update; 70 | }; 71 | 72 | struct _GraphConfig { 73 | gboolean visible; 74 | GdkColor colors[MAX_COLORS]; 75 | }; 76 | 77 | struct _MultiloadPlugin 78 | { 79 | /* Current state */ 80 | GtkWidget *box; 81 | GtkOrientation orientation; 82 | LoadGraph *graphs[NGRAPHS]; 83 | 84 | /* Settings */ 85 | GtkContainer *container; 86 | GraphConfig graph_config[NGRAPHS]; 87 | guint speed; 88 | guint size; 89 | }; 90 | 91 | struct _GraphType { 92 | const char *interactive_label; 93 | const char *noninteractive_label; 94 | const char *name; 95 | LoadGraphDataFunc get_data; 96 | guint num_colors; 97 | const struct 98 | { 99 | const char *prefs_label; 100 | const char *default_value; 101 | } 102 | colors[MAX_COLORS]; 103 | //const char *default_colors; 104 | }; 105 | GraphType graph_types[NGRAPHS]; 106 | 107 | #include "load-graph.h" 108 | #include "linux-proc.h" 109 | 110 | /* remove the old graphs and rebuild them */ 111 | void 112 | multiload_refresh(MultiloadPlugin *ma, GtkOrientation orientation); 113 | 114 | /* update the tooltip to the graph's current "used" percentage */ 115 | void 116 | multiload_tooltip_update(LoadGraph *g); 117 | 118 | void 119 | multiload_init(); 120 | 121 | void 122 | multiload_destroy(MultiloadPlugin *ma); 123 | 124 | /* Utility functions for preferences and data storage */ 125 | gboolean 126 | multiload_gdk_color_stringify(GdkColor* color, gchar *color_string); 127 | 128 | void 129 | multiload_colorconfig_stringify(MultiloadPlugin *ma, guint i, char *list); 130 | 131 | void 132 | multiload_colorconfig_default(MultiloadPlugin *ma, guint i); 133 | 134 | void 135 | multiload_colorconfig_unstringify(MultiloadPlugin *ma, guint i, 136 | const char *list); 137 | 138 | int 139 | multiload_find_graph_by_name(const char *str, const char **suffix); 140 | 141 | G_END_DECLS 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /multiload/netspeed.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include 3 | #endif 4 | #include 5 | #include 6 | 7 | #include "multiload.h" 8 | #include "netspeed.h" 9 | 10 | enum { N_STATES = 4 }; 11 | 12 | struct _NetSpeed 13 | { 14 | LoadGraph *graph; 15 | gulong states[N_STATES]; 16 | size_t cur; 17 | }; 18 | 19 | NetSpeed* netspeed_new(LoadGraph *g) 20 | { 21 | NetSpeed *ns = g_new0(NetSpeed, 1); 22 | ns->graph = g; 23 | return ns; 24 | } 25 | 26 | void netspeed_delete(NetSpeed *ns) 27 | { 28 | g_free(ns); 29 | } 30 | 31 | void netspeed_add(NetSpeed *ns, gulong tx) 32 | { 33 | ns->cur = (ns->cur + 1) % N_STATES; 34 | ns->states[ns->cur] = tx; 35 | } 36 | 37 | /* Something very similar to g_format_size_for_display() but for rates. 38 | * This should give the same display as in g-s-m */ 39 | static char* 40 | format_rate_for_display(guint rate) 41 | { 42 | char* bytes = g_format_size_for_display(rate); 43 | return g_strdup_printf(_("%s/s"), bytes); 44 | } 45 | 46 | char* netspeed_get(NetSpeed *ns) 47 | { 48 | gulong older, newer; 49 | guint rate; 50 | 51 | newer = ns->states[ns->cur]; 52 | older = ns->states[(ns->cur + 1) % N_STATES]; 53 | 54 | if ((older != 0) && (newer > older)) 55 | rate = (newer - older) * 1000 / ((N_STATES - 1) * 56 | ns->graph->multiload->speed); 57 | else 58 | /* We end up here if we haven't got enough data yet or the 59 | network interface has jumped back (or there has never 60 | been any activity on any interface). A value of 0 is 61 | likely to be accurate, but if it is wrong it will be 62 | clearly wrong. In any event, it should fix itself in a 63 | few seconds. */ 64 | rate = 0; 65 | 66 | return format_rate_for_display(rate); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /multiload/netspeed.h: -------------------------------------------------------------------------------- 1 | #ifndef H_MULTILOAD_NETSPEED_ 2 | #define H_MULTILOAD_NETSPEED_ 3 | 4 | #include 5 | 6 | #include "multiload.h" 7 | 8 | typedef struct _NetSpeed NetSpeed; 9 | 10 | G_GNUC_INTERNAL NetSpeed* netspeed_new(LoadGraph *graph); 11 | G_GNUC_INTERNAL void netspeed_delete(NetSpeed *ns); 12 | G_GNUC_INTERNAL void netspeed_add(NetSpeed *ns, gulong tx); 13 | G_GNUC_INTERNAL char* netspeed_get(NetSpeed *ns); 14 | 15 | #endif /* H_MULTILOAD_NETSPEED_ */ 16 | -------------------------------------------------------------------------------- /multiload/properties.c: -------------------------------------------------------------------------------- 1 | /* GNOME cpuload/memload panel applet 2 | * (C) 2002 The Free Software Foundation 3 | * 4 | * Authors: 5 | * Todd Kulesza 6 | * 7 | * 8 | */ 9 | 10 | #ifdef HAVE_CONFIG_H 11 | #include 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "properties.h" 19 | #include "multiload.h" 20 | 21 | #define PROP_SPEED 6 22 | #define PROP_SIZE 7 23 | #define HIG_IDENTATION " " 24 | 25 | /* Defined in panel-specific code. */ 26 | extern MultiloadPlugin * 27 | multiload_configure_get_plugin (GtkWidget *widget); 28 | 29 | #if 0 30 | #define NEVER_SENSITIVE "never_sensitive" 31 | /* set sensitive and setup NEVER_SENSITIVE appropriately */ 32 | static void 33 | hard_set_sensitive (GtkWidget *w, gboolean sensitivity) 34 | { 35 | gtk_widget_set_sensitive (w, sensitivity); 36 | g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE, 37 | GINT_TO_POINTER ( ! sensitivity)); 38 | } 39 | 40 | /* set sensitive, but always insensitive if NEVER_SENSITIVE is set */ 41 | static void 42 | soft_set_sensitive (GtkWidget *w, gboolean sensitivity) 43 | { 44 | if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE)) 45 | gtk_widget_set_sensitive (w, FALSE); 46 | else 47 | gtk_widget_set_sensitive (w, sensitivity); 48 | } 49 | 50 | static gboolean 51 | key_writable (PanelApplet *applet, const char *key) 52 | { 53 | gboolean writable; 54 | char *fullkey; 55 | static GConfClient *client = NULL; 56 | if (client == NULL) 57 | client = gconf_client_get_default (); 58 | 59 | fullkey = panel_applet_gconf_get_full_key (applet, key); 60 | 61 | writable = gconf_client_key_is_writable (client, fullkey, NULL); 62 | 63 | g_free (fullkey); 64 | 65 | return writable; 66 | } 67 | #else 68 | #define soft_set_sensitive gtk_widget_set_sensitive 69 | #endif 70 | 71 | static void 72 | properties_set_checkboxes_sensitive(MultiloadPlugin *ma, GtkWidget *checkbox, 73 | gboolean sensitive) 74 | { 75 | /* Cound the number of visible graphs */ 76 | gint i, total_graphs = 0, last_graph = 0; 77 | 78 | if ( !sensitive ) 79 | /* Only set unsensitive if one checkbox remains checked */ 80 | for (i = 0; i < NGRAPHS; i++) 81 | if (ma->graph_config[i].visible) 82 | { 83 | last_graph = i; 84 | total_graphs++; 85 | } 86 | 87 | if ( total_graphs < 2 ) 88 | { 89 | /* Container widget that contains the checkboxes */ 90 | GtkWidget *container = gtk_widget_get_ancestor(checkbox, GTK_TYPE_BOX); 91 | if (container && container != checkbox) 92 | { 93 | GList *list = gtk_container_get_children (GTK_CONTAINER(container)); 94 | if ( sensitive ) 95 | { 96 | /* Enable all checkboxes */ 97 | GList *item = list; 98 | while ( item && item->data ) { 99 | GtkWidget *nthbox = GTK_WIDGET (item->data); 100 | soft_set_sensitive(nthbox, TRUE); 101 | item = g_list_next (item); 102 | } 103 | } 104 | else 105 | { 106 | /* Disable last remaining checkbox */ 107 | GtkWidget *nthbox = GTK_WIDGET(g_list_nth_data(list, last_graph)); 108 | if ( nthbox ) 109 | soft_set_sensitive(nthbox, FALSE); 110 | else 111 | g_assert_not_reached (); 112 | } 113 | } 114 | else 115 | g_assert_not_reached (); 116 | } 117 | 118 | return; 119 | } 120 | 121 | static void 122 | property_toggled_cb(GtkWidget *widget, gpointer id) 123 | { 124 | MultiloadPlugin *ma = multiload_configure_get_plugin(widget); 125 | gint prop_type = GPOINTER_TO_INT(id); 126 | gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); 127 | 128 | if (active) 129 | { 130 | properties_set_checkboxes_sensitive(ma, widget, TRUE); 131 | gtk_widget_show_all (ma->graphs[prop_type]->main_widget); 132 | ma->graph_config[prop_type].visible = TRUE; 133 | load_graph_start(ma->graphs[prop_type]); 134 | } 135 | else 136 | { 137 | load_graph_stop(ma->graphs[prop_type]); 138 | gtk_widget_hide (ma->graphs[prop_type]->main_widget); 139 | ma->graph_config[prop_type].visible = FALSE; 140 | properties_set_checkboxes_sensitive(ma, widget, FALSE); 141 | } 142 | 143 | return; 144 | } 145 | 146 | static void 147 | spin_button_changed_cb(GtkWidget *widget, gpointer id) 148 | { 149 | MultiloadPlugin *ma = multiload_configure_get_plugin(widget); 150 | gint prop_type = GPOINTER_TO_INT(id); 151 | gint value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); 152 | gint i; 153 | 154 | switch(prop_type) 155 | { 156 | case PROP_SPEED: 157 | ma->speed = value; 158 | for (i = 0; i < NGRAPHS; i++) 159 | { 160 | load_graph_stop(ma->graphs[i]); 161 | if (ma->graph_config[i].visible) 162 | load_graph_start(ma->graphs[i]); 163 | } 164 | break; 165 | 166 | case PROP_SIZE: 167 | ma->size = value; 168 | for (i = 0; i < NGRAPHS; i++) 169 | load_graph_resize(ma->graphs[i]); 170 | break; 171 | 172 | default: 173 | g_assert_not_reached(); 174 | } 175 | 176 | return; 177 | } 178 | 179 | /* create a new page in the notebook widget, add it, and return a pointer to it */ 180 | static GtkWidget * 181 | add_page(GtkNotebook *notebook, const gchar *label) 182 | { 183 | GtkWidget *page; 184 | GtkWidget *page_label; 185 | 186 | page = gtk_hbox_new(TRUE, 0); 187 | page_label = gtk_label_new(label); 188 | gtk_container_set_border_width(GTK_CONTAINER(page), 6); 189 | 190 | gtk_notebook_append_page(notebook, page, page_label); 191 | 192 | return page; 193 | } 194 | 195 | /* apply the selected color to the applet */ 196 | static void 197 | color_picker_set_cb(GtkColorButton *color_picker, gpointer data) 198 | { 199 | 200 | /* Parse user data for graph and color slot */ 201 | MultiloadPlugin *ma = multiload_configure_get_plugin(GTK_WIDGET (color_picker)); 202 | guint color_slot = GPOINTER_TO_INT(data); 203 | guint graph = color_slot>>16, index = color_slot&0xFFFF; 204 | 205 | g_assert(graph >= 0 && graph < NGRAPHS); 206 | g_assert(index >= 0 && index < graph_types[graph].num_colors); 207 | 208 | gtk_color_button_get_color(color_picker, &ma->graph_config[graph].colors[index]); 209 | 210 | return; 211 | } 212 | 213 | /* create a color selector */ 214 | static void 215 | add_color_selector(GtkWidget *page, const gchar *name, guint graph, guint index, 216 | MultiloadPlugin *ma) 217 | { 218 | GtkWidget *vbox; 219 | GtkWidget *label; 220 | GtkWidget *color_picker; 221 | guint color_slot = ((graph&0xFFFF)<<16)|(index&0xFFFF); 222 | 223 | vbox = gtk_vbox_new (FALSE, 6); 224 | label = gtk_label_new_with_mnemonic(name); 225 | color_picker = gtk_color_button_new(); 226 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_picker); 227 | 228 | gtk_box_pack_start(GTK_BOX(vbox), color_picker, FALSE, FALSE, 0); 229 | gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); 230 | 231 | gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 0); 232 | 233 | gtk_color_button_set_color(GTK_COLOR_BUTTON(color_picker), 234 | &ma->graph_config[graph].colors[index]); 235 | 236 | g_signal_connect(G_OBJECT(color_picker), "color_set", 237 | G_CALLBACK(color_picker_set_cb), 238 | GINT_TO_POINTER(color_slot)); 239 | 240 | //if ( ! key_writable (ma->applet, gconf_path)) 241 | // hard_set_sensitive (vbox, FALSE); 242 | 243 | return; 244 | } 245 | 246 | /* creates the properties dialog and initialize it from the current 247 | * configuration */ 248 | void 249 | multiload_init_preferences(GtkWidget *dialog, MultiloadPlugin *ma) 250 | { 251 | GtkWidget *hbox, *vbox; 252 | GtkWidget *categories_vbox; 253 | GtkWidget *category_vbox; 254 | GtkWidget *control_vbox; 255 | GtkWidget *control_hbox; 256 | GtkWidget *indent; 257 | GtkWidget *spin_button; 258 | GtkWidget *label; 259 | GtkNotebook *notebook; 260 | GtkSizeGroup *label_size; 261 | GtkSizeGroup *spin_size; 262 | gchar *text; 263 | guint i; 264 | 265 | vbox = gtk_vbox_new (FALSE, 0); 266 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); 267 | gtk_widget_show (vbox); 268 | 269 | gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, 270 | TRUE, TRUE, 0); 271 | 272 | categories_vbox = gtk_vbox_new (FALSE, 18); 273 | gtk_box_pack_start (GTK_BOX (vbox), categories_vbox, TRUE, TRUE, 0); 274 | gtk_widget_show (categories_vbox); 275 | 276 | category_vbox = gtk_vbox_new (FALSE, 6); 277 | gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); 278 | gtk_widget_show (category_vbox); 279 | 280 | text = g_strconcat ("", _("Monitored Resources"), "", NULL); 281 | label = gtk_label_new (text); 282 | gtk_label_set_use_markup (GTK_LABEL (label), TRUE); 283 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); 284 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); 285 | gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); 286 | g_free (text); 287 | 288 | hbox = gtk_hbox_new (FALSE, 0); 289 | gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); 290 | gtk_widget_show (hbox); 291 | 292 | indent = gtk_label_new (HIG_IDENTATION); 293 | gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); 294 | gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); 295 | gtk_widget_show (indent); 296 | 297 | control_vbox = gtk_vbox_new (FALSE, 6); 298 | gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); 299 | gtk_widget_show (control_vbox); 300 | 301 | control_hbox = gtk_hbox_new (FALSE, 12); 302 | gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); 303 | gtk_widget_show (control_hbox); 304 | 305 | 306 | for ( i = 0; i < NGRAPHS; i++ ) 307 | { 308 | GtkWidget *checkbox = gtk_check_button_new_with_mnemonic 309 | (graph_types[i].interactive_label); 310 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), 311 | ma->graph_config[i].visible); 312 | g_signal_connect(G_OBJECT(checkbox), "toggled", 313 | G_CALLBACK(property_toggled_cb), 314 | GINT_TO_POINTER(i)); 315 | gtk_box_pack_start (GTK_BOX (control_hbox), checkbox, 316 | FALSE, FALSE, 0); 317 | 318 | //if ( ! key_writable (ma->applet, "view_cpuload")) 319 | // hard_set_sensitive (check_box, FALSE); // FIXME 320 | 321 | /* If only one graph is visible, disable its checkbox. */ 322 | if ( i == NGRAPHS-1 ) 323 | properties_set_checkboxes_sensitive(ma, checkbox, FALSE); 324 | } 325 | 326 | category_vbox = gtk_vbox_new (FALSE, 6); 327 | gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); 328 | gtk_widget_show (category_vbox); 329 | 330 | text = g_strconcat ("", _("Options"), "", NULL); 331 | label = gtk_label_new (text); 332 | gtk_label_set_use_markup (GTK_LABEL (label), TRUE); 333 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); 334 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); 335 | gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); 336 | gtk_widget_show (label); 337 | g_free (text); 338 | 339 | hbox = gtk_hbox_new (FALSE, 0); 340 | gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); 341 | gtk_widget_show (hbox); 342 | 343 | indent = gtk_label_new (HIG_IDENTATION); 344 | gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); 345 | gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); 346 | gtk_widget_show (indent); 347 | 348 | control_vbox = gtk_vbox_new (FALSE, 6); 349 | gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); 350 | gtk_widget_show (control_vbox); 351 | 352 | control_hbox = gtk_hbox_new (FALSE, 12); 353 | gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); 354 | gtk_widget_show (control_hbox); 355 | 356 | label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); 357 | 358 | if ( ma->orientation == GTK_ORIENTATION_HORIZONTAL ) 359 | text = g_strdup(_("Wid_th: ")); 360 | else 361 | text = g_strdup(_("Heigh_t: ")); 362 | 363 | label = gtk_label_new_with_mnemonic(text); 364 | gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); 365 | gtk_size_group_add_widget (label_size, label); 366 | gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); 367 | g_free(text); 368 | 369 | hbox = gtk_hbox_new (FALSE, 6); 370 | gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); 371 | gtk_widget_show (hbox); 372 | 373 | spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); 374 | 375 | spin_button = gtk_spin_button_new_with_range(MIN_SIZE, MAX_SIZE, 5); 376 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); 377 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), 378 | (gdouble)ma->size); 379 | g_signal_connect(G_OBJECT(spin_button), "value_changed", 380 | G_CALLBACK(spin_button_changed_cb), 381 | GINT_TO_POINTER(PROP_SIZE)); 382 | 383 | //if ( ! key_writable (ma->applet, "size")) { 384 | // hard_set_sensitive (label, FALSE); 385 | // hard_set_sensitive (hbox, FALSE); 386 | //} 387 | 388 | gtk_size_group_add_widget (spin_size, spin_button); 389 | gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); 390 | 391 | label = gtk_label_new (_("pixels")); 392 | gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); 393 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); 394 | 395 | control_hbox = gtk_hbox_new (FALSE, 12); 396 | gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0); 397 | gtk_widget_show (control_hbox); 398 | 399 | label = gtk_label_new_with_mnemonic(_("Upd_ate interval: ")); 400 | gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); 401 | gtk_size_group_add_widget (label_size, label); 402 | gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0); 403 | 404 | hbox = gtk_hbox_new (FALSE, 6); 405 | gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); 406 | gtk_widget_show (hbox); 407 | 408 | spin_button = gtk_spin_button_new_with_range(MIN_SPEED, MAX_SPEED, 50); 409 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); 410 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), 411 | (gdouble)ma->speed); 412 | g_signal_connect(G_OBJECT(spin_button), "value_changed", 413 | G_CALLBACK(spin_button_changed_cb), 414 | GINT_TO_POINTER(PROP_SPEED)); 415 | gtk_size_group_add_widget (spin_size, spin_button); 416 | gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0); 417 | 418 | //if ( ! key_writable (ma->applet, "speed")) { 419 | // hard_set_sensitive (label, FALSE); 420 | // hard_set_sensitive (hbox, FALSE); 421 | //} 422 | 423 | label = gtk_label_new(_("milliseconds")); 424 | gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); 425 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); 426 | 427 | 428 | category_vbox = gtk_vbox_new (FALSE, 6); 429 | gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0); 430 | gtk_widget_show (category_vbox); 431 | 432 | text = g_strconcat ("", _("Colors"), "", NULL); 433 | label = gtk_label_new (text); 434 | gtk_label_set_use_markup (GTK_LABEL (label), TRUE); 435 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); 436 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); 437 | gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0); 438 | gtk_widget_show (label); 439 | g_free (text); 440 | 441 | hbox = gtk_hbox_new (FALSE, 0); 442 | gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0); 443 | gtk_widget_show (hbox); 444 | 445 | indent = gtk_label_new (HIG_IDENTATION); 446 | gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT); 447 | gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0); 448 | gtk_widget_show (indent); 449 | 450 | control_vbox = gtk_vbox_new (FALSE, 6); 451 | gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0); 452 | gtk_widget_show (control_vbox); 453 | 454 | notebook = GTK_NOTEBOOK(gtk_notebook_new()); 455 | gtk_container_add (GTK_CONTAINER (control_vbox), GTK_WIDGET (notebook)); 456 | 457 | for ( i = 0; i < NGRAPHS; i++ ) 458 | { 459 | guint j; 460 | GtkWidget *page = 461 | add_page(notebook, graph_types[i].noninteractive_label); 462 | gtk_container_set_border_width (GTK_CONTAINER (page), 12); 463 | for ( j = 0; j < graph_types[i].num_colors; j++ ) 464 | { 465 | add_color_selector(page, graph_types[i].colors[j].prefs_label, 466 | i, j, ma); 467 | } 468 | } 469 | gtk_notebook_set_current_page (notebook, 0); 470 | 471 | return; 472 | } 473 | 474 | -------------------------------------------------------------------------------- /multiload/properties.h: -------------------------------------------------------------------------------- 1 | #ifndef __PROPERTIES_H__ 2 | #define __PROPERTIES_H__ 3 | 4 | #include "multiload.h" 5 | 6 | G_BEGIN_DECLS 7 | 8 | #define PROP_CPULOAD 0 9 | #define PROP_MEMLOAD 1 10 | #define PROP_NETLOAD 2 11 | #define PROP_SWAPLOAD 3 12 | #define PROP_LOADAVG 4 13 | #define PROP_DISKLOAD 5 14 | 15 | typedef enum { 16 | LOADAVG_1 = 0, 17 | LOADAVG_5, 18 | LOADAVG_15 19 | } LoadAvgType; 20 | 21 | typedef struct _MultiLoadProperties MultiLoadProperties; 22 | 23 | typedef struct _LoadGraphProperties LoadGraphProperties; 24 | 25 | struct _LoadGraphProperties { 26 | guint type, n; 27 | const gchar *name; 28 | const gchar **texts; 29 | const gchar **color_defs; 30 | GdkColor *colors; 31 | gulong adj_data [3]; 32 | gint loadavg_type; 33 | gint use_default; 34 | }; 35 | 36 | struct _MultiLoadProperties { 37 | LoadGraphProperties cpuload, memload, swapload, netload, loadavg; 38 | }; 39 | 40 | /* 41 | void multiload_properties_apply (void) G_GNUC_INTERNAL; 42 | void multiload_properties_close (void) G_GNUC_INTERNAL; 43 | void multiload_properties_changed (void) G_GNUC_INTERNAL; 44 | void multiload_show_properties (PropertyClass prop_class) G_GNUC_INTERNAL; 45 | void multiload_init_properties (void) G_GNUC_INTERNAL; 46 | */ 47 | G_GNUC_INTERNAL void 48 | multiload_init_preferences(GtkWidget *dialog, MultiloadPlugin *ma); 49 | 50 | G_END_DECLS 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | multiload/multiload.c 2 | multiload/netspeed.c 3 | multiload/properties.c 4 | xfce4/xfce4-multiload-plugin.c 5 | xfce4/xfce4-multiload-dialogs.c 6 | xfce4/multiload.desktop.in 7 | lxpanel/lxpanel-multiload-plugin.c 8 | -------------------------------------------------------------------------------- /po/POTFILES.skip: -------------------------------------------------------------------------------- 1 | xfce4/multiload.desktop.in.in 2 | -------------------------------------------------------------------------------- /po/cs.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | msgid "" 7 | msgstr "" 8 | "Project-Id-Version: multiload-nandhp\n" 9 | "Report-Msgid-Bugs-To: \n" 10 | "POT-Creation-Date: 2015-06-12 16:17+0200\n" 11 | "PO-Revision-Date: 2015-06-12 16:33+0100\n" 12 | "Last-Translator: Jan Breuer \n" 13 | "Language-Team: Jan Breuer \n" 14 | "Language: cs\n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" 19 | "X-Generator: Poedit 1.5.5\n" 20 | 21 | #. xgettext: use and cache are > 1 most of the time, 22 | #. please assume that they always are. 23 | #. 24 | #: ../multiload/multiload.c:46 25 | #, c-format 26 | msgid "" 27 | "%s:\n" 28 | "%u%% in use by programs\n" 29 | "%u%% in use as cache" 30 | msgstr "" 31 | "%s:\n" 32 | "%u%% použito programy\n" 33 | "%u%% použito jako cache" 34 | 35 | #. xgettext: same as in graphic tab of g-s-m 36 | #: ../multiload/multiload.c:60 37 | #, c-format 38 | msgid "" 39 | "%s:\n" 40 | "Receiving %s\n" 41 | "Sending %s" 42 | msgstr "" 43 | "%s:\n" 44 | "Přijímání %s\n" 45 | "Odesílání %s" 46 | 47 | #: ../multiload/multiload.c:69 48 | #, c-format 49 | msgid "The system load average is %0.02f" 50 | msgstr "Průměrná zátěž systému je %0.02f" 51 | 52 | #: ../multiload/multiload.c:84 53 | #, c-format 54 | msgid "" 55 | "%s:\n" 56 | "%u%% in use" 57 | msgid_plural "" 58 | "%s:\n" 59 | "%u%% in use" 60 | msgstr[0] "" 61 | "%s:\n" 62 | "%u%% použito" 63 | msgstr[1] "" 64 | "%s:\n" 65 | "%u%% použito" 66 | msgstr[2] "" 67 | "%s:\n" 68 | "%u%% použito" 69 | 70 | #. prefs_label tooltip_label name get_data num_colors 71 | #: ../multiload/multiload.c:177 72 | msgid "_Processor" 73 | msgstr "_Procesor" 74 | 75 | #: ../multiload/multiload.c:177 76 | msgid "Processor" 77 | msgstr "Procesor" 78 | 79 | #: ../multiload/multiload.c:178 ../multiload/multiload.c:183 80 | msgid "_User" 81 | msgstr "_Uživatel" 82 | 83 | #: ../multiload/multiload.c:178 84 | msgid "_System" 85 | msgstr "_Systém" 86 | 87 | #: ../multiload/multiload.c:179 88 | msgid "N_ice" 89 | msgstr "Ni_ce" 90 | 91 | #: ../multiload/multiload.c:179 92 | msgid "I_OWait" 93 | msgstr "IO_Wait" 94 | 95 | #: ../multiload/multiload.c:180 96 | msgid "Idl_e" 97 | msgstr "N_ečinný" 98 | 99 | #: ../multiload/multiload.c:182 100 | msgid "_Memory" 101 | msgstr "Pa_měť" 102 | 103 | #: ../multiload/multiload.c:182 104 | msgid "Memory" 105 | msgstr "Paměť" 106 | 107 | #: ../multiload/multiload.c:183 108 | msgid "_Shared" 109 | msgstr "Sdí_lené" 110 | 111 | #: ../multiload/multiload.c:184 112 | msgid "_Buffers" 113 | msgstr "_Buffery" 114 | 115 | #: ../multiload/multiload.c:184 116 | msgid "Cach_ed" 117 | msgstr "C_ache" 118 | 119 | #: ../multiload/multiload.c:185 ../multiload/multiload.c:192 120 | msgid "_Free" 121 | msgstr "V_olno" 122 | 123 | #: ../multiload/multiload.c:187 124 | msgid "_Network" 125 | msgstr "_Síť" 126 | 127 | #: ../multiload/multiload.c:187 128 | msgid "Network" 129 | msgstr "Síť" 130 | 131 | #: ../multiload/multiload.c:188 132 | msgid "_In" 133 | msgstr "Vst_up" 134 | 135 | #: ../multiload/multiload.c:188 136 | msgid "O_ut" 137 | msgstr "Výs_tup" 138 | 139 | #: ../multiload/multiload.c:189 140 | msgid "L_ocal" 141 | msgstr "Lo_kální" 142 | 143 | #: ../multiload/multiload.c:189 ../multiload/multiload.c:195 144 | #: ../multiload/multiload.c:199 145 | msgid "_Background" 146 | msgstr "_Pozadí" 147 | 148 | #: ../multiload/multiload.c:191 149 | msgid "S_wap Space" 150 | msgstr "Odkládací prostor" 151 | 152 | #: ../multiload/multiload.c:191 153 | msgid "Swap Space" 154 | msgstr "Odkládací prostor" 155 | 156 | #: ../multiload/multiload.c:192 157 | msgid "_Used" 158 | msgstr "_Použito" 159 | 160 | #: ../multiload/multiload.c:194 161 | msgid "_Load" 162 | msgstr "Zá_těž" 163 | 164 | #: ../multiload/multiload.c:194 165 | msgid "Load Average" 166 | msgstr "Průměrná zátěž" 167 | 168 | #: ../multiload/multiload.c:195 169 | msgid "A_verage" 170 | msgstr "P_růměr" 171 | 172 | #: ../multiload/multiload.c:197 173 | msgid "_Disk" 174 | msgstr "_Disk" 175 | 176 | #: ../multiload/multiload.c:197 177 | msgid "Disk" 178 | msgstr "Disk" 179 | 180 | #: ../multiload/multiload.c:198 181 | msgid "_Read" 182 | msgstr "Č_tení" 183 | 184 | #: ../multiload/multiload.c:198 185 | msgid "Wr_ite" 186 | msgstr "_Zápis" 187 | 188 | #: ../multiload/netspeed.c:43 189 | #, c-format 190 | msgid "%s/s" 191 | msgstr "%s/s" 192 | 193 | #: ../multiload/properties.c:280 194 | msgid "Monitored Resources" 195 | msgstr "Monitorované zdroje" 196 | 197 | #: ../multiload/properties.c:330 198 | msgid "Options" 199 | msgstr "Volby" 200 | 201 | #: ../multiload/properties.c:359 202 | msgid "Wid_th: " 203 | msgstr "_Šířka" 204 | 205 | #: ../multiload/properties.c:361 206 | msgid "Heigh_t: " 207 | msgstr "_Výška:" 208 | 209 | #: ../multiload/properties.c:391 210 | msgid "pixels" 211 | msgstr "pixelů" 212 | 213 | #: ../multiload/properties.c:399 214 | msgid "Upd_ate interval: " 215 | msgstr "_Interval aktualizace:" 216 | 217 | #. if ( ! key_writable (ma->applet, "speed")) { 218 | #. hard_set_sensitive (label, FALSE); 219 | #. hard_set_sensitive (hbox, FALSE); 220 | #. } 221 | #: ../multiload/properties.c:423 222 | msgid "milliseconds" 223 | msgstr "milisekund" 224 | 225 | #: ../multiload/properties.c:432 226 | msgid "Colors" 227 | msgstr "Barvy" 228 | 229 | #: ../xfce4/xfce4-multiload-dialogs.c:56 230 | #: ../lxpanel/lxpanel-multiload-plugin.c:224 231 | #, c-format 232 | msgid "Unable to open the following url: %s" 233 | msgstr "Není možné otevřít následující url: %s" 234 | 235 | #: ../xfce4/xfce4-multiload-dialogs.c:100 236 | #: ../xfce4/xfce4-multiload-dialogs.c:138 ../xfce4/multiload.desktop.in.h:1 237 | #: ../lxpanel/lxpanel-multiload-plugin.c:262 238 | #: ../lxpanel/lxpanel-multiload-plugin.c:307 239 | msgid "Multiload" 240 | msgstr "Multiload" 241 | 242 | #: ../xfce4/xfce4-multiload-dialogs.c:140 ../xfce4/multiload.desktop.in.h:2 243 | #: ../lxpanel/lxpanel-multiload-plugin.c:309 244 | msgid "" 245 | "A system load monitor that graphs processor, memory, and swap space use, " 246 | "plus network and disk activity." 247 | msgstr "" 248 | "Monitor zátěže systému, který zobrazuje procesor, paměť, využití odkládacího " 249 | "místa, síťovou a diskovou aktivitu." 250 | 251 | #: ../xfce4/xfce4-multiload-dialogs.c:143 252 | msgid "Copyright © 1999-2012 nandhp, FSF, and others" 253 | msgstr "Copyright © 1999-2012 nandhp, FSF a další" 254 | 255 | #. "documenters", about_data_documenters, 256 | #: ../xfce4/xfce4-multiload-dialogs.c:147 257 | msgid "translator-credits" 258 | msgstr "Jan Breuer " 259 | -------------------------------------------------------------------------------- /xfce4/Makefile.am: -------------------------------------------------------------------------------- 1 | # INCLUDES = 2 | AM_CPPFLAGS = \ 3 | -I$(top_srcdir) \ 4 | -I$(top_srcdir)/multiload \ 5 | -DG_LOG_DOMAIN=\"xfce4-multiload-plugin\" \ 6 | -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ 7 | $(PLATFORM_CPPFLAGS) 8 | 9 | # 10 | # multiload plugin 11 | # 12 | plugin_LTLIBRARIES = \ 13 | libmultiload.la 14 | 15 | plugindir = \ 16 | $(libdir)/xfce4/panel/plugins 17 | 18 | libmultiload_la_SOURCES = \ 19 | ../about-data.h \ 20 | xfce4-multiload-plugin.c xfce4-multiload-plugin.h \ 21 | xfce4-multiload-dialogs.c xfce4-multiload-dialogs.h \ 22 | xfce4-multiload-settings.c xfce4-multiload-settings.h 23 | 24 | libmultiload_la_CFLAGS = \ 25 | $(GTK_CFLAGS) \ 26 | $(XFCE4_CFLAGS) $(XFCE4UI_CFLAGS) $(XFCEGUI4_CFLAGS) 27 | 28 | libmultiload_la_LDFLAGS = \ 29 | -avoid-version \ 30 | -module \ 31 | -no-undefined \ 32 | -export-symbols-regex '^xfce_panel_(module_(preinit|init|construct)|plugin_get_(check|construct))' \ 33 | $(PLATFORM_LDFLAGS) 34 | 35 | libmultiload_la_LIBADD = \ 36 | $(GTK_LIBS) \ 37 | $(XFCE4_LIBS) $(XFCE4UI_LIBS) $(XFCEGUI4_LIBS) \ 38 | ../multiload/multiload-core.la 39 | 40 | # 41 | # Desktop file 42 | # 43 | if XFCE_IS_4_6 44 | desktopdir = \ 45 | $(datadir)/xfce4/panel-plugins 46 | else 47 | desktopdir = \ 48 | $(datadir)/xfce4/panel/plugins 49 | endif 50 | 51 | desktop_DATA = \ 52 | multiload.desktop 53 | 54 | @INTLTOOL_DESKTOP_RULE@ 55 | 56 | EXTRA_DIST = \ 57 | multiload.desktop.in.in 58 | 59 | CLEANFILES = \ 60 | $(desktop_DATA) 61 | 62 | DISTCLEANFILES = \ 63 | multiload.desktop.in 64 | 65 | # vi:set ts=8 sw=8 noet ai nocindent syntax=automake: 66 | -------------------------------------------------------------------------------- /xfce4/multiload.desktop.in.in: -------------------------------------------------------------------------------- 1 | [Xfce Panel] 2 | Type=X-XFCE-PanelPlugin 3 | Encoding=UTF-8 4 | _Name=Multiload 5 | _Comment=A system load monitor that graphs processor, memory, and swap space use, plus network and disk activity. 6 | Icon=utilities-system-monitor 7 | X-XFCE-Module=multiload 8 | X-XFCE-Internal=false 9 | X-XFCE-Unique=false 10 | X-XFCE-Module-Path=@LIBDIR@/xfce4/panel/plugins 11 | -------------------------------------------------------------------------------- /xfce4/xfce4-multiload-dialogs.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * 3 | * Copyright (C) 2012 nandhp 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | #include 25 | #include 26 | 27 | #ifdef HAVE_XFCE4UI 28 | #include 29 | #elif HAVE_XFCEGUI4 30 | #include 31 | #else 32 | #error Must have one of libxfce4ui or xfcegui4 33 | #endif 34 | #include 35 | 36 | #include "multiload.h" 37 | #include "properties.h" 38 | #include "xfce4-multiload-plugin.h" 39 | #include "xfce4-multiload-settings.h" 40 | #include "xfce4-multiload-dialogs.h" 41 | 42 | static void 43 | multiload_configure_response (GtkWidget *dialog, 44 | gint response, 45 | MultiloadXfcePlugin *multiload) 46 | { 47 | gboolean result; 48 | 49 | if (response == GTK_RESPONSE_HELP) 50 | { 51 | /* show help */ 52 | result = g_spawn_command_line_async ("exo-open --launch WebBrowser " 53 | PLUGIN_WEBSITE, NULL); 54 | 55 | if (G_UNLIKELY (result == FALSE)) 56 | g_warning (_("Unable to open the following url: %s"), PLUGIN_WEBSITE); 57 | } 58 | else 59 | { 60 | /* remove the dialog data from the plugin */ 61 | g_object_set_data (G_OBJECT (multiload->plugin), "dialog", NULL); 62 | 63 | /* unlock the panel menu */ 64 | xfce_panel_plugin_unblock_menu (multiload->plugin); 65 | 66 | /* save the plugin */ 67 | multiload_save (multiload->plugin, &multiload->ma); 68 | 69 | /* destroy the properties dialog */ 70 | gtk_widget_destroy (dialog); 71 | } 72 | } 73 | 74 | /* Lookup the MultiloadPlugin object from the preferences dialog. */ 75 | /* Called from multiload/properties.c */ 76 | MultiloadPlugin * 77 | multiload_configure_get_plugin (GtkWidget *widget) 78 | { 79 | GtkWidget *toplevel = gtk_widget_get_toplevel (widget); 80 | MultiloadPlugin *ma = NULL; 81 | if ( G_LIKELY (gtk_widget_is_toplevel (toplevel)) ) 82 | ma = g_object_get_data(G_OBJECT(toplevel), "MultiloadPlugin"); 83 | else 84 | g_assert_not_reached (); 85 | g_assert( ma != NULL); 86 | return ma; 87 | } 88 | 89 | void 90 | multiload_configure (XfcePanelPlugin *plugin, 91 | MultiloadXfcePlugin *multiload) 92 | { 93 | GtkWidget *dialog; 94 | 95 | /* block the plugin menu */ 96 | xfce_panel_plugin_block_menu (plugin); 97 | 98 | /* create the dialog */ 99 | dialog = xfce_titled_dialog_new_with_buttons 100 | (_("Multiload"), 101 | GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))), 102 | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, 103 | GTK_STOCK_HELP, GTK_RESPONSE_HELP, 104 | GTK_STOCK_CLOSE, GTK_RESPONSE_OK, 105 | NULL); 106 | 107 | /* center dialog on the screen */ 108 | gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); 109 | 110 | /* set dialog icon */ 111 | gtk_window_set_icon_name (GTK_WINDOW (dialog), "utilities-system-monitor"); 112 | 113 | /* link the dialog to the plugin, so we can destroy it when the plugin 114 | * is closed, but the dialog is still open */ 115 | g_object_set_data (G_OBJECT (plugin), "dialog", dialog); 116 | g_object_set_data (G_OBJECT (dialog), "MultiloadPlugin", &multiload->ma); 117 | 118 | /* Initialize dialog widgets */ 119 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); 120 | gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); 121 | multiload_init_preferences(dialog, &multiload->ma); 122 | 123 | /* connect the reponse signal to the dialog */ 124 | g_signal_connect (G_OBJECT (dialog), "response", 125 | G_CALLBACK(multiload_configure_response), multiload); 126 | 127 | /* show the entire dialog */ 128 | gtk_widget_show_all (dialog); 129 | } 130 | 131 | #include "about-data.h" 132 | 133 | void 134 | multiload_about (XfcePanelPlugin *plugin) 135 | { 136 | gtk_show_about_dialog(NULL, 137 | "logo-icon-name", "utilities-system-monitor", 138 | "program-name", _("Multiload"), 139 | "version", PACKAGE_VERSION, 140 | "comments", _("A system load monitor that graphs processor, memory, " 141 | "and swap space use, plus network and disk activity."), 142 | "website", PLUGIN_WEBSITE, 143 | "copyright", _("Copyright \xC2\xA9 1999-2012 nandhp, FSF, and others"), 144 | "license", about_data_license, 145 | "authors", about_data_authors, 146 | /* "documenters", about_data_documenters, */ 147 | "translator-credits", _("translator-credits"), 148 | NULL); 149 | } 150 | -------------------------------------------------------------------------------- /xfce4/xfce4-multiload-dialogs.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * 3 | * Copyright (C) 2012 nandhp 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __XFCE4_MULTILOAD_DIALOGS_H__ 21 | #define __XFCE4_MULTILOAD_DIALOGS_H__ 22 | 23 | G_BEGIN_DECLS 24 | 25 | void 26 | multiload_configure (XfcePanelPlugin *plugin, 27 | MultiloadXfcePlugin *multiload); 28 | 29 | void 30 | multiload_about (XfcePanelPlugin *plugin); 31 | 32 | G_END_DECLS 33 | 34 | #endif /* !__XFCE4_MULTILOAD_DIALOGS_H__ */ 35 | -------------------------------------------------------------------------------- /xfce4/xfce4-multiload-plugin.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * 3 | * Copyright (C) 2012 nandhp 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | #ifdef HAVE_STRING_H 24 | #include 25 | #endif 26 | 27 | #include "multiload.h" 28 | #include "xfce4-multiload-plugin.h" 29 | #include "xfce4-multiload-dialogs.h" 30 | #include "xfce4-multiload-settings.h" 31 | 32 | /* prototypes */ 33 | static void 34 | multiload_construct (XfcePanelPlugin *plugin); 35 | 36 | /* register the plugin */ 37 | #ifdef XFCE_PANEL_PLUGIN_REGISTER 38 | XFCE_PANEL_PLUGIN_REGISTER (multiload_construct); /* Xfce 4.8 */ 39 | #else 40 | XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (multiload_construct); /* Xfce 4.6 */ 41 | #endif 42 | 43 | static MultiloadXfcePlugin * 44 | multiload_new (XfcePanelPlugin *plugin) 45 | { 46 | MultiloadXfcePlugin *multiload; 47 | GtkOrientation orientation; 48 | 49 | /* allocate memory for the plugin structure */ 50 | multiload = panel_slice_new0 (MultiloadXfcePlugin); 51 | 52 | /* pointer to plugin */ 53 | multiload->plugin = plugin; 54 | 55 | /* read the user settings */ 56 | multiload_read (plugin, &multiload->ma); 57 | 58 | /* create a container widget */ 59 | multiload->ebox = gtk_event_box_new (); 60 | gtk_widget_show (multiload->ebox); 61 | 62 | /* get the current orientation */ 63 | orientation = xfce_panel_plugin_get_orientation (plugin); 64 | 65 | /* Initialize the applet */ 66 | multiload->ma.container = GTK_CONTAINER(multiload->ebox); 67 | multiload_refresh(&(multiload->ma), orientation); 68 | 69 | return multiload; 70 | } 71 | 72 | static void 73 | multiload_free (XfcePanelPlugin *plugin, 74 | MultiloadXfcePlugin *multiload) 75 | { 76 | GtkWidget *dialog; 77 | 78 | /* check if the dialog is still open. if so, destroy it */ 79 | dialog = g_object_get_data (G_OBJECT (plugin), "dialog"); 80 | if (G_UNLIKELY (dialog != NULL)) 81 | gtk_widget_destroy (dialog); 82 | 83 | multiload_destroy (&multiload->ma); 84 | 85 | /* destroy the panel widgets */ 86 | gtk_widget_destroy (multiload->ebox); 87 | 88 | /* cleanup the settings (FIXME) */ 89 | 90 | /* free the plugin structure */ 91 | panel_slice_free (MultiloadXfcePlugin, multiload); 92 | } 93 | 94 | static void 95 | multiload_orientation_changed (XfcePanelPlugin *plugin, 96 | GtkOrientation orientation, 97 | MultiloadPlugin *ma) 98 | { 99 | /* Get the plugin's current size request */ 100 | gint size = -1, size_alt = -1; 101 | gtk_widget_get_size_request (GTK_WIDGET (plugin), &size, &size_alt); 102 | if ( size < 0 ) 103 | size = size_alt; 104 | 105 | /* Rotate the plugin size to the new orientation */ 106 | if ( orientation == GTK_ORIENTATION_HORIZONTAL) 107 | gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size); 108 | else 109 | gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1); 110 | 111 | multiload_refresh(ma, orientation); 112 | } 113 | 114 | static gboolean 115 | multiload_size_changed (XfcePanelPlugin *plugin, 116 | gint size, 117 | MultiloadPlugin *ma) 118 | { 119 | 120 | /* get the orientation of the plugin */ 121 | GtkOrientation orientation = xfce_panel_plugin_get_orientation (plugin); 122 | 123 | /* set the widget size */ 124 | if ( orientation == GTK_ORIENTATION_HORIZONTAL) 125 | gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size); 126 | else 127 | gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1); 128 | 129 | multiload_refresh(ma, orientation); 130 | 131 | /* we handled the orientation */ 132 | return TRUE; 133 | } 134 | 135 | static void 136 | multiload_construct (XfcePanelPlugin *plugin) 137 | { 138 | MultiloadXfcePlugin *multiload; 139 | 140 | /* Initialize multiload */ 141 | multiload_init (); 142 | 143 | /* setup transation domain */ 144 | xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); 145 | 146 | /* create the plugin */ 147 | multiload = multiload_new (plugin); 148 | 149 | /* add the ebox to the panel */ 150 | gtk_container_add (GTK_CONTAINER (plugin), multiload->ebox); 151 | 152 | /* show the panel's right-click menu on this ebox */ 153 | xfce_panel_plugin_add_action_widget (plugin, multiload->ebox); 154 | 155 | /* connect plugin signals */ 156 | g_signal_connect (G_OBJECT (plugin), "free-data", 157 | G_CALLBACK (multiload_free), multiload); 158 | 159 | g_signal_connect (G_OBJECT (plugin), "save", 160 | G_CALLBACK (multiload_save), &multiload->ma); 161 | 162 | g_signal_connect (G_OBJECT (plugin), "size-changed", 163 | G_CALLBACK (multiload_size_changed), &multiload->ma); 164 | 165 | g_signal_connect (G_OBJECT (plugin), "orientation-changed", 166 | G_CALLBACK (multiload_orientation_changed), &multiload->ma); 167 | 168 | /* show the configure menu item and connect signal */ 169 | xfce_panel_plugin_menu_show_configure (plugin); 170 | g_signal_connect (G_OBJECT (plugin), "configure-plugin", 171 | G_CALLBACK (multiload_configure), multiload); 172 | 173 | /* show the about menu item and connect signal */ 174 | xfce_panel_plugin_menu_show_about (plugin); 175 | g_signal_connect (G_OBJECT (plugin), "about", 176 | G_CALLBACK (multiload_about), NULL); 177 | /* FIXME: void xfce_panel_plugin_menu_insert_item (XfcePanelPlugin *plugin, 178 | GtkMenuItem *item); 179 | */ 180 | } 181 | -------------------------------------------------------------------------------- /xfce4/xfce4-multiload-plugin.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * 3 | * Copyright (C) 2012 nandhp 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __XFCE4_MULTILOAD_PLUGIN_H__ 21 | #define __XFCE4_MULTILOAD_PLUGIN_H__ 22 | 23 | #include "multiload.h" 24 | #include 25 | #include 26 | 27 | G_BEGIN_DECLS 28 | 29 | typedef struct _MultiloadXfcePlugin MultiloadXfcePlugin; 30 | 31 | struct _MultiloadXfcePlugin 32 | { 33 | MultiloadPlugin ma; 34 | 35 | /* panel widgets */ 36 | XfcePanelPlugin *plugin; 37 | GtkWidget *ebox; 38 | }; 39 | 40 | G_END_DECLS 41 | 42 | #endif /* !__XFCE4_MULTILOAD_PLUGIN_H__ */ 43 | -------------------------------------------------------------------------------- /xfce4/xfce4-multiload-settings.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * 3 | * Copyright (C) 2012 nandhp 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | #ifdef HAVE_STRING_H 24 | #include 25 | #endif 26 | 27 | #include "multiload.h" 28 | #include "xfce4-multiload-plugin.h" 29 | #include "xfce4-multiload-dialogs.h" 30 | 31 | void 32 | multiload_save (XfcePanelPlugin *plugin, 33 | MultiloadPlugin *ma) 34 | { 35 | XfceRc *rc; 36 | gchar *file; 37 | guint i; 38 | 39 | /* get the config file location */ 40 | file = xfce_panel_plugin_save_location (plugin, TRUE); 41 | 42 | if (G_UNLIKELY (file == NULL)) 43 | { 44 | DBG ("Failed to open config file"); 45 | return; 46 | } 47 | 48 | /* open the config file, read/write */ 49 | rc = xfce_rc_simple_open (file, FALSE); 50 | g_free (file); 51 | 52 | if (G_LIKELY (rc != NULL)) 53 | { 54 | /* save the settings */ 55 | DBG("."); 56 | 57 | /* Write size and speed */ 58 | xfce_rc_write_int_entry (rc, "speed", ma->speed); 59 | xfce_rc_write_int_entry (rc, "size", ma->size); 60 | 61 | for ( i = 0; i < NGRAPHS; i++ ) 62 | { 63 | char *key, list[8*MAX_COLORS]; 64 | 65 | /* Visibility */ 66 | key = g_strdup_printf("%s_visible", graph_types[i].name); 67 | xfce_rc_write_bool_entry (rc, key, ma->graph_config[i].visible); 68 | g_free (key); 69 | 70 | /* Save colors */ 71 | multiload_colorconfig_stringify (ma, i, list); 72 | key = g_strdup_printf("%s_colors", graph_types[i].name); 73 | xfce_rc_write_entry (rc, key, list); 74 | g_free (key); 75 | } 76 | 77 | /* close the rc file */ 78 | xfce_rc_close (rc); 79 | } 80 | } 81 | 82 | void 83 | multiload_read (XfcePanelPlugin *plugin, 84 | MultiloadPlugin *ma) 85 | { 86 | XfceRc *rc; 87 | gchar *file; 88 | guint i, found = 0; 89 | 90 | /* get the plugin config file location */ 91 | file = xfce_panel_plugin_lookup_rc_file (plugin); 92 | 93 | if (G_LIKELY (file != NULL)) 94 | { 95 | /* open the config file, readonly */ 96 | rc = xfce_rc_simple_open (file, TRUE); 97 | 98 | /* cleanup */ 99 | g_free (file); 100 | 101 | if (G_LIKELY (rc != NULL)) 102 | { 103 | /* Read speed and size */ 104 | ma->speed = xfce_rc_read_int_entry(rc, "speed", DEFAULT_SPEED); 105 | ma->size = xfce_rc_read_int_entry(rc, "size", DEFAULT_SIZE); 106 | 107 | /* Read visibility and colors for each graph */ 108 | for ( i = 0; i < NGRAPHS; i++ ) 109 | { 110 | char *key; 111 | const char *list; 112 | 113 | /* Visibility */ 114 | key = g_strdup_printf("%s_visible", graph_types[i].name); 115 | ma->graph_config[i].visible = 116 | xfce_rc_read_bool_entry(rc, key, i == 0 ? TRUE : FALSE); 117 | g_free (key); 118 | 119 | /* Colors - Try to load from xfconf */ 120 | key = g_strdup_printf("%s_colors", graph_types[i].name); 121 | list = xfce_rc_read_entry (rc, key, NULL); 122 | g_free (key); 123 | multiload_colorconfig_unstringify(ma, i, list); 124 | } 125 | 126 | /* cleanup */ 127 | xfce_rc_close (rc); 128 | 129 | /* Ensure at lease one graph is visible */ 130 | for ( i = 0; i < NGRAPHS; i++ ) 131 | if ( ma->graph_config[i].visible == TRUE ) 132 | found++; 133 | if ( found == 0 ) 134 | ma->graph_config[0].visible = TRUE; 135 | 136 | /* leave the function, everything went well */ 137 | return; 138 | } 139 | } 140 | 141 | /* something went wrong, apply default values */ 142 | DBG ("Applying default settings"); 143 | 144 | ma->speed = DEFAULT_SPEED; 145 | ma->size = DEFAULT_SIZE; 146 | for ( i = 0; i < NGRAPHS; i++ ) 147 | { 148 | /* Default visibility and colors */ 149 | ma->graph_config[i].visible = i == 0 ? TRUE : FALSE; 150 | multiload_colorconfig_default(ma, i); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /xfce4/xfce4-multiload-settings.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * 3 | * Copyright (C) 2012 nandhp 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __XFCE4_MULTILOAD_SETTINGS_H__ 21 | #define __XFCE4_MULTILOAD_SETTINGS_H__ 22 | 23 | #include "multiload.h" 24 | #include 25 | #include 26 | 27 | G_BEGIN_DECLS 28 | 29 | void 30 | multiload_save (XfcePanelPlugin *plugin, 31 | MultiloadPlugin *ma); 32 | 33 | G_GNUC_INTERNAL void 34 | multiload_read (XfcePanelPlugin *plugin, 35 | MultiloadPlugin *ma); 36 | 37 | G_END_DECLS 38 | 39 | #endif /* !__XFCE4_MULTILOAD_SETTINGS_H__ */ 40 | --------------------------------------------------------------------------------