Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow use of global_variables in defwindow #1004

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/eww/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ homepage = "https://github.com/elkowar/eww"
edition = "2021"



[features]
default = ["x11", "wayland"]
x11 = ["gdkx11", "x11rb"]
Expand All @@ -23,6 +22,7 @@ notifier_host.workspace = true

gtk = "0.17.1"
gdk = "0.17.1"
gdk-sys = "0.17.0"
pango = "0.17.1"
glib = "0.17.8"
glib-macros = "0.17.8"
Expand All @@ -39,16 +39,16 @@ x11rb = { version = "0.11.1", features = ["randr"], optional = true }
zbus = { version = "3.7.0", default-features = false, features = ["tokio"] }
ordered-stream = "0.2.0"

anyhow.workspace = true
anyhow.workspace = true
bincode.workspace = true
chrono.workspace = true
clap = {workspace = true, features = ["derive"] }
clap = { workspace = true, features = ["derive"] }
clap_complete.workspace = true
codespan-reporting.workspace = true
derive_more.workspace = true
extend.workspace = true
futures.workspace = true
grass = {workspace = true, default-features = false}
grass = { workspace = true, default-features = false }
itertools.workspace = true
libc.workspace = true
log.workspace = true
Expand All @@ -59,7 +59,7 @@ once_cell.workspace = true
pretty_env_logger.workspace = true
regex.workspace = true
serde_json.workspace = true
serde = {workspace = true, features = ["derive"]}
serde = { workspace = true, features = ["derive"] }
simple-signal.workspace = true
sysinfo = { workspace = true }
tokio-util.workspace = true
Expand Down
14 changes: 11 additions & 3 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ impl<B: DisplayBackend> App<B> {

let window_def = self.eww_config.get_window(window_name)?.clone();
assert_eq!(window_def.name, window_name, "window definition name did not equal the called window");

let initiator = WindowInitiator::new(&window_def, window_args)?;
let global_vars = self.scope_graph.borrow().global_scope().data.clone();
let initiator = WindowInitiator::new(&window_def, window_args, global_vars)?;

let root_index = self.scope_graph.borrow().root_index;

Expand Down Expand Up @@ -643,7 +643,15 @@ pub fn get_monitor_from_display(display: &gdk::Display, identifier: &MonitorIden
MonitorIdentifier::Name(name) => {
for m in 0..display.n_monitors() {
if let Some(model) = display.monitor(m).and_then(|x| x.model()) {
if model == *name {
let plug_name;
unsafe {
use glib::translate::ToGlibPtr;
let plug_name_pointer =
gdk_sys::gdk_screen_get_monitor_plug_name(display.default_screen().to_glib_none().0, m);
use std::ffi::CStr;
plug_name = CStr::from_ptr(plug_name_pointer).to_str().unwrap();
}
if model == *name || name == plug_name {
return display.monitor(m);
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/eww/src/window_initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ pub struct WindowInitiator {
}

impl WindowInitiator {
pub fn new(window_def: &WindowDefinition, args: &WindowArguments) -> Result<Self> {
pub fn new(window_def: &WindowDefinition, args: &WindowArguments, mut global_vars: HashMap<VarName, DynVal>) -> Result<Self> {
let vars = args.get_local_window_variables(window_def)?;
global_vars.extend(vars.clone());

let geometry = match &window_def.geometry {
Some(geo) => Some(geo.eval(&vars)?.override_if_given(args.anchor, args.pos, args.size)),
None => None,
};
let monitor = if args.monitor.is_none() { window_def.eval_monitor(&vars)? } else { args.monitor.clone() };
let monitor = if args.monitor.is_none() { window_def.eval_monitor(&global_vars)? } else { args.monitor.clone() };
Ok(WindowInitiator {
backend_options: window_def.backend_options.eval(&vars)?,
backend_options: window_def.backend_options.eval(&global_vars)?,
geometry,
id: args.instance_id.clone(),
monitor,
name: window_def.name.clone(),
resizable: window_def.eval_resizable(&vars)?,
stacking: window_def.eval_stacking(&vars)?,
resizable: window_def.eval_resizable(&global_vars)?,
stacking: window_def.eval_stacking(&global_vars)?,
local_variables: vars,
})
}
Expand Down