X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=main.c;h=bfc63b163cb4f82befa90a16eb26c73676f2189d;hb=0e5c8198bc5a69e87b0114b81d6569188828edfa;hp=07e12aa3420d62739ba5287ae494d6fb71c74c34;hpb=efa7e514012865fcb3e9ea6e7d5b5c87d84353e5;p=dwm.git diff --git a/main.c b/main.c index 07e12aa..bfc63b1 100644 --- a/main.c +++ b/main.c @@ -3,9 +3,12 @@ * See LICENSE file for license details. */ +#include #include #include #include +#include +#include #include #include @@ -18,7 +21,6 @@ char *tags[TLast] = { [Tscratch] = "scratch", [Tdev] = "dev", - [Tirc] = "irc", [Twww] = "www", [Twork] = "work", }; @@ -33,9 +35,9 @@ Cursor cursor[CurLast]; Bool running = True; Bool issel; -char stext[1024]; int tsel = Tdev; /* default tag */ -int screen, sx, sy, sw, sh, th; +int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; +char stext[1024]; DC dc = {0}; Client *clients = NULL; @@ -43,7 +45,7 @@ Client *sel = NULL; static Bool other_wm_running; static const char version[] = - "dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; + "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; static int (*x_error_handler) (Display *, XErrorEvent *); static void @@ -169,7 +171,7 @@ static void cleanup() { while(sel) { - resize(sel); + resize(sel, True); unmanage(sel); } XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); @@ -184,13 +186,13 @@ quit(Arg *arg) int main(int argc, char *argv[]) { - int i; + int i, n; + fd_set rd; XSetWindowAttributes wa; unsigned int mask; Window w; XEvent ev; - /* command line args */ for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { switch (argv[i][1]) { case 'v': @@ -220,11 +222,6 @@ main(int argc, char *argv[]) if(other_wm_running) error("dwm: another window manager is already running\n"); - sx = sy = 0; - sw = DisplayWidth(dpy, screen); - sh = DisplayHeight(dpy, screen); - issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); - XSetErrorHandler(0); x_error_handler = XSetErrorHandler(error_handler); @@ -233,11 +230,9 @@ main(int argc, char *argv[]) wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); - XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atom, NetLast); - /* init cursors */ cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); @@ -251,22 +246,64 @@ main(int argc, char *argv[]) dc.border = initcolor(BORDERCOLOR); initfont(FONT); - th = dc.font.height + 4; + sx = sy = 0; + sw = DisplayWidth(dpy, screen); + sh = DisplayHeight(dpy, screen); + mw = (sw * MASTERW) / 100; - dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen)); - dc.gc = XCreateGC(dpy, root, 0, 0); + wa.override_redirect = 1; + wa.background_pixmap = ParentRelative; + wa.event_mask = ButtonPressMask | ExposureMask; + + bx = by = 0; + bw = sw; + dc.h = bh = dc.font.height + 4; + barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), + CopyFromParent, DefaultVisual(dpy, screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + XDefineCursor(dpy, barwin, cursor[CurNormal]); + XMapRaised(dpy, barwin); + + issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ | LeaveWindowMask; wa.cursor = cursor[CurNormal]; + XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); + dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); + dc.gc = XCreateGC(dpy, root, 0, 0); + + strcpy(stext, "dwm-"VERSION); scan_wins(); + draw_bar(); + /* main event loop, reads status text from stdin as well */ while(running) { - XNextEvent(dpy, &ev); - if(handler[ev.type]) - (handler[ev.type])(&ev); /* call handler */ + FD_ZERO(&rd); + FD_SET(0, &rd); + FD_SET(ConnectionNumber(dpy), &rd); + + i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); + if(i == -1 && errno == EINTR) + continue; + if(i < 0) + error("select failed\n"); + else if(i > 0) { + if(FD_ISSET(ConnectionNumber(dpy), &rd) && XPending(dpy) > 0) { + XNextEvent(dpy, &ev); + if(handler[ev.type]) + (handler[ev.type])(&ev); /* call handler */ + } + if(FD_ISSET(0, &rd)) { + i = n = 0; + while((i = getchar()) != '\n' && n < sizeof(stext) - 1) + stext[n++] = i; + stext[n] = 0; + draw_bar(); + } + } } cleanup();