mabox-tools/bin/mb-hotcorners
2020-02-18 17:24:18 +01:00

121 lines
4.3 KiB
Python
Executable File

#!/usr/bin/env python2.7
# bl-hotcorners:
# A script for adding hot corners to Openbox.
# Repackaged for BunsenLabs by John Crawley.
# Repackaged for Mabox by Daniel Napora.
# Originally written for CrunchBang Linux <http://crunchbang.org/>
# by Philip Newborough <corenominal@corenominal.org>
# ----------------------------------------------------------------------
from Xlib import display
from Xlib.ext.xtest import fake_input
from Xlib import X
from subprocess import Popen, PIPE, STDOUT
import sys, time, os, ConfigParser, re
check_intervall = 0.2
p = Popen(['xdotool','getdisplaygeometry'], stdout=PIPE, stderr=STDOUT)
Dimensions = p.communicate()
Dimensions = Dimensions[0].replace('\n', '')
Dimensions = Dimensions.split(' ')
width = int(Dimensions[0])
height = int(Dimensions[1])
hw = width / 2
rt = width - 1
bt = height - 1
def print_usage():
print "mb-hotcorners: usage:"
print " --help show this message and exit"
print " --kill attempt to kill any running instances"
print " --daemon run daemon and listen for cursor triggers"
print ""
exit()
if len(sys.argv) < 2 or sys.argv[1] == "--help":
print_usage()
elif sys.argv[1] == "--kill":
print "Attempting to kill any running instances..."
os.system('pkill -9 -f mb-hotcorners')
exit()
elif sys.argv[1] == "--daemon":
Config = ConfigParser.ConfigParser()
cfgdir = os.getenv("HOME")+"/.config/mb-hotcorners"
rcfile = cfgdir+"/mb-hotcornersrc"
bounce = 40
disp = display.Display()
root=display.Display().screen().root
def mousepos():
data = root.query_pointer()._data
return data["root_x"], data["root_y"], data["mask"]
def mousemove(x, y):
fake_input(disp, X.MotionNotify, x=x, y=y)
disp.sync()
try:
cfgfile = open(rcfile)
except IOError as e:
if not os.path.exists(cfgdir):
os.makedirs(cfgdir)
cfgfile = open(rcfile,'w')
Config.add_section('Hot Corners')
Config.set('Hot Corners','top_left_corner_command', 'dmenu_run')
Config.set('Hot Corners','top_right_corner_command', '')
Config.set('Hot Corners','bottom_left_corner_command', '')
Config.set('Hot Corners','bottom_right_corner_command', '')
Config.write(cfgfile)
cfgfile.close()
while True:
Config.read(rcfile)
time.sleep(check_intervall)
pos = mousepos()
if pos[0] == 0 and pos[1] == 0:
if Config.get('Hot Corners','top_left_corner_command') != '':
time.sleep(0.2)
pos = mousepos()
if pos[0] == 0 and pos[1] == 0:
mousemove(pos[0] + bounce, pos[1] + bounce)
os.system('(' + Config.get('Hot Corners','top_left_corner_command') + ') &')
mousemove(pos[0] + bounce, pos[1] + bounce)
time.sleep(2)
elif pos[0] == rt and pos[1] == 0:
if Config.get('Hot Corners','top_right_corner_command') != '':
time.sleep(0.2)
pos = mousepos()
if pos[0] == rt and pos[1] == 0 :
mousemove(pos[0] - bounce, pos[1] + bounce)
os.system('(' + Config.get('Hot Corners','top_right_corner_command') + ') &')
mousemove(pos[0] - bounce, pos[1] + bounce)
time.sleep(2)
elif pos[0] == 0 and pos[1] == bt:
if Config.get('Hot Corners','bottom_left_corner_command') != '':
time.sleep(0.2)
pos = mousepos()
if pos[0] == 0 and pos[1] == bt:
mousemove(pos[0] + bounce, pos[1] - bounce)
os.system('(' + Config.get('Hot Corners','bottom_left_corner_command') + ') &')
mousemove(pos[0] + bounce, pos[1] - bounce)
time.sleep(2)
elif pos[0] == rt and pos[1] == bt:
if Config.get('Hot Corners','bottom_right_corner_command') != '':
time.sleep(0.2)
pos = mousepos()
if pos[0] == rt and pos[1] == bt:
mousemove(pos[0] - bounce, pos[1] - bounce)
os.system('(' + Config.get('Hot Corners','bottom_right_corner_command') + ') &')
mousemove(pos[0] - bounce, pos[1] - bounce)
time.sleep(2)
else:
print_usage()