/* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this * notice you can do whatever you want with this stuff. If we meet some day, * and you think this stuff is worth it, you can buy me a beer in return. * Fredrik Lindberg * ---------------------------------------------------------------------------- */ #include #include #include #include #include "xwlans.h" int init_win(struct xw_t *xw) { XGCValues gvc; if ((xw->disp = XOpenDisplay(xw->display)) == 0) { fprintf(stderr, "Could not open display %s\n", xw->display); return 1; } xw->screen = DefaultScreen(xw->disp); xw->win = RootWindow(xw->disp, xw->screen); gvc.graphics_exposures = True; xw->winGC = XCreateGC(xw->disp, xw->win, GCBackground, &gvc); XMapWindow(xw->disp, xw->win); XSelectInput(xw->disp, xw->win, ExposureMask|FocusChangeMask); return 0; } void close_win(struct xw_t *xw) { XSync(xw->disp, False); clear_win(xw); XSync(xw->disp, False); XCloseDisplay(xw->disp); } XColor get_color(struct xw_t *xw, char *color) { XColor c; XWindowAttributes atrb; XGetWindowAttributes(xw->disp, xw->win, &atrb); XParseColor(xw->disp, atrb.colormap, color, &c); XAllocColor(xw->disp, atrb.colormap, &c); return c; } void redraw(struct xw_t *xw, int value, int max) { int bar_len = value * ((xw->width * 0.70) / xw->bmax); int mbar = (int)(xw->width * 0.70); int bheight = (int)(xw->height - 7); char buffer[16]; sprintf(buffer, "%d/%d dBm", value, max); if (xw->opt_shadow == 1) { XSetForeground(xw->disp, xw->winGC, xw->c_shadow.pixel); XFillRectangle(xw->disp, xw->win, xw->winGC, xw->x + SHW_OFFSET, xw->y + SHW_OFFSET, bar_len, bheight); XDrawLine(xw->disp, xw->win, xw->winGC, xw->x + SHW_OFFSET, xw->y + bheight + 2 + SHW_OFFSET, xw->x + SHW_OFFSET, xw->y + bheight + 5 + SHW_OFFSET); XDrawLine(xw->disp, xw->win, xw->winGC, xw->x + (mbar/2) + SHW_OFFSET, xw->y + bheight + 2 + SHW_OFFSET, xw->x + (mbar/2) + SHW_OFFSET, xw->y + bheight + 5 + SHW_OFFSET); XDrawLine(xw->disp, xw->win, xw->winGC, xw->x + (mbar) + SHW_OFFSET, xw->y + bheight + 2 + SHW_OFFSET, xw->x + (mbar) + SHW_OFFSET, xw->y + bheight + 5 + SHW_OFFSET); XSetForeground(xw->disp, xw->winGC, xw->c_shadow.pixel); XDrawString(xw->disp, xw->win, xw->winGC, xw->x + (xw->width * 0.70) + 3 + SHW_OFFSET, xw->y + bheight + SHW_OFFSET, buffer, strlen(buffer)); } XSetForeground(xw->disp, xw->winGC, xw->c_bar.pixel); XFillRectangle(xw->disp, xw->win, xw->winGC, xw->x, xw->y, bar_len, bheight); XDrawLine(xw->disp, xw->win, xw->winGC, xw->x, xw->y + bheight + 2, xw->x, xw->y + bheight + 5); XDrawLine(xw->disp, xw->win, xw->winGC, xw->x + (mbar/2), xw->y + bheight + 2, xw->x + (mbar/2), xw->y + bheight + 5); XDrawLine(xw->disp, xw->win, xw->winGC, xw->x + (mbar), xw->y + bheight + 2, xw->x + (mbar), xw->y + bheight + 5); XSetForeground(xw->disp, xw->winGC, xw->c_text.pixel); XDrawString(xw->disp, xw->win, xw->winGC, xw->x + (xw->width * 0.70) + 3, xw->y + bheight, buffer, strlen(buffer)); } void clear_win(struct xw_t *xw) { XClearArea(xw->disp, xw->win, xw->x, xw->y, xw->width, xw->height, False); }