aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--image.c4
-rw-r--r--options.c28
-rw-r--r--options.h3
-rw-r--r--window.c24
-rw-r--r--window.h6
5 files changed, 32 insertions, 33 deletions
diff --git a/image.c b/image.c
index 8a99737..83bd4b1 100644
--- a/image.c
+++ b/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;
diff --git a/options.c b/options.c
index 1bcfbe1..3a76120 100644
--- a/options.c
+++ b/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;
}
diff --git a/options.h b/options.h
index 072c700..71a1b21 100644
--- a/options.h
+++ b/options.h
@@ -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;
diff --git a/window.c b/window.c
index 82d8396..2b3e266 100644
--- a/window.c
+++ b/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,
diff --git a/window.h b/window.h
index 52fd759..d9413e0 100644
--- a/window.h
+++ b/window.h
@@ -44,12 +44,12 @@ typedef struct win_s {
unsigned long bgcol;
Pixmap pm;
- int w;
- int h;
int x;
int y;
+ unsigned int w;
+ unsigned int h;
- int bw;
+ unsigned int bw;
unsigned char fullscreen;
} win_t;