~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/50-fbsetbg-with-feh-skews-583704/util/fbsetbg

  • Committer: Package Import Robot
  • Author(s): Paul Tagliamonte
  • Date: 2010-08-12 21:16:02 UTC
  • mfrom: (0.1.1) (1.1.10)
  • Revision ID: package-import@ubuntu.com-20100812211602-3tsmzl9in5nmwz7z
Tags: 1.1.1+git20100807.0cc08f9-1
* debian/ dir has been cleaned out, complete repackage
  of most files.
* pulled new archive from git.fluxbox.org HEAD, saved as
  tar.gz.
* Added in fluxbox.* files from the old dfsg tree.
* Added in system.fluxbox-menu file from the old dfsg tree
* Added the source/format file to bump package source
  version from 1.0 to 3.0 (quilt). 
* Changed rules file to match the old dfsg setup so that
  fluxbox behaves nicely.
* Removed entries from copyright that no longer apply.
* Added theme based on Denis Brand ( naran )'s old theme.
* Added a background I whipped up.
* Changed compile flags to point to debian theme by default
* Adding a patch to have fluxbox use x-terminal-emulator
  over xterm. Closes: #591694 (LP: #580485)
* Adding a patch to allow titlebar-window dragging.
* Changed the flags in rules to pull from a script. This script
  lets us un-hardcode what theme is default. Be sure there
  is a theme pack!
* Added comments to my patches.
* Removing debian/docs, empty file.
* Fixing fluxbox.desktop to remove all the warnings from
  desktop-file-validate
* Fixing libtool issue by running an update before
  configure in the rules script.
* Added a compile flag script to auto-detect what platform
  we are running on, and apply the correct theme. This
  should solve Ubuntnu issues later on.
* adding in a get-orig-source rule
* fixing the upstream version number to pinpoint
  the commit ( thanks, lfaraone ).
* adding a rule for get-orig-source. ( thanks again,
  lfaraone ).
* Updated rules to actually allow us to do a build from it
* Removed Denis from the uploaders ( as per an email
  conversation )
* Removing madduck from the uploaders ( thanks for asking,
  lfaraone. ). Thanks for your hard work, madduck.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# Set wallpaper for fluxbox.
4
 
#
5
 
# Copyright (c) 2003-2004 Han Boetes <han@mijncomputer.nl>
6
 
#
7
 
# Permission is hereby granted, free of charge, to any person obtaining
8
 
# a copy of this software and associated documentation files (the
9
 
# "Software"), to deal in the Software without restriction, including
10
 
# without limitation the rights to use, copy, modify, merge, publish,
11
 
# distribute, sublicense, and/or sell copies of the Software, and to
12
 
# permit persons to whom the Software is furnished to do so, subject to
13
 
# the following conditions:
14
 
#
15
 
# The above copyright notice and this permission notice shall be
16
 
# included in all copies or substantial portions of the Software.
17
 
#
18
 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
 
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
 
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
 
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
 
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
 
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
 
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 
 
26
 
# Portability notes:
27
 
# To guarantee this script works on all platforms that support fluxbox
28
 
# please keep the following restrictions in mind:
29
 
#
30
 
# - don't use if ! command;, use command; if [ $? -ne 0 ];
31
 
# - don't use [ -e file ] use [ -r file ]
32
 
# - don't use $(), use ``
33
 
# - don't use ~, use ${HOME}
34
 
# - don't use id -u or $UID, use whoami
35
 
# - don't use echo -e
36
 
# - getopts won't work on all platforms, but the config-file can
37
 
#   compensate for that.
38
 
# - various software like grep/sed/perl may be not present or not
39
 
#   the version you have. for example grep '\W' only works on gnu-grep.
40
 
#   Keep this in mind, use bare basic defaults.
41
 
# - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash.
42
 
 
43
 
# TODO purheps: xprop -root _WIN_WORKSPACE
44
 
# _NET_CURRENT_DESKTOP
45
 
 
46
 
# The wallpapersetter is selected in this order
47
 
wpsetters="${wpsetters:=Esetroot wmsetbg feh hsetroot chbg display qiv xv xsri xli xsetbg}" # broken icewmbg'
48
 
lastwallpaper="${HOME}/.fluxbox/lastwallpaper"
49
 
 
50
 
 
51
 
WHOAMI=`whoami`
52
 
[ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin
53
 
 
54
 
command="`basename \"$0\"`"
55
 
 
56
 
 
57
 
# Functions
58
 
display_usage() {
59
 
    cat << EOF
60
 
Usage: $command [-u/-U [wallpapersetter]] [-fFcCtTaA] /path/to/wallpaper
61
 
       $command [-u/-U [wallpapersetter]] [-fFcCtTaA] -r/-R /path/to/wallpaperdirectory
62
 
       $command [-b/-B fbsetrootoptions]
63
 
       $command [-lhip]
64
 
Use \`\`$command -h'' for a complete help message.
65
 
 
66
 
EOF
67
 
}
68
 
 
69
 
display_help() {
70
 
    display_usage
71
 
    cat << EOF
72
 
 
73
 
Options:
74
 
 
75
 
    -f  Set fullscreen wallpaper (default).
76
 
    -c  Set centered wallpaper.
77
 
    -t  Set tiled wallpaper.
78
 
    -a  Set maximized wallpaper, preserving aspect.
79
 
        ( if your bgsetter doesn't support this
80
 
          we fall back to -f )
81
 
    -u  Use specified wallpapersetter, use no argument to forget.
82
 
    -b  Forward the options to fbsetroot.
83
 
    -r  set random wallpaper from a directory
84
 
 
85
 
    -F,-C,-T,-A,-U,-B,-R same as uncapsed but without remembering.
86
 
 
87
 
    -h  Display this help.
88
 
 
89
 
    -l  Set previous wallpaper.
90
 
 
91
 
    -i  Information about selected wallpaper command.
92
 
    -d  (deprecated, use -i) Debug info.
93
 
    -p  Tips.
94
 
 
95
 
 
96
 
Files:
97
 
 
98
 
    ~/.fluxbox/lastwallpaper     In this file the wallpaper you set
99
 
                                 will be stored, for the -l option:
100
 
Environment variables:
101
 
    wpsetters   Wallpapersetters to use.
102
 
                example:
103
 
                  wpsetters=feh fbsetbg wallpaper.jpg
104
 
 
105
 
    DISPLAY     The display you want to set the wallpaper on.
106
 
                example:
107
 
                  DISPLAY=:0.0 fbsetbg -l
108
 
 
109
 
EOF
110
 
}
111
 
 
112
 
display_tips() {
113
 
    cat << EOF
114
 
Common tips to use with $command:
115
 
 
116
 
1) To replace all occurrences of bsetbg with $command in a file use this
117
 
   command:
118
 
 
119
 
   perl -pi -e 's,([^f]|^)bsetbg,$command,' filename
120
 
 
121
 
2) If you want the style to set the wallpaper and you want $command to
122
 
   remember the previous wallpaper put this in your ~/.fluxbox/init
123
 
 
124
 
   session.screen0.rootCommand:    $command -l
125
 
 
126
 
3) Use $command -i to find out what wallpapersetter $command will be
127
 
   used and what $command thinks about it.
128
 
 
129
 
EOF
130
 
}
131
 
 
132
 
find_it() {
133
 
    [ -n "$1" ] && hash $1 2> /dev/null
134
 
}
135
 
 
136
 
message() {
137
 
 
138
 
    # This Terminal detection method is inaccurate. Looking for a
139
 
    # replacement.
140
 
 
141
 
    # echo if we have terminal output, otherwise pop up a window
142
 
    # if [ -t 1 ]; then
143
 
    #     echo "$command: $@"
144
 
    # else
145
 
    extra_args="-default okay"
146
 
        if find_it gxmessage; then
147
 
            gxmessage $extra_args -center "$command: $@" &
148
 
        else
149
 
            xmessage $extra_args -center "$command: $@" &
150
 
        fi
151
 
    # fi
152
 
}
153
 
 
154
 
remembercommand() {
155
 
    grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp
156
 
    mv -f ${lastwallpaper}.tmp ${lastwallpaper}
157
 
    if [ "$option" = fbsetroot ]; then
158
 
        echo $option"|$wallpaper|$style|"$DISPLAY >> $lastwallpaper
159
 
        return
160
 
    fi
161
 
    # Make dir/../../path/file.jpg work
162
 
    case $wallpaper in
163
 
        # no spaces allowed between the varname and '|'
164
 
        /*) echo $option $option2"|$wallpaper|$style|"$DISPLAY >> $lastwallpaper ;;
165
 
        *)  echo $option $option2"|$PWD/$wallpaper|$style|"$DISPLAY >> $lastwallpaper ;;
166
 
    esac
167
 
}
168
 
 
169
 
debugfbsetbg() {
170
 
    echo
171
 
    echo $debugstory
172
 
    echo $sad_esetroot_story
173
 
    exit 0
174
 
}
175
 
 
176
 
use_fbsetroot() {
177
 
 
178
 
    fbsetroot $wallpaper
179
 
    if [ ! "$remember" = false ]; then
180
 
        remembercommand
181
 
    fi
182
 
    exit 0
183
 
}
184
 
 
185
 
 
186
 
if [ $# -eq 0 ]; then
187
 
    message "no options given"
188
 
    display_usage
189
 
    exit 1
190
 
fi
191
 
 
192
 
# create directory and last wallpaper file 
193
 
if [ ! -d  "$HOME/.fluxbox" ]; then
194
 
        mkdir "$HOME/.fluxbox"
195
 
    touch ${lastwallpaper}
196
 
fi
197
 
 
198
 
unset debug setterfromcommandline
199
 
# Parse command-line options
200
 
while [ $# -gt 0 ]; do
201
 
    case "$1" in
202
 
        -u)
203
 
            if find_it "$2"; then
204
 
                grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
205
 
                echo "wpsetters $2" >> ${lastwallpaper}.tmp
206
 
                mv ${lastwallpaper}.tmp $lastwallpaper
207
 
                WPSETTER=$2
208
 
                setterfromcommandline=true
209
 
            elif [ -z "$2" ]; then
210
 
                grep -v wpsetters $lastwallpaper > ${lastwallpaper}.tmp
211
 
                mv ${lastwallpaper}.tmp $lastwallpaper
212
 
                message "wpsetter removed from historyfile"
213
 
                exit 0
214
 
            else
215
 
                message "Couldn't find \"$2\" for wallpapersetter"
216
 
                display_usage
217
 
                exit 1
218
 
            fi
219
 
            shift 2 ;;
220
 
        -U)
221
 
            if find_it "$2"; then
222
 
                WPSETTER=$2
223
 
                setterfromcommandline=true
224
 
            else
225
 
                message "Couldn't find \"$2\" for wallpapersetter"
226
 
                display_usage
227
 
                exit 1
228
 
            fi
229
 
            shift 2 ;;
230
 
        -d|-i) debug=true
231
 
            break ;;
232
 
        -a) option='$aspect'
233
 
            shift ;;
234
 
        -f) option='$full'
235
 
            shift ;;
236
 
        -c) option='$center'
237
 
            shift ;;
238
 
        -t) option='$tile'
239
 
            shift ;;
240
 
        -A) option='$aspect'
241
 
            remember=false
242
 
            shift ;;
243
 
        -F) option='$full'
244
 
            remember=false
245
 
            shift ;;
246
 
        -C) option='$center'
247
 
            remember=false
248
 
            shift ;;
249
 
        -T) option='$tile'
250
 
            remember=false
251
 
            shift ;;
252
 
        -b) option=fbsetroot
253
 
            shift
254
 
            wallpaper=$*
255
 
            break ;;
256
 
        -B) option=fbsetroot
257
 
            shift
258
 
            wallpaper=$*
259
 
            remember=false
260
 
            break ;;
261
 
        -r) option2=$option
262
 
            option=random
263
 
            wallpaper=$2 # in this case it's a dir
264
 
            break ;;
265
 
        -R) option2=$option
266
 
            option=random
267
 
            wallpaper=$2 # in this case it's a dir
268
 
            remember=false
269
 
            break ;;
270
 
        -l)
271
 
            if [ -r "$lastwallpaper" ]; then
272
 
                option=`grep "|${DISPLAY}$"    $lastwallpaper|cut -d'|' -f1`
273
 
                option2=`echo $option|cut -d' ' -f2`
274
 
                option=`echo $option|cut -d' ' -f1`
275
 
                wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
276
 
                if [ -z "$wallpaper" ]; then
277
 
                    option=`grep "|${DISPLAY}.0$"    $lastwallpaper|cut -d'|' -f1`
278
 
                    option2=`echo $option|cut -d' ' -f2`
279
 
                    option=`echo $option|cut -d' ' -f1`
280
 
                    wallpaper=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f2`
281
 
                fi
282
 
                if [ -z "$wallpaper" ]; then
283
 
                    message "No previous wallpaper recorded for display ${DISPLAY}"
284
 
                    exit 1
285
 
                fi
286
 
            else
287
 
                message "No previous wallpaper recorded for display ${DISPLAY}"
288
 
                exit 1
289
 
            fi
290
 
            remember=false
291
 
            break ;;
292
 
        -z)
293
 
            if [ -r "$lastwallpaper" ]; then
294
 
                option=`grep "|${DISPLAY}$"    $lastwallpaper|cut -d'|' -f1`
295
 
                option2=`echo $option|cut -d' ' -f2`
296
 
                option=`echo $option|cut -d' ' -f1`
297
 
                style=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f3`
298
 
                wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2`
299
 
                if [ -z "$wallpaper" ]; then
300
 
                    option=`grep "|${DISPLAY}.0$"    $lastwallpaper|cut -d'|' -f1`
301
 
                    option2=`echo $option|cut -d' ' -f2`
302
 
                    option=`echo $option|cut -d' ' -f1`
303
 
                    style=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f3`
304
 
                    wallpaper=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f2`
305
 
                fi
306
 
            fi
307
 
            if [ "$style" != "style" -a -n "$wallpaper" ]; then
308
 
                remember=false
309
 
                break
310
 
            fi
311
 
            style="style"
312
 
            shift ;;
313
 
        -Z)
314
 
            style="style"
315
 
            shift ;;
316
 
        -p) display_tips ; exit 0 ;;
317
 
        -h) display_help ; exit 0 ;;
318
 
        --)
319
 
            message "$command doesn't recognize -- gnu-longopts."
320
 
            message 'Use $command -h for a help message.'
321
 
            display_usage
322
 
            exit 1 ;;
323
 
        -*)
324
 
            message "unrecognized option "\`"$1'"
325
 
            display_usage
326
 
            exit 1 ;;
327
 
        *)
328
 
            if [ "$option" = random ]; then
329
 
                option='$aspect'
330
 
            elif [ ! -r "$1" ]; then
331
 
                message "$1 isn't an existing wallpaper or a valid option."
332
 
                display_usage
333
 
                exit 1
334
 
            elif [ -z "$1" ]; then
335
 
                message 'No wallpaper to set'
336
 
                display_usage
337
 
                exit 1
338
 
            else
339
 
                wallpaper=$1
340
 
                break
341
 
            fi ;;
342
 
    esac
343
 
done
344
 
 
345
 
if [ "$option" = "fbsetroot" ]; then
346
 
    use_fbsetroot
347
 
fi
348
 
 
349
 
# Find the default wallpapersetter
350
 
if [ "$setterfromcommandline" != true ]; then
351
 
    if [ -r "$lastwallpaper" ]; then
352
 
        wpsetters="`awk '/wpsetters/ {print $2}' $lastwallpaper` $wpsetters"
353
 
    fi
354
 
    for wpsetter in $wpsetters; do
355
 
        if find_it $wpsetter; then
356
 
            if [ ! "$wpsetter" = Esetroot ]; then
357
 
                WPSETTER=$wpsetter
358
 
                break
359
 
            elif ldd `which Esetroot`|grep libImlib 2>&1 > /dev/null; then
360
 
                WPSETTER=$wpsetter
361
 
                break
362
 
            else
363
 
                sad_esetroot_story="I also found Esetroot, but it doesn't have support for setting wallpapers. You need to install libimlib2 and rebuild Eterm to get it working."
364
 
            fi
365
 
        fi
366
 
    done
367
 
fi
368
 
 
369
 
standardrant=\
370
 
"$WPSETTER doesn't set the wallpaper properly. Transparency for fluxbox and
371
 
apps like aterm and xchat won't work right with it. Consider installing
372
 
feh, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use
373
 
them instead."
374
 
 
375
 
standardok=\
376
 
"$WPSETTER is a nice wallpapersetter. You won't have any problems."
377
 
 
378
 
case $WPSETTER in
379
 
    chbg)
380
 
        full='-once -mode maximize'
381
 
        tile='-once -mode tile'
382
 
        center='-once -mode center'
383
 
        aspect='-once -mode smart -max_grow 100 -max_size 100'
384
 
        debugstory="chbg supports all features but it doesn't report errors. I reported this bug to the chbg developers."
385
 
        ;;
386
 
    xsri)
387
 
        full='--center-x --center-y --scale-width=100 --scale-height=100'
388
 
        tile='--tile'
389
 
        center='--center-x --center-y --color=black'
390
 
        aspect='--center-x --center-y --scale-width=100 --scale-height=100 --keep-aspect --color=black'
391
 
        debugstory=$standardok
392
 
        ;;
393
 
    display)
394
 
        full="`xwininfo -root 2> /dev/null|grep geom` -window root"
395
 
        tile='-window root'
396
 
        center='-backdrop -window root'
397
 
        aspect=$full
398
 
        debugstory=$standardrant
399
 
        ;;
400
 
    Esetroot)
401
 
        full='-scale'
402
 
        tile=''
403
 
        center='-c'
404
 
        aspect='-fit'
405
 
        debugstory=$standardok
406
 
        ;;
407
 
    wmsetbg)
408
 
        full='-s -S'
409
 
        tile='-t'
410
 
        center='-b black -e'
411
 
        aspect='-b black -a -S'
412
 
        debugstory=$standardok
413
 
        ;;
414
 
    xsetbg)
415
 
        tile='-border black'
416
 
        center='-center -border black'
417
 
        aspect='-fullscreen -border black'
418
 
        full=$aspect #broken
419
 
        debugstory="xsetbg is actually xli. The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
420
 
        ;;
421
 
    xli)
422
 
        tile='-onroot -quiet -border black'
423
 
        center='-center -onroot -quiet -border black'
424
 
        aspect='-fullscreen -onroot -quiet -border black'
425
 
        full=$aspect #broken
426
 
        debugstory="The fillscreen option (-f) is broken, defaults to (-a). $standardrant"
427
 
        ;;
428
 
    qiv)
429
 
        full='--root_s'
430
 
        tile='--root_t'
431
 
        center='--root'
432
 
        aspect='-m --root'
433
 
        debugstory=$standardrant
434
 
        ;;
435
 
    xv)
436
 
        full='-max -smooth -root -quit'
437
 
        tile='-root -quit'
438
 
        center='-rmode 5 -root -quit'
439
 
        aspect='-maxpect -smooth -root -quit'
440
 
        debugstory=$standardrant
441
 
        ;;
442
 
    feh)
443
 
        full='--bg-scale'
444
 
        tile='--bg-tile'
445
 
        center='--bg-center'
446
 
        aspect=$full
447
 
        debugstory=$standardok
448
 
        ;;
449
 
    hsetroot)
450
 
        full='-fill'
451
 
        tile='-tile'
452
 
        center='-center'
453
 
        aspect='-full'
454
 
        debugstory=$standardok
455
 
        ;;
456
 
    icewmbg)
457
 
        tile='-s'
458
 
        full=$tile
459
 
        center=$tile
460
 
        aspect=$tile
461
 
        debugstory="icewmbg does support transparency, but only tiling. And I noticed odd
462
 
errormessages with aterm. Don't use it unless you have to."
463
 
        ;;
464
 
    '')
465
 
        message \
466
 
"I can't find an app to set the wallpaper with. You can install one in
467
 
many many ways but I will give you some simple advice: install Eterm and
468
 
you're set. Eterm provides Esetroot and thats a great wallpaper setter. I
469
 
recommend you install the package provided by your distro."
470
 
        exit 1
471
 
        ;;
472
 
esac
473
 
 
474
 
if [ "$debug" = true ]; then
475
 
    debugfbsetbg
476
 
    exit 0
477
 
fi
478
 
 
479
 
option=${option:='$full'}
480
 
option2=${option2:='$full'}
481
 
 
482
 
 
483
 
if [ -z "$DISPLAY" ]; then
484
 
    message "You are not connected to an X session\nPerhaps you should set the DISPLAY environment variable?"
485
 
    exit 1
486
 
fi
487
 
 
488
 
 
489
 
# random wallpaper code
490
 
if [ "$option" = random ]; then
491
 
    # Lets make one thing clear...
492
 
    wallpaperdir="$wallpaper"
493
 
    if [ -z "$wallpaperdir" ]; then
494
 
        message "No random wallpaper directory specified."
495
 
        exit 1
496
 
    fi
497
 
    if [ -d "$wallpaperdir" ]; then
498
 
        number_of_wallpapers=`ls "$wallpaperdir"|wc -l`
499
 
        if find_it random_number; then
500
 
            randomnumber=`random_number`
501
 
        # check if the program 'time' is available
502
 
        elif [ "$(command -v time)" ]; then
503
 
            randomnumber=`(echo $$ ;time ps; w ; date )2>&1 | cksum | cut -f1 -d' '`
504
 
        else
505
 
            randomnumber="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
506
 
        fi
507
 
        wallpapernumber=`expr $randomnumber % $number_of_wallpapers + 1`
508
 
        #remember previous wallpaper
509
 
        if [ ! "$remember" = false ]; then
510
 
            remembercommand
511
 
        fi
512
 
        remember=false
513
 
        #set -x
514
 
        wallpaper="$wallpaperdir/`ls \"$wallpaperdir\"|sed -n ${wallpapernumber}p`"
515
 
        option=$option2 # have to choose something...
516
 
    else
517
 
        message "Invalid random wallpaper directory specified."
518
 
        exit 1
519
 
    fi
520
 
fi
521
 
 
522
 
 
523
 
if [ ! -r "$wallpaper" ]; then
524
 
    message "Can't find wallpaper $wallpaper"
525
 
    exit 1
526
 
fi
527
 
 
528
 
 
529
 
$WPSETTER `eval echo $option` "$wallpaper"
530
 
if [ $? -ne 0 ]; then
531
 
    message "Something went wrong while setting the wallpaper.
532
 
Run '$WPSETTER "`eval echo $option` $wallpaper"' from an xterm to find out what."
533
 
    exit 1
534
 
fi
535
 
 
536
 
 
537
 
#remember previous wallpaper
538
 
if [ ! "$remember" = false ]; then
539
 
    remembercommand
540
 
fi