[hackers] [st] Removing the xclearborders() hack. St now cleans up the parts of the border, || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Sat, 6 Oct 2012 13:45:40 +0200 (CEST)

changeset: 352:cef23c4f9be8
tag: tip
user: Christoph Lohmann <20h_AT_r-36.net>
date: Sat Oct 06 13:43:01 2012 +0200
files: st.c
description:
Removing the xclearborders() hack. St now cleans up the parts of the border,
if something needs to be drawn close to it.


diff -r b0ba979227b1 -r cef23c4f9be8 st.c
--- a/st.c Sat Oct 06 09:58:45 2012 +0200
+++ b/st.c Sat Oct 06 13:43:01 2012 +0200
_AT_@ -224,7 +224,9 @@
         int mode;
         int bx, by;
         int ex, ey;
- struct {int x, y;} b, e;
+ struct {
+ int x, y;
+ } b, e;
         char *clip;
         Atom xtarget;
         bool alt;
_AT_@ -587,10 +589,10 @@
                 return BETWEEN(x, bx, ex);
         }
 
- return ((sel.b.y < y&&y < sel.e.y)
- || (y==sel.e.y && x<=sel.e.x))
- || (y==sel.b.y && x>=sel.b.x
- && (x<=sel.e.x || sel.b.y!=sel.e.y));
+ return ((sel.b.y < y && y < sel.e.y)
+ || (y == sel.e.y && x <= sel.e.x))
+ || (y == sel.b.y && x >= sel.b.x
+ && (x <= sel.e.x || sel.b.y != sel.e.y));
 }
 
 void
_AT_@ -803,12 +805,12 @@
                                 /* double click to select word */
                                 sel.bx = sel.ex;
                                 while(sel.bx > 0 && term.line[sel.ey][sel.bx-1].state & GLYPH_SET &&
- term.line[sel.ey][sel.bx-1].c[0] != ' ') {
+ term.line[sel.ey][sel.bx-1].c[0] != ' ') {
                                         sel.bx--;
                                 }
                                 sel.b.x = sel.bx;
                                 while(sel.ex < term.col-1 && term.line[sel.ey][sel.ex+1].state & GLYPH_SET &&
- term.line[sel.ey][sel.ex+1].c[0] != ' ') {
+ term.line[sel.ey][sel.ex+1].c[0] != ' ') {
                                         sel.ex++;
                                 }
                                 sel.e.x = sel.ex;
_AT_@ -1031,7 +1033,8 @@
         memset(term.tabs, 0, term.col * sizeof(*term.tabs));
         for(i = TAB; i < term.col; i += TAB)
                 term.tabs[i] = 1;
- term.top = 0, term.bot = term.row - 1;
+ term.top = 0;
+ term.bot = term.row - 1;
         term.mode = MODE_WRAP;
 
         tclearregion(0, 0, term.col-1, term.row-1);
_AT_@ -1040,7 +1043,8 @@
 void
 tnew(int col, int row) {
         /* set screen size */
- term.row = row, term.col = col;
+ term.row = row;
+ term.col = col;
         term.line = xmalloc(term.row * sizeof(Line));
         term.alt = xmalloc(term.row * sizeof(Line));
         term.dirty = xmalloc(term.row * sizeof(*term.dirty));
_AT_@ -1437,8 +1441,8 @@
                                 if(IS_SET(MODE_ALTSCREEN))
                                         tclearregion(0, 0, term.col-1, term.row-1);
                                 if((set && !IS_SET(MODE_ALTSCREEN)) ||
- (!set && IS_SET(MODE_ALTSCREEN))) {
- tswapscreen();
+ (!set && IS_SET(MODE_ALTSCREEN))) {
+ tswapscreen();
                                 }
                                 if(*args != 1049)
                                         break;
_AT_@ -1909,7 +1913,6 @@
                         case 'c': /* RIS -- Reset to inital state */
                                 treset();
                                 term.esc = 0;
- xclearborders();
                                 xresettitle();
                                 break;
                         case '=': /* DECPAM -- Application keypad */
_AT_@ -2091,18 +2094,6 @@
 }
 
 void
-xclearborders(void) {
- /* top and left border */
- xclear(0, 0, BORDER, xw.h);
- xclear(0, 0, xw.w, BORDER);
-
- /* lower and right border */
- xclear(BORDER, xw.th - 1, xw.w, xw.h);
- /* Will just draw what hasn't been drawn by the previous call. */
- xclear(xw.tw - 1, BORDER, xw.w, xw.h - xw.th - 2);
-}
-
-void
 xhints(void) {
         XClassHint class = {opt_class ? opt_class : TNAME, TNAME};
         XWMHints wm = {.flags = InputHint, .input = 1};
_AT_@ -2264,8 +2255,8 @@
 
 void
 xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
- int winx = BORDER+x*xw.cw, winy = BORDER+y*xw.ch,
- width = charlen*xw.cw;
+ int winx = BORDER + x * xw.cw, winy = BORDER + 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],
_AT_@ -2328,6 +2319,20 @@
                         &extents);
         width = extents.xOff;
 
+ /* Intelligent cleaning up of the borders. */
+ if(x == 0) {
+ xclear(0, (y == 0)? 0 : winy, BORDER,
+ 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,
+ winy + xw.ch + (y == term.row-1)? xw.h : 0);
+ }
+ if(y == 0)
+ xclear(winx, 0, winx + width, BORDER);
+ 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);
_AT_@ -2382,7 +2387,6 @@
 redraw(void) {
         struct timespec tv = {0, REDRAW_TIMEOUT * 1000};
 
- xclearborders();
         tfulldirt();
         draw();
         XSync(xw.dpy, False); /* necessary for a good tput flash */
_AT_@ -2598,7 +2602,6 @@
 
         tresize(col, row);
         xresize(col, row);
- xclearborders();
         ttyresize();
 }
 
Received on Sat Oct 06 2012 - 13:45:40 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 06 2012 - 13:48:06 CEST