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:
|
||||
return img_move(img, win, win->w / 5, 0);
|
||||
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:
|
||||
return img_move(img, win, 0, win->h / 5);
|
||||
case PAN_DOWN:
|
||||
return img_move(img, win, 0, -win->h / 5);
|
||||
return img_move(img, win, 0, win->h / 5 * -1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
28
options.c
28
options.c
|
@ -29,7 +29,7 @@ options_t _options;
|
|||
const options_t *options = (const options_t*) &_options;
|
||||
|
||||
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() {
|
||||
|
@ -38,7 +38,6 @@ void print_version() {
|
|||
}
|
||||
|
||||
void parse_options(int argc, char **argv) {
|
||||
unsigned short w, h;
|
||||
float z;
|
||||
int opt;
|
||||
|
||||
|
@ -46,13 +45,12 @@ void parse_options(int argc, char **argv) {
|
|||
_options.zoom = 1.0;
|
||||
_options.aa = 1;
|
||||
|
||||
_options.winw = w = 0;
|
||||
_options.winh = h = 0;
|
||||
_options.fullscreen = 0;
|
||||
_options.geometry = NULL;
|
||||
|
||||
_options.warn = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "dfg:hpsvWZz:")) != -1) {
|
||||
switch (opt) {
|
||||
case '?':
|
||||
print_usage();
|
||||
|
@ -63,6 +61,9 @@ void parse_options(int argc, char **argv) {
|
|||
case 'f':
|
||||
_options.fullscreen = 1;
|
||||
break;
|
||||
case 'g':
|
||||
_options.geometry = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
print_usage();
|
||||
exit(0);
|
||||
|
@ -78,16 +79,6 @@ void parse_options(int argc, char **argv) {
|
|||
case 'W':
|
||||
_options.warn = 1;
|
||||
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':
|
||||
_options.scalemode = SCALE_ZOOM;
|
||||
_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.filecnt = argc - optind;
|
||||
}
|
||||
|
|
|
@ -29,9 +29,8 @@ typedef struct options_s {
|
|||
float zoom;
|
||||
unsigned char aa;
|
||||
|
||||
int winw;
|
||||
int winh;
|
||||
unsigned char fullscreen;
|
||||
char *geometry;
|
||||
|
||||
unsigned char warn;
|
||||
} options_t;
|
||||
|
|
24
window.c
24
window.c
|
@ -35,6 +35,7 @@ void win_open(win_t *win) {
|
|||
win_env_t *e;
|
||||
XClassHint *classhint;
|
||||
XColor bgcol;
|
||||
int gmask;
|
||||
|
||||
if (!win)
|
||||
return;
|
||||
|
@ -58,10 +59,25 @@ void win_open(win_t *win) {
|
|||
win->pm = 0;
|
||||
|
||||
win->fullscreen = 0;
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
if (!(gmask & YValue))
|
||||
win->y = (e->scrh - win->h) / 2;
|
||||
|
||||
win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
|
||||
win->x, win->y, win->w, win->h, 0,
|
||||
|
|
Loading…
Reference in New Issue