Krolyxon
Commit 17e2a79

Branches

Refs →

nsxiv17e2a79

Added -w cmdline option

Author
Bert
Date
2011-01-27 16:15 +0100
Parent
e8a503b
Commit
17e2a795bbcdbf9bc8eb07e2aaca0a494871b9e8

+46 −10

5 files changed

  1. M README.md +4 −2
  2. M options.c +23 −2
  3. M options.h +2 −0
  4. M sxiv.1 +14 −0
  5. M window.c +3 −6
M README.md View
@@ -28,8 +28,10 @@ check and change them, so that they fit your needs.
2828
2929 Usage
3030 -----
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)
3335
3436 Use the following keys to control sxiv:
3537
M options.c View
@@ -29,7 +29,7 @@ options_t _options;
2929 const options_t *options = (const options_t*) &_options;
3030
3131 void print_usage() {
32− printf("usage: sxiv [-hv] FILES...\n");
32+ printf("usage: sxiv [-hv] [-w WIDTH[xHEIGHT]] FILES...\n");
3333 }
3434
3535 void print_version() {
@@ -38,9 +38,13 @@ void print_version() {
3838 }
3939
4040 void parse_options(int argc, char **argv) {
41+ unsigned short w, h;
4142 int opt;
4243
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) {
4448 switch (opt) {
4549 case '?':
4650 print_usage();
@@ -51,9 +55,26 @@ void parse_options(int argc, char **argv) {
5155 case 'v':
5256 print_version();
5357 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;
5468 }
5569 }
5670
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+
5778 _options.filenames = (const char**) argv + optind;
5879 _options.filecnt = argc - optind;
5980 }
M options.h View
@@ -22,6 +22,8 @@
2222 typedef struct options_s {
2323 const char **filenames;
2424 int filecnt;
25+ int winw;
26+ int winh;
2527 } options_t;
2628
2729 extern const options_t *options;
M sxiv.1 View
@@ -4,6 +4,10 @@ sxiv \- Simple (or small or suckless) X Image Viewer
44 .SH SYNOPSIS
55 .B sxiv
66 .RB [ \-hv ]
7+[
8+.B \-w
9+.IB WIDTH x HEIGHT
10+]
711 .IR FILE ...
812 .SH DESCRIPTION
913 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.
1822 .TP
1923 .B \-v
2024 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 .
2135 .SH KEYBOARD COMMANDS
2236 .SS General
2337 .TP
M window.c View
@@ -23,6 +23,7 @@
2323 #include <X11/Xutil.h>
2424
2525 #include "sxiv.h"
26+#include "options.h"
2627 #include "window.h"
2728
2829 GC bgc;
@@ -53,12 +54,8 @@ void win_open(win_t *win) {
5354 win->bgcol = bgcol.pixel;
5455 win->pm = 0;
5556
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);
6259 win->x = (e->scrw - win->w) / 2;
6360 win->y = (e->scrh - win->h) / 2;
6461