rebase/corrected all cases of Point<I> that were sizes

This commit is contained in:
Janis 2021-12-02 20:43:02 +01:00
parent 5dbfa6fbcf
commit c3f3ad7203
6 changed files with 123 additions and 66 deletions

View file

@ -1,7 +1,5 @@
use super::{ use super::window_event::{self, KeyOrMouseBind};
window_event, use crate::util::{Point, Size};
window_event::{KeyOrMouseBind, Point},
};
pub trait WindowServerBackend { pub trait WindowServerBackend {
type Window; type Window;
@ -26,13 +24,13 @@ pub trait WindowServerBackend {
fn configure_window( fn configure_window(
&self, &self,
window: Self::Window, window: Self::Window,
new_size: Option<Point<i32>>, new_size: Option<Size<i32>>,
new_pos: Option<Point<i32>>, new_pos: Option<Point<i32>>,
new_border: Option<i32>, new_border: Option<i32>,
); );
fn screen_size(&self) -> Point<i32>; fn screen_size(&self) -> Size<i32>;
fn get_window_size(&self, window: Self::Window) -> Option<Point<i32>>; fn get_window_size(&self, window: Self::Window) -> Option<Size<i32>>;
fn grab_cursor(&self); fn grab_cursor(&self);
fn ungrab_cursor(&self); fn ungrab_cursor(&self);
@ -43,7 +41,7 @@ pub trait WindowServerBackend {
fn set_active_window_border_color(&mut self, color_name: &str); fn set_active_window_border_color(&mut self, color_name: &str);
fn set_inactive_window_border_color(&mut self, color_name: &str); fn set_inactive_window_border_color(&mut self, color_name: &str);
fn resize_window(&self, window: Self::Window, new_size: Point<i32>) { fn resize_window(&self, window: Self::Window, new_size: Size<i32>) {
self.configure_window(window, Some(new_size), None, None); self.configure_window(window, Some(new_size), None, None);
} }

View file

@ -1,6 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use super::keycodes::{KeyOrButton, MouseButton, VirtualKeyCode}; use super::keycodes::{KeyOrButton, MouseButton, VirtualKeyCode};
use crate::util::{Point, Size};
use bitflags::bitflags; use bitflags::bitflags;
#[derive(Debug)] #[derive(Debug)]
@ -129,8 +130,6 @@ impl<Window> KeyEvent<Window> {
} }
} }
pub use crate::util::Point;
#[derive(Debug)] #[derive(Debug)]
pub struct ButtonEvent<Window> { pub struct ButtonEvent<Window> {
pub window: Window, pub window: Window,
@ -200,11 +199,11 @@ impl<Window> DestroyEvent<Window> {
pub struct CreateEvent<Window> { pub struct CreateEvent<Window> {
pub window: Window, pub window: Window,
pub position: Point<i32>, pub position: Point<i32>,
pub size: Point<i32>, pub size: Size<i32>,
} }
impl<Window> CreateEvent<Window> { impl<Window> CreateEvent<Window> {
pub fn new(window: Window, position: Point<i32>, size: Point<i32>) -> Self { pub fn new(window: Window, position: Point<i32>, size: Size<i32>) -> Self {
Self { Self {
window, window,
position, position,
@ -217,11 +216,11 @@ impl<Window> CreateEvent<Window> {
pub struct ConfigureEvent<Window> { pub struct ConfigureEvent<Window> {
pub window: Window, pub window: Window,
pub position: Point<i32>, pub position: Point<i32>,
pub size: Point<i32>, pub size: Size<i32>,
} }
impl<Window> ConfigureEvent<Window> { impl<Window> ConfigureEvent<Window> {
pub fn new(window: Window, position: Point<i32>, size: Point<i32>) -> Self { pub fn new(window: Window, position: Point<i32>, size: Size<i32>) -> Self {
Self { Self {
window, window,
position, position,

View file

@ -1,4 +1,5 @@
use log::{error, warn}; use log::{error, warn};
use num_traits::Zero;
use std::{ffi::CString, mem::MaybeUninit, rc::Rc}; use std::{ffi::CString, mem::MaybeUninit, rc::Rc};
use thiserror::Error; use thiserror::Error;
@ -19,10 +20,11 @@ use super::{
window_event::{ window_event::{
ButtonEvent, ConfigureEvent, DestroyEvent, EnterEvent, FullscreenEvent, ButtonEvent, ConfigureEvent, DestroyEvent, EnterEvent, FullscreenEvent,
FullscreenState, KeyEvent, KeyOrMouseBind, KeyState, MapEvent, FullscreenState, KeyEvent, KeyOrMouseBind, KeyState, MapEvent,
ModifierState, MotionEvent, Point, UnmapEvent, WindowEvent, ModifierState, MotionEvent, UnmapEvent, WindowEvent,
}, },
WindowServerBackend, WindowServerBackend,
}; };
use crate::util::{Point, Size};
pub mod color; pub mod color;
pub mod keysym; pub mod keysym;
@ -804,8 +806,8 @@ impl WindowServerBackend for XLib {
} }
fn hide_window(&self, window: Self::Window) { fn hide_window(&self, window: Self::Window) {
let screen_size = self.screen_size(); let screen_size = self.screen_size() + Size::new(100, 100);
self.move_window(window, screen_size); self.move_window(window, screen_size.into());
} }
fn kill_window(&self, window: Self::Window) { fn kill_window(&self, window: Self::Window) {
@ -831,17 +833,17 @@ impl WindowServerBackend for XLib {
fn configure_window( fn configure_window(
&self, &self,
window: Self::Window, window: Self::Window,
new_size: Option<super::window_event::Point<i32>>, new_size: Option<crate::util::Size<i32>>,
new_pos: Option<super::window_event::Point<i32>>, new_pos: Option<crate::util::Point<i32>>,
new_border: Option<i32>, new_border: Option<i32>,
) { ) {
let position = new_pos.unwrap_or(Point::new(0, 0)); let position = new_pos.unwrap_or(Point::zero());
let size = new_size.unwrap_or(Point::new(0, 0)); let size = new_size.unwrap_or(Size::zero());
let mut wc = xlib::XWindowChanges { let mut wc = xlib::XWindowChanges {
x: position.x, x: position.x,
y: position.y, y: position.y,
width: size.x, width: size.width,
height: size.y, height: size.height,
border_width: new_border.unwrap_or(0), border_width: new_border.unwrap_or(0),
sibling: 0, sibling: 0,
stack_mode: 0, stack_mode: 0,
@ -867,7 +869,7 @@ impl WindowServerBackend for XLib {
} }
} }
fn screen_size(&self) -> Point<i32> { fn screen_size(&self) -> Size<i32> {
unsafe { unsafe {
let mut wa = let mut wa =
std::mem::MaybeUninit::<xlib::XWindowAttributes>::zeroed(); std::mem::MaybeUninit::<xlib::XWindowAttributes>::zeroed();
@ -880,7 +882,7 @@ impl WindowServerBackend for XLib {
} }
} }
fn get_window_size(&self, window: Self::Window) -> Option<Point<i32>> { fn get_window_size(&self, window: Self::Window) -> Option<Size<i32>> {
self.get_window_attributes(window) self.get_window_attributes(window)
.map(|wa| (wa.width, wa.height).into()) .map(|wa| (wa.width, wa.height).into())
} }

View file

@ -9,14 +9,13 @@ use crate::util::{Point, Size};
mod client { mod client {
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use crate::util::{Point, Size};
use x11::xlib::Window; use x11::xlib::Window;
use crate::backends::window_event::Point;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Client { pub struct Client {
pub(crate) window: Window, pub(crate) window: Window,
pub(crate) size: Point<i32>, pub(crate) size: Size<i32>,
pub(crate) position: Point<i32>, pub(crate) position: Point<i32>,
pub(crate) transient_for: Option<Window>, pub(crate) transient_for: Option<Window>,
pub(crate) fullscreen: bool, pub(crate) fullscreen: bool,
@ -38,7 +37,7 @@ mod client {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new( pub fn new(
window: Window, window: Window,
size: Point<i32>, size: Size<i32>,
position: Point<i32>, position: Point<i32>,
) -> Self { ) -> Self {
Self { Self {
@ -51,7 +50,7 @@ mod client {
pub fn new_transient( pub fn new_transient(
window: Window, window: Window,
size: Point<i32>, size: Size<i32>,
transient: Window, transient: Window,
) -> Self { ) -> Self {
Self { Self {
@ -165,7 +164,7 @@ pub struct ClientState {
pub(self) virtual_screens: VirtualScreenStore, pub(self) virtual_screens: VirtualScreenStore,
pub(self) gap: i32, pub(self) gap: i32,
pub(self) screen_size: Point<i32>, pub(self) screen_size: Size<i32>,
pub(self) master_size: f32, pub(self) master_size: f32,
border_size: i32, border_size: i32,
} }
@ -214,7 +213,7 @@ impl ClientState {
} }
} }
pub fn with_screen_size(self, screen_size: Point<i32>) -> Self { pub fn with_screen_size(self, screen_size: Size<i32>) -> Self {
Self { Self {
screen_size, screen_size,
..self ..self
@ -248,9 +247,9 @@ impl ClientState {
client.position = { client.position = {
( (
transient.position.x transient.position.x
+ (transient.size.x - client.size.x) / 2, + (transient.size.width - client.size.width) / 2,
transient.position.y transient.position.y
+ (transient.size.y - client.size.y) / 2, + (transient.size.height - client.size.height) / 2,
) )
.into() .into()
}; };

View file

@ -4,13 +4,13 @@ use log::{error, info};
use x11::xlib::{self, Window}; use x11::xlib::{self, Window};
use crate::util::{Point, Size};
use crate::{ use crate::{
backends::{ backends::{
keycodes::{MouseButton, VirtualKeyCode}, keycodes::{MouseButton, VirtualKeyCode},
window_event::{ window_event::{
ButtonEvent, ConfigureEvent, FullscreenEvent, FullscreenState, ButtonEvent, ConfigureEvent, KeyBind, KeyEvent, KeyState, MapEvent,
KeyBind, KeyEvent, KeyState, MapEvent, ModifierKey, ModifierState, ModifierKey, ModifierState, MotionEvent, MouseBind, WindowEvent,
MotionEvent, MouseBind, Point, WindowEvent,
}, },
xlib::XLib, xlib::XLib,
WindowServerBackend, WindowServerBackend,
@ -105,7 +105,7 @@ struct MoveInfoInner {
struct ResizeInfoInner { struct ResizeInfoInner {
window: Window, window: Window,
starting_cursor_pos: Point<i32>, starting_cursor_pos: Point<i32>,
starting_window_size: Point<i32>, starting_window_size: Size<i32>,
} }
use derivative::*; use derivative::*;
@ -464,26 +464,6 @@ where
// None => self.xlib.configure_window(event), // None => self.xlib.configure_window(event),
// } // }
} }
WindowEvent::FullscreenEvent(FullscreenEvent {
window,
state,
}) => {
info!("FullscreenEvent for window {}: {:?}", window, state);
if match state {
FullscreenState::On => {
self.clients.set_fullscreen(&window, true)
}
FullscreenState::Off => {
self.clients.set_fullscreen(&window, false)
}
FullscreenState::Toggle => {
self.clients.toggle_fullscreen(&window)
}
} {
self.arrange_clients();
}
}
// i dont think i actually have to handle destroy notify events. // i dont think i actually have to handle destroy notify events.
// every window should be unmapped regardless // every window should be unmapped regardless
@ -782,12 +762,7 @@ where
let client = self.clients.get(&window).unwrap(); let client = self.clients.get(&window).unwrap();
let corner_pos = { let corner_pos = client.position + client.size.into();
(
client.position.x + client.size.x,
client.position.y + client.size.y,
)
};
self.backend.move_cursor(None, corner_pos.into()); self.backend.move_cursor(None, corner_pos.into());
self.backend.grab_cursor(); self.backend.grab_cursor();
@ -846,8 +821,10 @@ where
{ {
let size = &mut client.size; let size = &mut client.size;
size.x = std::cmp::max(1, info.starting_window_size.x + x); size.width =
size.y = std::cmp::max(1, info.starting_window_size.y + y); std::cmp::max(1, info.starting_window_size.width + x);
size.height =
std::cmp::max(1, info.starting_window_size.height + y);
self.backend.resize_window(client.window, client.size); self.backend.resize_window(client.window, client.size);
} }

View file

@ -36,6 +36,47 @@ mod size {
pub height: I, pub height: I,
} }
impl<I> std::ops::Add for Size<I>
where
I: num_traits::PrimInt + num_traits::Zero,
{
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
width: self.width + rhs.width,
height: self.height + rhs.height,
}
}
}
impl<I> std::ops::Sub for Size<I>
where
I: num_traits::PrimInt + num_traits::Zero,
{
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
Self {
width: self.width - rhs.width,
height: self.height - rhs.height,
}
}
}
impl<I> num_traits::Zero for Size<I>
where
I: num_traits::PrimInt + num_traits::Zero,
{
fn zero() -> Self {
Self::default()
}
fn is_zero(&self) -> bool {
self.width == I::zero() && self.height == I::zero()
}
}
impl<I> Default for Size<I> impl<I> Default for Size<I>
where where
I: num_traits::PrimInt + num_traits::Zero, I: num_traits::PrimInt + num_traits::Zero,
@ -101,6 +142,47 @@ mod point {
pub y: I, pub y: I,
} }
impl<I> std::ops::Add for Point<I>
where
I: num_traits::PrimInt + num_traits::Zero,
{
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
impl<I> std::ops::Sub for Point<I>
where
I: num_traits::PrimInt + num_traits::Zero,
{
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
Self {
x: self.x - rhs.x,
y: self.y - rhs.y,
}
}
}
impl<I> num_traits::Zero for Point<I>
where
I: num_traits::PrimInt + num_traits::Zero,
{
fn zero() -> Self {
Self::default()
}
fn is_zero(&self) -> bool {
self.x == I::zero() && self.y == I::zero()
}
}
impl<I> Default for Point<I> impl<I> Default for Point<I>
where where
I: num_traits::PrimInt + num_traits::Zero, I: num_traits::PrimInt + num_traits::Zero,