You are not logged in.

#1 2019-04-27 13:10:31

ohnonot
...again
Registered: 2015-09-29
Posts: 3,773
Website

feh wallpaper script & tips

the wallpaper script

what it does:

  • gets your screenresolution with xwininfo & awk (multimonitor folks: does this work?)

  • make that 90% - that will be the size of the

  • thumbnail window generated from all images found in the folders passed to feh

  • clicking on one opens it in another window - there you can set it as a wallpaper

#!/bin/sh

# $@ = list of folders to be searched for images

# tested with
# feh version 3.1.3
# Compile-time switches: curl exif help stat64 verscmp xinerama

# NOTE 1: feh distiguishes between closing a window and exiting completely.
# the default key for closing a window is x
# the default key for exiting is q
# so if you look at a wallpaper full size, then press 'q', feh will close completely, incl. the thumbnail window.
# you could change this by unsetting the quit action and assigning 'q' to the close action:
# quit
# close q
# (add this to ~/.config/feh/keys)
# that way you have to press 'q' twice to exit completely.

# NOTE 2:
# scrolling up and down works with arrow keys Up/Down.
# the Left/Right arrow keys do not work in an intuitive way.
# you can scroll up and down with keys but will need to click on the desired image.

# get screen resolution
width="$(xwininfo -root | awk '/Width/ {print $2}')"
height="$(xwininfo -root | awk '/Height/ {print $2}')"
# limit window size to 90% of screen size
width="$(((width/10)*9))"
height="$(((height/10)*9))"

# how many rows and columns of thumbnails?
divider=8
thumbheight=$((height/divider))
thumbwidth=$((width/divider))

# feh adds 5 pixels of background below each thumbnail
fehquirk=5

# it scrolls down 1 row of images at a time
scrollstep=$(( (thumbheight+fehquirk) * 1 ))

# recursive? add -r
feh -r -t --cache-thumbnails --no-menus --index-info '' --ignore-aspect --stretch \
-g ${width}x$height --limit-width $width --thumb-width $thumbwidth --thumb-height $thumbheight \
--scroll-step $scrollstep --action ";feh --title='%f --- %wx%hpx' -g ${width}x$height %F" "$@"
#--bg $HOME/.config/scripts/feh/grey.gif
tips
  • if you use thumbnail mode and see blue-tinted thumbnails with an X after clicking on them, prepend a semicolon to your action:

    --action ";feh %F"
  • feh has config files for mouse buttons & keyboard keys, but not a general config file. you can define various themes however; copy /usr/share/doc/feh/examples/themes to ~/.config/feh/ and read it.
    the best thing (imo): you can add a default theme called 'feh', e.g.:

    feh --insecure --output-dir ~/.config/feh/saved_images --scale-down --action9 ';[Edit in GIMP] gimp %f' --draw-tinted \
    --fontpath "/usr/share/fonts/TTF" --font "iosevka-medium.ttf/12" --menu-font "iosevka-medium.ttf/12"

    These options will apply when you open feh normally (without specifying a theme)

  • feh can load images straight from the internet.

...and many more.

Last edited by ohnonot (2019-04-27 13:12:36)

Offline

#2 2019-04-27 13:58:46

damo
....moderator....
Registered: 2015-08-20
Posts: 4,966

Re: feh wallpaper script & tips

ohnonot wrote:
the wallpaper script

what it does:

  • gets your screenresolution with xwininfo & awk (multimonitor folks: does this work?)

....

This doesn't work with a multimonitor setup. There is a BL utility script, bl-xinerama-prop, which you could use. There is a function in bl-obthemes (BLOB) which utilizes this, and could be adapted for your script:

function getActiveMonitorDimensions(){   # set width and height for View dialog
    declare -a dim=()
    dim=($(bl-xinerama-prop))
    W=$(( ${dim[0]} / 3 ))
    H=$(( ${dim[1]} / 3 * 2 ))
    [[ $W =~ ^[0-9]+$ ]] && [[ $H =~ ^[0-9]+$ ]] || {
        print 'Error in getActiveMonitorDimensions'
        exit 1
    }
}

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2019-04-28 06:45:06

ohnonot
...again
Registered: 2015-09-29
Posts: 3,773
Website

Re: feh wallpaper script & tips

I have a spare monitor but no way to connect it...

may i ask how exactly my xwininfo hack fails with multiple monitors?

Offline

#4 2019-04-28 09:05:58

damo
....moderator....
Registered: 2015-08-20
Posts: 4,966

Re: feh wallpaper script & tips

ohnonot wrote:

I have a spare monitor but no way to connect it...

may i ask how exactly my xwininfo hack fails with multiple monitors?

The "desktop" is the whole of the monitors' real estate, so the feh window crosses both. With different-sized monitors I get this:
Screenshot_2019-04-28_09-57-40.th.jpg

I think the script also needs to deal with no "$@" being passed - otherwise there are multiple errors in terminal output.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#5 2019-04-28 09:24:29

damo
....moderator....
Registered: 2015-08-20
Posts: 4,966

Re: feh wallpaper script & tips

This is working, although the feh window is placed on the primary monitor.

function getActiveMonitorDimensions(){   # set width and height for feh window
    declare -a dim=()
    dim=($(bl-xinerama-prop))
    width=${dim[0]}
    height=${dim[1]}
    [[ $width =~ ^[0-9]+$ ]] && [[ $height =~ ^[0-9]+$ ]] || {
        print 'Error in getActiveMonitorDimensions'
        exit 1
    }
}

# get screen resolution
#width="$(xwininfo -root | awk '/Width/ {print $2}')"
#height="$(xwininfo -root | awk '/Height/ {print $2}')"
getActiveMonitorDimensions

# limit window size to 90% of screen size
width="$(((width/10)*9))"
height="$(((height/10)*9))"

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#6 2019-06-03 00:19:04

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: feh wallpaper script & tips

In theory this should work.
Keep in mind that this is made with an imaginary monitor smile

#!/bin/bash

# Determine display(s) and resolution(s)
while read a b c d ; do
    case "$b" in
    connected)
        case "$c" in
        primary)
            pri_x=${d%%x*}
            pri_y=${d%%+*} ; pri_y=${pri_y#*x}
            ;;
        [0-9]*)
            sec_x=${c%%x*}
            sec_y=${c%%+*} ; sec_y=${sec_y#*x}
            ;;
        esac
    esac
done < <(xrandr -q)


# Store work area here
read -a net_work < <(xprop -root _NET_WORKAREA)

largest_x=$pri_x
[[ $sec_x -gt $largest_x ]] && largest_x=$sec_x

largest_y=$pri_y
[[ $sec_y -gt $largest_y ]] && largest_y=$sec_y

smallest_x=$pri_x
[[ $sec_x -lt $smallest_x ]] && smallest_x=$sec_x

smallest_y=$pri_y
[[ $sec_y -lt $smallest_y ]] && smallest_y=$sec_y


# If the monitors are arranged horizontally
if [ "${net_work[4]}" != "${largest_x}," ]; then
    width=$(($pri_x + $sec_x))
    height=$((${smallest_y}-${net_work[3]}))
# If the monitors are arranged vertically
elif [ "${net_work[5]}" != "${largest_y}," ]; then
    width=$smallest_x
    height=$(($pri_y + $sec_y))
# If there is only one monitor
elif [ -z "$pri_x" ] || [ -z "$sec_x" ]; then
    echo "Only one monitor"
    width=$largest_x
    height=$largest_y
else
    width=$largest_x
    height=$largest_y
fi

# minus panel strut
#width=$(($largest_x - ${net_work[2]%,*}))
#height=$(($largest_y - ${net_work[3]}%,*}))

#####################
# ohnonot's script  #
#####################

# $@ = list of folders to be searched for images


# tested with
# feh version 3.1.3
# Compile-time switches: curl exif help stat64 verscmp xinerama

# NOTE 1: feh distiguishes between closing a window and exiting completely.
# the default key for closing a window is x
# the default key for exiting is q
# so if you look at a wallpaper full size, then press 'q', feh will close completely, incl. the thumbnail window.
# you could change this by unsetting the quit action and assigning 'q' to the close action:
# quit
# close q
# (add this to ~/.config/feh/keys)
# that way you have to press 'q' twice to exit completely.

# NOTE 2:
# scrolling up and down works with arrow keys Up/Down.
# the Left/Right arrow keys do not work in an intuitive way.
# you can scroll up and down with keys but will need to click on the desired image.

# limit window width to 90%
width="$(((width/10)*9))"

# limit window height to 90%
height="$(((height/10)*9))"

# how many rows and columns of thumbnails?
divider=8
thumbheight=$((height/divider))
thumbwidth=$((width/divider))

# feh adds 5 pixels of background below each thumbnail
fehquirk=5

# it scrolls down 1 row of images at a time
scrollstep=$(( (thumbheight+fehquirk) * 1 ))

echo ${width}x${height}
# recursive? add -r
feh -r -t --cache-thumbnails --no-menus --index-info '' --ignore-aspect --stretch \
-g ${width}x$height --limit-width $width --thumb-width $thumbwidth --thumb-height $thumbheight \
--scroll-step $scrollstep --action ";feh --title='%f --- %wx%hpx' -g ${width}x${height} %F" "$@"
#--bg $HOME/.config/scripts/feh/grey.gif

Edit - that part "minus the panel strut" will not work, panel height should be used instead. Disabled for now.

Last edited by misko_2083 (2019-06-03 01:37:47)

Offline

Board footer

Powered by FluxBB