From 5c18894ab9c2b3beb20a616fc4328381ee59786a Mon Sep 17 00:00:00 2001 From: Antikyth <104020300+Antikyth@users.noreply.github.com> Date: Sat, 14 Jan 2023 17:04:48 +0000 Subject: [PATCH 001/157] WIP - rewrite requests --- src/lib.rs | 2 +- src/x11/request.rs | 37 ++ src/x11/requests/mod.rs | 1190 --------------------------------------- 3 files changed, 38 insertions(+), 1191 deletions(-) create mode 100644 src/x11/request.rs delete mode 100644 src/x11/requests/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 7aa51e58..eba27893 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,7 +62,7 @@ pub mod message; /// Implementation of the core X11 protocol. pub mod x11 { pub mod event; - // pub mod request; + pub mod request; } pub use common::*; diff --git a/src/x11/request.rs b/src/x11/request.rs new file mode 100644 index 00000000..4d8dd94d --- /dev/null +++ b/src/x11/request.rs @@ -0,0 +1,37 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +//! Requests: commands to the X server. +//! +//! Requests are messages sent _from_ the client _to_ the X server. They are +//! commands for the X server to carry out. Some requests generate replies +//! that are sent back to the client. + +use crate::{Inheritable, VisualId, Window, WindowClass}; +use bytes::BufMut; +use xrbk::{Buf, ConstantX11Size, ReadError, ReadResult, Readable, Writable, WriteResult, X11Size}; + +use crate::mask::AttributeMask; + +use xrbk_macro::derive_xrb; +extern crate self as xrb; + +derive_xrb! { + #[derive(Debug, Hash, PartialEq, Eq, X11Size, Readable, Writable)] + pub struct CreateWindow: Request(1) { + #[metabyte] + pub depth: u8, + + pub window_id: Window, + pub parent: Window, + pub x: i16, + pub y: i16, + pub width: u16, + pub height: u16, + pub border_width: u16, + //pub class: Inheritable, + //pub visual: Inheritable, + pub attribute_mask: AttributeMask, + } +} diff --git a/src/x11/requests/mod.rs b/src/x11/requests/mod.rs deleted file mode 100644 index cf4d5b57..00000000 --- a/src/x11/requests/mod.rs +++ /dev/null @@ -1,1190 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -use crate::x11::*; -use xrb_proc_macros::messages; - -messages! { - /// Creates an unmapped window with the given `window_id`. - /// - /// # Events - /// - [CreateNotify] - /// - /// # Errors - /// - [Alloc] - /// - [Colormap] - /// - [Cursor] - /// - [IdChoice] - /// - [Match] -- Generated if the `class` is [`InputOutput`] and the `visual` - /// type and `depth` are not a combination supported by the screen, or if - /// the `class` is [`InputOnly`] and the `depth` is not [`CopyFromParent`] - /// or `0`. - /// - [Pixmap] - /// - [Value] - /// - [Window] - /// - /// [Alloc]: crate::x11::errors::Alloc - /// [Colormap]: crate::x11::errors::Colormap - /// [Cursor]: crate::x11::errors::Cursor - /// [IdChoice]: crate::x11::errors::IdChoice - /// [Match]: crate::x11::errors::Match - /// [Pixmap]: crate::x11::errors::Pixmap - /// [Value]: crate::x11::errors::Value - /// [Window]: crate::x11::errors::Window - pub struct CreateWindow<'a>(1) { - /// The resource ID given to the window. - pub window_id: Window, - /// The parent of which the window will be created as a child of. - pub parent: Window, - /// The [window class] of the window. - /// - /// For [`InputOutput`], the `visual` type and `depth` must be a - /// combination supported by the screen, else a [`Match`] error occurs. - /// - /// For [`InputOnly`], the `depth` must be [`CopyFromParent`] (or `0`). - /// - /// [`InputOutput`]: WindowClass::InputOutput - /// [`InputOnly`]: WindowClass::InputOnly - /// [window class]: WindowClass - /// [`Match`]: crate::x11::errors::Match - pub class: Inheritable, - /// The color depth of the window in bits per pixel. - /// - /// If the class is not [`InputOnly`], [`CopyFromParent`] will copy the - /// `depth` from the parent. __If the class is [`InputOnly`], this must - /// be set to [`CopyFromParent`]__, else a [`Match`] error shall occur. - /// - /// [`InputOnly`]: WindowClass::InputOnly - /// [`CopyFromParent`]: Inherit::CopyFromParent - /// [`Match`]: crate::x11::errors::Match - pub $depth: Inheritable, - pub visual: Inheritable, - /// The initial x-coordinate of the window relative to its parent's - /// top-left corner. - pub x: i16, - /// The initial y-coordinate of the window relative to its parent's - /// top-right corner. - pub y: i16, - /// The width of the window. - pub width: u16, - /// The height of the window. - pub height: u16, - pub border_width: u16, - pub value_mask: AttributeMask, - /// A list of [window attributes] that are to configured for the window. - /// - /// [window attributes]: Attribute - pub values: &'a [Attribute], // Window is a placeholder until WinAttr is done - } - - pub struct ChangeWindowAttributes<'a>(2) { - pub target: Window, - pub value_mask: AttributeMask, - pub values: &'a [Attribute], - } - - pub struct GetWindowAttributes(3) -> GetWindowAttributesReply { - pub target: Window, - } - - pub struct GetWindowAttributesReply for GetWindowAttributes { - pub $backing_store: BackingStore, - pub visual: VisualId, - pub class: WindowClass, - pub bit_gravity: BitGravity, - pub win_gravity: WinGravity, - pub backing_planes: u32, - pub backing_pixel: u32, - pub save_under: bool, - pub map_is_installed: bool, - pub map_state: MapState, - pub override_redirect: bool, - pub colormap: Option, - pub all_event_masks: EventMask, - pub your_event_mask: EventMask, - pub do_not_propagate_mask: DeviceEventMask, - [(); 2], - } - - pub struct DestroyWindow(4): pub target: Window; - pub struct DestroySubwindows(5): pub target: Window; - - pub struct ChangeSaveSet(6) { - pub $mode: EditMode, - pub target: Window, - } - - pub struct ReparentWindow(7) { - pub target: Window, - pub new_parent: Window, - pub new_x: i16, - pub new_y: i16, - } - - pub struct MapWindow(8): pub target: Window; - pub struct MapSubwindows(9): pub target: Window; - - pub struct UnmapWindow(10): pub target: Window; - pub struct UnmapSubwindows(11): pub target: Window; - - pub struct ConfigureWindow<'a>(12) { - pub target: Window, - pub value_mask: ConfigureWindowMask, - pub values: &'a [ConfigureWindowValue], - } - - pub struct CirculateWindow(13) { - pub $direction: CirculateDirection, - pub target: Window, - } - - pub struct GetGeometry(14) -> GetGeometryReply: pub target: Box; - - pub struct GetGeometryReply for GetGeometry { - pub $depth: u8, - pub root: Window, - pub x: i16, - pub y: i16, - pub width: u16, - pub height: u16, - pub border_width: u16, - [(); 10], - } - - pub struct QueryTree(15) -> QueryTreeReply: pub target: Window; - - pub struct QueryTreeReply for QueryTree { - pub root: Window, - pub parent: Option, - #children: u16, - [(); 14], - pub children: Vec, - } - - pub struct InternAtom(16) -> InternAtomReply { - pub $only_if_exists: bool, - #name: u16, - [(); 2], - pub name: String8, - [(); {name}], - } - - pub struct InternAtomReply for InternAtom { - pub atom: Option, - [(); 20], - } - - pub struct GetAtomName(17) -> GetAtomNameReply: pub atom: Atom; - - pub struct GetAtomNameReply for GetAtomName { - #name: u16, - [(); 22], - pub name: String8, - [(); {name}], - } - - // The property requests (`ChangeProperty(18)`, `DeleteProperty(19)`, - // `GetProperty(20)`, and `ListProperties(21)`) are special cases and need - // to be defined manually. You can find them in `mod properties;`. - - pub struct SetSelectionOwner(22) { - pub $owner: Option, - pub selection: Atom, - pub time: Time, - } - - pub struct GetSelectionOwner(23) -> GetSelectionOwnerReply { - pub selection: Atom, - } - - pub struct GetSelectionOwnerReply for GetSelectionOwner { - pub owner: Option, - [(); 20], - } - - pub struct ConvertSelection(24) { - pub requestor: Window, - pub selection: Atom, - pub target: Atom, - pub property: Option, - pub time: Time, - } - - pub struct SendEvent(25) { - pub $propagate: bool, - pub destination: Destination, - pub event_mask: EventMask, - //pub event: Box, - } - - pub struct GrabPointer(26) -> GrabPointerReply { - pub $owner_events: bool, - pub target_window: Window, - pub event_mask: PointerEventMask, - pub pointer_mode: GrabMode, - pub keyboard_mode: GrabMode, - pub confine_to: Option, - pub cursor_override: Option, - pub time: Time, - } - - pub struct GrabPointerReply for GrabPointer { - pub $status: GrabStatus, - [(); 24], - } - - pub struct UngrabPointer(27): pub time: Time; - - pub struct GrabButton(28) { - pub $owner_events: bool, - pub target_window: Window, - pub event_mask: PointerEventMask, - pub pointer_mode: GrabMode, - pub keyboard_mode: GrabMode, - pub confine_to: Option, - pub cursor_override: Option, - pub button: Any