[ctl] re-add bumblebee-ctl
add a utility that allows the user to programmatically trigger mouse events for i3
This commit is contained in:
parent
972ada0697
commit
af80f4c620
2 changed files with 84 additions and 20 deletions
40
bumblebee-ctl
Executable file
40
bumblebee-ctl
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import glob
|
||||||
|
import socket
|
||||||
|
|
||||||
|
button = {
|
||||||
|
'left-mouse': 1,
|
||||||
|
'middle-mouse': 2,
|
||||||
|
'right-mouse': 3,
|
||||||
|
'wheel-up': 4,
|
||||||
|
'wheel-down': 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='send commands to bumblebee-status')
|
||||||
|
parser.add_argument('-b', '--button', choices=['left-mouse', 'right-mouse', 'middle-mouse', 'wheel-up', 'wheel-down'], help='button to emulate', default='left-mouse')
|
||||||
|
parser.add_argument('-i', '--id', help='ID of widget to trigger')
|
||||||
|
parser.add_argument('-m', '--module', help='name of the module to trigger', required=True)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
for f in glob.glob('/tmp/.bumblebee-status.*'):
|
||||||
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
try:
|
||||||
|
s.connect(f)
|
||||||
|
s.sendall(json.dumps({
|
||||||
|
'name': args.module,
|
||||||
|
'instance': args.id,
|
||||||
|
'button': button[args.button],
|
||||||
|
}).encode('ascii'))
|
||||||
|
except Exception as e:
|
||||||
|
os.remove(f)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
|
@ -3,6 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
import select
|
import select
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
@ -13,30 +14,53 @@ import core.module
|
||||||
import core.input
|
import core.input
|
||||||
import core.event
|
import core.event
|
||||||
|
|
||||||
|
class CommandSocket(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.__name = '/tmp/.bumblebee-status.{}'.format(os.getpid())
|
||||||
|
self.__socket = None
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.__socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
self.__socket.bind(self.__name)
|
||||||
|
self.__socket.listen(5)
|
||||||
|
return self.__socket
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
self.__socket.close()
|
||||||
|
os.unlink(self.__name)
|
||||||
|
|
||||||
def handle_input(output):
|
def handle_input(output):
|
||||||
poll = select.poll()
|
with CommandSocket() as cmdsocket:
|
||||||
poll.register(sys.stdin.fileno(), select.POLLIN)
|
poll = select.poll()
|
||||||
|
poll.register(sys.stdin.fileno(), select.POLLIN)
|
||||||
|
poll.register(cmdsocket, select.POLLIN)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
events = poll.poll()
|
events = poll.poll()
|
||||||
|
|
||||||
modules = {}
|
modules = {}
|
||||||
for fileno, event in events:
|
for fileno, event in events:
|
||||||
line = '['
|
if fileno == cmdsocket.fileno():
|
||||||
while line.startswith('['):
|
tmp, _ = cmdsocket.accept()
|
||||||
line = sys.stdin.readline().strip(',').strip()
|
line = tmp.recv(4096).decode()
|
||||||
logging.info('input event: {}'.format(line))
|
tmp.close()
|
||||||
try:
|
logging.debug('socket event {}'.format(line))
|
||||||
event = json.loads(line)
|
else:
|
||||||
core.input.trigger(event)
|
line = '['
|
||||||
if 'name' in event:
|
while line.startswith('['):
|
||||||
modules[event['name']] = True
|
line = sys.stdin.readline().strip(',').strip()
|
||||||
except ValueError:
|
logging.info('input event: {}'.format(line))
|
||||||
pass
|
try:
|
||||||
core.event.trigger('update', modules.keys())
|
event = json.loads(line)
|
||||||
core.event.trigger('draw')
|
core.input.trigger(event)
|
||||||
|
if 'name' in event:
|
||||||
|
modules[event['name']] = True
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
core.event.trigger('update', modules.keys())
|
||||||
|
core.event.trigger('draw')
|
||||||
|
|
||||||
poll.unregister(sys.stdin.fileno())
|
poll.unregister(sys.stdin.fileno())
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = core.config.Config(sys.argv[1:])
|
config = core.config.Config(sys.argv[1:])
|
||||||
|
|
Loading…
Reference in a new issue