Skip to content

Commit

Permalink
use IMV to preview images, it works on DWL wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed May 20, 2022
1 parent 391f061 commit 83a7264
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion ranger/ext/img_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import warnings
import json
import threading
from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, run
import time
from collections import defaultdict

import termios
Expand Down Expand Up @@ -779,3 +780,39 @@ def quit(self):
self.process.communicate()
finally:
timer_kill.cancel()


@register_image_displayer("imv")
class IMVImageDisplayer(ImageDisplayer):
"""Implementation of ImageDisplayer using imv
add following line into rc.conf to make it work
set preview_images_method imv
"""
is_initialized = False

def __init__(self):
self.process = None

def initialize(self):
""" start imv """
if (self.is_initialized and self.process.poll() is None
and not self.process.stdin.closed):
return

self.process = Popen(['imv'], cwd=self.working_dir, stdin=PIPE, universal_newlines=True)
self.is_initialized = True
sleep(5)

def draw(self, path, start_x, start_y, width, height):
self.initialize()
run(['imv-msg',str(self.process.pid),'close'])
run(['imv-msg',str(self.process.pid),'open',path])


def clear(self, start_x, start_y, width, height):
self.initialize()
run(['imv-msg',str(self.process.pid),'close'])

def quit(self):
if self.is_initialized and self.process.poll() is None:
self.process.terminate()

0 comments on commit 83a7264

Please sign in to comment.