From 6434c272b3e7a8bca26be90417eabfd26bcce554 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Wed, 4 Oct 2017 06:31:28 -0400 Subject: [PATCH] cputnik: Add version 0.2.0 to repository. From http://pkgs.fedoraproject.org/repo/pkgs/cputnik/cputnik-0.2.0.tar.gz/54df4b3b22a06ac8e0913ee54d121c18/cputnik-0.2.0.tar.gz --- cputnik/AUTHORS | 14 + cputnik/COPYING | 339 +++++++++++++++ cputnik/Makefile | 8 + cputnik/NEWS | 17 + cputnik/README | 12 + cputnik/src/Makefile | 23 + cputnik/src/cputnik.c | 361 ++++++++++++++++ cputnik/src/cputnik.h | 46 ++ cputnik/src/docklib.c | 979 ++++++++++++++++++++++++++++++++++++++++++ cputnik/src/docklib.h | 146 +++++++ cputnik/src/mask.h | 46 ++ cputnik/src/master.h | 101 +++++ 12 files changed, 2092 insertions(+) create mode 100644 cputnik/AUTHORS create mode 100644 cputnik/COPYING create mode 100644 cputnik/Makefile create mode 100644 cputnik/NEWS create mode 100644 cputnik/README create mode 100644 cputnik/src/Makefile create mode 100644 cputnik/src/cputnik.c create mode 100644 cputnik/src/cputnik.h create mode 100644 cputnik/src/docklib.c create mode 100644 cputnik/src/docklib.h create mode 100644 cputnik/src/mask.h create mode 100644 cputnik/src/master.h diff --git a/cputnik/AUTHORS b/cputnik/AUTHORS new file mode 100644 index 0000000..4284006 --- /dev/null +++ b/cputnik/AUTHORS @@ -0,0 +1,14 @@ + +Authors +-------- + +pasp +sill + +Borrowed code +-------------- + +cpu usage code based on WMMon 1.0b2 by + Martijn Pieterse (pieterse@xs4all.nl) + Antoine Nulle (warp@xs4all.nl) + diff --git a/cputnik/COPYING b/cputnik/COPYING new file mode 100644 index 0000000..a43ea21 --- /dev/null +++ b/cputnik/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/cputnik/Makefile b/cputnik/Makefile new file mode 100644 index 0000000..f7dd666 --- /dev/null +++ b/cputnik/Makefile @@ -0,0 +1,8 @@ + +all: + @cd src;\ + make;\ + mv cputnik ../cputnik + +clean: + rm -rf src/*.o src/*~ src/cputnik cputnik diff --git a/cputnik/NEWS b/cputnik/NEWS new file mode 100644 index 0000000..1238741 --- /dev/null +++ b/cputnik/NEWS @@ -0,0 +1,17 @@ + +0.2.0 - 26.03.2005 +------------------- + - memory usage meter (optionally) + - cputnik now uses config file (~/.clay/cputnik.rc) + - small graphics changes + +0.1.1 - 15.08.2002 +------------------- + - improved graphics + - new options + +0.1.0 - 25.07.2002 +------------------- + - first public release + + diff --git a/cputnik/README b/cputnik/README new file mode 100644 index 0000000..96cc256 --- /dev/null +++ b/cputnik/README @@ -0,0 +1,12 @@ + +cputnik - a simple cpu and memory monitor +------------------------------------------- + +This is small WindowMaker dockapp which displays cpu and memory usage. + +Configuration can be changed via ~/.clay/cputnik.rc using text editor. + +Patches, sugesstions are welcome... + + enjoy :) + diff --git a/cputnik/src/Makefile b/cputnik/src/Makefile new file mode 100644 index 0000000..e610131 --- /dev/null +++ b/cputnik/src/Makefile @@ -0,0 +1,23 @@ + +CFLAGS = -Wall -Os +INCS = -I/usr/X11R6/include/X11 +LIBS = -L/usr/X11R6/lib -lXpm -lXext -lX11 +INSTALL_PREFIX = /usr/local + + +all: cputnik.c docklib.o master.h mask.h + gcc $(CFLAGS) $(INCS) docklib.o cputnik.c -o cputnik $(LIBS) + +docklib.o: docklib.c docklib.h + gcc $(CFLAGS) $(INCS) -c docklib.c + +install: + cp ./cputnik $(INSTALL_PREFIX)/bin + +uninstall: + rm -f $(INSTALL_PREFIX)/bin/cputnik + +clean: + rm -f *.o cputnik *~ + + diff --git a/cputnik/src/cputnik.c b/cputnik/src/cputnik.c new file mode 100644 index 0000000..63b7fec --- /dev/null +++ b/cputnik/src/cputnik.c @@ -0,0 +1,361 @@ + +/* + * Cputnik - a simple cpu and memory monitor + * + * Copyright (C) 2002-2005 pasp and sill + * + * 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. + */ + + +#include "cputnik.h" + + +FILE *fp_stat, *fp_loadavg, *fp_memory; +int cmd_lmb, cmd_rmb, update_period; +int show_memory, free_memory; +char command_lmb[PATH_MAX], command_rmb[PATH_MAX], *ProgName; +stat_dev cpu_device; + +/*----------------------------------------------------------------------*/ + +void get_mem_statistics(int *free) +{ +long long int m_total, m_free, m_cached; +char temp[BUFFER_SIZE]; + + fp_memory = freopen("/proc/meminfo", "r", fp_memory); + + while(fscanf(fp_memory, "%s", temp)!=EOF) { + + if(!strncmp(temp,"MemTotal:", 9)) + fscanf(fp_memory, "%Ld", &m_total); + + if(!strncmp(temp,"MemFree:", 8)) + fscanf(fp_memory, "%Ld", &m_free); + + if(!strncmp(temp,"Cached:", 7)) + fscanf(fp_memory, "%Ld", &m_cached); + } + + *free = (int)(((float)(m_total - m_free - m_cached) / m_total) * 100.0); +} + +/*----------------------------------------------------------------------*/ + +void draw_memory_meter(void) +{ + free_memory = free_memory * (METER_WIDTH / 100.0); + if (free_memory > METER_WIDTH) free_memory = METER_WIDTH; + dcl_copy_xpm_area(0, 64, METER_WIDTH, 5, 26, 12); + dcl_copy_xpm_area(32, 64, free_memory, 5, 26, 12); +} + +/*----------------------------------------------------------------------*/ + +void get_cpu_statistics(char *devname, long *is, long *ds, long *idle) +{ +char temp[BUFFER_SIZE], *p, *tokens = " \t\n"; +int i; +float f; + + *is = *ds = *idle = 0; + + if (!strncmp(devname, "cpu", 3)) { + + fseek(fp_stat, 0, SEEK_SET); + + while (fgets(temp, 128, fp_stat)) { + + if (strstr(temp, "cpu")) { + p = strtok(temp, tokens); + /* 1..3, 4 == idle, we don't want idle! */ + for (i=0; i<3; i++) { + p = strtok(NULL, tokens); + *ds += atol(p); + } + + p = strtok(NULL, tokens); + *idle = atol(p); + } + + } + + fp_loadavg = freopen("/proc/loadavg", "r", fp_loadavg); + fscanf(fp_loadavg, "%f", &f); + *is = (long) (100 * f); + + } +} + +/*----------------------------------------------------------------------*/ + +void draw_stats(int *his, int num, int size, int x_left, int y_bottom) +{ +int pixels_per_byte, j, k, *p, d; + + pixels_per_byte = 100; + p = his; + + for (j=0; j pixels_per_byte) + pixels_per_byte += 100; + p++; + } + + p = his; + + for (k=0; k 0; j-=100) { + for (k=0; kname, &k, &istat, &idle); + + st->rt_idle = idle - st->idlelast; + st->idlelast = idle; + + st->rt_stat = istat - st->statlast; + st->statlast = istat; + + st->his[V_WIDTH] += k; + st->hisaddcnt++; +} + +/*----------------------------------------------------------------------*/ + +void cputnik_routine(int argc, char **argv) +{ +XEvent Event; +int but_stat = -1, xfd = 0; +long start_time, current_time, next_time, istat, idle, k; +unsigned long i, j; +fd_set inputs; +struct timeval timeout; + + fp_memory = fopen("/proc/meminfo", "r"); + fp_loadavg = fopen("/proc/loadavg", "r"); + fp_stat = fopen("/proc/stat", "r"); + + for (j=0; j METER_WIDTH) j = METER_WIDTH; + + dcl_copy_xpm_area(32, 64, j, 7-(show_memory*2), 26, 5); + + if (current_time >= next_time) { + next_time += update_period; + + if (cpu_device.his[V_WIDTH]) + cpu_device.his[V_WIDTH] /= cpu_device.hisaddcnt; + + for (j=1; jattributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); + + err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap), + &(wmgen->mask), &(wmgen->attributes)); + + if (err != XpmSuccess) { + fprintf(stderr, "ERROR: Not enough free colorcells.\n"); + exit(1); + } + +} + +/****************************************************************************** + * + * dcl_get_color + * + ******************************************************************************/ + +Pixel dcl_get_color (char *name) +{ +XColor color; +XWindowAttributes attributes; + + XGetWindowAttributes(display, Root, &attributes); + + color.pixel = 0; + if (!XParseColor(display, attributes.colormap, name, &color)) { + fprintf(stderr, "ERROR: can't parse %s.\n", name); + } else if (!XAllocColor(display, attributes.colormap, &color)) { + fprintf(stderr, "ERROR: can't allocate %s.\n", name); + } + + return color.pixel; +} + +/****************************************************************************** + * + * dcl_flush_expose + * + ******************************************************************************/ + +int dcl_flush_expose (Window w) +{ +XEvent dummy; +int i=0; + + while (XCheckTypedWindowEvent(display, w, Expose, &dummy)) + i++; + + return i; +} + +/****************************************************************************** + * + * dcl_redraw_window + * + ******************************************************************************/ + +void dcl_redraw_window (void) +{ + + dcl_flush_expose(iconwin); + XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, + 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0); + dcl_flush_expose(win); + XCopyArea(display, wmgen.pixmap, win, NormalGC, + 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0); +} + +/****************************************************************************** + * + * dcl_redraw_window_xy + * + ******************************************************************************/ + +void dcl_redraw_window_xy (int x, int y) +{ + + dcl_flush_expose(iconwin); + XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, + x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0); + dcl_flush_expose(win); + XCopyArea(display, wmgen.pixmap, win, NormalGC, + x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0); +} + +/****************************************************************************** + * + * dcl_add_mouse_region + * + ******************************************************************************/ + +void dcl_add_mouse_region (int index, int left, int top, int right, int bottom) +{ + if (index < MAX_MOUSE_REGION) { + mouse_region[index].enable = 1; + mouse_region[index].top = top; + mouse_region[index].left = left; + mouse_region[index].bottom = bottom; + mouse_region[index].right = right; + } +} + +/****************************************************************************** + * + * dcl_check_mouse_region + * + ******************************************************************************/ + +int dcl_check_mouse_region (int x, int y) +{ +int i, found; + + found = 0; + + for (i=0; i= mouse_region[i].left && + y <= mouse_region[i].bottom && + y >= mouse_region[i].top) + found = 1; + } + + if (!found) return -1; + return (i-1); +} + +/****************************************************************************** + * + * dcl_copy_xpm_area + * + ******************************************************************************/ + +void dcl_copy_xpm_area (int x, int y, int sx, int sy, int dx, int dy) +{ + + XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); + +} + + +/****************************************************************************** + * + * dcl_copy_font_xpm_area + * + ******************************************************************************/ + +void dcl_copy_font_xpm_area (int x, int y, int sx, int sy, int dx, int dy) +{ + XCopyArea(display, fonts_wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); + +} + + +/****************************************************************************** + * + * dcl_copy_led_xpm_area + * + ******************************************************************************/ + +void dcl_copy_led_xpm_area (int x, int y, int sx, int sy, int dx, int dy) +{ + + XCopyArea(display, leds_wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); + +} + +/****************************************************************************** + * + * dcl_copy_xbm_area + * + ******************************************************************************/ + +void dcl_copy_xbm_area (int x, int y, int sx, int sy, int dx, int dy) +{ + XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); +} + + +/****************************************************************************** + * + * dcl_set_mask_xy + * + ******************************************************************************/ + +void dcl_set_mask_xy (int x, int y) +{ + XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet); + XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet); +} + +/****************************************************************************** + * + * dcl_open_x_window + * + ******************************************************************************/ + +void dcl_open_x_window (int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) +{ +unsigned int borderwidth = 1; +XClassHint classHint; +char *display_name = NULL; +char *wname = argv[0]; +XTextProperty name; +XGCValues gcv; +unsigned long gcm; +int dummy=0, i, flags; + + for (i=1; argv[i]; i++) { + if (!strcmp(argv[i], "-display")) + display_name = argv[i+1]; + } + + if (!(display = XOpenDisplay(display_name))) { + fprintf(stderr, "ERROR: can't open display %s\n", XDisplayName(display_name)); + exit(1); + } + + screen = DefaultScreen(display); + Root = RootWindow(display, screen); + d_depth = DefaultDepth(display, screen); + x_fd = XConnectionNumber(display); + + /* Convert XPM to XImage */ + dcl_get_xpm(&wmgen, pixmap_bytes); + dcl_get_xpm(&fonts_wmgen, fonts_xpm); + dcl_get_xpm(&leds_wmgen, leds_xpm); + + /* Create a window to hold the stuff */ + mysizehints.flags = USSize | USPosition; + mysizehints.x = 0; + mysizehints.y = 0; + + back_pix = dcl_get_color("white"); + fore_pix = dcl_get_color("black"); + + XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, + &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + + mysizehints.width = 64; + mysizehints.height = 64; + + win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); + + iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); + + /* Activate hints */ + XSetWMNormalHints(display, win, &mysizehints); + classHint.res_name = wname; + classHint.res_class = wname; + XSetClassHint(display, win, &classHint); + + flags = ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; + + XSelectInput(display, win, flags); + XSelectInput(display, iconwin, flags); + + if (XStringListToTextProperty(&wname, 1, &name) == 0) { + fprintf(stderr, "ERROR: can't allocate window name\n"); + exit(1); + } + + XSetWMName(display, win, &name); + + /* Create GC for drawing */ + + gcm = GCForeground | GCBackground | GCGraphicsExposures; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.graphics_exposures = 0; + NormalGC = XCreateGC(display, Root, gcm, &gcv); + + /* ONLYSHAPE ON */ + + pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height); + + XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet); + XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); + + /* ONLYSHAPE OFF */ + + mywmhints.initial_state = WithdrawnState; + mywmhints.icon_window = iconwin; + mywmhints.icon_x = mysizehints.x; + mywmhints.icon_y = mysizehints.y; + mywmhints.window_group = win; + mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; + + XSetWMHints(display, win, &mywmhints); + + XSetCommand(display, win, argv, argc); + XMapWindow(display, win); + +} + + +/****************************************************************************** + * + * dcl_getdir_config + * + ******************************************************************************/ + +char* dcl_getdir_config (char *cdirectory) +{ +static char cfgdir[PATH_MAX]; +struct stat cfg; + + dcl_strcpy (cfgdir, getenv ("HOME"), PATH_MAX); + dcl_strcat (cfgdir, "/", PATH_MAX); + dcl_strcat (cfgdir, cdirectory, PATH_MAX); + + if(stat(cfgdir, &cfg) < 0) + mkdir(cfgdir, S_IRUSR | S_IWUSR | S_IXUSR); + + return cfgdir; +} + + +/****************************************************************************** + * + * dcl_getfilename_config + * + ******************************************************************************/ + +char* dcl_getfilename_config (char *config_dir, char *config_filename) +{ +static char filename[PATH_MAX]; + + dcl_strcpy (filename, dcl_getdir_config(config_dir), PATH_MAX); + dcl_strcat (filename, "/", PATH_MAX); + dcl_strcat (filename, config_filename, PATH_MAX); + + return filename; +} + + +/****************************************************************************** + * + * dcl_prefs_openfile + * + ******************************************************************************/ + +void* dcl_prefs_openfile (char *filename, int openmode) +{ + prefs_filehandle = NULL; + + if (openmode == P_READ) + prefs_filehandle = fopen (filename, "rb"); + else if (openmode == P_WRITE) + prefs_filehandle = fopen (filename, "wb"); + + return prefs_filehandle; +} + + +/****************************************************************************** + * + * dcl_prefs_closefile + * + ******************************************************************************/ + +void dcl_prefs_closefile (void) +{ + fclose (prefs_filehandle); +} + + +/****************************************************************************** + * + * dcl_prefs_put_int + * + ******************************************************************************/ + +void dcl_prefs_put_int (char *tagname, int value) +{ + fprintf (prefs_filehandle, "%s=%d\n", tagname, value); +} + + +/****************************************************************************** + * + * dcl_prefs_put_float + * + ******************************************************************************/ + +void dcl_prefs_put_float (char *tagname, float value) +{ + fprintf (prefs_filehandle, "%s=%f\n", tagname, value); +} + + +/****************************************************************************** + * + * dcl_prefs_put_string + * + ******************************************************************************/ + +void dcl_prefs_put_string (char *tagname, char *value) +{ + fprintf (prefs_filehandle, "%s=%s\n", tagname, value); +} + + +/****************************************************************************** + * + * dcl_prefs_put_lf + * + ******************************************************************************/ + +void dcl_prefs_put_lf (void) +{ + fprintf (prefs_filehandle, "\n"); +} + + +/****************************************************************************** + * + * dcl_prefs_put_comment + * + ******************************************************************************/ + +void dcl_prefs_put_comment (char *comment) +{ +char text[MAX_LINE_LEN]; + + dcl_strcpy (text, "# ", MAX_LINE_LEN); + dcl_strcat (text, comment, MAX_LINE_LEN); + fprintf (prefs_filehandle, text); +} + + +/****************************************************************************** + * + * dcl_prefs_get_line_with_tag + * + ******************************************************************************/ + +char* dcl_prefs_get_line_with_tag (char *tagname) +{ +static char prfline[MAX_LINE_LEN]; +int i; +char c; + + fseek (prefs_filehandle, 0, SEEK_SET); + + while (!feof (prefs_filehandle)) { + i = 0; + + while (((c = fgetc (prefs_filehandle)) != '\n') && c!= EOF && i < MAX_LINE_LEN) + prfline[i++] = c; + + prfline[i] = '\0'; + + if (prfline[0] != '#') + if (!strncmp (tagname, prfline, strlen (tagname))) break; + } + + return prfline; +} + + +/****************************************************************************** + * + * dcl_prefs_get_value_field + * + ******************************************************************************/ + +char* dcl_prefs_get_value_field (char *tagname) +{ +static char valuestr[MAX_VALUE_LEN]; +char *valpos, c; +int i; + + i = 0; + + if ((valpos = strchr (dcl_prefs_get_line_with_tag (tagname), '='))) { + while((c = valpos[i+1]) != '\0' && i < MAX_VALUE_LEN) valuestr[i++] = c; + } + + valuestr[i] = '\0'; + return valuestr; +} + + +/****************************************************************************** + * + * dcl_prefs_get_int + * + ******************************************************************************/ + +int dcl_prefs_get_int (char *tagname) +{ + return (atoi (dcl_prefs_get_value_field (tagname))); +} + + +/****************************************************************************** + * + * dcl_prefs_get_float + * + ******************************************************************************/ + +float dcl_prefs_get_float (char *tagname) +{ + return (atof (dcl_prefs_get_value_field (tagname))); +} + + +/****************************************************************************** + * + * dcl_prefs_get_string + * + ******************************************************************************/ + +char* dcl_prefs_get_string (char *tagname) +{ + return (dcl_prefs_get_value_field (tagname)); +} + + +/****************************************************************************** + * + * dcl_strcpy + * + ******************************************************************************/ + +char* dcl_strcpy (char *dest, const char *src, int maxlength) +{ +int len; + + if (!dest) { + fprintf (stderr, "ERROR: NULL dest in safe_strcpy\n"); + return NULL; + } + + if (!src) { + *dest = 0; + return dest; + } + + len = strlen(src); + + if (len > maxlength) { + fprintf (stderr, "ERROR: string overflow by %d in safe_strcpy [%.50s]\n", + (int)(len-maxlength), src); + len = maxlength; + } + + memcpy(dest, src, len); + dest[len] = 0; + return dest; +} + + +/****************************************************************************** + * + * dcl_strcat + * + ******************************************************************************/ + +char* dcl_strcat (char *dest, const char *src, int maxlength) +{ +int src_len, dest_len; + + if (!dest) { + fprintf (stderr, "ERROR: NULL dest in safe_strcat\n"); + return NULL; + } + + if (!src) { + return dest; + } + + src_len = strlen(src); + dest_len = strlen(dest); + + if (src_len + dest_len > maxlength) { + fprintf (stderr, "ERROR: string overflow by %d in safe_strcat [%.50s]\n", + (int)(src_len + dest_len - maxlength), src); + src_len = maxlength - dest_len; + } + + memcpy(&dest[dest_len], src, src_len); + dest[dest_len + src_len] = 0; + return dest; +} + + +/****************************************************************************** + * + * dcl_draw_char + * + ******************************************************************************/ + +int dcl_draw_char(int x, int y, char z, int font_type) +{ +char *ctable = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.[]-_:'@" }; +int ctable_len = 44; +int k, font_line, font_width, font_height; + + switch(font_type) { + + case FONT_SMALL: + font_width = 4; + font_height = 5; + font_line = 12; + break; + + case FONT_NORMAL: + font_width = 5; + font_height = 5; + font_line = 7; + break; + + case FONT_LARGE: + font_width = 5; + font_height = 7; + font_line = 0; + break; + + default: + fprintf(stderr, "ERROR: Unknown font type...\n"); + return false; + } + + for(k=0; k < ctable_len; k++) + if(toupper(z)==ctable[k]) { + + dcl_copy_font_xpm_area(k*font_width, font_line, font_width, font_height, x, y); + break; + + } + + return true; +} + +/****************************************************************************** + * + * dcl_draw_string + * + ******************************************************************************/ + +int dcl_draw_string(int x, int y, char *string, int font_type, int length) +{ +int j, len, font_width; +char a; + + if(length == -1) + len = strlen(string); + else + len = length; + + if(len <= 0 || len > MAX_STRING_LEN) { + + fprintf(stderr, "ERROR: Wrong string length...\n"); + return false; + + } + + switch(font_type) { + + case FONT_SMALL: + font_width = 4; + break; + + case FONT_NORMAL: + font_width = 5; + break; + + case FONT_LARGE: + font_width = 5; + break; + + default: + fprintf(stderr, "ERROR: Unknown font type...\n"); + return false; + } + + for(j=0; j NUM_COLORS) { + fprintf(stderr,"ERROR: Color doesn't exist..."); + return false; + } + + dcl_copy_led_xpm_area(5*color, 0, 5, 5, x, y); + + return true; +} + + +/****************************************************************************** + * + * dcl_execute_command + * + ******************************************************************************/ + +void dcl_execute_command(char *command, int flag) +{ +char *cmdline[4]; +pid_t pid, pid_status; + + pid = fork(); + + if (pid == 0) { + + cmdline[0] = "sh"; + cmdline[1] = "-c"; + cmdline[2] = command; + cmdline[3] = 0; + execvp("/bin/sh", cmdline); + _exit(121); + + } else + if(flag) + waitpid(pid, &pid_status, 0); + +} + +/****************************************************************************** + * + * dcl_check_file + * + ******************************************************************************/ + +int dcl_check_file(char *filename) +{ +struct stat ftype; +int state = F_NOT_AVAILABLE; + + if(stat(filename, &ftype)==-1) + state = F_NOT_AVAILABLE; + + else if(S_ISREG(ftype.st_mode)) + state = F_REGULAR; + + else if(S_ISDIR(ftype.st_mode)) + state = F_DIRECTORY; + + else if(S_ISCHR(ftype.st_mode)) + state = F_CHAR_DEVICE; + + else if(S_ISBLK(ftype.st_mode)) + state = F_BLOCK_DEVICE; + + else if(S_ISLNK(ftype.st_mode)) + state = F_LINK; + + else if(S_ISFIFO(ftype.st_mode)) + state = F_FIFO; + + else if(S_ISSOCK(ftype.st_mode)) + state = F_SOCK; + + return state; +} + + +/****************************************************************************** + * + * dcl_draw_point + * + ******************************************************************************/ + +void dcl_draw_point(int x, int y, Pixel color) +{ + XSetForeground(display, NormalGC, color); + XDrawPoint(display, wmgen.pixmap, NormalGC, x, y); +} + +/****************************************************************************** + * + * dcl_draw_line + * + ******************************************************************************/ + +void dcl_draw_line(int x0, int y0, int x1, int y1, Pixel color) +{ + XSetForeground(display, NormalGC, color); + XDrawLine(display, wmgen.pixmap, NormalGC, x0, y0, x1, y1); +} + +/*------------------------------------------------------------------------------------------- + * fonts and leds definitions + * gfx by sill + *-------------------------------------------------------------------------------------------*/ + +char * fonts_xpm[] = { +"220 17 8 1", +" c None", +". c #145B53", +"+ c #20B2AE", +"@ c #004941", +"# c #007D71", +"$ c #188A86", +"% c #202020", +"& c #22332F", +".+++.++++.@+++#++++@#+++##+++#@+++$+@%@+%#+#%#+++#+%%%++%%%%+%%%++@%%+@+++@++++@@+++@++++@@++++++++++%%%++%%%++%%%++%%%++%%%+++++#%%%#%#+++##+++##%%%##+++##+++##+++##+++##+++##+++#%%%%%+++$%%$+++%%%%%%%%%%%%%%%%%%%%@+++@", +"+%%%++%%%++@%%%+%%@++%%%%+%%%%+%%%@+@%@+%%+%%%%%%++%%##+%%%%+@%@+++%%++@%@++%%@++@%@++%%@++%%%@@%+%@+%%%++%%%++%%%++@%@++%%%+@%%@+%%%+%%%%%+%%%%++%%%++%%%%+%%%%%%%%++%%%++%%%++%%%+%%%%%+%%%%%%%%+%%%%%%%%%%%++%%%+$%%+@%@+", +"+%%%++%%%++%%%%+%%%++%%%%+%%%%+%%%%+@%@+%%+%%%%%%++@@+%+%%%%++@++++.%++%%%++%%%++%%%++%%%++%%%%%%+%%+%%%++%%%++%%%+%+@+%+@%@+%%@+.%%%+%%%%%+%%%%++%%%++%%%%+%%%%%%%%++%%%++%%%++%%%+%%%%%+%%%%%%%%+%%%%%%%%%%%$$%%%+$%%+%#%+", +"+%%%+++++%+%%%%+%%%++++#%+++#%+%++$+++++%%+%%%%%%++++%%+%%%%+@+@++%+%++%%%++%%@++%#%++%%@+@+++@%%+%%+%%%++@%@++%#%+%@+@%@+.+@%.+.%%%%#%#+++#%+++##+++##+++##+++#%%%%#%+++%#+++##%%%#%%%%%+%%%%%%%%+$+++$%%%%%%%%%%%$.%%+%+@+", +"++++++%%%++%%%%+%%%++%%%%+%%%%+%%%++@%@+%%+%%%%%%++@@+%+%%%%+%@%++%.+++%%%+++++@+%+@+++++%%%%%+%%+%%+%%%+##%##+@+@+%+@+%%@+@%.+@%%%%%+%+%%%%%%%%+%%%%+%%%%++%%%+%%%%++%%%+%%%%++%%%+%%%%%+%%%%%%%%+%%%%%%%%%%%%%%%%%%%%+%#+@", +"+%%%++%%%++@%%%+%%@++%%%%+%%%%+%%%++@%@+%%+%%+%%@++%%##+@%%%+%%%++%%+++@%@++%%%%+@@+.+%%@+@%%%+%%+%%+@%@+%+@+%++@+++@%@+%%+%%+@%%@%%%+%+%%%%%%%%+%%%%+%%%%++%%%+%%%%++%%%+%%%%++%%%+%$$%%+%%%%%%%%+%%%%%%%%%%%$$%%%%%%%+@%%%", +"+%%%+++++.@+++#++++@#+++#+%%%%@+++.+@%@+%#+#%@+++@+%%%+.+++#+%%%++%%@+@+++@+%%%%@++.++%%%+++++@%%+%%@+++@%@+@%+@%@++%%%+%%+%%#++++%%%#%#+++##+++#%%%%##+++##+++#%%%%##+++##+++##+++#%++%%+++$%%$+++%%%%%$+++$%++%%%%%%%@+++@", +"&+++&++++&&+++$++++&$+++$$+++$.+++.+%%%+%&+&%$+++$+%%%++%%%%++&+++%%%+&+++&++++&&+++&++++&&+++$$+++$+%%%++%%%++%%%++%%%++%%%+$++++%%%$%$++$%$++$%$%%$%$++$%$++$%$++$%$++$%$++$%$++$%%%%%%%++&%%&++%%%%%%%%%%%%$$%%%+$%%@+++@", +"+%%%++%%%++%%%%+%%%++%%%%+%%%%+%%%%+%%%+%%+%%%%%%++%%+%+%%%%+&+&+++%%++%%%++%%%++%%%++%%%++%%%%%%+%%+%%%++%%%++%+%+%+%+%+%%%+%%%+%%%%+%%%%+%%%%+%+%%+%+%%%%+%%%%%%%+%+%%+%+%%+%+%%+%%%%%%%+%%%%%%+%%%%%%%%%%%%++%%%+$%%+$$@+", +"+%%%+++++&+%%%%+%%%++++$%+++$%+%%+++++++%%+%%%%%%++++%%+%%%%+%+%++%+%++%%%++%%%++%+%++%%%+&+++&%%+%%+%%%+&+%+&+%+%+%%+%%%+%+%%%+%%%%%$%$++$%%++$%$++$%$++$%$++$%%%%$%$++$%$++$%$%%$%%%%%%%+%%%%%%+%$+++$%%%%%%%%%%%$.%%+%++$", +"++++++%%%++%%%%+%%%++%%%%+%%%%+%%%++%%%+%%+%%+%%%++%%+%+%%%%+%&%++%%+++%%%+++++&+%%+$++++&%%%%+%%+%%+%%%+%+%+%+&+&+%+%+%%%+%%%+%%%%%%+%+%%%%%%%+%%%%+%%%%+%+%%+%%%%+%+%%+%%%%+%+%%+%%$$%%%+%%%%%%+%%%%%%%%%%%%$$%%%%%%%+@@@%", +"+%%%+++++&&+++$++++&$+++$+%%%%.+++.+%%%+%&+&%&+++&+%%%+&+++++%%%++%%%+&+++&+%%%%&++$++%%%+$+++&%%+%%&+++&%&+&%&+&+&+%%%+%%+%%++++$%%%$%$++$%$++$%%%%$%$++$%$++$%%%%$%$++$%$++$%$++$%%++%%%++&%%&++%%%%%%$+++$%++%%%%%%%@+++@", +".++.+++.&++$$++.$++$$++$.++$$%%$%$.%$++$$%%$$%%%$%%$$%%$.++.+++..++.+++..++$++++$%%$$%%$$%%$$%%$$%%$$++$%%.$$++.$++.$%%$$++$.++$$++..++..++..++.%%%%++&%%&++%%%%%%%%%$$%%+$%@++@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", +"+%%++%%++%%%+%%++%%%+%%%+%%%+%%+%+.%%%%++%+.+%%%+$$+++%++%%++%%++%%++%%++%%%%$$%+%%++%%++%%++%%++%%+%%+%%.++%%%+%%%++%%++%%%+%%%%%%++%%++%%++%%+%%%%+%%%%%%+%%%%%%%%%++%%+$%+$@+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", +"+%%++++&+%%%+%%+++$%++$%+%+$++++%+.%%%%+++.%+%%%+..++&+++%%++%%++%$++%%+.++.%$$%+%%+$%%$+..+&++&%++%%+%%%%%+.++.%++$.+++$++.+++.%%%+.++..++++%%+%%%%+%%%%%%+$++$%%%%%%%%%$.%+%+$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", +"+++++%%++%%%+%%++%%%+%%%+%%++%%+%+.%+%%++%+.+%%%+%%++%&++%%++++.+%+$+++&%%%+%$$%+%%+$..$+++++%%+%&+%+%%%%%%++%%%%%%+%%%+%%%++%%+%%%++%%+%%%++%%+%$$%+%%%%%%+%%%%%%%%%$$%%%%%+@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", +"+%%++++.&++$$++.$++$+%%%.++.$%%$%$.%.++.$%%$$++$$%%$$%%$.++.+%%%.+$++%%+$++.%$$%.++.&++&$&&$$%%$%&$%$++$%%%$$++$$++.%%%$$++..++.%%%$.++..++..++.%++%++&%%&++%%%%$++$%++%%%%%@++@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"}; + +char * leds_xpm[] = { +"50 5 72 1", +" c #262626", +". c #3F4D4A", +"+ c #4A5754", +"@ c #3E3E1B", +"# c #B2B26F", +"$ c #DCDC30", +"% c #97970A", +"& c #1F431F", +"* c #5CA65C", +"= c #2DE02D", +"- c #0F8D0F", +"; c #282828", +"> c #448986", +", c #4EA9A5", +"' c #3B7F7D", +") c #032E50", +"! c #2776E2", +"~ c #6CA5EB", +"{ c #396CC4", +"] c #662F00", +"^ c #E58325", +"/ c #F2AF74", +"( c #C66100", +"_ c #4A1F1F", +": c #BB4545", +"< c #FF2424", +"[ c #B61111", +"} c #630000", +"| c #C32284", +"1 c #C2519E", +"2 c #B4197C", +"3 c #650000", +"4 c #9B4B55", +"5 c #AB6A72", +"6 c #8C434E", +"7 c #3D3D3D", +"8 c #898989", +"9 c #CDCDCD", +"0 c #F3F3DD", +"a c #F3F3BA", +"b c #D4D400", +"c c #D8F9D8", +"d c #8BEE8B", +"e c #17D717", +"f c #D6FAF9", +"g c #6ADAD7", +"h c #46A19E", +"i c #BFE0EC", +"j c #A5CEEB", +"k c #4C93FB", +"l c #F7E4D4", +"m c #FFDCBA", +"n c #FFA147", +"o c #F7DADA", +"p c #FF7373", +"q c #F81515", +"r c #FBFAFD", +"s c #D6ACD9", +"t c #C13E9E", +"u c #FBFEFD", +"v c #CBBCBF", +"w c #9F626C", +"x c #EBEBEB", +"y c #FFFFFF", +"z c #EBEB8B", +"A c #72EA72", +"B c #55B7B3", +"C c #93C2EB", +"D c #FFD1A5", +"E c #FF5454", +"F c #C170AD", +"G c #B57D85", +" .+. @#$%@&*=-&;>,';)!~{)]^/(]_:<[_}|12}3456378987", +".+++.#0ab%*cde->fgh'!ijk{^lmn(:opq[|rst24uvw68xyx8", +"+++++$az$b=dA=e,gB,h~jC~k/mD/n +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +extern Display *display; + +/* prefs file mode */ +#define P_READ 1 +#define P_WRITE 2 + +#define MAX_LINE_LEN 512 +#define MAX_VALUE_LEN 256 + +#define MAX_STRING_LEN 32 + +/* mouse buttons */ +#define LMB 1 +#define MMB 2 +#define RMB 3 + +#define MAX_MOUSE_REGION 8 + +#define FONT_SMALL 1 +#define FONT_NORMAL 2 +#define FONT_LARGE 3 + +/*-------------------------------------------------------------------------------*/ + +typedef struct { + int enable; + int top; + int bottom; + int left; + int right; +} MOUSE_REGION; + + +typedef struct { + Pixmap pixmap; + Pixmap mask; + XpmAttributes attributes; +} XpmIcon; + +#define NUM_COLORS 10 + +enum { /* don't change the order! */ + GRAY = 0, + YELLOW, + GREEN, + CYAN, + SKYBLUE, + ORANGE, + RED, + MAGENTA, + BROWN, + WHITE +} led_colors; + +enum { + F_NOT_AVAILABLE = 0, + F_REGULAR, + F_DIRECTORY, + F_CHAR_DEVICE, + F_BLOCK_DEVICE, + F_LINK, + F_FIFO, + F_SOCK +} file_types; + +/*-------------------------------------------------------------------------------*/ + +void dcl_open_x_window (int argc, char *argv[], char **, char *, int, int); +void dcl_redraw_window (void); +void dcl_redraw_window_xy (int x, int y); +void dcl_copy_xpm_area (int x, int y, int sx, int sy, int dx, int dy); +void dcl_copy_font_xpm_area (int x, int y, int sx, int sy, int dx, int dy); +void dcl_copy_led_xpm_area (int x, int y, int sx, int sy, int dx, int dy); +void dcl_copy_xbm_area (int x, int y, int sx, int sy, int dx, int dy); +void dcl_set_mask_xy (int x, int y); +void dcl_get_xpm (XpmIcon *wmgen, char **pixmap_bytes); +Pixel dcl_get_color (char *name); +int dcl_draw_char (int x, int y, char z, int font_type); +int dcl_draw_led (int x, int y, int color); +int dcl_draw_string (int x, int y, char *string, int font_type, int length); +void dcl_add_mouse_region (int index, int left, int top, int right, int bottom); +int dcl_check_mouse_region (int x, int y); +char* dcl_getfilename_config (char *config_dir, char *config_filename); +void* dcl_prefs_openfile (char *filename, int openmode); +void dcl_prefs_closefile (void); +void dcl_prefs_put_int (char *tagname, int value); +void dcl_prefs_put_float (char *tagname, float value); +void dcl_prefs_put_string (char *tagname, char *value); +void dcl_prefs_put_lf (void); +void dcl_prefs_put_comment (char *comment); +int dcl_prefs_get_int (char *tagname); +float dcl_prefs_get_float (char *tagname); +char* dcl_prefs_get_string (char *tagname); +char* dcl_strcpy (char *dest, const char *src, int maxlength); +char* dcl_strcat (char *dest, const char *src, int maxlength); +void dcl_execute_command (char *command, int flag); +int dcl_check_file (char *filename); +void dcl_draw_point (int x, int y, Pixel color); +void dcl_draw_line (int x0, int y0, int x1, int y1, Pixel color); + + +/* + * Created: Sat 26 Mar 2005 05:46:11 PM CET + * Last Modified: Sat 26 Mar 2005 10:53:50 PM CET + */ + diff --git a/cputnik/src/mask.h b/cputnik/src/mask.h new file mode 100644 index 0000000..6a62b99 --- /dev/null +++ b/cputnik/src/mask.h @@ -0,0 +1,46 @@ +#define MASK_WIDTH 64 +#define MASK_HEIGHT 64 +unsigned char cputnik_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/cputnik/src/master.h b/cputnik/src/master.h new file mode 100644 index 0000000..f501194 --- /dev/null +++ b/cputnik/src/master.h @@ -0,0 +1,101 @@ +/* XPM */ +char * cputnik_master_xpm[] = { +"64 72 26 1", +" c None", +". c #0000FF", +"+ c #000000", +"@ c #666366", +"# c #202020", +"$ c #898989", +"% c #004941", +"& c #292929", +"* c #135A57", +"= c #15615F", +"- c #166966", +"; c #18716E", +"> c #1A7976", +", c #1B817E", +"' c #1D8985", +") c #1F918D", +"! c #219995", +"~ c #22A19C", +"{ c #24A9A4", +"] c #26B1AC", +"^ c #27B9B4", +"/ c #29C1BB", +"( c #2BC8C3", +"_ c #188A86", +": c #20B6AE", +"< c #B59900", +"................................................................", +"................................................................", +"................................................................", +"...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++@...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+########################################################$...", +"...+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#$...", +"...+########################################################$...", +"...+########################################################$...", +"...@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$...", +"................................................................", +"................................................................", +"................................................................", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%*%*%=%-%;%>%,%'%)%!%~%{%]%^%/%(", +"_:#<............................................................"};