This commit is contained in:
Ohio2 2021-07-28 12:22:19 +02:00
commit 155cb18ffb
3 changed files with 95 additions and 0 deletions

17
Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "violet"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
penrose = "0.2.0"
log = "0.4.14"
nix = "0.17.0"
strum = "0.19.5"
strum_macros = "0.19.4"
thiserror = "1.0.26"
paste = "1.0.5"
serde_json = "1.0.64"
simplelog = "0.8.0"

9
Makefile Normal file
View file

@ -0,0 +1,9 @@
ohio2-penrose:
cargo build --release
install:
scp target/debug/ohio2-penrose /usr/bin/ohio2-penrose
remove:
rm /usr/bin/ohio2-penrose
clean:
rm Cargo.lock
rm -rf target

69
src/main.rs Normal file
View file

@ -0,0 +1,69 @@
#[macro_use]
extern crate penrose;
use penrose::{
core::{
bindings::KeyEventHandler,
config::Config,
helpers::index_selectors,
manager::WindowManager,
},
logging_error_handler,
xcb::new_xcb_backed_window_manager,
Backward, Forward, Less, More,
};
use simplelog::{LevelFilter, SimpleLogger};
// Replace these with your preferred terminal and program launcher
const TERMINAL: &str = "alacritty";
const LAUNCHER: &str = "dmenu_run";
fn main() -> penrose::Result<()> {
// Initialise the logger (use LevelFilter::Debug to enable debug logging)
if let Err(e) = SimpleLogger::init(LevelFilter::Info, simplelog::Config::default()) {
panic!("unable to set log level: {}", e);
};
</span><span style="color:#fa5c4b;">let</span><span style="color:#fdf4c1aa;"> config </span><span style="color:#fe8019;">= </span><span style="color:#fdf4c1aa;">Config::default();
</span><span style="color:#fa5c4b;">let</span><span style="color:#fdf4c1aa;"> key_bindings </span><span style="color:#fe8019;">= </span><span style="color:#fabd2f;">gen_keybindings! </span><span style="color:#fdf4c1aa;">{
</span><span style="font-style:italic;color:#928374;">// Program launchers
</span><span style="color:#b8bb26;">&quot;M-semicolon&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_external!</span><span style="color:#fdf4c1aa;">(</span><span style="color:#fdf4c1;">LAUNCHER</span><span style="color:#fdf4c1aa;">);
</span><span style="color:#b8bb26;">&quot;M-Return&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_external!</span><span style="color:#fdf4c1aa;">(</span><span style="color:#fdf4c1;">TERMINAL</span><span style="color:#fdf4c1aa;">);
</span><span style="font-style:italic;color:#928374;">// Exit Penrose (important to remember this one!)
</span><span style="color:#b8bb26;">&quot;M-A-C-Escape&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(exit);
</span><span style="font-style:italic;color:#928374;">// client management
</span><span style="color:#b8bb26;">&quot;M-j&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(cycle_client, Forward);
</span><span style="color:#b8bb26;">&quot;M-k&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(cycle_client, Backward);
</span><span style="color:#b8bb26;">&quot;M-S-j&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(drag_client, Forward);
</span><span style="color:#b8bb26;">&quot;M-S-k&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(drag_client, Backward);
</span><span style="color:#b8bb26;">&quot;M-S-f&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(toggle_client_fullscreen, </span><span style="color:#fe8019;">&amp;</span><span style="color:#fdf4c1aa;">Selector::Focused);
</span><span style="color:#b8bb26;">&quot;M-S-q&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(kill_client);
</span><span style="font-style:italic;color:#928374;">// workspace management
</span><span style="color:#b8bb26;">&quot;M-Tab&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(toggle_workspace);
</span><span style="color:#b8bb26;">&quot;M-A-period&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(cycle_workspace, Forward);
</span><span style="color:#b8bb26;">&quot;M-A-comma&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(cycle_workspace, Backward);
</span><span style="font-style:italic;color:#928374;">// Layout management
</span><span style="color:#b8bb26;">&quot;M-grave&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(cycle_layout, Forward);
</span><span style="color:#b8bb26;">&quot;M-S-grave&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(cycle_layout, Backward);
</span><span style="color:#b8bb26;">&quot;M-A-Up&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(update_max_main, More);
</span><span style="color:#b8bb26;">&quot;M-A-Down&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(update_max_main, Less);
</span><span style="color:#b8bb26;">&quot;M-A-Right&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(update_main_ratio, More);
</span><span style="color:#b8bb26;">&quot;M-A-Left&quot; </span><span style="color:#fe8019;">=&gt; </span><span style="color:#fabd2f;">run_internal!</span><span style="color:#fdf4c1aa;">(update_main_ratio, Less);
refmap [ config.</span><span style="color:#fabd2f;">ws_range</span><span style="color:#fdf4c1aa;">() ] </span><span style="color:#fe8019;">in </span><span style="color:#fdf4c1aa;">{
</span><span style="color:#b8bb26;">&quot;M-{}&quot; </span><span style="color:#fe8019;">=&gt;</span><span style="color:#fdf4c1aa;"> focus_workspace [ </span><span style="color:#fabd2f;">index_selectors</span><span style="color:#fdf4c1aa;">(config.</span><span style="color:#fabd2f;">workspaces</span><span style="color:#fdf4c1aa;">().</span><span style="color:#fabd2f;">len</span><span style="color:#fdf4c1aa;">()) ];
</span><span style="color:#b8bb26;">&quot;M-S-{}&quot; </span><span style="color:#fe8019;">=&gt;</span><span style="color:#fdf4c1aa;"> client_to_workspace [ </span><span style="color:#fabd2f;">index_selectors</span><span style="color:#fdf4c1aa;">(config.</span><span style="color:#fabd2f;">workspaces</span><span style="color:#fdf4c1aa;">().</span><span style="color:#fabd2f;">len</span><span style="color:#fdf4c1aa;">()) ];
};
};
</span><span style="color:#fa5c4b;">let mut</span><span style="color:#fdf4c1aa;"> wm </span><span style="color:#fe8019;">= </span><span style="color:#fabd2f;">new_xcb_backed_window_manager</span><span style="color:#fdf4c1aa;">(config, </span><span style="color:#fabd2f;">vec!</span><span style="color:#fdf4c1aa;">[], </span><span style="color:#fabd2f;">logging_error_handler</span><span style="color:#fdf4c1aa;">())</span><span style="color:#fe8019;">?</span><span style="color:#fdf4c1aa;">;
wm.</span><span style="color:#fabd2f;">grab_keys_and_run</span><span style="color:#fdf4c1aa;">(key_bindings, </span><span style="color:#fabd2f;">map!</span><span style="color:#fdf4c1aa;">{})
}