Skip to content

Commit fdba642

Browse files
authored
Fix macOS timer not firing during modal loop. (#1028)
1 parent bbbca65 commit fdba642

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ You can find its changes [documented below](#060---2020-06-01).
1919

2020
### Fixed
2121

22+
- macOS: Timers not firing during modal loop. ([#1028] by [@xStrom])
2223
- GTK: Directory selection now properly ignores file filters. ([#957] by [@xStrom])
2324

2425
### Visual
@@ -322,6 +323,7 @@ Last release without a changelog :(
322323
[#1008]: https://github.com/xi-editor/druid/pull/1008
323324
[#1011]: https://github.com/xi-editor/druid/pull/1011
324325
[#1013]: https://github.com/xi-editor/druid/pull/1013
326+
[#1028]: https://github.com/xi-editor/druid/pull/1028
325327

326328
[Unreleased]: https://github.com/xi-editor/druid/compare/v0.6.0...master
327329
[0.6.0]: https://github.com/xi-editor/druid/compare/v0.5.0...v0.6.0

druid-shell/src/platform/mac/appkit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ use cocoa::base::id;
2222
use cocoa::foundation::NSRect;
2323
use objc::{class, msg_send, sel, sel_impl};
2424

25+
#[link(name = "AppKit", kind = "framework")]
26+
extern "C" {
27+
pub static NSRunLoopCommonModes: id;
28+
}
29+
2530
bitflags! {
2631
pub struct NSTrackingAreaOptions: i32 {
2732
const MouseEnteredAndExited = 1;

druid-shell/src/platform/mac/window.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ use objc::{class, msg_send, sel, sel_impl};
4343
use crate::kurbo::{Point, Rect, Size, Vec2};
4444
use crate::piet::{Piet, RenderContext};
4545

46-
use super::appkit::{NSTrackingArea, NSTrackingAreaOptions, NSView as NSViewExt};
46+
use super::appkit::{
47+
NSRunLoopCommonModes, NSTrackingArea, NSTrackingAreaOptions, NSView as NSViewExt,
48+
};
4749
use super::application::Application;
4850
use super::dialog;
4951
use super::menu::Menu;
@@ -804,7 +806,9 @@ impl WindowHandle {
804806
let user_info: id = msg_send![nsnumber, numberWithUnsignedInteger: token.into_raw()];
805807
let selector = sel!(handleTimer:);
806808
let view = self.nsview.load();
807-
let _: id = msg_send![nstimer, scheduledTimerWithTimeInterval: ti target: view selector: selector userInfo: user_info repeats: NO];
809+
let timer: id = msg_send![nstimer, timerWithTimeInterval: ti target: view selector: selector userInfo: user_info repeats: NO];
810+
let runloop: id = msg_send![class!(NSRunLoop), currentRunLoop];
811+
let () = msg_send![runloop, addTimer: timer forMode: NSRunLoopCommonModes];
808812
}
809813
token
810814
}

0 commit comments

Comments
 (0)