Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 92 additions & 4 deletions Xlib/ext/randr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
This implementation is based off version 1.3 of the XRandR protocol, and may
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.3 -> 1.5

not be compatible with other versions.

Version 1.2 of the protocol is documented at:
Version 1.5 of the protocol is documented at:
http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt

Version 1.3.1 here:
Expand Down Expand Up @@ -168,6 +168,19 @@
rq.Card32('matrix33'),
)

MonitorInfo = rq.Struct(
rq.Card32('name'),
rq.Bool('primary'),
rq.Bool('automatic'),
rq.LengthOf('crtcs', 2),
rq.Int16('x'),
rq.Int16('y'),
rq.Card16('width_in_pixels'),
rq.Card16('height_in_pixels'),
rq.Card32('width_in_millimeters'),
rq.Card32('height_in_millimeters'),
rq.List('crtcs', rq.Card32Obj)
)

# Requests #

Expand Down Expand Up @@ -197,7 +210,7 @@ def query_version(self):
display=self.display,
opcode=self.display.get_extension_major(extname),
major_version=1,
minor_version=3,
minor_version=5,
)


Expand Down Expand Up @@ -1078,6 +1091,76 @@ def get_output_primary(self):
)


# Version 1.5 methods

class GetMonitors(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(42),
rq.RequestLength(),
rq.Window('window'),
rq.Bool('is_active'),
rq.Pad(3)
)

_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card32('timestamp'),
rq.LengthOf('monitors', 4),
rq.Card32('outputs'),
rq.Pad(12),
rq.List('monitors', MonitorInfo)
)


def get_monitors(self, is_active=True):
return GetMonitors(
display=self.display,
opcode=self.display.get_extension_major(extname),
window=self,
is_active=is_active
)

class SetMonitor(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(43),
rq.RequestLength(),
rq.Window('window'),
rq.Object('monitor_info', MonitorInfo)
)


def set_monitor(self, monitor_info):
return SetMonitor(
display=self.display,
opcode=self.display.get_extension_major(extname),
window=self,
monitor_info=monitor_info
)


class DeleteMonitor(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(44),
rq.RequestLength(),
rq.Window('window'),
rq.Card32('name')
)


def delete_monitor(self, name):
return DeleteMonitor(
display=self.display,
opcode=self.display.get_extension_major(extname),
window=self,
name=name
)

# Events #

class ScreenChangeNotify(rq.Event):
Expand Down Expand Up @@ -1149,8 +1232,8 @@ class OutputPropertyNotify(rq.Event):
rq.Card8('state'),
rq.Pad(11),
)


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like unnecessary extra spaces were added here.

# Initialization #

def init(disp, info):
Expand Down Expand Up @@ -1186,6 +1269,11 @@ def init(disp, info):
disp.extension_add_method('display', 'xrandr_get_panning', get_panning)
disp.extension_add_method('display', 'xrandr_set_panning', set_panning)

# version 1.5 compatible
disp.extension_add_method('window', 'xrandr_get_monitors', get_monitors)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if version 1.5 is present almost everywhere for now. Does it make sense to check version of the extension? So that we can support both 1.3 and 1.5+.

disp.extension_add_method('window', 'xrandr_set_monitor', set_monitor)
disp.extension_add_method('window', 'xrandr_delete_monitor', delete_monitor)

disp.extension_add_event(info.first_event + RRScreenChangeNotify, ScreenChangeNotify)
# add RRNotify events (1 event code with 3 subcodes)
disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_CrtcChange, CrtcChangeNotify)
Expand Down
3 changes: 2 additions & 1 deletion Xlib/protocol/rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ def parse_value(self, val, display):
return self.type.parse_value(val, display)

def pack_value(self, val):
return self.type.pack_value(val)
val = self.type.pack_value(val)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion to fix underlying functions is also applicable here.

return val, len(val), None

def check_value(self, val):
if isinstance(val, tuple):
Expand Down