File: bumblebee-ctl

package info (click to toggle)
bumblebee-status 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,844 kB
  • sloc: python: 13,430; sh: 68; makefile: 29
file content (55 lines) | stat: -rwxr-xr-x 1,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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,
    "update": -1,
}


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", "update"],
        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