LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   xdg-open $PWD opens directory in firefox, so does every qt app (http://www.linuxquestions.org/questions/slackware-14/xdg-open-%24pwd-opens-directory-in-firefox-so-does-every-qt-app-4175465310/)

Totoro-kun 06-09-2013 06:43 AM

xdg-open $PWD opens directory in firefox, so does every qt app
 
Good day fellow slackers,
I have this problem for quite a while now, but patiently tried to look for a cure myself. However, I was unlucky, so I'm asking for help.

My systems:
2 computers running Slackware64 14.0 multilib enabled, without KDE, Or Xfce, but with Mate 1.6 from MSB installed.

The problem:
Skype, Dropbox and possibly other qt programs always opens directory (where downloaded files are) in Firefox. GTK programs, shows them in caja however.

What I suspect, is misbehaving xdg-open, because, if I try to open directories directly form a command line using xdg-open:
Code:

xdg-open $PWD

Or:
xdg-open file:///home

directories opens in firefox.

I have tried to add application/x-directory=caja-folder-handler.desktop; and inode/directory=caja-folder-handler.desktop to my .local/share/applications/mimeapps.list but no effect.

and then I have used xdg-mime command to set default programs:
Code:

xdg-mime default caja-folder-handler.desktop inode/directory
and
xdg-mime default caja-folder-handler.desktop application/x-directory

without success.

I have also tried to remove my .local/share/mime and .local/share/applications so the system would create new ones, but that did not work aether.

I have tried to search for a solution online, but ended up banging my head onto the wall, which did not help too :scratch:

In Archforums, there was a solution to install perl-file-mimeinfo, but there is no such package for Slack. And other solution was to export DE=xfce in .xinitrc but that did not help.

So I thought I should ask here, hopefully someone had similar problems in the past.

Totoro-kun 06-09-2013 12:21 PM

I have just compared one of my systems, to another simmilar system, but with Xfce instead of mate, and there xdg-open $PWD and other applications does open directory in Thunar. But that system does not have any entry about inode/directory or application/x-directory in mimeapps.list. I am starting to think, that xdg-open script it self might not recognize caja, as a file browser. And in case I do not have any other file manager (dolphin, thunar, nautilus) it thinks of firefox as a last resort.

Now, xdg-open is quite complicated to me, so it would be nice if someone more capable would take a look :)

BroX 06-09-2013 01:36 PM

fwiw, on my full Slackware-current system (so incl. dolphin, thunar) xdg-open $PWD also opens in firefox.

Not sure if using i3 (instead of KDE or Xfce) has something to do with it.

T3slider 06-09-2013 02:05 PM

/usr/bin/xdg-open (it is just a shell script) checks to see if you're running a well-known desktop environment (KDE, Gnome, XFCE, or LXDE) and if identified tries to open it using the desktop environment's tools. XFCE is properly identified so it tries using exo-open to open files. Apparently when running MATE it is having difficulty detecting that you are running a Gnome equivalent. I assume MATE uses gvfs-open (which is actually installed by default on Slackware anyway), but if it is falling back to Firefox then it isn't trying gvfs-open at all. It attempts to detect a Gnome session by checking the value of
Code:

$GNOME_DESKTOP_SESSION_ID
which I believe is deprecated (though I don't use MATE/Gnome so I could be wrong), so it is empty. Then it tries this:
Code:

dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager
I don't know anything about MATE but I would guess that perhaps this dbus stuff has been tweaked to specify mate instead of gnome and it is therefore failing. If you can find the proper dbus line to use, you could modify /usr/bin/xdg-open to use that line instead to properly detect MATE.

If you want to forgo gvfs-open and just use the default behaviour of xdg-open, then you will have to specify at least some mime types using xdg-mime, as you have tried to do. However, it does matter where the .desktop file resides. xdg-open checks the following directories for .desktop files:
Code:

/usr/local/share/applications
/usr/share/applications
$HOME/.local/share/applications

If caja-folder-handler.desktop resides in a subdirectory, xdg-open will not find it (for example, dolphin.desktop is located in /usr/share/applications/kde4/dolphin.desktop -- therefore, if you specify dolphin.desktop as the default mime type for directories, it will not work with xdg-open's generic methods). If your .desktop file is in a subdirectory then I would advise copying (or symlinking) it to $HOME/.local/share/applications.

Using the same syntax you did, I was able to specify Thunar to open directories from a generic window manager, but not dolphin (due to the subdirectory issue -- though after symlinking it to $HOME/.local/share/applications it did work). xdg-mime will not give you an error if you specify an unknown .desktop file so you would have to do any checks manually.

The only other reason I can think of that it would fail is if the .desktop file is in $HOME/.local/share/applications but the XDG_DATA_HOME variable is set to something else, so you should make sure that is unset as well.

Totoro-kun 06-09-2013 02:40 PM

Thank you very much, T3slider. The problem indeed was in xdg-open failing to detect mate as gnome variant. Mate indeed uses gvfs-open. So I did a little, but dirty modification to xdg-open script:
Code:

# Checks for known desktop environments
# set variable DE to the desktop environments name, lowercase

detectDE()
{
    if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
    elif [ x"$DESKTOP_SESSION" != x"MATE" ]; then DE=gnome;
    elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
    elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
    elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
    else DE=""
    fi
}

Basically, just modified $GNOME_DESKTOP_SESSION_ID to $DESKTOP_SESSION and replaced GNOME with MATE, so it detects Mate as gnome, there for uses gvfs-open. So far everything seems to work fine. Thanks again!

chess 06-09-2013 02:57 PM

Thanks for this -- perhaps Willy and I need to incorporate this in MSB or at least mention it in the README.TXT.

Totoro-kun 06-09-2013 03:05 PM

Probably most "Clean" solution would be Mate's own section in xdg-open. Hopefully this will happen in time. Otherwise MSB mate is very reliable and dependable DE :hattip:

T3slider 06-09-2013 03:07 PM

That check for MATE will always return true -- it is checking to see if $DESKTOP_SESSION does NOT equal MATE, which it won't in any desktop environment (obviously non-MATE DEs will not have DESKTOP_SESSION set to MATE, and MATE uses the lowercase mate instead). See here for a more elegant patch that would allow you to use gvfs in mate and maintain proper activity in other DEs/WMs. It appears this has been addressed upstream (see here and here) checking for MATE_DESKTOP_SESSION_ID, but Slackware-current hasn't upgraded xdg-utils from 14.0 so this will probably still be an issue in the next Slackware release (and it probably isn't important for Pat to update it considering Slackware does not ship MATE).

Totoro-kun 06-09-2013 03:15 PM

Cheers, just fixed my xdg-open with your mentioned elegant fix. Thank you again :hattip:

chess 06-09-2013 10:04 PM

1 Attachment(s)
Just to put a bow on this and bring the above hints together -- here are the steps to get this working in MATE:

1. Apply the attached patch to /usr/bin/xdg-open.

2. Set your xdg-mime default handlers to caja (MATE's file manager):

Code:

xdg-mime default caja-folder-handler.desktop inode/directory
xdg-mime default caja-folder-handler.desktop application/x-directory

3. Profit. :-)

Thanks to Totoro-kun and T3slider!

chess 06-10-2013 07:39 PM

Thanks to Pat for incorporating the fix into -current that T3slider found. :-)

qweasd 09-26-2013 08:31 PM

Every time I have to deal with xdg, I want to pull out my hair. How does one even design something like this?

I use openbox, and as it stands, xdg-open opens urls and html files with firefox, even though

(1) ~/.local/share/applications/mimeapps.list is configured to use icecat.desktop, which resides in ~/.local/share/applications.

(2) /usr/share/applications/defaults.list does not exist.

(3) xdg-mime query default text/html prints nothing.

kde-open, the only one which seems to obey its own settings, starts icecat (desired behavior).

gnome-open and gvfs-open seem to start whatever is written in /usr/share/applications/mimeinfo.cache (at least they are consistent).

exo-open starts seamonkey, even though I used xfce config tool to make icecat both the default browser and the default text/html handler. But this one I don't really care about, since I use no part of xfce.

So how the heck does xdg-open start firefox? And how can I change that? Can I make it obey ~/.local/share/applications/mimeapps.list? Setting $KDE_FULL_SESSION seems to do the trick, but is that a clean solution in the absence of KDE? I don't want anyone else to get confused by assuming that KDE is running.

volkerdi 09-26-2013 08:37 PM

Quote:

Originally Posted by qweasd (Post 5035648)
Every time I have to deal with xdg, I want to pull out my hair. How does one even design something like this?

Good question. Wish I had a good answer.

qweasd 09-27-2013 10:23 AM

Quote:

Originally Posted by qweasd (Post 5035648)
So how the heck does xdg-open start firefox?

Bah, I got it. firefox is hard-coded into the script as the first browser to try if the configuration is missing.

chess 10-05-2013 11:52 PM

I agree. Xdg should be taken out behind the woodshed and dealt with. Severely.


All times are GMT -5. The time now is 07:48 AM.