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