diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_x11.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_x11.cpp | 118 |
1 files changed, 77 insertions, 41 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp index 02d14316952..16b7af4ffa1 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp @@ -11,7 +11,7 @@ #define XK_LATIN1 #include <X11/keysymdef.h> #include <X11/Xlib.h> // will include X11 which #defines None... Don't mess with order of includes. -#include <bgfxplatform.h> +#include <bgfx/bgfxplatform.h> #undef None #include <bx/thread.h> @@ -63,6 +63,11 @@ namespace entry struct Joystick { + Joystick() + : m_fd(-1) + { + } + void init() { m_fd = open("/dev/input/js0", O_RDONLY | O_NONBLOCK); @@ -80,7 +85,7 @@ namespace entry void shutdown() { - if (0 != m_fd) + if (-1 != m_fd) { close(m_fd); } @@ -99,7 +104,7 @@ namespace entry bool update(EventQueue& _eventQueue) { - if (0 == m_fd) + if (-1 == m_fd) { return false; } @@ -202,13 +207,24 @@ namespace entry initTranslateKey(XK_Down, Key::Down); initTranslateKey(XK_Left, Key::Left); initTranslateKey(XK_Right, Key::Right); - initTranslateKey(XK_Page_Up, Key::PageUp); - initTranslateKey(XK_Page_Down, Key::PageUp); + initTranslateKey(XK_Insert, Key::Insert); + initTranslateKey(XK_Delete, Key::Delete); initTranslateKey(XK_Home, Key::Home); initTranslateKey(XK_KP_End, Key::End); + initTranslateKey(XK_Page_Up, Key::PageUp); + initTranslateKey(XK_Page_Down, Key::PageDown); initTranslateKey(XK_Print, Key::Print); initTranslateKey(XK_equal, Key::Plus); initTranslateKey(XK_minus, Key::Minus); + initTranslateKey(XK_bracketleft, Key::LeftBracket); + initTranslateKey(XK_bracketright, Key::RightBracket); + initTranslateKey(XK_semicolon, Key::Semicolon); + initTranslateKey(XK_apostrophe, Key::Quote); + initTranslateKey(XK_comma, Key::Comma); + initTranslateKey(XK_period, Key::Period); + initTranslateKey(XK_slash, Key::Slash); + initTranslateKey(XK_backslash, Key::Backslash); + initTranslateKey(XK_grave, Key::Tilde); initTranslateKey(XK_F1, Key::F1); initTranslateKey(XK_F2, Key::F2); initTranslateKey(XK_F3, Key::F3); @@ -283,11 +299,10 @@ namespace entry m_visual = DefaultVisual(m_display, screen); m_root = RootWindow(m_display, screen); - XSetWindowAttributes windowAttrs; - memset(&windowAttrs, 0, sizeof(windowAttrs) ); - windowAttrs.background_pixmap = 0; - windowAttrs.border_pixel = 0; - windowAttrs.event_mask = 0 + memset(&m_windowAttrs, 0, sizeof(m_windowAttrs) ); + m_windowAttrs.background_pixmap = 0; + m_windowAttrs.border_pixel = 0; + m_windowAttrs.event_mask = 0 | ButtonPressMask | ButtonReleaseMask | ExposureMask @@ -306,7 +321,7 @@ namespace entry , InputOutput , m_visual , CWBorderPixel|CWEventMask - , &windowAttrs + , &m_windowAttrs ); // Clear window to black. @@ -322,6 +337,20 @@ namespace entry XMapWindow(m_display, m_window[0]); XStoreName(m_display, m_window[0], "BGFX"); + XIM im; + im = XOpenIM(m_display, NULL, NULL, NULL); + + XIC ic; + ic = XCreateIC(im + , XNInputStyle + , 0 + | XIMPreeditNothing + | XIMStatusNothing + , XNClientWindow + , m_window[0] + , NULL + ); + // bgfx::x11SetDisplayWindow(m_display, m_window[0]); @@ -433,10 +462,30 @@ namespace entry default: { + WindowHandle handle = findHandle(xkey.window); + if (KeyPress == event.type) + { + Status status = 0; + uint8_t utf8[4]; + int len = Xutf8LookupString(ic, &xkey, (char*)utf8, sizeof(utf8), &keysym, &status); + switch (status) + { + case XLookupChars: + case XLookupBoth: + if (0 != len) + { + m_eventQueue.postCharEvent(handle, len, utf8); + } + break; + + default: + break; + } + } + Key::Enum key = fromXk(keysym); if (Key::None != key) { - WindowHandle handle = findHandle(xkey.window); m_eventQueue.postKeyEvent(handle, key, m_modifiers, KeyPress == event.type); } } @@ -463,10 +512,13 @@ namespace entry s_joystick.shutdown(); + XDestroyIC(ic); + XCloseIM(im); + XUnmapWindow(m_display, m_window[0]); XDestroyWindow(m_display, m_window[0]); - return EXIT_SUCCESS; + return thread.getExitCode(); } void setModifier(Modifier::Enum _modifier, bool _set) @@ -477,21 +529,6 @@ namespace entry void createWindow(WindowHandle _handle, Msg* msg) { - XSetWindowAttributes windowAttrs; - memset(&windowAttrs, 0, sizeof(windowAttrs) ); - windowAttrs.background_pixmap = 0; - windowAttrs.border_pixel = 0; - windowAttrs.event_mask = 0 - | ButtonPressMask - | ButtonReleaseMask - | ExposureMask - | KeyPressMask - | KeyReleaseMask - | PointerMotionMask - | ResizeRedirectMask - | StructureNotifyMask - ; - Window window = XCreateWindow(m_display , m_root , msg->m_x @@ -503,7 +540,7 @@ namespace entry , InputOutput , m_visual , CWBorderPixel|CWEventMask - , &windowAttrs + , &m_windowAttrs ); m_window[_handle.idx] = window; @@ -567,6 +604,8 @@ namespace entry Visual* m_visual; Window m_root; + XSetWindowAttributes m_windowAttrs; + Display* m_display; Window m_window[ENTRY_CONFIG_MAX_WINDOWS]; uint32_t m_flags[ENTRY_CONFIG_MAX_WINDOWS]; @@ -632,26 +671,23 @@ namespace entry void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y) { - BX_UNUSED(_handle, _x, _y); + Display* display = s_ctx.m_display; + Window window = s_ctx.m_window[_handle.idx]; + XMoveWindow(display, window, _x, _y); } void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height) { - BX_UNUSED(_handle); - XResizeRequestEvent ev; - ev.type = ResizeRequest; - ev.serial = 0; - ev.send_event = true; - ev.display = s_ctx.m_display; - ev.window = s_ctx.m_window[0]; - ev.width = (int)_width; - ev.height = (int)_height; - XSendEvent(s_ctx.m_display, s_ctx.m_window[0], false, ResizeRedirectMask, (XEvent*)&ev); + Display* display = s_ctx.m_display; + Window window = s_ctx.m_window[_handle.idx]; + XResizeWindow(display, window, int32_t(_width), int32_t(_height) ); } void setWindowTitle(WindowHandle _handle, const char* _title) { - XStoreName(s_ctx.m_display, s_ctx.m_window[_handle.idx], _title); + Display* display = s_ctx.m_display; + Window window = s_ctx.m_window[_handle.idx]; + XStoreName(display, window, _title); } void toggleWindowFrame(WindowHandle _handle) |