Incorporate most clang-format changes

This commit is contained in:
Přemysl Eric Janouch 2021-11-01 04:59:38 +01:00
parent 810a1fee57
commit 6eecee6b91
Signed by: p
GPG Key ID: A0420B94F92B9493
7 changed files with 103 additions and 111 deletions

View File

@ -74,8 +74,8 @@ fastiv_browser_get_request_mode(G_GNUC_UNUSED GtkWidget *widget)
}
static void
fastiv_browser_get_preferred_width(GtkWidget *widget,
gint *minimum, gint *natural)
fastiv_browser_get_preferred_width(
GtkWidget *widget, gint *minimum, gint *natural)
{
G_GNUC_UNUSED FastivBrowser *self = FASTIV_BROWSER(widget);
// TODO(p): Set it to the width of the widget with one wide item within.
@ -83,8 +83,8 @@ fastiv_browser_get_preferred_width(GtkWidget *widget,
}
static void
fastiv_browser_get_preferred_height_for_width(GtkWidget *widget,
G_GNUC_UNUSED gint width, gint *minimum, gint *natural)
fastiv_browser_get_preferred_height_for_width(
GtkWidget *widget, G_GNUC_UNUSED gint width, gint *minimum, gint *natural)
{
G_GNUC_UNUSED FastivBrowser *self = FASTIV_BROWSER(widget);
// TODO(p): Re-layout, figure it out.
@ -109,8 +109,8 @@ fastiv_browser_realize(GtkWidget *widget)
.wclass = GDK_INPUT_OUTPUT,
.visual = gtk_widget_get_visual(widget),
.event_mask = gtk_widget_get_events(widget)
| GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK,
.event_mask = gtk_widget_get_events(widget) | GDK_KEY_PRESS_MASK |
GDK_BUTTON_PRESS_MASK,
};
// We need this window to receive input events at all.
@ -131,8 +131,8 @@ fastiv_browser_draw(GtkWidget *widget, cairo_t *cr)
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
gtk_render_background(gtk_widget_get_style_context(widget), cr,
0, 0, allocation.width, allocation.height);
gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0,
allocation.width, allocation.height);
const double row_height = 256;
@ -152,8 +152,8 @@ fastiv_browser_draw(GtkWidget *widget, cairo_t *cr)
int projected_width = round(scale * width);
int projected_height = round(scale * height);
if (occupied_width != 0
&& occupied_width + projected_width > allocation.width) {
if (occupied_width != 0 &&
occupied_width + projected_width > allocation.width) {
occupied_width = 0;
y += row_height;
}
@ -178,17 +178,15 @@ fastiv_browser_class_init(FastivBrowserClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
widget_class->get_request_mode = fastiv_browser_get_request_mode;
widget_class->get_preferred_width =
fastiv_browser_get_preferred_width;
widget_class->get_preferred_width = fastiv_browser_get_preferred_width;
widget_class->get_preferred_height_for_width =
fastiv_browser_get_preferred_height_for_width;
widget_class->realize = fastiv_browser_realize;
widget_class->draw = fastiv_browser_draw;
// TODO(p): Connect to this and emit it.
browser_signals[ITEM_ACTIVATED] =
g_signal_new("item-activated", G_TYPE_FROM_CLASS(klass),
0, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
browser_signals[ITEM_ACTIVATED] = g_signal_new("item-activated",
G_TYPE_FROM_CLASS(klass), 0, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
// TODO(p): Later override "screen_changed", recreate Pango layouts there,
// if we get to have any, or otherwise reflect DPI changes.
@ -217,12 +215,12 @@ fastiv_browser_load(FastivBrowser *self, const char *path)
const char *filename;
while ((filename = g_dir_read_name(dir))) {
if (!strcmp(filename, ".")
|| !strcmp(filename, ".."))
if (!strcmp(filename, ".") || !strcmp(filename, ".."))
continue;
gchar *subpath = g_build_filename(path, filename, NULL);
g_array_append_val(self->entries, ((Entry) {
g_array_append_val(self->entries,
((Entry){
.thumbnail = fastiv_io_lookup_thumbnail(subpath),
.filename = subpath,
}));

View File

@ -15,8 +15,8 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
#include <time.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <time.h>
#include "fastiv-view.h"

View File

@ -17,8 +17,8 @@
#include "config.h"
#include <glib.h>
#include <cairo.h>
#include <glib.h>
#include <turbojpeg.h>
#ifdef HAVE_LIBRAW
#include <libraw.h>
@ -64,8 +64,7 @@ enum FastivIoError {
static void
set_error(GError **error, const char *message)
{
g_set_error_literal(error,
FASTIV_IO_ERROR, FASTIV_IO_ERROR_OPEN, message);
g_set_error_literal(error, FASTIV_IO_ERROR, FASTIV_IO_ERROR_OPEN, message);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -74,8 +73,8 @@ set_error(GError **error, const char *message)
// is pure C, and a good reference. I can't use the auxiliary libraries,
// since they depend on C++, which is undesirable.
static cairo_surface_t *
open_wuffs(wuffs_base__image_decoder *dec,
wuffs_base__io_buffer src, GError **error)
open_wuffs(
wuffs_base__image_decoder *dec, wuffs_base__io_buffer src, GError **error)
{
wuffs_base__image_config cfg;
wuffs_base__status status =
@ -170,8 +169,8 @@ open_wuffs(wuffs_base__image_decoder *dec,
// Starting to modify pixel data directly. Probably an unnecessary call.
cairo_surface_flush(surface);
status = wuffs_base__image_decoder__decode_frame(dec, &pb, &src,
WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
status = wuffs_base__image_decoder__decode_frame(
dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
if (!wuffs_base__status__is_ok(&status)) {
set_error(error, wuffs_base__status__message(&status));
cairo_surface_destroy(surface);
@ -196,8 +195,8 @@ open_wuffs_using(wuffs_base__image_decoder *(*allocate)(),
return NULL;
}
cairo_surface_t *surface = open_wuffs(dec,
wuffs_base__ptr_u8__reader((uint8_t *) data, len, TRUE), error);
cairo_surface_t *surface = open_wuffs(
dec, wuffs_base__ptr_u8__reader((uint8_t *) data, len, TRUE), error);
free(dec);
return surface;
}
@ -255,8 +254,8 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
int stride = cairo_image_surface_get_stride(surface);
if (tjDecompress2(dec, (const unsigned char *) data, len,
cairo_image_surface_get_data(surface), width, stride,
height, pixel_format, TJFLAG_ACCURATEDCT)) {
cairo_image_surface_get_data(surface), width, stride, height,
pixel_format, TJFLAG_ACCURATEDCT)) {
set_error(error, tjGetErrorStr2(dec));
cairo_surface_destroy(surface);
tjDestroy(dec);
@ -267,8 +266,8 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
if (pixel_format == TJPF_CMYK) {
// CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with
// ARGB/BGR/XRGB/BGRX.
trivial_cmyk_to_bgra(cairo_image_surface_get_data(surface),
width * height);
trivial_cmyk_to_bgra(
cairo_image_surface_get_data(surface), width * height);
}
// Pixel data has been written, need to let Cairo know.
@ -284,8 +283,8 @@ static cairo_surface_t *
open_libraw(const gchar *data, gsize len, GError **error)
{
// https://github.com/LibRaw/LibRaw/issues/418
libraw_data_t *iprc = libraw_init(LIBRAW_OPIONS_NO_MEMERR_CALLBACK
| LIBRAW_OPIONS_NO_DATAERR_CALLBACK);
libraw_data_t *iprc = libraw_init(
LIBRAW_OPIONS_NO_MEMERR_CALLBACK | LIBRAW_OPIONS_NO_DATAERR_CALLBACK);
if (!iprc) {
set_error(error, "failed to obtain a LibRaw handle");
return NULL;
@ -368,8 +367,8 @@ open_libraw(const gchar *data, gsize len, GError **error)
unsigned char *p = image->data;
for (ushort y = 0; y < image->height; y++) {
for (ushort x = 0; x < image->width; x++) {
*pixels++ = 0xff000000 | (uint32_t) p[0] << 16
| (uint32_t) p[1] << 8 | (uint32_t) p[2];
*pixels++ = 0xff000000 | (uint32_t) p[0] << 16 |
(uint32_t) p[1] << 8 | (uint32_t) p[2];
p += 3;
}
}
@ -407,18 +406,18 @@ fastiv_io_open(const gchar *path, GError **error)
// Note that BMP can redirect into another format,
// which is so far unsupported here.
surface = open_wuffs_using(
wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder,
data, len, error);
wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder, data, len,
error);
break;
case WUFFS_BASE__FOURCC__GIF:
surface = open_wuffs_using(
wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder,
data, len, error);
wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder, data, len,
error);
break;
case WUFFS_BASE__FOURCC__PNG:
surface = open_wuffs_using(
wuffs_png__decoder__alloc_as__wuffs_base__image_decoder,
data, len, error);
wuffs_png__decoder__alloc_as__wuffs_base__image_decoder, data, len,
error);
break;
case WUFFS_BASE__FOURCC__JPEG:
surface = open_libjpeg_turbo(data, len, error);
@ -446,8 +445,8 @@ fastiv_io_open(const gchar *path, GError **error)
// scaled, linear encoded, pre-multiplied component values must be used!"
//
// We can use the pixman library to scale, PIXMAN_a8r8g8b8_sRGB.
#include <png.h>
#include <glib/gstdio.h>
#include <png.h>
// TODO(p): Reorganize the sources.
gchar *get_xdg_home_dir(const char *var, const char *default_);
@ -467,8 +466,8 @@ discard_png_warning(png_structp pngp, const char *warning)
}
static int
check_png_thumbnail(png_structp pngp, png_infop infop, const gchar *target,
time_t mtime)
check_png_thumbnail(
png_structp pngp, png_infop infop, const gchar *target, time_t mtime)
{
// May contain Thumb::Image::Width Thumb::Image::Height,
// but those aren't interesting currently (would be for fast previews).
@ -496,8 +495,8 @@ check_png_thumbnail(png_structp pngp, png_infop infop, const gchar *target,
// TODO(p): Support spng as well (it can't premultiply alpha by itself,
// but at least it won't gamma-adjust it for us).
static cairo_surface_t *
read_png_thumbnail(const gchar *path, const gchar *uri, time_t mtime,
GError **error)
read_png_thumbnail(
const gchar *path, const gchar *uri, time_t mtime, GError **error)
{
FILE *fp;
if (!(fp = fopen(path, "rb"))) {
@ -506,8 +505,8 @@ read_png_thumbnail(const gchar *path, const gchar *uri, time_t mtime,
}
cairo_surface_t *volatile surface = NULL;
png_structp pngp = png_create_read_struct(PNG_LIBPNG_VER_STRING,
error, redirect_png_error, discard_png_warning);
png_structp pngp = png_create_read_struct(
PNG_LIBPNG_VER_STRING, error, redirect_png_error, discard_png_warning);
png_infop infop = png_create_info_struct(pngp);
if (!infop) {
set_error(error, g_strerror(errno));
@ -617,8 +616,8 @@ fastiv_io_lookup_thumbnail(const gchar *target)
const gchar *sizes[] = {"large", "x-large", "xx-large", "normal"};
GError *error = NULL;
for (gsize i = 0; !result && i < G_N_ELEMENTS(sizes); i++) {
gchar *path = g_strdup_printf("%s/thumbnails/%s/%s.png",
cache_dir, sizes[i], sum);
gchar *path = g_strdup_printf(
"%s/thumbnails/%s/%s.png", cache_dir, sizes[i], sum);
result = read_png_thumbnail(path, uri, st.st_mtim.tv_sec, &error);
if (error) {
g_debug("%s: %s", path, error->message);

View File

@ -57,8 +57,8 @@ fastiv_view_finalize(GObject *gobject)
}
static void
fastiv_view_get_preferred_height(GtkWidget *widget,
gint *minimum, gint *natural)
fastiv_view_get_preferred_height(
GtkWidget *widget, gint *minimum, gint *natural)
{
*minimum = 0;
*natural = 0;
@ -68,8 +68,7 @@ fastiv_view_get_preferred_height(GtkWidget *widget,
}
static void
fastiv_view_get_preferred_width(GtkWidget *widget,
gint *minimum, gint *natural)
fastiv_view_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
{
*minimum = 0;
*natural = 0;
@ -113,14 +112,14 @@ static gboolean
fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
{
FastivView *self = FASTIV_VIEW(widget);
if (!self->surface
|| !gtk_cairo_should_draw_window(cr, gtk_widget_get_window(widget)))
if (!self->surface ||
!gtk_cairo_should_draw_window(cr, gtk_widget_get_window(widget)))
return TRUE;
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
gtk_render_background(gtk_widget_get_style_context(widget), cr,
0, 0, allocation.width, allocation.height);
gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0,
allocation.width, allocation.height);
int w = get_display_width(self);
int h = get_display_height(self);
@ -133,8 +132,8 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
y = round((allocation.height - h) / 2.);
cairo_scale(cr, self->scale, self->scale);
cairo_set_source_surface(cr, self->surface,
x / self->scale, y / self->scale);
cairo_set_source_surface(
cr, self->surface, x / self->scale, y / self->scale);
// TODO(p): Prescale it ourselves to an off-screen bitmap, gamma-correctly.
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);

View File

@ -15,26 +15,25 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <fnmatch.h>
#include "config.h"
#include "fastiv-browser.h"
#include "fastiv-io.h"
#include "fastiv-view.h"
#include "fastiv-browser.h"
// --- Utilities ---------------------------------------------------------------
static void
exit_fatal(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
static void exit_fatal(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
static void
exit_fatal(const gchar *format, ...)
@ -53,8 +52,8 @@ exit_fatal(const gchar *format, ...)
/// Add `element` to the `output` set. `relation` is a map of sets of strings
/// defining is-a relations, and is traversed recursively.
static void
add_applying_transitive_closure(const gchar *element, GHashTable *relation,
GHashTable *output)
add_applying_transitive_closure(
const gchar *element, GHashTable *relation, GHashTable *output)
{
// Stop condition.
if (!g_hash_table_add(output, g_strdup(element)))
@ -181,8 +180,8 @@ get_supported_globs(const char **media_types)
// The mime.cache format is inconvenient to parse,
// we'll do it from the text files manually, and once only.
GHashTable *subclass_sets = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_hash_table_destroy);
GHashTable *subclass_sets = g_hash_table_new_full(
g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy);
for (gsize i = 0; data_dirs[i]; i++) {
gchar *path =
g_build_filename(data_dirs[i], "mime", "subclasses", NULL);
@ -195,8 +194,8 @@ get_supported_globs(const char **media_types)
GHashTable *supported =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
while (*media_types) {
add_applying_transitive_closure(*media_types++,
subclass_sets, supported);
add_applying_transitive_closure(
*media_types++, subclass_sets, supported);
}
g_hash_table_destroy(subclass_sets);
@ -261,8 +260,8 @@ is_supported(const gchar *filename)
static void
show_error_dialog(GError *error)
{
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(g.window),
GTK_DIALOG_MODAL,
GtkWidget *dialog =
gtk_message_dialog_new(GTK_WINDOW(g.window), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
@ -336,7 +335,6 @@ open(const gchar *path)
}
}
g_free(dirname);
}
static void
@ -375,9 +373,8 @@ on_previous(void)
if (g.files_index >= 0) {
int previous =
(g.files->len - 1 + g.files_index - 1) % (g.files->len - 1);
char *absolute =
g_canonicalize_filename(g_ptr_array_index(g.files, previous),
g.directory);
char *absolute = g_canonicalize_filename(
g_ptr_array_index(g.files, previous), g.directory);
open(absolute);
g_free(absolute);
}
@ -388,9 +385,8 @@ on_next(void)
{
if (g.files_index >= 0) {
int next = (g.files_index + 1) % (g.files->len - 1);
char *absolute =
g_canonicalize_filename(g_ptr_array_index(g.files, next),
g.directory);
char *absolute = g_canonicalize_filename(
g_ptr_array_index(g.files, next), g.directory);
open(absolute);
g_free(absolute);
}
@ -413,8 +409,8 @@ main(int argc, char *argv[])
};
GError *error = NULL;
if (!gtk_init_with_args(&argc, &argv, " - fast image viewer",
options, NULL, &error))
if (!gtk_init_with_args(
&argc, &argv, " - fast image viewer", options, NULL, &error))
exit_fatal("%s", error->message);
if (show_version) {
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
@ -494,9 +490,9 @@ main(int argc, char *argv[])
if (!path_arg) {
load_directory(cwd);
} else if (g_stat(path_arg, &st)) {
show_error_dialog(g_error_new(G_FILE_ERROR,
g_file_error_from_errno(errno),
"%s: %s", path_arg, g_strerror(errno)));
show_error_dialog(
g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), "%s: %s",
path_arg, g_strerror(errno)));
load_directory(cwd);
} else {
gchar *path_arg_absolute = g_canonicalize_filename(path_arg, cwd);