]> git.mdlowis.com Git - projs/tide.git/commitdiff
Fixed two segfaults and implemented scrolling for selection
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 5 Nov 2016 04:23:42 +0000 (00:23 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 5 Nov 2016 04:23:42 +0000 (00:23 -0400)
libx/x11.c
xpick.c

index 60e7c220671c863f455b3176ade6a231f7ca33bb..8570bd350d94f5fb900d07040691057def6a977e 100644 (file)
@@ -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 257c28be7f9859c15666bf0deb8fc47d2b4ef3c4..91b293b567928e05ba99094c7e88403e27d72a8c 100644 (file)
--- 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;
 }