Skip to content

Commit

Permalink
Merge pull request #85 from MalpenZibo/82-show-on-all-monitor-config
Browse files Browse the repository at this point in the history
82 Show on all monitor config
  • Loading branch information
MalpenZibo authored Jan 19, 2025
2 parents 8fd006a + a22b4c5 commit 79c86f7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ The configuration uses the yaml file format and is named `~/.config/ashell.yml`
```yaml
# Ashell log level filter, possible values "DEBUG" | "INFO" | "WARNING" | "ERROR". Needs reload
logLevel: "INFO" # optional, default "INFO"
# List of outputs, example values: DP-1 | HDMI-1 | eDP-1.
# the status bar will be displayed on all the outputs listed here
# Possible status bar outputs, values could be: All, Active, or Targets
# All: the status bar will be displayed on all the available outputs, example: outputs: All
# Active: the status bar will be displayed on the active output, example: outputs: Active
# Targets: the status bar will be displayed on the outputs listed here,
# example:
# outputs: !Targets
# - DP-1
# - eDP-1
# if the outputs is not available the bar will be displayed in the active output
outputs: # optional, default empty list (the bar will be displayed on the active output)
- eDP-1
- DP-1
outputs: All # optional, default all
# Bar position, possible values Top | Bottom.
position: Top # optional, default Top
# Declare which modules should be used and in which position in the status bar.
Expand Down
28 changes: 25 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iced::{
Color, Subscription,
};
use inotify::{EventMask, Inotify, WatchMask};
use serde::Deserialize;
use serde::{de::Error, Deserialize, Deserializer};
use std::{any::TypeId, env, fs::File, path::Path, time::Duration};
use tokio::time::sleep;

Expand Down Expand Up @@ -302,6 +302,28 @@ impl Default for Modules {
}
}

#[derive(Deserialize, Clone, Default, Debug, PartialEq, Eq)]
pub enum Outputs {
#[default]
All,
Active,
#[serde(deserialize_with = "non_empty")]
Targets(Vec<String>),
}

fn non_empty<'de, D, T>(d: D) -> Result<Vec<T>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de>,
{
let vec = <Vec<T>>::deserialize(d)?;
if vec.is_empty() {
Err(D::Error::custom("need non-empty"))
} else {
Ok(vec)
}
}

#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Config {
Expand All @@ -310,7 +332,7 @@ pub struct Config {
#[serde(default)]
pub position: Position,
#[serde(default)]
pub outputs: Vec<String>,
pub outputs: Outputs,
#[serde(default)]
pub modules: Modules,
pub app_launcher_cmd: Option<String>,
Expand Down Expand Up @@ -342,7 +364,7 @@ impl Default for Config {
Self {
log_level: default_log_level(),
position: Position::Top,
outputs: vec![],
outputs: Outputs::default(),
modules: Modules::default(),
app_launcher_cmd: None,
clipboard_cmd: None,
Expand Down
26 changes: 16 additions & 10 deletions src/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use log::debug;
use wayland_client::protocol::wl_output::WlOutput;

use crate::{
config::Position,
config::{self, Position},
menu::{Menu, MenuType},
position_button::ButtonUIRef,
HEIGHT,
Expand Down Expand Up @@ -91,6 +91,16 @@ impl Outputs {
(id, menu_id, Task::batch(vec![task, menu_task]))
}

fn name_in_config(name: &str, outputs: &config::Outputs) -> bool {
match outputs {
config::Outputs::All => true,
config::Outputs::Active => false,
config::Outputs::Targets(request_outputs) => {
request_outputs.iter().any(|output| output.as_str() == name)
}
}
}

pub fn has(&self, id: Id) -> Option<HasOutput> {
self.0.iter().find_map(|(_, info, _)| {
if let Some(info) = info {
Expand All @@ -109,12 +119,12 @@ impl Outputs {

pub fn add<Message: 'static>(
&mut self,
request_outputs: &[String],
request_outputs: &config::Outputs,
position: Position,
name: &str,
wl_output: WlOutput,
) -> Task<Message> {
let target = request_outputs.iter().any(|output| output.as_str() == name);
let target = Self::name_in_config(name, request_outputs);

if target {
debug!("Found target output, creating a new layer surface");
Expand Down Expand Up @@ -224,7 +234,7 @@ impl Outputs {

pub fn sync<Message: 'static>(
&mut self,
request_outputs: &[String],
request_outputs: &config::Outputs,
position: Position,
) -> Task<Message> {
debug!(
Expand All @@ -236,9 +246,7 @@ impl Outputs {
.0
.iter()
.filter_map(|(name, shell_info, wl_output)| {
if !request_outputs.iter().any(|output| output.as_str() == name)
&& shell_info.is_some()
{
if !Self::name_in_config(name, request_outputs) && shell_info.is_some() {
Some(wl_output.clone())
} else {
None
Expand All @@ -252,9 +260,7 @@ impl Outputs {
.0
.iter()
.filter_map(|(name, shell_info, wl_output)| {
if request_outputs.iter().any(|output| output.as_str() == name)
&& shell_info.is_none()
{
if Self::name_in_config(name, request_outputs) && shell_info.is_none() {
Some((name.clone(), wl_output.clone()))
} else {
None
Expand Down

0 comments on commit 79c86f7

Please sign in to comment.