- values.foreground = XWhitePixel(xw.dis, xw.scr);
- values.font = dc.font->fid;
- valuemask = GCForeground | GCFont;
- dc.gc = XCreateGC(xw.dis, xw.win, valuemask, &values);
- XMapWindow(xw.dis, xw.win);
- /* wm stuff */
- chint.res_name = TNAME, chint.res_class = TNAME;
- wmhint.input = 1, wmhint.flags = InputHint;
- shint.height_inc = xw.ch, shint.width_inc = xw.cw;
- shint.height = xw.h, shint.width = xw.w;
- shint.flags = PSize | PResizeInc;
- XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
- XStoreName(xw.dis, xw.win, TNAME);
- XSync(xw.dis, 0);
-}
-
-void
-xdrawc(int x, int y, Glyph g) {
- XRectangle r = { x * xw.cw, y * xw.ch, xw.cw, xw.ch };
- unsigned long xfg, xbg;
-
- /* reverse video */
- if(g.mode & ATreverse)
- xfg = dc.col[g.bg], xbg = dc.col[g.fg];
- else
- xfg = dc.col[g.fg], xbg = dc.col[g.bg];
- /* background */
- XSetForeground(xw.dis, dc.gc, xbg);
- XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
- /* string */
- XSetForeground(xw.dis, dc.gc, xfg);
- XDrawString(xw.dis, xw.win, dc.gc, r.x, r.y+dc.font->ascent, &(g.c), 1);
- if(g.mode & ATbold) /* XXX: bold hack (draw again at x+1) */
- XDrawString(xw.dis, xw.win, dc.gc, r.x+1, r.y+dc.font->ascent, &(g.c), 1);
- /* underline */
- if(g.mode & ATunderline) {
- r.y += dc.font->ascent + 1;
- XDrawLine(xw.dis, xw.win, dc.gc, r.x, r.y, r.x+r.width-1, r.y);
- }
-}
-
-void
-xcursor(int mode) {
- static int oldx = 0;
- static int oldy = 0;
- Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0};
-
+ dc.gc = XCreateGC(xw.dpy, xw.win, 0, NULL);
+
+ /* white cursor, black outline */
+ cursor = XCreateFontCursor(xw.dpy, XC_xterm);
+ XDefineCursor(xw.dpy, xw.win, cursor);
+ XRecolorCursor(xw.dpy, cursor,
+ &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff},
+ &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000});
+
+ xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
+ xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
+ XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
+
+ xresettitle();
+ XMapWindow(xw.dpy, xw.win);
+ xhints();
+ XSync(xw.dpy, 0);
+}
+
+void
+xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
+ int winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch,
+ width = charlen * xw.cw;
+ Font *font = &dc.font;
+ XGlyphInfo extents;
+ XftColor *fg = &dc.xft_col[base.fg], *bg = &dc.xft_col[base.bg],
+ *temp, revfg, revbg;
+ XRenderColor colfg, colbg;
+
+ if(base.mode & ATTR_BOLD) {
+ if(BETWEEN(base.fg, 0, 7)) {
+ /* basic system colors */
+ fg = &dc.xft_col[base.fg + 8];
+ } else if(BETWEEN(base.fg, 16, 195)) {
+ /* 256 colors */
+ fg = &dc.xft_col[base.fg + 36];
+ } else if(BETWEEN(base.fg, 232, 251)) {
+ /* greyscale */
+ fg = &dc.xft_col[base.fg + 4];
+ }
+ /*
+ * Those ranges will not be brightened:
+ * 8 - 15 – bright system colors
+ * 196 - 231 – highest 256 color cube
+ * 252 - 255 – brightest colors in greyscale
+ */
+ font = &dc.bfont;
+ }
+
+ if(base.mode & ATTR_ITALIC)
+ font = &dc.ifont;
+ if((base.mode & ATTR_ITALIC) && (base.mode & ATTR_BOLD))
+ font = &dc.ibfont;
+
+ if(IS_SET(MODE_REVERSE)) {
+ if(fg == &dc.xft_col[defaultfg]) {
+ fg = &dc.xft_col[defaultbg];
+ } else {
+ colfg.red = ~fg->color.red;
+ colfg.green = ~fg->color.green;
+ colfg.blue = ~fg->color.blue;
+ colfg.alpha = fg->color.alpha;
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
+ fg = &revfg;
+ }
+
+ if(bg == &dc.xft_col[defaultbg]) {
+ bg = &dc.xft_col[defaultfg];
+ } else {
+ colbg.red = ~bg->color.red;
+ colbg.green = ~bg->color.green;
+ colbg.blue = ~bg->color.blue;
+ colbg.alpha = bg->color.alpha;
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &revbg);
+ bg = &revbg;
+ }
+ }
+
+ if(base.mode & ATTR_REVERSE)
+ temp = fg, fg = bg, bg = temp;
+
+ XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen,
+ &extents);
+ width = extents.xOff;
+
+ /* Intelligent cleaning up of the borders. */
+ if(x == 0) {
+ xclear(0, (y == 0)? 0 : winy, borderpx,
+ winy + xw.ch + (y == term.row-1)? xw.h : 0);
+ }
+ if(x + charlen >= term.col-1) {
+ xclear(winx + width, (y == 0)? 0 : winy, xw.w,
+ (y == term.row-1)? xw.h : (winy + xw.ch));
+ }
+ if(y == 0)
+ xclear(winx, 0, winx + width, borderpx);
+ if(y == term.row-1)
+ xclear(winx, winy + xw.ch, winx + width, xw.h);
+
+ XftDrawRect(xw.xft_draw, bg, winx, winy, width, xw.ch);
+ XftDrawStringUtf8(xw.xft_draw, fg, font->xft_set, winx,
+ winy + font->ascent, (FcChar8 *)s, bytelen);
+
+ if(base.mode & ATTR_UNDERLINE) {
+ XftDrawRect(xw.xft_draw, fg, winx, winy + font->ascent + 1,
+ width, 1);
+ }
+}
+
+void
+xdrawcursor(void) {
+ static int oldx = 0, oldy = 0;
+ int sl;
+ Glyph g = {{' '}, ATTR_NULL, defaultbg, defaultcs, 0};
+