changed multiple (i32, i32)
tuples to Point<i32>
This commit is contained in:
parent
af21769d52
commit
aafbcf2314
|
@ -4,6 +4,7 @@ use std::{ops::Rem, usize};
|
|||
use indexmap::IndexMap;
|
||||
use log::{error, info};
|
||||
|
||||
use crate::backends::window_event::Point;
|
||||
use crate::util::BuildIdentityHasher;
|
||||
|
||||
mod client {
|
||||
|
@ -11,11 +12,13 @@ mod client {
|
|||
|
||||
use x11::xlib::Window;
|
||||
|
||||
use crate::backends::window_event::Point;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Client {
|
||||
pub(crate) window: Window,
|
||||
pub(crate) size: (i32, i32),
|
||||
pub(crate) position: (i32, i32),
|
||||
pub(crate) size: Point<i32>,
|
||||
pub(crate) position: Point<i32>,
|
||||
pub(crate) transient_for: Option<Window>,
|
||||
}
|
||||
|
||||
|
@ -23,8 +26,8 @@ mod client {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
window: 0,
|
||||
size: (100, 100),
|
||||
position: (0, 0),
|
||||
size: (100, 100).into(),
|
||||
position: (0, 0).into(),
|
||||
transient_for: None,
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +37,8 @@ mod client {
|
|||
#[allow(dead_code)]
|
||||
pub fn new(
|
||||
window: Window,
|
||||
size: (i32, i32),
|
||||
position: (i32, i32),
|
||||
size: Point<i32>,
|
||||
position: Point<i32>,
|
||||
) -> Self {
|
||||
Self {
|
||||
window,
|
||||
|
@ -47,7 +50,7 @@ mod client {
|
|||
|
||||
pub fn new_transient(
|
||||
window: Window,
|
||||
size: (i32, i32),
|
||||
size: Point<i32>,
|
||||
transient: Window,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -140,7 +143,7 @@ pub struct ClientState {
|
|||
pub(self) virtual_screens: VirtualScreenStore,
|
||||
|
||||
pub(self) gap: i32,
|
||||
pub(self) screen_size: (i32, i32),
|
||||
pub(self) screen_size: Point<i32>,
|
||||
pub(self) master_size: f32,
|
||||
border_size: i32,
|
||||
}
|
||||
|
@ -166,7 +169,7 @@ impl Default for ClientState {
|
|||
focused: None,
|
||||
virtual_screens: VirtualScreenStore::new(1),
|
||||
gap: 0,
|
||||
screen_size: (1, 1),
|
||||
screen_size: (1, 1).into(),
|
||||
master_size: 1.0,
|
||||
border_size: 0,
|
||||
}
|
||||
|
@ -189,7 +192,7 @@ impl ClientState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_screen_size(self, screen_size: (i32, i32)) -> Self {
|
||||
pub fn with_screen_size(self, screen_size: Point<i32>) -> Self {
|
||||
Self {
|
||||
screen_size,
|
||||
..self
|
||||
|
@ -222,11 +225,12 @@ impl ClientState {
|
|||
|
||||
client.position = {
|
||||
(
|
||||
transient.position.0
|
||||
+ (transient.size.0 - client.size.0) / 2,
|
||||
transient.position.1
|
||||
+ (transient.size.1 - client.size.1) / 2,
|
||||
transient.position.x
|
||||
+ (transient.size.x - client.size.x) / 2,
|
||||
transient.position.y
|
||||
+ (transient.size.y - client.size.y) / 2,
|
||||
)
|
||||
.into()
|
||||
};
|
||||
|
||||
self.floating_clients.insert(key, client);
|
||||
|
@ -623,7 +627,7 @@ impl ClientState {
|
|||
*/
|
||||
pub fn arrange_virtual_screen(&mut self) {
|
||||
let gap = self.gap;
|
||||
let (width, height) = self.screen_size;
|
||||
let (width, height) = self.screen_size.as_tuple();
|
||||
|
||||
// should be fine to unwrap since we will always have at least 1 virtual screen
|
||||
let vs = self.virtual_screens.get_mut_current();
|
||||
|
@ -670,8 +674,8 @@ impl ClientState {
|
|||
|
||||
if let Some(client) = self.clients.get_mut(key) {
|
||||
*client = Client {
|
||||
size,
|
||||
position,
|
||||
size: size.into(),
|
||||
position: position.into(),
|
||||
..*client
|
||||
};
|
||||
}
|
||||
|
@ -689,8 +693,8 @@ impl ClientState {
|
|||
|
||||
if let Some(client) = self.clients.get_mut(key) {
|
||||
*client = Client {
|
||||
size,
|
||||
position,
|
||||
size: size.into(),
|
||||
position: position.into(),
|
||||
..*client
|
||||
};
|
||||
}
|
||||
|
|
40
src/state.rs
40
src/state.rs
|
@ -13,7 +13,7 @@ use crate::{
|
|||
keycodes::{MouseButton, VirtualKeyCode},
|
||||
window_event::{
|
||||
ButtonEvent, KeyBind, KeyEvent, KeyState, ModifierKey,
|
||||
ModifierState,
|
||||
ModifierState, Point,
|
||||
},
|
||||
xlib::XLib,
|
||||
WindowServerBackend,
|
||||
|
@ -59,14 +59,14 @@ enum MoveResizeInfo {
|
|||
|
||||
struct MoveInfoInner {
|
||||
window: Window,
|
||||
starting_cursor_pos: (i32, i32),
|
||||
starting_window_pos: (i32, i32),
|
||||
starting_cursor_pos: Point<i32>,
|
||||
starting_window_pos: Point<i32>,
|
||||
}
|
||||
|
||||
struct ResizeInfoInner {
|
||||
window: Window,
|
||||
starting_cursor_pos: (i32, i32),
|
||||
starting_window_size: (i32, i32),
|
||||
starting_cursor_pos: Point<i32>,
|
||||
starting_window_size: Point<i32>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -97,7 +97,7 @@ where
|
|||
B: WindowServerBackend<Window = xlib::Window>,
|
||||
{
|
||||
pub fn new(config: WMConfig) -> Self {
|
||||
let backend = B::new();
|
||||
let backend = B::build();
|
||||
|
||||
let clients = ClientState::new()
|
||||
.with_virtualscreens(config.num_virtualscreens)
|
||||
|
@ -600,7 +600,9 @@ where
|
|||
{
|
||||
Client::new_transient(
|
||||
window,
|
||||
self.backend.get_window_size(window).unwrap_or((100, 100)),
|
||||
self.backend
|
||||
.get_window_size(window)
|
||||
.unwrap_or((100, 100).into()),
|
||||
transient_window,
|
||||
)
|
||||
} else {
|
||||
|
@ -670,7 +672,7 @@ where
|
|||
|
||||
self.move_resize_window = MoveResizeInfo::Move(MoveInfoInner {
|
||||
window,
|
||||
starting_cursor_pos: event.cursor_position.as_tuple(),
|
||||
starting_cursor_pos: event.cursor_position,
|
||||
starting_window_pos: self
|
||||
.clients
|
||||
.get(&window)
|
||||
|
@ -687,8 +689,8 @@ where
|
|||
|
||||
let corner_pos = {
|
||||
(
|
||||
client.position.0 + client.size.0,
|
||||
client.position.1 + client.size.1,
|
||||
client.position.x + client.size.x,
|
||||
client.position.y + client.size.y,
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -699,7 +701,7 @@ where
|
|||
self.move_resize_window =
|
||||
MoveResizeInfo::Resize(ResizeInfoInner {
|
||||
window,
|
||||
starting_cursor_pos: corner_pos,
|
||||
starting_cursor_pos: corner_pos.into(),
|
||||
starting_window_size: client.size,
|
||||
});
|
||||
}
|
||||
|
@ -725,8 +727,8 @@ where
|
|||
match &self.move_resize_window {
|
||||
MoveResizeInfo::Move(info) => {
|
||||
let (x, y) = (
|
||||
event.x - info.starting_cursor_pos.0,
|
||||
event.y - info.starting_cursor_pos.1,
|
||||
event.x - info.starting_cursor_pos.x,
|
||||
event.y - info.starting_cursor_pos.y,
|
||||
);
|
||||
|
||||
if let Some(client) =
|
||||
|
@ -734,16 +736,16 @@ where
|
|||
{
|
||||
let position = &mut client.position;
|
||||
|
||||
position.0 = info.starting_window_pos.0 + x;
|
||||
position.1 = info.starting_window_pos.1 + y;
|
||||
position.x = info.starting_window_pos.x + x;
|
||||
position.y = info.starting_window_pos.y + y;
|
||||
|
||||
self.backend.move_window(client.window, client.position);
|
||||
}
|
||||
}
|
||||
MoveResizeInfo::Resize(info) => {
|
||||
let (x, y) = (
|
||||
event.x - info.starting_cursor_pos.0,
|
||||
event.y - info.starting_cursor_pos.1,
|
||||
event.x - info.starting_cursor_pos.x,
|
||||
event.y - info.starting_cursor_pos.y,
|
||||
);
|
||||
|
||||
if let Some(client) =
|
||||
|
@ -751,8 +753,8 @@ where
|
|||
{
|
||||
let size = &mut client.size;
|
||||
|
||||
size.0 = std::cmp::max(1, info.starting_window_size.0 + x);
|
||||
size.1 = std::cmp::max(1, info.starting_window_size.1 + y);
|
||||
size.x = std::cmp::max(1, info.starting_window_size.x + x);
|
||||
size.y = std::cmp::max(1, info.starting_window_size.y + y);
|
||||
|
||||
self.backend.resize_window(client.window, client.size);
|
||||
}
|
||||
|
|
48
src/xlib.rs
48
src/xlib.rs
|
@ -274,16 +274,16 @@ impl XLib {
|
|||
|
||||
pub fn move_resize_client(&self, client: &Client) {
|
||||
let mut windowchanges = xlib::XWindowChanges {
|
||||
x: client.position.0,
|
||||
y: client.position.1,
|
||||
width: client.size.0,
|
||||
height: client.size.1,
|
||||
x: client.position.x,
|
||||
y: client.position.y,
|
||||
width: client.size.x,
|
||||
height: client.size.y,
|
||||
border_width: 0,
|
||||
sibling: 0,
|
||||
stack_mode: 0,
|
||||
};
|
||||
|
||||
if client.size.0 < 1 || client.size.1 < 1 {
|
||||
if client.size.x < 1 || client.size.y < 1 {
|
||||
error!("client {:?} size is less than 1 pixel!", client);
|
||||
} else {
|
||||
unsafe {
|
||||
|
@ -303,16 +303,16 @@ impl XLib {
|
|||
|
||||
pub fn move_client(&self, client: &Client) {
|
||||
let mut wc = xlib::XWindowChanges {
|
||||
x: client.position.0,
|
||||
y: client.position.1,
|
||||
width: client.size.0,
|
||||
height: client.size.1,
|
||||
x: client.position.x,
|
||||
y: client.position.y,
|
||||
width: client.size.x,
|
||||
height: client.size.y,
|
||||
border_width: 0,
|
||||
sibling: 0,
|
||||
stack_mode: 0,
|
||||
};
|
||||
|
||||
if client.size.0 < 1 || client.size.1 < 1 {
|
||||
if client.size.x < 1 || client.size.y < 1 {
|
||||
error!("client {:?} size is less than 1 pixel!", client);
|
||||
} else {
|
||||
unsafe {
|
||||
|
@ -328,16 +328,16 @@ impl XLib {
|
|||
|
||||
pub fn resize_client(&self, client: &Client) {
|
||||
let mut wc = xlib::XWindowChanges {
|
||||
x: client.position.0,
|
||||
y: client.position.1,
|
||||
width: client.size.0,
|
||||
height: client.size.1,
|
||||
x: client.position.x,
|
||||
y: client.position.y,
|
||||
width: client.size.x,
|
||||
height: client.size.y,
|
||||
border_width: 0,
|
||||
sibling: 0,
|
||||
stack_mode: 0,
|
||||
};
|
||||
|
||||
if client.size.0 < 1 || client.size.1 < 1 {
|
||||
if client.size.x < 1 || client.size.y < 1 {
|
||||
error!("client {:?} size is less than 1 pixel!", client);
|
||||
} else {
|
||||
unsafe {
|
||||
|
@ -353,16 +353,16 @@ impl XLib {
|
|||
|
||||
pub fn hide_client(&self, client: &Client) {
|
||||
let mut wc = xlib::XWindowChanges {
|
||||
x: client.size.0 * -2,
|
||||
y: client.position.1,
|
||||
width: client.size.0,
|
||||
height: client.size.1,
|
||||
x: client.size.x * -2,
|
||||
y: client.position.y,
|
||||
width: client.size.x,
|
||||
height: client.size.y,
|
||||
border_width: 0,
|
||||
sibling: 0,
|
||||
stack_mode: 0,
|
||||
};
|
||||
|
||||
if client.size.0 < 1 || client.size.1 < 1 {
|
||||
if client.size.x < 1 || client.size.y < 1 {
|
||||
error!("client {:?} size is less than 1 pixel!", client);
|
||||
} else {
|
||||
unsafe {
|
||||
|
@ -477,10 +477,10 @@ impl XLib {
|
|||
display: self.dpy(),
|
||||
event: client.window,
|
||||
window: client.window,
|
||||
x: client.position.0,
|
||||
y: client.position.1,
|
||||
width: client.size.0,
|
||||
height: client.size.1,
|
||||
x: client.position.x,
|
||||
y: client.position.y,
|
||||
width: client.size.x,
|
||||
height: client.size.y,
|
||||
border_width: border,
|
||||
override_redirect: 0,
|
||||
send_event: 0,
|
||||
|
|
Loading…
Reference in a new issue