eww/src/main.rs
snakedye 9ea20cd753
Proper wayland support (#125)
* Initial commit for wayland support

* Improvements to Wayland backend, structs and enums

* gtk-layer-shell-rs imported

* Eww compiles with wayland backend

* Full layershell support

* Compatibility with x11 backend

* updated docs and better compatibily with X config

* error in example

* "screen" in config works

* Updated documentation

* bar example for wayland

* eww follow focus when screen is undefined

* NumWithUnit

* Removed SurfaceDefinition for StrutDefinition
again...

* cargo fmt

* fix match statement for screen number

* fix focusable / kb interactivity

* revision #2

* fix: compile error and example

* feat: I fixed the deps
X11 doesn't compile because of some x11 fuckery

* fix: x11 fuckery
PR NOW REEEEEEEEEEEEEEEEEEEEEEEEE

* fix conflics and cargo fmt

* i can't read

* conflicts: a never ending loop...

* dammit ptr

* conflicts: Cargo.lock

* Expression language (#124)

* Add AST

* add make-shift testing parser, and make stuff ocmpile

* add proper expression parser

* make string format use '

* Add empty doc page for expressions

* add tests

* Clean up file structure and add unary operators

* Write documentation

* make multiple daemons possible and make commands time out

* Add EwwPaths struct and refactor path handling in general

* Update docs to include <reserve>

* Improve handling of paths and daemon-ids

* Add elvis operator

* Allow literal-tag content to use user-defined widgets

* Add support for overriding monitor in CLI

* change formatting config

* Improve error messages for non-existant config dir

* Added tooltips (#127)

* update dependencies

* Explicetely states where to look for installing eww (#131)

I think this should be added, because we already had a couple of people opening issues because they didn't read the docs on how to install eww.

* (Very) Rudimentry gif support (#143)

* rudimentry gif support

* revert main.rs

* Fix variable reference detection, should fix #144

* cleanup TextPos in eww debug

* Manually resolve escaped symbols in xml.

This shouldn't be necesary.
Fixes #154 and fixes #147

* Add JSON support for exprs (fixes #146)

* Add docs for json values and make value related names shorter

* Add animated icon

* Initial commit for wayland support

* Improvements to Wayland backend, structs and enums

* gtk-layer-shell-rs imported

* Eww compiles with wayland backend

* Full layershell support

* Compatibility with x11 backend

* updated docs and better compatibily with X config

* "screen" in config works

* Updated documentation

* eww follow focus when screen is undefined

* Removed SurfaceDefinition for StrutDefinition
again...

* cargo fmt

* fix match statement for screen number

* fix focusable / kb interactivity

* revision #2

* fix: compile error and example

* feat: I fixed the deps
X11 doesn't compile because of some x11 fuckery

* fix conflics and cargo fmt

* i can't read

* conflicts: a never ending loop...

* dammit ptr

* conflicts: Cargo.lock

* yeeting git syntax

* trying to resolve conflicts

* yeeting Cargo.lock...

* i try

* revision: removing duplicates

* fix geometry, example and improving docs

* clearing up the documentation

* I forgot the scss file.
I also edited the bar to take advantage of eww expressions.

* more yeeting and moved exclusive to window

Co-authored-by: Bryan Ndjeutcha <ndjeutcha@gmail.com>
Co-authored-by: ElKowar <5300871+elkowar@users.noreply.github.com>
Co-authored-by: undefinedDarkness <38278035+undefinedDarkness@users.noreply.github.com>
Co-authored-by: legendofmiracles <30902201+legendofmiracles@users.noreply.github.com>
2021-05-03 21:14:34 +02:00

181 lines
5.9 KiB
Rust

#![feature(trace_macros)]
#![feature(box_syntax)]
#![feature(box_patterns)]
#![feature(slice_concat_trait)]
#![feature(result_cloned)]
#![feature(try_blocks)]
#![feature(nll)]
extern crate gio;
extern crate gtk;
#[cfg(feature = "wayland")]
extern crate gtk_layer_shell as gtk_layer_shell;
use anyhow::*;
use std::{
os::unix::net,
path::{Path, PathBuf},
};
pub mod app;
pub mod application_lifecycle;
pub mod client;
pub mod config;
pub mod display_backend;
pub mod eww_state;
pub mod geometry;
pub mod ipc_server;
pub mod opts;
pub mod script_var_handler;
pub mod server;
pub mod util;
pub mod value;
pub mod widgets;
fn main() {
let opts: opts::Opt = opts::Opt::from_env();
let log_level_filter = if opts.log_debug { log::LevelFilter::Debug } else { log::LevelFilter::Off };
pretty_env_logger::formatted_builder().filter(Some("eww"), log_level_filter).init();
let result: Result<()> = try {
let paths = opts
.config_path
.map(EwwPaths::from_config_dir)
.unwrap_or_else(EwwPaths::default)
.context("Failed to initialize eww paths")?;
match opts.action {
opts::Action::ClientOnly(action) => {
client::handle_client_only_action(&paths, action)?;
}
opts::Action::WithServer(action) => {
log::info!("Trying to find server process at socket {}", paths.get_ipc_socket_file().display());
match net::UnixStream::connect(&paths.get_ipc_socket_file()) {
Ok(stream) => {
log::info!("Connected to Eww server ({}).", &paths.get_ipc_socket_file().display());
let response =
client::do_server_call(stream, action).context("Error while forwarding command to server")?;
if let Some(response) = response {
println!("{}", response);
if response.is_failure() {
std::process::exit(1);
}
}
}
Err(_) => {
eprintln!("Failed to connect to the eww daemon.");
eprintln!("Make sure to start the eww daemon process by running `eww daemon` first.");
std::process::exit(1);
}
}
}
opts::Action::Daemon => {
// make sure that there isn't already a Eww daemon running.
if check_server_running(paths.get_ipc_socket_file()) {
eprintln!("Eww server already running.");
std::process::exit(1);
} else {
log::info!("Initializing Eww server. ({})", paths.get_ipc_socket_file().display());
let _ = std::fs::remove_file(paths.get_ipc_socket_file());
println!("Run `eww logs` to see any errors, warnings or information while editing your configuration.");
server::initialize_server(paths)?;
}
}
}
};
if let Err(e) = result {
eprintln!("{:?}", e);
std::process::exit(1);
}
}
/// Check if a eww server is currently running by trying to send a ping message to it.
fn check_server_running(socket_path: impl AsRef<Path>) -> bool {
let response = net::UnixStream::connect(socket_path)
.ok()
.and_then(|stream| client::do_server_call(stream, opts::ActionWithServer::Ping).ok());
response.is_some()
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EwwPaths {
log_file: PathBuf,
ipc_socket_file: PathBuf,
config_dir: PathBuf,
}
impl EwwPaths {
pub fn from_config_dir<P: AsRef<Path>>(config_dir: P) -> Result<Self> {
let config_dir = config_dir.as_ref();
let config_dir = if config_dir.is_file() {
config_dir.parent().context("Given config file did not have a parent directory")?
} else {
config_dir
};
if !config_dir.exists() {
bail!("Configuration directory {} does not exist", config_dir.display());
}
let config_dir = config_dir.canonicalize()?;
let daemon_id = base64::encode(format!("{}", config_dir.display()));
Ok(EwwPaths {
config_dir: config_dir.to_path_buf(),
log_file: std::env::var("XDG_CACHE_HOME")
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache"))
.join(format!("eww_{}.log", daemon_id)),
ipc_socket_file: std::env::var("XDG_RUNTIME_DIR")
.map(std::path::PathBuf::from)
.unwrap_or_else(|_| std::path::PathBuf::from("/tmp"))
.join(format!("eww-server_{}", daemon_id)),
})
}
pub fn default() -> Result<Self> {
let config_dir = std::env::var("XDG_CONFIG_HOME")
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".config"))
.join("eww");
Self::from_config_dir(config_dir)
}
pub fn get_log_file(&self) -> &Path {
self.log_file.as_path()
}
pub fn get_ipc_socket_file(&self) -> &Path {
self.ipc_socket_file.as_path()
}
pub fn get_config_dir(&self) -> &Path {
self.config_dir.as_path()
}
pub fn get_eww_xml_path(&self) -> PathBuf {
self.config_dir.join("eww.xml")
}
pub fn get_eww_scss_path(&self) -> PathBuf {
self.config_dir.join("eww.scss")
}
}
impl std::fmt::Display for EwwPaths {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"config-dir: {}, ipc-socket: {}, log-file: {}",
self.config_dir.display(),
self.ipc_socket_file.display(),
self.log_file.display()
)
}
}