Fix disappearing cursor after tty switch

This commit is contained in:
Drakulix 2018-01-27 13:05:52 +01:00
parent 5411209bb5
commit 310bc94a20
2 changed files with 25 additions and 6 deletions

View File

@ -24,8 +24,8 @@ pub struct DrmBackend<A: Device + 'static> {
}
pub(crate) struct DrmBackendInternal<A: Device + 'static> {
context: Rc<EGLContext<Gbm<framebuffer::Info>, GbmDevice<A>>>,
cursor: Cell<BufferObject<()>>,
pub(crate) context: Rc<EGLContext<Gbm<framebuffer::Info>, GbmDevice<A>>>,
pub(crate) cursor: Cell<(BufferObject<()>, (u32, u32))>,
current_frame_buffer: Cell<framebuffer::Info>,
front_buffer: Cell<SurfaceBufferHandle<framebuffer::Info>>,
next_buffer: Cell<Option<SurfaceBufferHandle<framebuffer::Info>>>,
@ -96,14 +96,14 @@ impl<A: Device + 'static> DrmBackend<A> {
})?;
front_bo.set_userdata(fb).unwrap();
let cursor = Cell::new(context
let cursor = Cell::new((context
.create_buffer_object(
1,
1,
GbmFormat::ARGB8888,
BufferObjectFlags::CURSOR | BufferObjectFlags::WRITE,
)
.chain_err(|| ErrorKind::GbmInitFailed)?);
.chain_err(|| ErrorKind::GbmInitFailed)?, (0,0)));
Ok(DrmBackend {
backend: Rc::new(DrmBackendInternal {
@ -455,7 +455,7 @@ impl<A: Device + 'static> GraphicsBackend for DrmBackend<A> {
}
// and store it
self.backend.cursor.set(cursor);
self.backend.cursor.set((cursor, hotspot));
Ok(())
}
}

View File

@ -219,7 +219,7 @@ use drm::control::{connector, crtc, encoder, Mode, ResourceInfo};
use drm::control::Device as ControlDevice;
use drm::control::framebuffer;
use drm::result::Error as DrmError;
use gbm::Device as GbmDevice;
use gbm::{Device as GbmDevice, BufferObject};
use nix;
use nix::sys::stat::{self, dev_t, fstat};
use std::collections::HashMap;
@ -655,6 +655,25 @@ impl<A: ControlDevice + 'static> SessionObserver for StateToken<DrmDevice<A>> {
"Failed to activate crtc ({:?}) again. Error: {}", crtc, err
);
}
// reset cursor
{
let &(ref cursor, ref hotspot) : &(BufferObject<()>, (u32, u32))
= unsafe { &*backend.cursor.as_ptr() };
if crtc::set_cursor2(
&*backend.context,
*crtc,
cursor,
((*hotspot).0 as i32, (*hotspot).1 as i32),
).is_err()
{
if let Err(err) = crtc::set_cursor(&*backend.context, *crtc, cursor) {
error!(
device.logger,
"Failed to reset cursor. Error: {}", err
);
}
}
}
} else {
crtcs.push(*crtc);
}