aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/term/x.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 15:33:39 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 15:33:39 -0700
commit55b9e38a7bee6dec42be835e91733d7f9cd8ccc4 (patch)
treeac7fa7375283add063f1173afacc1675ea644af7 /sys/cmd/term/x.c
parent254258b48b4ba761eae0a1563549e4f324564456 (diff)
change cursor color based on text
Diffstat (limited to 'sys/cmd/term/x.c')
-rw-r--r--sys/cmd/term/x.c110
1 files changed, 51 insertions, 59 deletions
diff --git a/sys/cmd/term/x.c b/sys/cmd/term/x.c
index 460bf7f..d6ec1bb 100644
--- a/sys/cmd/term/x.c
+++ b/sys/cmd/term/x.c
@@ -747,8 +747,7 @@ xloadcolor(int i, char *name, Color *ncolor)
color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16));
color.green = color.blue = color.red;
}
- return XftColorAllocValue(xw.dpy, xw.vis,
- xw.cmap, &color, ncolor);
+ return XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, ncolor);
} else
name = colorname[i];
}
@@ -811,9 +810,7 @@ xsetcolorname(int x, char *name)
void
xclear(int x1, int y1, int x2, int y2)
{
- XftDrawRect(xw.draw,
- &dc.col[IS_SET(Wreverse)? defaultfg : defaultbg],
- x1, y1, x2-x1, y2-y1);
+ XftDrawRect(xw.draw, &dc.col[IS_SET(Wreverse)? defaultfg : defaultbg], x1, y1, x2-x1, y2-y1);
}
void
@@ -1133,11 +1130,11 @@ xinit(int cols, int rows)
/* Events */
xw.attrs.background_pixel = dc.col[defaultbg].pixel;
- xw.attrs.border_pixel = dc.col[defaultbg].pixel;
- xw.attrs.bit_gravity = NorthWestGravity;
- xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
- | ExposureMask | VisibilityChangeMask | StructureNotifyMask
- | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
+ xw.attrs.border_pixel = dc.col[defaultbg].pixel;
+ xw.attrs.bit_gravity = NorthWestGravity;
+ xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
+ | ExposureMask | VisibilityChangeMask | StructureNotifyMask
+ | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
@@ -1161,10 +1158,8 @@ xinit(int cols, int rows)
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
/* input methods */
- if (!ximopen(xw.dpy)) {
- XRegisterIMInstantiateCallback(xw.dpy, nil, nil, nil,
- ximinstantiate, nil);
- }
+ if (!ximopen(xw.dpy))
+ XRegisterIMInstantiateCallback(xw.dpy, nil, nil, nil, ximinstantiate, nil);
/* white cursor, black outline */
cursor = XCreateFontCursor(xw.dpy, mouseshape);
@@ -1184,9 +1179,9 @@ xinit(int cols, int rows)
XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
- xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
+ xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
- xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
+ xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
@@ -1196,6 +1191,7 @@ xinit(int cols, int rows)
win.mode = Wnumlock;
resettitle();
xhints();
+
XMapWindow(xw.dpy, xw.win);
XSync(xw.dpy, False);
@@ -1213,8 +1209,8 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int
{
float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
ushort mode, prevmode = USHRT_MAX;
- Font *font = &dc.font;
- int frcflags = FRC_NORMAL;
+ Font *font = &dc.font;
+ int frcflags = FRC_NORMAL;
float runewidth = win.cw;
rune r;
FT_UInt glyphidx;
@@ -1255,10 +1251,10 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int
/* Lookup character index with default font. */
glyphidx = XftCharIndex(xw.dpy, font->match, r);
if (glyphidx) {
- specs[numspecs].font = font->match;
+ specs[numspecs].font = font->match;
specs[numspecs].glyph = glyphidx;
- specs[numspecs].x = (short)xp;
- specs[numspecs].y = (short)yp;
+ specs[numspecs].x = (short)xp;
+ specs[numspecs].y = (short)yp;
xp += runewidth;
numspecs++;
continue;
@@ -1361,9 +1357,9 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
if (IS_TRUECOL(base.fg)) {
colfg.alpha = 0xffff;
- colfg.red = TRUERED(base.fg);
+ colfg.red = TRUERED(base.fg);
colfg.green = TRUEGREEN(base.fg);
- colfg.blue = TRUEBLUE(base.fg);
+ colfg.blue = TRUEBLUE(base.fg);
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &truefg);
fg = &truefg;
} else {
@@ -1373,8 +1369,8 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
if (IS_TRUECOL(base.bg)) {
colbg.alpha = 0xffff;
colbg.green = TRUEGREEN(base.bg);
- colbg.red = TRUERED(base.bg);
- colbg.blue = TRUEBLUE(base.bg);
+ colbg.red = TRUERED(base.bg);
+ colbg.blue = TRUEBLUE(base.bg);
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &truebg);
bg = &truebg;
} else {
@@ -1389,42 +1385,37 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
if (fg == &dc.col[defaultfg]) {
fg = &dc.col[defaultbg];
} else {
- colfg.red = ~fg->color.red;
+ colfg.red = ~fg->color.red;
colfg.green = ~fg->color.green;
- colfg.blue = ~fg->color.blue;
+ colfg.blue = ~fg->color.blue;
colfg.alpha = fg->color.alpha;
- XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg,
- &revfg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
fg = &revfg;
}
if (bg == &dc.col[defaultbg]) {
bg = &dc.col[defaultfg];
} else {
- colbg.red = ~bg->color.red;
+ colbg.red = ~bg->color.red;
colbg.green = ~bg->color.green;
- colbg.blue = ~bg->color.blue;
+ colbg.blue = ~bg->color.blue;
colbg.alpha = bg->color.alpha;
- XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg,
- &revbg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &revbg);
bg = &revbg;
}
}
if ((base.mode & Gboldfaint) == Gfaint) {
- colfg.red = fg->color.red / 2;
+ colfg.red = fg->color.red / 2;
colfg.green = fg->color.green / 2;
- colfg.blue = fg->color.blue / 2;
+ colfg.blue = fg->color.blue / 2;
colfg.alpha = fg->color.alpha;
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
fg = &revfg;
}
- if (base.mode & Greverse) {
- temp = fg;
- fg = bg;
- bg = temp;
- }
+ if (base.mode & Greverse)
+ temp = fg, fg = bg, bg = temp;
if (base.mode & Gblink && win.mode & Wblink)
fg = bg;
@@ -1451,25 +1442,20 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
XftDrawRect(xw.draw, bg, winx, winy, width, win.ch);
/* Set the clip region because Xft is sometimes dirty. */
- r.x = 0;
- r.y = 0;
+ r.x = 0, r.y = 0;
r.height = win.ch;
- r.width = width;
+ r.width = width;
XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
/* Render the glyphs. */
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
/* Render underline and strikethrough. */
- if (base.mode & Gunline) {
- XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
- width, 1);
- }
+ if (base.mode & Gunline)
+ XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1, width, 1);
- if (base.mode & Gstruck) {
- XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
- width, 1);
- }
+ if (base.mode & Gstruck)
+ XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3, width, 1);
/* Reset clip to none. */
XftDrawSetClip(xw.draw, 0);
@@ -1505,10 +1491,10 @@ xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
if (IS_SET(Wreverse)) {
g.mode |= Greverse;
- g.bg = defaultfg;
+ g.bg = defaultfg;
if (selected(cx, cy)) {
drawcol = dc.col[defaultcs];
- g.fg = defaultrcs;
+ g.fg = defaultrcs;
} else {
drawcol = dc.col[defaultrcs];
g.fg = defaultcs;
@@ -1518,18 +1504,25 @@ xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
g.fg = defaultfg;
g.bg = defaultrcs;
} else {
- g.fg = defaultbg;
- g.bg = defaultcs;
+ g.fg = og.bg; //defaultbg;
+ g.bg = og.fg; //defaultcs;
+ if (IS_TRUECOL(og.fg)) {
+ drawcol.color.alpha = 0xffff;
+ drawcol.color.red = TRUERED(og.fg);
+ drawcol.color.green = TRUEGREEN(og.fg);
+ drawcol.color.blue = TRUEBLUE(og.fg);
+ goto drawnew;
+ }
}
drawcol = dc.col[g.bg];
}
- /* draw the new one */
+drawnew:
if (IS_SET(Wfocused)) {
switch (win.cursor) {
case 7: /* st extension */
g.u = 0x2603; /* snowman (U+2603) */
- /* FALLTHROUGH */
+ /* fallthrough */
case 0: /* Blinking Block */
case 1: /* Blinking Block (Default) */
case 2: /* Steady Block */
@@ -1539,8 +1532,7 @@ xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
case 4: /* Steady Underline */
XftDrawRect(xw.draw, &drawcol,
borderpx + cx * win.cw,
- borderpx + (cy + 1) * win.ch - \
- cursorthickness,
+ borderpx + (cy + 1) * win.ch - cursorthickness,
win.cw, cursorthickness);
break;
case 5: /* Blinking bar */