Skip to content

Commit

Permalink
New Widget: box
Browse files Browse the repository at this point in the history
  • Loading branch information
vars1ty committed Oct 21, 2022
1 parent f380955 commit bc1825b
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hybrid-bar"
authors = [ "varsity <[email protected]>" ]
version = "0.2.3"
version = "0.2.4"
edition = "2021"
description = "A simple status bar made for wlroots compositors."
license = "MIT"
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ It supports:
- Spacings;
- Transparency (+ blur if your compositor supports it);
- Custom CSS;
- Custom update-frequency for dynamic widgets (ones with a `command` set)
- Custom update-frequency for dynamic labels (ones with a `command` set) and CSS reloads;
- `...` and more

In other words, it's a simple Wayland status bar that does one thing: Display the stuff __you__ put onto it. Nothing more, nothing less, no over-engineered dogshit.
## I have no config
If the AUR version for whatever reason didn't give you the example one, copy the example one from `examples/config.json` into `~/.config/HybridBar/`.
If the AUR version for whatever reason didn't give you the example one, copy the example from `examples/config.json` into `~/.config/HybridBar/`.
# Config Layout
I'm assuming you are familiar with JSON. If you aren't, well too bad.
## Base
Expand All @@ -37,15 +38,11 @@ Here's an example:
}
```
## Video Tutorial
You can watch a video tutorial made by Foren [here](https://www.youtube.com/watch?v=5g7MX3jgv8A)
You can watch a video tutorial made by Foren [here](https://www.youtube.com/watch?v=5g7MX3jgv8A) - **Outdated but may help some**.
## CSS Support
Starting from `0.1.3`, CSS is now supported and you can make it auto-load on startup by making a `style.css` file next to your `config.json` at the same path.

If you want a sample CSS which has been used up until now, check `examples/style.css`.

Since `0.1.4`, you can now also style separate labels and buttons.

For example: `left-label_username_stuff` can be styled using CSS via `#username_stuff { /* Code */ }`.
## Environment Variables
`HYBRID_LOG` = `0` OR `1` : Logs debug output to stdout.

Expand Down Expand Up @@ -84,4 +81,4 @@ Tip: `chmod +x hybrid-bar` - So you can run the executable directly.
- Port over to GTK4 - Not possible right now due to GTK being 0IQ and [screwing shit up](https://github.com/wmww/gtk-layer-shell/issues/37)
- Refactor parts of the code to make it more readable and easier to maintain - **In progress**
- Publish a non-git AUR package which uses the latest built binary
- Potentially more widgets
- Potentially more widgets - **In progress, feel free to suggest widgets**
22 changes: 10 additions & 12 deletions WIDGETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@
>
> This can be performance intensive, so it's recommended that you set the update-rate to something like `100`.
***
**NOTE**: In order to use a widget, you'll have to specify how it should be aligned. For example: `left-button`, `centered-button` and `right-button`.

Available widgets:

Labels:
- left-label: Left-aligned label
- centered-label: Centered label
- right-label: Right-aligned label
`label`:

Keys Supported:
- text: String
- command: String
***
Buttons:
- left-button: Left-aligned button
- centered-button: Centered button
- right-button: Right-aligned button
`button`:

Keys Supported:
- text: String
- command: String
***
Spacing:
- left-spacing: Left-focused spacing
- centered-spacing: Centered-focused spacing
- right-spacing: Right-focused spacing
`spacing`:

Keys Supported:
- spacing_start: i32
- spacing_end: i32
***
`box`:

Keys Supported:
- width: i32
***
To actually use a widget, here's an example:

```json
Expand Down
4 changes: 2 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt::*;

use crate::environment;
use std::fmt::*;

/// Logs a message to the terminal if the environment variable `HYBRID_LOG` is set to `1`.
/// This accepts any type, as long as it implements one of `Display`, `Clone` or `Debug`.
pub fn log(msg: impl Display + Clone + Debug) {
if environment::try_get_var("HYBRID_LOG", "0") == "1" {
println!("[HYBRID] [DEBUG] {msg}");
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[macro_use]
extern crate lazy_static;

#[path = "widgets/box_widget.rs"]
mod box_widget;
#[path = "widgets/button_widget.rs"]
mod button_widget;
mod config;
Expand Down
25 changes: 24 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
button_widget::ButtonWidget, debug::log, r#loop::update, spacing_widget::SpacingWidget, *,
box_widget::BoxWidget, button_widget::ButtonWidget, debug::log, r#loop::update,
spacing_widget::SpacingWidget, structures::Align, *,
};
use gtk::traits::*;
use std::{str::FromStr, sync::Mutex};
Expand All @@ -12,6 +13,21 @@ lazy_static! {
};
}

/// Adds and aligns the specified widget.
pub fn add_and_align(
widget: &impl IsA<Widget>,
align: Align,
left: &Box,
centered: &Box,
right: &Box,
) {
match align {
Align::LEFT => left.add(widget),
Align::CENTERED => centered.add(widget),
Align::RIGHT => right.add(widget),
}
}

/// Builds all of the widgets.
pub fn build_widgets(window: &gtk::ApplicationWindow) {
// Create box widgets, which we'll be using to draw the content onto.
Expand Down Expand Up @@ -95,6 +111,13 @@ fn create_components(left: &Box, centered: &Box, right: &Box) {
};

spacing.add(alignment, left, centered, right)
} else if identifier.contains("box") {
let box_widget = BoxWidget {
name: widget_name,
width: config::try_get(key, "width", false).1,
};

box_widget.add(alignment, left, centered, right)
} else {
// You are stupid.
panic!("[ERROR] There are no widgets identified as '{identifier}'!\n")
Expand Down
20 changes: 20 additions & 0 deletions src/widgets/box_widget.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::{debug::log, structures::Align, ui, widget::HWidget};
use gtk::{traits::*, *};

/// Creates a new basic box widget.
pub struct BoxWidget {
pub name: String,
pub width: i32,
}

// Implements HWidget for the widget so that we can actually use it.
impl HWidget for BoxWidget {
fn add(self, align: Align, left: &Box, centered: &Box, right: &Box) {
let widget = Box::new(Orientation::Horizontal, 0);
widget.set_widget_name(&self.name);
widget.set_width_request(self.width);

ui::add_and_align(&widget, align, left, centered, right);
log("Added a new box widget");
}
}
10 changes: 2 additions & 8 deletions src/widgets/button_widget.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{debug::log, structures::Align, widget::HWidget};
use crate::{debug::log, structures::Align, ui, widget::HWidget};
use gtk::{traits::*, *};

/// Creates a new button widget.
Expand All @@ -21,13 +21,7 @@ impl HWidget for ButtonWidget {
});
}

// Align and add the widget
match align {
Align::LEFT => left.add(&self.button),
Align::CENTERED => centered.add(&self.button),
Align::RIGHT => right.add(&self.button),
}

ui::add_and_align(&self.button, align, left, centered, right);
log(format!("Added a new button widget named '{}'", self.name));
}
}
15 changes: 7 additions & 8 deletions src/widgets/label_widget.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use crate::{debug::log, structures::Align, ui::VEC, widget::HWidget};
use crate::{
debug::log,
structures::Align,
ui::{self, VEC},
widget::HWidget,
};
use gtk::{traits::*, *};

/// Creates a new label widget.
Expand All @@ -18,13 +23,7 @@ impl HWidget for LabelWidget {
fn add(self, align: Align, left: &Box, centered: &Box, right: &Box) {
self.label.set_widget_name(&self.name);

// Align and add the widget
match align {
Align::LEFT => left.add(&self.label),
Align::CENTERED => centered.add(&self.label),
Align::RIGHT => right.add(&self.label),
}

ui::add_and_align(&self.label, align, left, centered, right);
log(format!("Added a new label widget named '{}'", self.name));
VEC.lock()
.expect("[ERROR] Cannot access ui::VEC!\n")
Expand Down
10 changes: 2 additions & 8 deletions src/widgets/spacing_widget.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{debug::log, structures::Align, widget::HWidget};
use crate::{debug::log, structures::Align, ui, widget::HWidget};
use gtk::{traits::*, *};

/// Creates a new basic spacing widget.
Expand All @@ -17,13 +17,7 @@ impl HWidget for SpacingWidget {
widget.set_margin_start(self.spacing_start);
widget.set_margin_end(self.spacing_end);

// Align and add the widget
match align {
Align::LEFT => left.add(&widget),
Align::CENTERED => centered.add(&widget),
Align::RIGHT => right.add(&widget),
}

ui::add_and_align(&widget, align, left, centered, right);
log("Added a new spacing widget");
}
}

0 comments on commit bc1825b

Please sign in to comment.