1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
/*
* Copyright (C) 2013 James Miller <james@aatch.net>
* Copyright (c) 2016
* Remi Thebault <remi.thebault@gmail.com>
* Thomas Bracht Laumann Jespersen <laumann.thomas@gmail.com>
* Copyright (c) 2017-2021 Remi Thebault <remi.thebault@gmail.com>
*
* Permission is hereby granted, free of charge, to any
* person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the
* Software without restriction, including without
* limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice
* shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
* ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
* SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_parens)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::diverging_sub_expression)]
//! Rust bindings to the XCB library.
//!
//! The X protocol C-language Binding (XCB - <https://xcb.freedesktop.org/>) is
//! a replacement for Xlib featuring a small footprint, latency hiding, direct
//! access to the protocol, improved threading support, and extensibility.
//!
//! The communication is established with the X server by the creation of a
//! [Connection] object.
//!
//! A client communicates with the server by sending requests. There are 2 types
//! of requests:
//!
//! - void requests: requests that do not expect an answer
//! (e.g. [x::ChangeProperty])
//! - non-void requests: requests that need a `Reply` (e.g. [x::GetProperty])
//!
//! Requests are passed to the server by filling a request structure e.g.
//! [x::CreateWindow] and passing it to [Connection::send_request].
//!
//! The server can also communicate with clients by sending `Event`s.
//! The client listens to events with calls such as [Connection::wait_for_event]
//! (blocking) or [Connection::poll_for_event] (non-blocking).
//!
//! The [x] module contains definitions of the core X protocol.
//! Each extension is defined in its own module such as [xkb] or [render], and
//! is activated by a cargo feature of the same name.
//!
//! # Example
//!
//! Here is a walk-through of a simple `xcb` client.
//! ```no_run
//! // we import the necessary modules (only the core X module in this application).
//! use xcb::{x};
//! // we need to import the `Xid` trait for the `resource_id` call down there.
//! use xcb::{Xid};
//!
//! // Many xcb functions return a `xcb::Result` or compatible result.
//! fn main() -> xcb::Result<()> {
//! // Connect to the X server.
//! let (conn, screen_num) = xcb::Connection::connect(None)?;
//!
//! // Fetch the `x::Setup` and get the main `x::Screen` object.
//! let setup = conn.get_setup();
//! let screen = setup.roots().nth(screen_num as usize).unwrap();
//!
//! // Generate an `Xid` for the client window.
//! // The type inference is needed here.
//! let window: x::Window = conn.generate_id();
//!
//! // We can now create a window. For this we pass a `Request`
//! // object to the `send_request_checked` method. The method
//! // returns a cookie that will be used to check for success.
//! let cookie = conn.send_request_checked(&x::CreateWindow {
//! depth: x::COPY_FROM_PARENT as u8,
//! wid: window,
//! parent: screen.root(),
//! x: 0,
//! y: 0,
//! width: 150,
//! height: 150,
//! border_width: 0,
//! class: x::WindowClass::InputOutput,
//! visual: screen.root_visual(),
//! // this list must be in same order than `Cw` enum order
//! value_list: &[
//! x::Cw::BackPixel(screen.white_pixel()),
//! x::Cw::EventMask(x::EventMask::EXPOSURE | x::EventMask::KEY_PRESS)
//! ],
//! });
//! // We now check if the window creation worked.
//! // A cookie can't be cloned; it is moved to the function.
//! conn.check_request(cookie)?;
//!
//! // Let's change the window title
//! let cookie = conn.send_request_checked(&x::ChangeProperty {
//! mode: x::PropMode::Replace,
//! window,
//! property: x::ATOM_WM_NAME,
//! r#type: x::ATOM_STRING,
//! data: b"My XCB Window",
//! });
//! // And check for success again
//! conn.check_request(cookie);
//!
//! // We now show ("map" in X terminology) the window.
//! // This time we do not check for success, so we discard the cookie.
//! conn.send_request(&x::MapWindow {
//! window,
//! });
//!
//! // We need a few atoms for our application.
//! // We send a few requests in a row and wait for the replies after.
//! let (wm_protocols, wm_del_window, wm_state, wm_state_maxv, wm_state_maxh) = {
//! let cookies = (
//! conn.send_request(&x::InternAtom {
//! only_if_exists: true,
//! name: "WM_PROTOCOLS",
//! }),
//! conn.send_request(&x::InternAtom {
//! only_if_exists: true,
//! name: "WM_DELETE_WINDOW",
//! }),
//! conn.send_request(&x::InternAtom {
//! only_if_exists: true,
//! name: "_NET_WM_STATE",
//! }),
//! conn.send_request(&x::InternAtom {
//! only_if_exists: true,
//! name: "_NET_WM_STATE_MAXIMIZED_VERT",
//! }),
//! conn.send_request(&x::InternAtom {
//! only_if_exists: true,
//! name: "_NET_WM_STATE_MAXIMIZED_HORZ",
//! }),
//! );
//! (
//! conn.wait_for_reply(cookies.0)?.atom(),
//! conn.wait_for_reply(cookies.1)?.atom(),
//! conn.wait_for_reply(cookies.2)?.atom(),
//! conn.wait_for_reply(cookies.3)?.atom(),
//! conn.wait_for_reply(cookies.4)?.atom(),
//! )
//! };
//!
//! // We now activate the window close event by sending the following request.
//! // If we don't do this we can still close the window by clicking on the "x" button,
//! // but the event loop is notified through a connection shutdown error.
//! conn.check_request(conn.send_request_checked(&x::ChangeProperty {
//! mode: x::PropMode::Replace,
//! window,
//! property: wm_protocols,
//! r#type: x::ATOM_ATOM,
//! data: &[wm_del_window],
//! }))?;
//!
//! // Previous request was checked, so a flush is not necessary in this case.
//! // Otherwise, here is how to perform a connection flush.
//! conn.flush()?;
//!
//! let mut maximized = false;
//!
//! // We enter the main event loop
//! loop {
//! match conn.wait_for_event()? {
//! xcb::Event::X(x::Event::KeyPress(ev)) => {
//! if ev.detail() == 0x3a {
//! // The M key was pressed
//! // (M only on qwerty keyboards. Keymap support is done
//! // with the `xkb` extension and the `xkbcommon-rs` crate)
//!
//! // We toggle maximized state, for this we send a message
//! // by building a `x::ClientMessageEvent` with the proper
//! // atoms and send it to the server.
//!
//! let data = x::ClientMessageData::Data32([
//! if maximized { 0 } else { 1 },
//! wm_state_maxv.resource_id(),
//! wm_state_maxh.resource_id(),
//! 0,
//! 0,
//! ]);
//! let event = x::ClientMessageEvent::new(window, wm_state, data);
//! let cookie = conn.send_request_checked(&x::SendEvent {
//! propagate: false,
//! destination: x::SendEventDest::Window(screen.root()),
//! event_mask: x::EventMask::STRUCTURE_NOTIFY,
//! event: &event,
//! });
//! conn.check_request(cookie)?;
//!
//! // Same as before, if we don't check for error, we have to flush
//! // the connection.
//! // conn.flush()?;
//!
//! maximized = !maximized;
//! } else if ev.detail() == 0x18 {
//! // Q (on qwerty)
//!
//! // We exit the event loop (and the program)
//! break Ok(());
//! }
//! }
//! xcb::Event::X(x::Event::ClientMessage(ev)) => {
//! // We have received a message from the server
//! if let x::ClientMessageData::Data32([atom, ..]) = ev.data() {
//! if atom == wm_del_window.resource_id() {
//! // The received atom is "WM_DELETE_WINDOW".
//! // We can check here if the user needs to save before
//! // exit, or in our case, exit right away.
//! break Ok(());
//! }
//! }
//! }
//! _ => {}
//! }
//! }
//! }
//! ```
mod base;
mod error;
mod event;
mod ext;
pub use base::*;
pub use error::*;
pub use event::*;
pub use ext::*;
pub mod x {
//! The core X protocol definitions
pub use super::xproto::*;
}
pub mod ffi {
//! Module for Foreign Function Interface bindings.
#![allow(non_camel_case_types)]
#![allow(improper_ctypes)]
pub(crate) mod base;
pub(crate) mod ext;
#[cfg(feature = "xlib_xcb")]
pub(crate) mod xlib_xcb;
pub use base::*;
pub use ext::*;
#[cfg(feature = "xlib_xcb")]
pub use xlib_xcb::*;
}
#[cfg(test)]
mod test;
mod xproto {
#![allow(unused_variables)]
#![allow(clippy::unit_arg)]
#![allow(clippy::new_ret_no_self)]
#![allow(clippy::too_many_arguments)]
/// `COPY_FROM_PARENT` can be used for many `CreateWindow` fields
pub const COPY_FROM_PARENT: u32 = 0;
/// `CURRENT_TIME` can be used in most requests that take a `Timestamp`
pub const CURRENT_TIME: Timestamp = 0;
/// `NO_SYMBOL` fills in unused entries in `Keysym` tables
pub const NO_SYMBOL: Keysym = 0;
/// Trait for element in a property list
///
/// In events (e.g. `GetProperty::value`), it allows to assert that the format
/// correspond to the type cast and therefore to do the cast safely at runtime.
///
/// In request (e.g. `ChangeProperty::data`), it allows to infer the format value
/// from the type of passed data.
pub trait PropEl {
const FORMAT: u8;
}
impl PropEl for u8 {
const FORMAT: u8 = 8;
}
impl PropEl for u16 {
const FORMAT: u8 = 16;
}
impl PropEl for u32 {
const FORMAT: u8 = 32;
}
impl PropEl for Atom {
const FORMAT: u8 = 32;
}
include!(concat!(env!("OUT_DIR"), "/xproto.rs"));
}
pub mod bigreq {
//! The `BIG-REQUESTS` extension.
include!(concat!(env!("OUT_DIR"), "/bigreq.rs"));
}
pub mod xc_misc {
//! The `XC-MISC` extension.
include!(concat!(env!("OUT_DIR"), "/xc_misc.rs"));
}
#[cfg(feature = "composite")]
pub mod composite {
//! The `Composite` X extension.
//!
//! Accessible with the `composite` cargo feature.
include!(concat!(env!("OUT_DIR"), "/composite.rs"));
}
#[cfg(feature = "damage")]
pub mod damage {
//! The `DAMAGE` X extension.
//!
//! Accessible with the `damage` cargo feature.
include!(concat!(env!("OUT_DIR"), "/damage.rs"));
}
#[cfg(feature = "dpms")]
pub mod dpms {
//! The `DPMS` X extension.
//!
//! Accessible with the `dpms` cargo feature.
include!(concat!(env!("OUT_DIR"), "/dpms.rs"));
}
#[cfg(feature = "dri2")]
pub mod dri2 {
//! The `DRI2` X extension.
//!
//! Accessible with the `dri2` cargo feature.
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/dri2.rs"));
}
#[cfg(feature = "dri3")]
pub mod dri3 {
//! The `DRI3` X extension.
//!
//! Accessible with the `dri3` cargo feature.
include!(concat!(env!("OUT_DIR"), "/dri3.rs"));
}
#[cfg(feature = "ge")]
pub mod ge {
//! The `Generic Event Extension` X extension.
//!
//! Accessible with the `ge` cargo feature.
include!(concat!(env!("OUT_DIR"), "/ge.rs"));
}
#[cfg(feature = "glx")]
pub mod glx {
//! The `GLX` X extension.
//!
//! Accessible with the `glx` cargo feature.
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/glx.rs"));
}
#[cfg(feature = "xinput")]
pub mod xinput {
//! The `XInputExtension` X extension.
//!
//! Accessible with the `xinput` cargo feature.
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(clippy::unit_arg)]
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/xinput.rs"));
}
#[cfg(feature = "present")]
pub mod present {
//! The `Present` X extension.
//!
//! Accessible with the `present` cargo feature.
#![allow(clippy::unit_arg)]
include!(concat!(env!("OUT_DIR"), "/present.rs"));
}
#[cfg(feature = "randr")]
pub mod randr {
//! The `RANDR` X extension.
//!
//! Accessible with the `randr` cargo feature.
#![allow(clippy::unit_arg)]
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/randr.rs"));
}
#[cfg(feature = "record")]
pub mod record {
//! The `RECORD` X extension.
//!
//! Accessible with the `record` cargo feature.
#![allow(clippy::unit_arg)]
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/record.rs"));
}
#[cfg(feature = "render")]
pub mod render {
//! The `RENDER` X extension.
//!
//! Accessible with the `render` cargo feature.
#![allow(unused_variables)]
#![allow(clippy::unit_arg)]
include!(concat!(env!("OUT_DIR"), "/render.rs"));
}
#[cfg(feature = "res")]
pub mod res {
//! The `X-Resource` X extension.
//!
//! Accessible with the `res` cargo feature.
#![allow(unused_variables)]
#![allow(clippy::unit_arg)]
include!(concat!(env!("OUT_DIR"), "/res.rs"));
}
#[cfg(feature = "screensaver")]
pub mod screensaver {
//! The `MIT-SCREEN-SAVER` X extension.
//!
//! Accessible with the `screensaver` cargo feature.
#![allow(unused_variables)]
include!(concat!(env!("OUT_DIR"), "/screensaver.rs"));
}
#[cfg(feature = "xselinux")]
pub mod xselinux {
//! The `SELinux` X extension.
//!
//! Accessible with the `xselinux` cargo feature.
#![allow(clippy::unit_arg)]
include!(concat!(env!("OUT_DIR"), "/xselinux.rs"));
}
#[cfg(feature = "shape")]
pub mod shape {
//! The `SHAPE` X extension.
//!
//! Accessible with the `shape` cargo feature.
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/shape.rs"));
}
#[cfg(feature = "shm")]
pub mod shm {
//! The `MIT-SHM` X extension.
//!
//! Accessible with the `shm` cargo feature.
include!(concat!(env!("OUT_DIR"), "/shm.rs"));
}
#[cfg(feature = "sync")]
pub mod sync {
//! The `SYNC` X extension.
//!
//! Accessible with the `sync` cargo feature.
#![allow(unused_variables)]
#![allow(clippy::unit_arg)]
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/sync.rs"));
}
#[cfg(feature = "xtest")]
pub mod xtest {
//! The `XTEST` X extension.
//!
//! Accessible with the `xtest` cargo feature.
include!(concat!(env!("OUT_DIR"), "/xtest.rs"));
}
#[cfg(feature = "xprint")]
pub mod xprint {
//! The `XpExtension` X extension.
//!
//! Accessible with the `xprint` cargo feature.
#![allow(clippy::unit_arg)]
include!(concat!(env!("OUT_DIR"), "/xprint.rs"));
}
#[cfg(feature = "xevie")]
pub mod xevie {
//! The `XEVIE` X extension.
//!
//! Accessible with the `xevie` cargo feature.
include!(concat!(env!("OUT_DIR"), "/xevie.rs"));
}
#[cfg(feature = "xf86dri")]
pub mod xf86dri {
//! The `XFree86-DRI` X extension.
//!
//! Accessible with the `xf86dri` cargo feature.
include!(concat!(env!("OUT_DIR"), "/xf86dri.rs"));
}
#[cfg(feature = "xf86vidmode")]
pub mod xf86vidmode {
//! The `XFree86-VidModeExtension` X extension.
//!
//! Accessible with the `xf86vidmode` cargo feature.
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/xf86vidmode.rs"));
}
#[cfg(feature = "xfixes")]
pub mod xfixes {
//! The `XFIXES` X extension.
//!
//! Accessible with the `xfixes` cargo feature.
include!(concat!(env!("OUT_DIR"), "/xfixes.rs"));
}
#[cfg(feature = "xinerama")]
pub mod xinerama {
//! The `XINERAMA` X extension.
//!
//! Accessible with the `xinerama` cargo feature.
include!(concat!(env!("OUT_DIR"), "/xinerama.rs"));
}
#[cfg(feature = "xkb")]
pub mod xkb {
//! The `XKEYBOARD` X extension.
//!
//! Accessible with the `xkb` cargo feature.
#![allow(unused_variables)]
#![allow(clippy::unit_arg)]
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/xkb.rs"));
}
#[cfg(feature = "xv")]
pub mod xv {
//! The `XVideo` X extension.
//!
//! Accessible with the `xv` cargo feature.
#![allow(clippy::unit_arg)]
#![allow(clippy::too_many_arguments)]
include!(concat!(env!("OUT_DIR"), "/xv.rs"));
}
#[cfg(feature = "xvmc")]
pub mod xvmc {
//! The `XVideo-MotionCompensation` X extension.
//!
//! Accessible with the `xvmc` cargo feature.
include!(concat!(env!("OUT_DIR"), "/xvmc.rs"));
}