mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 22:51:21 +02:00
correct spacing on komorebi and network widgets (WIP)
This commit is contained in:
@@ -147,7 +147,7 @@ impl BarWidget for Battery {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, true, ui, |ui| {
|
||||
ui.add(
|
||||
Label::new(layout_job)
|
||||
.selectable(false)
|
||||
|
||||
@@ -99,7 +99,7 @@ impl BarWidget for Cpu {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, true, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -119,7 +119,7 @@ impl BarWidget for Date {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, true, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(WidgetText::LayoutJob(layout_job.clone()))
|
||||
|
||||
@@ -124,12 +124,30 @@ pub struct Komorebi {
|
||||
impl BarWidget for Komorebi {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
let mut komorebi_notification_state = self.komorebi_notification_state.borrow_mut();
|
||||
let mut enable_widget: [bool; 4] = [self.workspaces.enable, false, false, false];
|
||||
|
||||
if self.workspaces.enable {
|
||||
if let Some(layout) = self.layout {
|
||||
enable_widget[1] = layout.enable;
|
||||
}
|
||||
|
||||
if let Some(configuration_switcher) = &self.configuration_switcher {
|
||||
enable_widget[2] = configuration_switcher.enable;
|
||||
}
|
||||
|
||||
if let Some(focused_window) = self.focused_window {
|
||||
if focused_window.enable {
|
||||
let titles = &komorebi_notification_state.focused_container_information.0;
|
||||
enable_widget[3] = !titles.is_empty();
|
||||
}
|
||||
}
|
||||
|
||||
let last_enabled_widget_index = enable_widget.iter().rposition(|&x| x);
|
||||
|
||||
if enable_widget[0] {
|
||||
let mut update = None;
|
||||
|
||||
// NOTE: There should always be at least one workspace.
|
||||
config.apply_on_widget(false, ui, |ui| {
|
||||
config.apply_on_widget(false, last_enabled_widget_index == Some(0), ui, |ui| {
|
||||
for (i, (ws, should_show)) in
|
||||
komorebi_notification_state.workspaces.iter().enumerate()
|
||||
{
|
||||
@@ -194,9 +212,8 @@ impl BarWidget for Komorebi {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(layout) = self.layout {
|
||||
if layout.enable {
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
if enable_widget[1] {
|
||||
config.apply_on_widget(true, last_enabled_widget_index == Some(1), ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(komorebi_notification_state.layout.to_string())
|
||||
@@ -212,27 +229,18 @@ impl BarWidget for Komorebi {
|
||||
))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
"could not send message to komorebi: CycleLayout"
|
||||
);
|
||||
tracing::error!("could not send message to komorebi: CycleLayout");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Floating => {
|
||||
if komorebi_client::send_message(&SocketMessage::ToggleTiling)
|
||||
.is_err()
|
||||
if komorebi_client::send_message(&SocketMessage::ToggleTiling).is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
"could not send message to komorebi: ToggleTiling"
|
||||
);
|
||||
tracing::error!("could not send message to komorebi: ToggleTiling");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Paused => {
|
||||
if komorebi_client::send_message(&SocketMessage::TogglePause)
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
"could not send message to komorebi: TogglePause"
|
||||
);
|
||||
if komorebi_client::send_message(&SocketMessage::TogglePause).is_err() {
|
||||
tracing::error!("could not send message to komorebi: TogglePause");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Custom => {}
|
||||
@@ -240,14 +248,13 @@ impl BarWidget for Komorebi {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(configuration_switcher) = &self.configuration_switcher {
|
||||
if configuration_switcher.enable {
|
||||
if enable_widget[2] {
|
||||
let configuration_switcher = self.configuration_switcher.as_ref().unwrap();
|
||||
for (name, location) in configuration_switcher.configurations.iter() {
|
||||
let path = PathBuf::from(location);
|
||||
if path.is_file() {
|
||||
config.apply_on_widget(true, ui,|ui|{
|
||||
config.apply_on_widget(true, last_enabled_widget_index == Some(2), ui,|ui|{
|
||||
if ui
|
||||
.add(Label::new(name).selectable(false).sense(Sense::click()))
|
||||
.clicked()
|
||||
@@ -298,14 +305,11 @@ impl BarWidget for Komorebi {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(focused_window) = self.focused_window {
|
||||
if focused_window.enable {
|
||||
if enable_widget[3] {
|
||||
let focused_window = self.focused_window.unwrap();
|
||||
let titles = &komorebi_notification_state.focused_container_information.0;
|
||||
|
||||
if !titles.is_empty() {
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, last_enabled_widget_index == Some(4), ui, |ui| {
|
||||
let icons = &komorebi_notification_state.focused_container_information.1;
|
||||
let focused_window_idx =
|
||||
komorebi_notification_state.focused_container_information.2;
|
||||
@@ -378,9 +382,9 @@ impl BarWidget for Komorebi {
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if komorebi_client::send_message(
|
||||
&SocketMessage::MouseFollowsFocus(false),
|
||||
)
|
||||
if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(
|
||||
false,
|
||||
))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
@@ -388,9 +392,7 @@ impl BarWidget for Komorebi {
|
||||
);
|
||||
}
|
||||
|
||||
if komorebi_client::send_message(
|
||||
&SocketMessage::FocusStackWindow(i),
|
||||
)
|
||||
if komorebi_client::send_message(&SocketMessage::FocusStackWindow(i))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
@@ -398,11 +400,9 @@ impl BarWidget for Komorebi {
|
||||
);
|
||||
}
|
||||
|
||||
if komorebi_client::send_message(
|
||||
&SocketMessage::MouseFollowsFocus(
|
||||
if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(
|
||||
komorebi_notification_state.mouse_follows_focus,
|
||||
),
|
||||
)
|
||||
))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!(
|
||||
@@ -416,8 +416,6 @@ impl BarWidget for Komorebi {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn img_to_texture(ctx: &Context, rgba_image: &RgbaImage) -> TextureHandle {
|
||||
let size = [rgba_image.width() as usize, rgba_image.height() as usize];
|
||||
|
||||
@@ -102,7 +102,7 @@ impl BarWidget for Media {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, true, ui, |ui| {
|
||||
let available_height = ui.available_height();
|
||||
let mut custom_ui = CustomUi(ui);
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ impl BarWidget for Memory {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, true, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -318,26 +318,39 @@ impl Network {
|
||||
|
||||
impl BarWidget for Network {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.show_total_data_transmitted {
|
||||
for output in self.total_data_transmitted() {
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if self.show_network_activity {
|
||||
for output in self.network_activity() {
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
}
|
||||
let mut enable_widget: [bool; 3] = [
|
||||
self.show_total_data_transmitted,
|
||||
self.show_network_activity,
|
||||
false,
|
||||
];
|
||||
|
||||
if self.enable {
|
||||
self.default_interface();
|
||||
|
||||
if !self.default_interface.is_empty() {
|
||||
enable_widget[2] = true;
|
||||
}
|
||||
}
|
||||
|
||||
let last_enabled_widget_index = enable_widget.iter().rposition(|&x| x);
|
||||
|
||||
if enable_widget[0] {
|
||||
for output in self.total_data_transmitted() {
|
||||
config.apply_on_widget(true, last_enabled_widget_index == Some(0), ui, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if enable_widget[1] {
|
||||
for output in self.network_activity() {
|
||||
config.apply_on_widget(true, last_enabled_widget_index == Some(1), ui, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if enable_widget[2] {
|
||||
let font_id = ctx
|
||||
.style()
|
||||
.text_styles
|
||||
@@ -367,7 +380,7 @@ impl BarWidget for Network {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, last_enabled_widget_index == Some(2), ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
@@ -384,7 +397,6 @@ impl BarWidget for Network {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPrimitive)]
|
||||
enum DataUnit {
|
||||
|
||||
@@ -86,19 +86,20 @@ impl RenderConfig {
|
||||
|
||||
pub fn apply_on_widget<R>(
|
||||
&mut self,
|
||||
use_spacing: bool,
|
||||
// TODO: this should remove the margin on the last widget on the left side and the first widget on the right side
|
||||
// This is complex, since the last/first widget can have multiple "sections", like komorebi, network, ...
|
||||
// This and the same setting on RenderConfig needs to be combined.
|
||||
//no_spacing: Option<bool>,
|
||||
more_inner_margin: bool,
|
||||
is_last_widget: bool,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
// since a widget can call this multiple times, it is necessary to know the last time
|
||||
// in order to add widget spacing correctly
|
||||
self.no_spacing = self.no_spacing && is_last_widget;
|
||||
|
||||
if let Grouping::Widget(config) = self.grouping {
|
||||
return self.define_group(use_spacing, config, ui, add_contents);
|
||||
return self.define_group(more_inner_margin, config, ui, add_contents);
|
||||
}
|
||||
|
||||
self.fallback_widget_group(use_spacing, ui, add_contents)
|
||||
self.fallback_widget_group(more_inner_margin, ui, add_contents)
|
||||
}
|
||||
|
||||
fn fallback_group<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
|
||||
@@ -110,13 +111,13 @@ impl RenderConfig {
|
||||
|
||||
fn fallback_widget_group<R>(
|
||||
&mut self,
|
||||
use_spacing: bool,
|
||||
more_inner_margin: bool,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
Frame::none()
|
||||
.outer_margin(self.widget_outer_margin())
|
||||
.inner_margin(match use_spacing {
|
||||
.inner_margin(match more_inner_margin {
|
||||
true => Margin::symmetric(5.0, 0.0),
|
||||
false => Margin::same(0.0),
|
||||
})
|
||||
@@ -125,14 +126,14 @@ impl RenderConfig {
|
||||
|
||||
fn define_group<R>(
|
||||
&mut self,
|
||||
use_spacing: bool,
|
||||
more_inner_margin: bool,
|
||||
config: GroupingConfig,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
Frame::none()
|
||||
.outer_margin(self.widget_outer_margin())
|
||||
.inner_margin(match use_spacing {
|
||||
.inner_margin(match more_inner_margin {
|
||||
true => Margin::symmetric(8.0, 3.0),
|
||||
false => Margin::symmetric(3.0, 3.0),
|
||||
})
|
||||
|
||||
@@ -107,7 +107,8 @@ impl BarWidget for Storage {
|
||||
TextFormat::simple(font_id.clone(), ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
// TODO: WIP
|
||||
config.apply_on_widget(true, false, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -110,7 +110,7 @@ impl BarWidget for Time {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.apply_on_widget(true, ui, |ui| {
|
||||
config.apply_on_widget(true, true, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
Reference in New Issue
Block a user