nsxiv17e2a79
Added -w cmdline option
+46 −10
5 files changed
| @@ -28,8 +28,10 @@ check and change them, so that they fit your needs. | |||
| 28 | 28 | ||
| 29 | 29 | Usage | |
| 30 | 30 | ----- | |
| 31 | − | sxiv has no useful command line options yet, but they will be added in the next | |
| 32 | − | releases. Right now, it simply displays all files given on the command line. | |
| 31 | + | sxiv supports the following command-line options: | |
| 32 | + | ||
| 33 | + | -w WIDTHxHEIGHT set window width to WIDTH and height to HEIGHT | |
| 34 | + | (if HEIGHT is omitted, height is also set to WIDTH) | |
| 33 | 35 | ||
| 34 | 36 | Use the following keys to control sxiv: | |
| 35 | 37 | ||
| @@ -29,7 +29,7 @@ options_t _options; | |||
| 29 | 29 | const options_t *options = (const options_t*) &_options; | |
| 30 | 30 | ||
| 31 | 31 | void print_usage() { | |
| 32 | − | printf("usage: sxiv [-hv] FILES...\n"); | |
| 32 | + | printf("usage: sxiv [-hv] [-w WIDTH[xHEIGHT]] FILES...\n"); | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | 35 | void print_version() { | |
| @@ -38,9 +38,13 @@ void print_version() { | |||
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | 40 | void parse_options(int argc, char **argv) { | |
| 41 | + | unsigned short w, h; | |
| 41 | 42 | int opt; | |
| 42 | 43 | ||
| 43 | − | while ((opt = getopt(argc, argv, "hv")) != -1) { | |
| 44 | + | _options.winw = w = 0; | |
| 45 | + | _options.winh = h = 0; | |
| 46 | + | ||
| 47 | + | while ((opt = getopt(argc, argv, "hvw:")) != -1) { | |
| 44 | 48 | switch (opt) { | |
| 45 | 49 | case '?': | |
| 46 | 50 | print_usage(); | |
| @@ -51,9 +55,26 @@ void parse_options(int argc, char **argv) { | |||
| 51 | 55 | case 'v': | |
| 52 | 56 | print_version(); | |
| 53 | 57 | exit(0); | |
| 58 | + | case 'w': | |
| 59 | + | if (!sscanf(optarg, "%hux%hu", &w, &h)) { | |
| 60 | + | fprintf(stderr, "sxiv: invalid argument for option -w: %s\n", | |
| 61 | + | optarg); | |
| 62 | + | exit(1); | |
| 63 | + | } else { | |
| 64 | + | _options.winw = (int) w; | |
| 65 | + | _options.winh = (int) h; | |
| 66 | + | } | |
| 67 | + | break; | |
| 54 | 68 | } | |
| 55 | 69 | } | |
| 56 | 70 | ||
| 71 | + | if (!_options.winw) { | |
| 72 | + | _options.winw = WIN_WIDTH; | |
| 73 | + | _options.winh = WIN_HEIGHT; | |
| 74 | + | } else if (!_options.winh) { | |
| 75 | + | _options.winh = _options.winw; | |
| 76 | + | } | |
| 77 | + | ||
| 57 | 78 | _options.filenames = (const char**) argv + optind; | |
| 58 | 79 | _options.filecnt = argc - optind; | |
| 59 | 80 | } | |
| @@ -22,6 +22,8 @@ | |||
| 22 | 22 | typedef struct options_s { | |
| 23 | 23 | const char **filenames; | |
| 24 | 24 | int filecnt; | |
| 25 | + | int winw; | |
| 26 | + | int winh; | |
| 25 | 27 | } options_t; | |
| 26 | 28 | ||
| 27 | 29 | extern const options_t *options; | |
| @@ -4,6 +4,10 @@ sxiv \- Simple (or small or suckless) X Image Viewer | |||
| 4 | 4 | .SH SYNOPSIS | |
| 5 | 5 | .B sxiv | |
| 6 | 6 | .RB [ \-hv ] | |
| 7 | + | [ | |
| 8 | + | .B \-w | |
| 9 | + | .IB WIDTH x HEIGHT | |
| 10 | + | ] | |
| 7 | 11 | .IR FILE ... | |
| 8 | 12 | .SH DESCRIPTION | |
| 9 | 13 | sxiv is a simple image viewer for X. It only has the most basic features | |
| @@ -18,6 +22,16 @@ Print brief usage information to standard output and exit. | |||
| 18 | 22 | .TP | |
| 19 | 23 | .B \-v | |
| 20 | 24 | Print version information to standard output and exit. | |
| 25 | + | .TP | |
| 26 | + | .BI "\-w " WIDTH x HEIGHT | |
| 27 | + | Set window width to | |
| 28 | + | .I WIDTH | |
| 29 | + | and height to | |
| 30 | + | .IR HEIGHT . | |
| 31 | + | If | |
| 32 | + | .I HEIGHT | |
| 33 | + | is omitted, height is also set to | |
| 34 | + | .IR WIDTH . | |
| 21 | 35 | .SH KEYBOARD COMMANDS | |
| 22 | 36 | .SS General | |
| 23 | 37 | .TP | |
| @@ -23,6 +23,7 @@ | |||
| 23 | 23 | #include <X11/Xutil.h> | |
| 24 | 24 | ||
| 25 | 25 | #include "sxiv.h" | |
| 26 | + | #include "options.h" | |
| 26 | 27 | #include "window.h" | |
| 27 | 28 | ||
| 28 | 29 | GC bgc; | |
| @@ -53,12 +54,8 @@ void win_open(win_t *win) { | |||
| 53 | 54 | win->bgcol = bgcol.pixel; | |
| 54 | 55 | win->pm = 0; | |
| 55 | 56 | ||
| 56 | − | win->w = WIN_WIDTH; | |
| 57 | − | win->h = WIN_HEIGHT; | |
| 58 | − | if (win->w > e->scrw) | |
| 59 | − | win->w = e->scrw; | |
| 60 | − | if (win->h > e->scrh) | |
| 61 | − | win->h = e->scrh; | |
| 57 | + | win->w = MIN(options->winw, e->scrw); | |
| 58 | + | win->h = MIN(options->winh, e->scrh); | |
| 62 | 59 | win->x = (e->scrw - win->w) / 2; | |
| 63 | 60 | win->y = (e->scrh - win->h) / 2; | |
| 64 | 61 | ||