aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rw-r--r--thumbs.c20
-rw-r--r--thumbs.h1
-rw-r--r--window.c59
-rw-r--r--window.h4
5 files changed, 66 insertions, 20 deletions
diff --git a/config.h b/config.h
index b53acb4..775e34c 100644
--- a/config.h
+++ b/config.h
@@ -6,6 +6,8 @@
/* default color to use for window background: *
* (see X(7) "COLOR NAMES" section for valid values) */
#define BG_COLOR "#999999"
+/* default color to use for selections: */
+#define SEL_COLOR "#0000BB"
/* how should images be scaled when they are loaded?: *
* (also controllable via -d/-s/-Z/-z options) *
diff --git a/thumbs.c b/thumbs.c
index e66dd1c..f1703e8 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -88,8 +88,8 @@ void tns_render(tns_t *tns, win_t *win) {
if (!tns || !win)
return;
- tns->cols = win->w / thumb_dim;
- tns->rows = win->h / thumb_dim;
+ tns->cols = MAX(1, win->w / thumb_dim);
+ tns->rows = MAX(1, win->h / thumb_dim);
cnt = tns->cols * tns->rows;
if (tns->first && tns->first + cnt > tns->cnt)
@@ -114,6 +114,22 @@ void tns_render(tns_t *tns, win_t *win) {
}
}
+ tns_highlight(tns, win, -1);
win_draw(win);
}
+void tns_highlight(tns_t *tns, win_t *win, int old) {
+ thumb_t *t;
+
+ if (!tns || !win)
+ return;
+
+ if (old >= 0 && old < tns->cnt) {
+ t = &tns->thumbs[old];
+ win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, False);
+ }
+ if (tns->sel < tns->cnt) {
+ t = &tns->thumbs[tns->sel];
+ win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True);
+ }
+}
diff --git a/thumbs.h b/thumbs.h
index 82c3a1a..a25a15f 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -46,5 +46,6 @@ void tns_free(tns_t*, win_t*);
void tns_load(tns_t*, win_t*, const char*);
void tns_render(tns_t*, win_t*);
+void tns_highlight(tns_t*, win_t*, int);
#endif /* THUMBS_H */
diff --git a/window.c b/window.c
index 38501ca..857b3b5 100644
--- a/window.c
+++ b/window.c
@@ -29,7 +29,7 @@
static Cursor carrow;
static Cursor chand;
static Cursor cwatch;
-static GC bgc;
+static GC gc;
Atom wm_delete_win;
@@ -50,7 +50,8 @@ void win_set_sizehints(win_t *win) {
void win_open(win_t *win) {
win_env_t *e;
XClassHint classhint;
- XColor bgcol;
+ XColor col;
+ XGCValues gcval;
int gmask;
if (!win)
@@ -67,13 +68,18 @@ void win_open(win_t *win) {
e->cmap = DefaultColormap(e->dpy, e->scr);
e->depth = DefaultDepth(e->dpy, e->scr);
- if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
- &bgcol, &bgcol))
+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
+ &col, &col))
+ win->bgcol = col.pixel;
+ else
+ die("could not allocate color: %s", BG_COLOR);
+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), SEL_COLOR,
+ &col, &col))
+ win->selcol = col.pixel;
+ else
die("could not allocate color: %s", BG_COLOR);
- win->bgcol = bgcol.pixel;
win->pm = 0;
-
win->fullscreen = 0;
/* determine window offsets, width & height */
@@ -112,7 +118,8 @@ void win_open(win_t *win) {
chand = XCreateFontCursor(e->dpy, XC_fleur);
cwatch = XCreateFontCursor(e->dpy, XC_watch);
- bgc = XCreateGC(e->dpy, win->xwin, 0, None);
+ gcval.line_width = 2;
+ gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval);
win_set_title(win, "sxiv");
@@ -141,7 +148,7 @@ void win_close(win_t *win) {
XFreeCursor(win->env.dpy, chand);
XFreeCursor(win->env.dpy, cwatch);
- XFreeGC(win->env.dpy, bgc);
+ XFreeGC(win->env.dpy, gc);
XDestroyWindow(win->env.dpy, win->xwin);
XCloseDisplay(win->env.dpy);
@@ -226,11 +233,6 @@ void win_free_pixmap(win_t *win, Pixmap pm) {
XFreePixmap(win->env.dpy, pm);
}
-void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
- if (win)
- XCopyArea(win->env.dpy, pm, win->pm, bgc, 0, 0, w, h, x, y);
-}
-
void win_clear(win_t *win) {
win_env_t *e;
XGCValues gcval;
@@ -239,14 +241,37 @@ void win_clear(win_t *win) {
return;
e = &win->env;
- gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : win->bgcol;
-
+ gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
+ win->bgcol;
if (win->pm)
XFreePixmap(e->dpy, win->pm);
win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
- XChangeGC(e->dpy, bgc, GCForeground, &gcval);
- XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh);
+ XChangeGC(e->dpy, gc, GCForeground, &gcval);
+ XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
+}
+
+void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
+ if (win)
+ XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
+}
+
+void win_draw_rect(win_t *win, int x, int y, int w, int h, Bool sel) {
+ win_env_t *e;
+ XGCValues gcval;
+
+ if (!win)
+ return;
+
+ e = &win->env;
+
+ if (sel)
+ gcval.foreground = win->selcol;
+ else
+ gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
+ win->bgcol;
+ XChangeGC(e->dpy, gc, GCForeground, &gcval);
+ XDrawRectangle(e->dpy, win->pm, gc, x, y, w, h);
}
void win_draw(win_t *win) {
diff --git a/window.h b/window.h
index f00af22..e06c19f 100644
--- a/window.h
+++ b/window.h
@@ -43,6 +43,7 @@ typedef struct win_s {
win_env_t env;
unsigned long bgcol;
+ unsigned long selcol;
Pixmap pm;
int x;
@@ -66,9 +67,10 @@ void win_toggle_fullscreen(win_t*);
Pixmap win_create_pixmap(win_t*, int, int);
void win_free_pixmap(win_t*, Pixmap);
-void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
void win_clear(win_t*);
+void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
+void win_draw_rect(win_t*, int, int, int, int, Bool);
void win_draw(win_t*);
void win_set_title(win_t*, const char*);