python3 + init display only once
This commit is contained in:
parent
a70466d83a
commit
17171ba701
19
Azot/X.py
19
Azot/X.py
|
@ -1,17 +1,20 @@
|
|||
from Xlib import display
|
||||
from time import sleep
|
||||
|
||||
from Azot.logger import warning
|
||||
|
||||
working_display = display.Display()
|
||||
working_screen = working_display.screen()
|
||||
root_window = working_screen.root
|
||||
|
||||
# Get screen resolution
|
||||
def get_geometry():
|
||||
while 1:
|
||||
try:
|
||||
width = display.Display().screen().width_in_pixels
|
||||
height = display.Display().screen().height_in_pixels
|
||||
|
||||
width = working_screen.width_in_pixels
|
||||
height = working_screen.height_in_pixels
|
||||
|
||||
return {"x": width, "y": height}
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
warning(str(e) + '\n' + 'Spleep for 10 second')
|
||||
sleep(10)
|
||||
|
||||
|
@ -20,9 +23,9 @@ def get_geometry():
|
|||
def get_cursor_position():
|
||||
while 1:
|
||||
try:
|
||||
data = display.Display().screen().root.query_pointer()._data
|
||||
data = root_window.query_pointer()._data
|
||||
|
||||
return {'x': data['root_x'], 'y': data['root_y']}
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
warning(str(e) + '\n' + 'Spleep for 10 second')
|
||||
sleep(10)
|
||||
sleep(10)
|
|
@ -15,6 +15,11 @@ corners = {
|
|||
|
||||
# Execute command
|
||||
def do():
|
||||
def task_exec():
|
||||
msg = type_exec(action)
|
||||
notify(msg)
|
||||
sleep(1)
|
||||
|
||||
position = get_cursor_position()
|
||||
for action in config['actions']:
|
||||
|
||||
|
@ -22,27 +27,19 @@ def do():
|
|||
if action['position'] != 'middle':
|
||||
if action['corner'] == 'top' or action['corner'] == 'bottom':
|
||||
if position['y'] == corners[ action['corner'] ] and position['x'] == corners[action['position']]:
|
||||
msg = type_exec(action)
|
||||
notify(msg)
|
||||
sleep(1)
|
||||
task_exec()
|
||||
elif action['corner'] == 'left' or action['corner'] == 'right':
|
||||
if position['x'] == corners[ action['position'] ] and position['y'] == corners[ action['corner'] ]:
|
||||
msg = type_exec(action)
|
||||
notify(msg)
|
||||
sleep(1)
|
||||
task_exec()
|
||||
|
||||
# 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']:
|
||||
msg = type_exec(action)
|
||||
notify(msg)
|
||||
sleep(1)
|
||||
task_exec()
|
||||
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']:
|
||||
msg = type_exec(action)
|
||||
notify(msg)
|
||||
sleep(1)
|
||||
task_exec()
|
||||
sleep(0.3)
|
||||
|
||||
|
||||
|
@ -64,12 +61,10 @@ def type_exec(action):
|
|||
# Get shell command output
|
||||
def get_cmd(cmd):
|
||||
out = os.popen(cmd).read()
|
||||
|
||||
return out
|
||||
|
||||
|
||||
# Show notify message
|
||||
def notify(msg):
|
||||
if msg is not None:
|
||||
get_cmd( "notify-send 'azot event' \"{0}\"".format(msg) )
|
||||
|
||||
get_cmd( "notify-send 'azot event' \"{0}\"".format(msg) )
|
Loading…
Reference in New Issue
Block a user