By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 wl4pgi_example.py

View raw Download
text/x-script.python • 1.8 kiB
Python script, ASCII text executable
        
            
1
from pywayland.client import Display, EventQueue
2
import wl4pgi
3
4
import gi
5
from gi.repository import GLib, Gio
6
7
# The display is NOT converted to GObject since they have a lot of special behaviour. Also
8
# you still have to roundtrip, but only after creating GObject adapters.
9
display = Display()
10
display.connect()
11
event_queue = EventQueue(display)
12
13
14
def on_geometry(output, x, y, pw, ph, subpixel, make, model, transform):
15
print(output, x, y, pw, ph, subpixel, make, model, transform)
16
17
18
def on_geometry_1(output, x, y, pw, ph, subpixel, make, model, transform):
19
print("Since it uses GObject signals, multiple handlers work without problems")
20
print(f"Also, custom attributes work: {output.test}. There's always zero or one GObjects "
21
f"per Wayland object.")
22
23
24
def on_global(registry, name, interface, version):
25
if interface == "wl_output":
26
# GObjects adapters only represent a proxy. Thus, to get the interface class for use
27
# in this signal, you must go into pywayland.
28
output = registry.bind(name, wl4pgi.wayland.WlOutput.interface_type, version)
29
output.test = 0
30
# Multiple handlers, transparently and with a single display and a single registry.
31
output.connect("geometry", on_geometry)
32
output.connect("geometry", on_geometry_1)
33
display.roundtrip()
34
35
36
# Starting from the registry, operation is within PyGObject.
37
registry = wl4pgi.wayland.WlRegistry(display.get_registry())
38
registry.connect("global", on_global)
39
display.roundtrip()
40
41
# The next parts would be removed for GTK integration.
42
def on_display_event(self, source, condition):
43
if condition & GLib.IO_IN:
44
self.display.dispatch(queue=self.event_queue)
45
return True
46
47
48
fd = display.get_fd()
49
GLib.io_add_watch(fd, GLib.IO_IN, on_display_event)
50
51
main_loop = GLib.MainLoop()
52
main_loop.run()
53