diff --git a/glut.rs b/glut.rs index 96c35ab..999823d 100644 --- a/glut.rs +++ b/glut.rs @@ -14,7 +14,7 @@ use glut::bindgen::{glutKeyboardFunc, glutGetModifiers, glutMotionFunc, glutPass use glut::bindgen::{glutGet, glutGetWindow}; use glut::bindgen::{glutInit, glutInitDisplayMode, glutPostRedisplay, glutReshapeFunc}; use glut::bindgen::{glutReshapeWindow, glutSetWindow, glutSetWindowTitle, glutSwapBuffers}; -use glut::bindgen::{glutTimerFunc}; +use glut::bindgen::{glutTimerFunc, glutIdleFunc}; use core::libc::*; use core::local_data::{local_data_get, local_data_set}; use core::ptr::{null, to_unsafe_ptr}; @@ -111,7 +111,7 @@ pub fn set_window(window: Window) { } } -pub fn set_window_title(window: Window, title: ~str) { +pub fn set_window_title(window: Window, title: &str) { unsafe { let bytes = to_bytes(title); glutSetWindowTitle(to_ptr(bytes) as *c_char); @@ -265,6 +265,24 @@ pub fn reshape_func(_window: Window, callback: @fn(x: c_int, y: c_int)) { } } +pub fn idle_callback_tls_key(_callback: @@fn()) { + // Empty. +} + +pub extern fn idle_callback() { + unsafe { + let callback = local_data_get(idle_callback_tls_key).get(); + (*callback)(); + } +} + +pub fn idle_func(callback: @fn()) { + unsafe { + local_data_set(idle_callback_tls_key, @callback); + glutIdleFunc(idle_callback); + } +} + // Mouse wheel handling. // // This is not part of the standard, but it's supported by freeglut and our Mac hack.