Advertisement
Guest User

pbarautohide

a guest
Jan 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import time
  3. import subprocess
  4. import re
  5. import logging
  6.  
  7. SCREEN_HEIGHT = 800
  8. PERCENT_LIMIT = 30
  9. SHOW_CMD = 'xdotool search --name Polybar windowmove --relative -- 0 30'
  10. HIDE_CMD = 'xdotool search --name Polybar windowmove --relative -- 0 -30'
  11. STARTUP_CMD = 'xdotool search --name Polybar windowmove --relative -- 0 -30'
  12.  
  13. logging.basicConfig(level=logging.INFO)
  14.  
  15. def get_y_position():
  16. xdotool_output = subprocess.check_output(
  17. 'xdotool getmouselocation --shell',
  18. shell=True).decode('utf-8')
  19. return int(re.search(r'Y=(\d{1,})', xdotool_output).groups()[0]) + 1
  20.  
  21. hidden = True
  22. subprocess.call(HIDE_CMD, shell=True)
  23. while True:
  24. y = get_y_position()
  25. time.sleep(.30)
  26. on_edge = y < SCREEN_HEIGHT / PERCENT_LIMIT
  27. logging.info("Got height %d. On edge: %s", y, str(on_edge))
  28. if on_edge and hidden:
  29. subprocess.call(SHOW_CMD, shell=True)
  30. hidden = False
  31. if (not on_edge) and (not hidden):
  32. subprocess.call(HIDE_CMD, shell=True)
  33. hidden = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement