aboutsummaryrefslogtreecommitdiffstats
path: root/c_src
diff options
context:
space:
mode:
Diffstat (limited to 'c_src')
-rw-r--r--c_src/esdl2.h1
-rw-r--r--c_src/sdl_bool.c21
-rw-r--r--c_src/sdl_window.c19
3 files changed, 41 insertions, 0 deletions
diff --git a/c_src/esdl2.h b/c_src/esdl2.h
index d1d4ae7..d8da051 100644
--- a/c_src/esdl2.h
+++ b/c_src/esdl2.h
@@ -179,6 +179,7 @@
F(set_window_bordered, 2) \
F(set_window_brightness, 2) \
F(set_window_fullscreen, 2) \
+ F(set_window_grab, 2) \
// Generated declarations for the NIF.
diff --git a/c_src/sdl_bool.c b/c_src/sdl_bool.c
new file mode 100644
index 0000000..778ac43
--- /dev/null
+++ b/c_src/sdl_bool.c
@@ -0,0 +1,21 @@
+// Copyright (c) 2014, Loïc Hoguin <[email protected]>
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#include "esdl2.h"
+
+#define BOOL_ENUM(E) \
+ E(false, SDL_FALSE) \
+ E(true, SDL_TRUE)
+
+NIF_ATOM_TO_ENUM_FUNCTION(atom_to_bool, SDL_bool, BOOL_ENUM)
diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c
index 6cc37a8..bdd66a4 100644
--- a/c_src/sdl_window.c
+++ b/c_src/sdl_window.c
@@ -507,3 +507,22 @@ NIF_FUNCTION(set_window_fullscreen)
return nif_thread_call(env, thread_set_window_fullscreen, 2,
NIF_RES_GET(Window, window_res), flags);
}
+
+// set_window_grab
+
+NIF_CAST_HANDLER(thread_set_window_grab)
+{
+ SDL_SetWindowGrab(args[0], (long)args[1]);
+}
+
+NIF_FUNCTION(set_window_grab)
+{
+ void* window_res;
+ SDL_bool b;
+
+ BADARG_IF(!enif_get_resource(env, argv[0], res_Window, &window_res));
+ BADARG_IF(!atom_to_bool(env, argv[1], &b));
+
+ return nif_thread_cast(env, thread_set_window_grab, 2,
+ NIF_RES_GET(Window, window_res), b);
+}