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

Adds window size and position assertions for MacOS #925

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Adds window size and position assertions for MacOS
mnmaita committed Oct 2, 2019
commit 9df370f22e9b4421475d7703f634adc9ad0e8e63
26 changes: 26 additions & 0 deletions src/sdl2/video.rs
Original file line number Diff line number Diff line change
@@ -1251,6 +1251,14 @@ impl Window {
//pub fn SDL_GetWindowData(window: *SDL_Window, name: *c_char) -> *c_void;

pub fn set_position(&mut self, x: WindowPos, y: WindowPos) {
if cfg!(target_os="macos") {
let _x = to_ll_windowpos(x);
let _y = to_ll_windowpos(y);
assert!(
_x >= -16_000 && _x <= 16_000 && _y >= 16_000 && _y <= 16_000,
"the window server limits window position coordinates to ±16,000."
);
}
unsafe {
sys::SDL_SetWindowPosition(
self.context.raw, to_ll_windowpos(x), to_ll_windowpos(y)
@@ -1286,6 +1294,12 @@ impl Window {
-> Result<(), IntegerOrSdlError> {
let w = r#try!(validate_int(width, "width"));
let h = r#try!(validate_int(height, "height"));
if cfg!(target_os="macos") {
assert!(
w <= 10_000 && h <= 10_000,
"the window server limits window sizes to 10,000."
);
}
Ok(unsafe {
sys::SDL_SetWindowSize(self.context.raw, w, h)
})
@@ -1316,6 +1330,12 @@ impl Window {
-> Result<(), IntegerOrSdlError> {
let w = r#try!(validate_int(width, "width"));
let h = r#try!(validate_int(height, "height"));
if cfg!(target_os="macos") {
assert!(
w <= 10_000 && h <= 10_000,
"the window server limits window sizes to 10,000."
);
}
Ok(unsafe {
sys::SDL_SetWindowMinimumSize(self.context.raw, w, h)
})
@@ -1332,6 +1352,12 @@ impl Window {
-> Result<(), IntegerOrSdlError> {
let w = r#try!(validate_int(width, "width"));
let h = r#try!(validate_int(height, "height"));
if cfg!(target_os="macos") {
assert!(
w <= 10_000 && h <= 10_000,
"the window server limits window sizes to 10,000."
);
}
Ok(unsafe {
sys::SDL_SetWindowMaximumSize(self.context.raw, w, h)
})