apply clang-format
minus the bogus changes Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
This commit is contained in:
parent
2434e83807
commit
f2f4903de4
20
autoreload.c
20
autoreload.c
|
@ -28,7 +28,10 @@
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static struct { char *buf; size_t len; } scratch;
|
static struct {
|
||||||
|
char *buf;
|
||||||
|
size_t len;
|
||||||
|
} scratch;
|
||||||
|
|
||||||
void arl_init(arl_t *arl)
|
void arl_init(arl_t *arl)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +97,10 @@ bool arl_handle(arl_t *arl)
|
||||||
char *ptr;
|
char *ptr;
|
||||||
const struct inotify_event *e;
|
const struct inotify_event *e;
|
||||||
/* inotify_event aligned buffer */
|
/* inotify_event aligned buffer */
|
||||||
static union { char d[4096]; struct inotify_event e; } buf;
|
static union {
|
||||||
|
char d[4096];
|
||||||
|
struct inotify_event e;
|
||||||
|
} buf;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
|
ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
|
||||||
|
@ -105,7 +111,7 @@ bool arl_handle(arl_t *arl)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*e) + e->len) {
|
for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*e) + e->len) {
|
||||||
e = (const struct inotify_event*) ptr;
|
e = (const struct inotify_event *)ptr;
|
||||||
if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) {
|
if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) {
|
||||||
reload = true;
|
reload = true;
|
||||||
} else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) {
|
} else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) {
|
||||||
|
@ -128,18 +134,18 @@ void arl_init(arl_t *arl)
|
||||||
|
|
||||||
void arl_cleanup(arl_t *arl)
|
void arl_cleanup(arl_t *arl)
|
||||||
{
|
{
|
||||||
(void) arl;
|
(void)arl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void arl_add(arl_t *arl, const char *filepath)
|
void arl_add(arl_t *arl, const char *filepath)
|
||||||
{
|
{
|
||||||
(void) arl;
|
(void)arl;
|
||||||
(void) filepath;
|
(void)filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool arl_handle(arl_t *arl)
|
bool arl_handle(arl_t *arl)
|
||||||
{
|
{
|
||||||
(void) arl;
|
(void)arl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
commands.c
14
commands.c
|
@ -326,10 +326,10 @@ bool ci_drag(arg_t drag_mode)
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (drag_mode == DRAG_ABSOLUTE) {
|
if (drag_mode == DRAG_ABSOLUTE) {
|
||||||
px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) /
|
px = MIN(MAX(0.0, x - win.w * 0.1), win.w * 0.8) /
|
||||||
(win.w*0.8) * (win.w - img.w * img.zoom);
|
(win.w * 0.8) * (win.w - img.w * img.zoom);
|
||||||
py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) /
|
py = MIN(MAX(0.0, y - win.h * 0.1), win.h * 0.8) /
|
||||||
(win.h*0.8) * (win.h - img.h * img.zoom);
|
(win.h * 0.8) * (win.h - img.h * img.zoom);
|
||||||
} else {
|
} else {
|
||||||
px = img.x + x - ox;
|
px = img.x + x - ox;
|
||||||
py = img.y + y - oy;
|
py = img.y + y - oy;
|
||||||
|
@ -343,7 +343,8 @@ bool ci_drag(arg_t drag_mode)
|
||||||
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
||||||
if (e.type == ButtonPress || e.type == ButtonRelease)
|
if (e.type == ButtonPress || e.type == ButtonRelease)
|
||||||
break;
|
break;
|
||||||
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
|
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e))
|
||||||
|
;
|
||||||
ox = x;
|
ox = x;
|
||||||
oy = y;
|
oy = y;
|
||||||
x = e.xmotion.x;
|
x = e.xmotion.x;
|
||||||
|
@ -443,7 +444,8 @@ bool ct_drag_mark_image(arg_t _)
|
||||||
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
||||||
if (e.type == ButtonPress || e.type == ButtonRelease)
|
if (e.type == ButtonPress || e.type == ButtonRelease)
|
||||||
break;
|
break;
|
||||||
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
|
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e))
|
||||||
|
;
|
||||||
sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y);
|
sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
36
image.c
36
image.c
|
@ -55,7 +55,7 @@ enum { DEF_WEBP_DELAY = 75 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ZOOM_MIN (zoom_levels[0] / 100)
|
#define ZOOM_MIN (zoom_levels[0] / 100)
|
||||||
#define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels)-1] / 100)
|
#define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels) - 1] / 100)
|
||||||
|
|
||||||
static int calc_cache_size(void)
|
static int calc_cache_size(void)
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ static int calc_cache_size(void)
|
||||||
#endif
|
#endif
|
||||||
if (pages < 0 || page_size < 0)
|
if (pages < 0 || page_size < 0)
|
||||||
return CACHE_SIZE_FALLBACK;
|
return CACHE_SIZE_FALLBACK;
|
||||||
cache = (pages/100) * CACHE_SIZE_MEM_PERCENTAGE;
|
cache = (pages / 100) * CACHE_SIZE_MEM_PERCENTAGE;
|
||||||
cache *= page_size;
|
cache *= page_size;
|
||||||
|
|
||||||
return MIN(cache, CACHE_SIZE_LIMIT);
|
return MIN(cache, CACHE_SIZE_LIMIT);
|
||||||
|
@ -234,12 +234,12 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
|
||||||
while (ext) {
|
while (ext) {
|
||||||
if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
|
if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
|
||||||
if (ext[1] & 1)
|
if (ext[1] & 1)
|
||||||
transp = (int) ext[4];
|
transp = (int)ext[4];
|
||||||
else
|
else
|
||||||
transp = -1;
|
transp = -1;
|
||||||
|
|
||||||
delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
|
delay = 10 * ((unsigned int)ext[3] << 8 | (unsigned int)ext[2]);
|
||||||
disposal = (unsigned int) ext[1] >> 2 & 0x7;
|
disposal = (unsigned int)ext[1] >> 2 & 0x7;
|
||||||
}
|
}
|
||||||
ext = NULL;
|
ext = NULL;
|
||||||
DGifGetExtensionNext(gif, &ext);
|
DGifGetExtensionNext(gif, &ext);
|
||||||
|
@ -280,7 +280,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
|
||||||
for (i = 0; i < sh; i++) {
|
for (i = 0; i < sh; i++) {
|
||||||
for (j = 0; j < sw; j++) {
|
for (j = 0; j < sw; j++) {
|
||||||
if (i < y || i >= y + h || j < x || j >= x + w ||
|
if (i < y || i >= y + h || j < x || j >= x + w ||
|
||||||
rows[i-y][j-x] == transp)
|
rows[i - y][j - x] == transp)
|
||||||
{
|
{
|
||||||
if (prev_frame != NULL &&
|
if (prev_frame != NULL &&
|
||||||
(prev_disposal != 2 || i < py || i >= py + ph ||
|
(prev_disposal != 2 || i < py || i >= py + ph ||
|
||||||
|
@ -292,9 +292,9 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(cmap != NULL);
|
assert(cmap != NULL);
|
||||||
r = cmap->Colors[rows[i-y][j-x]].Red;
|
r = cmap->Colors[rows[i - y][j - x]].Red;
|
||||||
g = cmap->Colors[rows[i-y][j-x]].Green;
|
g = cmap->Colors[rows[i - y][j - x]].Green;
|
||||||
b = cmap->Colors[rows[i-y][j-x]].Blue;
|
b = cmap->Colors[rows[i - y][j - x]].Blue;
|
||||||
*ptr = 0xffu << 24 | r << 16 | g << 8 | b;
|
*ptr = 0xffu << 24 | r << 16 | g << 8 | b;
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
|
@ -418,7 +418,7 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file)
|
||||||
imlib_context_set_image(im);
|
imlib_context_set_image(im);
|
||||||
imlib_image_set_format("webp");
|
imlib_image_set_format("webp");
|
||||||
/* Get an iterator of this frame - used for frame info (duration, etc.) */
|
/* Get an iterator of this frame - used for frame info (duration, etc.) */
|
||||||
WebPDemuxGetFrame(demux, m->cnt+1, &iter);
|
WebPDemuxGetFrame(demux, m->cnt + 1, &iter);
|
||||||
imlib_image_set_has_alpha((flags & ALPHA_FLAG) == ALPHA_FLAG);
|
imlib_image_set_has_alpha((flags & ALPHA_FLAG) == ALPHA_FLAG);
|
||||||
/* Store info for this frame */
|
/* Store info for this frame */
|
||||||
m->frames[m->cnt].im = im;
|
m->frames[m->cnt].im = im;
|
||||||
|
@ -674,8 +674,8 @@ static bool img_fit(img_t *img)
|
||||||
if (img->scalemode == SCALE_ZOOM)
|
if (img->scalemode == SCALE_ZOOM)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
zw = (float) img->win->w / (float) img->w;
|
zw = (float)img->win->w / (float)img->w;
|
||||||
zh = (float) img->win->h / (float) img->h;
|
zh = (float)img->win->h / (float)img->h;
|
||||||
|
|
||||||
switch (img->scalemode) {
|
switch (img->scalemode) {
|
||||||
case SCALE_FILL:
|
case SCALE_FILL:
|
||||||
|
@ -693,7 +693,7 @@ static bool img_fit(img_t *img)
|
||||||
}
|
}
|
||||||
z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX);
|
z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX);
|
||||||
|
|
||||||
if (ABS(img->zoom - z) > 1.0/MAX(img->w, img->h)) {
|
if (ABS(img->zoom - z) > 1.0 / MAX(img->w, img->h)) {
|
||||||
img->zoom = z;
|
img->zoom = z;
|
||||||
img->dirty = title_dirty = true;
|
img->dirty = title_dirty = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -839,14 +839,14 @@ bool img_zoom_to(img_t *img, float z)
|
||||||
|
|
||||||
bool img_zoom(img_t *img, int d)
|
bool img_zoom(img_t *img, int d)
|
||||||
{
|
{
|
||||||
int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels)-1;
|
int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels) - 1;
|
||||||
while (i >= 0 && i < (int)ARRLEN(zoom_levels) &&
|
while (i >= 0 && i < (int)ARRLEN(zoom_levels) &&
|
||||||
(d > 0 ? zoom_levels[i]/100 <= img->zoom : zoom_levels[i]/100 >= img->zoom))
|
(d > 0 ? zoom_levels[i] / 100 <= img->zoom : zoom_levels[i] / 100 >= img->zoom))
|
||||||
{
|
{
|
||||||
i += d;
|
i += d;
|
||||||
}
|
}
|
||||||
i = MIN(MAX(i, 0), (int)ARRLEN(zoom_levels)-1);
|
i = MIN(MAX(i, 0), (int)ARRLEN(zoom_levels) - 1);
|
||||||
return img_zoom_to(img, zoom_levels[i]/100);
|
return img_zoom_to(img, zoom_levels[i] / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool img_pos(img_t *img, float x, float y)
|
bool img_pos(img_t *img, float x, float y)
|
||||||
|
@ -883,7 +883,7 @@ bool img_pan(img_t *img, direction_t dir, int d)
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
x = y = MAX(1, (float) d * img->zoom);
|
x = y = MAX(1, (float)d * img->zoom);
|
||||||
} else {
|
} else {
|
||||||
x = img->win->w / (d < 0 ? 1 : PAN_FRACTION);
|
x = img->win->w / (d < 0 ? 1 : PAN_FRACTION);
|
||||||
y = img->win->h / (d < 0 ? 1 : PAN_FRACTION);
|
y = img->win->h / (d < 0 ? 1 : PAN_FRACTION);
|
||||||
|
|
47
main.c
47
main.c
|
@ -45,10 +45,11 @@
|
||||||
|
|
||||||
#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
|
#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
|
||||||
((t1)->tv_usec - (t2)->tv_usec) / 1000)
|
((t1)->tv_usec - (t2)->tv_usec) / 1000)
|
||||||
#define TV_ADD_MSEC(tv,t) do { \
|
#define TV_ADD_MSEC(tv, t) \
|
||||||
(tv)->tv_sec += (t) / 1000; \
|
do { \
|
||||||
(tv)->tv_usec += (t) % 1000 * 1000; \
|
(tv)->tv_sec += (t) / 1000; \
|
||||||
} while (0)
|
(tv)->tv_usec += (t) % 1000 * 1000; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int err;
|
int err;
|
||||||
|
@ -112,8 +113,8 @@ static void cleanup(void)
|
||||||
static bool xgetline(char **lineptr, size_t *n)
|
static bool xgetline(char **lineptr, size_t *n)
|
||||||
{
|
{
|
||||||
ssize_t len = getdelim(lineptr, n, options->using_null ? '\0' : '\n', stdin);
|
ssize_t len = getdelim(lineptr, n, options->using_null ? '\0' : '\n', stdin);
|
||||||
if (!options->using_null && len > 0 && (*lineptr)[len-1] == '\n')
|
if (!options->using_null && len > 0 && (*lineptr)[len - 1] == '\n')
|
||||||
(*lineptr)[len-1] = '\0';
|
(*lineptr)[len - 1] = '\0';
|
||||||
return len > 0;
|
return len > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ static void check_add_file(const char *filename, bool given)
|
||||||
if (fileidx == filecnt) {
|
if (fileidx == filecnt) {
|
||||||
filecnt *= 2;
|
filecnt *= 2;
|
||||||
files = erealloc(files, filecnt * sizeof(*files));
|
files = erealloc(files, filecnt * sizeof(*files));
|
||||||
memset(&files[filecnt/2], 0, filecnt/2 * sizeof(*files));
|
memset(&files[filecnt / 2], 0, filecnt / 2 * sizeof(*files));
|
||||||
}
|
}
|
||||||
|
|
||||||
files[fileidx].name = estrdup(filename);
|
files[fileidx].name = estrdup(filename);
|
||||||
|
@ -193,8 +194,8 @@ void remove_file(int n, bool manual)
|
||||||
markcnt--;
|
markcnt--;
|
||||||
|
|
||||||
if (files[n].path != files[n].name)
|
if (files[n].path != files[n].name)
|
||||||
free((void*) files[n].path);
|
free((void *)files[n].path);
|
||||||
free((void*) files[n].name);
|
free((void *)files[n].name);
|
||||||
if (tns.thumbs != NULL)
|
if (tns.thumbs != NULL)
|
||||||
tns_unload(&tns, n);
|
tns_unload(&tns, n);
|
||||||
|
|
||||||
|
@ -287,7 +288,7 @@ static void read_title(void)
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
if ((n = read(wintitle.fd, buf, sizeof(buf)-1)) > 0) {
|
if ((n = read(wintitle.fd, buf, sizeof(buf) - 1)) > 0) {
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
win_set_title(&win, buf, n);
|
win_set_title(&win, buf, n);
|
||||||
}
|
}
|
||||||
|
@ -308,7 +309,7 @@ static void open_title(void)
|
||||||
snprintf(h, ARRLEN(h), "%d", img.h);
|
snprintf(h, ARRLEN(h), "%d", img.h);
|
||||||
snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
|
snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
|
||||||
}
|
}
|
||||||
snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1);
|
snprintf(fidx, ARRLEN(fidx), "%d", fileidx + 1);
|
||||||
snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
|
snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
|
||||||
construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
|
construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
|
||||||
fidx, fcnt, w, h, z, NULL);
|
fidx, fcnt, w, h, z, NULL);
|
||||||
|
@ -426,7 +427,8 @@ static void update_info(void)
|
||||||
/* update bar contents */
|
/* update bar contents */
|
||||||
if (win.bar.h == 0 || extprefix)
|
if (win.bar.h == 0 || extprefix)
|
||||||
return;
|
return;
|
||||||
for (fw = 0, i = filecnt; i > 0; fw++, i /= 10);
|
for (fw = 0, i = filecnt; i > 0; fw++, i /= 10)
|
||||||
|
;
|
||||||
mark = files[fileidx].flags & FF_MARK ? "* " : "";
|
mark = files[fileidx].flags & FF_MARK ? "* " : "";
|
||||||
l->p = l->buf;
|
l->p = l->buf;
|
||||||
r->p = r->buf;
|
r->p = r->buf;
|
||||||
|
@ -452,9 +454,10 @@ static void update_info(void)
|
||||||
bar_put(r, "B%+d" BAR_SEP, img.brightness);
|
bar_put(r, "B%+d" BAR_SEP, img.brightness);
|
||||||
if (img.contrast)
|
if (img.contrast)
|
||||||
bar_put(r, "C%+d" BAR_SEP, img.contrast);
|
bar_put(r, "C%+d" BAR_SEP, img.contrast);
|
||||||
bar_put(r, "%3d%%" BAR_SEP, (int) (img.zoom * 100.0));
|
bar_put(r, "%3d%%" BAR_SEP, (int)(img.zoom * 100.0));
|
||||||
if (img.multi.cnt > 0) {
|
if (img.multi.cnt > 0) {
|
||||||
for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10);
|
for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10)
|
||||||
|
;
|
||||||
bar_put(r, "%0*d/%d" BAR_SEP, fn, img.multi.sel + 1, img.multi.cnt);
|
bar_put(r, "%0*d/%d" BAR_SEP, fn, img.multi.sel + 1, img.multi.cnt);
|
||||||
}
|
}
|
||||||
bar_put(r, "%0*d/%d", fw, fileidx + 1, filecnt);
|
bar_put(r, "%0*d/%d", fw, fileidx + 1, filecnt);
|
||||||
|
@ -623,7 +626,8 @@ static bool run_key_handler(const char *key, unsigned int mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(pfs);
|
fclose(pfs);
|
||||||
while (waitpid(pid, NULL, 0) == -1 && errno == EINTR);
|
while (waitpid(pid, NULL, 0) == -1 && errno == EINTR)
|
||||||
|
;
|
||||||
|
|
||||||
for (f = i = 0; f < fcnt; i++) {
|
for (f = i = 0; f < fcnt; i++) {
|
||||||
if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) {
|
if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) {
|
||||||
|
@ -640,7 +644,8 @@ static bool run_key_handler(const char *key, unsigned int mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* drop user input events that occurred while running the key handler */
|
/* drop user input events that occurred while running the key handler */
|
||||||
while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL));
|
while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL))
|
||||||
|
;
|
||||||
|
|
||||||
if (mode == MODE_IMAGE && changed) {
|
if (mode == MODE_IMAGE && changed) {
|
||||||
img_close(&img, true);
|
img_close(&img, true);
|
||||||
|
@ -699,7 +704,7 @@ static void on_keypress(XKeyEvent *kev)
|
||||||
handle_key_handler(false);
|
handle_key_handler(false);
|
||||||
} else if (key >= '0' && key <= '9') {
|
} else if (key >= '0' && key <= '9') {
|
||||||
/* number prefix for commands */
|
/* number prefix for commands */
|
||||||
prefix = prefix * 10 + (int) (key - '0');
|
prefix = prefix * 10 + (int)(key - '0');
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
dirty = process_bindings(keys, ARRLEN(keys), ksym, kev->state, sh);
|
dirty = process_bindings(keys, ARRLEN(keys), ksym, kev->state, sh);
|
||||||
|
@ -730,7 +735,7 @@ static void run(void)
|
||||||
enum { FD_X, FD_INFO, FD_TITLE, FD_ARL, FD_CNT };
|
enum { FD_X, FD_INFO, FD_TITLE, FD_ARL, FD_CNT };
|
||||||
struct pollfd pfd[FD_CNT];
|
struct pollfd pfd[FD_CNT];
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
const struct timespec ten_ms = {0, 10000000};
|
const struct timespec ten_ms = { 0, 10000000 };
|
||||||
bool discard, init_thumb, load_thumb, to_set;
|
bool discard, init_thumb, load_thumb, to_set;
|
||||||
XEvent ev, nextev;
|
XEvent ev, nextev;
|
||||||
|
|
||||||
|
@ -795,7 +800,7 @@ static void run(void)
|
||||||
break;
|
break;
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
discard = (nextev.type == KeyPress || nextev.type == KeyRelease) &&
|
discard = (nextev.type == KeyPress || nextev.type == KeyRelease) &&
|
||||||
ev.xkey.keycode == nextev.xkey.keycode;
|
ev.xkey.keycode == nextev.xkey.keycode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -806,7 +811,7 @@ static void run(void)
|
||||||
on_buttonpress(&ev.xbutton);
|
on_buttonpress(&ev.xbutton);
|
||||||
break;
|
break;
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
|
if ((Atom)ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
|
||||||
cg_quit(EXIT_SUCCESS);
|
cg_quit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
case DestroyNotify:
|
case DestroyNotify:
|
||||||
|
@ -859,7 +864,7 @@ int main(int argc, char *argv[])
|
||||||
size_t n;
|
size_t n;
|
||||||
const char *homedir, *dsuffix = "";
|
const char *homedir, *dsuffix = "";
|
||||||
|
|
||||||
setup_signal(SIGCHLD, SIG_DFL, SA_RESTART|SA_NOCLDSTOP|SA_NOCLDWAIT);
|
setup_signal(SIGCHLD, SIG_DFL, SA_RESTART | SA_NOCLDSTOP | SA_NOCLDWAIT);
|
||||||
setup_signal(SIGPIPE, SIG_IGN, 0);
|
setup_signal(SIGPIPE, SIG_IGN, 0);
|
||||||
|
|
||||||
setlocale(LC_COLLATE, "");
|
setlocale(LC_COLLATE, "");
|
||||||
|
|
|
@ -43,7 +43,8 @@ void print_usage(void)
|
||||||
{
|
{
|
||||||
printf("usage: %s [-abcfhiopqrtvZ0] [-A FRAMERATE] [-e WID] [-G GAMMA] "
|
printf("usage: %s [-abcfhiopqrtvZ0] [-A FRAMERATE] [-e WID] [-G GAMMA] "
|
||||||
"[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] "
|
"[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] "
|
||||||
"[-z ZOOM] FILES...\n", progname);
|
"[-z ZOOM] FILES...\n",
|
||||||
|
progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_version(void)
|
static void print_version(void)
|
||||||
|
@ -227,7 +228,7 @@ void parse_options(int argc, char **argv)
|
||||||
if (*end != '\0' || n <= 0)
|
if (*end != '\0' || n <= 0)
|
||||||
error(EXIT_FAILURE, 0, "Invalid zoom level: %s", op.optarg);
|
error(EXIT_FAILURE, 0, "Invalid zoom level: %s", op.optarg);
|
||||||
_options.scalemode = SCALE_ZOOM;
|
_options.scalemode = SCALE_ZOOM;
|
||||||
_options.zoom = (float) n / 100.0f;
|
_options.zoom = (float)n / 100.0f;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
_options.using_null = true;
|
_options.using_null = true;
|
||||||
|
|
26
thumbs.c
26
thumbs.c
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
static char *cache_dir;
|
static char *cache_dir;
|
||||||
|
|
||||||
static char* tns_cache_filepath(const char *filepath)
|
static char *tns_cache_filepath(const char *filepath)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *cfile = NULL;
|
char *cfile = NULL;
|
||||||
|
@ -201,8 +201,8 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim)
|
||||||
imlib_context_set_image(im);
|
imlib_context_set_image(im);
|
||||||
w = imlib_image_get_width();
|
w = imlib_image_get_width();
|
||||||
h = imlib_image_get_height();
|
h = imlib_image_get_height();
|
||||||
zw = (float) dim / (float) w;
|
zw = (float)dim / (float)w;
|
||||||
zh = (float) dim / (float) h;
|
zh = (float)dim / (float)h;
|
||||||
z = MIN(zw, zh);
|
z = MIN(zw, zh);
|
||||||
z = MIN(z, 1.0);
|
z = MIN(z, 1.0);
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim)
|
||||||
|
|
||||||
bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
|
bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
|
||||||
{
|
{
|
||||||
int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
|
int maxwh = thumb_sizes[ARRLEN(thumb_sizes) - 1];
|
||||||
bool cache_hit = false;
|
bool cache_hit = false;
|
||||||
char *cfile;
|
char *cfile;
|
||||||
thumb_t *t;
|
thumb_t *t;
|
||||||
|
@ -290,8 +290,8 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
|
||||||
h = imlib_image_get_height();
|
h = imlib_image_get_height();
|
||||||
|
|
||||||
if (pw > w && ph > h && (pw - ph >= 0) == (w - h >= 0)) {
|
if (pw > w && ph > h && (pw - ph >= 0) == (w - h >= 0)) {
|
||||||
zw = (float) pw / (float) w;
|
zw = (float)pw / (float)w;
|
||||||
zh = (float) ph / (float) h;
|
zh = (float)ph / (float)h;
|
||||||
if (zw < zh) {
|
if (zw < zh) {
|
||||||
pw /= zh;
|
pw /= zh;
|
||||||
x = (w - pw) / 2;
|
x = (w - pw) / 2;
|
||||||
|
@ -343,10 +343,14 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
|
||||||
}
|
}
|
||||||
file->flags |= FF_TN_INIT;
|
file->flags |= FF_TN_INIT;
|
||||||
|
|
||||||
if (n == tns->initnext)
|
if (n == tns->initnext) {
|
||||||
while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT));
|
while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT))
|
||||||
if (n == tns->loadnext && !cache_only)
|
;
|
||||||
while (++tns->loadnext < tns->end && (++t)->im != NULL);
|
}
|
||||||
|
if (n == tns->loadnext && !cache_only) {
|
||||||
|
while (++tns->loadnext < tns->end && (++t)->im != NULL)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -557,7 +561,7 @@ bool tns_zoom(tns_t *tns, int d)
|
||||||
oldzl = tns->zl;
|
oldzl = tns->zl;
|
||||||
tns->zl += -(d < 0) + (d > 0);
|
tns->zl += -(d < 0) + (d > 0);
|
||||||
tns->zl = MAX(tns->zl, 0);
|
tns->zl = MAX(tns->zl, 0);
|
||||||
tns->zl = MIN(tns->zl, (int)ARRLEN(thumb_sizes)-1);
|
tns->zl = MIN(tns->zl, (int)ARRLEN(thumb_sizes) - 1);
|
||||||
|
|
||||||
tns->bw = ((thumb_sizes[tns->zl] - 1) >> 5) + 1;
|
tns->bw = ((thumb_sizes[tns->zl] - 1) >> 5) + 1;
|
||||||
tns->bw = MIN(tns->bw, 4);
|
tns->bw = MIN(tns->bw, 4);
|
||||||
|
|
21
util.c
21
util.c
|
@ -32,7 +32,7 @@
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
const char *progname = "nsxiv";
|
const char *progname = "nsxiv";
|
||||||
|
|
||||||
void* emalloc(size_t size)
|
void *emalloc(size_t size)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ void* emalloc(size_t size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* ecalloc(size_t nmemb, size_t size)
|
void *ecalloc(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void* ecalloc(size_t nmemb, size_t size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* erealloc(void *ptr, size_t size)
|
void *erealloc(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
ptr = realloc(ptr, size);
|
ptr = realloc(ptr, size);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
|
@ -60,13 +60,13 @@ void* erealloc(void *ptr, size_t size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* estrdup(const char *s)
|
char *estrdup(const char *s)
|
||||||
{
|
{
|
||||||
size_t n = strlen(s) + 1;
|
size_t n = strlen(s) + 1;
|
||||||
return memcpy(emalloc(n), s, n);
|
return memcpy(emalloc(n), s, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(int eval, int err, const char* fmt, ...)
|
void error(int eval, int err, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive)
|
||||||
rdir->stack = emalloc(rdir->stcap * sizeof(*rdir->stack));
|
rdir->stack = emalloc(rdir->stcap * sizeof(*rdir->stack));
|
||||||
rdir->stlen = 0;
|
rdir->stlen = 0;
|
||||||
|
|
||||||
rdir->name = (char*) dirname;
|
rdir->name = (char *)dirname;
|
||||||
rdir->d = 0;
|
rdir->d = 0;
|
||||||
rdir->recursive = recursive;
|
rdir->recursive = recursive;
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ int r_closedir(r_dir_t *rdir)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
|
char *r_readdir(r_dir_t *rdir, bool skip_dotfiles)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
@ -154,7 +154,7 @@ char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
|
||||||
len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
|
len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
|
||||||
filename = emalloc(len);
|
filename = emalloc(len);
|
||||||
snprintf(filename, len, "%s%s%s", rdir->name,
|
snprintf(filename, len, "%s%s%s", rdir->name,
|
||||||
rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/",
|
rdir->name[strlen(rdir->name) - 1] == '/' ? "" : "/",
|
||||||
dentry->d_name);
|
dentry->d_name);
|
||||||
|
|
||||||
if (stat(filename, &fstats) < 0) {
|
if (stat(filename, &fstats) < 0) {
|
||||||
|
@ -203,7 +203,8 @@ int r_mkdir(char *path)
|
||||||
s++;
|
s++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (; *s != '\0' && *s != '/'; s++);
|
for (; *s != '\0' && *s != '/'; s++)
|
||||||
|
;
|
||||||
c = *s;
|
c = *s;
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
if (mkdir(path, 0755) == -1) {
|
if (mkdir(path, 0755) == -1) {
|
||||||
|
@ -226,7 +227,7 @@ void construct_argv(char **argv, unsigned int len, ...)
|
||||||
for (i = 0; i < len; ++i)
|
for (i = 0; i < len; ++i)
|
||||||
argv[i] = va_arg(args, char *);
|
argv[i] = va_arg(args, char *);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
assert(argv[len-1] == NULL && "argv should be NULL terminated");
|
assert(argv[len - 1] == NULL && "argv should be NULL terminated");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx)
|
static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx)
|
||||||
|
|
28
window.c
28
window.c
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
#if HAVE_LIBFONTS
|
#if HAVE_LIBFONTS
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */
|
#define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */
|
||||||
#define TEXTWIDTH(win, text, len) \
|
#define TEXTWIDTH(win, text, len) \
|
||||||
win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
|
win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,8 +56,12 @@ static struct {
|
||||||
int name;
|
int name;
|
||||||
Cursor icon;
|
Cursor icon;
|
||||||
} cursors[CURSOR_COUNT] = {
|
} cursors[CURSOR_COUNT] = {
|
||||||
{ XC_left_ptr }, { XC_dotbox }, { XC_fleur }, { XC_watch },
|
{ XC_left_ptr },
|
||||||
{ XC_sb_left_arrow }, { XC_sb_right_arrow }
|
{ XC_dotbox },
|
||||||
|
{ XC_fleur },
|
||||||
|
{ XC_watch },
|
||||||
|
{ XC_sb_left_arrow },
|
||||||
|
{ XC_sb_right_arrow }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if HAVE_LIBFONTS
|
#if HAVE_LIBFONTS
|
||||||
|
@ -90,7 +94,7 @@ static void win_alloc_color(const win_env_t *e, const char *name, XColor *col)
|
||||||
error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
|
error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* win_res(XrmDatabase db, const char *name, const char *def)
|
static const char *win_res(XrmDatabase db, const char *name, const char *def)
|
||||||
{
|
{
|
||||||
char *type;
|
char *type;
|
||||||
XrmValue ret;
|
XrmValue ret;
|
||||||
|
@ -246,7 +250,7 @@ void win_open(win_t *win)
|
||||||
/* set the _NET_WM_PID */
|
/* set the _NET_WM_PID */
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_PID], XA_CARDINAL,
|
XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_PID], XA_CARDINAL,
|
||||||
32, PropModeReplace, (unsigned char *) &pid, 1);
|
32, PropModeReplace, (unsigned char *)&pid, 1);
|
||||||
if (gethostname(hostname, ARRLEN(hostname)) == 0) {
|
if (gethostname(hostname, ARRLEN(hostname)) == 0) {
|
||||||
XTextProperty tp;
|
XTextProperty tp;
|
||||||
tp.value = (unsigned char *)hostname;
|
tp.value = (unsigned char *)hostname;
|
||||||
|
@ -272,7 +276,7 @@ void win_open(win_t *win)
|
||||||
|
|
||||||
gc = XCreateGC(e->dpy, win->xwin, 0, None);
|
gc = XCreateGC(e->dpy, win->xwin, 0, None);
|
||||||
|
|
||||||
n = icons[ARRLEN(icons)-1].size;
|
n = icons[ARRLEN(icons) - 1].size;
|
||||||
icon_data = emalloc((n * n + 2) * sizeof(*icon_data));
|
icon_data = emalloc((n * n + 2) * sizeof(*icon_data));
|
||||||
|
|
||||||
for (i = 0; i < (int)ARRLEN(icons); i++) {
|
for (i = 0; i < (int)ARRLEN(icons); i++) {
|
||||||
|
@ -286,7 +290,7 @@ void win_open(win_t *win)
|
||||||
}
|
}
|
||||||
XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
|
XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
|
||||||
i == 0 ? PropModeReplace : PropModeAppend,
|
i == 0 ? PropModeReplace : PropModeAppend,
|
||||||
(unsigned char *) icon_data, n);
|
(unsigned char *)icon_data, n);
|
||||||
}
|
}
|
||||||
free(icon_data);
|
free(icon_data);
|
||||||
|
|
||||||
|
@ -311,7 +315,7 @@ void win_open(win_t *win)
|
||||||
if (options->fullscreen) {
|
if (options->fullscreen) {
|
||||||
XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_STATE],
|
XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_STATE],
|
||||||
XA_ATOM, 32, PropModeReplace,
|
XA_ATOM, 32, PropModeReplace,
|
||||||
(unsigned char *) &atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1);
|
(unsigned char *)&atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
win->h -= win->bar.h;
|
win->h -= win->bar.h;
|
||||||
|
@ -432,10 +436,10 @@ static int win_draw_text(win_t *win, XftDraw *d, const XftColor *color,
|
||||||
FC_SIZE, FcTypeDouble, fontsize, NULL);
|
FC_SIZE, FcTypeDouble, fontsize, NULL);
|
||||||
FcCharSetDestroy(fccharset);
|
FcCharSetDestroy(fccharset);
|
||||||
}
|
}
|
||||||
XftTextExtentsUtf8(win->env.dpy, f, (XftChar8*)t, next - t, &ext);
|
XftTextExtentsUtf8(win->env.dpy, f, (XftChar8 *)t, next - t, &ext);
|
||||||
tw += ext.xOff;
|
tw += ext.xOff;
|
||||||
if (tw <= w) {
|
if (tw <= w) {
|
||||||
XftDrawStringUtf8(d, color, f, x, y, (XftChar8*)t, next - t);
|
XftDrawStringUtf8(d, color, f, x, y, (XftChar8 *)t, next - t);
|
||||||
x += ext.xOff;
|
x += ext.xOff;
|
||||||
}
|
}
|
||||||
if (f != font)
|
if (f != font)
|
||||||
|
@ -456,7 +460,7 @@ static void win_draw_bar(win_t *win)
|
||||||
r = &win->bar.r;
|
r = &win->bar.r;
|
||||||
assert(l->buf != NULL && r->buf != NULL);
|
assert(l->buf != NULL && r->buf != NULL);
|
||||||
y = (win->bar.top ? 0 : win->h) + font->ascent + V_TEXT_PAD;
|
y = (win->bar.top ? 0 : win->h) + font->ascent + V_TEXT_PAD;
|
||||||
w = win->w - 2*H_TEXT_PAD;
|
w = win->w - 2 * H_TEXT_PAD;
|
||||||
d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap);
|
d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap);
|
||||||
|
|
||||||
XSetForeground(e->dpy, gc, win->bar_bg.pixel);
|
XSetForeground(e->dpy, gc, win->bar_bg.pixel);
|
||||||
|
@ -482,7 +486,7 @@ static void win_draw_bar(win_t *win)
|
||||||
#else
|
#else
|
||||||
static void win_draw_bar(win_t *win)
|
static void win_draw_bar(win_t *win)
|
||||||
{
|
{
|
||||||
(void) win;
|
(void)win;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_LIBFONTS */
|
#endif /* HAVE_LIBFONTS */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue