Krolyxon
Commit 229830a

Branches

Refs →

nsxiv229830a

Replace -w with well-known geometry option

Author
Bert
Date
2011-01-30 22:00 +0100
Parent
c937570
Commit
229830ad188fc520da56bfa8a3b8e0da3744c799

+32 −33

5 files changed

  1. M image.c +2 −2
  2. M options.c +6 −22
  3. M options.h +1 −2
  4. M window.c +20 −4
  5. M window.h +3 −3
M image.c View
@@ -254,11 +254,11 @@ int img_pan(img_t *img, win_t *win, pandir_t dir) {
254254 case PAN_LEFT:
255255 return img_move(img, win, win->w / 5, 0);
256256 case PAN_RIGHT:
257− return img_move(img, win, -win->w / 5, 0);
257+ return img_move(img, win, win->w / 5 * -1, 0);
258258 case PAN_UP:
259259 return img_move(img, win, 0, win->h / 5);
260260 case PAN_DOWN:
261− return img_move(img, win, 0, -win->h / 5);
261+ return img_move(img, win, 0, win->h / 5 * -1);
262262 }
263263
264264 return 0;
M options.c View
@@ -29,7 +29,7 @@ options_t _options;
2929 const options_t *options = (const options_t*) &_options;
3030
3131 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");
3333 }
3434
3535 void print_version() {
@@ -38,7 +38,6 @@ void print_version() {
3838 }
3939
4040 void parse_options(int argc, char **argv) {
41− unsigned short w, h;
4241 float z;
4342 int opt;
4443
@@ -46,13 +45,12 @@ void parse_options(int argc, char **argv) {
4645 _options.zoom = 1.0;
4746 _options.aa = 1;
4847
49− _options.winw = w = 0;
50− _options.winh = h = 0;
5148 _options.fullscreen = 0;
49+ _options.geometry = NULL;
5250
5351 _options.warn = 0;
5452
55− while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) {
53+ while ((opt = getopt(argc, argv, "dfg:hpsvWZz:")) != -1) {
5654 switch (opt) {
5755 case '?':
5856 print_usage();
@@ -63,6 +61,9 @@ void parse_options(int argc, char **argv) {
6361 case 'f':
6462 _options.fullscreen = 1;
6563 break;
64+ case 'g':
65+ _options.geometry = optarg;
66+ break;
6667 case 'h':
6768 print_usage();
6869 exit(0);
@@ -78,16 +79,6 @@ void parse_options(int argc, char **argv) {
7879 case 'W':
7980 _options.warn = 1;
8081 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;
9182 case 'Z':
9283 _options.scalemode = SCALE_ZOOM;
9384 _options.zoom = 1.0;
@@ -105,13 +96,6 @@ void parse_options(int argc, char **argv) {
10596 }
10697 }
10798
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−
11599 _options.filenames = (const char**) argv + optind;
116100 _options.filecnt = argc - optind;
117101 }
M options.h View
@@ -29,9 +29,8 @@ typedef struct options_s {
2929 float zoom;
3030 unsigned char aa;
3131
32− int winw;
33− int winh;
3432 unsigned char fullscreen;
33+ char *geometry;
3534
3635 unsigned char warn;
3736 } options_t;
M window.c View
@@ -35,6 +35,7 @@ void win_open(win_t *win) {
3535 win_env_t *e;
3636 XClassHint *classhint;
3737 XColor bgcol;
38+ int gmask;
3839
3940 if (!win)
4041 return;
@@ -58,10 +59,25 @@ void win_open(win_t *win) {
5859 win->pm = 0;
5960
6061 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;
6581
6682 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
6783 win->x, win->y, win->w, win->h, 0,
M window.h View
@@ -44,12 +44,12 @@ typedef struct win_s {
4444 unsigned long bgcol;
4545 Pixmap pm;
4646
47− int w;
48− int h;
4947 int x;
5048 int y;
49+ unsigned int w;
50+ unsigned int h;
5151
52− int bw;
52+ unsigned int bw;
5353 unsigned char fullscreen;
5454 } win_t;
5555