diff options
-rw-r--r-- | src/buttons.rs | 6 | ||||
-rw-r--r-- | src/clients/mod.rs | 58 |
2 files changed, 52 insertions, 12 deletions
diff --git a/src/buttons.rs b/src/buttons.rs index cc8cc74..94242be 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -168,8 +168,8 @@ pub fn grab(conn: &Connection<'_>, window: Window, focused: bool) { grab_window: window, owner_events: false, event_mask: EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, - pointer_mode: GrabMode::Sync, - keyboard_mode: GrabMode::Sync, + pointer_mode: GrabMode::Async, + keyboard_mode: GrabMode::Async, confine_to: Window::none(), cursor: Cursor::none(), }); @@ -189,7 +189,7 @@ pub fn grab(conn: &Connection<'_>, window: Window, focused: bool) { owner_events: false, event_mask: EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, pointer_mode: GrabMode::Async, - keyboard_mode: GrabMode::Sync, + keyboard_mode: GrabMode::Async, confine_to: Window::none(), cursor: Cursor::none(), }); diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 7216545..01f3205 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,9 +1,13 @@ //! Tracking and managing windows. -use std::{cmp::Ordering, mem}; +use std::{ + cmp::{min, Ordering}, + mem, +}; use crate::{ buttons, + config::BORDER_WIDTH, conn_info::Connection, debug, error::{Error, Result}, @@ -12,9 +16,9 @@ use crate::{ use xcb::{ x::{ self, ChangeProperty, CloseDown, ConfigWindow, ConfigWindowMask, ConfigureNotifyEvent, - ConfigureRequestEvent, ConfigureWindow, DeleteProperty, DestroyNotifyEvent, EventMask, - GetWindowAttributes, InputFocus, KillClient, MapRequestEvent, PropMode, SetCloseDownMode, - SetInputFocus, UnmapNotifyEvent, Window, + ConfigureRequestEvent, ConfigureWindow, DeleteProperty, DestroyNotifyEvent, Drawable, + EventMask, GetGeometry, GetWindowAttributes, InputFocus, KillClient, MapRequestEvent, + PropMode, SetCloseDownMode, SetInputFocus, UnmapNotifyEvent, Window, }, xinerama, BaseEvent, Extension, Xid, }; @@ -60,15 +64,34 @@ impl WM<'_> { c.configure_notify(&self.conn); } else { + let (mut x, mut y, mut width, mut height, mut border_width) = + (0_i32, 0_i32, 0_u32, 0_u32, 0_u32); + + if e.value_mask().contains(ConfigWindowMask::X) { + x = e.x() as i32; + } + if e.value_mask().contains(ConfigWindowMask::Y) { + y = e.y() as i32; + } + if e.value_mask().contains(ConfigWindowMask::HEIGHT) { + height = e.height() as u32; + } + if e.value_mask().contains(ConfigWindowMask::WIDTH) { + width = e.width() as u32; + } + if e.value_mask().contains(ConfigWindowMask::BORDER_WIDTH) { + border_width = e.border_width() as u32; + } + // Configure it as requested, and sort the rest when we actually map the window self.conn.send_and_check_request(&ConfigureWindow { window: e.window(), value_list: &[ - ConfigWindow::X(e.x().into()), - ConfigWindow::Y(e.y().into()), - ConfigWindow::Width(e.width().into()), - ConfigWindow::Height(e.height().into()), - ConfigWindow::BorderWidth(e.border_width().into()), + ConfigWindow::X(x), + ConfigWindow::Y(y), + ConfigWindow::Width(width), + ConfigWindow::Height(height), + ConfigWindow::BorderWidth(border_width), ConfigWindow::StackMode(e.stack_mode()), ], })?; @@ -167,10 +190,27 @@ impl ClientState { let new_idx = self.clients.len(); self.clients.push(Client::new(window, tag)); + let Ok(geom) = conn.wait_for_reply(conn.send_request(&GetGeometry { + drawable: Drawable::Window(window), + })) else { + return; // window stopped existing, so we can't manage it + }; let mon_geom = self.focused_mon().screen_info; let c = &mut self.clients[new_idx]; + #[allow(clippy::cast_sign_loss)] + c.set_geom( + conn, + geom.x(), + geom.y(), + min(geom.width(), mon_geom.width.saturating_sub(geom.x() as u16)), + min( + geom.height(), + mon_geom.height.saturating_sub(geom.y() as u16), + ), + BORDER_WIDTH, + ); c.set_border(conn, conn.colours.border_normal()); if floating { c.set_floating(conn); |