rustfmt 0.9 update
This commit is contained in:
parent
b131f8168e
commit
206007f5a5
39
build.rs
39
build.rs
|
@ -12,22 +12,25 @@ fn main() {
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
|
|
||||||
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
|
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
|
||||||
Registry::new(Api::Egl,
|
Registry::new(
|
||||||
(1, 5),
|
Api::Egl,
|
||||||
Profile::Core,
|
(1, 5),
|
||||||
Fallbacks::All,
|
Profile::Core,
|
||||||
["EGL_KHR_create_context",
|
Fallbacks::All,
|
||||||
"EGL_EXT_create_context_robustness",
|
[
|
||||||
"EGL_KHR_create_context_no_error",
|
"EGL_KHR_create_context",
|
||||||
"EGL_KHR_platform_x11",
|
"EGL_EXT_create_context_robustness",
|
||||||
"EGL_KHR_platform_android",
|
"EGL_KHR_create_context_no_error",
|
||||||
"EGL_KHR_platform_wayland",
|
"EGL_KHR_platform_x11",
|
||||||
"EGL_KHR_platform_gbm",
|
"EGL_KHR_platform_android",
|
||||||
"EGL_EXT_platform_base",
|
"EGL_KHR_platform_wayland",
|
||||||
"EGL_EXT_platform_x11",
|
"EGL_KHR_platform_gbm",
|
||||||
"EGL_MESA_platform_gbm",
|
"EGL_EXT_platform_base",
|
||||||
"EGL_EXT_platform_wayland",
|
"EGL_EXT_platform_x11",
|
||||||
"EGL_EXT_platform_device"])
|
"EGL_MESA_platform_gbm",
|
||||||
.write_bindings(gl_generator::StructGenerator, &mut file)
|
"EGL_EXT_platform_wayland",
|
||||||
.unwrap();
|
"EGL_EXT_platform_device",
|
||||||
|
],
|
||||||
|
).write_bindings(gl_generator::StructGenerator, &mut file)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,10 @@ fn main() {
|
||||||
|
|
||||||
// Insert the ShmGlobal as a handler to your event loop
|
// Insert the ShmGlobal as a handler to your event loop
|
||||||
// Here, we specify tha the standard Argb8888 and Xrgb8888 is the only supported.
|
// Here, we specify tha the standard Argb8888 and Xrgb8888 is the only supported.
|
||||||
let handler_id =
|
let handler_id = event_loop.add_handler_with_init(ShmGlobal::new(
|
||||||
event_loop.add_handler_with_init(ShmGlobal::new(vec![],
|
vec![],
|
||||||
None /* we don't provide a logger here */));
|
None, /* we don't provide a logger here */
|
||||||
|
));
|
||||||
|
|
||||||
// Register this handler to advertise a wl_shm global of version 1
|
// Register this handler to advertise a wl_shm global of version 1
|
||||||
let shm_global = event_loop.register_global::<wl_shm::WlShm, ShmGlobal>(handler_id, 1);
|
let shm_global = event_loop.register_global::<wl_shm::WlShm, ShmGlobal>(handler_id, 1);
|
||||||
|
|
|
@ -168,10 +168,11 @@ impl EGLContext {
|
||||||
///
|
///
|
||||||
/// This method is marked unsafe, because the contents of `NativeDisplay` cannot be verified and may
|
/// This method is marked unsafe, because the contents of `NativeDisplay` cannot be verified and may
|
||||||
/// contain dangling pointers or similar unsafe content
|
/// contain dangling pointers or similar unsafe content
|
||||||
pub unsafe fn new<L>(native: NativeDisplay, mut attributes: GlAttributes,
|
pub unsafe fn new<L>(native: NativeDisplay, mut attributes: GlAttributes, reqs: PixelFormatRequirements,
|
||||||
reqs: PixelFormatRequirements, logger: L)
|
logger: L)
|
||||||
-> Result<EGLContext, CreationError>
|
-> Result<EGLContext, CreationError>
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
let logger = logger.into();
|
let logger = logger.into();
|
||||||
let log = ::slog_or_stdlog(logger.clone()).new(o!("smithay_module" => "renderer_egl"));
|
let log = ::slog_or_stdlog(logger.clone()).new(o!("smithay_module" => "renderer_egl"));
|
||||||
|
@ -196,27 +197,31 @@ impl EGLContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some((1, _)) => {
|
Some((1, _)) => {
|
||||||
error!(log,
|
error!(
|
||||||
"OpenGLES 1.* is not supported by the EGL renderer backend");
|
log,
|
||||||
|
"OpenGLES 1.* is not supported by the EGL renderer backend"
|
||||||
|
);
|
||||||
return Err(CreationError::OpenGlVersionNotSupported);
|
return Err(CreationError::OpenGlVersionNotSupported);
|
||||||
}
|
}
|
||||||
Some(version) => {
|
Some(version) => {
|
||||||
error!(log,
|
error!(
|
||||||
"OpenGLES {:?} is unknown and not supported by the EGL renderer backend",
|
log,
|
||||||
version);
|
"OpenGLES {:?} is unknown and not supported by the EGL renderer backend",
|
||||||
|
version
|
||||||
|
);
|
||||||
return Err(CreationError::OpenGlVersionNotSupported);
|
return Err(CreationError::OpenGlVersionNotSupported);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lib = Library::new("libEGL.so.1")?;
|
let lib = Library::new("libEGL.so.1")?;
|
||||||
let egl = ffi::egl::Egl::load_with(|sym| {
|
let egl = ffi::egl::Egl::load_with(|sym| {
|
||||||
let name = CString::new(sym).unwrap();
|
let name = CString::new(sym).unwrap();
|
||||||
let symbol = lib.get::<*mut c_void>(name.as_bytes());
|
let symbol = lib.get::<*mut c_void>(name.as_bytes());
|
||||||
match symbol {
|
match symbol {
|
||||||
Ok(x) => *x as *const _,
|
Ok(x) => *x as *const _,
|
||||||
Err(_) => ptr::null(),
|
Err(_) => ptr::null(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// the first step is to query the list of extensions without any display, if supported
|
// the first step is to query the list of extensions without any display, if supported
|
||||||
let dp_extensions = {
|
let dp_extensions = {
|
||||||
|
@ -238,46 +243,54 @@ impl EGLContext {
|
||||||
let has_dp_extension = |e: &str| dp_extensions.iter().any(|s| s == e);
|
let has_dp_extension = |e: &str| dp_extensions.iter().any(|s| s == e);
|
||||||
|
|
||||||
let display = match native {
|
let display = match native {
|
||||||
NativeDisplay::X11(display) if has_dp_extension("EGL_KHR_platform_x11") &&
|
NativeDisplay::X11(display)
|
||||||
egl.GetPlatformDisplay.is_loaded() => {
|
if has_dp_extension("EGL_KHR_platform_x11") && egl.GetPlatformDisplay.is_loaded() => {
|
||||||
trace!(log, "EGL Display Initialization via EGL_KHR_platform_x11");
|
trace!(log, "EGL Display Initialization via EGL_KHR_platform_x11");
|
||||||
egl.GetPlatformDisplay(ffi::egl::PLATFORM_X11_KHR, display as *mut _, ptr::null())
|
egl.GetPlatformDisplay(ffi::egl::PLATFORM_X11_KHR, display as *mut _, ptr::null())
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeDisplay::X11(display) if has_dp_extension("EGL_EXT_platform_x11") &&
|
NativeDisplay::X11(display)
|
||||||
egl.GetPlatformDisplayEXT.is_loaded() => {
|
if has_dp_extension("EGL_EXT_platform_x11") && egl.GetPlatformDisplayEXT.is_loaded() => {
|
||||||
trace!(log, "EGL Display Initialization via EGL_EXT_platform_x11");
|
trace!(log, "EGL Display Initialization via EGL_EXT_platform_x11");
|
||||||
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_X11_EXT, display as *mut _, ptr::null())
|
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_X11_EXT, display as *mut _, ptr::null())
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeDisplay::Gbm(display) if has_dp_extension("EGL_KHR_platform_gbm") &&
|
NativeDisplay::Gbm(display)
|
||||||
egl.GetPlatformDisplay.is_loaded() => {
|
if has_dp_extension("EGL_KHR_platform_gbm") && egl.GetPlatformDisplay.is_loaded() => {
|
||||||
trace!(log, "EGL Display Initialization via EGL_KHR_platform_gbm");
|
trace!(log, "EGL Display Initialization via EGL_KHR_platform_gbm");
|
||||||
egl.GetPlatformDisplay(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null())
|
egl.GetPlatformDisplay(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null())
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeDisplay::Gbm(display) if has_dp_extension("EGL_MESA_platform_gbm") &&
|
NativeDisplay::Gbm(display)
|
||||||
egl.GetPlatformDisplayEXT.is_loaded() => {
|
if has_dp_extension("EGL_MESA_platform_gbm") && egl.GetPlatformDisplayEXT.is_loaded() => {
|
||||||
trace!(log, "EGL Display Initialization via EGL_MESA_platform_gbm");
|
trace!(log, "EGL Display Initialization via EGL_MESA_platform_gbm");
|
||||||
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null())
|
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null())
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeDisplay::Wayland(display) if has_dp_extension("EGL_KHR_platform_wayland") &&
|
NativeDisplay::Wayland(display)
|
||||||
egl.GetPlatformDisplay.is_loaded() => {
|
if has_dp_extension("EGL_KHR_platform_wayland") && egl.GetPlatformDisplay.is_loaded() => {
|
||||||
trace!(log,
|
trace!(
|
||||||
"EGL Display Initialization via EGL_KHR_platform_wayland");
|
log,
|
||||||
egl.GetPlatformDisplay(ffi::egl::PLATFORM_WAYLAND_KHR,
|
"EGL Display Initialization via EGL_KHR_platform_wayland"
|
||||||
display as *mut _,
|
);
|
||||||
ptr::null())
|
egl.GetPlatformDisplay(
|
||||||
|
ffi::egl::PLATFORM_WAYLAND_KHR,
|
||||||
|
display as *mut _,
|
||||||
|
ptr::null(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeDisplay::Wayland(display) if has_dp_extension("EGL_EXT_platform_wayland") &&
|
NativeDisplay::Wayland(display)
|
||||||
egl.GetPlatformDisplayEXT.is_loaded() => {
|
if has_dp_extension("EGL_EXT_platform_wayland") && egl.GetPlatformDisplayEXT.is_loaded() => {
|
||||||
trace!(log,
|
trace!(
|
||||||
"EGL Display Initialization via EGL_EXT_platform_wayland");
|
log,
|
||||||
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_WAYLAND_EXT,
|
"EGL Display Initialization via EGL_EXT_platform_wayland"
|
||||||
display as *mut _,
|
);
|
||||||
ptr::null())
|
egl.GetPlatformDisplayEXT(
|
||||||
|
ffi::egl::PLATFORM_WAYLAND_EXT,
|
||||||
|
display as *mut _,
|
||||||
|
ptr::null(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeDisplay::X11(display) |
|
NativeDisplay::X11(display) |
|
||||||
|
@ -315,8 +328,10 @@ impl EGLContext {
|
||||||
info!(log, "EGL Extensions: {:?}", extensions);
|
info!(log, "EGL Extensions: {:?}", extensions);
|
||||||
|
|
||||||
if egl_version >= (1, 2) && egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 {
|
if egl_version >= (1, 2) && egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 {
|
||||||
error!(log,
|
error!(
|
||||||
"OpenGLES not supported by the underlying EGL implementation");
|
log,
|
||||||
|
"OpenGLES not supported by the underlying EGL implementation"
|
||||||
|
);
|
||||||
return Err(CreationError::OpenGlVersionNotSupported);
|
return Err(CreationError::OpenGlVersionNotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,8 +354,10 @@ impl EGLContext {
|
||||||
match version {
|
match version {
|
||||||
(3, _) => {
|
(3, _) => {
|
||||||
if egl_version < (1, 3) {
|
if egl_version < (1, 3) {
|
||||||
error!(log,
|
error!(
|
||||||
"OpenglES 3.* is not supported on EGL Versions lower then 1.3");
|
log,
|
||||||
|
"OpenglES 3.* is not supported on EGL Versions lower then 1.3"
|
||||||
|
);
|
||||||
return Err(CreationError::NoAvailablePixelFormat);
|
return Err(CreationError::NoAvailablePixelFormat);
|
||||||
}
|
}
|
||||||
trace!(log, "Setting RENDERABLE_TYPE to OPENGL_ES3");
|
trace!(log, "Setting RENDERABLE_TYPE to OPENGL_ES3");
|
||||||
|
@ -352,8 +369,10 @@ impl EGLContext {
|
||||||
}
|
}
|
||||||
(2, _) => {
|
(2, _) => {
|
||||||
if egl_version < (1, 3) {
|
if egl_version < (1, 3) {
|
||||||
error!(log,
|
error!(
|
||||||
"OpenglES 2.* is not supported on EGL Versions lower then 1.3");
|
log,
|
||||||
|
"OpenglES 2.* is not supported on EGL Versions lower then 1.3"
|
||||||
|
);
|
||||||
return Err(CreationError::NoAvailablePixelFormat);
|
return Err(CreationError::NoAvailablePixelFormat);
|
||||||
}
|
}
|
||||||
trace!(log, "Setting RENDERABLE_TYPE to OPENGL_ES2");
|
trace!(log, "Setting RENDERABLE_TYPE to OPENGL_ES2");
|
||||||
|
@ -369,26 +388,30 @@ impl EGLContext {
|
||||||
if let Some(hardware_accelerated) = reqs.hardware_accelerated {
|
if let Some(hardware_accelerated) = reqs.hardware_accelerated {
|
||||||
out.push(ffi::egl::CONFIG_CAVEAT as c_int);
|
out.push(ffi::egl::CONFIG_CAVEAT as c_int);
|
||||||
out.push(if hardware_accelerated {
|
out.push(if hardware_accelerated {
|
||||||
trace!(log, "Setting CONFIG_CAVEAT to NONE");
|
trace!(log, "Setting CONFIG_CAVEAT to NONE");
|
||||||
ffi::egl::NONE as c_int
|
ffi::egl::NONE as c_int
|
||||||
} else {
|
} else {
|
||||||
trace!(log, "Setting CONFIG_CAVEAT to SLOW_CONFIG");
|
trace!(log, "Setting CONFIG_CAVEAT to SLOW_CONFIG");
|
||||||
ffi::egl::SLOW_CONFIG as c_int
|
ffi::egl::SLOW_CONFIG as c_int
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(color) = reqs.color_bits {
|
if let Some(color) = reqs.color_bits {
|
||||||
trace!(log, "Setting RED_SIZE to {}", color / 3);
|
trace!(log, "Setting RED_SIZE to {}", color / 3);
|
||||||
out.push(ffi::egl::RED_SIZE as c_int);
|
out.push(ffi::egl::RED_SIZE as c_int);
|
||||||
out.push((color / 3) as c_int);
|
out.push((color / 3) as c_int);
|
||||||
trace!(log,
|
trace!(
|
||||||
"Setting GREEN_SIZE to {}",
|
log,
|
||||||
color / 3 + if color % 3 != 0 { 1 } else { 0 });
|
"Setting GREEN_SIZE to {}",
|
||||||
|
color / 3 + if color % 3 != 0 { 1 } else { 0 }
|
||||||
|
);
|
||||||
out.push(ffi::egl::GREEN_SIZE as c_int);
|
out.push(ffi::egl::GREEN_SIZE as c_int);
|
||||||
out.push((color / 3 + if color % 3 != 0 { 1 } else { 0 }) as c_int);
|
out.push((color / 3 + if color % 3 != 0 { 1 } else { 0 }) as c_int);
|
||||||
trace!(log,
|
trace!(
|
||||||
"Setting BLUE_SIZE to {}",
|
log,
|
||||||
color / 3 + if color % 3 == 2 { 1 } else { 0 });
|
"Setting BLUE_SIZE to {}",
|
||||||
|
color / 3 + if color % 3 == 2 { 1 } else { 0 }
|
||||||
|
);
|
||||||
out.push(ffi::egl::BLUE_SIZE as c_int);
|
out.push(ffi::egl::BLUE_SIZE as c_int);
|
||||||
out.push((color / 3 + if color % 3 == 2 { 1 } else { 0 }) as c_int);
|
out.push((color / 3 + if color % 3 == 2 { 1 } else { 0 }) as c_int);
|
||||||
}
|
}
|
||||||
|
@ -429,12 +452,17 @@ impl EGLContext {
|
||||||
// calling `eglChooseConfig`
|
// calling `eglChooseConfig`
|
||||||
let mut config_id = mem::uninitialized();
|
let mut config_id = mem::uninitialized();
|
||||||
let mut num_configs = mem::uninitialized();
|
let mut num_configs = mem::uninitialized();
|
||||||
if egl.ChooseConfig(display,
|
if egl.ChooseConfig(
|
||||||
descriptor.as_ptr(),
|
display,
|
||||||
&mut config_id,
|
descriptor.as_ptr(),
|
||||||
1,
|
&mut config_id,
|
||||||
&mut num_configs) == 0 {
|
1,
|
||||||
return Err(CreationError::OsError(String::from("eglChooseConfig failed")));
|
&mut num_configs,
|
||||||
|
) == 0
|
||||||
|
{
|
||||||
|
return Err(CreationError::OsError(
|
||||||
|
String::from("eglChooseConfig failed"),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if num_configs == 0 {
|
if num_configs == 0 {
|
||||||
error!(log, "No matching color format found");
|
error!(log, "No matching color format found");
|
||||||
|
@ -458,10 +486,10 @@ impl EGLContext {
|
||||||
|
|
||||||
let desc = PixelFormat {
|
let desc = PixelFormat {
|
||||||
hardware_accelerated: attrib!(egl, display, config_id, ffi::egl::CONFIG_CAVEAT) !=
|
hardware_accelerated: attrib!(egl, display, config_id, ffi::egl::CONFIG_CAVEAT) !=
|
||||||
ffi::egl::SLOW_CONFIG as i32,
|
ffi::egl::SLOW_CONFIG as i32,
|
||||||
color_bits: attrib!(egl, display, config_id, ffi::egl::RED_SIZE) as u8 +
|
color_bits: attrib!(egl, display, config_id, ffi::egl::RED_SIZE) as u8 +
|
||||||
attrib!(egl, display, config_id, ffi::egl::BLUE_SIZE) as u8 +
|
attrib!(egl, display, config_id, ffi::egl::BLUE_SIZE) as u8 +
|
||||||
attrib!(egl, display, config_id, ffi::egl::GREEN_SIZE) as u8,
|
attrib!(egl, display, config_id, ffi::egl::GREEN_SIZE) as u8,
|
||||||
alpha_bits: attrib!(egl, display, config_id, ffi::egl::ALPHA_SIZE) as u8,
|
alpha_bits: attrib!(egl, display, config_id, ffi::egl::ALPHA_SIZE) as u8,
|
||||||
depth_bits: attrib!(egl, display, config_id, ffi::egl::DEPTH_SIZE) as u8,
|
depth_bits: attrib!(egl, display, config_id, ffi::egl::DEPTH_SIZE) as u8,
|
||||||
stencil_bits: attrib!(egl, display, config_id, ffi::egl::STENCIL_SIZE) as u8,
|
stencil_bits: attrib!(egl, display, config_id, ffi::egl::STENCIL_SIZE) as u8,
|
||||||
|
@ -509,8 +537,10 @@ impl EGLContext {
|
||||||
if context.is_null() {
|
if context.is_null() {
|
||||||
match egl.GetError() as u32 {
|
match egl.GetError() as u32 {
|
||||||
ffi::egl::BAD_ATTRIBUTE => {
|
ffi::egl::BAD_ATTRIBUTE => {
|
||||||
error!(log,
|
error!(
|
||||||
"Context creation failed as one or more requirements could not be met. Try removing some gl attributes or pixel format requirements");
|
log,
|
||||||
|
"Context creation failed as one or more requirements could not be met. Try removing some gl attributes or pixel format requirements"
|
||||||
|
);
|
||||||
return Err(CreationError::OpenGlVersionNotSupported);
|
return Err(CreationError::OpenGlVersionNotSupported);
|
||||||
}
|
}
|
||||||
e => panic!("eglCreateContext failed: 0x{:x}", e),
|
e => panic!("eglCreateContext failed: 0x{:x}", e),
|
||||||
|
@ -542,20 +572,20 @@ impl EGLContext {
|
||||||
info!(log, "EGL context created");
|
info!(log, "EGL context created");
|
||||||
|
|
||||||
Ok(EGLContext {
|
Ok(EGLContext {
|
||||||
_lib: lib,
|
_lib: lib,
|
||||||
context: context as *const _,
|
context: context as *const _,
|
||||||
display: display as *const _,
|
display: display as *const _,
|
||||||
egl: egl,
|
egl: egl,
|
||||||
config_id: config_id,
|
config_id: config_id,
|
||||||
surface_attributes: surface_attributes,
|
surface_attributes: surface_attributes,
|
||||||
pixel_format: desc,
|
pixel_format: desc,
|
||||||
backend_type: match native {
|
backend_type: match native {
|
||||||
NativeDisplay::X11(_) => NativeType::X11,
|
NativeDisplay::X11(_) => NativeType::X11,
|
||||||
NativeDisplay::Wayland(_) => NativeType::Wayland,
|
NativeDisplay::Wayland(_) => NativeType::Wayland,
|
||||||
NativeDisplay::Gbm(_) => NativeType::Gbm,
|
NativeDisplay::Gbm(_) => NativeType::Gbm,
|
||||||
},
|
},
|
||||||
logger: log,
|
logger: log,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a surface bound to the given egl context for rendering
|
/// Creates a surface bound to the given egl context for rendering
|
||||||
|
@ -573,17 +603,20 @@ impl EGLContext {
|
||||||
(NativeSurface::X11(window), NativeType::X11) |
|
(NativeSurface::X11(window), NativeType::X11) |
|
||||||
(NativeSurface::Wayland(window), NativeType::Wayland) |
|
(NativeSurface::Wayland(window), NativeType::Wayland) |
|
||||||
(NativeSurface::Gbm(window), NativeType::Gbm) => {
|
(NativeSurface::Gbm(window), NativeType::Gbm) => {
|
||||||
self.egl
|
self.egl.CreateWindowSurface(
|
||||||
.CreateWindowSurface(self.display,
|
self.display,
|
||||||
self.config_id,
|
self.config_id,
|
||||||
window,
|
window,
|
||||||
self.surface_attributes.as_ptr())
|
self.surface_attributes.as_ptr(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
_ => return Err(CreationError::NonMatchingSurfaceType),
|
_ => return Err(CreationError::NonMatchingSurfaceType),
|
||||||
};
|
};
|
||||||
|
|
||||||
if surface.is_null() {
|
if surface.is_null() {
|
||||||
return Err(CreationError::OsError(String::from("eglCreateWindowSurface failed")));
|
return Err(CreationError::OsError(
|
||||||
|
String::from("eglCreateWindowSurface failed"),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
surface
|
surface
|
||||||
|
@ -592,9 +625,9 @@ impl EGLContext {
|
||||||
debug!(self.logger, "EGL window surface successfully created");
|
debug!(self.logger, "EGL window surface successfully created");
|
||||||
|
|
||||||
Ok(EGLSurface {
|
Ok(EGLSurface {
|
||||||
context: &self,
|
context: &self,
|
||||||
surface: surface,
|
surface: surface,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the address of an OpenGL function.
|
/// Returns the address of an OpenGL function.
|
||||||
|
@ -621,9 +654,10 @@ impl<'a> EGLSurface<'a> {
|
||||||
/// Swaps buffers at the end of a frame.
|
/// Swaps buffers at the end of a frame.
|
||||||
pub fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
pub fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
self.context
|
self.context.egl.SwapBuffers(
|
||||||
.egl
|
self.context.display as *const _,
|
||||||
.SwapBuffers(self.context.display as *const _, self.surface as *const _)
|
self.surface as *const _,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
|
@ -643,12 +677,12 @@ impl<'a> EGLSurface<'a> {
|
||||||
/// This function is marked unsafe, because the context cannot be made current
|
/// This function is marked unsafe, because the context cannot be made current
|
||||||
/// on multiple threads.
|
/// on multiple threads.
|
||||||
pub unsafe fn make_current(&self) -> Result<(), SwapBuffersError> {
|
pub unsafe fn make_current(&self) -> Result<(), SwapBuffersError> {
|
||||||
let ret = self.context
|
let ret = self.context.egl.MakeCurrent(
|
||||||
.egl
|
self.context.display as *const _,
|
||||||
.MakeCurrent(self.context.display as *const _,
|
self.surface as *const _,
|
||||||
self.surface as *const _,
|
self.surface as *const _,
|
||||||
self.surface as *const _,
|
self.context.context as *const _,
|
||||||
self.context.context as *const _);
|
);
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
match self.context.egl.GetError() as u32 {
|
match self.context.egl.GetError() as u32 {
|
||||||
|
@ -671,8 +705,10 @@ impl Drop for EGLContext {
|
||||||
unsafe {
|
unsafe {
|
||||||
// we don't call MakeCurrent(0, 0) because we are not sure that the context
|
// we don't call MakeCurrent(0, 0) because we are not sure that the context
|
||||||
// is still the current one
|
// is still the current one
|
||||||
self.egl
|
self.egl.DestroyContext(
|
||||||
.DestroyContext(self.display as *const _, self.context as *const _);
|
self.display as *const _,
|
||||||
|
self.context as *const _,
|
||||||
|
);
|
||||||
self.egl.Terminate(self.display as *const _);
|
self.egl.Terminate(self.display as *const _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,9 +717,10 @@ impl Drop for EGLContext {
|
||||||
impl<'a> Drop for EGLSurface<'a> {
|
impl<'a> Drop for EGLSurface<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.context
|
self.context.egl.DestroySurface(
|
||||||
.egl
|
self.context.display as *const _,
|
||||||
.DestroySurface(self.context.display as *const _, self.surface as *const _);
|
self.surface as *const _,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,10 @@ impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
|
||||||
/// Note that destroying a `Frame` is immediate, even if vsync is enabled.
|
/// Note that destroying a `Frame` is immediate, even if vsync is enabled.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn draw(&self) -> Frame {
|
pub fn draw(&self) -> Frame {
|
||||||
Frame::new(self.context.clone(),
|
Frame::new(
|
||||||
self.backend.get_framebuffer_dimensions())
|
self.context.clone(),
|
||||||
|
self.backend.get_framebuffer_dimensions(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ impl ::std::cmp::PartialEq for Seat {
|
||||||
|
|
||||||
impl ::std::hash::Hash for Seat {
|
impl ::std::hash::Hash for Seat {
|
||||||
fn hash<H>(&self, state: &mut H)
|
fn hash<H>(&self, state: &mut H)
|
||||||
where H: ::std::hash::Hasher
|
where
|
||||||
|
H: ::std::hash::Hasher,
|
||||||
{
|
{
|
||||||
self.id.hash(state);
|
self.id.hash(state);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +276,10 @@ pub trait PointerMotionAbsoluteEvent: Event {
|
||||||
/// Device position converted to the targets coordinate space.
|
/// Device position converted to the targets coordinate space.
|
||||||
/// E.g. the focused output's resolution.
|
/// E.g. the focused output's resolution.
|
||||||
fn position_transformed(&self, coordinate_space: (u32, u32)) -> (u32, u32) {
|
fn position_transformed(&self, coordinate_space: (u32, u32)) -> (u32, u32) {
|
||||||
(self.x_transformed(coordinate_space.0), self.y_transformed(coordinate_space.1))
|
(
|
||||||
|
self.x_transformed(coordinate_space.0),
|
||||||
|
self.y_transformed(coordinate_space.1),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Device x position converted to the targets coordinate space's width.
|
/// Device x position converted to the targets coordinate space's width.
|
||||||
|
@ -336,7 +340,10 @@ pub trait TouchDownEvent: Event {
|
||||||
/// Touch position converted into the target coordinate space.
|
/// Touch position converted into the target coordinate space.
|
||||||
/// E.g. the focused output's resolution.
|
/// E.g. the focused output's resolution.
|
||||||
fn position_transformed(&self, coordinate_space: (u32, u32)) -> (u32, u32) {
|
fn position_transformed(&self, coordinate_space: (u32, u32)) -> (u32, u32) {
|
||||||
(self.x_transformed(coordinate_space.0), self.y_transformed(coordinate_space.1))
|
(
|
||||||
|
self.x_transformed(coordinate_space.0),
|
||||||
|
self.y_transformed(coordinate_space.1),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Touch event's x-coordinate in the device's native coordinate space
|
/// Touch event's x-coordinate in the device's native coordinate space
|
||||||
|
@ -395,7 +402,10 @@ pub trait TouchMotionEvent: Event {
|
||||||
/// Touch position converted into the target coordinate space.
|
/// Touch position converted into the target coordinate space.
|
||||||
/// E.g. the focused output's resolution.
|
/// E.g. the focused output's resolution.
|
||||||
fn position_transformed(&self, coordinate_space: (u32, u32)) -> (u32, u32) {
|
fn position_transformed(&self, coordinate_space: (u32, u32)) -> (u32, u32) {
|
||||||
(self.x_transformed(coordinate_space.0), self.y_transformed(coordinate_space.1))
|
(
|
||||||
|
self.x_transformed(coordinate_space.0),
|
||||||
|
self.y_transformed(coordinate_space.1),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Touch event's x-coordinate in the device's native coordinate space
|
/// Touch event's x-coordinate in the device's native coordinate space
|
||||||
|
|
|
@ -26,7 +26,8 @@ impl LibinputInputBackend {
|
||||||
/// Initialize a new `LibinputInputBackend` from a given already initialized libinput
|
/// Initialize a new `LibinputInputBackend` from a given already initialized libinput
|
||||||
/// context.
|
/// context.
|
||||||
pub fn new<L>(context: libinput::Libinput, logger: L) -> Self
|
pub fn new<L>(context: libinput::Libinput, logger: L) -> Self
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_libinput"));
|
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_libinput"));
|
||||||
info!(log, "Initializing a libinput backend");
|
info!(log, "Initializing a libinput backend");
|
||||||
|
@ -270,9 +271,9 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_handler(&mut self) -> Option<&mut backend::InputHandler<Self>> {
|
fn get_handler(&mut self) -> Option<&mut backend::InputHandler<Self>> {
|
||||||
self.handler
|
self.handler.as_mut().map(|handler| {
|
||||||
.as_mut()
|
handler as &mut backend::InputHandler<Self>
|
||||||
.map(|handler| handler as &mut backend::InputHandler<Self>)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_handler(&mut self) {
|
fn clear_handler(&mut self) {
|
||||||
|
@ -328,8 +329,8 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
Entry::Vacant(seat_entry) => {
|
Entry::Vacant(seat_entry) => {
|
||||||
let mut hasher = DefaultHasher::default();
|
let mut hasher = DefaultHasher::default();
|
||||||
seat_entry.key().hash(&mut hasher);
|
seat_entry.key().hash(&mut hasher);
|
||||||
let seat = seat_entry
|
let seat =
|
||||||
.insert(backend::Seat::new(hasher.finish(), new_caps));
|
seat_entry.insert(backend::Seat::new(hasher.finish(), new_caps));
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
||||||
handler.on_seat_created(seat);
|
handler.on_seat_created(seat);
|
||||||
|
@ -378,7 +379,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
} else {
|
} else {
|
||||||
panic!("Seat destroyed that was never created");
|
panic!("Seat destroyed that was never created");
|
||||||
}
|
}
|
||||||
// it has, notify about updates
|
// it has, notify about updates
|
||||||
} else if let Some(ref mut handler) = self.handler {
|
} else if let Some(ref mut handler) = self.handler {
|
||||||
let seat = self.seats[&device_seat];
|
let seat = self.seats[&device_seat];
|
||||||
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
||||||
|
@ -394,18 +395,20 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
use input::event::touch::*;
|
use input::event::touch::*;
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
let device_seat = touch_event.device().seat();
|
let device_seat = touch_event.device().seat();
|
||||||
let seat = &self.seats
|
let seat = &self.seats.get(&device_seat).expect(
|
||||||
.get(&device_seat)
|
"Recieved touch event of non existing Seat",
|
||||||
.expect("Recieved touch event of non existing Seat");
|
);
|
||||||
match touch_event {
|
match touch_event {
|
||||||
TouchEvent::Down(down_event) => {
|
TouchEvent::Down(down_event) => {
|
||||||
trace!(self.logger, "Calling on_touch_down with {:?}", down_event);
|
trace!(self.logger, "Calling on_touch_down with {:?}", down_event);
|
||||||
handler.on_touch_down(seat, down_event)
|
handler.on_touch_down(seat, down_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Motion(motion_event) => {
|
TouchEvent::Motion(motion_event) => {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_touch_motion with {:?}",
|
self.logger,
|
||||||
motion_event);
|
"Calling on_touch_motion with {:?}",
|
||||||
|
motion_event
|
||||||
|
);
|
||||||
handler.on_touch_motion(seat, motion_event)
|
handler.on_touch_motion(seat, motion_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Up(up_event) => {
|
TouchEvent::Up(up_event) => {
|
||||||
|
@ -413,9 +416,11 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
handler.on_touch_up(seat, up_event)
|
handler.on_touch_up(seat, up_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Cancel(cancel_event) => {
|
TouchEvent::Cancel(cancel_event) => {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_touch_cancel with {:?}",
|
self.logger,
|
||||||
cancel_event);
|
"Calling on_touch_cancel with {:?}",
|
||||||
|
cancel_event
|
||||||
|
);
|
||||||
handler.on_touch_cancel(seat, cancel_event)
|
handler.on_touch_cancel(seat, cancel_event)
|
||||||
}
|
}
|
||||||
TouchEvent::Frame(frame_event) => {
|
TouchEvent::Frame(frame_event) => {
|
||||||
|
@ -431,9 +436,9 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
KeyboardEvent::Key(key_event) => {
|
KeyboardEvent::Key(key_event) => {
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
let device_seat = key_event.device().seat();
|
let device_seat = key_event.device().seat();
|
||||||
let seat = &self.seats
|
let seat = &self.seats.get(&device_seat).expect(
|
||||||
.get(&device_seat)
|
"Recieved key event of non existing Seat",
|
||||||
.expect("Recieved key event of non existing Seat");
|
);
|
||||||
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
|
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
|
||||||
handler.on_keyboard_key(seat, key_event);
|
handler.on_keyboard_key(seat, key_event);
|
||||||
}
|
}
|
||||||
|
@ -444,49 +449,63 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
use input::event::pointer::*;
|
use input::event::pointer::*;
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
let device_seat = pointer_event.device().seat();
|
let device_seat = pointer_event.device().seat();
|
||||||
let seat = &self.seats
|
let seat = &self.seats.get(&device_seat).expect(
|
||||||
.get(&device_seat)
|
"Recieved pointer event of non existing Seat",
|
||||||
.expect("Recieved pointer event of non existing Seat");
|
);
|
||||||
match pointer_event {
|
match pointer_event {
|
||||||
PointerEvent::Motion(motion_event) => {
|
PointerEvent::Motion(motion_event) => {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_pointer_move with {:?}",
|
self.logger,
|
||||||
motion_event);
|
"Calling on_pointer_move with {:?}",
|
||||||
|
motion_event
|
||||||
|
);
|
||||||
handler.on_pointer_move(seat, motion_event);
|
handler.on_pointer_move(seat, motion_event);
|
||||||
}
|
}
|
||||||
PointerEvent::MotionAbsolute(motion_abs_event) => {
|
PointerEvent::MotionAbsolute(motion_abs_event) => {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_pointer_move_absolute with {:?}",
|
self.logger,
|
||||||
motion_abs_event);
|
"Calling on_pointer_move_absolute with {:?}",
|
||||||
|
motion_abs_event
|
||||||
|
);
|
||||||
handler.on_pointer_move_absolute(seat, motion_abs_event);
|
handler.on_pointer_move_absolute(seat, motion_abs_event);
|
||||||
}
|
}
|
||||||
PointerEvent::Axis(axis_event) => {
|
PointerEvent::Axis(axis_event) => {
|
||||||
let rc_axis_event = Rc::new(axis_event);
|
let rc_axis_event = Rc::new(axis_event);
|
||||||
if rc_axis_event.has_axis(Axis::Vertical) {
|
if rc_axis_event.has_axis(Axis::Vertical) {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_pointer_axis for Axis::Vertical with {:?}",
|
self.logger,
|
||||||
*rc_axis_event);
|
"Calling on_pointer_axis for Axis::Vertical with {:?}",
|
||||||
handler.on_pointer_axis(seat,
|
*rc_axis_event
|
||||||
self::PointerAxisEvent {
|
);
|
||||||
axis: Axis::Vertical,
|
handler.on_pointer_axis(
|
||||||
event: rc_axis_event.clone(),
|
seat,
|
||||||
});
|
self::PointerAxisEvent {
|
||||||
|
axis: Axis::Vertical,
|
||||||
|
event: rc_axis_event.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if rc_axis_event.has_axis(Axis::Horizontal) {
|
if rc_axis_event.has_axis(Axis::Horizontal) {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
|
self.logger,
|
||||||
*rc_axis_event);
|
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
|
||||||
handler.on_pointer_axis(seat,
|
*rc_axis_event
|
||||||
self::PointerAxisEvent {
|
);
|
||||||
axis: Axis::Horizontal,
|
handler.on_pointer_axis(
|
||||||
event: rc_axis_event.clone(),
|
seat,
|
||||||
});
|
self::PointerAxisEvent {
|
||||||
|
axis: Axis::Horizontal,
|
||||||
|
event: rc_axis_event.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Button(button_event) => {
|
PointerEvent::Button(button_event) => {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_pointer_button with {:?}",
|
self.logger,
|
||||||
button_event);
|
"Calling on_pointer_button with {:?}",
|
||||||
|
button_event
|
||||||
|
);
|
||||||
handler.on_pointer_button(seat, button_event);
|
handler.on_pointer_button(seat, button_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,13 +61,16 @@ pub struct WinitInputBackend {
|
||||||
/// graphics backend trait and a corresponding `WinitInputBackend`, which implements
|
/// graphics backend trait and a corresponding `WinitInputBackend`, which implements
|
||||||
/// the `InputBackend` trait
|
/// the `InputBackend` trait
|
||||||
pub fn init<L>(logger: L) -> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError>
|
pub fn init<L>(logger: L) -> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError>
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
init_from_builder(WindowBuilder::new()
|
init_from_builder(
|
||||||
.with_dimensions(1280, 800)
|
WindowBuilder::new()
|
||||||
.with_title("Smithay")
|
.with_dimensions(1280, 800)
|
||||||
.with_visibility(true),
|
.with_title("Smithay")
|
||||||
logger)
|
.with_visibility(true),
|
||||||
|
logger,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `WinitGraphicsBackend`, which implements the `EGLGraphicsBackend`
|
/// Create a new `WinitGraphicsBackend`, which implements the `EGLGraphicsBackend`
|
||||||
|
@ -75,26 +78,30 @@ pub fn init<L>(logger: L) -> Result<(WinitGraphicsBackend, WinitInputBackend), C
|
||||||
/// `WinitInputBackend`, which implements the `InputBackend` trait
|
/// `WinitInputBackend`, which implements the `InputBackend` trait
|
||||||
pub fn init_from_builder<L>(builder: WindowBuilder, logger: L)
|
pub fn init_from_builder<L>(builder: WindowBuilder, logger: L)
|
||||||
-> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError>
|
-> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError>
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
init_from_builder_with_gl_attr(builder,
|
init_from_builder_with_gl_attr(
|
||||||
GlAttributes {
|
builder,
|
||||||
version: None,
|
GlAttributes {
|
||||||
profile: None,
|
version: None,
|
||||||
debug: cfg!(debug_assertions),
|
profile: None,
|
||||||
vsync: true,
|
debug: cfg!(debug_assertions),
|
||||||
},
|
vsync: true,
|
||||||
logger)
|
},
|
||||||
|
logger,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `WinitGraphicsBackend`, which implements the `EGLGraphicsBackend`
|
/// Create a new `WinitGraphicsBackend`, which implements the `EGLGraphicsBackend`
|
||||||
/// graphics backend trait, from a given `WindowBuilder` struct, as well as given
|
/// graphics backend trait, from a given `WindowBuilder` struct, as well as given
|
||||||
/// `GlAttributes` for further customization of the rendering pipeline and a
|
/// `GlAttributes` for further customization of the rendering pipeline and a
|
||||||
/// corresponding `WinitInputBackend`, which implements the `InputBackend` trait.
|
/// corresponding `WinitInputBackend`, which implements the `InputBackend` trait.
|
||||||
pub fn init_from_builder_with_gl_attr<L>
|
pub fn init_from_builder_with_gl_attr<L>(
|
||||||
(builder: WindowBuilder, attributes: GlAttributes, logger: L)
|
builder: WindowBuilder, attributes: GlAttributes, logger: L)
|
||||||
-> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError>
|
-> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError>
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_winit"));
|
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_winit"));
|
||||||
info!(log, "Initializing a winit backend");
|
info!(log, "Initializing a winit backend");
|
||||||
|
@ -103,33 +110,45 @@ pub fn init_from_builder_with_gl_attr<L>
|
||||||
let window = Rc::new(builder.build(&events_loop)?);
|
let window = Rc::new(builder.build(&events_loop)?);
|
||||||
debug!(log, "Window created");
|
debug!(log, "Window created");
|
||||||
|
|
||||||
let (native_display, native_surface, surface) = if let (Some(conn), Some(window)) =
|
let (native_display, native_surface, surface) =
|
||||||
(get_x11_xconnection(), window.get_xlib_window()) {
|
if let (Some(conn), Some(window)) = (get_x11_xconnection(), window.get_xlib_window()) {
|
||||||
debug!(log, "Window is backed by X11");
|
debug!(log, "Window is backed by X11");
|
||||||
(NativeDisplay::X11(conn.display as *const _), NativeSurface::X11(window), None)
|
(
|
||||||
} else if let (Some(display), Some(surface)) =
|
NativeDisplay::X11(conn.display as *const _),
|
||||||
(window.get_wayland_display(), window.get_wayland_client_surface()) {
|
NativeSurface::X11(window),
|
||||||
debug!(log, "Window is backed by Wayland");
|
None,
|
||||||
let (w, h) = window.get_inner_size().unwrap();
|
)
|
||||||
let egl_surface = wegl::WlEglSurface::new(surface, w as i32, h as i32);
|
} else if let (Some(display), Some(surface)) =
|
||||||
(NativeDisplay::Wayland(display),
|
(
|
||||||
NativeSurface::Wayland(egl_surface.ptr() as *const _),
|
window.get_wayland_display(),
|
||||||
Some(egl_surface))
|
window.get_wayland_client_surface(),
|
||||||
} else {
|
)
|
||||||
error!(log, "Window is backed by an unsupported graphics framework");
|
{
|
||||||
return Err(CreationError::NotSupported);
|
debug!(log, "Window is backed by Wayland");
|
||||||
};
|
let (w, h) = window.get_inner_size().unwrap();
|
||||||
|
let egl_surface = wegl::WlEglSurface::new(surface, w as i32, h as i32);
|
||||||
|
(
|
||||||
|
NativeDisplay::Wayland(display),
|
||||||
|
NativeSurface::Wayland(egl_surface.ptr() as *const _),
|
||||||
|
Some(egl_surface),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
error!(log, "Window is backed by an unsupported graphics framework");
|
||||||
|
return Err(CreationError::NotSupported);
|
||||||
|
};
|
||||||
|
|
||||||
let context = unsafe {
|
let context = unsafe {
|
||||||
match EGLContext::new(native_display,
|
match EGLContext::new(
|
||||||
attributes,
|
native_display,
|
||||||
PixelFormatRequirements {
|
attributes,
|
||||||
hardware_accelerated: Some(true),
|
PixelFormatRequirements {
|
||||||
color_bits: Some(24),
|
hardware_accelerated: Some(true),
|
||||||
alpha_bits: Some(8),
|
color_bits: Some(24),
|
||||||
..Default::default()
|
alpha_bits: Some(8),
|
||||||
},
|
..Default::default()
|
||||||
log.clone()) {
|
},
|
||||||
|
log.clone(),
|
||||||
|
) {
|
||||||
Ok(context) => context,
|
Ok(context) => context,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(log, "EGLContext creation failed:\n {}", err);
|
error!(log, "EGLContext creation failed:\n {}", err);
|
||||||
|
@ -138,11 +157,12 @@ pub fn init_from_builder_with_gl_attr<L>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((WinitGraphicsBackend {
|
Ok((
|
||||||
|
WinitGraphicsBackend {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
context: match egl::RentEGL::try_new(Box::new(context), move |context| unsafe {
|
context: match egl::RentEGL::try_new(Box::new(context), move |context| unsafe {
|
||||||
context.create_surface(native_surface)
|
context.create_surface(native_surface)
|
||||||
}) {
|
}) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(::rental::TryNewError(err, _)) => return Err(err),
|
Err(::rental::TryNewError(err, _)) => return Err(err),
|
||||||
},
|
},
|
||||||
|
@ -154,16 +174,19 @@ pub fn init_from_builder_with_gl_attr<L>
|
||||||
surface: surface,
|
surface: surface,
|
||||||
time_counter: 0,
|
time_counter: 0,
|
||||||
key_counter: 0,
|
key_counter: 0,
|
||||||
seat: Seat::new(0,
|
seat: Seat::new(
|
||||||
SeatCapabilities {
|
0,
|
||||||
pointer: true,
|
SeatCapabilities {
|
||||||
keyboard: true,
|
pointer: true,
|
||||||
touch: true,
|
keyboard: true,
|
||||||
}),
|
touch: true,
|
||||||
|
},
|
||||||
|
),
|
||||||
input_config: (),
|
input_config: (),
|
||||||
handler: None,
|
handler: None,
|
||||||
logger: log.new(o!("smithay_winit_component" => "input")),
|
logger: log.new(o!("smithay_winit_component" => "input")),
|
||||||
}))
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsBackend for WinitGraphicsBackend {
|
impl GraphicsBackend for WinitGraphicsBackend {
|
||||||
|
@ -193,9 +216,9 @@ impl EGLGraphicsBackend for WinitGraphicsBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_framebuffer_dimensions(&self) -> (u32, u32) {
|
fn get_framebuffer_dimensions(&self) -> (u32, u32) {
|
||||||
self.window
|
self.window.get_inner_size_pixels().expect(
|
||||||
.get_inner_size_pixels()
|
"Window does not exist anymore",
|
||||||
.expect("Window does not exist anymore")
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_current(&self) -> bool {
|
fn is_current(&self) -> bool {
|
||||||
|
@ -288,16 +311,17 @@ impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn x_transformed(&self, width: u32) -> u32 {
|
fn x_transformed(&self, width: u32) -> u32 {
|
||||||
cmp::min((self.x * width as f64 /
|
cmp::min(
|
||||||
self.window.get_inner_size_points().unwrap_or((width, 0)).0 as f64) as u32,
|
(self.x * width as f64 / self.window.get_inner_size_points().unwrap_or((width, 0)).0 as f64) as u32,
|
||||||
0)
|
0,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn y_transformed(&self, height: u32) -> u32 {
|
fn y_transformed(&self, height: u32) -> u32 {
|
||||||
cmp::min((self.y * height as f64 /
|
cmp::min(
|
||||||
self.window.get_inner_size_points().unwrap_or((0, height)).1 as f64) as
|
(self.y * height as f64 / self.window.get_inner_size_points().unwrap_or((0, height)).1 as f64) as u32,
|
||||||
u32,
|
0,
|
||||||
0)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,15 +414,19 @@ impl TouchDownEvent for WinitTouchStartedEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn x_transformed(&self, width: u32) -> u32 {
|
fn x_transformed(&self, width: u32) -> u32 {
|
||||||
cmp::min(self.location.0 as i32 * width as i32 /
|
cmp::min(
|
||||||
self.window.get_inner_size_points().unwrap_or((width, 0)).0 as i32,
|
self.location.0 as i32 * width as i32 /
|
||||||
0) as u32
|
self.window.get_inner_size_points().unwrap_or((width, 0)).0 as i32,
|
||||||
|
0,
|
||||||
|
) as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn y_transformed(&self, height: u32) -> u32 {
|
fn y_transformed(&self, height: u32) -> u32 {
|
||||||
cmp::min(self.location.1 as i32 * height as i32 /
|
cmp::min(
|
||||||
self.window.get_inner_size_points().unwrap_or((0, height)).1 as i32,
|
self.location.1 as i32 * height as i32 /
|
||||||
0) as u32
|
self.window.get_inner_size_points().unwrap_or((0, height)).1 as i32,
|
||||||
|
0,
|
||||||
|
) as u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,16 +531,18 @@ impl InputBackend for WinitInputBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> {
|
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> {
|
||||||
self.handler
|
self.handler.as_mut().map(|handler| {
|
||||||
.as_mut()
|
handler as &mut InputHandler<Self>
|
||||||
.map(|handler| handler as &mut InputHandler<Self>)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_handler(&mut self) {
|
fn clear_handler(&mut self) {
|
||||||
if let Some(mut handler) = self.handler.take() {
|
if let Some(mut handler) = self.handler.take() {
|
||||||
trace!(self.logger,
|
trace!(
|
||||||
"Calling on_seat_destroyed with {:?}",
|
self.logger,
|
||||||
self.seat);
|
"Calling on_seat_destroyed with {:?}",
|
||||||
|
self.seat
|
||||||
|
);
|
||||||
handler.on_seat_destroyed(&self.seat);
|
handler.on_seat_destroyed(&self.seat);
|
||||||
}
|
}
|
||||||
info!(self.logger, "Removing input handler");
|
info!(self.logger, "Removing input handler");
|
||||||
|
@ -552,168 +582,188 @@ impl InputBackend for WinitInputBackend {
|
||||||
let mut handler = self.handler.as_mut();
|
let mut handler = self.handler.as_mut();
|
||||||
let logger = &self.logger;
|
let logger = &self.logger;
|
||||||
|
|
||||||
self.events_loop
|
self.events_loop.poll_events(move |event| match event {
|
||||||
.poll_events(move |event| match event {
|
Event::WindowEvent { event, .. } => {
|
||||||
Event::WindowEvent { event, .. } => {
|
match (event, handler.as_mut()) {
|
||||||
match (event, handler.as_mut()) {
|
(WindowEvent::Resized(x, y), _) => {
|
||||||
(WindowEvent::Resized(x, y), _) => {
|
trace!(logger, "Resizing window to {:?}", (x, y));
|
||||||
trace!(logger, "Resizing window to {:?}", (x, y));
|
window.set_inner_size(x, y);
|
||||||
window.set_inner_size(x, y);
|
if let Some(wl_egl_surface) = surface.as_ref() {
|
||||||
if let Some(wl_egl_surface) = surface.as_ref() {
|
wl_egl_surface.resize(x as i32, y as i32, 0, 0);
|
||||||
wl_egl_surface.resize(x as i32, y as i32, 0, 0);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
(WindowEvent::KeyboardInput {
|
|
||||||
input: KeyboardInput { scancode, state, .. }, ..
|
|
||||||
},
|
|
||||||
Some(handler)) => {
|
|
||||||
match state {
|
|
||||||
ElementState::Pressed => *key_counter += 1,
|
|
||||||
ElementState::Released => {
|
|
||||||
*key_counter = key_counter.checked_sub(1).unwrap_or(0)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
trace!(logger,
|
|
||||||
"Calling on_keyboard_key with {:?}",
|
|
||||||
(scancode, state));
|
|
||||||
handler.on_keyboard_key(seat,
|
|
||||||
WinitKeyboardInputEvent {
|
|
||||||
time: *time_counter,
|
|
||||||
key: scancode,
|
|
||||||
count: *key_counter,
|
|
||||||
state: state,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
(WindowEvent::MouseMoved { position: (x, y), .. },
|
|
||||||
Some(handler)) => {
|
|
||||||
trace!(logger,
|
|
||||||
"Calling on_pointer_move_absolute with {:?}",
|
|
||||||
(x, y));
|
|
||||||
handler.on_pointer_move_absolute(seat,
|
|
||||||
WinitMouseMovedEvent {
|
|
||||||
window: window.clone(),
|
|
||||||
time: *time_counter,
|
|
||||||
x: x,
|
|
||||||
y: y,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
(WindowEvent::MouseWheel { delta, .. }, Some(handler)) => {
|
|
||||||
match delta {
|
|
||||||
MouseScrollDelta::LineDelta(x, y) |
|
|
||||||
MouseScrollDelta::PixelDelta(x, y) => {
|
|
||||||
if x != 0.0 {
|
|
||||||
let event = WinitMouseWheelEvent {
|
|
||||||
axis: Axis::Horizontal,
|
|
||||||
time: *time_counter,
|
|
||||||
delta: delta,
|
|
||||||
};
|
|
||||||
trace!(logger,
|
|
||||||
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
|
|
||||||
x);
|
|
||||||
handler.on_pointer_axis(seat, event);
|
|
||||||
}
|
}
|
||||||
if y != 0.0 {
|
(WindowEvent::KeyboardInput {
|
||||||
let event = WinitMouseWheelEvent {
|
input: KeyboardInput { scancode, state, .. }, ..
|
||||||
axis: Axis::Vertical,
|
},
|
||||||
time: *time_counter,
|
Some(handler)) => {
|
||||||
delta: delta,
|
match state {
|
||||||
|
ElementState::Pressed => *key_counter += 1,
|
||||||
|
ElementState::Released => {
|
||||||
|
*key_counter = key_counter.checked_sub(1).unwrap_or(0)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
trace!(logger,
|
trace!(
|
||||||
"Calling on_pointer_axis for Axis::Vertical with {:?}",
|
logger,
|
||||||
y);
|
"Calling on_keyboard_key with {:?}",
|
||||||
handler.on_pointer_axis(seat, event);
|
(scancode, state)
|
||||||
|
);
|
||||||
|
handler.on_keyboard_key(
|
||||||
|
seat,
|
||||||
|
WinitKeyboardInputEvent {
|
||||||
|
time: *time_counter,
|
||||||
|
key: scancode,
|
||||||
|
count: *key_counter,
|
||||||
|
state: state,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
(WindowEvent::MouseMoved { position: (x, y), .. }, Some(handler)) => {
|
||||||
}
|
trace!(logger, "Calling on_pointer_move_absolute with {:?}", (x, y));
|
||||||
}
|
handler.on_pointer_move_absolute(
|
||||||
(WindowEvent::MouseInput { state, button, .. }, Some(handler)) => {
|
seat,
|
||||||
trace!(logger,
|
WinitMouseMovedEvent {
|
||||||
"Calling on_pointer_button with {:?}",
|
window: window.clone(),
|
||||||
(button, state));
|
time: *time_counter,
|
||||||
handler.on_pointer_button(seat,
|
x: x,
|
||||||
WinitMouseInputEvent {
|
y: y,
|
||||||
time: *time_counter,
|
},
|
||||||
button: button,
|
)
|
||||||
state: state,
|
}
|
||||||
})
|
(WindowEvent::MouseWheel { delta, .. }, Some(handler)) => {
|
||||||
}
|
match delta {
|
||||||
(WindowEvent::Touch(Touch {
|
MouseScrollDelta::LineDelta(x, y) |
|
||||||
phase: TouchPhase::Started,
|
MouseScrollDelta::PixelDelta(x, y) => {
|
||||||
location: (x, y),
|
if x != 0.0 {
|
||||||
id,
|
let event = WinitMouseWheelEvent {
|
||||||
..
|
axis: Axis::Horizontal,
|
||||||
}),
|
time: *time_counter,
|
||||||
Some(handler)) => {
|
delta: delta,
|
||||||
trace!(logger, "Calling on_touch_down at {:?}", (x, y));
|
};
|
||||||
handler.on_touch_down(seat,
|
trace!(
|
||||||
WinitTouchStartedEvent {
|
logger,
|
||||||
window: window.clone(),
|
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
|
||||||
time: *time_counter,
|
x
|
||||||
location: (x, y),
|
);
|
||||||
id: id,
|
handler.on_pointer_axis(seat, event);
|
||||||
})
|
}
|
||||||
}
|
if y != 0.0 {
|
||||||
(WindowEvent::Touch(Touch {
|
let event = WinitMouseWheelEvent {
|
||||||
phase: TouchPhase::Moved,
|
axis: Axis::Vertical,
|
||||||
location: (x, y),
|
time: *time_counter,
|
||||||
id,
|
delta: delta,
|
||||||
..
|
};
|
||||||
}),
|
trace!(
|
||||||
Some(handler)) => {
|
logger,
|
||||||
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
"Calling on_pointer_axis for Axis::Vertical with {:?}",
|
||||||
handler.on_touch_motion(seat,
|
y
|
||||||
WinitTouchMovedEvent {
|
);
|
||||||
window: window.clone(),
|
handler.on_pointer_axis(seat, event);
|
||||||
time: *time_counter,
|
}
|
||||||
location: (x, y),
|
}
|
||||||
id: id,
|
}
|
||||||
})
|
}
|
||||||
}
|
(WindowEvent::MouseInput { state, button, .. }, Some(handler)) => {
|
||||||
(WindowEvent::Touch(Touch {
|
trace!(
|
||||||
phase: TouchPhase::Ended,
|
logger,
|
||||||
location: (x, y),
|
"Calling on_pointer_button with {:?}",
|
||||||
id,
|
(button, state)
|
||||||
..
|
);
|
||||||
}),
|
handler.on_pointer_button(
|
||||||
Some(handler)) => {
|
seat,
|
||||||
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
WinitMouseInputEvent {
|
||||||
handler.on_touch_motion(seat,
|
time: *time_counter,
|
||||||
WinitTouchMovedEvent {
|
button: button,
|
||||||
window: window.clone(),
|
state: state,
|
||||||
time: *time_counter,
|
},
|
||||||
location: (x, y),
|
)
|
||||||
id: id,
|
}
|
||||||
});
|
(WindowEvent::Touch(Touch {
|
||||||
trace!(logger, "Calling on_touch_up");
|
phase: TouchPhase::Started,
|
||||||
handler.on_touch_up(seat,
|
location: (x, y),
|
||||||
WinitTouchEndedEvent {
|
id,
|
||||||
time: *time_counter,
|
..
|
||||||
id: id,
|
}),
|
||||||
});
|
Some(handler)) => {
|
||||||
}
|
trace!(logger, "Calling on_touch_down at {:?}", (x, y));
|
||||||
(WindowEvent::Touch(Touch {
|
handler.on_touch_down(
|
||||||
phase: TouchPhase::Cancelled,
|
seat,
|
||||||
id,
|
WinitTouchStartedEvent {
|
||||||
..
|
window: window.clone(),
|
||||||
}),
|
time: *time_counter,
|
||||||
Some(handler)) => {
|
location: (x, y),
|
||||||
trace!(logger, "Calling on_touch_cancel");
|
id: id,
|
||||||
handler.on_touch_cancel(seat,
|
},
|
||||||
WinitTouchCancelledEvent {
|
)
|
||||||
time: *time_counter,
|
}
|
||||||
id: id,
|
(WindowEvent::Touch(Touch {
|
||||||
})
|
phase: TouchPhase::Moved,
|
||||||
}
|
location: (x, y),
|
||||||
(WindowEvent::Closed, _) => {
|
id,
|
||||||
warn!(logger, "Window closed");
|
..
|
||||||
*closed_ptr = true;
|
}),
|
||||||
}
|
Some(handler)) => {
|
||||||
_ => {}
|
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
||||||
}
|
handler.on_touch_motion(
|
||||||
*time_counter += 1;
|
seat,
|
||||||
}
|
WinitTouchMovedEvent {
|
||||||
Event::DeviceEvent { .. } => {}
|
window: window.clone(),
|
||||||
});
|
time: *time_counter,
|
||||||
|
location: (x, y),
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
(WindowEvent::Touch(Touch {
|
||||||
|
phase: TouchPhase::Ended,
|
||||||
|
location: (x, y),
|
||||||
|
id,
|
||||||
|
..
|
||||||
|
}),
|
||||||
|
Some(handler)) => {
|
||||||
|
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
||||||
|
handler.on_touch_motion(
|
||||||
|
seat,
|
||||||
|
WinitTouchMovedEvent {
|
||||||
|
window: window.clone(),
|
||||||
|
time: *time_counter,
|
||||||
|
location: (x, y),
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
trace!(logger, "Calling on_touch_up");
|
||||||
|
handler.on_touch_up(
|
||||||
|
seat,
|
||||||
|
WinitTouchEndedEvent {
|
||||||
|
time: *time_counter,
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
(WindowEvent::Touch(Touch {
|
||||||
|
phase: TouchPhase::Cancelled,
|
||||||
|
id,
|
||||||
|
..
|
||||||
|
}),
|
||||||
|
Some(handler)) => {
|
||||||
|
trace!(logger, "Calling on_touch_cancel");
|
||||||
|
handler.on_touch_cancel(
|
||||||
|
seat,
|
||||||
|
WinitTouchCancelledEvent {
|
||||||
|
time: *time_counter,
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
(WindowEvent::Closed, _) => {
|
||||||
|
warn!(logger, "Window closed");
|
||||||
|
*closed_ptr = true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
*time_counter += 1;
|
||||||
|
}
|
||||||
|
Event::DeviceEvent { .. } => {}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if closed {
|
if closed {
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub use xkbcommon::xkb::{Keysym, keysyms};
|
||||||
///
|
///
|
||||||
/// For some modifiers, this means that the key is currently pressed, others are toggled
|
/// For some modifiers, this means that the key is currently pressed, others are toggled
|
||||||
/// (like caps lock).
|
/// (like caps lock).
|
||||||
#[derive(Copy,Clone,Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct ModifiersState {
|
pub struct ModifiersState {
|
||||||
/// The "control" key
|
/// The "control" key
|
||||||
pub ctrl: bool,
|
pub ctrl: bool,
|
||||||
|
@ -95,22 +95,23 @@ impl KbdInternal {
|
||||||
// FIXME: This is an issue with the xkbcommon-rs crate that does not reflect this
|
// FIXME: This is an issue with the xkbcommon-rs crate that does not reflect this
|
||||||
// non-threadsafety properly.
|
// non-threadsafety properly.
|
||||||
let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
|
let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
|
||||||
let keymap = xkb::Keymap::new_from_names(&context,
|
let keymap = xkb::Keymap::new_from_names(
|
||||||
&rules,
|
&context,
|
||||||
&model,
|
&rules,
|
||||||
&layout,
|
&model,
|
||||||
&variant,
|
&layout,
|
||||||
options,
|
&variant,
|
||||||
xkb::KEYMAP_COMPILE_NO_FLAGS)
|
options,
|
||||||
.ok_or(())?;
|
xkb::KEYMAP_COMPILE_NO_FLAGS,
|
||||||
|
).ok_or(())?;
|
||||||
let state = xkb::State::new(&keymap);
|
let state = xkb::State::new(&keymap);
|
||||||
Ok(KbdInternal {
|
Ok(KbdInternal {
|
||||||
focus: None,
|
focus: None,
|
||||||
pressed_keys: Vec::new(),
|
pressed_keys: Vec::new(),
|
||||||
mods_state: ModifiersState::new(),
|
mods_state: ModifiersState::new(),
|
||||||
keymap: keymap,
|
keymap: keymap,
|
||||||
state: state,
|
state: state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// return true if modifier state has changed
|
// return true if modifier state has changed
|
||||||
|
@ -148,8 +149,10 @@ impl KbdInternal {
|
||||||
|
|
||||||
fn serialize_pressed_keys(&self) -> Vec<u8> {
|
fn serialize_pressed_keys(&self) -> Vec<u8> {
|
||||||
let serialized = unsafe {
|
let serialized = unsafe {
|
||||||
::std::slice::from_raw_parts(self.pressed_keys.as_ptr() as *const u8,
|
::std::slice::from_raw_parts(
|
||||||
self.pressed_keys.len() * 4)
|
self.pressed_keys.as_ptr() as *const u8,
|
||||||
|
self.pressed_keys.len() * 4,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
serialized.into()
|
serialized.into()
|
||||||
}
|
}
|
||||||
|
@ -167,7 +170,8 @@ pub enum Error {
|
||||||
pub fn create_keyboard_handler<L>(rules: &str, model: &str, layout: &str, variant: &str,
|
pub fn create_keyboard_handler<L>(rules: &str, model: &str, layout: &str, variant: &str,
|
||||||
options: Option<String>, logger: L)
|
options: Option<String>, logger: L)
|
||||||
-> Result<KbdHandle, Error>
|
-> Result<KbdHandle, Error>
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "xkbcommon_handler"));
|
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "xkbcommon_handler"));
|
||||||
info!(log, "Initializing a xkbcommon handler with keymap";
|
info!(log, "Initializing a xkbcommon handler with keymap";
|
||||||
|
@ -176,17 +180,17 @@ pub fn create_keyboard_handler<L>(rules: &str, model: &str, layout: &str, varian
|
||||||
);
|
);
|
||||||
let internal = KbdInternal::new(rules, model, layout, variant, options)
|
let internal = KbdInternal::new(rules, model, layout, variant, options)
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
debug!(log, "Loading keymap failed");
|
debug!(log, "Loading keymap failed");
|
||||||
Error::BadKeymap
|
Error::BadKeymap
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
||||||
// prepare a tempfile with the keymap, to send it to clients
|
// prepare a tempfile with the keymap, to send it to clients
|
||||||
let mut keymap_file = tempfile().map_err(Error::IoError)?;
|
let mut keymap_file = tempfile().map_err(Error::IoError)?;
|
||||||
let keymap_data = internal.keymap.get_as_string(xkb::KEYMAP_FORMAT_TEXT_V1);
|
let keymap_data = internal.keymap.get_as_string(xkb::KEYMAP_FORMAT_TEXT_V1);
|
||||||
keymap_file
|
keymap_file.write_all(keymap_data.as_bytes()).map_err(
|
||||||
.write_all(keymap_data.as_bytes())
|
Error::IoError,
|
||||||
.map_err(Error::IoError)?;
|
)?;
|
||||||
keymap_file.flush().map_err(Error::IoError)?;
|
keymap_file.flush().map_err(Error::IoError)?;
|
||||||
|
|
||||||
trace!(log, "Keymap loaded and copied to tempfile.";
|
trace!(log, "Keymap loaded and copied to tempfile.";
|
||||||
|
@ -194,13 +198,13 @@ pub fn create_keyboard_handler<L>(rules: &str, model: &str, layout: &str, varian
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(KbdHandle {
|
Ok(KbdHandle {
|
||||||
arc: Arc::new(KbdArc {
|
arc: Arc::new(KbdArc {
|
||||||
internal: Mutex::new(internal),
|
internal: Mutex::new(internal),
|
||||||
keymap_file: keymap_file,
|
keymap_file: keymap_file,
|
||||||
keymap_len: keymap_data.as_bytes().len() as u32,
|
keymap_len: keymap_data.as_bytes().len() as u32,
|
||||||
logger: log,
|
logger: log,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
struct KbdArc {
|
struct KbdArc {
|
||||||
|
@ -235,7 +239,8 @@ impl KbdHandle {
|
||||||
/// The module `smithay::keyboard::keysyms` exposes definitions of all possible keysyms
|
/// The module `smithay::keyboard::keysyms` exposes definitions of all possible keysyms
|
||||||
/// to be compared against. This includes non-characted keysyms, such as XF86 special keys.
|
/// to be compared against. This includes non-characted keysyms, such as XF86 special keys.
|
||||||
pub fn input<F>(&self, keycode: u32, state: KeyState, serial: u32, filter: F)
|
pub fn input<F>(&self, keycode: u32, state: KeyState, serial: u32, filter: F)
|
||||||
where F: FnOnce(&ModifiersState, Keysym) -> bool
|
where
|
||||||
|
F: FnOnce(&ModifiersState, Keysym) -> bool,
|
||||||
{
|
{
|
||||||
trace!(self.arc.logger, "Handling keystroke"; "keycode" => keycode, "state" => format_args!("{:?}", state));
|
trace!(self.arc.logger, "Handling keystroke"; "keycode" => keycode, "state" => format_args!("{:?}", state));
|
||||||
let mut guard = self.arc.internal.lock().unwrap();
|
let mut guard = self.arc.internal.lock().unwrap();
|
||||||
|
@ -315,8 +320,10 @@ impl KbdHandle {
|
||||||
/// This should be done first, before anything else is done with this keyboard.
|
/// This should be done first, before anything else is done with this keyboard.
|
||||||
pub fn send_keymap(&self, kbd: &wl_keyboard::WlKeyboard) {
|
pub fn send_keymap(&self, kbd: &wl_keyboard::WlKeyboard) {
|
||||||
trace!(self.arc.logger, "Sending keymap to client");
|
trace!(self.arc.logger, "Sending keymap to client");
|
||||||
kbd.keymap(wl_keyboard::KeymapFormat::XkbV1,
|
kbd.keymap(
|
||||||
self.arc.keymap_file.as_raw_fd(),
|
wl_keyboard::KeymapFormat::XkbV1,
|
||||||
self.arc.keymap_len);
|
self.arc.keymap_file.as_raw_fd(),
|
||||||
|
self.arc.keymap_len,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,11 @@ pub mod backend;
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
|
|
||||||
fn slog_or_stdlog<L>(logger: L) -> ::slog::Logger
|
fn slog_or_stdlog<L>(logger: L) -> ::slog::Logger
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
use slog::Drain;
|
use slog::Drain;
|
||||||
logger
|
logger.into().unwrap_or_else(|| {
|
||||||
.into()
|
::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!())
|
||||||
.unwrap_or_else(|| ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!()))
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,8 @@ impl ShmGlobal {
|
||||||
/// as they are required by the protocol. Formats given as argument
|
/// as they are required by the protocol. Formats given as argument
|
||||||
/// as additionnaly advertized.
|
/// as additionnaly advertized.
|
||||||
pub fn new<L>(mut formats: Vec<wl_shm::Format>, logger: L) -> ShmGlobal
|
pub fn new<L>(mut formats: Vec<wl_shm::Format>, logger: L) -> ShmGlobal
|
||||||
where L: Into<Option<::slog::Logger>>
|
where
|
||||||
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
let log = ::slog_or_stdlog(logger);
|
let log = ::slog_or_stdlog(logger);
|
||||||
|
|
||||||
|
@ -147,7 +148,8 @@ impl ShmGlobalToken {
|
||||||
/// If the buffer is not managed by the associated ShmGlobal, the closure is not called
|
/// If the buffer is not managed by the associated ShmGlobal, the closure is not called
|
||||||
/// and this method will return `Err(())` (this will be the case for an EGL buffer for example).
|
/// and this method will return `Err(())` (this will be the case for an EGL buffer for example).
|
||||||
pub fn with_buffer_contents<F>(&self, buffer: &wl_buffer::WlBuffer, f: F) -> Result<(), BufferAccessError>
|
pub fn with_buffer_contents<F>(&self, buffer: &wl_buffer::WlBuffer, f: F) -> Result<(), BufferAccessError>
|
||||||
where F: FnOnce(&[u8], BufferData)
|
where
|
||||||
|
F: FnOnce(&[u8], BufferData),
|
||||||
{
|
{
|
||||||
if !resource_is_registered::<_, ShmHandler>(buffer, self.hid) {
|
if !resource_is_registered::<_, ShmHandler>(buffer, self.hid) {
|
||||||
return Err(BufferAccessError::NotManaged);
|
return Err(BufferAccessError::NotManaged);
|
||||||
|
@ -155,8 +157,9 @@ impl ShmGlobalToken {
|
||||||
let data = unsafe { &*(buffer.get_user_data() as *mut InternalBufferData) };
|
let data = unsafe { &*(buffer.get_user_data() as *mut InternalBufferData) };
|
||||||
|
|
||||||
if data.pool
|
if data.pool
|
||||||
.with_data_slice(|slice| f(slice, data.data))
|
.with_data_slice(|slice| f(slice, data.data))
|
||||||
.is_err() {
|
.is_err()
|
||||||
|
{
|
||||||
// SIGBUS error occured
|
// SIGBUS error occured
|
||||||
buffer.post_error(wl_shm::Error::InvalidFd as u32, "Bad pool size.".into());
|
buffer.post_error(wl_shm::Error::InvalidFd as u32, "Bad pool size.".into());
|
||||||
return Err(BufferAccessError::BadMap);
|
return Err(BufferAccessError::BadMap);
|
||||||
|
@ -168,10 +171,10 @@ impl ShmGlobalToken {
|
||||||
impl Init for ShmGlobal {
|
impl Init for ShmGlobal {
|
||||||
fn init(&mut self, evqh: &mut EventLoopHandle, _index: usize) {
|
fn init(&mut self, evqh: &mut EventLoopHandle, _index: usize) {
|
||||||
let id = evqh.add_handler_with_init(ShmHandler {
|
let id = evqh.add_handler_with_init(ShmHandler {
|
||||||
my_id: ::std::usize::MAX,
|
my_id: ::std::usize::MAX,
|
||||||
valid_formats: self.formats.clone(),
|
valid_formats: self.formats.clone(),
|
||||||
log: self.log.clone(),
|
log: self.log.clone(),
|
||||||
});
|
});
|
||||||
self.handler_id = Some(id);
|
self.handler_id = Some(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,8 +208,10 @@ impl wl_shm::Handler for ShmHandler {
|
||||||
fn create_pool(&mut self, evqh: &mut EventLoopHandle, _client: &Client, shm: &wl_shm::WlShm,
|
fn create_pool(&mut self, evqh: &mut EventLoopHandle, _client: &Client, shm: &wl_shm::WlShm,
|
||||||
pool: wl_shm_pool::WlShmPool, fd: RawFd, size: i32) {
|
pool: wl_shm_pool::WlShmPool, fd: RawFd, size: i32) {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
shm.post_error(wl_shm::Error::InvalidFd as u32,
|
shm.post_error(
|
||||||
"Invalid size for a new wl_shm_pool.".into());
|
wl_shm::Error::InvalidFd as u32,
|
||||||
|
"Invalid size for a new wl_shm_pool.".into(),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mmap_pool = match Pool::new(fd, size as usize, self.log.clone()) {
|
let mmap_pool = match Pool::new(fd, size as usize, self.log.clone()) {
|
||||||
|
@ -232,7 +237,7 @@ impl Destroy<wl_shm_pool::WlShmPool> for ShmHandler {
|
||||||
declare_handler!(ShmHandler, wl_shm::Handler, wl_shm::WlShm);
|
declare_handler!(ShmHandler, wl_shm::Handler, wl_shm::WlShm);
|
||||||
|
|
||||||
/// Details of the contents of a buffer relative to its pool
|
/// Details of the contents of a buffer relative to its pool
|
||||||
#[derive(Copy,Clone,Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct BufferData {
|
pub struct BufferData {
|
||||||
/// Offset of the start of the buffer relative to the beginning of the pool in bytes
|
/// Offset of the start of the buffer relative to the beginning of the pool in bytes
|
||||||
pub offset: i32,
|
pub offset: i32,
|
||||||
|
@ -261,15 +266,15 @@ impl wl_shm_pool::Handler for ShmHandler {
|
||||||
}
|
}
|
||||||
let arc_pool = unsafe { &*(pool.get_user_data() as *mut Arc<Pool>) };
|
let arc_pool = unsafe { &*(pool.get_user_data() as *mut Arc<Pool>) };
|
||||||
let data = Box::into_raw(Box::new(InternalBufferData {
|
let data = Box::into_raw(Box::new(InternalBufferData {
|
||||||
pool: arc_pool.clone(),
|
pool: arc_pool.clone(),
|
||||||
data: BufferData {
|
data: BufferData {
|
||||||
offset: offset,
|
offset: offset,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
stride: stride,
|
stride: stride,
|
||||||
format: format,
|
format: format,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
evqh.register_with_destructor::<_, ShmHandler, ShmHandler>(&buffer, self.my_id);
|
evqh.register_with_destructor::<_, ShmHandler, ShmHandler>(&buffer, self.my_id);
|
||||||
buffer.set_user_data(data as *mut ());
|
buffer.set_user_data(data as *mut ());
|
||||||
}
|
}
|
||||||
|
@ -280,8 +285,10 @@ impl wl_shm_pool::Handler for ShmHandler {
|
||||||
match arc_pool.resize(size) {
|
match arc_pool.resize(size) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(ResizeError::InvalidSize) => {
|
Err(ResizeError::InvalidSize) => {
|
||||||
pool.post_error(wl_shm::Error::InvalidFd as u32,
|
pool.post_error(
|
||||||
"Invalid new size for a wl_shm_pool.".into());
|
wl_shm::Error::InvalidFd as u32,
|
||||||
|
"Invalid new size for a wl_shm_pool.".into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(ResizeError::MremapFailed) => {
|
Err(ResizeError::MremapFailed) => {
|
||||||
pool.post_error(wl_shm::Error::InvalidFd as u32, "mremap failed.".into());
|
pool.post_error(wl_shm::Error::InvalidFd as u32, "mremap failed.".into());
|
||||||
|
|
|
@ -29,10 +29,10 @@ impl Pool {
|
||||||
let memmap = MemMap::new(fd, size)?;
|
let memmap = MemMap::new(fd, size)?;
|
||||||
trace!(log, "Creating new shm pool"; "fd" => fd as i32, "size" => size);
|
trace!(log, "Creating new shm pool"; "fd" => fd as i32, "size" => size);
|
||||||
Ok(Pool {
|
Ok(Pool {
|
||||||
map: RwLock::new(memmap),
|
map: RwLock::new(memmap),
|
||||||
fd: fd,
|
fd: fd,
|
||||||
log: log,
|
log: log,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(&self, newsize: i32) -> Result<(), ResizeError> {
|
pub fn resize(&self, newsize: i32) -> Result<(), ResizeError> {
|
||||||
|
@ -51,8 +51,8 @@ impl Pool {
|
||||||
pub fn with_data_slice<F: FnOnce(&[u8])>(&self, f: F) -> Result<(), ()> {
|
pub fn with_data_slice<F: FnOnce(&[u8])>(&self, f: F) -> Result<(), ()> {
|
||||||
// Place the sigbus handler
|
// Place the sigbus handler
|
||||||
SIGBUS_INIT.call_once(|| unsafe {
|
SIGBUS_INIT.call_once(|| unsafe {
|
||||||
place_sigbus_handler();
|
place_sigbus_handler();
|
||||||
});
|
});
|
||||||
|
|
||||||
let pool_guard = self.map.read().unwrap();
|
let pool_guard = self.map.read().unwrap();
|
||||||
|
|
||||||
|
@ -60,13 +60,13 @@ impl Pool {
|
||||||
|
|
||||||
// Prepare the access
|
// Prepare the access
|
||||||
SIGBUS_GUARD.with(|guard| {
|
SIGBUS_GUARD.with(|guard| {
|
||||||
let (p, _) = guard.get();
|
let (p, _) = guard.get();
|
||||||
if !p.is_null() {
|
if !p.is_null() {
|
||||||
// Recursive call of this method is not supported
|
// Recursive call of this method is not supported
|
||||||
panic!("Recursive access to a SHM pool content is not supported.");
|
panic!("Recursive access to a SHM pool content is not supported.");
|
||||||
}
|
}
|
||||||
guard.set((&*pool_guard as *const MemMap, false))
|
guard.set((&*pool_guard as *const MemMap, false))
|
||||||
});
|
});
|
||||||
|
|
||||||
let slice = pool_guard.get_slice();
|
let slice = pool_guard.get_slice();
|
||||||
f(slice);
|
f(slice);
|
||||||
|
@ -101,10 +101,10 @@ struct MemMap {
|
||||||
impl MemMap {
|
impl MemMap {
|
||||||
fn new(fd: RawFd, size: usize) -> Result<MemMap, ()> {
|
fn new(fd: RawFd, size: usize) -> Result<MemMap, ()> {
|
||||||
Ok(MemMap {
|
Ok(MemMap {
|
||||||
ptr: unsafe { map(fd, size) }?,
|
ptr: unsafe { map(fd, size) }?,
|
||||||
fd: fd,
|
fd: fd,
|
||||||
size: size,
|
size: size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remap(&mut self, newsize: usize) -> Result<(), ()> {
|
fn remap(&mut self, newsize: usize) -> Result<(), ()> {
|
||||||
|
@ -160,12 +160,14 @@ impl Drop for MemMap {
|
||||||
|
|
||||||
// mman::mmap should really be unsafe... why isn't it?
|
// mman::mmap should really be unsafe... why isn't it?
|
||||||
unsafe fn map(fd: RawFd, size: usize) -> Result<*mut u8, ()> {
|
unsafe fn map(fd: RawFd, size: usize) -> Result<*mut u8, ()> {
|
||||||
let ret = mman::mmap(ptr::null_mut(),
|
let ret = mman::mmap(
|
||||||
size,
|
ptr::null_mut(),
|
||||||
mman::PROT_READ,
|
size,
|
||||||
mman::MAP_SHARED,
|
mman::PROT_READ,
|
||||||
fd,
|
mman::MAP_SHARED,
|
||||||
0);
|
fd,
|
||||||
|
0,
|
||||||
|
);
|
||||||
ret.map(|p| p as *mut u8).map_err(|_| ())
|
ret.map(|p| p as *mut u8).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,20 +178,24 @@ unsafe fn unmap(ptr: *mut u8, size: usize) -> Result<(), ()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn nullify_map(ptr: *mut u8, size: usize) -> Result<(), ()> {
|
unsafe fn nullify_map(ptr: *mut u8, size: usize) -> Result<(), ()> {
|
||||||
let ret = mman::mmap(ptr as *mut _,
|
let ret = mman::mmap(
|
||||||
size,
|
ptr as *mut _,
|
||||||
mman::PROT_READ,
|
size,
|
||||||
mman::MAP_ANONYMOUS | mman::MAP_PRIVATE | mman::MAP_FIXED,
|
mman::PROT_READ,
|
||||||
-1,
|
mman::MAP_ANONYMOUS | mman::MAP_PRIVATE | mman::MAP_FIXED,
|
||||||
0);
|
-1,
|
||||||
|
0,
|
||||||
|
);
|
||||||
ret.map(|_| ()).map_err(|_| ())
|
ret.map(|_| ()).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn place_sigbus_handler() {
|
unsafe fn place_sigbus_handler() {
|
||||||
// create our sigbus handler
|
// create our sigbus handler
|
||||||
let action = SigAction::new(SigHandler::SigAction(sigbus_handler),
|
let action = SigAction::new(
|
||||||
signal::SA_NODEFER,
|
SigHandler::SigAction(sigbus_handler),
|
||||||
signal::SigSet::empty());
|
signal::SA_NODEFER,
|
||||||
|
signal::SigSet::empty(),
|
||||||
|
);
|
||||||
match signal::sigaction(Signal::SIGBUS, &action) {
|
match signal::sigaction(Signal::SIGBUS, &action) {
|
||||||
Ok(old_signal) => {
|
Ok(old_signal) => {
|
||||||
OLD_SIGBUS_HANDLER = Box::into_raw(Box::new(old_signal));
|
OLD_SIGBUS_HANDLER = Box::into_raw(Box::new(old_signal));
|
||||||
|
|
Loading…
Reference in New Issue