entry_x11.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include "entry_p.h"
  6. #if ENTRY_CONFIG_USE_NATIVE && (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI)
  7. #define XK_MISCELLANY
  8. #define XK_LATIN1
  9. #include <X11/keysymdef.h>
  10. #include <X11/Xlib.h> // will include X11 which #defines None... Don't mess with order of includes.
  11. #include <bgfx/bgfxplatform.h>
  12. #undef None
  13. #include <bx/thread.h>
  14. #include <bx/os.h>
  15. #include <bx/handlealloc.h>
  16. #include <string.h> // memset
  17. #include <string>
  18. #include <fcntl.h>
  19. namespace entry
  20. {
  21. #define JS_EVENT_BUTTON 0x01 /* button pressed/released */
  22. #define JS_EVENT_AXIS 0x02 /* joystick moved */
  23. #define JS_EVENT_INIT 0x80 /* initial state of device */
  24. struct JoystickEvent
  25. {
  26. uint32_t time; /* event timestamp in milliseconds */
  27. int16_t value; /* value */
  28. uint8_t type; /* event type */
  29. uint8_t number; /* axis/button number */
  30. };
  31. static Key::Enum s_translateButton[] =
  32. {
  33. Key::GamepadA,
  34. Key::GamepadB,
  35. Key::GamepadX,
  36. Key::GamepadY,
  37. Key::GamepadShoulderL,
  38. Key::GamepadShoulderR,
  39. Key::GamepadBack,
  40. Key::GamepadStart,
  41. Key::GamepadGuide,
  42. Key::GamepadThumbL,
  43. Key::GamepadThumbR,
  44. };
  45. static GamepadAxis::Enum s_translateAxis[] =
  46. {
  47. GamepadAxis::LeftX,
  48. GamepadAxis::LeftY,
  49. GamepadAxis::LeftZ,
  50. GamepadAxis::RightX,
  51. GamepadAxis::RightY,
  52. GamepadAxis::RightZ,
  53. };
  54. struct Joystick
  55. {
  56. Joystick()
  57. : m_fd(-1)
  58. {
  59. }
  60. void init()
  61. {
  62. m_fd = open("/dev/input/js0", O_RDONLY | O_NONBLOCK);
  63. memset(m_value, 0, sizeof(m_value) );
  64. // Deadzone values from xinput.h
  65. m_deadzone[GamepadAxis::LeftX ] =
  66. m_deadzone[GamepadAxis::LeftY ] = 7849;
  67. m_deadzone[GamepadAxis::RightX] =
  68. m_deadzone[GamepadAxis::RightY] = 8689;
  69. m_deadzone[GamepadAxis::LeftZ ] =
  70. m_deadzone[GamepadAxis::RightZ] = 30;
  71. }
  72. void shutdown()
  73. {
  74. if (-1 != m_fd)
  75. {
  76. close(m_fd);
  77. }
  78. }
  79. bool filter(GamepadAxis::Enum _axis, int32_t* _value)
  80. {
  81. const int32_t old = m_value[_axis];
  82. const int32_t deadzone = m_deadzone[_axis];
  83. int32_t value = *_value;
  84. value = value > deadzone || value < -deadzone ? value : 0;
  85. m_value[_axis] = value;
  86. *_value = value;
  87. return old != value;
  88. }
  89. bool update(EventQueue& _eventQueue)
  90. {
  91. if (-1 == m_fd)
  92. {
  93. return false;
  94. }
  95. JoystickEvent event;
  96. int32_t bytes = read(m_fd, &event, sizeof(JoystickEvent) );
  97. if (bytes != sizeof(JoystickEvent) )
  98. {
  99. return false;
  100. }
  101. WindowHandle defaultWindow = { 0 };
  102. GamepadHandle handle = { 0 };
  103. if (event.type & JS_EVENT_BUTTON)
  104. {
  105. if (event.number < BX_COUNTOF(s_translateButton) )
  106. {
  107. _eventQueue.postKeyEvent(defaultWindow, s_translateButton[event.number], 0, 0 != event.value);
  108. }
  109. }
  110. else if (event.type & JS_EVENT_AXIS)
  111. {
  112. if (event.number < BX_COUNTOF(s_translateAxis) )
  113. {
  114. GamepadAxis::Enum axis = s_translateAxis[event.number];
  115. int32_t value = event.value;
  116. if (filter(axis, &value) )
  117. {
  118. _eventQueue.postAxisEvent(defaultWindow, handle, axis, value);
  119. }
  120. }
  121. }
  122. return true;
  123. }
  124. int m_fd;
  125. int32_t m_value[GamepadAxis::Count];
  126. int32_t m_deadzone[GamepadAxis::Count];
  127. };
  128. static Joystick s_joystick;
  129. static uint8_t s_translateKey[512];
  130. static void initTranslateKey(uint16_t _xk, Key::Enum _key)
  131. {
  132. _xk += 256;
  133. BX_CHECK(_xk < BX_COUNTOF(s_translateKey), "Out of bounds %d.", _xk);
  134. s_translateKey[_xk&0x1ff] = (uint8_t)_key;
  135. }
  136. Key::Enum fromXk(uint16_t _xk)
  137. {
  138. _xk += 256;
  139. return 512 > _xk ? (Key::Enum)s_translateKey[_xk] : Key::None;
  140. }
  141. struct MainThreadEntry
  142. {
  143. int m_argc;
  144. char** m_argv;
  145. static int32_t threadFunc(void* _userData);
  146. };
  147. struct Msg
  148. {
  149. Msg()
  150. : m_x(0)
  151. , m_y(0)
  152. , m_width(0)
  153. , m_height(0)
  154. , m_flags(0)
  155. {
  156. }
  157. int32_t m_x;
  158. int32_t m_y;
  159. uint32_t m_width;
  160. uint32_t m_height;
  161. uint32_t m_flags;
  162. std::string m_title;
  163. };
  164. struct Context
  165. {
  166. Context()
  167. : m_modifiers(Modifier::None)
  168. , m_exit(false)
  169. {
  170. memset(s_translateKey, 0, sizeof(s_translateKey) );
  171. initTranslateKey(XK_Escape, Key::Esc);
  172. initTranslateKey(XK_Return, Key::Return);
  173. initTranslateKey(XK_Tab, Key::Tab);
  174. initTranslateKey(XK_BackSpace, Key::Backspace);
  175. initTranslateKey(XK_space, Key::Space);
  176. initTranslateKey(XK_Up, Key::Up);
  177. initTranslateKey(XK_Down, Key::Down);
  178. initTranslateKey(XK_Left, Key::Left);
  179. initTranslateKey(XK_Right, Key::Right);
  180. initTranslateKey(XK_Insert, Key::Insert);
  181. initTranslateKey(XK_Delete, Key::Delete);
  182. initTranslateKey(XK_Home, Key::Home);
  183. initTranslateKey(XK_KP_End, Key::End);
  184. initTranslateKey(XK_Page_Up, Key::PageUp);
  185. initTranslateKey(XK_Page_Down, Key::PageDown);
  186. initTranslateKey(XK_Print, Key::Print);
  187. initTranslateKey(XK_equal, Key::Plus);
  188. initTranslateKey(XK_minus, Key::Minus);
  189. initTranslateKey(XK_bracketleft, Key::LeftBracket);
  190. initTranslateKey(XK_bracketright, Key::RightBracket);
  191. initTranslateKey(XK_semicolon, Key::Semicolon);
  192. initTranslateKey(XK_apostrophe, Key::Quote);
  193. initTranslateKey(XK_comma, Key::Comma);
  194. initTranslateKey(XK_period, Key::Period);
  195. initTranslateKey(XK_slash, Key::Slash);
  196. initTranslateKey(XK_backslash, Key::Backslash);
  197. initTranslateKey(XK_grave, Key::Tilde);
  198. initTranslateKey(XK_F1, Key::F1);
  199. initTranslateKey(XK_F2, Key::F2);
  200. initTranslateKey(XK_F3, Key::F3);
  201. initTranslateKey(XK_F4, Key::F4);
  202. initTranslateKey(XK_F5, Key::F5);
  203. initTranslateKey(XK_F6, Key::F6);
  204. initTranslateKey(XK_F7, Key::F7);
  205. initTranslateKey(XK_F8, Key::F8);
  206. initTranslateKey(XK_F9, Key::F9);
  207. initTranslateKey(XK_F10, Key::F10);
  208. initTranslateKey(XK_F11, Key::F11);
  209. initTranslateKey(XK_F12, Key::F12);
  210. initTranslateKey(XK_KP_Insert, Key::NumPad0);
  211. initTranslateKey(XK_KP_End, Key::NumPad1);
  212. initTranslateKey(XK_KP_Down, Key::NumPad2);
  213. initTranslateKey(XK_KP_Page_Down, Key::NumPad3);
  214. initTranslateKey(XK_KP_Left, Key::NumPad4);
  215. initTranslateKey(XK_KP_Begin, Key::NumPad5);
  216. initTranslateKey(XK_KP_Right, Key::NumPad6);
  217. initTranslateKey(XK_KP_Home, Key::NumPad7);
  218. initTranslateKey(XK_KP_Up, Key::NumPad8);
  219. initTranslateKey(XK_KP_Page_Up, Key::NumPad9);
  220. initTranslateKey('0', Key::Key0);
  221. initTranslateKey('1', Key::Key1);
  222. initTranslateKey('2', Key::Key2);
  223. initTranslateKey('3', Key::Key3);
  224. initTranslateKey('4', Key::Key4);
  225. initTranslateKey('5', Key::Key5);
  226. initTranslateKey('6', Key::Key6);
  227. initTranslateKey('7', Key::Key7);
  228. initTranslateKey('8', Key::Key8);
  229. initTranslateKey('9', Key::Key9);
  230. initTranslateKey('a', Key::KeyA);
  231. initTranslateKey('b', Key::KeyB);
  232. initTranslateKey('c', Key::KeyC);
  233. initTranslateKey('d', Key::KeyD);
  234. initTranslateKey('e', Key::KeyE);
  235. initTranslateKey('f', Key::KeyF);
  236. initTranslateKey('g', Key::KeyG);
  237. initTranslateKey('h', Key::KeyH);
  238. initTranslateKey('i', Key::KeyI);
  239. initTranslateKey('j', Key::KeyJ);
  240. initTranslateKey('k', Key::KeyK);
  241. initTranslateKey('l', Key::KeyL);
  242. initTranslateKey('m', Key::KeyM);
  243. initTranslateKey('n', Key::KeyN);
  244. initTranslateKey('o', Key::KeyO);
  245. initTranslateKey('p', Key::KeyP);
  246. initTranslateKey('q', Key::KeyQ);
  247. initTranslateKey('r', Key::KeyR);
  248. initTranslateKey('s', Key::KeyS);
  249. initTranslateKey('t', Key::KeyT);
  250. initTranslateKey('u', Key::KeyU);
  251. initTranslateKey('v', Key::KeyV);
  252. initTranslateKey('w', Key::KeyW);
  253. initTranslateKey('x', Key::KeyX);
  254. initTranslateKey('y', Key::KeyY);
  255. initTranslateKey('z', Key::KeyZ);
  256. m_mx = 0;
  257. m_my = 0;
  258. m_mz = 0;
  259. }
  260. int32_t run(int _argc, char** _argv)
  261. {
  262. XInitThreads();
  263. m_display = XOpenDisplay(0);
  264. int32_t screen = DefaultScreen(m_display);
  265. m_depth = DefaultDepth(m_display, screen);
  266. m_visual = DefaultVisual(m_display, screen);
  267. m_root = RootWindow(m_display, screen);
  268. memset(&m_windowAttrs, 0, sizeof(m_windowAttrs) );
  269. m_windowAttrs.background_pixmap = 0;
  270. m_windowAttrs.border_pixel = 0;
  271. m_windowAttrs.event_mask = 0
  272. | ButtonPressMask
  273. | ButtonReleaseMask
  274. | ExposureMask
  275. | KeyPressMask
  276. | KeyReleaseMask
  277. | PointerMotionMask
  278. | StructureNotifyMask
  279. ;
  280. m_windowAlloc.alloc();
  281. m_window[0] = XCreateWindow(m_display
  282. , m_root
  283. , 0, 0
  284. , ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, 0
  285. , m_depth
  286. , InputOutput
  287. , m_visual
  288. , CWBorderPixel|CWEventMask
  289. , &m_windowAttrs
  290. );
  291. // Clear window to black.
  292. XSetWindowAttributes attr;
  293. memset(&attr, 0, sizeof(attr) );
  294. XChangeWindowAttributes(m_display, m_window[0], CWBackPixel, &attr);
  295. const char* wmDeleteWindowName = "WM_DELETE_WINDOW";
  296. Atom wmDeleteWindow;
  297. XInternAtoms(m_display, (char **)&wmDeleteWindowName, 1, False, &wmDeleteWindow);
  298. XSetWMProtocols(m_display, m_window[0], &wmDeleteWindow, 1);
  299. XMapWindow(m_display, m_window[0]);
  300. XStoreName(m_display, m_window[0], "BGFX");
  301. XIM im;
  302. im = XOpenIM(m_display, NULL, NULL, NULL);
  303. XIC ic;
  304. ic = XCreateIC(im
  305. , XNInputStyle
  306. , 0
  307. | XIMPreeditNothing
  308. | XIMStatusNothing
  309. , XNClientWindow
  310. , m_window[0]
  311. , NULL
  312. );printf("x0\n");
  313. //
  314. bgfx::x11SetDisplayWindow(m_display, m_window[0]);
  315. MainThreadEntry mte;
  316. mte.m_argc = _argc;
  317. mte.m_argv = _argv;
  318. bx::Thread thread;
  319. thread.init(mte.threadFunc, &mte);
  320. WindowHandle defaultWindow = { 0 };
  321. m_eventQueue.postSizeEvent(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  322. s_joystick.init();
  323. while (!m_exit)
  324. {
  325. bool joystick = s_joystick.update(m_eventQueue);
  326. bool xpending = XPending(m_display);
  327. if (!xpending)
  328. {
  329. bx::sleep(joystick ? 8 : 16);
  330. }
  331. else
  332. {
  333. XEvent event;
  334. XNextEvent(m_display, &event);
  335. switch (event.type)
  336. {
  337. case Expose:
  338. break;
  339. case ClientMessage:
  340. if ( (Atom)event.xclient.data.l[0] == wmDeleteWindow)
  341. {
  342. m_eventQueue.postExitEvent();
  343. }
  344. break;
  345. case ButtonPress:
  346. case ButtonRelease:
  347. {
  348. const XButtonEvent& xbutton = event.xbutton;
  349. MouseButton::Enum mb = MouseButton::None;
  350. switch (xbutton.button)
  351. {
  352. case Button1: mb = MouseButton::Left; break;
  353. case Button2: mb = MouseButton::Middle; break;
  354. case Button3: mb = MouseButton::Right; break;
  355. case Button4: ++m_mz; break;
  356. case Button5: --m_mz; break;
  357. }
  358. WindowHandle handle = findHandle(xbutton.window);
  359. if (MouseButton::None != mb)
  360. {
  361. m_eventQueue.postMouseEvent(handle
  362. , xbutton.x
  363. , xbutton.y
  364. , 0
  365. , mb
  366. , event.type == ButtonPress
  367. );
  368. }
  369. else
  370. {
  371. m_eventQueue.postMouseEvent(handle
  372. , m_mx
  373. , m_my
  374. , m_mz
  375. );
  376. }
  377. }
  378. break;
  379. case MotionNotify:
  380. {
  381. const XMotionEvent& xmotion = event.xmotion;
  382. WindowHandle handle = findHandle(xmotion.window);
  383. m_mx = xmotion.x;
  384. m_my = xmotion.y;
  385. m_eventQueue.postMouseEvent(handle
  386. , m_mx
  387. , m_my
  388. , m_mz
  389. );
  390. }
  391. break;
  392. case KeyPress:
  393. case KeyRelease:
  394. {
  395. XKeyEvent& xkey = event.xkey;
  396. KeySym keysym = XLookupKeysym(&xkey, 0);
  397. switch (keysym)
  398. {
  399. case XK_Meta_L: setModifier(Modifier::LeftMeta, KeyPress == event.type); break;
  400. case XK_Meta_R: setModifier(Modifier::RightMeta, KeyPress == event.type); break;
  401. case XK_Control_L: setModifier(Modifier::LeftCtrl, KeyPress == event.type); break;
  402. case XK_Control_R: setModifier(Modifier::RightCtrl, KeyPress == event.type); break;
  403. case XK_Shift_L: setModifier(Modifier::LeftShift, KeyPress == event.type); break;
  404. case XK_Shift_R: setModifier(Modifier::RightShift, KeyPress == event.type); break;
  405. case XK_Alt_L: setModifier(Modifier::LeftAlt, KeyPress == event.type); break;
  406. case XK_Alt_R: setModifier(Modifier::RightAlt, KeyPress == event.type); break;
  407. default:
  408. {
  409. WindowHandle handle = findHandle(xkey.window);
  410. if (KeyPress == event.type)
  411. {
  412. Status status = 0;
  413. uint8_t utf8[4];
  414. int len = Xutf8LookupString(ic, &xkey, (char*)utf8, sizeof(utf8), &keysym, &status);
  415. switch (status)
  416. {
  417. case XLookupChars:
  418. case XLookupBoth:
  419. if (0 != len)
  420. {
  421. m_eventQueue.postCharEvent(handle, len, utf8);
  422. }
  423. break;
  424. default:
  425. break;
  426. }
  427. }
  428. Key::Enum key = fromXk(keysym);
  429. if (Key::None != key)
  430. {
  431. m_eventQueue.postKeyEvent(handle, key, m_modifiers, KeyPress == event.type);
  432. }
  433. }
  434. break;
  435. }
  436. }
  437. break;
  438. case ConfigureNotify:
  439. {
  440. const XConfigureEvent& xev = event.xconfigure;
  441. WindowHandle handle = findHandle(xev.window);
  442. if (isValid(handle) )
  443. {
  444. m_eventQueue.postSizeEvent(handle, xev.width, xev.height);
  445. }
  446. }
  447. break;
  448. }
  449. }
  450. }
  451. thread.shutdown();
  452. s_joystick.shutdown();
  453. XDestroyIC(ic);
  454. XCloseIM(im);
  455. XUnmapWindow(m_display, m_window[0]);
  456. XDestroyWindow(m_display, m_window[0]);
  457. return thread.getExitCode();
  458. }
  459. void setModifier(Modifier::Enum _modifier, bool _set)
  460. {
  461. m_modifiers &= ~_modifier;
  462. m_modifiers |= _set ? _modifier : 0;
  463. }
  464. void createWindow(WindowHandle _handle, Msg* msg)
  465. {
  466. Window window = XCreateWindow(m_display
  467. , m_root
  468. , msg->m_x
  469. , msg->m_y
  470. , msg->m_width
  471. , msg->m_height
  472. , 0
  473. , m_depth
  474. , InputOutput
  475. , m_visual
  476. , CWBorderPixel|CWEventMask
  477. , &m_windowAttrs
  478. );
  479. m_window[_handle.idx] = window;
  480. // Clear window to black.
  481. XSetWindowAttributes attr;
  482. memset(&attr, 0, sizeof(attr) );
  483. XChangeWindowAttributes(m_display, window, CWBackPixel, &attr);
  484. const char* wmDeleteWindowName = "WM_DELETE_WINDOW";
  485. Atom wmDeleteWindow;
  486. XInternAtoms(m_display, (char **)&wmDeleteWindowName, 1, False, &wmDeleteWindow);
  487. XSetWMProtocols(m_display, window, &wmDeleteWindow, 1);
  488. XMapWindow(m_display, window);
  489. XStoreName(m_display, window, msg->m_title.c_str() );
  490. m_eventQueue.postSizeEvent(_handle, msg->m_width, msg->m_height);
  491. union cast
  492. {
  493. void* p;
  494. ::Window w;
  495. };
  496. cast c;
  497. c.w = window;
  498. m_eventQueue.postWindowEvent(_handle, c.p);
  499. delete msg;
  500. }
  501. WindowHandle findHandle(Window _window)
  502. {
  503. bx::LwMutexScope scope(m_lock);
  504. for (uint32_t ii = 0, num = m_windowAlloc.getNumHandles(); ii < num; ++ii)
  505. {
  506. uint16_t idx = m_windowAlloc.getHandleAt(ii);
  507. if (_window == m_window[idx])
  508. {
  509. WindowHandle handle = { idx };
  510. return handle;
  511. }
  512. }
  513. WindowHandle invalid = { UINT16_MAX };
  514. return invalid;
  515. }
  516. uint8_t m_modifiers;
  517. bool m_exit;
  518. int32_t m_mx;
  519. int32_t m_my;
  520. int32_t m_mz;
  521. EventQueue m_eventQueue;
  522. bx::LwMutex m_lock;
  523. bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
  524. int32_t m_depth;
  525. Visual* m_visual;
  526. Window m_root;
  527. XSetWindowAttributes m_windowAttrs;
  528. Display* m_display;
  529. Window m_window[ENTRY_CONFIG_MAX_WINDOWS];
  530. uint32_t m_flags[ENTRY_CONFIG_MAX_WINDOWS];
  531. };
  532. static Context s_ctx;
  533. int32_t MainThreadEntry::threadFunc(void* _userData)
  534. {
  535. MainThreadEntry* self = (MainThreadEntry*)_userData;
  536. int32_t result = main(self->m_argc, self->m_argv);
  537. s_ctx.m_exit = true;
  538. return result;
  539. }
  540. const Event* poll()
  541. {
  542. return s_ctx.m_eventQueue.poll();
  543. }
  544. const Event* poll(WindowHandle _handle)
  545. {
  546. return s_ctx.m_eventQueue.poll(_handle);
  547. }
  548. void release(const Event* _event)
  549. {
  550. s_ctx.m_eventQueue.release(_event);
  551. }
  552. WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
  553. {
  554. bx::LwMutexScope scope(s_ctx.m_lock);
  555. WindowHandle handle = { s_ctx.m_windowAlloc.alloc() };
  556. if (isValid(handle) )
  557. {
  558. Msg* msg = new Msg;
  559. msg->m_x = _x;
  560. msg->m_y = _y;
  561. msg->m_width = _width;
  562. msg->m_height = _height;
  563. msg->m_title = _title;
  564. msg->m_flags = _flags;
  565. s_ctx.createWindow(handle, msg);
  566. }
  567. return handle;
  568. }
  569. void destroyWindow(WindowHandle _handle)
  570. {
  571. if (isValid(_handle) )
  572. {
  573. s_ctx.m_eventQueue.postWindowEvent(_handle, NULL);
  574. XUnmapWindow(s_ctx.m_display, s_ctx.m_window[_handle.idx]);
  575. XDestroyWindow(s_ctx.m_display, s_ctx.m_window[_handle.idx]);
  576. bx::LwMutexScope scope(s_ctx.m_lock);
  577. s_ctx.m_windowAlloc.free(_handle.idx);
  578. }
  579. }
  580. void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
  581. {
  582. Display* display = s_ctx.m_display;
  583. Window window = s_ctx.m_window[_handle.idx];
  584. XMoveWindow(display, window, _x, _y);
  585. }
  586. void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
  587. {
  588. Display* display = s_ctx.m_display;
  589. Window window = s_ctx.m_window[_handle.idx];
  590. XResizeWindow(display, window, int32_t(_width), int32_t(_height) );
  591. }
  592. void setWindowTitle(WindowHandle _handle, const char* _title)
  593. {
  594. Display* display = s_ctx.m_display;
  595. Window window = s_ctx.m_window[_handle.idx];
  596. XStoreName(display, window, _title);
  597. }
  598. void toggleWindowFrame(WindowHandle _handle)
  599. {
  600. BX_UNUSED(_handle);
  601. }
  602. void toggleFullscreen(WindowHandle _handle)
  603. {
  604. BX_UNUSED(_handle);
  605. }
  606. void setMouseLock(WindowHandle _handle, bool _lock)
  607. {
  608. BX_UNUSED(_handle, _lock);
  609. }
  610. } // namespace entry
  611. int main(int _argc, char** _argv)
  612. {
  613. using namespace entry;
  614. return s_ctx.run(_argc, _argv);
  615. }
  616. #endif // ENTRY_CONFIG_USE_NATIVE && (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI)