mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-26 21:58:10 +01:00
Change TagId
back to struct
This commit is contained in:
parent
9f187aba65
commit
13ea0a683b
4 changed files with 17 additions and 42 deletions
29
src/api.rs
29
src/api.rs
|
@ -674,7 +674,7 @@ impl tag_service_server::TagService for TagService {
|
|||
async fn set_active(&self, request: Request<SetActiveRequest>) -> Result<Response<()>, Status> {
|
||||
let request = request.into_inner();
|
||||
|
||||
let tag_id = TagId::Some(
|
||||
let tag_id = TagId(
|
||||
request
|
||||
.tag_id
|
||||
.ok_or_else(|| Status::invalid_argument("no tag specified"))?,
|
||||
|
@ -712,7 +712,7 @@ impl tag_service_server::TagService for TagService {
|
|||
async fn switch_to(&self, request: Request<SwitchToRequest>) -> Result<Response<()>, Status> {
|
||||
let request = request.into_inner();
|
||||
|
||||
let tag_id = TagId::Some(
|
||||
let tag_id = TagId(
|
||||
request
|
||||
.tag_id
|
||||
.ok_or_else(|| Status::invalid_argument("no tag specified"))?,
|
||||
|
@ -755,10 +755,7 @@ impl tag_service_server::TagService for TagService {
|
|||
let tag_ids = new_tags
|
||||
.iter()
|
||||
.map(|tag| tag.id())
|
||||
.map(|id| match id {
|
||||
TagId::None => unreachable!(),
|
||||
TagId::Some(id) => id,
|
||||
})
|
||||
.map(|id| id.0)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if let Some(saved_state) = state.config.connector_saved_states.get_mut(&output_name) {
|
||||
|
@ -807,7 +804,7 @@ impl tag_service_server::TagService for TagService {
|
|||
async fn remove(&self, request: Request<RemoveRequest>) -> Result<Response<()>, Status> {
|
||||
let request = request.into_inner();
|
||||
|
||||
let tag_ids = request.tag_ids.into_iter().map(TagId::Some);
|
||||
let tag_ids = request.tag_ids.into_iter().map(TagId);
|
||||
|
||||
run_unary_no_response(&self.sender, move |state| {
|
||||
let tags_to_remove = tag_ids.flat_map(|id| id.tag(state)).collect::<Vec<_>>();
|
||||
|
@ -836,7 +833,7 @@ impl tag_service_server::TagService for TagService {
|
|||
async fn set_layout(&self, request: Request<SetLayoutRequest>) -> Result<Response<()>, Status> {
|
||||
let request = request.into_inner();
|
||||
|
||||
let tag_id = TagId::Some(
|
||||
let tag_id = TagId(
|
||||
request
|
||||
.tag_id
|
||||
.ok_or_else(|| Status::invalid_argument("no tag specified"))?,
|
||||
|
@ -879,10 +876,7 @@ impl tag_service_server::TagService for TagService {
|
|||
.outputs()
|
||||
.flat_map(|op| op.with_state(|state| state.tags.clone()))
|
||||
.map(|tag| tag.id())
|
||||
.map(|id| match id {
|
||||
TagId::None => unreachable!(),
|
||||
TagId::Some(id) => id,
|
||||
})
|
||||
.map(|id| id.0)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
tag::v0alpha1::GetResponse { tag_ids }
|
||||
|
@ -896,7 +890,7 @@ impl tag_service_server::TagService for TagService {
|
|||
) -> Result<Response<tag::v0alpha1::GetPropertiesResponse>, Status> {
|
||||
let request = request.into_inner();
|
||||
|
||||
let tag_id = TagId::Some(
|
||||
let tag_id = TagId(
|
||||
request
|
||||
.tag_id
|
||||
.ok_or_else(|| Status::invalid_argument("no tag specified"))?,
|
||||
|
@ -1056,14 +1050,7 @@ impl output_service_server::OutputService for OutputService {
|
|||
.as_ref()
|
||||
.map(|output| {
|
||||
output.with_state(|state| {
|
||||
state
|
||||
.tags
|
||||
.iter()
|
||||
.map(|tag| match tag.id() {
|
||||
TagId::None => unreachable!(),
|
||||
TagId::Some(id) => id,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
state.tags.iter().map(|tag| tag.id().0).collect::<Vec<_>>()
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
|
|
@ -367,7 +367,7 @@ impl window_service_server::WindowService for WindowService {
|
|||
.ok_or_else(|| Status::invalid_argument("no window specified"))?,
|
||||
);
|
||||
|
||||
let tag_id = TagId::Some(
|
||||
let tag_id = TagId(
|
||||
request
|
||||
.tag_id
|
||||
.ok_or_else(|| Status::invalid_argument("no tag specified"))?,
|
||||
|
@ -395,7 +395,7 @@ impl window_service_server::WindowService for WindowService {
|
|||
.ok_or_else(|| Status::invalid_argument("no window specified"))?,
|
||||
);
|
||||
|
||||
let tag_id = TagId::Some(
|
||||
let tag_id = TagId(
|
||||
request
|
||||
.tag_id
|
||||
.ok_or_else(|| Status::invalid_argument("no tag specified"))?,
|
||||
|
@ -640,14 +640,7 @@ impl window_service_server::WindowService for WindowService {
|
|||
.as_ref()
|
||||
.map(|win| {
|
||||
win.with_state(|state| {
|
||||
state
|
||||
.tags
|
||||
.iter()
|
||||
.map(|tag| match tag.id() {
|
||||
TagId::Some(id) => id,
|
||||
TagId::None => unreachable!(),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
state.tags.iter().map(|tag| tag.id().0).collect::<Vec<_>>()
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
@ -722,7 +715,7 @@ impl From<WindowRuleCondition> for crate::window::rules::WindowRuleCondition {
|
|||
|
||||
let tag = match cond.tags.is_empty() {
|
||||
true => None,
|
||||
false => Some(cond.tags.into_iter().map(TagId::Some).collect::<Vec<_>>()),
|
||||
false => Some(cond.tags.into_iter().map(TagId).collect::<Vec<_>>()),
|
||||
};
|
||||
|
||||
crate::window::rules::WindowRuleCondition {
|
||||
|
@ -752,7 +745,7 @@ impl From<WindowRule> for crate::window::rules::WindowRule {
|
|||
let output = rule.output.map(OutputName);
|
||||
let tags = match rule.tags.is_empty() {
|
||||
true => None,
|
||||
false => Some(rule.tags.into_iter().map(TagId::Some).collect::<Vec<_>>()),
|
||||
false => Some(rule.tags.into_iter().map(TagId).collect::<Vec<_>>()),
|
||||
};
|
||||
let floating_or_tiled = rule.floating.map(|floating| match floating {
|
||||
true => crate::window::rules::FloatingOrTiled::Floating,
|
||||
|
|
|
@ -18,17 +18,12 @@ static TAG_ID_COUNTER: AtomicU32 = AtomicU32::new(0);
|
|||
|
||||
/// A unique id for a [`Tag`].
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize)]
|
||||
pub enum TagId {
|
||||
/// The tag given was invalid/nonexistent
|
||||
None,
|
||||
#[serde(untagged)]
|
||||
Some(u32),
|
||||
}
|
||||
pub struct TagId(pub u32);
|
||||
|
||||
impl TagId {
|
||||
/// Get the next available `TagId`.
|
||||
fn next() -> Self {
|
||||
Self::Some(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed))
|
||||
Self(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// Get the tag associated with this id.
|
||||
|
|
|
@ -237,7 +237,7 @@ mod coverage {
|
|||
..Default::default()
|
||||
},
|
||||
WindowRule {
|
||||
tags: Some(vec![TagId::Some(0)]),
|
||||
tags: Some(vec![TagId(0)]),
|
||||
..Default::default()
|
||||
}
|
||||
)
|
||||
|
@ -272,7 +272,7 @@ mod coverage {
|
|||
WindowRuleCondition {
|
||||
cond_all: Some(vec![WindowRuleCondition {
|
||||
class: Some(vec!["steam".to_string()]),
|
||||
tag: Some(vec![TagId::Some(0), TagId::Some(1)]),
|
||||
tag: Some(vec![TagId(0), TagId(1)]),
|
||||
..Default::default()
|
||||
}]),
|
||||
..Default::default()
|
||||
|
|
Loading…
Reference in a new issue