X-Git-Url: http://git.subgeniuskitty.com/dwm/.git/blobdiff_plain/5715edf56054808a5950dec7084d79b9df679483..a583293889ce0ccebf1574dd0c153d121ee05444:/dwm.c diff --git a/dwm.c b/dwm.c index e5efb6a..f20ee79 100644 --- a/dwm.c +++ b/dwm.c @@ -178,16 +178,19 @@ static void grabkeys(void); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); +static void layoutmenu(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); +static void nametag(const Arg *arg); static Client *nexttiled(Client *c); static void pop(Client *c); static void propertynotify(XEvent *e); static void quit(const Arg *arg); +static void quitprompt(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); @@ -235,6 +238,11 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); +static void keyrelease(XEvent *e); +static void combotag(const Arg *arg); +static void comboview(const Arg *arg); + + /* variables */ static const char broken[] = "broken"; static char stext[256]; @@ -246,6 +254,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, + [ButtonRelease] = keyrelease, [ClientMessage] = clientmessage, [ConfigureRequest] = configurerequest, [ConfigureNotify] = configurenotify, @@ -253,6 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { [EnterNotify] = enternotify, [Expose] = expose, [FocusIn] = focusin, + [KeyRelease] = keyrelease, [KeyPress] = keypress, [MappingNotify] = mappingnotify, [MapRequest] = maprequest, @@ -262,6 +272,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { }; static Atom wmatom[WMLast], netatom[NetLast]; static int running = 1; +static int restart = 1; static Cur *cursor[CurLast]; static Clr **scheme; static Display *dpy; @@ -276,6 +287,42 @@ static Window root, wmcheckwin; struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; /* function implementations */ +static int combo = 0; + +void +keyrelease(XEvent *e) { + combo = 0; +} + +void +combotag(const Arg *arg) { + if(selmon->sel && arg->ui & TAGMASK) { + if (combo) { + selmon->sel->tags |= arg->ui & TAGMASK; + } else { + combo = 1; + selmon->sel->tags = arg->ui & TAGMASK; + } + focus(NULL); + arrange(selmon); + } +} + +void +comboview(const Arg *arg) { + unsigned newtags = arg->ui & TAGMASK; + if (combo) { + selmon->tagset[selmon->seltags] |= newtags; + } else { + selmon->seltags ^= 1; /*toggle tagset*/ + combo = 1; + if (newtags) + selmon->tagset[selmon->seltags] = newtags; + } + focus(NULL); + arrange(selmon); +} + void applyrules(Client *c) { @@ -309,7 +356,9 @@ applyrules(Client *c) XFree(ch.res_class); if (ch.res_name) XFree(ch.res_name); - c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; + if(c->tags & TAGMASK) c->tags = c->tags & TAGMASK; + else if(c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags]; + else c->tags = 1; } int @@ -637,7 +686,7 @@ createmon(void) Monitor *m; m = ecalloc(1, sizeof(Monitor)); - m->tagset[0] = m->tagset[1] = 1; + m->tagset[0] = m->tagset[1] = startontag ? 1 : 0; m->mfact = mfact; m->nmaster = nmaster; m->showbar = showbar; @@ -699,6 +748,7 @@ dirtomon(int dir) void drawbar(Monitor *m) { + int indn; int x, w, tw = 0; int boxs = drw->fonts->h / 9; int boxw = drw->fonts->h / 6 + 2; @@ -722,13 +772,18 @@ drawbar(Monitor *m) } x = 0; for (i = 0; i < LENGTH(tags); i++) { + indn = 0; w = TEXTW(tags[i]); drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); - if (occ & 1 << i) - drw_rect(drw, x + boxs, boxs, boxw, boxw, - m == selmon && selmon->sel && selmon->sel->tags & 1 << i, - urg & 1 << i); + + for (c = m->clients; c; c = c->next) { + if (c->tags & (1 << i)) { + drw_rect(drw, x, 1 + (indn * 2), selmon->sel == c ? 6 : 1, 1, 1, urg & 1 << i); + indn++; + } + } + x += w; } w = TEXTW(m->ltsymbol); @@ -737,8 +792,12 @@ drawbar(Monitor *m) if ((w = m->ww - tw - x) > bh) { if (m->sel) { + /* fix overflow when window name is bigger than window width */ + int mid = (m->ww - (int)TEXTW(m->sel->name)) / 2 - x; + /* make sure name will not overlap on tags even when it is very long */ + mid = mid >= lrpad / 2 ? mid : lrpad / 2; drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); + drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0); if (m->sel->isfloating) drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); } else { @@ -1019,6 +1078,24 @@ killclient(const Arg *arg) } } +void +layoutmenu(const Arg *arg) { + FILE *p; + char c[3], *s; + int i; + + if (!(p = popen(layoutmenu_cmd, "r"))) + return; + s = fgets(c, sizeof(c), p); + pclose(p); + + if (!s || *s == '\0' || c[0] == '\0') + return; + + i = atoi(c); + setlayout(&((Arg) { .v = &layouts[i] })); +} + void manage(Window w, XWindowAttributes *wa) { @@ -1193,6 +1270,34 @@ movemouse(const Arg *arg) } } +void +nametag(const Arg *arg) { + char *p, name[MAX_TAGLEN]; + FILE *f; + int i; + + errno = 0; // popen(3p) says on failure it "may" set errno + // TODO: Create a central location for the dmenu font specification. + // It should not be hardcoded in multiple locations. + if(!(f = popen("dmenu -fn monospace:size=14 < /dev/null", "r"))) { + fprintf(stderr, "dwm: popen 'dmenu < /dev/null' failed%s%s\n", errno ? ": " : "", errno ? strerror(errno) : ""); + return; + } + if (!(p = fgets(name, MAX_TAGLEN, f)) && (i = errno) && ferror(f)) + fprintf(stderr, "dwm: fgets failed: %s\n", strerror(i)); + if (pclose(f) < 0) + fprintf(stderr, "dwm: pclose failed: %s\n", strerror(errno)); + if(!p) + return; + if((p = strchr(name, '\n'))) + *p = '\0'; + + for(i = 0; i < LENGTH(tags); i++) + if(selmon->tagset[selmon->seltags] & (1 << i)) + strcpy(tags[i], name); + drawbars(); +} + Client * nexttiled(Client *c) { @@ -1252,6 +1357,33 @@ quit(const Arg *arg) running = 0; } +void +quitprompt(const Arg *arg) +{ + // TODO: Create a central location for the dmenu font specification. + // It should not be hardcoded in multiple locations. + FILE *pp = popen("echo -e \"no\nrestart\nyes\" | dmenu -fn monospace:size=14 -i -sb red -p \"Quit DWM?\"", "r"); + if(pp != NULL) { + char buf[1024]; + if (fgets(buf, sizeof(buf), pp) == NULL) { + fprintf(stderr, "Quitprompt: Error reading pipe!\n"); + return; + } + if (strcmp(buf, "yes\n") == 0) { + pclose(pp); + restart = 0; + quit(NULL); + } else if (strcmp(buf, "restart\n") == 0) { + pclose(pp); + restart = 1; + quit(NULL); + } else if (strcmp(buf, "no\n") == 0) { + pclose(pp); + return; + } + } +} + Monitor * recttomon(int x, int y, int w, int h) { @@ -1417,7 +1549,7 @@ sendmon(Client *c, Monitor *m) detach(c); detachstack(c); c->mon = m; - c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ + c->tags = (m->tagset[m->seltags] ? m->tagset[m->seltags] : 1); attach(c); attachstack(c); focus(NULL); @@ -1737,11 +1869,9 @@ toggleview(const Arg *arg) { unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); - if (newtagset) { - selmon->tagset[selmon->seltags] = newtagset; - focus(NULL); - arrange(selmon); - } + selmon->tagset[selmon->seltags] = newtagset; + focus(NULL); + arrange(selmon); } void @@ -2035,7 +2165,7 @@ updatewmhints(Client *c) void view(const Arg *arg) { - if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) + if(arg->ui && (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) return; selmon->seltags ^= 1; /* toggle sel tagset */ if (arg->ui & TAGMASK) @@ -2143,5 +2273,8 @@ main(int argc, char *argv[]) run(); cleanup(); XCloseDisplay(dpy); + if (restart == 1) { + execlp("dwm-sgk", "dwm-sgk", NULL); + } return EXIT_SUCCESS; }