ltk

Socket-based GUI for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

commit dd010d6ac6864d58107799eb3625cdd4660684a1
parent 1e8ddcfae89e504b4106c3cc213b1e81e9ebca7d
Author: lumidify <nobody@lumidify.org>
Date:   Sat, 23 Jan 2021 22:11:29 +0100

Do some more stuff with the scrollbar, but it's still really glitchy

Diffstat:
Mbox.c | 7+++++--
Mbutton.c | 14+++++++++++---
Mltkd.c | 4++--
Mtest.gui | 19+++++++++++++++----
Mtext_line.c | 9++++-----
Mtext_stb.c | 8+++++++-
6 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/box.c b/box.c @@ -133,7 +133,8 @@ static void ltk_recalculate_box(ltk_box *box) { ltk_widget *ptr; ltk_rect *sc_rect = &box->sc->widget.rect; - int cur_pos = 0; + int offset = box->orient == LTK_HORIZONTAL ? box->widget.rect.x : box->widget.rect.y; + int cur_pos = offset; for (size_t i = 0; i < box->num_widgets; i++) { ptr = box->widgets[i]; if (box->orient == LTK_HORIZONTAL) { @@ -164,12 +165,14 @@ ltk_recalculate_box(ltk_box *box) { cur_pos += ptr->rect.h; } } - ltk_scrollbar_set_virtual_size(box->sc, cur_pos); + ltk_scrollbar_set_virtual_size(box->sc, cur_pos - offset); if (box->orient == LTK_HORIZONTAL) { + sc_rect->x = box->widget.rect.x; sc_rect->y = box->widget.rect.y + box->widget.rect.h - sc_rect->h; sc_rect->w = box->widget.rect.w; } else { sc_rect->x = box->widget.rect.x + box->widget.rect.w - sc_rect->w; + sc_rect->y = box->widget.rect.y; sc_rect->h = box->widget.rect.h; } } diff --git a/button.c b/button.c @@ -128,6 +128,10 @@ static void ltk_button_draw(ltk_button *button, ltk_rect clip) { ltk_window *window = button->widget.window; ltk_rect rect = button->widget.rect; + ltk_rect clip_final = ltk_rect_intersect(clip, rect); + /* no idea why it would be less than 0, but whatever */ + if (clip_final.w <= 0 || clip_final.h <= 0) + return; int bw = theme.border_width; LtkColor *border; LtkColor *fill; @@ -152,21 +156,25 @@ ltk_button_draw(ltk_button *button, ltk_rect clip) { ltk_fatal("No style found for button!\n"); } XSetForeground(window->dpy, window->gc, fill->xcolor.pixel); - XFillRectangle(window->dpy, window->xwindow, window->gc, rect.x, - rect.y, rect.w, rect.h); + XFillRectangle(window->dpy, window->xwindow, window->gc, clip_final.x, + clip_final.y, clip_final.w, clip_final.h); /* FIXME: Why did I do this? */ if (bw < 1) return; + /* FIXME: Maybe draw to tmp pixmap first, so this can be done properly? */ + /* XSetForeground(window->dpy, window->gc, border->xcolor.pixel); XSetLineAttributes(window->dpy, window->gc, bw, LineSolid, CapButt, JoinMiter); XDrawRectangle(window->dpy, window->xwindow, window->gc, rect.x + bw / 2, rect.y + bw / 2, rect.w - bw, rect.h - bw); + */ int text_w, text_h; ltk_text_line_get_size(button->tl, &text_w, &text_h); int text_x = rect.x + (rect.w - text_w) / 2; int text_y = rect.y + (rect.h - text_h) / 2; - ltk_text_line_draw(button->tl, window->gc, text_x, text_y, clip); + /* FIXME: Actually use button->text_pixmap */ + ltk_text_line_draw(button->tl, window->gc, text_x, text_y, clip_final); } static void diff --git a/ltkd.c b/ltkd.c @@ -187,8 +187,8 @@ ltk_mainloop(ltk_window *window) { maxfd = listenfd; printf("%d", window->xwindow); - fflush(stdout); - /*daemonize();*/ + /*fflush(stdout);*/ + daemonize(); while (running) { rfds = rallfds; diff --git a/test.gui b/test.gui @@ -1,10 +1,21 @@ -grid grd1 create 2 2 +grid grd1 create 2 1 grid grd1 set-row-weight 0 1 grid grd1 set-row-weight 1 1 grid grd1 set-column-weight 0 1 -grid grd1 set-column-weight 1 1 set-root-widget grd1 +box box1 create vertical +grid grd1 add box1 0 0 1 1 nsew button btn1 create "I'm a button!" -grid grd1 add btn1 0 0 1 1 u button btn2 create "I'm also a button!" -grid grd1 add btn2 1 0 1 2 ew +button btn3 create "I'm another boring button." +box box1 add btn1 ew +box box1 add btn2 e +box box1 add btn3 +box box2 create vertical +grid grd1 add box2 1 0 1 1 nsew +button btn4 create "2 I'm a button!" +button btn5 create "2 I'm also a button!" +button btn6 create "2 I'm another boring button." +box box2 add btn4 ew +box box2 add btn5 e +box box2 add btn6 diff --git a/text_line.c b/text_line.c @@ -42,7 +42,7 @@ void ltk_text_line_destroy(LtkTextLine *tl); static void ltk_text_line_create_glyphs(struct ltk_text_line *tl); static void ltk_text_line_draw_glyph(ltk_glyph *glyph, int xoff, int yoff, - XImage *img, XColor fg, ltk_rect clip); + XImage *img, XColor fg); static XImage *ltk_create_ximage(Display *dpy, int w, int h, int depth, XColor bg); @@ -68,7 +68,7 @@ ltk_create_ximage(Display *dpy, int w, int h, int depth, XColor bg) { /* based on http://codemadness.org/git/dwm-font/file/drw.c.html#l315 */ static void -ltk_text_line_draw_glyph(ltk_glyph *glyph, int xoff, int yoff, XImage *img, XColor fg, ltk_rect clip) { +ltk_text_line_draw_glyph(ltk_glyph *glyph, int xoff, int yoff, XImage *img, XColor fg) { int x = glyph->x + xoff; int y = glyph->y + yoff; double a; @@ -95,8 +95,7 @@ ltk_text_line_render( GC gc, Colormap colormap, XColor fg, - XColor bg, - ltk_rect clip) + XColor bg) { ltk_glyph *glyph; @@ -106,7 +105,7 @@ ltk_text_line_render( /* FIXME: pass old image; if it has same dimensions, just clear it */ XImage *img = ltk_create_ximage(dpy, tl->w, tl->h, depth, bg); for (int i = 0; i < tl->glyph_len; i++) { - ltk_text_line_draw_glyph(&tl->glyphs[i], -tl->x_min, -tl->y_min, img, fg, clip); + ltk_text_line_draw_glyph(&tl->glyphs[i], -tl->x_min, -tl->y_min, img, fg); } return img; } diff --git a/text_stb.c b/text_stb.c @@ -535,7 +535,13 @@ ltk_text_line_render( /* FIXME: error checking if img is rendered yet, tm initialized, etc. */ void ltk_text_line_draw(LtkTextLine *tl, GC gc, int x, int y, ltk_rect clip) { - XPutImage(tm.dpy, tl->window, gc, tl->img, 0, 0, x, y, tl->w, tl->h); + int xoff = clip.x - x; + int yoff = clip.y - y; + xoff = xoff >= 0 ? xoff : 0; + yoff = yoff >= 0 ? yoff : 0; + int w = clip.w > tl->w - xoff ? tl->w - xoff : clip.w; + int h = clip.h > tl->h - yoff ? tl->h - yoff : clip.h; + XPutImage(tm.dpy, tl->window, gc, tl->img, xoff, yoff, x + xoff, y + yoff, w, h); } void