Make statusbar optional (#95)
libXft and libfontconfig are now optional dependencies which can be disabled via `HAVE_LIBFONTS=0`. Disabling them means disabling the statusbar. This also does not search for freetype2 header if disabled. Co-authored-by: NRK <nrk@disroot.org>
This commit is contained in:
parent
6ce94e3e3b
commit
675db4bbb6
14
Makefile
14
Makefile
|
@ -13,6 +13,7 @@ OPT_DEP_DEFAULT ?= 1
|
|||
HAVE_INOTIFY ?= $(OPT_DEP_DEFAULT)
|
||||
|
||||
# optional dependencies, see README for more info
|
||||
HAVE_LIBFONTS ?= $(OPT_DEP_DEFAULT)
|
||||
HAVE_LIBGIF ?= $(OPT_DEP_DEFAULT)
|
||||
HAVE_LIBEXIF ?= $(OPT_DEP_DEFAULT)
|
||||
HAVE_LIBWEBP ?= $(OPT_DEP_DEFAULT)
|
||||
|
@ -23,11 +24,16 @@ CFLAGS ?= -std=c99 -Wall -pedantic
|
|||
# icons that will be installed via `make icon`
|
||||
ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png
|
||||
|
||||
inc_fonts_0 =
|
||||
inc_fonts_1 = -I/usr/include/freetype2 -I$(PREFIX)/include/freetype2
|
||||
|
||||
CPPFLAGS = -D_XOPEN_SOURCE=700 \
|
||||
-DHAVE_LIBGIF=$(HAVE_LIBGIF) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF) \
|
||||
-DHAVE_LIBWEBP=$(HAVE_LIBWEBP) \
|
||||
-I/usr/include/freetype2 -I$(PREFIX)/include/freetype2
|
||||
-DHAVE_LIBWEBP=$(HAVE_LIBWEBP) -DHAVE_LIBFONTS=$(HAVE_LIBFONTS) \
|
||||
$(inc_fonts_$(HAVE_LIBFONTS))
|
||||
|
||||
lib_fonts_0 =
|
||||
lib_fonts_1 = -lXft -lfontconfig
|
||||
lib_exif_0 =
|
||||
lib_exif_1 = -lexif
|
||||
lib_gif_0 =
|
||||
|
@ -37,9 +43,9 @@ lib_webp_1 = -lwebpdemux -lwebp
|
|||
autoreload_0 = nop
|
||||
autoreload_1 = inotify
|
||||
# using += because certain *BSD distros may need to add additional flags
|
||||
LDLIBS += -lImlib2 -lX11 -lXft -lfontconfig \
|
||||
LDLIBS += -lImlib2 -lX11 \
|
||||
$(lib_exif_$(HAVE_LIBEXIF)) $(lib_gif_$(HAVE_LIBGIF)) \
|
||||
$(lib_webp_$(HAVE_LIBWEBP))
|
||||
$(lib_webp_$(HAVE_LIBWEBP)) $(lib_fonts_$(HAVE_LIBFONTS))
|
||||
|
||||
OBJS = autoreload_$(autoreload_$(HAVE_INOTIFY)).o commands.o image.o main.o options.o \
|
||||
thumbs.o util.o window.o
|
||||
|
|
|
@ -45,14 +45,13 @@ nsxiv requires the following software to be installed:
|
|||
|
||||
* Imlib2
|
||||
* X11
|
||||
* Xft
|
||||
* freetype2
|
||||
* fontconfig
|
||||
|
||||
The following dependencies are optional.
|
||||
|
||||
* inotify : Used for auto-reloading images on change.
|
||||
Disabled via `HAVE_INOTIFY=0`
|
||||
* libXft, freetype2, fontconfig : Used for the status bar.
|
||||
Disabled via `HAVE_LIBFONTS=0`
|
||||
* giflib : Used for animated gif playback.
|
||||
Disabled via `HAVE_LIBGIF=0`.
|
||||
* libexif : Used for auto-orientation and exif thumbnails.
|
||||
|
|
2
image.c
2
image.c
|
@ -643,7 +643,7 @@ void img_render(img_t *img)
|
|||
}
|
||||
imlib_image_put_back_data(data);
|
||||
} else {
|
||||
c = win->win_bg.pixel;
|
||||
c = win->win_bg;
|
||||
imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
|
||||
imlib_image_fill_rectangle(0, 0, dw, dh);
|
||||
}
|
||||
|
|
10
nsxiv.h
10
nsxiv.h
|
@ -383,7 +383,9 @@ int r_mkdir(char*);
|
|||
/* window.c */
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#if HAVE_LIBFONTS
|
||||
#include <X11/Xft/Xft.h>
|
||||
#endif
|
||||
|
||||
enum {
|
||||
BAR_L_LEN = 512,
|
||||
|
@ -420,11 +422,13 @@ struct win {
|
|||
Window xwin;
|
||||
win_env_t env;
|
||||
|
||||
XftColor win_bg;
|
||||
XftColor win_fg;
|
||||
unsigned long win_bg;
|
||||
unsigned long win_fg;
|
||||
unsigned long mrk_fg;
|
||||
#if HAVE_LIBFONTS
|
||||
XftColor bar_bg;
|
||||
XftColor bar_fg;
|
||||
XftColor mrk_fg;
|
||||
#endif
|
||||
|
||||
int x;
|
||||
int y;
|
||||
|
|
6
thumbs.c
6
thumbs.c
|
@ -471,14 +471,14 @@ void tns_mark(tns_t *tns, int n, bool mark)
|
|||
if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
|
||||
win_t *win = tns->win;
|
||||
thumb_t *t = &tns->thumbs[n];
|
||||
unsigned long col = win->win_bg.pixel;
|
||||
unsigned long col = win->win_bg;
|
||||
int x = t->x + t->w, y = t->y + t->h;
|
||||
|
||||
win_draw_rect(win, x - 1, y + 1, 1, tns->bw, true, 1, col);
|
||||
win_draw_rect(win, x + 1, y - 1, tns->bw, 1, true, 1, col);
|
||||
|
||||
if (mark)
|
||||
col = win->mrk_fg.pixel;
|
||||
col = win->mrk_fg;
|
||||
|
||||
win_draw_rect(win, x, y, tns->bw + 2, tns->bw + 2, true, 1, col);
|
||||
|
||||
|
@ -492,7 +492,7 @@ void tns_highlight(tns_t *tns, int n, bool hl)
|
|||
if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
|
||||
win_t *win = tns->win;
|
||||
thumb_t *t = &tns->thumbs[n];
|
||||
unsigned long col = hl ? win->win_fg.pixel : win->win_bg.pixel;
|
||||
unsigned long col = hl ? win->win_fg : win->win_bg;
|
||||
int oxy = (tns->bw + 1) / 2 + 1, owh = tns->bw + 2;
|
||||
|
||||
win_draw_rect(win, t->x - oxy, t->y - oxy, t->w + owh, t->h + owh,
|
||||
|
|
60
window.c
60
window.c
|
@ -20,7 +20,6 @@
|
|||
#define _WINDOW_CONFIG
|
||||
#include "config.h"
|
||||
#include "icon/data.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -30,6 +29,12 @@
|
|||
#include <X11/Xatom.h>
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
#if HAVE_LIBFONTS
|
||||
#include "utf8.h"
|
||||
static XftFont *font;
|
||||
static double fontsize;
|
||||
#endif
|
||||
|
||||
#define RES_CLASS "Nsxiv"
|
||||
|
||||
enum {
|
||||
|
@ -47,15 +52,14 @@ static struct {
|
|||
|
||||
static GC gc;
|
||||
|
||||
static XftFont *font;
|
||||
static int fontheight;
|
||||
static double fontsize;
|
||||
static int barheight;
|
||||
|
||||
Atom atoms[ATOM_COUNT];
|
||||
|
||||
#if HAVE_LIBFONTS
|
||||
void win_init_font(const win_env_t *e, const char *fontstr)
|
||||
{
|
||||
int fontheight = 0;
|
||||
if ((font = XftFontOpenName(e->dpy, e->scr, fontstr)) == NULL)
|
||||
error(EXIT_FAILURE, 0, "Error loading font '%s'", fontstr);
|
||||
fontheight = font->ascent + font->descent;
|
||||
|
@ -64,13 +68,19 @@ void win_init_font(const win_env_t *e, const char *fontstr)
|
|||
XftFontClose(e->dpy, font);
|
||||
}
|
||||
|
||||
void win_alloc_color(const win_env_t *e, const char *name, XftColor *col)
|
||||
void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col)
|
||||
{
|
||||
if (!XftColorAllocName(e->dpy, e->vis,
|
||||
e->cmap, name, col))
|
||||
{
|
||||
if (!XftColorAllocName(e->dpy, e->vis, e->cmap, name, col))
|
||||
error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_LIBFONTS */
|
||||
|
||||
void win_alloc_color(const win_env_t *e, const char *name, unsigned long *pixel)
|
||||
{
|
||||
XColor screen, exact;
|
||||
if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, &exact))
|
||||
error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
|
||||
*pixel = exact.pixel;
|
||||
}
|
||||
|
||||
const char* win_res(XrmDatabase db, const char *name, const char *def)
|
||||
|
@ -94,7 +104,10 @@ const char* win_res(XrmDatabase db, const char *name, const char *def)
|
|||
void win_init(win_t *win)
|
||||
{
|
||||
win_env_t *e;
|
||||
const char *win_bg, *win_fg, *bar_bg, *bar_fg, *mrk_fg, *f;
|
||||
const char *win_bg, *win_fg, *mrk_fg;
|
||||
#if HAVE_LIBFONTS
|
||||
const char *bar_fg, *bar_bg, *f;
|
||||
#endif
|
||||
char *res_man;
|
||||
XrmDatabase db;
|
||||
XVisualInfo vis;
|
||||
|
@ -131,20 +144,22 @@ void win_init(win_t *win)
|
|||
res_man = XResourceManagerString(e->dpy);
|
||||
db = res_man != NULL ? XrmGetStringDatabase(res_man) : None;
|
||||
|
||||
f = win_res(db, RES_CLASS ".bar.font", "monospace-8");
|
||||
win_init_font(e, f);
|
||||
|
||||
win_bg = win_res(db, RES_CLASS ".window.background", "white");
|
||||
win_fg = win_res(db, RES_CLASS ".window.foreground", "black");
|
||||
bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg);
|
||||
bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg);
|
||||
mrk_fg = win_res(db, RES_CLASS ".mark.foreground", win_fg);
|
||||
win_alloc_color(e, win_bg, &win->win_bg);
|
||||
win_alloc_color(e, win_fg, &win->win_fg);
|
||||
win_alloc_color(e, bar_bg, &win->bar_bg);
|
||||
win_alloc_color(e, bar_fg, &win->bar_fg);
|
||||
win_alloc_color(e, mrk_fg, &win->mrk_fg);
|
||||
|
||||
#if HAVE_LIBFONTS
|
||||
bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg);
|
||||
bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg);
|
||||
xft_alloc_color(e, bar_bg, &win->bar_bg);
|
||||
xft_alloc_color(e, bar_fg, &win->bar_fg);
|
||||
|
||||
f = win_res(db, RES_CLASS ".bar.font", "monospace-8");
|
||||
win_init_font(e, f);
|
||||
|
||||
win->bar.l.size = BAR_L_LEN;
|
||||
win->bar.r.size = BAR_R_LEN;
|
||||
/* 3 padding bytes needed by utf8_decode */
|
||||
|
@ -153,6 +168,7 @@ void win_init(win_t *win)
|
|||
win->bar.r.buf = emalloc(win->bar.r.size + 3);
|
||||
win->bar.r.buf[0] = '\0';
|
||||
win->bar.h = options->hide_bar ? 0 : barheight;
|
||||
#endif /* HAVE_LIBFONTS */
|
||||
|
||||
INIT_ATOM_(WM_DELETE_WINDOW);
|
||||
INIT_ATOM_(_NET_WM_NAME);
|
||||
|
@ -306,7 +322,7 @@ void win_open(win_t *win)
|
|||
win->buf.h = e->scrh;
|
||||
win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
|
||||
win->buf.w, win->buf.h, e->depth);
|
||||
XSetForeground(e->dpy, gc, win->win_bg.pixel);
|
||||
XSetForeground(e->dpy, gc, win->win_bg);
|
||||
XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
|
||||
XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm);
|
||||
|
||||
|
@ -388,10 +404,11 @@ void win_clear(win_t *win)
|
|||
win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
|
||||
win->buf.w, win->buf.h, e->depth);
|
||||
}
|
||||
XSetForeground(e->dpy, gc, win->win_bg.pixel);
|
||||
XSetForeground(e->dpy, gc, win->win_bg);
|
||||
XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
|
||||
}
|
||||
|
||||
#if HAVE_LIBFONTS
|
||||
#define TEXTWIDTH(win, text, len) \
|
||||
win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
|
||||
|
||||
|
@ -448,7 +465,7 @@ void win_draw_bar(win_t *win)
|
|||
XSetForeground(e->dpy, gc, win->bar_bg.pixel);
|
||||
XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);
|
||||
|
||||
XSetForeground(e->dpy, gc, win->win_bg.pixel);
|
||||
XSetForeground(e->dpy, gc, win->win_bg);
|
||||
XSetBackground(e->dpy, gc, win->bar_bg.pixel);
|
||||
|
||||
if ((len = strlen(r->buf)) > 0) {
|
||||
|
@ -465,6 +482,9 @@ void win_draw_bar(win_t *win)
|
|||
}
|
||||
XftDrawDestroy(d);
|
||||
}
|
||||
#else
|
||||
void win_draw_bar(win_t *win){}
|
||||
#endif /* HAVE_LIBFONTS */
|
||||
|
||||
void win_draw(win_t *win)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue