summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Real <github@tildepipe.org>2013-02-14 17:02:16 +0100
committerDennis Real <github@tildepipe.org>2013-02-14 17:02:16 +0100
commit08faff479023efff6380061d81362073f679cd34 (patch)
treea462195afe9a6e2e2249f070c12ff6d1ff60d65c /src
parent353578ebc130f53547996ab87f5b3795c1360f3f (diff)
parent43a7d315ae6952e096ae3a0351273c5639377870 (diff)
Merge branch 'master' of git://github.com/derf/feh
Diffstat (limited to 'src')
-rw-r--r--src/events.c60
-rw-r--r--src/filelist.c39
-rw-r--r--src/imlib.c69
-rw-r--r--src/options.h2
-rw-r--r--src/winwidget.c17
5 files changed, 136 insertions, 51 deletions
diff --git a/src/events.c b/src/events.c
index dcd1aa1..fadae9b 100644
--- a/src/events.c
+++ b/src/events.c
@@ -152,6 +152,10 @@ void init_buttonbindings(void)
cur_bb = &buttons.blur;
else if (!strcmp(action, "rotate"))
cur_bb = &buttons.rotate;
+ else if (!strcmp(action, "zoom_in"))
+ cur_bb = &buttons.zoom_in;
+ else if (!strcmp(action, "zoom_out"))
+ cur_bb = &buttons.zoom_out;
else
weprintf("buttons: Invalid action: %s", action);
@@ -246,6 +250,62 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
winwid->im_click_offset_y = (winwid->click_offset_y
- winwid->im_y) / winwid->old_zoom;
+ } else if (feh_is_bb(&buttons.zoom_in, button, state)) {
+ D(("Zoom_In Button Press event\n"));
+ D(("click offset is %d,%d\n", ev->xbutton.x, ev->xbutton.y));
+ winwid->click_offset_x = ev->xbutton.x;
+ winwid->click_offset_y = ev->xbutton.y;
+ winwid->old_zoom = winwid->zoom;
+
+ /* required to adjust the image position in zoom mode */
+ winwid->im_click_offset_x = (winwid->click_offset_x
+ - winwid->im_x) / winwid->old_zoom;
+ winwid->im_click_offset_y = (winwid->click_offset_y
+ - winwid->im_y) / winwid->old_zoom;
+
+ /* copied from zoom_in, keyevents.c */
+ winwid->zoom = winwid->zoom * 1.25;
+
+ if (winwid->zoom > ZOOM_MAX)
+ winwid->zoom = ZOOM_MAX;
+
+ /* copied from below (ZOOM, feh_event_handle_MotionNotify) */
+ winwid->im_x = winwid->click_offset_x
+ - (winwid->im_click_offset_x * winwid->zoom);
+ winwid->im_y = winwid->click_offset_y
+ - (winwid->im_click_offset_y * winwid->zoom);
+
+ winwidget_sanitise_offsets(winwid);
+ winwidget_render_image(winwid, 0, 0);
+
+ } else if (feh_is_bb(&buttons.zoom_out, button, state)) {
+ D(("Zoom_Out Button Press event\n"));
+ D(("click offset is %d,%d\n", ev->xbutton.x, ev->xbutton.y));
+ winwid->click_offset_x = ev->xbutton.x;
+ winwid->click_offset_y = ev->xbutton.y;
+ winwid->old_zoom = winwid->zoom;
+
+ /* required to adjust the image position in zoom mode */
+ winwid->im_click_offset_x = (winwid->click_offset_x
+ - winwid->im_x) / winwid->old_zoom;
+ winwid->im_click_offset_y = (winwid->click_offset_y
+ - winwid->im_y) / winwid->old_zoom;
+
+ /* copied from zoom_out, keyevents.c */
+ winwid->zoom = winwid->zoom * 0.80;
+
+ if (winwid->zoom < ZOOM_MIN)
+ winwid->zoom = ZOOM_MIN;
+
+ /* copied from below (ZOOM, feh_event_handle_MotionNotify) */
+ winwid->im_x = winwid->click_offset_x
+ - (winwid->im_click_offset_x * winwid->zoom);
+ winwid->im_y = winwid->click_offset_y
+ - (winwid->im_click_offset_y * winwid->zoom);
+
+ winwidget_sanitise_offsets(winwid);
+ winwidget_render_image(winwid, 0, 0);
+
} else if (feh_is_bb(&buttons.reload, button, state)) {
D(("Reload Button Press event\n"));
feh_reload_image(winwid, 0, 1);
diff --git a/src/filelist.c b/src/filelist.c
index 3ea0928..bbde98c 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -155,6 +155,41 @@ static void feh_print_stat_error(char *path)
}
}
+static void add_stdin_to_filelist()
+{
+ char buf[1024];
+ size_t readsize;
+ char *sfn = estrjoin("_", "/tmp/feh_stdin", "XXXXXX", NULL);
+ int fd = mkstemp(sfn);
+ FILE *outfile;
+
+ if (fd == -1) {
+ free(sfn);
+ weprintf("cannot read from stdin: mktemp:");
+ return;
+ }
+
+ outfile = fdopen(fd, "w");
+
+ if (outfile == NULL) {
+ free(sfn);
+ weprintf("cannot read from stdin: fdopen:");
+ return;
+ }
+
+ while ((readsize = fread(buf, sizeof(char), sizeof(buf), stdin)) > 0) {
+ if (fwrite(buf, sizeof(char), readsize, outfile) < readsize) {
+ free(sfn);
+ return;
+ }
+ }
+ fclose(outfile);
+
+ filelist = gib_list_add_front(filelist, feh_file_new(sfn));
+ add_file_to_rm_filelist(sfn);
+ free(sfn);
+}
+
/* Recursive */
void add_file_to_filelist_recursively(char *origpath, unsigned char level)
@@ -186,8 +221,8 @@ void add_file_to_filelist_recursively(char *origpath, unsigned char level)
free(path);
return;
} else if ((len == 1) && (path[0] == '-')) {
- D(("Addig stdin (-) to filelist\n"));
- filelist = gib_list_add_front(filelist, feh_file_new(path));
+ D(("Adding temporary file for stdin (-) to filelist\n"));
+ add_stdin_to_filelist();
free(path);
return;
} else if (opt.filelistfile) {
diff --git a/src/imlib.c b/src/imlib.c
index bdf54ac..5514a34 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -61,7 +61,6 @@ int num_xinerama_screens;
int childpid = 0;
-static char *feh_stdin_load_image();
static char *feh_http_load_image(char *url);
static char *feh_magick_load_image(char *filename);
@@ -69,13 +68,32 @@ static char *feh_magick_load_image(char *filename);
void init_xinerama(void)
{
if (opt.xinerama && XineramaIsActive(disp)) {
- int major, minor;
+ int major, minor, px, py, i;
+
+ /* discarded */
+ Window dw;
+ int di;
+ unsigned int du;
+
+ XineramaQueryVersion(disp, &major, &minor);
+ xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens);
+
if (getenv("XINERAMA_SCREEN"))
xinerama_screen = atoi(getenv("XINERAMA_SCREEN"));
- else
+ else {
xinerama_screen = 0;
- XineramaQueryVersion(disp, &major, &minor);
- xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens);
+ XQueryPointer(disp, root, &dw, &dw, &px, &py, &di, &di, &du);
+ for (i = 0; i < num_xinerama_screens; i++) {
+ if (XY_IN_RECT(px, py,
+ xinerama_screens[i].x_org,
+ xinerama_screens[i].y_org,
+ xinerama_screens[i].width,
+ xinerama_screens[i].height)) {
+ xinerama_screen = i;
+ break;
+ }
+ }
+ }
}
}
#endif /* HAVE_LIBXINERAMA */
@@ -210,7 +228,7 @@ void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err)
int feh_load_image(Imlib_Image * im, feh_file * file)
{
Imlib_Load_Error err;
- enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK, SRC_STDIN } image_source =
+ enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK } image_source =
SRC_IMLIB;
char *tmpname = NULL;
char *real_filename = NULL;
@@ -225,11 +243,8 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
|| (!strncmp(file->filename, "ftp://", 6))) {
image_source = SRC_HTTP;
- tmpname = feh_http_load_image(file->filename);
- }
- if ((strlen(file->filename) == 1) && (file->filename[0] == '-')) {
- image_source = SRC_STDIN;
- tmpname = feh_stdin_load_image();
+ if ((tmpname = feh_http_load_image(file->filename)) == NULL)
+ err = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST;
}
else
*im = imlib_load_image_with_error_return(file->filename, &err);
@@ -275,38 +290,6 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
return(1);
}
-static char *feh_stdin_load_image()
-{
- char buf[1024];
- size_t readsize;
- char *sfn = estrjoin("_", "/tmp/feh_stdin", "XXXXXX", NULL);
- int fd = mkstemp(sfn);
- FILE *outfile;
-
- if (fd == -1) {
- free(sfn);
- return NULL;
- }
-
- outfile = fdopen(fd, "w");
-
- if (outfile == NULL) {
- free(sfn);
- return NULL;
- }
-
- while ((readsize = fread(buf, sizeof(char), sizeof(buf), stdin)) > 0) {
- if (fwrite(buf, sizeof(char), readsize, outfile) < readsize) {
- free(sfn);
- return NULL;
- }
- }
-
- fclose(outfile);
-
- return sfn;
-}
-
static char *feh_magick_load_image(char *filename)
{
char argv_fd[12];
diff --git a/src/options.h b/src/options.h
index f3f49eb..27d3d38 100644
--- a/src/options.h
+++ b/src/options.h
@@ -207,6 +207,8 @@ struct __fehbb {
struct __fehbutton menu;
struct __fehbutton blur;
struct __fehbutton rotate;
+ struct __fehbutton zoom_in;
+ struct __fehbutton zoom_out;
};
void init_parse_options(int argc, char **argv);
diff --git a/src/winwidget.c b/src/winwidget.c
index 2f543df..ada4c02 100644
--- a/src/winwidget.c
+++ b/src/winwidget.c
@@ -780,23 +780,28 @@ void winwidget_move(winwidget winwid, int x, int y)
void winwidget_resize(winwidget winwid, int w, int h)
{
- Window ignored_window;
XWindowAttributes attributes;
- int tc_x, tc_y;
+ int tc_x, tc_y, px, py;
int scr_width = scr->width;
int scr_height = scr->height;
+ /* discarded */
+ Window dw;
+ int di, i;
+ unsigned int du;
+
XGetWindowAttributes(disp, winwid->win, &attributes);
#ifdef HAVE_LIBXINERAMA
if (opt.xinerama && xinerama_screens) {
- int i;
xinerama_screen = 0;
+ XQueryPointer(disp, root, &dw, &dw, &px, &py, &di, &di, &du);
for (i = 0; i < num_xinerama_screens; i++) {
- if (XY_IN_RECT(attributes.x, attributes.y,
+ if (XY_IN_RECT(px, py,
xinerama_screens[i].x_org,
xinerama_screens[i].y_org,
- xinerama_screens[i].width, xinerama_screens[i].height)) {
+ xinerama_screens[i].width,
+ xinerama_screens[i].height)) {
xinerama_screen = i;
break;
}
@@ -828,7 +833,7 @@ void winwidget_resize(winwidget winwid, int w, int h)
XTranslateCoordinates(disp, winwid->win, attributes.root,
-attributes.border_width -
attributes.x,
- -attributes.border_width - attributes.y, &tc_x, &tc_y, &ignored_window);
+ -attributes.border_width - attributes.y, &tc_x, &tc_y, &dw);
winwid->x = tc_x;
winwid->y = tc_y;
XMoveResizeWindow(disp, winwid->win, tc_x, tc_y, winwid->w, winwid->h);