From 95d77401192d5856a43480ed374c938be71a02e2 Mon Sep 17 00:00:00 2001 From: NoOneBtw Date: Tue, 4 May 2021 10:50:23 +0200 Subject: [PATCH] made gaps prettier --- src/clients.rs | 26 ++++++++------------------ src/xlib.rs | 13 +++++++++---- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/clients.rs b/src/clients.rs index 3c712e5..274b98f 100644 --- a/src/clients.rs +++ b/src/clients.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::num::NonZeroI32; -use log::{debug, error}; +use log::{error, info}; use crate::util::BuildIdentityHasher; @@ -630,17 +630,6 @@ impl ClientState { } } - /** - there should be no need to call this function since a `VirtualScreen` refreshes it self on - client removal. - */ - #[deprecated] - fn refresh_virtual_screen(&mut self) { - if let Some(vs) = self.virtual_screens.front_mut() { - vs.refresh(); - } - } - /** resizes and moves clients on the current virtual screen with `width` and `height` as screen width and screen height. @@ -657,24 +646,25 @@ impl ClientState { // should be fine to unwrap since we will always have at least 1 virtual screen if let Some(vs) = self.virtual_screens.front_mut() { // if aux is empty -> width : width / 2 - let width = width / (1 + i32::from(!vs.aux.is_empty())); + let width = (width - gap * 2) / (1 + i32::from(!vs.aux.is_empty())); // make sure we dont devide by 0 // height is max height / number of clients in the stack - let master_height = height + let master_height = (height - gap * 2) / match NonZeroI32::new(vs.master.len() as i32) { Some(i) => i.get(), None => 1, }; // height is max height / number of clients in the stack - let aux_height = height + let aux_height = (height - gap * 2) / match NonZeroI32::new(vs.aux.len() as i32) { Some(i) => i.get(), None => 1, }; - // chaining master and aux together with `Zip`s for height and x reduces duplicate code + // chaining master and aux together with `Zip`s for height and x + // reduces duplicate code for ((i, key), (height, x)) in vs .master .iter() @@ -690,7 +680,7 @@ impl ClientState { ) { let size = (width - gap * 2, height - gap * 2); - let position = (x + gap, height * i as i32 + gap); + let position = (x + gap * 2, height * i as i32 + gap * 2); if let Some(client) = self.clients.get_mut(key) { *client = Client { @@ -702,7 +692,7 @@ impl ClientState { } } - debug!("{:#?}", self); + info!("{:#?}", self); } // Should have xlib send those changes back to the x server after this function diff --git a/src/xlib.rs b/src/xlib.rs index d9c2291..d374c6c 100644 --- a/src/xlib.rs +++ b/src/xlib.rs @@ -443,10 +443,15 @@ impl XLib { pub fn dimensions(&self) -> (i32, i32) { unsafe { - ( - xlib::XDisplayWidth(self.dpy(), self.screen), - xlib::XDisplayHeight(self.dpy(), self.screen), - ) + let mut wa = + std::mem::MaybeUninit::::zeroed() + .assume_init(); + + xlib::XGetWindowAttributes(self.dpy(), self.root, &mut wa); + + info!("Root window dimensions: {}, {}", wa.width, wa.height); + + (wa.width, wa.height) } }