Debian Codegraph @

obvious/bluetooth/init.lua

raw symbols SCIP
1 -----------------------------------------------------
2 -- Bluetooth widget for the awesome window manager --
3 -----------------------------------------------------
4 -- Author: Christian Kuka [email protected] --
5 -- Copyright 2010 Christian Kuka --
6 -- Licensed under GPLv2 --
7 -----------------------------------------------------
8
9 local assert = assert
10 local string = string
11 local table = table
12 local io = {
13 popen = io.popen
14 }
15 local mouse = mouse
16
17 local naughty = require("naughty")
18 local awful = require("awful")
19 local wibox = require 'wibox'
20
21 local lib = {
22 hooks = require("obvious.lib.hooks"),
23 markup = require("obvious.lib.markup")
24 }
25
26 local widget = wibox.widget {
27 align = 'right',
28 text = '⋊',
29 widget = wibox.widget.textbox,
30 }
31
32 -- Major device classes
33 local classes = {
34 x00 = "Misc",
35 x01 = "Computer",
36 x02 = "Phone",
37 x03 = "Network",
38 x04 = "Audio",
39 x05 = "Peripheral",
40 x06 = "Imaging",
41 x1f = "Uncategorized"
42 }
43
44 -- Return device list
45 local devices = {}
46 local function get_data()
47 return devices
48 end
49
50
51 -- Update device list
52 local function update()
53 devices = {}
54 local fd = io.popen("hcitool inq")
55 if not fd then return end
56
57 -- Inquery takes 10.5s
58 for addr, cl in string.gfind(fd:read("*all"),"%s+([a-zA-Z0-9:]+)%s+clock offset: [a-z0-9]+%s+class: ([a-z0-9]+)") do
59 local dev = {
60 address = addr,
61 class = classes[cl:sub(2,4)] or "Uncategorized"
62 }
63 table.insert(devices, dev)
64 end
65 end
66
67 -- Show address and major device class
68 local function detail()
69 local d = "Bluetooth Devices:"
70 table.foreach(devices, function(i,dev)
71 d = d.."\n"..dev.address.."\t"..dev.class
72 end)
73 naughty.notify({ text = d, screen = mouse.screen })
74 end
75
76 widget:buttons(awful.util.table.join(
77 awful.button({ }, 1, detail)
78 ))
79
80 lib.hooks.timer.register(60, 300, update)
81 lib.hooks.timer.start(update)
82
83 return setmetatable({
84 get_data = get_data,
85 }, { __call = function () return widget end })
86
87 -- vim:ft=lua:ts=2:sw=2:sts=2:tw=80:et