Compare commits

...

3 Commits

Author SHA1 Message Date
f8526d486a
Do not lie as much in the desktop file 2021-11-18 13:41:58 +01:00
06af1a3cc9
Add a command line option to list supported types
Make it work without a display connection.
2021-11-18 12:46:05 +01:00
47293cfc10
Make the forward mouse button go back to the view
For symmetry.
2021-11-18 12:46:04 +01:00
5 changed files with 77 additions and 13 deletions

View File

@ -78,6 +78,28 @@ const char *fastiv_io_supported_media_types[] = {
NULL
};
char **
fastiv_io_all_supported_media_types(void)
{
GPtrArray *types = g_ptr_array_new();
for (const char **p = fastiv_io_supported_media_types; *p; p++)
g_ptr_array_add(types, g_strdup(*p));
#ifdef HAVE_GDKPIXBUF
GSList *formats = gdk_pixbuf_get_formats();
for (GSList *iter = formats; iter; iter = iter->next) {
gchar **subtypes = gdk_pixbuf_format_get_mime_types(iter->data);
for (gchar **p = subtypes; *p; p++)
g_ptr_array_add(types, *p);
g_free(subtypes);
}
g_slist_free(formats);
#endif // HAVE_GDKPIXBUF
g_ptr_array_add(types, NULL);
return (char **) g_ptr_array_free(types, FALSE);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#define FASTIV_IO_ERROR fastiv_io_error_quark()

View File

@ -22,6 +22,8 @@
extern const char *fastiv_io_supported_media_types[];
char **fastiv_io_all_supported_media_types(void);
cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
cairo_surface_t *fastiv_io_open_from_data(
const char *data, size_t len, const gchar *path, GError **error);

View File

@ -368,35 +368,61 @@ on_key_press_view(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event,
static gboolean
on_button_press_view(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event)
{
if (!(event->state & gtk_accelerator_get_default_mod_mask()) &&
event->button == 8 /* back */) {
if ((event->state & gtk_accelerator_get_default_mod_mask()))
return FALSE;
switch (event->button) {
case 8: // back
gtk_stack_set_visible_child(GTK_STACK(g.stack), g.browser_paned);
return TRUE;
default:
return FALSE;
}
}
static gboolean
on_button_press_browser(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event)
{
if ((event->state & gtk_accelerator_get_default_mod_mask()))
return FALSE;
switch (event->button) {
case 9: // forward
gtk_stack_set_visible_child(GTK_STACK(g.stack), g.view_scroller);
return TRUE;
default:
return FALSE;
}
return FALSE;
}
int
main(int argc, char *argv[])
{
gboolean show_version = FALSE;
gboolean show_version = FALSE, show_supported_media_types = FALSE;
gchar **path_args = NULL;
const GOptionEntry options[] = {
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &path_args,
NULL, "[FILE | DIRECTORY]"},
{"list-supported-media-types", 0, G_OPTION_FLAG_IN_MAIN,
G_OPTION_ARG_NONE, &show_supported_media_types,
"Output supported media types and exit", NULL},
{"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&show_version, "output version information and exit", NULL},
&show_version, "Output version information and exit", NULL},
{},
};
GError *error = NULL;
if (!gtk_init_with_args(
&argc, &argv, " - fast image viewer", options, NULL, &error))
exit_fatal("%s", error->message);
gboolean initialized = gtk_init_with_args(
&argc, &argv, " - fast image viewer", options, NULL, &error);
if (show_version) {
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
return 0;
}
if (show_supported_media_types) {
for (char **types = fastiv_io_all_supported_media_types(); *types; )
g_print("%s\n", *types++);
return 0;
}
if (!initialized)
exit_fatal("%s", error->message);
// NOTE: Firefox and Eye of GNOME both interpret multiple arguments
// in a special way. This is problematic, because one-element lists
@ -453,6 +479,8 @@ main(int argc, char *argv[])
gtk_widget_set_hexpand(g.browser, TRUE);
g_signal_connect(g.browser, "item-activated",
G_CALLBACK(on_item_activated), NULL);
g_signal_connect(g.browser, "button-press-event",
G_CALLBACK(on_button_press_browser), NULL);
gtk_container_add(GTK_CONTAINER(g.browser_scroller), g.browser);
// TODO(p): Put a GtkListBox underneath, but with subdirectories.
@ -487,8 +515,10 @@ main(int argc, char *argv[])
G_CALLBACK(on_key_press), NULL);
gtk_container_add(GTK_CONTAINER(g.window), g.stack);
// TODO(p): Also milk gdk-pixbuf, if linked in, needs to be done in runtime.
g.supported_globs = extract_mime_globs(fastiv_io_supported_media_types);
char **types = fastiv_io_all_supported_media_types();
g.supported_globs = extract_mime_globs((const char **) types);
g_strfreev(types);
g.files = g_ptr_array_new_full(16, g_free);
gchar *cwd = g_get_current_dir();

View File

@ -7,5 +7,4 @@ Exec=fastiv %F
Terminal=false
StartupNotify=true
Categories=Graphics;2DGraphics;Viewer;
# TODO(p): Generate this list from source files.
MimeType=image/png;image/bmp;image/gif;image/jpeg;image/x-dcraw;image/svg+xml;image/x-xcursor;
MimeType=image/png;image/bmp;image/gif;image/jpeg;

View File

@ -30,7 +30,7 @@ configure_file(
configuration : conf,
)
executable('fastiv', 'fastiv.c', 'fastiv-view.c', 'fastiv-io.c',
exe = executable('fastiv', 'fastiv.c', 'fastiv-view.c', 'fastiv-io.c',
'fastiv-browser.c', 'xdg.c',
install : true,
dependencies : [dependencies])
@ -45,3 +45,14 @@ install_data('fastiv.desktop',
install_dir : get_option('datadir') + '/applications')
install_data('fastiv.svg',
install_dir : get_option('datadir') + '/icons/hicolor/scalable/apps')
# TODO(p): Replace this with custom_target().
if not meson.is_cross_build()
meson.add_install_script(
'sh', '-c', '''sed -i "/^MimeType=/{c \\
MimeType=$($1 --list-supported-media-types | tr "\\012" ";")
}" "$MESON_INSTALL_DESTDIR_PREFIX/$2"''',
'sh',
exe.full_path(),
get_option('datadir') + '/applications/fastiv.desktop')
endif