diff --git a/src/app_tray/compositor/cosmic.rs b/src/app_tray/compositor/cosmic.rs new file mode 100644 index 0000000..ad14554 --- /dev/null +++ b/src/app_tray/compositor/cosmic.rs @@ -0,0 +1,102 @@ +use std::collections::HashSet; + +use cosmic_protocols::toplevel_info::v1::client::{ + zcosmic_toplevel_handle_v1, zcosmic_toplevel_info_v1, +}; +use wayland_client::{Connection, Dispatch, Proxy, QueueHandle}; + +use super::{AppData, ToplevelHandle, ToplevelHandleEvent, ToplevelManagerEvent, ToplevelState}; + +impl From for ToplevelState { + fn from(value: zcosmic_toplevel_handle_v1::State) -> Self { + match value { + zcosmic_toplevel_handle_v1::State::Maximized => Self::Maximized, + zcosmic_toplevel_handle_v1::State::Minimized => Self::Minimized, + zcosmic_toplevel_handle_v1::State::Activated => Self::Activated, + zcosmic_toplevel_handle_v1::State::Fullscreen => Self::Fullscreen, + _ => todo!(), + } + } +} + +impl From for ToplevelHandleEvent { + fn from(value: zcosmic_toplevel_handle_v1::Event) -> Self { + match value { + zcosmic_toplevel_handle_v1::Event::Closed => ToplevelHandleEvent::Closed, + zcosmic_toplevel_handle_v1::Event::Done => ToplevelHandleEvent::Done, + zcosmic_toplevel_handle_v1::Event::Title { title } => { + ToplevelHandleEvent::Title { title } + } + zcosmic_toplevel_handle_v1::Event::AppId { app_id } => { + ToplevelHandleEvent::AppId { app_id } + } + zcosmic_toplevel_handle_v1::Event::OutputEnter { output } => { + ToplevelHandleEvent::OutputEnter { output } + } + zcosmic_toplevel_handle_v1::Event::OutputLeave { output } => { + ToplevelHandleEvent::OutputLeave { output } + } + zcosmic_toplevel_handle_v1::Event::WorkspaceEnter { .. } => todo!(), + zcosmic_toplevel_handle_v1::Event::WorkspaceLeave { .. } => todo!(), + zcosmic_toplevel_handle_v1::Event::State { state } => { + let mut r_state = HashSet::new(); + for value in state.chunks_exact(4) { + if let Ok(state) = zcosmic_toplevel_handle_v1::State::try_from( + u32::from_ne_bytes(value[0..4].try_into().unwrap()), + ) { + r_state.insert(ToplevelState::from(state)); + } + } + Self::State { state: r_state } + } + _ => todo!(), + } + } +} + +impl From for ToplevelManagerEvent { + fn from(value: zcosmic_toplevel_info_v1::Event) -> Self { + match value { + zcosmic_toplevel_info_v1::Event::Toplevel { toplevel } => { + Self::Toplevel(ToplevelHandle::Zcosmic(toplevel)) + } + zcosmic_toplevel_info_v1::Event::Finished => Self::Finished, + _ => todo!(), + } + } +} + +// COSMIC Foreign Toplevel Info + +impl Dispatch for AppData { + fn event( + state: &mut Self, + toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1, + event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + state.handle_toplevel_handle_event( + ToplevelHandle::Zcosmic(toplevel.clone()), + ToplevelHandleEvent::from(event), + ); + } +} + +impl Dispatch for AppData { + fn event( + state: &mut Self, + _proxy: &zcosmic_toplevel_info_v1::ZcosmicToplevelInfoV1, + event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + state.handle_toplevel_manager_event(ToplevelManagerEvent::from(event)); + } + + wayland_client::event_created_child!(AppData, zcosmic_toplevel_info_v1::ZcosmicToplevelInfoV1, [ + zcosmic_toplevel_info_v1::EVT_TOPLEVEL_OPCODE => (zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1, ()) + ]); +} diff --git a/src/app_tray/compositor/kde.rs b/src/app_tray/compositor/kde.rs new file mode 100644 index 0000000..0a279af --- /dev/null +++ b/src/app_tray/compositor/kde.rs @@ -0,0 +1,34 @@ +// KDE Window Management + +use wayland_client::{Connection, Dispatch, Proxy, QueueHandle}; +use wayland_protocols_plasma::plasma_window_management::client::{ + org_kde_plasma_window, org_kde_plasma_window_management, +}; + +use super::AppData; + +impl Dispatch for AppData { + fn event( + _state: &mut Self, + _proxy: &org_kde_plasma_window::OrgKdePlasmaWindow, + event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + println!("{:?}", event); + } +} + +impl Dispatch for AppData { + fn event( + _state: &mut Self, + _proxy: &org_kde_plasma_window_management::OrgKdePlasmaWindowManagement, + event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + println!("{:?}", event); + } +} diff --git a/src/app_tray/compositor/mod.rs b/src/app_tray/compositor/mod.rs index 88cbbbd..bf340f1 100644 --- a/src/app_tray/compositor/mod.rs +++ b/src/app_tray/compositor/mod.rs @@ -47,6 +47,10 @@ use wayland_protocols_wlr::foreign_toplevel::v1::client::{ use crate::app_tray::AppTrayMessage; +pub mod cosmic; +pub mod kde; +pub mod wlr; + struct AppData { exit: bool, tx: UnboundedSender, @@ -159,30 +163,6 @@ pub enum ToplevelState { Activated, } -impl From for ToplevelState { - fn from(value: zcosmic_toplevel_handle_v1::State) -> Self { - match value { - zcosmic_toplevel_handle_v1::State::Maximized => Self::Maximized, - zcosmic_toplevel_handle_v1::State::Minimized => Self::Minimized, - zcosmic_toplevel_handle_v1::State::Activated => Self::Activated, - zcosmic_toplevel_handle_v1::State::Fullscreen => Self::Fullscreen, - _ => todo!(), - } - } -} - -impl From for ToplevelState { - fn from(value: zwlr_foreign_toplevel_handle_v1::State) -> Self { - match value { - zwlr_foreign_toplevel_handle_v1::State::Maximized => Self::Maximized, - zwlr_foreign_toplevel_handle_v1::State::Minimized => Self::Minimized, - zwlr_foreign_toplevel_handle_v1::State::Activated => Self::Activated, - zwlr_foreign_toplevel_handle_v1::State::Fullscreen => Self::Fullscreen, - _ => todo!(), - } - } -} - impl OutputHandler for AppData { fn output_state(&mut self) -> &mut OutputState { &mut self.output_state @@ -246,203 +226,12 @@ enum ToplevelHandleEvent { None, } -impl From for ToplevelHandleEvent { - fn from(value: zwlr_foreign_toplevel_handle_v1::Event) -> Self { - match value { - zwlr_foreign_toplevel_handle_v1::Event::Title { title } => Self::Title { title }, - zwlr_foreign_toplevel_handle_v1::Event::AppId { app_id } => Self::AppId { app_id }, - zwlr_foreign_toplevel_handle_v1::Event::OutputEnter { output } => { - Self::OutputEnter { output } - } - zwlr_foreign_toplevel_handle_v1::Event::OutputLeave { output } => { - Self::OutputLeave { output } - } - zwlr_foreign_toplevel_handle_v1::Event::State { state } => { - let mut r_state = HashSet::new(); - for value in state.chunks_exact(4) { - if let Ok(state) = zwlr_foreign_toplevel_handle_v1::State::try_from( - u32::from_ne_bytes(value[0..4].try_into().unwrap()), - ) { - r_state.insert(ToplevelState::from(state)); - } - } - Self::State { state: r_state } - } - zwlr_foreign_toplevel_handle_v1::Event::Done => Self::Done, - zwlr_foreign_toplevel_handle_v1::Event::Closed => Self::Closed, - zwlr_foreign_toplevel_handle_v1::Event::Parent { .. } => Self::None, // TODO: Not implemented - _ => todo!(), - } - } -} - -impl From for ToplevelHandleEvent { - fn from(value: zcosmic_toplevel_handle_v1::Event) -> Self { - match value { - zcosmic_toplevel_handle_v1::Event::Closed => ToplevelHandleEvent::Closed, - zcosmic_toplevel_handle_v1::Event::Done => ToplevelHandleEvent::Done, - zcosmic_toplevel_handle_v1::Event::Title { title } => { - ToplevelHandleEvent::Title { title } - } - zcosmic_toplevel_handle_v1::Event::AppId { app_id } => { - ToplevelHandleEvent::AppId { app_id } - } - zcosmic_toplevel_handle_v1::Event::OutputEnter { output } => { - ToplevelHandleEvent::OutputEnter { output } - } - zcosmic_toplevel_handle_v1::Event::OutputLeave { output } => { - ToplevelHandleEvent::OutputLeave { output } - } - zcosmic_toplevel_handle_v1::Event::WorkspaceEnter { .. } => todo!(), - zcosmic_toplevel_handle_v1::Event::WorkspaceLeave { .. } => todo!(), - zcosmic_toplevel_handle_v1::Event::State { state } => { - let mut r_state = HashSet::new(); - for value in state.chunks_exact(4) { - if let Ok(state) = zcosmic_toplevel_handle_v1::State::try_from( - u32::from_ne_bytes(value[0..4].try_into().unwrap()), - ) { - r_state.insert(ToplevelState::from(state)); - } - } - Self::State { state: r_state } - } - _ => todo!(), - } - } -} - #[derive(Debug, Clone)] enum ToplevelManagerEvent { Toplevel(ToplevelHandle), Finished, } -impl From for ToplevelManagerEvent { - fn from(value: zwlr_foreign_toplevel_manager_v1::Event) -> Self { - match value { - zwlr_foreign_toplevel_manager_v1::Event::Toplevel { toplevel } => { - Self::Toplevel(ToplevelHandle::Zwlr(toplevel)) - } - zwlr_foreign_toplevel_manager_v1::Event::Finished => Self::Finished, - _ => todo!(), - } - } -} - -impl From for ToplevelManagerEvent { - fn from(value: zcosmic_toplevel_info_v1::Event) -> Self { - match value { - zcosmic_toplevel_info_v1::Event::Toplevel { toplevel } => { - Self::Toplevel(ToplevelHandle::Zcosmic(toplevel)) - } - zcosmic_toplevel_info_v1::Event::Finished => Self::Finished, - _ => todo!(), - } - } -} - -// WLR Foreign Toplevel Management - -impl Dispatch for AppData { - fn event( - state: &mut Self, - toplevel: &zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1, - event: ::Event, - _data: &(), - _conn: &Connection, - _qhandle: &QueueHandle, - ) { - state.handle_toplevel_handle_event( - ToplevelHandle::Zwlr(toplevel.clone()), - ToplevelHandleEvent::from(event), - ); - } -} - -impl Dispatch for AppData { - fn event( - state: &mut Self, - _proxy: &wayland_protocols_wlr::foreign_toplevel::v1::client::zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1, - event: wayland_protocols_wlr::foreign_toplevel::v1::client::zwlr_foreign_toplevel_manager_v1::Event, - _data: &(), - _conn: &Connection, - _qhandle: &QueueHandle, - ) { - // println!("Toplevel event {:?}", event); - state.handle_toplevel_manager_event(ToplevelManagerEvent::from(event)); - } - - event_created_child!( - AppData, zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1, - [ - zwlr_foreign_toplevel_manager_v1::EVT_TOPLEVEL_OPCODE => (zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1, ()) - ] - ); -} - -// COSMIC Foreign Toplevel Info - -impl Dispatch for AppData { - fn event( - state: &mut Self, - toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1, - event: ::Event, - _data: &(), - _conn: &Connection, - _qhandle: &QueueHandle, - ) { - state.handle_toplevel_handle_event( - ToplevelHandle::Zcosmic(toplevel.clone()), - ToplevelHandleEvent::from(event), - ); - } -} - -impl Dispatch for AppData { - fn event( - state: &mut Self, - _proxy: &zcosmic_toplevel_info_v1::ZcosmicToplevelInfoV1, - event: ::Event, - _data: &(), - _conn: &Connection, - _qhandle: &QueueHandle, - ) { - state.handle_toplevel_manager_event(ToplevelManagerEvent::from(event)); - } - - wayland_client::event_created_child!(AppData, zcosmic_toplevel_info_v1::ZcosmicToplevelInfoV1, [ - zcosmic_toplevel_info_v1::EVT_TOPLEVEL_OPCODE => (zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1, ()) - ]); -} - -// KDE Window Management - -impl Dispatch for AppData { - fn event( - _state: &mut Self, - _proxy: &org_kde_plasma_window::OrgKdePlasmaWindow, - event: ::Event, - _data: &(), - _conn: &Connection, - _qhandle: &QueueHandle, - ) { - println!("{:?}", event); - } -} - -impl Dispatch for AppData { - fn event( - _state: &mut Self, - _proxy: &org_kde_plasma_window_management::OrgKdePlasmaWindowManagement, - event: ::Event, - _data: &(), - _conn: &Connection, - _qhandle: &QueueHandle, - ) { - println!("{:?}", event); - } -} - // WL REGISTRY // You need to provide a Dispatch impl for your app diff --git a/src/app_tray/compositor/wlr.rs b/src/app_tray/compositor/wlr.rs new file mode 100644 index 0000000..29da4ca --- /dev/null +++ b/src/app_tray/compositor/wlr.rs @@ -0,0 +1,101 @@ +use std::collections::HashSet; + +use wayland_client::{event_created_child, Connection, Dispatch, Proxy, QueueHandle}; +use wayland_protocols_wlr::foreign_toplevel::v1::client::{ + zwlr_foreign_toplevel_handle_v1, zwlr_foreign_toplevel_manager_v1, +}; + +use super::{AppData, ToplevelHandle, ToplevelHandleEvent, ToplevelManagerEvent, ToplevelState}; + +impl From for ToplevelState { + fn from(value: zwlr_foreign_toplevel_handle_v1::State) -> Self { + match value { + zwlr_foreign_toplevel_handle_v1::State::Maximized => Self::Maximized, + zwlr_foreign_toplevel_handle_v1::State::Minimized => Self::Minimized, + zwlr_foreign_toplevel_handle_v1::State::Activated => Self::Activated, + zwlr_foreign_toplevel_handle_v1::State::Fullscreen => Self::Fullscreen, + _ => todo!(), + } + } +} + +impl From for ToplevelHandleEvent { + fn from(value: zwlr_foreign_toplevel_handle_v1::Event) -> Self { + match value { + zwlr_foreign_toplevel_handle_v1::Event::Title { title } => Self::Title { title }, + zwlr_foreign_toplevel_handle_v1::Event::AppId { app_id } => Self::AppId { app_id }, + zwlr_foreign_toplevel_handle_v1::Event::OutputEnter { output } => { + Self::OutputEnter { output } + } + zwlr_foreign_toplevel_handle_v1::Event::OutputLeave { output } => { + Self::OutputLeave { output } + } + zwlr_foreign_toplevel_handle_v1::Event::State { state } => { + let mut r_state = HashSet::new(); + for value in state.chunks_exact(4) { + if let Ok(state) = zwlr_foreign_toplevel_handle_v1::State::try_from( + u32::from_ne_bytes(value[0..4].try_into().unwrap()), + ) { + r_state.insert(ToplevelState::from(state)); + } + } + Self::State { state: r_state } + } + zwlr_foreign_toplevel_handle_v1::Event::Done => Self::Done, + zwlr_foreign_toplevel_handle_v1::Event::Closed => Self::Closed, + zwlr_foreign_toplevel_handle_v1::Event::Parent { .. } => Self::None, // TODO: Not implemented + _ => todo!(), + } + } +} + +impl From for ToplevelManagerEvent { + fn from(value: zwlr_foreign_toplevel_manager_v1::Event) -> Self { + match value { + zwlr_foreign_toplevel_manager_v1::Event::Toplevel { toplevel } => { + Self::Toplevel(ToplevelHandle::Zwlr(toplevel)) + } + zwlr_foreign_toplevel_manager_v1::Event::Finished => Self::Finished, + _ => todo!(), + } + } +} + +// WLR Foreign Toplevel Management + +impl Dispatch for AppData { + fn event( + state: &mut Self, + toplevel: &zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1, + event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + state.handle_toplevel_handle_event( + ToplevelHandle::Zwlr(toplevel.clone()), + ToplevelHandleEvent::from(event), + ); + } +} + +impl Dispatch for AppData { + fn event( + state: &mut Self, + _proxy: &wayland_protocols_wlr::foreign_toplevel::v1::client::zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1, + event: wayland_protocols_wlr::foreign_toplevel::v1::client::zwlr_foreign_toplevel_manager_v1::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + // println!("Toplevel event {:?}", event); + state.handle_toplevel_manager_event(ToplevelManagerEvent::from(event)); + } + + event_created_child!( + AppData, zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1, + [ + zwlr_foreign_toplevel_manager_v1::EVT_TOPLEVEL_OPCODE => (zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1, ()) + ] + ); +} diff --git a/src/app_tray/mod.rs b/src/app_tray/mod.rs index 119e4e8..62acbbc 100644 --- a/src/app_tray/mod.rs +++ b/src/app_tray/mod.rs @@ -201,5 +201,5 @@ fn get_horizontal_rule<'a>( }), ) .width(Length::Fixed(if is_active { 12.0 } else { 6.0 })) - .center_x(Length::Fill) + // .center_x(Length::Fill) }