Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a scroll wheel hack for the Mac #17

Merged
merged 1 commit into from Jun 6, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add a scroll wheel hack for the Mac

  • Loading branch information
pcwalton committed Jun 6, 2013
commit 969af0260ef38d2c80ef2f51037da7ed1fc5cc85
@@ -15,6 +15,12 @@ extern mod std;

pub mod glut;

#[cfg(target_os="macos")]
pub mod machack;
#[cfg(not(target_os="macos"))]
#[path="machackstub.rs"]
pub mod machack;

#[cfg(test)]
pub mod test;

@@ -0,0 +1,36 @@
extern mod cocoa;

use glut::mouse_callback_tls_key;

use core::cast::transmute;
use core::local_data::local_data_get;
use machack::cocoa::base::{SEL, class_addMethod, id, msg_send_double, objc_getClass};
use machack::cocoa::base::{sel_registerName};

extern fn scrollWheelImpl(this: id, _cmd: SEL, event: id) {
unsafe {
let sel_deltaY = sel_registerName(transmute(&"deltaY"[0]));
let delta_y = msg_send_double(event, sel_deltaY);
let button = if delta_y == 0.0 {
return
} else if delta_y > 0.0 {
3
} else {
4
};
let callback = local_data_get(mouse_callback_tls_key).get();
(*callback)(button, 1, 0, 0);
}
}

pub fn perform_scroll_wheel_hack() {
unsafe {
let sel_scrollWheel = sel_registerName(transmute(&"scrollWheel:"[0]));
let class_GLUTView = objc_getClass(transmute(&"GLUTView"[0]));
class_addMethod(class_GLUTView,
sel_scrollWheel,
transmute(scrollWheelImpl),
transmute(&"v@:@"[0]));
}
}

@@ -0,0 +1,4 @@
pub fn perform_scroll_wheel_hack() {
// Just a stub.
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.