Merge branch 'refactor_point-size' into feature-fullscreen
This commit is contained in:
commit
25c0d94217
|
@ -1,7 +1,5 @@
|
|||
use super::{
|
||||
window_event,
|
||||
window_event::{KeyOrMouseBind, Point},
|
||||
};
|
||||
use super::window_event::{self, KeyOrMouseBind};
|
||||
use crate::util::{Point, Size};
|
||||
|
||||
pub trait WindowServerBackend {
|
||||
type Window;
|
||||
|
@ -26,13 +24,13 @@ pub trait WindowServerBackend {
|
|||
fn configure_window(
|
||||
&self,
|
||||
window: Self::Window,
|
||||
new_size: Option<Point<i32>>,
|
||||
new_size: Option<Size<i32>>,
|
||||
new_pos: Option<Point<i32>>,
|
||||
new_border: Option<i32>,
|
||||
);
|
||||
|
||||
fn screen_size(&self) -> Point<i32>;
|
||||
fn get_window_size(&self, window: Self::Window) -> Option<Point<i32>>;
|
||||
fn screen_size(&self) -> Size<i32>;
|
||||
fn get_window_size(&self, window: Self::Window) -> Option<Size<i32>>;
|
||||
|
||||
fn grab_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_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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use super::keycodes::{KeyOrButton, MouseButton, VirtualKeyCode};
|
||||
use crate::util::{Point, Size};
|
||||
use bitflags::bitflags;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -129,8 +130,6 @@ impl<Window> KeyEvent<Window> {
|
|||
}
|
||||
}
|
||||
|
||||
pub use crate::util::Point;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ButtonEvent<Window> {
|
||||
pub window: Window,
|
||||
|
@ -200,11 +199,11 @@ impl<Window> DestroyEvent<Window> {
|
|||
pub struct CreateEvent<Window> {
|
||||
pub window: Window,
|
||||
pub position: Point<i32>,
|
||||
pub size: Point<i32>,
|
||||
pub size: Size<i32>,
|
||||
}
|
||||
|
||||
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 {
|
||||
window,
|
||||
position,
|
||||
|
@ -217,11 +216,11 @@ impl<Window> CreateEvent<Window> {
|
|||
pub struct ConfigureEvent<Window> {
|
||||
pub window: Window,
|
||||
pub position: Point<i32>,
|
||||
pub size: Point<i32>,
|
||||
pub size: Size<i32>,
|
||||
}
|
||||
|
||||
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 {
|
||||
window,
|
||||
position,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use log::{error, warn};
|
||||
use num_traits::Zero;
|
||||
use std::{ffi::CString, mem::MaybeUninit, rc::Rc};
|
||||
|
||||
use thiserror::Error;
|
||||
|
@ -19,10 +20,11 @@ use super::{
|
|||
window_event::{
|
||||
ButtonEvent, ConfigureEvent, DestroyEvent, EnterEvent, FullscreenEvent,
|
||||
FullscreenState, KeyEvent, KeyOrMouseBind, KeyState, MapEvent,
|
||||
ModifierState, MotionEvent, Point, UnmapEvent, WindowEvent,
|
||||
ModifierState, MotionEvent, UnmapEvent, WindowEvent,
|
||||
},
|
||||
WindowServerBackend,
|
||||
};
|
||||
use crate::util::{Point, Size};
|
||||
|
||||
pub mod color;
|
||||
pub mod keysym;
|
||||
|
@ -804,8 +806,8 @@ impl WindowServerBackend for XLib {
|
|||
}
|
||||
|
||||
fn hide_window(&self, window: Self::Window) {
|
||||
let screen_size = self.screen_size();
|
||||
self.move_window(window, screen_size);
|
||||
let screen_size = self.screen_size() + Size::new(100, 100);
|
||||
self.move_window(window, screen_size.into());
|
||||
}
|
||||
|
||||
fn kill_window(&self, window: Self::Window) {
|
||||
|
@ -831,17 +833,17 @@ impl WindowServerBackend for XLib {
|
|||
fn configure_window(
|
||||
&self,
|
||||
window: Self::Window,
|
||||
new_size: Option<super::window_event::Point<i32>>,
|
||||
new_pos: Option<super::window_event::Point<i32>>,
|
||||
new_size: Option<crate::util::Size<i32>>,
|
||||
new_pos: Option<crate::util::Point<i32>>,
|
||||
new_border: Option<i32>,
|
||||
) {
|
||||
let position = new_pos.unwrap_or(Point::new(0, 0));
|
||||
let size = new_size.unwrap_or(Point::new(0, 0));
|
||||
let position = new_pos.unwrap_or(Point::zero());
|
||||
let size = new_size.unwrap_or(Size::zero());
|
||||
let mut wc = xlib::XWindowChanges {
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
width: size.x,
|
||||
height: size.y,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
border_width: new_border.unwrap_or(0),
|
||||
sibling: 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 {
|
||||
let mut wa =
|
||||
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)
|
||||
.map(|wa| (wa.width, wa.height).into())
|
||||
}
|
||||
|
|
|
@ -9,14 +9,13 @@ use crate::util::{Point, Size};
|
|||
mod client {
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use crate::util::{Point, Size};
|
||||
use x11::xlib::Window;
|
||||
|
||||
use crate::backends::window_event::Point;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Client {
|
||||
pub(crate) window: Window,
|
||||
pub(crate) size: Point<i32>,
|
||||
pub(crate) size: Size<i32>,
|
||||
pub(crate) position: Point<i32>,
|
||||
pub(crate) transient_for: Option<Window>,
|
||||
pub(crate) fullscreen: bool,
|
||||
|
@ -38,7 +37,7 @@ mod client {
|
|||
#[allow(dead_code)]
|
||||
pub fn new(
|
||||
window: Window,
|
||||
size: Point<i32>,
|
||||
size: Size<i32>,
|
||||
position: Point<i32>,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -51,7 +50,7 @@ mod client {
|
|||
|
||||
pub fn new_transient(
|
||||
window: Window,
|
||||
size: Point<i32>,
|
||||
size: Size<i32>,
|
||||
transient: Window,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -165,7 +164,7 @@ pub struct ClientState {
|
|||
pub(self) virtual_screens: VirtualScreenStore,
|
||||
|
||||
pub(self) gap: i32,
|
||||
pub(self) screen_size: Point<i32>,
|
||||
pub(self) screen_size: Size<i32>,
|
||||
pub(self) master_size: f32,
|
||||
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 {
|
||||
screen_size,
|
||||
..self
|
||||
|
@ -248,9 +247,9 @@ impl ClientState {
|
|||
client.position = {
|
||||
(
|
||||
transient.position.x
|
||||
+ (transient.size.x - client.size.x) / 2,
|
||||
+ (transient.size.width - client.size.width) / 2,
|
||||
transient.position.y
|
||||
+ (transient.size.y - client.size.y) / 2,
|
||||
+ (transient.size.height - client.size.height) / 2,
|
||||
)
|
||||
.into()
|
||||
};
|
||||
|
|
22
src/state.rs
22
src/state.rs
|
@ -4,13 +4,14 @@ use log::{error, info};
|
|||
|
||||
use x11::xlib::{self, Window};
|
||||
|
||||
use crate::backends::window_event::{FullscreenEvent, FullscreenState};
|
||||
use crate::util::{Point, Size};
|
||||
use crate::{
|
||||
backends::{
|
||||
keycodes::{MouseButton, VirtualKeyCode},
|
||||
window_event::{
|
||||
ButtonEvent, ConfigureEvent, FullscreenEvent, FullscreenState,
|
||||
KeyBind, KeyEvent, KeyState, MapEvent, ModifierKey, ModifierState,
|
||||
MotionEvent, MouseBind, Point, WindowEvent,
|
||||
ButtonEvent, ConfigureEvent, KeyBind, KeyEvent, KeyState, MapEvent,
|
||||
ModifierKey, ModifierState, MotionEvent, MouseBind, WindowEvent,
|
||||
},
|
||||
xlib::XLib,
|
||||
WindowServerBackend,
|
||||
|
@ -105,7 +106,7 @@ struct MoveInfoInner {
|
|||
struct ResizeInfoInner {
|
||||
window: Window,
|
||||
starting_cursor_pos: Point<i32>,
|
||||
starting_window_size: Point<i32>,
|
||||
starting_window_size: Size<i32>,
|
||||
}
|
||||
|
||||
use derivative::*;
|
||||
|
@ -780,12 +781,7 @@ where
|
|||
|
||||
let client = self.clients.get(&window).unwrap();
|
||||
|
||||
let corner_pos = {
|
||||
(
|
||||
client.position.x + client.size.x,
|
||||
client.position.y + client.size.y,
|
||||
)
|
||||
};
|
||||
let corner_pos = client.position + client.size.into();
|
||||
|
||||
self.backend.move_cursor(None, corner_pos.into());
|
||||
self.backend.grab_cursor();
|
||||
|
@ -844,8 +840,10 @@ where
|
|||
{
|
||||
let size = &mut client.size;
|
||||
|
||||
size.x = std::cmp::max(1, info.starting_window_size.x + x);
|
||||
size.y = std::cmp::max(1, info.starting_window_size.y + y);
|
||||
size.width =
|
||||
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);
|
||||
}
|
||||
|
|
82
src/util.rs
82
src/util.rs
|
@ -36,6 +36,47 @@ mod size {
|
|||
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>
|
||||
where
|
||||
I: num_traits::PrimInt + num_traits::Zero,
|
||||
|
@ -101,6 +142,47 @@ mod point {
|
|||
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>
|
||||
where
|
||||
I: num_traits::PrimInt + num_traits::Zero,
|
||||
|
|
Loading…
Reference in a new issue