Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,16 @@ pub fn executeStartCmds(wm: WM) -> WM {
* Main program loop
*/
pub fn run(mut wm: WM) -> WM {
let ev = &mut xlib::XEvent { any: xlib::XAnyEvent { type_: 0, serial: 0, send_event: 0, display: wm.drw.dpy, window: wm.root } }; // Dummy value
let ev = &mut xlib::XEvent {
any: xlib::XAnyEvent {
type_: 0,
serial: 0,
send_event: 0,
display: wm.drw.dpy,
window: wm.root
}
}; // Dummy value

unsafe {
xlib::XSync(wm.drw.dpy, 0);
while wm.running && xlib::XNextEvent(wm.drw.dpy, ev) == 0 {
Expand Down Expand Up @@ -240,6 +249,7 @@ pub fn changeWs<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> {
workspace::hideAllClients(&wm.wss[wm.selwsindex], wm.drw.dpy);
let wm = wm::updateStatus(WM {
selwsindex: (index-1) as usize,
oldwsindex: wm.selwsindex,
..wm
});
workspace::showAllClients(&wm.wss[wm.selwsindex], wm.drw.dpy);
Expand All @@ -249,6 +259,41 @@ pub fn changeWs<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> {
}
}

/**
* Change to another Workspace relative to the current one
*
* # Arguments
* * `arg` - Reference to an Arg containing the number (i32) of positions
* * to go forward (>0) or backwards (<0)
* * `wm` - Window Manager
*/
pub fn changeWsRel<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> {
let index = unsafe { arg.i } + wm.selwsindex as i32;

if index < 0 {
let wm = changeWs(&Arg {u: wm.wss.len() as u32}, wm);
wm
} else if index >= wm.wss.len() as i32 {
let wm = changeWs(&Arg {u: 1}, wm);
wm
} else {
let wm = changeWs(&Arg {u: index as u32 + 1}, wm);
wm
}
}

/**
* Change to the previously selected Workspace
*
* # Arguments
* * `arg` - Reference to an Arg containing whatever
* * `wm` - Window Manager
*/
pub fn pivotWs<'a>(_arg: &Arg, wm: WM<'a>) -> WM<'a> {
let wm = changeWs(&Arg {u: wm.oldwsindex as u32 + 1}, wm);
wm
}

/**
* Moves a Client to another Workspace
*
Expand Down Expand Up @@ -280,6 +325,41 @@ pub fn moveClientToWs<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> {
}
}

/**
* Move a Client to another Workspace relative to the current one
*
* # Arguments
* * `arg` - Reference to an Arg containing the number (i32) of positions
* * to move the client forward (>0) or backwards (<0)
* * `wm` - Window Manager
*/
pub fn moveClientToWsRel<'a>(arg: &Arg, wm: WM<'a>) -> WM<'a> {
let index = unsafe { arg.i } + wm.selwsindex as i32;

if index < 0 {
let wm = moveClientToWs(&Arg {u: wm.wss.len() as u32}, wm);
wm
} else if index >= wm.wss.len() as i32 {
let wm = moveClientToWs(&Arg {u: 1}, wm);
wm
} else {
let wm = moveClientToWs(&Arg {u: index as u32 + 1}, wm);
wm
}
}

/**
* Move a client to the previously selected Workspace
*
* # Arguments
* * `arg` - Reference to an Arg containing whatever
* * `wm` - Window Manager
*/
pub fn pivotClientToWs<'a>(_: &Arg, wm: WM<'a>) -> WM<'a> {
let wm = moveClientToWs(&Arg {u: wm.oldwsindex as u32 + 1}, wm);
wm
}

/**
* Closes a Client
*
Expand Down
2 changes: 1 addition & 1 deletion src/wm/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> PartialEq for Client<'a> {
}

/**
* Create a new client from a window ant it's attributes
* Create a new client from a window and it's attributes
*/
pub fn createClient<'a>(win: xlib::Window, wa: xlib::XWindowAttributes, wsindex: usize) -> Client<'a> {
Client {
Expand Down
2 changes: 2 additions & 0 deletions src/wm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct WM<'a> {
pub scheme: Vec<ClrScheme>,
pub wss: Vec<Workspace<'a>>,
pub selwsindex: usize,
pub oldwsindex: usize,
pub sw: u32, pub sh: u32,
pub bh: u32,
pub stext: String,
Expand All @@ -53,6 +54,7 @@ pub fn initWm(drw: Drw, screen: i32, root: u64, sw: u32, sh: u32) -> WM {
scheme: Vec::new(),
wss: Vec::new(),
selwsindex: 0,
oldwsindex: 0,
sw, sh,
bh: 0,
stext: String::from("dwm-rust"),
Expand Down
84 changes: 78 additions & 6 deletions src/wm/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use config;
pub fn tileArrange(mut ws: Workspace) -> Workspace {
let n = ws.clients.len() as u32;
let x = minX(&ws); let y = minY(&ws); let w = maxW(&ws); let h = maxH(&ws);

if n == 1 { // If there is only one window
Workspace {
clients: vec! [client::setGeom(ws.clients.remove(0), x, y, w, h)],
Expand All @@ -30,18 +31,89 @@ pub fn tileArrange(mut ws: Workspace) -> Workspace {
}
}

pub fn monocleArrange(ws: Workspace) -> Workspace {
// TODO
ws
pub fn monocleArrange(mut ws: Workspace) -> Workspace {
let n = ws.clients.len() as u32;
let x = minX(&ws); let y = minY(&ws); let w = maxW(&ws); let h = maxH(&ws);

if n == 1 { // If there is only one window
Workspace {
clients: vec! [client::setGeom(ws.clients.remove(0), x, y, w, h)],
..ws
}
} else if n > 1 {
Workspace {
clients: ws.clients.into_iter().enumerate().map(|(i, c)| { client::setGeom(c, x+(i as i32 * w as i32), y, w, h) }).collect(),
..ws
}
} else {
ws
}
}

pub fn noArrange(ws: Workspace) -> Workspace {
ws // Nothing
}

pub fn gridArrange(ws: Workspace) -> Workspace {
// TODO
ws
pub fn gridArrange(mut ws: Workspace) -> Workspace {
let n = ws.clients.len() as u32;
let x = minX(&ws); let y = minY(&ws); let w = maxW(&ws); let h = maxH(&ws);
let mut rows = 0 as u32; let mut cols = 0 as u32;
// let mut gx = 0 as u32; let mut gy = 0; let mut gh = 0; let mut gw = 0;

if n == 1 { // If there is only one window
Workspace {
clients: vec! [client::setGeom(ws.clients.remove(0), x, y, w, h)],
..ws
}
} else if n > 1 {
// Original code by dwm gapless grid mode
for x in 0..(n/2 + 1) {
if x*x >= n {
cols = x as u32;
println!("Found {}", x);
break;
}
}

if cols == 0 {
cols = 1;
}

if n == 5 {
cols = 2;
}

rows = n / cols;

println!("Clients: {}, rows: {}, cols: {}", n, rows, cols);

let gw = match cols {
0 => w,
_ => w / cols
};

Workspace {
clients: ws.clients.into_iter().enumerate().map(|(i, c)| {
if i as u32 / rows + 1 > cols - n % cols {
rows = n / cols + 1;
}

let gh = match rows {
0 => h,
_ => h / rows
};
// let gx = match rows {
// 0 => h,
// _ => h / rows
// };

client::setGeom(c, x + ((i as i32 / rows as i32) * gw as i32), y + ((i as i32 % rows as i32) * gh as i32), gw, gh)
}).collect(),
..ws
}
} else {
ws
}
}

/**
Expand Down