From e2ebaaa2cd997b553c772bafd082b5b2e69efeec Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 19 Jun 2010 20:53:38 +0200 Subject: Make and actually useful --- ChangeLog | 1 + src/events.c | 28 +--------------------------- src/keyevents.c | 2 ++ src/winwidget.c | 29 +++++++++++++++++++++++++++++ src/winwidget.h | 1 + 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ba3f6d..41abda2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ git HEAD * --font now sets the global default font (for action/filename display etc.) * Rename --screen-clip 0 to --no-screen-clip * Allow multiline theme definitions (via backslash, like in the shell) + * Center the image after pressing or Thu Jun 10 12:12:04 CEST 2010 diff --git a/src/events.c b/src/events.c index 7caa4d2..de2e3c0 100644 --- a/src/events.c +++ b/src/events.c @@ -61,7 +61,6 @@ void feh_event_init(void) static void feh_event_handle_ButtonPress(XEvent * ev) { winwidget winwid = NULL; - int scr_width, scr_height; /* get the heck out if it's a mouse-click on the cover, we'll hide the menus on release */ @@ -69,15 +68,6 @@ static void feh_event_handle_ButtonPress(XEvent * ev) return; } - scr_width = scr->width; - scr_height = scr->height; -#ifdef HAVE_LIBXINERAMA - if (opt.xinerama && xinerama_screens) { - scr_width = xinerama_screens[xinerama_screen].width; - scr_height = xinerama_screens[xinerama_screen].height; - } -#endif /* HAVE_LIBXINERAMA */ - winwid = winwidget_get_from_window(ev->xbutton.window); if (winwid && winwid->caption_entry) { return; @@ -132,23 +122,7 @@ static void feh_event_handle_ButtonPress(XEvent * ev) winwid->im_click_offset_y = (winwid->click_offset_y - winwid->im_y) / winwid->old_zoom; - /* center the image */ - if (winwid->full_screen) { - winwid->im_x = (scr_width - winwid->im_w) >> 1; - winwid->im_y = (scr_height - winwid->im_h) >> 1; - } else { - if (opt.geom_flags & WidthValue) { - winwid->im_x = (opt.geom_w - winwid->im_w) >> 1; - } else { - winwid->im_x = 0; - } - if (opt.geom_flags & HeightValue) { - winwid->im_y = (opt.geom_h - winwid->im_h) >> 1; - } else { - winwid->im_y = 0; - } - } - + winwidget_center_image(winwid); winwidget_render_image(winwid, 0, 0); } } else if (ev->xbutton.button == opt.reload_button) { diff --git a/src/keyevents.c b/src/keyevents.c index 67f5389..aa18d02 100644 --- a/src/keyevents.c +++ b/src/keyevents.c @@ -271,11 +271,13 @@ void feh_event_handle_keypress(XEvent * ev) case XK_KP_Multiply: len = 0; winwid->zoom = 1; + winwidget_center_image(winwid); winwidget_render_image(winwid, 0, 0); break; case XK_KP_Divide: len = 0; feh_calc_needed_zoom(&winwid->zoom, winwid->im_w, winwid->im_h, winwid->w, winwid->h); + winwidget_center_image(winwid); winwidget_render_image(winwid, 0, 1); break; case XK_KP_Begin: diff --git a/src/winwidget.c b/src/winwidget.c index e57be89..3172086 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -886,6 +886,35 @@ void winwidget_reset_image(winwidget winwid) return; } +void winwidget_center_image(winwidget winwid) +{ + int scr_width, scr_height; + + scr_width = scr->width; + scr_height = scr->height; + +#ifdef HAVE_LIBXINERAMA + if (opt.xinerama && xinerama_screens) { + scr_width = xinerama_screens[xinerama_screen].width; + scr_height = xinerama_screens[xinerama_screen].height; + } +#endif /* HAVE_LIBXINERAMA */ + + if (winwid->full_screen) { + winwid->im_x = (scr_width - lround(winwid->im_w * winwid->zoom)) >> 1; + winwid->im_y = (scr_height - lround(winwid->im_h * winwid->zoom)) >> 1; + } else { + if (opt.geom_flags & WidthValue) + winwid->im_x = (opt.geom_w - lround(winwid->im_w * winwid->zoom)) >> 1; + else + winwid->im_x = 0; + if (opt.geom_flags & HeightValue) + winwid->im_y = (opt.geom_h - lround(winwid->im_h * winwid->zoom)) >> 1; + else + winwid->im_y = 0; + } +} + void winwidget_sanitise_offsets(winwidget winwid) { int far_left, far_top; diff --git a/src/winwidget.h b/src/winwidget.h index 37e0624..a856475 100644 --- a/src/winwidget.h +++ b/src/winwidget.h @@ -121,6 +121,7 @@ void winwidget_show_menu(winwidget winwid); void winwidget_hide(winwidget winwid); void winwidget_destroy_all(void); void winwidget_free_image(winwidget w); +void winwidget_center_image(winwidget w); void winwidget_render_image(winwidget winwid, int resize, int alias); void winwidget_rotate_image(winwidget winid, double angle); void winwidget_move(winwidget winwid, int x, int y); -- cgit v1.2.3