Module xrandr
Lua bindings for libxrandr
.
Documentation here will extend the official library’s documentation, not replace it.
Please take a look at the libxrandr documentation before use,
especially the protocol specification
and Xrandr.h.
Additionally, libxrandr
provides man pages locally (packaging depends on the distribution).
Table of contents
Functions
Tables
RR_OUTPUT | An enum of well-known output property names. |
XRRScreenConfiguration | This only functions as a marker. |
XRRModeFlags | This table maps the bitfield to individual booleans. |
XRRMode | Contrary to the other types in this module, this is provided as an actual Lua table, rather than userdata. |
XRRScreenResources | |
XRROutputInfo | |
XRRPropertyInfo | If pending == true , changes to the property via XRRChangeOutputProperty will be queued
until the next call to XRRSetCrtcConfig. |
XRRCrtcInfo |
Functions
The return values of the major and minor extension version are only defined when
the status value is 1
. In all other cases, using the version numbers is considered
undefined behaviour.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
Returns:
-
The request status.
-
The major extension version.
-
The minor extension version.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
Returns:
-
-
The event base code
-
The error base code
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window
Returns:
Usage:
local display = xlib.xlib.XOpenDisplay() local screen = xlib.DefaultScreen(display) local root = xlib.RootWindow(display, screen) local info = xrandr.XRRGetScreenInfo(display, root)
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
config
-
draw
-
size_index
-
rotation
-
timestamp
Returns:
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
config
-
draw
-
size_index
-
rotation
-
rate
-
timestamp
Returns:
Parameters:
-
config
Returns:
-
rotations
-
current_rotation
Parameters:
-
config
Returns:
-
timestamp
-
config_timestamp
Parameters:
-
config
Returns:
Parameters:
-
config
-
size_index : Index of the current screen size from XRRConfigCurrentConfiguration.
Returns:
Parameters:
-
config
Returns:
-
Index into the return value of XRRConfigSizes
-
Current rotation
Parameters:
-
config
Returns:
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window : The XID of the window to query.
Returns:
Usage:
local display = xlib.xlib.XOpenDisplay() local screen = xlib.DefaultScreen(display) local root = xlib.RootWindow(display, screen) local res = xrandr.XRRGetScreenResources(display, root)
This returns a userdatum that wrapping the output info data. Table index operations are supported to retrieve the fields described in XRROutputInfo.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
resources
-
output : The XID of the output to fetch information about.
Returns:
Usage:
local res = xrandr.XRRGetScreenResources(display, root) for _, output in ipairs(res.outputs) do local info = xrandr.XRRGetOutputInfo(display, res, output) printf("%s %s", info.name, info.connection) end
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window : The XID of the window to query.
Returns:
-
The XID of the primary output.
Usage:
local res = xrandr.XRRGetScreenResources(display, root) local primary = xrandr.XRRGetOutputPrimary(display, root) for _, output in ipairs(res.outputs) do if output == primary then local info = xrandr.XRRGetOutputInfo(display, res, output) printf("Primary: %s", info.name) end end
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window : The XID of the window.
-
output : The XID of the output.
This returns a list of Atom
s (mapped to simple integer numbers).
Metadata of the property can be queried with using XRRQueryOutputProperty,
values with XRRGetOutputProperty.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
output : The XID of the output.
Returns:
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
output : The XID of the output.
-
property : An X11
Atom
.
Returns:
See XRRPropertyInfo for the semantics of the various metadata fields.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
output : The XID of the output.
-
property : An X11
Atom
. -
pending
-
range
-
values
The value has to match with the metadata from XRRQueryOutputProperty.
For now, only string values are supported, and they are treated as raw, unsigned byte buffers.
If “append” or “prepend” modes are chosen, the types of the existing and new values must match. For undefined properties, all three modes work the same.
The maximum allowed size of the property data depends on the server implementation, and may change dynamically at runtime or between resets. The lifetime of a property is tied to the output and server, not the client that set it.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
output : The XID of the output.
-
property : An X11
Atom
. -
type : An X11
Atom
. -
mode : If
1
, prepend data. If2
, append data. Otherwise replace data. -
data
As with XRRChangeOutputProperty, only properties of type string
(which maps to Xorg’s XA_STRING
from X11/Xatom.h
) are currently supported. The req_type
property
is just a placeholder because of that.
If there is no such property, the function will return nothing.
For properties of unknown length, first call this function with offset == 0
, length == 0
,
and the second return value will report the full length of the value. Then call the function
a second time with the desired offset and length.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
output : The XID of the output.
-
property : An X11
Atom
. -
offset : The offset at which to start reading the return value.
-
length : The amount of bytes (regardless of the element size) to read into the return value.
-
delete : If
true
, delete the property after reading. -
pending : If
true
and there is a pending change for the property, return that change instead of the current value. -
req_type : An X11
Atom
. Currently ignored and hardcoded to XLib’sXA_STRING
.
Returns:
-
The data.
-
The number of elements in the value, as passed when setting the property (see XRRChangeOutputProperty).
-
The element size of the byte array as passed when setting the property. One of
8
,16
,32
. -
The number of bytes (regardless of the element size) left in the value.
Usage:
-- Check the length local _, length = xrandr.XRRGetOutputProperty(display, output, atom, 0, 0) local value, nitems, format = xrandr.XRRGetOutputProperty(display, output, atom, 0, length) print(value) -- may be arbitrary, non-printable bytes. If so, use `nitems` and `format` to interpret it
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
output : The XID of the output.
-
property : An X11
Atom
.
This returns a userdatum that wrapping the CRTC info data. Table index operations are supported to retrieve the fields described in XRRCrtcInfo.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
resources
-
crtc : The XID of the CRTC to fetch information about.
Returns:
Usage:
local res = xrandr.XRRGetScreenResources(display, root) local info = xrandr.XRRGetCrtcInfo(display, res, res.crtcs[1]) local mode = find_by_id(res.modes, info.mode) require("pl.pretty").dump(mode)
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
resources
-
crtc : The XID of the CRTC to change.
-
timestamp
-
x
-
y
-
mode : The id of the XRRMode to set for this CRTC. If
0
ornil
is passed, the CRTC will be disabled. -
rotation
-
outputs : The list of output XIDs to assign to this CRTC.
Returns:
-
An X11
Status
.
Usage:
local res = xrandr.XRRGetScreenResources(display, root) local info = xrandr.XRRGetCrtcInfo(display, res, res.crtcs[1]) local mode = find_by_id(res.modes, info.mode) local status = xrandr.XRRSetCrtcConfig( display, res, res.crtcs[1], info.timestamp, info.x, info.y, res.modes[2].id, info.rotation, info.outputs )
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window
- mask
-
screen : Configure screen change notifications.
-
crtc : Configure crtc change notifications.
-
output : Configure output change notifications.
-
output_property : Configure output property change notifications.
-
provider : Configure provider change notifications.
-
provider_property : Configure provider property change notifications.
-
resource : Configure resource change notifications.
-
Usage:
-- Enable notifications for CRTCs and outputs xrandr.XRRSelectInput(display, root, { crtc = true, output = true })
This returns the minimum and maximum boundaries within which screen sizes may be set.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window
Returns:
-
status Despite being designated a X11
Status
inXrandr.h
, this returns1
on success. -
min_width
-
min_height
-
max_width
-
max_height
The width
and height
must be within the ranges returned by XRRGetScreenSizeRange.
Parameters:
-
display : A display connection opened with xlib.XOpenDisplay.
-
window
-
width
-
height
-
mm_width : Physical size of the screen, in millimeters.
-
mm_height : Physical size of the screen, in millimeters.
Tables
Fields:
-
BACKLIGHT :
Backlight
-
RANDR_EDID :
EDID
-
SIGNAL_FORMAT :
SignalFormat
-
SIGNAL_PROPERTIES :
SignalProperties
-
CONNECTOR_TYPE :
ConnectorType
-
CONNECTOR_NUMBER :
ConnectorNumber
-
COMPATIBILITY_LIST :
CompatibilityList
-
CLONE_LIST :
CloneList
-
BORDER :
Border
-
BORDER_DIMENSIONS :
BorderDimensions
-
GUID :
GUID
-
RANDR_TILE :
TILE
-
NON_DESKTOP :
non-desktop
XRRConfig*
functions, such as
XRRConfigCurrentRate.Fields:
-
HSyncPositive
-
HSyncNegative
-
VSyncPositive
-
VSyncNegative
-
Interlace
-
DoubleScan
-
CSync
-
CSyncPositive
-
CSyncNegative
-
HSkewPresent
-
BCast
-
PixelMultiplex
-
DoubleClock
-
ClockDivideBy2
Fields:
-
id
-
name
-
width
-
height
-
dotClock
-
hSyncStart
-
hSyncEnd
-
hTotal
-
hSkew
-
vSyncStart
-
vSyncEnd
-
vTotal
-
modeFlags
Fields:
-
timestamp
-
configTimestamp
-
crtcs
-
outputs
-
modes
Fields:
-
name
-
mm_width
-
mm_height
-
connection
-
subpixel_order
-
modes : List of IDs. These map to the mode list in XRRScreenResources.
-
crtcs : List of XIDs
-
crtc
pending == true
, changes to the property via XRRChangeOutputProperty will be queued
until the next call to XRRSetCrtcConfig.
If range == true
, values
will contain exactly two entries, that denote the minimum and maximum
values for the property. Otherwise values
is a list of valid values.
If immutable == true
, the property cannot be changed by the client.
Fields:
-
pending
-
range
-
immutable
-
values
Fields:
-
name
-
mm_width
-
mm_height
-
connection
-
subpixel_order
-
modes