Sort headers using clang-tidy
[geeqie.git] / src / image.cc
index cf2754f..5cd517b 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "image.h"
 
+#include <config.h>
+
 #include "collect-table.h"
 #include "color-man.h"
+#include "compat.h"
+#include "debug.h"
 #include "exif.h"
-#include "metadata.h"
+#include "filecache.h"
 #include "history-list.h"
 #include "image-load.h"
-#include "layout.h"
+#include "intl.h"
 #include "layout-image.h"
+#include "layout.h"
+#include "metadata.h"
 #include "pixbuf-renderer.h"
 #include "pixbuf-util.h"
 #include "ui-fileops.h"
-#include "filecache.h"
+#include "ui-misc.h"
 
-#include <math.h>
+#include <cmath>
 
-static GList *image_list = NULL;
+static GList *image_list = nullptr;
 
-void image_update_title(ImageWindow *imd);
 static void image_read_ahead_start(ImageWindow *imd);
 static void image_cache_set(ImageWindow *imd, FileData *fd);
 
@@ -57,9 +61,9 @@ static gint rect_id = 0;
  *-------------------------------------------------------------------
  */
 
-static void image_click_cb(PixbufRenderer *UNUSED(pr), GdkEventButton *event, gpointer data)
+static void image_click_cb(PixbufRenderer *, GdkEventButton *event, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
        if (!options->image_lm_click_nav && event->button == MOUSE_BUTTON_MIDDLE)
                {
                imd->mouse_wheel_mode = !imd->mouse_wheel_mode;
@@ -139,9 +143,10 @@ static void switch_coords_orientation(ImageWindow *imd, gint x, gint y, gint wid
 
 static void image_press_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
        LayoutWindow *lw;
-       gint x_pixel, y_pixel;
+       gint x_pixel;
+       gint y_pixel;
 
        if(options->draw_rectangle)
                {
@@ -171,27 +176,48 @@ static void image_press_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer d
 
        if (rect_id)
                {
-               pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, rect_id);
+               pixbuf_renderer_overlay_remove(reinterpret_cast<PixbufRenderer *>(imd->pr), rect_id);
                }
 
        lw = layout_find_by_image(imd);
+       if (!lw)
+               {
+               layout_valid(&lw);
+               }
+
        if (lw && event->button == MOUSE_BUTTON_LEFT && event->type == GDK_2BUTTON_PRESS
                                                                                                && !options->image_lm_click_nav)
                {
-               if (lw->full_screen)
-                       layout_image_full_screen_stop(lw);
+               layout_image_full_screen_toggle(lw);
                }
 }
 
+static void image_release_cb(PixbufRenderer *, GdkEventButton *event, gpointer data)
+{
+       auto imd = static_cast<ImageWindow *>(data);
+       LayoutWindow *lw;
+
+       lw = layout_find_by_image(imd);
+       if (!lw)
+               {
+               layout_valid(&lw);
+               }
+
+       defined_mouse_buttons(nullptr, event, lw);
+}
+
 static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer data)
 {
-       ImageWindow *imd = data;
-       gint width, height;
+       auto imd = static_cast<ImageWindow *>(data);
+       gint width;
+       gint height;
        gint rect_width;
        gint rect_height;
        GdkPixbuf *rect_pixbuf;
-       gint x_pixel, y_pixel;
-       gint image_x_pixel, image_y_pixel;
+       gint x_pixel;
+       gint y_pixel;
+       gint image_x_pixel;
+       gint image_y_pixel;
 
        if (options->draw_rectangle)
                {
@@ -219,7 +245,7 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer da
                switch_coords_orientation(imd, image_x_pixel, image_y_pixel, width, height);
                if (rect_id)
                        {
-                       pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, rect_id);
+                       pixbuf_renderer_overlay_remove(reinterpret_cast<PixbufRenderer *>(imd->pr), rect_id);
                        }
 
                rect_width = pr->drag_last_x - pixbuf_start_x;
@@ -238,7 +264,7 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer da
                pixbuf_set_rect(rect_pixbuf, 1, 1, rect_width-2, rect_height - 2, 0, 0, 0, 255, 1, 1, 1, 1);
                pixbuf_set_rect(rect_pixbuf, 2, 2, rect_width-4, rect_height - 4, 255, 255, 255, 255, 1, 1, 1, 1);
 
-               rect_id = pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, rect_pixbuf, pixbuf_start_x, pixbuf_start_y, OVL_NORMAL);
+               rect_id = pixbuf_renderer_overlay_add(reinterpret_cast<PixbufRenderer *>(imd->pr), rect_pixbuf, pixbuf_start_x, pixbuf_start_y, OVL_NORMAL);
                }
 
        pixbuf_renderer_get_scaled_size(pr, &width, &height);
@@ -246,23 +272,23 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer da
        if (imd->func_drag)
                {
                imd->func_drag(imd, event,
-                              (gfloat)(pr->drag_last_x - event->x) / width,
-                              (gfloat)(pr->drag_last_y - event->y) / height,
+                              static_cast<gfloat>(pr->drag_last_x - event->x) / width,
+                              static_cast<gfloat>(pr->drag_last_y - event->y) / height,
                               imd->data_button);
                }
 }
 
 static void image_scroll_notify_cb(PixbufRenderer *pr, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        if (imd->func_scroll_notify && pr->scale)
                {
                imd->func_scroll_notify(imd,
-                                       (gint)((gdouble)pr->x_scroll / pr->scale),
-                                       (gint)((gdouble)pr->y_scroll / pr->scale),
-                                       (gint)((gdouble)pr->image_width - pr->vis_width / pr->scale),
-                                       (gint)((gdouble)pr->image_height - pr->vis_height / pr->scale),
+                                       static_cast<gint>(static_cast<gdouble>(pr->x_scroll) / pr->scale),
+                                       static_cast<gint>(static_cast<gdouble>(pr->y_scroll) / pr->scale),
+                                       static_cast<gint>(static_cast<gdouble>(pr->image_width) - pr->vis_width / pr->scale),
+                                       static_cast<gint>(static_cast<gdouble>(pr->image_height) - pr->vis_height / pr->scale),
                                        imd->data_scroll_notify);
                }
 }
@@ -286,9 +312,9 @@ static void image_complete_util(ImageWindow *imd, gboolean preload)
        if (imd->func_complete) imd->func_complete(imd, preload, imd->data_complete);
 }
 
-static void image_render_complete_cb(PixbufRenderer *UNUSED(pr), gpointer data)
+static void image_render_complete_cb(PixbufRenderer *, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        image_complete_util(imd, FALSE);
 }
@@ -301,20 +327,20 @@ static void image_state_set(ImageWindow *imd, ImageState state)
                }
        else
                {
-               imd->state |= state;
+               imd->state = static_cast<ImageState>(imd->state | state);
                }
        if (imd->func_state) imd->func_state(imd, state, imd->data_state);
 }
 
 static void image_state_unset(ImageWindow *imd, ImageState state)
 {
-       imd->state &= ~state;
+       imd->state = static_cast<ImageState>(imd->state & ~state);
        if (imd->func_state) imd->func_state(imd, state, imd->data_state);
 }
 
-static void image_zoom_cb(PixbufRenderer *UNUSED(pr), gdouble UNUSED(zoom), gpointer data)
+static void image_zoom_cb(PixbufRenderer *, gdouble, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        if (imd->title_show_zoom) image_update_title(imd);
        image_state_set(imd, IMAGE_STATE_IMAGE);
@@ -329,11 +355,11 @@ static void image_zoom_cb(PixbufRenderer *UNUSED(pr), gdouble UNUSED(zoom), gpoi
 
 void image_update_title(ImageWindow *imd)
 {
-       gchar *title = NULL;
-       gchar *zoom = NULL;
-       gchar *collection = NULL;
+       gchar *title = nullptr;
+       gchar *zoom = nullptr;
+       gchar *collection = nullptr;
        LayoutWindow *lw;
-       gchar *lw_ident = NULL;
+       gchar *lw_ident = nullptr;
 
        if (!imd->top_window) return;
 
@@ -401,11 +427,11 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
        ColorMan *cm;
        ColorManProfileType input_type;
        ColorManProfileType screen_type;
-       const gchar *input_file = NULL;
-       const gchar *screen_file = NULL;
-       guchar *profile = NULL;
+       const gchar *input_file = nullptr;
+       const gchar *screen_file = nullptr;
+       guchar *profile = nullptr;
        guint profile_len;
-       guchar *screen_profile = NULL;
+       guchar *screen_profile = nullptr;
        gint screen_profile_len;
        ExifData *exif;
 
@@ -424,8 +450,8 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
        else if (imd->color_profile_input >= COLOR_PROFILE_SRGB &&
                 imd->color_profile_input <  COLOR_PROFILE_FILE)
                {
-               input_type = imd->color_profile_input;
-               input_file = NULL;
+               input_type = static_cast<ColorManProfileType>(imd->color_profile_input);
+               input_file = nullptr;
                }
        else
                {
@@ -447,7 +473,7 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
        else
                {
                screen_type = COLOR_PROFILE_SRGB;
-               screen_file = NULL;
+               screen_file = nullptr;
                }
 
 
@@ -472,7 +498,7 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
                        if (!imd->color_profile_use_image)
                                {
                                g_free(profile);
-                               profile = NULL;
+                               profile = nullptr;
                                }
                        DEBUG_1("Found embedded color profile");
                        imd->color_profile_from_image = COLOR_PROFILE_MEM;
@@ -517,8 +543,8 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
 
                        if (imd->color_profile_use_image && imd->color_profile_from_image != COLOR_PROFILE_NONE)
                                {
-                               input_type = imd->color_profile_from_image;
-                               input_file = NULL;
+                               input_type = static_cast<ColorManProfileType>(imd->color_profile_from_image);
+                               input_file = nullptr;
                                }
                        }
 
@@ -528,14 +554,14 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
 
        if (profile)
                {
-               cm = color_man_new_embedded(run_in_bg ? imd : NULL, NULL,
+               cm = color_man_new_embedded(run_in_bg ? imd : nullptr, nullptr,
                                            profile, profile_len,
                                            screen_type, screen_file, screen_profile, screen_profile_len);
                g_free(profile);
                }
        else
                {
-               cm = color_man_new(run_in_bg ? imd : NULL, NULL,
+               cm = color_man_new(run_in_bg ? imd : nullptr, nullptr,
                                   input_type, input_file,
                                   screen_type, screen_file, screen_profile, screen_profile_len);
                }
@@ -548,7 +574,7 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
                        cm->incremental_sync = TRUE;
                        }
 
-               imd->cm = (gpointer)cm;
+               imd->cm = cm;
                }
 
        image_update_util(imd);
@@ -556,17 +582,17 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
        if (screen_profile)
                {
                g_free(screen_profile);
-               screen_profile = NULL;
+               screen_profile = nullptr;
                }
 
        return !!cm;
 }
 
 
-static void image_post_process_tile_color_cb(PixbufRenderer *UNUSED(pr), GdkPixbuf **pixbuf, gint x, gint y, gint w, gint h, gpointer data)
+static void image_post_process_tile_color_cb(PixbufRenderer *, GdkPixbuf **pixbuf, gint x, gint y, gint w, gint h, gpointer data)
 {
-       ImageWindow *imd = (ImageWindow *)data;
-       if (imd->cm) color_man_correct_region(imd->cm, *pixbuf, x, y, w, h);
+       auto imd = static_cast<ImageWindow *>(data);
+       if (imd->cm) color_man_correct_region(static_cast<ColorMan *>(imd->cm), *pixbuf, x, y, w, h);
        if (imd->desaturate) pixbuf_desaturate_rect(*pixbuf, x, y, w, h);
        if (imd->overunderexposed) pixbuf_highlight_overunderexposed(*pixbuf, x, y, w, h);
 }
@@ -670,10 +696,10 @@ void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
                        }
                }
 
-       if (imd->image_fd == fd_n && !(options->metadata.write_orientation && !options->image.exif_rotate_enable))
+       if (imd->image_fd == fd_n && (!options->metadata.write_orientation || options->image.exif_rotate_enable))
                {
                imd->orientation = orientation;
-               pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, orientation);
+               pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), orientation);
                }
 }
 
@@ -681,10 +707,10 @@ void image_set_desaturate(ImageWindow *imd, gboolean desaturate)
 {
        imd->desaturate = desaturate;
        if (imd->cm || imd->desaturate || imd->overunderexposed)
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), image_post_process_tile_color_cb, imd, (imd->cm != nullptr) );
        else
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
-       pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), nullptr, nullptr, TRUE);
+       pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
 }
 
 gboolean image_get_desaturate(ImageWindow *imd)
@@ -696,20 +722,15 @@ void image_set_overunderexposed(ImageWindow *imd, gboolean overunderexposed)
 {
        imd->overunderexposed = overunderexposed;
        if (imd->cm || imd->desaturate || imd->overunderexposed)
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), image_post_process_tile_color_cb, imd, (imd->cm != nullptr) );
        else
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
-       pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
-}
-
-gboolean image_get_overunderexposed(ImageWindow *imd)
-{
-       return imd->overunderexposed;
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), nullptr, nullptr, TRUE);
+       pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
 }
 
 void image_set_ignore_alpha(ImageWindow *imd, gboolean ignore_alpha)
 {
-   pixbuf_renderer_set_ignore_alpha((PixbufRenderer *)imd->pr, ignore_alpha);
+   pixbuf_renderer_set_ignore_alpha(reinterpret_cast<PixbufRenderer *>(imd->pr), ignore_alpha);
 }
 
 /*
@@ -723,15 +744,15 @@ static void image_read_ahead_cancel(ImageWindow *imd)
        DEBUG_1("%s read ahead cancelled for :%s", get_exec_time(), imd->read_ahead_fd ? imd->read_ahead_fd->path : "null");
 
        image_loader_free(imd->read_ahead_il);
-       imd->read_ahead_il = NULL;
+       imd->read_ahead_il = nullptr;
 
        file_data_unref(imd->read_ahead_fd);
-       imd->read_ahead_fd = NULL;
+       imd->read_ahead_fd = nullptr;
 }
 
-static void image_read_ahead_done_cb(ImageLoader *UNUSED(il), gpointer data)
+static void image_read_ahead_done_cb(ImageLoader *, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        if (!imd->read_ahead_fd || !imd->read_ahead_il) return;
 
@@ -747,7 +768,7 @@ static void image_read_ahead_done_cb(ImageLoader *UNUSED(il), gpointer data)
                        }
                }
        image_loader_free(imd->read_ahead_il);
-       imd->read_ahead_il = NULL;
+       imd->read_ahead_il = nullptr;
 
        image_complete_util(imd, TRUE);
 }
@@ -804,22 +825,22 @@ static void image_read_ahead_set(ImageWindow *imd, FileData *fd)
 static void image_cache_release_cb(FileData *fd)
 {
        g_object_unref(fd->pixbuf);
-       fd->pixbuf = NULL;
+       fd->pixbuf = nullptr;
 }
 
-static FileCacheData *image_get_cache(void)
+static FileCacheData *image_get_cache()
 {
-       static FileCacheData *cache = NULL;
+       static FileCacheData *cache = nullptr;
        if (!cache) cache = file_cache_new(image_cache_release_cb, 1);
-       file_cache_set_max_size(cache, (gulong)options->image.image_cache_max * 1048576); /* update from options */
+       file_cache_set_max_size(cache, static_cast<gulong>(options->image.image_cache_max) * 1048576); /* update from options */
        return cache;
 }
 
-static void image_cache_set(ImageWindow *UNUSED(imd), FileData *fd)
+static void image_cache_set(ImageWindow *, FileData *fd)
 {
        g_assert(fd->pixbuf);
 
-       file_cache_put(image_get_cache(), fd, (gulong)gdk_pixbuf_get_rowstride(fd->pixbuf) * (gulong)gdk_pixbuf_get_height(fd->pixbuf));
+       file_cache_put(image_get_cache(), fd, static_cast<gulong>(gdk_pixbuf_get_rowstride(fd->pixbuf)) * static_cast<gulong>(gdk_pixbuf_get_height(fd->pixbuf)));
        file_data_send_notification(fd, NOTIFY_PIXBUF); /* to update histogram */
 }
 
@@ -834,7 +855,6 @@ static gint image_cache_get(ImageWindow *imd)
                image_change_pixbuf(imd, imd->image_fd->pixbuf, image_zoom_get(imd), FALSE);
                }
 
-//     file_cache_dump(image_get_cache());
        return success;
 }
 
@@ -853,10 +873,10 @@ static void image_load_pixbuf_ready(ImageWindow *imd)
 
 static void image_load_area_cb(ImageLoader *il, guint x, guint y, guint w, guint h, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
        PixbufRenderer *pr;
 
-       pr = (PixbufRenderer *)imd->pr;
+       pr = reinterpret_cast<PixbufRenderer *>(imd->pr);
 
        if (imd->delay_flip &&
            pr->pixbuf != image_loader_get_pixbuf(il))
@@ -869,15 +889,15 @@ static void image_load_area_cb(ImageLoader *il, guint x, guint y, guint w, guint
        pixbuf_renderer_area_changed(pr, x, y, w, h);
 }
 
-static void image_load_done_cb(ImageLoader *UNUSED(il), gpointer data)
+static void image_load_done_cb(ImageLoader *, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        DEBUG_1("%s image done", get_exec_time());
 
        if (options->image.enable_read_ahead && imd->image_fd && !imd->image_fd->pixbuf && image_loader_get_pixbuf(imd->il))
                {
-               imd->image_fd->pixbuf = g_object_ref(image_loader_get_pixbuf(imd->il));
+               imd->image_fd->pixbuf = static_cast<GdkPixbuf*>(g_object_ref(image_loader_get_pixbuf(imd->il)));
                image_cache_set(imd, imd->image_fd);
                }
        /* call the callback triggered by image_state after fd->pixbuf is set */
@@ -886,31 +906,7 @@ static void image_load_done_cb(ImageLoader *UNUSED(il), gpointer data)
 
        if (!image_loader_get_pixbuf(imd->il))
                {
-               GdkPixbuf *pixbuf;
-
-               switch (imd->image_fd->format_class)
-                       {
-                       case FORMAT_CLASS_UNKNOWN:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_UNKNOWN);
-                               break;
-                       case FORMAT_CLASS_META:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_METADATA);
-                               break;
-                       case FORMAT_CLASS_VIDEO:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_VIDEO);
-                               break;
-                       case FORMAT_CLASS_COLLECTION:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_COLLECTION);
-                               break;
-                       case FORMAT_CLASS_DOCUMENT:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_PDF);
-                               break;
-                       case FORMAT_CLASS_ARCHIVE:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_ARCHIVE);
-                               break;
-                       default:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
-                       }
+               GdkPixbuf *pixbuf = pixbuf_fallback(imd->image_fd, 0, 0);
 
                image_change_pixbuf(imd, pixbuf, image_zoom_get(imd), FALSE);
                g_object_unref(pixbuf);
@@ -925,19 +921,17 @@ static void image_load_done_cb(ImageLoader *UNUSED(il), gpointer data)
                }
 
        image_loader_free(imd->il);
-       imd->il = NULL;
-
-//     image_post_process(imd, TRUE);
+       imd->il = nullptr;
 
        image_read_ahead_start(imd);
 }
 
-static void image_load_size_cb(ImageLoader *UNUSED(il), guint width, guint height, gpointer data)
+static void image_load_size_cb(ImageLoader *, guint width, guint height, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        DEBUG_1("image_load_size_cb: %dx%d", width, height);
-       pixbuf_renderer_set_size_early((PixbufRenderer *)imd->pr, width, height);
+       pixbuf_renderer_set_size_early(reinterpret_cast<PixbufRenderer *>(imd->pr), width, height);
 }
 
 static void image_load_error_cb(ImageLoader *il, gpointer data)
@@ -956,7 +950,7 @@ static void image_load_set_signals(ImageWindow *imd, gboolean override_old_signa
        if (override_old_signals)
                {
                /* override the old signals */
-               g_signal_handlers_disconnect_matched(G_OBJECT(imd->il), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, imd);
+               g_signal_handlers_disconnect_matched(G_OBJECT(imd->il), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, imd);
                }
 
        g_signal_connect(G_OBJECT(imd->il), "area_ready", (GCallback)image_load_area_cb, imd);
@@ -981,7 +975,7 @@ static gboolean image_read_ahead_check(ImageWindow *imd)
        if (imd->read_ahead_il)
                {
                imd->il = imd->read_ahead_il;
-               imd->read_ahead_il = NULL;
+               imd->read_ahead_il = nullptr;
 
                image_load_set_signals(imd, TRUE);
 
@@ -996,17 +990,16 @@ static gboolean image_read_ahead_check(ImageWindow *imd)
                image_loader_delay_area_ready(imd->il, FALSE); /* send the delayed area_ready signals */
 
                file_data_unref(imd->read_ahead_fd);
-               imd->read_ahead_fd = NULL;
+               imd->read_ahead_fd = nullptr;
                return TRUE;
                }
-       else if (imd->read_ahead_fd->pixbuf)
+       if (imd->read_ahead_fd->pixbuf)
                {
                image_change_pixbuf(imd, imd->read_ahead_fd->pixbuf, image_zoom_get(imd), FALSE);
 
                file_data_unref(imd->read_ahead_fd);
-               imd->read_ahead_fd = NULL;
+               imd->read_ahead_fd = nullptr;
 
-//             image_post_process(imd, FALSE);
                return TRUE;
                }
 
@@ -1041,7 +1034,7 @@ static gboolean image_load_begin(ImageWindow *imd, FileData *fd)
 
                pr = PIXBUF_RENDERER(imd->pr);
                if (pr->pixbuf) g_object_unref(pr->pixbuf);
-               pr->pixbuf = NULL;
+               pr->pixbuf = nullptr;
                }
 
        g_object_set(G_OBJECT(imd->pr), "loading", TRUE, NULL);
@@ -1057,7 +1050,7 @@ static gboolean image_load_begin(ImageWindow *imd, FileData *fd)
                g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL);
 
                image_loader_free(imd->il);
-               imd->il = NULL;
+               imd->il = nullptr;
 
                image_complete_util(imd, FALSE);
 
@@ -1084,10 +1077,10 @@ static void image_reset(ImageWindow *imd)
        g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL);
 
        image_loader_free(imd->il);
-       imd->il = NULL;
+       imd->il = nullptr;
 
-       color_man_free((ColorMan *)imd->cm);
-       imd->cm = NULL;
+       color_man_free(static_cast<ColorMan *>(imd->cm));
+       imd->cm = nullptr;
 
        imd->delay_alter_type = ALTER_NONE;
 
@@ -1111,7 +1104,7 @@ static void image_change_complete(ImageWindow *imd, gdouble zoom)
 
        if (!imd->image_fd)
                {
-               image_change_pixbuf(imd, NULL, zoom, FALSE);
+               image_change_pixbuf(imd, nullptr, zoom, FALSE);
                }
        else
                {
@@ -1180,9 +1173,9 @@ static void image_change_real(ImageWindow *imd, FileData *fd,
  *-------------------------------------------------------------------
  */
 
-static gboolean image_focus_in_cb(GtkWidget *UNUSED(widget), GdkEventFocus *UNUSED(event), gpointer data)
+static gboolean image_focus_in_cb(GtkWidget *, GdkEventFocus *, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        if (imd->func_focus_in)
                {
@@ -1192,12 +1185,12 @@ static gboolean image_focus_in_cb(GtkWidget *UNUSED(widget), GdkEventFocus *UNUS
        return TRUE;
 }
 
-static gboolean image_scroll_cb(GtkWidget *UNUSED(widget), GdkEventScroll *event, gpointer data)
+static gboolean image_scroll_cb(GtkWidget *, GdkEventScroll *event, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
        gboolean in_lw = FALSE;
        gint i = 0;
-       LayoutWindow *lw = NULL;
+       LayoutWindow *lw = nullptr;
 
        if (imd->func_scroll && event && event->type == GDK_SCROLL)
                {
@@ -1231,11 +1224,9 @@ static gboolean image_scroll_cb(GtkWidget *UNUSED(widget), GdkEventScroll *event
                                }
                        return TRUE;
                        }
-               else
-                       {
-                       imd->func_scroll(imd, event, imd->data_scroll);
-                       return TRUE;
-                       }
+
+               imd->func_scroll(imd, event, imd->data_scroll);
+               return TRUE;
                }
 
        return FALSE;
@@ -1261,9 +1252,9 @@ void image_attach_window(ImageWindow *imd, GtkWidget *window,
 
        lw = layout_find_by_image(imd);
 
-       if (!(options->image.fit_window_to_image && lw && (lw->options.tools_float || lw->options.tools_hidden))) window = NULL;
+       if (!(options->image.fit_window_to_image && lw && (lw->options.tools_float || lw->options.tools_hidden))) window = nullptr;
 
-       pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)window);
+       pixbuf_renderer_set_parent(reinterpret_cast<PixbufRenderer *>(imd->pr), reinterpret_cast<GtkWindow *>(window));
 
        image_update_title(imd);
 }
@@ -1317,13 +1308,16 @@ void image_set_scroll_func(ImageWindow *imd,
        imd->data_scroll = data;
 }
 
-//void image_set_scroll_notify_func(ImageWindow *imd,
-                                 //void (*func)(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data),
-                                 //gpointer data)
-//{
-       //imd->func_scroll_notify = func;
-       //imd->data_scroll_notify = data;
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void image_set_scroll_notify_func_unused(ImageWindow *imd,
+                                 void (*func)(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data),
+                                 gpointer data)
+{
+       imd->func_scroll_notify = func;
+       imd->data_scroll_notify = data;
+}
+#pragma GCC diagnostic pop
 
 void image_set_focus_in_func(ImageWindow *imd,
                           void (*func)(ImageWindow *, gpointer),
@@ -1337,13 +1331,13 @@ void image_set_focus_in_func(ImageWindow *imd,
 
 const gchar *image_get_path(ImageWindow *imd)
 {
-       if (imd->image_fd == NULL) return NULL;
+       if (imd->image_fd == nullptr) return nullptr;
        return imd->image_fd->path;
 }
 
 const gchar *image_get_name(ImageWindow *imd)
 {
-       if (imd->image_fd == NULL) return NULL;
+       if (imd->image_fd == nullptr) return nullptr;
        return imd->image_fd->name;
 }
 
@@ -1374,7 +1368,7 @@ void image_change_fd(ImageWindow *imd, FileData *fd, gdouble zoom)
 {
        if (imd->image_fd == fd) return;
 
-       image_change_real(imd, fd, NULL, NULL, zoom);
+       image_change_real(imd, fd, nullptr, nullptr, zoom);
 }
 
 gboolean image_get_image_size(ImageWindow *imd, gint *width, gint *height)
@@ -1384,7 +1378,7 @@ gboolean image_get_image_size(ImageWindow *imd, gint *width, gint *height)
 
 GdkPixbuf *image_get_pixbuf(ImageWindow *imd)
 {
-       return pixbuf_renderer_get_pixbuf((PixbufRenderer *)imd->pr);
+       return pixbuf_renderer_get_pixbuf(reinterpret_cast<PixbufRenderer *>(imd->pr));
 }
 
 void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboolean lazy)
@@ -1420,29 +1414,29 @@ void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboo
 
        if (pixbuf)
                {
-               stereo_data = imd->user_stereo;
+               stereo_data = static_cast<StereoPixbufData>(imd->user_stereo);
                if (stereo_data == STEREO_PIXBUF_DEFAULT)
                        {
-                       stereo_data = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(pixbuf), "stereo_data"));
+                       stereo_data = static_cast<StereoPixbufData>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(pixbuf), "stereo_data")));
                        }
                }
 
-       pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, FALSE);
+       pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), nullptr, nullptr, FALSE);
        if (imd->cm)
                {
-               color_man_free(imd->cm);
-               imd->cm = NULL;
+               color_man_free(static_cast<ColorMan *>(imd->cm));
+               imd->cm = nullptr;
                }
 
        if (lazy)
                {
-               pixbuf_renderer_set_pixbuf_lazy((PixbufRenderer *)imd->pr, pixbuf, zoom, imd->orientation, stereo_data);
+               pixbuf_renderer_set_pixbuf_lazy(reinterpret_cast<PixbufRenderer *>(imd->pr), pixbuf, zoom, imd->orientation, stereo_data);
                }
        else
                {
-               pixbuf_renderer_set_pixbuf((PixbufRenderer *)imd->pr, pixbuf, zoom);
-               pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
-               pixbuf_renderer_set_stereo_data((PixbufRenderer *)imd->pr, stereo_data);
+               pixbuf_renderer_set_pixbuf(reinterpret_cast<PixbufRenderer *>(imd->pr), pixbuf, zoom);
+               pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
+               pixbuf_renderer_set_stereo_data(reinterpret_cast<PixbufRenderer *>(imd->pr), stereo_data);
                }
 
        if (pixbuf) g_object_unref(pixbuf);
@@ -1455,7 +1449,7 @@ void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboo
                }
 
        if (imd->cm || imd->desaturate || imd->overunderexposed)
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), image_post_process_tile_color_cb, imd, (imd->cm != nullptr) );
 
        image_state_set(imd, IMAGE_STATE_IMAGE);
 }
@@ -1485,19 +1479,19 @@ CollectionData *image_get_collection(ImageWindow *imd, CollectInfo **info)
 {
        if (collection_to_number(imd->collection) >= 0)
                {
-               if (g_list_find(imd->collection->list, imd->collection_info) != NULL)
+               if (g_list_find(imd->collection->list, imd->collection_info) != nullptr)
                        {
                        if (info) *info = imd->collection_info;
                        }
                else
                        {
-                       if (info) *info = NULL;
+                       if (info) *info = nullptr;
                        }
                return imd->collection;
                }
 
-       if (info) *info = NULL;
-       return NULL;
+       if (info) *info = nullptr;
+       return nullptr;
 }
 
 static void image_loader_sync_read_ahead_data(ImageLoader *il, gpointer old_data, gpointer data)
@@ -1534,7 +1528,7 @@ void image_move_from_image(ImageWindow *imd, ImageWindow *source)
        imd->collection_info = source->collection_info;
 
        image_loader_free(imd->il);
-       imd->il = NULL;
+       imd->il = nullptr;
 
        image_set_fd(imd, image_get_fd(source));
 
@@ -1542,7 +1536,7 @@ void image_move_from_image(ImageWindow *imd, ImageWindow *source)
        if (source->il)
                {
                imd->il = source->il;
-               source->il = NULL;
+               source->il = nullptr;
 
                image_loader_sync_data(imd->il, source, imd);
 
@@ -1553,22 +1547,22 @@ void image_move_from_image(ImageWindow *imd, ImageWindow *source)
        imd->color_profile_enable = source->color_profile_enable;
        imd->color_profile_input = source->color_profile_input;
        imd->color_profile_use_image = source->color_profile_use_image;
-       color_man_free((ColorMan *)imd->cm);
-       imd->cm = NULL;
+       color_man_free(static_cast<ColorMan *>(imd->cm));
+       imd->cm = nullptr;
        if (source->cm)
                {
                ColorMan *cm;
 
                imd->cm = source->cm;
-               source->cm = NULL;
+               source->cm = nullptr;
 
-               cm = (ColorMan *)imd->cm;
+               cm = static_cast<ColorMan *>(imd->cm);
                cm->imd = imd;
                cm->func_done_data = imd;
                }
 
        file_data_unref(imd->read_ahead_fd);
-       source->read_ahead_fd = NULL;
+       source->read_ahead_fd = nullptr;
 
        imd->orientation = source->orientation;
        imd->desaturate = source->desaturate;
@@ -1578,9 +1572,9 @@ void image_move_from_image(ImageWindow *imd, ImageWindow *source)
        pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr));
 
        if (imd->cm || imd->desaturate || imd->overunderexposed)
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), image_post_process_tile_color_cb, imd, (imd->cm != nullptr) );
        else
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), nullptr, nullptr, TRUE);
 
 }
 
@@ -1597,7 +1591,7 @@ void image_copy_from_image(ImageWindow *imd, ImageWindow *source)
        imd->collection_info = source->collection_info;
 
        image_loader_free(imd->il);
-       imd->il = NULL;
+       imd->il = nullptr;
 
        image_set_fd(imd, image_get_fd(source));
 
@@ -1605,28 +1599,28 @@ void image_copy_from_image(ImageWindow *imd, ImageWindow *source)
        imd->color_profile_enable = source->color_profile_enable;
        imd->color_profile_input = source->color_profile_input;
        imd->color_profile_use_image = source->color_profile_use_image;
-       color_man_free((ColorMan *)imd->cm);
-       imd->cm = NULL;
+       color_man_free(static_cast<ColorMan *>(imd->cm));
+       imd->cm = nullptr;
        if (source->cm)
                {
                ColorMan *cm;
 
                imd->cm = source->cm;
-               source->cm = NULL;
+               source->cm = nullptr;
 
-               cm = (ColorMan *)imd->cm;
+               cm = static_cast<ColorMan *>(imd->cm);
                cm->imd = imd;
                cm->func_done_data = imd;
                }
 
        image_loader_free(imd->read_ahead_il);
        imd->read_ahead_il = source->read_ahead_il;
-       source->read_ahead_il = NULL;
+       source->read_ahead_il = nullptr;
        if (imd->read_ahead_il) image_loader_sync_read_ahead_data(imd->read_ahead_il, source, imd);
 
        file_data_unref(imd->read_ahead_fd);
        imd->read_ahead_fd = source->read_ahead_fd;
-       source->read_ahead_fd = NULL;
+       source->read_ahead_fd = nullptr;
 
        imd->completed = source->completed;
        imd->state = source->state;
@@ -1640,9 +1634,9 @@ void image_copy_from_image(ImageWindow *imd, ImageWindow *source)
        pixbuf_renderer_copy(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr));
 
        if (imd->cm || imd->desaturate || imd->overunderexposed)
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), image_post_process_tile_color_cb, imd, (imd->cm != nullptr) );
        else
-               pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
+               pixbuf_renderer_set_post_process_func(reinterpret_cast<PixbufRenderer *>(imd->pr), nullptr, nullptr, TRUE);
 
 }
 
@@ -1651,25 +1645,25 @@ void image_copy_from_image(ImageWindow *imd, ImageWindow *source)
 
 void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height)
 {
-       pixbuf_renderer_area_changed((PixbufRenderer *)imd->pr, x, y, width, height);
+       pixbuf_renderer_area_changed(reinterpret_cast<PixbufRenderer *>(imd->pr), x, y, width, height);
 }
 
 void image_reload(ImageWindow *imd)
 {
-       if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return;
+       if (pixbuf_renderer_get_tiles(reinterpret_cast<PixbufRenderer *>(imd->pr))) return;
 
        image_change_complete(imd, image_zoom_get(imd));
 }
 
 void image_scroll(ImageWindow *imd, gint x, gint y)
 {
-       pixbuf_renderer_scroll((PixbufRenderer *)imd->pr, x, y);
+       pixbuf_renderer_scroll(reinterpret_cast<PixbufRenderer *>(imd->pr), x, y);
 }
 
 void image_scroll_to_point(ImageWindow *imd, gint x, gint y,
                           gdouble x_align, gdouble y_align)
 {
-       pixbuf_renderer_scroll_to_point((PixbufRenderer *)imd->pr, x, y, x_align, y_align);
+       pixbuf_renderer_scroll_to_point(reinterpret_cast<PixbufRenderer *>(imd->pr), x, y, x_align, y_align);
 }
 
 void image_get_scroll_center(ImageWindow *imd, gdouble *x, gdouble *y)
@@ -1684,42 +1678,43 @@ void image_set_scroll_center(ImageWindow *imd, gdouble x, gdouble y)
 
 void image_zoom_adjust(ImageWindow *imd, gdouble increment)
 {
-       pixbuf_renderer_zoom_adjust((PixbufRenderer *)imd->pr, increment);
+       pixbuf_renderer_zoom_adjust(reinterpret_cast<PixbufRenderer *>(imd->pr), increment);
 }
 
 void image_zoom_adjust_at_point(ImageWindow *imd, gdouble increment, gint x, gint y)
 {
-       pixbuf_renderer_zoom_adjust_at_point((PixbufRenderer *)imd->pr, increment, x, y);
+       pixbuf_renderer_zoom_adjust_at_point(reinterpret_cast<PixbufRenderer *>(imd->pr), increment, x, y);
 }
 
 void image_zoom_set_limits(ImageWindow *imd, gdouble min, gdouble max)
 {
-       pixbuf_renderer_zoom_set_limits((PixbufRenderer *)imd->pr, min, max);
+       pixbuf_renderer_zoom_set_limits(reinterpret_cast<PixbufRenderer *>(imd->pr), min, max);
 }
 
 void image_zoom_set(ImageWindow *imd, gdouble zoom)
 {
-       pixbuf_renderer_zoom_set((PixbufRenderer *)imd->pr, zoom);
+       pixbuf_renderer_zoom_set(reinterpret_cast<PixbufRenderer *>(imd->pr), zoom);
 }
 
 void image_zoom_set_fill_geometry(ImageWindow *imd, gboolean vertical)
 {
        PixbufRenderer *pr;
        gdouble zoom;
-       gint width, height;
+       gint width;
+       gint height;
 
-       pr = (PixbufRenderer *)imd->pr;
+       pr = reinterpret_cast<PixbufRenderer *>(imd->pr);
 
        if (!pixbuf_renderer_get_pixbuf(pr) ||
            !pixbuf_renderer_get_image_size(pr, &width, &height)) return;
 
        if (vertical)
                {
-               zoom = (gdouble)pr->viewport_height / height;
+               zoom = static_cast<gdouble>(pr->viewport_height) / height;
                }
        else
                {
-               zoom = (gdouble)pr->viewport_width / width;
+               zoom = static_cast<gdouble>(pr->viewport_width) / width;
                }
 
        if (zoom < 1.0)
@@ -1732,12 +1727,12 @@ void image_zoom_set_fill_geometry(ImageWindow *imd, gboolean vertical)
 
 gdouble image_zoom_get(ImageWindow *imd)
 {
-       return pixbuf_renderer_zoom_get((PixbufRenderer *)imd->pr);
+       return pixbuf_renderer_zoom_get(reinterpret_cast<PixbufRenderer *>(imd->pr));
 }
 
 gdouble image_zoom_get_real(ImageWindow *imd)
 {
-       return pixbuf_renderer_zoom_get_scale((PixbufRenderer *)imd->pr);
+       return pixbuf_renderer_zoom_get_scale(reinterpret_cast<PixbufRenderer *>(imd->pr));
 }
 
 gchar *image_zoom_get_as_text(ImageWindow *imd)
@@ -1748,7 +1743,7 @@ gchar *image_zoom_get_as_text(ImageWindow *imd)
        gdouble r = 1.0;
        gint pl = 0;
        gint pr = 0;
-       gchar *approx = " ";
+       const gchar *approx = " ";
 
        zoom = image_zoom_get(imd);
        scale = image_zoom_get_real(imd);
@@ -1800,27 +1795,34 @@ gdouble image_zoom_get_default(ImageWindow *imd)
 }
 
 /* stereo */
-//gint image_stereo_get(ImageWindow *imd)
-//{
-       //return pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
-//}
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gint image_stereo_get_unused(ImageWindow *imd)
+{
+       return pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
+}
+#pragma GCC diagnostic pop
 
 void image_stereo_set(ImageWindow *imd, gint stereo_mode)
 {
        DEBUG_1("Setting stereo mode %04x for imd %p", stereo_mode, (void *)imd);
-       pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
+       pixbuf_renderer_stereo_set(reinterpret_cast<PixbufRenderer *>(imd->pr), stereo_mode);
 }
 
-//void image_stereo_swap(ImageWindow *imd)
-//{
-       //gint stereo_mode = pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
-       //stereo_mode ^= PR_STEREO_SWAP;
-       //pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void image_stereo_swap_unused(ImageWindow *imd)
+{
+       gint stereo_mode = pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
+       stereo_mode ^= PR_STEREO_SWAP;
+       pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
+}
+#pragma GCC diagnostic pop
 
 StereoPixbufData image_stereo_pixbuf_get(ImageWindow *imd)
 {
-       return imd->user_stereo;
+       return static_cast<StereoPixbufData>(imd->user_stereo);
 }
 
 void image_stereo_pixbuf_set(ImageWindow *imd, StereoPixbufData stereo_mode)
@@ -1833,7 +1835,7 @@ void image_stereo_pixbuf_set(ImageWindow *imd, StereoPixbufData stereo_mode)
 
 void image_prebuffer_set(ImageWindow *imd, FileData *fd)
 {
-       if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return;
+       if (pixbuf_renderer_get_tiles(reinterpret_cast<PixbufRenderer *>(imd->pr))) return;
 
        if (fd)
                {
@@ -1850,7 +1852,7 @@ void image_prebuffer_set(ImageWindow *imd, FileData *fd)
 
 static void image_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
 
        if (!imd || !image_get_pixbuf(imd) ||
            /* imd->il || */ /* loading in progress - do not check - it should start from the beginning anyway */
@@ -1887,18 +1889,18 @@ void image_top_window_set_sync(ImageWindow *imd, gboolean allow_sync)
        g_object_set(G_OBJECT(imd->pr), "window_fit", allow_sync, NULL);
 }
 
-void image_background_set_color(ImageWindow *imd, GdkColor *color)
+void image_background_set_color(ImageWindow *imd, GdkRGBA *color)
 {
-       pixbuf_renderer_set_color((PixbufRenderer *)imd->pr, color);
+       pixbuf_renderer_set_color(reinterpret_cast<PixbufRenderer *>(imd->pr), color);
 }
 
 void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen)
 {
-       GdkColor *color = NULL;
-       GdkColor theme_color;
+       GdkRGBA *color = nullptr;
+       GdkRGBA theme_color;
        GdkRGBA bg_color;
        GtkStyleContext *style_context;
-       LayoutWindow *lw = NULL;
+       LayoutWindow *lw = nullptr;
 
        if ((options->image.use_custom_border_color && !fullscreen) ||
            (options->image.use_custom_border_color_in_fullscreen && fullscreen))
@@ -1913,9 +1915,9 @@ void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscre
                style_context = gtk_widget_get_style_context(lw->window);
                gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color);
 
-               theme_color.red = bg_color.red * 65535;
-               theme_color.green = bg_color.green * 65535;
-               theme_color.blue = bg_color.blue * 65535;
+               theme_color.red = bg_color.red * 1;
+               theme_color.green = bg_color.green * 1;
+               theme_color.blue = bg_color.blue * 1;
 
                color = &theme_color;
                }
@@ -1971,7 +1973,7 @@ gboolean image_color_profile_get_status(ImageWindow *imd, gchar **image_profile,
        ColorMan *cm;
        if (!imd) return FALSE;
 
-       cm = imd->cm;
+       cm = static_cast<ColorMan *>(imd->cm);
        if (!cm) return FALSE;
        return color_man_get_status(cm, image_profile, screen_profile);
 
@@ -1992,13 +1994,13 @@ void image_set_delay_flip(ImageWindow *imd, gboolean delay)
 
                pr = PIXBUF_RENDERER(imd->pr);
                if (pr->pixbuf) g_object_unref(pr->pixbuf);
-               pr->pixbuf = NULL;
+               pr->pixbuf = nullptr;
 
                image_load_pixbuf_ready(imd);
                }
 }
 
-void image_to_root_window(ImageWindow *UNUSED(imd), gboolean UNUSED(scaled))
+void image_to_root_window(ImageWindow *, gboolean)
 {
 }
 
@@ -2019,7 +2021,7 @@ void image_set_selectable(ImageWindow *imd, gboolean selectable)
 {
        if (!imd->has_frame) return;
 
-       gtk_frame_set_shadow_type(GTK_FRAME(imd->frame), GTK_SHADOW_NONE);
+       gq_gtk_frame_set_shadow_type(GTK_FRAME(imd->frame), GTK_SHADOW_NONE);
        gtk_container_set_border_width(GTK_CONTAINER(imd->frame), selectable ? 4 : 0);
 }
 
@@ -2058,16 +2060,16 @@ static void image_options_set(ImageWindow *imd)
 
                                        NULL);
 
-       pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)imd->top_window);
+       pixbuf_renderer_set_parent(reinterpret_cast<PixbufRenderer *>(imd->pr), reinterpret_cast<GtkWindow *>(imd->top_window));
 
        image_stereo_set(imd, options->stereo.mode);
-       pixbuf_renderer_stereo_fixed_set((PixbufRenderer *)imd->pr,
+       pixbuf_renderer_stereo_fixed_set(reinterpret_cast<PixbufRenderer *>(imd->pr),
                                        options->stereo.fixed_w, options->stereo.fixed_h,
                                        options->stereo.fixed_x1, options->stereo.fixed_y1,
                                        options->stereo.fixed_x2, options->stereo.fixed_y2);
 }
 
-void image_options_sync(void)
+void image_options_sync()
 {
        GList *work;
 
@@ -2076,7 +2078,7 @@ void image_options_sync(void)
                {
                ImageWindow *imd;
 
-               imd = work->data;
+               imd = static_cast<ImageWindow *>(work->data);
                work = work->next;
 
                image_options_set(imd);
@@ -2108,38 +2110,27 @@ static void image_free(ImageWindow *imd)
        g_free(imd);
 }
 
-static void image_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+static void image_destroy_cb(GtkWidget *, gpointer data)
 {
-       ImageWindow *imd = data;
+       auto imd = static_cast<ImageWindow *>(data);
        image_free(imd);
 }
 
-gboolean selectable_frame_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer UNUSED(data))
+gboolean selectable_frame_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer)
 {
        GtkAllocation allocation;
        gtk_widget_get_allocation(widget, &allocation);
-       gtk_paint_flat_box(gtk_widget_get_style(widget),
-                          cr,
-                          gtk_widget_get_state(widget),
-                          gtk_frame_get_shadow_type(GTK_FRAME(widget)),
-                          widget,
-                          NULL,
-                          allocation.x + 3, allocation.y + 3,
-                          allocation.width - 6, allocation.height - 6);
+
+       gtk_render_frame(gtk_widget_get_style_context(widget), cr, allocation.x + 3, allocation.y + 3, allocation.width - 6, allocation.height - 6);
+       gtk_render_background(gtk_widget_get_style_context(widget), cr, allocation.x + 3, allocation.y + 3, allocation.width - 6, allocation.height - 6);
 
        if (gtk_widget_has_focus(widget))
                {
-               gtk_paint_focus(gtk_widget_get_style(widget), cr, GTK_STATE_ACTIVE,
-                               widget, "image_window",
-                               allocation.x, allocation.y,
-                               allocation.width - 1, allocation.height - 1);
+               gtk_render_focus(gtk_widget_get_style_context(widget), cr, allocation.x, allocation.y, allocation.width - 1, allocation.height - 1);
                }
        else
                {
-               gtk_paint_shadow(gtk_widget_get_style(widget), cr, GTK_STATE_NORMAL, GTK_SHADOW_IN,
-                                widget, "image_window",
-                                allocation.x, allocation.y,
-                                allocation.width - 1, allocation.height - 1);
+               gtk_render_frame(gtk_widget_get_style_context(widget), cr, allocation.x, allocation.y, allocation.width - 1, allocation.height - 1);
                }
        return FALSE;
 }
@@ -2154,11 +2145,11 @@ void image_set_frame(ImageWindow *imd, gboolean frame)
 
        if (frame)
                {
-               imd->frame = gtk_frame_new(NULL);
+               imd->frame = gtk_frame_new(nullptr);
                DEBUG_NAME(imd->frame);
                g_object_ref(imd->pr);
                if (imd->has_frame != -1) gtk_container_remove(GTK_CONTAINER(imd->widget), imd->pr);
-               gtk_container_add(GTK_CONTAINER(imd->frame), imd->pr);
+               gq_gtk_container_add(GTK_WIDGET(imd->frame), imd->pr);
 
                g_object_unref(imd->pr);
                gtk_widget_set_can_focus(imd->frame, TRUE);
@@ -2169,7 +2160,7 @@ void image_set_frame(ImageWindow *imd, gboolean frame)
                g_signal_connect(G_OBJECT(imd->frame), "focus_in_event",
                                 G_CALLBACK(image_focus_in_cb), imd);
 
-               gtk_box_pack_start(GTK_BOX(imd->widget), imd->frame, TRUE, TRUE, 0);
+               gq_gtk_box_pack_start(GTK_BOX(imd->widget), imd->frame, TRUE, TRUE, 0);
                gtk_widget_show(imd->frame);
                }
        else
@@ -2178,10 +2169,10 @@ void image_set_frame(ImageWindow *imd, gboolean frame)
                if (imd->frame)
                        {
                        gtk_container_remove(GTK_CONTAINER(imd->frame), imd->pr);
-                       gtk_widget_destroy(imd->frame);
-                       imd->frame = NULL;
+                       g_object_unref(imd->frame);
+                       imd->frame = nullptr;
                        }
-               gtk_box_pack_start(GTK_BOX(imd->widget), imd->pr, TRUE, TRUE, 0);
+               gq_gtk_box_pack_start(GTK_BOX(imd->widget), imd->pr, TRUE, TRUE, 0);
 
                g_object_unref(imd->pr);
                }
@@ -2220,6 +2211,8 @@ ImageWindow *image_new(gboolean frame)
                         G_CALLBACK(image_click_cb), imd);
        g_signal_connect(G_OBJECT(imd->pr), "button_press_event",
                         G_CALLBACK(image_press_cb), imd);
+       g_signal_connect(G_OBJECT(imd->pr), "button_release_event",
+                        G_CALLBACK(image_release_cb), imd);
        g_signal_connect(G_OBJECT(imd->pr), "scroll_notify",
                         G_CALLBACK(image_scroll_notify_cb), imd);