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
|
Usage
|
||||||
-----
|
-----
|
||||||
sxiv has no useful command line options yet, but they will be added in the next
|
sxiv supports the following command-line options:
|
||||||
releases. Right now, it simply displays all files given on the command line.
|
|
||||||
|
-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:
|
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;
|
const options_t *options = (const options_t*) &_options;
|
||||||
|
|
||||||
void print_usage() {
|
void print_usage() {
|
||||||
printf("usage: sxiv [-hv] FILES...\n");
|
printf("usage: sxiv [-hv] [-w WIDTH[xHEIGHT]] FILES...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_version() {
|
void print_version() {
|
||||||
|
@ -38,9 +38,13 @@ void print_version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_options(int argc, char **argv) {
|
void parse_options(int argc, char **argv) {
|
||||||
|
unsigned short w, h;
|
||||||
int opt;
|
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) {
|
switch (opt) {
|
||||||
case '?':
|
case '?':
|
||||||
print_usage();
|
print_usage();
|
||||||
|
@ -51,7 +55,24 @@ void parse_options(int argc, char **argv) {
|
||||||
case 'v':
|
case 'v':
|
||||||
print_version();
|
print_version();
|
||||||
exit(0);
|
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.filenames = (const char**) argv + optind;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
typedef struct options_s {
|
typedef struct options_s {
|
||||||
const char **filenames;
|
const char **filenames;
|
||||||
int filecnt;
|
int filecnt;
|
||||||
|
int winw;
|
||||||
|
int winh;
|
||||||
} options_t;
|
} options_t;
|
||||||
|
|
||||||
extern const options_t *options;
|
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
|
.SH SYNOPSIS
|
||||||
.B sxiv
|
.B sxiv
|
||||||
.RB [ \-hv ]
|
.RB [ \-hv ]
|
||||||
|
[
|
||||||
|
.B \-w
|
||||||
|
.IB WIDTH x HEIGHT
|
||||||
|
]
|
||||||
.IR FILE ...
|
.IR FILE ...
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
sxiv is a simple image viewer for X. It only has the most basic features
|
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
|
.TP
|
||||||
.B \-v
|
.B \-v
|
||||||
Print version information to standard output and exit.
|
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
|
.SH KEYBOARD COMMANDS
|
||||||
.SS General
|
.SS General
|
||||||
.TP
|
.TP
|
||||||
|
|
9
window.c
9
window.c
|
@ -23,6 +23,7 @@
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
#include "sxiv.h"
|
#include "sxiv.h"
|
||||||
|
#include "options.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
GC bgc;
|
GC bgc;
|
||||||
|
@ -53,12 +54,8 @@ void win_open(win_t *win) {
|
||||||
win->bgcol = bgcol.pixel;
|
win->bgcol = bgcol.pixel;
|
||||||
win->pm = 0;
|
win->pm = 0;
|
||||||
|
|
||||||
win->w = WIN_WIDTH;
|
win->w = MIN(options->winw, e->scrw);
|
||||||
win->h = WIN_HEIGHT;
|
win->h = MIN(options->winh, e->scrh);
|
||||||
if (win->w > e->scrw)
|
|
||||||
win->w = e->scrw;
|
|
||||||
if (win->h > e->scrh)
|
|
||||||
win->h = e->scrh;
|
|
||||||
win->x = (e->scrw - win->w) / 2;
|
win->x = (e->scrw - win->w) / 2;
|
||||||
win->y = (e->scrh - win->h) / 2;
|
win->y = (e->scrh - win->h) / 2;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue