Added -w cmdline option
This commit is contained in:
parent
e8a503bcbb
commit
17e2a795bb
|
@ -28,8 +28,10 @@ check and change them, so that they fit your needs.
|
|||
|
||||
Usage
|
||||
-----
|
||||
sxiv has no useful command line options yet, but they will be added in the next
|
||||
releases. Right now, it simply displays all files given on the command line.
|
||||
sxiv supports the following command-line options:
|
||||
|
||||
-w WIDTHxHEIGHT set window width to WIDTH and height to HEIGHT
|
||||
(if HEIGHT is omitted, height is also set to WIDTH)
|
||||
|
||||
Use the following keys to control sxiv:
|
||||
|
||||
|
|
25
options.c
25
options.c
|
@ -29,7 +29,7 @@ options_t _options;
|
|||
const options_t *options = (const options_t*) &_options;
|
||||
|
||||
void print_usage() {
|
||||
printf("usage: sxiv [-hv] FILES...\n");
|
||||
printf("usage: sxiv [-hv] [-w WIDTH[xHEIGHT]] FILES...\n");
|
||||
}
|
||||
|
||||
void print_version() {
|
||||
|
@ -38,9 +38,13 @@ void print_version() {
|
|||
}
|
||||
|
||||
void parse_options(int argc, char **argv) {
|
||||
unsigned short w, h;
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hv")) != -1) {
|
||||
_options.winw = w = 0;
|
||||
_options.winh = h = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hvw:")) != -1) {
|
||||
switch (opt) {
|
||||
case '?':
|
||||
print_usage();
|
||||
|
@ -51,9 +55,26 @@ void parse_options(int argc, char **argv) {
|
|||
case 'v':
|
||||
print_version();
|
||||
exit(0);
|
||||
case 'w':
|
||||
if (!sscanf(optarg, "%hux%hu", &w, &h)) {
|
||||
fprintf(stderr, "sxiv: invalid argument for option -w: %s\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
} else {
|
||||
_options.winw = (int) w;
|
||||
_options.winh = (int) h;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_options.winw) {
|
||||
_options.winw = WIN_WIDTH;
|
||||
_options.winh = WIN_HEIGHT;
|
||||
} else if (!_options.winh) {
|
||||
_options.winh = _options.winw;
|
||||
}
|
||||
|
||||
_options.filenames = (const char**) argv + optind;
|
||||
_options.filecnt = argc - optind;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
typedef struct options_s {
|
||||
const char **filenames;
|
||||
int filecnt;
|
||||
int winw;
|
||||
int winh;
|
||||
} options_t;
|
||||
|
||||
extern const options_t *options;
|
||||
|
|
14
sxiv.1
14
sxiv.1
|
@ -4,6 +4,10 @@ sxiv \- Simple (or small or suckless) X Image Viewer
|
|||
.SH SYNOPSIS
|
||||
.B sxiv
|
||||
.RB [ \-hv ]
|
||||
[
|
||||
.B \-w
|
||||
.IB WIDTH x HEIGHT
|
||||
]
|
||||
.IR FILE ...
|
||||
.SH DESCRIPTION
|
||||
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.
|
|||
.TP
|
||||
.B \-v
|
||||
Print version information to standard output and exit.
|
||||
.TP
|
||||
.BI "\-w " WIDTH x HEIGHT
|
||||
Set window width to
|
||||
.I WIDTH
|
||||
and height to
|
||||
.IR HEIGHT .
|
||||
If
|
||||
.I HEIGHT
|
||||
is omitted, height is also set to
|
||||
.IR WIDTH .
|
||||
.SH KEYBOARD COMMANDS
|
||||
.SS General
|
||||
.TP
|
||||
|
|
9
window.c
9
window.c
|
@ -23,6 +23,7 @@
|
|||
#include <X11/Xutil.h>
|
||||
|
||||
#include "sxiv.h"
|
||||
#include "options.h"
|
||||
#include "window.h"
|
||||
|
||||
GC bgc;
|
||||
|
@ -53,12 +54,8 @@ void win_open(win_t *win) {
|
|||
win->bgcol = bgcol.pixel;
|
||||
win->pm = 0;
|
||||
|
||||
win->w = WIN_WIDTH;
|
||||
win->h = WIN_HEIGHT;
|
||||
if (win->w > e->scrw)
|
||||
win->w = e->scrw;
|
||||
if (win->h > e->scrh)
|
||||
win->h = e->scrh;
|
||||
win->w = MIN(options->winw, e->scrw);
|
||||
win->h = MIN(options->winh, e->scrh);
|
||||
win->x = (e->scrw - win->w) / 2;
|
||||
win->y = (e->scrh - win->h) / 2;
|
||||
|
||||
|
|
Loading…
Reference in New Issue