Replace -w with well-known geometry option
This commit is contained in:
parent
c937570bbe
commit
229830ad18
4
image.c
4
image.c
|
@ -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;
|
||||||
|
|
28
options.c
28
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 [-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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
24
window.c
24
window.c
|
@ -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,10 +59,25 @@ 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 */
|
||||||
win->x = (e->scrw - win->w) / 2;
|
if (!options->geometry)
|
||||||
win->y = (e->scrh - win->h) / 2;
|
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;
|
||||||
|
if (!(gmask & YValue))
|
||||||
|
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),
|
||||||
win->x, win->y, win->w, win->h, 0,
|
win->x, win->y, win->w, win->h, 0,
|
||||||
|
|
Loading…
Reference in a new issue