DISTRHO Plugin Framework
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.

651 lines
21KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2023 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "pugl.hpp"
  17. // --------------------------------------------------------------------------------------------------------------------
  18. // include base headers
  19. #ifdef DGL_CAIRO
  20. # include <cairo.h>
  21. #endif
  22. #ifdef DGL_OPENGL
  23. # include "../OpenGL-include.hpp"
  24. #endif
  25. #ifdef DGL_VULKAN
  26. # include <vulkan/vulkan_core.h>
  27. #endif
  28. /* we will include all header files used in pugl in their C++ friendly form, then pugl stuff in custom namespace */
  29. #include <cassert>
  30. #include <cmath>
  31. #include <cstdlib>
  32. #include <cstdio>
  33. #include <cstring>
  34. #include <ctime>
  35. #if defined(DISTRHO_OS_HAIKU)
  36. # include <Application.h>
  37. # include <Window.h>
  38. # ifdef DGL_OPENGL
  39. # include <GL/gl.h>
  40. # include <opengl/GLView.h>
  41. # endif
  42. #elif defined(DISTRHO_OS_MAC)
  43. # import <Cocoa/Cocoa.h>
  44. # include <dlfcn.h>
  45. # include <mach/mach_time.h>
  46. # ifdef DGL_CAIRO
  47. # include <cairo-quartz.h>
  48. # endif
  49. # ifdef DGL_VULKAN
  50. # import <QuartzCore/CAMetalLayer.h>
  51. # include <vulkan/vulkan_macos.h>
  52. # endif
  53. #elif defined(DISTRHO_OS_WASM)
  54. # include <emscripten/emscripten.h>
  55. # include <emscripten/html5.h>
  56. # ifdef DGL_OPENGL
  57. # include <EGL/egl.h>
  58. # endif
  59. #elif defined(DISTRHO_OS_WINDOWS)
  60. # include <wctype.h>
  61. # include <winsock2.h>
  62. # include <windows.h>
  63. # include <windowsx.h>
  64. # ifdef DGL_CAIRO
  65. # include <cairo-win32.h>
  66. # endif
  67. # ifdef DGL_OPENGL
  68. # include <GL/gl.h>
  69. # endif
  70. # ifdef DGL_VULKAN
  71. # include <vulkan/vulkan.h>
  72. # include <vulkan/vulkan_win32.h>
  73. # endif
  74. #elif defined(HAVE_X11)
  75. # include <dlfcn.h>
  76. # include <limits.h>
  77. # include <unistd.h>
  78. # include <sys/select.h>
  79. // # include <sys/time.h>
  80. # include <X11/X.h>
  81. # include <X11/Xatom.h>
  82. # include <X11/Xlib.h>
  83. # include <X11/Xresource.h>
  84. # include <X11/Xutil.h>
  85. # include <X11/keysym.h>
  86. # ifdef HAVE_XCURSOR
  87. # include <X11/Xcursor/Xcursor.h>
  88. // # include <X11/cursorfont.h>
  89. # endif
  90. # ifdef HAVE_XRANDR
  91. # include <X11/extensions/Xrandr.h>
  92. # endif
  93. # ifdef HAVE_XSYNC
  94. # include <X11/extensions/sync.h>
  95. # include <X11/extensions/syncconst.h>
  96. # endif
  97. # ifdef DGL_CAIRO
  98. # include <cairo-xlib.h>
  99. # endif
  100. # ifdef DGL_OPENGL
  101. # include <GL/glx.h>
  102. # endif
  103. # ifdef DGL_VULKAN
  104. # include <vulkan/vulkan_xlib.h>
  105. # endif
  106. #endif
  107. #ifndef DGL_FILE_BROWSER_DISABLED
  108. # define FILE_BROWSER_DIALOG_DGL_NAMESPACE
  109. # define FILE_BROWSER_DIALOG_NAMESPACE DGL_NAMESPACE
  110. # define DGL_FILE_BROWSER_DIALOG_HPP_INCLUDED
  111. START_NAMESPACE_DGL
  112. # include "../../distrho/extra/FileBrowserDialogImpl.hpp"
  113. END_NAMESPACE_DGL
  114. # include "../../distrho/extra/FileBrowserDialogImpl.cpp"
  115. #endif
  116. #if defined(DGL_USING_X11) && defined(DGL_X11_WINDOW_ICON_NAME)
  117. extern const ulong* DGL_X11_WINDOW_ICON_NAME;
  118. #endif
  119. #ifndef DISTRHO_OS_MAC
  120. START_NAMESPACE_DGL
  121. #endif
  122. // --------------------------------------------------------------------------------------------------------------------
  123. #if defined(DISTRHO_OS_HAIKU)
  124. # include "pugl-extra/haiku.cpp"
  125. # include "pugl-extra/haiku_stub.cpp"
  126. # ifdef DGL_OPENGL
  127. # include "pugl-extra/haiku_gl.cpp"
  128. # endif
  129. #elif defined(DISTRHO_OS_MAC)
  130. # ifndef DISTRHO_MACOS_NAMESPACE_MACRO
  131. # define DISTRHO_MACOS_NAMESPACE_MACRO_HELPER(NS, SEP, INTERFACE) NS ## SEP ## INTERFACE
  132. # define DISTRHO_MACOS_NAMESPACE_MACRO(NS, INTERFACE) DISTRHO_MACOS_NAMESPACE_MACRO_HELPER(NS, _, INTERFACE)
  133. # define PuglCairoView DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglCairoView)
  134. # define PuglOpenGLView DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglOpenGLView)
  135. # define PuglStubView DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglStubView)
  136. # define PuglVulkanView DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglVulkanView)
  137. # define PuglWindow DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglWindow)
  138. # define PuglWindowDelegate DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglWindowDelegate)
  139. # define PuglWrapperView DISTRHO_MACOS_NAMESPACE_MACRO(DGL_NAMESPACE, PuglWrapperView)
  140. # endif
  141. # pragma clang diagnostic push
  142. # pragma clang diagnostic ignored "-Wdeprecated-declarations"
  143. # import "pugl-upstream/src/mac.m"
  144. # import "pugl-upstream/src/mac_stub.m"
  145. # ifdef DGL_CAIRO
  146. # import "pugl-upstream/src/mac_cairo.m"
  147. # endif
  148. # ifdef DGL_OPENGL
  149. # import "pugl-upstream/src/mac_gl.m"
  150. # endif
  151. # ifdef DGL_VULKAN
  152. # import "pugl-upstream/src/mac_vulkan.m"
  153. # endif
  154. # pragma clang diagnostic pop
  155. #elif defined(DISTRHO_OS_WASM)
  156. # include "pugl-extra/wasm.c"
  157. # include "pugl-extra/wasm_stub.c"
  158. # ifdef DGL_OPENGL
  159. # include "pugl-extra/wasm_gl.c"
  160. # endif
  161. #elif defined(DISTRHO_OS_WINDOWS)
  162. # include "pugl-upstream/src/win.c"
  163. # include "pugl-upstream/src/win_stub.c"
  164. # ifdef DGL_CAIRO
  165. # include "pugl-upstream/src/win_cairo.c"
  166. # endif
  167. # ifdef DGL_OPENGL
  168. # include "pugl-upstream/src/win_gl.c"
  169. # endif
  170. # ifdef DGL_VULKAN
  171. # include "pugl-upstream/src/win_vulkan.c"
  172. # endif
  173. #elif defined(HAVE_X11)
  174. # include "pugl-upstream/src/x11.c"
  175. # include "pugl-upstream/src/x11_stub.c"
  176. # ifdef DGL_CAIRO
  177. # include "pugl-upstream/src/x11_cairo.c"
  178. # endif
  179. # ifdef DGL_OPENGL
  180. # include "pugl-upstream/src/x11_gl.c"
  181. # endif
  182. # ifdef DGL_VULKAN
  183. # include "pugl-upstream/src/x11_vulkan.c"
  184. # endif
  185. #endif
  186. #include "pugl-upstream/src/common.c"
  187. #include "pugl-upstream/src/internal.c"
  188. // --------------------------------------------------------------------------------------------------------------------
  189. // DGL specific, expose backend enter
  190. bool puglBackendEnter(PuglView* const view)
  191. {
  192. return view->backend->enter(view, nullptr) == PUGL_SUCCESS;
  193. }
  194. // --------------------------------------------------------------------------------------------------------------------
  195. // DGL specific, expose backend leave
  196. bool puglBackendLeave(PuglView* const view)
  197. {
  198. return view->backend->leave(view, nullptr) == PUGL_SUCCESS;
  199. }
  200. // --------------------------------------------------------------------------------------------------------------------
  201. // DGL specific, assigns backend that matches current DGL build
  202. void puglSetMatchingBackendForCurrentBuild(PuglView* const view)
  203. {
  204. #ifdef DGL_CAIRO
  205. puglSetBackend(view, puglCairoBackend());
  206. #endif
  207. #ifdef DGL_OPENGL
  208. puglSetBackend(view, puglGlBackend());
  209. #endif
  210. #ifdef DGL_VULKAN
  211. puglSetBackend(view, puglVulkanBackend());
  212. #endif
  213. if (view->backend != nullptr)
  214. {
  215. #ifdef DGL_OPENGL
  216. #if defined(DGL_USE_GLES2)
  217. puglSetViewHint(view, PUGL_CONTEXT_API, PUGL_OPENGL_ES_API);
  218. puglSetViewHint(view, PUGL_CONTEXT_PROFILE, PUGL_OPENGL_CORE_PROFILE);
  219. puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 2);
  220. #elif defined(DGL_USE_OPENGL3)
  221. puglSetViewHint(view, PUGL_CONTEXT_API, PUGL_OPENGL_API);
  222. puglSetViewHint(view, PUGL_CONTEXT_PROFILE, PUGL_OPENGL_CORE_PROFILE);
  223. puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 3);
  224. #else
  225. puglSetViewHint(view, PUGL_CONTEXT_API, PUGL_OPENGL_API);
  226. puglSetViewHint(view, PUGL_CONTEXT_PROFILE, PUGL_OPENGL_COMPATIBILITY_PROFILE);
  227. puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 2);
  228. #endif
  229. #endif
  230. }
  231. else
  232. {
  233. puglSetBackend(view, puglStubBackend());
  234. }
  235. }
  236. // --------------------------------------------------------------------------------------------------------------------
  237. // bring view window into the foreground, aka "raise" window
  238. void puglRaiseWindow(PuglView* const view)
  239. {
  240. #if defined(DISTRHO_OS_HAIKU)
  241. #elif defined(DISTRHO_OS_MAC)
  242. if (NSWindow* const window = view->impl->window ? view->impl->window
  243. : [view->impl->wrapperView window])
  244. [window orderFrontRegardless];
  245. #elif defined(DISTRHO_OS_WASM)
  246. // nothing
  247. #elif defined(DISTRHO_OS_WINDOWS)
  248. SetForegroundWindow(view->impl->hwnd);
  249. SetActiveWindow(view->impl->hwnd);
  250. #elif defined(HAVE_X11)
  251. XRaiseWindow(view->world->impl->display, view->impl->win);
  252. #endif
  253. }
  254. // --------------------------------------------------------------------------------------------------------------------
  255. // Combined puglSetSizeHint using PUGL_MIN_SIZE and PUGL_FIXED_ASPECT
  256. PuglStatus puglSetGeometryConstraints(PuglView* const view, const uint width, const uint height, const bool aspect)
  257. {
  258. view->sizeHints[PUGL_MIN_SIZE].width = width;
  259. view->sizeHints[PUGL_MIN_SIZE].height = height;
  260. if (aspect)
  261. {
  262. view->sizeHints[PUGL_FIXED_ASPECT].width = width;
  263. view->sizeHints[PUGL_FIXED_ASPECT].height = height;
  264. }
  265. #if defined(DISTRHO_OS_HAIKU)
  266. #elif defined(DISTRHO_OS_MAC)
  267. if (view->impl->window)
  268. {
  269. if (const PuglStatus status = updateSizeHint(view, PUGL_MIN_SIZE))
  270. return status;
  271. if (const PuglStatus status = updateSizeHint(view, PUGL_FIXED_ASPECT))
  272. return status;
  273. }
  274. #elif defined(DISTRHO_OS_WASM)
  275. // nothing
  276. #elif defined(DISTRHO_OS_WINDOWS)
  277. // nothing
  278. #elif defined(HAVE_X11)
  279. if (view->impl->win)
  280. {
  281. if (const PuglStatus status = updateSizeHints(view))
  282. return status;
  283. XFlush(view->world->impl->display);
  284. }
  285. #endif
  286. return PUGL_SUCCESS;
  287. }
  288. // --------------------------------------------------------------------------------------------------------------------
  289. // set view as resizable (or not) during runtime
  290. void puglSetResizable(PuglView* const view, const bool resizable)
  291. {
  292. puglSetViewHint(view, PUGL_RESIZABLE, resizable ? PUGL_TRUE : PUGL_FALSE);
  293. #if defined(DISTRHO_OS_HAIKU)
  294. #elif defined(DISTRHO_OS_MAC)
  295. if (PuglWindow* const window = view->impl->window)
  296. {
  297. const uint style = (NSClosableWindowMask | NSTitledWindowMask | NSMiniaturizableWindowMask)
  298. | (resizable ? NSResizableWindowMask : 0x0);
  299. [window setStyleMask:style];
  300. }
  301. // FIXME use [view setAutoresizingMask:NSViewNotSizable] ?
  302. #elif defined(DISTRHO_OS_WASM)
  303. // nothing
  304. #elif defined(DISTRHO_OS_WINDOWS)
  305. if (const HWND hwnd = view->impl->hwnd)
  306. {
  307. const uint winFlags = resizable ? GetWindowLong(hwnd, GWL_STYLE) | (WS_SIZEBOX | WS_MAXIMIZEBOX)
  308. : GetWindowLong(hwnd, GWL_STYLE) & ~(WS_SIZEBOX | WS_MAXIMIZEBOX);
  309. SetWindowLong(hwnd, GWL_STYLE, winFlags);
  310. }
  311. #elif defined(HAVE_X11)
  312. updateSizeHints(view);
  313. #endif
  314. }
  315. // --------------------------------------------------------------------------------------------------------------------
  316. // set window size while also changing default
  317. PuglStatus puglSetSizeAndDefault(PuglView* view, uint width, uint height)
  318. {
  319. if (width > INT16_MAX || height > INT16_MAX)
  320. return PUGL_BAD_PARAMETER;
  321. #ifdef DGL_USING_X11
  322. // workaround issues in fluxbox, see https://github.com/lv2/pugl/issues/118
  323. if (view->impl->win)
  324. {
  325. view->sizeHints[PUGL_DEFAULT_SIZE].width = view->sizeHints[PUGL_DEFAULT_SIZE].height = 0;
  326. }
  327. else
  328. #endif
  329. // set default size first
  330. {
  331. view->sizeHints[PUGL_DEFAULT_SIZE].width = static_cast<PuglSpan>(width);
  332. view->sizeHints[PUGL_DEFAULT_SIZE].height = static_cast<PuglSpan>(height);
  333. }
  334. #if defined(DISTRHO_OS_HAIKU)
  335. #elif defined(DISTRHO_OS_MAC)
  336. // matches upstream pugl
  337. if (view->impl->wrapperView)
  338. {
  339. if (const PuglStatus status = puglSetSize(view, width, height))
  340. return status;
  341. // nothing to do for PUGL_DEFAULT_SIZE hint
  342. }
  343. #elif defined(DISTRHO_OS_WASM)
  344. d_stdout("className is %s", view->world->strings[PUGL_CLASS_NAME]);
  345. emscripten_set_canvas_element_size(view->world->strings[PUGL_CLASS_NAME], width, height);
  346. #elif defined(DISTRHO_OS_WINDOWS)
  347. // matches upstream pugl, except we re-enter context after resize
  348. if (view->impl->hwnd)
  349. {
  350. if (const PuglStatus status = puglSetSize(view, width, height))
  351. return status;
  352. // nothing to do for PUGL_DEFAULT_SIZE hint
  353. // make sure to return context back to ourselves
  354. puglBackendEnter(view);
  355. }
  356. #elif defined(HAVE_X11)
  357. // matches upstream pugl, adds flush at the end
  358. if (view->impl->win)
  359. {
  360. if (const PuglStatus status = puglSetSize(view, width, height))
  361. return status;
  362. // handle new PUGL_DEFAULT_SIZE hint
  363. if (const PuglStatus status = updateSizeHints(view))
  364. return status;
  365. // flush size changes
  366. XFlush(view->world->impl->display);
  367. }
  368. #endif
  369. return PUGL_SUCCESS;
  370. }
  371. // --------------------------------------------------------------------------------------------------------------------
  372. // DGL specific, build-specific drawing prepare
  373. void puglOnDisplayPrepare(PuglView*)
  374. {
  375. #ifdef DGL_OPENGL
  376. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  377. #ifndef DGL_USE_OPENGL3
  378. glLoadIdentity();
  379. #endif
  380. #endif
  381. }
  382. // --------------------------------------------------------------------------------------------------------------------
  383. // DGL specific, build-specific fallback resize
  384. void puglFallbackOnResize(PuglView* const view, const uint width, const uint height)
  385. {
  386. #ifdef DGL_OPENGL
  387. glEnable(GL_BLEND);
  388. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  389. #ifdef DGL_USE_OPENGL3
  390. glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
  391. #else
  392. glMatrixMode(GL_PROJECTION);
  393. glLoadIdentity();
  394. glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0);
  395. glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
  396. glMatrixMode(GL_MODELVIEW);
  397. glLoadIdentity();
  398. #endif
  399. #else
  400. return;
  401. // unused
  402. (void)view;
  403. #endif
  404. }
  405. // --------------------------------------------------------------------------------------------------------------------
  406. #if defined(DISTRHO_OS_HAIKU)
  407. // --------------------------------------------------------------------------------------------------------------------
  408. #elif defined(DISTRHO_OS_MAC)
  409. // --------------------------------------------------------------------------------------------------------------------
  410. // macOS specific, add another view's window as child
  411. PuglStatus
  412. puglMacOSAddChildWindow(PuglView* const view, PuglView* const child)
  413. {
  414. if (NSWindow* const viewWindow = view->impl->window ? view->impl->window
  415. : [view->impl->wrapperView window])
  416. {
  417. if (NSWindow* const childWindow = child->impl->window ? child->impl->window
  418. : [child->impl->wrapperView window])
  419. {
  420. [viewWindow addChildWindow:childWindow ordered:NSWindowAbove];
  421. return PUGL_SUCCESS;
  422. }
  423. }
  424. return PUGL_FAILURE;
  425. }
  426. // --------------------------------------------------------------------------------------------------------------------
  427. // macOS specific, remove another view's window as child
  428. PuglStatus
  429. puglMacOSRemoveChildWindow(PuglView* const view, PuglView* const child)
  430. {
  431. if (NSWindow* const viewWindow = view->impl->window ? view->impl->window
  432. : [view->impl->wrapperView window])
  433. {
  434. if (NSWindow* const childWindow = child->impl->window ? child->impl->window
  435. : [child->impl->wrapperView window])
  436. {
  437. [viewWindow removeChildWindow:childWindow];
  438. return PUGL_SUCCESS;
  439. }
  440. }
  441. return PUGL_FAILURE;
  442. }
  443. // --------------------------------------------------------------------------------------------------------------------
  444. // macOS specific, center view based on parent coordinates (if there is one)
  445. void puglMacOSShowCentered(PuglView* const view)
  446. {
  447. if (puglShow(view, PUGL_SHOW_RAISE) != PUGL_SUCCESS)
  448. return;
  449. if (view->transientParent != 0)
  450. {
  451. NSWindow* const transientWindow = [(NSView*)view->transientParent window];
  452. DISTRHO_SAFE_ASSERT_RETURN(transientWindow != nullptr,);
  453. const NSRect ourFrame = [view->impl->window frame];
  454. const NSRect transientFrame = [transientWindow frame];
  455. const int x = transientFrame.origin.x + (transientFrame.size.width - ourFrame.size.width) / 2;
  456. const int y = transientFrame.origin.y + (transientFrame.size.height - ourFrame.size.height) / 2;
  457. [view->impl->window setFrameTopLeftPoint:NSMakePoint(x, y)];
  458. }
  459. else
  460. {
  461. [view->impl->window center];
  462. }
  463. }
  464. // --------------------------------------------------------------------------------------------------------------------
  465. #elif defined(DISTRHO_OS_WINDOWS)
  466. // --------------------------------------------------------------------------------------------------------------------
  467. // win32 specific, call ShowWindow with SW_RESTORE
  468. void puglWin32RestoreWindow(PuglView* const view)
  469. {
  470. PuglInternals* impl = view->impl;
  471. DISTRHO_SAFE_ASSERT_RETURN(impl->hwnd != nullptr,);
  472. ShowWindow(impl->hwnd, SW_RESTORE);
  473. SetFocus(impl->hwnd);
  474. }
  475. // --------------------------------------------------------------------------------------------------------------------
  476. // win32 specific, center view based on parent coordinates (if there is one)
  477. void puglWin32ShowCentered(PuglView* const view)
  478. {
  479. PuglInternals* impl = view->impl;
  480. DISTRHO_SAFE_ASSERT_RETURN(impl->hwnd != nullptr,);
  481. RECT rectChild, rectParent;
  482. if (view->transientParent != 0 &&
  483. GetWindowRect(impl->hwnd, &rectChild) &&
  484. GetWindowRect((HWND)view->transientParent, &rectParent))
  485. {
  486. SetWindowPos(impl->hwnd, HWND_TOP,
  487. rectParent.left + (rectParent.right-rectParent.left)/2 - (rectChild.right-rectChild.left)/2,
  488. rectParent.top + (rectParent.bottom-rectParent.top)/2 - (rectChild.bottom-rectChild.top)/2,
  489. 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
  490. }
  491. else
  492. {
  493. MONITORINFO mInfo;
  494. std::memset(&mInfo, 0, sizeof(mInfo));
  495. mInfo.cbSize = sizeof(mInfo);
  496. if (GetMonitorInfo(MonitorFromWindow(impl->hwnd, MONITOR_DEFAULTTOPRIMARY), &mInfo))
  497. SetWindowPos(impl->hwnd, HWND_TOP,
  498. mInfo.rcWork.left + (mInfo.rcWork.right - mInfo.rcWork.left - view->lastConfigure.width) / 2,
  499. mInfo.rcWork.top + (mInfo.rcWork.bottom - mInfo.rcWork.top - view->lastConfigure.height) / 2,
  500. 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
  501. else
  502. ShowWindow(impl->hwnd, SW_NORMAL);
  503. }
  504. SetFocus(impl->hwnd);
  505. }
  506. // --------------------------------------------------------------------------------------------------------------------
  507. #elif defined(DISTRHO_OS_WASM)
  508. // nothing here yet
  509. // --------------------------------------------------------------------------------------------------------------------
  510. #elif defined(HAVE_X11)
  511. // --------------------------------------------------------------------------------------------------------------------
  512. // X11 specific, update world without triggering exposure events
  513. PuglStatus puglX11UpdateWithoutExposures(PuglWorld* const world)
  514. {
  515. const bool wasDispatchingEvents = world->impl->dispatchingEvents;
  516. world->impl->dispatchingEvents = true;
  517. PuglStatus st = PUGL_SUCCESS;
  518. const double startTime = puglGetTime(world);
  519. const double endTime = startTime + 0.03;
  520. for (double t = startTime; !st && t < endTime; t = puglGetTime(world))
  521. {
  522. pollX11Socket(world, endTime - t);
  523. st = dispatchX11Events(world);
  524. }
  525. world->impl->dispatchingEvents = wasDispatchingEvents;
  526. return st;
  527. }
  528. // --------------------------------------------------------------------------------------------------------------------
  529. // X11 specific, set dialog window type and pid hints
  530. void puglX11SetWindowTypeAndPID(const PuglView* const view, const bool isStandalone)
  531. {
  532. const PuglInternals* const impl = view->impl;
  533. Display* const display = view->world->impl->display;
  534. const pid_t pid = getpid();
  535. const Atom _nwp = XInternAtom(display, "_NET_WM_PID", False);
  536. XChangeProperty(display, impl->win, _nwp, XA_CARDINAL, 32, PropModeReplace, (const uchar*)&pid, 1);
  537. #if defined(DGL_X11_WINDOW_ICON_NAME) && defined(DGL_X11_WINDOW_ICON_SIZE)
  538. if (isStandalone)
  539. {
  540. const Atom _nwi = XInternAtom(display, "_NET_WM_ICON", False);
  541. XChangeProperty(display, impl->win, _nwi, XA_CARDINAL, 32, PropModeReplace,
  542. (const uchar*)DGL_X11_WINDOW_ICON_NAME, DGL_X11_WINDOW_ICON_SIZE);
  543. }
  544. #endif
  545. const Atom _wt = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
  546. Atom _wts[2];
  547. int numAtoms = 0;
  548. if (! isStandalone)
  549. _wts[numAtoms++] = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
  550. _wts[numAtoms++] = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
  551. XChangeProperty(display, impl->win, _wt, XA_ATOM, 32, PropModeReplace, (const uchar*)&_wts, numAtoms);
  552. }
  553. // --------------------------------------------------------------------------------------------------------------------
  554. #endif // HAVE_X11
  555. #ifndef DISTRHO_OS_MAC
  556. END_NAMESPACE_DGL
  557. #endif