Audio plugin host https://kx.studio/carla
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.

1379 lines
41KB

  1. /*
  2. * Carla Plugin UI
  3. * Copyright (C) 2014-2020 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaJuceUtils.hpp"
  18. #include "CarlaPluginUI.hpp"
  19. #ifdef HAVE_X11
  20. # include <sys/types.h>
  21. # include <X11/Xatom.h>
  22. # include <X11/Xlib.h>
  23. # include <X11/Xutil.h>
  24. # include "CarlaPluginUI_X11Icon.hpp"
  25. #endif
  26. #ifdef CARLA_OS_MAC
  27. # include "CarlaMacUtils.hpp"
  28. # import <Cocoa/Cocoa.h>
  29. #endif
  30. #ifdef CARLA_OS_WIN
  31. # include <ctime>
  32. # include "water/common.hpp"
  33. #endif
  34. #ifndef CARLA_PLUGIN_UI_CLASS_PREFIX
  35. # error CARLA_PLUGIN_UI_CLASS_PREFIX undefined
  36. #endif
  37. // ---------------------------------------------------------------------------------------------------------------------
  38. // X11
  39. #ifdef HAVE_X11
  40. typedef void (*EventProcPtr)(XEvent* ev);
  41. static const uint X11Key_Escape = 9;
  42. static bool gErrorTriggered = false;
  43. static int temporaryErrorHandler(Display*, XErrorEvent*)
  44. {
  45. gErrorTriggered = true;
  46. return 0;
  47. }
  48. class X11PluginUI : public CarlaPluginUI
  49. {
  50. public:
  51. X11PluginUI(Callback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
  52. : CarlaPluginUI(cb, isResizable),
  53. fDisplay(nullptr),
  54. fHostWindow(0),
  55. fChildWindow(0),
  56. fChildWindowConfigured(false),
  57. fIsVisible(false),
  58. fFirstShow(true),
  59. fSetSizeCalledAtLeastOnce(false),
  60. fEventProc(nullptr)
  61. {
  62. fDisplay = XOpenDisplay(nullptr);
  63. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  64. const int screen = DefaultScreen(fDisplay);
  65. XSetWindowAttributes attr;
  66. carla_zeroStruct(attr);
  67. attr.event_mask = KeyPressMask|KeyReleaseMask|FocusChangeMask|StructureNotifyMask|SubstructureNotifyMask;
  68. fHostWindow = XCreateWindow(fDisplay, RootWindow(fDisplay, screen),
  69. 0, 0, 300, 300, 0,
  70. DefaultDepth(fDisplay, screen),
  71. InputOutput,
  72. DefaultVisual(fDisplay, screen),
  73. CWBorderPixel|CWEventMask, &attr);
  74. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  75. XGrabKey(fDisplay, X11Key_Escape, AnyModifier, fHostWindow, 1, GrabModeAsync, GrabModeAsync);
  76. Atom wmDelete = XInternAtom(fDisplay, "WM_DELETE_WINDOW", True);
  77. XSetWMProtocols(fDisplay, fHostWindow, &wmDelete, 1);
  78. const pid_t pid = getpid();
  79. const Atom _nwp = XInternAtom(fDisplay, "_NET_WM_PID", False);
  80. XChangeProperty(fDisplay, fHostWindow, _nwp, XA_CARDINAL, 32, PropModeReplace, (const uchar*)&pid, 1);
  81. const Atom _nwi = XInternAtom(fDisplay, "_NET_WM_ICON", False);
  82. XChangeProperty(fDisplay, fHostWindow, _nwi, XA_CARDINAL, 32, PropModeReplace, (const uchar*)sCarlaX11Icon, sCarlaX11IconSize);
  83. const Atom _wt = XInternAtom(fDisplay, "_NET_WM_WINDOW_TYPE", False);
  84. // Setting the window to both dialog and normal will produce a decorated floating dialog
  85. // Order is important: DIALOG needs to come before NORMAL
  86. const Atom _wts[2] = {
  87. XInternAtom(fDisplay, "_NET_WM_WINDOW_TYPE_DIALOG", False),
  88. XInternAtom(fDisplay, "_NET_WM_WINDOW_TYPE_NORMAL", False)
  89. };
  90. XChangeProperty(fDisplay, fHostWindow, _wt, XA_ATOM, 32, PropModeReplace, (const uchar*)&_wts, 2);
  91. if (parentId != 0)
  92. setTransientWinId(parentId);
  93. }
  94. ~X11PluginUI() override
  95. {
  96. CARLA_SAFE_ASSERT(! fIsVisible);
  97. if (fIsVisible)
  98. {
  99. XUnmapWindow(fDisplay, fHostWindow);
  100. fIsVisible = false;
  101. }
  102. if (fHostWindow != 0)
  103. {
  104. XDestroyWindow(fDisplay, fHostWindow);
  105. fHostWindow = 0;
  106. }
  107. if (fDisplay != nullptr)
  108. {
  109. XCloseDisplay(fDisplay);
  110. fDisplay = nullptr;
  111. }
  112. }
  113. void show() override
  114. {
  115. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  116. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  117. if (fFirstShow)
  118. {
  119. if (const Window childWindow = getChildWindow())
  120. {
  121. if (! fSetSizeCalledAtLeastOnce)
  122. {
  123. XSizeHints hints;
  124. carla_zeroStruct(hints);
  125. if (XGetNormalHints(fDisplay, childWindow, &hints))
  126. {
  127. int width = 0;
  128. int height = 0;
  129. if (hints.flags & PSize)
  130. {
  131. width = hints.width;
  132. height = hints.height;
  133. }
  134. else if (hints.flags & PBaseSize)
  135. {
  136. width = hints.base_width;
  137. height = hints.base_height;
  138. }
  139. else if (hints.flags & PMinSize)
  140. {
  141. width = hints.min_width;
  142. height = hints.min_height;
  143. }
  144. if (width > 0 && height > 0)
  145. setSize(static_cast<uint>(width), static_cast<uint>(height), false);
  146. }
  147. }
  148. const Atom _xevp = XInternAtom(fDisplay, "_XEventProc", False);
  149. gErrorTriggered = false;
  150. const XErrorHandler oldErrorHandler(XSetErrorHandler(temporaryErrorHandler));
  151. Atom actualType;
  152. int actualFormat;
  153. ulong nitems, bytesAfter;
  154. uchar* data = nullptr;
  155. XGetWindowProperty(fDisplay, childWindow, _xevp, 0, 1, False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesAfter, &data);
  156. XSetErrorHandler(oldErrorHandler);
  157. if (nitems == 1 && ! gErrorTriggered)
  158. {
  159. fEventProc = *reinterpret_cast<EventProcPtr*>(data);
  160. XMapRaised(fDisplay, childWindow);
  161. }
  162. }
  163. }
  164. fIsVisible = true;
  165. fFirstShow = false;
  166. XMapRaised(fDisplay, fHostWindow);
  167. XSync(fDisplay, False);
  168. }
  169. void hide() override
  170. {
  171. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  172. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  173. fIsVisible = false;
  174. XUnmapWindow(fDisplay, fHostWindow);
  175. XFlush(fDisplay);
  176. }
  177. void idle() override
  178. {
  179. // prevent recursion
  180. if (fIsIdling) return;
  181. int nextWidth = 0;
  182. int nextHeight = 0;
  183. fIsIdling = true;
  184. for (XEvent event; XPending(fDisplay) > 0;)
  185. {
  186. XNextEvent(fDisplay, &event);
  187. if (! fIsVisible)
  188. continue;
  189. char* type = nullptr;
  190. switch (event.type)
  191. {
  192. case ConfigureNotify:
  193. CARLA_SAFE_ASSERT_CONTINUE(fCallback != nullptr);
  194. CARLA_SAFE_ASSERT_CONTINUE(event.xconfigure.width > 0);
  195. CARLA_SAFE_ASSERT_CONTINUE(event.xconfigure.height > 0);
  196. if (event.xconfigure.window == fHostWindow)
  197. {
  198. const uint width = static_cast<uint>(event.xconfigure.width);
  199. const uint height = static_cast<uint>(event.xconfigure.height);
  200. if (fChildWindow != 0)
  201. {
  202. if (! fChildWindowConfigured)
  203. {
  204. gErrorTriggered = false;
  205. const XErrorHandler oldErrorHandler = XSetErrorHandler(temporaryErrorHandler);
  206. XSizeHints sizeHints;
  207. carla_zeroStruct(sizeHints);
  208. if (XGetNormalHints(fDisplay, fChildWindow, &sizeHints) && !gErrorTriggered)
  209. {
  210. XSetNormalHints(fDisplay, fHostWindow, &sizeHints);
  211. }
  212. else
  213. {
  214. carla_stdout("Caught errors while accessing child window");
  215. fChildWindow = 0;
  216. }
  217. fChildWindowConfigured = true;
  218. XSetErrorHandler(oldErrorHandler);
  219. }
  220. if (fChildWindow != 0)
  221. XResizeWindow(fDisplay, fChildWindow, width, height);
  222. }
  223. fCallback->handlePluginUIResized(width, height);
  224. }
  225. else if (event.xconfigure.window == fChildWindow && fChildWindow != 0)
  226. {
  227. nextWidth = event.xconfigure.width;
  228. nextHeight = event.xconfigure.height;
  229. }
  230. break;
  231. case ClientMessage:
  232. type = XGetAtomName(fDisplay, event.xclient.message_type);
  233. CARLA_SAFE_ASSERT_CONTINUE(type != nullptr);
  234. if (std::strcmp(type, "WM_PROTOCOLS") == 0)
  235. {
  236. fIsVisible = false;
  237. CARLA_SAFE_ASSERT_CONTINUE(fCallback != nullptr);
  238. fCallback->handlePluginUIClosed();
  239. }
  240. break;
  241. case KeyRelease:
  242. if (event.xkey.keycode == X11Key_Escape)
  243. {
  244. fIsVisible = false;
  245. CARLA_SAFE_ASSERT_CONTINUE(fCallback != nullptr);
  246. fCallback->handlePluginUIClosed();
  247. }
  248. break;
  249. case FocusIn:
  250. if (fChildWindow == 0)
  251. fChildWindow = getChildWindow();
  252. if (fChildWindow != 0)
  253. XSetInputFocus(fDisplay, fChildWindow, RevertToNone, CurrentTime);
  254. break;
  255. }
  256. if (type != nullptr)
  257. XFree(type);
  258. else if (fEventProc != nullptr)
  259. fEventProc(&event);
  260. }
  261. if (nextWidth != 0 && nextHeight != 0)
  262. {
  263. XSizeHints sizeHints;
  264. carla_zeroStruct(sizeHints);
  265. if (XGetNormalHints(fDisplay, fChildWindow, &sizeHints))
  266. XSetNormalHints(fDisplay, fHostWindow, &sizeHints);
  267. XResizeWindow(fDisplay, fHostWindow, static_cast<uint>(nextWidth), static_cast<uint>(nextHeight));
  268. XFlush(fDisplay);
  269. }
  270. fIsIdling = false;
  271. }
  272. void focus() override
  273. {
  274. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  275. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  276. XWindowAttributes wa;
  277. carla_zeroStruct(wa);
  278. CARLA_SAFE_ASSERT_RETURN(XGetWindowAttributes(fDisplay, fHostWindow, &wa),);
  279. if (wa.map_state == IsViewable)
  280. {
  281. XRaiseWindow(fDisplay, fHostWindow);
  282. XSetInputFocus(fDisplay, fHostWindow, RevertToPointerRoot, CurrentTime);
  283. XSync(fDisplay, False);
  284. }
  285. }
  286. void setSize(const uint width, const uint height, const bool forceUpdate) override
  287. {
  288. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  289. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  290. fSetSizeCalledAtLeastOnce = true;
  291. XResizeWindow(fDisplay, fHostWindow, width, height);
  292. if (fChildWindow != 0)
  293. XResizeWindow(fDisplay, fChildWindow, width, height);
  294. if (! fIsResizable)
  295. {
  296. XSizeHints sizeHints;
  297. carla_zeroStruct(sizeHints);
  298. sizeHints.flags = PSize|PMinSize|PMaxSize;
  299. sizeHints.width = static_cast<int>(width);
  300. sizeHints.height = static_cast<int>(height);
  301. sizeHints.min_width = static_cast<int>(width);
  302. sizeHints.min_height = static_cast<int>(height);
  303. sizeHints.max_width = static_cast<int>(width);
  304. sizeHints.max_height = static_cast<int>(height);
  305. XSetNormalHints(fDisplay, fHostWindow, &sizeHints);
  306. }
  307. if (forceUpdate)
  308. XSync(fDisplay, False);
  309. }
  310. void setTitle(const char* const title) override
  311. {
  312. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  313. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  314. XStoreName(fDisplay, fHostWindow, title);
  315. }
  316. void setTransientWinId(const uintptr_t winId) override
  317. {
  318. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,);
  319. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,);
  320. XSetTransientForHint(fDisplay, fHostWindow, static_cast<Window>(winId));
  321. }
  322. void setChildWindow(void* const winId) override
  323. {
  324. CARLA_SAFE_ASSERT_RETURN(winId != nullptr,);
  325. fChildWindow = (Window)winId;
  326. }
  327. void* getPtr() const noexcept override
  328. {
  329. return (void*)fHostWindow;
  330. }
  331. void* getDisplay() const noexcept override
  332. {
  333. return fDisplay;
  334. }
  335. protected:
  336. Window getChildWindow() const
  337. {
  338. CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr, 0);
  339. CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0, 0);
  340. Window rootWindow, parentWindow, ret = 0;
  341. Window* childWindows = nullptr;
  342. uint numChildren = 0;
  343. XQueryTree(fDisplay, fHostWindow, &rootWindow, &parentWindow, &childWindows, &numChildren);
  344. if (numChildren > 0 && childWindows != nullptr)
  345. {
  346. ret = childWindows[0];
  347. XFree(childWindows);
  348. }
  349. return ret;
  350. }
  351. private:
  352. Display* fDisplay;
  353. Window fHostWindow;
  354. Window fChildWindow;
  355. bool fChildWindowConfigured;
  356. bool fIsVisible;
  357. bool fFirstShow;
  358. bool fSetSizeCalledAtLeastOnce;
  359. EventProcPtr fEventProc;
  360. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(X11PluginUI)
  361. };
  362. #endif // HAVE_X11
  363. // ---------------------------------------------------------------------------------------------------------------------
  364. // MacOS / Cocoa
  365. #ifdef CARLA_OS_MAC
  366. #if defined(BUILD_BRIDGE_ALTERNATIVE_ARCH)
  367. # define CarlaPluginWindow CARLA_JOIN_MACRO(CarlaPluginWindowBridgedArch, CARLA_PLUGIN_UI_CLASS_PREFIX)
  368. #elif defined(BUILD_BRIDGE)
  369. # define CarlaPluginWindow CARLA_JOIN_MACRO(CarlaPluginWindowBridged, CARLA_PLUGIN_UI_CLASS_PREFIX)
  370. #else
  371. # define CarlaPluginWindow CARLA_JOIN_MACRO(CarlaPluginWindow, CARLA_PLUGIN_UI_CLASS_PREFIX)
  372. #endif
  373. @interface CarlaPluginWindow : NSWindow
  374. {
  375. @public
  376. CarlaPluginUI::Callback* callback;
  377. }
  378. - (id) initWithContentRect:(NSRect)contentRect
  379. styleMask:(unsigned int)aStyle
  380. backing:(NSBackingStoreType)bufferingType
  381. defer:(BOOL)flag;
  382. - (void) setCallback:(CarlaPluginUI::Callback*)cb;
  383. - (BOOL) acceptsFirstResponder;
  384. - (BOOL) canBecomeKeyWindow;
  385. - (BOOL) canBecomeMainWindow;
  386. - (BOOL) windowShouldClose:(id)sender;
  387. - (NSSize) windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize;
  388. @end
  389. @implementation CarlaPluginWindow
  390. - (id)initWithContentRect:(NSRect)contentRect
  391. styleMask:(unsigned int)aStyle
  392. backing:(NSBackingStoreType)bufferingType
  393. defer:(BOOL)flag
  394. {
  395. callback = nil;
  396. NSWindow* result = [super initWithContentRect:contentRect
  397. styleMask:aStyle
  398. backing:bufferingType
  399. defer:flag];
  400. [result setAcceptsMouseMovedEvents:YES];
  401. return (CarlaPluginWindow*)result;
  402. // unused
  403. (void)flag;
  404. }
  405. - (void)setCallback:(CarlaPluginUI::Callback*)cb
  406. {
  407. callback = cb;
  408. }
  409. - (BOOL)acceptsFirstResponder
  410. {
  411. return YES;
  412. }
  413. - (BOOL)canBecomeKeyWindow
  414. {
  415. return YES;
  416. }
  417. - (BOOL)canBecomeMainWindow
  418. {
  419. return NO;
  420. }
  421. - (BOOL)windowShouldClose:(id)sender
  422. {
  423. if (callback != nil)
  424. callback->handlePluginUIClosed();
  425. return NO;
  426. // unused
  427. (void)sender;
  428. }
  429. - (NSSize) windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize
  430. {
  431. if (callback != nil)
  432. callback->handlePluginUIResized(frameSize.width, frameSize.height);
  433. return frameSize;
  434. // unused
  435. (void)sender;
  436. }
  437. @end
  438. class CocoaPluginUI : public CarlaPluginUI
  439. {
  440. public:
  441. CocoaPluginUI(Callback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
  442. : CarlaPluginUI(cb, isResizable),
  443. fView(nullptr),
  444. fParentWindow(nullptr),
  445. fWindow(nullptr)
  446. {
  447. carla_debug("CocoaPluginUI::CocoaPluginUI(%p, " P_UINTPTR, "%s)", cb, parentId, bool2str(isResizable));
  448. const CarlaBackend::AutoNSAutoreleasePool arp;
  449. [NSApplication sharedApplication];
  450. fView = [[NSView new]retain];
  451. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,)
  452. uint style = NSClosableWindowMask | NSTitledWindowMask;
  453. /*
  454. if (isResizable)
  455. style |= NSResizableWindowMask;
  456. */
  457. NSRect frame = NSMakeRect(0, 0, 100, 100);
  458. fWindow = [[[CarlaPluginWindow alloc]
  459. initWithContentRect:frame
  460. styleMask:style
  461. backing:NSBackingStoreBuffered
  462. defer:NO
  463. ] retain];
  464. if (fWindow == nullptr)
  465. {
  466. [fView release];
  467. fView = nullptr;
  468. return;
  469. }
  470. //if (! isResizable)
  471. {
  472. [fView setAutoresizingMask:NSViewNotSizable];
  473. [[fWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
  474. }
  475. [fWindow setCallback:cb];
  476. [fWindow setContentView:fView];
  477. [fWindow makeFirstResponder:fView];
  478. [fView setHidden:NO];
  479. if (parentId != 0)
  480. setTransientWinId(parentId);
  481. }
  482. ~CocoaPluginUI() override
  483. {
  484. carla_debug("CocoaPluginUI::~CocoaPluginUI()");
  485. if (fView == nullptr)
  486. return;
  487. [fView setHidden:YES];
  488. [fView removeFromSuperview];
  489. [fWindow close];
  490. [fView release];
  491. [fWindow release];
  492. }
  493. void show() override
  494. {
  495. carla_debug("CocoaPluginUI::show()");
  496. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);
  497. if (fParentWindow != nullptr)
  498. {
  499. [fParentWindow addChildWindow:fWindow
  500. ordered:NSWindowAbove];
  501. }
  502. else
  503. {
  504. [fWindow setIsVisible:YES];
  505. }
  506. }
  507. void hide() override
  508. {
  509. carla_debug("CocoaPluginUI::hide()");
  510. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);
  511. [fWindow setIsVisible:NO];
  512. if (fParentWindow != nullptr)
  513. [fParentWindow removeChildWindow:fWindow];
  514. }
  515. void idle() override
  516. {
  517. // carla_debug("CocoaPluginUI::idle()");
  518. }
  519. void focus() override
  520. {
  521. carla_debug("CocoaPluginUI::focus()");
  522. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  523. [fWindow makeKeyAndOrderFront:fWindow];
  524. [NSApp activateIgnoringOtherApps:YES];
  525. }
  526. void setSize(const uint width, const uint height, const bool forceUpdate) override
  527. {
  528. carla_debug("CocoaPluginUI::setSize(%u, %u, %s)", width, height, bool2str(forceUpdate));
  529. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  530. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);
  531. [fView setFrame:NSMakeRect(0, 0, width, height)];
  532. for (NSView* subview in [fView subviews])
  533. {
  534. [subview setFrame:NSMakeRect(0, 0, width, height)];
  535. break;
  536. }
  537. const NSSize size = NSMakeSize(width, height);
  538. [fWindow setContentSize:size];
  539. /*
  540. if (fIsResizable)
  541. {
  542. [fWindow setContentMinSize:NSMakeSize(1, 1)];
  543. [fWindow setContentMaxSize:NSMakeSize(99999, 99999)];
  544. }
  545. else
  546. {
  547. [fWindow setContentMinSize:size];
  548. [fWindow setContentMaxSize:size];
  549. }
  550. */
  551. if (forceUpdate)
  552. {
  553. // FIXME, not enough
  554. [fView setNeedsDisplay:YES];
  555. }
  556. }
  557. void setTitle(const char* const title) override
  558. {
  559. carla_debug("CocoaPluginUI::setTitle(\"%s\")", title);
  560. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  561. NSString* titleString = [[NSString alloc]
  562. initWithBytes:title
  563. length:strlen(title)
  564. encoding:NSUTF8StringEncoding];
  565. [fWindow setTitle:titleString];
  566. }
  567. void setTransientWinId(const uintptr_t winId) override
  568. {
  569. carla_debug("CocoaPluginUI::setTransientWinId(" P_UINTPTR ")", winId);
  570. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  571. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:winId];
  572. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);
  573. fParentWindow = parentWindow;
  574. if ([fWindow isVisible])
  575. [fParentWindow addChildWindow:fWindow
  576. ordered:NSWindowAbove];
  577. }
  578. void setChildWindow(void* const childWindow) override
  579. {
  580. carla_debug("CocoaPluginUI::setChildWindow(%p)", childWindow);
  581. CARLA_SAFE_ASSERT_RETURN(childWindow != nullptr,);
  582. NSView* const view = (NSView*)childWindow;
  583. const NSRect frame = [view frame];
  584. [fWindow setContentSize:frame.size];
  585. [fView setFrame:frame];
  586. [fView setNeedsDisplay:YES];
  587. }
  588. void* getPtr() const noexcept override
  589. {
  590. carla_debug("CocoaPluginUI::getPtr()");
  591. return (void*)fView;
  592. }
  593. void* getDisplay() const noexcept
  594. {
  595. carla_debug("CocoaPluginUI::getDisplay()");
  596. return (void*)fWindow;
  597. }
  598. private:
  599. NSView* fView;
  600. NSWindow* fParentWindow;
  601. CarlaPluginWindow* fWindow;
  602. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CocoaPluginUI)
  603. };
  604. #endif // CARLA_OS_MAC
  605. // ---------------------------------------------------------------------------------------------------------------------
  606. // Windows
  607. #ifdef CARLA_OS_WIN
  608. #define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50)
  609. static LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  610. class WindowsPluginUI : public CarlaPluginUI
  611. {
  612. public:
  613. WindowsPluginUI(Callback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
  614. : CarlaPluginUI(cb, isResizable),
  615. fWindow(nullptr),
  616. fChildWindow(nullptr),
  617. fParentWindow(nullptr),
  618. fIsVisible(false),
  619. fFirstShow(true)
  620. {
  621. // FIXME
  622. static int wc_count = 0;
  623. char classNameBuf[32];
  624. std::srand((std::time(nullptr)));
  625. std::snprintf(classNameBuf, 32, "CarlaWin-%d-%d", ++wc_count, std::rand());
  626. classNameBuf[31] = '\0';
  627. const HINSTANCE hInstance = water::getCurrentModuleInstanceHandle();
  628. carla_zeroStruct(fWindowClass);
  629. fWindowClass.style = CS_OWNDC;
  630. fWindowClass.lpfnWndProc = wndProc;
  631. fWindowClass.hInstance = hInstance;
  632. fWindowClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
  633. fWindowClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
  634. fWindowClass.lpszClassName = strdup(classNameBuf);
  635. if (!RegisterClass(&fWindowClass)) {
  636. free((void*)fWindowClass.lpszClassName);
  637. return;
  638. }
  639. int winFlags = WS_POPUPWINDOW | WS_CAPTION;
  640. if (isResizable)
  641. {
  642. // not supported right now
  643. // winFlags |= WS_SIZEBOX;
  644. }
  645. #ifdef BUILDING_CARLA_FOR_WINE
  646. const uint winType = WS_EX_DLGMODALFRAME;
  647. const HWND parent = nullptr;
  648. #else
  649. const uint winType = WS_EX_TOOLWINDOW;
  650. const HWND parent = (HWND)parentId;
  651. #endif
  652. fWindow = CreateWindowEx(winType,
  653. classNameBuf, "Carla Plugin UI", winFlags,
  654. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  655. parent, nullptr,
  656. hInstance, nullptr);
  657. if (fWindow == nullptr) {
  658. const DWORD errorCode = ::GetLastError();
  659. carla_stderr2("CreateWindowEx failed with error code 0x%x, class name was '%s'",
  660. errorCode, fWindowClass.lpszClassName);
  661. UnregisterClass(fWindowClass.lpszClassName, nullptr);
  662. free((void*)fWindowClass.lpszClassName);
  663. return;
  664. }
  665. SetWindowLongPtr(fWindow, GWLP_USERDATA, (LONG_PTR)this);
  666. #ifndef BUILDING_CARLA_FOR_WINE
  667. if (parentId != 0)
  668. setTransientWinId(parentId);
  669. #endif
  670. return;
  671. // maybe unused
  672. (void)parentId;
  673. }
  674. ~WindowsPluginUI() override
  675. {
  676. CARLA_SAFE_ASSERT(! fIsVisible);
  677. if (fWindow != 0)
  678. {
  679. if (fIsVisible)
  680. ShowWindow(fWindow, SW_HIDE);
  681. DestroyWindow(fWindow);
  682. fWindow = 0;
  683. }
  684. // FIXME
  685. UnregisterClass(fWindowClass.lpszClassName, nullptr);
  686. free((void*)fWindowClass.lpszClassName);
  687. }
  688. void show() override
  689. {
  690. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  691. if (fFirstShow)
  692. {
  693. fFirstShow = false;
  694. RECT rectChild, rectParent;
  695. if (fParentWindow != nullptr &&
  696. GetWindowRect(fWindow, &rectChild) &&
  697. GetWindowRect(fParentWindow, &rectParent))
  698. {
  699. SetWindowPos(fWindow, fParentWindow,
  700. rectParent.left + (rectChild.right-rectChild.left)/2,
  701. rectParent.top + (rectChild.bottom-rectChild.top)/2,
  702. 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
  703. }
  704. else
  705. {
  706. ShowWindow(fWindow, SW_SHOWNORMAL);
  707. }
  708. }
  709. else
  710. {
  711. ShowWindow(fWindow, SW_RESTORE);
  712. }
  713. fIsVisible = true;
  714. UpdateWindow(fWindow);
  715. }
  716. void hide() override
  717. {
  718. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  719. ShowWindow(fWindow, SW_HIDE);
  720. fIsVisible = false;
  721. UpdateWindow(fWindow);
  722. }
  723. void idle() override
  724. {
  725. if (fIsIdling || fWindow == nullptr)
  726. return;
  727. MSG msg;
  728. fIsIdling = true;
  729. while (::PeekMessage(&msg, fWindow, 0, 0, PM_REMOVE))
  730. {
  731. switch (msg.message)
  732. {
  733. case WM_QUIT:
  734. case PUGL_LOCAL_CLOSE_MSG:
  735. fIsVisible = false;
  736. CARLA_SAFE_ASSERT_BREAK(fCallback != nullptr);
  737. fCallback->handlePluginUIClosed();
  738. break;
  739. }
  740. DispatchMessageA(&msg);
  741. }
  742. fIsIdling = false;
  743. }
  744. LRESULT checkAndHandleMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  745. {
  746. if (fWindow == hwnd)
  747. {
  748. switch (message)
  749. {
  750. case WM_QUIT:
  751. case PUGL_LOCAL_CLOSE_MSG:
  752. fIsVisible = false;
  753. CARLA_SAFE_ASSERT_BREAK(fCallback != nullptr);
  754. fCallback->handlePluginUIClosed();
  755. break;
  756. }
  757. }
  758. return DefWindowProcA(hwnd, message, wParam, lParam);
  759. }
  760. void focus() override
  761. {
  762. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  763. SetForegroundWindow(fWindow);
  764. SetActiveWindow(fWindow);
  765. SetFocus(fWindow);
  766. }
  767. void setSize(const uint width, const uint height, const bool forceUpdate) override
  768. {
  769. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  770. const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fIsResizable ? WS_SIZEBOX : 0x0);
  771. RECT wr = { 0, 0, static_cast<long>(width), static_cast<long>(height) };
  772. AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST);
  773. SetWindowPos(fWindow, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top,
  774. SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
  775. if (forceUpdate)
  776. UpdateWindow(fWindow);
  777. }
  778. void setTitle(const char* const title) override
  779. {
  780. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  781. SetWindowTextA(fWindow, title);
  782. }
  783. void setTransientWinId(const uintptr_t winId) override
  784. {
  785. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  786. fParentWindow = (HWND)winId;
  787. SetWindowLongPtr(fWindow, GWLP_HWNDPARENT, (LONG_PTR)winId);
  788. }
  789. void setChildWindow(void* const winId) override
  790. {
  791. CARLA_SAFE_ASSERT_RETURN(winId != nullptr,);
  792. fChildWindow = (HWND)fChildWindow;
  793. }
  794. void* getPtr() const noexcept override
  795. {
  796. return (void*)fWindow;
  797. }
  798. void* getDisplay() const noexcept
  799. {
  800. return nullptr;
  801. }
  802. private:
  803. HWND fWindow;
  804. HWND fChildWindow;
  805. HWND fParentWindow;
  806. WNDCLASS fWindowClass;
  807. bool fIsVisible;
  808. bool fFirstShow;
  809. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WindowsPluginUI)
  810. };
  811. LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  812. {
  813. switch (message)
  814. {
  815. case WM_CLOSE:
  816. PostMessage(hwnd, PUGL_LOCAL_CLOSE_MSG, wParam, lParam);
  817. return 0;
  818. #if 0
  819. case WM_CREATE:
  820. PostMessage(hwnd, WM_SHOWWINDOW, TRUE, 0);
  821. return 0;
  822. case WM_DESTROY:
  823. return 0;
  824. #endif
  825. default:
  826. if (WindowsPluginUI* const ui = (WindowsPluginUI*)GetWindowLongPtr(hwnd, GWLP_USERDATA))
  827. return ui->checkAndHandleMessage(hwnd, message, wParam, lParam);
  828. return DefWindowProcA(hwnd, message, wParam, lParam);
  829. }
  830. }
  831. #endif // CARLA_OS_WIN
  832. // -----------------------------------------------------
  833. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  834. bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* const uiTitle, const uintptr_t winId, const bool centerUI)
  835. {
  836. CARLA_SAFE_ASSERT_RETURN(uiTitle != nullptr && uiTitle[0] != '\0', true);
  837. CARLA_SAFE_ASSERT_RETURN(winId != 0, true);
  838. #if defined(HAVE_X11)
  839. struct ScopedDisplay {
  840. Display* display;
  841. ScopedDisplay() : display(XOpenDisplay(nullptr)) {}
  842. ~ScopedDisplay() { if (display!=nullptr) XCloseDisplay(display); }
  843. // c++ compat stuff
  844. CARLA_PREVENT_HEAP_ALLOCATION
  845. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisplay)
  846. };
  847. struct ScopedFreeData {
  848. union {
  849. char* data;
  850. uchar* udata;
  851. };
  852. ScopedFreeData(char* d) : data(d) {}
  853. ScopedFreeData(uchar* d) : udata(d) {}
  854. ~ScopedFreeData() { XFree(data); }
  855. // c++ compat stuff
  856. CARLA_PREVENT_HEAP_ALLOCATION
  857. CARLA_DECLARE_NON_COPY_CLASS(ScopedFreeData)
  858. };
  859. const ScopedDisplay sd;
  860. CARLA_SAFE_ASSERT_RETURN(sd.display != nullptr, true);
  861. const Window rootWindow(DefaultRootWindow(sd.display));
  862. const Atom _ncl = XInternAtom(sd.display, "_NET_CLIENT_LIST" , False);
  863. const Atom _nwn = XInternAtom(sd.display, "_NET_WM_NAME", False);
  864. const Atom _nwp = XInternAtom(sd.display, "_NET_WM_PID", False);
  865. const Atom utf8 = XInternAtom(sd.display, "UTF8_STRING", True);
  866. Atom actualType;
  867. int actualFormat;
  868. ulong numWindows, bytesAfter;
  869. uchar* data = nullptr;
  870. int status = XGetWindowProperty(sd.display, rootWindow, _ncl, 0L, (~0L), False, AnyPropertyType, &actualType, &actualFormat, &numWindows, &bytesAfter, &data);
  871. CARLA_SAFE_ASSERT_RETURN(data != nullptr, true);
  872. const ScopedFreeData sfd(data);
  873. CARLA_SAFE_ASSERT_RETURN(status == Success, true);
  874. CARLA_SAFE_ASSERT_RETURN(actualFormat == 32, true);
  875. CARLA_SAFE_ASSERT_RETURN(numWindows != 0, true);
  876. Window* windows = (Window*)data;
  877. Window lastGoodWindowPID = 0, lastGoodWindowNameSimple = 0, lastGoodWindowNameUTF8 = 0;
  878. for (ulong i = 0; i < numWindows; i++)
  879. {
  880. const Window window(windows[i]);
  881. CARLA_SAFE_ASSERT_CONTINUE(window != 0);
  882. // ------------------------------------------------
  883. // try using pid
  884. if (pid != 0)
  885. {
  886. ulong pidSize;
  887. uchar* pidData = nullptr;
  888. status = XGetWindowProperty(sd.display, window, _nwp, 0L, (~0L), False, XA_CARDINAL, &actualType, &actualFormat, &pidSize, &bytesAfter, &pidData);
  889. if (pidData != nullptr)
  890. {
  891. const ScopedFreeData sfd2(pidData);
  892. CARLA_SAFE_ASSERT_CONTINUE(status == Success);
  893. CARLA_SAFE_ASSERT_CONTINUE(pidSize != 0);
  894. if (*(ulong*)pidData == static_cast<ulong>(pid))
  895. lastGoodWindowPID = window;
  896. }
  897. }
  898. // ------------------------------------------------
  899. // try using name (UTF-8)
  900. ulong nameSize;
  901. uchar* nameData = nullptr;
  902. status = XGetWindowProperty(sd.display, window, _nwn, 0L, (~0L), False, utf8, &actualType, &actualFormat, &nameSize, &bytesAfter, &nameData);
  903. if (nameData != nullptr)
  904. {
  905. const ScopedFreeData sfd2(nameData);
  906. CARLA_SAFE_ASSERT_CONTINUE(status == Success);
  907. if (nameSize != 0 && std::strstr((const char*)nameData, uiTitle) != nullptr)
  908. lastGoodWindowNameUTF8 = window;
  909. }
  910. // ------------------------------------------------
  911. // try using name (simple)
  912. char* wmName = nullptr;
  913. status = XFetchName(sd.display, window, &wmName);
  914. if (wmName != nullptr)
  915. {
  916. const ScopedFreeData sfd2(wmName);
  917. CARLA_SAFE_ASSERT_CONTINUE(status != 0);
  918. if (std::strstr(wmName, uiTitle) != nullptr)
  919. lastGoodWindowNameSimple = window;
  920. }
  921. }
  922. if (lastGoodWindowPID == 0 && lastGoodWindowNameSimple == 0 && lastGoodWindowNameUTF8 == 0)
  923. return false;
  924. Window windowToMap;
  925. if (lastGoodWindowPID != 0)
  926. {
  927. if (lastGoodWindowPID == lastGoodWindowNameSimple && lastGoodWindowPID == lastGoodWindowNameUTF8)
  928. {
  929. carla_stdout("Match found using pid, simple and UTF-8 name all at once, nice!");
  930. windowToMap = lastGoodWindowPID;
  931. }
  932. else if (lastGoodWindowPID == lastGoodWindowNameUTF8)
  933. {
  934. carla_stdout("Match found using pid and UTF-8 name");
  935. windowToMap = lastGoodWindowPID;
  936. }
  937. else if (lastGoodWindowPID == lastGoodWindowNameSimple)
  938. {
  939. carla_stdout("Match found using pid and simple name");
  940. windowToMap = lastGoodWindowPID;
  941. }
  942. else if (lastGoodWindowNameUTF8 != 0)
  943. {
  944. if (lastGoodWindowNameUTF8 == lastGoodWindowNameSimple)
  945. {
  946. carla_stdout("Match found using simple and UTF-8 name (ignoring pid)");
  947. windowToMap = lastGoodWindowNameUTF8;
  948. }
  949. else
  950. {
  951. carla_stdout("Match found using UTF-8 name (ignoring pid)");
  952. windowToMap = lastGoodWindowNameUTF8;
  953. }
  954. }
  955. else
  956. {
  957. carla_stdout("Match found using pid");
  958. windowToMap = lastGoodWindowPID;
  959. }
  960. }
  961. else if (lastGoodWindowNameUTF8 != 0)
  962. {
  963. if (lastGoodWindowNameUTF8 == lastGoodWindowNameSimple)
  964. {
  965. carla_stdout("Match found using simple and UTF-8 name");
  966. windowToMap = lastGoodWindowNameUTF8;
  967. }
  968. else
  969. {
  970. carla_stdout("Match found using UTF-8 name");
  971. windowToMap = lastGoodWindowNameUTF8;
  972. }
  973. }
  974. else
  975. {
  976. carla_stdout("Match found using simple name");
  977. windowToMap = lastGoodWindowNameSimple;
  978. }
  979. const Atom _nwt = XInternAtom(sd.display ,"_NET_WM_STATE", False);
  980. const Atom _nws[2] = {
  981. XInternAtom(sd.display, "_NET_WM_STATE_SKIP_TASKBAR", False),
  982. XInternAtom(sd.display, "_NET_WM_STATE_SKIP_PAGER", False)
  983. };
  984. XChangeProperty(sd.display, windowToMap, _nwt, XA_ATOM, 32, PropModeAppend, (const uchar*)_nws, 2);
  985. const Atom _nwi = XInternAtom(sd.display, "_NET_WM_ICON", False);
  986. XChangeProperty(sd.display, windowToMap, _nwi, XA_CARDINAL, 32, PropModeReplace, (const uchar*)sCarlaX11Icon, sCarlaX11IconSize);
  987. const Window hostWinId((Window)winId);
  988. XSetTransientForHint(sd.display, windowToMap, hostWinId);
  989. if (centerUI && false /* moving the window after being shown isn't pretty... */)
  990. {
  991. int hostX, hostY, pluginX, pluginY;
  992. uint hostWidth, hostHeight, pluginWidth, pluginHeight, border, depth;
  993. Window retWindow;
  994. if (XGetGeometry(sd.display, hostWinId, &retWindow, &hostX, &hostY, &hostWidth, &hostHeight, &border, &depth) != 0 &&
  995. XGetGeometry(sd.display, windowToMap, &retWindow, &pluginX, &pluginY, &pluginWidth, &pluginHeight, &border, &depth) != 0)
  996. {
  997. if (XTranslateCoordinates(sd.display, hostWinId, rootWindow, hostX, hostY, &hostX, &hostY, &retWindow) == True &&
  998. XTranslateCoordinates(sd.display, windowToMap, rootWindow, pluginX, pluginY, &pluginX, &pluginY, &retWindow) == True)
  999. {
  1000. const int newX = hostX + int(hostWidth/2 - pluginWidth/2);
  1001. const int newY = hostY + int(hostHeight/2 - pluginHeight/2);
  1002. XMoveWindow(sd.display, windowToMap, newX, newY);
  1003. }
  1004. }
  1005. }
  1006. // focusing the host UI and then the plugin UI forces the WM to repaint the plugin window icon
  1007. XRaiseWindow(sd.display, hostWinId);
  1008. XSetInputFocus(sd.display, hostWinId, RevertToPointerRoot, CurrentTime);
  1009. XRaiseWindow(sd.display, windowToMap);
  1010. XSetInputFocus(sd.display, windowToMap, RevertToPointerRoot, CurrentTime);
  1011. XFlush(sd.display);
  1012. return true;
  1013. #endif
  1014. #ifdef CARLA_OS_MAC
  1015. uint const hints = kCGWindowListOptionOnScreenOnly|kCGWindowListExcludeDesktopElements;
  1016. CFArrayRef const windowListRef = CGWindowListCopyWindowInfo(hints, kCGNullWindowID);
  1017. const NSArray* const windowList = (const NSArray*)windowListRef;
  1018. int windowToMap, windowWithPID = 0, windowWithNameAndPID = 0;
  1019. const NSDictionary* entry;
  1020. for (entry in windowList)
  1021. {
  1022. // FIXME: is this needed? is old version safe?
  1023. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1024. if ([entry[(id)kCGWindowSharingState] intValue] == kCGWindowSharingNone)
  1025. continue;
  1026. NSString* const windowName = entry[(id)kCGWindowName];
  1027. int const windowNumber = [entry[(id)kCGWindowNumber] intValue];
  1028. uintptr_t const windowPID = [entry[(id)kCGWindowOwnerPID] intValue];
  1029. #else
  1030. if ([[entry objectForKey:(id)kCGWindowSharingState] intValue] == kCGWindowSharingNone)
  1031. continue;
  1032. NSString* const windowName = [entry objectForKey:(id)kCGWindowName];
  1033. int const windowNumber = [[entry objectForKey:(id)kCGWindowNumber] intValue];
  1034. uintptr_t const windowPID = [[entry objectForKey:(id)kCGWindowOwnerPID] intValue];
  1035. #endif
  1036. if (windowPID != pid)
  1037. continue;
  1038. windowWithPID = windowNumber;
  1039. if (windowName != nullptr && std::strcmp([windowName UTF8String], uiTitle) == 0)
  1040. windowWithNameAndPID = windowNumber;
  1041. }
  1042. CFRelease(windowListRef);
  1043. if (windowWithNameAndPID != 0)
  1044. {
  1045. carla_stdout("Match found using pid and name");
  1046. windowToMap = windowWithNameAndPID;
  1047. }
  1048. else if (windowWithPID != 0)
  1049. {
  1050. carla_stdout("Match found using pid");
  1051. windowToMap = windowWithPID;
  1052. }
  1053. else
  1054. {
  1055. return false;
  1056. }
  1057. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:winId];
  1058. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr, false);
  1059. [parentWindow orderWindow:NSWindowBelow
  1060. relativeTo:windowToMap];
  1061. return true;
  1062. #endif
  1063. #ifdef CARLA_OS_WIN
  1064. if (HWND const childWindow = FindWindowA(nullptr, uiTitle))
  1065. {
  1066. HWND const parentWindow = (HWND)winId;
  1067. SetWindowLongPtr(childWindow, GWLP_HWNDPARENT, (LONG_PTR)parentWindow);
  1068. if (centerUI)
  1069. {
  1070. RECT rectChild, rectParent;
  1071. if (GetWindowRect(childWindow, &rectChild) && GetWindowRect(parentWindow, &rectParent))
  1072. {
  1073. SetWindowPos(childWindow, parentWindow,
  1074. rectParent.left + (rectChild.right-rectChild.left)/2,
  1075. rectParent.top + (rectChild.bottom-rectChild.top)/2,
  1076. 0, 0, SWP_NOSIZE);
  1077. }
  1078. }
  1079. carla_stdout("Match found using window name");
  1080. return true;
  1081. }
  1082. return false;
  1083. #endif
  1084. // fallback, may be unused
  1085. return true;
  1086. (void)pid; (void)centerUI;
  1087. }
  1088. #endif // BUILD_BRIDGE_ALTERNATIVE_ARCH
  1089. // -----------------------------------------------------
  1090. #ifdef HAVE_X11
  1091. CarlaPluginUI* CarlaPluginUI::newX11(Callback* cb, uintptr_t parentId, bool isResizable)
  1092. {
  1093. return new X11PluginUI(cb, parentId, isResizable);
  1094. }
  1095. #endif
  1096. #ifdef CARLA_OS_MAC
  1097. CarlaPluginUI* CarlaPluginUI::newCocoa(Callback* cb, uintptr_t parentId, bool isResizable)
  1098. {
  1099. return new CocoaPluginUI(cb, parentId, isResizable);
  1100. }
  1101. #endif
  1102. #ifdef CARLA_OS_WIN
  1103. CarlaPluginUI* CarlaPluginUI::newWindows(Callback* cb, uintptr_t parentId, bool isResizable)
  1104. {
  1105. return new WindowsPluginUI(cb, parentId, isResizable);
  1106. }
  1107. #endif
  1108. // -----------------------------------------------------