Skip to content

Commit e944ee9

Browse files
committed
protocols/workspace: Store request queue in workspace manager udata
This is slightly simpler, if there's not some reason I'm missing to do this as it was previously done. And in particular provides a cleaner API (if we wanted to move this to Smithay; perhaps without the Cosmic extension). But it also should be more correct. Presumably if a client (unusually) had multiple components with their own `ext_workspace_manager_v1` instance, they should have their own queues, and `ext_workspace_manager_v1::commit` should be independent. Inevitably, there's a racy element to multiple components trying to update the workspace state like this, but it should behave the same as two clients with separate connections. (This is different from `CompositorClientState`, since the commit queue there is fundamentally tied to the client, and different components with their own compositor instance way have related surfaces.)
1 parent 2f6d600 commit e944ee9

File tree

5 files changed

+106
-113
lines changed

5 files changed

+106
-113
lines changed

src/state.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
screencopy::ScreencopyState,
2525
toplevel_info::ToplevelInfoState,
2626
toplevel_management::{ManagementCapabilities, ToplevelManagementState},
27-
workspace::{WorkspaceClientState, WorkspaceState, WorkspaceUpdateGuard},
27+
workspace::{WorkspaceState, WorkspaceUpdateGuard},
2828
},
2929
},
3030
xwayland::XWaylandState,
@@ -141,7 +141,6 @@ macro_rules! fl {
141141

142142
pub struct ClientState {
143143
pub compositor_client_state: CompositorClientState,
144-
pub workspace_client_state: WorkspaceClientState,
145144
pub advertised_drm_node: Option<DrmNode>,
146145
pub privileged: bool,
147146
pub evls: LoopSignal,
@@ -679,7 +678,6 @@ impl State {
679678
pub fn new_client_state(&self) -> ClientState {
680679
ClientState {
681680
compositor_client_state: CompositorClientState::default(),
682-
workspace_client_state: WorkspaceClientState::default(),
683681
advertised_drm_node: match &self.backend {
684682
BackendData::Kms(kms_state) => kms_state.primary_node,
685683
_ => None,

src/wayland/handlers/workspace.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22

33
use crate::{
44
shell::WorkspaceDelta,
5-
state::ClientState,
65
utils::prelude::*,
76
wayland::protocols::workspace::{
8-
delegate_workspace, Request, WorkspaceClientHandler, WorkspaceClientState,
9-
WorkspaceHandler, WorkspaceState,
7+
delegate_workspace, Request, WorkspaceHandler, WorkspaceState,
108
},
119
};
1210
use cosmic_protocols::workspace::v2::server::zcosmic_workspace_handle_v2::TilingState;
1311
use smithay::reexports::wayland_server::DisplayHandle;
1412

15-
impl WorkspaceClientHandler for ClientState {
16-
fn workspace_state(&self) -> &WorkspaceClientState {
17-
&self.workspace_client_state
18-
}
19-
}
20-
2113
impl WorkspaceHandler for State {
22-
type Client = ClientState;
2314
fn workspace_state(&self) -> &WorkspaceState<Self> {
2415
&self.common.workspace_state
2516
}

src/wayland/protocols/workspace/cosmic_v2.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use smithay::reexports::{
1313
use std::sync::Mutex;
1414

1515
use super::{
16-
Request, Workspace, WorkspaceCapabilities, WorkspaceClientHandler, WorkspaceData,
17-
WorkspaceGlobalData, WorkspaceHandler, WorkspaceState,
16+
Request, Workspace, WorkspaceCapabilities, WorkspaceData, WorkspaceGlobalData,
17+
WorkspaceHandler, WorkspaceManagerData, WorkspaceState,
1818
};
1919

2020
#[derive(Default)]
@@ -113,7 +113,7 @@ where
113113
{
114114
fn request(
115115
state: &mut D,
116-
client: &Client,
116+
_client: &Client,
117117
_obj: &ZcosmicWorkspaceHandleV2,
118118
request: zcosmic_workspace_handle_v2::Request,
119119
data: &CosmicWorkspaceV2Data,
@@ -128,16 +128,19 @@ where
128128
if let Some(workspace_handle) =
129129
state.workspace_state().get_ext_workspace_handle(&workspace)
130130
{
131-
let mut state = client
132-
.get_data::<<D as WorkspaceHandler>::Client>()
133-
.unwrap()
134-
.workspace_state()
135-
.lock()
136-
.unwrap();
137-
state.requests.push(Request::Rename {
138-
workspace: workspace_handle,
139-
name,
140-
});
131+
if let Ok(manager) =
132+
workspace.data::<WorkspaceData>().unwrap().manager.upgrade()
133+
{
134+
let mut state = manager
135+
.data::<WorkspaceManagerData>()
136+
.unwrap()
137+
.lock()
138+
.unwrap();
139+
state.requests.push(Request::Rename {
140+
workspace: workspace_handle,
141+
name,
142+
});
143+
}
141144
}
142145
}
143146
zcosmic_workspace_handle_v2::Request::SetTilingState {
@@ -146,16 +149,19 @@ where
146149
if let Some(workspace_handle) =
147150
state.workspace_state().get_ext_workspace_handle(&workspace)
148151
{
149-
let mut state = client
150-
.get_data::<<D as WorkspaceHandler>::Client>()
151-
.unwrap()
152-
.workspace_state()
153-
.lock()
154-
.unwrap();
155-
state.requests.push(Request::SetTilingState {
156-
workspace: workspace_handle,
157-
state: tiling_state,
158-
});
152+
if let Ok(manager) =
153+
workspace.data::<WorkspaceData>().unwrap().manager.upgrade()
154+
{
155+
let mut state = manager
156+
.data::<WorkspaceManagerData>()
157+
.unwrap()
158+
.lock()
159+
.unwrap();
160+
state.requests.push(Request::SetTilingState {
161+
workspace: workspace_handle,
162+
state: tiling_state,
163+
});
164+
}
159165
}
160166
}
161167
zcosmic_workspace_handle_v2::Request::Destroy => {}

src/wayland/protocols/workspace/ext.rs

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ use smithay::{
2020
use std::{collections::HashSet, sync::Mutex};
2121

2222
use super::{
23-
Request, Workspace, WorkspaceCapabilities, WorkspaceClientHandler, WorkspaceGlobalData,
24-
WorkspaceGroup, WorkspaceGroupHandle, WorkspaceHandler, WorkspaceState,
23+
Request, Workspace, WorkspaceCapabilities, WorkspaceGlobalData, WorkspaceGroup,
24+
WorkspaceGroupHandle, WorkspaceHandler, WorkspaceState,
2525
};
2626

27+
#[derive(Debug, Default)]
28+
pub struct WorkspaceManagerDataInner {
29+
pub(super) requests: Vec<Request>,
30+
}
31+
32+
pub type WorkspaceManagerData = Mutex<WorkspaceManagerDataInner>;
33+
2734
#[derive(Default)]
2835
pub struct WorkspaceGroupDataInner {
2936
outputs: Vec<Output>,
@@ -64,7 +71,7 @@ where
6471
data_init: &mut DataInit<'_, D>,
6572
) {
6673
let state = state.workspace_state_mut();
67-
let instance = data_init.init(resource, ());
74+
let instance = data_init.init(resource, WorkspaceManagerData::default());
6875
for group in &mut state.groups {
6976
send_group_to_client::<D>(dh, &instance, group);
7077
}
@@ -77,29 +84,24 @@ where
7784
}
7885
}
7986

80-
impl<D> Dispatch<ExtWorkspaceManagerV1, (), D> for WorkspaceState<D>
87+
impl<D> Dispatch<ExtWorkspaceManagerV1, WorkspaceManagerData, D> for WorkspaceState<D>
8188
where
8289
D: WorkspaceHandler,
8390
{
8491
fn request(
8592
state: &mut D,
86-
client: &Client,
93+
_client: &Client,
8794
obj: &ExtWorkspaceManagerV1,
8895
request: ext_workspace_manager_v1::Request,
89-
_data: &(),
96+
data: &WorkspaceManagerData,
9097
dh: &DisplayHandle,
9198
_data_init: &mut DataInit<'_, D>,
9299
) {
93100
match request {
94101
ext_workspace_manager_v1::Request::Commit => {
95102
if state.workspace_state().ext_instances.contains(obj) {
96-
let mut client_state = client
97-
.get_data::<<D as WorkspaceHandler>::Client>()
98-
.unwrap()
99-
.workspace_state()
100-
.lock()
101-
.unwrap();
102-
state.commit_requests(dh, std::mem::take(&mut client_state.requests));
103+
let mut data = data.lock().unwrap();
104+
state.commit_requests(dh, std::mem::take(&mut data.requests));
103105
}
104106
}
105107
ext_workspace_manager_v1::Request::Stop => {
@@ -114,7 +116,12 @@ where
114116
}
115117
}
116118

117-
fn destroyed(state: &mut D, _client: ClientId, resource: &ExtWorkspaceManagerV1, _data: &()) {
119+
fn destroyed(
120+
state: &mut D,
121+
_client: ClientId,
122+
resource: &ExtWorkspaceManagerV1,
123+
_data: &WorkspaceManagerData,
124+
) {
118125
state
119126
.workspace_state_mut()
120127
.ext_instances
@@ -128,10 +135,10 @@ where
128135
{
129136
fn request(
130137
state: &mut D,
131-
client: &Client,
138+
_client: &Client,
132139
obj: &ExtWorkspaceGroupHandleV1,
133140
request: ext_workspace_group_handle_v1::Request,
134-
_data: &WorkspaceGroupData,
141+
data: &WorkspaceGroupData,
135142
_dh: &DisplayHandle,
136143
_data_init: &mut DataInit<'_, D>,
137144
) {
@@ -144,16 +151,17 @@ where
144151
.find(|g| g.ext_instances.contains(obj))
145152
.map(|g| g.id)
146153
{
147-
let mut state = client
148-
.get_data::<<D as WorkspaceHandler>::Client>()
149-
.unwrap()
150-
.workspace_state()
151-
.lock()
152-
.unwrap();
153-
state.requests.push(Request::Create {
154-
in_group: WorkspaceGroupHandle { id },
155-
name: workspace,
156-
});
154+
if let Ok(manager) = data.manager.upgrade() {
155+
let mut state = manager
156+
.data::<WorkspaceManagerData>()
157+
.unwrap()
158+
.lock()
159+
.unwrap();
160+
state.requests.push(Request::Create {
161+
in_group: WorkspaceGroupHandle { id },
162+
name: workspace,
163+
});
164+
}
157165
}
158166
}
159167
ext_workspace_group_handle_v1::Request::Destroy => {
@@ -183,10 +191,10 @@ where
183191
{
184192
fn request(
185193
state: &mut D,
186-
client: &Client,
194+
_client: &Client,
187195
obj: &ExtWorkspaceHandleV1,
188196
request: ext_workspace_handle_v1::Request,
189-
_data: &WorkspaceData,
197+
data: &WorkspaceData,
190198
_dh: &DisplayHandle,
191199
_data_init: &mut DataInit<'_, D>,
192200
) {
@@ -195,39 +203,42 @@ where
195203
if let Some(workspace_handle) =
196204
state.workspace_state().get_ext_workspace_handle(obj)
197205
{
198-
let mut state = client
199-
.get_data::<<D as WorkspaceHandler>::Client>()
200-
.unwrap()
201-
.workspace_state()
202-
.lock()
203-
.unwrap();
204-
state.requests.push(Request::Activate(workspace_handle));
206+
if let Ok(manager) = data.manager.upgrade() {
207+
let mut state = manager
208+
.data::<WorkspaceManagerData>()
209+
.unwrap()
210+
.lock()
211+
.unwrap();
212+
state.requests.push(Request::Activate(workspace_handle));
213+
}
205214
}
206215
}
207216
ext_workspace_handle_v1::Request::Deactivate => {
208217
if let Some(workspace_handle) =
209218
state.workspace_state().get_ext_workspace_handle(obj)
210219
{
211-
let mut state = client
212-
.get_data::<<D as WorkspaceHandler>::Client>()
213-
.unwrap()
214-
.workspace_state()
215-
.lock()
216-
.unwrap();
217-
state.requests.push(Request::Deactivate(workspace_handle));
220+
if let Ok(manager) = data.manager.upgrade() {
221+
let mut state = manager
222+
.data::<WorkspaceManagerData>()
223+
.unwrap()
224+
.lock()
225+
.unwrap();
226+
state.requests.push(Request::Deactivate(workspace_handle));
227+
}
218228
}
219229
}
220230
ext_workspace_handle_v1::Request::Remove => {
221231
if let Some(workspace_handle) =
222232
state.workspace_state().get_ext_workspace_handle(obj)
223233
{
224-
let mut state = client
225-
.get_data::<<D as WorkspaceHandler>::Client>()
226-
.unwrap()
227-
.workspace_state()
228-
.lock()
229-
.unwrap();
230-
state.requests.push(Request::Remove(workspace_handle));
234+
if let Ok(manager) = data.manager.upgrade() {
235+
let mut state = manager
236+
.data::<WorkspaceManagerData>()
237+
.unwrap()
238+
.lock()
239+
.unwrap();
240+
state.requests.push(Request::Remove(workspace_handle));
241+
}
231242
}
232243
}
233244
ext_workspace_handle_v1::Request::Assign { workspace_group } => {
@@ -241,16 +252,17 @@ where
241252
.find(|g| g.ext_instances.contains(&workspace_group))
242253
.map(|g| g.id)
243254
{
244-
let mut state = client
245-
.get_data::<<D as WorkspaceHandler>::Client>()
246-
.unwrap()
247-
.workspace_state()
248-
.lock()
249-
.unwrap();
250-
state.requests.push(Request::Assign {
251-
workspace: workspace_handle,
252-
group: WorkspaceGroupHandle { id: group_id },
253-
});
255+
if let Ok(manager) = data.manager.upgrade() {
256+
let mut state = manager
257+
.data::<WorkspaceManagerData>()
258+
.unwrap()
259+
.lock()
260+
.unwrap();
261+
state.requests.push(Request::Assign {
262+
workspace: workspace_handle,
263+
group: WorkspaceGroupHandle { id: group_id },
264+
});
265+
}
254266
}
255267
}
256268
}

0 commit comments

Comments
 (0)