changed FullscreenEvent
to be On, Off, Toggle
instead of a simple bool
This commit is contained in:
parent
7961c97d2f
commit
f6a871d1e7
|
@ -265,18 +265,31 @@ impl<Window> ConfigureEvent<Window> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum FullscreenState {
|
||||||
|
On,
|
||||||
|
Off,
|
||||||
|
Toggle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<bool> for FullscreenState {
|
||||||
|
fn from(value: bool) -> Self {
|
||||||
|
match value {
|
||||||
|
true => Self::On,
|
||||||
|
false => Self::Off,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FullscreenEvent<Window> {
|
pub struct FullscreenEvent<Window> {
|
||||||
window: Window,
|
pub window: Window,
|
||||||
new_fullscreen: bool,
|
pub state: FullscreenState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Window> FullscreenEvent<Window> {
|
impl<Window> FullscreenEvent<Window> {
|
||||||
pub fn new(window: Window, new_fullscreen: bool) -> Self {
|
pub fn new(window: Window, state: FullscreenState) -> Self {
|
||||||
Self {
|
Self { window, state }
|
||||||
window,
|
|
||||||
new_fullscreen,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use std::{ffi::CString, rc::Rc};
|
use std::{ffi::CString, mem::MaybeUninit, rc::Rc};
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ use self::keysym::{
|
||||||
use super::{
|
use super::{
|
||||||
keycodes::VirtualKeyCode,
|
keycodes::VirtualKeyCode,
|
||||||
window_event::{
|
window_event::{
|
||||||
ButtonEvent, ConfigureEvent, DestroyEvent, EnterEvent, KeyEvent,
|
ButtonEvent, ConfigureEvent, DestroyEvent, EnterEvent, FullscreenEvent,
|
||||||
KeyOrMouseBind, KeyState, MapEvent, ModifierState, MotionEvent, Point,
|
FullscreenState, KeyEvent, KeyOrMouseBind, KeyState, MapEvent,
|
||||||
UnmapEvent, WindowEvent,
|
ModifierState, MotionEvent, Point, UnmapEvent, WindowEvent,
|
||||||
},
|
},
|
||||||
WindowServerBackend,
|
WindowServerBackend,
|
||||||
};
|
};
|
||||||
|
@ -285,6 +285,53 @@ impl XLib {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
xlib::PropertyNotify => {
|
||||||
|
let ev = unsafe { &event.property };
|
||||||
|
|
||||||
|
(ev.atom == self.atoms.net_wm_window_type)
|
||||||
|
.then(|| {
|
||||||
|
(self.get_atom_property(
|
||||||
|
ev.window,
|
||||||
|
self.atoms.net_wm_state,
|
||||||
|
) == Some(self.atoms.net_wm_state_fullscreen))
|
||||||
|
.then(|| {
|
||||||
|
XLibWindowEvent::FullscreenEvent(
|
||||||
|
FullscreenEvent::new(
|
||||||
|
ev.window,
|
||||||
|
FullscreenState::On,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
xlib::ClientMessage => {
|
||||||
|
let ev = unsafe { &event.client_message };
|
||||||
|
|
||||||
|
(ev.message_type == self.atoms.net_wm_state)
|
||||||
|
.then(|| {
|
||||||
|
let data = ev.data.as_longs();
|
||||||
|
(data[1] as u64 == self.atoms.net_wm_state_fullscreen
|
||||||
|
|| data[2] as u64
|
||||||
|
== self.atoms.net_wm_state_fullscreen)
|
||||||
|
.then(|| {
|
||||||
|
XLibWindowEvent::FullscreenEvent(
|
||||||
|
FullscreenEvent::new(
|
||||||
|
ev.window,
|
||||||
|
match data[0] /* as u64 */ {
|
||||||
|
0 => FullscreenState::Off,
|
||||||
|
1 => FullscreenState::On,
|
||||||
|
2 => FullscreenState::Toggle,
|
||||||
|
_ => {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,6 +355,37 @@ impl XLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_atom_property(
|
||||||
|
&self,
|
||||||
|
window: xlib::Window,
|
||||||
|
atom: xlib::Atom,
|
||||||
|
) -> Option<xlib::Atom> {
|
||||||
|
let mut di = 0;
|
||||||
|
let mut dl0 = 0;
|
||||||
|
let mut dl1 = 0;
|
||||||
|
let mut da = 0;
|
||||||
|
|
||||||
|
let mut atom_out = MaybeUninit::<xlib::Atom>::zeroed();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
(xlib::XGetWindowProperty(
|
||||||
|
self.dpy(),
|
||||||
|
window,
|
||||||
|
atom,
|
||||||
|
0,
|
||||||
|
std::mem::size_of::<xlib::Atom>() as i64,
|
||||||
|
0,
|
||||||
|
xlib::XA_ATOM,
|
||||||
|
&mut da,
|
||||||
|
&mut di,
|
||||||
|
&mut dl0,
|
||||||
|
&mut dl1,
|
||||||
|
atom_out.as_mut_ptr() as *mut _,
|
||||||
|
) != 0)
|
||||||
|
.then(|| atom_out.assume_init())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_for_protocol(
|
fn check_for_protocol(
|
||||||
&self,
|
&self,
|
||||||
window: xlib::Window,
|
window: xlib::Window,
|
||||||
|
|
12
src/state.rs
12
src/state.rs
|
@ -8,9 +8,9 @@ use crate::{
|
||||||
backends::{
|
backends::{
|
||||||
keycodes::{MouseButton, VirtualKeyCode},
|
keycodes::{MouseButton, VirtualKeyCode},
|
||||||
window_event::{
|
window_event::{
|
||||||
ButtonEvent, ConfigureEvent, KeyBind, KeyEvent, KeyState, MapEvent,
|
ButtonEvent, ConfigureEvent, FullscreenEvent, KeyBind, KeyEvent,
|
||||||
ModifierKey, ModifierState, MotionEvent, MouseBind, Point,
|
KeyState, MapEvent, ModifierKey, ModifierState, MotionEvent,
|
||||||
WindowEvent,
|
MouseBind, Point, WindowEvent,
|
||||||
},
|
},
|
||||||
xlib::XLib,
|
xlib::XLib,
|
||||||
WindowServerBackend,
|
WindowServerBackend,
|
||||||
|
@ -464,6 +464,12 @@ where
|
||||||
// None => self.xlib.configure_window(event),
|
// None => self.xlib.configure_window(event),
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
WindowEvent::FullscreenEvent(FullscreenEvent {
|
||||||
|
window,
|
||||||
|
state,
|
||||||
|
}) => {
|
||||||
|
info!("FullscreenEvent for window {}: {:?}", window, state);
|
||||||
|
}
|
||||||
|
|
||||||
// i dont think i actually have to handle destroy notify events.
|
// i dont think i actually have to handle destroy notify events.
|
||||||
// every window should be unmapped regardless
|
// every window should be unmapped regardless
|
||||||
|
|
Loading…
Reference in a new issue