From: Michael D. Lowis Date: Sat, 5 Nov 2016 04:23:42 +0000 (-0400) Subject: Fixed two segfaults and implemented scrolling for selection X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=50a8b53b80d7c6929dd577216bb5bd2c046a756e;p=projs%2Ftide.git Fixed two segfaults and implemented scrolling for selection --- diff --git a/libx/x11.c b/libx/x11.c index 60e7c22..8570bd3 100644 --- a/libx/x11.c +++ b/libx/x11.c @@ -87,7 +87,6 @@ void x11_window(char* name, int width, int height) { /* initialize pixmap and drawing context */ X.pixmap = XCreatePixmap(X.display, X.window, width, height, X.depth); X.xft = XftDrawCreate(X.display, X.pixmap, X.visual, X.colormap); - /* initialize the graphics context */ XGCValues gcv; gcv.foreground = WhitePixel(X.display, X.screen); @@ -206,10 +205,12 @@ void x11_loop(void) { break; } } - /* redraw the window */ - Config->redraw(X.width, X.height); - XCopyArea(X.display, X.pixmap, X.window, X.gc, 0, 0, X.width, X.height, 0, 0); - XFlush(X.display); + if (Running) { + /* redraw the window */ + Config->redraw(X.width, X.height); + XCopyArea(X.display, X.pixmap, X.window, X.gc, 0, 0, X.width, X.height, 0, 0); + XFlush(X.display); + } } XCloseDisplay(X.display); } diff --git a/xpick.c b/xpick.c index 257c28b..91b293b 100644 --- a/xpick.c +++ b/xpick.c @@ -153,21 +153,24 @@ static void redraw(int width, int height) { x11_draw_rect(CLR_BASE02, 0, 0, width, Fonts.base.height); x11_draw_rect(CLR_BASE01, 0, Fonts.base.height, width, 1); /* create the array for the query glyphs */ - height = height / Fonts.base.height - 1, - width = width / Fonts.base.width; - XGlyph glyphs[width], *text = glyphs; + int rows = height / Fonts.base.height - 1; + int cols = width / Fonts.base.width; + XGlyph glyphs[cols], *text = glyphs; /* draw the query */ unsigned start = 0, end = buf_end(&Query); - while (start < end) + while (start < end && start < cols) (text++)->rune = buf_get(&Query, start++); draw_runes(0, 0, CLR_BASE3, CLR_BASE03, glyphs, text - glyphs); - - for (size_t i = 0; i < vec_size(&Choices) && i < height; i++) { - Choice* choice = vec_at(&Choices, i); - if (i == ChoiceIdx) + /* Draw the choices */ + size_t off = (ChoiceIdx >= rows ? (ChoiceIdx-rows+1) : 0); + for (size_t i = 0; i < vec_size(&Choices) && i < rows; i++) { + Choice* choice = vec_at(&Choices, i+off); + if (i+off == ChoiceIdx) { + x11_draw_rect(CLR_BASE1, 0, ((i+1) * Fonts.base.height)+Fonts.base.descent, width, Fonts.base.height); x11_draw_utf8(&Fonts, CLR_BASE03, CLR_BASE1, 0, (i+2) * Fonts.base.height, choice->string); - else + } else { x11_draw_utf8(&Fonts, CLR_BASE1, CLR_BASE03, 0, (i+2) * Fonts.base.height, choice->string); + } } } @@ -218,8 +221,9 @@ int main(int argc, char** argv) { x11_font_load(&Fonts, FONTNAME); x11_loop(); /* print out the choice */ - Choice* choice = (Choice*)vec_at(&Choices, ChoiceIdx); - if (vec_size(&Choices) && ChoiceIdx != SIZE_MAX) + if (vec_size(&Choices) && ChoiceIdx != SIZE_MAX) { + Choice* choice = (Choice*)vec_at(&Choices, ChoiceIdx); puts(choice->string); + } return 0; }