File: ipc-trace.py

package info (click to toggle)
python-i3ipc 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: python: 2,968; makefile: 222; sh: 4
file content (49 lines) | stat: -rw-r--r-- 861 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
#!/usr/bin/env python3

import i3ipc
from time import strftime, gmtime

i3 = i3ipc.Connection()


def print_separator():
    print('-----')


def print_time():
    print(strftime(strftime("%Y-%m-%d %H:%M:%S", gmtime())))


def print_con_info(con):
    if con:
        print('Id: %s' % con.id)
        print('Name: %s' % con.name)
    else:
        print('(none)')


def on_window(i3, e):
    print_separator()
    print('Got window event:')
    print_time()
    print('Change: %s' % e.change)
    print_con_info(e.container)


def on_workspace(i3, e):
    print_separator()
    print('Got workspace event:')
    print_time()
    print('Change: %s' % e.change)
    print('Current:')
    print_con_info(e.current)
    print('Old:')
    print_con_info(e.old)


# TODO subscribe to all events

i3.on('window', on_window)
i3.on('workspace', on_workspace)

i3.main()