mateslackbuilds / msb

SlackBuild scripts for the MATE desktop environment
https://mateslackbuilds.github.io/
48 stars 16 forks source link

Full Install broke xdg_open #2

Closed cdr255 closed 10 years ago

cdr255 commented 10 years ago

I recently compiled the entire project (both the base and everything in /extra) and am very impressed with the way things work, save for one small detail:

For whatever reason, the environment variable $DESKTOP_SESSION is not set by default.

I was able to get around this without editing the /usr/bin/xdg-open file by editing the /etc/x11/xinit/xinitrc.mate-session file. Adding the following:

export DESKTOP_SESSION="mate"

above each of the exec lines fixed the issue entirely.

However, tracking down the problem took me quite a while.

This is by no means an urgent issue, but a few characters of text will make the system perfectly workable for situations where there are multiple people of differing levels of computer literacy who use the same computer, and some don't ever want to have to open a terminal (for whatever reason).

Of course, it is possible that I was the problem as well. Is there something I did wrong during the installation process?

willysr commented 10 years ago

is there any reason for you to set the environment variable DESKTOP_SESSION? I saw that KDE and other DE doesn't set them in xinitrc.{kde,xfce}

cdr255 commented 10 years ago

The main reason I needed it set is that, with it unset, all mime types open as a url in firefox (which, incidently, is NOT set as my default browser in MATE) when passed to xdg-open (for instance, when clicked on in a download manager).

I don't know for sure (not at my computer at the moment) but I believe this environment variable is set automatically in kde/gnome/xfce4. Will try to find out when I return home in an hour or so. On Feb 18, 2014 12:04 AM, "Willy Sudiarto Raharjo" notifications@github.com wrote:

is there any reason for you to set the environment variable DESKTOP_SESSION? I saw that KDE and other DE doesn't set them in xinitrc.{kde,xfce}

Reply to this email directly or view it on GitHubhttps://github.com/mateslackbuilds/msb/issues/2#issuecomment-35352935 .

willysr commented 10 years ago

Ah... you should check KNOWN ISSUES documentation it's all there and how to fix the problem as well :)

let me know after you apply the fix in the documentation

cdr255 commented 10 years ago

Thank You very much for Your quick replies!

However, I had applied these fixes immediately after installing. It may be worth nothing that caja, Dropbox, and to a certain degree firefox were all able to function correctly without this change. However, anything that explicitly called xdg-open (near as I can tell, but especially browsers, download managers, and image viewers trying to pass an image to each other) would instead attempt to open the file (no matter what it was) in firefox.

After a decent amount of poking around online, I realized the following:

The problem wasn't the mime defaults, the problem was that xdg-open wasn't following the chain to see them. If I can trace the way the xdg-open code flows without the DESKTOP_SESSION variable set to mate, it falls into a bit of kludge meant to substitute for either gvfs-open (which is what my system uses at the moment, since it is installed) or mate-open (which for some reason seems not to have been installed... at least for me). I have copied and pasted the relevant blocks of xdg-open below.

Deciding which path to follow:

detectDE()
{
    if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
    elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; 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 D\
E=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;
    elif [ x"$DESKTOP_SESSION" == x"mate" ]; then DE=mate;
    else DE=""
    fi
}

Tracing the logic drops me into the block below, which for some reason fails to react to any changes (including complete removal!) to my ~/.local/share/applications directory.

open_generic_xdg_mime()
{
    filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
    default=`xdg-mime query default "$filetype"`
    if [ -n "$default" ] ; then
        xdg_user_dir="$XDG_DATA_HOME"
        [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"

        xdg_system_dirs="$XDG_DATA_DIRS"
        [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/

        for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
            local file="$x/applications/$default"
            if [ -r "$file" ] ; then
                command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
                command_exec=`which $command 2>/dev/null`
                if [ -x "$command_exec" ] ; then
                    $command_exec "$1"
                    if [ $? -eq 0 ]; then
                        exit_success
                    fi
                fi
            fi
        done
    fi
}

Defining this variable puts us, instead in the following block, which (to me) is much cleaner and more UNIX like:

open_mate()
{
    if gvfs-open --help 2>/dev/null 1>&2; then
        gvfs-open "$1"
    else
        mate-open "$1"
    fi

    if [ $? -eq 0 ]; then
    exit_success
    else
        exit_failure_operation_failed
    fi
}

I apologize if I am missing something obvious. I did go back and reread the KNOWN_ISSUES file included in the x86 directory, and double checked to make sure those changes had indeed been made. Having defined that variable, they are now also respected... which, when having the variable set to null, they are not.

Let me know what You think, and sorry for being such a bother.

willysr commented 10 years ago

Have you checked System > Preferences > Preferred Applications menu? Just to make sure you have set the default applications there

so far, it worked for me to set the default applications for some types defined there.

willysr commented 10 years ago

i think you are right i just tested on konsole by running xdg-open file.jpg and it opened on Firefox retested with export DESKTOP_SESSION=mate and it opened to gwenview (the application i set in my preffered applications).

I will make the changes when i'm home later on

Thanks for spotting it