Skip to content

Commit

Permalink
unix::WindowExt no longer returns pointers for things that aren't act…
Browse files Browse the repository at this point in the history
…ually pointers

Fixes #256

`get_xlib_window` and `get_xlib_screen_id` previously returned `Option<*mut c_void>` by
casting integer IDs into pointers, which while producing no functionality issues, is
semantically incorrect and rather surprising. Worse still, the docs for `get_xlib_window`
stated that it was in fact a valid pointer.

This is a breaking change, and will require some trivial changes to glutin.
  • Loading branch information
francesca64 committed Dec 15, 2017
1 parent 9698d0a commit 9e8af57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Add support for `Touch` for emscripten backend.
- Added support for `DroppedFile`, `HoveredFile`, and `HoveredFileCancelled` to X11 backend.
- **Breaking:** `unix::WindowExt` no longer returns pointers for things that aren't actually pointers; `get_xlib_window` now returns `Option<libc::c_ulong>` and `get_xlib_screen_id` returns `Option<libc::c_int>`.

# Version 0.9.0 (2017-12-01)

Expand Down
14 changes: 6 additions & 8 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ impl EventsLoopExt for EventsLoop {

/// Additional methods on `Window` that are specific to Unix.
pub trait WindowExt {
/// Returns a pointer to the `Window` object of xlib that is used by this window.
/// Returns the ID of the `Window` xlib object that is used by this window.
///
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
///
/// The pointer will become invalid when the glutin `Window` is destroyed.
fn get_xlib_window(&self) -> Option<*mut libc::c_void>;
fn get_xlib_window(&self) -> Option<libc::c_ulong>;

/// Returns a pointer to the `Display` object of xlib that is used by this window.
///
Expand All @@ -92,12 +90,12 @@ pub trait WindowExt {
/// The pointer will become invalid when the glutin `Window` is destroyed.
fn get_xlib_display(&self) -> Option<*mut libc::c_void>;

fn get_xlib_screen_id(&self) -> Option<*mut libc::c_void>;
fn get_xlib_screen_id(&self) -> Option<libc::c_int>;

fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>>;

fn send_xim_spot(&self, x: i16, y: i16);

/// This function returns the underlying `xcb_connection_t` of an xlib `Display`.
///
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
Expand Down Expand Up @@ -131,7 +129,7 @@ pub trait WindowExt {

impl WindowExt for Window {
#[inline]
fn get_xlib_window(&self) -> Option<*mut libc::c_void> {
fn get_xlib_window(&self) -> Option<libc::c_ulong> {
match self.window {
LinuxWindow::X(ref w) => Some(w.get_xlib_window()),
_ => None
Expand All @@ -146,7 +144,7 @@ impl WindowExt for Window {
}
}

fn get_xlib_screen_id(&self) -> Option<*mut libc::c_void> {
fn get_xlib_screen_id(&self) -> Option<libc::c_int> {
match self.window {
LinuxWindow::X(ref w) => Some(w.get_xlib_screen_id()),
_ => None
Expand Down
8 changes: 4 additions & 4 deletions src/platform/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ impl Window2 {
}

#[inline]
pub fn get_xlib_screen_id(&self) -> *mut libc::c_void {
self.x.screen_id as *mut libc::c_void
pub fn get_xlib_screen_id(&self) -> libc::c_int {
self.x.screen_id
}

#[inline]
Expand All @@ -534,8 +534,8 @@ impl Window2 {
}

#[inline]
pub fn get_xlib_window(&self) -> *mut libc::c_void {
self.x.window as *mut libc::c_void
pub fn get_xlib_window(&self) -> libc::c_ulong {
self.x.window
}

#[inline]
Expand Down

0 comments on commit 9e8af57

Please sign in to comment.