diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-07-05 19:05:14 -0700 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-07-05 19:05:14 -0700 |
commit | 6417ce01971e4c5213ecf813aebce73095ea466d (patch) | |
tree | c8331c1f7ca1265be0e7db6a88768e858d599e34 | |
parent | 78951baa03b0047203c1d4ca6e27224fe2a1f46c (diff) |
fix unfocused cursor
-rw-r--r-- | config.def.h | 1 | ||||
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | st.c | 62 | ||||
-rw-r--r-- | term.c | 4 | ||||
-rw-r--r-- | term.h | 7 |
5 files changed, 43 insertions, 33 deletions
diff --git a/config.def.h b/config.def.h index 2d307b4..3c64a13 100644 --- a/config.def.h +++ b/config.def.h @@ -53,7 +53,6 @@ static const char *colorname[] = { static unsigned int defaultfg = 7; static unsigned int defaultbg = 0; static unsigned int defaultcs = 256; -static unsigned int defaultucs = 257; /* Internal shortcuts. */ #define MODKEY Mod1Mask @@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib INCS = -I. -I/usr/include -I${X11INC} \ $(shell pkg-config --cflags fontconfig) \ $(shell pkg-config --cflags freetype2) -LIBS = -L/usr/lib -lm -lc -L${X11LIB} -lX11 -lutil -lXext -lXft \ +LIBS = -L/usr/lib -lm -lc -L${X11LIB} -lX11 -lutil -lXft \ $(shell pkg-config --libs fontconfig) \ $(shell pkg-config --libs freetype2) @@ -319,28 +319,31 @@ static void selrequest(struct st_window *xw, XEvent *e) /* Screen drawing code */ static void xclear(struct st_window *xw, XftColor *color, - struct coord pos, unsigned charlen) + struct coord pos, unsigned charlen, + bool clear_border) { - unsigned x1 = borderpx + pos.x * xw->charsize.x; - unsigned y1 = borderpx + pos.y * xw->charsize.y; - unsigned x2 = xw->charsize.x * charlen, y2 = xw->charsize.y; - - /* Get borders if we're clearing adjacent to them */ - if (!pos.x) { - x2 += x1; - x1 = 0; - } + unsigned x1 = xw->charsize.x * pos.x + borderpx; + unsigned x2 = xw->charsize.x * charlen; + unsigned y1 = xw->charsize.y * pos.y + borderpx; + unsigned y2 = xw->charsize.y; + + if (clear_border) { + if (!pos.x) { + x2 += x1; + x1 = 0; + } - if (pos.x + charlen == xw->term.size.x) - x2 = xw->winsize.x - x1; + if (pos.x + charlen == xw->term.size.x) + x2 = xw->winsize.x - x1; - if (!pos.y) { - y2 += y1; - y1 = 0; - } + if (!pos.y) { + y2 += y1; + y1 = 0; + } - if (pos.y + 1 == xw->term.size.y) - y2 = xw->winsize.y - y1; + if (pos.y + 1 == xw->term.size.y) + y2 = xw->winsize.y - y1; + } /* Clean up the region we want to draw to. */ XftDrawRect(xw->draw, color, x1, y1, x2, y2); @@ -426,7 +429,7 @@ static XftFont *find_font(struct st_window *xw, static void xdraw_glyphs(struct st_window *xw, struct coord pos, struct st_glyph base, struct st_glyph *glyphs, - unsigned charlen) + unsigned charlen, bool clear_border) { unsigned winx = borderpx + pos.x * xw->charsize.x, xp = winx; unsigned winy = borderpx + pos.y * xw->charsize.y; @@ -478,7 +481,7 @@ static void xdraw_glyphs(struct st_window *xw, struct coord pos, if (base.reverse) swap(bg, fg); - xclear(xw, bg, pos, charlen); + xclear(xw, bg, pos, charlen, clear_border); for (unsigned i = 0; i < charlen; i++) { /* @@ -545,7 +548,7 @@ static void xdrawcursor(struct st_window *xw) g.c = term_pos(&xw->term, xw->term.c.pos)->c; g.cmp = 0; g.fg = defaultbg; - g.bg = xw->focused ? defaultcs : defaultucs; + g.bg = defaultcs; g.reverse = xw->term.reverse; if (g.reverse) { @@ -554,7 +557,15 @@ static void xdrawcursor(struct st_window *xw) g.bg = t; } - xdraw_glyphs(xw, xw->term.c.pos, g, &g, 1); + if (xw->focused) { + xdraw_glyphs(xw, xw->term.c.pos, g, &g, 1, false); + } else { + XSetForeground(xw->dpy, xw->gc, xw->col[defaultcs].pixel); + XDrawRectangle(xw->dpy, xw->buf, xw->gc, + borderpx + xw->term.c.pos.x * xw->charsize.x, + borderpx + xw->term.c.pos.y * xw->charsize.y, + xw->charsize.x, xw->charsize.y); + } } static struct st_glyph sel_glyph(struct st_window *xw, unsigned x, unsigned y) @@ -591,7 +602,8 @@ static void draw(struct st_window *xw) x2++; xdraw_glyphs(xw, pos, base, - term_pos(&xw->term, pos), x2 - pos.x); + term_pos(&xw->term, pos), x2 - pos.x, + true); pos.x = x2; } } @@ -1221,9 +1233,11 @@ static void focus(struct st_window *xw, XEvent *ev) if (ev->type == FocusIn) { XSetICFocus(xw->xic); xw->focused = 1; + xw->term.dirty = true; xseturgency(&xw->term, 0); } else { XUnsetICFocus(xw->xic); + xw->term.dirty = true; xw->focused = 0; } } @@ -1400,7 +1414,7 @@ int main(int argc, char *argv[]) setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); term_init(&xw.term, 80, 24, shell, opt_cmd, opt_io, xw.win, - defaultfg, defaultbg, defaultcs, defaultucs); + defaultfg, defaultbg, defaultcs); xinit(&xw); run(&xw); @@ -1519,14 +1519,12 @@ static void term_ttyinit(struct st_term *term, unsigned long windowid, void term_init(struct st_term *term, int col, int row, char *shell, char **cmd, const char *logfile, unsigned long windowid, - unsigned defaultfg, unsigned defaultbg, unsigned defaultcs, - unsigned defaultucs) + unsigned defaultfg, unsigned defaultbg, unsigned defaultcs) { term->logfile = logfile; term->defaultfg = defaultfg; term->defaultbg = defaultbg; term->defaultcs = defaultcs; - term->defaultucs = defaultucs; /* set screen size */ term->size.y = row; @@ -57,7 +57,8 @@ #define SPACES_PER_TAB 8 /* TERM value */ -#define TERMNAME "st-256color" +//#define TERMNAME "st-256color" +#define TERMNAME "xterm" #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) @@ -186,7 +187,6 @@ struct st_term { unsigned short defaultfg; unsigned short defaultbg; unsigned short defaultcs; - unsigned short defaultucs; int (*setcolorname)(struct st_term *, int, const char *); void (*settitle)(struct st_term *, char *); @@ -205,8 +205,7 @@ void term_resize(struct st_term *term, struct coord size); void term_shutdown(struct st_term *term); void term_init(struct st_term *term, int col, int row, char *shell, char **cmd, const char *logfile, unsigned long windowid, - unsigned defaultfg, unsigned defaultbg, unsigned defaultcs, - unsigned defaultucs); + unsigned defaultfg, unsigned defaultbg, unsigned defaultcs); /* Random utility code */ |