diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_x11.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_x11.cpp | 126 |
1 files changed, 65 insertions, 61 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp index 7f1520b95c6..a5f4b3fa6da 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "entry_p.h" @@ -12,8 +12,6 @@ #include <X11/keysymdef.h> #include <X11/Xlib.h> // will include X11 which #defines None... Don't mess with order of includes. #include <X11/Xutil.h> -#include <bgfx/platform.h> - #include <unistd.h> // syscall #undef None @@ -31,18 +29,6 @@ namespace entry static const char* s_applicationName = "BGFX"; static const char* s_applicationClass = "bgfx"; - /// - inline void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL) - { - bgfx::PlatformData pd; - pd.ndt = _display; - pd.nwh = (void*)(uintptr_t)_window; - pd.context = _glx; - pd.backBuffer = NULL; - pd.backBufferDS = NULL; - bgfx::setPlatformData(pd); - } - #define JS_EVENT_BUTTON 0x01 /* button pressed/released */ #define JS_EVENT_AXIS 0x02 /* joystick moved */ #define JS_EVENT_INIT 0x80 /* initial state of device */ @@ -346,7 +332,13 @@ namespace entry int32_t run(int _argc, const char* const* _argv) { XInitThreads(); + m_display = XOpenDisplay(NULL); + if (NULL == m_display) + { + bx::printf("XOpenDisplay failed: DISPLAY environment variable must be set.\n\n"); + return bx::kExitFailure; + } int32_t screen = DefaultScreen(m_display); m_depth = DefaultDepth(m_display, screen); @@ -355,29 +347,29 @@ namespace entry bx::memSet(&m_windowAttrs, 0, sizeof(m_windowAttrs) ); m_windowAttrs.background_pixel = 0; - m_windowAttrs.border_pixel = 0; + m_windowAttrs.border_pixel = 0; m_windowAttrs.bit_gravity = StaticGravity; - m_windowAttrs.event_mask = 0 - | ButtonPressMask - | ButtonReleaseMask - | ExposureMask - | KeyPressMask - | KeyReleaseMask - | PointerMotionMask - | StructureNotifyMask - ; + m_windowAttrs.event_mask = 0 + | ButtonPressMask + | ButtonReleaseMask + | ExposureMask + | KeyPressMask + | KeyReleaseMask + | PointerMotionMask + | StructureNotifyMask + ; m_windowAlloc.alloc(); - m_window[0] = XCreateWindow(m_display - , m_root - , 0, 0 - , 1, 1, 0 - , m_depth - , InputOutput - , m_visual - , CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity - , &m_windowAttrs - ); + m_window[0] = XCreateWindow( + m_display + , m_root + , 0, 0, 1, 1, 0 + , m_depth + , InputOutput + , m_visual + , CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity + , &m_windowAttrs + ); const char* wmDeleteWindowName = "WM_DELETE_WINDOW"; Atom wmDeleteWindow; @@ -397,18 +389,16 @@ namespace entry im = XOpenIM(m_display, NULL, NULL, NULL); XIC ic; - ic = XCreateIC(im - , XNInputStyle - , 0 - | XIMPreeditNothing - | XIMStatusNothing - , XNClientWindow - , m_window[0] - , NULL - ); - - // - x11SetDisplayWindow(m_display, m_window[0]); + ic = XCreateIC( + im + , XNInputStyle + , 0 + | XIMPreeditNothing + | XIMStatusNothing + , XNClientWindow + , m_window[0] + , NULL + ); MainThreadEntry mte; mte.m_argc = _argc; @@ -574,6 +564,9 @@ namespace entry XUnmapWindow(m_display, m_window[0]); XDestroyWindow(m_display, m_window[0]); + XCloseDisplay(m_display); + m_display = NULL; + return thread.getExitCode(); } @@ -585,19 +578,20 @@ namespace entry void createWindow(WindowHandle _handle, Msg* msg) { - Window window = XCreateWindow(m_display - , m_root - , msg->m_x - , msg->m_y - , msg->m_width - , msg->m_height - , 0 - , m_depth - , InputOutput - , m_visual - , CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity - , &m_windowAttrs - ); + Window window = XCreateWindow( + m_display + , m_root + , msg->m_x + , msg->m_y + , msg->m_width + , msg->m_height + , 0 + , m_depth + , InputOutput + , m_visual + , CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity + , &m_windowAttrs + ); m_window[_handle.idx] = window; const char* wmDeleteWindowName = "WM_DELETE_WINDOW"; @@ -767,6 +761,16 @@ namespace entry BX_UNUSED(_handle, _lock); } + void* getNativeWindowHandle(WindowHandle _handle) + { + return (void*)(uintptr_t)s_ctx.m_window[_handle.idx]; + } + + void* getNativeDisplayHandle() + { + return s_ctx.m_display; + } + } // namespace entry int main(int _argc, const char* const* _argv) |