├── .gitignore ├── Cargo.toml ├── Makefile.toml ├── README.md ├── src ├── drw │ ├── clrscheme.rs │ ├── fnt.rs │ └── mod.rs ├── config.rs ├── events.rs ├── wm │ ├── workspace.rs │ ├── client.rs │ └── mod.rs └── main.rs ├── Cargo.lock └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dwm-rust" 3 | version = "0.1.0" 4 | authors = ["Vertmo "] 5 | build = "build.rs" 6 | 7 | [dependencies] 8 | x11 = "2.17.5" 9 | libc = "" 10 | servo-fontconfig = "0.4.0" 11 | -------------------------------------------------------------------------------- /Makefile.toml: -------------------------------------------------------------------------------- 1 | [tasks.install] 2 | description = "Installs dwm-rust in /usr/local/bin." 3 | script = [ 4 | "cargo build --release", 5 | "echo Installing in /usr/local/bin", 6 | "sudo mkdir -p /usr/local/bin", 7 | "sudo cp -f target/release/dwm-rust /usr/local/bin", 8 | "sudo chmod 755 /usr/local/bin/dwm-rust" 9 | ] 10 | 11 | [tasks.xnest] 12 | description = "Tests the debug build inside xnest" 13 | script = [ 14 | "cargo build", 15 | "Xnest :2 -name 'dwm-rust' -ac &", 16 | "export DISPLAY=:2", 17 | "exec target/debug/dwm-rust" 18 | ] 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dwm-rust # 2 | The goal of this project is to implement the [Dynamic Window Manager](https://dwm.suckless.org/) from suckless, using the Rust programming language. 3 | 4 | We will try to use as many Rust "safe" features as possible, even if relying on the xlib library forces us to use unsafe C features in our code. 5 | 6 | ## Dependencies ## 7 | * xlib and xft libraries (should be installed on any linux system) 8 | * cargo and cargo-make to compile and install the project. Cargo comes installed with your typical Rust installation. Use `cargo install cargo-make` 9 | * Xnest to test the wm in a nested Xserver environment 10 | 11 | ## Usage ## 12 | * `cargo build` to build the project (`cargo build --release` to build it in a more optimized release mode) 13 | * `cargo make xnest` to build the project and test it in a nested X environment 14 | * `cargo make install` to build the project in release mode and install it in `/usr/local/bin`. This command will use sudo to copy the necessary files in `/usr/local/bin`, and therefore ask for your password. 15 | 16 | ## LICENSE ## 17 | This project is under the GNU GPLv3 license. See more in [LICENSE](LICENSE) 18 | 19 | ## Acknoledgements ## 20 | This project uses the [x11-rs](https://github.com/Daggerbot/x11-rs) bindings. Thanks to [Daggerbot](https://github.com/Daggerbot) ! 21 | -------------------------------------------------------------------------------- /src/drw/clrscheme.rs: -------------------------------------------------------------------------------- 1 | extern crate x11; 2 | 3 | use std::process; 4 | use std::ffi::CString; 5 | 6 | use x11::{ xlib, xft, xrender }; 7 | 8 | /** 9 | * Stores a color (wrapper around the xft::XftColor struct) 10 | */ 11 | pub struct Clr { 12 | pub pix: u64, 13 | pub rgb: xft::XftColor 14 | } 15 | 16 | /** 17 | * Creates a new color 18 | */ 19 | pub fn createClr(dpy: &mut xlib::Display, screen: i32, clrname: &str) -> Clr { 20 | let mut rgb = xft::XftColor { 21 | pixel: 0, 22 | color: xrender::XRenderColor { red: 0, green: 0, blue: 0, alpha: 0 } 23 | }; 24 | if unsafe { xft::XftColorAllocName(dpy, 25 | xlib::XDefaultVisual(dpy, screen), 26 | xlib::XDefaultColormap(dpy, screen), 27 | CString::new(clrname).unwrap().as_ptr(), 28 | &mut rgb) } == 0 { 29 | eprintln!("Error, cannot allocate color {:?}\n", clrname); 30 | process::exit(1) 31 | } 32 | Clr { 33 | pix: rgb.pixel, 34 | rgb: rgb 35 | } 36 | } 37 | 38 | /** 39 | * Stores a color scheme (foreground, background and border colors) 40 | */ 41 | pub struct ClrScheme { 42 | pub fg: Clr, 43 | pub bg: Clr, 44 | pub border: Clr 45 | } 46 | 47 | /** 48 | * Create a new colorScheme 49 | */ 50 | pub fn createClrScheme(fg: Clr, bg: Clr, border: Clr) -> ClrScheme { 51 | ClrScheme { 52 | fg, 53 | bg, 54 | border 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/drw/fnt.rs: -------------------------------------------------------------------------------- 1 | extern crate x11; 2 | 3 | use std::process; 4 | use std::ffi::CString; 5 | 6 | use x11::{ xlib, xft, xrender }; 7 | 8 | /** 9 | * Font extent (width and height) 10 | */ 11 | pub struct Extnts { 12 | pub w: u32, 13 | pub h: u32 14 | } 15 | 16 | /** 17 | * Stores a font (wrapper around xft::XftFont struct) 18 | */ 19 | pub struct Fnt { 20 | pub ascent: i32, 21 | pub descent: i32, 22 | pub h: u32, 23 | pub xfont: *mut xft::XftFont, 24 | pub pattern: *mut xft::FcPattern 25 | } 26 | 27 | impl PartialEq for Fnt { 28 | fn eq(&self, other: &Fnt) -> bool { 29 | self.xfont == other.xfont 30 | } 31 | } 32 | 33 | /** 34 | * Add a new font 35 | */ 36 | pub fn createFont(dpy: &mut xlib::Display, screen: i32, fontname: Option<&str>, fontpattern: Option) -> Option{ 37 | if let Some(ftn) = fontname { 38 | let ftn_c = CString::new(ftn).unwrap(); 39 | let xfont = unsafe { xft::XftFontOpenName(dpy, screen, ftn_c.as_ptr()) }; 40 | if xfont.is_null() { 41 | eprintln!("error, cannot load font: {:?}\n", fontname); 42 | None 43 | } else { 44 | let pattern = unsafe { xft::XftNameParse(ftn_c.as_ptr()) }; 45 | if pattern.is_null() { 46 | eprintln!("error, cannot load font: {:?}\n", fontname); 47 | None 48 | } else { 49 | unsafe { 50 | Some(Fnt { 51 | ascent: (*xfont).ascent, 52 | descent: (*xfont).descent, 53 | h: ((*xfont).ascent + (*xfont).descent) as u32, 54 | xfont: xfont, 55 | pattern: pattern 56 | }) 57 | } 58 | } 59 | } 60 | } else if let Some(mut ftp) = fontpattern { 61 | let xfont = unsafe { xft::XftFontOpenPattern(dpy, &mut ftp) }; 62 | if !xfont.is_null() { 63 | eprintln!("error, cannot load font pattern\n"); 64 | None 65 | } else { 66 | unsafe { 67 | Some(Fnt { 68 | ascent: (*xfont).ascent, 69 | descent: (*xfont).descent, 70 | h: ((*xfont).ascent + (*xfont).descent) as u32, 71 | xfont: xfont, 72 | pattern: &mut ftp 73 | }) 74 | } 75 | } 76 | } else { 77 | eprintln!("no font specified\n"); 78 | process::exit(1); 79 | } 80 | } 81 | 82 | /** 83 | * Destructor (frees xfont) 84 | */ 85 | pub fn freeFnt(fnt: Fnt, dpy: &mut xlib::Display) { 86 | unsafe { xft::XftFontClose(dpy, fnt.xfont) }; 87 | } 88 | 89 | pub fn getexts(fnt: &Fnt, dpy: &mut xlib::Display, text: Vec, tex: &mut Extnts) { 90 | let mut ext = xrender::XGlyphInfo { // Dummy value 91 | height: 0, width: 0, x: 0, y: 0, xOff: 0, yOff: 0 92 | }; 93 | unsafe { xft::XftTextExtentsUtf8(dpy, fnt.xfont, text.as_ptr(), text.len() as i32, &mut ext) } 94 | tex.h = fnt.h; 95 | tex.w = ext.xOff as u32; 96 | } 97 | 98 | // pub fn getexts_width(&mut self, dpy: &mut xlib::Display, text: Vec) -> u32 { 99 | // let mut tex = Extnts { // Dummy value 100 | // w: 0, h: 0 101 | // }; 102 | // self.getexts(dpy, text, &mut tex); 103 | // tex.w 104 | // } 105 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "cc" 3 | version = "1.0.15" 4 | source = "registry+https://github.com/rust-lang/crates.io-index" 5 | 6 | [[package]] 7 | name = "cmake" 8 | version = "0.1.31" 9 | source = "registry+https://github.com/rust-lang/crates.io-index" 10 | dependencies = [ 11 | "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", 12 | ] 13 | 14 | [[package]] 15 | name = "dwm-rust" 16 | version = "0.1.0" 17 | dependencies = [ 18 | "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", 19 | "servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 20 | "x11 2.17.5 (registry+https://github.com/rust-lang/crates.io-index)", 21 | ] 22 | 23 | [[package]] 24 | name = "expat-sys" 25 | version = "2.1.5" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | dependencies = [ 28 | "cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", 29 | "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 30 | ] 31 | 32 | [[package]] 33 | name = "libc" 34 | version = "0.2.40" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | 37 | [[package]] 38 | name = "pkg-config" 39 | version = "0.3.9" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | 42 | [[package]] 43 | name = "servo-fontconfig" 44 | version = "0.4.0" 45 | source = "registry+https://github.com/rust-lang/crates.io-index" 46 | dependencies = [ 47 | "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", 48 | "servo-fontconfig-sys 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 49 | ] 50 | 51 | [[package]] 52 | name = "servo-fontconfig-sys" 53 | version = "4.0.4" 54 | source = "registry+https://github.com/rust-lang/crates.io-index" 55 | dependencies = [ 56 | "expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 57 | "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 58 | "servo-freetype-sys 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 59 | ] 60 | 61 | [[package]] 62 | name = "servo-freetype-sys" 63 | version = "4.0.3" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | dependencies = [ 66 | "cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", 67 | "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 68 | ] 69 | 70 | [[package]] 71 | name = "x11" 72 | version = "2.17.5" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | dependencies = [ 75 | "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", 76 | "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 77 | ] 78 | 79 | [metadata] 80 | "checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba" 81 | "checksum cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "95470235c31c726d72bf2e1f421adc1e65b9d561bf5529612cbe1a72da1467b3" 82 | "checksum expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c470ccb972f2088549b023db8029ed9da9426f5affbf9b62efff7009ab8ed5b1" 83 | "checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" 84 | "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" 85 | "checksum servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a088f8d775a5c5314aae09bd77340bc9c67d72b9a45258be34c83548b4814cd9" 86 | "checksum servo-fontconfig-sys 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "38b494f03009ee81914b0e7d387ad7c145cafcd69747c2ec89b0e17bb94f303a" 87 | "checksum servo-freetype-sys 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9232032c2e85118c0282c6562c84cab12316e655491ba0a5d1905b2320060d1b" 88 | "checksum x11 2.17.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a86db9d61a3697ded72bb068b4b641a752aaba77a6ce569827bc7e97dc4c5b" 89 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use x11::xlib; 2 | use x11::keysym::*; 3 | 4 | use { Layout, Key, Button, Arg }; 5 | use wm::workspace::{ tileArrange, monocleArrange, noArrange, gridArrange }; 6 | use { spawn, quit, changeWs, moveClientToWs, closeClient }; 7 | 8 | /// Fonts (the first one available is used) 9 | pub const fonts: [&str; 1] = ["Fixed:size=11"]; 10 | 11 | pub const normbordercolor: &str = "#444444"; 12 | pub const normbgcolor: &str = "#222222"; 13 | pub const normfgcolor: &str = "#bbbbbb"; 14 | pub const selbordercolor: &str = "#005577"; 15 | pub const selbgcolor: &str = "#005577"; 16 | pub const selfgcolor: &str = "#eeeeee"; 17 | /// Background color 18 | pub const backgroundColor: u64 = 0x00aa00; 19 | /// Size (in pixels) of window borders 20 | pub const borderpx: u32 = 2; 21 | /// Snap pixel 22 | pub const snap: u32 = 32; 23 | /// Show the status bar (false means no bar) 24 | pub const showbar: bool = true; 25 | /// Show the status bar on top (false means bottom) 26 | pub const topbar: bool = true; 27 | // Bar time formatting 28 | pub const timeFormat: &str = "%H:%M:%S - %d %b %Y"; 29 | 30 | /// Ratio of master area to stack area width 31 | pub const mfact: f32 = 0.5; 32 | /// Maximum number of clients in the master area 33 | pub const nmaster: u32 = 1; 34 | 35 | /// Layouts 36 | pub const layouts: [Layout; 4] = [ 37 | Layout { symbol: "[]=", arrange: tileArrange }, 38 | Layout { symbol: "[M]", arrange: monocleArrange }, 39 | Layout { symbol: "><>", arrange: noArrange }, 40 | Layout { symbol: "HHH", arrange: gridArrange } 41 | ]; 42 | 43 | /// Tags 44 | pub const tags: [&str; 9] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; 45 | 46 | /// Modifier key for key controls; Mod4Mask by default 47 | pub const MODKEY: u32 = xlib::Mod4Mask; 48 | 49 | /// Key combinations and their actions 50 | pub const keys: [Key; 25] = [ 51 | // modifier key function argument 52 | Key { modif:MODKEY, keysym:XK_Return as u64, func:spawn, arg:Arg {s: "terminator"}}, 53 | Key { modif:MODKEY, keysym:XK_d as u64, func:spawn, arg:Arg {s: "rofi -show run"}}, 54 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_e as u64, func:quit, arg:Arg {i: 0}}, 55 | 56 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_q as u64, func:closeClient, arg:Arg {i: 0}}, 57 | 58 | // Change WS 59 | Key { modif:MODKEY, keysym:XK_1 as u64, func:changeWs, arg:Arg {u: 1}}, 60 | Key { modif:MODKEY, keysym:XK_2 as u64, func:changeWs, arg:Arg {u: 2}}, 61 | Key { modif:MODKEY, keysym:XK_3 as u64, func:changeWs, arg:Arg {u: 3}}, 62 | Key { modif:MODKEY, keysym:XK_4 as u64, func:changeWs, arg:Arg {u: 4}}, 63 | Key { modif:MODKEY, keysym:XK_5 as u64, func:changeWs, arg:Arg {u: 5}}, 64 | Key { modif:MODKEY, keysym:XK_6 as u64, func:changeWs, arg:Arg {u: 6}}, 65 | Key { modif:MODKEY, keysym:XK_7 as u64, func:changeWs, arg:Arg {u: 7}}, 66 | Key { modif:MODKEY, keysym:XK_8 as u64, func:changeWs, arg:Arg {u: 8}}, 67 | Key { modif:MODKEY, keysym:XK_9 as u64, func:changeWs, arg:Arg {u: 9}}, 68 | 69 | // Move window to WS 70 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_1 as u64, func:moveClientToWs, arg:Arg {u: 1}}, 71 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_2 as u64, func:moveClientToWs, arg:Arg {u: 2}}, 72 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_3 as u64, func:moveClientToWs, arg:Arg {u: 3}}, 73 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_4 as u64, func:moveClientToWs, arg:Arg {u: 4}}, 74 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_5 as u64, func:moveClientToWs, arg:Arg {u: 5}}, 75 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_6 as u64, func:moveClientToWs, arg:Arg {u: 6}}, 76 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_7 as u64, func:moveClientToWs, arg:Arg {u: 7}}, 77 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_8 as u64, func:moveClientToWs, arg:Arg {u: 8}}, 78 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XK_9 as u64, func:moveClientToWs, arg:Arg {u: 9}}, 79 | 80 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XF86XK_AudioLowerVolume as u64, func:spawn, arg:Arg {s: "amixer -q sset 'Master' 5%-"}}, 81 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XF86XK_AudioRaiseVolume as u64, func:spawn, arg:Arg {s: "amixer -q sset 'Master' 5%+"}}, 82 | Key { modif:MODKEY|xlib::ShiftMask, keysym:XF86XK_AudioMute as u64, func:spawn, arg:Arg {s: "amixer -q sset 'Master' "}}, 83 | ]; 84 | 85 | /// Buttons and their actions 86 | pub const buttons: [Button; 0] = [ 87 | 88 | ]; 89 | 90 | /// Commands to execute at start of the wm 91 | pub const startCmds: [&str; 2] = [ 92 | "feh --bg-scale /home/vertmo/Images/Wallpapers/botw.png", 93 | "statusbar" 94 | ]; 95 | -------------------------------------------------------------------------------- /src/events.rs: -------------------------------------------------------------------------------- 1 | 2 | use std::ptr; 3 | 4 | use x11::xlib; 5 | 6 | use wm; 7 | use wm::WM; 8 | use wm::client; 9 | 10 | use config; 11 | 12 | /** 13 | * Handles an event 14 | */ 15 | pub fn handleEvent<'a>(wm: WM<'a>, ev: &xlib::XEvent) -> WM<'a> { 16 | unsafe { 17 | match ev.type_ { 18 | xlib::ConfigureRequest => configureRequest(wm, ev), 19 | xlib::ConfigureNotify => configureNotify(wm, ev), 20 | //xlib::EnterNotify => enternotify(wm, ev), 21 | xlib::DestroyNotify => destroyNotify(wm, ev), 22 | xlib::KeyPress => keyPress(wm, ev), 23 | xlib::ButtonPress => buttonPress(wm, ev), 24 | xlib::MapRequest => mapRequest(wm, ev), 25 | xlib::PropertyNotify => propertyNotify(wm, ev), 26 | // TODO : les autres handlers 27 | _ => wm 28 | } 29 | } 30 | } 31 | 32 | /** 33 | * Handles a ConfigureRequest event : before changing the configuration of a window 34 | */ 35 | pub fn configureRequest<'a>(wm: WM<'a>, e: &xlib::XEvent) -> WM<'a> { 36 | let ev = unsafe { e.configure_request }; 37 | if let Some(c) = client::findFromWindow(ev.window, &wm.wss) { 38 | client::configure(c, wm.drw.dpy); 39 | } else { 40 | let mut wc = xlib::XWindowChanges { 41 | x: ev.x, y: ev.y, 42 | width: ev.width, height: ev.height, 43 | border_width: ev.border_width, 44 | sibling: ev.above, 45 | stack_mode: ev.detail 46 | }; 47 | unsafe { xlib::XConfigureWindow(wm.drw.dpy, ev.window, ev.value_mask as u32, &mut wc) }; 48 | } 49 | unsafe { xlib::XSync(wm.drw.dpy, 0) }; 50 | wm 51 | } 52 | 53 | /** 54 | * Handles a ConfigureNotify event : after reconfiguration of a window 55 | */ 56 | pub fn configureNotify<'a>(wm : WM<'a>, e: &xlib::XEvent) -> WM<'a> { 57 | let _ev = unsafe { e.configure }; 58 | // TODO 59 | wm::updateStatus(wm) 60 | } 61 | 62 | // /** 63 | // * Handles an EnterNotify event 64 | // */ 65 | // pub fn enternotify(wm: &mut WM, e: &xlib::XEvent) { 66 | // let ev = unsafe { e.crossing }; 67 | // if (ev.mode != xlib::NotifyNormal || ev.detail == xlib::NotifyInferior) && ev.window != wm.root { 68 | // return; 69 | // } 70 | // let mut c = Client::from(ev.window, &wm.mons); 71 | // let m = if let Some(ref mut cl) = c { 72 | // &wm.mons[cl.monindex] 73 | // } else { 74 | // Workspace::from_window(ev.window, wm.root, &wm.mons, &wm.mons[wm.selmonindex]) 75 | // }; 76 | // if m != &wm.mons[wm.selmonindex] { 77 | // // unfocus(selmon.sel, true); TODO 78 | // wm.selmonindex = m.num as usize; 79 | // } else { 80 | // let mut c = Client::from(ev.window, &wm.mons); 81 | // let selmon = &wm.mons[wm.selmonindex]; 82 | // match (c, selmon.sel) { 83 | // (None, _) => return, 84 | // (Some(cl), Some(sel)) => if cl == sel { return }, 85 | // _ => () 86 | // } 87 | // } 88 | // if let Some(cl) = c { 89 | // // focus(cl); TODO 90 | // } 91 | // } 92 | 93 | /** 94 | * Handles Window destruction 95 | */ 96 | pub fn destroyNotify<'a>(wm: WM<'a>, e: &xlib::XEvent) -> WM<'a> { 97 | let ev = unsafe { e.destroy_window }; 98 | wm::updateStatus(wm::unManage(wm, ev.window)) 99 | } 100 | 101 | fn cleanmask(mask: u32) -> u32 { 102 | mask 103 | } 104 | 105 | /** 106 | * Handles a KeyPress event 107 | */ 108 | pub fn keyPress<'a>(wm: WM<'a>, e: &xlib::XEvent) -> WM<'a> { 109 | let ev = unsafe { e.key }; 110 | let keysym = unsafe { xlib::XKeycodeToKeysym(wm.drw.dpy, ev.keycode as u8, 0) }; 111 | for i in 0..config::keys.len() { 112 | if keysym == config::keys[i].keysym 113 | && cleanmask(ev.state) == cleanmask(config::keys[i].modif) { 114 | let func = config::keys[i].func; 115 | return func(&config::keys[i].arg, wm); 116 | } 117 | } 118 | wm 119 | } 120 | 121 | /** 122 | * Handles a button press 123 | */ 124 | pub fn buttonPress<'a>(wm: WM<'a>, e: &xlib::XEvent) -> WM<'a> { 125 | let _ev = unsafe { e.button }; 126 | // TODO 127 | wm 128 | } 129 | 130 | /** 131 | * Handles a MapRequest event 132 | */ 133 | pub fn mapRequest<'a>(wm: WM<'a>, e: &xlib::XEvent) -> WM<'a> { 134 | let ev = unsafe { e.map_request }; 135 | let mut wa = xlib::XWindowAttributes { // Dummy value 136 | x: 0, y: 0, width: 0, height: 0, border_width: 0, depth: 0, visual: ptr::null_mut(), root: wm.root, class: 0, bit_gravity: 0, win_gravity: 0, backing_store: 0, backing_planes: 0, backing_pixel: 0, save_under: 0, colormap: 0, map_installed: 0, map_state: 0, all_event_masks: 0, your_event_mask: 0, do_not_propagate_mask: 0, override_redirect: 0, screen: ptr::null_mut() 137 | }; 138 | if unsafe { xlib::XGetWindowAttributes(wm.drw.dpy, ev.window, &mut wa) } == 0 || wa.override_redirect != 0 { 139 | wm 140 | } else if client::findFromWindow(ev.window, &wm.wss) == None { 141 | return wm::manage(wm, ev.window, wa); 142 | } else { 143 | wm 144 | } 145 | } 146 | 147 | /** 148 | * Handles a Property Notify event 149 | */ 150 | pub fn propertyNotify<'a>(wm: WM<'a>, e: &xlib::XEvent) -> WM<'a> { 151 | let ev = unsafe { e.property }; 152 | if ev.window == wm.root { wm::updateStatus(wm) } else { wm } 153 | } 154 | -------------------------------------------------------------------------------- /src/drw/mod.rs: -------------------------------------------------------------------------------- 1 | extern crate x11; 2 | extern crate libc; 3 | 4 | use std::ptr; 5 | 6 | use x11::{ xlib, xft }; 7 | 8 | pub mod clrscheme; 9 | pub mod fnt; 10 | 11 | use self::clrscheme::ClrScheme; 12 | use self::fnt::Fnt; 13 | 14 | /** 15 | * Stores a cursor (wrapper around xlib::Cursor) 16 | */ 17 | pub struct Cur { 18 | pub cursor: xlib::Cursor 19 | } 20 | 21 | /** 22 | * Creates a new cursor for a drawable area 23 | */ 24 | pub fn createCur(drw: &mut Drw, shape: u32) -> Cur { 25 | Cur { 26 | cursor: unsafe { xlib::XCreateFontCursor(drw.dpy, shape)} 27 | } 28 | } 29 | 30 | /** 31 | * Stores a drawble area (related to a Display) 32 | */ 33 | pub struct Drw<'a> { 34 | pub w: u32, 35 | pub h: u32, 36 | pub dpy: &'a mut xlib::Display, 37 | pub screen: i32, 38 | root: xlib::Window, 39 | drawable: xlib::Drawable, 40 | gc: xlib::GC, 41 | scheme: *const ClrScheme, 42 | pub fonts: Vec 43 | } 44 | 45 | /** 46 | * Creates a drawable area for a display 47 | */ 48 | pub fn createDrw(dpy: &mut xlib::Display, screen: i32, root: xlib::Window, w: u32, h:u32) -> Drw { 49 | let mut drw = Drw { 50 | dpy, 51 | screen, 52 | root, 53 | w, 54 | h, 55 | drawable: 0, 56 | gc: ptr::null_mut(), 57 | fonts: Vec::new(), 58 | scheme: ptr::null_mut() 59 | }; 60 | drw.drawable = unsafe { xlib::XCreatePixmap(drw.dpy, root, w, h, xlib::XDefaultDepth(drw.dpy, screen) as u32) }; 61 | drw.gc = unsafe { xlib::XCreateGC(drw.dpy, root, 0, ptr::null_mut()) }; 62 | drw 63 | } 64 | 65 | // /** 66 | // * Destructor 67 | // */ 68 | // pub fn freeDrw(&mut self) { 69 | // for f in &mut self.fonts { 70 | // f.free(self.dpy); 71 | // } 72 | // unsafe { 73 | // xlib::XFreePixmap(self.dpy, self.drawable); 74 | // xlib::XFreeGC(self.dpy, self.gc); 75 | // } 76 | // } 77 | 78 | /** 79 | * Changes the color scheme 80 | */ 81 | pub fn setScheme<'a>(drw: Drw<'a>, scheme: &ClrScheme) -> Drw<'a> { 82 | Drw { scheme, ..drw } 83 | } 84 | 85 | /** 86 | * Loads fonts 87 | */ 88 | pub fn loadFonts<'a>(mut drw: Drw<'a>, fontnames: Vec<&str>) -> Drw<'a> { 89 | for f in fontnames { 90 | if let Some(font) = fnt::createFont(drw.dpy, drw.screen, Some(f), None) { 91 | drw.fonts.push(font); 92 | } 93 | } 94 | drw 95 | } 96 | 97 | /** 98 | * Draws a rectangle 99 | */ 100 | pub fn rect(drw: Drw, x: i32, y: i32, w: u32, h: u32, filled: bool, invert: bool) -> Drw { 101 | let s = drw.scheme; 102 | if !s.is_null() { 103 | if invert { 104 | unsafe { xlib::XSetForeground(drw.dpy, drw.gc, (*s).bg.pix) }; 105 | } else { 106 | unsafe { xlib::XSetForeground(drw.dpy, drw.gc, (*s).fg.pix) }; 107 | } 108 | 109 | if filled { 110 | unsafe { xlib::XFillRectangle(drw.dpy, drw.drawable, drw.gc, x, y, w + 1, h + 1) }; 111 | } else { 112 | unsafe { xlib::XDrawRectangle(drw.dpy, drw.drawable, drw.gc, x, y, w, h) }; 113 | } 114 | } 115 | drw 116 | } 117 | 118 | /** 119 | * Draws text, and returns text width 120 | */ 121 | pub fn text<'a>(drw: Drw<'a>, mut x: i32, y: i32, mut w:u32, h:u32, text: &str, invert: bool) -> (Drw<'a>, i32) { 122 | let s = drw.scheme; 123 | let mut d = ptr::null_mut(); 124 | if !s.is_null() { 125 | if drw.fonts.len() > 0 { 126 | let render = x!= 0 || y != 0 || w != 0 || h != 0; 127 | if !render { 128 | w = !w; 129 | } else { 130 | if invert { 131 | unsafe { xlib::XSetForeground(drw.dpy, drw.gc, (*s).fg.pix) }; 132 | } else { 133 | unsafe { xlib::XSetForeground(drw.dpy, drw.gc, (*s).bg.pix) }; 134 | } 135 | unsafe { xlib::XFillRectangle(drw.dpy, drw.drawable, drw.gc, x, y, w, h) }; 136 | d = unsafe { xft:: XftDrawCreate(drw.dpy, drw.drawable, xlib::XDefaultVisual(drw.dpy, drw.screen), xlib::XDefaultColormap(drw.dpy, drw.screen)) }; 137 | } 138 | 139 | let curfont = &drw.fonts[0]; 140 | let mut charexists = false; 141 | let mut tex = fnt::Extnts { // Dummy value 142 | w: 0, h: 0 143 | }; 144 | loop { 145 | let utf8str = text.as_bytes(); 146 | fnt::getexts(curfont, drw.dpy, utf8str.to_vec(), &mut tex); 147 | 148 | if render { 149 | let th = curfont.ascent + curfont.descent; 150 | let ty = y + (h / 2) as i32 - (th / 2) + curfont.ascent; 151 | let tx = x + (h / 2) as i32; 152 | if invert { 153 | unsafe { xft::XftDrawStringUtf8(d, &(*s).bg.rgb, curfont.xfont, tx, ty, utf8str.as_ptr(), utf8str.len() as i32) }; 154 | } else { 155 | unsafe { xft::XftDrawStringUtf8(d, &(*s).fg.rgb, curfont.xfont, tx, ty, utf8str.as_ptr(), utf8str.len() as i32) }; 156 | } 157 | } 158 | x += tex.w as i32; 159 | w -= tex.w; 160 | 161 | if !charexists /* || nextfont != curfont*/ { 162 | break; 163 | } else { 164 | charexists = false; 165 | } 166 | } 167 | } 168 | } 169 | if !d.is_null() { 170 | unsafe { xft::XftDrawDestroy(d) }; 171 | } 172 | (drw, x) 173 | } 174 | 175 | /** 176 | * Width of a text 177 | */ 178 | pub fn textw<'a>(s: &str, drw: Drw<'a>) -> (Drw<'a>, u32) { 179 | let (drw, w) = text(drw, 0, 0, 0, 0, s, false); 180 | let h = drw.fonts[0].h; 181 | (drw, w as u32 + h) 182 | } 183 | 184 | /** 185 | * Draws content from a Window on the screen 186 | */ 187 | pub fn mapWindow(drw: Drw, win: xlib::Window, x: i32, y: i32, w: u32, h: u32) -> Drw { 188 | unsafe { 189 | xlib::XCopyArea(drw.dpy, drw.drawable, win, drw.gc, x, y, w, h, x, y); 190 | xlib::XSync(drw.dpy, 0); 191 | } 192 | drw 193 | } 194 | -------------------------------------------------------------------------------- /src/wm/workspace.rs: -------------------------------------------------------------------------------- 1 | extern crate x11; 2 | 3 | use x11::xlib; 4 | 5 | use client; 6 | use { Client, Pertag }; 7 | use { SCHEMENORM, SCHEMESEL }; 8 | use drw; 9 | use drw::Drw; 10 | use drw::clrscheme::ClrScheme; 11 | use config; 12 | 13 | /// Arrange functions 14 | pub fn tileArrange(mut ws: Workspace) -> Workspace { 15 | let n = ws.clients.len() as u32; 16 | let x = minX(&ws); let y = minY(&ws); let w = maxW(&ws); let h = maxH(&ws); 17 | if n == 1 { // If there is only one window 18 | Workspace { 19 | clients: vec! [client::setGeom(ws.clients.remove(0), x, y, w, h)], 20 | ..ws 21 | } 22 | } else if n > 1 { 23 | let w = w/n; 24 | Workspace { 25 | clients: ws.clients.into_iter().enumerate().map(|(i, c)| { client::setGeom(c, x+(i as i32 * w as i32), y, w, h) }).collect(), 26 | ..ws 27 | } 28 | } else { 29 | ws 30 | } 31 | } 32 | 33 | pub fn monocleArrange(ws: Workspace) -> Workspace { 34 | // TODO 35 | ws 36 | } 37 | 38 | pub fn noArrange(ws: Workspace) -> Workspace { 39 | ws // Nothing 40 | } 41 | 42 | pub fn gridArrange(ws: Workspace) -> Workspace { 43 | // TODO 44 | ws 45 | } 46 | 47 | /** 48 | * Stores a layout 49 | */ 50 | pub struct Layout<'a> { 51 | pub symbol: &'a str, 52 | pub arrange: fn (Workspace) -> Workspace 53 | } 54 | 55 | /** 56 | * Stores a monitor 57 | */ 58 | pub struct Workspace<'a> { 59 | pub mfact: f32, 60 | pub nmaster: u32, 61 | pub num: i32, 62 | pub tag: &'a str, 63 | pub by: i32, pub bh: u32, // Y position and height of bar 64 | pub x: i32, pub y: i32, pub w: u32, pub h: u32, // Workspace 65 | pub seltags: u32, 66 | pub sellt: u32, 67 | pub tagset: Vec, 68 | pub showbar: bool, 69 | pub topbar: bool, 70 | pub clients: Vec>, 71 | pub barwin: xlib::Window, 72 | pub lt: Layout<'a>, 73 | pub pertag: Pertag<'a> 74 | } 75 | 76 | impl<'a> PartialEq for Workspace<'a> { 77 | fn eq(&self, other: &Workspace<'a>) -> bool { 78 | self.num == other.num 79 | } 80 | } 81 | 82 | /** 83 | * Creates a new monitor 84 | */ 85 | pub fn createWorkspace<'a>(tag: &'a str) -> Workspace<'a> { 86 | let mut mon = Workspace { 87 | mfact: config::mfact, 88 | nmaster: config::nmaster, 89 | num: 0, 90 | tag, 91 | by: 0, bh: 0, 92 | x: 0, y: 0, w: 0, h: 0, 93 | seltags: 0, 94 | sellt: 0, 95 | tagset: Vec::new(), 96 | showbar: config::showbar, 97 | topbar: config::topbar, 98 | clients: Vec::new(), 99 | barwin: 0, 100 | lt: Layout { symbol: &config::layouts[0].symbol, arrange: config::layouts[0].arrange }, 101 | pertag: Pertag { 102 | curtag: 1, 103 | prevtag: 1, 104 | nmasters: Vec::new(), 105 | mfacts: Vec::new(), 106 | selltds: Vec::new(), 107 | ltidxs: Vec::new(), 108 | showbars: Vec::new(), 109 | prefzooms: Vec::new() 110 | } 111 | }; 112 | mon.tagset.push(1); mon.tagset.push(1); 113 | mon 114 | // TODO tags 115 | } 116 | 117 | // /** 118 | // * Finds the Workspace a Window is on 119 | // */ 120 | // pub fn from_window(w: xlib::Window, root: xlib::Window, mons: &'a Vec>, selmon: &'a Workspace<'a>) -> &'a Workspace<'a> { 121 | // if w == root && true /* TODO */ { 122 | // return Workspace::from_rect(0, 0, 1, 1, mons, selmon); 123 | // } 124 | // // TODO 125 | // if let Some(c) = Client::from(w, mons) { 126 | // return &mons[c.monindex]; 127 | // } 128 | // selmon 129 | // } 130 | 131 | pub fn minX(ws: &Workspace) -> i32 { ws.x } 132 | 133 | pub fn maxW(ws: &Workspace) -> u32 { ws.w } 134 | 135 | pub fn minY(ws : &Workspace) -> i32 { 136 | if ws.showbar && ws.topbar { ws.bh as i32} else { ws.y } 137 | } 138 | 139 | pub fn maxH(ws: &Workspace) -> u32 { 140 | let m = if ws.showbar { ws.h - ws.bh as u32 } else { ws.h }; 141 | m 142 | } 143 | 144 | /** 145 | * Updates the position of the statusbar for this Workspace 146 | */ 147 | pub fn updateBarPos(ws: Workspace, bh: u32) -> Workspace { 148 | if ws.showbar { 149 | return Workspace { 150 | by: if ws.topbar { ws.y } else { (ws.h as i32) - (bh as i32)}, 151 | bh, 152 | ..ws 153 | }; 154 | } 155 | Workspace { 156 | by: -(bh as i32), 157 | bh, 158 | ..ws 159 | } 160 | } 161 | 162 | /** 163 | * Draws the statusbar 164 | */ 165 | pub fn drawBar<'a>(drw: Drw<'a>, bh: u32, scheme: &Vec, wss: &Vec, selmonindex: usize, stext: &str) -> Drw<'a> { 166 | let w = drw.w; 167 | let drw = drw::rect(drw::setScheme(drw, &scheme[SCHEMENORM]), 0, 0, w, bh, true, true); 168 | let dx: u32 = ((drw.fonts[0].ascent + drw.fonts[0].descent + 2) / 4) as u32; 169 | let occ = 0; 170 | let urg = 0; 171 | // for mut c in self.clients.iter() { 172 | // occ = occ|c.tags; 173 | // if c.isurgent { 174 | // urg = urg|c.tags 175 | // } 176 | // } 177 | 178 | // Draw list of workspaces, with their tags 179 | let (drw, _) = wss.iter().enumerate().fold((drw, 0), |(drw, x), (i, ws)| { 180 | let (drw, w) = drw::textw(ws.tag, drw); 181 | let (drw, _) = drw::text(if i == selmonindex { drw::setScheme(drw, &scheme[SCHEMESEL]) } 182 | else { drw::setScheme(drw, &scheme[SCHEMENORM]) }, 183 | x, 1, w, bh, ws.tag, urg & (1 << i) != 0); 184 | let drw = if ws.clients.len() > 0 { 185 | drw::rect(drw, x + 1, 1, dx, dx, i == selmonindex, occ & (1 << i) != 0) 186 | } 187 | else { drw }; 188 | (drw, x + w as i32) 189 | }); 190 | 191 | // Show status text on right of the bar 192 | let (drw, w) = drw::textw(&stext, drw); 193 | let bw = drw.w as i32; 194 | let (drw, _) = drw::text(drw::setScheme(drw, &scheme[SCHEMENORM]), bw - (w as i32), 1, w, bh, &stext, false); 195 | 196 | // Map the window 197 | let w = drw.w; 198 | drw::mapWindow(drw, wss[selmonindex].barwin, 0, 0, w, bh) // C'est la que ca crashe : self.ww = 0 ? 199 | } 200 | 201 | /** 202 | * Adds a Client to this Workspace 203 | */ 204 | pub fn addClient<'a>(ws: &'a mut Workspace<'a>, c: Client<'a>) { 205 | ws.clients.insert(0, c); 206 | } 207 | 208 | /** 209 | * Removes a Client from this Workspace, returning it 210 | */ 211 | pub fn removeClient<'a>(ws: &mut Workspace<'a>, c: &Client<'a>) -> Option> { 212 | for i in 0..ws.clients.len() { 213 | if &ws.clients[i] == c { 214 | let cl = ws.clients.remove(i); 215 | return Some(cl); 216 | } 217 | } 218 | None 219 | } 220 | 221 | /** 222 | * Updates geometry of the Workspace 223 | */ 224 | pub fn updateGeom<'a>(ws: Workspace<'a>, dpy: &mut xlib::Display) -> Workspace<'a> { 225 | let arrange = ws.lt.arrange; 226 | let ws = arrange(ws); 227 | for c in ws.clients.iter() { 228 | client::configure(c, dpy); 229 | } 230 | ws 231 | } 232 | 233 | /** 234 | * Draws all the windows in this workspace 235 | */ 236 | pub fn showAllClients(ws: &Workspace, dpy: &mut xlib::Display) { 237 | for c in ws.clients.iter() { client::show(c, dpy); } 238 | } 239 | 240 | /** 241 | * Draws all the windows in this workspace 242 | */ 243 | pub fn hideAllClients(ws: &Workspace, dpy: &mut xlib::Display) { 244 | for c in ws.clients.iter() { client::hide(c, dpy); } 245 | } 246 | -------------------------------------------------------------------------------- /src/wm/client.rs: -------------------------------------------------------------------------------- 1 | extern crate x11; 2 | 3 | use x11::xlib; 4 | 5 | use wm::workspace::Workspace; 6 | use config; 7 | 8 | /** 9 | * Stores a Client (wrapper around the xlib::Window struct) 10 | */ 11 | pub struct Client<'a> { 12 | pub name: &'a str, 13 | pub mina: f32, pub maxa: f32, 14 | pub x: i32, pub y: i32, pub w: u32, pub h: u32, 15 | pub bw: u32, 16 | pub wsindex: usize, 17 | pub tags: u32, 18 | pub isfixed: bool, pub isfloating: bool, pub isurgent: bool, pub neverfocus: bool, pub oldwm:bool, pub isfullscreen: bool, pub oldstate: bool, 19 | pub win: xlib::Window 20 | } 21 | 22 | impl<'a> PartialEq for Client<'a> { 23 | fn eq(&self, other: &Client<'a>) -> bool { 24 | self.win == other.win 25 | } 26 | } 27 | 28 | /** 29 | * Create a new client from a window ant it's attributes 30 | */ 31 | pub fn createClient<'a>(win: xlib::Window, wa: xlib::XWindowAttributes, wsindex: usize) -> Client<'a> { 32 | Client { 33 | name: "", 34 | mina: 0.0, maxa: 0.0, 35 | x: wa.x, y: wa.y, w: wa.width as u32, h: wa.height as u32, 36 | bw: config::borderpx, 37 | wsindex, 38 | tags: 0, 39 | isfixed: false, isfloating: false, isurgent: false, neverfocus: false, oldwm: false, isfullscreen: false, oldstate: false, 40 | win 41 | } 42 | } 43 | 44 | /** 45 | * Finds the Client containing a Window 46 | */ 47 | pub fn findFromWindow<'a>(window : xlib::Window, mons: &'a Vec>) -> Option<&'a Client<'a>> { 48 | for m in mons.iter() { 49 | for c in m.clients.iter() { 50 | if c.win == window { 51 | return Some(c) 52 | } 53 | } 54 | } 55 | None 56 | } 57 | 58 | /** 59 | * Total width of the window (including borders) 60 | */ 61 | pub fn width(client: &Client) -> u32 { 62 | client.w + 2 * client.bw 63 | } 64 | 65 | /** 66 | * Total height of the window (including borders) 67 | */ 68 | pub fn height(client: &Client) -> u32 { 69 | client.h + 2 * client.bw 70 | } 71 | 72 | /** 73 | * Sets the window x, y, width and height (use total width and height, including bar width) 74 | */ 75 | pub fn setGeom(c: Client, x:i32, y:i32, w: u32, h: u32) -> Client { 76 | Client { 77 | x, 78 | y, 79 | w: w - c.bw*2, 80 | h: h - c.bw*2, 81 | ..c 82 | } 83 | } 84 | 85 | /** 86 | * Change configuration of the window : sends a Configure event 87 | */ 88 | pub fn configure<'a>(c: &'a Client<'a>, dpy: &mut xlib::Display) { 89 | let mut wc = xlib::XWindowChanges { 90 | x: c.x, y: c.y, 91 | width: c.w as i32, height: c.h as i32, 92 | border_width: c.bw as i32, 93 | sibling: 0, 94 | stack_mode: 0 95 | }; 96 | unsafe { xlib::XConfigureWindow(dpy, c.win, 0b11111, &mut wc) }; 97 | } 98 | 99 | /** 100 | * Draws the Window on the screen 101 | */ 102 | pub fn show(c: &Client, dpy: &mut xlib::Display) { 103 | unsafe { xlib::XMapWindow(dpy, c.win) }; 104 | } 105 | 106 | /** 107 | * Hides the Window from the screen 108 | */ 109 | pub fn hide(c: &Client, dpy: &mut xlib::Display) { 110 | unsafe { xlib::XUnmapWindow(dpy, c.win) }; 111 | } 112 | 113 | /** 114 | * Destroys the Window and frees the client 115 | */ 116 | pub fn destroyClient(c: Client, dpy: &mut xlib::Display) { 117 | unsafe { xlib::XDestroyWindow(dpy, c.win) }; 118 | } 119 | 120 | /* 121 | * Set the window to fullscreen (or not) 122 | */ 123 | // pub fn setfullscreen(client: &Client, dpy: &mut xlib::Display, fullscreen: bool, netatom: &Vec) { 124 | // println!("dwm-rust : full screen !"); 125 | // if fullscreen && !self.isfullscreen { 126 | // unsafe { xlib::XChangeProperty(dpy, self.win, netatom[NETWMSTATE], xlib::XA_ATOM, 32, xlib::PropModeReplace, &(netatom[NETWMFULLSCREEN] as u8), 1) }; 127 | // self.isfullscreen = true; 128 | // self.oldstate = self.isfloating; 129 | // self.oldbw = self.bw; 130 | // self.isfloating = true; 131 | // // self.resize(self.mon.mx, self.mon.my, self.mon.mw, self.mon.mh); TODO 132 | // unsafe { xlib::XRaiseWindow(dpy, self.win) }; 133 | // } else if !fullscreen && self.isfullscreen { 134 | // unsafe { xlib::XChangeProperty(dpy, self.win, netatom[NETWMSTATE], xlib::XA_ATOM, 32, xlib::PropModeReplace, &0, 0) }; 135 | // self.isfullscreen = false; 136 | // self.isfloating = self.oldstate; 137 | // self.bw = self.oldbw; 138 | // self.x = self.oldx; 139 | // self.y = self.oldy; 140 | // self.w = self.oldw; 141 | // self.h = self.oldh; 142 | // // self.resize(self.x, self.y, self.w, self.h); TODO 143 | // // self.mon.arrange(); TODO 144 | // } 145 | // } 146 | 147 | /* 148 | * Gets Atom property 149 | */ 150 | // pub fn getatomprop(&mut self, dpy: &mut xlib::Display, prop: xlib::Atom) -> xlib::Atom { 151 | // let mut di = 0; 152 | // let mut dl = 0; 153 | // let mut p = ptr::null_mut(); 154 | // let mut da = 0; let mut atom = 0; 155 | // if unsafe { xlib::XGetWindowProperty(dpy, self.win, prop, 0, size_of::() as i64, 0, xlib::XA_ATOM, &mut da, &mut di, &mut dl, &mut dl, &mut p) } == xlib::Success as i32 && !(p.is_null()) { 156 | // // TODO 157 | // atom = unsafe { *p } as u64; 158 | // // xlib::XFree(p); TODO 159 | // } 160 | // atom 161 | // } 162 | 163 | /** 164 | * Updates the title 165 | */ 166 | pub fn updateTitle(c: Client) -> Client { 167 | Client { ..c } 168 | } 169 | 170 | /* 171 | * Updates type of the window 172 | */ 173 | // pub fn updatewindowtype(&mut self, dpy: &mut xlib::Display, netatom: &Vec) { 174 | // let state = self.getatomprop(dpy, netatom[NETWMSTATE]); 175 | // let wtype = self.getatomprop(dpy, netatom[NETWMWINDOWTYPE]); 176 | 177 | // println!("dwm-rust : atom : {}", state); 178 | // println!("dwm-rust : netwmfullscreen atom : {}", netatom[NETWMFULLSCREEN]); // Pourquoi pas fullscreen ? 179 | 180 | // if state == netatom[NETWMFULLSCREEN] { 181 | // self.setfullscreen(dpy, true, netatom); 182 | // } 183 | // if wtype == netatom[NETWMWINDOWTYPEDIALOG] { 184 | // self.isfloating = true; 185 | // } 186 | // } 187 | 188 | /* 189 | * Updates size hints of the window 190 | */ 191 | // pub fn updatesizehints(&mut self, dpy: &mut xlib::Display) { 192 | // let mut msize = 0; 193 | // let mut size = xlib::XSizeHints { // Dummy value 194 | // flags: 0, x: 0, y: 0, width: 0, height: 0, min_width: 0, min_height: 0, max_width: 0, max_height: 0, width_inc: 0, height_inc: 0, min_aspect: xlib::AspectRatio{x:0, y:0}, max_aspect: xlib::AspectRatio{x:0, y:0}, base_width: 0, base_height: 0, win_gravity: 0 195 | // }; 196 | // if unsafe { xlib::XGetWMNormalHints(dpy, self.win, &mut size, &mut msize) == 0} { 197 | // // size is not initialized 198 | // size.flags = xlib::PSize; 199 | // if size.flags & xlib::PBaseSize != 0 { 200 | // self.basew = size.base_width as u32; 201 | // self.baseh = size.base_height as u32; 202 | // } else if size.flags & xlib::PMinSize != 0 { 203 | // self.basew = size.min_width as u32; 204 | // self.baseh = size.min_height as u32; 205 | // } else { 206 | // self.basew = 0; 207 | // self.baseh = 0; 208 | // } 209 | // if size.flags & xlib::PMaxSize != 0 { 210 | // self.maxw = size.max_width as u32; 211 | // self.maxh = size.max_height as u32; 212 | // } else { 213 | // self.maxw = 0; 214 | // self.maxh = 0; 215 | // } 216 | // if size.flags & xlib::PMinSize != 0 { 217 | // self.minw = size.min_width as u32; 218 | // self.minh = size.min_height as u32; 219 | // } else if size.flags & xlib::PBaseSize != 0 { 220 | // self.minw = size.base_width as u32; 221 | // self.maxw = size.base_height as u32; 222 | // } else { 223 | // self.minw = 0; 224 | // self.minh = 0; 225 | // } 226 | // if size.flags & xlib::PAspect != 0 { 227 | // self.mina = size.min_aspect.y as f32 / size.min_aspect.x as f32; 228 | // self.maxa = size.max_aspect.x as f32 / size.max_aspect.y as f32; 229 | // } else { 230 | // self.mina = 0.0; 231 | // self.maxa = 0.0; 232 | // } 233 | // self.isfixed = self.maxw != 0 && self.minw != 0 && self.maxh != 0 && self.minh != 0 && self.maxw == self.minw && self.maxh == self.minh; 234 | // } 235 | // } 236 | 237 | /* 238 | * Updates the WM Hints 239 | */ 240 | // pub fn updatewmhints(&mut self, dpy: &mut xlib::Display, selmon: &Workspace<'a>) { 241 | // let wmh = unsafe { xlib::XGetWMHints(dpy, self.win) }; 242 | // if !(wmh.is_null()) { 243 | // if let Some(sel) = selmon.sel { 244 | // if self == sel && unsafe { (*wmh).flags } & xlib::XUrgencyHint != 0 { 245 | // unsafe { (*wmh).flags &= !xlib::XUrgencyHint }; 246 | // unsafe { xlib::XSetWMHints(dpy, self.win, wmh) }; 247 | // } else { 248 | // self.isurgent = unsafe { (*wmh).flags } & xlib::XUrgencyHint != 0; 249 | // } 250 | // } 251 | // if unsafe { (*wmh).flags } & xlib::InputHint != 0 { 252 | // self.neverfocus = unsafe { (*wmh).input == 0}; 253 | // } else { 254 | // self.neverfocus = false; 255 | // } 256 | // // xlib::XFree(wmh); TODO 257 | // } 258 | // } 259 | 260 | /* 261 | * Grabs buttons 262 | */ 263 | // pub fn grabbuttons(&mut self, wm: &mut WM, focused: bool) { 264 | // wm.updatenumlockmask(); 265 | // let modifiers = vec![0, xlib::LockMask, wm.numlockmask, xlib::LockMask|wm.numlockmask]; 266 | // unsafe { xlib::XUngrabButton(wm.drw.dpy, xlib::AnyButton as u32, xlib::AnyModifier, self.win) }; 267 | // if focused { 268 | // for b in config::buttons.iter() { 269 | // /*if b.click == ClkClientWin { 270 | // TODO 271 | // }*/ 272 | // } 273 | // } else { 274 | // unsafe { xlib::XGrabButton(wm.drw.dpy, xlib::AnyButton as u32, xlib::AnyModifier, self.win, 0, (xlib::ButtonPressMask|xlib::ButtonReleaseMask) as u32, xlib::GrabModeAsync, xlib::GrabModeSync, 0, 0) }; 275 | // } 276 | // } 277 | 278 | /* 279 | * Applies the rules 280 | */ 281 | // pub fn applyrules(&mut self) { 282 | // // TODO 283 | // } 284 | 285 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_upper_case_globals)] 2 | #![allow(non_snake_case)] 3 | #![allow(dead_code)] 4 | 5 | extern crate x11; 6 | 7 | use std::env; 8 | use std::process; 9 | use std::ptr; 10 | use std::process::Command; 11 | 12 | use x11::{ xlib, xinerama }; 13 | 14 | /// Events handling 15 | pub mod events; 16 | /// Window Manager module 17 | pub mod wm; 18 | /// Drawable module 19 | pub mod drw; 20 | /// Configuration module 21 | pub mod config; 22 | 23 | use events::handleEvent; 24 | 25 | use wm::WM; 26 | use wm::workspace; 27 | use wm::workspace::Layout; 28 | use wm::client; 29 | use wm::client::Client; 30 | 31 | const VERSION: &str = "0.0.1"; 32 | 33 | // WM Atom indexes 34 | const WMPROTOCOLS: usize = 0; const WMDELETE: usize = 1; const WMSTATE: usize = 2; const WMTAKEFOCUS: usize = 3; const WMLAST: usize = 4; 35 | // Net Atom indexes 36 | const NETACTIVEWINDOW: usize = 0; const NETSUPPORTED: usize = 1; const NETWMNAME: usize = 2; const NETWMSTATE: usize = 3; const NETWMFULLSCREEN: usize = 4; const NETWMWINDOWTYPE: usize = 5; const NETWMWINDOWTYPEDIALOG: usize = 6; const NETCLIENTLIST: usize = 7; const NETLAST: usize = 8; 37 | // Cursor indexes 38 | pub const CURNORMAL: usize = 0; pub const CURRESIZE: usize = 1; pub const CURMOVE: usize = 2; 39 | // Color scheme indexes 40 | pub const SCHEMENORM: usize = 0; pub const SCHEMESEL: usize = 1; 41 | 42 | /** 43 | * Stores an argument to pass to functions on keypress and click events 44 | */ 45 | pub union Arg<'a> { 46 | i: i32, 47 | u: u32, 48 | f: f32, 49 | s: &'a str 50 | } 51 | 52 | /** 53 | * Stores a key for keypress events 54 | */ 55 | pub struct Key<'a> { 56 | modif: u32, 57 | keysym: xlib::KeySym, 58 | func: for<'b> fn (&Arg, WM<'b>) -> WM<'b>, 59 | arg: Arg<'a> 60 | } 61 | 62 | /** 63 | * Different types of click events 64 | */ 65 | pub enum Click { 66 | ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast 67 | } 68 | 69 | /** 70 | * Stores a button for click events 71 | */ 72 | pub struct Button<'a> { 73 | click: Click, 74 | mask: u32, 75 | button: u32, 76 | func: for<'b> fn (&Arg, WM<'b>) -> WM<'b>, 77 | arg: Arg<'a> 78 | } 79 | 80 | /** 81 | * Stores a tag 82 | */ 83 | pub struct Pertag<'a> { 84 | curtag: u32, prevtag: u32, // Current and previous tag 85 | nmasters: Vec, // number windows in master area 86 | mfacts: Vec, // mfacts per tag 87 | selltds: Vec, // Selected layouts 88 | ltidxs: Vec>>, // Matrix of tags and layouts 89 | showbars: Vec, // Display bar for each tag 90 | prefzooms: Vec<&'a Client<'a>> // Zoom information 91 | } 92 | 93 | fn main() { 94 | let args: Vec = env::args().collect(); 95 | if args.len()==2 && args[1]==String::from("-v") { 96 | println!("dwm-rust-{}", ::VERSION); 97 | process::exit(0); 98 | } if args.len()>1 { 99 | println!("usage: dwm-rust [-v]"); 100 | process::exit(1); 101 | } 102 | if unsafe { xlib::XSupportsLocale() } == 0 { 103 | println!("Warning : no locale support"); 104 | } if let Some(dpy) = Some( unsafe { &mut(*xlib::XOpenDisplay(ptr::null())) }) { 105 | // This is where we'll work 106 | checkOtherWm(dpy); 107 | let wm = cleanup(run(setup(dpy))); 108 | unsafe { xlib::XCloseDisplay(wm.drw.dpy) }; 109 | } else { 110 | println!("dwm-rust: can't open display"); 111 | process::exit(1); 112 | } 113 | } 114 | 115 | /// Prints an X error on start of the wm and exits the program. 116 | extern "C" fn xerrorstart(_dpy: *mut xlib::Display, _ee: *mut xlib::XErrorEvent) -> i32 { 117 | println!("dwm-rust: another window manager is already running\n"); 118 | process::exit(1); 119 | } 120 | 121 | /// Handles errors. TODO : completer les cas sans erreur 122 | unsafe extern "C" fn xerror(_dpy: *mut xlib::Display, ee: *mut xlib::XErrorEvent) -> i32 { 123 | if (*ee).error_code == xlib::BadWindow 124 | || (*ee).error_code == xlib::BadDrawable 125 | || (*ee).error_code == xlib::BadMatch 126 | || (*ee).error_code == xlib::BadAccess { 127 | 0 128 | } else { 129 | eprintln!("dwm-rust: fatal error: request code={}, error code={}", (*ee).request_code, (*ee).error_code); 130 | process::exit(1); 131 | } 132 | } 133 | 134 | /** 135 | * Checks for another WM running. If there is one, prints an error and exits. 136 | */ 137 | pub fn checkOtherWm(dpy: *mut xlib::Display) { 138 | unsafe { 139 | xlib::XSetErrorHandler(Some(xerrorstart)); 140 | xlib::XSelectInput(dpy, xlib::XDefaultRootWindow(dpy), xlib::SubstructureRedirectMask); 141 | xlib::XSync(dpy, 0); xlib::XSetErrorHandler(Some(xerror)); xlib::XSync(dpy, 0); 142 | } 143 | } 144 | 145 | /** 146 | * Setup the Window Manager 147 | */ 148 | pub fn setup(dpy: &mut xlib::Display) -> WM { 149 | let screen = unsafe { xlib::XDefaultScreen(dpy) }; 150 | let sw = unsafe { xlib::XDisplayWidth(dpy, screen) } as u32; 151 | let sh = unsafe { xlib::XDisplayHeight(dpy, screen) } as u32; 152 | let root = unsafe { xlib::XRootWindow(dpy, screen) }; 153 | let drw = drw::createDrw(dpy, screen, root, sw, sh); 154 | 155 | let drw = drw::loadFonts(drw, config::fonts.to_vec()); 156 | if drw.fonts.len()<1 { 157 | eprintln!("no fonts could be loaded.\n"); 158 | process::exit(1); 159 | } 160 | 161 | let wm = wm::updateStatus(wm::updateBars(wm::createWorkspaces(wm::initWm(drw, screen, root, sw, sh)))); 162 | unsafe { 163 | xlib::XChangeProperty(wm.drw.dpy, wm.root, wm.netatom[NETSUPPORTED], xlib::XA_ATOM, 32, xlib::PropModeReplace, &(wm.netatom[0] as u8), NETLAST as i32); 164 | xlib::XDeleteProperty(wm.drw.dpy, wm.root, wm.netatom[NETCLIENTLIST]); 165 | xlib::XChangeWindowAttributes(wm.drw.dpy, wm.root, xlib::CWEventMask|xlib::CWCursor, &mut xlib::XSetWindowAttributes { 166 | background_pixmap: 0, 167 | background_pixel: 0, 168 | border_pixmap: xlib::CopyFromParent as u64, 169 | border_pixel: 0, 170 | bit_gravity: xlib::ForgetGravity, 171 | win_gravity: xlib::NorthWestGravity, 172 | backing_store: xlib::NotUseful, 173 | backing_planes: 1, 174 | backing_pixel: 0, 175 | save_under: 0, 176 | event_mask: xlib::SubstructureRedirectMask|xlib::SubstructureNotifyMask|xlib::ButtonPressMask|xlib::PointerMotionMask|xlib::EnterWindowMask|xlib::LeaveWindowMask|xlib::StructureNotifyMask|xlib::PropertyChangeMask, 177 | do_not_propagate_mask: 0, 178 | override_redirect: 0, 179 | colormap: xlib::CopyFromParent as u64, 180 | cursor: wm.cursor[CURNORMAL].cursor 181 | }); 182 | } 183 | // focus(None); TODO 184 | executeStartCmds(wm::setRootBackground(wm::grabKeys(wm))) 185 | } 186 | 187 | pub fn isUniqueGeom(unique: &Vec, n: usize, info: &xinerama::XineramaScreenInfo) -> bool { 188 | for i in n..0 { 189 | if unique[i].x_org == info.x_org && unique[i].y_org == info.y_org && unique[i].width == info.width && unique[i].height == info.height { 190 | return false 191 | } 192 | } 193 | true 194 | } 195 | 196 | pub fn executeStartCmds(wm: WM) -> WM { 197 | config::startCmds.into_iter().map(|s| {Arg {s}}).fold(wm, |wm, a| { spawn(&a, wm) }) 198 | } 199 | 200 | /** 201 | * Main program loop 202 | */ 203 | pub fn run(mut wm: WM) -> WM { 204 | let ev = &mut xlib::XEvent { any: xlib::XAnyEvent { type_: 0, serial: 0, send_event: 0, display: wm.drw.dpy, window: wm.root } }; // Dummy value 205 | unsafe { 206 | xlib::XSync(wm.drw.dpy, 0); 207 | while wm.running && xlib::XNextEvent(wm.drw.dpy, ev) == 0 { 208 | wm = handleEvent(wm, ev); 209 | } 210 | } 211 | wm 212 | } 213 | /** 214 | * Executes a shell command 215 | * 216 | * # Arguments 217 | * * `arg` - Reference to an Arg containing the command (&str) to execute 218 | * * `wm` - Window Manager 219 | */ 220 | pub fn spawn<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> { 221 | let v : Vec<&str> = unsafe { arg.s.split(' ').collect() }; 222 | let mut command = Command::new(v[0]); 223 | for i in 1..v.len() { 224 | command.arg(v[i]); 225 | } 226 | command.spawn().expect(&["Command", unsafe { arg.s }, "has failed..."].join(" ")[..]); 227 | wm 228 | } 229 | 230 | /** 231 | * Change to another Workspace 232 | * 233 | * # Arguments 234 | * * `arg` - Reference to an Arg containing the number (u32) of the Workspace to switch to 235 | * * `wm` - Window Manager 236 | */ 237 | pub fn changeWs<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> { 238 | let index = unsafe { arg.u }; 239 | if index > 0 && index <= wm.wss.len() as u32 && (index-1) != wm.selwsindex as u32 { 240 | workspace::hideAllClients(&wm.wss[wm.selwsindex], wm.drw.dpy); 241 | let wm = wm::updateStatus(WM { 242 | selwsindex: (index-1) as usize, 243 | ..wm 244 | }); 245 | workspace::showAllClients(&wm.wss[wm.selwsindex], wm.drw.dpy); 246 | wm 247 | } else { 248 | wm 249 | } 250 | } 251 | 252 | /** 253 | * Moves a Client to another Workspace 254 | * 255 | * # Arguments 256 | * * `arg` - Reference to an Arg containing the number (u32) of the Workspace to move the client to 257 | * * `wm` - Window Manager 258 | */ 259 | pub fn moveClientToWs<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> { 260 | let index = (unsafe { arg.u } - 1) as usize; 261 | if index < wm.wss.len() as usize && index != wm.selwsindex as usize { 262 | let (mut wm, w) = wm::findPointedWindow(wm); 263 | { 264 | for i in 0..wm.wss[wm.selwsindex].clients.len() { 265 | if wm.wss[wm.selwsindex].clients[i].win == w { 266 | let c = wm.wss[wm.selwsindex].clients.remove(i); 267 | wm.wss[index].clients.insert(0, c); 268 | break; 269 | } 270 | } 271 | } 272 | let ws = workspace::updateGeom(wm.wss.remove(wm.selwsindex), wm.drw.dpy); 273 | wm.wss.insert(wm.selwsindex, ws); 274 | let ws = workspace::updateGeom(wm.wss.remove(index), wm.drw.dpy); 275 | workspace::hideAllClients(&ws, wm.drw.dpy); 276 | wm.wss.insert(index, ws); 277 | wm::updateStatus(wm) 278 | } else { 279 | wm 280 | } 281 | } 282 | 283 | /** 284 | * Closes a Client 285 | * 286 | * # Arguments 287 | * * `arg` - Reference to an Arg containing whatever 288 | * * `wm` - Window Manager 289 | */ 290 | pub fn closeClient<'a>(_: &Arg, wm: WM<'a>) -> WM<'a> { 291 | let (mut wm, w) = wm::findPointedWindow(wm); 292 | for i in 0..wm.wss.len() { 293 | let ws = &mut wm.wss[i]; 294 | for i in 0..ws.clients.len() { 295 | if ws.clients[i].win == w { 296 | let c = ws.clients.remove(i); 297 | client::destroyClient(c, wm.drw.dpy); 298 | break; 299 | } 300 | } 301 | } 302 | wm 303 | } 304 | 305 | 306 | /** 307 | * Quits the WM 308 | */ 309 | pub fn quit<'a>(_: &Arg, wm: WM<'a>) -> WM<'a> { 310 | WM { 311 | running: false, 312 | ..wm 313 | } 314 | } 315 | 316 | /** 317 | * Cleanup and frees memory 318 | */ 319 | fn cleanup(wm: WM) -> WM { 320 | // TODO 321 | wm 322 | } 323 | -------------------------------------------------------------------------------- /src/wm/mod.rs: -------------------------------------------------------------------------------- 1 | extern crate x11; 2 | 3 | use std::ffi::CString; 4 | 5 | use x11::xlib; 6 | use x11::keysym; 7 | 8 | /// Workspace module 9 | pub mod workspace; 10 | /// Client module 11 | pub mod client; 12 | 13 | use CURNORMAL; 14 | use wm::workspace::Workspace; 15 | use drw; 16 | use drw::{ Drw, Cur }; 17 | use drw::clrscheme; 18 | use drw::clrscheme::ClrScheme; 19 | use config; 20 | 21 | /** 22 | * Stores the state of the Window Manager 23 | */ 24 | pub struct WM<'a> { 25 | pub drw: Drw<'a>, 26 | pub screen: i32, 27 | pub root: u64, 28 | pub running: bool, 29 | pub wmatom: Vec, 30 | pub netatom: Vec, 31 | pub cursor: Vec, 32 | pub scheme: Vec, 33 | pub wss: Vec>, 34 | pub selwsindex: usize, 35 | pub sw: u32, pub sh: u32, 36 | pub bh: u32, 37 | pub stext: String, 38 | pub numlockmask: u32, 39 | } 40 | 41 | /** 42 | * Inits the window manager 43 | */ 44 | pub fn initWm(drw: Drw, screen: i32, root: u64, sw: u32, sh: u32) -> WM { 45 | let mut wm = WM { 46 | drw, 47 | screen, 48 | root, 49 | running: true, 50 | wmatom: Vec::new(), 51 | netatom: Vec::new(), 52 | cursor: Vec::new(), 53 | scheme: Vec::new(), 54 | wss: Vec::new(), 55 | selwsindex: 0, 56 | sw, sh, 57 | bh: 0, 58 | stext: String::from("dwm-rust"), 59 | numlockmask: 0 60 | }; 61 | wm.bh = wm.drw.fonts[0].h + 2; 62 | unsafe { 63 | // Init atoms 64 | wm.wmatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("WM_PROTOCOLS").unwrap().as_ptr(), 0)); 65 | wm.wmatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("WM_DELETE_WINDOW").unwrap().as_ptr(), 0)); 66 | wm.wmatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("WM_STATE").unwrap().as_ptr(), 0)); 67 | wm.wmatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("WM_TAKE_FOCUS").unwrap().as_ptr(), 0)); 68 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy,CString::new("_NET_ACTIVE_WINDOW").unwrap().as_ptr(), 0)); 69 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_SUPPORTED").unwrap().as_ptr(), 0)); 70 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_WM_NAME").unwrap().as_ptr(), 0)); 71 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_WM_STATE").unwrap().as_ptr(), 0)); 72 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_WM_STATE_FULLSCREEN").unwrap().as_ptr(), 0)); 73 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_WM_WINDOWN_TYPE").unwrap().as_ptr(), 0)); 74 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_WM_WINDOW_TYPE_DIALOG").unwrap().as_ptr(), 0)); 75 | wm.netatom.push(xlib::XInternAtom(wm.drw.dpy, CString::new("_NET_CLIENT_LIST").unwrap().as_ptr(), 0)); 76 | // Init cursors 77 | wm.cursor.push(drw::createCur(&mut (wm.drw), 68)); // Normal 78 | wm.cursor.push(drw::createCur(&mut (wm.drw), 120)); // Resize 79 | wm.cursor.push(drw::createCur(&mut (wm.drw), 52)); // Move 80 | // Init color schemes 81 | wm.scheme.push(clrscheme::createClrScheme( 82 | clrscheme::createClr(wm.drw.dpy, wm.drw.screen, config::normfgcolor), 83 | clrscheme::createClr(wm.drw.dpy, wm.drw.screen, config::normbgcolor), 84 | clrscheme::createClr(wm.drw.dpy, wm.drw.screen, config::normbordercolor))); // Normal 85 | wm.scheme.push(clrscheme::createClrScheme( 86 | clrscheme::createClr(wm.drw.dpy, wm.drw.screen, config::selfgcolor), 87 | clrscheme::createClr(wm.drw.dpy, wm.drw.screen, config::selbgcolor), 88 | clrscheme::createClr(wm.drw.dpy, wm.drw.screen, config::selbordercolor))); // Selected 89 | } 90 | wm 91 | } 92 | 93 | /** 94 | * Sets a color for the root Window background 95 | */ 96 | pub fn setRootBackground(wm: WM) -> WM { 97 | unsafe { xlib::XSetWindowBackground(wm.drw.dpy, wm.root, config::backgroundColor) }; 98 | unsafe { xlib::XClearWindow(wm.drw.dpy, wm.root) }; 99 | wm 100 | } 101 | 102 | /** 103 | * Create all the workspaces and set their data 104 | */ 105 | pub fn createWorkspaces(wm: WM) -> WM { 106 | WM { 107 | wss:config::tags.iter().map(|t| { 108 | let ws = workspace::createWorkspace(t); 109 | workspace::updateBarPos(workspace::Workspace { 110 | w: wm.sw, h: wm.sh, 111 | ..ws 112 | }, wm.bh) 113 | }).collect(), 114 | selwsindex: 0, 115 | ..wm 116 | } 117 | } 118 | // /** 119 | // * Grabs buttons 120 | // */ 121 | // pub fn grabbuttons(&mut wm, c: &Client, focused: bool) { 122 | // wm.updatenumlockmask(); 123 | // let modifiers = vec![0, xlib::LockMask, wm.numlockmask, xlib::LockMask|wm.numlockmask]; 124 | // unsafe { xlib::XUngrabButton(wm.drw.dpy, xlib::AnyButton as u32, xlib::AnyModifier, c.win) }; 125 | // if focused { 126 | // for b in config::buttons.iter() { 127 | // /*if b.click == ClkClientWin { 128 | // TODO 129 | // }*/ 130 | // } 131 | // } else { 132 | // unsafe { xlib::XGrabButton(wm.drw.dpy, xlib::AnyButton as u32, xlib::AnyModifier, c.win, 0, (xlib::ButtonPressMask|xlib::ButtonReleaseMask) as u32, xlib::GrabModeAsync, xlib::GrabModeSync, 0, 0) }; 133 | // } 134 | // } 135 | 136 | fn updatenumlockmask(wm: WM) -> WM { 137 | let modmap = unsafe { (*xlib::XGetModifierMapping(wm.drw.dpy)) }; 138 | let modifiermap = unsafe { Vec::from_raw_parts(modmap.modifiermap, 8 * modmap.max_keypermod as usize, 8 * modmap.max_keypermod as usize) }; 139 | for i in 0..8 { 140 | for j in 0..modmap.max_keypermod { 141 | if modifiermap[(i * modmap.max_keypermod + j) as usize] == unsafe { xlib::XKeysymToKeycode(wm.drw.dpy, keysym::XK_Num_Lock as u64) } { 142 | return WM { 143 | numlockmask: 1 << i, 144 | ..wm 145 | } 146 | } 147 | } 148 | } 149 | WM { numlockmask:0, ..wm} 150 | // unsafe { xlib::XFreeModifiermap(&mut modmap); } TODO Causes a crash for some reason 151 | } 152 | 153 | /** 154 | * Loads and grabs the keys defined in config::keys 155 | */ 156 | pub fn grabKeys(wm: WM) -> WM { 157 | let wm = updatenumlockmask(wm); 158 | let modifiers = vec![0, xlib::LockMask, wm.numlockmask, wm.numlockmask|xlib::LockMask]; 159 | 160 | unsafe { xlib::XUngrabKey(wm.drw.dpy, xlib::AnyKey, xlib::AnyModifier, wm.root) }; 161 | for i in 0..config::keys.len() { 162 | let code = unsafe { xlib::XKeysymToKeycode(wm.drw.dpy, config::keys[i].keysym) }; 163 | if code != 0 { 164 | for j in 0..modifiers.len() { 165 | unsafe { xlib::XGrabKey(wm.drw.dpy, code as i32, config::keys[i].modif | modifiers[j], wm.root, 1, xlib::GrabModeAsync, xlib::GrabModeAsync) }; 166 | } 167 | } 168 | } 169 | wm 170 | } 171 | 172 | /** 173 | * Updates the status bars 174 | */ 175 | pub fn updateBars(mut wm: WM) -> WM { 176 | let mut wa = xlib::XSetWindowAttributes { 177 | background_pixmap: xlib::ParentRelative as u64, 178 | background_pixel: 0, 179 | border_pixmap: xlib::CopyFromParent as u64, 180 | border_pixel: 0, 181 | bit_gravity: xlib::ForgetGravity, 182 | win_gravity: xlib::NorthWestGravity, 183 | backing_store: xlib::NotUseful, 184 | backing_planes: u64::max_value(), 185 | backing_pixel: 0, 186 | save_under: 0, 187 | event_mask: xlib::ButtonPressMask|xlib::ExposureMask, 188 | do_not_propagate_mask: 0, 189 | override_redirect: 1, 190 | colormap: xlib::CopyFromParent as u64, 191 | cursor: 0 192 | }; 193 | if wm.wss[0].barwin == 0 { 194 | let barwin = unsafe { 195 | xlib::XCreateWindow(wm.drw.dpy, 196 | wm.root, 197 | wm.wss[0].x, wm.wss[0].by, wm.wss[0].w as u32, 198 | wm.bh, 199 | 0, 200 | xlib::XDefaultDepth(wm.drw.dpy, wm.screen), 201 | xlib::CopyFromParent as u32, 202 | xlib::XDefaultVisual(wm.drw.dpy, wm.screen), 203 | xlib::CWOverrideRedirect|xlib::CWBackPixmap|xlib::CWEventMask, 204 | &mut wa) }; 205 | unsafe { xlib::XDefineCursor(wm.drw.dpy, barwin, wm.cursor[CURNORMAL].cursor) }; 206 | unsafe { xlib::XMapRaised(wm.drw.dpy, barwin) }; 207 | for ws in wm.wss.iter_mut() { 208 | if ws.barwin == 0 { ws.barwin = barwin }; 209 | } 210 | } 211 | wm 212 | } 213 | 214 | fn getTextProp(dpy: &mut xlib::Display, w: xlib::Window, atom: xlib::Atom) -> Option { 215 | let mut name = xlib::XTextProperty { // Dummy value 216 | value: (CString::new("").unwrap().into_bytes().as_mut_ptr()), encoding: 0, format: 8, nitems: 0 217 | }; 218 | unsafe { xlib::XGetTextProperty(dpy, w, &mut name, atom) }; 219 | let text = unsafe { CString::from_vec_unchecked(Vec::from_raw_parts(name.value, name.nitems as usize, name.nitems as usize))}.into_string().unwrap(); 220 | if text == "" { None } else { Some(text) } 221 | } 222 | 223 | /** 224 | * Updates the status bar text 225 | */ 226 | pub fn updateStatus(wm: WM) -> WM { 227 | let wm = WM { 228 | stext: if let Some(text) = getTextProp(wm.drw.dpy, wm.root, xlib::XA_WM_NAME) { text } else { wm.stext }, 229 | ..wm 230 | }; 231 | WM {drw: workspace::drawBar(wm.drw, wm.bh, &wm.scheme, &wm.wss, wm.selwsindex, &wm.stext[..]), ..wm} 232 | } 233 | 234 | /** 235 | * Manage a new Window 236 | */ 237 | pub fn manage<'a>(mut wm: WM<'a>, w: xlib::Window, wa: xlib::XWindowAttributes) -> WM<'a> { 238 | let c = client::updateTitle(client::createClient(w, wa, wm.selwsindex)); 239 | // let mut trans = 0; 240 | // if unsafe { xlib::XGetTransientForHint(wm.drw.dpy, w, &mut trans) } != 0 { 241 | // if let Some(t) = Client::from(trans, &wm.mons) { 242 | // c.monindex = t.monindex; 243 | // c.tags = t.tags; 244 | // } else { 245 | // c.monindex = wm.selmonindex; 246 | // c.applyrules(); 247 | // } 248 | // } else { 249 | // c.applyrules(); 250 | // } 251 | // let mon = &wm.mons[c.monindex]; 252 | // if c.x + c.width() as i32 > mon.mx + mon.mw as i32 { 253 | // c.x = mon.mx + mon.mw as i32 - c.width() as i32; 254 | // } 255 | // if c.y + c.height() as i32 > mon.my + mon.mw as i32 { 256 | // c.y = mon.my + mon.mw as i32 - c.height() as i32; 257 | // } 258 | // c.x = c.x.max(mon.mx); 259 | // c.y = c.y.max(if mon.by == mon.my && c.x + (c.w/2) as i32 >= mon.wx && c.x + ((c.w/2) as i32) < mon.wx + mon.ww as i32 { wm.bh as i32 } else { mon.my }); 260 | // let mut wc = xlib::XWindowChanges { 261 | // x: 0, y: 0, width:0, height: 0, border_width: c.bw as i32, sibling: 0, stack_mode: 0 262 | // }; 263 | // unsafe { xlib::XConfigureWindow(wm.drw.dpy, w, xlib::CWBorderWidth as u32, &mut wc) }; 264 | // unsafe { xlib::XSetWindowBorder(wm.drw.dpy, w, wm.scheme[SCHEMENORM].border.pix) }; 265 | // c.updatewindowtype(wm.drw.dpy, &wm.netatom); 266 | // c.updatesizehints(wm.drw.dpy); 267 | // c.updatewmhints(wm.drw.dpy, &wm.mons[wm.selmonindex]); 268 | // unsafe { xlib::XSelectInput(wm.drw.dpy, w, xlib::EnterWindowMask | xlib::FocusChangeMask | xlib::PropertyChangeMask | xlib::StructureNotifyMask) }; 269 | // // wm.grabbuttons(&c, false); TODO 270 | // if !c.isfloating { 271 | // c.isfloating = trans != 0 || c.isfixed; 272 | // c.oldstate = c.isfloating; 273 | // } 274 | // if c.isfloating { 275 | // unsafe { xlib::XRaiseWindow(wm.drw.dpy, c.win) }; 276 | // } 277 | // TODO 278 | 279 | // Add the client to the current workspace 280 | wm.wss[wm.selwsindex].clients.insert(0, c); 281 | // Update geometry of the current workspace 282 | let ws = workspace::updateGeom(wm.wss.remove(wm.selwsindex), wm.drw.dpy); 283 | wm.wss.insert(wm.selwsindex, ws); 284 | // Draw the client on the screen 285 | if let Some(c) = wm.wss[wm.selwsindex].clients.first() { 286 | client::show(c, wm.drw.dpy); 287 | } 288 | wm 289 | // focus(None) TODO 290 | } 291 | 292 | /** 293 | * Unmanage a Client 294 | */ 295 | pub fn unManage<'a>(wm: WM<'a>, w: xlib::Window) -> WM<'a> { 296 | let mut wm = WM { 297 | wss : wm.wss.into_iter().map(|ws| { 298 | Workspace { 299 | clients: ws.clients.into_iter().filter(|c| { c.win != w } ).collect(), 300 | ..ws 301 | } 302 | }).collect(), 303 | ..wm 304 | }; 305 | let ws = workspace::updateGeom(wm.wss.remove(wm.selwsindex), wm.drw.dpy); 306 | wm.wss.insert(wm.selwsindex, ws); 307 | wm 308 | } 309 | 310 | /** 311 | * Find the Window the pointer is on 312 | */ 313 | pub fn findPointedWindow<'a>(wm: WM<'a>) -> (WM<'a>, xlib::Window) { 314 | let root_return: &mut xlib::Window = &mut 0; 315 | let child_return: &mut xlib::Window = &mut 0; 316 | let root_x_return: &mut i32 = &mut 0; 317 | let root_y_return: &mut i32 = &mut 0; 318 | let win_x_return: &mut i32 = &mut 0; 319 | let win_y_return: &mut i32 = &mut 0; 320 | let mask_return: &mut u32 = &mut 0; 321 | unsafe { xlib::XQueryPointer(wm.drw.dpy, wm.root, root_return, child_return, root_x_return, root_y_return, win_x_return, win_y_return, mask_return) }; 322 | (wm, *child_return) 323 | } 324 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------