@@ -361,12 +361,28 @@ draw_dir() {
361361
362362draw_img () {
363363 # Draw an image file on the screen using w3m-img.
364+
365+ # If we are on tmux, use the client's TERM.
366+ [[ $TMUX ]] && {
367+ type -p tmux & > /dev/null || {
368+ cmd_line " error: Couldn't find 'tmux'; is it in your PATH?"
369+ return
370+ }
371+
372+ for var in client_width client_height pane_width pane_height \
373+ pane_id window_visible_layout client_termname; {
374+ declare " $var =$( tmux display-message -p " #{$var }" ) "
375+ }
376+
377+ term=" $client_termname "
378+ }
379+
364380 # We can use the framebuffer; set win_info_cmd as appropriate.
365- [[ $( tty ) == /dev/tty[0-9] * && -w /dev/fb0 ]] &&
381+ [[ ${term := $TERM } == linux && -w /dev/fb0 ]] &&
366382 win_info_cmd=" fbset"
367383
368384 # X isn't running and we can't use the framebuffer, do nothing.
369- [[ -z $DISPLAY && $ win_info_cmd != fbset ]] &&
385+ [[ -z ${ DISPLAY}${ win_info_cmd} ]] &&
370386 return
371387
372388 # File isn't an image file, do nothing.
@@ -400,6 +416,21 @@ draw_img() {
400416 IFS=x read -r WIDTH HEIGHT <<< " ${BASH_REMATCH[1]}"
401417 fi
402418
419+ # Adjust the dimensions and offsets to the current tmux pane.
420+ [[ $TMUX ]] && {
421+ (( col_width= WIDTH/ client_width))
422+ (( line_height= HEIGHT/ client_height))
423+
424+ (( WIDTH= pane_width* col_width))
425+ (( HEIGHT= pane_height* line_height))
426+
427+ [[ $window_visible_layout =~ .* x[0-9]+,([0-9]+,[0-9]+),${pane_id#% } .* ]]
428+ IFS=, read -r tmux_xoffset tmux_yoffset <<< " ${BASH_REMATCH[1]}"
429+
430+ (( tmux_xoffset= tmux_xoffset* col_width))
431+ (( tmux_yoffset= tmux_yoffset* line_height))
432+ }
433+
403434 # Get the image size in pixels.
404435 read -r img_width img_height < <( " $w3m " <<< " 5;${list[scroll]}" )
405436
@@ -425,8 +456,8 @@ draw_img() {
425456
426457 # Display the image.
427458 printf ' 0;1;%s;%s;%s;%s;;;;;%s\n3;\n4\n' \
428- " ${ FFF_W3M_XOFFSET:- 0} " \
429- " ${ FFF_W3M_YOFFSET:- 0} " \
459+ $(( FFF_W3 M_XOFFSET+ tmux_xoffset )) \
460+ $(( FFF_W3 M_YOFFSET+ tmux_yoffset )) \
430461 " $img_width " \
431462 " $img_height " \
432463 " ${list[scroll]} " | " $w3m " & > /dev/null
@@ -436,8 +467,8 @@ draw_img() {
436467
437468 # Clear the image.
438469 printf ' 6;%s;%s;%s;%s\n3;' \
439- " ${ FFF_W3M_XOFFSET:- 0} " \
440- " ${ FFF_W3M_YOFFSET:- 0} " \
470+ $(( FFF_W3 M_XOFFSET+ tmux_xoffset )) \
471+ $(( FFF_W3 M_YOFFSET+ tmux_yoffset )) \
441472 " $WIDTH " \
442473 " $HEIGHT " | " $w3m " & > /dev/null
443474
0 commit comments