nsxiv229830a
Replace -w with well-known geometry option
+32 −33
5 files changed
| @@ -254,11 +254,11 @@ int img_pan(img_t *img, win_t *win, pandir_t dir) { | |||
| 254 | 254 | case PAN_LEFT: | |
| 255 | 255 | return img_move(img, win, win->w / 5, 0); | |
| 256 | 256 | case PAN_RIGHT: | |
| 257 | − | return img_move(img, win, -win->w / 5, 0); | |
| 257 | + | return img_move(img, win, win->w / 5 * -1, 0); | |
| 258 | 258 | case PAN_UP: | |
| 259 | 259 | return img_move(img, win, 0, win->h / 5); | |
| 260 | 260 | case PAN_DOWN: | |
| 261 | − | return img_move(img, win, 0, -win->h / 5); | |
| 261 | + | return img_move(img, win, 0, win->h / 5 * -1); | |
| 262 | 262 | } | |
| 263 | 263 | ||
| 264 | 264 | return 0; | |
| @@ -29,7 +29,7 @@ options_t _options; | |||
| 29 | 29 | const options_t *options = (const options_t*) &_options; | |
| 30 | 30 | ||
| 31 | 31 | void print_usage() { | |
| 32 | − | printf("usage: sxiv [-dfhpsvWZ] [-w WIDTH[xHEIGHT]] [-z ZOOM] FILES...\n"); | |
| 32 | + | printf("usage: sxiv [-dfhpsvWZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | 35 | void print_version() { | |
| @@ -38,7 +38,6 @@ void print_version() { | |||
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | 40 | void parse_options(int argc, char **argv) { | |
| 41 | − | unsigned short w, h; | |
| 42 | 41 | float z; | |
| 43 | 42 | int opt; | |
| 44 | 43 | ||
| @@ -46,13 +45,12 @@ void parse_options(int argc, char **argv) { | |||
| 46 | 45 | _options.zoom = 1.0; | |
| 47 | 46 | _options.aa = 1; | |
| 48 | 47 | ||
| 49 | − | _options.winw = w = 0; | |
| 50 | − | _options.winh = h = 0; | |
| 51 | 48 | _options.fullscreen = 0; | |
| 49 | + | _options.geometry = NULL; | |
| 52 | 50 | ||
| 53 | 51 | _options.warn = 0; | |
| 54 | 52 | ||
| 55 | − | while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) { | |
| 53 | + | while ((opt = getopt(argc, argv, "dfg:hpsvWZz:")) != -1) { | |
| 56 | 54 | switch (opt) { | |
| 57 | 55 | case '?': | |
| 58 | 56 | print_usage(); | |
| @@ -63,6 +61,9 @@ void parse_options(int argc, char **argv) { | |||
| 63 | 61 | case 'f': | |
| 64 | 62 | _options.fullscreen = 1; | |
| 65 | 63 | break; | |
| 64 | + | case 'g': | |
| 65 | + | _options.geometry = optarg; | |
| 66 | + | break; | |
| 66 | 67 | case 'h': | |
| 67 | 68 | print_usage(); | |
| 68 | 69 | exit(0); | |
| @@ -78,16 +79,6 @@ void parse_options(int argc, char **argv) { | |||
| 78 | 79 | case 'W': | |
| 79 | 80 | _options.warn = 1; | |
| 80 | 81 | break; | |
| 81 | − | case 'w': | |
| 82 | − | if (!sscanf(optarg, "%hux%hu", &w, &h)) { | |
| 83 | − | fprintf(stderr, "sxiv: invalid argument for option -w: %s\n", | |
| 84 | − | optarg); | |
| 85 | − | exit(1); | |
| 86 | − | } else { | |
| 87 | − | _options.winw = (int) w; | |
| 88 | − | _options.winh = (int) h; | |
| 89 | − | } | |
| 90 | − | break; | |
| 91 | 82 | case 'Z': | |
| 92 | 83 | _options.scalemode = SCALE_ZOOM; | |
| 93 | 84 | _options.zoom = 1.0; | |
| @@ -105,13 +96,6 @@ void parse_options(int argc, char **argv) { | |||
| 105 | 96 | } | |
| 106 | 97 | } | |
| 107 | 98 | ||
| 108 | − | if (!_options.winw) { | |
| 109 | − | _options.winw = WIN_WIDTH; | |
| 110 | − | _options.winh = WIN_HEIGHT; | |
| 111 | − | } else if (!_options.winh) { | |
| 112 | − | _options.winh = _options.winw; | |
| 113 | − | } | |
| 114 | − | ||
| 115 | 99 | _options.filenames = (const char**) argv + optind; | |
| 116 | 100 | _options.filecnt = argc - optind; | |
| 117 | 101 | } | |
| @@ -29,9 +29,8 @@ typedef struct options_s { | |||
| 29 | 29 | float zoom; | |
| 30 | 30 | unsigned char aa; | |
| 31 | 31 | ||
| 32 | − | int winw; | |
| 33 | − | int winh; | |
| 34 | 32 | unsigned char fullscreen; | |
| 33 | + | char *geometry; | |
| 35 | 34 | ||
| 36 | 35 | unsigned char warn; | |
| 37 | 36 | } options_t; | |
| @@ -35,6 +35,7 @@ void win_open(win_t *win) { | |||
| 35 | 35 | win_env_t *e; | |
| 36 | 36 | XClassHint *classhint; | |
| 37 | 37 | XColor bgcol; | |
| 38 | + | int gmask; | |
| 38 | 39 | ||
| 39 | 40 | if (!win) | |
| 40 | 41 | return; | |
| @@ -58,10 +59,25 @@ void win_open(win_t *win) { | |||
| 58 | 59 | win->pm = 0; | |
| 59 | 60 | ||
| 60 | 61 | win->fullscreen = 0; | |
| 61 | − | win->w = MIN(options->winw, e->scrw); | |
| 62 | − | win->h = MIN(options->winh, e->scrh); | |
| 63 | − | win->x = (e->scrw - win->w) / 2; | |
| 64 | − | win->y = (e->scrh - win->h) / 2; | |
| 62 | + | ||
| 63 | + | /* determine window offsets, width & height */ | |
| 64 | + | if (!options->geometry) | |
| 65 | + | gmask = 0; | |
| 66 | + | else | |
| 67 | + | gmask = XParseGeometry(options->geometry, &win->x, &win->y, | |
| 68 | + | &win->w, &win->h); | |
| 69 | + | if (!(gmask & WidthValue)) | |
| 70 | + | win->w = WIN_WIDTH; | |
| 71 | + | if (win->w > e->scrw) | |
| 72 | + | win->w = e->scrw; | |
| 73 | + | if (!(gmask & HeightValue)) | |
| 74 | + | win->h = WIN_HEIGHT; | |
| 75 | + | if (win->h > e->scrh) | |
| 76 | + | win->h = e->scrh; | |
| 77 | + | if (!(gmask & XValue)) | |
| 78 | + | win->x = (e->scrw - win->w) / 2; | |
| 79 | + | if (!(gmask & YValue)) | |
| 80 | + | win->y = (e->scrh - win->h) / 2; | |
| 65 | 81 | ||
| 66 | 82 | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), | |
| 67 | 83 | win->x, win->y, win->w, win->h, 0, | |
| @@ -44,12 +44,12 @@ typedef struct win_s { | |||
| 44 | 44 | unsigned long bgcol; | |
| 45 | 45 | Pixmap pm; | |
| 46 | 46 | ||
| 47 | − | int w; | |
| 48 | − | int h; | |
| 49 | 47 | int x; | |
| 50 | 48 | int y; | |
| 49 | + | unsigned int w; | |
| 50 | + | unsigned int h; | |
| 51 | 51 | ||
| 52 | − | int bw; | |
| 52 | + | unsigned int bw; | |
| 53 | 53 | unsigned char fullscreen; | |
| 54 | 54 | } win_t; | |
| 55 | 55 | ||