Skip to content

Instantly share code, notes, and snippets.

@siers
Created September 8, 2016 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siers/3b97d3f84347e8600985ce19bf5fb35b to your computer and use it in GitHub Desktop.
Save siers/3b97d3f84347e8600985ce19bf5fb35b to your computer and use it in GitHub Desktop.
Wait while xprintidle increases predictably thereby waiting until activity has been observed in the xorg
#!/usr/bin/env ruby
if %x{type xprintidle &> /dev/null; echo $?}.strip == '1'
raise 'xprintidle not found'
end
def idle
%x{xprintidle}.to_i
end
t = Time.now
i = idle - 100
wait = (ENV['IDLE_POLL'] || 100).to_i / 1000.0
loop do
sleep wait
prediction = (Time.now - t) * 1000.0 + i
break if prediction > idle
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment