aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel/native
diff options
context:
space:
mode:
authordelta <darkussdelta@gmail.com>2023-05-21 10:12:46 +0200
committerdelta <darkussdelta@gmail.com>2023-05-21 10:12:46 +0200
commitf42a3a2cc941e34dd938b1e6bc24785a44781db2 (patch)
treebec91db370c7bcd5be2bb614d2d315a32c751215 /.config/awesome/quarrel/native
parentf5612f081db0dc69f5c0ebc69e67fa3b098a9ad9 (diff)
major update of awesome config
add new icons, switch over to using stylesheets instead of gears.color.recolor_image, add a music widget to the panel, optimize services in common.lua, fix the application lense filtering and increase the update rate of services in common.lua Signed-off-by: delta <darkussdelta@gmail.com>
Diffstat (limited to '.config/awesome/quarrel/native')
-rw-r--r--.config/awesome/quarrel/native/Cargo.toml4
-rw-r--r--.config/awesome/quarrel/native/src/lenses/application.rs6
-rw-r--r--.config/awesome/quarrel/native/src/lib.rs6
-rw-r--r--.config/awesome/quarrel/native/src/net/mod.rs8
-rw-r--r--.config/awesome/quarrel/native/src/time.rs75
5 files changed, 88 insertions, 11 deletions
diff --git a/.config/awesome/quarrel/native/Cargo.toml b/.config/awesome/quarrel/native/Cargo.toml
index 6c44528..9cff8fc 100644
--- a/.config/awesome/quarrel/native/Cargo.toml
+++ b/.config/awesome/quarrel/native/Cargo.toml
@@ -9,12 +9,14 @@ edition = "2021"
freedesktop_entry_parser = "1.3.0"
cpc = "1.9.1"
mlua = { version = "0.8.7", features = [ "module", "lua54", "serialize" ] }
-palette = { version = "0.6.1", default-features = false, features = [ "std" ] }
rayon = "1.6.1"
serde = { version = "1.0.152", features = [ "derive" ] }
url = "2.3.1"
rodio = "0.17.1"
nix = "0.26.2"
+chrono = "0.4.24"
+itertools = "0.10.5"
+html-escape = "0.2.13"
[lib]
crate-type = ["cdylib"]
diff --git a/.config/awesome/quarrel/native/src/lenses/application.rs b/.config/awesome/quarrel/native/src/lenses/application.rs
index b0135d4..0857802 100644
--- a/.config/awesome/quarrel/native/src/lenses/application.rs
+++ b/.config/awesome/quarrel/native/src/lenses/application.rs
@@ -13,10 +13,6 @@ use crate::lenses::entry::{
Entry,
};
-fn contains_ignore_ascii_case(a: &str, b: &str) -> bool {
- return false;
-}
-
fn parse_entry(entry: &fd::Entry, path: &PathBuf) -> Result<Entry, ()> {
let section = entry.section("Desktop Entry");
let name = section.attr("Name").ok_or(())?.to_string();
@@ -84,7 +80,7 @@ pub fn query(lua: &Lua, input: String) -> LuaResult<LuaTable> {
Ok(entries_to_lua_table(
parsed_entries
.into_iter()
- .filter(|entry| entry.message.to_lowercase().contains(&input))
+ .filter(|entry| entry.message.to_lowercase().contains(&input.to_lowercase()))
.collect(),
lua,
))
diff --git a/.config/awesome/quarrel/native/src/lib.rs b/.config/awesome/quarrel/native/src/lib.rs
index e21e306..d89b610 100644
--- a/.config/awesome/quarrel/native/src/lib.rs
+++ b/.config/awesome/quarrel/native/src/lib.rs
@@ -2,6 +2,7 @@ mod lenses;
mod net;
use mlua::prelude::*;
+use html_escape::decode_html_entities_to_string;
#[mlua::lua_module]
fn qnative(lua: &Lua) -> LuaResult<LuaTable> {
@@ -12,6 +13,11 @@ fn qnative(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
exports.set("lenses", lenses)?;
exports.set("get_essid", lua.create_function(net::get_first_essid)?)?;
+ exports.set("decode_html", lua.create_function(|_: &Lua, string: String| {
+ let mut output = String::new();
+ decode_html_entities_to_string(string, &mut output);
+ Ok(output)
+ })?)?;
Ok(exports)
}
diff --git a/.config/awesome/quarrel/native/src/net/mod.rs b/.config/awesome/quarrel/native/src/net/mod.rs
index c9d617c..71eaeea 100644
--- a/.config/awesome/quarrel/native/src/net/mod.rs
+++ b/.config/awesome/quarrel/native/src/net/mod.rs
@@ -10,7 +10,6 @@ use std::{
},
mem::size_of,
os::fd::RawFd,
- str,
};
use mlua::prelude::*;
@@ -23,7 +22,7 @@ use nix::{
SockFlag,
SockType,
},
- unistd::close
+ unistd::close,
};
use wireless::{
IfConf,
@@ -59,6 +58,7 @@ pub fn get_first_essid(_: &Lua, _: ()) -> LuaResult<String> {
if_req = if_conf.data.ifc_req;
}
+ #[allow(clippy::cast_possible_truncation)]
for _ in 0..if_conf.ifc_len / size_of::<IfConf>() as c_int {
if let Ok(essid) = get_essid(socket, unsafe { *if_req }.ifr_name) {
close(socket).map_err(LuaError::external)?;
@@ -90,9 +90,7 @@ fn get_essid(socket: RawFd, if_name: [c_char; IF_NAMESIZE]) -> LuaResult<String>
ioctl_get_essid(socket, &mut wrq).map_err(LuaError::external)?;
}
- Ok(str::from_utf8(essid.as_slice())
- .map_err(LuaError::external)?
- .to_owned())
+ String::from_utf8(essid.to_vec()).map_err(LuaError::external)
}
fn get_first_socket() -> LuaResult<RawFd> {
diff --git a/.config/awesome/quarrel/native/src/time.rs b/.config/awesome/quarrel/native/src/time.rs
new file mode 100644
index 0000000..9850822
--- /dev/null
+++ b/.config/awesome/quarrel/native/src/time.rs
@@ -0,0 +1,75 @@
+use chrono::prelude::*;
+use mlua::{
+ prelude::*,
+ LuaSerdeExt,
+};
+
+// Taken from https://github.com/chronotope/chrono/issues/69#issuecomment-1510506428
+trait NaiveDateExt {
+ fn days_in_month(&self) -> u32;
+ fn days_in_year(&self) -> u32;
+ fn is_leap_year(&self) -> bool;
+}
+
+impl NaiveDateExt for NaiveDate {
+ fn days_in_month(&self) -> u32 {
+ let month = self.month();
+ match month {
+ 1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
+ 4 | 6 | 9 | 11 => 30,
+ 2 => {
+ if self.is_leap_year() {
+ 29
+ } else {
+ 28
+ }
+ }
+ _ => panic!("Invalid month: {}", month),
+ }
+ }
+
+ fn days_in_year(&self) -> u32 {
+ if self.is_leap_year() {
+ 366
+ } else {
+ 365
+ }
+ }
+
+ fn is_leap_year(&self) -> bool {
+ let year = self.year();
+ return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
+ }
+}
+
+struct Day {
+ day: u32,
+ ce: bool,
+ weekday: Weekday,
+}
+
+pub fn get_calendar_table(lua: &Lua, (year, month, day): (i32, u32, u32)) -> LuaResult<LuaTable> {
+ let date =
+ NaiveDate::from_ymd_opt(year, month, day).ok_or(LuaError::external("invalid date"))?;
+ let days: Vec<Day> = (1..=date.days_in_month())
+ .map(|day| NaiveDate::from_ymd_opt(date.year(), date.month(), day).unwrap())
+ .map(|date| {
+ let (ce, year) = date.year_ce();
+ Day {
+ day: date.day(),
+ ce,
+ weekday: date.weekday(),
+ }
+ })
+ .collect();
+
+ let calendar: Vec<Vec<Day>> = vec![vec![], vec![], vec![], vec![], vec![], vec![], vec![]];
+
+ if days[1].weekday != Weekday::Mon {
+ get_calendar_table(lua)
+ }
+
+ if days.last().unwrap().weekday != Weekday::Sun {}
+
+ Ok(lua.create_table()?)
+}