fullscreen windows can no longer be resized or moved

This commit is contained in:
Janis 2021-12-02 22:16:57 +01:00
parent 192f865fec
commit 2c6d4fd465
2 changed files with 108 additions and 62 deletions

View file

@ -2,6 +2,7 @@ use std::{ops::Rem, usize};
use indexmap::IndexMap; use indexmap::IndexMap;
use log::error; use log::error;
use num_traits::Zero;
use crate::util::BuildIdentityHasher; use crate::util::BuildIdentityHasher;
use crate::util::{Point, Size}; use crate::util::{Point, Size};
@ -457,13 +458,20 @@ impl ClientState {
where where
K: ClientKey, K: ClientKey,
{ {
self.get_mut(key) let fullscreen_size = self.screen_size
.into_option() - Size::new(self.border_size * 2, self.border_size * 2);
.map(|client| {
client.toggle_fullscreen(); match self.get_mut(key).into_option() {
Some(client) => {
if client.toggle_fullscreen() {
client.size = fullscreen_size;
client.position = Point::zero();
}
true true
}) }
.unwrap_or(false) None => false,
}
} }
/** /**
@ -491,35 +499,48 @@ impl ClientState {
where where
K: ClientKey, K: ClientKey,
{ {
let key = key.key(); // do nothing if either no client matches the key or the client is fullscreen.
let client = self.clients.remove(&key); // FIXME: this should probably disable fullscreen mode (but that has to
let floating_client = self.floating_clients.remove(&key); // be handled in the wm state so that the backend can notify the client
// that it is no longer fullscreen)
if !self
.get(key)
.into_option()
.map(|c| c.is_fullscreen())
.unwrap_or(true)
{
let key = key.key();
let client = self.clients.remove(&key);
let floating_client = self.floating_clients.remove(&key);
match (client, floating_client) { match (client, floating_client) {
(Some(client), None) => { (Some(client), None) => {
self.floating_clients.insert(key, client); self.floating_clients.insert(key, client);
self.remove_from_virtual_screens(&key); self.remove_from_virtual_screens(&key);
} }
(None, Some(floating_client)) => { (None, Some(floating_client)) => {
// transient clients cannot be tiled // transient clients cannot be tiled
match floating_client.is_transient() { match floating_client.is_transient() {
true => { true => {
self.floating_clients.insert(key, floating_client); self.floating_clients.insert(key, floating_client);
} }
false => { false => {
self.clients.insert(key, floating_client); self.clients.insert(key, floating_client);
self.virtual_screens.get_mut_current().insert(&key); self.virtual_screens.get_mut_current().insert(&key);
}
} }
} }
} _ => {
_ => { error!(
error!("wtf? Client was present in tiled and floating list.") "wtf? Client was present in tiled and floating list."
} )
}; }
};
// we added or removed a client from the tiling so the layout changed, rearrange // we added or removed a client from the tiling so the layout changed, rearrange
self.arrange_virtual_screen(); self.arrange_virtual_screen();
}
} }
fn remove_from_virtual_screens<K>(&mut self, key: &K) fn remove_from_virtual_screens<K>(&mut self, key: &K)
@ -1007,3 +1028,25 @@ impl<T> ClientEntry<T> {
!self.is_vacant() !self.is_vacant()
} }
} }
impl ClientEntry<&client::Client> {
pub fn is_fullscreen(&self) -> bool {
match self {
ClientEntry::Tiled(c) | ClientEntry::Floating(c) => {
c.is_fullscreen()
}
ClientEntry::Vacant => false,
}
}
}
impl ClientEntry<&mut client::Client> {
pub fn is_fullscreen(&self) -> bool {
match self {
ClientEntry::Tiled(c) | ClientEntry::Floating(c) => {
c.is_fullscreen()
}
ClientEntry::Vacant => false,
}
}
}

View file

@ -758,42 +758,45 @@ where
fn start_move_resize_window(&mut self, event: &ButtonEvent<B::Window>) { fn start_move_resize_window(&mut self, event: &ButtonEvent<B::Window>) {
let window = event.window; // xev.subwindow let window = event.window; // xev.subwindow
match event.keycode { if !self.clients.get(&window).is_fullscreen() {
MouseButton::Left => { match event.keycode {
if self.clients.set_floating(&window) { MouseButton::Left => {
self.arrange_clients(); if self.clients.set_floating(&window) {
self.arrange_clients();
}
self.move_resize_window =
MoveResizeInfo::Move(MoveInfoInner {
window,
starting_cursor_pos: event.cursor_position,
starting_window_pos: self
.clients
.get(&window)
.unwrap()
.position,
});
} }
MouseButton::Right => {
if self.clients.set_floating(&window) {
self.arrange_clients();
}
self.move_resize_window = MoveResizeInfo::Move(MoveInfoInner { let client = self.clients.get(&window).unwrap();
window,
starting_cursor_pos: event.cursor_position, let corner_pos = client.position + client.size.into();
starting_window_pos: self
.clients self.backend.move_cursor(None, corner_pos.into());
.get(&window) self.backend.grab_cursor();
.unwrap()
.position, self.move_resize_window =
}); MoveResizeInfo::Resize(ResizeInfoInner {
} window,
MouseButton::Right => { starting_cursor_pos: corner_pos.into(),
if self.clients.set_floating(&window) { starting_window_size: client.size,
self.arrange_clients(); });
} }
_ => {}
let client = self.clients.get(&window).unwrap();
let corner_pos = client.position + client.size.into();
self.backend.move_cursor(None, corner_pos.into());
self.backend.grab_cursor();
self.move_resize_window =
MoveResizeInfo::Resize(ResizeInfoInner {
window,
starting_cursor_pos: corner_pos.into(),
starting_window_size: client.size,
});
} }
_ => {}
} }
} }