Highlight selected thumbnail
This commit is contained in:
parent
095217b26f
commit
ef24ded6af
2
config.h
2
config.h
@ -6,6 +6,8 @@
|
|||||||
/* default color to use for window background: *
|
/* default color to use for window background: *
|
||||||
* (see X(7) "COLOR NAMES" section for valid values) */
|
* (see X(7) "COLOR NAMES" section for valid values) */
|
||||||
#define BG_COLOR "#999999"
|
#define BG_COLOR "#999999"
|
||||||
|
/* default color to use for selections: */
|
||||||
|
#define SEL_COLOR "#0000BB"
|
||||||
|
|
||||||
/* how should images be scaled when they are loaded?: *
|
/* how should images be scaled when they are loaded?: *
|
||||||
* (also controllable via -d/-s/-Z/-z options) *
|
* (also controllable via -d/-s/-Z/-z options) *
|
||||||
|
20
thumbs.c
20
thumbs.c
@ -88,8 +88,8 @@ void tns_render(tns_t *tns, win_t *win) {
|
|||||||
if (!tns || !win)
|
if (!tns || !win)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tns->cols = win->w / thumb_dim;
|
tns->cols = MAX(1, win->w / thumb_dim);
|
||||||
tns->rows = win->h / thumb_dim;
|
tns->rows = MAX(1, win->h / thumb_dim);
|
||||||
|
|
||||||
cnt = tns->cols * tns->rows;
|
cnt = tns->cols * tns->rows;
|
||||||
if (tns->first && tns->first + cnt > tns->cnt)
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
thumbs.h
1
thumbs.h
@ -46,5 +46,6 @@ void tns_free(tns_t*, win_t*);
|
|||||||
void tns_load(tns_t*, win_t*, const char*);
|
void tns_load(tns_t*, win_t*, const char*);
|
||||||
|
|
||||||
void tns_render(tns_t*, win_t*);
|
void tns_render(tns_t*, win_t*);
|
||||||
|
void tns_highlight(tns_t*, win_t*, int);
|
||||||
|
|
||||||
#endif /* THUMBS_H */
|
#endif /* THUMBS_H */
|
||||||
|
59
window.c
59
window.c
@ -29,7 +29,7 @@
|
|||||||
static Cursor carrow;
|
static Cursor carrow;
|
||||||
static Cursor chand;
|
static Cursor chand;
|
||||||
static Cursor cwatch;
|
static Cursor cwatch;
|
||||||
static GC bgc;
|
static GC gc;
|
||||||
|
|
||||||
Atom wm_delete_win;
|
Atom wm_delete_win;
|
||||||
|
|
||||||
@ -50,7 +50,8 @@ void win_set_sizehints(win_t *win) {
|
|||||||
void win_open(win_t *win) {
|
void win_open(win_t *win) {
|
||||||
win_env_t *e;
|
win_env_t *e;
|
||||||
XClassHint classhint;
|
XClassHint classhint;
|
||||||
XColor bgcol;
|
XColor col;
|
||||||
|
XGCValues gcval;
|
||||||
int gmask;
|
int gmask;
|
||||||
|
|
||||||
if (!win)
|
if (!win)
|
||||||
@ -67,13 +68,18 @@ void win_open(win_t *win) {
|
|||||||
e->cmap = DefaultColormap(e->dpy, e->scr);
|
e->cmap = DefaultColormap(e->dpy, e->scr);
|
||||||
e->depth = DefaultDepth(e->dpy, e->scr);
|
e->depth = DefaultDepth(e->dpy, e->scr);
|
||||||
|
|
||||||
if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
|
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
|
||||||
&bgcol, &bgcol))
|
&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);
|
die("could not allocate color: %s", BG_COLOR);
|
||||||
|
|
||||||
win->bgcol = bgcol.pixel;
|
|
||||||
win->pm = 0;
|
win->pm = 0;
|
||||||
|
|
||||||
win->fullscreen = 0;
|
win->fullscreen = 0;
|
||||||
|
|
||||||
/* determine window offsets, width & height */
|
/* determine window offsets, width & height */
|
||||||
@ -112,7 +118,8 @@ void win_open(win_t *win) {
|
|||||||
chand = XCreateFontCursor(e->dpy, XC_fleur);
|
chand = XCreateFontCursor(e->dpy, XC_fleur);
|
||||||
cwatch = XCreateFontCursor(e->dpy, XC_watch);
|
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");
|
win_set_title(win, "sxiv");
|
||||||
|
|
||||||
@ -141,7 +148,7 @@ void win_close(win_t *win) {
|
|||||||
XFreeCursor(win->env.dpy, chand);
|
XFreeCursor(win->env.dpy, chand);
|
||||||
XFreeCursor(win->env.dpy, cwatch);
|
XFreeCursor(win->env.dpy, cwatch);
|
||||||
|
|
||||||
XFreeGC(win->env.dpy, bgc);
|
XFreeGC(win->env.dpy, gc);
|
||||||
|
|
||||||
XDestroyWindow(win->env.dpy, win->xwin);
|
XDestroyWindow(win->env.dpy, win->xwin);
|
||||||
XCloseDisplay(win->env.dpy);
|
XCloseDisplay(win->env.dpy);
|
||||||
@ -226,11 +233,6 @@ void win_free_pixmap(win_t *win, Pixmap pm) {
|
|||||||
XFreePixmap(win->env.dpy, 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) {
|
void win_clear(win_t *win) {
|
||||||
win_env_t *e;
|
win_env_t *e;
|
||||||
XGCValues gcval;
|
XGCValues gcval;
|
||||||
@ -239,14 +241,37 @@ void win_clear(win_t *win) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
e = &win->env;
|
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)
|
if (win->pm)
|
||||||
XFreePixmap(e->dpy, win->pm);
|
XFreePixmap(e->dpy, win->pm);
|
||||||
win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
|
win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
|
||||||
|
|
||||||
XChangeGC(e->dpy, bgc, GCForeground, &gcval);
|
XChangeGC(e->dpy, gc, GCForeground, &gcval);
|
||||||
XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh);
|
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) {
|
void win_draw(win_t *win) {
|
||||||
|
4
window.h
4
window.h
@ -43,6 +43,7 @@ typedef struct win_s {
|
|||||||
win_env_t env;
|
win_env_t env;
|
||||||
|
|
||||||
unsigned long bgcol;
|
unsigned long bgcol;
|
||||||
|
unsigned long selcol;
|
||||||
Pixmap pm;
|
Pixmap pm;
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
@ -66,9 +67,10 @@ void win_toggle_fullscreen(win_t*);
|
|||||||
|
|
||||||
Pixmap win_create_pixmap(win_t*, int, int);
|
Pixmap win_create_pixmap(win_t*, int, int);
|
||||||
void win_free_pixmap(win_t*, Pixmap);
|
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_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_draw(win_t*);
|
||||||
|
|
||||||
void win_set_title(win_t*, const char*);
|
void win_set_title(win_t*, const char*);
|
||||||
|
Loading…
Reference in New Issue
Block a user