#include <ctype.h>
/* Provided by x11.c */
-extern size_t glyph_width(int c);
+extern size_t glyph_width(View* view, int c);
#define BUF (&(view->buffer))
#define CSRPOS (view->buffer.selection.end)
}
}
-static size_t rune_width(int c, size_t xpos, size_t width) {
+static size_t rune_width(View* view, int c, size_t xpos, size_t width) {
if (c == '\r')
return 0;
else if (c == '\n')
return (width-xpos);
else if (c == '\t')
- return (glyph_width(c) - (xpos % glyph_width(c)));
+ return (glyph_width(view, c) - (xpos % glyph_width(view, c)));
else
- return glyph_width(c);
+ return glyph_width(view, c);
}
size_t view_limitrows(View* view, size_t maxrows) {
size_t nrows = 1, off = 0, xpos = 0;
while (nrows < maxrows && off < buf_end(&(view->buffer))) {
Rune rune = buf_getrat(&(view->buffer), off);
- xpos += rune_width(rune, xpos, view->width);
+ xpos += rune_width(view, rune, xpos, view->width);
/* if the line is full, reset the line and increase row count */
if (xpos > view->width) {
xpos = 0, nrows++;
/* populate the row with characters */
for (size_t xpos = 0; xpos < view->width;) {
int rune = buf_getrat(&(view->buffer), off);
- size_t rwidth = rune_width(rune, xpos, view->width);
+ size_t rwidth = rune_width(view, rune, xpos, view->width);
xpos += rwidth;
if (xpos <= view->width) {
size_t len = view->rows[view->nrows-1]->len + 1;
XIC xic;
XIM xim;
GC gc;
+ XftFont* tagfont;
XftFont* font;
};
XftColorAllocValue(X.display, X.visual, X.colormap, &(xc->color), xc);
}
-size_t glyph_width(int c) {
+size_t glyph_width(View* view, int c) {
FcChar32 rune = (FcChar32)c;
XGlyphInfo extents;
- XftTextExtents32(X.display, X.font, &rune, 1, &extents);
+ XftFont* font = (&Regions[TAGS] == view ? X.tagfont : X.font);
+ XftTextExtents32(X.display, font, &rune, 1, &extents);
if (c == '\t')
return (TabWidth * extents.xOff);
else
}
}
-static void draw_view(int i, size_t nrows, drawcsr* csr, int bg, int fg, int sel) {
- size_t fheight = X.font->height;
+static void draw_view(View* view, XftFont* font, size_t nrows, drawcsr* csr, int bg, int fg, int sel) {
+ size_t fheight = font->height;
size_t csrx = SIZE_MAX, csry = SIZE_MAX;
bool csr_drawn = false;
/* draw the view to the window */
- View* view = win_view(i);
view_resize(view, (csr->w - csr->x), nrows);
view_update(view, &csrx, &csry);
- draw_rect(bg, csr->x, csr->y, csr->w, (nrows * fheight) + 9);
+ draw_rect(bg, csr->x, csr->y, csr->w, ((nrows + 1) * fheight) + 9);
for (size_t i = 0; i < nrows; i++) {
Row* row = view_getrow(view, i + view->index);
size_t x = (csr->x + 2), y = (csr->y + 2 + (i * fheight));
draw_rect((i == TAGS ? TagsCsr : EditCsr), x-1, y+fheight-3, 3, 3);
csr_drawn = true;
}
- specs[i].glyph = XftCharIndex(X.display, X.font, rune);
+ specs[i].glyph = XftCharIndex(X.display, font, rune);
specs[i].x = x;
- specs[i].y = y + X.font->ascent;
+ specs[i].y = y + font->ascent;
x += row->cols[i].width;
}
XftColor fgc;
xftcolor(&fgc, EditFg);
- XftDrawGlyphSpec(X.xft, &fgc, X.font, specs, row->len);
+ XftDrawGlyphSpec(X.xft, &fgc, font, specs, row->len);
XftColorFree(X.display, X.visual, X.colormap, &fgc);
}
csr->y += (nrows * fheight) + 3;
size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->len;
double scroll_vis = (double)(vend - vbeg) / (double)bend;
double scroll_off = ((double)vbeg / (double)bend);
- size_t thumbreg = (csr->y - Divider) + 4;
+ size_t thumbreg = (csr->h - Divider) + 4;
size_t thumboff = (size_t)((thumbreg * scroll_off) + Divider);
size_t thumbsz = (size_t)(thumbreg * scroll_vis);
if (thumbsz < 5) thumbsz = 5;
static void xupdate(Job* job) {
int nevents;
- size_t fheight = X.font->height;
/* process events from the queue */
XEventsQueued(X.display, QueuedAfterFlush);
XGetMotionEvents(X.display, X.self, CurrentTime, CurrentTime, &nevents);
(EventHandlers[e.type])(&e);
}
/* determine the size of the regions */
- size_t maxrows = ((X.height - 7) / fheight);
- size_t tagrows = view_limitrows(win_view(TAGS), maxrows / 4);
- size_t editrows = maxrows - tagrows;
+ size_t maxtagrows = ((X.height/4) / X.tagfont->height);
+ size_t tagrows = view_limitrows(win_view(TAGS), maxtagrows);
+ size_t tagregsz = (tagrows * X.tagfont->height) + 7;
+ size_t editrows = (X.height - tagregsz) / X.font->height ;
/* draw the regions to the window */
drawcsr csr = { .w = X.width, .h = X.height };
csr.x += ScrollWidth + 1;
draw_statbox(&csr);
- draw_view(TAGS, tagrows, &csr, TagsBg, TagsFg, TagsSel);
+ draw_view(&Regions[TAGS], X.tagfont, tagrows, &csr, TagsBg, TagsFg, TagsSel);
draw_hrule(&csr);
- draw_view(EDIT, editrows, &csr, EditBg, EditFg, EditSel);
+ draw_view(&Regions[EDIT], X.font, editrows, &csr, EditBg, EditFg, EditSel);
draw_scroll(&csr);
XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
XFlush(X.display);
X.screen = DefaultScreen(X.display);
X.depth = DefaultDepth(X.display, X.screen);
font_load(Fonts[FontSel = 0]);
+ X.tagfont = X.font;
x11_window("unnamed");
/* initialize selection atoms */
for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++)