Search code examples
vimthemeswebcamgnomelight-sensor

Howto create vim bundle to switch theme depending on webcam light measurement


I have seen several tricks to switch vim theme depending on the time of day, but I want to switch depending on the light in the room and thought that maybe I could use the webcam. Has anyone seen such a vim bundle?

If I where to take an image with the webcam and take an average rgb value once every minute from the image I would not know how much the image was brightened by the camera/drivers.

I would be using it with Arch Linux with Gnome on a ThinkPad, it would also be nice to use this for theming of other applications as well.

Any ideas?


Solution

  • The accepted answer here claims to get usable results; they use downscaling of the image for averaging and then measure the maximum luminosity(?) of the thumbnail. There's no mention of any correction for adjustments done by the camera driver. You will probably have to do some calibration.

    The linked solution uses python and openCV, so it should work with most cameras on linux. Also, you can pretty easily write vim plugins in python. It might not be a good idea to poll a script like this every minute, though, since there is no good support for asynchronous operations in vim.

    One cheap alternative would be to have the purely python-based light measurement running in its own process and communicating with vim by calling vim --servername foo --remote-send [command]. This only works as long as you have only one vim instance, though.