Skip to content

Commit

Permalink
fix performance issue resizing/moving windows
Browse files Browse the repository at this point in the history
lex148 committed Oct 26, 2020
1 parent 644e0bc commit ee7c003
Showing 5 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/display_event.rs
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ pub enum DisplayEvent {
WindowChange(WindowChange),
WindowDestroy(WindowHandle),
FocusedWindow(WindowHandle, i32, i32),
MoveWindow(WindowHandle, i32, i32),
ResizeWindow(WindowHandle, i32, i32),
MoveWindow(WindowHandle, u64, i32, i32),
ResizeWindow(WindowHandle, u64, i32, i32),
ScreenCreate(Screen),
SendCommand(Command, Option<String>),
ChangeToNormalMode,
18 changes: 13 additions & 5 deletions src/display_servers/xlib_display_server/event_translate.rs
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ impl<'a> From<XEvent<'a>> for Option<DisplayEvent> {

if w.floating() {
if let Ok(geo) = xw.get_window_geometry(event.window) {
log::debug!("geo: {geo:?}", geo=geo);
log::debug!("geo: {geo:?}", geo = geo);
geo.update_window_floating(&mut w);
}
}
@@ -145,11 +145,19 @@ impl<'a> From<XEvent<'a>> for Option<DisplayEvent> {
Mode::NormalMode => {
Some(DisplayEvent::Movement(event_h, event.x_root, event.y_root))
}
Mode::MovingWindow(h) => {
Some(DisplayEvent::MoveWindow(h.clone(), offset_x, offset_y))
}
Mode::MovingWindow(h) => Some(DisplayEvent::MoveWindow(
h.clone(),
event.time,
offset_x,
offset_y,
)),
Mode::ResizingWindow(h) => {
Some(DisplayEvent::ResizeWindow(h.clone(), offset_x, offset_y))
Some(DisplayEvent::ResizeWindow(
h.clone(),
event.time,
offset_x,
offset_y,
))
//h, w
}
}
20 changes: 16 additions & 4 deletions src/handlers/display_event_handler.rs
Original file line number Diff line number Diff line change
@@ -54,11 +54,23 @@ impl DisplayEventHandler {
}
}

DisplayEvent::MoveWindow(handle, x, y) => {
window_move_handler::process(manager, &handle, x, y)
DisplayEvent::MoveWindow(handle, time, x, y) => {
//limit the frame rate to 60f/sec. otherwise you get lag
let mut refresh = false;
if (time - manager.frame_rate_limitor) > (1000 / 60) {
refresh = window_move_handler::process(manager, &handle, x, y);
manager.frame_rate_limitor = time;
}
refresh
}
DisplayEvent::ResizeWindow(handle, x, y) => {
window_resize_handler::process(manager, &handle, x, y)
DisplayEvent::ResizeWindow(handle, time, x, y) => {
//limit the frame rate to 60f/sec. otherwise you get lag
let mut refresh = false;
if (time - manager.frame_rate_limitor) > (1000 / 60) {
refresh = window_resize_handler::process(manager, &handle, x, y);
manager.frame_rate_limitor = time;
}
refresh
}
};

4 changes: 2 additions & 2 deletions src/handlers/window_resize_handler.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ pub fn process(manager: &mut Manager, handle: &WindowHandle, offset_w: i32, offs
return true;
}
}
true
false
}

fn process_window(window: &mut Window, offset_w: i32, offset_h: i32) {
@@ -17,7 +17,7 @@ fn process_window(window: &mut Window, offset_w: i32, offset_h: i32) {
.get_floating_offsets()
.unwrap_or(XYHWBuilder::default().into());
let start = window.start_loc.unwrap_or(XYHWBuilder::default().into());
offset.clear_minmax();
//offset.clear_minmax();
offset.set_w(start.w() + offset_w);
offset.set_h(start.h() + offset_h);
window.set_floating_offsets(Some(offset));
3 changes: 3 additions & 0 deletions src/models/manager.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@ pub struct Manager {
pub focused_window_history: VecDeque<WindowHandle>,
pub focused_tag_history: VecDeque<String>,
pub actions: VecDeque<DisplayAction>,

//this is used to limit framerate when resizing/moving windows
pub frame_rate_limitor: u64,
#[serde(skip)]
pub children: Children,
#[serde(skip)]

0 comments on commit ee7c003

Please sign in to comment.