浏览代码

Added -w cmdline option

master
Bert 14 年前
父节点
当前提交
17e2a795bb
共有 5 个文件被更改,包括 46 次插入10 次删除
  1. +4
    -2
      README.md
  2. +23
    -2
      options.c
  3. +2
    -0
      options.h
  4. +14
    -0
      sxiv.1
  5. +3
    -6
      window.c

+ 4
- 2
README.md 查看文件

@@ -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:



+ 23
- 2
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;
}

+ 2
- 0
options.h 查看文件

@@ -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
- 0
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


+ 3
- 6
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;



正在加载...
取消
保存