Updated winit to 0.27.2 for examples and raw-window-handle to 0.5.0
This commit is contained in:
parent
bef3c52706
commit
d30d3255c2
8 changed files with 72 additions and 41 deletions
24
src/x11.rs
24
src/x11.rs
|
|
@ -1,10 +1,11 @@
|
|||
use crate::{GraphicsContextImpl, SoftBufferError};
|
||||
use raw_window_handle::{HasRawWindowHandle, XlibHandle};
|
||||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, XlibDisplayHandle, XlibWindowHandle};
|
||||
use std::os::raw::{c_char, c_uint};
|
||||
use x11_dl::xlib::{Display, Visual, Xlib, ZPixmap, GC};
|
||||
|
||||
pub struct X11Impl {
|
||||
handle: XlibHandle,
|
||||
window_handle: XlibWindowHandle,
|
||||
display_handle: XlibDisplayHandle,
|
||||
lib: Xlib,
|
||||
gc: GC,
|
||||
visual: *mut Visual,
|
||||
|
|
@ -12,19 +13,20 @@ pub struct X11Impl {
|
|||
}
|
||||
|
||||
impl X11Impl {
|
||||
pub unsafe fn new<W: HasRawWindowHandle>(handle: XlibHandle) -> Result<Self, SoftBufferError<W>> {
|
||||
pub unsafe fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(window_handle: XlibWindowHandle, display_handle: XlibDisplayHandle) -> Result<Self, SoftBufferError<W>> {
|
||||
let lib = match Xlib::open() {
|
||||
Ok(lib) => lib,
|
||||
Err(e) => return Err(SoftBufferError::PlatformError(Some("Failed to open Xlib".into()), Some(Box::new(e))))
|
||||
};
|
||||
let screen = (lib.XDefaultScreen)(handle.display as *mut Display);
|
||||
let gc = (lib.XDefaultGC)(handle.display as *mut Display, screen);
|
||||
let visual = (lib.XDefaultVisual)(handle.display as *mut Display, screen);
|
||||
let depth = (lib.XDefaultDepth)(handle.display as *mut Display, screen);
|
||||
let screen = (lib.XDefaultScreen)(display_handle.display as *mut Display);
|
||||
let gc = (lib.XDefaultGC)(display_handle.display as *mut Display, screen);
|
||||
let visual = (lib.XDefaultVisual)(display_handle.display as *mut Display, screen);
|
||||
let depth = (lib.XDefaultDepth)(display_handle.display as *mut Display, screen);
|
||||
|
||||
Ok(
|
||||
Self {
|
||||
handle,
|
||||
window_handle,
|
||||
display_handle,
|
||||
lib,
|
||||
gc,
|
||||
visual,
|
||||
|
|
@ -38,7 +40,7 @@ impl GraphicsContextImpl for X11Impl {
|
|||
unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
|
||||
//create image
|
||||
let image = (self.lib.XCreateImage)(
|
||||
self.handle.display as *mut Display,
|
||||
self.display_handle.display as *mut Display,
|
||||
self.visual,
|
||||
self.depth as u32,
|
||||
ZPixmap,
|
||||
|
|
@ -52,8 +54,8 @@ impl GraphicsContextImpl for X11Impl {
|
|||
|
||||
//push image to window
|
||||
(self.lib.XPutImage)(
|
||||
self.handle.display as *mut Display,
|
||||
self.handle.window,
|
||||
self.display_handle.display as *mut Display,
|
||||
self.window_handle.window,
|
||||
self.gc,
|
||||
image,
|
||||
0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue