Xinqi Bao's Git
projects
/
st.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Fixing a resize bug, if a smaller amount than the lineheight is resized.
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
cdf1fdc
..
2654676
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-72,8
+72,6
@@
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
#define IS_SET(flag) (term.mode & (flag))
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
#define IS_SET(flag) (term.mode & (flag))
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000)
-#define X2COL(x) (((x) - borderpx)/xw.cw)
-#define Y2ROW(y) (((y) - borderpx)/xw.ch)
#define VT102ID "\033[?6c"
#define VT102ID "\033[?6c"
@@
-582,6
+580,22
@@
selinit(void) {
sel.xtarget = XA_STRING;
}
sel.xtarget = XA_STRING;
}
+static int
+x2col(int x) {
+ x -= borderpx;
+ x /= xw.cw;
+
+ return LIMIT(x, 0, term.col-1);
+}
+
+static int
+y2row(int y) {
+ y -= borderpx;
+ y /= xw.ch;
+
+ return LIMIT(y, 0, term.row-1);
+}
+
static inline bool
selected(int x, int y) {
int bx, ex;
static inline bool
selected(int x, int y) {
int bx, ex;
@@
-603,8
+617,9
@@
getbuttoninfo(XEvent *e, int *b, int *x, int *y) {
if(b)
*b = e->xbutton.button;
if(b)
*b = e->xbutton.button;
- *x = X2COL(e->xbutton.x);
- *y = Y2ROW(e->xbutton.y);
+ *x = x2col(e->xbutton.x);
+ *y = y2row(e->xbutton.y);
+
sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex;
sel.b.y = MIN(sel.by, sel.ey);
sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx;
sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex;
sel.b.y = MIN(sel.by, sel.ey);
sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx;
@@
-613,8
+628,8
@@
getbuttoninfo(XEvent *e, int *b, int *x, int *y) {
void
mousereport(XEvent *e) {
void
mousereport(XEvent *e) {
- int x =
X2COL
(e->xbutton.x);
- int y =
Y2ROW
(e->xbutton.y);
+ int x =
x2col
(e->xbutton.x);
+ int y =
y2row
(e->xbutton.y);
int button = e->xbutton.button;
int state = e->xbutton.state;
char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 };
int button = e->xbutton.button;
int state = e->xbutton.state;
char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 };
@@
-656,8
+671,8
@@
bpress(XEvent *e) {
draw();
}
sel.mode = 1;
draw();
}
sel.mode = 1;
- sel.ex = sel.bx =
X2COL
(e->xbutton.x);
- sel.ey = sel.by =
Y2ROW
(e->xbutton.y);
+ sel.ex = sel.bx =
x2col
(e->xbutton.x);
+ sel.ey = sel.by =
y2row
(e->xbutton.y);
}
}
}
}
@@
-2226,7
+2241,12
@@
xloadfonts(char *fontstr, int fontsize) {
FcResult result;
double fontval;
FcResult result;
double fontval;
- pattern = FcNameParse((FcChar8 *)fontstr);
+ if(fontstr[0] == '-') {
+ pattern = XftXlfdParse(fontstr, False, False);
+ } else {
+ pattern = FcNameParse((FcChar8 *)fontstr);
+ }
+
if(!pattern)
die("st: can't open font %s\n", fontstr);
if(!pattern)
die("st: can't open font %s\n", fontstr);
@@
-2378,9
+2398,6
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
*temp, revfg, revbg;
XRenderColor colfg, colbg;
*temp, revfg, revbg;
XRenderColor colfg, colbg;
- if(base.mode & ATTR_REVERSE)
- temp = fg, fg = bg, bg = temp;
-
if(base.mode & ATTR_BOLD) {
if(BETWEEN(base.fg, 0, 7)) {
/* basic system colors */
if(base.mode & ATTR_BOLD) {
if(BETWEEN(base.fg, 0, 7)) {
/* basic system colors */
@@
-2403,7
+2420,7
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
if(base.mode & ATTR_ITALIC)
font = &dc.ifont;
if(base.mode & ATTR_ITALIC)
font = &dc.ifont;
- if(
base.mode & (ATTR_ITALIC|ATTR_ITALIC
))
+ if(
(base.mode & ATTR_ITALIC) && (base.mode & ATTR_BOLD
))
font = &dc.ibfont;
if(IS_SET(MODE_REVERSE)) {
font = &dc.ibfont;
if(IS_SET(MODE_REVERSE)) {
@@
-2430,6
+2447,9
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
}
}
}
}
+ if(base.mode & ATTR_REVERSE)
+ temp = fg, fg = bg, bg = temp;
+
XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen,
&extents);
width = extents.xOff;
XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen,
&extents);
width = extents.xOff;
@@
-2722,8
+2742,6
@@
cresize(int width, int height)
col = (xw.w - 2*borderpx) / xw.cw;
row = (xw.h - 2*borderpx) / xw.ch;
col = (xw.w - 2*borderpx) / xw.cw;
row = (xw.h - 2*borderpx) / xw.ch;
- if(col == term.col && row == term.row)
- return;
tresize(col, row);
xresize(col, row);
tresize(col, row);
xresize(col, row);
@@
-2732,6
+2750,8
@@
cresize(int width, int height)
void
resize(XEvent *e) {
void
resize(XEvent *e) {
+ fprintf(stderr, "resize -> %d,%d\n", e->xconfigure.width,
+ e->xconfigure.height);
if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h)
return;
if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h)
return;