# $Id: request.py,v 1.13 2007/06/10 14:11:58 mggrant Exp $
#
# Xlib.protocol.request -- definitions of core requests
#
#    Copyright (C) 2000-2002 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


# Xlib modules
from Xlib import X

# Xlib.protocol modules
import rq
import structs


class CreateWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(1),
        rq.Card8('depth'),
        rq.RequestLength(),
        rq.Window('wid'),
        rq.Window('parent'),
        rq.Int16('x'),
        rq.Int16('y'),
        rq.Card16('width'),
        rq.Card16('height'),
        rq.Card16('border_width'),
        rq.Set('window_class', 2, (X.CopyFromParent, X.InputOutput, X.InputOnly)),
        rq.Card32('visual'),
        structs.WindowValues('attrs'),
        )

class ChangeWindowAttributes(rq.Request):
    _request = rq.Struct(
        rq.Opcode(2),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window'),
        structs.WindowValues('attrs'),
        )

class GetWindowAttributes(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(3),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Card8('backing_store'),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Card32('visual'),
        rq.Card16('win_class'),
        rq.Card8('bit_gravity'),
        rq.Card8('win_gravity'),
        rq.Card32('backing_bit_planes'),
        rq.Card32('backing_pixel'),
        rq.Card8('save_under'),
        rq.Card8('map_is_installed'),
        rq.Card8('map_state'),
        rq.Card8('override_redirect'),
        rq.Colormap('colormap', (X.NONE, )),
        rq.Card32('all_event_masks'),
        rq.Card32('your_event_mask'),
        rq.Card16('do_not_propagate_mask'),
        rq.Pad(2),
        )

class DestroyWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(4),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

class DestroySubWindows(rq.Request):
    _request = rq.Struct(
        rq.Opcode(5),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

class ChangeSaveSet(rq.Request):
    _request = rq.Struct(
        rq.Opcode(6),
        rq.Set('mode', 1, (X.SetModeInsert, X.SetModeDelete)),
        rq.RequestLength(),
        rq.Window('window'),
        )

class ReparentWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(7),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window'),
        rq.Window('parent'),
        rq.Int16('x'),
        rq.Int16('y'),
        )

class MapWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(8),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

class MapSubwindows(rq.Request):
    _request = rq.Struct(
        rq.Opcode(9),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

class UnmapWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(10),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

class UnmapSubwindows(rq.Request):
    _request = rq.Struct(
        rq.Opcode(11),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

class ConfigureWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(12),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window'),
        rq.ValueList( 'attrs', 2, 2,
                      rq.Int16('x'),
                      rq.Int16('y'),
                      rq.Card16('width'),
                      rq.Card16('height'),
                      rq.Int16('border_width'),
                      rq.Window('sibling'),
                      rq.Set('stack_mode', 1,
                             (X.Above, X.Below, X.TopIf,
                              X.BottomIf, X.Opposite))
                      )
        )

class CirculateWindow(rq.Request):
    _request = rq.Struct(
        rq.Opcode(13),
        rq.Set('direction', 1, (X.RaiseLowest, X.LowerHighest)),
        rq.RequestLength(),
        rq.Window('window'),
        )

class GetGeometry(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(14),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Drawable('drawable')
        )

    _reply = rq.Struct (
        rq.ReplyCode(),
        rq.Card8('depth'),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Window('root'),
        rq.Int16('x'),
        rq.Int16('y'),
        rq.Card16('width'),
        rq.Card16('height'),
        rq.Card16('border_width'),
        rq.Pad(10)
        )

class QueryTree(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(15),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Pad(1),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Window('root'),
        rq.Window('parent', (X.NONE, )),
        rq.LengthOf('children', 2),
        rq.Pad(14),
        rq.List('children', rq.WindowObj),
        )

class InternAtom(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(16),
        rq.Bool('only_if_exists'),
        rq.RequestLength(),
        rq.LengthOf('name', 2),
        rq.Pad(2),
        rq.String8('name'),
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Pad(1),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Card32('atom'),
        rq.Pad(20),
        )


class GetAtomName(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(17),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Card32('atom')
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Pad(1),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.LengthOf('name', 2),
        rq.Pad(22),
        rq.String8('name'),
        )

class ChangeProperty(rq.Request):
    _request = rq.Struct(
        rq.Opcode(18),
        rq.Set('mode', 1, (X.PropModeReplace, X.PropModePrepend, X.PropModeAppend)),
        rq.RequestLength(),
        rq.Window('window'),
        rq.Card32('property'),
        rq.Card32('type'),
        rq.Format('data', 1),
        rq.Pad(3),
        rq.LengthOf('data', 4),
        rq.PropertyData('data'),
        )

class DeleteProperty(rq.Request):
    _request = rq.Struct(
        rq.Opcode(19),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window'),
        rq.Card32('property'),
        )

class GetProperty(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(20),
        rq.Bool('delete'),
        rq.RequestLength(),
        rq.Window('window'),
        rq.Card32('property'),
        rq.Card32('type'),
        rq.Card32('long_offset'),
        rq.Card32('long_length'),
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Format('value', 1),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Card32('property_type'),
        rq.Card32('bytes_after'),
        rq.LengthOf('value', 4),
        rq.Pad(12),
        rq.PropertyData('value'),
        )

class ListProperties(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(21),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window')
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Pad(1),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.LengthOf('atoms', 2),
        rq.Pad(22),
        rq.List('atoms', rq.Card32Obj),
        )

class SetSelectionOwner(rq.Request):
    _request = rq.Struct(
        rq.Opcode(22),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('window'),
        rq.Card32('selection'),
        rq.Card32('time'),
        )

class GetSelectionOwner(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(23),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Card32('selection')
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Pad(1),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Window('owner', (X.NONE, )),
        rq.Pad(20),
        )

class ConvertSelection(rq.Request):
    _request = rq.Struct(
        rq.Opcode(24),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Window('requestor'),
        rq.Card32('selection'),
        rq.Card32('target'),
        rq.Card32('property'),
        rq.Card32('time'),
        )

class SendEvent(rq.Request):
    _request = rq.Struct(
        rq.Opcode(25),
        rq.Bool('propagate'),
        rq.RequestLength(),
        rq.Window('destination'),
        rq.Card32('event_mask'),
        rq.EventField('event'),
        )

class GrabPointer(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(26),
        rq.Bool('owner_events'),
        rq.RequestLength(),
        rq.Window('grab_window'),
        rq.Card16('event_mask'),
        rq.Set('pointer_mode', 1, (X.GrabModeSync, X.GrabModeAsync)),
        rq.Set('keyboard_mode', 1, (X.GrabModeSync, X.GrabModeAsync)),
        rq.Window('confine_to', (X.NONE, )),
        rq.Cursor('cursor', (X.NONE, )),
        rq.Card32('time'),
        )

    _reply = rq.Struct(
        rq.ReplyCode(),
        rq.Card8('status'),
        rq.Card16('sequence_number'),
        rq.ReplyLength(),
        rq.Pad(24),
        )

class UngrabPointer(rq.Request):
    _request = rq.Struct(
        rq.Opcode(27),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Card32('time')
        )

class GrabButton(rq.Request):
    _request = rq.Struct(
        rq.Opcode(28),
        rq.Bool('owner_events'),
        rq.RequestLength(),
        rq.Window('grab_window'),
        rq.Card16('event_mask'),
        rq.Set('pointer_mode', 1, (X.GrabModeSync, X.GrabModeAsync)),
        rq.Set('keyboard_mode', 1, (X.GrabModeSync, X.GrabModeAsync)),
        rq.Window('confine_to', (X.NONE, )),
        rq.Cursor('cursor', (X.NONE, )),
        rq.Card8('button'),
        rq.Pad(1),
        rq.Card16('modifiers'),
        )

class UngrabButton(rq.Request):
    _request = rq.Struct(
        rq.Opcode(29),
        rq.Card8('button'),
        rq.RequestLength(),
        rq.Window('grab_window'),
        rq.Card16('modifiers'),
        rq.Pad(2),
        )

class ChangeActivePointerGrab(rq.Request):
    _request = rq.Struct(
        rq.Opcode(30),
        rq.Pad(1),
        rq.RequestLength(),
        rq.Cursor('cursor'),
        rq.Card32('time'),
        rq.Card16('event_mask'),
        rq.Pad(2),
        )

class GrabKeyboard(rq.ReplyRequest):
    _request = rq.Struct(
        rq.Opcode(31),
        rq.Bool('owner_events'),
        rq.RequestLength(),
        rq.Window('grab_window'),
        rq.Card32('time'),
        rq.Set('pointer_mode', 1, (X.GrabModeSync, X.GrabModeAsync)),
        rq.Set('keyboard_mode', 1, (X.GrabModeSync, X.GrabModeAsync)),