2020-05-02 09:41:41 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import glob
|
|
|
|
import socket
|
|
|
|
|
|
|
|
button = {
|
2020-05-03 11:15:52 +02:00
|
|
|
"left-mouse": 1,
|
|
|
|
"middle-mouse": 2,
|
|
|
|
"right-mouse": 3,
|
|
|
|
"wheel-up": 4,
|
|
|
|
"wheel-down": 5,
|
2020-05-02 09:41:41 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-05-02 09:41:41 +02:00
|
|
|
def main():
|
2020-05-03 11:15:52 +02:00
|
|
|
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
|
|
|
|
)
|
2020-05-02 09:41:41 +02:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
for f in glob.glob("/tmp/.bumblebee-status.*"):
|
2020-05-02 09:41:41 +02:00
|
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
try:
|
|
|
|
s.connect(f)
|
2020-05-03 11:15:52 +02:00
|
|
|
s.sendall(
|
|
|
|
json.dumps(
|
|
|
|
{
|
|
|
|
"name": args.module,
|
|
|
|
"instance": args.id,
|
|
|
|
"button": button[args.button],
|
|
|
|
}
|
|
|
|
).encode("ascii")
|
|
|
|
)
|
2020-05-02 09:41:41 +02:00
|
|
|
except Exception as e:
|
|
|
|
os.remove(f)
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-05-02 09:41:41 +02:00
|
|
|
main()
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|