From 19d4dac4d9b30fdebc445c70e6524c0d207b6917 Mon Sep 17 00:00:00 2001 From: tcmal Date: Thu, 4 Jul 2024 21:46:08 +0100 Subject: clamp window size to monitor --- src/clients/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/clients') diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 266a61d..8fac307 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,5 +1,7 @@ //! Tracking and managing windows. +use std::cmp::min; + use crate::{ config::BORDER_WIDTH, conn_info::Connection, @@ -185,14 +187,19 @@ impl ClientState { // TODO: inserting at index 0 is why dwm uses linked lists, maybe this can be improved self.mons[mon].clients.insert(0, Client::new(window)); - // TODO: Clamp window size to monitor + let MonitorGeometry { + width: mon_width, + height: mon_height, + .. + } = self.mons[mon].screen_info; + let c = &mut self.mons[mon].clients[0]; c.set_geom( conn, geom.x(), geom.y(), - geom.width(), - geom.height(), + min(geom.width(), mon_width.saturating_sub(geom.x() as u16)), + min(geom.height(), mon_height.saturating_sub(geom.y() as u16)), BORDER_WIDTH, ); c.set_border(conn, conn.colours.border_normal()); -- cgit v1.2.3