summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /platform/x11
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/context_gl_x11.cpp117
-rw-r--r--platform/x11/context_gl_x11.h13
-rw-r--r--platform/x11/export/export.cpp9
-rw-r--r--platform/x11/godot_x11.cpp10
-rw-r--r--platform/x11/joypad_linux.cpp156
-rw-r--r--platform/x11/joypad_linux.h11
-rw-r--r--platform/x11/key_mapping_x11.cpp336
-rw-r--r--platform/x11/key_mapping_x11.h7
-rw-r--r--platform/x11/os_x11.cpp1378
-rw-r--r--platform/x11/os_x11.h93
-rw-r--r--platform/x11/power_x11.cpp177
-rw-r--r--platform/x11/power_x11.h11
12 files changed, 1112 insertions, 1206 deletions
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp
index caa5e4fc89..41d110a1e1 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -31,17 +31,17 @@
#ifdef X11_ENABLED
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
#include <stdio.h>
-#include <unistd.h>
#include <stdlib.h>
+#include <unistd.h>
#define GLX_GLXEXT_PROTOTYPES
#include <GL/glx.h>
#include <GL/glxext.h>
-#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
-#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
+#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
+#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
-typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
+typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display *, GLXFBConfig, GLXContext, Bool, const int *);
struct ContextGL_X11_Private {
@@ -60,7 +60,7 @@ void ContextGL_X11::make_current() {
void ContextGL_X11::swap_buffers() {
- glXSwapBuffers(x11_display,x11_window);
+ glXSwapBuffers(x11_display, x11_window);
}
/*
@@ -77,38 +77,35 @@ static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) {
}*/
static bool ctxErrorOccurred = false;
-static int ctxErrorHandler( Display *dpy, XErrorEvent *ev )
-{
- ctxErrorOccurred = true;
- return 0;
+static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
+ ctxErrorOccurred = true;
+ return 0;
}
Error ContextGL_X11::initialize() {
-
GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = NULL;
//const char *extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display));
- glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
-
- ERR_FAIL_COND_V( !glXCreateContextAttribsARB, ERR_UNCONFIGURED );
+ glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte *)"glXCreateContextAttribsARB");
+ ERR_FAIL_COND_V(!glXCreateContextAttribsARB, ERR_UNCONFIGURED);
static int visual_attribs[] = {
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
- GLX_DOUBLEBUFFER, true,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 24,
- None
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+ GLX_DOUBLEBUFFER, true,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DEPTH_SIZE, 24,
+ None
};
int fbcount;
GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount);
- ERR_FAIL_COND_V(!fbc,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED);
XVisualInfo *vi = glXGetVisualFromFBConfig(x11_display, fbc[0]);
@@ -127,15 +124,13 @@ Error ContextGL_X11::initialize() {
x11_window = atol(windowid);
} else {
*/
- x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa);
- ERR_FAIL_COND_V(!x11_window,ERR_UNCONFIGURED);
- XMapWindow(x11_display, x11_window);
- //};
-
-
- int (*oldHandler)(Display*, XErrorEvent*) =
- XSetErrorHandler(&ctxErrorHandler);
+ x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa);
+ ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED);
+ XMapWindow(x11_display, x11_window);
+ //};
+ int (*oldHandler)(Display *, XErrorEvent *) =
+ XSetErrorHandler(&ctxErrorHandler);
if (!opengl_3_context) {
//oldstyle context:
@@ -144,17 +139,17 @@ Error ContextGL_X11::initialize() {
static int context_attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
- GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB/*|GLX_CONTEXT_DEBUG_BIT_ARB*/,
+ GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*|GLX_CONTEXT_DEBUG_BIT_ARB*/,
None
};
p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs);
ERR_EXPLAIN("Could not obtain an OpenGL 3.3 context!");
- ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context, ERR_UNCONFIGURED);
}
- XSync( x11_display, False );
- XSetErrorHandler( oldHandler );
+ XSync(x11_display, False);
+ XSetErrorHandler(oldHandler);
print_line("ALL IS GOOD");
@@ -168,8 +163,8 @@ Error ContextGL_X11::initialize() {
*/
//glXMakeCurrent(x11_display, None, NULL);
- XFree( vi );
- XFree( fbc );
+ XFree(vi);
+ XFree(fbc);
return OK;
}
@@ -177,14 +172,14 @@ Error ContextGL_X11::initialize() {
int ContextGL_X11::get_window_width() {
XWindowAttributes xwa;
- XGetWindowAttributes(x11_display,x11_window,&xwa);
+ XGetWindowAttributes(x11_display, x11_window, &xwa);
return xwa.width;
}
int ContextGL_X11::get_window_height() {
XWindowAttributes xwa;
- XGetWindowAttributes(x11_display,x11_window,&xwa);
+ XGetWindowAttributes(x11_display, x11_window, &xwa);
return xwa.height;
}
@@ -199,24 +194,22 @@ void ContextGL_X11::set_use_vsync(bool p_use) {
setup = true;
String extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display));
if (extensions.find("GLX_EXT_swap_control") != -1)
- glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
+ glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalEXT");
if (extensions.find("GLX_MESA_swap_control") != -1)
- glXSwapIntervalMESA = (PFNGLXSWAPINTERVALSGIPROC) glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalMESA");
+ glXSwapIntervalMESA = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA");
if (extensions.find("GLX_SGI_swap_control") != -1)
- glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalSGI");
+ glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalSGI");
}
- int val = p_use ? 1:0;
+ int val = p_use ? 1 : 0;
if (glXSwapIntervalMESA) {
glXSwapIntervalMESA(val);
- }
- else if (glXSwapIntervalSGI) {
+ } else if (glXSwapIntervalSGI) {
glXSwapIntervalSGI(val);
- }
- else if (glXSwapIntervalEXT) {
+ } else if (glXSwapIntervalEXT) {
GLXDrawable drawable = glXGetCurrentDrawable();
glXSwapIntervalEXT(x11_display, drawable, val);
- }
- else return;
+ } else
+ return;
use_vsync = p_use;
}
bool ContextGL_X11::is_using_vsync() const {
@@ -224,30 +217,28 @@ bool ContextGL_X11::is_using_vsync() const {
return use_vsync;
}
+ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, bool p_opengl_3_context)
+ : x11_window(p_x11_window) {
-ContextGL_X11::ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,const OS::VideoMode& p_default_video_mode,bool p_opengl_3_context) : x11_window(p_x11_window) {
+ default_video_mode = p_default_video_mode;
+ x11_display = p_x11_display;
- default_video_mode=p_default_video_mode;
- x11_display=p_x11_display;
+ opengl_3_context = p_opengl_3_context;
- opengl_3_context=p_opengl_3_context;
-
- double_buffer=false;
- direct_render=false;
- glx_minor=glx_major=0;
- p = memnew( ContextGL_X11_Private );
- p->glx_context=0;
- use_vsync=false;
+ double_buffer = false;
+ direct_render = false;
+ glx_minor = glx_major = 0;
+ p = memnew(ContextGL_X11_Private);
+ p->glx_context = 0;
+ use_vsync = false;
}
-
ContextGL_X11::~ContextGL_X11() {
release_current();
- glXDestroyContext( x11_display, p->glx_context );
+ glXDestroyContext(x11_display, p->glx_context);
- memdelete( p );
+ memdelete(p);
}
-
#endif
#endif
diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h
index efea700224..be0f4c822c 100644
--- a/platform/x11/context_gl_x11.h
+++ b/platform/x11/context_gl_x11.h
@@ -36,10 +36,8 @@
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
-
-
-#include "os/os.h"
#include "drivers/gl_context/context_gl.h"
+#include "os/os.h"
#include <X11/Xlib.h>
struct ContextGL_X11_Private;
@@ -50,14 +48,14 @@ class ContextGL_X11 : public ContextGL {
OS::VideoMode default_video_mode;
//::Colormap x11_colormap;
::Display *x11_display;
- ::Window& x11_window;
+ ::Window &x11_window;
bool double_buffer;
bool direct_render;
- int glx_minor,glx_major;
+ int glx_minor, glx_major;
bool opengl_3_context;
bool use_vsync;
-public:
+public:
virtual void release_current();
virtual void make_current();
virtual void swap_buffers();
@@ -69,9 +67,8 @@ public:
virtual void set_use_vsync(bool p_use);
virtual bool is_using_vsync() const;
- ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,const OS::VideoMode& p_default_video_mode,bool p_opengl_3_context);
+ ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, bool p_opengl_3_context);
~ContextGL_X11();
-
};
#endif
diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp
index c40b8f3c1f..2659c771ca 100644
--- a/platform/x11/export/export.cpp
+++ b/platform/x11/export/export.cpp
@@ -27,12 +27,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "export.h"
-#include "platform/x11/logo.h"
#include "editor/editor_export.h"
+#include "platform/x11/logo.h"
#include "scene/resources/texture.h"
-
-
void register_x11_exporter() {
Ref<EditorExportPlatformPC> platform;
@@ -48,7 +46,7 @@ void register_x11_exporter() {
EditorExport::get_singleton()->add_export_platform(platform);
- #if 0
+#if 0
Image img(_x11_logo);
Ref<ImageTexture> logo = memnew( ImageTexture );
logo->create_from_image(img);
@@ -65,6 +63,5 @@ void register_x11_exporter() {
EditorImportExport::get_singleton()->add_export_platform(exporter);
}
- #endif
+#endif
}
-
diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp
index adb919c2f1..078baf76ee 100644
--- a/platform/x11/godot_x11.cpp
+++ b/platform/x11/godot_x11.cpp
@@ -26,22 +26,22 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
+#include <unistd.h>
#include "main/main.h"
#include "os_x11.h"
-int main(int argc, char* argv[]) {
+int main(int argc, char *argv[]) {
OS_X11 os;
- char *cwd = (char*)malloc(PATH_MAX);
+ char *cwd = (char *)malloc(PATH_MAX);
getcwd(cwd, PATH_MAX);
- Error err = Main::setup(argv[0],argc-1,&argv[1]);
- if (err!=OK)
+ Error err = Main::setup(argv[0], argc - 1, &argv[1]);
+ if (err != OK)
return 255;
if (Main::start())
diff --git a/platform/x11/joypad_linux.cpp b/platform/x11/joypad_linux.cpp
index bdbd2912a6..62ece58f58 100644
--- a/platform/x11/joypad_linux.cpp
+++ b/platform/x11/joypad_linux.cpp
@@ -31,21 +31,21 @@
#include "joypad_linux.h"
+#include <errno.h>
+#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
#ifdef UDEV_ENABLED
#include <libudev.h>
#endif
-#define LONG_BITS (sizeof(long) * 8)
-#define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0)
-#define NBITS(x) ((((x)-1)/LONG_BITS)+1)
+#define LONG_BITS (sizeof(long) * 8)
+#define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0)
+#define NBITS(x) ((((x)-1) / LONG_BITS) + 1)
#ifdef UDEV_ENABLED
-static const char* ignore_str = "/dev/input/js";
+static const char *ignore_str = "/dev/input/js";
#endif
JoypadLinux::Joypad::Joypad() {
@@ -67,20 +67,19 @@ JoypadLinux::Joypad::~Joypad() {
}
void JoypadLinux::Joypad::reset() {
- dpad = 0;
- fd = -1;
+ dpad = 0;
+ fd = -1;
InputDefault::JoyAxis jx;
jx.min = -1;
jx.value = 0.0f;
- for (int i=0; i < MAX_ABS; i++) {
+ for (int i = 0; i < MAX_ABS; i++) {
abs_map[i] = -1;
curr_axis[i] = jx;
}
}
-JoypadLinux::JoypadLinux(InputDefault *in)
-{
+JoypadLinux::JoypadLinux(InputDefault *in) {
exit_udev = false;
input = in;
joy_mutex = Mutex::create();
@@ -98,7 +97,7 @@ JoypadLinux::~JoypadLinux() {
void JoypadLinux::joy_thread_func(void *p_user) {
if (p_user) {
- JoypadLinux* joy = (JoypadLinux*) p_user;
+ JoypadLinux *joy = (JoypadLinux *)p_user;
joy->run_joypad_thread();
}
return;
@@ -124,16 +123,16 @@ void JoypadLinux::enumerate_joypads(udev *p_udev) {
udev_device *dev;
enumerate = udev_enumerate_new(p_udev);
- udev_enumerate_add_match_subsystem(enumerate,"input");
+ udev_enumerate_add_match_subsystem(enumerate, "input");
udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYPAD", "1");
udev_enumerate_scan_devices(enumerate);
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices) {
- const char* path = udev_list_entry_get_name(dev_list_entry);
+ const char *path = udev_list_entry_get_name(dev_list_entry);
dev = udev_device_new_from_syspath(p_udev, path);
- const char* devnode = udev_device_get_devnode(dev);
+ const char *devnode = udev_device_get_devnode(dev);
if (devnode) {
@@ -168,7 +167,7 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
tv.tv_sec = 0;
tv.tv_usec = 0;
- ret = select(fd+1, &fds, NULL, NULL, &tv);
+ ret = select(fd + 1, &fds, NULL, NULL, &tv);
/* Check if our file descriptor has received data. */
if (ret > 0 && FD_ISSET(fd, &fds)) {
@@ -180,7 +179,7 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
joy_mutex->lock();
String action = udev_device_get_action(dev);
- const char* devnode = udev_device_get_devnode(dev);
+ const char *devnode = udev_device_get_devnode(dev);
if (devnode) {
String devnode_str = devnode;
@@ -232,13 +231,13 @@ int JoypadLinux::get_joy_from_path(String p_path) const {
void JoypadLinux::close_joypad(int p_id) {
if (p_id == -1) {
- for (int i=0; i<JOYPADS_MAX; i++) {
+ for (int i = 0; i < JOYPADS_MAX; i++) {
close_joypad(i);
};
return;
- }
- else if (p_id < 0) return;
+ } else if (p_id < 0)
+ return;
Joypad &joy = joypads[p_id];
@@ -253,11 +252,11 @@ void JoypadLinux::close_joypad(int p_id) {
static String _hex_str(uint8_t p_byte) {
- static const char* dict = "0123456789abcdef";
+ static const char *dict = "0123456789abcdef";
char ret[3];
ret[2] = 0;
- ret[0] = dict[p_byte>>4];
+ ret[0] = dict[p_byte >> 4];
ret[1] = dict[p_byte & 0xF];
return ret;
@@ -265,7 +264,7 @@ static String _hex_str(uint8_t p_byte) {
void JoypadLinux::setup_joypad_properties(int p_id) {
- Joypad* joy = &joypads[p_id];
+ Joypad *joy = &joypads[p_id];
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
@@ -274,7 +273,7 @@ void JoypadLinux::setup_joypad_properties(int p_id) {
int num_axes = 0;
if ((ioctl(joy->fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
- (ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
+ (ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
return;
}
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
@@ -332,8 +331,8 @@ void JoypadLinux::open_joypad(const char *p_path) {
attached_devices.push_back(String(p_path));
if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
- (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
- (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
+ (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
+ (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
close(fd);
return;
}
@@ -341,10 +340,10 @@ void JoypadLinux::open_joypad(const char *p_path) {
//check if the device supports basic gamepad events, prevents certain keyboards from
//being detected as joypads
if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
- (test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit) || test_bit(ABS_HAT0X, absbit) ||
- test_bit(ABS_GAS, absbit) || test_bit(ABS_RUDDER, absbit)) &&
- (test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit) ||
- test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_1, keybit)))) {
+ (test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit) || test_bit(ABS_HAT0X, absbit) ||
+ test_bit(ABS_GAS, absbit) || test_bit(ABS_RUDDER, absbit)) &&
+ (test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit) ||
+ test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_1, keybit)))) {
close(fd);
return;
}
@@ -375,13 +374,12 @@ void JoypadLinux::open_joypad(const char *p_path) {
uint16_t product = __bswap_16(inpid.product);
uint16_t version = __bswap_16(inpid.version);
- sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor,0,product,0,version,0);
+ sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor, 0, product, 0, version, 0);
input->joy_connection_changed(joy_num, true, name, uid);
- }
- else {
+ } else {
String uidname = uid;
int uidlen = MIN(name.length(), 11);
- for (int i=0; i<uidlen; i++) {
+ for (int i = 0; i < uidlen; i++) {
uidname = uidname + _hex_str(name[i]);
}
@@ -391,9 +389,8 @@ void JoypadLinux::open_joypad(const char *p_path) {
}
}
-void JoypadLinux::joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp)
-{
- Joypad& joy = joypads[p_id];
+void JoypadLinux::joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) {
+ Joypad &joy = joypads[p_id];
if (!joy.force_feedback || joy.fd == -1 || p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
return;
}
@@ -417,15 +414,14 @@ void JoypadLinux::joypad_vibration_start(int p_id, float p_weak_magnitude, float
play.type = EV_FF;
play.code = effect.id;
play.value = 1;
- write(joy.fd, (const void*)&play, sizeof(play));
+ write(joy.fd, (const void *)&play, sizeof(play));
joy.ff_effect_id = effect.id;
joy.ff_effect_timestamp = p_timestamp;
}
-void JoypadLinux::joypad_vibration_stop(int p_id, uint64_t p_timestamp)
-{
- Joypad& joy = joypads[p_id];
+void JoypadLinux::joypad_vibration_stop(int p_id, uint64_t p_timestamp) {
+ Joypad &joy = joypads[p_id];
if (!joy.force_feedback || joy.fd == -1 || joy.ff_effect_id == -1) {
return;
}
@@ -447,13 +443,13 @@ InputDefault::JoyAxis JoypadLinux::axis_correct(const input_absinfo *p_abs, int
if (min < 0) {
jx.min = -1;
if (p_value < 0) {
- jx.value = (float) -p_value / min;
+ jx.value = (float)-p_value / min;
}
- jx.value = (float) p_value / max;
+ jx.value = (float)p_value / max;
}
if (min == 0) {
jx.min = 0;
- jx.value = 0.0f + (float) p_value / max;
+ jx.value = 0.0f + (float)p_value / max;
}
return jx;
}
@@ -463,12 +459,12 @@ uint32_t JoypadLinux::process_joypads(uint32_t p_event_id) {
if (joy_mutex->try_lock() != OK) {
return p_event_id;
}
- for (int i=0; i<JOYPADS_MAX; i++) {
+ for (int i = 0; i < JOYPADS_MAX; i++) {
if (joypads[i].fd == -1) continue;
input_event events[32];
- Joypad* joy = &joypads[i];
+ Joypad *joy = &joypads[i];
int len;
@@ -480,45 +476,49 @@ uint32_t JoypadLinux::process_joypads(uint32_t p_event_id) {
// ev may be tainted and out of MAX_KEY range, which will cause
// joy->key_map[ev.code] to crash
- if( ev.code < 0 || ev.code >= MAX_KEY )
+ if (ev.code < 0 || ev.code >= MAX_KEY)
return p_event_id;
switch (ev.type) {
- case EV_KEY:
- p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value);
- break;
-
- case EV_ABS:
-
- switch (ev.code) {
- case ABS_HAT0X:
- if (ev.value != 0) {
- if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_LEFT;
- else joy->dpad |= InputDefault::HAT_MASK_RIGHT;
- }
- else joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT);
-
- p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
+ case EV_KEY:
+ p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value);
break;
- case ABS_HAT0Y:
- if (ev.value != 0) {
- if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_UP;
- else joy->dpad |= InputDefault::HAT_MASK_DOWN;
+ case EV_ABS:
+
+ switch (ev.code) {
+ case ABS_HAT0X:
+ if (ev.value != 0) {
+ if (ev.value < 0)
+ joy->dpad |= InputDefault::HAT_MASK_LEFT;
+ else
+ joy->dpad |= InputDefault::HAT_MASK_RIGHT;
+ } else
+ joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT);
+
+ p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
+ break;
+
+ case ABS_HAT0Y:
+ if (ev.value != 0) {
+ if (ev.value < 0)
+ joy->dpad |= InputDefault::HAT_MASK_UP;
+ else
+ joy->dpad |= InputDefault::HAT_MASK_DOWN;
+ } else
+ joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN);
+
+ p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
+ break;
+
+ default:
+ if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) {
+ InputDefault::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value);
+ joy->curr_axis[joy->abs_map[ev.code]] = value;
+ }
+ break;
}
- else joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN);
-
- p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
break;
-
- default:
- if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) {
- InputDefault::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value);
- joy->curr_axis[joy->abs_map[ev.code]] = value;
- }
- break;
- }
- break;
}
}
}
diff --git a/platform/x11/joypad_linux.h b/platform/x11/joypad_linux.h
index 310f5c1488..f90ca9319a 100644
--- a/platform/x11/joypad_linux.h
+++ b/platform/x11/joypad_linux.h
@@ -33,23 +33,22 @@
#ifdef JOYDEV_ENABLED
#include "main/input_default.h"
-#include "os/thread.h"
#include "os/mutex.h"
+#include "os/thread.h"
struct input_absinfo;
-class JoypadLinux
-{
+class JoypadLinux {
public:
JoypadLinux(InputDefault *in);
~JoypadLinux();
uint32_t process_joypads(uint32_t p_event_id);
-private:
+private:
enum {
JOYPADS_MAX = 16,
MAX_ABS = 63,
- MAX_KEY = 767, // Hack because <linux/input.h> can't be included here
+ MAX_KEY = 767, // Hack because <linux/input.h> can't be included here
};
struct Joypad {
@@ -90,7 +89,7 @@ private:
#endif
void monitor_joypads();
void run_joypad_thread();
- void open_joypad(const char* path);
+ void open_joypad(const char *path);
void joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
void joypad_vibration_stop(int p_id, uint64_t p_timestamp);
diff --git a/platform/x11/key_mapping_x11.cpp b/platform/x11/key_mapping_x11.cpp
index d25fe40c4d..4cfcffede0 100644
--- a/platform/x11/key_mapping_x11.cpp
+++ b/platform/x11/key_mapping_x11.cpp
@@ -28,7 +28,6 @@
/*************************************************************************/
#include "key_mapping_x11.h"
-
/***** SCAN CODE CONVERSION ******/
struct _XTranslatePair {
@@ -37,162 +36,161 @@ struct _XTranslatePair {
unsigned int keycode;
};
-static _XTranslatePair _xkeysym_to_keycode[]={
- // misc keys
+static _XTranslatePair _xkeysym_to_keycode[] = {
+ // misc keys
- { XK_Escape, KEY_ESCAPE },
- { XK_Tab, KEY_TAB },
- { XK_ISO_Left_Tab, KEY_BACKTAB },
- { XK_BackSpace, KEY_BACKSPACE },
- { XK_Return, KEY_RETURN },
- { XK_Insert, KEY_INSERT },
- { XK_Delete, KEY_DELETE },
- { XK_Clear, KEY_DELETE },
- { XK_Pause, KEY_PAUSE },
- { XK_Print, KEY_PRINT },
- { XK_Home, KEY_HOME },
- { XK_End, KEY_END },
- { XK_Left, KEY_LEFT },
- { XK_Up, KEY_UP },
- { XK_Right, KEY_RIGHT },
- { XK_Down, KEY_DOWN },
- { XK_Prior, KEY_PAGEUP },
- { XK_Next, KEY_PAGEDOWN },
- { XK_Shift_L, KEY_SHIFT },
- { XK_Shift_R, KEY_SHIFT },
- { XK_Shift_Lock, KEY_SHIFT },
- { XK_Control_L, KEY_CONTROL },
- { XK_Control_R, KEY_CONTROL },
- { XK_Meta_L, KEY_META },
- { XK_Meta_R, KEY_META },
- { XK_Alt_L, KEY_ALT },
- { XK_Alt_R, KEY_ALT },
- { XK_Caps_Lock, KEY_CAPSLOCK },
- { XK_Num_Lock, KEY_NUMLOCK },
- { XK_Scroll_Lock, KEY_SCROLLLOCK },
- { XK_Super_L, KEY_SUPER_L },
- { XK_Super_R, KEY_SUPER_R },
- { XK_Menu, KEY_MENU },
- { XK_Hyper_L, KEY_HYPER_L },
- { XK_Hyper_R, KEY_HYPER_R },
- { XK_Help, KEY_HELP },
- { XK_KP_Space, KEY_SPACE },
- { XK_KP_Tab, KEY_TAB },
- { XK_KP_Enter, KEY_ENTER },
- { XK_Home, KEY_HOME },
- { XK_Left, KEY_LEFT },
- { XK_Up, KEY_UP },
- { XK_Right, KEY_RIGHT },
- { XK_Down, KEY_DOWN },
- { XK_Prior, KEY_PAGEUP },
- { XK_Next, KEY_PAGEDOWN },
- { XK_End, KEY_END },
- { XK_Begin, KEY_CLEAR },
- { XK_Insert, KEY_INSERT },
- { XK_Delete, KEY_DELETE },
+ { XK_Escape, KEY_ESCAPE },
+ { XK_Tab, KEY_TAB },
+ { XK_ISO_Left_Tab, KEY_BACKTAB },
+ { XK_BackSpace, KEY_BACKSPACE },
+ { XK_Return, KEY_RETURN },
+ { XK_Insert, KEY_INSERT },
+ { XK_Delete, KEY_DELETE },
+ { XK_Clear, KEY_DELETE },
+ { XK_Pause, KEY_PAUSE },
+ { XK_Print, KEY_PRINT },
+ { XK_Home, KEY_HOME },
+ { XK_End, KEY_END },
+ { XK_Left, KEY_LEFT },
+ { XK_Up, KEY_UP },
+ { XK_Right, KEY_RIGHT },
+ { XK_Down, KEY_DOWN },
+ { XK_Prior, KEY_PAGEUP },
+ { XK_Next, KEY_PAGEDOWN },
+ { XK_Shift_L, KEY_SHIFT },
+ { XK_Shift_R, KEY_SHIFT },
+ { XK_Shift_Lock, KEY_SHIFT },
+ { XK_Control_L, KEY_CONTROL },
+ { XK_Control_R, KEY_CONTROL },
+ { XK_Meta_L, KEY_META },
+ { XK_Meta_R, KEY_META },
+ { XK_Alt_L, KEY_ALT },
+ { XK_Alt_R, KEY_ALT },
+ { XK_Caps_Lock, KEY_CAPSLOCK },
+ { XK_Num_Lock, KEY_NUMLOCK },
+ { XK_Scroll_Lock, KEY_SCROLLLOCK },
+ { XK_Super_L, KEY_SUPER_L },
+ { XK_Super_R, KEY_SUPER_R },
+ { XK_Menu, KEY_MENU },
+ { XK_Hyper_L, KEY_HYPER_L },
+ { XK_Hyper_R, KEY_HYPER_R },
+ { XK_Help, KEY_HELP },
+ { XK_KP_Space, KEY_SPACE },
+ { XK_KP_Tab, KEY_TAB },
+ { XK_KP_Enter, KEY_ENTER },
+ { XK_Home, KEY_HOME },
+ { XK_Left, KEY_LEFT },
+ { XK_Up, KEY_UP },
+ { XK_Right, KEY_RIGHT },
+ { XK_Down, KEY_DOWN },
+ { XK_Prior, KEY_PAGEUP },
+ { XK_Next, KEY_PAGEDOWN },
+ { XK_End, KEY_END },
+ { XK_Begin, KEY_CLEAR },
+ { XK_Insert, KEY_INSERT },
+ { XK_Delete, KEY_DELETE },
//{ XK_KP_Equal, KEY_EQUAL },
//{ XK_KP_Separator, KEY_COMMA },
- { XK_KP_Decimal, KEY_KP_PERIOD },
- { XK_KP_Delete, KEY_KP_PERIOD },
- { XK_KP_Enter, KEY_KP_ENTER },
- { XK_KP_Multiply, KEY_KP_MULTIPLY},
- { XK_KP_Divide, KEY_KP_DIVIDE},
- { XK_KP_Subtract, KEY_KP_SUBTRACT},
- { XK_KP_Add, KEY_KP_ADD},
- { XK_KP_0, KEY_KP_0},
- { XK_KP_1, KEY_KP_1},
- { XK_KP_2, KEY_KP_2},
- { XK_KP_3, KEY_KP_3},
- { XK_KP_4, KEY_KP_4},
- { XK_KP_5, KEY_KP_5},
- { XK_KP_6, KEY_KP_6},
- { XK_KP_7, KEY_KP_7},
- { XK_KP_8, KEY_KP_8},
- { XK_KP_9, KEY_KP_9},
+ { XK_KP_Decimal, KEY_KP_PERIOD },
+ { XK_KP_Delete, KEY_KP_PERIOD },
+ { XK_KP_Enter, KEY_KP_ENTER },
+ { XK_KP_Multiply, KEY_KP_MULTIPLY },
+ { XK_KP_Divide, KEY_KP_DIVIDE },
+ { XK_KP_Subtract, KEY_KP_SUBTRACT },
+ { XK_KP_Add, KEY_KP_ADD },
+ { XK_KP_0, KEY_KP_0 },
+ { XK_KP_1, KEY_KP_1 },
+ { XK_KP_2, KEY_KP_2 },
+ { XK_KP_3, KEY_KP_3 },
+ { XK_KP_4, KEY_KP_4 },
+ { XK_KP_5, KEY_KP_5 },
+ { XK_KP_6, KEY_KP_6 },
+ { XK_KP_7, KEY_KP_7 },
+ { XK_KP_8, KEY_KP_8 },
+ { XK_KP_9, KEY_KP_9 },
// same but with numlock
- { XK_KP_Insert, KEY_KP_0},
- { XK_KP_End, KEY_KP_1},
- { XK_KP_Down, KEY_KP_2},
- { XK_KP_Page_Down, KEY_KP_3},
- { XK_KP_Left, KEY_KP_4},
- { XK_KP_Begin, KEY_KP_5},
- { XK_KP_Right, KEY_KP_6},
- { XK_KP_Home, KEY_KP_7},
- { XK_KP_Up, KEY_KP_8},
- { XK_KP_Page_Up, KEY_KP_9},
- { XK_F1, KEY_F1},
- { XK_F2, KEY_F2},
- { XK_F3, KEY_F3},
- { XK_F4, KEY_F4},
- { XK_F5, KEY_F5},
- { XK_F6, KEY_F6},
- { XK_F7, KEY_F7},
- { XK_F8, KEY_F8},
- { XK_F9, KEY_F9},
- { XK_F10, KEY_F10},
- { XK_F11, KEY_F11},
- { XK_F12, KEY_F12},
- { XK_F13, KEY_F13},
- { XK_F14, KEY_F14},
- { XK_F15, KEY_F15},
- { XK_F16, KEY_F16},
+ { XK_KP_Insert, KEY_KP_0 },
+ { XK_KP_End, KEY_KP_1 },
+ { XK_KP_Down, KEY_KP_2 },
+ { XK_KP_Page_Down, KEY_KP_3 },
+ { XK_KP_Left, KEY_KP_4 },
+ { XK_KP_Begin, KEY_KP_5 },
+ { XK_KP_Right, KEY_KP_6 },
+ { XK_KP_Home, KEY_KP_7 },
+ { XK_KP_Up, KEY_KP_8 },
+ { XK_KP_Page_Up, KEY_KP_9 },
+ { XK_F1, KEY_F1 },
+ { XK_F2, KEY_F2 },
+ { XK_F3, KEY_F3 },
+ { XK_F4, KEY_F4 },
+ { XK_F5, KEY_F5 },
+ { XK_F6, KEY_F6 },
+ { XK_F7, KEY_F7 },
+ { XK_F8, KEY_F8 },
+ { XK_F9, KEY_F9 },
+ { XK_F10, KEY_F10 },
+ { XK_F11, KEY_F11 },
+ { XK_F12, KEY_F12 },
+ { XK_F13, KEY_F13 },
+ { XK_F14, KEY_F14 },
+ { XK_F15, KEY_F15 },
+ { XK_F16, KEY_F16 },
- // media keys
- { XF86XK_Back, KEY_BACK },
- { XF86XK_Forward, KEY_FORWARD },
- { XF86XK_Stop, KEY_STOP },
- { XF86XK_Refresh, KEY_REFRESH },
- { XF86XK_Favorites, KEY_FAVORITES },
- { XF86XK_AudioMedia, KEY_LAUNCHMEDIA },
- { XF86XK_OpenURL, KEY_OPENURL },
- { XF86XK_HomePage, KEY_HOMEPAGE },
- { XF86XK_Search, KEY_SEARCH },
- { XF86XK_AudioLowerVolume, KEY_VOLUMEDOWN },
- { XF86XK_AudioMute, KEY_VOLUMEMUTE },
- { XF86XK_AudioRaiseVolume, KEY_VOLUMEUP },
- { XF86XK_AudioPlay, KEY_MEDIAPLAY },
- { XF86XK_AudioStop, KEY_MEDIASTOP },
- { XF86XK_AudioPrev, KEY_MEDIAPREVIOUS },
- { XF86XK_AudioNext, KEY_MEDIANEXT },
- { XF86XK_AudioRecord, KEY_MEDIARECORD },
+ // media keys
+ { XF86XK_Back, KEY_BACK },
+ { XF86XK_Forward, KEY_FORWARD },
+ { XF86XK_Stop, KEY_STOP },
+ { XF86XK_Refresh, KEY_REFRESH },
+ { XF86XK_Favorites, KEY_FAVORITES },
+ { XF86XK_AudioMedia, KEY_LAUNCHMEDIA },
+ { XF86XK_OpenURL, KEY_OPENURL },
+ { XF86XK_HomePage, KEY_HOMEPAGE },
+ { XF86XK_Search, KEY_SEARCH },
+ { XF86XK_AudioLowerVolume, KEY_VOLUMEDOWN },
+ { XF86XK_AudioMute, KEY_VOLUMEMUTE },
+ { XF86XK_AudioRaiseVolume, KEY_VOLUMEUP },
+ { XF86XK_AudioPlay, KEY_MEDIAPLAY },
+ { XF86XK_AudioStop, KEY_MEDIASTOP },
+ { XF86XK_AudioPrev, KEY_MEDIAPREVIOUS },
+ { XF86XK_AudioNext, KEY_MEDIANEXT },
+ { XF86XK_AudioRecord, KEY_MEDIARECORD },
- // launch keys
- { XF86XK_Mail, KEY_LAUNCHMAIL },
- { XF86XK_MyComputer, KEY_LAUNCH0 },
- { XF86XK_Calculator, KEY_LAUNCH1 },
- { XF86XK_Standby, KEY_STANDBY },
+ // launch keys
+ { XF86XK_Mail, KEY_LAUNCHMAIL },
+ { XF86XK_MyComputer, KEY_LAUNCH0 },
+ { XF86XK_Calculator, KEY_LAUNCH1 },
+ { XF86XK_Standby, KEY_STANDBY },
- { XF86XK_Launch0, KEY_LAUNCH2 },
- { XF86XK_Launch1, KEY_LAUNCH3 },
- { XF86XK_Launch2, KEY_LAUNCH4 },
- { XF86XK_Launch3, KEY_LAUNCH5 },
- { XF86XK_Launch4, KEY_LAUNCH6 },
- { XF86XK_Launch5, KEY_LAUNCH7 },
- { XF86XK_Launch6, KEY_LAUNCH8 },
- { XF86XK_Launch7, KEY_LAUNCH9 },
- { XF86XK_Launch8, KEY_LAUNCHA },
- { XF86XK_Launch9, KEY_LAUNCHB },
- { XF86XK_LaunchA, KEY_LAUNCHC },
- { XF86XK_LaunchB, KEY_LAUNCHD },
- { XF86XK_LaunchC, KEY_LAUNCHE },
- { XF86XK_LaunchD, KEY_LAUNCHF },
+ { XF86XK_Launch0, KEY_LAUNCH2 },
+ { XF86XK_Launch1, KEY_LAUNCH3 },
+ { XF86XK_Launch2, KEY_LAUNCH4 },
+ { XF86XK_Launch3, KEY_LAUNCH5 },
+ { XF86XK_Launch4, KEY_LAUNCH6 },
+ { XF86XK_Launch5, KEY_LAUNCH7 },
+ { XF86XK_Launch6, KEY_LAUNCH8 },
+ { XF86XK_Launch7, KEY_LAUNCH9 },
+ { XF86XK_Launch8, KEY_LAUNCHA },
+ { XF86XK_Launch9, KEY_LAUNCHB },
+ { XF86XK_LaunchA, KEY_LAUNCHC },
+ { XF86XK_LaunchB, KEY_LAUNCHD },
+ { XF86XK_LaunchC, KEY_LAUNCHE },
+ { XF86XK_LaunchD, KEY_LAUNCHF },
- {0, 0 }
+ { 0, 0 }
};
-
unsigned int KeyMappingX11::get_keycode(KeySym p_keysym) {
// kinda bruteforce.. could optimize.
- if (p_keysym<0x100) // Latin 1, maps 1-1
+ if (p_keysym < 0x100) // Latin 1, maps 1-1
return p_keysym;
// look for special key
- for(int idx=0;_xkeysym_to_keycode[idx].keysym!=0;idx++) {
+ for (int idx = 0; _xkeysym_to_keycode[idx].keysym != 0; idx++) {
- if (_xkeysym_to_keycode[idx].keysym==p_keysym)
- return _xkeysym_to_keycode[idx].keycode;
+ if (_xkeysym_to_keycode[idx].keysym == p_keysym)
+ return _xkeysym_to_keycode[idx].keycode;
}
return 0;
@@ -202,20 +200,19 @@ KeySym KeyMappingX11::get_keysym(unsigned int p_code) {
// kinda bruteforce.. could optimize.
- if (p_code<0x100) // Latin 1, maps 1-1
+ if (p_code < 0x100) // Latin 1, maps 1-1
return p_code;
// look for special key
- for(int idx=0;_xkeysym_to_keycode[idx].keysym!=0;idx++) {
+ for (int idx = 0; _xkeysym_to_keycode[idx].keysym != 0; idx++) {
- if (_xkeysym_to_keycode[idx].keycode==p_code)
- return _xkeysym_to_keycode[idx].keysym;
+ if (_xkeysym_to_keycode[idx].keycode == p_code)
+ return _xkeysym_to_keycode[idx].keysym;
}
return 0;
}
-
/***** UNICODE CONVERSION ******/
// Tables taken from FOX toolkit
@@ -228,7 +225,7 @@ struct _XTranslateUnicodePair {
enum {
- _KEYSYM_MAX=759
+ _KEYSYM_MAX = 759
};
static _XTranslateUnicodePair _xkeysym_to_unicode[_KEYSYM_MAX] = {
@@ -995,32 +992,31 @@ static _XTranslateUnicodePair _xkeysym_to_unicode[_KEYSYM_MAX] = {
unsigned int KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) {
/* Latin-1 */
- if (p_keysym>=0x20 && p_keysym<=0x7e)
+ if (p_keysym >= 0x20 && p_keysym <= 0x7e)
return p_keysym;
- if (p_keysym>=0xa0 && p_keysym<=0xff)
+ if (p_keysym >= 0xa0 && p_keysym <= 0xff)
return p_keysym;
// keypad to latin1 is easy
- if (p_keysym>=0xffaa && p_keysym<=0xffb9)
- return p_keysym-0xff80;
+ if (p_keysym >= 0xffaa && p_keysym <= 0xffb9)
+ return p_keysym - 0xff80;
/* Unicode (may be present)*/
- if((p_keysym&0xff000000)==0x01000000)
- return p_keysym&0x00ffffff;
+ if ((p_keysym & 0xff000000) == 0x01000000)
+ return p_keysym & 0x00ffffff;
- int middle,low=0,high=_KEYSYM_MAX-1;
+ int middle, low = 0, high = _KEYSYM_MAX - 1;
do {
- middle=(high+low)/2;
- if ( _xkeysym_to_unicode[middle].keysym==p_keysym)
+ middle = (high + low) / 2;
+ if (_xkeysym_to_unicode[middle].keysym == p_keysym)
return _xkeysym_to_unicode[middle].unicode;
- if ( _xkeysym_to_unicode[middle].keysym<=p_keysym )
- low=middle+1;
+ if (_xkeysym_to_unicode[middle].keysym <= p_keysym)
+ low = middle + 1;
else
- high=middle-1;
- } while (high>=low);
+ high = middle - 1;
+ } while (high >= low);
return 0;
-
}
struct _XTranslateUnicodePairReverse {
@@ -1031,7 +1027,7 @@ struct _XTranslateUnicodePairReverse {
enum {
- _UNICODE_MAX=750
+ _UNICODE_MAX = 750
};
static _XTranslateUnicodePairReverse _unicode_to_xkeysym[_UNICODE_MAX] = {
@@ -1791,23 +1787,23 @@ KeySym KeyMappingX11::get_keysym_from_unicode(unsigned int p_unicode) {
/* Latin 1 */
- if (p_unicode>=0x20 && p_unicode<=0x7e)
+ if (p_unicode >= 0x20 && p_unicode <= 0x7e)
return p_unicode;
- if (p_unicode>=0xa0 && p_unicode<=0xff)
+ if (p_unicode >= 0xa0 && p_unicode <= 0xff)
return p_unicode;
- int middle,low=0,high=_UNICODE_MAX-1;
+ int middle, low = 0, high = _UNICODE_MAX - 1;
do {
- middle=(high+low)/2;
- if ( _unicode_to_xkeysym[middle].keysym==p_unicode)
+ middle = (high + low) / 2;
+ if (_unicode_to_xkeysym[middle].keysym == p_unicode)
return _unicode_to_xkeysym[middle].keysym;
- if ( _unicode_to_xkeysym[middle].keysym<=p_unicode )
- low=middle+1;
+ if (_unicode_to_xkeysym[middle].keysym <= p_unicode)
+ low = middle + 1;
else
- high=middle-1;
- } while (high>=low);
+ high = middle - 1;
+ } while (high >= low);
// if not found, let's hope X understands it as unicode
- return p_unicode|0x01000000;
+ return p_unicode | 0x01000000;
}
diff --git a/platform/x11/key_mapping_x11.h b/platform/x11/key_mapping_x11.h
index 9749b2ec2a..8210df06e7 100644
--- a/platform/x11/key_mapping_x11.h
+++ b/platform/x11/key_mapping_x11.h
@@ -32,8 +32,8 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-#include <X11/Xlib.h>
#include <X11/XF86keysym.h>
+#include <X11/Xlib.h>
#define XK_MISCELLANY
#define XK_LATIN1
#define XK_XKB_KEYS
@@ -42,14 +42,13 @@
#include "os/keyboard.h"
class KeyMappingX11 {
- KeyMappingX11() {};
+ KeyMappingX11(){};
+
public:
static unsigned int get_keycode(KeySym p_keysym);
static KeySym get_keysym(unsigned int p_code);
static unsigned int get_unicode_from_keysym(KeySym p_keysym);
static KeySym get_keysym_from_unicode(unsigned int p_unicode);
-
};
-
#endif
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 689fe076f1..4f79f2fb5d 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -26,45 +26,42 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "servers/visual/visual_server_raster.h"
-#include "drivers/gles3/rasterizer_gles3.h"
#include "os_x11.h"
+#include "drivers/gles3/rasterizer_gles3.h"
+#include "errno.h"
#include "key_mapping_x11.h"
+#include "print_string.h"
+#include "servers/physics/physics_server_sw.h"
+#include "servers/visual/visual_server_raster.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "print_string.h"
-#include "servers/physics/physics_server_sw.h"
-#include "errno.h"
#include "X11/Xutil.h"
#include "X11/Xatom.h"
#include "X11/extensions/Xinerama.h"
// ICCCM
-#define WM_NormalState 1L // window normal state
-#define WM_IconicState 3L // window minimized
+#define WM_NormalState 1L // window normal state
+#define WM_IconicState 3L // window minimized
// EWMH
-#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
+#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
#include "main/main.h"
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <dlfcn.h>
#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <dlfcn.h>
//stupid linux.h
#ifdef KEY_TAB
#undef KEY_TAB
#endif
-
#include <X11/Xatom.h>
#undef CursorShape
@@ -73,75 +70,73 @@ int OS_X11::get_video_driver_count() const {
return 1;
}
-const char * OS_X11::get_video_driver_name(int p_driver) const {
+const char *OS_X11::get_video_driver_name(int p_driver) const {
return "GLES3";
}
OS::VideoMode OS_X11::get_default_video_mode() const {
- return OS::VideoMode(1024,600,false);
+ return OS::VideoMode(1024, 600, false);
}
int OS_X11::get_audio_driver_count() const {
- return AudioDriverManager::get_driver_count();
+ return AudioDriverManager::get_driver_count();
}
const char *OS_X11::get_audio_driver_name(int p_driver) const {
- AudioDriver* driver = AudioDriverManager::get_driver(p_driver);
- ERR_FAIL_COND_V( !driver, "" );
- return AudioDriverManager::get_driver(p_driver)->get_name();
+ AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
+ ERR_FAIL_COND_V(!driver, "");
+ return AudioDriverManager::get_driver(p_driver)->get_name();
}
-void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
+void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
- last_button_state=0;
+ last_button_state = 0;
- xmbstring=NULL;
- event_id=0;
- 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;
+ xmbstring = NULL;
+ event_id = 0;
+ 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;
xdnd_version = 0;
- if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) {
+ if (get_render_thread_mode() == RENDER_SEPARATE_THREAD) {
XInitThreads();
}
/** XLIB INITIALIZATION **/
x11_display = XOpenDisplay(NULL);
- char * modifiers = XSetLocaleModifiers ("@im=none");
- if (modifiers==NULL) {
+ char *modifiers = XSetLocaleModifiers("@im=none");
+ if (modifiers == NULL) {
WARN_PRINT("Error setting locale modifiers");
}
- const char* err;
+ const char *err;
xrr_get_monitors = NULL;
xrr_free_monitors = NULL;
int xrandr_major = 0;
int xrandr_minor = 0;
int event_base, error_base;
- xrandr_ext_ok = XRRQueryExtension(x11_display,&event_base, &error_base);
+ xrandr_ext_ok = XRRQueryExtension(x11_display, &event_base, &error_base);
xrandr_handle = dlopen("libXrandr.so.2", RTLD_LAZY);
if (!xrandr_handle) {
err = dlerror();
fprintf(stderr, "could not load libXrandr.so.2, Error: %s\n", err);
- }
- else {
+ } else {
XRRQueryVersion(x11_display, &xrandr_major, &xrandr_minor);
if (((xrandr_major << 8) | xrandr_minor) >= 0x0105) {
- xrr_get_monitors = (xrr_get_monitors_t) dlsym(xrandr_handle, "XRRGetMonitors");
+ xrr_get_monitors = (xrr_get_monitors_t)dlsym(xrandr_handle, "XRRGetMonitors");
if (!xrr_get_monitors) {
err = dlerror();
fprintf(stderr, "could not find symbol XRRGetMonitors\nError: %s\n", err);
- }
- else {
- xrr_free_monitors = (xrr_free_monitors_t) dlsym(xrandr_handle, "XRRFreeMonitors");
+ } else {
+ xrr_free_monitors = (xrr_free_monitors_t)dlsym(xrandr_handle, "XRRFreeMonitors");
if (!xrr_free_monitors) {
err = dlerror();
fprintf(stderr, "could not find XRRFreeMonitors\nError: %s\n", err);
@@ -151,39 +146,38 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
}
}
- xim = XOpenIM (x11_display, NULL, NULL, NULL);
-
+ xim = XOpenIM(x11_display, NULL, NULL, NULL);
if (xim == NULL) {
WARN_PRINT("XOpenIM failed");
- xim_style=0L;
+ xim_style = 0L;
} else {
- ::XIMStyles *xim_styles=NULL;
- xim_style=0L;
- char *imvalret=NULL;
+ ::XIMStyles *xim_styles = NULL;
+ xim_style = 0L;
+ char *imvalret = NULL;
imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
if (imvalret != NULL || xim_styles == NULL) {
- fprintf (stderr, "Input method doesn't support any styles\n");
+ fprintf(stderr, "Input method doesn't support any styles\n");
}
if (xim_styles) {
xim_style = 0L;
- for (int i=0;i<xim_styles->count_styles;i++) {
+ for (int i = 0; i < xim_styles->count_styles; i++) {
if (xim_styles->supported_styles[i] ==
- (XIMPreeditNothing | XIMStatusNothing)) {
+ (XIMPreeditNothing | XIMStatusNothing)) {
- xim_style = xim_styles->supported_styles[i];
- break;
- }
+ xim_style = xim_styles->supported_styles[i];
+ break;
+ }
}
- XFree (xim_styles);
+ XFree(xim_styles);
}
- XFree( imvalret );
+ XFree(imvalret);
}
- /*
+/*
char* windowid = getenv("GODOT_WINDOWID");
if (windowid) {
@@ -199,12 +193,11 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
};
*/
- // maybe contextgl wants to be in charge of creating the window
- //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
+// maybe contextgl wants to be in charge of creating the window
+//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
-
- context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, true ) );
+ context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, true));
context_gl->initialize();
RasterizerGLES3::register_config();
@@ -212,7 +205,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
RasterizerGLES3::make_current();
#endif
- visual_server = memnew( VisualServerRaster );
+ visual_server = memnew(VisualServerRaster);
#if 0
if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) {
@@ -221,7 +214,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
#endif
// borderless fullscreen window mode
if (current_videomode.fullscreen) {
- // needed for lxde/openbox, possibly others
+ // needed for lxde/openbox, possibly others
Hints hints;
Atom property;
hints.flags = 2;
@@ -257,9 +250,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
xsh->flags = PMinSize | PMaxSize;
XWindowAttributes xwa;
if (current_videomode.fullscreen) {
- XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa);
+ XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
} else {
- XGetWindowAttributes(x11_display,x11_window,&xwa);
+ XGetWindowAttributes(x11_display, x11_window, &xwa);
}
xsh->min_width = xwa.width;
xsh->max_width = xwa.width;
@@ -271,52 +264,49 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
- audio_driver_index=p_audio_driver;
- if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) {
+ audio_driver_index = p_audio_driver;
+ if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
- bool success=false;
- audio_driver_index=-1;
- for(int i=0;i<AudioDriverManager::get_driver_count();i++) {
- if (i==p_audio_driver)
+ bool success = false;
+ audio_driver_index = -1;
+ for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
+ if (i == p_audio_driver)
continue;
AudioDriverManager::get_driver(i)->set_singleton();
- if (AudioDriverManager::get_driver(i)->init()==OK) {
- success=true;
- print_line("Audio Driver Failed: "+String(AudioDriverManager::get_driver(p_audio_driver)->get_name()));
- print_line("Using alternate audio driver: "+String(AudioDriverManager::get_driver(i)->get_name()));
- audio_driver_index=i;
+ if (AudioDriverManager::get_driver(i)->init() == OK) {
+ success = true;
+ print_line("Audio Driver Failed: " + String(AudioDriverManager::get_driver(p_audio_driver)->get_name()));
+ print_line("Using alternate audio driver: " + String(AudioDriverManager::get_driver(i)->get_name()));
+ audio_driver_index = i;
break;
}
}
if (!success) {
ERR_PRINT("Initializing audio failed.");
}
-
}
-
-
ERR_FAIL_COND(!visual_server);
- ERR_FAIL_COND(x11_window==0);
+ ERR_FAIL_COND(x11_window == 0);
XSetWindowAttributes new_attr;
- 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 |
- ColormapChangeMask | OwnerGrabButtonMask;
+ 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 |
+ ColormapChangeMask | OwnerGrabButtonMask;
- XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr);
+ XChangeWindowAttributes(x11_display, x11_window, CWEventMask, &new_attr);
- XClassHint* classHint;
+ XClassHint *classHint;
/* set the titlebar name */
XStoreName(x11_display, x11_window, "Godot");
@@ -333,39 +323,37 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true);
XSetWMProtocols(x11_display, x11_window, &wm_delete, 1);
-
if (xim && xim_style) {
- xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL);
+ xic = XCreateIC(xim, XNInputStyle, xim_style, XNClientWindow, x11_window, XNFocusWindow, x11_window, (char *)NULL);
} else {
- xic=NULL;
+ xic = NULL;
WARN_PRINT("XCreateIC couldn't create xic");
-
}
- XcursorSetTheme(x11_display,"default");
+ XcursorSetTheme(x11_display, "default");
cursor_size = XcursorGetDefaultSize(x11_display);
cursor_theme = XcursorGetTheme(x11_display);
if (!cursor_theme) {
print_line("not found theme");
- cursor_theme="default";
+ cursor_theme = "default";
}
- for(int i=0;i<CURSOR_MAX;i++) {
+ for (int i = 0; i < CURSOR_MAX; i++) {
- cursors[i]=None;
- img[i]=NULL;
+ cursors[i] = None;
+ img[i] = NULL;
}
- current_cursor=CURSOR_ARROW;
+ current_cursor = CURSOR_ARROW;
if (cursor_theme) {
//print_line("cursor theme: "+String(cursor_theme));
- for(int i=0;i<CURSOR_MAX;i++) {
+ for (int i = 0; i < CURSOR_MAX; i++) {
- static const char *cursor_file[]={
+ static const char *cursor_file[] = {
"left_ptr",
"xterm",
"hand2",
@@ -385,26 +373,25 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
"question_arrow"
};
- img[i] = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size);
+ img[i] = XcursorLibraryLoadImage(cursor_file[i], cursor_theme, cursor_size);
if (img[i]) {
- cursors[i]=XcursorImageLoadCursor(x11_display,img[i]);
+ cursors[i] = XcursorImageLoadCursor(x11_display, img[i]);
//print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i]));
} else {
if (OS::is_stdout_verbose())
- print_line("failed cursor: "+String(cursor_file[i]));
+ print_line("failed cursor: " + String(cursor_file[i]));
}
}
}
-
{
Pixmap cursormask;
- XGCValues xgc;
- GC gc;
- XColor col;
- Cursor cursor;
+ XGCValues xgc;
+ GC gc;
+ XColor col;
+ Cursor cursor;
- cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1);
+ cursormask = XCreatePixmap(x11_display, RootWindow(x11_display, DefaultScreen(x11_display)), 1, 1, 1);
xgc.function = GXclear;
gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc);
XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1);
@@ -412,25 +399,23 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
col.red = 0;
col.flags = 4;
cursor = XCreatePixmapCursor(x11_display,
- cursormask, cursormask,
- &col, &col, 0, 0);
- XFreePixmap(x11_display, cursormask);
- XFreeGC(x11_display, gc);
-
+ cursormask, cursormask,
+ &col, &col, 0, 0);
+ XFreePixmap(x11_display, cursormask);
+ XFreeGC(x11_display, gc);
- if (cursor == None)
- {
- ERR_PRINT("FAILED CREATING CURSOR");
- }
+ if (cursor == None) {
+ ERR_PRINT("FAILED CREATING CURSOR");
+ }
- null_cursor=cursor;
+ null_cursor = cursor;
}
set_cursor_shape(CURSOR_BUSY);
//Set Xdnd (drag & drop) support
Atom XdndAware = XInternAtom(x11_display, "XdndAware", False);
- Atom version=5;
- XChangeProperty(x11_display, x11_window, XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1);
+ Atom version = 5;
+ XChangeProperty(x11_display, x11_window, XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char *)&version, 1);
xdnd_enter = XInternAtom(x11_display, "XdndEnter", False);
xdnd_position = XInternAtom(x11_display, "XdndPosition", False);
@@ -443,32 +428,32 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
visual_server->init();
//
- physics_server = memnew( PhysicsServerSW );
+ physics_server = memnew(PhysicsServerSW);
physics_server->init();
//physics_2d_server = memnew( Physics2DServerSW );
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
physics_2d_server->init();
- input = memnew( InputDefault );
+ input = memnew(InputDefault);
window_has_focus = true; // Set focus to true at init
#ifdef JOYDEV_ENABLED
- joypad = memnew( JoypadLinux(input));
+ joypad = memnew(JoypadLinux(input));
#endif
_ensure_data_dir();
}
void OS_X11::finalize() {
- if(main_loop)
+ if (main_loop)
memdelete(main_loop);
- main_loop=NULL;
+ main_loop = NULL;
for (int i = 0; i < get_audio_driver_count(); i++) {
AudioDriverManager::get_driver(i)->finish();
}
- /*
+/*
if (debugger_connection_console) {
memdelete(debugger_connection_console);
}
@@ -492,61 +477,58 @@ void OS_X11::finalize() {
if (xrandr_handle)
dlclose(xrandr_handle);
- XUnmapWindow( x11_display, x11_window );
- XDestroyWindow( x11_display, x11_window );
+ XUnmapWindow(x11_display, x11_window);
+ XDestroyWindow(x11_display, x11_window);
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
memdelete(context_gl);
#endif
- for(int i=0;i<CURSOR_MAX;i++) {
- if( cursors[i] != None )
- XFreeCursor( x11_display, cursors[i] );
- if( img[i] != NULL )
- XcursorImageDestroy( img[i] );
+ for (int i = 0; i < CURSOR_MAX; i++) {
+ if (cursors[i] != None)
+ XFreeCursor(x11_display, cursors[i]);
+ if (img[i] != NULL)
+ XcursorImageDestroy(img[i]);
};
- XDestroyIC( xic );
- XCloseIM( xim );
+ XDestroyIC(xic);
+ XCloseIM(xim);
XCloseDisplay(x11_display);
if (xmbstring)
memfree(xmbstring);
-
args.clear();
-
}
-
void OS_X11::set_mouse_mode(MouseMode p_mode) {
- if (p_mode==mouse_mode)
+ if (p_mode == mouse_mode)
return;
- if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED)
+ if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED)
XUngrabPointer(x11_display, CurrentTime);
// 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) {
- XUndefineCursor(x11_display,x11_window); // show cursor
+ XUndefineCursor(x11_display, x11_window); // show cursor
} else {
- XDefineCursor(x11_display,x11_window,null_cursor); // hide cursor
+ XDefineCursor(x11_display, x11_window, null_cursor); // hide cursor
}
- mouse_mode=p_mode;
+ mouse_mode = p_mode;
- if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
+ if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
- while(true) {
+ while (true) {
//flush pending motion events
if (XPending(x11_display) > 0) {
XEvent event;
XPeekEvent(x11_display, &event);
- if (event.type==MotionNotify) {
- XNextEvent(x11_display,&event);
+ if (event.type == MotionNotify) {
+ XNextEvent(x11_display, &event);
} else {
break;
}
@@ -556,30 +538,30 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) {
}
if (XGrabPointer(
- x11_display, x11_window, True,
- ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
- GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime) != GrabSuccess) {
+ x11_display, x11_window, True,
+ ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
+ GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime) != GrabSuccess) {
ERR_PRINT("NO GRAB");
}
- center.x = current_videomode.width/2;
- center.y = current_videomode.height/2;
+ center.x = current_videomode.width / 2;
+ center.y = current_videomode.height / 2;
XWarpPointer(x11_display, None, x11_window,
- 0,0,0,0, (int)center.x, (int)center.y);
+ 0, 0, 0, 0, (int)center.x, (int)center.y);
input->set_mouse_pos(center);
} else {
- do_mouse_warp=false;
+ do_mouse_warp = false;
}
XFlush(x11_display);
}
-void OS_X11::warp_mouse_pos(const Point2& p_to) {
+void OS_X11::warp_mouse_pos(const Point2 &p_to) {
- if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ if (mouse_mode == MOUSE_MODE_CAPTURED) {
- last_mouse_pos=p_to;
+ last_mouse_pos = p_to;
} else {
/*XWindowAttributes xwa;
@@ -587,9 +569,8 @@ void OS_X11::warp_mouse_pos(const Point2& p_to) {
printf("%d %d\n", xwa.x, xwa.y); needed? */
XWarpPointer(x11_display, None, x11_window,
- 0,0,0,0, (int)p_to.x , (int)p_to.y);
+ 0, 0, 0, 0, (int)p_to.x, (int)p_to.y);
}
-
}
OS::MouseMode OS_X11::get_mouse_mode() const {
@@ -604,22 +585,22 @@ Point2 OS_X11::get_mouse_pos() const {
return last_mouse_pos;
}
-void OS_X11::set_window_title(const String& p_title) {
- XStoreName(x11_display,x11_window,p_title.utf8().get_data());
+void OS_X11::set_window_title(const String &p_title) {
+ XStoreName(x11_display, x11_window, p_title.utf8().get_data());
Atom _net_wm_name = XInternAtom(x11_display, "_NET_WM_NAME", false);
Atom utf8_string = XInternAtom(x11_display, "UTF8_STRING", false);
- XChangeProperty( x11_display, x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char*) p_title.utf8().get_data(), p_title.utf8().length());
+ XChangeProperty(x11_display, x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char *)p_title.utf8().get_data(), p_title.utf8().length());
}
-void OS_X11::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
+void OS_X11::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
}
OS::VideoMode OS_X11::get_video_mode(int p_screen) const {
return current_videomode;
}
-void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const {
+void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
}
void OS_X11::set_wm_fullscreen(bool p_enabled) {
@@ -638,31 +619,30 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
xev.xclient.data.l[2] = 0;
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
-
}
int OS_X11::get_screen_count() const {
// Using Xinerama Extension
int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if( !ext_okay ) return 0;
+ if (!ext_okay) return 0;
int count;
- XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count);
+ XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
XFree(xsi);
return count;
}
int OS_X11::get_current_screen() const {
- int x,y;
- Window child;
- XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
+ int x, y;
+ Window child;
+ XTranslateCoordinates(x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
int count = get_screen_count();
- for(int i=0; i<count; i++) {
+ for (int i = 0; i < count; i++) {
Point2i pos = get_screen_position(i);
Size2i size = get_screen_size(i);
- if( (x >= pos.x && x <pos.x + size.width) && (y >= pos.y && y < pos.y + size.height) )
+ if ((x >= pos.x && x < pos.x + size.width) && (y >= pos.y && y < pos.y + size.height))
return i;
}
return 0;
@@ -670,16 +650,15 @@ int OS_X11::get_current_screen() const {
void OS_X11::set_current_screen(int p_screen) {
int count = get_screen_count();
- if(p_screen >= count) return;
+ if (p_screen >= count) return;
- if( current_videomode.fullscreen ) {
+ if (current_videomode.fullscreen) {
Point2i position = get_screen_position(p_screen);
Size2i size = get_screen_size(p_screen);
- XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y);
- }
- else {
- if( p_screen != get_current_screen() ) {
+ XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y);
+ } else {
+ if (p_screen != get_current_screen()) {
Point2i position = get_screen_position(p_screen);
XMoveWindow(x11_display, x11_window, position.x, position.y);
}
@@ -690,14 +669,14 @@ Point2 OS_X11::get_screen_position(int p_screen) const {
// Using Xinerama Extension
int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if( !ext_okay ) {
- return Point2i(0,0);
+ if (!ext_okay) {
+ return Point2i(0, 0);
}
int count;
- XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count);
- if( p_screen >= count ) {
- return Point2i(0,0);
+ XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
+ if (p_screen >= count) {
+ return Point2i(0, 0);
}
Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org);
@@ -711,11 +690,11 @@ Size2 OS_X11::get_screen_size(int p_screen) const {
// Using Xinerama Extension
int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if( !ext_okay ) return Size2i(0,0);
+ if (!ext_okay) return Size2i(0, 0);
int count;
- XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count);
- if( p_screen >= count ) return Size2i(0,0);
+ XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
+ if (p_screen >= count) return Size2i(0, 0);
Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height);
XFree(xsi);
@@ -734,47 +713,46 @@ int OS_X11::get_screen_dpi(int p_screen) const {
if (xrr_get_monitors) {
xrr_monitor_info *monitors = xrr_get_monitors(x11_display, x11_window, true, &count);
if (p_screen < count) {
- double xdpi = sc.width / (double) monitors[p_screen].mwidth * 25.4;
- double ydpi = sc.height / (double) monitors[p_screen].mheight * 25.4;
+ double xdpi = sc.width / (double)monitors[p_screen].mwidth * 25.4;
+ double ydpi = sc.height / (double)monitors[p_screen].mheight * 25.4;
xrr_free_monitors(monitors);
return (xdpi + ydpi) / 2;
}
xrr_free_monitors(monitors);
- }
- else if (p_screen == 0) {
+ } else if (p_screen == 0) {
XRRScreenSize *sizes = XRRSizes(x11_display, 0, &count);
if (sizes) {
- double xdpi = sc.width / (double) sizes[0].mwidth * 25.4;
- double ydpi = sc.height / (double) sizes[0].mheight * 25.4;
+ double xdpi = sc.width / (double)sizes[0].mwidth * 25.4;
+ double ydpi = sc.height / (double)sizes[0].mheight * 25.4;
return (xdpi + ydpi) / 2;
}
}
}
- int width_mm = DisplayWidthMM(x11_display, p_screen);
+ int width_mm = DisplayWidthMM(x11_display, p_screen);
int height_mm = DisplayHeightMM(x11_display, p_screen);
- double xdpi = (width_mm ? sc.width / (double) width_mm * 25.4 : 0);
- double ydpi = (height_mm ? sc.height / (double) height_mm * 25.4 : 0);
+ double xdpi = (width_mm ? sc.width / (double)width_mm * 25.4 : 0);
+ double ydpi = (height_mm ? sc.height / (double)height_mm * 25.4 : 0);
if (xdpi || xdpi)
- return (xdpi + ydpi)/(xdpi && ydpi ? 2 : 1);
+ return (xdpi + ydpi) / (xdpi && ydpi ? 2 : 1);
//could not get dpi
return 96;
}
Point2 OS_X11::get_window_position() const {
- int x,y;
+ int x, y;
Window child;
- XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
+ XTranslateCoordinates(x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
int screen = get_current_screen();
Point2i screen_position = get_screen_position(screen);
- return Point2i(x-screen_position.x, y-screen_position.y);
+ return Point2i(x - screen_position.x, y - screen_position.y);
}
-void OS_X11::set_window_position(const Point2& p_position) {
- XMoveWindow(x11_display,x11_window,p_position.x,p_position.y);
+void OS_X11::set_window_position(const Point2 &p_position) {
+ XMoveWindow(x11_display, x11_window, p_position.x, p_position.y);
}
Size2 OS_X11::get_window_size() const {
@@ -820,7 +798,7 @@ void OS_X11::set_window_resizable(bool p_enabled) {
xsh = XAllocSizeHints();
xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize;
- if(!p_enabled) {
+ if (!p_enabled) {
xsh->min_width = size.x;
xsh->max_width = size.x;
xsh->min_height = size.y;
@@ -849,8 +827,8 @@ void OS_X11::set_window_minimized(bool p_enabled) {
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
- Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
- Atom wm_hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", False);
+ Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
+ Atom wm_hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", False);
memset(&xev, 0, sizeof(xev));
xev.type = ClientMessage;
@@ -865,31 +843,30 @@ void OS_X11::set_window_minimized(bool p_enabled) {
bool OS_X11::is_window_minimized() const {
// Using ICCCM -- Inter-Client Communication Conventions Manual
- 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 )
+ 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)
return true;
}
return false;
@@ -918,7 +895,7 @@ void OS_X11::set_window_maximized(bool p_enabled) {
bool OS_X11::is_window_maximized() const {
// Using EWMH -- Extended Window Manager Hints
- Atom property = XInternAtom(x11_display,"_NET_WM_STATE",False );
+ Atom property = XInternAtom(x11_display, "_NET_WM_STATE", False);
Atom type;
int format;
unsigned long len;
@@ -937,23 +914,22 @@ bool OS_X11::is_window_maximized() const {
&format,
&len,
&remaining,
- &data
- );
+ &data);
- if(result == Success) {
- Atom *atoms = (Atom*) data;
+ if (result == Success) {
+ Atom *atoms = (Atom *)data;
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;
- for( unsigned int i=0; i < len; i++ ) {
- if( atoms[i] == wm_max_horz )
+ for (unsigned int i = 0; i < len; i++) {
+ if (atoms[i] == wm_max_horz)
found_wm_max_horz = true;
- if( atoms[i] == wm_max_vert )
+ if (atoms[i] == wm_max_vert)
found_wm_max_vert = true;
- if( found_wm_max_horz && found_wm_max_vert )
+ if (found_wm_max_horz && found_wm_max_vert)
return true;
}
XFree(atoms);
@@ -987,44 +963,44 @@ InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) {
InputModifierState state;
- state.shift = (p_x11_state&ShiftMask);
- state.control = (p_x11_state&ControlMask);
- state.alt = (p_x11_state&Mod1Mask /*|| p_x11_state&Mod5Mask*/); //altgr should not count as alt
- state.meta = (p_x11_state&Mod4Mask);
+ state.shift = (p_x11_state & ShiftMask);
+ state.control = (p_x11_state & ControlMask);
+ state.alt = (p_x11_state & Mod1Mask /*|| p_x11_state&Mod5Mask*/); //altgr should not count as alt
+ state.meta = (p_x11_state & Mod4Mask);
return state;
}
unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) {
- unsigned int state=0;
+ unsigned int state = 0;
- if (p_x11_state&Button1Mask) {
+ if (p_x11_state & Button1Mask) {
- state|=1<<0;
+ state |= 1 << 0;
}
- if (p_x11_state&Button3Mask) {
+ if (p_x11_state & Button3Mask) {
- state|=1<<1;
+ state |= 1 << 1;
}
- if (p_x11_state&Button2Mask) {
+ if (p_x11_state & Button2Mask) {
- state|=1<<2;
+ state |= 1 << 2;
}
- if (p_x11_state&Button4Mask) {
+ if (p_x11_state & Button4Mask) {
- state|=1<<3;
+ state |= 1 << 3;
}
- if (p_x11_state&Button5Mask) {
+ if (p_x11_state & Button5Mask) {
- state|=1<<4;
+ state |= 1 << 4;
}
- last_button_state=state;
+ last_button_state = state;
return state;
}
@@ -1052,20 +1028,19 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// you want to keep.
// This is a real bizarreness and cpu waster.
- KeySym keysym_keycode=0; // keysym used to find a keycode
- KeySym keysym_unicode=0; // keysym used to find unicode
+ KeySym keysym_keycode = 0; // keysym used to find a keycode
+ KeySym keysym_unicode = 0; // keysym used to find unicode
// XLookupString returns keysyms usable as nice scancodes/
- char str[256+1];
+ char str[256 + 1];
XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL);
- // Meanwhile, XLookupString returns keysyms useful for unicode.
-
+ // Meanwhile, XLookupString returns keysyms useful for unicode.
if (!xmbstring) {
// keep a temporary buffer for the string
- xmbstring=(char*)memalloc(sizeof(char)*8);
- xmblen=8;
+ xmbstring = (char *)memalloc(sizeof(char) * 8);
+ xmblen = 8;
}
if (xkeyevent->type == KeyPress && xic) {
@@ -1073,17 +1048,16 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
Status status;
do {
- int mnbytes = XmbLookupString (xic, xkeyevent, xmbstring, xmblen - 1, &keysym_unicode, &status);
+ int mnbytes = XmbLookupString(xic, xkeyevent, xmbstring, xmblen - 1, &keysym_unicode, &status);
xmbstring[mnbytes] = '\0';
if (status == XBufferOverflow) {
xmblen = mnbytes + 1;
- xmbstring = (char*)memrealloc (xmbstring, xmblen);
+ xmbstring = (char *)memrealloc(xmbstring, xmblen);
}
} while (status == XBufferOverflow);
}
-
/* Phase 2, obtain a pigui keycode from the keysym */
// KeyMappingX11 just translated the X11 keysym to a PIGUI
@@ -1097,8 +1071,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// It does a binary search on a table to translate
// most properly.
//print_line("keysym_unicode: "+rtos(keysym_unicode));
- unsigned int unicode = keysym_unicode>0? KeyMappingX11::get_unicode_from_keysym(keysym_unicode):0;
-
+ unsigned int unicode = keysym_unicode > 0 ? KeyMappingX11::get_unicode_from_keysym(keysym_unicode) : 0;
/* Phase 4, determine if event must be filtered */
@@ -1112,11 +1085,11 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
bool keypress = xkeyevent->type == KeyPress;
if (xkeyevent->type == KeyPress && xic) {
- if (XFilterEvent((XEvent*)xkeyevent, x11_window))
- return;
+ if (XFilterEvent((XEvent *)xkeyevent, x11_window))
+ return;
}
- if (keycode==0 && unicode==0)
+ if (keycode == 0 && unicode == 0)
return;
/* Phase 5, determine modifier mask */
@@ -1136,12 +1109,11 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// To detect them, i use XPeekEvent and check that their
// difference in time is below a treshold.
-
if (xkeyevent->type != KeyPress) {
// make sure there are events pending,
// so this call won't block.
- if (XPending(x11_display)>0) {
+ if (XPending(x11_display) > 0) {
XEvent peek_event;
XPeekEvent(x11_display, &peek_event);
@@ -1151,14 +1123,14 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// is correct, but the xorg developers are
// not very helpful today.
- ::Time tresh=ABS(peek_event.xkey.time-xkeyevent->time);
- if (peek_event.type == KeyPress && tresh<5 ) {
+ ::Time tresh = ABS(peek_event.xkey.time - xkeyevent->time);
+ if (peek_event.type == KeyPress && tresh < 5) {
KeySym rk;
- XLookupString((XKeyEvent*)&peek_event, str, 256, &rk, NULL);
- if (rk==keysym_keycode) {
+ XLookupString((XKeyEvent *)&peek_event, str, 256, &rk, NULL);
+ if (rk == keysym_keycode) {
XEvent event;
XNextEvent(x11_display, &event); //erase next event
- handle_key_event( (XKeyEvent*)&event,true );
+ handle_key_event((XKeyEvent *)&event, true);
return; //ignore current, echo next
}
}
@@ -1169,27 +1141,26 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// save the time to check for echo when keypress happens
}
-
/* Phase 7, send event to Window */
InputEvent event;
- event.ID=++event_id;
+ event.ID = ++event_id;
event.type = InputEvent::KEY;
- event.device=0;
- event.key.mod=state;
- event.key.pressed=keypress;
+ event.device = 0;
+ event.key.mod = state;
+ event.key.pressed = keypress;
- if (keycode>='a' && keycode<='z')
- keycode-='a'-'A';
+ if (keycode >= 'a' && keycode <= 'z')
+ keycode -= 'a' - 'A';
- event.key.scancode=keycode;
- event.key.unicode=unicode;
- event.key.echo=p_echo;
+ event.key.scancode = keycode;
+ event.key.unicode = unicode;
+ event.key.echo = p_echo;
- if (event.key.scancode==KEY_BACKTAB) {
+ if (event.key.scancode == KEY_BACKTAB) {
//make it consistent accross platforms.
- event.key.scancode=KEY_TAB;
- event.key.mod.shift=true;
+ event.key.scancode = KEY_TAB;
+ event.key.mod.shift = true;
}
//don't set mod state if modifier keys are released by themselves
@@ -1206,63 +1177,61 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
}
//printf("key: %x\n",event.key.scancode);
- input->parse_input_event( event);
+ input->parse_input_event(event);
}
-struct Property
-{
+struct Property {
unsigned char *data;
int format, nitems;
Atom type;
};
-static Property read_property(Display* p_display, Window p_window, Atom p_property) {
+static Property read_property(Display *p_display, Window p_window, Atom p_property) {
Atom actual_type;
int actual_format;
unsigned long nitems;
unsigned long bytes_after;
- unsigned char *ret=0;
+ unsigned char *ret = 0;
int read_bytes = 1024;
//Keep trying to read the property until there are no
//bytes unread.
- do
- {
- if(ret != 0)
+ do {
+ if (ret != 0)
XFree(ret);
XGetWindowProperty(p_display, p_window, p_property, 0, read_bytes, False, AnyPropertyType,
- &actual_type, &actual_format, &nitems, &bytes_after,
- &ret);
+ &actual_type, &actual_format, &nitems, &bytes_after,
+ &ret);
read_bytes *= 2;
- }while(bytes_after != 0);
+ } while (bytes_after != 0);
- Property p = {ret, actual_format, (int)nitems, actual_type};
+ Property p = { ret, actual_format, (int)nitems, actual_type };
return p;
}
-static Atom pick_target_from_list(Display* p_display, Atom *p_list, int p_count) {
+static Atom pick_target_from_list(Display *p_display, Atom *p_list, int p_count) {
- static const char* target_type = "text/uri-list";
+ static const char *target_type = "text/uri-list";
for (int i = 0; i < p_count; i++) {
Atom atom = p_list[i];
if (atom != None && String(XGetAtomName(p_display, atom)) == target_type)
- return atom;
+ return atom;
}
return None;
}
-static Atom pick_target_from_atoms(Display* p_disp, Atom p_t1, Atom p_t2, Atom p_t3) {
+static Atom pick_target_from_atoms(Display *p_disp, Atom p_t1, Atom p_t2, Atom p_t3) {
- static const char* target_type = "text/uri-list";
+ static const char *target_type = "text/uri-list";
if (p_t1 != None && String(XGetAtomName(p_disp, p_t1)) == target_type)
return p_t1;
@@ -1279,382 +1248,375 @@ void OS_X11::process_xevents() {
//printf("checking events %i\n", XPending(x11_display));
- do_mouse_warp=false;
-
+ do_mouse_warp = false;
// Is the current mouse mode one where it needs to be grabbed.
- bool mouse_mode_grab = mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED;
+ bool mouse_mode_grab = mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED;
while (XPending(x11_display) > 0) {
XEvent event;
XNextEvent(x11_display, &event);
switch (event.type) {
- case Expose:
- Main::force_redraw();
- break;
-
- case NoExpose:
- minimized = true;
- break;
-
- 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);
+ case Expose:
+ Main::force_redraw();
+ break;
- } break;
- case EnterNotify: {
- if (main_loop && !mouse_mode_grab)
- main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER);
- if (input)
- 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);
- }
- break;
+ case NoExpose:
+ minimized = true;
+ break;
- 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);
+ 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);
+ if (input)
+ 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);
}
- XUngrabPointer(x11_display, CurrentTime);
- }
- break;
-
- case ConfigureNotify:
- /* call resizeGLScene only if our window-size changed */
-
- if ((event.xconfigure.width == current_videomode.width) &&
- (event.xconfigure.height == current_videomode.height))
break;
- current_videomode.width=event.xconfigure.width;
- current_videomode.height=event.xconfigure.height;
- 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;
- }
+ 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);
+ }
+ break;
- InputEvent mouse_event;
- mouse_event.ID=++event_id;
- mouse_event.type = InputEvent::MOUSE_BUTTON;
- mouse_event.device=0;
- mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state);
- mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state);
- mouse_event.mouse_button.x=event.xbutton.x;
- mouse_event.mouse_button.y=event.xbutton.y;
- mouse_event.mouse_button.global_x=event.xbutton.x;
- mouse_event.mouse_button.global_y=event.xbutton.y;
- mouse_event.mouse_button.button_index=event.xbutton.button;
- if (mouse_event.mouse_button.button_index==2)
- mouse_event.mouse_button.button_index=3;
- else if (mouse_event.mouse_button.button_index==3)
- mouse_event.mouse_button.button_index=2;
+ case ConfigureNotify:
+ /* call resizeGLScene only if our window-size changed */
- mouse_event.mouse_button.pressed=(event.type==ButtonPress);
+ if ((event.xconfigure.width == current_videomode.width) &&
+ (event.xconfigure.height == current_videomode.height))
+ break;
- if (event.type==ButtonPress && event.xbutton.button==1) {
+ current_videomode.width = event.xconfigure.width;
+ current_videomode.height = event.xconfigure.height;
+ 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;
+ }
- uint64_t diff = get_ticks_usec()/1000 - last_click_ms;
+ InputEvent mouse_event;
+ mouse_event.ID = ++event_id;
+ mouse_event.type = InputEvent::MOUSE_BUTTON;
+ mouse_event.device = 0;
+ mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state);
+ mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state);
+ mouse_event.mouse_button.x = event.xbutton.x;
+ mouse_event.mouse_button.y = event.xbutton.y;
+ mouse_event.mouse_button.global_x = event.xbutton.x;
+ mouse_event.mouse_button.global_y = event.xbutton.y;
+ mouse_event.mouse_button.button_index = event.xbutton.button;
+ if (mouse_event.mouse_button.button_index == 2)
+ mouse_event.mouse_button.button_index = 3;
+ else if (mouse_event.mouse_button.button_index == 3)
+ mouse_event.mouse_button.button_index = 2;
- if (diff<400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x,event.xbutton.y))<5) {
+ mouse_event.mouse_button.pressed = (event.type == ButtonPress);
- last_click_ms=0;
- last_click_pos = Point2(-100,-100);
- mouse_event.mouse_button.doubleclick=true;
- mouse_event.ID=++event_id;
+ if (event.type == ButtonPress && event.xbutton.button == 1) {
- } else {
- last_click_ms+=diff;
- last_click_pos = Point2(event.xbutton.x,event.xbutton.y);
- }
- }
+ uint64_t diff = get_ticks_usec() / 1000 - last_click_ms;
- input->parse_input_event( mouse_event);
+ if (diff < 400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x, event.xbutton.y)) < 5) {
+ last_click_ms = 0;
+ last_click_pos = Point2(-100, -100);
+ mouse_event.mouse_button.doubleclick = true;
+ mouse_event.ID = ++event_id;
- } 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;
+ } else {
+ last_click_ms += diff;
+ last_click_pos = Point2(event.xbutton.x, event.xbutton.y);
+ }
}
- if (XPending(x11_display) > 0) {
- XEvent tevent;
- XPeekEvent(x11_display, &tevent);
- if (tevent.type==MotionNotify) {
- XNextEvent(x11_display,&event);
+ input->parse_input_event(mouse_event);
+
+ } 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;
+ }
} else {
break;
}
- } else {
- break;
}
- }
- last_timestamp=event.xmotion.time;
+ last_timestamp = event.xmotion.time;
- // 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 );
+ // 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);
- if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ if (mouse_mode == MOUSE_MODE_CAPTURED) {
#if 1
- //Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2);
- 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.
+ //Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2);
+ 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.
- center=pos;
- break;
- }
+ center = pos;
+ break;
+ }
- 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
+ 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
#else
- //Dear X11, thanks for making my life miserable
+ //Dear X11, thanks for making my life miserable
- center.x = current_videomode.width/2;
- center.y = current_videomode.height/2;
- pos = last_mouse_pos + ( pos-center );
- if (pos==last_mouse_pos)
- break;
- XWarpPointer(x11_display, None, x11_window,
- 0,0,0,0, (int)center.x, (int)center.y);
+ center.x = current_videomode.width / 2;
+ center.y = current_videomode.height / 2;
+ pos = last_mouse_pos + (pos - center);
+ if (pos == last_mouse_pos)
+ break;
+ XWarpPointer(x11_display, None, x11_window,
+ 0, 0, 0, 0, (int)center.x, (int)center.y);
#endif
- }
-
- if (!last_mouse_pos_valid) {
-
- last_mouse_pos=pos;
- last_mouse_pos_valid=true;
- }
-
- Point2i rel = pos - last_mouse_pos;
-
- InputEvent motion_event;
- motion_event.ID=++event_id;
- motion_event.type=InputEvent::MOUSE_MOTION;
- motion_event.device=0;
-
- motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state);
- motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state);
- motion_event.mouse_motion.x=pos.x;
- motion_event.mouse_motion.y=pos.y;
- input->set_mouse_pos(pos);
- motion_event.mouse_motion.global_x=pos.x;
- motion_event.mouse_motion.global_y=pos.y;
- motion_event.mouse_motion.speed_x=input->get_last_mouse_speed().x;
- motion_event.mouse_motion.speed_y=input->get_last_mouse_speed().y;
-
- motion_event.mouse_motion.relative_x=rel.x;
- motion_event.mouse_motion.relative_y=rel.y;
+ }
- last_mouse_pos=pos;
+ if (!last_mouse_pos_valid) {
- // 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)
- input->parse_input_event( motion_event);
+ last_mouse_pos = pos;
+ last_mouse_pos_valid = true;
+ }
- } break;
- case KeyPress:
- case KeyRelease: {
+ Point2i rel = pos - last_mouse_pos;
+
+ InputEvent motion_event;
+ motion_event.ID = ++event_id;
+ motion_event.type = InputEvent::MOUSE_MOTION;
+ motion_event.device = 0;
+
+ motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state);
+ motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state);
+ motion_event.mouse_motion.x = pos.x;
+ motion_event.mouse_motion.y = pos.y;
+ input->set_mouse_pos(pos);
+ motion_event.mouse_motion.global_x = pos.x;
+ motion_event.mouse_motion.global_y = pos.y;
+ motion_event.mouse_motion.speed_x = input->get_last_mouse_speed().x;
+ motion_event.mouse_motion.speed_y = input->get_last_mouse_speed().y;
+
+ motion_event.mouse_motion.relative_x = rel.x;
+ motion_event.mouse_motion.relative_y = rel.y;
+
+ 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)
+ input->parse_input_event(motion_event);
+
+ } 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);
+ if (req->target == XA_STRING || req->target == XInternAtom(x11_display, "COMPOUND_TEXT", 0) ||
+ req->target == XInternAtom(x11_display, "UTF8_STRING", 0)) {
+ 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)) {
+
+ Atom data[2];
+ data[0] = XInternAtom(x11_display, "UTF8_STRING", 0);
+ data[1] = XA_STRING;
+ XChangeProperty(x11_display, req->requestor, req->property, req->target,
+ 8, PropModeReplace, (unsigned char *)&data,
+ sizeof(data));
+ respond.xselection.property = req->property;
- last_timestamp=event.xkey.time;
+ } else {
+ printf("No String %x\n",
+ (int)req->target);
+ respond.xselection.property = None;
+ }
+ 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;
+ XSendEvent(x11_display, req->requestor, 0, 0, &respond);
+ XFlush(x11_display);
+ } break;
- // 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);
- if (req->target == XA_STRING || req->target == XInternAtom(x11_display, "COMPOUND_TEXT", 0) ||
- req->target == XInternAtom(x11_display, "UTF8_STRING", 0))
- {
- 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)) {
-
- Atom data[2];
- data[0] = XInternAtom(x11_display, "UTF8_STRING", 0);
- data[1] = XA_STRING;
- XChangeProperty (x11_display, req->requestor, req->property, req->target,
- 8, PropModeReplace, (unsigned char *) &data,
- sizeof (data));
- respond.xselection.property=req->property;
+ case SelectionNotify:
- } else {
- printf ("No String %x\n",
- (int)req->target);
- respond.xselection.property= None;
- }
- 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;
- XSendEvent (x11_display, req->requestor,0,0,&respond);
- XFlush (x11_display);
- } break;
+ if (event.xselection.target == requested) {
- case SelectionNotify:
+ Property p = read_property(x11_display, x11_window, XInternAtom(x11_display, "PRIMARY", 0));
- if (event.xselection.target == requested) {
+ 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);
- Property p = read_property(x11_display, x11_window, XInternAtom(x11_display, "PRIMARY", 0));
+ //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.
- 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();
+ XSendEvent(x11_display, xdnd_source_window, False, NoEventMask, (XEvent *)&m);
}
- main_loop->drop_files(files);
-
- //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.
-
- XSendEvent(x11_display, xdnd_source_window, False, NoEventMask, (XEvent*)&m);
- }
- break;
+ break;
- case ClientMessage:
+ case ClientMessage:
- if ((unsigned int)event.xclient.data.l[0]==(unsigned int)wm_delete)
- main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
+ if ((unsigned int)event.xclient.data.l[0] == (unsigned int)wm_delete)
+ main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
- else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_enter) {
+ else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_enter) {
- //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
- 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_status;
- m.format=32;
- m.data.l[0] = x11_window;
- 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.
+ //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
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.message_type = xdnd_status;
+ 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);
+ 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);
+ }
}
- }
- break;
- default:
- break;
+ break;
+ default:
+ break;
}
}
@@ -1663,7 +1625,7 @@ void OS_X11::process_xevents() {
if (do_mouse_warp) {
XWarpPointer(x11_display, None, x11_window,
- 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2);
+ 0, 0, 0, 0, (int)current_videomode.width / 2, (int)current_videomode.height / 2);
/*
Window root, child;
@@ -1687,12 +1649,12 @@ void OS_X11::delete_main_loop() {
if (main_loop)
memdelete(main_loop);
- main_loop=NULL;
+ main_loop = NULL;
}
-void OS_X11::set_main_loop( MainLoop * p_main_loop ) {
+void OS_X11::set_main_loop(MainLoop *p_main_loop) {
- main_loop=p_main_loop;
+ main_loop = p_main_loop;
input->set_main_loop(p_main_loop);
}
@@ -1701,7 +1663,7 @@ bool OS_X11::can_draw() const {
return !minimized;
};
-void OS_X11::set_clipboard(const String& p_text) {
+void OS_X11::set_clipboard(const String &p_text) {
OS::set_clipboard(p_text);
@@ -1709,7 +1671,7 @@ void OS_X11::set_clipboard(const String& p_text) {
XSetSelectionOwner(x11_display, XInternAtom(x11_display, "CLIPBOARD", 0), x11_window, CurrentTime);
};
-static String _get_clipboard(Atom p_source, Window x11_window, ::Display* x11_display, String p_internal_clipboard) {
+static String _get_clipboard(Atom p_source, Window x11_window, ::Display *x11_display, String p_internal_clipboard) {
String ret;
@@ -1718,7 +1680,7 @@ static String _get_clipboard(Atom p_source, Window x11_window, ::Display* x11_di
int format, result;
unsigned long len, bytes_left, dummy;
unsigned char *data;
- Window Sown = XGetSelectionOwner (x11_display, p_source);
+ Window Sown = XGetSelectionOwner(x11_display, p_source);
if (Sown == x11_window) {
@@ -1726,9 +1688,9 @@ static String _get_clipboard(Atom p_source, Window x11_window, ::Display* x11_di
};
if (Sown != None) {
- XConvertSelection (x11_display, p_source, XA_STRING, selection,
- x11_window, CurrentTime);
- XFlush (x11_display);
+ XConvertSelection(x11_display, p_source, XA_STRING, selection,
+ x11_window, CurrentTime);
+ XFlush(x11_display);
while (true) {
XEvent event;
XNextEvent(x11_display, &event);
@@ -1740,31 +1702,30 @@ static String _get_clipboard(Atom p_source, Window x11_window, ::Display* x11_di
//
// Do not get any data, see how much data is there
//
- 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);
+ 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);
// DATA is There
- if (bytes_left > 0)
- {
- result = XGetWindowProperty (x11_display, x11_window,
- selection, 0,bytes_left,0,
- AnyPropertyType, &type,&format,
- &len, &dummy, &data);
+ if (bytes_left > 0) {
+ result = XGetWindowProperty(x11_display, x11_window,
+ selection, 0, bytes_left, 0,
+ AnyPropertyType, &type, &format,
+ &len, &dummy, &data);
if (result == Success) {
- ret.parse_utf8((const char*)data);
- } else printf ("FAIL\n");
- XFree (data);
+ ret.parse_utf8((const char *)data);
+ } else
+ printf("FAIL\n");
+ XFree(data);
}
}
return ret;
-
}
String OS_X11::get_clipboard() const {
@@ -1789,59 +1750,58 @@ Error OS_X11::shell_open(String p_uri) {
Error ok;
List<String> args;
args.push_back(p_uri);
- ok = execute("/usr/bin/xdg-open",args,false);
- if (ok==OK)
+ ok = execute("/usr/bin/xdg-open", args, false);
+ if (ok == OK)
return OK;
- ok = execute("gnome-open",args,false);
- if (ok==OK)
+ ok = execute("gnome-open", args, false);
+ if (ok == OK)
return OK;
- ok = execute("kde-open",args,false);
+ ok = execute("kde-open", args, false);
return ok;
}
String OS_X11::get_system_dir(SystemDir p_dir) const {
-
String xdgparam;
- switch(p_dir) {
+ switch (p_dir) {
case SYSTEM_DIR_DESKTOP: {
- xdgparam="DESKTOP";
+ xdgparam = "DESKTOP";
} break;
case SYSTEM_DIR_DCIM: {
- xdgparam="PICTURES";
+ xdgparam = "PICTURES";
} break;
case SYSTEM_DIR_DOCUMENTS: {
- xdgparam="DOCUMENTS";
+ xdgparam = "DOCUMENTS";
} break;
case SYSTEM_DIR_DOWNLOADS: {
- xdgparam="DOWNLOAD";
+ xdgparam = "DOWNLOAD";
} break;
case SYSTEM_DIR_MOVIES: {
- xdgparam="VIDEOS";
+ xdgparam = "VIDEOS";
} break;
case SYSTEM_DIR_MUSIC: {
- xdgparam="MUSIC";
+ xdgparam = "MUSIC";
} break;
case SYSTEM_DIR_PICTURES: {
- xdgparam="PICTURES";
+ xdgparam = "PICTURES";
} break;
case SYSTEM_DIR_RINGTONES: {
- xdgparam="MUSIC";
+ xdgparam = "MUSIC";
} break;
}
@@ -1849,38 +1809,36 @@ String OS_X11::get_system_dir(SystemDir p_dir) const {
String pipe;
List<String> arg;
arg.push_back(xdgparam);
- Error err = const_cast<OS_X11*>(this)->execute("/usr/bin/xdg-user-dir",arg,true,NULL,&pipe);
- if (err!=OK)
+ Error err = const_cast<OS_X11 *>(this)->execute("/usr/bin/xdg-user-dir", arg, true, NULL, &pipe);
+ if (err != OK)
return ".";
return pipe.strip_edges();
}
void OS_X11::move_window_to_foreground() {
- XRaiseWindow(x11_display,x11_window);
+ XRaiseWindow(x11_display, x11_window);
}
void OS_X11::set_cursor_shape(CursorShape p_shape) {
- ERR_FAIL_INDEX(p_shape,CURSOR_MAX);
+ ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
- if (p_shape==current_cursor)
+ if (p_shape == current_cursor)
return;
- 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]);
+ 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]);
}
- current_cursor=p_shape;
+ current_cursor = p_shape;
}
-
void OS_X11::release_rendering_thread() {
context_gl->release_current();
-
}
void OS_X11::make_rendering_thread() {
@@ -1893,7 +1851,7 @@ void OS_X11::swap_buffers() {
context_gl->swap_buffers();
}
-void OS_X11::alert(const String& p_alert,const String& p_title) {
+void OS_X11::alert(const String &p_alert, const String &p_title) {
List<String> args;
args.push_back("-center");
@@ -1901,14 +1859,14 @@ void OS_X11::alert(const String& p_alert,const String& p_title) {
args.push_back(p_title);
args.push_back(p_alert);
- execute("/usr/bin/xmessage",args,true);
+ execute("/usr/bin/xmessage", args, true);
}
-void OS_X11::set_icon(const Image& p_icon) {
+void OS_X11::set_icon(const Image &p_icon) {
Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
if (!p_icon.empty()) {
- Image img=p_icon;
+ Image img = p_icon;
img.convert(Image::FORMAT_RGBA8);
int w = img.get_width();
@@ -1917,31 +1875,30 @@ void OS_X11::set_icon(const Image& p_icon) {
// We're using long to have wordsize (32Bit build -> 32 Bits, 64 Bit build -> 64 Bits
Vector<long> pd;
- pd.resize(2+w*h);
+ pd.resize(2 + w * h);
- pd[0]=w;
- pd[1]=h;
+ pd[0] = w;
+ pd[1] = h;
PoolVector<uint8_t>::Read r = img.get_data().read();
- long * wr = &pd[2];
- uint8_t const * pr = r.ptr();
+ long *wr = &pd[2];
+ uint8_t const *pr = r.ptr();
- for(int i=0;i<w*h;i++) {
- long v=0;
+ for (int i = 0; i < w * h; i++) {
+ long v = 0;
// A R G B
- v|=pr[3] << 24 | pr[0] << 16 | pr[1] << 8 | pr[2];
- *wr++=v;
+ v |= pr[3] << 24 | pr[0] << 16 | pr[1] << 8 | pr[2];
+ *wr++ = v;
pr += 4;
}
- XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char*) pd.ptr(), pd.size());
+ XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)pd.ptr(), pd.size());
} else {
- XDeleteProperty(x11_display, x11_window, net_wm_icon);
+ XDeleteProperty(x11_display, x11_window, net_wm_icon);
}
XFlush(x11_display);
}
-
void OS_X11::run() {
force_quit = false;
@@ -1962,7 +1919,7 @@ void OS_X11::run() {
#ifdef JOYDEV_ENABLED
event_id = joypad->process_joypads(event_id);
#endif
- if (Main::iteration()==true)
+ if (Main::iteration() == true)
break;
};
@@ -1990,10 +1947,9 @@ bool OS_X11::is_vsync_enabled() const {
return true;
}
-
void OS_X11::set_context(int p_context) {
- XClassHint* classHint = NULL;
+ XClassHint *classHint = NULL;
classHint = XAllocClassHint();
if (classHint) {
@@ -2033,12 +1989,12 @@ OS_X11::OS_X11() {
AudioDriverManager::add_driver(&driver_alsa);
#endif
- if(AudioDriverManager::get_driver_count() == 0){
+ if (AudioDriverManager::get_driver_count() == 0) {
WARN_PRINT("No sound driver found... Defaulting to dummy driver");
AudioDriverManager::add_driver(&driver_dummy);
}
minimized = false;
- xim_style=0L;
- mouse_mode=MOUSE_MODE_VISIBLE;
+ xim_style = 0L;
+ mouse_mode = MOUSE_MODE_VISIBLE;
}
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index ce2e2df6e9..cbda18c0bc 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -29,29 +29,28 @@
#ifndef OS_X11_H
#define OS_X11_H
-
-#include "os/input.h"
-#include "drivers/unix/os_unix.h"
#include "context_gl_x11.h"
+#include "drivers/unix/os_unix.h"
+#include "os/input.h"
#include "servers/visual_server.h"
//#include "servers/visual/visual_server_wrap_mt.h"
-#include "servers/visual/rasterizer.h"
-#include "servers/physics_server.h"
-#include "servers/audio_server.h"
-#include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "drivers/alsa/audio_driver_alsa.h"
#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
+#include "drivers/rtaudio/audio_driver_rtaudio.h"
+#include "joypad_linux.h"
+#include "main/input_default.h"
+#include "power_x11.h"
#include "servers/audio/audio_driver_dummy.h"
+#include "servers/audio_server.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
-#include "main/input_default.h"
-#include "joypad_linux.h"
-#include "power_x11.h"
+#include "servers/physics_server.h"
+#include "servers/visual/rasterizer.h"
-#include <X11/keysym.h>
-#include <X11/Xlib.h>
#include <X11/Xcursor/Xcursor.h>
+#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
+#include <X11/keysym.h>
// Hints for X11 fullscreen
typedef struct {
@@ -63,17 +62,17 @@ typedef struct {
} Hints;
typedef struct _xrr_monitor_info {
- Atom name;
- Bool primary;
- Bool automatic;
- int noutput;
- int x;
- int y;
- int width;
- int height;
- int mwidth;
- int mheight;
- RROutput *outputs;
+ Atom name;
+ Bool primary;
+ Bool automatic;
+ int noutput;
+ int x;
+ int y;
+ int width;
+ int height;
+ int mwidth;
+ int mheight;
+ RROutput *outputs;
} xrr_monitor_info;
#undef CursorShape
@@ -93,7 +92,7 @@ class OS_X11 : public OS_Unix {
Atom xdnd_selection;
Atom requested;
- int xdnd_version;
+ int xdnd_version;
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
ContextGL_X11 *context_gl;
@@ -105,7 +104,7 @@ class OS_X11 : public OS_Unix {
Window x11_window;
Window xdnd_source_window;
MainLoop *main_loop;
- ::Display* x11_display;
+ ::Display *x11_display;
char *xmbstring;
int xmblen;
unsigned long last_timestamp;
@@ -128,7 +127,7 @@ class OS_X11 : public OS_Unix {
MouseMode mouse_mode;
Point2i center;
- void handle_key_event(XKeyEvent *p_event,bool p_echo=false);
+ void handle_key_event(XKeyEvent *p_event, bool p_echo = false);
void process_xevents();
virtual void delete_main_loop();
IP_Unix *ip_unix;
@@ -165,7 +164,7 @@ class OS_X11 : public OS_Unix {
AudioDriverDummy driver_dummy;
Atom net_wm_icon;
-
+
PowerX11 *power_manager;
int audio_driver_index;
@@ -174,30 +173,27 @@ class OS_X11 : public OS_Unix {
//void set_wm_border(bool p_enabled);
void set_wm_fullscreen(bool p_enabled);
- typedef xrr_monitor_info* (*xrr_get_monitors_t)(Display *dpy, Window window, Bool get_active, int *nmonitors);
- typedef void (*xrr_free_monitors_t)(xrr_monitor_info* monitors);
+ typedef xrr_monitor_info *(*xrr_get_monitors_t)(Display *dpy, Window window, Bool get_active, int *nmonitors);
+ typedef void (*xrr_free_monitors_t)(xrr_monitor_info *monitors);
xrr_get_monitors_t xrr_get_monitors;
xrr_free_monitors_t xrr_free_monitors;
void *xrandr_handle;
Bool xrandr_ext_ok;
protected:
-
virtual int get_video_driver_count() const;
- virtual const char * get_video_driver_name(int p_driver) const;
+ virtual const char *get_video_driver_name(int p_driver) const;
virtual VideoMode get_default_video_mode() const;
virtual int get_audio_driver_count() const;
- virtual const char * get_audio_driver_name(int p_driver) const;
+ virtual const char *get_audio_driver_name(int p_driver) const;
- virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
+ virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
- virtual void set_main_loop( MainLoop * p_main_loop );
-
+ virtual void set_main_loop(MainLoop *p_main_loop);
public:
-
virtual String get_name();
virtual void set_cursor_shape(CursorShape p_shape);
@@ -205,18 +201,18 @@ public:
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;
- virtual void warp_mouse_pos(const Point2& p_to);
+ virtual void warp_mouse_pos(const Point2 &p_to);
virtual Point2 get_mouse_pos() const;
virtual int get_mouse_button_state() const;
- virtual void set_window_title(const String& p_title);
+ virtual void set_window_title(const String &p_title);
- virtual void set_icon(const Image& p_icon);
+ virtual void set_icon(const Image &p_icon);
virtual MainLoop *get_main_loop() const;
virtual bool can_draw() const;
- virtual void set_clipboard(const String& p_text);
+ virtual void set_clipboard(const String &p_text);
virtual String get_clipboard() const;
virtual void release_rendering_thread();
@@ -227,19 +223,18 @@ public:
virtual Error shell_open(String p_uri);
- virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
- virtual VideoMode get_video_mode(int p_screen=0) const;
- virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
-
+ virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
+ virtual VideoMode get_video_mode(int p_screen = 0) const;
+ virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
virtual int get_screen_count() const;
virtual int get_current_screen() const;
virtual void set_current_screen(int p_screen);
- virtual Point2 get_screen_position(int p_screen=0) const;
- virtual Size2 get_screen_size(int p_screen=0) const;
- virtual int get_screen_dpi(int p_screen=0) const;
+ virtual Point2 get_screen_position(int p_screen = 0) const;
+ virtual Size2 get_screen_size(int p_screen = 0) const;
+ virtual int get_screen_dpi(int p_screen = 0) const;
virtual Point2 get_window_position() const;
- virtual void set_window_position(const Point2& p_position);
+ virtual void set_window_position(const Point2 &p_position);
virtual Size2 get_window_size() const;
virtual void set_window_size(const Size2 p_size);
virtual void set_window_fullscreen(bool p_enabled);
@@ -253,7 +248,7 @@ public:
virtual void request_attention();
virtual void move_window_to_foreground();
- virtual void alert(const String& p_alert,const String& p_title="ALERT!");
+ virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device) const;
diff --git a/platform/x11/power_x11.cpp b/platform/x11/power_x11.cpp
index 472a32bb48..2f98d2f335 100644
--- a/platform/x11/power_x11.cpp
+++ b/platform/x11/power_x11.cpp
@@ -32,34 +32,31 @@
#include <stdio.h>
#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
// CODE CHUNK IMPORTED FROM SDL 2.0
-static const char* proc_apm_path = "/proc/apm";
-static const char* proc_acpi_battery_path = "/proc/acpi/battery";
-static const char* proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter";
-static const char* sys_class_power_supply_path = "/sys/class/power_supply";
+static const char *proc_apm_path = "/proc/apm";
+static const char *proc_acpi_battery_path = "/proc/acpi/battery";
+static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter";
+static const char *sys_class_power_supply_path = "/sys/class/power_supply";
-FileAccessRef PowerX11::open_power_file(const char* base, const char* node, const char* key)
-{
+FileAccessRef PowerX11::open_power_file(const char *base, const char *node, const char *key) {
String path = String(base) + String("/") + String(node) + String("/") + String(key);
- FileAccessRef f = FileAccess::open(path,FileAccess::READ);
+ FileAccessRef f = FileAccess::open(path, FileAccess::READ);
return f;
}
-
-bool PowerX11::read_power_file(const char* base, const char* node, const char* key, char* buf, size_t buflen)
-{
+bool PowerX11::read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen) {
ssize_t br = 0;
FileAccessRef fd = open_power_file(base, node, key);
if (!fd) {
return false;
}
- br = fd->get_buffer(reinterpret_cast<uint8_t*>(buf), buflen-1);
+ br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), buflen - 1);
fd->close();
if (br < 0) {
return false;
@@ -68,17 +65,15 @@ bool PowerX11::read_power_file(const char* base, const char* node, const char* k
return true;
}
-
-bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
-{
+bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val) {
char *ptr = *_ptr;
while (*ptr == ' ') {
- ptr++; /* skip whitespace. */
+ ptr++; /* skip whitespace. */
}
if (*ptr == '\0') {
- return false; /* EOF. */
+ return false; /* EOF. */
}
*_key = ptr;
@@ -88,17 +83,17 @@ bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
}
if (*ptr == '\0') {
- return false; /* (unexpected) EOF. */
+ return false; /* (unexpected) EOF. */
}
- *(ptr++) = '\0'; /* terminate the key. */
+ *(ptr++) = '\0'; /* terminate the key. */
while ((*ptr == ' ') && (*ptr != '\0')) {
- ptr++; /* skip whitespace. */
+ ptr++; /* skip whitespace. */
}
if (*ptr == '\0') {
- return false; /* (unexpected) EOF. */
+ return false; /* (unexpected) EOF. */
}
*_val = ptr;
@@ -108,16 +103,14 @@ bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
}
if (*ptr != '\0') {
- *(ptr++) = '\0'; /* terminate the value. */
+ *(ptr++) = '\0'; /* terminate the value. */
}
- *_ptr = ptr; /* store for next time. */
+ *_ptr = ptr; /* store for next time. */
return true;
}
-void
-PowerX11::check_proc_acpi_battery(const char * node, bool * have_battery, bool * charging)
-{
+void PowerX11::check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging) {
const char *base = proc_acpi_battery_path;
char info[1024];
char state[1024];
@@ -131,10 +124,10 @@ PowerX11::check_proc_acpi_battery(const char * node, bool * have_battery, bool *
int secs = -1;
int pct = -1;
- if (!read_power_file(base, node, "state", state, sizeof (state))) {
+ if (!read_power_file(base, node, "state", state, sizeof(state))) {
return;
} else {
- if (!read_power_file(base, node, "info", info, sizeof (info)))
+ if (!read_power_file(base, node, "info", info, sizeof(info)))
return;
}
@@ -175,7 +168,7 @@ PowerX11::check_proc_acpi_battery(const char * node, bool * have_battery, bool *
}
if ((maximum >= 0) && (remaining >= 0)) {
- pct = (int) ((((float) remaining) / ((float) maximum)) * 100.0f);
+ pct = (int)((((float)remaining) / ((float)maximum)) * 100.0f);
if (pct < 0) {
pct = 0;
} else if (pct > 100) {
@@ -191,7 +184,7 @@ PowerX11::check_proc_acpi_battery(const char * node, bool * have_battery, bool *
*/
if ((secs < 0) && (this->nsecs_left < 0)) {
if ((pct < 0) && (this->percent_left < 0)) {
- choose = true; /* at least we know there's a battery. */
+ choose = true; /* at least we know there's a battery. */
}
if (pct > this->percent_left) {
choose = true;
@@ -207,15 +200,14 @@ PowerX11::check_proc_acpi_battery(const char * node, bool * have_battery, bool *
}
}
-void PowerX11::check_proc_acpi_ac_adapter(const char * node, bool * have_ac)
-{
+void PowerX11::check_proc_acpi_ac_adapter(const char *node, bool *have_ac) {
const char *base = proc_acpi_ac_adapter_path;
char state[256];
char *ptr = NULL;
char *key = NULL;
char *val = NULL;
- if (!read_power_file(base, node, "state", state, sizeof (state))) {
+ if (!read_power_file(base, node, "state", state, sizeof(state))) {
return;
}
@@ -231,9 +223,7 @@ void PowerX11::check_proc_acpi_ac_adapter(const char * node, bool * have_ac)
}
}
-
-bool PowerX11::GetPowerInfo_Linux_proc_acpi()
-{
+bool PowerX11::GetPowerInfo_Linux_proc_acpi() {
String node;
DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
bool have_battery = false;
@@ -244,16 +234,15 @@ bool PowerX11::GetPowerInfo_Linux_proc_acpi()
this->percent_left = -1;
this->power_state = POWERSTATE_UNKNOWN;
-
dirp->change_dir(proc_acpi_battery_path);
dirp->list_dir_begin();
if (dirp == NULL) {
- return false; /* can't use this interface. */
+ return false; /* can't use this interface. */
} else {
node = dirp->get_next();
while (node != "") {
- check_proc_acpi_battery(node.utf8().get_data(), &have_battery, &charging/*, seconds, percent*/);
+ check_proc_acpi_battery(node.utf8().get_data(), &have_battery, &charging /*, seconds, percent*/);
node = dirp->get_next();
}
memdelete(dirp);
@@ -262,7 +251,7 @@ bool PowerX11::GetPowerInfo_Linux_proc_acpi()
dirp->change_dir(proc_acpi_ac_adapter_path);
dirp->list_dir_begin();
if (dirp == NULL) {
- return false; /* can't use this interface. */
+ return false; /* can't use this interface. */
} else {
node = dirp->get_next();
while (node != "") {
@@ -282,16 +271,14 @@ bool PowerX11::GetPowerInfo_Linux_proc_acpi()
this->power_state = POWERSTATE_ON_BATTERY;
}
- return true; /* definitive answer. */
+ return true; /* definitive answer. */
}
-
-bool PowerX11::next_string(char **_ptr, char **_str)
-{
+bool PowerX11::next_string(char **_ptr, char **_str) {
char *ptr = *_ptr;
char *str = *_str;
- while (*ptr == ' ') { /* skip any spaces... */
+ while (*ptr == ' ') { /* skip any spaces... */
ptr++;
}
@@ -311,67 +298,65 @@ bool PowerX11::next_string(char **_ptr, char **_str)
return true;
}
-bool PowerX11::int_string(char *str, int *val)
-{
+bool PowerX11::int_string(char *str, int *val) {
String sval = str;
*val = sval.to_int();
return (*str != '\0');
}
/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
-bool PowerX11::GetPowerInfo_Linux_proc_apm()
-{
+bool PowerX11::GetPowerInfo_Linux_proc_apm() {
bool need_details = false;
int ac_status = 0;
int battery_status = 0;
int battery_flag = 0;
int battery_percent = 0;
int battery_time = 0;
- FileAccessRef fd = FileAccess::open(proc_apm_path,FileAccess::READ);
+ FileAccessRef fd = FileAccess::open(proc_apm_path, FileAccess::READ);
char buf[128];
char *ptr = &buf[0];
char *str = NULL;
ssize_t br;
if (!fd) {
- return false; /* can't use this interface. */
+ return false; /* can't use this interface. */
}
- br = fd->get_buffer(reinterpret_cast<uint8_t*>(buf), sizeof (buf) - 1);
+ br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), sizeof(buf) - 1);
fd->close();
if (br < 0) {
return false;
}
- buf[br] = '\0'; /* null-terminate the string. */
- if (!next_string(&ptr, &str)) { /* driver version */
+ buf[br] = '\0'; /* null-terminate the string. */
+ if (!next_string(&ptr, &str)) { /* driver version */
return false;
}
- if (!next_string(&ptr, &str)) { /* BIOS version */
+ if (!next_string(&ptr, &str)) { /* BIOS version */
return false;
}
- if (!next_string(&ptr, &str)) { /* APM flags */
+ if (!next_string(&ptr, &str)) { /* APM flags */
return false;
}
- if (!next_string(&ptr, &str)) { /* AC line status */
+ if (!next_string(&ptr, &str)) { /* AC line status */
return false;
} else if (!int_string(str, &ac_status)) {
return false;
}
- if (!next_string(&ptr, &str)) { /* battery status */
+ if (!next_string(&ptr, &str)) { /* battery status */
return false;
} else if (!int_string(str, &battery_status)) {
return false;
}
- if (!next_string(&ptr, &str)) { /* battery flag */
+ if (!next_string(&ptr, &str)) { /* battery flag */
return false;
} else if (!int_string(str, &battery_flag)) {
return false;
}
- if (!next_string(&ptr, &str)) { /* remaining battery life percent */
+ if (!next_string(&ptr, &str)) { /* remaining battery life percent */
return false;
}
String sstr = str;
@@ -382,13 +367,13 @@ bool PowerX11::GetPowerInfo_Linux_proc_apm()
return false;
}
- if (!next_string(&ptr, &str)) { /* remaining battery life time */
+ if (!next_string(&ptr, &str)) { /* remaining battery life time */
return false;
} else if (!int_string(str, &battery_time)) {
return false;
}
- if (!next_string(&ptr, &str)) { /* remaining battery life time units */
+ if (!next_string(&ptr, &str)) { /* remaining battery life time units */
return false;
} else if (String(str) == "min") {
battery_time *= 60;
@@ -396,13 +381,13 @@ bool PowerX11::GetPowerInfo_Linux_proc_apm()
if (battery_flag == 0xFF) { /* unknown state */
this->power_state = POWERSTATE_UNKNOWN;
- } else if (battery_flag & (1 << 7)) { /* no battery */
+ } else if (battery_flag & (1 << 7)) { /* no battery */
this->power_state = POWERSTATE_NO_BATTERY;
- } else if (battery_flag & (1 << 3)) { /* charging */
+ } else if (battery_flag & (1 << 3)) { /* charging */
this->power_state = POWERSTATE_CHARGING;
need_details = true;
} else if (ac_status == 1) {
- this->power_state = POWERSTATE_CHARGED; /* on AC, not charging. */
+ this->power_state = POWERSTATE_CHARGED; /* on AC, not charging. */
need_details = true;
} else {
this->power_state = POWERSTATE_ON_BATTERY;
@@ -415,10 +400,10 @@ bool PowerX11::GetPowerInfo_Linux_proc_apm()
const int pct = battery_percent;
const int secs = battery_time;
- if (pct >= 0) { /* -1 == unknown */
+ if (pct >= 0) { /* -1 == unknown */
this->percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
}
- if (secs >= 0) { /* -1 == unknown */
+ if (secs >= 0) { /* -1 == unknown */
this->nsecs_left = secs;
}
}
@@ -428,9 +413,8 @@ bool PowerX11::GetPowerInfo_Linux_proc_apm()
/* !!! FIXME: implement d-bus queries to org.freedesktop.UPower. */
-bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, int *seconds, int *percent*/)
-{
- const char* base = sys_class_power_supply_path;
+bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, int *seconds, int *percent*/) {
+ const char *base = sys_class_power_supply_path;
String name;
DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
@@ -441,7 +425,7 @@ bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, in
return false;
}
- this->power_state = POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
+ this->power_state = POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
this->nsecs_left = -1;
this->percent_left = -1;
@@ -456,24 +440,24 @@ bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, in
if ((name == ".") || (name == "..")) {
name = dirp->get_next();
- continue; //skip these, of course.
+ continue; //skip these, of course.
} else {
- if (!read_power_file(base, name.utf8().get_data(), "type", str, sizeof (str))) {
+ if (!read_power_file(base, name.utf8().get_data(), "type", str, sizeof(str))) {
name = dirp->get_next();
- continue; // Don't know _what_ we're looking at. Give up on it.
+ continue; // Don't know _what_ we're looking at. Give up on it.
} else {
if (String(str) != "Battery\n") {
name = dirp->get_next();
- continue; // we don't care about UPS and such.
+ continue; // we don't care about UPS and such.
}
}
}
/* some drivers don't offer this, so if it's not explicitly reported assume it's present. */
- if (read_power_file(base, name.utf8().get_data(), "present", str, sizeof (str)) && (String(str) == "0\n")) {
+ if (read_power_file(base, name.utf8().get_data(), "present", str, sizeof(str)) && (String(str) == "0\n")) {
st = POWERSTATE_NO_BATTERY;
- } else if (!read_power_file(base, name.utf8().get_data(), "status", str, sizeof (str))) {
- st = POWERSTATE_UNKNOWN; /* uh oh */
+ } else if (!read_power_file(base, name.utf8().get_data(), "status", str, sizeof(str))) {
+ st = POWERSTATE_UNKNOWN; /* uh oh */
} else if (String(str) == "Charging\n") {
st = POWERSTATE_CHARGING;
} else if (String(str) == "Discharging\n") {
@@ -481,21 +465,21 @@ bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, in
} else if ((String(str) == "Full\n") || (String(str) == "Not charging\n")) {
st = POWERSTATE_CHARGED;
} else {
- st = POWERSTATE_UNKNOWN; /* uh oh */
+ st = POWERSTATE_UNKNOWN; /* uh oh */
}
- if (!read_power_file(base, name.utf8().get_data(), "capacity", str, sizeof (str))) {
+ if (!read_power_file(base, name.utf8().get_data(), "capacity", str, sizeof(str))) {
pct = -1;
} else {
pct = String(str).to_int();
pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
}
- if (!read_power_file(base, name.utf8().get_data(), "time_to_empty_now", str, sizeof (str))) {
+ if (!read_power_file(base, name.utf8().get_data(), "time_to_empty_now", str, sizeof(str))) {
secs = -1;
} else {
secs = String(str).to_int();
- secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
+ secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
}
/*
@@ -504,7 +488,7 @@ bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, in
*/
if ((secs < 0) && (this->nsecs_left < 0)) {
if ((pct < 0) && (this->percent_left < 0)) {
- choose = true; /* at least we know there's a battery. */
+ choose = true; /* at least we know there's a battery. */
} else if (pct > this->percent_left) {
choose = true;
}
@@ -522,26 +506,24 @@ bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, in
}
memdelete(dirp);
- return true; /* don't look any further*/
+ return true; /* don't look any further*/
}
-
-
-bool PowerX11::UpdatePowerInfo()
-{
- if (GetPowerInfo_Linux_sys_class_power_supply()) { // try method 1
+bool PowerX11::UpdatePowerInfo() {
+ if (GetPowerInfo_Linux_sys_class_power_supply()) { // try method 1
return true;
}
- if (GetPowerInfo_Linux_proc_acpi()) { // try further
+ if (GetPowerInfo_Linux_proc_acpi()) { // try further
return true;
}
- if (GetPowerInfo_Linux_proc_apm()) { // try even further
+ if (GetPowerInfo_Linux_proc_apm()) { // try even further
return true;
}
return false;
}
-PowerX11::PowerX11() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
+PowerX11::PowerX11()
+ : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
}
PowerX11::~PowerX11() {
@@ -550,8 +532,7 @@ PowerX11::~PowerX11() {
PowerState PowerX11::get_power_state() {
if (UpdatePowerInfo()) {
return power_state;
- }
- else {
+ } else {
return POWERSTATE_UNKNOWN;
}
}
@@ -559,8 +540,7 @@ PowerState PowerX11::get_power_state() {
int PowerX11::get_power_seconds_left() {
if (UpdatePowerInfo()) {
return nsecs_left;
- }
- else {
+ } else {
return -1;
}
}
@@ -568,8 +548,7 @@ int PowerX11::get_power_seconds_left() {
int PowerX11::get_power_percent_left() {
if (UpdatePowerInfo()) {
return percent_left;
- }
- else {
+ } else {
return -1;
}
}
diff --git a/platform/x11/power_x11.h b/platform/x11/power_x11.h
index 6efb2de348..7693a5b022 100644
--- a/platform/x11/power_x11.h
+++ b/platform/x11/power_x11.h
@@ -34,7 +34,6 @@
#include "os/file_access.h"
#include "os/power.h"
-
class PowerX11 {
private:
@@ -42,12 +41,11 @@ private:
int percent_left;
PowerState power_state;
-
- FileAccessRef open_power_file(const char* base, const char* node, const char* key);
- bool read_power_file(const char* base, const char* node, const char* key, char* buf, size_t buflen);
+ FileAccessRef open_power_file(const char *base, const char *node, const char *key);
+ bool read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen);
bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val);
- void check_proc_acpi_battery(const char * node, bool * have_battery, bool * charging);
- void check_proc_acpi_ac_adapter(const char * node, bool * have_ac);
+ void check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging);
+ void check_proc_acpi_ac_adapter(const char *node, bool *have_ac);
bool GetPowerInfo_Linux_proc_acpi();
bool next_string(char **_ptr, char **_str);
bool int_string(char *str, int *val);
@@ -55,7 +53,6 @@ private:
bool GetPowerInfo_Linux_sys_class_power_supply();
bool UpdatePowerInfo();
-
public:
PowerX11();
virtual ~PowerX11();