Skip to content

Commit

Permalink
fix!: eliminate some dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
w-lfchen committed Aug 13, 2024
1 parent 4d55e9a commit 434353f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
18 changes: 8 additions & 10 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{
config,
daemon_response::DaemonResponseSender,
display_backend::DisplayBackend,
error_handling_ctx,
Expand All @@ -23,6 +22,7 @@ use simplexpr::{dynval::DynVal, SimplExpr};
use std::{
cell::RefCell,
collections::{HashMap, HashSet},
marker::PhantomData,
rc::Rc,
};
use tokio::sync::mpsc::UnboundedSender;
Expand Down Expand Up @@ -87,10 +87,6 @@ pub enum DaemonCommand {
/// An opened window.
#[derive(Debug)]
pub struct EwwWindow {
/// Every window has an id, uniquely identifying it.
/// If no specific ID was specified whilst starting the window,
/// this will be the same as the window name.
pub instance_id: String,
pub name: String,
pub scope_index: ScopeIndex,
pub gtk_window: Window,
Expand All @@ -111,11 +107,13 @@ impl EwwWindow {
}
}

pub struct App<B> {
pub display_backend: B,
pub struct App<B: DisplayBackend> {
pub scope_graph: Rc<RefCell<ScopeGraph>>,
pub eww_config: config::EwwConfig,
/// Map of all currently open windows by their IDs
/// Map of all currently open windows to their unique IDs
/// If no specific ID was specified whilst starting the window,
/// it will be the same as the window name.
/// Therefore, only one window of a given name can exist when not using IDs.
pub open_windows: HashMap<String, EwwWindow>,
pub instance_id_to_args: HashMap<String, WindowArguments>,
/// Window names that are supposed to be open, but failed.
Expand All @@ -131,9 +129,10 @@ pub struct App<B> {
pub window_close_timer_abort_senders: HashMap<String, futures::channel::oneshot::Sender<()>>,

pub paths: EwwPaths,
pub phantom: PhantomData<B>,
}

impl<B> std::fmt::Debug for App<B> {
impl<B: DisplayBackend> std::fmt::Debug for App<B> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("App")
.field("scope_graph", &*self.scope_graph.borrow())
Expand Down Expand Up @@ -572,7 +571,6 @@ fn initialize_window<B: DisplayBackend>(
window.show_all();

Ok(EwwWindow {
instance_id: window_init.id.clone(),
name: window_init.name.clone(),
gtk_window: window,
scope_index: window_scope,
Expand Down
16 changes: 8 additions & 8 deletions crates/eww/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,24 @@ fn main() {
let use_wayland = opts.force_wayland || detect_wayland();
#[cfg(all(feature = "wayland", feature = "x11"))]
let result = if use_wayland {
run(opts, eww_binary_name, display_backend::WaylandBackend)
run::<display_backend::WaylandBackend>(opts, eww_binary_name)
} else {
run(opts, eww_binary_name, display_backend::X11Backend)
run::<display_backend::X11Backend>(opts, eww_binary_name)
};

#[cfg(all(not(feature = "wayland"), feature = "x11"))]
let result = {
if use_wayland {
log::warn!("Eww compiled without wayland support. falling back to X11, eventhough wayland was requested.");
}
run(opts, eww_binary_name, display_backend::X11Backend)
run::<display_backend::X11Backend>(opts, eww_binary_name)
};

#[cfg(all(feature = "wayland", not(feature = "x11")))]
let result = run(opts, eww_binary_name, display_backend::WaylandBackend);
let result = run::<display_backend::WaylandBackend>(opts, eww_binary_name);

#[cfg(not(any(feature = "wayland", feature = "x11")))]
let result = run(opts, eww_binary_name, display_backend::NoBackend);
let result = run::<display_backend::NoBackend>(opts, eww_binary_name);

if let Err(err) = result {
error_handling_ctx::print_error(err);
Expand All @@ -88,7 +88,7 @@ fn detect_wayland() -> bool {
session_type.contains("wayland") || (!wayland_display.is_empty() && !session_type.contains("x11"))
}

fn run<B: DisplayBackend>(opts: opts::Opt, eww_binary_name: String, display_backend: B) -> Result<()> {
fn run<B: DisplayBackend>(opts: opts::Opt, eww_binary_name: String) -> Result<()> {
let paths = opts
.config_path
.map(EwwPaths::from_config_dir)
Expand Down Expand Up @@ -128,7 +128,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, eww_binary_name: String, display_back
if !opts.show_logs {
println!("Run `{} logs` to see any errors while editing your configuration.", eww_binary_name);
}
let fork_result = server::initialize_server(paths.clone(), None, display_backend, !opts.no_daemonize)?;
let fork_result = server::initialize_server::<B>(paths.clone(), None, !opts.no_daemonize)?;
opts.no_daemonize || fork_result == ForkResult::Parent
}

Expand Down Expand Up @@ -160,7 +160,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, eww_binary_name: String, display_back

let (command, response_recv) = action.into_daemon_command();
// start the daemon and give it the command
let fork_result = server::initialize_server(paths.clone(), Some(command), display_backend, true)?;
let fork_result = server::initialize_server::<B>(paths.clone(), Some(command), true)?;
let is_parent = fork_result == ForkResult::Parent;
if let (Some(recv), true) = (response_recv, is_parent) {
listen_for_daemon_response(recv);
Expand Down
8 changes: 4 additions & 4 deletions crates/eww/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
app::{self, DaemonCommand},
app::{self, App, DaemonCommand},
config, daemon_response,
display_backend::DisplayBackend,
error_handling_ctx, ipc_server, script_var_handler,
Expand All @@ -12,6 +12,7 @@ use std::{
cell::RefCell,
collections::{HashMap, HashSet},
io::Write,
marker::PhantomData,
os::unix::io::AsRawFd,
path::Path,
rc::Rc,
Expand All @@ -22,7 +23,6 @@ use tokio::sync::mpsc::*;
pub fn initialize_server<B: DisplayBackend>(
paths: EwwPaths,
action: Option<DaemonCommand>,
display_backend: B,
should_daemonize: bool,
) -> Result<ForkResult> {
let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel();
Expand Down Expand Up @@ -75,8 +75,7 @@ pub fn initialize_server<B: DisplayBackend>(

let (scope_graph_evt_send, mut scope_graph_evt_recv) = tokio::sync::mpsc::unbounded_channel();

let mut app = app::App {
display_backend,
let mut app: App<B> = app::App {
scope_graph: Rc::new(RefCell::new(ScopeGraph::from_global_vars(
eww_config.generate_initial_state()?,
scope_graph_evt_send,
Expand All @@ -90,6 +89,7 @@ pub fn initialize_server<B: DisplayBackend>(
app_evt_send: ui_send.clone(),
window_close_timer_abort_senders: HashMap::new(),
paths,
phantom: PhantomData,
};

if let Some(screen) = gdk::Screen::default() {
Expand Down
2 changes: 0 additions & 2 deletions crates/eww/src/window_initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::window_arguments::WindowArguments;
pub struct WindowInitiator {
pub backend_options: BackendWindowOptions,
pub geometry: Option<WindowGeometry>,
pub id: String,
pub local_variables: HashMap<VarName, DynVal>,
pub monitor: Option<MonitorIdentifier>,
pub name: String,
Expand All @@ -37,7 +36,6 @@ impl WindowInitiator {
Ok(WindowInitiator {
backend_options: window_def.backend_options.eval(&vars)?,
geometry,
id: args.instance_id.clone(),
monitor,
name: window_def.name.clone(),
resizable: window_def.eval_resizable(&vars)?,
Expand Down

0 comments on commit 434353f

Please sign in to comment.