/*!***************************************************************************\ NES.css Framework Version: development \*****************************************************************************//*! * Bootstrap Reboot v4.1.3 (https://getbootstrap.com/) * Copyright 2011-2018 The Bootstrap Authors * Copyright 2011-2018 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-ms-overflow-style:scrollbar;-webkit-tap-highlight-color:transparent}@-ms-viewport{width:device-width}article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;text-align:left;background-color:#fff}[tabindex="-1"]:focus{outline:0!important}hr{box-sizing:content-box;height:0;overflow:visible}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem}p{margin-top:0;margin-bottom:1rem}abbr[data-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline;text-decoration:underline dotted;cursor:help;border-bottom:0}address{margin-bottom:1rem;font-style:normal;line-height:inherit}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#007bff;text-decoration:none;background-color:transparent}a:hover{color:#0056b3;text-decoration:underline}a:not([href]):not([tabindex]){color:inherit;text-decoration:none}a:not([href]):not([tabindex]):focus,a:not([href]):not([tabindex]):hover{color:inherit;text-decoration:none}a:not([href]):not([tabindex]):focus{outline:0}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em}pre{margin-top:0;margin-bottom:1rem;overflow:auto;-ms-overflow-style:scrollbar}figure{margin:0 0 1rem}img{vertical-align:middle;border-style:none}svg{overflow:hidden;vertical-align:middle}table{border-collapse:collapse}caption{padding-top:.75rem;padding-bottom:.75rem;color:#6c757d;text-align:left;caption-side:bottom}th{text-align:inherit}label{display:inline-block;margin-bottom:.5rem}button{border-radius:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{padding:0;border-style:none}button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0}input[type=date],input[type=datetime-local],input[type=month],input[type=time]{-webkit-appearance:listbox}textarea{overflow:auto;resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{display:block;width:100%;max-width:100%;padding:0;margin-bottom:.5rem;font-size:1.5rem;line-height:inherit;color:inherit;white-space:normal}progress{vertical-align:baseline}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:none}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}summary{display:list-item;cursor:pointer}template{display:none}[hidden]{display:none!important}body,code,html,kbd,pre,samp{font-family:"Press Start 2P"}html{cursor:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABFklEQVRYR9WXURLDIAhE6/0PbSdOtUpcd1Gnpv1KGpTHBpCE1/cXq+vrMph7dGvXZTtpfW10DCA5jrH1H0Jhs5E0hnZdCR+vb5S8Nn8mQCeS9BdSalYJqMBjAGzq59xAESN7VFVUgV8AZB/dZBR7QTFDCqGquvUBVVoEtgIwpQRzmANSFHgWQKExHdIrPeuMvQNDarXe6nC/AutgV3JW+6bgqQLeV8FekRtgV+ToDKEKnACYKsfZjjkam7a0ZpYTytwmgainpC3HvwBocgKOxqRjehoR9DFKNFYtOwCGYCszobeCbl26N6yyQ6g8X/Wex/rBPsNEV6qAMaJPMynIHQCoSqS9JSMmwef51LflTgCRszU7DvAGiV6mHWfsaVUAAAAASUVORK5CYII=),auto}body{font-size:16px;color:#212529;background-color:#fff;-webkit-font-smoothing:antialiased}label{cursor:inherit}a,button{cursor:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAzElEQVRYR+2X0Q6AIAhF5f8/2jYXZkwEjNSVvVUjDpcrGgT7FUkI2D9xRfQETwNIiWO85wfINfQUEyxBG2ArsLwC0jioGt5zFcwF4OYDPi/mBYKm4t0U8ATgRm3ThFoAqkhNgWkA0jJLvaOVSs7j3qMnSgXWBMiWPXe94QqMBMBc1VZIvaTu5u5pQewq0EqNZvIEMCmxAawK0DNkay9QmfFNAJUXfgGgUkLaE7j/h8fnASkxHTz0DGIBMCnBeeM7AArpUd3mz2x3C7wADglA8BcWMZhZAAAAAElFTkSuQmCC) 14 0,pointer}[type=button],[type=reset],[type=submit],button{-webkit-appearance:none}input[type=checkbox],input[type=radio]{outline:0}@keyframes blink{0%{opacity:1}50%{opacity:0}}.nes-balloon,.nes-balloon.is-dark,.nes-btn,.nes-container.is-rounded,.nes-container.is-rounded.is-dark,.nes-dialog.is-rounded,.nes-dialog.is-rounded.is-dark,.nes-input,.nes-progress,.nes-progress.is-rounded,.nes-select select,.nes-table.is-bordered,.nes-table.is-dark.is-bordered,.nes-textarea{border-style:solid;border-width:4px}.nes-pointer{cursor:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAzElEQVRYR+2X0Q6AIAhF5f8/2jYXZkwEjNSVvVUjDpcrGgT7FUkI2D9xRfQETwNIiWO85wfINfQUEyxBG2ArsLwC0jioGt5zFcwF4OYDPi/mBYKm4t0U8ATgRm3ThFoAqkhNgWkA0jJLvaOVSs7j3qMnSgXWBMiWPXe94QqMBMBc1VZIvaTu5u5pQewq0EqNZvIEMCmxAawK0DNkay9QmfFNAJUXfgGgUkLaE7j/h8fnASkxHTz0DGIBMCnBeeM7AArpUd3mz2x3C7wADglA8BcWMZhZAAAAAElFTkSuQmCC) 14 0,pointer}.nes-avatar{width:32px;height:32px}.nes-avatar.is-rounded{border-radius:50px}.nes-avatar.is-small{width:16px;height:16px}.nes-avatar.is-small.is-rounded{border-radius:50px}.nes-avatar.is-medium{width:48px;height:48px}.nes-avatar.is-medium.is-rounded{border-radius:50px}.nes-avatar.is-large{width:64px;height:64px}.nes-avatar.is-large.is-rounded{border-radius:50px}.nes-badge{position:relative;display:inline-block;width:10.5em;height:1.875em;margin:.5em;font-size:.9em;white-space:nowrap;vertical-align:top;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.nes-badge.is-splited span.is-dark:first-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#212529;left:0;box-shadow:0 .5em #212529,0 -.5em #212529,0 0 #212529,-.5em 0 #212529}.nes-badge.is-splited span.is-dark:last-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#212529;right:0;box-shadow:0 .5em #212529,0 -.5em #212529,.5em 0 #212529,0 0 #212529}.nes-badge.is-icon{width:5.25em}.nes-badge.is-icon span.is-dark:first-child{display:flex;align-items:center;justify-content:center;width:2.7em;font-size:.5em;color:#fff;text-align:center;background-color:#212529;position:absolute;top:-2.8em;left:-2.7em;height:2.7em}.nes-badge.is-icon span.is-dark:last-child{display:inline-block;align-items:center;justify-content:center;width:6em;font-size:.88em;color:#fff;text-align:center;background-color:#212529;box-shadow:0 .5em #212529,0 -.5em #212529,.5em 0 #212529,-.5em 0 #212529}.nes-badge span.is-dark:first-child{position:absolute;top:0;width:100%;color:#fff;text-align:center;background-color:#212529;box-shadow:0 .5em #212529,0 -.5em #212529,.5em 0 #212529,-.5em 0 #212529}.nes-badge.is-splited span.is-primary:first-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#209cee;left:0;box-shadow:0 .5em #209cee,0 -.5em #209cee,0 0 #209cee,-.5em 0 #209cee}.nes-badge.is-splited span.is-primary:last-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#209cee;right:0;box-shadow:0 .5em #209cee,0 -.5em #209cee,.5em 0 #209cee,0 0 #209cee}.nes-badge.is-icon{width:5.25em}.nes-badge.is-icon span.is-primary:first-child{display:flex;align-items:center;justify-content:center;width:2.7em;font-size:.5em;color:#fff;text-align:center;background-color:#209cee;position:absolute;top:-2.8em;left:-2.7em;height:2.7em}.nes-badge.is-icon span.is-primary:last-child{display:inline-block;align-items:center;justify-content:center;width:6em;font-size:.88em;color:#fff;text-align:center;background-color:#209cee;box-shadow:0 .5em #209cee,0 -.5em #209cee,.5em 0 #209cee,-.5em 0 #209cee}.nes-badge span.is-primary:first-child{position:absolute;top:0;width:100%;color:#fff;text-align:center;background-color:#209cee;box-shadow:0 .5em #209cee,0 -.5em #209cee,.5em 0 #209cee,-.5em 0 #209cee}.nes-badge.is-splited span.is-success:first-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#92cc41;left:0;box-shadow:0 .5em #92cc41,0 -.5em #92cc41,0 0 #92cc41,-.5em 0 #92cc41}.nes-badge.is-splited span.is-success:last-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#92cc41;right:0;box-shadow:0 .5em #92cc41,0 -.5em #92cc41,.5em 0 #92cc41,0 0 #92cc41}.nes-badge.is-icon{width:5.25em}.nes-badge.is-icon span.is-success:first-child{display:flex;align-items:center;justify-content:center;width:2.7em;font-size:.5em;color:#fff;text-align:center;background-color:#92cc41;position:absolute;top:-2.8em;left:-2.7em;height:2.7em}.nes-badge.is-icon span.is-success:last-child{display:inline-block;align-items:center;justify-content:center;width:6em;font-size:.88em;color:#fff;text-align:center;background-color:#92cc41;box-shadow:0 .5em #92cc41,0 -.5em #92cc41,.5em 0 #92cc41,-.5em 0 #92cc41}.nes-badge span.is-success:first-child{position:absolute;top:0;width:100%;color:#fff;text-align:center;background-color:#92cc41;box-shadow:0 .5em #92cc41,0 -.5em #92cc41,.5em 0 #92cc41,-.5em 0 #92cc41}.nes-badge.is-splited span.is-warning:first-child{position:absolute;top:0;width:50%;color:#212529;text-align:center;background-color:#f7d51d;left:0;box-shadow:0 .5em #f7d51d,0 -.5em #f7d51d,0 0 #f7d51d,-.5em 0 #f7d51d}.nes-badge.is-splited span.is-warning:last-child{position:absolute;top:0;width:50%;color:#212529;text-align:center;background-color:#f7d51d;right:0;box-shadow:0 .5em #f7d51d,0 -.5em #f7d51d,.5em 0 #f7d51d,0 0 #f7d51d}.nes-badge.is-icon{width:5.25em}.nes-badge.is-icon span.is-warning:first-child{display:flex;align-items:center;justify-content:center;width:2.7em;font-size:.5em;color:#212529;text-align:center;background-color:#f7d51d;position:absolute;top:-2.8em;left:-2.7em;height:2.7em}.nes-badge.is-icon span.is-warning:last-child{display:inline-block;align-items:center;justify-content:center;width:6em;font-size:.88em;color:#212529;text-align:center;background-color:#f7d51d;box-shadow:0 .5em #f7d51d,0 -.5em #f7d51d,.5em 0 #f7d51d,-.5em 0 #f7d51d}.nes-badge span.is-warning:first-child{position:absolute;top:0;width:100%;color:#212529;text-align:center;background-color:#f7d51d;box-shadow:0 .5em #f7d51d,0 -.5em #f7d51d,.5em 0 #f7d51d,-.5em 0 #f7d51d}.nes-badge.is-splited span.is-error:first-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#e76e55;left:0;box-shadow:0 .5em #e76e55,0 -.5em #e76e55,0 0 #e76e55,-.5em 0 #e76e55}.nes-badge.is-splited span.is-error:last-child{position:absolute;top:0;width:50%;color:#fff;text-align:center;background-color:#e76e55;right:0;box-shadow:0 .5em #e76e55,0 -.5em #e76e55,.5em 0 #e76e55,0 0 #e76e55}.nes-badge.is-icon{width:5.25em}.nes-badge.is-icon span.is-error:first-child{display:flex;align-items:center;justify-content:center;width:2.7em;font-size:.5em;color:#fff;text-align:center;background-color:#e76e55;position:absolute;top:-2.8em;left:-2.7em;height:2.7em}.nes-badge.is-icon span.is-error:last-child{display:inline-block;align-items:center;justify-content:center;width:6em;font-size:.88em;color:#fff;text-align:center;background-color:#e76e55;box-shadow:0 .5em #e76e55,0 -.5em #e76e55,.5em 0 #e76e55,-.5em 0 #e76e55}.nes-badge span.is-error:first-child{position:absolute;top:0;width:100%;color:#fff;text-align:center;background-color:#e76e55;box-shadow:0 .5em #e76e55,0 -.5em #e76e55,.5em 0 #e76e55,-.5em 0 #e76e55}.nes-balloon{border-image-slice:3;border-image-width:3;border-image-repea
/*
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "dwm.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
/* static */
static int (*xerrorxlib)(Display *, XErrorEvent *);
static Bool otherwm;
static void
cleanup()
{
while(sel) {
resize(sel, True, TopLeft);
unmanage(sel);
}
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
}
static void
scan()
{
unsigned int i, num;
Window *wins, d1, d2;
XWindowAttributes wa;
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
for(i = 0; i < num; i++) {
if(!XGetWindowAttributes(dpy, wins[i], &wa))
continue;
if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
continue;
if(wa.map_state == IsViewable)
manage(wins[i], &wa);
}
}
if(wins)
XFree(wins);
}
static int
win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
{
int status, format;
unsigned long res, extra;
Atom real;
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
&res, &extra, prop);
if(status != Success || *prop == 0) {
return 0;
}
if(res == 0) {
free((void *) *prop);
}
return res;
}
/*
* Startup Error handler to check if another window manager
* is already running.
*/
static int
xerrorstart(Display *dsply, XErrorEvent *ee)
{
otherwm = True;
return -1;
}
/* extern */
char stext[1024];
int tsel = DEFTAG;
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
Atom wmatom[WMLast], netatom[NetLast];
Bool running = True;
Bool issel = True;
Client *clients = NULL;
Client *sel = NULL;
Cursor cursor[CurLast];
Display *dpy;
DC dc = {0};
Window root, barwin;
int
getproto(Window w)
{
int protos = 0;
int i;
long res;
unsigned char *protocols;
res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols);
if(res <= 0) {
return protos;
}
for(i = 0; i < res; i++) {
if(protocols[i] == wmatom[WMDelete])
protos |= PROTODELWIN;
}
free((char *) protocols);
return protos;
}
void
sendevent(Window w, Atom a, long value)
{
XEvent e;
e.type = ClientMessage;
e.xclient.window = w;
e.xclient.message_type = a;
e.xclient.format = 32;
e.xclient.data.l[0] = value;
e.xclient.data.l[1] = CurrentTime;
XSendEvent(dpy, w, False, NoEventMask, &e);
XSync(dpy, False);
}
void
quit(Arg *arg)
{
running = False;
}
/*
* There's no way to check accesses to destroyed windows, thus those cases are
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
* default error handler, which calls exit().
*/
int
xerror(Display *dpy, XErrorEvent *ee)
{
if(ee->error_code == BadWindow
|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess))
return 0;
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
ee->request_code, ee->error_code);
return xerrorxlib(dpy, ee); /* may call exit() */
}
int
main(int argc, char *argv[])
{
int i;
unsigned int mask;
fd_set rd;
Bool readin = True;
Window w;
XEvent ev;
XSetWindowAttributes wa;
if(argc == 2 && !strncmp("-v", argv[1], 3)) {
fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
exit(EXIT_SUCCESS);
}
else if(argc != 1)
eprint("usage: dwm [-v]\n");
dpy = XOpenDisplay(0);
if(!dpy)
eprint("dwm: cannot connect X server\n");
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
/* check if another WM is already running */
otherwm = False;
XSetErrorHandler(xerrorstart);
/* this causes an error if some other WM is running */
XSelectInput(dpy, root, SubstructureRedirectMask);
XSync(dpy, False);
if(otherwm)
eprint("dwm: another window manager is already running\n");
XSetErrorHandler(NULL);
xerrorxlib = XSetErrorHandler(xerror);
/* init atoms */
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) netatom, NetLast);
/* init cursors */
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
grabkeys();
/* style */
dc.bg = getcolor(BGCOLOR);
dc.fg = getcolor(FGCOLOR);
dc.border = getcolor(BORDERCOLOR);
setfont(FONT);
sx = sy = 0;
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
mw = (sw * MASTERW) / 100;
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);
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, 0);
drawstatus();
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);
strcpy(stext, "dwm-"VERSION);
scan();
/* main event loop, reads status text from stdin as well */
while(running) {
FD_ZERO(&rd);
if(readin)
FD_SET(STDIN_FILENO, &rd);
FD_SET(ConnectionNumber(dpy), &rd);
i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
if(i == -1 && errno == EINTR)
continue;
if(i < 0)
eprint("select failed\n");
else if(i > 0) {
if(FD_ISSET(ConnectionNumber(dpy), &rd)) {
while(XPending(dpy)) {
XNextEvent(dpy, &ev);
if(handler[ev.type])
(handler[ev.type])(&ev); /* call handler */
}
}
if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
readin = NULL != fgets(stext, sizeof(stext), stdin);
if(readin)
stext[strlen(stext) - 1] = 0;
else
strcpy(stext, "broken pipe");
drawstatus();
}
}
}
cleanup();
XCloseDisplay(dpy);
return 0;
}