2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* os_x11.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-01 13:40:08 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os_x11.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "drivers/gles3/rasterizer_gles3.h"
|
|
|
|
#include "errno.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "key_mapping_x11.h"
|
2018-02-13 23:04:11 +00:00
|
|
|
#include "os/dir_access.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "print_string.h"
|
|
|
|
#include "servers/visual/visual_server_raster.h"
|
2017-06-09 03:23:50 +00:00
|
|
|
#include "servers/visual/visual_server_wrap_mt.h"
|
2017-10-17 16:50:41 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MNTENT
|
2017-09-25 13:15:11 +00:00
|
|
|
#include <mntent.h>
|
2017-10-17 16:50:41 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-11-19 21:16:00 +00:00
|
|
|
#include <string.h>
|
2015-05-26 04:05:08 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "X11/Xutil.h"
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2015-01-16 15:18:45 +00:00
|
|
|
#include "X11/Xatom.h"
|
2015-01-13 13:01:24 +00:00
|
|
|
#include "X11/extensions/Xinerama.h"
|
2015-01-16 15:18:45 +00:00
|
|
|
// ICCCM
|
2017-03-05 15:44:50 +00:00
|
|
|
#define WM_NormalState 1L // window normal state
|
|
|
|
#define WM_IconicState 3L // window minimized
|
2015-01-16 15:18:45 +00:00
|
|
|
// EWMH
|
2017-03-05 15:44:50 +00:00
|
|
|
#define _NET_WM_STATE_REMOVE 0L // remove/unset property
|
|
|
|
#define _NET_WM_STATE_ADD 1L // add/set property
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2L // toggle property
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "main/main.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#include <dlfcn.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <fcntl.h>
|
2017-03-05 15:44:50 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <unistd.h>
|
2014-02-23 20:20:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//stupid linux.h
|
|
|
|
#ifdef KEY_TAB
|
|
|
|
#undef KEY_TAB
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
|
|
#undef CursorShape
|
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int OS_X11::get_video_driver_count() const {
|
2015-01-10 20:35:26 +00:00
|
|
|
return 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const char *OS_X11::get_video_driver_name(int p_driver) const {
|
2016-10-03 19:33:42 +00:00
|
|
|
return "GLES3";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 12:44:34 +00:00
|
|
|
int OS_X11::get_audio_driver_count() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
return AudioDriverManager::get_driver_count();
|
2014-12-19 12:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *OS_X11::get_audio_driver_name(int p_driver) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
|
|
|
|
ERR_FAIL_COND_V(!driver, "");
|
|
|
|
return AudioDriverManager::get_driver(p_driver)->get_name();
|
2014-12-19 12:44:34 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 01:01:49 +00:00
|
|
|
void OS_X11::initialize_core() {
|
|
|
|
|
|
|
|
crash_handler.initialize();
|
|
|
|
|
|
|
|
OS_Unix::initialize_core();
|
|
|
|
}
|
|
|
|
|
2018-01-03 17:26:44 +00:00
|
|
|
Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
long im_event_mask = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
last_button_state = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xmbstring = NULL;
|
|
|
|
x11_window = 0;
|
|
|
|
last_click_ms = 0;
|
|
|
|
args = OS::get_singleton()->get_cmdline_args();
|
|
|
|
current_videomode = p_desired;
|
|
|
|
main_loop = NULL;
|
|
|
|
last_timestamp = 0;
|
|
|
|
last_mouse_pos_valid = false;
|
|
|
|
last_keyrelease_time = 0;
|
2016-05-28 19:35:42 +00:00
|
|
|
xdnd_version = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (get_render_thread_mode() == RENDER_SEPARATE_THREAD) {
|
2014-02-10 01:10:30 +00:00
|
|
|
XInitThreads();
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/** XLIB INITIALIZATION **/
|
|
|
|
x11_display = XOpenDisplay(NULL);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2018-01-03 17:26:44 +00:00
|
|
|
if (!x11_display) {
|
|
|
|
ERR_PRINT("X11 Display is not available");
|
|
|
|
return ERR_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
2017-08-25 15:14:33 +00:00
|
|
|
char *modifiers = NULL;
|
2017-06-27 09:26:43 +00:00
|
|
|
Bool xkb_dar = False;
|
2018-01-03 17:26:44 +00:00
|
|
|
XAutoRepeatOn(x11_display);
|
|
|
|
xkb_dar = XkbSetDetectableAutoRepeat(x11_display, True, NULL);
|
2017-06-27 09:26:43 +00:00
|
|
|
|
2018-01-03 17:26:44 +00:00
|
|
|
// Try to support IME if detectable auto-repeat is supported
|
|
|
|
if (xkb_dar == True) {
|
2017-06-27 09:26:43 +00:00
|
|
|
|
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
2018-01-03 17:26:44 +00:00
|
|
|
// Xutf8LookupString will be used later instead of XmbLookupString before
|
|
|
|
// the multibyte sequences can be converted to unicode string.
|
|
|
|
modifiers = XSetLocaleModifiers("");
|
2017-06-27 09:26:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiers == NULL) {
|
|
|
|
if (is_stdout_verbose()) {
|
|
|
|
WARN_PRINT("IME is disabled");
|
|
|
|
}
|
|
|
|
modifiers = XSetLocaleModifiers("@im=none");
|
2016-07-08 14:26:48 +00:00
|
|
|
WARN_PRINT("Error setting locale modifiers");
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const char *err;
|
2016-06-09 16:54:06 +00:00
|
|
|
xrr_get_monitors = NULL;
|
2016-06-12 13:29:02 +00:00
|
|
|
xrr_free_monitors = NULL;
|
|
|
|
int xrandr_major = 0;
|
|
|
|
int xrandr_minor = 0;
|
|
|
|
int event_base, error_base;
|
2017-03-05 15:44:50 +00:00
|
|
|
xrandr_ext_ok = XRRQueryExtension(x11_display, &event_base, &error_base);
|
2016-08-11 15:25:13 +00:00
|
|
|
xrandr_handle = dlopen("libXrandr.so.2", RTLD_LAZY);
|
2016-06-09 16:54:06 +00:00
|
|
|
if (!xrandr_handle) {
|
2016-08-11 15:25:13 +00:00
|
|
|
err = dlerror();
|
|
|
|
fprintf(stderr, "could not load libXrandr.so.2, Error: %s\n", err);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
2016-06-12 13:29:02 +00:00
|
|
|
XRRQueryVersion(x11_display, &xrandr_major, &xrandr_minor);
|
|
|
|
if (((xrandr_major << 8) | xrandr_minor) >= 0x0105) {
|
2017-03-05 15:44:50 +00:00
|
|
|
xrr_get_monitors = (xrr_get_monitors_t)dlsym(xrandr_handle, "XRRGetMonitors");
|
2016-06-12 13:29:02 +00:00
|
|
|
if (!xrr_get_monitors) {
|
|
|
|
err = dlerror();
|
|
|
|
fprintf(stderr, "could not find symbol XRRGetMonitors\nError: %s\n", err);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
|
|
|
xrr_free_monitors = (xrr_free_monitors_t)dlsym(xrandr_handle, "XRRFreeMonitors");
|
2016-06-12 13:29:02 +00:00
|
|
|
if (!xrr_free_monitors) {
|
|
|
|
err = dlerror();
|
|
|
|
fprintf(stderr, "could not find XRRFreeMonitors\nError: %s\n", err);
|
|
|
|
xrr_get_monitors = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 16:54:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 20:01:26 +00:00
|
|
|
#ifdef TOUCH_ENABLED
|
|
|
|
if (!XQueryExtension(x11_display, "XInputExtension", &touch.opcode, &event_base, &error_base)) {
|
|
|
|
fprintf(stderr, "XInput extension not available");
|
|
|
|
} else {
|
|
|
|
// 2.2 is the first release with multitouch
|
|
|
|
int xi_major = 2;
|
|
|
|
int xi_minor = 2;
|
|
|
|
if (XIQueryVersion(x11_display, &xi_major, &xi_minor) != Success) {
|
|
|
|
fprintf(stderr, "XInput 2.2 not available (server supports %d.%d)\n", xi_major, xi_minor);
|
|
|
|
touch.opcode = 0;
|
|
|
|
} else {
|
|
|
|
int dev_count;
|
|
|
|
XIDeviceInfo *info = XIQueryDevice(x11_display, XIAllDevices, &dev_count);
|
|
|
|
|
|
|
|
for (int i = 0; i < dev_count; i++) {
|
|
|
|
XIDeviceInfo *dev = &info[i];
|
|
|
|
if (!dev->enabled)
|
|
|
|
continue;
|
2017-12-10 06:05:17 +00:00
|
|
|
if (!(dev->use == XIMasterPointer || dev->use == XIFloatingSlave))
|
|
|
|
continue;
|
2017-11-29 20:01:26 +00:00
|
|
|
|
|
|
|
bool direct_touch = false;
|
|
|
|
for (int j = 0; j < dev->num_classes; j++) {
|
|
|
|
if (dev->classes[j]->type == XITouchClass && ((XITouchClassInfo *)dev->classes[j])->mode == XIDirectTouch) {
|
|
|
|
direct_touch = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (direct_touch) {
|
|
|
|
touch.devices.push_back(dev->deviceid);
|
|
|
|
fprintf(stderr, "Using touch device: %s\n", dev->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XIFreeDeviceInfo(info);
|
|
|
|
|
2018-01-24 20:35:35 +00:00
|
|
|
if (is_stdout_verbose() && !touch.devices.size()) {
|
2017-12-10 06:05:17 +00:00
|
|
|
fprintf(stderr, "No touch devices found\n");
|
2017-11-29 20:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xim = XOpenIM(x11_display, NULL, NULL, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (xim == NULL) {
|
|
|
|
WARN_PRINT("XOpenIM failed");
|
2017-03-05 15:44:50 +00:00
|
|
|
xim_style = 0L;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-06-27 09:26:43 +00:00
|
|
|
::XIMCallback im_destroy_callback;
|
|
|
|
im_destroy_callback.client_data = (::XPointer)(this);
|
|
|
|
im_destroy_callback.callback = (::XIMProc)(xim_destroy_callback);
|
|
|
|
if (XSetIMValues(xim, XNDestroyCallback, &im_destroy_callback,
|
|
|
|
NULL) != NULL) {
|
|
|
|
WARN_PRINT("Error setting XIM destroy callback");
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
::XIMStyles *xim_styles = NULL;
|
|
|
|
xim_style = 0L;
|
2017-08-21 19:15:36 +00:00
|
|
|
char *imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (imvalret != NULL || xim_styles == NULL) {
|
2017-03-05 15:44:50 +00:00
|
|
|
fprintf(stderr, "Input method doesn't support any styles\n");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (xim_styles) {
|
2015-01-16 05:44:41 +00:00
|
|
|
xim_style = 0L;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < xim_styles->count_styles; i++) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (xim_styles->supported_styles[i] ==
|
2017-03-05 15:44:50 +00:00
|
|
|
(XIMPreeditNothing | XIMStatusNothing)) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xim_style = xim_styles->supported_styles[i];
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
XFree(xim_styles);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
XFree(imvalret);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
char* windowid = getenv("GODOT_WINDOWID");
|
|
|
|
if (windowid) {
|
|
|
|
|
|
|
|
//freopen("/home/punto/stdout", "w", stdout);
|
|
|
|
//reopen("/home/punto/stderr", "w", stderr);
|
|
|
|
x11_window = atol(windowid);
|
|
|
|
|
|
|
|
XWindowAttributes xwa;
|
|
|
|
XGetWindowAttributes(x11_display,x11_window,&xwa);
|
|
|
|
|
|
|
|
current_videomode.width = xwa.width;
|
|
|
|
current_videomode.height = xwa.height;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
// maybe contextgl wants to be in charge of creating the window
|
|
|
|
//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
|
2017-10-12 22:18:04 +00:00
|
|
|
#if defined(OPENGL_ENABLED)
|
2015-01-10 17:07:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, true));
|
2014-02-10 01:10:30 +00:00
|
|
|
context_gl->initialize();
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
RasterizerGLES3::register_config();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
RasterizerGLES3::make_current();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-08 16:58:28 +00:00
|
|
|
context_gl->set_use_vsync(current_videomode.use_vsync);
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
#endif
|
2017-03-05 15:44:50 +00:00
|
|
|
visual_server = memnew(VisualServerRaster);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-09 03:23:50 +00:00
|
|
|
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
|
|
|
|
|
|
|
|
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-10-24 19:35:28 +00:00
|
|
|
if (current_videomode.maximized) {
|
|
|
|
current_videomode.maximized = false;
|
|
|
|
set_window_maximized(true);
|
|
|
|
// borderless fullscreen window mode
|
|
|
|
} else if (current_videomode.fullscreen) {
|
|
|
|
current_videomode.fullscreen = false;
|
|
|
|
set_window_fullscreen(true);
|
2017-07-05 15:19:24 +00:00
|
|
|
} else if (current_videomode.borderless_window) {
|
|
|
|
Hints hints;
|
|
|
|
Atom property;
|
|
|
|
hints.flags = 2;
|
|
|
|
hints.decorations = 0;
|
|
|
|
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
|
|
|
|
XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
|
2014-08-25 06:54:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 13:50:23 +00:00
|
|
|
// disable resizable window
|
2014-08-25 06:54:10 +00:00
|
|
|
if (!current_videomode.resizable) {
|
|
|
|
XSizeHints *xsh;
|
|
|
|
xsh = XAllocSizeHints();
|
|
|
|
xsh->flags = PMinSize | PMaxSize;
|
|
|
|
XWindowAttributes xwa;
|
|
|
|
if (current_videomode.fullscreen) {
|
2017-03-05 15:44:50 +00:00
|
|
|
XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
|
2014-09-16 06:49:31 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
XGetWindowAttributes(x11_display, x11_window, &xwa);
|
2014-08-25 06:54:10 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
xsh->min_width = xwa.width;
|
2014-08-25 06:54:10 +00:00
|
|
|
xsh->max_width = xwa.width;
|
|
|
|
xsh->min_height = xwa.height;
|
|
|
|
xsh->max_height = xwa.height;
|
|
|
|
XSetWMNormalHints(x11_display, x11_window, xsh);
|
2015-01-15 13:50:23 +00:00
|
|
|
XFree(xsh);
|
2014-08-25 06:54:10 +00:00
|
|
|
}
|
2015-01-17 15:28:04 +00:00
|
|
|
|
2017-12-27 19:51:19 +00:00
|
|
|
if (current_videomode.always_on_top) {
|
|
|
|
current_videomode.always_on_top = false;
|
|
|
|
set_window_always_on_top(true);
|
|
|
|
}
|
|
|
|
|
2017-09-13 16:34:22 +00:00
|
|
|
AudioDriverManager::initialize(p_audio_driver);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-01-03 17:26:44 +00:00
|
|
|
ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE);
|
|
|
|
ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
XSetWindowAttributes new_attr;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
new_attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
|
|
|
ButtonReleaseMask | EnterWindowMask |
|
|
|
|
LeaveWindowMask | PointerMotionMask |
|
|
|
|
Button1MotionMask |
|
|
|
|
Button2MotionMask | Button3MotionMask |
|
|
|
|
Button4MotionMask | Button5MotionMask |
|
|
|
|
ButtonMotionMask | KeymapStateMask |
|
|
|
|
ExposureMask | VisibilityChangeMask |
|
|
|
|
StructureNotifyMask |
|
|
|
|
SubstructureNotifyMask | SubstructureRedirectMask |
|
|
|
|
FocusChangeMask | PropertyChangeMask |
|
2017-06-27 09:26:43 +00:00
|
|
|
ColormapChangeMask | OwnerGrabButtonMask |
|
|
|
|
im_event_mask;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
XChangeWindowAttributes(x11_display, x11_window, CWEventMask, &new_attr);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-11-29 20:01:26 +00:00
|
|
|
#ifdef TOUCH_ENABLED
|
|
|
|
if (touch.devices.size()) {
|
|
|
|
|
|
|
|
// Must be alive after this block
|
|
|
|
static unsigned char mask_data[XIMaskLen(XI_LASTEVENT)] = {};
|
|
|
|
|
2017-12-10 06:05:17 +00:00
|
|
|
touch.event_mask.deviceid = XIAllDevices;
|
2017-11-29 20:01:26 +00:00
|
|
|
touch.event_mask.mask_len = sizeof(mask_data);
|
|
|
|
touch.event_mask.mask = mask_data;
|
|
|
|
|
|
|
|
XISetMask(touch.event_mask.mask, XI_TouchBegin);
|
|
|
|
XISetMask(touch.event_mask.mask, XI_TouchUpdate);
|
|
|
|
XISetMask(touch.event_mask.mask, XI_TouchEnd);
|
|
|
|
XISetMask(touch.event_mask.mask, XI_TouchOwnership);
|
|
|
|
|
|
|
|
XISelectEvents(x11_display, x11_window, &touch.event_mask, 1);
|
|
|
|
|
2017-12-10 06:05:17 +00:00
|
|
|
// Disabled by now since grabbing also blocks mouse events
|
|
|
|
// (they are received as extended events instead of standard events)
|
|
|
|
/*XIClearMask(touch.event_mask.mask, XI_TouchOwnership);
|
2017-11-29 20:01:26 +00:00
|
|
|
|
|
|
|
// 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);
|
2017-12-10 06:05:17 +00:00
|
|
|
}*/
|
2017-11-29 20:01:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-15 13:50:23 +00:00
|
|
|
/* set the titlebar name */
|
|
|
|
XStoreName(x11_display, x11_window, "Godot");
|
2014-05-22 06:05:05 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true);
|
2014-02-10 01:10:30 +00:00
|
|
|
XSetWMProtocols(x11_display, x11_window, &wm_delete, 1);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (xim && xim_style) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xic = XCreateIC(xim, XNInputStyle, xim_style, XNClientWindow, x11_window, XNFocusWindow, x11_window, (char *)NULL);
|
2017-06-27 09:26:43 +00:00
|
|
|
if (XGetICValues(xic, XNFilterEvents, &im_event_mask, NULL) != NULL) {
|
|
|
|
WARN_PRINT("XGetICValues couldn't obtain XNFilterEvents value");
|
|
|
|
XDestroyIC(xic);
|
|
|
|
xic = NULL;
|
|
|
|
}
|
|
|
|
if (xic) {
|
|
|
|
XSetICFocus(xic);
|
|
|
|
} else {
|
|
|
|
WARN_PRINT("XCreateIC couldn't create xic");
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xic = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
WARN_PRINT("XCreateIC couldn't create xic");
|
2016-03-08 23:00:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
cursor_size = XcursorGetDefaultSize(x11_display);
|
|
|
|
cursor_theme = XcursorGetTheme(x11_display);
|
|
|
|
|
|
|
|
if (!cursor_theme) {
|
2017-05-29 18:41:01 +00:00
|
|
|
if (is_stdout_verbose()) {
|
|
|
|
print_line("XcursorGetTheme could not get cursor theme");
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
cursor_theme = "default";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < CURSOR_MAX; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cursors[i] = None;
|
|
|
|
img[i] = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
current_cursor = CURSOR_ARROW;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (cursor_theme) {
|
|
|
|
//print_line("cursor theme: "+String(cursor_theme));
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < CURSOR_MAX; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *cursor_file[] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"left_ptr",
|
|
|
|
"xterm",
|
|
|
|
"hand2",
|
|
|
|
"cross",
|
|
|
|
"watch",
|
|
|
|
"left_ptr_watch",
|
|
|
|
"fleur",
|
|
|
|
"hand1",
|
|
|
|
"X_cursor",
|
|
|
|
"sb_v_double_arrow",
|
|
|
|
"sb_h_double_arrow",
|
|
|
|
"size_bdiag",
|
|
|
|
"size_fdiag",
|
|
|
|
"hand1",
|
|
|
|
"sb_v_double_arrow",
|
|
|
|
"sb_h_double_arrow",
|
|
|
|
"question_arrow"
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
img[i] = XcursorLibraryLoadImage(cursor_file[i], cursor_theme, cursor_size);
|
2015-10-25 14:15:56 +00:00
|
|
|
if (img[i]) {
|
2017-03-05 15:44:50 +00:00
|
|
|
cursors[i] = XcursorImageLoadCursor(x11_display, img[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
//print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i]));
|
|
|
|
} else {
|
|
|
|
if (OS::is_stdout_verbose())
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("failed cursor: " + String(cursor_file[i]));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Pixmap cursormask;
|
2017-03-05 15:44:50 +00:00
|
|
|
XGCValues xgc;
|
|
|
|
GC gc;
|
|
|
|
XColor col;
|
|
|
|
Cursor cursor;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cursormask = XCreatePixmap(x11_display, RootWindow(x11_display, DefaultScreen(x11_display)), 1, 1, 1);
|
2015-10-25 14:15:56 +00:00
|
|
|
xgc.function = GXclear;
|
|
|
|
gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc);
|
2014-02-10 01:10:30 +00:00
|
|
|
XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1);
|
|
|
|
col.pixel = 0;
|
|
|
|
col.red = 0;
|
|
|
|
col.flags = 4;
|
|
|
|
cursor = XCreatePixmapCursor(x11_display,
|
2017-03-05 15:44:50 +00:00
|
|
|
cursormask, cursormask,
|
|
|
|
&col, &col, 0, 0);
|
|
|
|
XFreePixmap(x11_display, cursormask);
|
|
|
|
XFreeGC(x11_display, gc);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (cursor == None) {
|
|
|
|
ERR_PRINT("FAILED CREATING CURSOR");
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
null_cursor = cursor;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
set_cursor_shape(CURSOR_BUSY);
|
|
|
|
|
2016-05-28 19:35:42 +00:00
|
|
|
//Set Xdnd (drag & drop) support
|
|
|
|
Atom XdndAware = XInternAtom(x11_display, "XdndAware", False);
|
2017-03-05 15:44:50 +00:00
|
|
|
Atom version = 5;
|
|
|
|
XChangeProperty(x11_display, x11_window, XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char *)&version, 1);
|
2016-05-28 19:35:42 +00:00
|
|
|
|
|
|
|
xdnd_enter = XInternAtom(x11_display, "XdndEnter", False);
|
|
|
|
xdnd_position = XInternAtom(x11_display, "XdndPosition", False);
|
|
|
|
xdnd_status = XInternAtom(x11_display, "XdndStatus", False);
|
|
|
|
xdnd_action_copy = XInternAtom(x11_display, "XdndActionCopy", False);
|
|
|
|
xdnd_drop = XInternAtom(x11_display, "XdndDrop", False);
|
|
|
|
xdnd_finished = XInternAtom(x11_display, "XdndFinished", False);
|
|
|
|
xdnd_selection = XInternAtom(x11_display, "XdndSelection", False);
|
|
|
|
requested = None;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
visual_server->init();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
input = memnew(InputDefault);
|
2017-01-25 18:21:41 +00:00
|
|
|
|
|
|
|
window_has_focus = true; // Set focus to true at init
|
2015-12-21 21:39:03 +00:00
|
|
|
#ifdef JOYDEV_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
joypad = memnew(JoypadLinux(input));
|
2015-12-18 05:12:53 +00:00
|
|
|
#endif
|
2017-11-17 14:25:22 +00:00
|
|
|
_ensure_user_data_dir();
|
2017-07-26 21:29:51 +00:00
|
|
|
|
|
|
|
power_manager = memnew(PowerX11);
|
2017-10-24 19:35:28 +00:00
|
|
|
|
|
|
|
XEvent xevent;
|
2017-12-09 22:21:34 +00:00
|
|
|
while (XPending(x11_display) > 0) {
|
|
|
|
XNextEvent(x11_display, &xevent);
|
|
|
|
if (xevent.type == ConfigureNotify) {
|
|
|
|
_window_changed(&xevent);
|
|
|
|
}
|
2017-10-24 19:35:28 +00:00
|
|
|
}
|
2018-01-05 11:10:47 +00:00
|
|
|
|
|
|
|
return OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-10-25 14:15:56 +00:00
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
void OS_X11::xim_destroy_callback(::XIM im, ::XPointer client_data,
|
|
|
|
::XPointer call_data) {
|
|
|
|
|
|
|
|
WARN_PRINT("Input method stopped");
|
|
|
|
OS_X11 *os = reinterpret_cast<OS_X11 *>(client_data);
|
|
|
|
os->xim = NULL;
|
|
|
|
os->xic = NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-25 15:50:45 +00:00
|
|
|
void OS_X11::set_ime_position(const Point2 &p_pos) {
|
2017-06-27 09:26:43 +00:00
|
|
|
|
2017-06-25 15:50:45 +00:00
|
|
|
if (!xic)
|
2017-06-27 09:26:43 +00:00
|
|
|
return;
|
2017-06-25 15:50:45 +00:00
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
::XPoint spot;
|
2017-06-25 15:50:45 +00:00
|
|
|
spot.x = short(p_pos.x);
|
|
|
|
spot.y = short(p_pos.y);
|
|
|
|
XVaNestedList preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
|
|
|
|
XSetICValues(xic, XNPreeditAttributes, preedit_attr, NULL);
|
2017-06-27 09:26:43 +00:00
|
|
|
XFree(preedit_attr);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_X11::finalize() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (main_loop)
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(main_loop);
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-06 20:36:34 +00:00
|
|
|
/*
|
2017-01-14 11:26:56 +00:00
|
|
|
if (debugger_connection_console) {
|
|
|
|
memdelete(debugger_connection_console);
|
|
|
|
}
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 22:35:54 +00:00
|
|
|
#ifdef JOYDEV_ENABLED
|
2017-01-08 20:05:51 +00:00
|
|
|
memdelete(joypad);
|
2017-11-29 20:01:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TOUCH_ENABLED
|
|
|
|
touch.devices.clear();
|
|
|
|
touch.state.clear();
|
2016-01-05 22:35:54 +00:00
|
|
|
#endif
|
2015-12-31 13:25:21 +00:00
|
|
|
memdelete(input);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
visual_server->finish();
|
|
|
|
memdelete(visual_server);
|
2016-10-03 19:33:42 +00:00
|
|
|
//memdelete(rasterizer);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-08-24 16:51:28 +00:00
|
|
|
memdelete(power_manager);
|
|
|
|
|
2016-06-09 16:54:06 +00:00
|
|
|
if (xrandr_handle)
|
|
|
|
dlclose(xrandr_handle);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
XUnmapWindow(x11_display, x11_window);
|
|
|
|
XDestroyWindow(x11_display, x11_window);
|
2015-10-25 14:15:56 +00:00
|
|
|
|
2017-10-12 22:18:04 +00:00
|
|
|
#if defined(OPENGL_ENABLED)
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(context_gl);
|
|
|
|
#endif
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < CURSOR_MAX; i++) {
|
|
|
|
if (cursors[i] != None)
|
|
|
|
XFreeCursor(x11_display, cursors[i]);
|
|
|
|
if (img[i] != NULL)
|
|
|
|
XcursorImageDestroy(img[i]);
|
2016-03-08 23:00:52 +00:00
|
|
|
};
|
2015-10-25 14:15:56 +00:00
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
if (xic) {
|
|
|
|
XDestroyIC(xic);
|
|
|
|
}
|
|
|
|
if (xim) {
|
|
|
|
XCloseIM(xim);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
XCloseDisplay(x11_display);
|
|
|
|
if (xmbstring)
|
|
|
|
memfree(xmbstring);
|
2015-10-25 14:15:56 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
args.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_X11::set_mouse_mode(MouseMode p_mode) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_mode == mouse_mode)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED)
|
2014-02-10 01:10:30 +00:00
|
|
|
XUngrabPointer(x11_display, CurrentTime);
|
2017-01-25 18:21:41 +00:00
|
|
|
|
|
|
|
// The only modes that show a cursor are VISIBLE and CONFINED
|
|
|
|
bool showCursor = (p_mode == MOUSE_MODE_VISIBLE || p_mode == MOUSE_MODE_CONFINED);
|
|
|
|
|
|
|
|
if (showCursor) {
|
2017-03-05 15:44:50 +00:00
|
|
|
XUndefineCursor(x11_display, x11_window); // show cursor
|
2017-01-25 18:21:41 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
XDefineCursor(x11_display, x11_window, null_cursor); // hide cursor
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mouse_mode = p_mode;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
2015-08-29 04:43:21 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2015-08-29 04:43:21 +00:00
|
|
|
//flush pending motion events
|
|
|
|
|
|
|
|
if (XPending(x11_display) > 0) {
|
|
|
|
XEvent event;
|
|
|
|
XPeekEvent(x11_display, &event);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (event.type == MotionNotify) {
|
|
|
|
XNextEvent(x11_display, &event);
|
2015-08-29 04:43:21 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 21:15:47 +00:00
|
|
|
if (XGrabPointer(
|
2017-03-05 15:44:50 +00:00
|
|
|
x11_display, x11_window, True,
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
|
|
|
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime) != GrabSuccess) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_PRINT("NO GRAB");
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
center.x = current_videomode.width / 2;
|
|
|
|
center.y = current_videomode.height / 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
XWarpPointer(x11_display, None, x11_window,
|
2017-03-05 15:44:50 +00:00
|
|
|
0, 0, 0, 0, (int)center.x, (int)center.y);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
input->set_mouse_position(center);
|
2015-08-29 04:43:21 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
do_mouse_warp = false;
|
2015-02-12 14:58:00 +00:00
|
|
|
}
|
2016-04-12 14:20:28 +00:00
|
|
|
|
|
|
|
XFlush(x11_display);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
void OS_X11::warp_mouse_position(const Point2 &p_to) {
|
2014-09-20 00:01:41 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
2014-09-20 00:01:41 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_mouse_pos = p_to;
|
2014-09-20 00:01:41 +00:00
|
|
|
} else {
|
|
|
|
|
2015-02-14 22:22:06 +00:00
|
|
|
/*XWindowAttributes xwa;
|
|
|
|
XGetWindowAttributes(x11_display, x11_window, &xwa);
|
|
|
|
printf("%d %d\n", xwa.x, xwa.y); needed? */
|
|
|
|
|
2014-09-20 00:01:41 +00:00
|
|
|
XWarpPointer(x11_display, None, x11_window,
|
2017-03-05 15:44:50 +00:00
|
|
|
0, 0, 0, 0, (int)p_to.x, (int)p_to.y);
|
2014-09-20 00:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::MouseMode OS_X11::get_mouse_mode() const {
|
|
|
|
return mouse_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_X11::get_mouse_button_state() const {
|
|
|
|
return last_button_state;
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
Point2 OS_X11::get_mouse_position() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return last_mouse_pos;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::set_window_title(const String &p_title) {
|
|
|
|
XStoreName(x11_display, x11_window, p_title.utf8().get_data());
|
2016-02-03 23:39:53 +00:00
|
|
|
|
|
|
|
Atom _net_wm_name = XInternAtom(x11_display, "_NET_WM_NAME", false);
|
|
|
|
Atom utf8_string = XInternAtom(x11_display, "UTF8_STRING", false);
|
2017-03-05 15:44:50 +00:00
|
|
|
XChangeProperty(x11_display, x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char *)p_title.utf8().get_data(), p_title.utf8().length());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-10-25 17:36:27 +00:00
|
|
|
OS::VideoMode OS_X11::get_video_mode(int p_screen) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return current_videomode;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 13:50:31 +00:00
|
|
|
void OS_X11::set_wm_fullscreen(bool p_enabled) {
|
2018-02-16 20:49:17 +00:00
|
|
|
if (p_enabled && !get_borderless_window()) {
|
|
|
|
// remove decorations if the window is not already borderless
|
|
|
|
Hints hints;
|
|
|
|
Atom property;
|
|
|
|
hints.flags = 2;
|
|
|
|
hints.decorations = 0;
|
|
|
|
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
|
|
|
|
XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
|
|
|
|
}
|
2017-10-24 19:35:28 +00:00
|
|
|
|
2017-07-12 17:20:29 +00:00
|
|
|
if (p_enabled && !is_window_resizable()) {
|
|
|
|
// Set the window as resizable to prevent window managers to ignore the fullscreen state flag.
|
|
|
|
XSizeHints *xsh;
|
|
|
|
|
|
|
|
xsh = XAllocSizeHints();
|
|
|
|
xsh->flags = 0L;
|
|
|
|
XSetWMNormalHints(x11_display, x11_window, xsh);
|
|
|
|
XFree(xsh);
|
|
|
|
}
|
|
|
|
|
2018-02-21 16:30:55 +00:00
|
|
|
// Using EWMH -- Extended Window Manager Hints
|
2015-01-10 07:47:34 +00:00
|
|
|
XEvent xev;
|
|
|
|
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
|
|
|
|
Atom wm_fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
|
|
|
xev.xclient.window = x11_window;
|
|
|
|
xev.xclient.message_type = wm_state;
|
|
|
|
xev.xclient.format = 32;
|
2015-01-16 15:18:45 +00:00
|
|
|
xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
|
2015-01-10 07:47:34 +00:00
|
|
|
xev.xclient.data.l[1] = wm_fullscreen;
|
|
|
|
xev.xclient.data.l[2] = 0;
|
|
|
|
|
2015-01-17 10:43:12 +00:00
|
|
|
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
|
2017-09-09 21:24:19 +00:00
|
|
|
|
|
|
|
// set bypass compositor hint
|
|
|
|
Atom bypass_compositor = XInternAtom(x11_display, "_NET_WM_BYPASS_COMPOSITOR", False);
|
|
|
|
unsigned long compositing_disable_on = p_enabled ? 1 : 0;
|
|
|
|
XChangeProperty(x11_display, x11_window, bypass_compositor, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&compositing_disable_on, 1);
|
|
|
|
|
2017-07-12 17:20:29 +00:00
|
|
|
XFlush(x11_display);
|
|
|
|
|
|
|
|
if (!p_enabled && !is_window_resizable()) {
|
|
|
|
// Reset the non-resizable flags if we un-set these before.
|
|
|
|
Size2 size = get_window_size();
|
|
|
|
XSizeHints *xsh;
|
|
|
|
|
|
|
|
xsh = XAllocSizeHints();
|
|
|
|
xsh->flags = PMinSize | PMaxSize;
|
|
|
|
xsh->min_width = size.x;
|
|
|
|
xsh->max_width = size.x;
|
|
|
|
xsh->min_height = size.y;
|
|
|
|
xsh->max_height = size.y;
|
|
|
|
|
|
|
|
XSetWMNormalHints(x11_display, x11_window, xsh);
|
|
|
|
XFree(xsh);
|
|
|
|
}
|
2017-09-10 04:41:34 +00:00
|
|
|
|
|
|
|
if (!p_enabled && !get_borderless_window()) {
|
|
|
|
// put decorations back if the window wasn't suppoesed to be borderless
|
|
|
|
Hints hints;
|
|
|
|
Atom property;
|
|
|
|
hints.flags = 2;
|
|
|
|
hints.decorations = 1;
|
|
|
|
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
|
|
|
|
XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
|
|
|
|
}
|
2015-01-10 13:50:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 19:51:19 +00:00
|
|
|
void OS_X11::set_wm_above(bool p_enabled) {
|
|
|
|
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
|
|
|
|
Atom wm_above = XInternAtom(x11_display, "_NET_WM_STATE_ABOVE", False);
|
|
|
|
|
|
|
|
XClientMessageEvent xev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
|
|
|
xev.window = x11_window;
|
|
|
|
xev.message_type = wm_state;
|
|
|
|
xev.format = 32;
|
|
|
|
xev.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
|
|
|
|
xev.data.l[1] = wm_above;
|
|
|
|
xev.data.l[3] = 1;
|
|
|
|
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xev);
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:52:42 +00:00
|
|
|
int OS_X11::get_screen_count() const {
|
2015-01-16 15:18:45 +00:00
|
|
|
// Using Xinerama Extension
|
2015-01-13 13:01:24 +00:00
|
|
|
int event_base, error_base;
|
|
|
|
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!ext_okay) return 0;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
int count;
|
2017-03-05 15:44:50 +00:00
|
|
|
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
|
2015-01-13 13:01:24 +00:00
|
|
|
XFree(xsi);
|
|
|
|
return count;
|
2015-01-11 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
int OS_X11::get_current_screen() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
int x, y;
|
|
|
|
Window child;
|
|
|
|
XTranslateCoordinates(x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
|
2015-01-14 04:02:59 +00:00
|
|
|
|
|
|
|
int count = get_screen_count();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2015-01-14 04:02:59 +00:00
|
|
|
Point2i pos = get_screen_position(i);
|
|
|
|
Size2i size = get_screen_size(i);
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((x >= pos.x && x < pos.x + size.width) && (y >= pos.y && y < pos.y + size.height))
|
2016-03-08 23:00:52 +00:00
|
|
|
return i;
|
2015-01-14 04:02:59 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
void OS_X11::set_current_screen(int p_screen) {
|
2015-01-14 04:02:59 +00:00
|
|
|
int count = get_screen_count();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_screen >= count) return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (current_videomode.fullscreen) {
|
2015-01-14 04:02:59 +00:00
|
|
|
Point2i position = get_screen_position(p_screen);
|
|
|
|
Size2i size = get_screen_size(p_screen);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y);
|
|
|
|
} else {
|
|
|
|
if (p_screen != get_current_screen()) {
|
2015-01-14 04:02:59 +00:00
|
|
|
Point2i position = get_screen_position(p_screen);
|
|
|
|
XMoveWindow(x11_display, x11_window, position.x, position.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-13 09:25:50 +00:00
|
|
|
Point2 OS_X11::get_screen_position(int p_screen) const {
|
2017-08-20 19:12:29 +00:00
|
|
|
if (p_screen == -1) {
|
|
|
|
p_screen = get_current_screen();
|
|
|
|
}
|
|
|
|
|
2015-01-16 15:18:45 +00:00
|
|
|
// Using Xinerama Extension
|
2015-01-13 13:01:24 +00:00
|
|
|
int event_base, error_base;
|
|
|
|
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!ext_okay) {
|
|
|
|
return Point2i(0, 0);
|
2015-08-31 02:36:46 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
int count;
|
2017-03-05 15:44:50 +00:00
|
|
|
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
|
|
|
|
if (p_screen >= count) {
|
|
|
|
return Point2i(0, 0);
|
2015-08-31 02:36:46 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org);
|
2015-08-31 02:36:46 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
XFree(xsi);
|
2015-08-31 02:36:46 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
return position;
|
2015-01-13 09:25:50 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 11:35:53 +00:00
|
|
|
Size2 OS_X11::get_screen_size(int p_screen) const {
|
2017-08-20 19:12:29 +00:00
|
|
|
if (p_screen == -1) {
|
|
|
|
p_screen = get_current_screen();
|
|
|
|
}
|
|
|
|
|
2015-01-16 15:18:45 +00:00
|
|
|
// Using Xinerama Extension
|
2015-01-13 13:01:24 +00:00
|
|
|
int event_base, error_base;
|
|
|
|
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!ext_okay) return Size2i(0, 0);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
int count;
|
2017-03-05 15:44:50 +00:00
|
|
|
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
|
|
|
|
if (p_screen >= count) return Size2i(0, 0);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2015-01-13 13:01:24 +00:00
|
|
|
Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height);
|
|
|
|
XFree(xsi);
|
|
|
|
return size;
|
2015-01-11 11:35:53 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 16:54:06 +00:00
|
|
|
int OS_X11::get_screen_dpi(int p_screen) const {
|
2017-08-20 19:12:29 +00:00
|
|
|
if (p_screen == -1) {
|
|
|
|
p_screen = get_current_screen();
|
|
|
|
}
|
2016-06-09 16:54:06 +00:00
|
|
|
|
|
|
|
//invalid screen?
|
|
|
|
ERR_FAIL_INDEX_V(p_screen, get_screen_count(), 0);
|
|
|
|
|
|
|
|
//Get physical monitor Dimensions through XRandR and calculate dpi
|
|
|
|
Size2 sc = get_screen_size(p_screen);
|
2016-06-12 13:29:02 +00:00
|
|
|
if (xrandr_ext_ok) {
|
2016-06-09 16:54:06 +00:00
|
|
|
int count = 0;
|
|
|
|
if (xrr_get_monitors) {
|
|
|
|
xrr_monitor_info *monitors = xrr_get_monitors(x11_display, x11_window, true, &count);
|
|
|
|
if (p_screen < count) {
|
2017-03-05 15:44:50 +00:00
|
|
|
double xdpi = sc.width / (double)monitors[p_screen].mwidth * 25.4;
|
|
|
|
double ydpi = sc.height / (double)monitors[p_screen].mheight * 25.4;
|
2016-06-12 13:29:02 +00:00
|
|
|
xrr_free_monitors(monitors);
|
2016-06-09 16:54:06 +00:00
|
|
|
return (xdpi + ydpi) / 2;
|
|
|
|
}
|
2016-06-12 13:29:02 +00:00
|
|
|
xrr_free_monitors(monitors);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_screen == 0) {
|
2016-06-09 16:54:06 +00:00
|
|
|
XRRScreenSize *sizes = XRRSizes(x11_display, 0, &count);
|
|
|
|
if (sizes) {
|
2017-03-05 15:44:50 +00:00
|
|
|
double xdpi = sc.width / (double)sizes[0].mwidth * 25.4;
|
|
|
|
double ydpi = sc.height / (double)sizes[0].mheight * 25.4;
|
2016-06-09 16:54:06 +00:00
|
|
|
return (xdpi + ydpi) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int width_mm = DisplayWidthMM(x11_display, p_screen);
|
2016-06-09 16:54:06 +00:00
|
|
|
int height_mm = DisplayHeightMM(x11_display, p_screen);
|
2017-03-05 15:44:50 +00:00
|
|
|
double xdpi = (width_mm ? sc.width / (double)width_mm * 25.4 : 0);
|
|
|
|
double ydpi = (height_mm ? sc.height / (double)height_mm * 25.4 : 0);
|
2016-06-09 16:54:06 +00:00
|
|
|
if (xdpi || xdpi)
|
2017-03-05 15:44:50 +00:00
|
|
|
return (xdpi + ydpi) / (xdpi && ydpi ? 2 : 1);
|
2016-06-09 16:54:06 +00:00
|
|
|
|
|
|
|
//could not get dpi
|
|
|
|
return 96;
|
|
|
|
}
|
|
|
|
|
2015-01-11 07:47:27 +00:00
|
|
|
Point2 OS_X11::get_window_position() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
int x, y;
|
2015-01-11 07:47:27 +00:00
|
|
|
Window child;
|
2017-03-05 15:44:50 +00:00
|
|
|
XTranslateCoordinates(x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
|
2015-01-17 15:28:04 +00:00
|
|
|
|
2015-03-23 00:31:38 +00:00
|
|
|
int screen = get_current_screen();
|
2015-01-17 15:28:04 +00:00
|
|
|
Point2i screen_position = get_screen_position(screen);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return Point2i(x - screen_position.x, y - screen_position.y);
|
2015-01-11 07:47:27 +00:00
|
|
|
}
|
2015-01-10 17:07:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::set_window_position(const Point2 &p_position) {
|
|
|
|
XMoveWindow(x11_display, x11_window, p_position.x, p_position.y);
|
2015-01-11 07:47:27 +00:00
|
|
|
}
|
2015-01-10 13:50:31 +00:00
|
|
|
|
2015-01-11 09:36:56 +00:00
|
|
|
Size2 OS_X11::get_window_size() const {
|
2017-01-30 16:25:48 +00:00
|
|
|
// Use current_videomode width and height instead of XGetWindowAttributes
|
|
|
|
// since right after a XResizeWindow the attributes may not be updated yet
|
|
|
|
return Size2i(current_videomode.width, current_videomode.height);
|
2015-01-11 09:36:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 17:17:29 +00:00
|
|
|
Size2 OS_X11::get_real_window_size() const {
|
|
|
|
XWindowAttributes xwa;
|
|
|
|
XSync(x11_display, False);
|
|
|
|
XGetWindowAttributes(x11_display, x11_window, &xwa);
|
|
|
|
int w = xwa.width;
|
|
|
|
int h = xwa.height;
|
|
|
|
Atom prop = XInternAtom(x11_display, "_NET_FRAME_EXTENTS", True);
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long len;
|
|
|
|
unsigned long remaining;
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
if (XGetWindowProperty(x11_display, x11_window, prop, 0, 4, False, AnyPropertyType, &type, &format, &len, &remaining, &data) == Success) {
|
|
|
|
long *extents = (long *)data;
|
|
|
|
w += extents[0] + extents[1]; // left, right
|
|
|
|
h += extents[2] + extents[3]; // top, bottom
|
|
|
|
}
|
|
|
|
return Size2(w, h);
|
|
|
|
}
|
|
|
|
|
2015-01-11 09:36:56 +00:00
|
|
|
void OS_X11::set_window_size(const Size2 p_size) {
|
2017-01-30 16:25:48 +00:00
|
|
|
// If window resizable is disabled we need to update the attributes first
|
|
|
|
if (is_window_resizable() == false) {
|
|
|
|
XSizeHints *xsh;
|
|
|
|
xsh = XAllocSizeHints();
|
|
|
|
xsh->flags = PMinSize | PMaxSize;
|
|
|
|
xsh->min_width = p_size.x;
|
|
|
|
xsh->max_width = p_size.x;
|
|
|
|
xsh->min_height = p_size.y;
|
|
|
|
xsh->max_height = p_size.y;
|
|
|
|
XSetWMNormalHints(x11_display, x11_window, xsh);
|
|
|
|
XFree(xsh);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize the window
|
2015-01-11 09:36:56 +00:00
|
|
|
XResizeWindow(x11_display, x11_window, p_size.x, p_size.y);
|
2017-01-30 16:25:48 +00:00
|
|
|
|
|
|
|
// Update our videomode width and height
|
|
|
|
current_videomode.width = p_size.x;
|
|
|
|
current_videomode.height = p_size.y;
|
2015-01-11 09:36:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
void OS_X11::set_window_fullscreen(bool p_enabled) {
|
2017-12-27 19:51:19 +00:00
|
|
|
if (current_videomode.fullscreen == p_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p_enabled && current_videomode.always_on_top) {
|
|
|
|
// Fullscreen + Always-on-top requires a maximized window on some window managers (Metacity)
|
|
|
|
set_window_maximized(true);
|
|
|
|
}
|
2015-01-17 10:43:12 +00:00
|
|
|
set_wm_fullscreen(p_enabled);
|
2017-12-27 19:51:19 +00:00
|
|
|
if (!p_enabled && !current_videomode.always_on_top) {
|
|
|
|
// Restore
|
|
|
|
set_window_maximized(false);
|
|
|
|
}
|
|
|
|
|
2015-01-17 10:43:12 +00:00
|
|
|
current_videomode.fullscreen = p_enabled;
|
2015-01-10 07:47:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
bool OS_X11::is_window_fullscreen() const {
|
2015-01-10 08:01:01 +00:00
|
|
|
return current_videomode.fullscreen;
|
2015-01-10 07:47:34 +00:00
|
|
|
}
|
2015-01-15 13:50:23 +00:00
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
void OS_X11::set_window_resizable(bool p_enabled) {
|
2015-01-17 10:43:12 +00:00
|
|
|
XSizeHints *xsh;
|
2017-01-30 16:25:48 +00:00
|
|
|
Size2 size = get_window_size();
|
|
|
|
|
2015-01-17 10:43:12 +00:00
|
|
|
xsh = XAllocSizeHints();
|
|
|
|
xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!p_enabled) {
|
2017-01-30 16:25:48 +00:00
|
|
|
xsh->min_width = size.x;
|
|
|
|
xsh->max_width = size.x;
|
|
|
|
xsh->min_height = size.y;
|
|
|
|
xsh->max_height = size.y;
|
2015-01-15 13:50:23 +00:00
|
|
|
}
|
2015-01-17 10:43:12 +00:00
|
|
|
XSetWMNormalHints(x11_display, x11_window, xsh);
|
|
|
|
XFree(xsh);
|
|
|
|
current_videomode.resizable = p_enabled;
|
2015-01-15 13:50:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
bool OS_X11::is_window_resizable() const {
|
2015-01-15 13:50:23 +00:00
|
|
|
return current_videomode.resizable;
|
|
|
|
}
|
2015-01-16 15:18:45 +00:00
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
void OS_X11::set_window_minimized(bool p_enabled) {
|
2016-07-21 19:11:34 +00:00
|
|
|
// Using ICCCM -- Inter-Client Communication Conventions Manual
|
|
|
|
XEvent xev;
|
|
|
|
Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False);
|
2015-01-16 15:18:45 +00:00
|
|
|
|
2016-07-21 19:11:34 +00:00
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
|
|
|
xev.xclient.window = x11_window;
|
|
|
|
xev.xclient.message_type = wm_change;
|
|
|
|
xev.xclient.format = 32;
|
|
|
|
xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState;
|
2015-01-16 15:18:45 +00:00
|
|
|
|
2016-07-21 19:11:34 +00:00
|
|
|
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
|
|
|
|
Atom wm_hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", False);
|
2015-01-16 17:36:07 +00:00
|
|
|
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
|
|
|
xev.xclient.window = x11_window;
|
|
|
|
xev.xclient.message_type = wm_state;
|
|
|
|
xev.xclient.format = 32;
|
|
|
|
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
|
|
|
|
xev.xclient.data.l[1] = wm_hidden;
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
|
2015-01-16 15:18:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
bool OS_X11::is_window_minimized() const {
|
2015-01-16 15:18:45 +00:00
|
|
|
// Using ICCCM -- Inter-Client Communication Conventions Manual
|
2017-03-05 15:44:50 +00:00
|
|
|
Atom property = XInternAtom(x11_display, "WM_STATE", True);
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long len;
|
|
|
|
unsigned long remaining;
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
|
|
|
|
int result = XGetWindowProperty(
|
|
|
|
x11_display,
|
|
|
|
x11_window,
|
|
|
|
property,
|
|
|
|
0,
|
|
|
|
32,
|
|
|
|
False,
|
|
|
|
AnyPropertyType,
|
|
|
|
&type,
|
|
|
|
&format,
|
|
|
|
&len,
|
|
|
|
&remaining,
|
|
|
|
&data);
|
|
|
|
|
|
|
|
if (result == Success) {
|
|
|
|
long *state = (long *)data;
|
|
|
|
if (state[0] == WM_IconicState)
|
2015-01-16 15:18:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
void OS_X11::set_window_maximized(bool p_enabled) {
|
2017-10-24 19:35:28 +00:00
|
|
|
if (is_window_maximized() == p_enabled)
|
|
|
|
return;
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
// Using EWMH -- Extended Window Manager Hints
|
2015-01-16 15:18:45 +00:00
|
|
|
XEvent xev;
|
|
|
|
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
|
|
|
|
Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
|
|
|
Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
|
|
|
|
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
|
|
|
xev.xclient.window = x11_window;
|
|
|
|
xev.xclient.message_type = wm_state;
|
|
|
|
xev.xclient.format = 32;
|
|
|
|
xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
|
|
|
|
xev.xclient.data.l[1] = wm_max_horz;
|
|
|
|
xev.xclient.data.l[2] = wm_max_vert;
|
|
|
|
|
2015-01-16 17:36:07 +00:00
|
|
|
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
|
2016-01-03 21:52:42 +00:00
|
|
|
|
2017-12-27 10:25:57 +00:00
|
|
|
if (is_window_maximize_allowed()) {
|
|
|
|
while (p_enabled && !is_window_maximized()) {
|
|
|
|
// Wait for effective resizing (so the GLX context is too).
|
|
|
|
}
|
2017-12-23 23:59:51 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 15:18:45 +00:00
|
|
|
maximized = p_enabled;
|
|
|
|
}
|
|
|
|
|
2017-12-27 10:25:57 +00:00
|
|
|
bool OS_X11::is_window_maximize_allowed() {
|
|
|
|
Atom property = XInternAtom(x11_display, "_NET_WM_ALLOWED_ACTIONS", False);
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long len;
|
|
|
|
unsigned long remaining;
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
|
|
|
|
int result = XGetWindowProperty(
|
|
|
|
x11_display,
|
|
|
|
x11_window,
|
|
|
|
property,
|
|
|
|
0,
|
|
|
|
1024,
|
|
|
|
False,
|
|
|
|
XA_ATOM,
|
|
|
|
&type,
|
|
|
|
&format,
|
|
|
|
&len,
|
|
|
|
&remaining,
|
|
|
|
&data);
|
|
|
|
|
|
|
|
if (result == Success) {
|
|
|
|
Atom *atoms = (Atom *)data;
|
|
|
|
Atom wm_act_max_horz = XInternAtom(x11_display, "_NET_WM_ACTION_MAXIMIZE_HORZ", False);
|
|
|
|
Atom wm_act_max_vert = XInternAtom(x11_display, "_NET_WM_ACTION_MAXIMIZE_VERT", False);
|
|
|
|
bool found_wm_act_max_horz = false;
|
|
|
|
bool found_wm_act_max_vert = false;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < len; i++) {
|
|
|
|
if (atoms[i] == wm_act_max_horz)
|
|
|
|
found_wm_act_max_horz = true;
|
|
|
|
if (atoms[i] == wm_act_max_vert)
|
|
|
|
found_wm_act_max_vert = true;
|
|
|
|
|
|
|
|
if (found_wm_act_max_horz || found_wm_act_max_vert)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
XFree(atoms);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
bool OS_X11::is_window_maximized() const {
|
2015-01-16 15:18:45 +00:00
|
|
|
// Using EWMH -- Extended Window Manager Hints
|
2017-03-05 15:44:50 +00:00
|
|
|
Atom property = XInternAtom(x11_display, "_NET_WM_STATE", False);
|
2016-07-21 19:11:34 +00:00
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long len;
|
|
|
|
unsigned long remaining;
|
|
|
|
unsigned char *data = NULL;
|
2018-02-28 20:55:13 +00:00
|
|
|
bool retval = false;
|
2015-01-16 15:18:45 +00:00
|
|
|
|
2016-07-21 19:11:34 +00:00
|
|
|
int result = XGetWindowProperty(
|
|
|
|
x11_display,
|
|
|
|
x11_window,
|
|
|
|
property,
|
|
|
|
0,
|
|
|
|
1024,
|
|
|
|
False,
|
|
|
|
XA_ATOM,
|
|
|
|
&type,
|
|
|
|
&format,
|
|
|
|
&len,
|
|
|
|
&remaining,
|
2017-03-05 15:44:50 +00:00
|
|
|
&data);
|
2015-01-16 15:18:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (result == Success) {
|
|
|
|
Atom *atoms = (Atom *)data;
|
2015-01-16 15:18:45 +00:00
|
|
|
Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
|
|
|
Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
|
|
|
|
bool found_wm_max_horz = false;
|
|
|
|
bool found_wm_max_vert = false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (unsigned int i = 0; i < len; i++) {
|
|
|
|
if (atoms[i] == wm_max_horz)
|
2015-01-16 15:18:45 +00:00
|
|
|
found_wm_max_horz = true;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (atoms[i] == wm_max_vert)
|
2015-01-16 15:18:45 +00:00
|
|
|
found_wm_max_vert = true;
|
|
|
|
|
2018-02-28 20:55:13 +00:00
|
|
|
if (found_wm_max_horz && found_wm_max_vert) {
|
|
|
|
retval = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-16 15:18:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 20:55:13 +00:00
|
|
|
XFree(data);
|
|
|
|
return retval;
|
2015-01-16 15:18:45 +00:00
|
|
|
}
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-12-27 19:51:19 +00:00
|
|
|
void OS_X11::set_window_always_on_top(bool p_enabled) {
|
|
|
|
if (is_window_always_on_top() == p_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p_enabled && current_videomode.fullscreen) {
|
|
|
|
// Fullscreen + Always-on-top requires a maximized window on some window managers (Metacity)
|
|
|
|
set_window_maximized(true);
|
|
|
|
}
|
|
|
|
set_wm_above(p_enabled);
|
|
|
|
if (!p_enabled && !current_videomode.fullscreen) {
|
|
|
|
// Restore
|
|
|
|
set_window_maximized(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_videomode.always_on_top = p_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_X11::is_window_always_on_top() const {
|
|
|
|
return current_videomode.always_on_top;
|
|
|
|
}
|
|
|
|
|
2017-12-14 18:15:46 +00:00
|
|
|
void OS_X11::set_borderless_window(bool p_borderless) {
|
2017-07-05 15:19:24 +00:00
|
|
|
|
|
|
|
if (current_videomode.borderless_window == p_borderless)
|
|
|
|
return;
|
|
|
|
|
|
|
|
current_videomode.borderless_window = p_borderless;
|
|
|
|
|
|
|
|
Hints hints;
|
|
|
|
Atom property;
|
|
|
|
hints.flags = 2;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_X11::get_borderless_window() {
|
|
|
|
return current_videomode.borderless_window;
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:40:36 +00:00
|
|
|
void OS_X11::request_attention() {
|
|
|
|
// Using EWMH -- Extended Window Manager Hints
|
|
|
|
//
|
|
|
|
// Sets the _NET_WM_STATE_DEMANDS_ATTENTION atom for WM_STATE
|
|
|
|
// Will be unset by the window manager after user react on the request for attention
|
|
|
|
//
|
|
|
|
XEvent xev;
|
|
|
|
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
|
|
|
|
Atom wm_attention = XInternAtom(x11_display, "_NET_WM_STATE_DEMANDS_ATTENTION", False);
|
|
|
|
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
|
|
|
xev.xclient.window = x11_window;
|
|
|
|
xev.xclient.message_type = wm_state;
|
|
|
|
xev.xclient.format = 32;
|
|
|
|
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
|
|
|
|
xev.xclient.data.l[1] = wm_attention;
|
|
|
|
|
|
|
|
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void OS_X11::get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
state->set_shift((p_x11_state & ShiftMask));
|
|
|
|
state->set_control((p_x11_state & ControlMask));
|
|
|
|
state->set_alt((p_x11_state & Mod1Mask /*|| p_x11_state&Mod5Mask*/)); //altgr should not count as alt
|
|
|
|
state->set_metakey((p_x11_state & Mod4Mask));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
unsigned int state = 0;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_x11_state & Button1Mask) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
state |= 1 << 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_x11_state & Button3Mask) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
state |= 1 << 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_x11_state & Button2Mask) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
state |= 1 << 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_x11_state & Button4Mask) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
state |= 1 << 3;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_x11_state & Button5Mask) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
state |= 1 << 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_button_state = state;
|
2014-02-10 01:10:30 +00:00
|
|
|
return state;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-05-24 04:35:47 +00:00
|
|
|
void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// X11 functions don't know what const is
|
|
|
|
XKeyEvent *xkeyevent = p_event;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// This code was pretty difficult to write.
|
|
|
|
// The docs stink and every toolkit seems to
|
2016-03-08 23:00:52 +00:00
|
|
|
// do it in a different way.
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* Phase 1, obtain a proper keysym */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// This was also very difficult to figure out.
|
|
|
|
// You'd expect you could just use Keysym provided by
|
2016-03-08 23:00:52 +00:00
|
|
|
// XKeycodeToKeysym to obtain internationalized
|
|
|
|
// input.. WRONG!!
|
2014-02-10 01:10:30 +00:00
|
|
|
// you must use XLookupString (???) which not only wastes
|
2017-03-24 20:45:31 +00:00
|
|
|
// cycles generating an unnecessary string, but also
|
2014-02-10 01:10:30 +00:00
|
|
|
// still works in half the cases. (won't handle deadkeys)
|
|
|
|
// For more complex input methods (deadkeys and more advanced)
|
|
|
|
// you have to use XmbLookupString (??).
|
|
|
|
// So.. then you have to chosse which of both results
|
|
|
|
// you want to keep.
|
|
|
|
// This is a real bizarreness and cpu waster.
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
KeySym keysym_keycode = 0; // keysym used to find a keycode
|
|
|
|
KeySym keysym_unicode = 0; // keysym used to find unicode
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// XLookupString returns keysyms usable as nice scancodes/
|
2017-03-05 15:44:50 +00:00
|
|
|
char str[256 + 1];
|
2015-01-16 05:44:41 +00:00
|
|
|
XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
// Meanwhile, XLookupString returns keysyms useful for unicode.
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!xmbstring) {
|
|
|
|
// keep a temporary buffer for the string
|
2017-03-05 15:44:50 +00:00
|
|
|
xmbstring = (char *)memalloc(sizeof(char) * 8);
|
|
|
|
xmblen = 8;
|
2016-03-08 23:00:52 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
keysym_unicode = keysym_keycode;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (xkeyevent->type == KeyPress && xic) {
|
|
|
|
|
|
|
|
Status status;
|
2017-06-27 09:26:43 +00:00
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
|
|
|
int utf8len = 8;
|
|
|
|
char *utf8string = (char *)memalloc(sizeof(char) * utf8len);
|
|
|
|
int utf8bytes = Xutf8LookupString(xic, xkeyevent, utf8string,
|
|
|
|
utf8len - 1, &keysym_unicode, &status);
|
|
|
|
if (status == XBufferOverflow) {
|
|
|
|
utf8len = utf8bytes + 1;
|
|
|
|
utf8string = (char *)memrealloc(utf8string, utf8len);
|
|
|
|
utf8bytes = Xutf8LookupString(xic, xkeyevent, utf8string,
|
|
|
|
utf8len - 1, &keysym_unicode, &status);
|
|
|
|
}
|
|
|
|
utf8string[utf8bytes] = '\0';
|
|
|
|
|
|
|
|
if (status == XLookupChars) {
|
|
|
|
bool keypress = xkeyevent->type == KeyPress;
|
|
|
|
unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode);
|
|
|
|
if (keycode >= 'a' && keycode <= 'z')
|
|
|
|
keycode -= 'a' - 'A';
|
|
|
|
|
|
|
|
String tmp;
|
|
|
|
tmp.parse_utf8(utf8string, utf8bytes);
|
|
|
|
for (int i = 0; i < tmp.length(); i++) {
|
|
|
|
Ref<InputEventKey> k;
|
|
|
|
k.instance();
|
|
|
|
if (keycode == 0 && tmp[i] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_key_modifier_state(xkeyevent->state, k);
|
|
|
|
|
|
|
|
k->set_unicode(tmp[i]);
|
|
|
|
|
|
|
|
k->set_pressed(keypress);
|
|
|
|
|
|
|
|
k->set_scancode(keycode);
|
|
|
|
|
|
|
|
k->set_echo(false);
|
|
|
|
|
|
|
|
if (k->get_scancode() == KEY_BACKTAB) {
|
|
|
|
//make it consistent across platforms.
|
|
|
|
k->set_scancode(KEY_TAB);
|
|
|
|
k->set_shift(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
input->parse_input_event(k);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memfree(utf8string);
|
|
|
|
#else
|
2017-06-24 13:09:39 +00:00
|
|
|
do {
|
2017-06-25 23:09:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int mnbytes = XmbLookupString(xic, xkeyevent, xmbstring, xmblen - 1, &keysym_unicode, &status);
|
2014-02-10 01:10:30 +00:00
|
|
|
xmbstring[mnbytes] = '\0';
|
|
|
|
|
|
|
|
if (status == XBufferOverflow) {
|
|
|
|
xmblen = mnbytes + 1;
|
2017-03-05 15:44:50 +00:00
|
|
|
xmbstring = (char *)memrealloc(xmbstring, xmblen);
|
2016-03-08 23:00:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} while (status == XBufferOverflow);
|
2017-06-27 09:26:43 +00:00
|
|
|
#endif
|
2016-03-08 23:00:52 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* Phase 2, obtain a pigui keycode from the keysym */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// KeyMappingX11 just translated the X11 keysym to a PIGUI
|
|
|
|
// keysym, so it works in all platforms the same.
|
|
|
|
|
|
|
|
unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-09-02 14:19:06 +00:00
|
|
|
/* Phase 3, obtain a unicode character from the keysym */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// KeyMappingX11 also translates keysym to unicode.
|
|
|
|
// It does a binary search on a table to translate
|
2016-03-08 23:00:52 +00:00
|
|
|
// most properly.
|
2014-02-10 01:10:30 +00:00
|
|
|
//print_line("keysym_unicode: "+rtos(keysym_unicode));
|
2017-03-05 15:44:50 +00:00
|
|
|
unsigned int unicode = keysym_unicode > 0 ? KeyMappingX11::get_unicode_from_keysym(keysym_unicode) : 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/* Phase 4, determine if event must be filtered */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// This seems to be a side-effect of using XIM.
|
2017-03-24 20:45:31 +00:00
|
|
|
// XEventFilter looks like a core X11 function,
|
2014-02-10 01:10:30 +00:00
|
|
|
// but it's actually just used to see if we must
|
|
|
|
// ignore a deadkey, or events XIM determines
|
|
|
|
// must not reach the actual gui.
|
|
|
|
// Guess it was a design problem of the extension
|
|
|
|
|
|
|
|
bool keypress = xkeyevent->type == KeyPress;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (keycode == 0 && unicode == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Phase 5, determine modifier mask */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// No problems here, except I had no way to
|
|
|
|
// know Mod1 was ALT and Mod4 was META (applekey/winkey)
|
|
|
|
// just tried Mods until i found them.
|
|
|
|
|
|
|
|
//print_line("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> k;
|
|
|
|
k.instance();
|
|
|
|
|
|
|
|
get_key_modifier_state(xkeyevent->state, k);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* Phase 6, determine echo character */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// Echo characters in X11 are a keyrelease and a keypress
|
|
|
|
// one after the other with the (almot) same timestamp.
|
|
|
|
// To detect them, i use XPeekEvent and check that their
|
2017-07-08 15:12:18 +00:00
|
|
|
// difference in time is below a threshold.
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-05-24 04:35:47 +00:00
|
|
|
if (xkeyevent->type != KeyPress) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
p_echo = false;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// make sure there are events pending,
|
|
|
|
// so this call won't block.
|
2017-03-05 15:44:50 +00:00
|
|
|
if (XPending(x11_display) > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
XEvent peek_event;
|
|
|
|
XPeekEvent(x11_display, &peek_event);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-07-08 15:12:18 +00:00
|
|
|
// I'm using a threshold of 5 msecs,
|
2014-02-10 01:10:30 +00:00
|
|
|
// since sometimes there seems to be a little
|
|
|
|
// jitter. I'm still not convinced that all this approach
|
|
|
|
// is correct, but the xorg developers are
|
|
|
|
// not very helpful today.
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
::Time tresh = ABS(peek_event.xkey.time - xkeyevent->time);
|
|
|
|
if (peek_event.type == KeyPress && tresh < 5) {
|
2014-05-24 04:35:47 +00:00
|
|
|
KeySym rk;
|
2017-03-05 15:44:50 +00:00
|
|
|
XLookupString((XKeyEvent *)&peek_event, str, 256, &rk, NULL);
|
|
|
|
if (rk == keysym_keycode) {
|
2014-05-24 04:35:47 +00:00
|
|
|
XEvent event;
|
|
|
|
XNextEvent(x11_display, &event); //erase next event
|
2017-03-05 15:44:50 +00:00
|
|
|
handle_key_event((XKeyEvent *)&event, true);
|
2014-05-24 04:35:47 +00:00
|
|
|
return; //ignore current, echo next
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// use the time from peek_event so it always works
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
// save the time to check for echo when keypress happens
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* Phase 7, send event to Window */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
k->set_pressed(keypress);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (keycode >= 'a' && keycode <= 'z')
|
|
|
|
keycode -= 'a' - 'A';
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
k->set_scancode(keycode);
|
|
|
|
k->set_unicode(unicode);
|
|
|
|
k->set_echo(p_echo);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (k->get_scancode() == KEY_BACKTAB) {
|
2017-03-24 20:45:31 +00:00
|
|
|
//make it consistent across platforms.
|
2017-05-20 15:38:03 +00:00
|
|
|
k->set_scancode(KEY_TAB);
|
|
|
|
k->set_shift(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 10:24:44 +00:00
|
|
|
//don't set mod state if modifier keys are released by themselves
|
|
|
|
//else event.is_action() will not work correctly here
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!k->is_pressed()) {
|
|
|
|
if (k->get_scancode() == KEY_SHIFT)
|
|
|
|
k->set_shift(false);
|
|
|
|
else if (k->get_scancode() == KEY_CONTROL)
|
|
|
|
k->set_control(false);
|
|
|
|
else if (k->get_scancode() == KEY_ALT)
|
|
|
|
k->set_alt(false);
|
|
|
|
else if (k->get_scancode() == KEY_META)
|
|
|
|
k->set_metakey(false);
|
2016-09-22 10:24:44 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_scancode());
|
|
|
|
if (k->is_pressed()) {
|
|
|
|
if (last_is_pressed) {
|
|
|
|
k->set_echo(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//ignore
|
|
|
|
if (last_is_pressed == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
//printf("key: %x\n",k->get_scancode());
|
|
|
|
input->parse_input_event(k);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
struct Property {
|
2016-05-29 15:40:08 +00:00
|
|
|
unsigned char *data;
|
|
|
|
int format, nitems;
|
|
|
|
Atom type;
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static Property read_property(Display *p_display, Window p_window, Atom p_property) {
|
2016-05-29 15:40:08 +00:00
|
|
|
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes_after;
|
2017-03-05 15:44:50 +00:00
|
|
|
unsigned char *ret = 0;
|
2016-05-29 15:40:08 +00:00
|
|
|
|
|
|
|
int read_bytes = 1024;
|
|
|
|
|
|
|
|
//Keep trying to read the property until there are no
|
|
|
|
//bytes unread.
|
2017-03-05 15:44:50 +00:00
|
|
|
do {
|
|
|
|
if (ret != 0)
|
2016-05-29 15:40:08 +00:00
|
|
|
XFree(ret);
|
|
|
|
|
|
|
|
XGetWindowProperty(p_display, p_window, p_property, 0, read_bytes, False, AnyPropertyType,
|
2017-03-05 15:44:50 +00:00
|
|
|
&actual_type, &actual_format, &nitems, &bytes_after,
|
|
|
|
&ret);
|
2016-05-29 15:40:08 +00:00
|
|
|
|
|
|
|
read_bytes *= 2;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} while (bytes_after != 0);
|
2016-05-29 15:40:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Property p = { ret, actual_format, (int)nitems, actual_type };
|
2016-05-29 15:40:08 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static Atom pick_target_from_list(Display *p_display, Atom *p_list, int p_count) {
|
2016-05-29 15:40:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *target_type = "text/uri-list";
|
2016-05-29 15:40:08 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < p_count; i++) {
|
|
|
|
|
|
|
|
Atom atom = p_list[i];
|
|
|
|
|
|
|
|
if (atom != None && String(XGetAtomName(p_display, atom)) == target_type)
|
2017-03-05 15:44:50 +00:00
|
|
|
return atom;
|
2016-05-29 15:40:08 +00:00
|
|
|
}
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static Atom pick_target_from_atoms(Display *p_disp, Atom p_t1, Atom p_t2, Atom p_t3) {
|
2016-05-28 19:35:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *target_type = "text/uri-list";
|
2016-05-28 19:35:42 +00:00
|
|
|
if (p_t1 != None && String(XGetAtomName(p_disp, p_t1)) == target_type)
|
|
|
|
return p_t1;
|
|
|
|
|
|
|
|
if (p_t2 != None && String(XGetAtomName(p_disp, p_t2)) == target_type)
|
|
|
|
return p_t2;
|
|
|
|
|
|
|
|
if (p_t3 != None && String(XGetAtomName(p_disp, p_t3)) == target_type)
|
|
|
|
return p_t3;
|
|
|
|
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-10-24 19:35:28 +00:00
|
|
|
void OS_X11::_window_changed(XEvent *event) {
|
|
|
|
|
|
|
|
if (xic) {
|
|
|
|
// Not portable.
|
|
|
|
set_ime_position(Point2(0, 1));
|
|
|
|
}
|
|
|
|
if ((event->xconfigure.width == current_videomode.width) &&
|
|
|
|
(event->xconfigure.height == current_videomode.height))
|
|
|
|
return;
|
|
|
|
|
|
|
|
current_videomode.width = event->xconfigure.width;
|
|
|
|
current_videomode.height = event->xconfigure.height;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_X11::process_xevents() {
|
|
|
|
|
|
|
|
//printf("checking events %i\n", XPending(x11_display));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
do_mouse_warp = false;
|
2017-01-25 18:21:41 +00:00
|
|
|
|
|
|
|
// Is the current mouse mode one where it needs to be grabbed.
|
2017-03-05 15:44:50 +00:00
|
|
|
bool mouse_mode_grab = mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED;
|
2017-01-25 18:21:41 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
while (XPending(x11_display) > 0) {
|
|
|
|
XEvent event;
|
|
|
|
XNextEvent(x11_display, &event);
|
|
|
|
|
2017-06-27 09:26:43 +00:00
|
|
|
if (XFilterEvent(&event, None)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-11-29 20:01:26 +00:00
|
|
|
#ifdef TOUCH_ENABLED
|
|
|
|
if (XGetEventData(x11_display, &event.xcookie)) {
|
|
|
|
|
2017-12-10 06:05:17 +00:00
|
|
|
if (event.xcookie.type == GenericEvent && event.xcookie.extension == touch.opcode) {
|
2017-11-29 20:01:26 +00:00
|
|
|
|
|
|
|
XIDeviceEvent *event_data = (XIDeviceEvent *)event.xcookie.data;
|
|
|
|
int index = event_data->detail;
|
|
|
|
Vector2 pos = Vector2(event_data->event_x, event_data->event_y);
|
|
|
|
|
|
|
|
switch (event_data->evtype) {
|
|
|
|
|
|
|
|
case XI_TouchBegin: // Fall-through
|
2017-12-10 06:05:17 +00:00
|
|
|
// Disabled hand-in-hand with the grabbing
|
|
|
|
//XIAllowTouchEvents(x11_display, event_data->deviceid, event_data->detail, x11_window, XIAcceptTouch);
|
2017-11-29 20:01:26 +00:00
|
|
|
|
|
|
|
case XI_TouchEnd: {
|
|
|
|
|
|
|
|
bool is_begin = event_data->evtype == XI_TouchBegin;
|
|
|
|
|
|
|
|
Ref<InputEventScreenTouch> st;
|
|
|
|
st.instance();
|
|
|
|
st->set_index(index);
|
|
|
|
st->set_position(pos);
|
|
|
|
st->set_pressed(is_begin);
|
|
|
|
|
|
|
|
if (is_begin) {
|
|
|
|
if (touch.state.has(index)) // Defensive
|
|
|
|
break;
|
|
|
|
touch.state[index] = pos;
|
2018-02-24 02:04:30 +00:00
|
|
|
if (touch.state.size() == 1) {
|
|
|
|
// X11 may send a motion event when a touch gesture begins, that would result
|
|
|
|
// in a spurious mouse motion event being sent to Godot; remember it to be able to filter it out
|
|
|
|
touch.mouse_pos_to_filter = pos;
|
|
|
|
}
|
2017-11-29 20:01:26 +00:00
|
|
|
input->parse_input_event(st);
|
|
|
|
} else {
|
|
|
|
if (!touch.state.has(index)) // Defensive
|
|
|
|
break;
|
|
|
|
touch.state.erase(index);
|
|
|
|
input->parse_input_event(st);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case XI_TouchUpdate: {
|
|
|
|
|
|
|
|
Map<int, Vector2>::Element *curr_pos_elem = touch.state.find(index);
|
|
|
|
if (!curr_pos_elem) { // Defensive
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curr_pos_elem->value() != pos) {
|
|
|
|
|
|
|
|
Ref<InputEventScreenDrag> sd;
|
|
|
|
sd.instance();
|
|
|
|
sd->set_index(index);
|
|
|
|
sd->set_position(pos);
|
|
|
|
sd->set_relative(pos - curr_pos_elem->value());
|
|
|
|
input->parse_input_event(sd);
|
|
|
|
|
|
|
|
curr_pos_elem->value() = pos;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-10 06:05:17 +00:00
|
|
|
XFreeEventData(x11_display, &event.xcookie);
|
2017-11-29 20:01:26 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
switch (event.type) {
|
2017-03-05 15:44:50 +00:00
|
|
|
case Expose:
|
|
|
|
Main::force_redraw();
|
|
|
|
break;
|
2015-09-24 21:06:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case NoExpose:
|
|
|
|
minimized = true;
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case VisibilityNotify: {
|
|
|
|
XVisibilityEvent *visibility = (XVisibilityEvent *)&event;
|
|
|
|
minimized = (visibility->state == VisibilityFullyObscured);
|
|
|
|
} break;
|
|
|
|
case LeaveNotify: {
|
|
|
|
if (main_loop && !mouse_mode_grab)
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT);
|
|
|
|
if (input)
|
|
|
|
input->set_mouse_in_window(false);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case EnterNotify: {
|
|
|
|
if (main_loop && !mouse_mode_grab)
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER);
|
2017-04-06 16:08:42 +00:00
|
|
|
if (input)
|
2017-03-05 15:44:50 +00:00
|
|
|
input->set_mouse_in_window(true);
|
|
|
|
} break;
|
|
|
|
case FocusIn:
|
|
|
|
minimized = false;
|
|
|
|
window_has_focus = true;
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
|
|
|
if (mouse_mode_grab) {
|
|
|
|
// Show and update the cursor if confined and the window regained focus.
|
|
|
|
if (mouse_mode == MOUSE_MODE_CONFINED)
|
|
|
|
XUndefineCursor(x11_display, x11_window);
|
|
|
|
else if (mouse_mode == MOUSE_MODE_CAPTURED) // or re-hide it in captured mode
|
|
|
|
XDefineCursor(x11_display, x11_window, null_cursor);
|
|
|
|
|
|
|
|
XGrabPointer(
|
|
|
|
x11_display, x11_window, True,
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
|
|
|
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime);
|
2017-01-25 18:21:41 +00:00
|
|
|
}
|
2017-11-29 20:01:26 +00:00
|
|
|
#ifdef TOUCH_ENABLED
|
2018-07-18 14:24:33 +00:00
|
|
|
// Grab touch devices to avoid OS gesture interference
|
|
|
|
/*for (int i = 0; i < touch.devices.size(); ++i) {
|
2017-11-29 20:01:26 +00:00
|
|
|
XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
|
2017-12-10 06:05:17 +00:00
|
|
|
}*/
|
2017-11-29 20:01:26 +00:00
|
|
|
#endif
|
2017-06-27 09:26:43 +00:00
|
|
|
if (xic) {
|
|
|
|
XSetICFocus(xic);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case FocusOut:
|
|
|
|
window_has_focus = false;
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
|
|
|
if (mouse_mode_grab) {
|
|
|
|
//dear X11, I try, I really try, but you never work, you do whathever you want.
|
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
|
|
|
// Show the cursor if we're in captured mode so it doesn't look weird.
|
|
|
|
XUndefineCursor(x11_display, x11_window);
|
|
|
|
}
|
|
|
|
XUngrabPointer(x11_display, CurrentTime);
|
|
|
|
}
|
2017-11-29 20:01:26 +00:00
|
|
|
#ifdef TOUCH_ENABLED
|
|
|
|
// Ungrab touch devices so input works as usual while we are unfocused
|
2017-12-10 06:05:17 +00:00
|
|
|
/*for (int i = 0; i < touch.devices.size(); ++i) {
|
2017-11-29 20:01:26 +00:00
|
|
|
XIUngrabDevice(x11_display, touch.devices[i], CurrentTime);
|
2017-12-10 06:05:17 +00:00
|
|
|
}*/
|
2017-11-29 20:01:26 +00:00
|
|
|
|
|
|
|
// Release every pointer to avoid sticky points
|
|
|
|
for (Map<int, Vector2>::Element *E = touch.state.front(); E; E = E->next()) {
|
|
|
|
|
|
|
|
Ref<InputEventScreenTouch> st;
|
|
|
|
st.instance();
|
|
|
|
st->set_index(E->key());
|
|
|
|
st->set_position(E->get());
|
|
|
|
input->parse_input_event(st);
|
|
|
|
}
|
|
|
|
touch.state.clear();
|
|
|
|
#endif
|
2017-06-27 09:26:43 +00:00
|
|
|
if (xic) {
|
|
|
|
XUnsetICFocus(xic);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case ConfigureNotify:
|
2017-10-24 19:35:28 +00:00
|
|
|
_window_changed(&event);
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease: {
|
|
|
|
|
|
|
|
/* exit in case of a mouse button press */
|
|
|
|
last_timestamp = event.xbutton.time;
|
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
|
|
|
event.xbutton.x = last_mouse_pos.x;
|
|
|
|
event.xbutton.y = last_mouse_pos.y;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mb;
|
|
|
|
mb.instance();
|
|
|
|
|
|
|
|
get_key_modifier_state(event.xbutton.state, mb);
|
|
|
|
mb->set_button_mask(get_mouse_button_state(event.xbutton.state));
|
2017-06-03 08:54:24 +00:00
|
|
|
mb->set_position(Vector2(event.xbutton.x, event.xbutton.y));
|
|
|
|
mb->set_global_position(mb->get_position());
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_button_index(event.xbutton.button);
|
|
|
|
if (mb->get_button_index() == 2)
|
|
|
|
mb->set_button_index(3);
|
|
|
|
else if (mb->get_button_index() == 3)
|
|
|
|
mb->set_button_index(2);
|
|
|
|
|
|
|
|
mb->set_pressed((event.type == ButtonPress));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (event.type == ButtonPress && event.xbutton.button == 1) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint64_t diff = get_ticks_usec() / 1000 - last_click_ms;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (diff < 400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x, event.xbutton.y)) < 5) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_click_ms = 0;
|
|
|
|
last_click_pos = Point2(-100, -100);
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_doubleclick(true);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
|
|
|
last_click_ms += diff;
|
|
|
|
last_click_pos = Point2(event.xbutton.x, event.xbutton.y);
|
|
|
|
}
|
2015-08-29 04:43:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
input->parse_input_event(mb);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case MotionNotify: {
|
|
|
|
|
|
|
|
// FUCK YOU X11 API YOU SERIOUSLY GROSS ME OUT
|
|
|
|
// YOU ARE AS GROSS AS LOOKING AT A PUTRID PILE
|
|
|
|
// OF POOP STICKING OUT OF A CLOGGED TOILET
|
|
|
|
// HOW THE FUCK I AM SUPPOSED TO KNOW WHICH ONE
|
|
|
|
// OF THE MOTION NOTIFY EVENTS IS THE ONE GENERATED
|
|
|
|
// BY WARPING THE MOUSE POINTER?
|
|
|
|
// YOU ARE FORCING ME TO FILTER ONE BY ONE TO FIND IT
|
|
|
|
// PLEASE DO ME A FAVOR AND DIE DROWNED IN A FECAL
|
|
|
|
// MOUNTAIN BECAUSE THAT'S WHERE YOU BELONG.
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED && event.xmotion.x == current_videomode.width / 2 && event.xmotion.y == current_videomode.height / 2) {
|
|
|
|
//this is likely the warp event since it was warped here
|
|
|
|
center = Vector2(event.xmotion.x, event.xmotion.y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XPending(x11_display) > 0) {
|
|
|
|
XEvent tevent;
|
|
|
|
XPeekEvent(x11_display, &tevent);
|
|
|
|
if (tevent.type == MotionNotify) {
|
|
|
|
XNextEvent(x11_display, &event);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2015-08-29 04:43:21 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_timestamp = event.xmotion.time;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
// Motion is also simple.
|
|
|
|
// A little hack is in order
|
|
|
|
// to be able to send relative motion events.
|
|
|
|
Point2i pos(event.xmotion.x, event.xmotion.y);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-02-24 02:04:30 +00:00
|
|
|
// Avoidance of spurious mouse motion (see handling of touch)
|
|
|
|
bool filter = false;
|
|
|
|
// Adding some tolerance to match better Point2i to Vector2
|
|
|
|
if (touch.state.size() && Vector2(pos).distance_squared_to(touch.mouse_pos_to_filter) < 2) {
|
|
|
|
filter = true;
|
|
|
|
}
|
|
|
|
// Invalidate to avoid filtering a possible legitimate similar event coming later
|
|
|
|
touch.mouse_pos_to_filter = Vector2(1e10, 1e10);
|
|
|
|
if (filter) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
2017-08-27 19:07:15 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (pos == Point2i(current_videomode.width / 2, current_videomode.height / 2)) {
|
|
|
|
//this sucks, it's a hack, etc and is a little inaccurate, etc.
|
|
|
|
//but nothing I can do, X11 sucks.
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
center = pos;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2i new_center = pos;
|
|
|
|
pos = last_mouse_pos + (pos - center);
|
|
|
|
center = new_center;
|
|
|
|
do_mouse_warp = window_has_focus; // warp the cursor if we're focused in
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!last_mouse_pos_valid) {
|
2015-02-12 14:58:00 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_mouse_pos = pos;
|
|
|
|
last_mouse_pos_valid = true;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2i rel = pos - last_mouse_pos;
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm;
|
|
|
|
mm.instance();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
get_key_modifier_state(event.xmotion.state, mm);
|
|
|
|
mm->set_button_mask(get_mouse_button_state(event.xmotion.state));
|
2017-06-03 08:54:24 +00:00
|
|
|
mm->set_position(pos);
|
|
|
|
mm->set_global_position(pos);
|
2017-03-29 15:29:38 +00:00
|
|
|
input->set_mouse_position(pos);
|
2017-05-20 15:38:03 +00:00
|
|
|
mm->set_speed(input->get_last_mouse_speed());
|
|
|
|
mm->set_relative(rel);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
last_mouse_pos = pos;
|
|
|
|
|
|
|
|
// printf("rel: %d,%d\n", rel.x, rel.y );
|
|
|
|
// Don't propagate the motion event unless we have focus
|
|
|
|
// this is so that the relative motion doesn't get messed up
|
|
|
|
// after we regain focus.
|
|
|
|
if (window_has_focus || !mouse_mode_grab)
|
2017-05-20 15:38:03 +00:00
|
|
|
input->parse_input_event(mm);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease: {
|
|
|
|
|
|
|
|
last_timestamp = event.xkey.time;
|
|
|
|
|
|
|
|
// key event is a little complex, so
|
|
|
|
// it will be handled in it's own function.
|
|
|
|
handle_key_event((XKeyEvent *)&event);
|
|
|
|
} break;
|
|
|
|
case SelectionRequest: {
|
|
|
|
|
|
|
|
XSelectionRequestEvent *req;
|
|
|
|
XEvent e, respond;
|
|
|
|
e = event;
|
|
|
|
|
|
|
|
req = &(e.xselectionrequest);
|
2018-01-28 23:33:57 +00:00
|
|
|
if (req->target == XInternAtom(x11_display, "UTF8_STRING", 0) ||
|
|
|
|
req->target == XInternAtom(x11_display, "COMPOUND_TEXT", 0) ||
|
|
|
|
req->target == XInternAtom(x11_display, "TEXT", 0) ||
|
|
|
|
req->target == XA_STRING ||
|
|
|
|
req->target == XInternAtom(x11_display, "text/plain;charset=utf-8", 0) ||
|
|
|
|
req->target == XInternAtom(x11_display, "text/plain", 0)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
CharString clip = OS::get_clipboard().utf8();
|
|
|
|
XChangeProperty(x11_display,
|
|
|
|
req->requestor,
|
|
|
|
req->property,
|
|
|
|
req->target,
|
|
|
|
8,
|
|
|
|
PropModeReplace,
|
|
|
|
(unsigned char *)clip.get_data(),
|
|
|
|
clip.length());
|
|
|
|
respond.xselection.property = req->property;
|
|
|
|
} else if (req->target == XInternAtom(x11_display, "TARGETS", 0)) {
|
|
|
|
|
2018-01-28 23:33:57 +00:00
|
|
|
Atom data[7];
|
|
|
|
data[0] = XInternAtom(x11_display, "TARGETS", 0);
|
|
|
|
data[1] = XInternAtom(x11_display, "UTF8_STRING", 0);
|
|
|
|
data[2] = XInternAtom(x11_display, "COMPOUND_TEXT", 0);
|
|
|
|
data[3] = XInternAtom(x11_display, "TEXT", 0);
|
|
|
|
data[4] = XA_STRING;
|
|
|
|
data[5] = XInternAtom(x11_display, "text/plain;charset=utf-8", 0);
|
|
|
|
data[6] = XInternAtom(x11_display, "text/plain", 0);
|
|
|
|
|
|
|
|
XChangeProperty(x11_display,
|
|
|
|
req->requestor,
|
|
|
|
req->property,
|
|
|
|
XA_ATOM,
|
|
|
|
32,
|
|
|
|
PropModeReplace,
|
|
|
|
(unsigned char *)&data,
|
|
|
|
sizeof(data) / sizeof(data[0]));
|
2017-03-05 15:44:50 +00:00
|
|
|
respond.xselection.property = req->property;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
2018-01-28 23:33:57 +00:00
|
|
|
char *targetname = XGetAtomName(x11_display, req->target);
|
|
|
|
printf("No Target '%s'\n", targetname);
|
|
|
|
if (targetname)
|
|
|
|
XFree(targetname);
|
2017-03-05 15:44:50 +00:00
|
|
|
respond.xselection.property = None;
|
|
|
|
}
|
2018-01-28 23:33:57 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
respond.xselection.type = SelectionNotify;
|
|
|
|
respond.xselection.display = req->display;
|
|
|
|
respond.xselection.requestor = req->requestor;
|
|
|
|
respond.xselection.selection = req->selection;
|
|
|
|
respond.xselection.target = req->target;
|
|
|
|
respond.xselection.time = req->time;
|
2018-01-28 23:33:57 +00:00
|
|
|
XSendEvent(x11_display, req->requestor, True, NoEventMask, &respond);
|
2017-03-05 15:44:50 +00:00
|
|
|
XFlush(x11_display);
|
|
|
|
} break;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case SelectionNotify:
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (event.xselection.target == requested) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Property p = read_property(x11_display, x11_window, XInternAtom(x11_display, "PRIMARY", 0));
|
2016-05-28 19:35:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
main_loop->drop_files(files);
|
2016-05-28 19:35:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
//Reply that all is well.
|
|
|
|
XClientMessageEvent m;
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
m.type = ClientMessage;
|
|
|
|
m.display = x11_display;
|
|
|
|
m.window = xdnd_source_window;
|
|
|
|
m.message_type = xdnd_finished;
|
|
|
|
m.format = 32;
|
|
|
|
m.data.l[0] = x11_window;
|
|
|
|
m.data.l[1] = 1;
|
|
|
|
m.data.l[2] = xdnd_action_copy; //We only ever copy.
|
2016-05-28 19:35:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
XSendEvent(x11_display, xdnd_source_window, False, NoEventMask, (XEvent *)&m);
|
2016-05-28 19:35:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case ClientMessage:
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((unsigned int)event.xclient.data.l[0] == (unsigned int)wm_delete)
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
|
2016-05-28 19:35:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_enter) {
|
2016-05-28 19:35:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
//File(s) have been dragged over the window, check for supported target (text/uri-list)
|
|
|
|
xdnd_version = (event.xclient.data.l[1] >> 24);
|
|
|
|
Window source = event.xclient.data.l[0];
|
|
|
|
bool more_than_3 = event.xclient.data.l[1] & 1;
|
|
|
|
if (more_than_3) {
|
|
|
|
Property p = read_property(x11_display, source, XInternAtom(x11_display, "XdndTypeList", False));
|
|
|
|
requested = pick_target_from_list(x11_display, (Atom *)p.data, p.nitems);
|
|
|
|
} else
|
|
|
|
requested = pick_target_from_atoms(x11_display, event.xclient.data.l[2], event.xclient.data.l[3], event.xclient.data.l[4]);
|
|
|
|
} else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_position) {
|
|
|
|
|
|
|
|
//xdnd position event, reply with an XDND status message
|
|
|
|
//just depending on type of data for now
|
2016-05-28 19:35:42 +00:00
|
|
|
XClientMessageEvent m;
|
2016-06-19 00:06:25 +00:00
|
|
|
memset(&m, 0, sizeof(m));
|
2016-05-28 19:35:42 +00:00
|
|
|
m.type = ClientMessage;
|
|
|
|
m.display = event.xclient.display;
|
|
|
|
m.window = event.xclient.data.l[0];
|
2017-03-05 15:44:50 +00:00
|
|
|
m.message_type = xdnd_status;
|
|
|
|
m.format = 32;
|
2016-05-28 19:35:42 +00:00
|
|
|
m.data.l[0] = x11_window;
|
2017-03-05 15:44:50 +00:00
|
|
|
m.data.l[1] = (requested != None);
|
|
|
|
m.data.l[2] = 0; //empty rectangle
|
|
|
|
m.data.l[3] = 0;
|
|
|
|
m.data.l[4] = xdnd_action_copy;
|
|
|
|
|
|
|
|
XSendEvent(x11_display, event.xclient.data.l[0], False, NoEventMask, (XEvent *)&m);
|
|
|
|
XFlush(x11_display);
|
|
|
|
} else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_drop) {
|
|
|
|
|
|
|
|
if (requested != None) {
|
|
|
|
xdnd_source_window = event.xclient.data.l[0];
|
|
|
|
if (xdnd_version >= 1)
|
|
|
|
XConvertSelection(x11_display, xdnd_selection, requested, XInternAtom(x11_display, "PRIMARY", 0), x11_window, event.xclient.data.l[2]);
|
|
|
|
else
|
|
|
|
XConvertSelection(x11_display, xdnd_selection, requested, XInternAtom(x11_display, "PRIMARY", 0), x11_window, CurrentTime);
|
|
|
|
} else {
|
|
|
|
//Reply that we're not interested.
|
|
|
|
XClientMessageEvent m;
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
m.type = ClientMessage;
|
|
|
|
m.display = event.xclient.display;
|
|
|
|
m.window = event.xclient.data.l[0];
|
|
|
|
m.message_type = xdnd_finished;
|
|
|
|
m.format = 32;
|
|
|
|
m.data.l[0] = x11_window;
|
|
|
|
m.data.l[1] = 0;
|
|
|
|
m.data.l[2] = None; //Failed.
|
|
|
|
XSendEvent(x11_display, event.xclient.data.l[0], False, NoEventMask, (XEvent *)&m);
|
|
|
|
}
|
2016-05-28 19:35:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
XFlush(x11_display);
|
|
|
|
|
|
|
|
if (do_mouse_warp) {
|
|
|
|
|
|
|
|
XWarpPointer(x11_display, None, x11_window,
|
2017-03-05 15:44:50 +00:00
|
|
|
0, 0, 0, 0, (int)current_videomode.width / 2, (int)current_videomode.height / 2);
|
2015-02-12 14:58:00 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
/*
|
2015-02-12 14:58:00 +00:00
|
|
|
Window root, child;
|
|
|
|
int root_x, root_y;
|
|
|
|
int win_x, win_y;
|
|
|
|
unsigned int mask;
|
|
|
|
XQueryPointer( x11_display, x11_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask );
|
|
|
|
|
|
|
|
printf("Root: %d,%d\n", root_x, root_y);
|
|
|
|
printf("Win: %d,%d\n", win_x, win_y);
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MainLoop *OS_X11::get_main_loop() const {
|
|
|
|
|
|
|
|
return main_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_X11::delete_main_loop() {
|
|
|
|
|
|
|
|
if (main_loop)
|
|
|
|
memdelete(main_loop);
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::set_main_loop(MainLoop *p_main_loop) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = p_main_loop;
|
2014-02-10 01:10:30 +00:00
|
|
|
input->set_main_loop(p_main_loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_X11::can_draw() const {
|
|
|
|
|
|
|
|
return !minimized;
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::set_clipboard(const String &p_text) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
OS::set_clipboard(p_text);
|
|
|
|
|
|
|
|
XSetSelectionOwner(x11_display, XA_PRIMARY, x11_window, CurrentTime);
|
|
|
|
XSetSelectionOwner(x11_display, XInternAtom(x11_display, "CLIPBOARD", 0), x11_window, CurrentTime);
|
|
|
|
};
|
|
|
|
|
2017-07-24 22:36:19 +00:00
|
|
|
static String _get_clipboard_impl(Atom p_source, Window x11_window, ::Display *x11_display, String p_internal_clipboard, Atom target) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String ret;
|
|
|
|
|
|
|
|
Atom type;
|
|
|
|
Atom selection = XA_PRIMARY;
|
|
|
|
int format, result;
|
|
|
|
unsigned long len, bytes_left, dummy;
|
|
|
|
unsigned char *data;
|
2017-03-05 15:44:50 +00:00
|
|
|
Window Sown = XGetSelectionOwner(x11_display, p_source);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (Sown == x11_window) {
|
|
|
|
|
|
|
|
return p_internal_clipboard;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Sown != None) {
|
2017-07-24 22:36:19 +00:00
|
|
|
XConvertSelection(x11_display, p_source, target, selection,
|
2017-03-05 15:44:50 +00:00
|
|
|
x11_window, CurrentTime);
|
|
|
|
XFlush(x11_display);
|
2014-02-10 01:10:30 +00:00
|
|
|
while (true) {
|
|
|
|
XEvent event;
|
|
|
|
XNextEvent(x11_display, &event);
|
|
|
|
if (event.type == SelectionNotify && event.xselection.requestor == x11_window) {
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do not get any data, see how much data is there
|
|
|
|
//
|
2017-03-05 15:44:50 +00:00
|
|
|
XGetWindowProperty(x11_display, x11_window,
|
|
|
|
selection, // Tricky..
|
|
|
|
0, 0, // offset - len
|
|
|
|
0, // Delete 0==FALSE
|
|
|
|
AnyPropertyType, //flag
|
|
|
|
&type, // return type
|
|
|
|
&format, // return format
|
|
|
|
&len, &bytes_left, //that
|
|
|
|
&data);
|
2014-02-10 01:10:30 +00:00
|
|
|
// DATA is There
|
2017-03-05 15:44:50 +00:00
|
|
|
if (bytes_left > 0) {
|
|
|
|
result = XGetWindowProperty(x11_display, x11_window,
|
|
|
|
selection, 0, bytes_left, 0,
|
|
|
|
AnyPropertyType, &type, &format,
|
|
|
|
&len, &dummy, &data);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (result == Success) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ret.parse_utf8((const char *)data);
|
|
|
|
} else
|
|
|
|
printf("FAIL\n");
|
|
|
|
XFree(data);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2016-07-21 19:11:34 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-07-24 22:36:19 +00:00
|
|
|
static String _get_clipboard(Atom p_source, Window x11_window, ::Display *x11_display, String p_internal_clipboard) {
|
|
|
|
String ret;
|
|
|
|
Atom utf8_atom = XInternAtom(x11_display, "UTF8_STRING", True);
|
|
|
|
if (utf8_atom != None) {
|
|
|
|
ret = _get_clipboard_impl(p_source, x11_window, x11_display, p_internal_clipboard, utf8_atom);
|
|
|
|
}
|
|
|
|
if (ret == "") {
|
|
|
|
ret = _get_clipboard_impl(p_source, x11_window, x11_display, p_internal_clipboard, XA_STRING);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS_X11::get_clipboard() const {
|
|
|
|
|
|
|
|
String ret;
|
|
|
|
ret = _get_clipboard(XInternAtom(x11_display, "CLIPBOARD", 0), x11_window, x11_display, OS::get_clipboard());
|
|
|
|
|
|
|
|
if (ret == "") {
|
|
|
|
ret = _get_clipboard(XA_PRIMARY, x11_window, x11_display, OS::get_clipboard());
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2016-07-21 19:11:34 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String OS_X11::get_name() {
|
|
|
|
|
|
|
|
return "X11";
|
|
|
|
}
|
|
|
|
|
2014-04-18 14:43:54 +00:00
|
|
|
Error OS_X11::shell_open(String p_uri) {
|
|
|
|
|
2014-12-02 17:02:41 +00:00
|
|
|
Error ok;
|
|
|
|
List<String> args;
|
|
|
|
args.push_back(p_uri);
|
2017-10-13 14:45:24 +00:00
|
|
|
ok = execute("xdg-open", args, false);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ok == OK)
|
2014-12-02 17:02:41 +00:00
|
|
|
return OK;
|
2017-03-05 15:44:50 +00:00
|
|
|
ok = execute("gnome-open", args, false);
|
|
|
|
if (ok == OK)
|
2014-12-02 17:02:41 +00:00
|
|
|
return OK;
|
2017-03-05 15:44:50 +00:00
|
|
|
ok = execute("kde-open", args, false);
|
2014-12-02 17:02:41 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
bool OS_X11::_check_internal_feature_support(const String &p_feature) {
|
|
|
|
|
|
|
|
return p_feature == "pc" || p_feature == "s3tc";
|
|
|
|
}
|
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
String OS_X11::get_config_path() const {
|
|
|
|
|
|
|
|
if (has_environment("XDG_CONFIG_HOME")) {
|
|
|
|
return get_environment("XDG_CONFIG_HOME");
|
|
|
|
} else if (has_environment("HOME")) {
|
|
|
|
return get_environment("HOME").plus_file(".config");
|
|
|
|
} else {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_X11::get_data_path() const {
|
|
|
|
|
|
|
|
if (has_environment("XDG_DATA_HOME")) {
|
|
|
|
return get_environment("XDG_DATA_HOME");
|
|
|
|
} else if (has_environment("HOME")) {
|
|
|
|
return get_environment("HOME").plus_file(".local/share");
|
|
|
|
} else {
|
|
|
|
return get_config_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_X11::get_cache_path() const {
|
|
|
|
|
|
|
|
if (has_environment("XDG_CACHE_HOME")) {
|
|
|
|
return get_environment("XDG_CACHE_HOME");
|
|
|
|
} else if (has_environment("HOME")) {
|
|
|
|
return get_environment("HOME").plus_file(".cache");
|
|
|
|
} else {
|
|
|
|
return get_config_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 17:02:41 +00:00
|
|
|
String OS_X11::get_system_dir(SystemDir p_dir) const {
|
|
|
|
|
|
|
|
String xdgparam;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_dir) {
|
2014-12-02 17:02:41 +00:00
|
|
|
case SYSTEM_DIR_DESKTOP: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "DESKTOP";
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DCIM: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "PICTURES";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOCUMENTS: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "DOCUMENTS";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOWNLOADS: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "DOWNLOAD";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MOVIES: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "VIDEOS";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MUSIC: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "MUSIC";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_PICTURES: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "PICTURES";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_RINGTONES: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xdgparam = "MUSIC";
|
2014-12-02 17:02:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
String pipe;
|
|
|
|
List<String> arg;
|
|
|
|
arg.push_back(xdgparam);
|
2017-10-13 14:45:24 +00:00
|
|
|
Error err = const_cast<OS_X11 *>(this)->execute("xdg-user-dir", arg, true, NULL, &pipe);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (err != OK)
|
2014-12-02 17:02:41 +00:00
|
|
|
return ".";
|
|
|
|
return pipe.strip_edges();
|
2014-04-18 14:43:54 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_X11::move_window_to_foreground() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
XRaiseWindow(x11_display, x11_window);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_X11::set_cursor_shape(CursorShape p_shape) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_shape == current_cursor)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_VISIBLE) {
|
|
|
|
if (cursors[p_shape] != None)
|
|
|
|
XDefineCursor(x11_display, x11_window, cursors[p_shape]);
|
|
|
|
else if (cursors[CURSOR_ARROW] != None)
|
|
|
|
XDefineCursor(x11_display, x11_window, cursors[CURSOR_ARROW]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
current_cursor = p_shape;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 10:50:11 +00:00
|
|
|
void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
|
|
|
if (p_cursor.is_valid()) {
|
|
|
|
Ref<Texture> texture = p_cursor;
|
|
|
|
Ref<Image> image = texture->get_data();
|
|
|
|
|
|
|
|
ERR_FAIL_COND(texture->get_width() != 32 || texture->get_height() != 32);
|
|
|
|
|
|
|
|
// Create the cursor structure
|
|
|
|
XcursorImage *cursor_image = XcursorImageCreate(texture->get_width(), texture->get_height());
|
|
|
|
XcursorUInt image_size = 32 * 32;
|
|
|
|
XcursorDim size = sizeof(XcursorPixel) * image_size;
|
|
|
|
|
|
|
|
cursor_image->version = 1;
|
|
|
|
cursor_image->size = size;
|
|
|
|
cursor_image->xhot = p_hotspot.x;
|
|
|
|
cursor_image->yhot = p_hotspot.y;
|
|
|
|
|
|
|
|
// allocate memory to contain the whole file
|
|
|
|
cursor_image->pixels = (XcursorPixel *)malloc(size);
|
|
|
|
|
|
|
|
image->lock();
|
|
|
|
|
|
|
|
for (XcursorPixel index = 0; index < image_size; index++) {
|
|
|
|
int column_index = floor(index / 32);
|
|
|
|
int row_index = index % 32;
|
|
|
|
|
|
|
|
*(cursor_image->pixels + index) = image->get_pixel(row_index, column_index).to_argb32();
|
|
|
|
}
|
|
|
|
|
|
|
|
image->unlock();
|
|
|
|
|
|
|
|
ERR_FAIL_COND(cursor_image->pixels == NULL);
|
|
|
|
|
|
|
|
// Save it for a further usage
|
|
|
|
cursors[p_shape] = XcursorImageLoadCursor(x11_display, cursor_image);
|
|
|
|
|
|
|
|
if (p_shape == CURSOR_ARROW) {
|
|
|
|
XDefineCursor(x11_display, x11_window, cursors[p_shape]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_X11::release_rendering_thread() {
|
|
|
|
|
|
|
|
context_gl->release_current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_X11::make_rendering_thread() {
|
|
|
|
|
|
|
|
context_gl->make_current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_X11::swap_buffers() {
|
|
|
|
|
|
|
|
context_gl->swap_buffers();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_X11::alert(const String &p_alert, const String &p_title) {
|
2015-09-21 12:39:46 +00:00
|
|
|
|
|
|
|
List<String> args;
|
|
|
|
args.push_back("-center");
|
|
|
|
args.push_back("-title");
|
|
|
|
args.push_back(p_title);
|
|
|
|
args.push_back(p_alert);
|
|
|
|
|
2017-10-13 14:45:24 +00:00
|
|
|
execute("xmessage", args, true);
|
2015-09-21 12:39:46 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
void OS_X11::set_icon(const Ref<Image> &p_icon) {
|
2015-10-25 17:36:27 +00:00
|
|
|
Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
|
2015-10-25 14:15:56 +00:00
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
if (p_icon.is_valid()) {
|
|
|
|
Ref<Image> img = p_icon->duplicate();
|
|
|
|
img->convert(Image::FORMAT_RGBA8);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
int w = img->get_width();
|
|
|
|
int h = img->get_height();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-02-14 11:42:47 +00:00
|
|
|
// We're using long to have wordsize (32Bit build -> 32 Bits, 64 Bit build -> 64 Bits
|
|
|
|
Vector<long> pd;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pd.resize(2 + w * h);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pd[0] = w;
|
|
|
|
pd[1] = h;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
PoolVector<uint8_t>::Read r = img->get_data().read();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
long *wr = &pd[2];
|
|
|
|
uint8_t const *pr = r.ptr();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < w * h; i++) {
|
|
|
|
long v = 0;
|
2014-02-14 10:31:41 +00:00
|
|
|
// A R G B
|
2017-03-05 15:44:50 +00:00
|
|
|
v |= pr[3] << 24 | pr[0] << 16 | pr[1] << 8 | pr[2];
|
|
|
|
*wr++ = v;
|
2014-02-14 10:31:41 +00:00
|
|
|
pr += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)pd.ptr(), pd.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
XDeleteProperty(x11_display, x11_window, net_wm_icon);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
XFlush(x11_display);
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
void OS_X11::force_process_input() {
|
|
|
|
process_xevents(); // get rid of pending events
|
|
|
|
#ifdef JOYDEV_ENABLED
|
|
|
|
joypad->process_joypads();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_X11::run() {
|
|
|
|
|
|
|
|
force_quit = false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!main_loop)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
main_loop->init();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//uint64_t last_ticks=get_ticks_usec();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//int frames=0;
|
|
|
|
//uint64_t frame=0;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
while (!force_quit) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
process_xevents(); // get rid of pending events
|
2015-12-21 21:39:03 +00:00
|
|
|
#ifdef JOYDEV_ENABLED
|
2017-03-26 13:59:13 +00:00
|
|
|
joypad->process_joypads();
|
2015-12-18 05:12:53 +00:00
|
|
|
#endif
|
2017-03-05 15:44:50 +00:00
|
|
|
if (Main::iteration() == true)
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
main_loop->finish();
|
|
|
|
}
|
|
|
|
|
2016-01-07 23:40:41 +00:00
|
|
|
bool OS_X11::is_joy_known(int p_device) {
|
|
|
|
return input->is_joy_mapped(p_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_X11::get_joy_guid(int p_device) const {
|
|
|
|
return input->get_joy_guid_remapped(p_device);
|
|
|
|
}
|
|
|
|
|
2017-12-16 20:09:25 +00:00
|
|
|
void OS_X11::_set_use_vsync(bool p_enable) {
|
2016-06-05 22:14:33 +00:00
|
|
|
if (context_gl)
|
|
|
|
return context_gl->set_use_vsync(p_enable);
|
|
|
|
}
|
2017-12-16 20:09:25 +00:00
|
|
|
/*
|
2016-11-08 14:06:57 +00:00
|
|
|
bool OS_X11::is_vsync_enabled() const {
|
2016-06-05 22:14:33 +00:00
|
|
|
|
|
|
|
if (context_gl)
|
|
|
|
return context_gl->is_using_vsync();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-16 20:09:25 +00:00
|
|
|
*/
|
2016-01-27 20:53:37 +00:00
|
|
|
void OS_X11::set_context(int p_context) {
|
|
|
|
|
2017-08-21 19:15:36 +00:00
|
|
|
XClassHint *classHint = XAllocClassHint();
|
2016-01-27 20:53:37 +00:00
|
|
|
if (classHint) {
|
|
|
|
|
|
|
|
if (p_context == CONTEXT_EDITOR)
|
|
|
|
classHint->res_name = (char *)"Godot_Editor";
|
|
|
|
if (p_context == CONTEXT_PROJECTMAN)
|
|
|
|
classHint->res_name = (char *)"Godot_ProjectList";
|
|
|
|
classHint->res_class = (char *)"Godot";
|
|
|
|
XSetClassHint(x11_display, x11_window, classHint);
|
|
|
|
XFree(classHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 19:09:06 +00:00
|
|
|
OS::PowerState OS_X11::get_power_state() {
|
2016-07-23 11:15:55 +00:00
|
|
|
return power_manager->get_power_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_X11::get_power_seconds_left() {
|
|
|
|
return power_manager->get_power_seconds_left();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_X11::get_power_percent_left() {
|
|
|
|
return power_manager->get_power_percent_left();
|
|
|
|
}
|
|
|
|
|
2017-09-08 01:01:49 +00:00
|
|
|
void OS_X11::disable_crash_handler() {
|
|
|
|
crash_handler.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_X11::is_disable_crash_handler() const {
|
|
|
|
return crash_handler.is_disabled();
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:15:11 +00:00
|
|
|
static String get_mountpoint(const String &p_path) {
|
|
|
|
struct stat s;
|
|
|
|
if (stat(p_path.utf8().get_data(), &s)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:50:41 +00:00
|
|
|
#ifdef HAVE_MNTENT
|
2017-09-25 13:15:11 +00:00
|
|
|
dev_t dev = s.st_dev;
|
|
|
|
FILE *fd = setmntent("/proc/mounts", "r");
|
|
|
|
if (!fd) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mntent mnt;
|
|
|
|
char buf[1024];
|
|
|
|
size_t buflen = 1024;
|
|
|
|
while (getmntent_r(fd, &mnt, buf, buflen)) {
|
|
|
|
if (!stat(mnt.mnt_dir, &s) && s.st_dev == dev) {
|
|
|
|
endmntent(fd);
|
|
|
|
return String(mnt.mnt_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
endmntent(fd);
|
2017-10-17 16:50:41 +00:00
|
|
|
#endif
|
2017-09-25 13:15:11 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
Error OS_X11::move_to_trash(const String &p_path) {
|
2018-02-13 23:04:11 +00:00
|
|
|
String trash_can = "";
|
2017-09-25 13:15:11 +00:00
|
|
|
String mnt = get_mountpoint(p_path);
|
|
|
|
|
2018-02-13 23:04:11 +00:00
|
|
|
// If there is a directory "[Mountpoint]/.Trash-[UID]/files", use it as the trash can.
|
2017-09-25 13:15:11 +00:00
|
|
|
if (mnt != "") {
|
|
|
|
String path(mnt + "/.Trash-" + itos(getuid()) + "/files");
|
|
|
|
struct stat s;
|
|
|
|
if (!stat(path.utf8().get_data(), &s)) {
|
2018-02-13 23:04:11 +00:00
|
|
|
trash_can = path;
|
2017-09-25 13:15:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:04:11 +00:00
|
|
|
// Otherwise, if ${XDG_DATA_HOME} is defined, use "${XDG_DATA_HOME}/Trash/files" as the trash can.
|
|
|
|
if (trash_can == "") {
|
2017-09-25 13:15:11 +00:00
|
|
|
char *dhome = getenv("XDG_DATA_HOME");
|
|
|
|
if (dhome) {
|
2018-02-13 23:04:11 +00:00
|
|
|
trash_can = String(dhome) + "/Trash/files";
|
2017-09-25 13:15:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:04:11 +00:00
|
|
|
// Otherwise, if ${HOME} is defined, use "${HOME}/.local/share/Trash/files" as the trash can.
|
|
|
|
if (trash_can == "") {
|
2017-09-25 13:15:11 +00:00
|
|
|
char *home = getenv("HOME");
|
|
|
|
if (home) {
|
2018-02-13 23:04:11 +00:00
|
|
|
trash_can = String(home) + "/.local/share/Trash/files";
|
2017-09-25 13:15:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:04:11 +00:00
|
|
|
// Issue an error if none of the previous locations is appropriate for the trash can.
|
|
|
|
if (trash_can == "") {
|
|
|
|
ERR_PRINTS("move_to_trash: Could not determine the trash can location");
|
2017-09-25 13:15:11 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:04:11 +00:00
|
|
|
// Create needed directories for decided trash can location.
|
|
|
|
DirAccess *dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
Error err = dir_access->make_dir_recursive(trash_can);
|
|
|
|
memdelete(dir_access);
|
|
|
|
|
|
|
|
// Issue an error if trash can is not created proprely.
|
|
|
|
if (err != OK) {
|
|
|
|
ERR_PRINTS("move_to_trash: Could not create the trash can \"" + trash_can + "\"");
|
|
|
|
return err;
|
2017-09-25 13:15:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 23:04:11 +00:00
|
|
|
// The trash can is successfully created, now move the given resource to it.
|
|
|
|
// Do not use DirAccess:rename() because it can't move files across multiple mountpoints.
|
|
|
|
List<String> mv_args;
|
|
|
|
mv_args.push_back(p_path);
|
|
|
|
mv_args.push_back(trash_can);
|
|
|
|
int retval;
|
|
|
|
err = execute("mv", mv_args, true, NULL, NULL, &retval);
|
|
|
|
|
|
|
|
// Issue an error if "mv" failed to move the given resource to the trash can.
|
|
|
|
if (err != OK || retval != 0) {
|
|
|
|
ERR_PRINTS("move_to_trash: Could not move the resource \"" + p_path + "\" to the trash can \"" + trash_can + "\"");
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2017-09-25 13:15:11 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 14:40:42 +00:00
|
|
|
OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const {
|
|
|
|
|
|
|
|
XkbDescRec *xkbdesc = XkbAllocKeyboard();
|
|
|
|
ERR_FAIL_COND_V(!xkbdesc, LATIN_KEYBOARD_QWERTY);
|
|
|
|
|
|
|
|
XkbGetNames(x11_display, XkbSymbolsNameMask, xkbdesc);
|
|
|
|
ERR_FAIL_COND_V(!xkbdesc->names, LATIN_KEYBOARD_QWERTY);
|
|
|
|
ERR_FAIL_COND_V(!xkbdesc->names->symbols, LATIN_KEYBOARD_QWERTY);
|
|
|
|
|
|
|
|
char *layout = XGetAtomName(x11_display, xkbdesc->names->symbols);
|
|
|
|
ERR_FAIL_COND_V(!layout, LATIN_KEYBOARD_QWERTY);
|
|
|
|
|
|
|
|
Vector<String> info = String(layout).split("+");
|
|
|
|
ERR_FAIL_INDEX_V(1, info.size(), LATIN_KEYBOARD_QWERTY);
|
|
|
|
|
2017-10-24 17:32:40 +00:00
|
|
|
if (info[1].find("colemak") != -1) {
|
2017-10-30 14:40:42 +00:00
|
|
|
return LATIN_KEYBOARD_COLEMAK;
|
2017-10-24 17:32:40 +00:00
|
|
|
} else if (info[1].find("qwertz") != -1) {
|
2017-10-30 14:40:42 +00:00
|
|
|
return LATIN_KEYBOARD_QWERTZ;
|
|
|
|
} else if (info[1].find("azerty") != -1) {
|
|
|
|
return LATIN_KEYBOARD_AZERTY;
|
|
|
|
} else if (info[1].find("qzerty") != -1) {
|
|
|
|
return LATIN_KEYBOARD_QZERTY;
|
|
|
|
} else if (info[1].find("dvorak") != -1) {
|
|
|
|
return LATIN_KEYBOARD_DVORAK;
|
|
|
|
} else if (info[1].find("neo") != -1) {
|
|
|
|
return LATIN_KEYBOARD_NEO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LATIN_KEYBOARD_QWERTY;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_X11::OS_X11() {
|
|
|
|
|
2014-12-19 12:44:34 +00:00
|
|
|
#ifdef PULSEAUDIO_ENABLED
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriverManager::add_driver(&driver_pulseaudio);
|
2014-12-19 12:44:34 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
#ifdef ALSA_ENABLED
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriverManager::add_driver(&driver_alsa);
|
2014-12-21 14:42:44 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
minimized = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
xim_style = 0L;
|
|
|
|
mouse_mode = MOUSE_MODE_VISIBLE;
|
2016-07-21 19:11:34 +00:00
|
|
|
}
|