aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 13:59:25 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 13:59:25 -0700
commit254258b48b4ba761eae0a1563549e4f324564456 (patch)
tree721a3ca12d87da563a9f9bb5aed85398c629ddfb
parentb3ea2b804fbd35babac86c83c718a5491542db7c (diff)
opacity
-rw-r--r--sys/cmd/term/config.h10
-rw-r--r--sys/cmd/term/rules.mk2
-rw-r--r--sys/cmd/term/term.c90
-rw-r--r--sys/cmd/term/term.h33
-rw-r--r--sys/cmd/term/x.c220
5 files changed, 191 insertions, 164 deletions
diff --git a/sys/cmd/term/config.h b/sys/cmd/term/config.h
index a195786..e4b37ce 100644
--- a/sys/cmd/term/config.h
+++ b/sys/cmd/term/config.h
@@ -94,6 +94,9 @@ char *termname = "term-256color";
*/
uint tabspaces = 4;
+/* bg opacity */
+float alpha = 0.8;
+
/* Terminal colors (16 first used in escape sequence) */
static char *colorname[] = {
/* 8 normal colors */
@@ -121,6 +124,7 @@ static char *colorname[] = {
/* more colors can be added after 255 to use with DefaultXX */
"#cccccc",
"#555555",
+ "black",
};
@@ -128,9 +132,9 @@ static char *colorname[] = {
* Default colors (colorname index)
* foreground, background, cursor, reverse cursor
*/
-uint defaultfg = 7;
-uint defaultbg = 0;
-static uint defaultcs = 256;
+uint defaultfg = 7;
+uint defaultbg = 258;
+static uint defaultcs = 256;
static uint defaultrcs = 257;
/*
diff --git a/sys/cmd/term/rules.mk b/sys/cmd/term/rules.mk
index 18821eb..1b0fae3 100644
--- a/sys/cmd/term/rules.mk
+++ b/sys/cmd/term/rules.mk
@@ -15,7 +15,7 @@ $(BINS_$(d)): TCFLAGS = \
$(BINS_$(d)): TCLIBS = \
`$(PKG) --libs fontconfig` \
`$(PKG) --libs freetype2` \
- -lm -lrt -lX11 -lutil -lXft \
+ -lm -lrt -lX11 -lutil -lXft -lXrender \
$(OBJ_DIR)/libn/libn.a
$(BINS_$(d)): $(OBJS_$(d))
diff --git a/sys/cmd/term/term.c b/sys/cmd/term/term.c
index aecdcb4..4569394 100644
--- a/sys/cmd/term/term.c
+++ b/sys/cmd/term/term.c
@@ -3,8 +3,6 @@
#include <pwd.h>
#include <termios.h>
-#include <wchar.h>
-
#if defined(__linux)
#include <pty.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
@@ -13,12 +11,6 @@
#include <libutil.h>
#endif
-/* arbitrary sizes */
-#define ESC_BUF_SIZ (128*UTFmax)
-#define ESC_ARG_SIZ 16
-#define STR_BUF_SIZ ESC_BUF_SIZ
-#define STR_ARG_SIZ ESC_ARG_SIZ
-
/* macros */
#define IS_SET(flag) ((term.mode & (flag)) != 0)
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == 0x7f)
@@ -120,7 +112,7 @@ xmalloc(size_t len)
void *p;
if (!(p = malloc(len)))
- die("malloc: %s\n", strerror(errno));
+ fatal("malloc: %s\n", strerror(errno));
return p;
}
@@ -128,8 +120,8 @@ xmalloc(size_t len)
void *
xrealloc(void *p, size_t len)
{
- if ((p = realloc(p, len)) == NULL)
- die("realloc: %s\n", strerror(errno));
+ if ((p = realloc(p, len)) == nil)
+ fatal("realloc: %s\n", strerror(errno));
return p;
}
@@ -137,8 +129,8 @@ xrealloc(void *p, size_t len)
char *
xstrdup(char *s)
{
- if ((s = strdup(s)) == NULL)
- die("strdup: %s\n", strerror(errno));
+ if ((s = strdup(s)) == nil)
+ fatal("strdup: %s\n", strerror(errno));
return s;
}
@@ -390,7 +382,7 @@ getsel(void)
Letter *gp, *last;
if (sel.ob.x == -1)
- return NULL;
+ return nil;
bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTFmax;
ptr = str = xmalloc(bufsize);
@@ -448,7 +440,7 @@ selclear(void)
}
void
-die(char *errstr, ...)
+fatal(char *errstr, ...)
{
va_list ap;
@@ -465,30 +457,30 @@ execsh(char *cmd, char **args)
struct passwd *pw;
errno = 0;
- if ((pw = getpwuid(getuid())) == NULL) {
+ if ((pw = getpwuid(getuid())) == nil) {
if (errno)
- die("getpwuid: %s\n", strerror(errno));
+ fatal("getpwuid: %s\n", strerror(errno));
else
- die("who are you?\n");
+ fatal("who are you?\n");
}
- if ((sh = getenv("SHELL")) == NULL)
+ if ((sh = getenv("SHELL")) == nil)
sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
if (args) {
prog = args[0];
- arg = NULL;
+ arg = nil;
} else if (scroll) {
prog = scroll;
arg = utmp ? utmp : sh;
} else if (utmp) {
prog = utmp;
- arg = NULL;
+ arg = nil;
} else {
prog = sh;
- arg = NULL;
+ arg = nil;
}
- DEFAULT(args, ((char *[]) {prog, arg, NULL}));
+ DEFAULT(args, ((char *[]) {prog, arg, nil}));
unsetenv("COLUMNS");
unsetenv("LINES");
@@ -517,15 +509,15 @@ sigchld(int a)
pid_t p;
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
- die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
+ fatal("waiting for pid %hd failed: %s\n", pid, strerror(errno));
if (pid != p)
return;
if (WIFEXITED(stat) && WEXITSTATUS(stat))
- die("child exited with status %d\n", WEXITSTATUS(stat));
+ fatal("child exited with status %d\n", WEXITSTATUS(stat));
else if (WIFSIGNALED(stat))
- die("child terminated due to signal %d\n", WTERMSIG(stat));
+ fatal("child terminated due to signal %d\n", WTERMSIG(stat));
_exit(0);
}
@@ -536,13 +528,13 @@ stty(char **args)
size_t n, siz;
if ((n = strlen(stty_args)) > sizeof(cmd)-1)
- die("incorrect stty parameters\n");
+ fatal("incorrect stty parameters\n");
memcpy(cmd, stty_args, n);
q = cmd + n;
siz = sizeof(cmd) - n;
for (p = args; p && (s = *p); ++p) {
if ((n = strlen(s)) > siz-1)
- die("stty parameter length too long\n");
+ fatal("stty parameter length too long\n");
*q++ = ' ';
memcpy(q, s, n);
q += n;
@@ -570,7 +562,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
if (line) {
if ((cmdfd = open(line, O_RDWR)) < 0)
- die("open line '%s' failed: %s\n",
+ fatal("open line '%s' failed: %s\n",
line, strerror(errno));
dup2(cmdfd, 0);
stty(args);
@@ -578,12 +570,12 @@ ttynew(char *line, char *cmd, char *out, char **args)
}
/* seems to work fine on linux, openbsd and freebsd */
- if (openpty(&m, &s, NULL, NULL, NULL) < 0)
- die("openpty failed: %s\n", strerror(errno));
+ if (openpty(&m, &s, nil, nil, nil) < 0)
+ fatal("openpty failed: %s\n", strerror(errno));
switch (pid = fork()) {
case -1:
- die("fork failed: %s\n", strerror(errno));
+ fatal("fork failed: %s\n", strerror(errno));
break;
case 0:
close(iofd);
@@ -591,20 +583,20 @@ ttynew(char *line, char *cmd, char *out, char **args)
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
- if (ioctl(s, TIOCSCTTY, NULL) < 0)
- die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
+ if (ioctl(s, TIOCSCTTY, nil) < 0)
+ fatal("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
#ifdef __OpenBSD__
- if (pledge("stdio getpw proc exec", NULL) == -1)
- die("pledge\n");
+ if (pledge("stdio getpw proc exec", nil) == -1)
+ fatal("pledge\n");
#endif
execsh(cmd, args);
break;
default:
#ifdef __OpenBSD__
- if (pledge("stdio rpath tty proc", NULL) == -1)
- die("pledge\n");
+ if (pledge("stdio rpath tty proc", nil) == -1)
+ fatal("pledge\n");
#endif
close(s);
cmdfd = m;
@@ -628,7 +620,7 @@ ttyread(void)
case 0:
exit(0);
case -1:
- die("couldn't read from shell: %s\n", strerror(errno));
+ fatal("couldn't read from shell: %s\n", strerror(errno));
default:
buflen += ret;
written = twrite(buf, buflen, 0);
@@ -688,10 +680,10 @@ ttywriteraw(char *s, size_t n)
FD_SET(cmdfd, &rfd);
/* Check if we can write. */
- if (pselect(cmdfd+1, &rfd, &wfd, NULL, NULL, NULL) < 0) {
+ if (pselect(cmdfd+1, &rfd, &wfd, nil, nil, nil) < 0) {
if (errno == EINTR)
continue;
- die("select failed: %s\n", strerror(errno));
+ fatal("select failed: %s\n", strerror(errno));
}
if (FD_ISSET(cmdfd, &wfd)) {
/*
@@ -722,7 +714,7 @@ ttywriteraw(char *s, size_t n)
return;
write_error:
- die("write error on tty: %s\n", strerror(errno));
+ fatal("write error on tty: %s\n", strerror(errno));
}
void
@@ -941,7 +933,7 @@ csiparse(void)
csiescseq.buf[csiescseq.len] = '\0';
while (p < csiescseq.buf+csiescseq.len) {
- np = NULL;
+ np = nil;
v = strtol(p, &np, 10);
if (np == p)
v = 0;
@@ -1404,7 +1396,7 @@ csihandle(void)
unknown:
fprintf(stderr, "erresc: unknown csi ");
csidump();
- /* die(""); */
+ /* fatal(""); */
break;
case '@': /* ICH -- Insert <n> blank char */
DEFAULT(csiescseq.arg[0], 1);
@@ -1638,7 +1630,7 @@ csireset(void)
void
strhandle(void)
{
- char *p = NULL, *dec;
+ char *p = nil, *dec;
int j, narg, par;
term.esc &= ~(Xstrend|Xstr);
@@ -1670,7 +1662,7 @@ strhandle(void)
break;
p = strescseq.args[2];
/* FALLTHROUGH */
- case 104: /* color reset, here p = NULL */
+ case 104: /* color reset, here p = nil */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1)
@@ -1862,7 +1854,7 @@ tdeftran(char ascii)
static int vcs[] = {CSgfx0, CSusa};
char *p;
- if ((p = strchr(cs, ascii)) == NULL) {
+ if ((p = strchr(cs, ascii)) == nil) {
fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
} else {
term.trantbl[term.icharset] = vcs[p - cs];
@@ -2296,7 +2288,7 @@ tresize(int col, int row)
free(term.line[i]);
free(term.alt[i]);
}
- /* ensure that both src and dst are not NULL */
+ /* ensure that both src and dst are not nil */
if (i > 0) {
memmove(term.line, term.line + i, row * sizeof(Letter*));
memmove(term.alt, term.alt + i, row * sizeof(Letter*));
@@ -2357,7 +2349,7 @@ tresize(int col, int row)
void
resettitle(void)
{
- xsettitle(NULL);
+ xsettitle(nil);
}
void
diff --git a/sys/cmd/term/term.h b/sys/cmd/term/term.h
index a155bbe..deb494c 100644
--- a/sys/cmd/term/term.h
+++ b/sys/cmd/term/term.h
@@ -157,14 +157,6 @@ struct Letter {
uint32_t bg; /* background */
};
-union Arg {
- int i;
- uint ui;
- float f;
- void *v;
- char *s;
-};
-
struct Dot {
Letter attr; /* current char attributes */
int x;
@@ -233,7 +225,29 @@ typedef struct {
int narg; /* nb of args */
} STREscape;
+/* x.c */
+typedef struct TermWindow TermWindow;
+
+struct TermWindow {
+ int tw, th; /* tty width and height */
+ int w, h; /* window width and height */
+ int ch; /* char height */
+ int cw; /* char width */
+ int mode; /* window state/mode flags */
+ int cursor; /* cursor style */
+};
+/* used for user hooks */
+union Arg {
+ int i;
+ uint ui;
+ float f;
+ void *v;
+ char *s;
+};
+
+// -----------------------------------------------------------------------
+// x.c (backend functions)
void xbell(void);
void xclipcopy(void);
@@ -250,7 +264,7 @@ void xsetsel(char *);
int xstartdraw(void);
void xximspot(int, int);
-void die( char *, ...);
+void fatal( char *, ...);
void redraw(void);
void draw(void);
@@ -294,3 +308,4 @@ extern char *termname;
extern uint tabspaces;
extern uint defaultfg;
extern uint defaultbg;
+extern float alpha;
diff --git a/sys/cmd/term/x.c b/sys/cmd/term/x.c
index 74f3752..460bf7f 100644
--- a/sys/cmd/term/x.c
+++ b/sys/cmd/term/x.c
@@ -1,4 +1,6 @@
/* See LICENSE for license details. */
+#include "term.h"
+
#include <locale.h>
#include <time.h>
@@ -9,32 +11,34 @@
#include <X11/Xft/Xft.h>
#include <X11/XKBlib.h>
-#include "term.h"
-
/* types used in config.h */
-typedef struct {
+typedef struct Shortcut Shortcut;
+typedef struct MouseShortcut MouseShortcut;
+typedef struct Key Key;
+
+struct Shortcut{
uint mod;
KeySym keysym;
void (*func)(Arg *);
Arg arg;
-} Shortcut;
+};
-typedef struct {
+struct MouseShortcut {
uint mod;
uint button;
void (*func)(Arg *);
Arg arg;
uint release;
-} MouseShortcut;
+};
-typedef struct {
+struct Key {
KeySym k;
uint mask;
char *s;
/* three-valued logic variables: 0 indifferent, 1 on, -1 off */
schar appkey; /* application keypad */
schar appcursor; /* application cursor */
-} Key;
+};
/* X modifiers */
#define XK_ANY_MOD UINT_MAX
@@ -70,15 +74,6 @@ typedef XftGlyphFontSpec GlyphFontSpec;
/* Purely graphic info */
typedef struct {
- int tw, th; /* tty width and height */
- int w, h; /* window width and height */
- int ch; /* char height */
- int cw; /* char width */
- int mode; /* window state/mode flags */
- int cursor; /* cursor style */
-} TermWindow;
-
-typedef struct {
Display *dpy;
Colormap cmap;
Window win;
@@ -95,9 +90,10 @@ typedef struct {
Visual *vis;
XSetWindowAttributes attrs;
int scr;
- int isfixed; /* is fixed geometry? */
- int l, t; /* left and top offset */
- int gm; /* geometry mask */
+ int isfixed; /* is fixed geometry? */
+ int depth; /* color depth */
+ int l, t; /* left and top offset */
+ int gm; /* geometry mask */
} XWindow;
typedef struct {
@@ -132,53 +128,53 @@ typedef struct {
} DC;
static inline ushort sixd_to_16bit(int);
-static int xmakeglyphfontspecs(XftGlyphFontSpec *, Letter *, int, int, int);
-static void xdrawglyphfontspecs(XftGlyphFontSpec *, Letter, int, int, int);
-static void xdrawglyph(Letter, int, int);
-static void xclear(int, int, int, int);
-static int xgeommasktogravity(int);
-static int ximopen(Display *);
-static void ximinstantiate(Display *, XPointer, XPointer);
-static void ximdestroy(XIM, XPointer, XPointer);
-static int xicdestroy(XIC, XPointer, XPointer);
-static void xinit(int, int);
-static void cresize(int, int);
-static void xresize(int, int);
-static void xhints(void);
-static int xloadcolor(int, char *, Color *);
-static int xloadfont(Font *, FcPattern *);
-static void xloadfonts(char *, double);
-static void xunloadfont(Font *);
-static void xunloadfonts(void);
-static void xsetenv(void);
-static void xseturgency(int);
-static int evcol(XEvent *);
-static int evrow(XEvent *);
-
-static void expose(XEvent *);
-static void visibility(XEvent *);
-static void unmap(XEvent *);
-static void kpress(XEvent *);
-static void cmessage(XEvent *);
-static void resize(XEvent *);
-static void focus(XEvent *);
-static uint buttonmask(uint);
-static int mouseaction(XEvent *, uint);
-static void brelease(XEvent *);
-static void bpress(XEvent *);
-static void bmotion(XEvent *);
-static void propnotify(XEvent *);
-static void selnotify(XEvent *);
-static void selclear_(XEvent *);
-static void selrequest(XEvent *);
-static void setsel(char *, Time);
-static void mousesel(XEvent *, int);
-static void mousereport(XEvent *);
-static char *kmap(KeySym, uint);
-static int match(uint, uint);
-
-static void run(void);
-static void usage(void);
+static int xmakeglyphfontspecs(XftGlyphFontSpec *, Letter *, int, int, int);
+static void xdrawglyphfontspecs(XftGlyphFontSpec *, Letter, int, int, int);
+static void xdrawglyph(Letter, int, int);
+static void xclear(int, int, int, int);
+static int xgeommasktogravity(int);
+static int ximopen(Display *);
+static void ximinstantiate(Display *, XPointer, XPointer);
+static void ximdestroy(XIM, XPointer, XPointer);
+static int xicdestroy(XIC, XPointer, XPointer);
+static void xinit(int, int);
+static void cresize(int, int);
+static void xresize(int, int);
+static void xhints(void);
+static int xloadcolor(int, char *, Color *);
+static int xloadfont(Font *, FcPattern *);
+static void xloadfonts(char *, double);
+static void xunloadfont(Font *);
+static void xunloadfonts(void);
+static void xsetenv(void);
+static void xseturgency(int);
+static int evcol(XEvent *);
+static int evrow(XEvent *);
+
+static void expose(XEvent *);
+static void visibility(XEvent *);
+static void unmap(XEvent *);
+static void kpress(XEvent *);
+static void cmessage(XEvent *);
+static void resize(XEvent *);
+static void focus(XEvent *);
+static uint buttonmask(uint);
+static int mouseaction(XEvent *, uint);
+static void brelease(XEvent *);
+static void bpress(XEvent *);
+static void bmotion(XEvent *);
+static void propnotify(XEvent *);
+static void selnotify(XEvent *);
+static void selclear_(XEvent *);
+static void selrequest(XEvent *);
+static void setsel(char *, Time);
+static void mousesel(XEvent *, int);
+static void mousereport(XEvent *);
+static char *kmap(KeySym, uint);
+static int match(uint, uint);
+
+static void run(void);
+static void usage(void);
static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress,
@@ -192,11 +188,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
[MotionNotify] = bmotion,
[ButtonPress] = bpress,
[ButtonRelease] = brelease,
-/*
- * Uncomment if you want the selection to disappear when you select something
- * different in another window.
- */
-/* [SelectionClear] = selclear_, */
+ [SelectionClear] = selclear_,
[SelectionNotify] = selnotify,
/*
* PropertyNotify is only turned on when there is some INCR transfer happening
@@ -228,12 +220,13 @@ typedef struct {
/* Fontcache is an array now. A new font will be appended to the array. */
static Fontcache *frc = nil;
-static int frclen = 0;
-static int frccap = 0;
+static int frclen = 0;
+static int frccap = 0;
static char *usedfont = nil;
static double usedfontsize = 0;
static double defaultfontsize = 0;
+static char *opt_alpha = nil;
static char *opt_class = nil;
static char **opt_cmd = nil;
static char *opt_embed = nil;
@@ -724,8 +717,8 @@ xresize(int col, int row)
win.th = row * win.ch;
XFreePixmap(xw.dpy, xw.buf);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
+
XftDrawChange(xw.draw, xw.buf);
xclear(0, 0, win.w, win.h);
@@ -781,10 +774,17 @@ xloadcols(void)
for (i = 0; i < dc.collen; i++)
if (!xloadcolor(i, nil, &dc.col[i])) {
if (colorname[i])
- die("could not allocate color '%s'\n", colorname[i]);
+ fatal("could not allocate color '%s'\n", colorname[i]);
else
- die("could not allocate color %d\n", i);
+ fatal("could not allocate color %d\n", i);
}
+
+ if (opt_alpha)
+ alpha = strtof(opt_alpha, nil);
+
+ dc.col[defaultbg].color.alpha = (ushort)(0xffff * alpha);
+ dc.col[defaultbg].pixel &= 0x00ffffff;
+ dc.col[defaultbg].pixel |= (uchar)(0xff*alpha) << 24;
loaded = 1;
}
@@ -952,7 +952,7 @@ xloadfonts(char *fontstr, double fontsize)
pattern = FcNameParse((FcChar8 *)fontstr);
if (!pattern)
- die("can't open font %s\n", fontstr);
+ fatal("can't open font %s\n", fontstr);
if (fontsize > 1) {
FcPatternDel(pattern, FC_PIXEL_SIZE);
@@ -978,7 +978,7 @@ xloadfonts(char *fontstr, double fontsize)
}
if (xloadfont(&dc.font, pattern))
- die("can't open font %s\n", fontstr);
+ fatal("can't open font %s\n", fontstr);
if (usedfontsize < 0) {
FcPatternGetDouble(dc.font.match->pattern,
@@ -995,17 +995,17 @@ xloadfonts(char *fontstr, double fontsize)
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
if (xloadfont(&dc.ifont, pattern))
- die("can't open font %s\n", fontstr);
+ fatal("can't open font %s\n", fontstr);
FcPatternDel(pattern, FC_WEIGHT);
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
if (xloadfont(&dc.ibfont, pattern))
- die("can't open font %s\n", fontstr);
+ fatal("can't open font %s\n", fontstr);
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
if (xloadfont(&dc.bfont, pattern))
- die("can't open font %s\n", fontstr);
+ fatal("can't open font %s\n", fontstr);
FcPatternDestroy(pattern);
}
@@ -1090,25 +1090,37 @@ void
xinit(int cols, int rows)
{
XGCValues gcvalues;
- Cursor cursor;
- Window parent;
+ Cursor cursor;
+ Window parent;
+ XColor xmousefg, xmousebg;
+ XWindowAttributes attr;
+ XVisualInfo vis;
pid_t thispid = getpid();
- XColor xmousefg, xmousebg;
if (!(xw.dpy = XOpenDisplay(nil)))
- die("can't open display\n");
+ fatal("can't open display\n");
+
+ if (!(opt_embed && (parent == strtol(opt_embed, nil, 0)))) {
+ parent = XRootWindow(xw.dpy, xw.scr);
+ xw.depth = 32;
+ } else {
+ XGetWindowAttributes(xw.dpy, parent, &attr);
+ xw.depth = attr.depth;
+ }
+
+ XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
+ xw.vis = vis.visual;
xw.scr = XDefaultScreen(xw.dpy);
- xw.vis = XDefaultVisual(xw.dpy, xw.scr);
/* font */
if (!FcInit())
- die("could not init fontconfig.\n");
+ fatal("could not init fontconfig.\n");
usedfont = (opt_font == nil)? font : opt_font;
xloadfonts(usedfont, 0);
/* colors */
- xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols();
/* adjust fixed window geometry */
@@ -1128,19 +1140,17 @@ xinit(int cols, int rows)
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;
- if (!(opt_embed && (parent = strtol(opt_embed, nil, 0))))
- parent = XRootWindow(xw.dpy, xw.scr);
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
- win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
+ win.w, win.h, 0, xw.depth, InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs);
memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False;
- dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
- &gcvalues);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+
+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
+ dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
+
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
@@ -1305,7 +1315,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int
frc[frclen].font = XftFontOpenPattern(xw.dpy,
fontpattern);
if (!frc[frclen].font)
- die("XftFontOpenPattern failed seeking fallback font: %s\n",
+ fatal("XftFontOpenPattern failed seeking fallback font: %s\n",
strerror(errno));
frc[frclen].flags = frcflags;
frc[frclen].unicodep = r;
@@ -1896,7 +1906,7 @@ run(void)
if (pselect(MAX(xfd, ttyfd)+1, &rfd, nil, nil, tv, nil) < 0) {
if (errno == EINTR)
continue;
- die("select failed: %s\n", strerror(errno));
+ fatal("select failed: %s\n", strerror(errno));
}
clock_gettime(CLOCK_MONOTONIC, &now);
@@ -1958,7 +1968,7 @@ run(void)
void
usage(void)
{
- die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
+ fatal("usage: %s [-aiv] [-c class] [-f font] [-A alpha] [-g geometry]"
" [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid]"
" [[-e] command [args ...]]\n"
@@ -1979,6 +1989,9 @@ main(int argc, char *argv[])
case 'a':
allowaltscreen = 0;
break;
+ case 'A':
+ opt_alpha = EARGF(usage());
+ break;
case 'c':
opt_class = EARGF(usage());
break;
@@ -1997,7 +2010,7 @@ main(int argc, char *argv[])
xw.isfixed = 1;
break;
case 'o':
- opt_io = EARGF(usage());
+ opt_io = EARGF(usage());
break;
case 'l':
opt_line = EARGF(usage());
@@ -2013,7 +2026,7 @@ main(int argc, char *argv[])
opt_embed = EARGF(usage());
break;
case 'v':
- die("%s " VERSION "\n", argv0);
+ fatal("%s " VERSION "\n", argv0);
break;
default:
usage();
@@ -2028,12 +2041,15 @@ run:
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
+
cols = MAX(cols, 1);
rows = MAX(rows, 1);
+
tnew(cols, rows);
xinit(cols, rows);
xsetenv();
selinit();
+
run();
return 0;