aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel
diff options
context:
space:
mode:
Diffstat (limited to '.config/awesome/quarrel')
-rw-r--r--.config/awesome/quarrel/native/Cargo.toml2
-rw-r--r--.config/awesome/quarrel/native/src/lenses/application.rs14
-rw-r--r--.config/awesome/quarrel/native/src/lenses/calculator.rs27
-rw-r--r--.config/awesome/quarrel/native/src/lenses/mod.rs90
-rw-r--r--.config/awesome/quarrel/native/src/net/mod.rs4
-rw-r--r--.config/awesome/quarrel/native/src/net/wireless.rs4
-rw-r--r--.config/awesome/quarrel/ui/init.lua87
7 files changed, 169 insertions, 59 deletions
diff --git a/.config/awesome/quarrel/native/Cargo.toml b/.config/awesome/quarrel/native/Cargo.toml
index 1b98681..8d1bd80 100644
--- a/.config/awesome/quarrel/native/Cargo.toml
+++ b/.config/awesome/quarrel/native/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "qnative"
version = "0.1.0"
-edition = "2021"
+edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/.config/awesome/quarrel/native/src/lenses/application.rs b/.config/awesome/quarrel/native/src/lenses/application.rs
index 38a7762..cc12e82 100644
--- a/.config/awesome/quarrel/native/src/lenses/application.rs
+++ b/.config/awesome/quarrel/native/src/lenses/application.rs
@@ -3,13 +3,13 @@ use std::{
fs::read_dir,
path::PathBuf,
sync::{
+ Arc,
+ OnceLock,
+ RwLock,
atomic::{
AtomicBool,
Ordering,
},
- Arc,
- OnceLock,
- RwLock,
},
};
@@ -20,7 +20,10 @@ use rayon::prelude::*;
use url::Url;
use crate::lenses::{
- Cache, Entries, Entry, Lense
+ Cache,
+ Entries,
+ Entry,
+ Lense,
};
static APPS_DIR: &'static str = "/usr/share/applications";
@@ -34,6 +37,7 @@ pub struct Application {
impl Lense for Application {
const NAME: &str = "Application";
+ const PREFIX: Option<&'static str> = None;
fn init() -> Arc<Self> {
let this = Arc::new(Application::default());
@@ -94,7 +98,7 @@ impl Lense for Application {
// self.should_interrupt.load(Ordering::Relaxed)
}
- fn entries(&self, _: &Lua, _: String) -> Result<Entries, anyhow::Error> {
+ fn entries(&self, _: &Lua, _: &str) -> Result<Entries, anyhow::Error> {
let entries = read_dir(APPS_DIR)?
.map(|result| result.map(|e| e.path()))
.collect::<Result<Vec<_>, std::io::Error>>()?;
diff --git a/.config/awesome/quarrel/native/src/lenses/calculator.rs b/.config/awesome/quarrel/native/src/lenses/calculator.rs
index 36f9805..a483d10 100644
--- a/.config/awesome/quarrel/native/src/lenses/calculator.rs
+++ b/.config/awesome/quarrel/native/src/lenses/calculator.rs
@@ -1,22 +1,25 @@
use std::sync::{
+ Arc,
+ LazyLock,
+ Mutex,
atomic::{
AtomicBool,
Ordering,
},
- Arc,
- LazyLock,
- Mutex,
};
use fend_core::{
- evaluate_with_interrupt,
Context,
Interrupt,
+ evaluate_with_interrupt,
};
use mlua::prelude::*;
use crate::lenses::{
- Cache, Entries, Entry, Lense
+ Cache,
+ Entries,
+ Entry,
+ Lense,
};
static CTX: LazyLock<Mutex<Context>> = LazyLock::new(|| {
@@ -32,6 +35,7 @@ pub struct Calculator {
impl Lense for Calculator {
const NAME: &str = "Calculator";
+ const PREFIX: Option<&'static str> = Some("#");
fn init() -> std::sync::Arc<Self> {
Arc::new(Calculator::default())
@@ -55,18 +59,14 @@ impl Lense for Calculator {
self.should_interrupt.load(Ordering::Relaxed)
}
- fn entries(&self, _: &Lua, input: String) -> Result<Entries, anyhow::Error> {
+ fn entries(&self, _: &Lua, input: &str) -> Result<Entries, anyhow::Error> {
let result = match evaluate_with_interrupt(
input.trim(),
&mut CTX.lock().expect("Failed to acquire Fend context lock"),
self,
) {
- Ok(result) => {
- result.get_main_result().to_string()
- }
- Err(err) => {
- err
- }
+ Ok(result) => result.get_main_result().to_string(),
+ Err(err) => err,
};
Ok(if result.is_empty() {
@@ -77,11 +77,10 @@ impl Lense for Calculator {
exec: None,
})
})
-
}
#[inline]
- fn filter(&self, entries: Entries, _: String) -> Entries {
+ fn filter(&self, entries: Entries, _: &str) -> Entries {
entries
}
}
diff --git a/.config/awesome/quarrel/native/src/lenses/mod.rs b/.config/awesome/quarrel/native/src/lenses/mod.rs
index bb7f727..0b7864e 100644
--- a/.config/awesome/quarrel/native/src/lenses/mod.rs
+++ b/.config/awesome/quarrel/native/src/lenses/mod.rs
@@ -5,8 +5,8 @@ use std::sync::Arc;
use itertools::Itertools;
use mlua::{
- prelude::*,
LuaSerdeExt,
+ prelude::*,
};
use rayon::iter::FromParallelIterator;
use serde::{
@@ -18,7 +18,7 @@ use serde::{
pub enum Entries {
Multiple(Vec<Entry>),
Single(Entry),
- None
+ None,
}
impl FromIterator<Entry> for Entries {
@@ -32,7 +32,7 @@ impl FromIterator<Entry> for Entries {
let mut vec = Vec::from([first, second]);
vec.extend(iter);
Self::Multiple(vec)
- },
+ }
}
}
}
@@ -44,8 +44,8 @@ impl From<Vec<Entry>> for Entries {
1 => {
let entry = entries.into_iter().exactly_one().unwrap();
Self::Single(entry)
- },
- _ => Self::Multiple(entries)
+ }
+ _ => Self::Multiple(entries),
}
}
}
@@ -55,7 +55,7 @@ impl IntoLua for Entries {
match self {
Entries::Multiple(entries) => entries.into_lua(lua),
Entries::Single(entry) => entry.into_lua(lua),
- Entries::None => Ok(LuaValue::Nil)
+ Entries::None => Ok(LuaValue::Nil),
}
}
}
@@ -89,6 +89,7 @@ pub struct _Lense<T: Lense>(pub Arc<T>);
pub trait Lense {
const NAME: &'static str;
+ const PREFIX: Option<&'static str>;
fn init() -> Arc<Self>;
@@ -98,51 +99,70 @@ pub trait Lense {
fn set_interrupt(&self, interrupt: bool);
fn get_interrupt(&self) -> bool;
- fn entries(&self, lua: &Lua, input: String) -> Result<Entries, anyhow::Error>;
- fn filter(&self, entries: Entries, input: String) -> Entries {
- let entry_contains = |entry: &Entry| {
- entry.message.to_lowercase().contains(&input.to_lowercase())
- };
+ fn entries(&self, lua: &Lua, input: &str) -> Result<Entries, anyhow::Error>;
+ fn filter(&self, entries: Entries, input: &str) -> Entries {
+ let entry_contains =
+ |entry: &Entry| entry.message.to_lowercase().contains(&input.to_lowercase());
match entries {
- Entries::Multiple(entries) => entries.into_iter()
- .filter(entry_contains)
- .collect(),
- Entries::Single(entry) => if entry_contains(&entry) { Entries::Single(entry) } else { Entries::None }
- Entries::None => Entries::None
+ Entries::Multiple(entries) => entries.into_iter().filter(entry_contains).collect(),
+ Entries::Single(entry) => {
+ if entry_contains(&entry) {
+ Entries::Single(entry)
+ } else {
+ Entries::None
+ }
+ }
+ Entries::None => Entries::None,
}
}
}
impl<T: Lense + 'static> LuaUserData for _Lense<T> {
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
- fields.add_field_method_get("stale", |_, this| {
- Ok(matches!(this.0.get_cache(), Cache::Stale))
+ fields.add_field_method_get("stale", |_, Self(this)| {
+ Ok(matches!(this.get_cache(), Cache::Stale))
});
fields.add_field("name", T::NAME);
}
fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {
- methods.add_method_mut("query", |lua, this, input: String| {
- this.0.set_interrupt(false); // reset interrupt so that we can use the lense again
- return Ok(match this.0.get_cache() {
- Cache::Valid(entries) => this.0.filter(entries.clone(), input),
- Cache::Stale => {
- let entries = this.0.entries(lua, input.clone()).map_err(LuaError::external)?;
- let mut entries = this.0.filter(entries, input);
- match entries {
- Entries::Multiple(ref mut entries) => entries.sort_by(|a, b| a.message.cmp(&b.message)),
- _ => {}
- }
- this.0.set_cache(Cache::Valid(entries.clone()));
- entries
+ methods.add_method_mut("query", |lua, Self(this), input: String| {
+ if T::PREFIX.is_some_and(|prefix| input.starts_with(prefix)) || T::PREFIX.is_none() {
+ let input = if let Some(prefix) = T::PREFIX {
+ input.trim_start_matches(prefix)
+ } else {
+ &input
}
- });
+ .trim();
+
+ this.set_interrupt(false); // reset interrupt so that we can use the lense again
+
+ return Ok(match this.get_cache() {
+ Cache::Valid(entries) => this.filter(entries.clone(), input),
+ Cache::Stale => {
+ let entries = this.entries(lua, input).map_err(LuaError::external)?;
+ let mut entries = this.filter(entries, input);
+ match entries {
+ Entries::Multiple(ref mut entries) => {
+ entries.sort_by(|a, b| a.message.cmp(&b.message))
+ }
+ _ => {}
+ }
+ this.set_cache(Cache::Valid(entries.clone()));
+ entries
+ }
+ });
+ } else {
+ return Ok(Entries::None);
+ }
});
- methods.add_method_mut("mark_stale", |_, this, _: ()| {
- Ok(this.0.set_cache(Cache::Stale))
+ methods.add_method_mut("mark_stale", |_, Self(this), _: ()| {
+ Ok(this.set_cache(Cache::Stale))
+ });
+ methods.add_method_mut("interrupt", |_, Self(this), _: ()| {
+ Ok(this.set_interrupt(true))
});
- methods.add_method_mut("interrupt", |_, this, _: ()| Ok(this.0.set_interrupt(true)));
}
}
diff --git a/.config/awesome/quarrel/native/src/net/mod.rs b/.config/awesome/quarrel/native/src/net/mod.rs
index 383e800..728e6ec 100644
--- a/.config/awesome/quarrel/native/src/net/mod.rs
+++ b/.config/awesome/quarrel/native/src/net/mod.rs
@@ -20,21 +20,21 @@ use nix::{
ioctl_read_bad,
libc::IF_NAMESIZE,
sys::socket::{
- socket as open_socket,
AddressFamily,
SockFlag,
SockType,
+ socket as open_socket,
},
unistd::close,
};
use wireless::{
+ IW_ESSID_MAX_SIZE,
IfConf,
IfConfData,
IwPoint,
IwReq,
IwReqData,
IwReqName,
- IW_ESSID_MAX_SIZE,
SIOCGIFCONF,
SIOCGIWESSID,
};
diff --git a/.config/awesome/quarrel/native/src/net/wireless.rs b/.config/awesome/quarrel/native/src/net/wireless.rs
index d3999db..3500751 100644
--- a/.config/awesome/quarrel/native/src/net/wireless.rs
+++ b/.config/awesome/quarrel/native/src/net/wireless.rs
@@ -7,11 +7,11 @@ use std::ffi::{
use nix::libc::{
__s16,
__s32,
- __u16,
__u8,
+ __u16,
+ IF_NAMESIZE,
ifreq as IfReq,
sockaddr as SockAddr,
- IF_NAMESIZE,
};
pub static SIOCGIFCONF: c_int = 0x8912;
diff --git a/.config/awesome/quarrel/ui/init.lua b/.config/awesome/quarrel/ui/init.lua
index 5e68b1d..7ba6a58 100644
--- a/.config/awesome/quarrel/ui/init.lua
+++ b/.config/awesome/quarrel/ui/init.lua
@@ -4,7 +4,9 @@ local gshape = require "gears.shape"
local gtable = require "gears.table"
local qbind = require "quarrel.bind"
local qcolor = require "quarrel.color"
+local qdelegate = require "quarrel.delegate"
local wibox = require "wibox"
+local cairo = require("lgi").cairo
--- Clip Cairo context
---@param cr cairo_surface Cairo surface
@@ -199,4 +201,89 @@ function M.hoverable(widget, cursor)
return widget
end
+---@param wibox wibox
+function M.animateable_shape(wibox)
+ local old_apply_shape = wibox._apply_shape
+
+ wibox:disconnect_signal("property::geometry", old_apply_shape)
+ wibox:disconnect_signal("property::border_width", old_apply_shape)
+
+ function wibox:set_shape_width(value)
+ self._shape_width = value
+ self:emit_signal("property::shape_width")
+ end
+
+ function wibox:get_shape_width(value)
+ return self._shape_width
+ end
+
+ function wibox:set_shape_height(value)
+ self._shape_height = value
+ self:emit_signal("property::shape_height")
+ end
+
+ function wibox:get_shape_height(value)
+ return self._shape_height
+ end
+
+ -- override to allow us to override shape
+ wibox._apply_shape = qdelegate(function(env, self)
+ local shape = self._shape
+
+ if not shape then
+ self.shape_bounding = nil
+ self.shape_clip = nil
+ return
+ end
+
+ local geo = self:geometry()
+ local bw = self.border_width
+
+ if self.shape_width then
+ geo.width = self.shape_width
+ end
+
+ if self.shape_height then
+ geo.height = self.shape_height
+ end
+
+ -- First handle the bounding shape (things including the border)
+ local img = cairo.ImageSurface(cairo.Format.A1, geo.width + 2*bw, geo.height + 2*bw)
+ local cr = cairo.Context(img)
+
+ -- We just draw the shape in its full size
+ shape(cr, geo.width + 2*bw, geo.height + 2*bw)
+ cr:set_operator(cairo.Operator.SOURCE)
+ cr:fill()
+ self.shape_bounding = img._native
+ img:finish()
+
+ -- Now handle the clip shape (things excluding the border)
+ img = cairo.ImageSurface(cairo.Format.A1, geo.width, geo.height)
+ cr = cairo.Context(img)
+
+ -- We give the shape the same arguments as for the bounding shape and draw
+ -- it in its full size (the translate is to compensate for the smaller
+ -- surface)
+ cr:translate(-bw, -bw)
+ shape(cr, geo.width + 2*bw, geo.height + 2*bw)
+ cr:set_operator(cairo.Operator.SOURCE)
+ cr:fill_preserve()
+ -- Now we remove an area of width 'bw' again around the shape (We use 2*bw
+ -- since half of that is on the outside and only half on the inside)
+ cr:set_source_rgba(0, 0, 0, 0)
+ cr:set_line_width(2*bw)
+ cr:stroke()
+ self.shape_clip = img._native
+ img:finish()
+ end, old_apply_shape)
+
+ wibox:connect_signal("property::geometry", wibox._apply_shape)
+ wibox:connect_signal("property::border_width", wibox._apply_shape)
+ wibox:connect_signal("property::shape_width", wibox._apply_shape)
+ wibox:connect_signal("property::shape_height", wibox._apply_shape)
+
+ return wibox
+end
+
return M