2015-07-22 12:21:14 +03:00
|
|
|
import os
|
2015-07-28 12:28:37 +03:00
|
|
|
import Azot.config
|
|
|
|
from Azot.X import get_cursor_position
|
2015-07-22 14:07:24 +03:00
|
|
|
from time import sleep
|
2015-07-22 12:21:14 +03:00
|
|
|
|
|
|
|
# Globals
|
2015-07-28 12:28:37 +03:00
|
|
|
config = Azot.config.load()
|
2015-07-22 14:07:24 +03:00
|
|
|
corners = {
|
|
|
|
'top': config['corners']['top_corner'],
|
|
|
|
'right': config['corners']['right_corner'],
|
|
|
|
'bottom': config['corners']['bottom_corner'],
|
|
|
|
'left': config['corners']['left_corner']
|
|
|
|
}
|
2015-07-22 12:21:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Execute command
|
2015-07-22 14:07:24 +03:00
|
|
|
def do():
|
2016-05-19 11:01:10 +03:00
|
|
|
def task_exec():
|
|
|
|
msg = type_exec(action)
|
|
|
|
notify(msg)
|
2016-05-19 15:05:16 +03:00
|
|
|
sleep(config['after_exec_delay'])
|
2016-05-19 11:01:10 +03:00
|
|
|
|
2015-07-22 14:07:24 +03:00
|
|
|
position = get_cursor_position()
|
|
|
|
for action in config['actions']:
|
|
|
|
|
|
|
|
# angles
|
|
|
|
if action['position'] != 'middle':
|
|
|
|
if action['corner'] == 'top' or action['corner'] == 'bottom':
|
|
|
|
if position['y'] == corners[ action['corner'] ] and position['x'] == corners[action['position']]:
|
2016-05-19 11:01:10 +03:00
|
|
|
task_exec()
|
2015-07-22 14:07:24 +03:00
|
|
|
elif action['corner'] == 'left' or action['corner'] == 'right':
|
|
|
|
if position['x'] == corners[ action['position'] ] and position['y'] == corners[ action['corner'] ]:
|
2016-05-19 11:01:10 +03:00
|
|
|
task_exec()
|
2015-07-22 14:07:24 +03:00
|
|
|
|
|
|
|
# middles
|
|
|
|
elif action['position'] == 'middle':
|
|
|
|
if action['corner'] == 'top' or action['corner'] == 'bottom':
|
|
|
|
if position['y'] == corners[ action['corner'] ] and position['x'] > config['corners']['middle_x_start'] and position['x'] < config['corners']['middle_x_end']:
|
2016-05-19 11:01:10 +03:00
|
|
|
task_exec()
|
2015-07-22 14:07:24 +03:00
|
|
|
elif action['corner'] == 'left' or action['corner'] == 'right':
|
|
|
|
if position['x'] == corners[ action['corner'] ] and position['y'] > config['corners']['middle_y_start'] and position['y'] < config['corners']['middle_y_end']:
|
2016-05-19 11:01:10 +03:00
|
|
|
task_exec()
|
2016-05-19 15:05:16 +03:00
|
|
|
sleep(config['check_delay'])
|
2015-07-22 14:07:24 +03:00
|
|
|
|
|
|
|
|
2015-07-22 14:24:47 +03:00
|
|
|
# Detect type and execute
|
|
|
|
def type_exec(action):
|
|
|
|
if action['type'] == 'notify':
|
|
|
|
out = get_cmd(action['command'])
|
|
|
|
return out
|
|
|
|
elif action['type'] == 'exec':
|
|
|
|
get_cmd(action['command'])
|
|
|
|
return action['command']
|
2015-07-23 11:33:20 +03:00
|
|
|
elif action['type'] == 'simple':
|
|
|
|
get_cmd(action['command'])
|
2015-07-23 11:35:02 +03:00
|
|
|
return None
|
2015-07-22 14:24:47 +03:00
|
|
|
else:
|
|
|
|
return 'Unknown type!'
|
2015-07-22 12:21:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Get shell command output
|
|
|
|
def get_cmd(cmd):
|
2015-07-22 14:07:24 +03:00
|
|
|
out = os.popen(cmd).read()
|
|
|
|
return out
|
2015-07-22 12:21:14 +03:00
|
|
|
|
|
|
|
|
2015-07-22 14:07:24 +03:00
|
|
|
# Show notify message
|
|
|
|
def notify(msg):
|
2015-07-23 11:35:02 +03:00
|
|
|
if msg is not None:
|
2016-05-19 11:01:10 +03:00
|
|
|
get_cmd( "notify-send 'azot event' \"{0}\"".format(msg) )
|