1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use crate::sys;
use libc::c_char;
use std::ffi::{CStr, CString};
const VIDEO_MINIMIZE_ON_FOCUS_LOSS: &str = "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS";
pub enum Hint {
Default,
Normal,
Override,
}
pub fn set_video_minimize_on_focus_loss(value: bool) -> bool {
set(VIDEO_MINIMIZE_ON_FOCUS_LOSS, if value { "1" } else { "0" })
}
pub fn set_video_minimize_on_focus_loss_with_priority(value: bool, priority: &Hint) -> bool {
set_with_priority(
VIDEO_MINIMIZE_ON_FOCUS_LOSS,
if value { "1" } else { "0" },
priority,
)
}
pub fn get_video_minimize_on_focus_loss() -> bool {
match get(VIDEO_MINIMIZE_ON_FOCUS_LOSS) {
Some(value) => match &*value {
"1" => true,
_ => false,
},
_ => true,
}
}
#[doc(alias = "SDL_SetHint")]
pub fn set(name: &str, value: &str) -> bool {
let name = CString::new(name).unwrap();
let value = CString::new(value).unwrap();
unsafe {
sys::SDL_SetHint(
name.as_ptr() as *const c_char,
value.as_ptr() as *const c_char,
) == sys::SDL_bool::SDL_TRUE
}
}
#[doc(alias = "SDL_GetHint")]
pub fn get(name: &str) -> Option<String> {
use std::str;
let name = CString::new(name).unwrap();
unsafe {
let res = sys::SDL_GetHint(name.as_ptr() as *const c_char);
if res.is_null() {
None
} else {
Some(
str::from_utf8(CStr::from_ptr(res as *const _).to_bytes())
.unwrap()
.to_owned(),
)
}
}
}
#[doc(alias = "SDL_SetHintWithPriority")]
pub fn set_with_priority(name: &str, value: &str, priority: &Hint) -> bool {
let name = CString::new(name).unwrap();
let value = CString::new(value).unwrap();
let priority_val = match *priority {
Hint::Normal => sys::SDL_HintPriority::SDL_HINT_NORMAL,
Hint::Override => sys::SDL_HintPriority::SDL_HINT_OVERRIDE,
Hint::Default => sys::SDL_HintPriority::SDL_HINT_DEFAULT,
};
unsafe {
sys::SDL_SetHintWithPriority(
name.as_ptr() as *const c_char,
value.as_ptr() as *const c_char,
priority_val,
) == sys::SDL_bool::SDL_TRUE
}
}