Skip to content
Open
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
545 changes: 187 additions & 358 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "leftwm-config"
version = "0.1.0"
authors = ["BlackDragon2447 <blackdragon2447@e.email>"]
edition = "2021"
edition = "2024"
license = "MIT"
readme = "README.md"
#description = "A window manager for Adventurers"
Expand All @@ -12,12 +12,12 @@ anyhow = {version="1.0.69", features=["backtrace"]}
clap = "4.5.41"
xdg = "3.0.0"
serde = { version = "1.0.152", features = ["derive", "rc"] }
ron = "0.10.1"
ron = "0.12.1"
serde_json = "1.0.94"
log = "0.4.17"
git-version = "0.3.5"
thiserror = "2.0.12"
tui = "0.19.0"
crossterm = "0.29.0"
glob = "0.3.1"
toml = "0.8.2"
toml = "1.1.2"
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() {
#[cfg(debug_assertions)]
println!("cargo:warning=leftwm-config is being build in debug mode, if build in debug mode leftwm-config will work with a `test_config.ron` (or .toml) file, build in release mode to work with `config.ron`");
println!(
"cargo:warning=leftwm-config is being build in debug mode, if build in debug mode leftwm-config will work with a `test_config.ron` (or .toml) file, build in release mode to work with `config.ron`"
);
}
16 changes: 11 additions & 5 deletions src/config/check.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::config;
use crate::config::Config;
use crate::config::{all_ids_some, all_ids_unique, get_workspace_ids};
use anyhow::bail;
use anyhow::Result;
use anyhow::bail;
use std::collections::HashSet;
use std::{env, fs};

Expand All @@ -28,7 +28,7 @@ pub fn check_config(path: Option<&str>, verbose: bool) -> Result<()> {
}
Err(e) => {
println!("Configuration failed. Reason: {e:?}");
bail!("Configuration failed. Reason: {:?}", e);
bail!("Configuration failed. Reason: {e:?}");
}
}
println!("\x1b[0;94m::\x1b[0m Checking environment . . .");
Expand All @@ -47,7 +47,9 @@ impl Config {
println!("Mousekey is set.");
}
if mousekey.is_empty() {
println!("Your mousekey is set to nothing, this will cause windows to move/resize with just a mouse press.");
println!(
"Your mousekey is set to nothing, this will cause windows to move/resize with just a mouse press."
);
return;
}
if verbose {
Expand All @@ -66,10 +68,14 @@ impl Config {
if ids.iter().any(std::option::Option::is_some) {
if all_ids_some(&ids) {
if !all_ids_unique(&ids) {
println!("Your config.toml contains duplicate workspace IDs. Please assign unique IDs to workspaces. The default config will be used instead.");
println!(
"Your config.toml contains duplicate workspace IDs. Please assign unique IDs to workspaces. The default config will be used instead."
);
}
} else {
println!("Your config.toml specifies an ID for some but not all workspaces. This can lead to ID collisions and is not allowed. The default config will be used instead.");
println!(
"Your config.toml specifies an ID for some but not all workspaces. This can lead to ID collisions and is not allowed. The default config will be used instead."
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::values::WindowHandle;
use crate::config::Layout;
use crate::config::values::WindowHandle;
use serde::{Deserialize, Serialize};

#[allow(clippy::module_name_repetitions)]
Expand Down
2 changes: 1 addition & 1 deletion src/config/keybind.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::Config;
use crate::config::command::{BaseCommand, CoreCommand};
use crate::config::layout::Layout;
use crate::config::modifier::Modifier;
use crate::config::Config;
use anyhow::ensure;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
Expand Down
9 changes: 2 additions & 7 deletions src/config/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use serde::{Deserialize, Serialize};
use std::str::FromStr;
use thiserror::Error;

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
pub enum Layout {
#[default]
MainAndVertStack,
MainAndHorizontalStack,
MainAndDeck,
Expand Down Expand Up @@ -39,12 +40,6 @@ pub const LAYOUTS: &[Layout] = &[
Layout::LeftWiderRightStack,
];

impl Default for Layout {
fn default() -> Self {
Self::MainAndVertStack
}
}

#[derive(Debug, Error)]
#[error("Could not parse layout: {0}")]
pub struct ParseLayoutError(String);
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod utils;
use crate::config::check_config;
use crate::config::filehandler::{load_from_file, write_to_file};
use anyhow::Result;
use clap::{Arg, Command as ClapCmd};
use clap::{Arg, ArgAction, Command as ClapCmd};
use std::path::Path;
use std::process::Command;
use std::{env, fs, io};
Expand All @@ -33,36 +33,42 @@ fn main() -> Result<()> {
.arg(
Arg::new("New")
.short('n')
.action(ArgAction::SetTrue)
.long("new")
.help("Generate a new config file"),
)
.arg(
Arg::new("Editor")
.short('e')
.action(ArgAction::SetTrue)
.long("editor")
.help("Open the current config file in the default editor (default)"),
)
.arg(
Arg::new("TUI")
.short('t')
.action(ArgAction::SetTrue)
.long("tui")
.help("Open the current config file in the TUI"),
)
.arg(
Arg::new("Check")
.short('c')
.action(ArgAction::SetTrue)
.long("check")
.help("Check if the current config is valid"),
)
.arg(
Arg::new("Verbose")
.short('v')
.action(ArgAction::SetTrue)
.long("verbose")
.help("Outputs received configuration file."),
)
.arg(
Arg::new("Migrate")
.long("migrate")
.action(ArgAction::SetTrue)
.help("Migrate an old .toml config to the RON format."),
)
.get_matches();
Expand Down
68 changes: 28 additions & 40 deletions src/tui/key_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::mem;

use anyhow::{bail, Result};
use anyhow::{Result, bail};
use crossterm::event;
use crossterm::event::{Event, KeyCode};
use tui::widgets::ListState;
Expand All @@ -12,7 +12,7 @@ use crate::config::layout::Layout as WMLayout;
use crate::config::modifier::{Modifier as KeyModifier, Modifier};
use crate::config::structs::{ScratchPad, WindowHook, Workspace};
use crate::config::values::{FocusBehaviour, InsertBehavior, LayoutMode, Size};
use crate::tui::{next, previous, App, MultiselectListState, PopupState, Window};
use crate::tui::{App, MultiselectListState, PopupState, Window, next, previous};
use crate::utils::xkeysym_lookup::into_keysym;
use crate::utils::{TryRemove, TryUnwrap};

Expand Down Expand Up @@ -105,13 +105,11 @@ fn up(app: &mut App) -> Result<bool> {
14 => {}
_ => {}
},
Window::Workspaces { .. } => {
if s == 6 {
if let PopupState::MultiList(s) = &mut app.current_popup_state {
previous(&mut s.liststate, 14);
} else {
bail!("Invalid popup state");
}
Window::Workspaces { .. } if s == 6 => {
if let PopupState::MultiList(s) = &mut app.current_popup_state {
previous(&mut s.liststate, 14);
} else {
bail!("Invalid popup state");
}
}
Window::KeyBinds { .. } => match s {
Expand Down Expand Up @@ -192,13 +190,11 @@ fn down(app: &mut App) -> Result<bool> {
14 => {}
_ => {}
},
Window::Workspaces { .. } => {
if s == 6 {
if let PopupState::MultiList(s) = &mut app.current_popup_state {
next(&mut s.liststate, 14);
} else {
bail!("Invalid popup state");
}
Window::Workspaces { .. } if s == 6 => {
if let PopupState::MultiList(s) = &mut app.current_popup_state {
next(&mut s.liststate, 14);
} else {
bail!("Invalid popup state");
}
}
Window::KeyBinds { .. } => match s {
Expand Down Expand Up @@ -959,7 +955,7 @@ fn enter_workspaces(app: &mut App, index: usize, empty: bool) -> Result<bool> {
.workspaces
.as_mut()
.try_unwrap()?
.try_remove(index)?;
.try_remove_temp(index)?;
if app
.current_config
.workspaces
Expand Down Expand Up @@ -1024,7 +1020,7 @@ fn enter_tags(app: &mut App, index: usize, empty: bool) -> Result<bool> {
.tags
.as_mut()
.try_unwrap()?
.try_remove(index)?;
.try_remove_temp(index)?;
if app.current_config.tags.as_ref().try_unwrap()?.is_empty() {
app.current_window = Window::Workspaces { index, empty: true };
}
Expand Down Expand Up @@ -1059,11 +1055,7 @@ fn enter_window_rules(app: &mut App, index: usize, empty: bool) -> Result<bool>
.try_unwrap()?
.window_title = {
if let PopupState::String(s) = app.current_popup_state.clone() {
if s.is_empty() {
None
} else {
Some(s)
}
if s.is_empty() { None } else { Some(s) }
} else {
bail!("Invalid popup state");
}
Expand All @@ -1080,11 +1072,7 @@ fn enter_window_rules(app: &mut App, index: usize, empty: bool) -> Result<bool>
.try_unwrap()?
.window_class = {
if let PopupState::String(s) = app.current_popup_state.clone() {
if s.is_empty() {
None
} else {
Some(s)
}
if s.is_empty() { None } else { Some(s) }
} else {
bail!("Invalid popup state");
}
Expand Down Expand Up @@ -1206,7 +1194,7 @@ fn enter_window_rules(app: &mut App, index: usize, empty: bool) -> Result<bool>
.window_rules
.as_mut()
.try_unwrap()?
.try_remove(index)?;
.try_remove_temp(index)?;
if index == app.current_config.window_rules.as_ref().try_unwrap()?.len()
&& !app
.current_config
Expand Down Expand Up @@ -1408,7 +1396,7 @@ fn enter_scratchpads(app: &mut App, index: usize, empty: bool) -> Result<bool> {
.scratchpad
.as_mut()
.try_unwrap()?
.try_remove(index)?;
.try_remove_temp(index)?;
if index == app.current_config.scratchpad.as_ref().try_unwrap()?.len()
&& !app
.current_config
Expand Down Expand Up @@ -1584,12 +1572,12 @@ fn enter_keybinds(app: &mut App, index: usize, empty: bool) -> Result<bool> {
}
}
Some(3) => {
if let PopupState::String(s) = &mut app.current_popup_state {
if into_keysym(s).is_some() {
app.current_config.keybind.get_mut(index).try_unwrap()?.key = s.clone();
app.current_popup = None;
app.current_popup_state = PopupState::None;
}
if let PopupState::String(s) = &mut app.current_popup_state
&& into_keysym(s).is_some()
{
app.current_config.keybind.get_mut(index).try_unwrap()?.key = s.clone();
app.current_popup = None;
app.current_popup_state = PopupState::None;
}
}
None => {
Expand Down Expand Up @@ -1714,7 +1702,7 @@ fn enter_keybinds(app: &mut App, index: usize, empty: bool) -> Result<bool> {
app.current_config.keybind.push(Keybind::default());
}
Some(8) => {
app.current_config.keybind.try_remove(index)?;
app.current_config.keybind.try_remove_temp(index)?;
app.current_window.try_decrement_index();
}
_ => {}
Expand Down Expand Up @@ -1822,7 +1810,7 @@ fn enter_keybinds(app: &mut App, index: usize, empty: bool) -> Result<bool> {
app.current_config.keybind.push(Keybind::default());
}
Some(7) => {
app.current_config.keybind.try_remove(index)?;
app.current_config.keybind.try_remove_temp(index)?;
app.current_window.try_decrement_index();
}
_ => {}
Expand All @@ -1847,7 +1835,7 @@ fn space(app: &mut App) -> Result<bool> {
.iter()
.position(|x| *x == l.liststate.selected().unwrap_or(14))
.try_unwrap()?;
l.selected.try_remove(index)?;
l.selected.try_remove_temp(index)?;
} else {
l.selected.push(l.liststate.selected().unwrap_or(14));
}
Expand All @@ -1865,7 +1853,7 @@ fn space(app: &mut App) -> Result<bool> {
.iter()
.position(|x| *x == l.liststate.selected().unwrap_or(14))
.try_unwrap()?;
l.selected.try_remove(index)?;
l.selected.try_remove_temp(index)?;
} else {
l.selected.push(l.liststate.selected().unwrap_or(14));
}
Expand Down
6 changes: 3 additions & 3 deletions src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use anyhow::Result;
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
use crossterm::execute;
use crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode,
};
use tui::layout::{Alignment, Constraint, Direction, Layout};
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{BorderType, List, ListItem, ListState};
use tui::{
Terminal,
backend::CrosstermBackend,
widgets::{Block, Borders, Paragraph, Wrap},
Terminal,
};

use crate::config::Config;
use crate::config::filehandler::load;
use crate::config::modifier::Modifier as KeyModifier;
use crate::config::values::{FocusBehaviour, InsertBehavior, LayoutMode};
use crate::config::Config;
use crate::utils;
use crate::utils::TryUnwrap;

Expand Down
8 changes: 4 additions & 4 deletions src/tui/popups.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use std::io::Stdout;
use std::mem;

use anyhow::{bail, Result};
use anyhow::{Result, bail};
use tui::Frame;
use tui::backend::CrosstermBackend;
use tui::layout::{Alignment, Constraint, Direction, Layout};
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, BorderType, Borders, Clear, List, ListItem, Paragraph, Wrap};
use tui::Frame;

use crate::config::Config;
use crate::config::command::BaseCommand;
use crate::config::modifier::Modifier as KeyModifier;
use crate::config::modifier::Modifier::Single;
use crate::config::values::{FocusBehaviour, InsertBehavior, LayoutMode};
use crate::config::Config;
use crate::tui::PopupState;
use crate::utils::xkeysym_lookup::into_keysym;
use crate::utils::{centered_rect, TryUnwrap};
use crate::utils::{TryUnwrap, centered_rect};

pub fn modkey(
current_config: &Config,
Expand Down
Loading
Loading