Initial commit

This commit is contained in:
Untriex Programming
2021-08-31 22:06:02 +02:00
commit 9b6723e11e
5142 changed files with 1455625 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# Xlib.ext.__init__ -- X extension modules
#
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# __extensions__ is a list of tuples: (extname, extmod)
# extname is the name of the extension according to the X
# protocol. extmod is the name of the module in this package.
__extensions__ = [
('XTEST', 'xtest'),
('SHAPE', 'shape'),
('XINERAMA', 'xinerama'),
('RECORD', 'record'),
('Composite', 'composite'),
('RANDR', 'randr'),
]
__all__ = [x[1] for x in __extensions__]

View File

@@ -0,0 +1,234 @@
# $Id: xtest.py,v 1.1 2000/08/21 10:03:45 petli Exp $
#
# Xlib.ext.composite -- Composite extension module
#
# Copyright (C) 2007 Peter Liljenberg <peter.liljenberg@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Composite extension, allowing windows to be rendered to off-screen
storage.
For detailed description, see the protocol specification at
http://freedesktop.org/wiki/Software/CompositeExt
By itself this extension is not very useful, it is intended to be used
together with the DAMAGE and XFIXES extensions. Typically you would
also need RENDER or glX or some similar method of creating fancy
graphics.
"""
from Xlib import X
from Xlib.protocol import rq
from Xlib.xobject import drawable
extname = 'Composite'
RedirectAutomatic = 0
RedirectManual = 1
class QueryVersion(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(0),
rq.RequestLength(),
rq.Card32('major_version'),
rq.Card32('minor_version')
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card32('major_version'),
rq.Card32('minor_version'),
rq.Pad(16),
)
def query_version(self):
return QueryVersion(
display = self.display,
opcode = self.display.get_extension_major(extname),
)
class RedirectWindow(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(1),
rq.RequestLength(),
rq.Window('window'),
rq.Set('update', 1, (RedirectAutomatic, RedirectManual)),
rq.Pad(3),
)
def redirect_window(self, update):
"""Redirect the hierarchy starting at this window to off-screen
storage.
"""
RedirectWindow(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self,
update = update,
)
class RedirectSubwindows(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(2),
rq.RequestLength(),
rq.Window('window'),
rq.Set('update', 1, (RedirectAutomatic, RedirectManual)),
rq.Pad(3),
)
def redirect_subwindows(self, update):
"""Redirect the hierarchies starting at all current and future
children to this window to off-screen storage.
"""
RedirectSubwindows(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self,
update = update,
)
class UnredirectWindow(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(3),
rq.RequestLength(),
rq.Window('window'),
rq.Set('update', 1, (RedirectAutomatic, RedirectManual)),
rq.Pad(3),
)
def unredirect_window(self, update):
"""Stop redirecting this window hierarchy.
"""
UnredirectWindow(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self,
update = update,
)
class UnredirectSubindows(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(4),
rq.RequestLength(),
rq.Window('window'),
rq.Set('update', 1, (RedirectAutomatic, RedirectManual)),
rq.Pad(3),
)
def unredirect_subwindows(self, update):
"""Stop redirecting the hierarchies of children to this window.
"""
RedirectWindow(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self,
update = update,
)
class CreateRegionFromBorderClip(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(5),
rq.RequestLength(),
rq.Card32('region'), # FIXME: this should be a Region from XFIXES extension
rq.Window('window'),
)
def create_region_from_border_clip(self):
"""Create a region of the border clip of the window, i.e. the area
that is not clipped by the parent and any sibling windows.
"""
rid = self.display.allocate_resource_id()
CreateRegionFromBorderClip(
display = self.display,
opcode = self.display.get_extension_major(extname),
region = rid,
window = self,
)
# FIXME: create Region object and return it
return rid
class NameWindowPixmap(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(6),
rq.RequestLength(),
rq.Window('window'),
rq.Pixmap('pixmap'),
)
def name_window_pixmap(self):
"""Create a new pixmap that refers to the off-screen storage of
the window, including its border.
This pixmap will remain allocated until freed whatever happens
with the window. However, the window will get a new off-screen
pixmap every time it is mapped or resized, so to keep track of the
contents you must listen for these events and get a new pixmap
after them.
"""
pid = self.display.allocate_resource_id()
NameWindowPixmap(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self,
pixmap = pid,
)
cls = self.display.get_resource_class('pixmap', drawable.Pixmap)
return cls(self.display, pid, owner = 1)
def init(disp, info):
disp.extension_add_method('display',
'composite_query_version',
query_version)
disp.extension_add_method('window',
'composite_redirect_window',
redirect_window)
disp.extension_add_method('window',
'composite_redirect_subwindows',
redirect_subwindows)
disp.extension_add_method('window',
'composite_unredirect_window',
unredirect_window)
disp.extension_add_method('window',
'composite_unredirect_subwindows',
unredirect_subwindows)
disp.extension_add_method('window',
'composite_create_region_from_border_clip',
create_region_from_border_clip)
disp.extension_add_method('window',
'composite_name_window_pixmap',
name_window_pixmap)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,278 @@
# Xlib.ext.record -- RECORD extension module
#
# Copyright (C) 2006 Alex Badea <vamposdecampos@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from Xlib import X
from Xlib.protocol import rq
extname = 'RECORD'
FromServerTime = 0x01
FromClientTime = 0x02
FromClientSequence = 0x04
CurrentClients = 1
FutureClients = 2
AllClients = 3
FromServer = 0
FromClient = 1
ClientStarted = 2
ClientDied = 3
StartOfData = 4
EndOfData = 5
Record_Range8 = rq.Struct(
rq.Card8('first'),
rq.Card8('last'))
Record_Range16 = rq.Struct(
rq.Card16('first'),
rq.Card16('last'))
Record_ExtRange = rq.Struct(
rq.Object('major_range', Record_Range8),
rq.Object('minor_range', Record_Range16))
Record_Range = rq.Struct(
rq.Object('core_requests', Record_Range8),
rq.Object('core_replies', Record_Range8),
rq.Object('ext_requests', Record_ExtRange),
rq.Object('ext_replies', Record_ExtRange),
rq.Object('delivered_events', Record_Range8),
rq.Object('device_events', Record_Range8),
rq.Object('errors', Record_Range8),
rq.Bool('client_started'),
rq.Bool('client_died'))
Record_ClientInfo = rq.Struct(
rq.Card32('client_resource'),
rq.LengthOf('ranges', 4),
rq.List('ranges', Record_Range))
class RawField(rq.ValueField):
"""A field with raw data, stored as a string"""
structcode = None
def pack_value(self, val):
return val, len(val), None
def parse_binary_value(self, data, display, length, format):
return data, ''
class GetVersion(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(0),
rq.RequestLength(),
rq.Card16('major_version'),
rq.Card16('minor_version'))
_reply = rq.Struct(
rq.Pad(2),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card16('major_version'),
rq.Card16('minor_version'),
rq.Pad(20))
def get_version(self, major, minor):
return GetVersion(
display = self.display,
opcode = self.display.get_extension_major(extname),
major_version = major,
minor_version = minor)
class CreateContext(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(1),
rq.RequestLength(),
rq.Card32('context'), # Record_RC
rq.Card8('element_header'), # Record_Element_Header
rq.Pad(3),
rq.LengthOf('clients', 4),
rq.LengthOf('ranges', 4),
rq.List('clients', rq.Card32Obj),
rq.List('ranges', Record_Range))
def create_context(self, datum_flags, clients, ranges):
context = self.display.allocate_resource_id()
CreateContext(
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context,
element_header = datum_flags,
clients = clients,
ranges = ranges)
return context
class RegisterClients(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(2),
rq.RequestLength(),
rq.Card32('context'), # Record_RC
rq.Card8('element_header'), # Record_Element_Header
rq.Pad(3),
rq.LengthOf('clients', 4),
rq.LengthOf('ranges', 4),
rq.List('clients', rq.Card32Obj),
rq.List('ranges', Record_Range))
def register_clients(self, context, element_header, clients, ranges):
RegisterClients(
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context,
element_header = element_header,
clients = clients,
ranges = ranges)
class UnregisterClients(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(3),
rq.RequestLength(),
rq.Card32('context'), # Record_RC
rq.LengthOf('clients', 4),
rq.List('clients', rq.Card32Obj))
def unregister_clients(self, context, clients):
UnregisterClients(
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context,
clients = clients)
class GetContext(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(4),
rq.RequestLength(),
rq.Card32('context')) # Record_RC
_reply = rq.Struct(
rq.Pad(2),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card8('element_header'), # Record_Element_Header
rq.Pad(3),
rq.LengthOf('client_info', 4),
rq.Pad(16),
rq.List('client_info', Record_ClientInfo))
def get_context(self, context):
return GetContext(
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context)
class EnableContext(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(5),
rq.RequestLength(),
rq.Card32('context')) # Record_RC
_reply = rq.Struct(
rq.Pad(1),
rq.Card8('category'),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card8('element_header'), # Record_Element_Header
rq.Bool('client_swapped'),
rq.Pad(2),
rq.Card32('id_base'), # Record_XIDBase
rq.Card32('server_time'),
rq.Card32('recorded_sequence_number'),
rq.Pad(8),
RawField('data'))
# This request receives multiple responses, so we need to keep
# ourselves in the 'sent_requests' list in order to receive them all.
# See the discussion on ListFonstsWithInfo in request.py
def __init__(self, callback, *args, **keys):
self._callback = callback
rq.ReplyRequest.__init__(self, *args, **keys)
def _parse_response(self, data):
r, d = self._reply.parse_binary(data, self._display)
self._callback(r)
if r.category == StartOfData:
# Hack ourselves a sequence number, used by the code in
# Xlib.protocol.display.Display.parse_request_response()
self.sequence_number = r.sequence_number
if r.category == EndOfData:
self._response_lock.acquire()
self._data = r
self._response_lock.release()
else:
self._display.sent_requests.insert(0, self)
def enable_context(self, context, callback):
EnableContext(
callback = callback,
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context)
class DisableContext(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(6),
rq.RequestLength(),
rq.Card32('context')) # Record_RC
def disable_context(self, context):
DisableContext(
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context)
class FreeContext(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(7),
rq.RequestLength(),
rq.Card32('context')) # Record_RC
def free_context(self, context):
FreeContext(
display = self.display,
opcode = self.display.get_extension_major(extname),
context = context)
self.display.free_resource_id(context)
def init(disp, info):
disp.extension_add_method('display', 'record_get_version', get_version)
disp.extension_add_method('display', 'record_create_context', create_context)
disp.extension_add_method('display', 'record_register_clients', register_clients)
disp.extension_add_method('display', 'record_unregister_clients', unregister_clients)
disp.extension_add_method('display', 'record_get_context', get_context)
disp.extension_add_method('display', 'record_enable_context', enable_context)
disp.extension_add_method('display', 'record_disable_context', disable_context)
disp.extension_add_method('display', 'record_free_context', free_context)

View File

@@ -0,0 +1,334 @@
# Xlib.ext.shape -- SHAPE extension module
#
# Copyright (C) 2002 Jeffrey Boser <verin@lvcm.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Constants to use
#
# Regions of a window
ShapeBounding = 0 # the 'edge' of a shaped window
ShapeClip = 1 # the clipping region
# Shape Operations
ShapeSet = 0 # Set the region unmodified (dest=src)
ShapeUnion = 1 # Add the new region to the old (dest=src|dest)
ShapeIntersect = 2 # Use the intersection (dest=src&dest)
ShapeSubtract = 3 # remove region (dest = dest - intersect)
ShapeInvert = 4 # opposite of subtract (dest = src - intersect)
# Events
ShapeNotifyMask = (1<<0) #a keypress mask?
ShapeNotify = 0 #still unsure of these values
# How to Use
# The basic functions that change the shapes of things are:
# shape_rectangles (uses a set of rectangles as the source)
# operation, region, ordering, rects
# shape_mask (uses a bitmap as the source)
# operation, region, x_offset, y_offset, bitmap
# shape_combine (uses a window as the source)
# operation, src_region, dest_region, x_offset, y_offset, src_window
# shape_offset (moves the region)
# region, x_offset, y_offset
# The functions to find stuff out (these three return mappings of field/values):
# shape_query_version (shape extension version)
# major_version, minor_version
# shape_query_extents (rectangle boundaries of a window's regions)
# clip_shaped, clip_x, clip_y, clip_width, clip_height,
# bounding_shaped, bounding_x, bounding_y, bounding_width, bounding_height
# shape_input_selected (if the window products shapenotify events)
# enabled
# shape_get_rectangles (the rectangles set by shape_rectangles)
# ordering, rects
# And to turn on shape notify events:
# shape_select_input
# enable
from Xlib import X
from Xlib.protocol import rq, structs
extname = 'SHAPE'
class QueryVersion(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(0),
rq.RequestLength(),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card16('major_version'),
rq.Card16('minor_version'),
rq.Pad(20),
)
def query_version(self):
return QueryVersion(
display = self.display,
opcode = self.display.get_extension_major(extname),
)
class Rectangles(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(1),
rq.RequestLength(),
rq.Card8('operation'),
rq.Set('region', 1, (ShapeBounding, ShapeClip)),
rq.Card8('ordering'),
rq.Pad(1),
rq.Window('window'),
rq.Int16('x'),
rq.Int16('y'),
rq.List('rectangles', structs.Rectangle),
)
def rectangles(self, region, operation, ordering, x, y, rectangles):
Rectangles(
display = self.display,
opcode = self.display.get_extension_major(extname),
operation = operation,
region = region,
ordering = ordering,
window = self.id,
x = x,
y = y,
rectangles = rectangles,
)
class Mask(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(2),
rq.RequestLength(),
rq.Card8('operation'),
rq.Set('region', 1, (ShapeBounding, ShapeClip)),
rq.Pad(2),
rq.Window('window'),
rq.Int16('x'),
rq.Int16('y'),
rq.Pixmap('source', (X.NONE, )),
)
def mask(self, operation, region, x, y, source):
Mask(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self.id,
operation = operation,
region = region,
x = x,
y = y,
source = source,
)
class Combine(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(3),
rq.RequestLength(),
rq.Card8('operation'),
rq.Set('dest_region', 1, (ShapeBounding, ShapeClip)),
rq.Set('source_region', 1, (ShapeBounding, ShapeClip)),
rq.Pad(1),
rq.Window('dest'),
rq.Int16('x'),
rq.Int16('y'),
rq.Window('source'),
)
def combine(self, operation, region, source, source_region, x, y):
Combine(
display = self.display,
opcode = self.display.get_extension_major(extname),
operation = operation,
dest_region = region,
source_region = source_region,
dest = self.id,
x = x,
y = y,
source = source,
)
class Offset(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(4),
rq.RequestLength(),
rq.Set('region', 1, (ShapeBounding, ShapeClip)),
rq.Pad(3),
rq.Window('window'),
rq.Int16('x'),
rq.Int16('y'),
)
def offset(self, region, x, y):
Offset(
display = self.display,
opcode = self.display.get_extension_major(extname),
region = region,
window = self.id,
x = x,
y = y,
)
class QueryExtents(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(5),
rq.RequestLength(),
rq.Window('window'),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Bool('bounding_shaped'),
rq.Bool('clip_shaped'),
rq.Pad(2),
rq.Int16('bounding_x'),
rq.Int16('bounding_y'),
rq.Card16('bounding_width'),
rq.Card16('bounding_height'),
rq.Int16('clip_x'),
rq.Int16('clip_y'),
rq.Card16('clip_width'),
rq.Card16('clip_height'),
rq.Pad(4),
)
def query_extents(self):
return QueryExtents(
display = self.display,
opcode = self.display.get_extension_major(extname),
window = self.id,
)
class SelectInput(rq.Request):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(6),
rq.RequestLength(),
rq.Window('window'),
rq.Bool('enable'),
rq.Pad(3),
)
def select_input(self, enable = 1):
SelectInput(
display = self.display,
opcode = self.display.get_extension_major(extname),
window = self.id,
enable = enable,
)
class InputSelected(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(7),
rq.RequestLength(),
rq.Window('window'),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Bool('enabled'),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Pad(24),
)
def input_selected(self):
reply = InputSelected(
display = self.display,
opcode = self.display.get_extension_major(extname),
window = self.id,
)
return reply.enabled
class GetRectangles(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(8),
rq.RequestLength(),
rq.Window('window'),
rq.Set('region', 1, (ShapeBounding, ShapeClip)),
rq.Pad(3),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Card8('ordering'),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.LengthOf('rectangles', 4),
rq.Pad(20),
rq.List('rectangles', structs.Rectangle),
)
def get_rectangles(self, region):
return GetRectangles(
display = self.display,
opcode = self.display.get_extension_major(extname),
window = self.id,
region = region,
)
class ShapeNotify(rq.Event):
_code = None
_fields = rq.Struct( rq.Card8('type'),
rq.Set('region', 1, (ShapeBounding, ShapeClip)),
rq.Card16('sequence_number'),
rq.Window('window'),
rq.Int16('x'),
rq.Int16('y'),
rq.Card16('width'),
rq.Card16('height'),
rq.Card32('time'),
rq.Bool('shaped'),
rq.Pad(11),
)
def init(disp, info):
disp.extension_add_method('display', 'shape_query_version', query_version )
disp.extension_add_method('window', 'shape_rectangles', rectangles )
disp.extension_add_method('window', 'shape_mask', mask )
disp.extension_add_method('window', 'shape_combine', combine )
disp.extension_add_method('window', 'shape_offset', offset )
disp.extension_add_method('window', 'shape_query_extents', query_extents )
disp.extension_add_method('window', 'shape_select_input', select_input )
disp.extension_add_method('window', 'shape_input_selected', input_selected )
disp.extension_add_method('window', 'shape_get_rectangles', get_rectangles )
disp.extension_add_event(info.first_event, ShapeNotify)

View File

@@ -0,0 +1,221 @@
# Xlib.ext.xinerama -- Xinerama extension module
#
# Copyright (C) 2006 Mike Meyer <mwm@mired.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Xinerama - provide access to the Xinerama extension information.
There are at least there different - and mutually incomparable -
Xinerama extensions available. This uses the one bundled with XFree86
4.6 and/or Xorg 6.9 in the ati/radeon driver. It uses the include
files from that X distribution, so should work with it as well. I
provide code for the lone Sun 1.0 request that isn't part of 1.1, but
this is untested because I don't have a server that implements it.
The functions loosely follow the libXineram functions. Mostly, they
return an rq.Struct in lieue of passing in pointers that get data from
the rq.Struct crammed into them. The exception is isActive, which
returns the state information - because that's what libXinerama does."""
from Xlib import X
from Xlib.protocol import rq, structs
extname = 'XINERAMA'
class QueryVersion(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(0),
rq.RequestLength(),
rq.Card8('major_version'),
rq.Card8('minor_version'),
rq.Pad(2),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card16('major_version'),
rq.Card16('minor_version'),
rq.Pad(20),
)
def query_version(self):
return QueryVersion(display=self.display,
opcode=self.display.get_extension_major(extname),
major_version=1,
minor_version=1)
class GetState(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(1),
rq.RequestLength(),
rq.Window('window'),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Bool('state'),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Window('window'),
rq.Pad(20),
)
def get_state(self):
return GetState(display=self.display,
opcode=self.display.get_extension_major(extname),
window=self.id,
)
class GetScreenCount(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(2),
rq.RequestLength(),
rq.Window('window'),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Card8('screen_count'),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Window('window'),
rq.Pad(20),
)
def get_screen_count(self):
return GetScreenCount(display=self.display,
opcode=self.display.get_extension_major(extname),
window=self.id,
)
class GetScreenSize(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(3),
rq.RequestLength(),
rq.Window('window'),
rq.Card32('screen'),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.Card32('length'),
rq.Card32('width'),
rq.Card32('height'),
rq.Window('window'),
rq.Card32('screen'),
rq.Pad(8),
)
def get_screen_size(self, screen_no):
"""Returns the size of the given screen number"""
return GetScreenSize(display=self.display,
opcode=self.display.get_extension_major(extname),
window=self.id,
screen=screen_no,
)
# IsActive is only available from Xinerama 1.1 and later.
# It should be used in preference to GetState.
class IsActive(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(4),
rq.RequestLength(),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card32('state'),
rq.Pad(20),
)
def is_active(self):
r = IsActive(display=self.display,
opcode=self.display.get_extension_major(extname),
)
return r.state
# QueryScreens is only available from Xinerama 1.1 and later
class QueryScreens(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(5),
rq.RequestLength(),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Card32('number'),
rq.Pad(20),
rq.List('screens', structs.Rectangle),
)
def query_screens(self):
# Hmm. This one needs to read the screen data from the socket. Ooops...
return QueryScreens(display=self.display,
opcode=self.display.get_extension_major(extname),
)
# GetInfo is only available from some Xinerama 1.0, and *NOT* later! Untested
class GetInfo(rq.ReplyRequest):
_request = rq.Struct(
rq.Card8('opcode'),
rq.Opcode(4),
rq.RequestLength(),
rq.Card32('visual'),
)
_reply = rq.Struct(
rq.ReplyCode(),
rq.Pad(1),
rq.Card16('sequence_number'),
rq.ReplyLength(),
rq.Window('window'),
# An array of subwindow slots goes here. Bah.
)
def get_info(self, visual):
r = GetInfo(display=self.display,
opcode=self.display.get_extension_major(extname),
visual=visual)
def init(disp, info):
disp.extension_add_method('display', 'xinerama_query_version', query_version)
disp.extension_add_method('window', 'xinerama_get_state', get_state)
disp.extension_add_method('window', 'xinerama_get_screen_count', get_screen_count)
disp.extension_add_method('window', 'xinerama_get_screen_size', get_screen_size)
disp.extension_add_method('display', 'xinerama_is_active', is_active)
disp.extension_add_method('display', 'xinerama_query_screens', query_screens)
disp.extension_add_method('display', 'xinerama_get_info', get_info)

View File

@@ -0,0 +1,119 @@
# Xlib.ext.xtest -- XTEST extension module
#
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from Xlib import X
from Xlib.protocol import rq
extname = 'XTEST'
CurrentCursor = 1
class GetVersion(rq.ReplyRequest):
_request = rq.Struct(rq.Card8('opcode'),
rq.Opcode(0),
rq.RequestLength(),
rq.Card8('major_version'),
rq.Pad(1),
rq.Card16('minor_version')
)
_reply = rq.Struct(rq.Pad(1),
rq.Card8('major_version'),
rq.Card16('sequence_number'),
rq.Pad(4),
rq.Card16('minor_version'),
rq.Pad(22)
)
def get_version(self, major, minor):
return GetVersion(display = self.display,
opcode = self.display.get_extension_major(extname),
major_version = major,
minor_version = minor)
class CompareCursor(rq.ReplyRequest):
_request = rq.Struct(rq.Card8('opcode'),
rq.Opcode(1),
rq.RequestLength(),
rq.Window('window'),
rq.Cursor('cursor', (X.NONE, CurrentCursor)),
)
_reply = rq.Struct(rq.Pad(1),
rq.Card8('same'),
rq.Card16('sequence_number'),
rq.Pad(28),
)
def compare_cursor(self, cursor):
r = CompareCursor(display = self.display,
opcode = self.display.get_extension_major(extname),
window = self.id,
cursor = cursor)
return r.same
class FakeInput(rq.Request):
_request = rq.Struct(rq.Card8('opcode'),
rq.Opcode(2),
rq.RequestLength(),
rq.Set('event_type', 1, (X.KeyPress,
X.KeyRelease,
X.ButtonPress,
X.ButtonRelease,
X.MotionNotify)),
rq.Card8('detail'),
rq.Pad(2),
rq.Card32('time'),
rq.Window('root', (X.NONE, )),
rq.Pad(8),
rq.Int16('x'),
rq.Int16('y'),
rq.Pad(8)
)
def fake_input(self, event_type, detail = 0, time = X.CurrentTime,
root = X.NONE, x = 0, y = 0):
FakeInput(display = self.display,
opcode = self.display.get_extension_major(extname),
event_type = event_type,
detail = detail,
time = time,
root = root,
x = x,
y = y)
class GrabControl(rq.Request):
_request = rq.Struct(rq.Card8('opcode'),
rq.Opcode(3),
rq.RequestLength(),
rq.Bool('impervious'),
rq.Pad(3)
)
def grab_control(self, impervious):
GrabControl(display = self.display,
opcode = self.display.get_extension_major(extname),
impervious = impervious)
def init(disp, info):
disp.extension_add_method('display', 'xtest_get_version', get_version)
disp.extension_add_method('window', 'xtest_compare_cursor', compare_cursor)
disp.extension_add_method('display', 'xtest_fake_input', fake_input)
disp.extension_add_method('display', 'xtest_grab_control', grab_control)