Add mouse cursor to Window
This commit is contained in:
parent
47b122c86e
commit
adc8fe0974
2 changed files with 32 additions and 2 deletions
|
@ -9,6 +9,7 @@ pub enum MouseCursor {
|
||||||
Grabbing,
|
Grabbing,
|
||||||
ResizingHorizontally,
|
ResizingHorizontally,
|
||||||
ResizingVertically,
|
ResizingVertically,
|
||||||
|
Hidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MouseCursor {
|
impl Default for MouseCursor {
|
||||||
|
|
|
@ -7,14 +7,15 @@ use raw_window_handle::{unix::XlibHandle, HasRawWindowHandle, RawWindowHandle};
|
||||||
|
|
||||||
use super::XcbConnection;
|
use super::XcbConnection;
|
||||||
use crate::{
|
use crate::{
|
||||||
Event, KeyboardEvent, MouseButton, MouseEvent, Parent, ScrollDelta, WindowEvent, WindowHandler,
|
Event, KeyboardEvent, MouseButton, MouseCursor, MouseEvent, Parent, ScrollDelta, WindowEvent,
|
||||||
WindowInfo, WindowOpenOptions,
|
WindowHandler,WindowInfo, WindowOpenOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
xcb_connection: XcbConnection,
|
xcb_connection: XcbConnection,
|
||||||
window_id: u32,
|
window_id: u32,
|
||||||
window_info: WindowInfo,
|
window_info: WindowInfo,
|
||||||
|
mouse_cursor: MouseCursor,
|
||||||
|
|
||||||
frame_interval: Duration,
|
frame_interval: Duration,
|
||||||
event_loop_running: bool,
|
event_loop_running: bool,
|
||||||
|
@ -145,6 +146,7 @@ impl Window {
|
||||||
xcb_connection,
|
xcb_connection,
|
||||||
window_id,
|
window_id,
|
||||||
window_info,
|
window_info,
|
||||||
|
mouse_cursor: MouseCursor::default(),
|
||||||
|
|
||||||
frame_interval: Duration::from_millis(15),
|
frame_interval: Duration::from_millis(15),
|
||||||
event_loop_running: false,
|
event_loop_running: false,
|
||||||
|
@ -162,6 +164,33 @@ impl Window {
|
||||||
&self.window_info
|
&self.window_info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn set_mouse_cursor(&mut self, mouse_cursor: MouseCursor) {
|
||||||
|
if self.mouse_cursor != mouse_cursor {
|
||||||
|
if mouse_cursor == MouseCursor::Hidden {
|
||||||
|
xcb::change_cursor(&self.xcb_connection.conn, xcb::CW_CURSOR, xcb::CURSOR_NONE);
|
||||||
|
} else {
|
||||||
|
let cursor_name = match mouse_cursor {
|
||||||
|
MouseCursor::Idle => "pointer",
|
||||||
|
MouseCursor::Pointer => "pointer",
|
||||||
|
MouseCursor::Grab => "hand1",
|
||||||
|
MouseCursor::Text => "xterm",
|
||||||
|
MouseCursor::Crosshair => "crosshair",
|
||||||
|
MouseCursor::Working => "watch",
|
||||||
|
MouseCursor::Grabbing => "hand2",
|
||||||
|
MouseCursor::ResizingHorizontally => "sizing",
|
||||||
|
MouseCursor::ResizingVertically => "sizing",
|
||||||
|
_ => "pointer",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.mouse_cursor = mouse_cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn drain_xcb_events<H: WindowHandler>(&mut self, handler: &mut H) {
|
fn drain_xcb_events<H: WindowHandler>(&mut self, handler: &mut H) {
|
||||||
while let Some(event) = self.xcb_connection.conn.poll_for_event() {
|
while let Some(event) = self.xcb_connection.conn.poll_for_event() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue