gkrellm-leds-0.8.0/0040700000175000001440000000000007612402417013405 5ustar madhackusersgkrellm-leds-0.8.0/Changelog0100644000175000001440000000642207571734405015243 0ustar madhackusers0.2.0: * initial release 0.2.1: * cleaned up Makefile and added test and install_sys * slight modification to pixmaps * got rid of some memory waste * removed set_led_state and updated update_plugin accordingly * rearranged directory and file structure * placed in CVS(local only) * updated documentation 0.4.0: * added configuration tab with: - about tab on license, version, etc. - info tab on gkleds and how to configure it - options tab : + margin adjustment + image size + order and presence + image selection * changed pixmap structure, se Themes for details * fixed panel masking bug * fixed memory leakage * added plugin functions create_plugin_config, apply_plugin_config, save_plugin_config, load_plugin_config * added callback functions spin_misc_changed, spin_order_changed, radio_pm_idx_toggled, button_pm_clicked * added config struct and copy_config 0.4.1: * fixed pixmap_unref bug which caused gkrellm to crash, when enable plugin was clicked repeatedly. first_create works differently then one would think, so we can't trust it. When renabling it sets first_create = 0 and gives you rubbish decals but intact signals. go figure (but I suspect imlib1 is to blame). 0.4.2: * fixed(hopefully) all pixmap, image and decal unref bugs. * fixed image memory leakage * fixed height configuration bug * fixed leds positioning bug * fixed panel_exposed bug on vis == 0 at startup * fixed a gdkwindow bug which caused gkrellm to crash for vis == 0 * added debugging info, modified test in Makefile 0.6.0: * improved existing subimages, added new ones * added gkrellmrc support for number of subimages * added feedback on image selection * changed image selection from radio buttons to combo boxes. * added the ability to change indicator state by mouse click * fixed divide by zero bug, if chart_width < 0 (never? happens) * cleaned up led positioning code * cleaned up spin_order_changed code+bug * added callback set_indicators * added function configure_indicators * removed radio_pm_idx_toggled * renamed update_plugin to get_indicators 0.6.1: * added make install_theme/uninstall_theme for example theme * changed installation to make install(checks for uid)/uninstall * added get indicator mask by name, for portability * added config for which mouse button sets led state * theme images now adds to, instead of replacing, the embedded images * changed from label/separators to labeled frames in conf tab * fixed about_text mem leakage * fixed keyevent bug when led not visible * fixed empty pixmap bug in config when numlock bg_off was none * fixed decals bug when masks/pixmaps were NULL * removed icon from about tab(only wasting space) * general code cleanup(esp. gtk code) * rewrote led drawing code * renamed callback button_pm_clicked to pm_idx_altered * added callback combo_mb_panel_changed 0.8.0: * now supports GkrellM 2.x * got rid off all imlib functions, replaced with gkrellm* and gdk* * added locale->utf8 convert for about_text * moved all info in INSTALL to README (will put generic configure info in INSTALL) * removed make uninstall, make install_theme and make uninstall_theme in Makefile * removed option to use later version of the GNU GPL in License++ * removed info on example theme in Themes gkrellm-leds-0.8.0/COPYING0100644000175000001440000004313107475410222014451 0ustar madhackusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. gkrellm-leds-0.8.0/License0100644000175000001440000000137407571155663014742 0ustar madhackusersgkleds is copyright (C) 2002 by Øyvind Hagen and released under the GNU General Public License Version 2. Please refer to COPYING for details. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License Version 2 along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. gkrellm-leds-0.8.0/Makefile0100644000175000001440000000237707571721720015072 0ustar madhackusersSHELL = /bin/sh VPATH = src:src/pixmaps GTK_INCLUDE = `pkg-config gtk+-2.0 --cflags` GTK_LIB = `pkg-config gtk+-2.0 --libs` X11_LIB = -L/usr/X11R6/lib -lX11 -lXtst LIBS = $(GTK_LIB) $(X11_LIB) DEFINES = LFLAGS = -shared INCLUDES = $(GTK_INCLUDE) CFLAGS = -ansi -pedantic -Wall -O2 -fPIC CC = gcc SRCS = gkleds.c HDRS = gkleds.h OBJS = gkleds.o IMAGES = leds.xpm INSTALL_PROG = install .PHONY : clean .PHONY : install .PHONY : uninstall .PHONY : test #======================================================================= #======================================================================= gkleds.so : $(OBJS) $(CC) $(LFLAGS) $(LIBS) -o $@ $< gkleds.o : $(SRCS) $(HDRS) $(IMAGES) $(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -c -o $@ $< test : $(MAKE) clean $(MAKE) DEFINES="-DGKLEDS_DEBUG" gkrellm --sync --demo -p gkleds.so $(MAKE) clean clean: rm -rf *.o *.so* *~ \#* rm -rf src/*~ src/\#* install : gkleds.so @ if [ $$UID -ne 0 ]; \ then PLUGIN_DIR=$$HOME/.gkrellm2/plugins; \ elif [ -e /usr/bin/gkrellm ]; \ then PLUGIN_DIR=/usr/lib/gkrellm2/plugins; \ else \ PLUGIN_DIR=/usr/local/lib/gkrellm2/plugins; \ fi; \ $(INSTALL_PROG) -d $$PLUGIN_DIR; \ $(INSTALL_PROG) -s gkleds.so $$PLUGIN_DIR; \ printf "\ngkleds installed in $$PLUGIN_DIR\n" gkrellm-leds-0.8.0/INSTALL0100644000175000001440000000000007571154050014434 0ustar madhackusersgkrellm-leds-0.8.0/Themes0100644000175000001440000000173507571153676014610 0ustar madhackusersgkleds can be themed by making the following image and placing it into a "gkleds" subdirectory of a theme: - leds.png : contains all subimages which makes up the LEDs. The image may be of type png, xpm or jpeg. This image consists of any number of vertically stacked subimages. The subimages must be the same width and height. If not, then they will be displayed wrongly. Transparency is supported(and encouraged). You must also tell gkleds how many subimages there are(again, they will be displayed wrongly if you don't). This is done in the gkrellmrc file: set_integer gkleds_num_img = n If you don't set "gkleds_num_img", then the default hardcoded define "GKLEDS_NUM_IMG" will be used. If your "gkleds_num_img" is less then "GKLEDS_NUM_IMG"(or some other themes "gkleds_num_img") and a theme change occures, the following will happen: If a previously selected subimage has an index(into leds.png) higher than your "gkleds_num_img", then that subimage will be set to "none". gkrellm-leds-0.8.0/src/0040700000175000001440000000000007612402417014174 5ustar madhackusersgkrellm-leds-0.8.0/src/gkleds.c0100644000175000001440000010522707571731451015636 0ustar madhackusers/* Copyright (C) 2002 Øyvind Hagen */ /* This file is part of gkleds. */ /* gkleds is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License Version 2 as */ /* published by the Free Software Foundation */ /* gkleds is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License */ /* along with gkleds; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* gkrellm already includes several libs */ #include #include #include #include #include #include "gkleds.h" #include "pixmaps/leds.xpm" static GkrellmMonitor gkleds_mon = { GKLEDS_NAME, /* Name, for config tab. */ 0, /* Id, 0 if a plugin */ create_plugin, /* The create_plugin() function */ get_indicators, /* The update_plugin() function */ create_plugin_config, /* The create_plugin_tab() config function */ apply_plugin_config, /* The apply_plugin_config() function */ save_plugin_config, /* The save_plugin_config() function */ load_plugin_config, /* The load_plugin_config() function */ GKLEDS_CONFIG, /* config keyword */ NULL, /* Undefined 2 */ NULL, /* Undefined 1 */ NULL, /* Undefined 0 */ GKLEDS_PLACEMENT, /* Insert plugin before this monitor */ NULL, /* Handle if a plugin, filled in by GKrellM */ NULL /* path if a plugin, filled in by GKrellM */ }; /* default config */ static gkleds_user_conf conf = { {2, 2, 2, 0}, {0, 0}, {6, 0, 7, 0, 6 ,1, 7, 1, 6, 2, 7, 2}, {1, 2, 3}, 0, GKLEDS_NUM_IMG }; static gkleds_user_conf na_conf; static gkleds_indicator_conf ind_conf; static GkrellmPanel *panel; static GkrellmDecal *decals[GKLEDS_NUM_IND]; static GkrellmMonitor *monitor; static gint style_id; static GtkWidget *gk_vbox; static GtkWidget *keys_spin[3]; static GtkWidget *combos[2]; static GtkWidget *pmfb_wid; static GdkPixmap *pixmaps; static GdkBitmap *masks; static gint panel_expose_event(GtkWidget *widget, GdkEventExpose *ev){ /* redraw only the exposed area */ #ifdef GKLEDS_DEBUG printf("panel_expose_event: start/end\n"); fflush(stdout); #endif if(widget == panel->drawing_area) gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], panel->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); return FALSE; } static void configure_indicators(gkleds_indicator_conf *ind){ int i, j, mask; char *ind_name = NULL; char *lock_names[GKLEDS_NUM_IND] = {"Num Lock","Caps Lock", "Scroll Lock"}; int key_syms[GKLEDS_NUM_IND] = {XK_Num_Lock, XK_Caps_Lock, XK_Scroll_Lock}; XkbDescPtr xkb; #ifdef GKLEDS_DEBUG printf("configure_indicators: start\n"); fflush(stdout); #endif /* we need a display handler to get/set indicator status */ ind->dpy = XOpenDisplay(NULL); if(!ind->dpy){ printf("gkrellm::%s : unable to connect to the X server\n", GKLEDS_NAME); printf("gkrellm::%s : you won't be able to get/set indicator status\n", GKLEDS_NAME); return; } /* get the keycode for set_indicators */ for(i = 0; i < GKLEDS_NUM_IND; i++) ind->keys[i] = XKeysymToKeycode(ind->dpy, key_syms[i]); /* get a keyboard structure */ xkb = XkbAllocKeyboard(); if(!xkb){ printf("gkrellm::%s : unable to allocate keyboard structure\n", GKLEDS_NAME); printf("gkrellm::%s : you won't be able to get/set indicator status\n", GKLEDS_NAME); XCloseDisplay(ind->dpy); ind->dpy = NULL; return; } /* get the names(atoms) of the indicators */ if(XkbGetNames(ind->dpy, XkbIndicatorNamesMask, xkb) != Success){ printf("gkrellm::%s : unable to get indicator names from the X server\n", GKLEDS_NAME); printf("gkrellm::%s : you won't be able to get/set indicator status\n", GKLEDS_NAME); XkbFreeKeyboard(xkb, 0, True); XCloseDisplay(ind->dpy); ind->dpy = NULL; return; } /* get the correct mask & shift for get_indicators */ for(i = 0; i < XkbNumIndicators; i++){ if(xkb->names->indicators[i]) ind_name = XGetAtomName(ind->dpy, xkb->names->indicators[i]); #ifdef GKLEDS_DEBUG if(ind_name) printf("configure_indicators: %s\n", ind_name); fflush(stdout); #endif for(j = 0; j < GKLEDS_NUM_IND; j++){ if(ind_name && !strcmp(lock_names[j], ind_name)){ if(XkbGetNamedIndicator(ind->dpy, xkb->names->indicators[i], &mask, NULL, NULL, NULL) == True){ #ifdef GKLEDS_DEBUG printf("configure_indicators: mask %d: %d\n", i, mask); fflush(stdout); #endif ind->masks[j] = 1 << mask; ind->idx[j] = mask; }else{ printf("gkrellm::%s : unable to get the indicator mask from the X " "server\n", GKLEDS_NAME); printf("gkrellm::%s : you won't be able to get/set indicator " "status\n", GKLEDS_NAME); XkbFreeKeyboard(xkb, 0, True); XCloseDisplay(ind->dpy); ind->dpy = NULL; return; } } } if(ind_name){ free(ind_name); ind_name = NULL; } } XkbFreeKeyboard(xkb, 0, True); #ifdef GKLEDS_DEBUG printf("configure_indicators: end\n"); fflush(stdout); #endif return; } static void set_indicators(GtkWidget *widget, GdkEventButton *ev){ int i; #ifdef GKLEDS_DEBUG printf("set_indicators: start\n"); fflush(stdout); #endif if(!ind_conf.dpy) return; if(widget != panel->drawing_area || (ev->y < ind_conf.y || ev->y > ind_conf.y+ind_conf.h)) return; #ifdef GKLEDS_DEBUG printf("set_indicators: ev->button: %d\n", ev->button); printf("set_indicators: mb_panel: %d\n", conf.mb_panel); fflush(stdout); #endif if((conf.mb_panel != 0) && (ev->button != conf.mb_panel)) return; /* find out if a led has been clicked. if so, then set it */ /* generating a key event is a nice, low cost way of setting it */ for(i = 0; i < GKLEDS_NUM_IND; i++){ if(conf.order[i] && (ev->x > ind_conf.led_x[i]) && (ev->x < ind_conf.led_x[i]+ind_conf.w)){ XTestFakeKeyEvent(ind_conf.dpy, ind_conf.keys[i], True, CurrentTime); XTestFakeKeyEvent(ind_conf.dpy, ind_conf.keys[i], False, CurrentTime); #ifdef GKLEDS_DEBUG printf("set_indicators: ind: %d\n", i); fflush(stdout); #endif } } #ifdef GKLEDS_DEBUG printf("set_indicators: end\n"); fflush(stdout); #endif return; } static void get_indicators(void){ unsigned int states; int i; if(!ind_conf.dpy) return; /* get the indicator status */ if(XkbGetIndicatorState(ind_conf.dpy, XkbUseCoreKbd, &states) != Success) return; /* draw the correct led state onto the panel */ for(i = 0; i < GKLEDS_NUM_IND; i++){ if(conf.order[i]) gkrellm_draw_decal_pixmap(panel, decals[i], (states & ind_conf.masks[i]) >> ind_conf.idx[i]); } gkrellm_draw_panel_layers(panel); return; } static void create_plugin(GtkWidget *vbox, gint first_create){ GkrellmStyle *style; int height, width, vis, i, j, highest_order, num_img, tmp; int pos[GKLEDS_NUM_IND+1]; int chart_width = gkrellm_chart_width(); gboolean theme_found; GkrellmPiximage *leds_img = NULL; GdkPixmap *subpixmap = NULL; GdkBitmap *submask = NULL; GdkGC *mask_gc, *pixmap_gc; GdkColor color; #ifdef GKLEDS_DEBUG GtkWidget *window; GtkWidget *pm_wid; printf("create_plugin: start\n"); fflush(stdout); #endif if(first_create){ configure_indicators(&ind_conf); panel = gkrellm_panel_new0(); gk_vbox = vbox; }else{ gkrellm_destroy_decal_list(panel); } /* theme configuration */ style = gkrellm_meter_style(style_id); theme_found = gkrellm_load_piximage("leds", leds_xpm, &leds_img, GKLEDS_NAME); if(gkrellm_get_gkrellmrc_integer("gkleds_num_img", &num_img)){ conf.num_img = num_img + GKLEDS_NUM_IMG; }else{ theme_found = FALSE; leds_img = gkrellm_piximage_new_from_xpm_data(leds_xpm); } #ifdef GKLEDS_DEBUG printf("create_plugin: before sizing\n"); fflush(stdout); #endif /* set the correct width/height for image scaling */ if(conf.size[0] > 0) width = conf.size[0]; else width = gdk_pixbuf_get_width(leds_img->pixbuf); if(conf.size[1] > 0){ height = conf.size[1]; }else{ if(theme_found) height = (int) gdk_pixbuf_get_height(leds_img->pixbuf) / num_img; else height = (int) gdk_pixbuf_get_height(leds_img->pixbuf) / GKLEDS_NUM_IMG; } /* number of visible leds */ for(vis = 0, i = 0; i < GKLEDS_NUM_IND; i++) if(conf.order[i] > 0) vis++; /* constrain to chart width */ if(vis && (width * vis > chart_width)) width = (int) (chart_width)/vis; #ifdef GKLEDS_DEBUG printf("create_plugin: before combine\n"); fflush(stdout); #endif /* combine theme pixmap and embedded pixmap */ pixmaps = gdk_pixmap_new(vbox->window, width, height*conf.num_img, -1); masks = gdk_pixmap_new(NULL, width, height*conf.num_img, 1); mask_gc = gdk_gc_new(masks); pixmap_gc = gdk_gc_new(pixmaps); /* pixmap_new doesn't clear, we have to clear it for the mask */ /* to get the transperancy correct */ gdk_color_black(gdk_colormap_get_system(), &color); gdk_gc_set_foreground(mask_gc, &color); gdk_draw_rectangle(masks, mask_gc, TRUE, 0, 0, -1, -1); if(theme_found){ #ifdef GKLEDS_DEBUG printf("create_plugin: theme_img\n"); fflush(stdout); #endif gkrellm_scale_pixbuf_to_pixmap(leds_img->pixbuf, &subpixmap, &submask, width, height*num_img); if(!submask){ submask = gdk_pixmap_new(NULL, width, height*conf.num_img, 1); gdk_color_white(gdk_colormap_get_system(), &color); gdk_gc_set_foreground(mask_gc, &color); gdk_draw_rectangle(submask, mask_gc, TRUE, 0, 0, -1, -1); } gdk_draw_pixmap(pixmaps, pixmap_gc, subpixmap, 0, 0, 0, GKLEDS_NUM_IMG*height, width, num_img*height); gdk_draw_pixmap(masks, mask_gc, submask, 0, 0, 0, GKLEDS_NUM_IMG*height, width, num_img*height); gkrellm_free_pixmap(&subpixmap); gkrellm_free_bitmap(&submask); gkrellm_destroy_piximage(leds_img); leds_img = gkrellm_piximage_new_from_xpm_data(leds_xpm); } #ifdef GKLEDS_DEBUG printf("create_plugin: embedded\n"); fflush(stdout); #endif gkrellm_scale_pixbuf_to_pixmap(leds_img->pixbuf, &subpixmap, &submask, width, height*GKLEDS_NUM_IMG); gdk_draw_pixmap(pixmaps, pixmap_gc, subpixmap, 0, 0, 0, 0, width, height*GKLEDS_NUM_IMG); gdk_draw_pixmap(masks, mask_gc, submask, 0, 0, 0, 0, width, height*GKLEDS_NUM_IMG); gkrellm_free_pixmap(&subpixmap); gkrellm_free_bitmap(&submask); gkrellm_destroy_piximage(leds_img); gdk_gc_unref(pixmap_gc); gdk_gc_unref(mask_gc); #if 0 printf("create_plugin: after combine\n"); fflush(stdout); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); pm_wid = gtk_pixmap_new(pixmaps, masks); gtk_container_add(GTK_CONTAINER(window), pm_wid); gtk_widget_show(pm_wid); gtk_widget_show(window); #endif /* we have to make sure the user configuration is correct */ for(i = 0; i < GKLEDS_NUM_IND*4; i++) if(conf.pm_idx[i] >= conf.num_img) conf.pm_idx[i] = -1; for(i = 0; i < GKLEDS_NUM_IND; i++) if(conf.order[i] > GKLEDS_NUM_IND) conf.order[i] = 0; #ifdef GKLEDS_DEBUG printf("create_plugin: width: %d\n", width); printf("create_plugin: height: %d\n", height); printf("create_plugin: vis: %d\n", vis); fflush(stdout); #endif /* determine the positioning of the leds */ for(highest_order = 0, i = 0; i < GKLEDS_NUM_IND; i++) if(conf.order[i] > highest_order) highest_order = conf.order[i]; if(vis == 1){ pos[1] = conf.margin[0] + (int) (chart_width/2 - width/2) - conf.margin[1]; pos[2] = conf.margin[0] + (int) (chart_width/2 - width/2) - conf.margin[1]; pos[3] = conf.margin[0] + (int) (chart_width/2 - width/2) - conf.margin[1]; } else if(vis == 2){ pos[1] = conf.margin[0] + (int) (chart_width/3 - 4*width/6); if(highest_order == 3) pos[2] = conf.margin[0] + (int) (chart_width/3 - 4*width/6); else pos[2] = (int) (2*chart_width/3 - 2*width/6) - conf.margin[1]; pos[3] = (int) (2*chart_width/3 - 2*width/6) - conf.margin[1]; } else if(vis == 3){ pos[1] = conf.margin[0]; pos[2] = conf.margin[0] + (int) (chart_width/2 - width/2) - conf.margin[1]; pos[3] = chart_width - width - conf.margin[1]; } /* constrain to drawing area */ pos[0] = 0; for(i = 1; i < GKLEDS_NUM_IND+1; i++){ if(pos[i] < 0) pos[i] = 0; else if(pos[i] > chart_width) pos[i] = chart_width - width; #ifdef GKLEDS_DEBUG printf("create_plugin: pos[%d]: %d\n", i, pos[i]); fflush(stdout); #endif } ind_conf.w = width; ind_conf.h = height; ind_conf.y = conf.margin[2]; for(i = 0; i < GKLEDS_NUM_IND; i++) ind_conf.led_x[i] = pos[conf.order[i]]; /* we have to combine the foreground and background masks, */ /* and create a stacked mask(2*h) as well as the pixmaps. */ /* This is to get correct masking on the panel */ #ifdef GKLEDS_DEBUG printf("create_plugin: before decals\n"); if(!pixmaps) printf("create_plugin: no pixmaps\n"); fflush(stdout); if(!masks) printf("create_plugin: no masks\n"); fflush(stdout); #endif /* make the decals, create_decal cleans up pixmap/mask */ for(j = 0; j < GKLEDS_NUM_IND; j++){ if(conf.order[j]){ submask = gdk_pixmap_new(NULL, width, height * 2, 1); mask_gc = gdk_gc_new(submask); /* pixmap_new doesn't clear, we have to clear it for the mask */ gdk_color_black(gdk_colormap_get_system(), &color); gdk_gc_set_foreground(mask_gc, &color); gdk_draw_rectangle(submask, mask_gc, TRUE, 0, 0, -1, -1); gdk_gc_set_clip_mask(mask_gc, masks); subpixmap = gdk_pixmap_new(vbox->window, width, height * 2, -1); pixmap_gc = gdk_gc_new(subpixmap); gdk_gc_set_clip_mask(pixmap_gc, masks); tmp = (j + 1) * 4 - 2; #ifdef GKLEDS_DEBUG printf("create_plugin: tmp: %d\n", tmp); fflush(stdout); #endif for(i = j*4; i < (j+1)*4; i++){ if(conf.pm_idx[i] >= 0){ #ifdef GKLEDS_DEBUG printf("create_plugin: pm %d: %d\n", i, conf.pm_idx[i]); fflush(stdout); #endif gdk_gc_set_clip_origin(pixmap_gc, 0, height * (int) (i/tmp) - conf.pm_idx[i]*height); gdk_draw_pixmap(subpixmap, pixmap_gc, pixmaps, 0, conf.pm_idx[i]*height, 0, height * (int) (i/tmp), width, height); #ifdef GKLEDS_DEBUG printf("create_plugin: index %d: %d\n", i, height * (int) (i/tmp)); fflush(stdout); #endif gdk_gc_set_clip_origin(mask_gc, 0, height * (int) (i/tmp) - conf.pm_idx[i]*height); gdk_draw_pixmap(submask, mask_gc, masks, 0, conf.pm_idx[i]*height, 0, height * (int) (i/tmp), width, height); } } decals[j] = gkrellm_create_decal_pixmap(panel, subpixmap, submask, 2, style, pos[conf.order[j]], conf.margin[2]); #if 0 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); pm_wid = gtk_pixmap_new(subpixmap, submask); gtk_container_add(GTK_CONTAINER(window), pm_wid); gtk_widget_show(pm_wid); gtk_widget_show(window); #endif gdk_gc_unref(pixmap_gc); gdk_gc_unref(mask_gc); } } #ifdef GKLEDS_DEBUG printf("create_plugin: after decals\n"); fflush(stdout); #endif /* configure and create the panel */ gkrellm_panel_configure(panel, NULL, style); gkrellm_panel_configure_add_height(panel, conf.margin[3]); gkrellm_panel_create(vbox, monitor, panel); #ifdef GKLEDS_DEBUG printf("create_plugin: after panel_creation\n"); fflush(stdout); #endif if(first_create){ gtk_signal_connect(GTK_OBJECT(panel->drawing_area), "expose_event", (GtkSignalFunc) panel_expose_event, NULL); gtk_signal_connect(GTK_OBJECT(panel->drawing_area), "button_press_event", (GtkSignalFunc) set_indicators, NULL); } #ifdef GKLEDS_DEBUG printf("create_plugin: end\n"); fflush(stdout); #endif return; } static void create_plugin_config(GtkWidget *conf_vbox){ GtkWidget *tabs; GtkWidget *tab_vbox; GtkWidget *text; GtkAdjustment *adjust; GtkWidget *spin; GtkWidget *label; GtkWidget *table; GtkWidget *frame; GtkWidget *viewport; GtkWidget *scroll_bar; GtkWidget *hbox; GtkWidget *button; GtkWidget *pixmap_wid; GtkWidget *mc_combo; GList *combo_list = NULL; GdkPixmap *subpixmap; GdkBitmap *submask; GdkGC *mask_gc, *pixmap_gc; GdkColor color; int width, height, i, j; char *info_text[] = {"gkleds\n", "\tgkleds monitors the NumLock, CapsLock and ScrollLock keys\n", "\tand reports their current status via on screen LEDs.\n\n", "Margin Adjustment\n", "\tYou can adjust the top, bottom, left and right margins in\n", "\tthe options tab.\n\n", "Image Size\n", "\tYou can adjust the size of the LEDs in the options tab.\n", "\tSetting a size of zero keeps the orginal image size.\n\n", "Order and Presence\n", "\tYou can choose which LEDs that are to be present and the\n", "\torder they'll be in. Setting the order to zero means that\n", "\tthe led will not be present on the panel.\n\n", "Set Indicator\n", "\tSelect which mouse button will cause a state change to the\n", "\tvisible indicators on the panel. You can also choose to have\n", "\tall or none of the mouse buttons cause a state change\n\n", "Image Selection\n", "\tYou can choose from different combinations of images in the\n" "\toptions tab. All leds consists of four subimages. You can also\n", "\tset any of the subimages to none if you want.\n"}; char *about_text_locale = g_strdup_printf ("gkleds %s\n\n" "Copyright (C) 2002 Øyvind Hagen\n" "oyvinha@ifi.uio.no\n" "http://www.stud.ifi.uio.no/~oyvinha/gkleds\n\n" "Released under the GNU General Public Licence", GKLEDS_VERSION); char *about_text = g_locale_to_utf8(about_text_locale, -1 , NULL, NULL, NULL); char *margin_text[4] = {"Left Margin", "Right Margin", "Top Margin", "Bottom Margin"}; char *size_text[2] = {"Image Width", "Image Height"}; char *image_text[GKLEDS_NUM_IND+4] = {"NumLock", "CapsLock", "ScrollLock", "Background Off", "Foreground Off", "Background On", "Foreground On"}; char *mc_text[7] = {"None", "Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "All"}; #ifdef GKLEDS_DEBUG printf("create_plugin_config: start\n"); fflush(stdout); #endif copy_config(&conf, &na_conf); /* the notebook */ tabs = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(conf_vbox), tabs, TRUE, TRUE, 0); /* the options tab */ tab_vbox = gkrellm_gtk_framed_notebook_page(tabs, "Options"); hbox = gtk_hbox_new(FALSE, 0); /* the options tab, the margin adjustment area */ frame = gtk_frame_new("Margin Adjustment"); table = gtk_table_new(4, 2, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 5); for(i = 0; i < 4; i++){ adjust = (GtkAdjustment *) gtk_adjustment_new(0, 0, 99, 1, 5, 0); spin = gtk_spin_button_new(adjust, 1, 0); gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), na_conf.margin[i]); label = gtk_label_new(margin_text[i]); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i, i+1); gtk_table_attach_defaults(GTK_TABLE(table), spin, 1, 2, i, i+1); gtk_signal_connect(GTK_OBJECT(spin),"changed", (GtkSignalFunc) spin_misc_changed, &na_conf.margin[i]); } gtk_container_add(GTK_CONTAINER(frame), table); gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); /* the options tab, the image size area */ frame = gtk_frame_new("Image Size"); table = gtk_table_new(2, 2, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 5); for(i = 0; i < 2; i++){ adjust = (GtkAdjustment *) gtk_adjustment_new(0, 0, 99, 1, 5, 0); spin = gtk_spin_button_new(adjust, 1, 0); gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), na_conf.size[i]); label = gtk_label_new(size_text[i]); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i, i+1); gtk_table_attach_defaults(GTK_TABLE(table), spin, 1, 2, i, i+1); gtk_signal_connect(GTK_OBJECT(spin),"changed", (GtkSignalFunc) spin_misc_changed, &na_conf.size[i]); } gtk_container_add(GTK_CONTAINER(frame), table); gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); /* the options tab, the order & presence area */ frame = gtk_frame_new("Order & Presence"); table = gtk_table_new(3, 2, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 5); for(i = 0; i < 3; i++){ label = gtk_label_new(image_text[i]); adjust = (GtkAdjustment *) gtk_adjustment_new(0, 0, 3, 1, 1, 0); keys_spin[i] = gtk_spin_button_new(adjust, 1, 0); gtk_spin_button_set_value(GTK_SPIN_BUTTON(keys_spin[i]), na_conf.order[i]); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i, i+1); gtk_table_attach_defaults(GTK_TABLE(table), keys_spin[i], 1, 2, i, i+1); gtk_signal_connect(GTK_OBJECT(keys_spin[i]),"changed", (GtkSignalFunc) spin_order_changed, (int *) i); } gtk_container_add(GTK_CONTAINER(frame), table); gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(tab_vbox), hbox, FALSE, FALSE, 0); /* the options tab, the set indicator area */ frame = gtk_frame_new("Set Indicator"); table = gtk_table_new(1, 2, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 5); gtk_table_set_col_spacing(GTK_TABLE(table), 0, 20); gtk_table_set_col_spacing(GTK_TABLE(table), 1, 20); gtk_table_set_row_spacing(GTK_TABLE(table), 0, 10); label = gtk_label_new("Mouse button that will change indicator state"); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); mc_combo = gtk_combo_new(); for(i = 0; i < 7; i++){ combo_list = g_list_append(combo_list, mc_text[i]); } gtk_combo_set_popdown_strings(GTK_COMBO(mc_combo), combo_list); g_list_free(combo_list); combo_list = NULL; gtk_combo_set_value_in_list(GTK_COMBO(mc_combo), TRUE, FALSE); gtk_table_attach_defaults(GTK_TABLE(table), mc_combo, 1, 2, 0, 1); gtk_signal_connect(GTK_OBJECT(GTK_COMBO(mc_combo)->entry), "changed", GTK_SIGNAL_FUNC(combo_mb_panel_changed), NULL); gtk_container_add(GTK_CONTAINER(frame), table); gtk_box_pack_start(GTK_BOX(tab_vbox), frame, FALSE, FALSE, 0); /* the options tab, the image selection area */ frame = gtk_frame_new("Image Selection"); table = gtk_table_new(3, 3, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 5); gtk_table_set_col_spacing(GTK_TABLE(table), 0, 20); gtk_table_set_col_spacing(GTK_TABLE(table), 1, 20); gtk_table_set_row_spacing(GTK_TABLE(table), 0, 10); for(i = 0; i < 2; i++){ combos[i] = gtk_combo_new(); for(j = GKLEDS_NUM_IND*i; j < GKLEDS_NUM_IND+(4*i); j++){ combo_list = g_list_append(combo_list, image_text[j]); } gtk_combo_set_popdown_strings(GTK_COMBO(combos[i]), combo_list); g_list_free(combo_list); combo_list = NULL; gtk_combo_set_value_in_list(GTK_COMBO(combos[i]), TRUE, FALSE); gtk_table_attach_defaults(GTK_TABLE(table), combos[i], i, i+1, 0, 1); gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combos[i])->entry), "changed", GTK_SIGNAL_FUNC(pm_idx_altered), (int *) -3); } /* make feedback pixmap */ gdk_window_get_size(pixmaps, &width, &height); height = (int) height / conf.num_img; subpixmap = gdk_pixmap_new(gk_vbox->window, width, height, -1); submask = gdk_pixmap_new(NULL, width, height, 1); pixmap_gc = gdk_gc_new(subpixmap); mask_gc = gdk_gc_new(submask); gdk_color_black(gdk_colormap_get_system(), &color); gdk_gc_set_foreground(mask_gc, &color); gdk_draw_rectangle(submask, mask_gc, TRUE, 0, 0, -1, -1); if(na_conf.pm_idx[0] >= 0){ gdk_draw_pixmap(subpixmap, pixmap_gc, pixmaps, 0, na_conf.pm_idx[0]*height, 0, 0, width, height); gdk_draw_pixmap(submask, mask_gc, masks, 0, na_conf.pm_idx[0]*height, 0, 0, width, height); } pmfb_wid = gtk_pixmap_new(subpixmap, submask); gdk_pixmap_unref(subpixmap); gdk_pixmap_unref(submask); gtk_table_attach_defaults(GTK_TABLE(table), pmfb_wid, 2, 3, 0, 1); #ifdef GKLEDS_DEBUG printf("create_plugin_config: before button image\n"); fflush(stdout); #endif hbox = gtk_hbox_new(FALSE, 0); button = gtk_button_new_with_label("none"); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(pm_idx_altered), (int *) -1); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); for(i = 0; i < conf.num_img; i++){ subpixmap = gdk_pixmap_new(gk_vbox->window, width, height, -1); submask = gdk_pixmap_new(NULL, width, height, 1); gdk_draw_pixmap(subpixmap, pixmap_gc, pixmaps, 0, i*height, 0, 0, width, height); gdk_draw_pixmap(submask, mask_gc, masks, 0, i*height, 0, 0, width, height); pixmap_wid = gtk_pixmap_new(subpixmap, submask); button = gtk_button_new (); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(pm_idx_altered), (int *) i); gtk_container_add(GTK_CONTAINER(button), pixmap_wid); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); gdk_pixmap_unref(subpixmap); gdk_pixmap_unref(submask); } /* clean up gcs */ gdk_gc_unref(pixmap_gc); gdk_gc_unref(mask_gc); #ifdef GKLEDS_DEBUG printf("create_plugin_config: after button image\n"); fflush(stdout); #endif viewport = gtk_viewport_new(NULL, NULL); scroll_bar = gtk_hscrollbar_new(gtk_viewport_get_hadjustment(GTK_VIEWPORT(viewport))); gtk_container_add(GTK_CONTAINER(viewport), hbox); gtk_table_attach_defaults(GTK_TABLE(table), viewport, 0, 3, 1, 2); gtk_table_attach_defaults(GTK_TABLE(table), scroll_bar, 0, 3, 2, 3); gtk_container_add(GTK_CONTAINER(frame), table); gtk_box_pack_end(GTK_BOX(tab_vbox), frame, FALSE, FALSE, 0); /* the info tab */ tab_vbox = gkrellm_gtk_framed_notebook_page(tabs, "Info"); text = gkrellm_gtk_scrolled_text_view(tab_vbox, NULL, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gkrellm_gtk_text_view_append_strings(text, info_text, sizeof(info_text)/sizeof(gchar *)); /* the about tab */ tab_vbox = gkrellm_gtk_framed_notebook_page(tabs, "About"); text = gtk_label_new(about_text); gtk_label_set_justify(GTK_LABEL(text), GTK_JUSTIFY_CENTER); gtk_box_pack_start(GTK_BOX(tab_vbox), text, TRUE, TRUE, 0); if(about_text) free(about_text); #ifdef GKLEDS_DEBUG printf("create_plugin_config: end\n"); fflush(stdout); #endif return; } /* callback for spinbutton changed in margin adjustment and image size */ static void spin_misc_changed(GtkWidget *spin, gpointer data){ #ifdef GKLEDS_DEBUG printf("spin_misc_changed: start/end\n"); fflush(stdout); #endif *((int *) data) = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin)); return; } /* callback for spinbutton changed in order & presence */ static void spin_order_changed(GtkWidget *spin, gpointer data){ int indicator = (int) data; int order = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin)); int old_indicator = -1; /* new order's old indicator */ int old_order; /* new indicator's old order */ int i; #ifdef GKLEDS_DEBUG printf("spin_order_changed: start\n"); fflush(stdout); printf("spin_order_changed: indicator: %d\n", indicator); fflush(stdout); printf("spin_order_changed: order: %d\n", order); fflush(stdout); #endif /* find the new indicator's old order */ old_order = na_conf.order[indicator]; /* find the new order's old indicator */ for(i = 0; i < 3; i++){ if(na_conf.order[i] == order) old_indicator = i; } if(na_conf.order[old_indicator] != order) old_indicator = -1; /* set the new indicator to the new order */ na_conf.order[indicator] = order; #ifdef GKLEDS_DEBUG printf("spin_order_changed: indicator: %d\n", indicator); printf("spin_order_changed: order: %d\n", order); printf("spin_order_changed: old_indicator: %d\n", old_indicator); printf("spin_order_changed: old_order: %d\n", old_order); fflush(stdout); #endif /* set the old indicator to the old order and spin it */ /* old_indicator isn't sane when order == 0, */ /* and we don't want to spin it if new order is free */ /* NB! this will create a new changed signal, */ /* which we will have to deal with */ if(order && (old_indicator != -1)){ na_conf.order[old_indicator] = old_order; gtk_spin_button_set_value(GTK_SPIN_BUTTON(keys_spin[old_indicator]), (float) old_order); } #ifdef GKLEDS_DEBUG printf("spin_order_changed: end\n"); fflush(stdout); #endif return; } /* callback for which mouse button sets led state */ static void combo_mb_panel_changed(GtkWidget *mc_entry, gpointer data){ const char *mc_text = gtk_entry_get_text(GTK_ENTRY(mc_entry)); #ifdef GKLEDS_DEBUG printf("combo_mb_panel_changed: start/end\n"); fflush(stdout); #endif if(!strcmp(mc_text, "None")) na_conf.mb_panel = -1; else if(!strcmp(mc_text, "Button 1")) na_conf.mb_panel = 1; else if(!strcmp(mc_text, "Button 2")) na_conf.mb_panel = 2; else if(!strcmp(mc_text, "Button 3")) na_conf.mb_panel = 3; else if(!strcmp(mc_text, "Button 4")) na_conf.mb_panel = 4; else if(!strcmp(mc_text, "Button 5")) na_conf.mb_panel = 5; else if(!strcmp(mc_text, "All")) na_conf.mb_panel = 0; return; } /* callback for pixmap buttons clicked and combos changed in image selection */ static void pm_idx_altered(GtkWidget *widget, gpointer data){ const char *key_txt = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combos[0])->entry)); const char *subimg_txt = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combos[1])->entry)); int index = 0; GdkPixmap *subpixmap; GdkBitmap *submask; GdkGC *mask_gc, *pixmap_gc; GdkColor color; int width, height; #ifdef GKLEDS_DEBUG printf("pm_idx_altered: start\n"); fflush(stdout); #endif /* find the correct index into pm_idx */ if(!strcmp(key_txt, "NumLock")) index += 0; else if(!strcmp(key_txt, "CapsLock")) index += 4; else if(!strcmp(key_txt, "ScrollLock")) index += 8; else return; if(!strcmp(subimg_txt, "Background Off")) index += 0; else if(!strcmp(subimg_txt, "Foreground Off")) index += 1; else if(!strcmp(subimg_txt, "Background On")) index += 2; else if(!strcmp(subimg_txt, "Foreground On")) index += 3; else return; #ifdef GKLEDS_DEBUG printf("pm_idx_altered: index: %d\n", index); fflush(stdout); #endif /* data isn't sane for combo */ if((int) data != -3) na_conf.pm_idx[index] = (int) data; #ifdef GKLEDS_DEBUG if((int) data != -3) printf("pm_idx_altered: is_button\n"); else printf("pm_idx_altered: is_combo widget\n"); fflush(stdout); #endif /* update pixmap of choosen led subimage */ gdk_window_get_size(pixmaps, &width, &height); height = (int) height / conf.num_img; subpixmap = gdk_pixmap_new(gk_vbox->window, width, height, -1); submask = gdk_pixmap_new(NULL, width, height, 1); pixmap_gc = gdk_gc_new(subpixmap); mask_gc = gdk_gc_new(submask); gdk_color_black(gdk_colormap_get_system(), &color); gdk_gc_set_foreground(mask_gc, &color); gdk_draw_rectangle(submask, mask_gc, TRUE, 0, 0, -1, -1); if(na_conf.pm_idx[index] >= 0){ gdk_draw_pixmap(subpixmap, pixmap_gc, pixmaps, 0, na_conf.pm_idx[index]*height, 0, 0, width, height); gdk_draw_pixmap(submask, mask_gc, masks, 0, na_conf.pm_idx[index]*height, 0, 0, width, height); } gtk_pixmap_set(GTK_PIXMAP(pmfb_wid), subpixmap, submask); /* clean up gc and pixmaps */ gdk_pixmap_unref(subpixmap); gdk_pixmap_unref(submask); gdk_gc_unref(pixmap_gc); gdk_gc_unref(mask_gc); #ifdef GKLEDS_DEBUG printf("pm_idx_altered: end\n"); fflush(stdout); #endif return; } /* just hide how config copying is done */ static inline void copy_config(gkleds_user_conf *from, gkleds_user_conf *to){ memcpy(to, from, sizeof(gkleds_user_conf)); return; } static void apply_plugin_config(void){ #ifdef GKLEDS_DEBUG int i; printf("apply_plugin_config: start\n"); fflush(stdout); #endif copy_config(&na_conf, &conf); #ifdef GKLEDS_DEBUG printf("apply_plugin_config: margin: "); fflush(stdout); for(i = 0; i < 4; i++) printf("%d ", conf.margin[i]); fflush(stdout); printf("\n"); fflush(stdout); printf("apply_plugin_config: width: "); fflush(stdout); for(i = 0; i < 2; i++) printf("%d ", conf.size[i]); fflush(stdout); printf("\n"); fflush(stdout); printf("apply_plugin_config: pmidx: "); fflush(stdout); for(i = 0; i < GKLEDS_NUM_IND*4; i++) printf("%d ", conf.pm_idx[i]); fflush(stdout); printf("\n"); fflush(stdout); printf("apply_plugin_config: order: "); fflush(stdout); for(i = 0; i < GKLEDS_NUM_IND; i++) printf("%d ", conf.order[i]); fflush(stdout); printf("\n"); fflush(stdout); printf("apply_plugin_config: num_img: %d\n", conf.num_img); fflush(stdout); #endif create_plugin(gk_vbox, 0); #ifdef GKLEDS_DEBUG printf("apply_plugin_config: end\n"); fflush(stdout); #endif return; } static void save_plugin_config(FILE *f){ int i; #ifdef GKLEDS_DEBUG printf("save_plugin_config: start/end\n"); fflush(stdout); #endif fprintf(f, "%s margin", GKLEDS_CONFIG); for(i = 0; i < 4; i++) fprintf(f, " %d", conf.margin[i]); fprintf(f, "\n"); fprintf(f, "%s size", GKLEDS_CONFIG); for(i = 0; i < 2; i++) fprintf(f, " %d", conf.size[i]); fprintf(f, "\n"); fprintf(f, "%s pm_idx", GKLEDS_CONFIG); for(i = 0; i < GKLEDS_NUM_IND*4; i++) fprintf(f, " %d", conf.pm_idx[i]); fprintf(f, "\n"); fprintf(f, "%s order", GKLEDS_CONFIG); for(i = 0; i < GKLEDS_NUM_IND; i++) fprintf(f, " %d", conf.order[i]); fprintf(f, "\n"); fprintf(f, "%s mb_panel %d\n", GKLEDS_CONFIG, conf.mb_panel); return; } /* this is run once for each gkleds_plugin line in user_config */ static void load_plugin_config(gchar *arg){ char config_name[GKLEDS_CONF_LENGTH]; char config_data[GKLEDS_CONF_LENGTH]; #ifdef GKLEDS_DEBUG printf("load_plugin_config: start/end\n"); fflush(stdout); #endif /* if overflow then use default config */ if(strlen(arg) > GKLEDS_CONF_LENGTH) return; sscanf(arg,"%s %[^\n]", config_name, config_data); if(!strcmp(config_name, "margin")) sscanf(config_data, "%d %d %d %d", &conf.margin[0], &conf.margin[1], &conf.margin[2], &conf.margin[3]); else if(!strcmp(config_name, "size")) sscanf(config_data, "%d %d", &conf.size[0], &conf.size[1]); else if(!strcmp(config_name, "pm_idx")) sscanf(config_data, "%d %d %d %d %d %d %d %d %d %d %d %d", &conf.pm_idx[0], &conf.pm_idx[1], &conf.pm_idx[2], &conf.pm_idx[3], &conf.pm_idx[4], &conf.pm_idx[5], &conf.pm_idx[6], &conf.pm_idx[7], &conf.pm_idx[8], &conf.pm_idx[9], &conf.pm_idx[10], &conf.pm_idx[11]); else if(!strcmp(config_name, "order")) sscanf(config_data, "%d %d %d", &conf.order[0], &conf.order[1], &conf.order[2]); else if(!strcmp(config_name, "mb_panel")) sscanf(config_data, "%d", &conf.mb_panel); return; } extern GkrellmMonitor *gkrellm_init_plugin(void){ #ifdef GKLEDS_DEBUG printf("\ngklrellm_init_plugin: start/end\n"); fflush(stdout); #endif style_id = gkrellm_add_meter_style(&gkleds_mon, GKLEDS_NAME); monitor = &gkleds_mon; return &gkleds_mon; } gkrellm-leds-0.8.0/src/gkleds.h0100644000175000001440000000602707571734473015650 0ustar madhackusers/* Copyright (C) 2002 Øyvind Hagen */ /* This file is part of gkleds. */ /* gkleds is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License Version 2 as */ /* published by the Free Software Foundation */ /* gkleds is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License */ /* along with gkleds; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define GKLEDS_PLACEMENT (MON_UPTIME | GRAVITY(3)) #define GKLEDS_NAME "gkleds" #define GKLEDS_VERSION "0.8.0" #define GKLEDS_CONFIG "gkleds_plugin" /* #define NUM 0 */ /* #define CAPS 1 */ /* #define SCROLL 2 */ #define GKLEDS_NUM_IND 3 #define GKLEDS_NUM_IMG 12 #define GKLEDS_CONF_LENGTH 64 struct struct_gkleds_user_conf{ int margin[4]; /* margin adjustment: left, right, top, bottom*/ int size[2]; /* image size: width, height */ /* NUM, CAPS, SCROLL: bg_off, fg_off, bg_on, fg_on - -1 is none*/ int pm_idx[GKLEDS_NUM_IND*4]; int order[GKLEDS_NUM_IND]; /* NUM, CAPS, SCROLL: 1, 2, 3 - 0 is off */ int mb_panel; /* mb click -> indicator state (-1 - none, 0 - all, 1-5 )*/ int num_img; /* number of subimages in led_img, set in gkrellmrc/NUM_IMG */ }; typedef struct struct_gkleds_user_conf gkleds_user_conf; struct struct_gkleds_indicator_conf{ int w; /* actual width and height of leds */ int h; int y; /* leds y position in panel == user_conf.margin[2](top) */ int led_x[GKLEDS_NUM_IND]; /* actual leds x position in panel */ Display *dpy; /* the display */ KeyCode keys[GKLEDS_NUM_IND]; /* NUM, CAPS, SCROLL: keycode of the lock keys */ int masks[GKLEDS_NUM_IND]; /* NUM, CAPS, SCROLL: indicator mask, for XKB*/ int idx[GKLEDS_NUM_IND];/* NUM, CAPS, SCROLL: indicator index, for XKB */ }; typedef struct struct_gkleds_indicator_conf gkleds_indicator_conf; /* plugin functions */ extern GkrellmMonitor *gkrellm_init_plugin(void); static void create_plugin(GtkWidget *vbox, gint first_create); static void create_plugin_config(GtkWidget *conf_vbox); static void apply_plugin_config(void); static void save_plugin_config(FILE *f); static void load_plugin_config(gchar *arg); static void get_indicators(void); /* update_plugin */ /* configuration callbacks */ static void spin_misc_changed(GtkWidget *spin, gpointer data); static void spin_order_changed(GtkWidget *spin, gpointer data); static void combo_mb_panel_changed(GtkWidget *mc_entry, gpointer data); static void pm_idx_altered(GtkWidget *widget, gpointer data); /* misc */ static gint panel_expose_event(GtkWidget *widget, GdkEventExpose *ev); static inline void copy_config(gkleds_user_conf *from, gkleds_user_conf *to); static void set_indicators(GtkWidget *widget, GdkEventButton *ev); static void configure_indicators(gkleds_indicator_conf *ind); gkrellm-leds-0.8.0/src/pixmaps/0040700000175000001440000000000007612402417015655 5ustar madhackusersgkrellm-leds-0.8.0/src/pixmaps/leds.xpm0100644000175000001440000001110707571734556017361 0ustar madhackusers/* Copyright (C) 2002 Øyvind Hagen */ /* This file is part of gkleds. */ /* gkleds is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License Version 2 as */ /* published by the Free Software Foundation */ /* gkleds is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License */ /* along with gkleds; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* XPM */ static char * leds_xpm[] = { "16 144 67 1", " c None", ". c #000000", "+ c #2B2B2B", "@ c #2D2D2D", "# c #2F2F2F", "$ c #313131", "% c #333333", "& c #343434", "* c #363636", "= c #383838", "- c #3A3A3A", "; c #3C3C3C", "> c #3D3D3D", ", c #3F3F3F", "' c #414141", ") c #434343", "! c #454545", "~ c #474747", "{ c #2A2A2A", "] c #316429", "^ c #2F6027", "/ c #2D5D26", "( c #2B5924", "_ c #295623", ": c #275221", "< c #254E1F", "[ c #234B1D", "} c #27C40F", "| c #2ABB13", "1 c #2CB218", "2 c #2FA91C", "3 c #31A020", "4 c #339725", "5 c #39852D", "6 c #368E29", "7 c #2A4669", "8 c #294467", "9 c #284365", "0 c #274163", "a c #264061", "b c #253E5F", "c c #243D5D", "d c #233B5B", "e c #3E679B", "f c #3C6497", "g c #3B6292", "h c #395F8F", "i c #375C8B", "j c #365A87", "k c #33547F", "l c #345782", "m c #680E0E", "n c #640E0E", "o c #610D0D", "p c #5D0D0D", "q c #5A0C0C", "r c #560C0C", "s c #520B0B", "t c #4F0A0A", "u c #991616", "v c #931515", "w c #8E1414", "x c #881313", "y c #821212", "z c #7D1111", "A c #720F0F", "B c #771010", " ", " ", " .. .. ", " ... .. ", " .... .. ", " ..... .. ", " .. ..... ", " .. .... ", " .. ... ", " .. .. ", " ", " ", " ", " ", " ...... ", " ........ ", " .. .. ", " .. ", " .. ", " .. .. ", " ........ ", " ...... ", " ", " ", " ", " ", " ........ ", " ........ ", " .. ", " ........ ", " ........ ", " .. ", " ........ ", " ........ ", " ", " ", " ", " ", " .. ", " ... ", " .... ", " .. ", " .. ", " .. ", " .. ", " ...... ", " ", " ", " ", " ", " .... ", " ...... ", " .. .. ", " .. .. ", " ...... ", " ...... ", " .. .. ", " .. .. ", " ", " ", " ", " ", " .. ", " .. ", " .. ", " .. ", " ...... ", " .... ", " .. ", " ...... ", " ", " ", "+@#$%&*=-;>,')!~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "{]^/(_:<[:_(/^]~", "+@#$%&*=-;>,')!~", "+@#$%&*=-;>,')!~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "{}|1234564321|}~", "+@#$%&*=-;>,')!~", "+@#$%&*=-;>,')!~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "{7890abcdba0987~", "+@#$%&*=-;>,')!~", "+@#$%&*=-;>,')!~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "{efghijkljihgfe~", "+@#$%&*=-;>,')!~", "+@#$%&*=-;>,')!~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "{mnopqrstrqponm~", "+@#$%&*=-;>,')!~", "+@#$%&*=-;>,')!~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "{uvwxyzABzyxwvu~", "+@#$%&*=-;>,')!~"}; gkrellm-leds-0.8.0/TODO0100644000175000001440000000035707571735315014123 0ustar madhackusers* feature - general indicator config(not just the 3 currently supported) (maybe 0.8.1) * port - Windows port(maybe 0.8.2) * distribution - autoconf(0.8.1) - deb package(0.8.2) - gentoo ebulid(0.8.2) - rpm package(0.8.2) gkrellm-leds-0.8.0/README0100644000175000001440000000236007571735022014302 0ustar madhackusersgkleds ====== gkleds is a GKrellM plugin which monitors the CapsLock, NumLock and ScrollLock keys and reports their current status via on screen LEDs. This is useful for people who have keyboards without LEDs, typically cordless keyboards. It also lets you toggle the indicator state via mouse clicks. gkleds now only supports GKrellM 2.x. from version 0.8.0 and later. For informasjon on gkleds theme support, see Themes. Installing gkleds =================== $make $make install This will install gkleds system wide if you are root, otherwise it will install in the $HOME/.gkrellm2/plugins directory. The correct permissons and ownership is set. Debugging gkleds ================ $make test This will compile gkleds with debugging information and then run "gkrellm --demo -p gkleds.so". This is useful if you want to send me a bug report(do "make test > bug.txt" and then send me the "bug.txt" file along with a description of the problem). NB! The debugging mode will _not_ overwrite user configuration. Contact Information =================== email: oyvinha@ifi.uio.no homepage: http://www.stud.ifi.uio.no/~oyvinha/gkleds When sending me an email about gkleds, please set the subject line to: gkleds -