Skip to content

Commit b1bc562

Browse files
allfrovasily-v-ryabov
authored andcommitted
Update randr.py
Add version 1.5 support for RRSetMonitor RRGetMonitors and RRDeleteMonitors
1 parent 75100a2 commit b1bc562

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

Xlib/ext/randr.py

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
This implementation is based off version 1.3 of the XRandR protocol, and may
2626
not be compatible with other versions.
2727
28-
Version 1.2 of the protocol is documented at:
28+
Version 1.5 of the protocol is documented at:
2929
http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
3030
3131
Version 1.3.1 here:
@@ -168,6 +168,19 @@
168168
rq.Card32('matrix33'),
169169
)
170170

171+
MonitorInfo = rq.Struct(
172+
rq.Card32('name'),
173+
rq.Bool('primary'),
174+
rq.Bool('automatic'),
175+
rq.LengthOf('crtcs', 2),
176+
rq.Int16('x'),
177+
rq.Int16('y'),
178+
rq.Card16('width_in_pixels'),
179+
rq.Card16('height_in_pixels'),
180+
rq.Card32('width_in_millimeters'),
181+
rq.Card32('height_in_millimeters'),
182+
rq.List('crtcs', rq.Card32Obj)
183+
)
171184

172185
# Requests #
173186

@@ -197,7 +210,7 @@ def query_version(self):
197210
display=self.display,
198211
opcode=self.display.get_extension_major(extname),
199212
major_version=1,
200-
minor_version=3,
213+
minor_version=5,
201214
)
202215

203216

@@ -1078,6 +1091,76 @@ def get_output_primary(self):
10781091
)
10791092

10801093

1094+
# Version 1.5 methods
1095+
1096+
class GetMonitors(rq.ReplyRequest):
1097+
_request = rq.Struct(
1098+
rq.Card8('opcode'),
1099+
rq.Opcode(42),
1100+
rq.RequestLength(),
1101+
rq.Window('window'),
1102+
rq.Bool('is_active'),
1103+
rq.Pad(3)
1104+
)
1105+
1106+
_reply = rq.Struct(
1107+
rq.ReplyCode(),
1108+
rq.Pad(1),
1109+
rq.Card16('sequence_number'),
1110+
rq.ReplyLength(),
1111+
rq.Card32('timestamp'),
1112+
rq.LengthOf('monitors', 4),
1113+
rq.Card32('outputs'),
1114+
rq.Pad(12),
1115+
rq.List('monitors', MonitorInfo)
1116+
)
1117+
1118+
1119+
def get_monitors(self, is_active=True):
1120+
return GetMonitors(
1121+
display=self.display,
1122+
opcode=self.display.get_extension_major(extname),
1123+
window=self,
1124+
is_active=is_active
1125+
)
1126+
1127+
class SetMonitor(rq.Request):
1128+
_request = rq.Struct(
1129+
rq.Card8('opcode'),
1130+
rq.Opcode(43),
1131+
rq.RequestLength(),
1132+
rq.Window('window'),
1133+
rq.Object('monitor_info', MonitorInfo)
1134+
)
1135+
1136+
1137+
def set_monitor(self, monitor_info):
1138+
return SetMonitor(
1139+
display=self.display,
1140+
opcode=self.display.get_extension_major(extname),
1141+
window=self,
1142+
monitor_info=monitor_info
1143+
)
1144+
1145+
1146+
class DeleteMonitor(rq.Request):
1147+
_request = rq.Struct(
1148+
rq.Card8('opcode'),
1149+
rq.Opcode(44),
1150+
rq.RequestLength(),
1151+
rq.Window('window'),
1152+
rq.Card32('name')
1153+
)
1154+
1155+
1156+
def delete_monitor(self, name):
1157+
return DeleteMonitor(
1158+
display=self.display,
1159+
opcode=self.display.get_extension_major(extname),
1160+
window=self,
1161+
name=name
1162+
)
1163+
10811164
# Events #
10821165

10831166
class ScreenChangeNotify(rq.Event):
@@ -1149,8 +1232,8 @@ class OutputPropertyNotify(rq.Event):
11491232
rq.Card8('state'),
11501233
rq.Pad(11),
11511234
)
1152-
1153-
1235+
1236+
11541237
# Initialization #
11551238

11561239
def init(disp, info):
@@ -1186,6 +1269,11 @@ def init(disp, info):
11861269
disp.extension_add_method('display', 'xrandr_get_panning', get_panning)
11871270
disp.extension_add_method('display', 'xrandr_set_panning', set_panning)
11881271

1272+
# version 1.5 compatible
1273+
disp.extension_add_method('window', 'xrandr_get_monitors', get_monitors)
1274+
disp.extension_add_method('window', 'xrandr_set_monitor', set_monitor)
1275+
disp.extension_add_method('window', 'xrandr_delete_monitor', delete_monitor)
1276+
11891277
disp.extension_add_event(info.first_event + RRScreenChangeNotify, ScreenChangeNotify)
11901278
# add RRNotify events (1 event code with 3 subcodes)
11911279
disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_CrtcChange, CrtcChangeNotify)

0 commit comments

Comments
 (0)