Skip to content

Commit

Permalink
Remove depdendency x11rb's image feature
Browse files Browse the repository at this point in the history
The code only used x11rb's image feature for splitting a large PutImage
request into smaller pieces. Since X11 servers usually have a maximum
request size of 16 MiB these days, it is unlikely that people create
cursors large enough to go above this limit. You'd need a 2k x 2k cursor
for that!

Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed May 30, 2021
1 parent 912991d commit d864ac0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ glib = { version = "0.10.1", optional = true }
glib-sys = { version = "0.10.0", optional = true }
gtk-sys = { version = "0.10.0", optional = true }
nix = { version = "0.18.0", optional = true }
x11rb = { version = "0.8.0", features = ["allow-unsafe-code", "present", "render", "randr", "xfixes", "resource_manager", "cursor", "image"], optional = true }
x11rb = { version = "0.8.0", features = ["allow-unsafe-code", "present", "render", "randr", "xfixes", "resource_manager", "cursor"], optional = true }

[target.'cfg(target_arch="wasm32")'.dependencies]
wasm-bindgen = "0.2.67"
Expand Down
25 changes: 6 additions & 19 deletions druid-shell/src/platform/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

//! X11 window creation and window management.
use std::borrow::Cow;
use std::cell::{Cell, RefCell};
use std::collections::BinaryHeap;
use std::convert::{TryFrom, TryInto};
Expand All @@ -31,14 +30,13 @@ use tracing::{error, info, warn};
use x11rb::atom_manager;
use x11rb::connection::Connection;
use x11rb::errors::ReplyOrIdError;
use x11rb::image::{BitsPerPixel, Image, ImageOrder, ScanlinePad};
use x11rb::protocol::present::{CompleteNotifyEvent, ConnectionExt as _, IdleNotifyEvent};
use x11rb::protocol::render::{ConnectionExt as _, Pictformat};
use x11rb::protocol::xfixes::{ConnectionExt as _, Region as XRegion};
use x11rb::protocol::xproto::{
self, AtomEnum, ChangeWindowAttributesAux, ConfigureNotifyEvent, ConnectionExt, CreateGCAux,
EventMask, Gcontext, ImageOrder as X11ImageOrder, Pixmap, PropMode, Rectangle, Visualtype,
WindowClass,
EventMask, Gcontext, ImageFormat, ImageOrder as X11ImageOrder, Pixmap, PropMode, Rectangle,
Visualtype, WindowClass,
};
use x11rb::wrapper::ConnectionExt as _;
use x11rb::xcb_ffi::XCBConnection;
Expand Down Expand Up @@ -1734,27 +1732,16 @@ fn make_cursor(
})
})
.collect::<Vec<u8>>();
let image = Image::new(
desc.image.width().try_into().expect("Invalid cursor width"),
desc.image
.height()
.try_into()
.expect("Invalid cursor height"),
ScanlinePad::Pad8,
32,
BitsPerPixel::B32,
ImageOrder::MSBFirst,
Cow::Owned(pixels),
)
.expect("We got the number of bytes for this image wrong?!");
let width = desc.image.width().try_into().expect("Invalid cursor width");
let height = desc.image.height().try_into().expect("Invalid cursor height");

let pixmap = conn.generate_id()?;
let gc = conn.generate_id()?;
let picture = conn.generate_id()?;
conn.create_pixmap(32, pixmap, root_window, image.width(), image.height())?;
conn.create_pixmap(32, pixmap, root_window, width, height)?;
conn.create_gc(gc, pixmap, &Default::default())?;

image.put(conn, pixmap, gc, 0, 0)?;
conn.put_image(ImageFormat::Z_PIXMAP, pixmap, gc, width, height, 0, 0, 0, 32, &pixels)?;
conn.render_create_picture(picture, pixmap, argb32_format, &Default::default())?;

conn.free_gc(gc)?;
Expand Down

0 comments on commit d864ac0

Please sign in to comment.