File: test_window.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 (62 lines) | stat: -rw-r--r-- 1,516 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
56
57
58
59
60
61
62
from i3ipc import Event

import time
from ipctest import IpcTest
from threading import Timer


class TestWindow(IpcTest):
    def test_window_event(self, i3):
        event = None

        def on_window(i3, e):
            nonlocal event
            event = e
            i3.main_quit()

        i3.on('window', on_window)
        Timer(0.001, self.open_window).start()
        i3.main(timeout=2)

        assert event is not None
        i3.off(on_window)

    def test_marks(self, i3):
        self.fresh_workspace()
        self.open_window()
        i3.command('mark foo')
        assert 'foo' in i3.get_tree().find_focused().marks

    def test_detailed_window_event(self, i3):
        events = []

        def generate_events():
            win1 = self.open_window()
            win2 = self.open_window()
            i3.command(f'[id={win1}] kill; [id={win2}] kill')
            # TODO sync protocol
            time.sleep(0.01)
            i3.main_quit()

        def on_window(i3, e):
            nonlocal events
            events.append(e)

        i3.on(Event.WINDOW_NEW, on_window)
        Timer(0.01, generate_events).start()
        i3.main(timeout=2)

        assert len(events)
        for e in events:
            assert e.change == 'new'

        events.clear()
        i3.off(on_window)

        i3.on(Event.WINDOW_FOCUS, on_window)
        Timer(0.01, generate_events).start()
        i3.main(timeout=2)

        assert len(events)
        for e in events:
            assert e.change == 'focus'