get penrose working

This commit is contained in:
zoe 2022-10-29 17:18:08 +02:00
parent ad65357fbc
commit e07c6af1aa
11 changed files with 140 additions and 2399 deletions

View File

@ -53,11 +53,10 @@
{
manage = "desktop";
name = "penrose";
start = ''/etc/nixos/penrose-custom'';
start = ''/etc/nixos/penrose-custom &> /home/zoe/.penrose.log'';
}
];
# Configure keymap in X11
services.xserver = {
layout = "us";

View File

@ -10,6 +10,12 @@ opt.cursorline = false -- dont highlight current line
opt.number = true
g.rainbow_active = true
-- files
opt.autoread = true --reload files when they are changed on disk
-- autoformat
g.rustfmt_autosave = true -- rustfmt on save
-- highlight yanked text for 200ms using the "Visual" highlight group
vim.cmd[[
augroup highlight_yank

View File

@ -1,5 +1,7 @@
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
xorg.xmodmap
xorg.libxcb
];
}

File diff suppressed because it is too large Load Diff

View File

@ -7,3 +7,5 @@ edition = "2021"
[dependencies]
penrose="0.2"
log4rs="1"
log = "0.4"

View File

@ -1,31 +1,10 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [ rustc cargo gcc pango cairo pkg-config python311 ];
buildInputs = with pkgs; [ rustfmt clippy ];
let
generatedBuild = import ./Cargo.nix {
inherit pkgs;
defaultCrateOverrides = with pkgs; defaultCrateOverrides // {
cairo-sys-rs = attrs: {
buildInputs = [ pkg-config cairo ];
};
gobject-sys = attrs: {
buildInputs = [
pkg-config
glib.dev
];
};
pango-sys = attrs: {
buildInputs = [
pkg-config
pango
];
};
pangocairo-sys = attrs: {
buildInputs = [
pkg-config
gnome2.pango.dev
];
};
};
};
in
generatedBuild.rootCrate.build
# Certain Rust tools won't work without this
# This can also be fixed by using oxalica/rust-overlay and specifying the rust-src extension
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela. for more details.
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}

View File

@ -1 +0,0 @@
/nix/store/ba1c87fw6ccs2a8gyhkbd3zbs7lysqcc-rust_penrose-custom-0.1.0

78
penrose/src/logger.rs Normal file
View File

@ -0,0 +1,78 @@
use log::SetLoggerError;
use log4rs::{
append::{
console::{ConsoleAppender, Target},
file::FileAppender,
},
config::{Appender, Config, Root},
encode::pattern::PatternEncoder,
filter::threshold::ThresholdFilter,
};
use std::fs;
pub fn init_log(
log_path: &String,
log_size: f64,
console_level: log::LevelFilter,
file_level: log::LevelFilter,
) -> Result<(), SetLoggerError> {
// if the log file is bigger than log_size in bytes, we replace the log file instead of
// appending to it.
let mut append = true;
match fs::metadata(log_path) {
Ok(log) => {
if log.len() as f64 > log_size * 1048576.0 {
append = false;
}
}
Err(_) => {
append = true;
}
};
// creates configuration for the log file
let log_file = FileAppender::builder()
.encoder(Box::new(PatternEncoder::new(
"{l} {d(%Y-%m-%d %H:%M:%S)} - {m}\n",
)))
.append(append)
.build(log_path)
.unwrap();
// creates configuration for stderr outputs
let stderr = ConsoleAppender::builder()
.target(Target::Stderr)
.encoder(Box::new(PatternEncoder::new(
"{h({l})} {d(%Y-%m-%d %H:%M:%S)} - {m}\n", // pattern is the same as in the log file,
// but slightly more colourful
)))
.build();
// creates the full configuration using log_file and stderr
let config = Config::builder()
.appender(
Appender::builder()
.filter(Box::new(ThresholdFilter::new(file_level)))
.build("log_file", Box::new(log_file)),
)
.appender(
Appender::builder()
.filter(Box::new(ThresholdFilter::new(console_level)))
.build("stderr", Box::new(stderr)),
)
.build(
Root::builder()
.appender("log_file")
.appender("stderr")
.build(log::LevelFilter::Trace),
)
.unwrap();
// initializes config
let _handle = log4rs::init_config(config)?;
// send a lil message announcing that logging has started successfully
info!("Logging has started :)");
Ok(()) //Ok
}

View File

@ -1,45 +1,58 @@
/**
* penrose :: minimal configuration
* This file will give you a functional if incredibly minimal window manager that has multiple
* workspaces and simple client/workspace movement. For a more fleshed out example see the
* 'simple_config_with_hooks' example.
*/
#[macro_use]
extern crate penrose;
#[macro_use]
extern crate log as logmacro;
use penrose::{
core::{
bindings::MouseEvent, config::Config, helpers::index_selectors, manager::WindowManager,
config::Config, helpers::index_selectors,
},
logging_error_handler,
xcb::new_xcb_backed_window_manager,
Backward, Forward, Less, More, Result,
Backward, Forward, Less, More, Selector,
};
fn main() -> Result<()> {
let config = Config::default();
let hooks = vec![];
mod logger;
// Replace these with your preferred terminal and program launcher
const TERMINAL: &str = "kitty";
const LAUNCHER: &str =
"rofi -combi-modi window,drun,scripts,ssh, -show-icons -show combi -modi combi";
fn main() -> penrose::Result<()> {
logger::init_log(&"/home/zoe/.penrose.log".to_string(), 5.0, log::LevelFilter::Info, log::LevelFilter::Info).unwrap();
info!("now logging");
// Initialise the logger (use LevelFilter::Debug to enable debug logging)
let config = Config::default();
let key_bindings = gen_keybindings! {
// Program launchers
"M-semicolon" => run_external!(LAUNCHER);
"M-Return" => run_external!(TERMINAL);
// Exit Penrose (important to remember this one!)
"M-A-C-Escape" => run_internal!(exit);
// client management
"M-j" => run_internal!(cycle_client, Forward);
"M-k" => run_internal!(cycle_client, Backward);
"M-S-j" => run_internal!(drag_client, Forward);
"M-S-k" => run_internal!(drag_client, Backward);
"M-S-f" => run_internal!(toggle_client_fullscreen, &Selector::Focused);
"M-S-q" => run_internal!(kill_client);
// workspace management
"M-Tab" => run_internal!(toggle_workspace);
"M-bracketright" => run_internal!(cycle_screen, Forward);
"M-bracketleft" => run_internal!(cycle_screen, Backward);
"M-S-bracketright" => run_internal!(drag_workspace, Forward);
"M-S-bracketleft" => run_internal!(drag_workspace, Backward);
"M-A-period" => run_internal!(cycle_workspace, Forward);
"M-A-comma" => run_internal!(cycle_workspace, Backward);
// Layout management
"M-grave" => run_internal!(cycle_layout, Forward);
"M-S-grave" => run_internal!(cycle_layout, Backward);
"M-A-Up" => run_internal!(update_max_main, More);
"M-A-Down" => run_internal!(update_max_main, Less);
"M-A-Right" => run_internal!(update_main_ratio, More);
"M-A-Left" => run_internal!(update_main_ratio, Less);
"M-A-Escape" => run_internal!(exit);
"M-semicolon" => run_external!("rofi");
"M-Return" => run_external!("kitty");
map: { "1", "2", "3", "4", "5", "6", "7", "8", "9" } to index_selectors(9) => {
"M-{}" => focus_workspace (REF);
@ -47,14 +60,12 @@ fn main() -> Result<()> {
};
};
let mouse_bindings = gen_mousebindings! {
Press Right + [Meta] => |wm: &mut WindowManager<_>, _: &MouseEvent| wm.cycle_workspace(Forward),
Press Left + [Meta] => |wm: &mut WindowManager<_>, _: &MouseEvent| wm.cycle_workspace(Backward)
let mut wm = match new_xcb_backed_window_manager(config, vec![], logging_error_handler()) {
Err(e) => {
error!("{}", e);
return Err(e);
},
Ok(connection) => connection
};
let mut wm = new_xcb_backed_window_manager(config, hooks, logging_error_handler())?;
wm.grab_keys_and_run(key_bindings, mouse_bindings)?;
Ok(())
wm.grab_keys_and_run(key_bindings, map! {})
}

1
result
View File

@ -1 +0,0 @@
/nix/store/ba1c87fw6ccs2a8gyhkbd3zbs7lysqcc-rust_penrose-custom-0.1.0

View File

@ -14,9 +14,11 @@ cp -r /etc/nixos/ ./backup
# copy over all the files to /etc/nixos/
sudo cp -r ./configuration.nix ./nvim/ ./packages.nix ./home.nix ./user.nix /etc/nixos/
nix-build ./penrose
sudo cp ./penrose/result/bin/penrose-custom /etc/nixos
# build penrose and copy it to nixos folder
cd ./penrose
nix-shell --run "cargo build --release" --pure
sudo cp ./target/release/penrose-custom /etc/nixos
cd ../
# update and build my new config
sudo nixos-rebuild switch --upgrade