Replace -w with well-known geometry option

This commit is contained in:
Bert 2011-01-30 22:00:58 +01:00
parent c937570bbe
commit 229830ad18
5 changed files with 32 additions and 33 deletions

View file

@ -254,11 +254,11 @@ int img_pan(img_t *img, win_t *win, pandir_t dir) {
case PAN_LEFT: case PAN_LEFT:
return img_move(img, win, win->w / 5, 0); return img_move(img, win, win->w / 5, 0);
case PAN_RIGHT: case PAN_RIGHT:
return img_move(img, win, -win->w / 5, 0); return img_move(img, win, win->w / 5 * -1, 0);
case PAN_UP: case PAN_UP:
return img_move(img, win, 0, win->h / 5); return img_move(img, win, 0, win->h / 5);
case PAN_DOWN: case PAN_DOWN:
return img_move(img, win, 0, -win->h / 5); return img_move(img, win, 0, win->h / 5 * -1);
} }
return 0; return 0;

View file

@ -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 [-dfhpsvWZ] [-w WIDTH[xHEIGHT]] [-z ZOOM] FILES...\n"); printf("usage: sxiv [-dfhpsvWZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
} }
void print_version() { void print_version() {
@ -38,7 +38,6 @@ void print_version() {
} }
void parse_options(int argc, char **argv) { void parse_options(int argc, char **argv) {
unsigned short w, h;
float z; float z;
int opt; int opt;
@ -46,13 +45,12 @@ void parse_options(int argc, char **argv) {
_options.zoom = 1.0; _options.zoom = 1.0;
_options.aa = 1; _options.aa = 1;
_options.winw = w = 0;
_options.winh = h = 0;
_options.fullscreen = 0; _options.fullscreen = 0;
_options.geometry = NULL;
_options.warn = 0; _options.warn = 0;
while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) { while ((opt = getopt(argc, argv, "dfg:hpsvWZz:")) != -1) {
switch (opt) { switch (opt) {
case '?': case '?':
print_usage(); print_usage();
@ -63,6 +61,9 @@ void parse_options(int argc, char **argv) {
case 'f': case 'f':
_options.fullscreen = 1; _options.fullscreen = 1;
break; break;
case 'g':
_options.geometry = optarg;
break;
case 'h': case 'h':
print_usage(); print_usage();
exit(0); exit(0);
@ -78,16 +79,6 @@ void parse_options(int argc, char **argv) {
case 'W': case 'W':
_options.warn = 1; _options.warn = 1;
break; break;
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;
case 'Z': case 'Z':
_options.scalemode = SCALE_ZOOM; _options.scalemode = SCALE_ZOOM;
_options.zoom = 1.0; _options.zoom = 1.0;
@ -105,13 +96,6 @@ void parse_options(int argc, char **argv) {
} }
} }
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;
_options.filecnt = argc - optind; _options.filecnt = argc - optind;
} }

View file

@ -29,9 +29,8 @@ typedef struct options_s {
float zoom; float zoom;
unsigned char aa; unsigned char aa;
int winw;
int winh;
unsigned char fullscreen; unsigned char fullscreen;
char *geometry;
unsigned char warn; unsigned char warn;
} options_t; } options_t;

View file

@ -35,6 +35,7 @@ void win_open(win_t *win) {
win_env_t *e; win_env_t *e;
XClassHint *classhint; XClassHint *classhint;
XColor bgcol; XColor bgcol;
int gmask;
if (!win) if (!win)
return; return;
@ -58,9 +59,24 @@ void win_open(win_t *win) {
win->pm = 0; win->pm = 0;
win->fullscreen = 0; win->fullscreen = 0;
win->w = MIN(options->winw, e->scrw);
win->h = MIN(options->winh, e->scrh); /* determine window offsets, width & height */
if (!options->geometry)
gmask = 0;
else
gmask = XParseGeometry(options->geometry, &win->x, &win->y,
&win->w, &win->h);
if (!(gmask & WidthValue))
win->w = WIN_WIDTH;
if (win->w > e->scrw)
win->w = e->scrw;
if (!(gmask & HeightValue))
win->h = WIN_HEIGHT;
if (win->h > e->scrh)
win->h = e->scrh;
if (!(gmask & XValue))
win->x = (e->scrw - win->w) / 2; win->x = (e->scrw - win->w) / 2;
if (!(gmask & YValue))
win->y = (e->scrh - win->h) / 2; win->y = (e->scrh - win->h) / 2;
win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),

View file

@ -44,12 +44,12 @@ typedef struct win_s {
unsigned long bgcol; unsigned long bgcol;
Pixmap pm; Pixmap pm;
int w;
int h;
int x; int x;
int y; int y;
unsigned int w;
unsigned int h;
int bw; unsigned int bw;
unsigned char fullscreen; unsigned char fullscreen;
} win_t; } win_t;