Src/0000775000175000017500000000000013013306555012120 5ustar profzoomprofzoomSrc/xutils.h0000664000175000017500000000152113013306522013612 0ustar profzoomprofzoom#ifndef WMGENERAL_H_INCLUDED #define WMGENERAL_H_INCLUDED /* * Typedefs */ typedef struct { Pixmap pixmap; Pixmap mask; XpmAttributes attributes; } XpmIcon; /* * Global variable */ Display *display; Window Root; Window iconwin, win; int screen; int DisplayDepth; /* * Function Prototypes */ void AddMouseRegion(int, int, int, int, int); int CheckMouseRegion(int, int); void openXwindow(int, char **, char **, char *, int, int, char *, char *, char *, char *,char *); void initXwindow(int, char **); void RedrawWindow(void); void RedrawWindowXY(int, int); void copyXPMArea(int, int, int, int, int, int); void copyXBMArea(int, int, int, int, int, int); void setMaskXY(int, int); unsigned long getColor(char *, float); void RedrawWindow(void); #endif Src/xutils.c0000664000175000017500000001765413013306522013623 0ustar profzoomprofzoom/* * xutils.c - A collection of X-windows utilties for creating WindowMAker * DockApps. * * This file contains alot of the lower-level X windows routines. Origins with wmppp * (by Martijn Pieterse (pieterse@xs4all.nl)), but its been hacked up quite a bit * and passed on from one new DockApp to the next. * * * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file COPYING); if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA * * * * */ #include #include #include #include #include #include #include #include #include #include "xutils.h" /* * X11 Variables */ int x_fd; XSizeHints mysizehints; XWMHints mywmhints; Pixel back_pix, fore_pix; char *Geometry = ""; GC NormalGC; XpmIcon wmgen; Pixmap pixmask; /* * flush_expose */ static int flush_expose(Window w) { XEvent dummy; int i=0; while (XCheckTypedWindowEvent(display, w, Expose, &dummy)) i++; return i; } /* * RedrawWindow * RedrawWindowXY */ void RedrawWindow(void) { flush_expose(iconwin); XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 0,0, wmgen.attributes.width, wmgen.attributes.height, 0, 0); flush_expose(win); XCopyArea(display, wmgen.pixmap, win, NormalGC, 0,0, wmgen.attributes.width, wmgen.attributes.height, 0, 0); } void RedrawWindowXY(int x, int y) { flush_expose(iconwin); XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, x,y, wmgen.attributes.width, wmgen.attributes.height, 0, 0); flush_expose(win); XCopyArea(display, wmgen.pixmap, win, NormalGC, x,y, wmgen.attributes.width, wmgen.attributes.height, 0, 0); } /* * copyXPMArea * copyXBMArea */ void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) { XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); } void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) { XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); } /* * initXwindow */ void initXwindow(int argc, char *argv[]){ int i; char *display_name = NULL; for (i=1; argv[i]; ++i) { if (!strcmp(argv[i], "-display")) display_name = argv[i+1]; } if (!(display = XOpenDisplay(display_name))) { fprintf(stderr, "%s: can't open display %s\n", argv[0], XDisplayName(display_name)); exit(1); } screen = DefaultScreen(display); Root = RootWindow(display, screen); DisplayDepth = DefaultDepth(display, screen); x_fd = XConnectionNumber(display); } /* * openXwindow */ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height, char *BackColor, char *LabelColor, char *WindGustColor, char *DataColor, char *StationTimeColor) { unsigned int borderwidth = 1; XClassHint classHint; char *wname = argv[0]; XTextProperty name; XGCValues gcv; unsigned long gcm; int dummy=0; XpmColorSymbol cols[5]={ {"BackColor", NULL, 0}, {"LabelColor", NULL, 0}, {"DataColor", NULL, 0}, {"WindGustColor", NULL, 0}, {"StationTimeColor", NULL, 0} }; /* * Create Pixmap */ cols[0].pixel = getColor(BackColor, 1.0); cols[1].pixel = getColor(LabelColor, 1.0); cols[2].pixel = getColor(DataColor, 1.0); cols[3].pixel = getColor(WindGustColor, 1.0); cols[4].pixel = getColor(StationTimeColor, 1.0); wmgen.attributes.numsymbols = 5; wmgen.attributes.colorsymbols = cols; wmgen.attributes.exactColors = False; wmgen.attributes.closeness = 40000; wmgen.attributes.valuemask = XpmReturnPixels | XpmReturnExtensions | XpmColorSymbols | XpmExactColors | XpmCloseness | XpmSize; if (XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen.pixmap), &(wmgen.mask), &(wmgen.attributes)) != XpmSuccess){ fprintf(stderr, "Not enough free colorcells.\n"); exit(1); } /* * Create a window */ mysizehints.flags = USSize | USPosition; mysizehints.x = 0; mysizehints.y = 0; back_pix = getColor("white", 1.0); fore_pix = getColor("black", 1.0); 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); /* * Set up the xevents that you want the relevent windows to inherit * Currently, its seems that setting KeyPress events here has no * effect. I.e. for some you will need to Grab the focus and then return * it after you are done... */ XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask); XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask); if (XStringListToTextProperty(&wname, 1, &name) == 0) { fprintf(stderr, "%s: can't allocate window name\n", wname); exit(1); } XSetWMName(display, win, &name); /* * Create Graphics Context (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); 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); 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); } unsigned long getColor(char *ColorName, float fac) { XColor Color; XWindowAttributes Attributes; XGetWindowAttributes(display, Root, &Attributes); Color.pixel = 0; XParseColor(display, Attributes.colormap, ColorName, &Color); Color.red = (unsigned short)(Color.red/fac); Color.blue = (unsigned short)(Color.blue/fac); Color.green = (unsigned short)(Color.green/fac); Color.flags = DoRed | DoGreen | DoBlue; XAllocColor(display, Attributes.colormap, &Color); return Color.pixel; } Src/wmfrog.c0000664000175000017500000004642613013306522013573 0ustar profzoomprofzoom/* Thibaut Colar http://www.colar.net/ 2002/05 This is a dockapp wich shows you the weather at a specific location from it's METAR code. If this program blew up your computer it isn't my fault :-) This use a bit of code borrowed from the wmWeather application(originally). To build from src needs libxpm-dev, libx11-dev, libext-dev */ /* * Includes */ #include #include #include #include #include #include #include #include #include #include #include #include "xutils.h" #include "frog.xpm" #include "frog.xbm" /* * Delay between refreshes (in microseconds) */ #define DEBUG 0 #define VERSION "0.3.1" // 5 mn in seconds #define DEFAULT_UPDATEDELAY 300L // max wind in KNOTS #define MAX_WIND 50 #define TIME_OFFSET 0 #define METRIC 0 void ParseCMDLine(int argc, char *argv[]); void ButtonPressEvent(XButtonEvent *); void KeyPressEvent(XKeyEvent *); char *StringToUpper(char *); char *mystrsep(char **stringp, char *delim); char *GetTempDir(char *suffix); void UpdateData(); void Repaint(); struct WeatherStruct { int intensity; char* precip; char* desc; char* obsc; char* misc; char* coverage; int temp; int dew; float humidity; int hour; int min; int wind; int gust; int dir; } weather; char StationID[10]; char Label[20]; int Metric = METRIC; int NeedsUpdate = 1; int maxWind = MAX_WIND; int timeOffset = TIME_OFFSET; long UpdateDelay; char* folder; int needsUpdate = 1; /* * main */ int main(int argc, char *argv[]) { XEvent event; Display *dis; dis = XOpenDisplay((char *) 0); /* * Parse any command line arguments. */ ParseCMDLine(argc, argv); folder = GetTempDir(".wmapps"); initXwindow(argc, argv); openXwindow(argc, argv, frog_xpm, frog_bits, frog_width, frog_height, "#181818", "#79bdbf", "#ff0000", "#ffbf50", "#c5a6ff"); XSelectInput(dis, win, ExposureMask); // Update the data now .... which calls itself back every x seconds (UpdateDelay) using an alarm UpdateData(); while (1) { while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindow(); break; } } // check for events 2x seconds to take it easy on cpu usleep(500000); } } void Repaint() { int i, y, q; char chr; /* * Clear window. */ copyXPMArea(0, 64, 56, 56, 4, 4); //clouds if (strcmp(weather.coverage, "FEW") == 0) { copyXPMArea(0, 183, 56, 15, 4, 4); } if (strcmp(weather.coverage, "SCT") == 0) { copyXPMArea(56, 183, 56, 15, 4, 4); } if (strcmp(weather.coverage, "BKN") == 0) { copyXPMArea(112, 183, 56, 15, 4, 4); } if (strcmp(weather.coverage, "OVC") == 0 || strcmp(weather.coverage, "VV") == 0) { copyXPMArea(168, 183, 56, 15, 4, 4); } //obstruction if (strcmp(weather.obsc, "") != 0) { //fog if (strcmp(weather.desc, "BL") == 0) copyXPMArea(56, 90, 56, 26, 4, 34); else if (strcmp(weather.desc, "FZ") == 0) copyXPMArea(112, 90, 56, 26, 4, 34); else copyXPMArea(168, 64, 56, 26, 4, 34); } //precipitation if (strcmp(weather.precip, "DZ") == 0) { copyXPMArea(112, 120, 56, 15, 4, 18); } if (strcmp(weather.precip, "RA") == 0) { if (weather.intensity == 0) copyXPMArea(56, 150, 56, 15, 4, 18); if (weather.intensity < 0) copyXPMArea(0, 150, 56, 15, 4, 18); if (weather.intensity > 0) copyXPMArea(112, 150, 56, 15, 4, 18); } if (strcmp(weather.precip, "SN") == 0 || strcmp(weather.precip, "SG") == 0) { if (weather.intensity == 0) copyXPMArea(56, 135, 56, 15, 4, 18); if (weather.intensity > 0) copyXPMArea(112, 135, 56, 15, 4, 18); if (weather.intensity < 0) copyXPMArea(0, 135, 56, 15, 4, 18); } if (strcmp(weather.precip, "IC") == 0 || strcmp(weather.precip, "IC") == 0 || strcmp(weather.precip, "IC") == 0 || strcmp(weather.precip, "IC") == 0) { if (weather.intensity == 0) copyXPMArea(56, 166, 56, 16, 4, 18); if (weather.intensity > 0) copyXPMArea(112, 166, 56, 16, 4, 18); if (weather.intensity < 0) copyXPMArea(0, 166, 56, 16, 4, 18); } //descriptor if (strcmp(weather.desc, "BL") == 0 && strcmp(weather.obsc, "") == 0) { copyXPMArea(56, 64, 56, 26, 4, 34); } if (strcmp(weather.desc, "FZ") == 0 && strcmp(weather.obsc, "") == 0) { copyXPMArea(112, 64, 56, 26, 4, 34); } if (strcmp(weather.desc, "TS") == 0) { if (strcmp(weather.precip, "") != 0) copyXPMArea(164, 150, 56, 15, 4, 18); else copyXPMArea(56, 120, 56, 15, 4, 18); } //special if (strcmp(weather.misc, "") != 0) { copyXPMArea(168, 90, 56, 26, 4, 34); copyXPMArea(0, 120, 56, 15, 4, 18); copyXPMArea(168, 183, 56, 16, 4, 4); } //writtings: //clearing: copyXPMArea(170, 20, 25, 17, 29, 44); copyXPMArea(220, 0, 3, 60, 4, 4); copyXPMArea(220, 0, 3, 60, 57, 4); copyXPMArea(220, 0, 3, 60, 4, 4); //humidity y = (weather.humidity * 58) / 100; copyXPMArea(60, 0, 1, y, 4, 60 - y); copyXPMArea(60, 0, 1, y, 5, 60 - y); //wind & gust y = (weather.gust * 58) / maxWind; copyXPMArea(62, 0, 1, y, 58, 60 - y); copyXPMArea(62, 0, 1, y, 59, 60 - y); y = (weather.wind * 58) / maxWind; copyXPMArea(61, 0, 1, y, 58, 60 - y); copyXPMArea(61, 0, 1, y, 59, 60 - y); //station name for (i = 0; i != 4; i++) { chr = (int) Label[i] - 65; copyXPMArea(chr * 5 + 89, 0, 5, 6, 31 + (i * 5), 45); } //time i = weather.hour / 10; copyXPMArea(89 + (i * 5), 7, 5, 6, 30, 53); i = weather.hour - ((weather.hour / 10)*10); copyXPMArea(89 + (i * 5), 7, 5, 6, 35, 53); copyXPMArea(89 + (52), 7, 1, 6, 41, 53); i = weather.min / 10; copyXPMArea(89 + (i * 5), 7, 5, 6, 43, 53); i = weather.min - ((weather.min / 10)*10); copyXPMArea(89 + (i * 5), 7, 5, 6, 48, 53); //temp q = 10; copyXPMArea(136, 30, 17, 9, q - 1, 22); if (weather.temp < 0) { copyXPMArea(90, 30, 3, 7, q, 23); q += 5; } /*if(temp>100) { copyXPMArea(96, 20, 5, 7, q, 23); q+=6; } */ copyXPMArea(136, 30, 17, 9, (q - 1), 22); i = weather.temp; if (i < 0) i = -i; if (i / 100 > 0) { copyXPMArea(96, 20, 5, 7, q, 23); q += 6; i -= 100; } if ((i == 0 && q > 10) || i / 10 > 0 || q > 10) { copyXPMArea(90 + 6 * (i / 10), 20, 5, 7, q, 23); q += 6; } copyXPMArea(90 + 6 * (i - ((i / 10)*10)), 20, 5, 7, q, 23); q += 5; copyXPMArea(95, 29, 5, 7, q, 23); // wind weather.dir if ((weather.dir >= 0 && weather.dir <= 22) || (weather.dir <= 360 && weather.dir > 337)) copyXPMArea(0, 198, 7, 7, 48, 6); if (weather.dir > 22 && weather.dir <= 67) copyXPMArea(42, 198, 7, 7, 48, 6); if (weather.dir > 67 && weather.dir <= 112) copyXPMArea(14, 198, 7, 7, 48, 6); if (weather.dir > 112 && weather.dir <= 157) copyXPMArea(28, 198, 7, 7, 48, 6); if (weather.dir > 157 && weather.dir <= 202) copyXPMArea(7, 198, 7, 7, 48, 6); if (weather.dir > 202 && weather.dir <= 247) copyXPMArea(35, 198, 7, 7, 48, 6); if (weather.dir > 247 && weather.dir <= 292) copyXPMArea(21, 198, 7, 7, 48, 6); if (weather.dir > 292 && weather.dir <= 337) copyXPMArea(49, 198, 7, 7, 48, 6); /* * Make changes visible */ RedrawWindow(); } /* * ParseCMDLine() */ void ParseCMDLine(int argc, char *argv[]) { int i; void print_usage(); StationID[0] = '\0'; UpdateDelay = DEFAULT_UPDATEDELAY; for (i = 1; i < argc; i++) { if ((!strcmp(argv[i], "-metric")) || (!strcmp(argv[i], "-m"))) { Metric = 1; } else if (!strcmp(argv[i], "-w")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "You must give a max wind value with the -w option.\n"); print_usage(); exit(-1); } else if (sscanf(argv[i + 1], "%d", &maxWind) != 1) { fprintf(stderr, "Don't understand the max wind value have entered (%s).\n", argv[i + 1]); print_usage(); exit(-1); } } else if (!strcmp(argv[i], "-o")) { if ((i + 1 >= argc)) { fprintf(stderr, "You must give a time offset value with the -t option.\n"); print_usage(); exit(-1); } else if (sscanf(argv[i + 1], "%d", &timeOffset) != 1) { fprintf(stderr, "Don't understand the time offset value have entered (%s).\n", argv[i + 1]); print_usage(); exit(-1); } } else if (!strcmp(argv[i], "-tmp")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "-tmp option invalid.\n"); print_usage(); exit(-1); } strcpy(folder, argv[++i]); } else if ((!strcmp(argv[i], "-station")) || (!strcmp(argv[i], "-s"))) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "No METAR station ID found\n"); print_usage(); exit(-1); } strcpy(StationID, StringToUpper(argv[++i])); strcpy(Label, StationID); } else if (!strcmp(argv[i], "-delay")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "You must give a time with the -delay option.\n"); print_usage(); exit(-1); } else if (sscanf(argv[i + 1], "%ld", &UpdateDelay) != 1) { fprintf(stderr, "Don't understand the delay time you have entered (%s).\n", argv[i + 1]); print_usage(); exit(-1); } /* * Convert Time to seconds */ UpdateDelay *= 60; ++i; } else if (!strcmp(argv[i], "-l")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "You must give a station label name.\n"); print_usage(); exit(-1); } strcpy(Label, StringToUpper(argv[++i])); } } if (StationID[0] == '\0') { fprintf(stderr, "\nYou must specify a METAR station code\n\n"); print_usage(); exit(1); } } void print_usage() { printf("\nwmfrog version: %s\n", VERSION); printf("\nusage: wmfrog -s [-h] [-w ] [-t