Merge pull request #1 from vit1-irk/master
Починки и "улучшения" по плану
This commit is contained in:
commit
7879cd5e38
19
Azot/X.py
19
Azot/X.py
|
@ -1,17 +1,20 @@
|
||||||
from Xlib import display
|
from Xlib import display
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from Azot.logger import warning
|
from Azot.logger import warning
|
||||||
|
|
||||||
|
working_display = display.Display()
|
||||||
|
working_screen = working_display.screen()
|
||||||
|
root_window = working_screen.root
|
||||||
|
|
||||||
# Get screen resolution
|
# Get screen resolution
|
||||||
def get_geometry():
|
def get_geometry():
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
width = display.Display().screen().width_in_pixels
|
width = working_screen.width_in_pixels
|
||||||
height = display.Display().screen().height_in_pixels
|
height = working_screen.height_in_pixels
|
||||||
|
|
||||||
return {"x": width, "y": height}
|
return {"x": width, "y": height}
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
warning(str(e) + '\n' + 'Spleep for 10 second')
|
warning(str(e) + '\n' + 'Spleep for 10 second')
|
||||||
sleep(10)
|
sleep(10)
|
||||||
|
|
||||||
|
@ -20,9 +23,9 @@ def get_geometry():
|
||||||
def get_cursor_position():
|
def get_cursor_position():
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
data = display.Display().screen().root.query_pointer()._data
|
data = root_window.query_pointer()._data
|
||||||
|
|
||||||
return {'x': data['root_x'], 'y': data['root_y']}
|
return {'x': data['root_x'], 'y': data['root_y']}
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
warning(str(e) + '\n' + 'Spleep for 10 second')
|
warning(str(e) + '\n' + 'Spleep for 10 second')
|
||||||
sleep(10)
|
sleep(10)
|
|
@ -15,6 +15,11 @@ corners = {
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
def do():
|
def do():
|
||||||
|
def task_exec():
|
||||||
|
msg = type_exec(action)
|
||||||
|
notify(msg)
|
||||||
|
sleep(config['after_exec_delay'])
|
||||||
|
|
||||||
position = get_cursor_position()
|
position = get_cursor_position()
|
||||||
for action in config['actions']:
|
for action in config['actions']:
|
||||||
|
|
||||||
|
@ -22,28 +27,20 @@ def do():
|
||||||
if action['position'] != 'middle':
|
if action['position'] != 'middle':
|
||||||
if action['corner'] == 'top' or action['corner'] == 'bottom':
|
if action['corner'] == 'top' or action['corner'] == 'bottom':
|
||||||
if position['y'] == corners[ action['corner'] ] and position['x'] == corners[action['position']]:
|
if position['y'] == corners[ action['corner'] ] and position['x'] == corners[action['position']]:
|
||||||
msg = type_exec(action)
|
task_exec()
|
||||||
notify(msg)
|
|
||||||
sleep(1)
|
|
||||||
elif action['corner'] == 'left' or action['corner'] == 'right':
|
elif action['corner'] == 'left' or action['corner'] == 'right':
|
||||||
if position['x'] == corners[ action['position'] ] and position['y'] == corners[ action['corner'] ]:
|
if position['x'] == corners[ action['position'] ] and position['y'] == corners[ action['corner'] ]:
|
||||||
msg = type_exec(action)
|
task_exec()
|
||||||
notify(msg)
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
# middles
|
# middles
|
||||||
elif action['position'] == 'middle':
|
elif action['position'] == 'middle':
|
||||||
if action['corner'] == 'top' or action['corner'] == 'bottom':
|
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']:
|
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)
|
task_exec()
|
||||||
notify(msg)
|
|
||||||
sleep(1)
|
|
||||||
elif action['corner'] == 'left' or action['corner'] == 'right':
|
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']:
|
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)
|
task_exec()
|
||||||
notify(msg)
|
sleep(config['check_delay'])
|
||||||
sleep(1)
|
|
||||||
sleep(0.3)
|
|
||||||
|
|
||||||
|
|
||||||
# Detect type and execute
|
# Detect type and execute
|
||||||
|
@ -64,12 +61,10 @@ def type_exec(action):
|
||||||
# Get shell command output
|
# Get shell command output
|
||||||
def get_cmd(cmd):
|
def get_cmd(cmd):
|
||||||
out = os.popen(cmd).read()
|
out = os.popen(cmd).read()
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
# Show notify message
|
# Show notify message
|
||||||
def notify(msg):
|
def notify(msg):
|
||||||
if msg is not None:
|
if msg is not None:
|
||||||
get_cmd( "notify-send 'azot event' \"{0}\"".format(msg) )
|
get_cmd( "notify-send 'azot event' \"{0}\"".format(msg) )
|
||||||
|
|
|
@ -2,16 +2,29 @@ import ast
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
from Azot.X import get_geometry
|
from Azot.X import get_geometry
|
||||||
|
from Azot.logger import info
|
||||||
|
|
||||||
# Globals
|
# Globals
|
||||||
config_path = os.environ['HOME'] + '/.config/azot/config.json'
|
config_dir = os.environ['HOME'] + '/.config/azot/'
|
||||||
|
config_path = config_dir + "config.json"
|
||||||
|
|
||||||
|
default_config_paths = ['/usr/share/doc/azot/config.sample.json', './config.sample.json']
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-c', '--config')
|
parser.add_argument('-c', '--config')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.config:
|
if args.config:
|
||||||
config_path = args.config
|
config_path = args.config
|
||||||
|
|
||||||
|
# Check config existence and copy if needed
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
for default_path in default_config_paths:
|
||||||
|
if os.path.exists(default_path):
|
||||||
|
os.makedirs(config_dir)
|
||||||
|
import shutil
|
||||||
|
info("Config doesn't exist in " + config_path + "; copying...")
|
||||||
|
shutil.copyfile(default_path, config_path)
|
||||||
|
break
|
||||||
|
|
||||||
# Load configuration from file
|
# Load configuration from file
|
||||||
def load():
|
def load():
|
||||||
|
@ -19,11 +32,17 @@ def load():
|
||||||
with open(config_path) as config_file:
|
with open(config_path) as config_file:
|
||||||
for line in config_file:
|
for line in config_file:
|
||||||
config += line
|
config += line
|
||||||
|
|
||||||
config_file.close()
|
config_file.close()
|
||||||
config = ast.literal_eval(config)
|
config = ast.literal_eval(config)
|
||||||
config['corners'] = get_middle_areas()
|
config['corners'] = get_middle_areas()
|
||||||
|
|
||||||
|
if not 'check_delay' in config.keys():
|
||||||
|
config['check_delay'] = 0.3
|
||||||
|
|
||||||
|
if not 'after_exec_delay' in config.keys():
|
||||||
|
config['after_exec_delay'] = 1
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +59,7 @@ def get_middle_areas():
|
||||||
middle_y_start = int( middle_y - middle_y_area_pixels )
|
middle_y_start = int( middle_y - middle_y_area_pixels )
|
||||||
middle_x_end = int( middle_x + middle_x_area_pixels )
|
middle_x_end = int( middle_x + middle_x_area_pixels )
|
||||||
middle_y_end = int( middle_y + middle_y_area_pixels )
|
middle_y_end = int( middle_y + middle_y_area_pixels )
|
||||||
|
|
||||||
corners = { 'left_corner': 0,
|
corners = { 'left_corner': 0,
|
||||||
'right_corner': geometry['x'] - 1,
|
'right_corner': geometry['x'] - 1,
|
||||||
'top_corner': 0,
|
'top_corner': 0,
|
||||||
|
@ -51,5 +70,4 @@ def get_middle_areas():
|
||||||
'middle_y_end': middle_y_end
|
'middle_y_end': middle_y_end
|
||||||
}
|
}
|
||||||
|
|
||||||
return corners
|
return corners
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from __future__ import print_function
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,4 +8,4 @@ def warning(msg):
|
||||||
|
|
||||||
# Print to STDOUT
|
# Print to STDOUT
|
||||||
def info(msg):
|
def info(msg):
|
||||||
print("INFO: ", msg, file=sys.stdout)
|
print("INFO: ", msg, file=sys.stdout)
|
|
@ -6,7 +6,7 @@ It's look like KWin or Compiz, e.t.c
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Edit config.sample.json and put it into ~/.config/azot/config.json
|
By default it's stored in ~/.config/azot/config.json
|
||||||
|
|
||||||
* type must be ''exec'', ''notify'' or ''simple''
|
* type must be ''exec'', ''notify'' or ''simple''
|
||||||
* exec: just show command
|
* exec: just show command
|
||||||
|
@ -15,6 +15,7 @@ Edit config.sample.json and put it into ~/.config/azot/config.json
|
||||||
* command: command to execute
|
* command: command to execute
|
||||||
* corner: Screen corner 'left', 'right', 'top', 'bottom'
|
* corner: Screen corner 'left', 'right', 'top', 'bottom'
|
||||||
* position: 'left', 'right', 'middle'
|
* position: 'left', 'right', 'middle'
|
||||||
|
* check_delay and after_exec_delay are set in seconds
|
||||||
|
|
||||||
### Depends
|
### Depends
|
||||||
|
|
||||||
|
|
2
azot.py
2
azot.py
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import Azot.action
|
import Azot.action
|
||||||
|
|
||||||
|
|
34
azot.spec
34
azot.spec
|
@ -23,7 +23,7 @@ rm -rf $RPM_BUILD_ROOT
|
||||||
rm -f *.pyc
|
rm -f *.pyc
|
||||||
rm -f Azot/*.pyc
|
rm -f Azot/*.pyc
|
||||||
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/usr/lib/python2.7/site-packages/Azot/
|
mkdir -p $RPM_BUILD_ROOT/usr/lib/python3.4/site-packages/Azot/
|
||||||
mkdir -p $RPM_BUILD_ROOT/usr/share/doc/azot/
|
mkdir -p $RPM_BUILD_ROOT/usr/share/doc/azot/
|
||||||
mkdir -p $RPM_BUILD_ROOT/usr/bin/
|
mkdir -p $RPM_BUILD_ROOT/usr/bin/
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ cp README.md $RPM_BUILD_ROOT/usr/share/doc/azot
|
||||||
cp LICENSE $RPM_BUILD_ROOT/usr/share/doc/azot
|
cp LICENSE $RPM_BUILD_ROOT/usr/share/doc/azot
|
||||||
cp config.sample.json $RPM_BUILD_ROOT/usr/share/doc/azot
|
cp config.sample.json $RPM_BUILD_ROOT/usr/share/doc/azot
|
||||||
cp azot.py $RPM_BUILD_ROOT/usr/bin/
|
cp azot.py $RPM_BUILD_ROOT/usr/bin/
|
||||||
cp azot/* $RPM_BUILD_ROOT/usr/lib/python2.7/site-packages/Azot/
|
cp azot/* $RPM_BUILD_ROOT/usr/lib/python3.4/site-packages/Azot/
|
||||||
|
|
||||||
%{_fixperms} $RPM_BUILD_ROOT/*
|
%{_fixperms} $RPM_BUILD_ROOT/*
|
||||||
|
|
||||||
|
@ -40,21 +40,21 @@ rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
%files
|
%files
|
||||||
/usr/bin/azot.py
|
/usr/bin/azot.py
|
||||||
/usr/lib/python2.7/site-packages/Azot/X.py
|
/usr/lib/python3.4/site-packages/Azot/X.py
|
||||||
/usr/lib/python2.7/site-packages/Azot/X.pyc
|
/usr/lib/python3.4/site-packages/Azot/X.pyc
|
||||||
/usr/lib/python2.7/site-packages/Azot/X.pyo
|
/usr/lib/python3.4/site-packages/Azot/X.pyo
|
||||||
/usr/lib/python2.7/site-packages/Azot/__init__.py
|
/usr/lib/python3.4/site-packages/Azot/__init__.py
|
||||||
/usr/lib/python2.7/site-packages/Azot/__init__.pyc
|
/usr/lib/python3.4/site-packages/Azot/__init__.pyc
|
||||||
/usr/lib/python2.7/site-packages/Azot/__init__.pyo
|
/usr/lib/python3.4/site-packages/Azot/__init__.pyo
|
||||||
/usr/lib/python2.7/site-packages/Azot/action.py
|
/usr/lib/python3.4/site-packages/Azot/action.py
|
||||||
/usr/lib/python2.7/site-packages/Azot/action.pyc
|
/usr/lib/python3.4/site-packages/Azot/action.pyc
|
||||||
/usr/lib/python2.7/site-packages/Azot/action.pyo
|
/usr/lib/python3.4/site-packages/Azot/action.pyo
|
||||||
/usr/lib/python2.7/site-packages/Azot/config.py
|
/usr/lib/python3.4/site-packages/Azot/config.py
|
||||||
/usr/lib/python2.7/site-packages/Azot/config.pyc
|
/usr/lib/python3.4/site-packages/Azot/config.pyc
|
||||||
/usr/lib/python2.7/site-packages/Azot/config.pyo
|
/usr/lib/python3.4/site-packages/Azot/config.pyo
|
||||||
/usr/lib/python2.7/site-packages/Azot/logger.py
|
/usr/lib/python3.4/site-packages/Azot/logger.py
|
||||||
/usr/lib/python2.7/site-packages/Azot/logger.pyc
|
/usr/lib/python3.4/site-packages/Azot/logger.pyc
|
||||||
/usr/lib/python2.7/site-packages/Azot/logger.pyo
|
/usr/lib/python3.4/site-packages/Azot/logger.pyo
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
%doc LICENSE README.md config.sample.json
|
%doc LICENSE README.md config.sample.json
|
||||||
|
|
||||||
|
|
|
@ -18,5 +18,7 @@
|
||||||
'type': 'exec',
|
'type': 'exec',
|
||||||
'command': 'scrot'
|
'command': 'scrot'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'check_delay': 0.3,
|
||||||
|
'after_exec_delay': 1
|
||||||
}
|
}
|
||||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -8,7 +8,7 @@ Vcs-Git: https://github.com/Difrex/azot
|
||||||
|
|
||||||
Package: azot
|
Package: azot
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: python, python-xlib, libnotify-bin
|
Depends: python3, python3-xlib, libnotify-bin
|
||||||
Description: Screen corners action in all WMs
|
Description: Screen corners action in all WMs
|
||||||
|
|
||||||
Package: azot-docs
|
Package: azot-docs
|
||||||
|
|
12
debian/install
vendored
12
debian/install
vendored
|
@ -1,6 +1,6 @@
|
||||||
Azot/action.py usr/lib/python2.7/dist-packages/Azot
|
Azot/action.py usr/lib/python3.4/dist-packages/Azot
|
||||||
Azot/logger.py usr/lib/python2.7/dist-packages/Azot
|
Azot/logger.py usr/lib/python3.4/dist-packages/Azot
|
||||||
Azot/config.py usr/lib/python2.7/dist-packages/Azot
|
Azot/config.py usr/lib/python3.4/dist-packages/Azot
|
||||||
Azot/X.py usr/lib/python2.7/dist-packages/Azot
|
Azot/X.py usr/lib/python3.4/dist-packages/Azot
|
||||||
Azot/__init__.py usr/lib/python2.7/dist-packages/Azot
|
Azot/__init__.py usr/lib/python3.4/dist-packages/Azot
|
||||||
azot.py usr/bin
|
azot.py usr/bin
|
Loading…
Reference in New Issue
Block a user