diff --git a/1.1.md b/1.1.md index cf3515c0..cab60285 100644 --- a/1.1.md +++ b/1.1.md @@ -31,6 +31,7 @@ at launch or in script. **Window Manager:** - Added support for `$XINITRC` +- Added support for `xprop` **Shell:** diff --git a/README.md b/README.md index 1c287395..029d856a 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ https://github.com/dylanaraps/fetch/wiki/Customizing-Info - **Note:** The script can now also use iTerm2's builtin image rendering instead of w3m!
Enable it by changing `$image_backend` to `iterm2` or by using the launch flag `--image_backend`. - Image Cropping, Resizing etc: `ImageMagick` -- More accurate window manager detection: `wmctrl` +- More accurate window manager detection: `wmctrl` or `xprop` **Linux / BSD:** diff --git a/fetch b/fetch index 07a1bd75..36c98484 100755 --- a/fetch +++ b/fetch @@ -12,7 +12,7 @@ # Optional Dependencies: (You'll lose these features without them) # Displaying Images: w3m + w3m-img # Image Cropping: ImageMagick -# More accurate window manager detection: wmctrl +# More accurate window manager detection: wmctrl or xprop # [ Linux / BSD ] Wallpaper Display: feh, nitrogen or gsettings # [ Linux / BSD ] Current Song: mpc or cmus # [ Linux / BSD ] Resolution detection: xorg-xdpyinfo @@ -652,39 +652,54 @@ getshell () { # Window Manager {{{ getwindowmanager () { + # Check for window manager using wmctrl and xprop if type -p wmctrl >/dev/null 2>&1; then windowmanager="$(wmctrl -m | head -n1)" windowmanager=${windowmanager/Name: } - elif [ "$XDG_CURRENT_DESKTOP" ]; then - windowmanager="$XDG_CURRENT_DESKTOP" + elif type -p xprop >/dev/null 2>&1; then + # Get id of window manager + wid=$(xprop -root _NET_SUPPORTING_WM_CHECK 2>/dev/null) + wid=${wid//* } - elif [ "$XINITRC" ]; then - windowmanager=$(grep "^[^#]*exec" "$XINITRC") - - elif [ -e "$HOME/.xinitrc" ]; then - windowmanager=$(grep "^[^#]*exec" "${HOME}/.xinitrc") - - else - case "$os" in - "Mac OS X") - windowmanager="Quartz Compositor" - ;; - - "Windows") - windowmanager="Explorer" - ;; - - *) - windowmanager="Unknown" - ;; - - esac + windowmanager="$(xprop -id $wid 8s _NET_WM_NAME 2>/dev/null)" + windowmanager=${windowmanager/*\(*\) = \"} + windowmanager=${windowmanager/\"} fi - windowmanager="${windowmanager/exec }" - windowmanager="${windowmanager/-session}" - windowmanager="${windowmanager^}" + # If the window manager wasn't found, fallback to + # checking files / envars. + if [ -z "$windowmanager" ]; then + if [ "$XDG_CURRENT_DESKTOP" ]; then + windowmanager="$XDG_CURRENT_DESKTOP" + + elif [ "$XINITRC" ]; then + windowmanager=$(grep "^[^#]*exec" "$XINITRC") + + elif [ -e "$HOME/.xinitrc" ]; then + windowmanager=$(grep "^[^#]*exec" "${HOME}/.xinitrc") + + else + case "$os" in + "Mac OS X") + windowmanager="Quartz Compositor" + ;; + + "Windows") + windowmanager="Explorer" + ;; + + *) + windowmanager="Unknown" + ;; + + esac + fi + + windowmanager="${windowmanager/exec }" + windowmanager="${windowmanager/-session}" + windowmanager="${windowmanager^}" + fi } # }}}