tats / w3m

Debian's w3m: WWW browsable pager
https://tracker.debian.org/pkg/w3m
Other
845 stars 91 forks source link

w3m won't use feh to open images #106

Open SlidingHorn opened 5 years ago

SlidingHorn commented 5 years ago

I've tried setting the "External command to display image" to feh, feh -F %f, feh -Fx %f, and feh %f, and it will open images in just about any application other than feh.

I'm happy to help troubleshoot if you could point me to a log that might explain why this is happening.

Boruch-Baum commented 5 years ago

Until @tats swoops in and saves the day, here's how I'm successfully using feh: On 'options' page (press O), for entry 'External command to display image', I have 'w3mimgdisplay', which I believe is the default. About a dozen lines up from there, just above the heading 'Display settings', is a link for 'external viewer setup'. That seems to be some sort of editable list of mimetypes, possibly taken from a mimetype database. In that list, there are entries for various image formats, which for using 'feh' are as follows in my case;

"$DISPLAY";
description=PNG image;
nametemplate=%s.png
feh '%s'; test=test -n

My guess is that @tats will explain how to make this work for you without manually tinkering with this section at all, maybe by simply adjusting your personal mimetype data, but I could be wrong. If you do want to investigate from the system-wide mimetype side of things, a command xdg-mime default feh.desktop image/jpg will perform an association, once you define the file feh.desktop (in /usr/share/applications/ or ~/.local/share/applications/). To query a current association, xdg-mime query filetype foo.png will return the mimetype for file foo.png, and xdg-mime query default $(xdg-mime query filetype foo.png) will return the program to be used to open that file / mimetype.

SlidingHorn commented 5 years ago

@Boruch-Baum That fixed my issue. I'd love to see w3m override those if the setting is set in options, but for now, my problem is solved. Feel free to close this if that's something you don't intend to work on, @tats

SlidingHorn commented 5 years ago

Correction: It works about 75% of the time. Sometimes it opens an imagemagik window, other times (though far less often now) it still opens Firefox

Boruch-Baum commented 5 years ago

Are you reporting that for the same image it works unreliably? If you are reporting different responses for different images, double check their file extensions and their file's 'magic number' against the corresponding entry in your mimetype database. It's unclear to me from your report exactly what part of what I wrote solved (part?) of your issue, but if what you did was create or modify a file 'feh.desktop', then you need to be sure that its mimetype definition explicitly includes each mimetype you want that program to open.

Here are the two relevant lines from my own feh.desktop file:

Exec=feh --draw-filename --draw-exif --magick-timeout 1 --image-bg black -g 800x600 %f %d
MimeType=image/jpeg;image/png;image/gif;image/tiff;image/bmp;image/x-icon;image/x-xpixmap;image/x-xbitmap;
SlidingHorn commented 5 years ago

Oh, sorry for my lack of clarity. I went into the "External Viewer Setup" and made entries for image/jpg, image/jpeg, image/gif, and image/png (those are essentially the file types I come across) to call feh -F '%s'; test=test -n "$DISPLAY" ' DESCRIPTION=XXXX Image, nametemplate=%.ext

I can open the same picture twice, and it can open different applications to view it. I haven't attempted to create a .desktop file at this time.

If I'm to do that, where do I put the file, and do I need to do anything else other than to have it exist in a specific directory?

Boruch-Baum commented 5 years ago

I can open the same picture twice, and it can open different applications to view it.

That is very curious, unexpected and concerning.

... where do I put the file, and do I need to do anything else ...

See my prior response. The file feh.desktop should be in ~/.local/share/applications/ for per-user defintions, and if among all the *.desktop files on the system, more than one wants to be associated with a particular mimetype, then you will need to use the xdg-mime command, in the form xdg-mime default feh.desktop image/jpg for each mimetype giving you trouble.

Still, it's very curious that you are reporting the same file being opened by different programs on different attempts. Are you sure each attempt was identical, using the same keystroke within w3m?

SlidingHorn commented 5 years ago

Created the desktop file and ran the xdg-mime default feh.desktop command for every filetype mentioned within it. I opened w3m and used U to go to this url (jpg image: https://imgur.com/mBicNPO.jpg) - First two times, it opened in feh, the next, a private Firefox window, then the next, ImageMagick.

Here's the .desktop file I created:

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Name=Feh
GenericName=Image Viewer
Exec=feh -F %f
Terminal=false
Type=Application
Icon=image-viewer
StartupNotify=false
NoDisplay=true
Hidden=false
Categories=Graphics;Viewer;
MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/pjpg;image/png;image/tiff;image/xbmp;image/x-gray;image/x-icb;image/x-ico;image/x-icon;image/x-png;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-xpixmap;image/x-xbitmap;image/x-pcx;

EDIT: Did it a few more times and even got it to open in GIMP once.

Boruch-Baum commented 5 years ago

I'm stumped, without being ready to look at w3m internals for something weird going on there, so let's wait for @tats to login. As a separate issue, you don't need the line #!/usr/bin/env xdg-open in your desktop file.

tats commented 5 years ago

As @Boruch-Baum suggested, VIEW_IMAGE (I) uses MIME Apps configuration.

For w3m, you may create ~/.w3m/mailcap. On my Debian system, the following command adds configuration to prefer feh for w3m.

$ grep '\bfeh\b' /etc/mailcap >>~/.w3m/mailcap
SlidingHorn commented 5 years ago

@tats I've run the command given, and run the same test, with similar results. It's still using different applications to open the image.

tats commented 5 years ago

@SlidingHorn

I opened w3m and used U to go to this url (jpg image: https://imgur.com/mBicNPO.jpg) - First two times, it opened in feh, the next, a private Firefox window, then the next, ImageMagick.

Unreproducible for me, it opened in feh five times.

SlidingHorn commented 5 years ago

Is there some kind of flag I can run with w3m that would create some form of logging to determine what's causing this?

SlidingHorn commented 5 years ago

Another thing I'd like to try: Is there a "comment" tag for the mailcap file that will mute lines? I can try to mute anything that mentions "firefox -private-window" to see if that makes a difference.

EDIT: I commented out the following lines, and after testing the image at least 10-15 times, it only opened in feh:

#x-scheme-handler/http; firefox -private-window %s; test=test -n "$DISPLAY"
#x-scheme-handler/https;    firefox -private-window %s; test=test -n "$DISPLAY"
#x-scheme-handler/ftp;  firefox -private-window %s; test=test -n "$DISPLAY"
#x-scheme-handler/chrome;   firefox -private-window %s; test=test -n "$DISPLAY"
#application/x-xpinstall;   firefox -private-window %s; test=test -n "$DISPLAY"
#image/bmp; gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-portable-anymap;   gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-portable-bitmap;   gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-portable-graymap;  gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-portable-pixmap;   gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-xbitmap;   gimp-2.8 %s; test=test -n "$DISPLAY"
#image/tiff;    gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-icon;  gimp-2.8 %s; test=test -n "$DISPLAY"
#image/x-xpixmap;   gimp-2.8 %s; test=test -n "$DISPLAY"
SlidingHorn commented 5 years ago

I've officially commented out every entry for GIMP and Firefox, and it's still (but very rarely) using them. I don't know what to do anymore :sob:

Boruch-Baum commented 5 years ago

Try this: Close firefox and gimp, induce the undesired response, and use htop to see how firefox or gimp was spawned. htop has an option to view process trees (F5 for me) so if some third-party program is intercepting the display request, you should be able to see it as a process (or series of processes) appearing in htop between w3m and firefox/gimp. In htop use F3 or / to search for the w3m process.

felipesaa commented 5 years ago

Maybe some useful data

mailcap ~/.w3m/mailcap, /etc/w3m/mailcap, /etc/mailcap

application/pdf; /usr/bin/zathura '%s'

Image/Gif; /usr/bin/viewnior '%s'

Image/Gif; /usr/bin/mpv --loop '%s' Image/svg+xml; /usr/bin/inkview '%s' Image/jpeg; /usr/bin/sxiv -s f -f '%s' Image/png; /usr/bin/sxiv -s f -f '%s'

image/jpg; feh -F '%s' image/jpeg; feh -F '%s' image/gif; feh -F '%s' image/png; feh -F '%s'