summaryrefslogtreecommitdiff
path: root/platform/x11/os_x11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r--platform/x11/os_x11.cpp71
1 files changed, 61 insertions, 10 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index eec371865e..9d1e3291b7 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -84,6 +84,10 @@ void OS_X11::initialize_core() {
OS_Unix::initialize_core();
}
+int OS_X11::get_current_video_driver() const {
+ return video_driver_index;
+}
+
Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
long im_event_mask = 0;
@@ -285,6 +289,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
} break;
}
+ video_driver_index = p_video_driver; // FIXME TODO - FIX IF DRIVER DETECTION HAPPENS AND GLES2 MUST BE USED
+
context_gl->set_use_vsync(current_videomode.use_vsync);
#endif
@@ -336,6 +342,10 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
AudioDriverManager::initialize(p_audio_driver);
+#ifdef ALSAMIDI_ENABLED
+ driver_alsamidi.open();
+#endif
+
ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE);
ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE);
@@ -391,6 +401,9 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true);
XSetWMProtocols(x11_display, x11_window, &wm_delete, 1);
+ im_active = false;
+ im_position = Vector2();
+
if (xim && xim_style) {
xic = XCreateIC(xim, XNInputStyle, xim_style, XNClientWindow, x11_window, XNFocusWindow, x11_window, (char *)NULL);
@@ -400,7 +413,7 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
xic = NULL;
}
if (xic) {
- XSetICFocus(xic);
+ XUnsetICFocus(xic);
} else {
WARN_PRINT("XCreateIC couldn't create xic");
}
@@ -541,8 +554,25 @@ void OS_X11::xim_destroy_callback(::XIM im, ::XPointer client_data,
os->xic = NULL;
}
+void OS_X11::set_ime_active(const bool p_active) {
+
+ im_active = p_active;
+
+ if (!xic)
+ return;
+
+ if (p_active) {
+ XSetICFocus(xic);
+ set_ime_position(im_position);
+ } else {
+ XUnsetICFocus(xic);
+ }
+}
+
void OS_X11::set_ime_position(const Point2 &p_pos) {
+ im_position = p_pos;
+
if (!xic)
return;
@@ -580,6 +610,9 @@ void OS_X11::finalize() {
memdelete(debugger_connection_console);
}
*/
+#ifdef ALSAMIDI_ENABLED
+ driver_alsamidi.close();
+#endif
#ifdef JOYDEV_ENABLED
memdelete(joypad);
@@ -1292,6 +1325,9 @@ void OS_X11::set_borderless_window(bool p_borderless) {
hints.decorations = current_videomode.borderless_window ? 0 : 1;
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
+
+ // Preserve window size
+ set_window_size(Size2(current_videomode.width, current_videomode.height));
}
bool OS_X11::get_borderless_window() {
@@ -1802,8 +1838,8 @@ void OS_X11::process_xevents() {
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime);
}
#ifdef TOUCH_ENABLED
- // Grab touch devices to avoid OS gesture interference
- /*for (int i = 0; i < touch.devices.size(); ++i) {
+ // Grab touch devices to avoid OS gesture interference
+ /*for (int i = 0; i < touch.devices.size(); ++i) {
XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
}*/
#endif
@@ -1931,6 +1967,7 @@ void OS_X11::process_xevents() {
// to be able to send relative motion events.
Point2i pos(event.xmotion.x, event.xmotion.y);
+#ifdef TOUCH_ENABLED
// Avoidance of spurious mouse motion (see handling of touch)
bool filter = false;
// Adding some tolerance to match better Point2i to Vector2
@@ -1942,6 +1979,7 @@ void OS_X11::process_xevents() {
if (filter) {
break;
}
+#endif
if (mouse_mode == MOUSE_MODE_CAPTURED) {
@@ -2067,7 +2105,7 @@ void OS_X11::process_xevents() {
Vector<String> files = String((char *)p.data).split("\n", false);
for (int i = 0; i < files.size(); i++) {
- files[i] = files[i].replace("file://", "").replace("%20", " ").strip_escapes();
+ files.write[i] = files[i].replace("file://", "").replace("%20", " ").strip_escapes();
}
main_loop->drop_files(files);
@@ -2407,7 +2445,7 @@ void OS_X11::set_cursor_shape(CursorShape p_shape) {
if (p_shape == current_cursor)
return;
- if (mouse_mode == MOUSE_MODE_VISIBLE) {
+ if (mouse_mode == MOUSE_MODE_VISIBLE && mouse_mode != MOUSE_MODE_CONFINED) {
if (cursors[p_shape] != None)
XDefineCursor(x11_display, x11_window, cursors[p_shape]);
else if (cursors[CURSOR_ARROW] != None)
@@ -2449,6 +2487,8 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
image = texture->get_data();
+ ERR_FAIL_COND(!image.is_valid());
+
// Create the cursor structure
XcursorImage *cursor_image = XcursorImageCreate(texture_size.width, texture_size.height);
XcursorUInt image_size = texture_size.width * texture_size.height;
@@ -2460,7 +2500,7 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
cursor_image->yhot = p_hotspot.y;
// allocate memory to contain the whole file
- cursor_image->pixels = (XcursorPixel *)malloc(size);
+ cursor_image->pixels = (XcursorPixel *)memalloc(size);
image->lock();
@@ -2486,6 +2526,9 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
if (p_shape == CURSOR_ARROW) {
XDefineCursor(x11_display, x11_window, cursors[p_shape]);
}
+
+ memfree(cursor_image->pixels);
+ XcursorImageDestroy(cursor_image);
} else {
// Reset to default system cursor
if (img[p_shape]) {
@@ -2499,17 +2542,23 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
void OS_X11::release_rendering_thread() {
+#if defined(OPENGL_ENABLED)
context_gl->release_current();
+#endif
}
void OS_X11::make_rendering_thread() {
+#if defined(OPENGL_ENABLED)
context_gl->make_current();
+#endif
}
void OS_X11::swap_buffers() {
+#if defined(OPENGL_ENABLED)
context_gl->swap_buffers();
+#endif
}
void OS_X11::alert(const String &p_alert, const String &p_title) {
@@ -2538,12 +2587,12 @@ void OS_X11::set_icon(const Ref<Image> &p_icon) {
pd.resize(2 + w * h);
- pd[0] = w;
- pd[1] = h;
+ pd.write[0] = w;
+ pd.write[1] = h;
PoolVector<uint8_t>::Read r = img->get_data().read();
- long *wr = &pd[2];
+ long *wr = &pd.write[2];
uint8_t const *pr = r.ptr();
for (int i = 0; i < w * h; i++) {
@@ -2603,8 +2652,10 @@ String OS_X11::get_joy_guid(int p_device) const {
}
void OS_X11::_set_use_vsync(bool p_enable) {
+#if defined(OPENGL_ENABLED)
if (context_gl)
- return context_gl->set_use_vsync(p_enable);
+ context_gl->set_use_vsync(p_enable);
+#endif
}
/*
bool OS_X11::is_vsync_enabled() const {