Skip to content

Commit

Permalink
Merge pull request #15 from MalpenZibo/14_bottom-status-bar-position
Browse files Browse the repository at this point in the history
Add Bottom status bar position
  • Loading branch information
MalpenZibo authored Sep 10, 2024
2 parents 3c2d6e5 + 46b4a94 commit 75edeef
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ paru/yay -S ashell-git # to get the latest source version
The configuration uses the yaml file format and is named `~/.config/ashell.yml`

``` yaml
# Ashell log level filter, possible values "DEBUG" | "INFO" | "WARNING" | "ERROR"
# Ashell log level filter, possible values "DEBUG" | "INFO" | "WARNING" | "ERROR". Needs reload
logLevel: "INFO" # optional, default "INFO"
# Ashell bar position, possible values Top | Bottom. Needs reload
position: Top # optional, default Top
# App lancher commanda, it will be used to open the launcher,
# without a value the related button will not appear
appLauncherCmd: "~/.config/rofi/launcher.sh" # optional, default None
Expand Down
12 changes: 9 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use crate::{
// centerbox,
centerbox, config::{self, Config}, get_log_spec, menu::{menu_wrapper, Menu, MenuType}, modules::{
centerbox,
config::{self, Config},
get_log_spec,
menu::{menu_wrapper, Menu, MenuType},
modules::{
clock::Clock, launcher, privacy::Privacy, settings::Settings, system_info::SystemInfo,
title::Title, updates::Updates, workspaces::Workspaces,
}, style::ashell_theme, HEIGHT
},
style::ashell_theme,
HEIGHT,
};
use flexi_logger::LoggerHandle;
use iced::{
Expand Down Expand Up @@ -153,6 +158,7 @@ impl Application for App {
MenuType::Privacy => crate::menu::MenuPosition::Right,
MenuType::Settings => crate::menu::MenuPosition::Right,
},
self.config.position
)
} else {
row!().into()
Expand Down
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,20 @@ impl Default for Appearance {
}
}

#[derive(Deserialize, Clone, Copy, Debug, Default)]
pub enum Position {
#[default]
Top,
Bottom,
}

#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Config {
#[serde(default = "default_log_level")]
pub log_level: log::LevelFilter,
#[serde(default)]
pub position: Position,
pub app_launcher_cmd: Option<String>,
#[serde(default = "default_truncate_title_after_length")]
pub truncate_title_after_length: u32,
Expand Down Expand Up @@ -295,6 +304,7 @@ impl Default for Config {
fn default() -> Self {
Self {
log_level: default_log_level(),
position: Position::Top,
app_launcher_cmd: None,
truncate_title_after_length: default_truncate_title_after_length(),
updates: None,
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use app::App;
use config::read_config;
use config::{read_config, Position};
use flexi_logger::{
Age, Cleanup, Criterion, FileSpec, LogSpecBuilder, LogSpecification, Logger, Naming,
};
Expand Down Expand Up @@ -73,7 +73,12 @@ async fn main() {
namespace: "ashell".into(),
layer: Layer::Top,
size: Some((None, Some(HEIGHT))),
anchor: Anchor::TOP.union(Anchor::LEFT).union(Anchor::RIGHT),
anchor: match config.position {
Position::Top => Anchor::TOP,
Position::Bottom => Anchor::BOTTOM,
}
.union(Anchor::LEFT)
.union(Anchor::RIGHT),
exclusive_zone: HEIGHT as i32,
..Default::default()
}),
Expand Down
7 changes: 7 additions & 0 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use iced_sctk::commands::layer_surface::{
};
use iced::{self, widget::container, Command, Element, Theme};

use crate::config::Position;

fn open_menu<Message: 'static>() -> (Id, Command<Message>) {
let id = Id::unique();

Expand Down Expand Up @@ -164,6 +166,7 @@ pub enum MenuPosition {
pub fn menu_wrapper(
content: Element<crate::app::Message>,
position: MenuPosition,
bar_position: Position
) -> Element<crate::app::Message> {
iced::widget::mouse_area(
container(
Expand All @@ -183,6 +186,10 @@ pub fn menu_wrapper(
)
.on_release(crate::app::Message::None),
)
.align_y(match bar_position {
Position::Top => iced::alignment::Vertical::Top,
Position::Bottom => iced::alignment::Vertical::Bottom,
})
.align_x(match position {
MenuPosition::Left => iced::alignment::Horizontal::Left,
MenuPosition::Right => iced::alignment::Horizontal::Right,
Expand Down

0 comments on commit 75edeef

Please sign in to comment.