X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=x.c;h=1b656aca1636f871eea9af371139ce921f7721a7;hb=dbe8676d7d69651132bde2b6d9ec3787cbbc552a;hp=186e4081c396256fe73666ef86387b44573cf4fe;hpb=a09138afa57adb4b76dba8ca72dc7ee2642a5c8d;p=st.git diff --git a/x.c b/x.c index 186e408..1b656ac 100644 --- a/x.c +++ b/x.c @@ -88,12 +88,16 @@ static void xclear(int, int, int, int); static void xdrawcursor(void); static int xgeommasktogravity(int); static void xinit(void); +static void cresize(int, int); +static void xresize(int, int); static int xloadfont(Font *, FcPattern *); static void xloadfonts(char *, double); static void xunloadfont(Font *); static void xunloadfonts(void); static void xsetenv(void); static void xseturgency(int); +static int x2col(int); +static int y2row(int); static void expose(XEvent *); static void visibility(XEvent *); @@ -109,7 +113,6 @@ static void propnotify(XEvent *); static void selnotify(XEvent *); static void selclear_(XEvent *); static void selrequest(XEvent *); - static void selcopy(Time); static void getbuttoninfo(XEvent *); static void mousereport(XEvent *); @@ -148,6 +151,11 @@ static DC dc; static XWindow xw; static XSelection xsel; +enum window_state { + WIN_VISIBLE = 1, + WIN_FOCUSED = 2 +}; + /* Font Ring Cache */ enum { FRC_NORMAL, @@ -184,7 +192,7 @@ zoomabs(const Arg *arg) xunloadfonts(); xloadfonts(usedfont, arg->f); cresize(0, 0); - ttyresize(); + ttyresize(win.tw, win.th); redraw(); xhints(); } @@ -200,6 +208,24 @@ zoomreset(const Arg *arg) } } +int +x2col(int x) +{ + x -= borderpx; + x /= win.cw; + + return LIMIT(x, 0, term.col-1); +} + +int +y2row(int y) +{ + y -= borderpx; + y /= win.ch; + + return LIMIT(y, 0, term.row-1); +} + void getbuttoninfo(XEvent *e) { @@ -596,6 +622,23 @@ bmotion(XEvent *e) tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey)); } +void +cresize(int width, int height) +{ + int col, row; + + if (width != 0) + win.w = width; + if (height != 0) + win.h = height; + + col = (win.w - 2 * borderpx) / win.cw; + row = (win.h - 2 * borderpx) / win.ch; + + tresize(col, row); + xresize(col, row); +} + void xresize(int col, int row) { @@ -1636,7 +1679,7 @@ resize(XEvent *e) return; cresize(e->xconfigure.width, e->xconfigure.height); - ttyresize(); + ttyresize(win.tw, win.th); } void @@ -1667,7 +1710,7 @@ run(void) cresize(w, h); ttynew(); - ttyresize(); + ttyresize(win.tw, win.th); clock_gettime(CLOCK_MONOTONIC, &last); lastblink = last;