File: sync.py

package info (click to toggle)
python-i3ipc 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 580 kB
  • sloc: python: 2,968; makefile: 222; sh: 4
file content (31 lines) | stat: -rw-r--r-- 1,168 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
from Xlib import display
from Xlib.protocol import event
from Xlib import X
import random


class Synchronizer:
    def __init__(self):
        self.display = display.Display()
        self.screen = self.display.screen()
        self.root = self.screen.root
        self.sync_atom = self.display.intern_atom('I3_SYNC')
        self.send_window = self.root.create_window(-10, -10, 10, 10, 0, self.screen.root_depth)

    def sync(self):
        rnd = random.randint(0, 2147483647)

        message = event.ClientMessage(window=self.root,
                                      data=([32, [self.send_window.id, rnd, 0, 0, 0]]),
                                      message_type=self.sync_atom,
                                      client_type=self.sync_atom,
                                      sequence_number=0)

        self.display.send_event(self.root, message, X.SubstructureRedirectMask)

        while True:
            e = self.display.next_event()
            if e.type == X.ClientMessage and e.client_type == self.sync_atom:
                fmt, data = e.data
                if data[0] == self.send_window.id and data[1] == rnd:
                    break