You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1421 lines
43KB

  1. /* ----
  2. * ---- file : lglw_linux.c (**stub**)
  3. * ---- author : bsp
  4. * ---- legal : Distributed under terms of the MIT LICENSE (MIT).
  5. * ----
  6. * ---- Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * ---- of this software and associated documentation files (the "Software"), to deal
  8. * ---- in the Software without restriction, including without limitation the rights
  9. * ---- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * ---- copies of the Software, and to permit persons to whom the Software is
  11. * ---- furnished to do so, subject to the following conditions:
  12. * ----
  13. * ---- The above copyright notice and this permission notice shall be included in
  14. * ---- all copies or substantial portions of the Software.
  15. * ----
  16. * ---- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * ---- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * ---- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * ---- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * ---- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * ---- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * ---- THE SOFTWARE.
  23. * ----
  24. * ---- info : This is part of the "lglw" package.
  25. * ----
  26. * ---- created: 04Aug2018
  27. * ---- changed: 05Aug2018, 06Aug2018, 07Aug2018, 08Aug2018, 09Aug2018, 18Aug2018, 10Oct2018, 16Oct2018
  28. * ----
  29. * ----
  30. */
  31. #include "lglw.h"
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <X11/Xlib.h>
  36. #include <X11/Xutil.h>
  37. #include <X11/Xos.h>
  38. #include <GL/gl.h>
  39. #include <GL/glx.h>
  40. #ifdef ARCH_X64
  41. #include <sys/mman.h>
  42. #include <unistd.h>
  43. #endif // ARCH_X64
  44. #define Dprintf if(0);else printf
  45. // #define Dprintf if(1);else printf
  46. // ---------------------------------------------------------------------------- macros and defines
  47. #define LGLW(a) lglw_int_t *lglw = ((lglw_int_t*)(a))
  48. #define LGLW_DEFAULT_HIDDEN_W (800)
  49. #define LGLW_DEFAULT_HIDDEN_H (600)
  50. #define LGLW_MOUSE_TOUCH_LMB_TIMEOUT (250u)
  51. #define LGLW_MOUSE_TOUCH_RMB_TIMEOUT (500u)
  52. #define LGLW_MOUSE_TOUCH_RMB_STATE_IDLE (0u)
  53. #define LGLW_MOUSE_TOUCH_RMB_STATE_LMB (1u)
  54. #define LGLW_MOUSE_TOUCH_RMB_STATE_WAIT (2u)
  55. #define LGLW_MOUSE_TOUCH_RMB_STATE_RMB (3u)
  56. #define LGLW_MOUSE_TOUCH_RMB_MOVE_THRESHOLD (7u)
  57. #define sABS(x) (((x)>0)?(x):-(x))
  58. // ---------------------------------------------------------------------------- structs and typedefs
  59. typedef struct lglw_int_s {
  60. void *user_data; // arbitrary user data
  61. Display *xdsp;
  62. XVisualInfo *vi;
  63. Colormap cmap;
  64. Window parent_xwnd; // created by host
  65. struct {
  66. lglw_vec2i_t size;
  67. Window xwnd;
  68. } hidden;
  69. struct {
  70. lglw_vec2i_t size;
  71. Window xwnd;
  72. lglw_bool_t mapped;
  73. int32_t swap_interval;
  74. lglw_bool_t b_owner;
  75. } win;
  76. GLXContext ctx;
  77. struct {
  78. GLXContext ctx;
  79. GLXDrawable drw;
  80. } prev;
  81. struct {
  82. uint32_t kmod_state; // See LGLW_KMOD_xxx
  83. lglw_keyboard_fxn_t cbk;
  84. } keyboard;
  85. struct {
  86. lglw_vec2i_t p; // last seen mouse position
  87. uint32_t button_state;
  88. lglw_mouse_fxn_t cbk;
  89. struct {
  90. uint32_t mode;
  91. lglw_vec2i_t p; // grab-start mouse position
  92. lglw_bool_t b_queue_warp;
  93. lglw_vec2i_t last_p;
  94. } grab;
  95. struct {
  96. lglw_bool_t b_enable;
  97. lglw_bool_t b_update_queued;
  98. lglw_bool_t b_syn_rmb;
  99. uint32_t syn_rmb_hold_state; // see LGLW_MOUSE_TOUCH_RMB_STATE_xxx
  100. uint32_t hold_start_ms;
  101. lglw_vec2i_t hold_start_p;
  102. } touch;
  103. } mouse;
  104. struct {
  105. uint32_t state;
  106. lglw_focus_fxn_t cbk;
  107. } focus;
  108. struct {
  109. lglw_bool_t b_running;
  110. lglw_timer_fxn_t cbk;
  111. } timer;
  112. struct {
  113. lglw_dropfiles_fxn_t cbk;
  114. } dropfiles;
  115. struct {
  116. lglw_redraw_fxn_t cbk;
  117. } redraw;
  118. } lglw_int_t;
  119. // ---------------------------------------------------------------------------- module fxn fwd decls
  120. static lglw_bool_t loc_create_hidden_window (lglw_int_t *lglw, int32_t _w, int32_t _h);
  121. static void loc_destroy_hidden_window(lglw_int_t *lglw);
  122. static void loc_key_hook(lglw_int_t *lglw);
  123. static void loc_key_unhook(lglw_int_t *lglw);
  124. static lglw_bool_t loc_handle_key (lglw_int_t *lglw, lglw_bool_t _bPressed, uint32_t _vkey);
  125. // static lglw_bool_t loc_touchkeyboard_get_rect (RECT *rect);
  126. // static lglw_bool_t loc_touchkeyboard_is_visible (void);
  127. extern lglw_bool_t lglw_int_touchkeyboard_toggle (void);
  128. static void loc_handle_mouseleave (lglw_int_t *lglw);
  129. static void loc_handle_mouseenter (lglw_int_t *lglw);
  130. static void loc_handle_mousebutton (lglw_int_t *lglw, lglw_bool_t _bPressed, uint32_t _button);
  131. static void loc_handle_mousemotion (lglw_int_t *lglw);
  132. static void loc_handle_queued_mouse_warp (lglw_int_t *lglw);
  133. static void loc_touchinput_update (lglw_int_t *lglw);
  134. static void loc_enable_dropfiles (lglw_int_t *lglw, lglw_bool_t _bEnable);
  135. static void loc_eventProc (void *_xevent);
  136. static void loc_setProperty (Display *_display, Window _window, const char *_name, void *_value);
  137. static void *loc_getProperty (Display *_display, Window _window, const char *_name);
  138. static void loc_setEventProc (Display *display, Window window);
  139. // ---------------------------------------------------------------------------- module vars
  140. static lglw_int_t *khook_lglw = NULL; // currently key-hooked lglw instance (one at a time)
  141. // TODO: remove and/or improve debug logging for a debug build
  142. // ---------------------------------------------------------------------------- lglw_log
  143. static FILE *logfile;
  144. void lglw_log(const char *logData, ...) {
  145. fprintf(logfile, logData);
  146. fflush(logfile);
  147. printf(logData);
  148. }
  149. // TODO: remove, or maybe not in some specific use cases
  150. // ---------------------------------------------------------------------------- xerror_log
  151. static int xerror_handler(Display *display, XErrorEvent *error) {
  152. char error_text[1024];
  153. XGetErrorText(display, error->error_code, error_text, 1024);
  154. lglw_log("XERROR (%d): %s, %d, %d\n", error->error_code, error_text, error->request_code, error->minor_code);
  155. return 0;
  156. }
  157. // ---------------------------------------------------------------------------- lglw_init
  158. lglw_t lglw_init(int32_t _w, int32_t _h) {
  159. lglw_int_t *lglw = malloc(sizeof(lglw_int_t));
  160. printf("xxx lglw_init: sizeof(uint32_t)=%u sizeof(long)=%u sizeof(void*)=%u\n", sizeof(uint32_t), sizeof(long), sizeof(void*));
  161. // TODO: remove/improve
  162. logfile = fopen("/tmp/lglw_log.txt", "w");
  163. XSetErrorHandler(xerror_handler);
  164. XInitThreads(); // fix GL crash, see <https://forum.juce.com/t/linux-vst-opengl-crash-because-xinitthreads-not-called/22821>
  165. if(NULL != lglw)
  166. {
  167. memset(lglw, 0, sizeof(lglw_int_t));
  168. lglw_log("lglw:lglw_init: 1\n");
  169. if(_w <= 16)
  170. _w = LGLW_DEFAULT_HIDDEN_W;
  171. if(_h <= 16)
  172. _h = LGLW_DEFAULT_HIDDEN_H;
  173. lglw_log("lglw:lglw_init: 2\n");
  174. if(!loc_create_hidden_window(lglw, _w, _h))
  175. {
  176. free(lglw);
  177. lglw = NULL;
  178. }
  179. lglw_log("lglw:lglw_init: 3\n");
  180. }
  181. lglw_log("lglw:lglw_init: EXIT\n");
  182. return lglw;
  183. }
  184. // ---------------------------------------------------------------------------- lglw_exit
  185. void lglw_exit(lglw_t _lglw) {
  186. LGLW(_lglw);
  187. if(NULL != lglw)
  188. {
  189. lglw_log("lglw:lglw_exit: 1\n");
  190. loc_destroy_hidden_window(lglw);
  191. lglw_log("lglw:lglw_exit: 2\n");
  192. fclose(logfile);
  193. free(lglw);
  194. }
  195. }
  196. // ---------------------------------------------------------------------------- lglw_userdata_set
  197. void lglw_userdata_set(lglw_t _lglw, void *_userData) {
  198. LGLW(_lglw);
  199. if(NULL != lglw)
  200. {
  201. lglw_log("lglw:lglw_userdata_set: 1\n");
  202. lglw->user_data = _userData;
  203. }
  204. }
  205. // ---------------------------------------------------------------------------- lglw_userdata_get
  206. void *lglw_userdata_get(lglw_t _lglw) {
  207. LGLW(_lglw);
  208. if(NULL != lglw)
  209. {
  210. lglw_log("lglw:lglw_userdata_get: 1\n");
  211. return lglw->user_data;
  212. }
  213. return NULL;
  214. }
  215. // ---------------------------------------------------------------------------- loc_create_hidden_window
  216. static lglw_bool_t loc_create_hidden_window(lglw_int_t *lglw, int32_t _w, int32_t _h) {
  217. // TODO: compare to 'WindowClass' from Windows implementation
  218. lglw_log("lglw:loc_create_hidden_window: 1\n");
  219. XSetWindowAttributes swa;
  220. int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, None };
  221. int screen;
  222. lglw_log("lglw:loc_create_hidden_window: 2\n");
  223. lglw->xdsp = XOpenDisplay(NULL);
  224. screen = DefaultScreen(lglw->xdsp);
  225. lglw_log("lglw:loc_create_hidden_window: 3\n");
  226. lglw->vi = glXChooseVisual(lglw->xdsp, screen, attrib);
  227. lglw_log("lglw:loc_create_hidden_window: 4\n");
  228. if(NULL == lglw->vi)
  229. {
  230. lglw_log("[---] lglw: failed to find GLX Visual for hidden window\n");
  231. return LGLW_FALSE;
  232. }
  233. lglw_log("lglw:loc_create_hidden_window: 5\n");
  234. lglw->ctx = glXCreateContext(lglw->xdsp, lglw->vi, None, True);
  235. lglw_log("lglw:loc_create_hidden_window: 6\n");
  236. if(NULL == lglw->ctx)
  237. {
  238. lglw_log("[---] lglw: failed to create GLX Context for hidden window\n");
  239. return LGLW_FALSE;
  240. }
  241. lglw_log("lglw:loc_create_hidden_window: 7\n");
  242. lglw->cmap = XCreateColormap(lglw->xdsp, RootWindow(lglw->xdsp, lglw->vi->screen),
  243. lglw->vi->visual, AllocNone);
  244. lglw_log("lglw:loc_create_hidden_window: 8\n");
  245. swa.border_pixel = 0;
  246. swa.colormap = lglw->cmap;
  247. lglw->hidden.xwnd = XCreateWindow(lglw->xdsp, DefaultRootWindow(lglw->xdsp),
  248. 0, 0, LGLW_DEFAULT_HIDDEN_W, LGLW_DEFAULT_HIDDEN_H, 0, CopyFromParent, InputOutput,
  249. lglw->vi->visual, CWBorderPixel | CWColormap, &swa);
  250. lglw_log("lglw:loc_create_hidden_window: 9\n");
  251. XSetStandardProperties(lglw->xdsp, lglw->hidden.xwnd, "LGLW_hidden", "LGLW_hidden", None, NULL, 0, NULL);
  252. XSync(lglw->xdsp, False);
  253. lglw_log("lglw:loc_create_hidden_window: EXIT\n");
  254. lglw->hidden.size.x = _w;
  255. lglw->hidden.size.y = _h;
  256. return LGLW_TRUE;
  257. }
  258. // ---------------------------------------------------------------------------- loc_destroy_hidden_window
  259. static void loc_destroy_hidden_window(lglw_int_t *lglw) {
  260. lglw_log("lglw:loc_destroy_hidden_window: 1\n");
  261. if(NULL != lglw->xdsp && NULL != lglw->ctx)
  262. {
  263. glXMakeCurrent(lglw->xdsp, None, NULL);
  264. glXDestroyContext(lglw->xdsp, lglw->ctx);
  265. }
  266. lglw_log("lglw:loc_destroy_hidden_window: 2\n");
  267. if(NULL != lglw->xdsp && 0 != lglw->hidden.xwnd) XDestroyWindow(lglw->xdsp, lglw->hidden.xwnd);
  268. lglw_log("lglw:loc_destroy_hidden_window: 3\n");
  269. if(NULL != lglw->xdsp && 0 != lglw->cmap) XFreeColormap(lglw->xdsp, lglw->cmap);
  270. lglw_log("lglw:loc_destroy_hidden_window: 4\n");
  271. if(NULL != lglw->vi) XFree(lglw->vi);
  272. lglw_log("lglw:loc_destroy_hidden_window: 5\n");
  273. XSync(lglw->xdsp, False);
  274. if(NULL != lglw->xdsp) XCloseDisplay(lglw->xdsp);
  275. }
  276. // ---------------------------------------------------------------------------- loc_setEventProc
  277. // https://www.kvraudio.com/forum/viewtopic.php?t=387924
  278. // https://github.com/Ardour/ardour/blob/master/gtk2_ardour/linux_vst_gui_support.cc
  279. // https://discourse.ardour.org/t/overtonedsp-plugins/90115/22
  280. // https://github.com/amsynth/amsynth/blob/4a87798e650c6d71d70274a961c9b8d98fc6da7e/src/amsynth_vst.cpp
  281. // https://github.com/rsenn/eXT2/blob/7f00a09561ded8175ffed2f4912dad74e466a1c7/vstplugins/vstgui/vstgui.cpp
  282. // https://github.com/COx2/DistortionFilter/blob/c6a34fb56b503a6e95bf0975e00f438bbf4ff52a/juce/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
  283. // Very simple function to test _XEventProc is properly called
  284. static void loc_eventProc(void *_xevent) {
  285. XEvent *xev = (XEvent*)_xevent;
  286. lglw_log("XEventProc\n");
  287. printf("vstgltest<lglw_linux>: XEventProc, xev=%p\n", xev);
  288. if(NULL != xev)
  289. {
  290. LGLW(loc_getProperty(xev->xany.display, xev->xany.window, "_lglw")); // get instance pointer
  291. printf("vstgltest<lglw_linux>: XEventProc, type=%d serial=%lu send_event=%d lglw=%p\n", xev->xany.type, xev->xany.serial, xev->xany.send_event, lglw);
  292. if(NULL != lglw)
  293. {
  294. switch(xev->type)
  295. {
  296. default:
  297. printf("vstgltest<lglw_linux>: unhandled X11 event type=%d\n", xev->type);
  298. break;
  299. case Expose:
  300. printf("vstgltest<lglw_linux>: xev Expose\n");
  301. if(NULL != lglw->redraw.cbk)
  302. {
  303. lglw->redraw.cbk(lglw);
  304. }
  305. break;
  306. case MotionNotify:
  307. printf("vstgltest<lglw_linux>: xev MotionNotify\n");
  308. break;
  309. case KeyPress:
  310. printf("vstgltest<lglw_linux>: xev KeyPress\n");
  311. lglw_redraw(lglw);
  312. break;
  313. case KeyRelease:
  314. printf("vstgltest<lglw_linux>: xev KeyRelease\n");
  315. break;
  316. }
  317. }
  318. }
  319. }
  320. static void loc_setProperty(Display *_display, Window _window, const char *_name, void *_value) {
  321. size_t data = (size_t)_value;
  322. long temp[2];
  323. // Split the 64 bit pointer into a little-endian long array
  324. temp[0] = (long)(data & 0xffffffffUL);
  325. temp[1] = (long)(data >> 32L);
  326. printf("xxx lglw_linux:loc_setProperty: name=\"%s\" value=%p temp[0]=%08x temp[1]=%08x\n", _name, _value, temp[0], temp[1]);
  327. Atom atom = XInternAtom(_display, _name, False/*only_if_exists*/);
  328. // (note) what's quite weird here is that we're writing an array of 32bit values, yet the element format must be 64bit (long)
  329. XChangeProperty(_display, _window,
  330. atom/*property*/,
  331. atom/*type*/,
  332. 32/*format*/,
  333. PropModeReplace/*mode*/,
  334. (unsigned char*)temp/*data*/,
  335. 2/*nelements*/
  336. );
  337. }
  338. static void *loc_getProperty(Display *_display, Window _window, const char *_name) {
  339. int userSize;
  340. unsigned long bytes;
  341. unsigned long userCount;
  342. unsigned char *data;
  343. Atom userType;
  344. Atom atom = XInternAtom(_display, _name, False);
  345. // (note) 64bit properties need to be read with two XGetWindowProperty() calls.
  346. // When using just one call and setting the 'length' to 2, the upper 32bit (second array element) will be 0xFFFFffff.
  347. XGetWindowProperty(_display,
  348. _window,
  349. atom,
  350. 0/*offset*/,
  351. 1/*length*/,
  352. False/*delete*/,
  353. AnyPropertyType,
  354. &userType/*actual_type_return*/,
  355. &userSize/*actual_format_return*/,
  356. &userCount/*nitems_return*/,
  357. &bytes/*bytes_after_return / partial reads*/,
  358. &data);
  359. union {
  360. uint32_t ui[2];
  361. void *any;
  362. } uptr;
  363. uptr.any = 0;
  364. printf("xxx lglw_linux: loc_getProperty: LOWER userSize=%d userCount=%lu bytes=%lu data=%p\n", userSize, userCount, bytes, data);
  365. if(NULL != data)
  366. {
  367. if(userCount >= 1)
  368. {
  369. if(userCount >= 2)
  370. {
  371. printf("xxx loc_getProperty: lo=0x%08x hi=0x%08x\n", ((uint32_t*)data)[0], ((uint32_t*)data)[1]);
  372. }
  373. // lower 32-bit
  374. uptr.ui[0] = *(long*)data;
  375. uptr.ui[1] = 0;
  376. printf("xxx lower=0x%08x\n", uptr.ui[0]);
  377. // // printf("xxx upper=0x%08x\n", uptr.ui[1]);
  378. XFree(data);
  379. // // if(userCount >= 2)
  380. {
  381. XGetWindowProperty(_display,
  382. _window,
  383. atom,
  384. 1/*offset*/,
  385. 1/*length*/,
  386. False/*delete*/,
  387. AnyPropertyType,
  388. &userType/*actual_type_return*/,
  389. &userSize/*actual_format_return*/,
  390. &userCount/*nitems_return*/,
  391. &bytes/*bytes_after_return / partial reads*/,
  392. &data);
  393. printf("xxx lglw_linux: loc_getProperty: UPPER userSize=%d userCount=%lu bytes=%lu data=%p\n", userSize, userCount, bytes, data);
  394. if(NULL != data)
  395. {
  396. // upper 32-bit
  397. uptr.ui[1] = *(long*)data;
  398. printf("xxx upper=0x%08x\n", uptr.ui[1]);
  399. XFree(data);
  400. }
  401. }
  402. }
  403. }
  404. printf("xxx lglw_linux: loc_getProperty: return value=%p\n", uptr.any);
  405. return uptr.any;
  406. }
  407. #ifdef ARCH_X64
  408. #if 0
  409. // Pulled from the Renoise 64-bit callback example
  410. // Unsure what data was supposed to be, but swapping it to a function name did not work
  411. // This does nothing, no event proc found
  412. static void loc_setEventProc (Display *display, Window window) {
  413. size_t data = (size_t)loc_eventProc;
  414. long temp[2];
  415. printf("vstgltest<lglw_linux>: setEventProc (2*32bit). window=%lu loc_eventProc=%p\n", window, &loc_eventProc);
  416. // Split the 64 bit pointer into a little-endian unsigned int array
  417. temp[0] = (uint32_t)(data & 0xffffffffUL);
  418. temp[1] = (uint32_t)(data >> 32L);
  419. Atom atom = XInternAtom(display, "_XEventProc", False);
  420. XChangeProperty(display, window,
  421. atom/*property*/,
  422. atom/*type*/,
  423. 32/*format*/,
  424. PropModeReplace/*mode*/,
  425. (unsigned char*)temp/*data*/,
  426. 2/*nelements*/
  427. );
  428. }
  429. #else
  430. // GPL code pulled from the amsynth example <https://github.com/amsynth/amsynth/blob/4a87798e650c6d71d70274a961c9b8d98fc6da7e/src/amsynth_vst.cpp>
  431. // Simply swapped out the function names, crashes Ardour in the same was as the others
  432. static void loc_setEventProc (Display *display, Window window) {
  433. //
  434. // JUCE calls XGetWindowProperty with long_length = 1 which means it only fetches the lower 32 bits of the address.
  435. // Therefore we need to ensure we return an address in the lower 32-bits of address space.
  436. //
  437. // based on mach_override
  438. static const unsigned char kJumpInstructions[] = {
  439. 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00,
  440. 0x00, 0x00, 0x00, 0x00,
  441. 0x00, 0x00, 0x00, 0x00
  442. };
  443. static const int kJumpAddress = 6;
  444. static char *ptr = 0;
  445. if (!ptr) {
  446. ptr = (char *)mmap(0,
  447. getpagesize()/*PAGE_SIZE*/,
  448. PROT_READ | PROT_WRITE | PROT_EXEC,
  449. MAP_ANONYMOUS | MAP_PRIVATE | MAP_32BIT,
  450. 0, 0);
  451. if (ptr == MAP_FAILED) {
  452. perror("mmap");
  453. ptr = 0;
  454. return;
  455. } else {
  456. memcpy(ptr, kJumpInstructions, sizeof(kJumpInstructions));
  457. *((uint64_t *)(ptr + kJumpAddress)) = (uint64_t)(&loc_eventProc);
  458. msync(ptr, sizeof(kJumpInstructions), MS_INVALIDATE);
  459. printf("vstgltest<lglw_linux>: 64bit trampoline installed\n");
  460. }
  461. }
  462. long temp[2] = {(uint32_t)(((size_t)ptr)&0xFFFFfffful), 0};
  463. Atom atom = XInternAtom(display, "_XEventProc", False);
  464. XChangeProperty(display, window,
  465. atom/*property*/,
  466. atom/*type*/,
  467. 32/*format*/,
  468. PropModeReplace/*mode*/,
  469. (unsigned char *)temp/*data*/,
  470. 2/*nelements*/
  471. );
  472. }
  473. #endif
  474. #else
  475. // Pulled from the eXT2 example
  476. static void loc_setEventProc (Display *display, Window window) {
  477. void* data = (void*)&loc_eventProc; // swapped the function name here
  478. // (note) 32-bit only
  479. Atom atom = XInternAtom(display, "_XEventProc", False);
  480. XChangeProperty(display, window,
  481. atom/*property*/,
  482. atom/*type*/,
  483. 32/*format*/,
  484. PropModeReplace/*mode*/,
  485. (unsigned char*)&data/*data*/,
  486. 1/*nelements*/
  487. );
  488. }
  489. #endif // ARCH_X64
  490. // ---------------------------------------------------------------------------- lglw_window_open
  491. lglw_bool_t lglw_window_open (lglw_t _lglw, void *_parentHWNDOrNull, int32_t _x, int32_t _y, int32_t _w, int32_t _h) {
  492. lglw_bool_t r = LGLW_FALSE;
  493. LGLW(_lglw);
  494. if(NULL != lglw)
  495. {
  496. lglw_log("lglw:lglw_window_open: 1, %p, %i \n", (Window)_parentHWNDOrNull, (Window)_parentHWNDOrNull);
  497. lglw->parent_xwnd = (0 == _parentHWNDOrNull) ? DefaultRootWindow(lglw->xdsp) : (Window)_parentHWNDOrNull;
  498. lglw_log("lglw:lglw_window_open: 2 lglw=%p\n", lglw);
  499. if(_w <= 16)
  500. _w = lglw->hidden.size.x;
  501. lglw_log("lglw:lglw_window_open: 3\n");
  502. if(_h <= 16)
  503. _h = lglw->hidden.size.y;
  504. // TODO: compare to 'WindowClass' from Windows implementation
  505. lglw_log("lglw:lglw_window_open: 4\n");
  506. XSetWindowAttributes swa;
  507. // // XEvent event;
  508. XSync(lglw->xdsp, False);
  509. #if 1
  510. lglw_log("lglw:lglw_window_open: 5\n");
  511. swa.border_pixel = 0;
  512. swa.colormap = lglw->cmap;
  513. // (note) [bsp] setting this to NoEventMask causes all events to be propagated to the parent (host) window.
  514. // The host then reports the event to the plugin by calling its eventProc function (set via "_XEventProc").
  515. swa.event_mask = NoEventMask;/////ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask | FocusChangeMask;
  516. lglw->win.xwnd = XCreateWindow(lglw->xdsp/*display*/,
  517. DefaultRootWindow(lglw->xdsp)/*parent. see Cameron's comment below.*/,
  518. 0/*x*/,
  519. 0/*y*/,
  520. _w/*width*/,
  521. _h/*height*/,
  522. 0/*border_width*/,
  523. CopyFromParent/*depth*/,
  524. InputOutput/*class*/,
  525. lglw->vi->visual,
  526. CWBorderPixel | CWColormap | CWEventMask/*value_mask*/,
  527. &swa/*attributes*/
  528. );
  529. lglw_log("lglw:lglw_window_open: 6\n");
  530. XSetStandardProperties(lglw->xdsp/*display*/,
  531. lglw->win.xwnd/*window*/,
  532. "LGLW"/*window_name*/,
  533. "LGLW"/*icon_name*/,
  534. None/*icon_pixmap*/,
  535. NULL/*argv*/,
  536. 0/*argc*/,
  537. NULL/*XSizeHints*/
  538. );
  539. // Setup the event proc now, on the parent window as well just for the debug host
  540. // It was simpler to do this than check in the debug host for the reparent event
  541. lglw_log("lglw:lglw_window_open: 7\n");
  542. loc_setEventProc(lglw->xdsp, lglw->win.xwnd);
  543. loc_setProperty(lglw->xdsp, lglw->win.xwnd, "_lglw", (void*)lglw); // set instance pointer
  544. if(0 != _parentHWNDOrNull)
  545. {
  546. loc_setEventProc(lglw->xdsp, lglw->parent_xwnd);
  547. loc_setProperty(lglw->xdsp, lglw->parent_xwnd, "_lglw", (void*)lglw); // set instance pointer
  548. }
  549. // Some hosts only check and store the callback when the Window is reparented
  550. // Since creating the Window with a Parent may or may not do that, but the callback is not set,
  551. // ... it's created as a root window, the callback is set, and then it's reparented
  552. #if 1
  553. // (note) [cameronleger] In Ardour's code-base, the only time it looks for the _XEventProc is during a ReparentNotify event
  554. if (0 != _parentHWNDOrNull)
  555. {
  556. lglw_log("lglw:lglw_window_open: 8\n");
  557. XReparentWindow(lglw->xdsp, lglw->win.xwnd, lglw->parent_xwnd, 0, 0);
  558. }
  559. #endif
  560. lglw->win.b_owner = LGLW_TRUE;
  561. #else
  562. lglw->win.xwnd = (Window)_parentHWNDOrNull;
  563. lglw->win.b_owner = LGLW_FALSE;
  564. #endif
  565. lglw_log("lglw:lglw_window_open: 9\n");
  566. if(lglw->win.b_owner)
  567. {
  568. // // XMapRaised(lglw->xdsp, lglw->win.xwnd);
  569. XMapWindow(lglw->xdsp, lglw->win.xwnd);
  570. }
  571. #if 0
  572. XSelectInput(lglw->xdsp, lglw->win.xwnd,
  573. ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask | FocusChangeMask
  574. );
  575. XGrabKeyboard(lglw->xdsp, lglw->win.xwnd,
  576. False/*owner_events*/,
  577. GrabModeAsync/*pointer_mode*/,
  578. GrabModeAsync/*keyboard_mode*/,
  579. CurrentTime/*time*/
  580. );
  581. #endif
  582. #if 0
  583. XSetInputFocus(lglw->xdsp/*display*/,
  584. PointerRoot/*focus*/,
  585. RevertToPointerRoot/*revert_to*/,
  586. CurrentTime
  587. );
  588. #endif
  589. XSync(lglw->xdsp, False);
  590. lglw->win.mapped = LGLW_TRUE;
  591. lglw_log("lglw:lglw_window_open: 10\n");
  592. lglw->win.size.x = _w;
  593. lglw->win.size.y = _h;
  594. lglw_log("lglw:lglw_window_open: 11\n");
  595. loc_enable_dropfiles(lglw, (NULL != lglw->dropfiles.cbk));
  596. lglw_log("lglw:lglw_window_open: EXIT\n");
  597. r = LGLW_TRUE;
  598. }
  599. return r;
  600. }
  601. // ---------------------------------------------------------------------------- lglw_window_resize
  602. lglw_bool_t lglw_window_resize (lglw_t _lglw, int32_t _w, int32_t _h) {
  603. lglw_bool_t r = LGLW_FALSE;
  604. LGLW(_lglw);
  605. if(NULL != lglw)
  606. {
  607. if(0 != lglw->win.xwnd)
  608. {
  609. lglw_log("lglw:lglw_window_resize: 1\n");
  610. r = LGLW_TRUE;
  611. lglw_log("lglw:lglw_window_resize: 2\n");
  612. XResizeWindow(lglw->xdsp, lglw->win.xwnd, _w, _h);
  613. XRaiseWindow(lglw->xdsp, lglw->win.xwnd);
  614. lglw_log("lglw:lglw_window_resize: 3\n");
  615. int deltaW = _w - lglw->win.size.x;
  616. int deltaH = _h - lglw->win.size.y;
  617. lglw_log("lglw:lglw_window_resize: 4\n");
  618. lglw->win.size.x = _w;
  619. lglw->win.size.y = _h;
  620. lglw_log("lglw:lglw_window_resize: 5\n");
  621. Window root, parent, *children = NULL;
  622. unsigned int num_children;
  623. lglw_log("lglw:lglw_window_resize: 6\n");
  624. if(!XQueryTree(lglw->xdsp, lglw->win.xwnd, &root, &parent, &children, &num_children))
  625. return r;
  626. lglw_log("lglw:lglw_window_resize: 7\n");
  627. if(children)
  628. XFree((char *)children);
  629. lglw_log("lglw:lglw_window_resize: 8\n");
  630. // Resize parent window (if any)
  631. if(0 != parent)
  632. {
  633. lglw_log("lglw:lglw_window_resize: 8.1\n");
  634. int x, y;
  635. unsigned int width, height;
  636. unsigned int border_width;
  637. unsigned int depth;
  638. lglw_log("lglw:lglw_window_resize: 8.2\n");
  639. if(!XGetGeometry(lglw->xdsp, lglw->win.xwnd, &root, &x, &y, &width, &height, &border_width, &depth))
  640. return r;
  641. lglw_log("lglw:lglw_window_resize: 8.3\n");
  642. XResizeWindow(lglw->xdsp, parent, width + deltaW, height + deltaH);
  643. }
  644. lglw_log("lglw:lglw_window_resize: EXIT\n");
  645. }
  646. }
  647. return r;
  648. }
  649. // ---------------------------------------------------------------------------- lglw_window_close
  650. void lglw_window_close (lglw_t _lglw) {
  651. LGLW(_lglw);
  652. if(NULL != lglw)
  653. {
  654. if(0 != lglw->win.xwnd)
  655. {
  656. lglw_log("lglw:lglw_window_close: 1\n");
  657. lglw_timer_stop(_lglw);
  658. lglw_log("lglw:lglw_window_close: 2\n");
  659. loc_key_unhook(lglw);
  660. lglw_log("lglw:lglw_window_close: 3\n");
  661. glXMakeCurrent(lglw->xdsp, None, NULL);
  662. lglw_log("lglw:lglw_window_close: 4\n");
  663. if(lglw->win.b_owner)
  664. {
  665. XDestroyWindow(lglw->xdsp, lglw->win.xwnd);
  666. lglw->win.b_owner = LGLW_FALSE;
  667. }
  668. XSync(lglw->xdsp, False);
  669. lglw->win.xwnd = 0;
  670. lglw->win.mapped = LGLW_FALSE;
  671. }
  672. }
  673. lglw_log("lglw:lglw_window_close: EXIT\n");
  674. }
  675. // ---------------------------------------------------------------------------- lglw_window_show
  676. void lglw_window_show(lglw_t _lglw) {
  677. LGLW(_lglw);
  678. if(NULL != lglw)
  679. {
  680. lglw_log("lglw:lglw_window_show: 1\n");
  681. XMapRaised(lglw->xdsp, lglw->win.xwnd);
  682. lglw->win.mapped = LGLW_TRUE;
  683. }
  684. lglw_log("lglw:lglw_window_show: EXIT\n");
  685. }
  686. // ---------------------------------------------------------------------------- lglw_window_hide
  687. void lglw_window_hide(lglw_t _lglw) {
  688. LGLW(_lglw);
  689. if(NULL != lglw)
  690. {
  691. lglw_log("lglw:lglw_window_hide: 1\n");
  692. XUnmapWindow(lglw->xdsp, lglw->win.xwnd);
  693. lglw->win.mapped = LGLW_FALSE;
  694. }
  695. lglw_log("lglw:lglw_window_hide: EXIT\n");
  696. }
  697. // ---------------------------------------------------------------------------- lglw_window_is_visible
  698. lglw_bool_t lglw_window_is_visible(lglw_t _lglw) {
  699. lglw_bool_t r = LGLW_FALSE;
  700. LGLW(_lglw);
  701. // lglw_log("lglw:lglw_window_is_visible: 1\n");
  702. if(NULL != lglw && 0 != lglw->win.xwnd)
  703. {
  704. // lglw_log("lglw:lglw_window_is_visible: 2\n");
  705. r = lglw->win.mapped;
  706. }
  707. // lglw_log("lglw:lglw_window_is_visible: EXIT\n");
  708. return r;
  709. }
  710. // ---------------------------------------------------------------------------- lglw_window_size_get
  711. void lglw_window_size_get(lglw_t _lglw, int32_t *_retX, int32_t *_retY) {
  712. LGLW(_lglw);
  713. lglw_log("lglw:lglw_window_size_get: 1\n");
  714. if(NULL != lglw)
  715. {
  716. if(0 != lglw->win.xwnd)
  717. {
  718. if(NULL != _retX)
  719. *_retX = lglw->win.size.x;
  720. if(NULL != _retY)
  721. *_retY = lglw->win.size.y;
  722. }
  723. }
  724. lglw_log("lglw:lglw_window_size_get: EXIT\n");
  725. }
  726. // ---------------------------------------------------------------------------- lglw_redraw
  727. void lglw_redraw(lglw_t _lglw) {
  728. LGLW(_lglw);
  729. // (todo) implement me
  730. if(NULL != lglw)
  731. {
  732. if(0 != lglw->win.xwnd)
  733. {
  734. // TODO Event Loop
  735. lglw_log("lglw:lglw_redraw: 1\n");
  736. // XClearArea(lglw->xdsp, lglw->win.xwnd, 0, 0, 1, 1, True); // clear tiny area for exposing
  737. XEvent xev;
  738. xev.xany.type = Expose;
  739. xev.xany.serial = 0;
  740. xev.xany.send_event = True;
  741. xev.xany.display = lglw->xdsp;
  742. xev.xany.window = lglw->win.xwnd;
  743. xev.xexpose.x = 0;
  744. xev.xexpose.y = 0;
  745. xev.xexpose.width = lglw->win.size.x;
  746. xev.xexpose.height = lglw->win.size.y;
  747. xev.xexpose.count = 0;
  748. XSendEvent(lglw->xdsp, lglw->win.xwnd,
  749. True/*propagate*/,
  750. ExposureMask/*event_mask*/,
  751. &xev
  752. );
  753. XFlush(lglw->xdsp);
  754. }
  755. }
  756. }
  757. // ---------------------------------------------------------------------------- lglw_redraw_callback_set
  758. void lglw_redraw_callback_set(lglw_t _lglw, lglw_redraw_fxn_t _cbk) {
  759. LGLW(_lglw);
  760. if(NULL != lglw)
  761. {
  762. lglw->redraw.cbk = _cbk;
  763. }
  764. }
  765. // ---------------------------------------------------------------------------- lglw_glcontext_push
  766. void lglw_glcontext_push(lglw_t _lglw) {
  767. LGLW(_lglw);
  768. if(NULL != lglw)
  769. {
  770. lglw->prev.drw = glXGetCurrentDrawable();
  771. lglw->prev.ctx = glXGetCurrentContext();
  772. // lglw_log("lglw:lglw_glcontext_push: win.xwnd=%p hidden.xwnd=%p ctx=%p\n",
  773. // lglw->win.xwnd, lglw->hidden.xwnd, lglw->ctx);
  774. if(!glXMakeCurrent(lglw->xdsp, (0 == lglw->win.xwnd) ? lglw->hidden.xwnd : lglw->win.xwnd, lglw->ctx))
  775. {
  776. lglw_log("[---] lglw_glcontext_push: glXMakeCurrent() failed. win.xwnd=%p hidden.xwnd=%p ctx=%p glGetError()=%d\n", lglw->win.xwnd, lglw->hidden.xwnd, lglw->ctx, glGetError());
  777. }
  778. }
  779. }
  780. // ---------------------------------------------------------------------------- lglw_glcontext_pop
  781. void lglw_glcontext_pop(lglw_t _lglw) {
  782. LGLW(_lglw);
  783. if(NULL != lglw)
  784. {
  785. // lglw_log("lglw:lglw_glcontext_pop: prev.drw=%p prev.ctx=%p\n",
  786. // lglw->prev.drw, lglw->prev.ctx);
  787. if(!glXMakeCurrent(lglw->xdsp, lglw->prev.drw, lglw->prev.ctx))
  788. {
  789. lglw_log("[---] lglw_glcontext_pop: glXMakeCurrent() failed. prev.drw=%p ctx=%p glGetError()=%d\n", lglw->prev.drw, lglw->prev.ctx, glGetError());
  790. }
  791. }
  792. }
  793. // ---------------------------------------------------------------------------- lglw_swap_buffers
  794. void lglw_swap_buffers(lglw_t _lglw) {
  795. LGLW(_lglw);
  796. if(NULL != lglw)
  797. {
  798. if(0 != lglw->win.xwnd)
  799. {
  800. // lglw_log("lglw:lglw_swap_buffers: 1\n");
  801. glXSwapBuffers(lglw->xdsp, lglw->win.xwnd);
  802. }
  803. }
  804. }
  805. // ---------------------------------------------------------------------------- lglw_swap_interval_set
  806. typedef void (APIENTRY *PFNWGLEXTSWAPINTERVALPROC) (int);
  807. void lglw_swap_interval_set(lglw_t _lglw, int32_t _ival) {
  808. LGLW(_lglw);
  809. if(NULL != lglw)
  810. {
  811. lglw_log("lglw:lglw_swap_interval_set: 1\n");
  812. PFNWGLEXTSWAPINTERVALPROC glXSwapIntervalEXT;
  813. glXSwapIntervalEXT = (PFNWGLEXTSWAPINTERVALPROC) glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT");
  814. if(NULL != glXSwapIntervalEXT)
  815. {
  816. lglw_log("lglw:lglw_swap_interval_set: 2\n");
  817. glXSwapIntervalEXT(_ival);
  818. lglw->win.swap_interval = _ival;
  819. }
  820. }
  821. }
  822. // ---------------------------------------------------------------------------- lglw_swap_interval_get
  823. int32_t lglw_swap_interval_get(lglw_t _lglw) {
  824. LGLW(_lglw);
  825. int32_t r = 0;
  826. if(NULL != lglw)
  827. {
  828. r = lglw->win.swap_interval;
  829. }
  830. return r;
  831. }
  832. // ---------------------------------------------------------------------------- loc_key_hook
  833. static void loc_key_hook(lglw_int_t *lglw) {
  834. loc_key_unhook(lglw);
  835. // (todo) implement me
  836. khook_lglw = lglw;
  837. }
  838. // ---------------------------------------------------------------------------- loc_key_unhook
  839. static void loc_key_unhook(lglw_int_t *lglw) {
  840. // (todo) implement me
  841. if(khook_lglw == lglw)
  842. khook_lglw = NULL;
  843. }
  844. // ---------------------------------------------------------------------------- loc_handle_mouseleave
  845. static void loc_handle_mouseleave(lglw_int_t *lglw) {
  846. loc_key_unhook(lglw);
  847. lglw->focus.state &= ~LGLW_FOCUS_MOUSE;
  848. if(NULL != lglw->focus.cbk)
  849. {
  850. lglw->focus.cbk(lglw, lglw->focus.state, LGLW_FOCUS_MOUSE);
  851. }
  852. lglw_log("xxx lglw:loc_handle_mouseleave: LEAVE\n");
  853. }
  854. // ---------------------------------------------------------------------------- loc_handle_mouseenter
  855. static void loc_handle_mouseenter(lglw_int_t *lglw) {
  856. loc_key_hook(lglw);
  857. lglw->focus.state |= LGLW_FOCUS_MOUSE;
  858. if(NULL != lglw->focus.cbk)
  859. {
  860. lglw->focus.cbk(lglw, lglw->focus.state, LGLW_FOCUS_MOUSE);
  861. }
  862. lglw_log("xxx lglw:loc_handle_mouseenter: LEAVE\n");
  863. }
  864. // ---------------------------------------------------------------------------- loc_handle_mousebutton
  865. static void loc_handle_mousebutton(lglw_int_t *lglw, lglw_bool_t _bPressed, uint32_t _button) {
  866. if(_bPressed)
  867. lglw->mouse.button_state |= _button;
  868. else
  869. lglw->mouse.button_state &= ~_button;
  870. if(NULL != lglw->mouse.cbk)
  871. {
  872. lglw->mouse.cbk(lglw, lglw->mouse.p.x, lglw->mouse.p.y, lglw->mouse.button_state, _button);
  873. }
  874. }
  875. // ---------------------------------------------------------------------------- loc_handle_mousemotion
  876. static void loc_handle_mousemotion(lglw_int_t *lglw) {
  877. if(NULL != lglw->mouse.cbk)
  878. {
  879. lglw->mouse.cbk(lglw, lglw->mouse.p.x, lglw->mouse.p.y, lglw->mouse.button_state, 0u/*changedbuttonstate*/);
  880. }
  881. }
  882. // ---------------------------------------------------------------------------- lglw_mouse_callback_set
  883. void lglw_mouse_callback_set(lglw_t _lglw, lglw_mouse_fxn_t _cbk) {
  884. LGLW(_lglw);
  885. if(NULL != lglw)
  886. {
  887. lglw->mouse.cbk = _cbk;
  888. }
  889. }
  890. // ---------------------------------------------------------------------------- lglw_mouse_callback_set
  891. void lglw_focus_callback_set(lglw_t _lglw, lglw_focus_fxn_t _cbk) {
  892. LGLW(_lglw);
  893. if(NULL != lglw)
  894. {
  895. lglw->focus.cbk = _cbk;
  896. }
  897. }
  898. // ---------------------------------------------------------------------------- loc_handle_key
  899. static lglw_bool_t loc_handle_key(lglw_int_t *lglw, lglw_bool_t _bPressed, uint32_t _vkey) {
  900. lglw_bool_t r = LGLW_FALSE;
  901. if(NULL != lglw->keyboard.cbk)
  902. {
  903. r = lglw->keyboard.cbk(lglw, _vkey, lglw->keyboard.kmod_state, _bPressed);
  904. }
  905. return r;
  906. }
  907. // ---------------------------------------------------------------------------- lglw_keyboard_callback_set
  908. void lglw_keyboard_callback_set(lglw_t _lglw, lglw_keyboard_fxn_t _cbk) {
  909. LGLW(_lglw);
  910. if(NULL != lglw)
  911. {
  912. lglw->keyboard.cbk = _cbk;
  913. }
  914. }
  915. // ---------------------------------------------------------------------------- lglw_keyboard_get_modifiers
  916. uint32_t lglw_keyboard_get_modifiers(lglw_t _lglw) {
  917. uint32_t r = 0u;
  918. LGLW(_lglw);
  919. if(NULL != lglw)
  920. {
  921. r = lglw->keyboard.kmod_state;
  922. }
  923. return r;
  924. }
  925. // ---------------------------------------------------------------------------- lglw_touchkeyboard_show
  926. void lglw_touchkeyboard_show(lglw_t _lglw, lglw_bool_t _bEnable) {
  927. LGLW(_lglw);
  928. // (todo) implement me
  929. if(NULL != lglw)
  930. {
  931. }
  932. }
  933. // ---------------------------------------------------------------------------- lglw_mouse_get_buttons
  934. uint32_t lglw_mouse_get_buttons(lglw_t _lglw) {
  935. uint32_t r = 0u;
  936. LGLW(_lglw);
  937. if(NULL != lglw)
  938. {
  939. r = lglw->mouse.button_state;
  940. }
  941. return r;
  942. }
  943. // ---------------------------------------------------------------------------- lglw_mouse_grab
  944. void lglw_mouse_grab(lglw_t _lglw, uint32_t _grabMode) {
  945. LGLW(_lglw);
  946. if(NULL != lglw)
  947. {
  948. // (todo) implement me
  949. // if(NULL != lglw->win.hwnd)
  950. {
  951. if(!lglw->mouse.touch.b_enable)
  952. {
  953. if(lglw->mouse.grab.mode != _grabMode)
  954. {
  955. lglw_mouse_ungrab(_lglw);
  956. }
  957. switch(_grabMode)
  958. {
  959. default:
  960. case LGLW_MOUSE_GRAB_NONE:
  961. break;
  962. case LGLW_MOUSE_GRAB_CAPTURE:
  963. // (todo) implement me
  964. // (void)SetCapture(lglw->win.hwnd);
  965. lglw->mouse.grab.mode = _grabMode;
  966. break;
  967. case LGLW_MOUSE_GRAB_WARP:
  968. // (todo) implement me
  969. // (void)SetCapture(lglw->win.hwnd);
  970. lglw_mouse_cursor_show(_lglw, LGLW_FALSE);
  971. lglw->mouse.grab.p = lglw->mouse.p;
  972. lglw->mouse.grab.last_p = lglw->mouse.p;
  973. lglw->mouse.grab.mode = _grabMode;
  974. break;
  975. }
  976. }
  977. }
  978. }
  979. }
  980. // ---------------------------------------------------------------------------- lglw_mouse_ungrab
  981. void lglw_mouse_ungrab(lglw_t _lglw) {
  982. LGLW(_lglw);
  983. if(NULL != lglw)
  984. {
  985. // (todo) implement me
  986. // if(NULL != lglw->win.hwnd)
  987. {
  988. if(!lglw->mouse.touch.b_enable)
  989. {
  990. switch(lglw->mouse.grab.mode)
  991. {
  992. default:
  993. case LGLW_MOUSE_GRAB_NONE:
  994. break;
  995. case LGLW_MOUSE_GRAB_CAPTURE:
  996. // (todo) implement me
  997. // (void)ReleaseCapture();
  998. lglw->mouse.grab.mode = LGLW_MOUSE_GRAB_NONE;
  999. break;
  1000. case LGLW_MOUSE_GRAB_WARP:
  1001. // (todo) implement me
  1002. // (void)ReleaseCapture();
  1003. lglw->mouse.grab.mode = LGLW_MOUSE_GRAB_NONE;
  1004. lglw->mouse.grab.b_queue_warp = LGLW_TRUE;
  1005. lglw_mouse_cursor_show(_lglw, LGLW_TRUE);
  1006. break;
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. // ---------------------------------------------------------------------------- lglw_mouse_warp
  1013. void lglw_mouse_warp(lglw_t _lglw, int32_t _x, int32_t _y) {
  1014. LGLW(_lglw);
  1015. // (todo) implement me
  1016. if(NULL != lglw)
  1017. {
  1018. }
  1019. }
  1020. // ---------------------------------------------------------------------------- loc_handle_queued_mouse_warp
  1021. static void loc_handle_queued_mouse_warp(lglw_int_t *lglw) {
  1022. if(lglw->mouse.grab.b_queue_warp)
  1023. {
  1024. lglw->mouse.grab.b_queue_warp = LGLW_FALSE;
  1025. lglw_mouse_warp(lglw, lglw->mouse.grab.p.x, lglw->mouse.grab.p.y);
  1026. lglw->mouse.grab.last_p = lglw->mouse.grab.p;
  1027. }
  1028. }
  1029. // ---------------------------------------------------------------------------- lglw_mouse_cursor_show
  1030. void lglw_mouse_cursor_show (lglw_t _lglw, lglw_bool_t _bShow) {
  1031. LGLW(_lglw);
  1032. // (todo) implement me
  1033. if(NULL != lglw)
  1034. {
  1035. }
  1036. }
  1037. // ---------------------------------------------------------------------------- lglw_timer_start
  1038. void lglw_timer_start(lglw_t _lglw, uint32_t _millisec) {
  1039. LGLW(_lglw);
  1040. // (todo) implement me
  1041. if(NULL != lglw)
  1042. {
  1043. }
  1044. }
  1045. // ---------------------------------------------------------------------------- lglw_timer_stop
  1046. void lglw_timer_stop(lglw_t _lglw) {
  1047. LGLW(_lglw);
  1048. // (todo) implement me
  1049. if(NULL != lglw)
  1050. {
  1051. }
  1052. }
  1053. // ---------------------------------------------------------------------------- lglw_timer_callback_set
  1054. void lglw_timer_callback_set(lglw_t _lglw, lglw_timer_fxn_t _cbk) {
  1055. LGLW(_lglw);
  1056. if(NULL != lglw)
  1057. {
  1058. lglw->timer.cbk = _cbk;
  1059. }
  1060. }
  1061. // ---------------------------------------------------------------------------- loc_enable_dropfiles
  1062. static void loc_enable_dropfiles(lglw_int_t *lglw, lglw_bool_t _bEnable) {
  1063. // (todo) implement me
  1064. }
  1065. // ---------------------------------------------------------------------------- lglw_dropfiles_callback_set
  1066. void lglw_dropfiles_callback_set(lglw_t _lglw, lglw_dropfiles_fxn_t _cbk) {
  1067. LGLW(_lglw);
  1068. if(NULL != _lglw)
  1069. {
  1070. lglw->dropfiles.cbk = _cbk;
  1071. loc_enable_dropfiles(lglw, (NULL != _cbk));
  1072. }
  1073. }
  1074. // ---------------------------------------------------------------------------- loc_touchinput_update
  1075. static void loc_touchinput_update(lglw_int_t *lglw) {
  1076. // (todo) implement me
  1077. }
  1078. // ---------------------------------------------------------------------------- lglw_touchinput_set
  1079. void lglw_touchinput_set(lglw_t _lglw, lglw_bool_t _bEnable) {
  1080. LGLW(_lglw);
  1081. if(NULL != _lglw)
  1082. {
  1083. lglw->mouse.touch.b_enable = _bEnable;
  1084. lglw->mouse.touch.b_update_queued = LGLW_TRUE;
  1085. }
  1086. }
  1087. // ---------------------------------------------------------------------------- lglw_touchinput_get
  1088. lglw_bool_t lglw_touchinput_get(lglw_t _lglw) {
  1089. lglw_bool_t r = LGLW_FALSE;
  1090. LGLW(_lglw);
  1091. if(NULL != _lglw)
  1092. {
  1093. r = lglw->mouse.touch.b_enable;
  1094. }
  1095. return r;
  1096. }
  1097. // ---------------------------------------------------------------------------- lglw_clipboard_text_set
  1098. void lglw_clipboard_text_set(lglw_t _lglw, const uint32_t _numChars, const char *_text) {
  1099. LGLW(_lglw);
  1100. (void)_numChars;
  1101. // (todo) implement me
  1102. if(NULL != _text)
  1103. {
  1104. (void)lglw;
  1105. }
  1106. }
  1107. // ---------------------------------------------------------------------------- lglw_clipboard_text_get
  1108. void lglw_clipboard_text_get(lglw_t _lglw, uint32_t _maxChars, uint32_t *_retNumChars, char *_retText) {
  1109. LGLW(_lglw);
  1110. if(NULL != _retNumChars)
  1111. *_retNumChars = 0u;
  1112. if(NULL != _retText)
  1113. *_retText = 0;
  1114. if(_maxChars > 0u)
  1115. {
  1116. if(NULL != _lglw)
  1117. {
  1118. // (todo) implement me
  1119. (void)lglw;
  1120. }
  1121. }
  1122. }