forked from bulletmark/libinput-gestures
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to move diagonally on virtual desktop
See the comments added about configuring this in libinput-gestures.conf. This is an enhancement added to address issue bulletmark#224.
- Loading branch information
1 parent
dcdc33b
commit bc69ac9
Showing
7 changed files
with
982 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
README.html | ||
.idea/ | ||
.vscode/ | ||
README.html | ||
*.pyc | ||
__pycache__ | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env python3 | ||
'Command line program to exercise/test/debug the _internal command.' | ||
# Mark Blakeney, Oct 2019 | ||
import sys, importlib, argparse | ||
from pathlib import Path | ||
|
||
CMD = '_internal' | ||
GESTURE = 'swipe' | ||
PROG = Path(sys.argv[0]).resolve() | ||
NAME = Path.cwd().name | ||
CACHE = Path.home() / '.cache' / PROG.name | ||
|
||
def import_path(path, add_to_path=False): | ||
'Import given module path' | ||
modname = Path(path).stem.replace('-', '_') | ||
spec = importlib.util.spec_from_loader(modname, | ||
importlib.machinery.SourceFileLoader(modname, path)) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
if add_to_path: | ||
sys.modules[modname] = module | ||
return module | ||
|
||
opt = argparse.ArgumentParser(description=__doc__) | ||
opt.add_argument('-c', '--conffile', | ||
help='alternative configuration file') | ||
opt.add_argument('-i', '--initial', type=int, | ||
help='initial desktop') | ||
opt.add_argument('-C', '--cols', type=int, default=1, | ||
help='number of columns') | ||
opt.add_argument('-t', '--text', action='store_true', | ||
help='output desktop change in text') | ||
opt.add_argument('-n', '--nocache', action='store_true', | ||
help='do not use cache') | ||
opt.add_argument('num', type=int, | ||
help='number of desktops') | ||
opt.add_argument('action', nargs='?', | ||
help='action to perform') | ||
opt.add_argument('-d', '--display', type=int, | ||
help=argparse.SUPPRESS) | ||
opt.add_argument('-s', '--set', type=int, help=argparse.SUPPRESS) | ||
args = opt.parse_args() | ||
|
||
def showgrid(pos, num, cols): | ||
print() | ||
for i in range(num): | ||
end = '\n' if (i % cols) == (cols - 1) else '' | ||
if i == pos: | ||
print(' {:02} '.format(i), end=end) | ||
else: | ||
print(' ** ', end=end) | ||
if end != '\n': | ||
print() | ||
|
||
if args.set is not None: | ||
print(args.set) | ||
sys.exit(0) | ||
|
||
if args.display is not None: | ||
for i in range(args.num): | ||
print('{} {} -'.format(i, '*' if i == args.display else '-')) | ||
sys.exit(0) | ||
|
||
if args.initial is None: | ||
if args.nocache: | ||
opt.error('Initial value must be specified') | ||
if not CACHE.exists(): | ||
opt.error('Need initial desktop specified') | ||
start = int(CACHE.read_text().strip()) | ||
else: | ||
start = args.initial | ||
|
||
lg = import_path(NAME) | ||
icmd = lg.internal_commands[CMD] | ||
|
||
icmd.CMDLIST = '{} -d {} {}'.format(PROG, start, args.num).split() | ||
icmd.CMDSET = '{} {} -s'.format(PROG, args.num).split() | ||
|
||
lg.read_conf(args.conffile, NAME + '.conf') | ||
motions = lg.handlers[GESTURE.upper()].motions | ||
actions = {k: v for k, v in motions.items() if isinstance(v, icmd)} | ||
|
||
if not args.action or args.action not in actions: | ||
opt.error('action must be one of {}'.format(list(actions.keys()))) | ||
|
||
cmd = motions[args.action] | ||
print('Command "{} {} is "{}"'.format(GESTURE, args.action, cmd)) | ||
res = cmd.run(block=True) | ||
|
||
if res: | ||
end = int(res.strip()) | ||
if not args.nocache: | ||
CACHE.write_text(str(end)) | ||
else: | ||
end = start | ||
|
||
if end < 0 or end >= args.num: | ||
sys.exit('Desktop change from {} to {}, out of range 0 to <{}!'.format( | ||
start, end, args.num)) | ||
|
||
if args.text: | ||
if start != end: | ||
print('Desktop change from {} to {}'.format(start, end)) | ||
else: | ||
print('No change') | ||
else: | ||
showgrid(start, args.num, args.cols) | ||
showgrid(end, args.num, args.cols) |
Oops, something went wrong.