asdf
This commit is contained in:
parent
d8860f28cc
commit
5dbbe7be24
10 changed files with 113 additions and 23 deletions
4
build.rs
4
build.rs
|
@ -2,9 +2,12 @@ use std::env;
|
|||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(feature = "glx")]
|
||||
use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry};
|
||||
|
||||
fn main() {
|
||||
#[cfg(feature = "glx")]
|
||||
{
|
||||
let dest = env::var("OUT_DIR").unwrap();
|
||||
let mut file = File::create(&Path::new(&dest).join("bindings.rs")).unwrap();
|
||||
|
||||
|
@ -12,3 +15,4 @@ fn main() {
|
|||
.write_bindings(GlobalGenerator, &mut file)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
//! An extension that bridges X11 with OpenGL, an API used for rendering
|
||||
//! graphics with the GPU.
|
||||
|
||||
mod context;
|
||||
mod drawable;
|
||||
|
||||
|
@ -10,6 +13,7 @@ pub use self::context::GlxContext;
|
|||
pub use self::drawable::GlxDrawable;
|
||||
|
||||
pub trait GlxExtension {
|
||||
/// Checks if glx is available in this implementation.
|
||||
fn query_glx_extension(&self) -> Result<bool>;
|
||||
|
||||
fn create_context(
|
||||
|
|
11
src/rect.rs
11
src/rect.rs
|
@ -22,3 +22,14 @@ impl Rectangle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(i32, i32, u32, u32)> for Rectangle {
|
||||
fn from((x, y, width, height): (i32, i32, u32, u32)) -> Self {
|
||||
Rectangle {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
//! An extension that enables applications and window managers to use two or
|
||||
//! more physical displays as one large virtual display.
|
||||
|
||||
mod screen_info;
|
||||
|
||||
pub use self::screen_info::ScreensInfo;
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
|
||||
//! Component of x11 related to listing available input devices, querying
|
||||
//! information about a device and changing input device settings.
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Display {
|
|||
let ptr = event.as_mut_ptr();
|
||||
unsafe { xlib::XNextEvent(self.inner, ptr) };
|
||||
// TODO: check to make sure this isn't null
|
||||
let mut event = unsafe { event.assume_init() };
|
||||
let event = unsafe { event.assume_init() };
|
||||
debug!("event: {:?}", event);
|
||||
unsafe { Event::from_raw(event) }
|
||||
}
|
||||
|
@ -179,10 +179,10 @@ impl Display {
|
|||
/// Query extension
|
||||
pub fn query_extension(&self, name: impl AsRef<str>) -> Result<()> {
|
||||
let name = ffi::c_char_star_from_string(name)?;
|
||||
let mut major_opcode_return = ptr::null_mut();
|
||||
let mut first_event_return = ptr::null_mut();
|
||||
let mut first_error_return = ptr::null_mut();
|
||||
let result = unsafe {
|
||||
let major_opcode_return = ptr::null_mut();
|
||||
let first_event_return = ptr::null_mut();
|
||||
let first_error_return = ptr::null_mut();
|
||||
let _result = unsafe {
|
||||
xlib::XQueryExtension(
|
||||
self.inner,
|
||||
name,
|
||||
|
@ -198,7 +198,7 @@ impl Display {
|
|||
|
||||
/// List extensions
|
||||
pub fn list_extensions(&self) -> Result<ListExtensions> {
|
||||
let mut nextensions_return = ptr::null_mut();
|
||||
let nextensions_return = ptr::null_mut();
|
||||
let result = unsafe { xlib::XListExtensions(self.inner, nextensions_return) };
|
||||
// TODO: check result null
|
||||
// TODO: check nextensions_return
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
//! The core of x11
|
||||
|
||||
mod atom;
|
||||
mod cursor;
|
||||
mod display;
|
||||
mod drawable;
|
||||
mod event;
|
||||
mod image;
|
||||
mod pixmap;
|
||||
mod visual;
|
||||
mod window;
|
||||
|
||||
|
@ -14,4 +17,5 @@ pub use self::drawable::Drawable;
|
|||
pub use self::event::{Event, EventKind};
|
||||
pub use self::image::{Image, ImageByteOrder, PixBuffer};
|
||||
pub use self::visual::{Visual, VisualInfo};
|
||||
pub use self::window::{EventMask, Window};
|
||||
pub use self::window::{EventMask, SetWindowAttributes, Window, WindowAttributes};
|
||||
pub use self::pixmap::PixMap;
|
||||
|
|
20
src/xlib/pixmap.rs
Normal file
20
src/xlib/pixmap.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use x11::xlib;
|
||||
|
||||
/// Pixmaps are off-screen resources that are used for various operations, for
|
||||
/// example, defining cursors as tiling patterns or as the source for certain
|
||||
/// raster operations
|
||||
///
|
||||
/// Most graphics requests can operate either on a window or on a pixmap. A
|
||||
/// bitmap is a single bit-plane pixmap. Pixmaps can only be used on the screen
|
||||
/// on which they were created.
|
||||
#[derive(Debug)]
|
||||
pub struct PixMap {
|
||||
pub(crate) display: *mut xlib::Display,
|
||||
pub(crate) inner: xlib::Pixmap,
|
||||
}
|
||||
|
||||
impl Drop for PixMap {
|
||||
fn drop(&mut self) {
|
||||
unsafe { xlib::XFreePixmap(self.display, self.inner) };
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
use std::mem;
|
||||
use std::os::raw::c_ulong;
|
||||
use std::os::raw::{c_long, c_ulong};
|
||||
use std::ptr;
|
||||
|
||||
use x11::xlib;
|
||||
|
||||
|
@ -10,12 +11,13 @@ use super::atom::Atom;
|
|||
use super::display::{Display, GetDisplay};
|
||||
use super::drawable::Drawable;
|
||||
use super::image::Image;
|
||||
use super::pixmap::PixMap;
|
||||
|
||||
/// A wrapper around a window handle.
|
||||
#[derive(Clone)]
|
||||
pub struct Window<'a> {
|
||||
pub(super) display: &'a Display,
|
||||
pub(super) inner: xlib::Window,
|
||||
pub(crate) display: &'a Display,
|
||||
pub(crate) inner: xlib::Window,
|
||||
}
|
||||
|
||||
impl<'a> Window<'a> {
|
||||
|
@ -24,6 +26,7 @@ impl<'a> Window<'a> {
|
|||
display: &'a Display,
|
||||
parent: Option<Window>,
|
||||
location: Rectangle,
|
||||
set_attributes: SetWindowAttributes,
|
||||
) -> Result<Window<'a>> {
|
||||
let parent = match parent {
|
||||
Some(parent) => parent,
|
||||
|
@ -43,7 +46,7 @@ impl<'a> Window<'a> {
|
|||
0,
|
||||
visual.as_raw(),
|
||||
0,
|
||||
0 as *mut xlib::XSetWindowAttributes,
|
||||
set_attributes.into_raw(),
|
||||
)
|
||||
};
|
||||
Ok(Window {
|
||||
|
@ -148,12 +151,6 @@ pub struct WindowAttributes<'a> {
|
|||
pub(self) inner: *mut xlib::XWindowAttributes,
|
||||
}
|
||||
|
||||
// impl AsRef<Drawable> for Window {
|
||||
// fn as_ref(&self) -> &Drawable {
|
||||
// &self.inner
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<'a> WindowAttributes<'a> {
|
||||
/// Gets the width of the window
|
||||
pub fn get_x(&self) -> i32 {
|
||||
|
@ -184,7 +181,14 @@ impl<'a> WindowAttributes<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for WindowAttributes<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe { libc::free(self.inner as *mut libc::c_void) };
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Default)]
|
||||
pub struct EventMask: c_ulong {
|
||||
const NO_EVENT_MASK = 0;
|
||||
const KEY_PRESS_MASK = (1<<0);
|
||||
|
@ -214,3 +218,39 @@ bitflags! {
|
|||
const OWNER_GRAB_BUTTON_MASK = (1<<24);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct SetWindowAttributes {
|
||||
pub background_pixmap: Option<PixMap>,
|
||||
pub background_pixel: c_ulong,
|
||||
pub border_pixmap: Option<PixMap>,
|
||||
pub border_pixel: c_ulong,
|
||||
pub save_under: bool,
|
||||
pub event_mask: EventMask,
|
||||
pub do_not_propagate_mask: c_long,
|
||||
pub override_redirect: bool,
|
||||
}
|
||||
|
||||
impl SetWindowAttributes {
|
||||
pub fn into_raw(self) -> *mut xlib::XSetWindowAttributes {
|
||||
let result = xlib::XSetWindowAttributes {
|
||||
background_pixmap: unimplemented!(),
|
||||
background_pixel: self.background_pixel,
|
||||
border_pixmap: unimplemented!(),
|
||||
border_pixel: unimplemented!(),
|
||||
bit_gravity: unimplemented!(),
|
||||
win_gravity: unimplemented!(),
|
||||
backing_store: unimplemented!(),
|
||||
backing_planes: unimplemented!(),
|
||||
backing_pixel: unimplemented!(),
|
||||
save_under: self.save_under.into(),
|
||||
event_mask: self.event_mask.bits() as i64,
|
||||
do_not_propagate_mask: self.do_not_propagate_mask,
|
||||
override_redirect: self.override_redirect.into(),
|
||||
colormap: unimplemented!(),
|
||||
cursor: unimplemented!(),
|
||||
};
|
||||
|
||||
Box::into_raw(Box::new(result))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
//! An extension that deals with rendering and compositing images with other
|
||||
//! drawing primitives.
|
||||
|
||||
mod picture;
|
||||
|
|
Loading…
Reference in a new issue