-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
313 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
use cosmic_protocols::workspace::v2::server::{ | ||
zcosmic_workspace_handle_v2::{self, ZcosmicWorkspaceHandleV2}, | ||
zcosmic_workspace_manager_v2::{self, ZcosmicWorkspaceManagerV2}, | ||
}; | ||
use smithay::reexports::{ | ||
wayland_protocols::ext::workspace::v1::server::ext_workspace_handle_v1::ExtWorkspaceHandleV1, | ||
wayland_server::{ | ||
backend::ClientData, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, | ||
Resource, Weak, | ||
}, | ||
}; | ||
|
||
use super::{ | ||
GroupCapabilities, Request, Workspace, WorkspaceCapabilities, WorkspaceClientHandler, | ||
WorkspaceData, WorkspaceDataInner, WorkspaceGlobalData, WorkspaceGroup, WorkspaceGroupData, | ||
WorkspaceGroupHandle, WorkspaceHandler, WorkspaceState, | ||
}; | ||
|
||
pub struct CosmicWorkspaceData { | ||
workspace: Weak<ExtWorkspaceHandleV1>, | ||
} | ||
|
||
impl<D> GlobalDispatch<ZcosmicWorkspaceManagerV2, WorkspaceGlobalData, D> for WorkspaceState<D> | ||
where | ||
D: GlobalDispatch<ZcosmicWorkspaceManagerV2, WorkspaceGlobalData> | ||
+ Dispatch<ZcosmicWorkspaceManagerV2, ()> | ||
+ Dispatch<ZcosmicWorkspaceHandleV2, CosmicWorkspaceData> | ||
+ WorkspaceHandler | ||
+ 'static, | ||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static, | ||
{ | ||
fn bind( | ||
_state: &mut D, | ||
_dh: &DisplayHandle, | ||
_client: &Client, | ||
resource: New<ZcosmicWorkspaceManagerV2>, | ||
_global_data: &WorkspaceGlobalData, | ||
data_init: &mut DataInit<'_, D>, | ||
) { | ||
data_init.init(resource, ()); | ||
} | ||
|
||
fn can_view(client: Client, global_data: &WorkspaceGlobalData) -> bool { | ||
(global_data.filter)(&client) | ||
} | ||
} | ||
|
||
impl<D> Dispatch<ZcosmicWorkspaceManagerV2, (), D> for WorkspaceState<D> | ||
where | ||
D: GlobalDispatch<ZcosmicWorkspaceManagerV2, WorkspaceGlobalData> | ||
+ Dispatch<ZcosmicWorkspaceManagerV2, ()> | ||
+ Dispatch<ZcosmicWorkspaceHandleV2, CosmicWorkspaceData> | ||
+ WorkspaceHandler | ||
+ 'static, | ||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static, | ||
{ | ||
fn request( | ||
state: &mut D, | ||
_client: &Client, | ||
_obj: &ZcosmicWorkspaceManagerV2, | ||
request: zcosmic_workspace_manager_v2::Request, | ||
_data: &(), | ||
_dh: &DisplayHandle, | ||
data_init: &mut DataInit<'_, D>, | ||
) { | ||
match request { | ||
zcosmic_workspace_manager_v2::Request::GetCosmicWorkspace { | ||
cosmic_workspace, | ||
workspace, | ||
} => { | ||
let cosmic_workspace = data_init.init( | ||
cosmic_workspace, | ||
CosmicWorkspaceData { | ||
workspace: workspace.downgrade(), | ||
}, | ||
); | ||
if let Some(data) = workspace.data::<WorkspaceData>() { | ||
// TODO protocol error if workspace has a cosmic workspace | ||
let mut data = data.lock().unwrap(); | ||
data.cosmic_v2_handle = Some(cosmic_workspace.downgrade()); | ||
if let Some((workspace, ext_mngr, _)) = state | ||
.workspace_state() | ||
.groups | ||
.iter() | ||
.flat_map(|g| &g.workspaces) | ||
.flat_map(|w| w.ext_instances.iter().map(move |(mngr, i)| (w, mngr, i))) | ||
.find(|(_, _, i)| **i == workspace) | ||
{ | ||
if let Ok(ext_mngr) = ext_mngr.upgrade() { | ||
send_workspace_to_client(&cosmic_workspace, &mut data, workspace); | ||
ext_mngr.done(); | ||
} | ||
} | ||
} | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
|
||
impl<D> Dispatch<ZcosmicWorkspaceHandleV2, CosmicWorkspaceData, D> for WorkspaceState<D> | ||
where | ||
D: GlobalDispatch<ZcosmicWorkspaceManagerV2, WorkspaceGlobalData> | ||
+ Dispatch<ZcosmicWorkspaceManagerV2, ()> | ||
+ Dispatch<ZcosmicWorkspaceHandleV2, CosmicWorkspaceData> | ||
+ WorkspaceHandler | ||
+ 'static, | ||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static, | ||
{ | ||
fn request( | ||
state: &mut D, | ||
client: &Client, | ||
_obj: &ZcosmicWorkspaceHandleV2, | ||
request: zcosmic_workspace_handle_v2::Request, | ||
data: &CosmicWorkspaceData, | ||
_dh: &DisplayHandle, | ||
_data_init: &mut DataInit<'_, D>, | ||
) { | ||
let Ok(workspace) = data.workspace.upgrade() else { | ||
return; | ||
}; | ||
match request { | ||
zcosmic_workspace_handle_v2::Request::Rename { name } => { | ||
if let Some(workspace_handle) = | ||
state.workspace_state().get_ext_workspace_handle(&workspace) | ||
{ | ||
let mut state = client | ||
.get_data::<<D as WorkspaceHandler>::Client>() | ||
.unwrap() | ||
.workspace_state() | ||
.lock() | ||
.unwrap(); | ||
state.requests.push(Request::Rename { | ||
workspace: workspace_handle, | ||
name, | ||
}); | ||
} | ||
} | ||
zcosmic_workspace_handle_v2::Request::SetTilingState { | ||
state: tiling_state, | ||
} => { | ||
if let Some(workspace_handle) = | ||
state.workspace_state().get_ext_workspace_handle(&workspace) | ||
{ | ||
let mut state = client | ||
.get_data::<<D as WorkspaceHandler>::Client>() | ||
.unwrap() | ||
.workspace_state() | ||
.lock() | ||
.unwrap(); | ||
state.requests.push(Request::SetTilingState { | ||
workspace: workspace_handle, | ||
state: tiling_state, | ||
}); | ||
} | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
|
||
// TODO: destroyed | ||
} | ||
|
||
pub fn send_workspace_to_client( | ||
instance: &ZcosmicWorkspaceHandleV2, | ||
handle_state: &mut WorkspaceDataInner, | ||
workspace: &Workspace, | ||
) -> bool { | ||
let mut changed = false; | ||
|
||
// TODO capabilities | ||
|
||
if handle_state | ||
.tiling | ||
.map(|state| state != workspace.tiling) | ||
.unwrap_or(true) | ||
{ | ||
instance.tiling_state(workspace.tiling); | ||
handle_state.tiling = Some(workspace.tiling); | ||
changed = true; | ||
} | ||
|
||
false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.