Browse Source

[PATCH] custom colors from config.h

base
ziggys 7 months ago
parent
commit
9d71887637
Signed by: ziggys <ziggys@autistici.org> GPG Key ID: 72CAC7BD2B3F4B8C
9 changed files with 96 additions and 19 deletions
  1. +1
    -1
      Makefile
  2. +30
    -0
      README.md
  3. +14
    -1
      commands.c
  4. +19
    -7
      config.def.h
  5. +14
    -2
      image.c
  6. +6
    -2
      main.c
  7. +1
    -1
      sxiv.1
  8. +2
    -0
      sxiv.h
  9. +9
    -5
      window.c

+ 1
- 1
Makefile View File

@@ -23,7 +23,7 @@ cppflags = -I. $(CPPFLAGS) -D_XOPEN_SOURCE=700 \
lib_exif_0 =
lib_exif_1 = -lexif
lib_gif_0 =
lib_gif_1 = -lgif
lib_gif_1 = /usr/lib/libgif.so
ldlibs = $(LDLIBS) -lImlib2 -lX11 -lXft -lfontconfig \
$(lib_exif_$(HAVE_LIBEXIF)) $(lib_gif_$(HAVE_GIFLIB))



+ 30
- 0
README.md View File

@@ -2,6 +2,36 @@

**Simple X Image Viewer**

Flurrywinde's Modded SXIV
-------------------------

Sxiv is my favorite image viewer (Thank you, muennich!), but I needed a few mods to suit my use-cases:

* The bar color is customizable again (but other colors are still set in .Xresources)
* Makefile edit to use latest giflib (because some gifs don't work with some versions of giflib)
* Send all unbound keys to the key-handler, not just after ctrl-x
* Removing an image from the image list can optionally generate an external key-handler event
* Small images default to 1.5x zoom for better viewing
* Add a few more zoom levels for bigger and finer zooming
* Made the mouse act like it used to (mostly because I like right-click to go to the previous image again)
* Make ctrl-m unmark_all again (because I want to use ctrl-u for something else)

**Notes:**

1. The key-handler is responsible for recognizing a symlink and calling realpath if necessary.

2. Foreground color, background color, and font are now set in .Xresources (at least on my system, Ubuntu 18.04). I added:
```
Sxiv.foreground: lightgray
Sxiv.background: #000000
```
to the end because I prefer a black background.

To update, run: `xrdb -load .Xresources` after making your changes.

Original Readme
---------------

The sole purpose of sxiv is to be the perfect image viewer for me. It is free
software so that you can use it and modify it for your needs. Please file a bug
report if something does not work as documented or expected. Contributions are


+ 14
- 1
commands.c View File

@@ -38,6 +38,10 @@ void slideshow(void);
void set_timeout(timeout_f, int, bool);
void reset_timeout(timeout_f);

// Kanon added
bool ci_fit_to_win(arg_t sm);
void run_key_handler(const char *key, unsigned int mask);

extern appmode_t mode;
extern img_t img;
extern tns_t tns;
@@ -132,8 +136,15 @@ bool cg_reload_image(arg_t _)
return true;
}

bool cg_remove_image(arg_t _)
// Seems original programmer uses _ to mean parm not used. I changed it to banish.
// In thumbnail mode, still removes current image, not marked ones
bool cg_remove_image(arg_t banish)
{
if (banish) {
// printf("banish\n");
run_key_handler("d", 4); // 4 means ctrl. Ugly hack. Better way: have keyhandler able to remove images from the list. Removes image from external database.
}

remove_file(fileidx, true);
if (mode == MODE_IMAGE)
load_image(fileidx);
@@ -282,6 +293,8 @@ bool ci_navigate(arg_t n)

if (n != fileidx) {
load_image(n);
// Kanon added
ci_fit_to_win(SCALE_DOWN);
return true;
} else {
return false;


+ 19
- 7
config.def.h View File

@@ -11,6 +11,10 @@ enum {
* See X(7) section Resources and xrdb(1) for more information.
*/

// Kanon needs his bar color
static const char * const BAR_BG_COLOR = "#110e0d";
static const char * const BAR_FG_COLOR = "#fe8019";

#endif
#ifdef _IMAGE_CONFIG

@@ -18,8 +22,9 @@ enum {
* (first/last value is used as min/max zoom level)
*/
static const float zoom_levels[] = {
12.5, 25.0, 50.0, 75.0,
100.0, 150.0, 200.0, 400.0, 800.0
11.1, 20.0, 30.0, 40.0, 50.0, 65.0, 80.0, 90.0,
100.0, 125.0, 150.0, 175.0, 200.0, 300.0, 400.0, 500.0,
600.0, 700.0, 800.0, 900.0, 1000.0, 1111.1
};

/* default slideshow delay (in sec, overwritten via -S option): */
@@ -67,7 +72,8 @@ static const keymap_t keys[] = {
{ 0, XK_g, g_first, None },
{ 0, XK_G, g_n_or_last, None },
{ 0, XK_r, g_reload_image, None },
{ 0, XK_D, g_remove_image, None },
{ 0, XK_d, g_remove_image, 0 }, // Kanon mod: gave it a parm
{ 0, XK_D, g_remove_image, 1 }, // See commands.c
{ ControlMask, XK_h, g_scroll_screen, DIR_LEFT },
{ ControlMask, XK_Left, g_scroll_screen, DIR_LEFT },
{ ControlMask, XK_j, g_scroll_screen, DIR_DOWN },
@@ -82,8 +88,8 @@ static const keymap_t keys[] = {
{ 0, XK_KP_Subtract, g_zoom, -1 },
{ 0, XK_m, g_toggle_image_mark, None },
{ 0, XK_M, g_mark_range, None },
{ ControlMask, XK_m, g_reverse_marks, None },
{ ControlMask, XK_u, g_unmark_all, None },
// { ControlMask, XK_u, g_reverse_marks, None },
{ ControlMask, XK_m, g_unmark_all, None },
{ 0, XK_N, g_navigate_marked, +1 },
{ 0, XK_P, g_navigate_marked, -1 },
{ 0, XK_braceleft, g_change_gamma, -1 },
@@ -142,9 +148,15 @@ static const keymap_t keys[] = {
/* mouse button mappings for image mode: */
static const button_t buttons[] = {
/* modifiers button function argument */
{ 0, 1, i_cursor_navigate, None },
{ 0, 1, i_navigate, +1 }, // Used to be i_cursor_navigate
{ 0, 3, i_navigate, -1 }, // Used to be g_switch_mode.
{ 0, 2, i_drag, DRAG_ABSOLUTE },
{ 0, 3, g_switch_mode, None },
{ ControlMask, 4, i_scroll, DIR_UP },
{ ControlMask, 5, i_scroll, DIR_DOWN },
{ ShiftMask, 4, i_scroll, DIR_LEFT },
{ ShiftMask, 5, i_scroll, DIR_RIGHT },
{ 0, 6, i_scroll, DIR_LEFT },
{ 0, 7, i_scroll, DIR_RIGHT },
{ 0, 4, g_zoom, +1 },
{ 0, 5, g_zoom, -1 },
};


+ 14
- 2
image.c View File

@@ -393,11 +393,22 @@ void img_check_pan(img_t *img, bool moved)

bool img_fit(img_t *img)
{
float z, zw, zh;
float z, zmax, zw, zh;

if (img->scalemode == SCALE_ZOOM)
return false;

zmax = img->scalemode == SCALE_DOWN ? 1.0 : zoom_max;

// Kanon added: If too small, make bigger
if (img->scalemode == SCALE_DOWN) {
if (img->w <= 600) {
zmax = 1.5;
} else if (img->h <=400) {
zmax = 1.5;
}
}

zw = (float) img->win->w / (float) img->w;
zh = (float) img->win->h / (float) img->h;

@@ -412,7 +423,8 @@ bool img_fit(img_t *img)
z = MIN(zw, zh);
break;
}
z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : zoom_max);

z = MIN(z, zmax);

if (zoomdiff(img, z) != 0) {
img->zoom = z;


+ 6
- 2
main.c View File

@@ -527,7 +527,7 @@ void run_key_handler(const char *key, unsigned int mask)
for (f = i = 0; f < fcnt; i++) {
if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) {
stat(files[i].path, &oldst[f]);
fprintf(pfs, "%s\n", files[i].name);
fprintf(pfs, "%s\n", files[i].name); // Change 'name' to 'path' to send realpath
f++;
}
}
@@ -573,10 +573,10 @@ void on_keypress(XKeyEvent *kev)
unsigned int sh = 0;
KeySym ksym, shksym;
char dummy, key;
bool bound = false;
bool dirty = false;

XLookupString(kev, &key, 1, &ksym, NULL);

if (kev->state & ShiftMask) {
kev->state &= ~ShiftMask;
XLookupString(kev, &dummy, 1, &shksym, NULL);
@@ -603,8 +603,12 @@ void on_keypress(XKeyEvent *kev)
{
if (cmds[keys[i].cmd].func(keys[i].arg))
dirty = true;
bound = true;
// printf("Bound: %d-%s\n", kev->state & ~sh, XKeysymToString(ksym));
}
}
if (!bound)
run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
if (dirty)
redraw();
prefix = 0;


+ 1
- 1
sxiv.1 View File

@@ -387,7 +387,7 @@ Color of the window foreground and bar background
.B font
Name of Xft bar font
.TP
Please see xrdb(1) on how to change them.
Please see xrdb(1) on how to change them. (.Xresources file)
.SH STATUS BAR
The information displayed on the left side of the status bar can be replaced
with the output of a user-provided script, which is called by sxiv whenever an


+ 2
- 0
sxiv.h View File

@@ -426,6 +426,8 @@ struct win {
unsigned int h;
win_bar_t l;
win_bar_t r;
XftColor bgcol;
XftColor fgcol;
} bar;
};



+ 9
- 5
window.c View File

@@ -122,6 +122,10 @@ void win_init(win_t *win)
win_alloc_color(e, bg, &win->bg);
win_alloc_color(e, fg, &win->fg);

// Kanon trying to get bar colors back
win_alloc_color(e, BAR_BG_COLOR, &win->bar.bgcol);
win_alloc_color(e, BAR_FG_COLOR, &win->bar.fgcol);

win->bar.l.size = BAR_L_LEN;
win->bar.r.size = BAR_R_LEN;
/* 3 padding bytes needed by utf8_decode */
@@ -395,23 +399,23 @@ void win_draw_bar(win_t *win)
d = XftDrawCreate(e->dpy, win->buf.pm, DefaultVisual(e->dpy, e->scr),
DefaultColormap(e->dpy, e->scr));

XSetForeground(e->dpy, gc, win->fg.pixel);
XSetForeground(e->dpy, gc, win->bar.bgcol.pixel);
XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);

XSetForeground(e->dpy, gc, win->bg.pixel);
XSetBackground(e->dpy, gc, win->fg.pixel);
XSetForeground(e->dpy, gc, win->bar.fgcol.pixel);
XSetBackground(e->dpy, gc, win->bar.bgcol.pixel);

if ((len = strlen(r->buf)) > 0) {
if ((tw = TEXTWIDTH(win, r->buf, len)) > w)
return;
x = win->w - tw - H_TEXT_PAD;
w -= tw;
win_draw_text(win, d, &win->bg, x, y, r->buf, len, tw);
win_draw_text(win, d, &win->bar.fgcol, x, y, r->buf, len, tw);
}
if ((len = strlen(l->buf)) > 0) {
x = H_TEXT_PAD;
w -= 2 * H_TEXT_PAD; /* gap between left and right parts */
win_draw_text(win, d, &win->bg, x, y, l->buf, len, w);
win_draw_text(win, d, &win->bar.fgcol, x, y, l->buf, len, w);
}
XftDrawDestroy(d);
}


Loading…
Cancel
Save