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.

1372 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 window) override
  579. {
  580. carla_debug("CocoaPluginUI::setChildWindow(%p)", window);
  581. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  582. }
  583. void* getPtr() const noexcept override
  584. {
  585. carla_debug("CocoaPluginUI::getPtr()");
  586. return (void*)fView;
  587. }
  588. void* getDisplay() const noexcept
  589. {
  590. carla_debug("CocoaPluginUI::getDisplay()");
  591. return (void*)fWindow;
  592. }
  593. private:
  594. NSView* fView;
  595. NSWindow* fParentWindow;
  596. CarlaPluginWindow* fWindow;
  597. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CocoaPluginUI)
  598. };
  599. #endif // CARLA_OS_MAC
  600. // ---------------------------------------------------------------------------------------------------------------------
  601. // Windows
  602. #ifdef CARLA_OS_WIN
  603. #define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50)
  604. static LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  605. class WindowsPluginUI : public CarlaPluginUI
  606. {
  607. public:
  608. WindowsPluginUI(Callback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
  609. : CarlaPluginUI(cb, isResizable),
  610. fWindow(nullptr),
  611. fChildWindow(nullptr),
  612. fParentWindow(nullptr),
  613. fIsVisible(false),
  614. fFirstShow(true)
  615. {
  616. // FIXME
  617. static int wc_count = 0;
  618. char classNameBuf[32];
  619. std::srand((std::time(nullptr)));
  620. std::snprintf(classNameBuf, 32, "CarlaWin-%d-%d", ++wc_count, std::rand());
  621. classNameBuf[31] = '\0';
  622. const HINSTANCE hInstance = water::getCurrentModuleInstanceHandle();
  623. carla_zeroStruct(fWindowClass);
  624. fWindowClass.style = CS_OWNDC;
  625. fWindowClass.lpfnWndProc = wndProc;
  626. fWindowClass.hInstance = hInstance;
  627. fWindowClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
  628. fWindowClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
  629. fWindowClass.lpszClassName = strdup(classNameBuf);
  630. if (!RegisterClass(&fWindowClass)) {
  631. free((void*)fWindowClass.lpszClassName);
  632. return;
  633. }
  634. int winFlags = WS_POPUPWINDOW | WS_CAPTION;
  635. if (isResizable)
  636. {
  637. // not supported right now
  638. // winFlags |= WS_SIZEBOX;
  639. }
  640. #ifdef BUILDING_CARLA_FOR_WINE
  641. const uint winType = WS_EX_DLGMODALFRAME;
  642. const HWND parent = nullptr;
  643. #else
  644. const uint winType = WS_EX_TOOLWINDOW;
  645. const HWND parent = (HWND)parentId;
  646. #endif
  647. fWindow = CreateWindowEx(winType,
  648. classNameBuf, "Carla Plugin UI", winFlags,
  649. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  650. parent, nullptr,
  651. hInstance, nullptr);
  652. if (fWindow == nullptr) {
  653. const DWORD errorCode = ::GetLastError();
  654. carla_stderr2("CreateWindowEx failed with error code 0x%x, class name was '%s'",
  655. errorCode, fWindowClass.lpszClassName);
  656. UnregisterClass(fWindowClass.lpszClassName, nullptr);
  657. free((void*)fWindowClass.lpszClassName);
  658. return;
  659. }
  660. SetWindowLongPtr(fWindow, GWLP_USERDATA, (LONG_PTR)this);
  661. #ifndef BUILDING_CARLA_FOR_WINE
  662. if (parentId != 0)
  663. setTransientWinId(parentId);
  664. #endif
  665. return;
  666. // maybe unused
  667. (void)parentId;
  668. }
  669. ~WindowsPluginUI() override
  670. {
  671. CARLA_SAFE_ASSERT(! fIsVisible);
  672. if (fWindow != 0)
  673. {
  674. if (fIsVisible)
  675. ShowWindow(fWindow, SW_HIDE);
  676. DestroyWindow(fWindow);
  677. fWindow = 0;
  678. }
  679. // FIXME
  680. UnregisterClass(fWindowClass.lpszClassName, nullptr);
  681. free((void*)fWindowClass.lpszClassName);
  682. }
  683. void show() override
  684. {
  685. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  686. if (fFirstShow)
  687. {
  688. fFirstShow = false;
  689. RECT rectChild, rectParent;
  690. if (fParentWindow != nullptr &&
  691. GetWindowRect(fWindow, &rectChild) &&
  692. GetWindowRect(fParentWindow, &rectParent))
  693. {
  694. SetWindowPos(fWindow, fParentWindow,
  695. rectParent.left + (rectChild.right-rectChild.left)/2,
  696. rectParent.top + (rectChild.bottom-rectChild.top)/2,
  697. 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
  698. }
  699. else
  700. {
  701. ShowWindow(fWindow, SW_SHOWNORMAL);
  702. }
  703. }
  704. else
  705. {
  706. ShowWindow(fWindow, SW_RESTORE);
  707. }
  708. fIsVisible = true;
  709. UpdateWindow(fWindow);
  710. }
  711. void hide() override
  712. {
  713. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  714. ShowWindow(fWindow, SW_HIDE);
  715. fIsVisible = false;
  716. UpdateWindow(fWindow);
  717. }
  718. void idle() override
  719. {
  720. if (fIsIdling || fWindow == nullptr)
  721. return;
  722. MSG msg;
  723. fIsIdling = true;
  724. while (::PeekMessage(&msg, fWindow, 0, 0, PM_REMOVE))
  725. {
  726. switch (msg.message)
  727. {
  728. case WM_QUIT:
  729. case PUGL_LOCAL_CLOSE_MSG:
  730. fIsVisible = false;
  731. CARLA_SAFE_ASSERT_BREAK(fCallback != nullptr);
  732. fCallback->handlePluginUIClosed();
  733. break;
  734. }
  735. DispatchMessageA(&msg);
  736. }
  737. fIsIdling = false;
  738. }
  739. LRESULT checkAndHandleMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  740. {
  741. if (fWindow == hwnd)
  742. {
  743. switch (message)
  744. {
  745. case WM_QUIT:
  746. case PUGL_LOCAL_CLOSE_MSG:
  747. fIsVisible = false;
  748. CARLA_SAFE_ASSERT_BREAK(fCallback != nullptr);
  749. fCallback->handlePluginUIClosed();
  750. break;
  751. }
  752. }
  753. return DefWindowProcA(hwnd, message, wParam, lParam);
  754. }
  755. void focus() override
  756. {
  757. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  758. SetForegroundWindow(fWindow);
  759. SetActiveWindow(fWindow);
  760. SetFocus(fWindow);
  761. }
  762. void setSize(const uint width, const uint height, const bool forceUpdate) override
  763. {
  764. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  765. const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fIsResizable ? WS_SIZEBOX : 0x0);
  766. RECT wr = { 0, 0, static_cast<long>(width), static_cast<long>(height) };
  767. AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST);
  768. SetWindowPos(fWindow, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top,
  769. SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
  770. if (forceUpdate)
  771. UpdateWindow(fWindow);
  772. }
  773. void setTitle(const char* const title) override
  774. {
  775. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  776. SetWindowTextA(fWindow, title);
  777. }
  778. void setTransientWinId(const uintptr_t winId) override
  779. {
  780. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  781. fParentWindow = (HWND)winId;
  782. SetWindowLongPtr(fWindow, GWLP_HWNDPARENT, (LONG_PTR)winId);
  783. }
  784. void setChildWindow(void* const winId) override
  785. {
  786. CARLA_SAFE_ASSERT_RETURN(winId != nullptr,);
  787. fChildWindow = (HWND)fChildWindow;
  788. }
  789. void* getPtr() const noexcept override
  790. {
  791. return (void*)fWindow;
  792. }
  793. void* getDisplay() const noexcept
  794. {
  795. return nullptr;
  796. }
  797. private:
  798. HWND fWindow;
  799. HWND fChildWindow;
  800. HWND fParentWindow;
  801. WNDCLASS fWindowClass;
  802. bool fIsVisible;
  803. bool fFirstShow;
  804. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WindowsPluginUI)
  805. };
  806. LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  807. {
  808. switch (message)
  809. {
  810. case WM_CLOSE:
  811. PostMessage(hwnd, PUGL_LOCAL_CLOSE_MSG, wParam, lParam);
  812. return 0;
  813. #if 0
  814. case WM_CREATE:
  815. PostMessage(hwnd, WM_SHOWWINDOW, TRUE, 0);
  816. return 0;
  817. case WM_DESTROY:
  818. return 0;
  819. #endif
  820. default:
  821. if (WindowsPluginUI* const ui = (WindowsPluginUI*)GetWindowLongPtr(hwnd, GWLP_USERDATA))
  822. return ui->checkAndHandleMessage(hwnd, message, wParam, lParam);
  823. return DefWindowProcA(hwnd, message, wParam, lParam);
  824. }
  825. }
  826. #endif // CARLA_OS_WIN
  827. // -----------------------------------------------------
  828. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  829. bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* const uiTitle, const uintptr_t winId, const bool centerUI)
  830. {
  831. CARLA_SAFE_ASSERT_RETURN(uiTitle != nullptr && uiTitle[0] != '\0', true);
  832. CARLA_SAFE_ASSERT_RETURN(winId != 0, true);
  833. #if defined(HAVE_X11)
  834. struct ScopedDisplay {
  835. Display* display;
  836. ScopedDisplay() : display(XOpenDisplay(nullptr)) {}
  837. ~ScopedDisplay() { if (display!=nullptr) XCloseDisplay(display); }
  838. // c++ compat stuff
  839. CARLA_PREVENT_HEAP_ALLOCATION
  840. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisplay)
  841. };
  842. struct ScopedFreeData {
  843. union {
  844. char* data;
  845. uchar* udata;
  846. };
  847. ScopedFreeData(char* d) : data(d) {}
  848. ScopedFreeData(uchar* d) : udata(d) {}
  849. ~ScopedFreeData() { XFree(data); }
  850. // c++ compat stuff
  851. CARLA_PREVENT_HEAP_ALLOCATION
  852. CARLA_DECLARE_NON_COPY_CLASS(ScopedFreeData)
  853. };
  854. const ScopedDisplay sd;
  855. CARLA_SAFE_ASSERT_RETURN(sd.display != nullptr, true);
  856. const Window rootWindow(DefaultRootWindow(sd.display));
  857. const Atom _ncl = XInternAtom(sd.display, "_NET_CLIENT_LIST" , False);
  858. const Atom _nwn = XInternAtom(sd.display, "_NET_WM_NAME", False);
  859. const Atom _nwp = XInternAtom(sd.display, "_NET_WM_PID", False);
  860. const Atom utf8 = XInternAtom(sd.display, "UTF8_STRING", True);
  861. Atom actualType;
  862. int actualFormat;
  863. ulong numWindows, bytesAfter;
  864. uchar* data = nullptr;
  865. int status = XGetWindowProperty(sd.display, rootWindow, _ncl, 0L, (~0L), False, AnyPropertyType, &actualType, &actualFormat, &numWindows, &bytesAfter, &data);
  866. CARLA_SAFE_ASSERT_RETURN(data != nullptr, true);
  867. const ScopedFreeData sfd(data);
  868. CARLA_SAFE_ASSERT_RETURN(status == Success, true);
  869. CARLA_SAFE_ASSERT_RETURN(actualFormat == 32, true);
  870. CARLA_SAFE_ASSERT_RETURN(numWindows != 0, true);
  871. Window* windows = (Window*)data;
  872. Window lastGoodWindowPID = 0, lastGoodWindowNameSimple = 0, lastGoodWindowNameUTF8 = 0;
  873. for (ulong i = 0; i < numWindows; i++)
  874. {
  875. const Window window(windows[i]);
  876. CARLA_SAFE_ASSERT_CONTINUE(window != 0);
  877. // ------------------------------------------------
  878. // try using pid
  879. if (pid != 0)
  880. {
  881. ulong pidSize;
  882. uchar* pidData = nullptr;
  883. status = XGetWindowProperty(sd.display, window, _nwp, 0L, (~0L), False, XA_CARDINAL, &actualType, &actualFormat, &pidSize, &bytesAfter, &pidData);
  884. if (pidData != nullptr)
  885. {
  886. const ScopedFreeData sfd2(pidData);
  887. CARLA_SAFE_ASSERT_CONTINUE(status == Success);
  888. CARLA_SAFE_ASSERT_CONTINUE(pidSize != 0);
  889. if (*(ulong*)pidData == static_cast<ulong>(pid))
  890. lastGoodWindowPID = window;
  891. }
  892. }
  893. // ------------------------------------------------
  894. // try using name (UTF-8)
  895. ulong nameSize;
  896. uchar* nameData = nullptr;
  897. status = XGetWindowProperty(sd.display, window, _nwn, 0L, (~0L), False, utf8, &actualType, &actualFormat, &nameSize, &bytesAfter, &nameData);
  898. if (nameData != nullptr)
  899. {
  900. const ScopedFreeData sfd2(nameData);
  901. CARLA_SAFE_ASSERT_CONTINUE(status == Success);
  902. if (nameSize != 0 && std::strstr((const char*)nameData, uiTitle) != nullptr)
  903. lastGoodWindowNameUTF8 = window;
  904. }
  905. // ------------------------------------------------
  906. // try using name (simple)
  907. char* wmName = nullptr;
  908. status = XFetchName(sd.display, window, &wmName);
  909. if (wmName != nullptr)
  910. {
  911. const ScopedFreeData sfd2(wmName);
  912. CARLA_SAFE_ASSERT_CONTINUE(status != 0);
  913. if (std::strstr(wmName, uiTitle) != nullptr)
  914. lastGoodWindowNameSimple = window;
  915. }
  916. }
  917. if (lastGoodWindowPID == 0 && lastGoodWindowNameSimple == 0 && lastGoodWindowNameUTF8 == 0)
  918. return false;
  919. Window windowToMap;
  920. if (lastGoodWindowPID != 0)
  921. {
  922. if (lastGoodWindowPID == lastGoodWindowNameSimple && lastGoodWindowPID == lastGoodWindowNameUTF8)
  923. {
  924. carla_stdout("Match found using pid, simple and UTF-8 name all at once, nice!");
  925. windowToMap = lastGoodWindowPID;
  926. }
  927. else if (lastGoodWindowPID == lastGoodWindowNameUTF8)
  928. {
  929. carla_stdout("Match found using pid and UTF-8 name");
  930. windowToMap = lastGoodWindowPID;
  931. }
  932. else if (lastGoodWindowPID == lastGoodWindowNameSimple)
  933. {
  934. carla_stdout("Match found using pid and simple name");
  935. windowToMap = lastGoodWindowPID;
  936. }
  937. else if (lastGoodWindowNameUTF8 != 0)
  938. {
  939. if (lastGoodWindowNameUTF8 == lastGoodWindowNameSimple)
  940. {
  941. carla_stdout("Match found using simple and UTF-8 name (ignoring pid)");
  942. windowToMap = lastGoodWindowNameUTF8;
  943. }
  944. else
  945. {
  946. carla_stdout("Match found using UTF-8 name (ignoring pid)");
  947. windowToMap = lastGoodWindowNameUTF8;
  948. }
  949. }
  950. else
  951. {
  952. carla_stdout("Match found using pid");
  953. windowToMap = lastGoodWindowPID;
  954. }
  955. }
  956. else if (lastGoodWindowNameUTF8 != 0)
  957. {
  958. if (lastGoodWindowNameUTF8 == lastGoodWindowNameSimple)
  959. {
  960. carla_stdout("Match found using simple and UTF-8 name");
  961. windowToMap = lastGoodWindowNameUTF8;
  962. }
  963. else
  964. {
  965. carla_stdout("Match found using UTF-8 name");
  966. windowToMap = lastGoodWindowNameUTF8;
  967. }
  968. }
  969. else
  970. {
  971. carla_stdout("Match found using simple name");
  972. windowToMap = lastGoodWindowNameSimple;
  973. }
  974. const Atom _nwt = XInternAtom(sd.display ,"_NET_WM_STATE", False);
  975. const Atom _nws[2] = {
  976. XInternAtom(sd.display, "_NET_WM_STATE_SKIP_TASKBAR", False),
  977. XInternAtom(sd.display, "_NET_WM_STATE_SKIP_PAGER", False)
  978. };
  979. XChangeProperty(sd.display, windowToMap, _nwt, XA_ATOM, 32, PropModeAppend, (const uchar*)_nws, 2);
  980. const Atom _nwi = XInternAtom(sd.display, "_NET_WM_ICON", False);
  981. XChangeProperty(sd.display, windowToMap, _nwi, XA_CARDINAL, 32, PropModeReplace, (const uchar*)sCarlaX11Icon, sCarlaX11IconSize);
  982. const Window hostWinId((Window)winId);
  983. XSetTransientForHint(sd.display, windowToMap, hostWinId);
  984. if (centerUI && false /* moving the window after being shown isn't pretty... */)
  985. {
  986. int hostX, hostY, pluginX, pluginY;
  987. uint hostWidth, hostHeight, pluginWidth, pluginHeight, border, depth;
  988. Window retWindow;
  989. if (XGetGeometry(sd.display, hostWinId, &retWindow, &hostX, &hostY, &hostWidth, &hostHeight, &border, &depth) != 0 &&
  990. XGetGeometry(sd.display, windowToMap, &retWindow, &pluginX, &pluginY, &pluginWidth, &pluginHeight, &border, &depth) != 0)
  991. {
  992. if (XTranslateCoordinates(sd.display, hostWinId, rootWindow, hostX, hostY, &hostX, &hostY, &retWindow) == True &&
  993. XTranslateCoordinates(sd.display, windowToMap, rootWindow, pluginX, pluginY, &pluginX, &pluginY, &retWindow) == True)
  994. {
  995. const int newX = hostX + int(hostWidth/2 - pluginWidth/2);
  996. const int newY = hostY + int(hostHeight/2 - pluginHeight/2);
  997. XMoveWindow(sd.display, windowToMap, newX, newY);
  998. }
  999. }
  1000. }
  1001. // focusing the host UI and then the plugin UI forces the WM to repaint the plugin window icon
  1002. XRaiseWindow(sd.display, hostWinId);
  1003. XSetInputFocus(sd.display, hostWinId, RevertToPointerRoot, CurrentTime);
  1004. XRaiseWindow(sd.display, windowToMap);
  1005. XSetInputFocus(sd.display, windowToMap, RevertToPointerRoot, CurrentTime);
  1006. XFlush(sd.display);
  1007. return true;
  1008. #endif
  1009. #ifdef CARLA_OS_MAC
  1010. uint const hints = kCGWindowListOptionOnScreenOnly|kCGWindowListExcludeDesktopElements;
  1011. CFArrayRef const windowListRef = CGWindowListCopyWindowInfo(hints, kCGNullWindowID);
  1012. const NSArray* const windowList = (const NSArray*)windowListRef;
  1013. int windowToMap, windowWithPID = 0, windowWithNameAndPID = 0;
  1014. const NSDictionary* entry;
  1015. for (entry in windowList)
  1016. {
  1017. // FIXME: is this needed? is old version safe?
  1018. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1019. if ([entry[(id)kCGWindowSharingState] intValue] == kCGWindowSharingNone)
  1020. continue;
  1021. NSString* const windowName = entry[(id)kCGWindowName];
  1022. int const windowNumber = [entry[(id)kCGWindowNumber] intValue];
  1023. uintptr_t const windowPID = [entry[(id)kCGWindowOwnerPID] intValue];
  1024. #else
  1025. if ([[entry objectForKey:(id)kCGWindowSharingState] intValue] == kCGWindowSharingNone)
  1026. continue;
  1027. NSString* const windowName = [entry objectForKey:(id)kCGWindowName];
  1028. int const windowNumber = [[entry objectForKey:(id)kCGWindowNumber] intValue];
  1029. uintptr_t const windowPID = [[entry objectForKey:(id)kCGWindowOwnerPID] intValue];
  1030. #endif
  1031. if (windowPID != pid)
  1032. continue;
  1033. windowWithPID = windowNumber;
  1034. if (windowName != nullptr && std::strcmp([windowName UTF8String], uiTitle) == 0)
  1035. windowWithNameAndPID = windowNumber;
  1036. }
  1037. CFRelease(windowListRef);
  1038. if (windowWithNameAndPID != 0)
  1039. {
  1040. carla_stdout("Match found using pid and name");
  1041. windowToMap = windowWithNameAndPID;
  1042. }
  1043. else if (windowWithPID != 0)
  1044. {
  1045. carla_stdout("Match found using pid");
  1046. windowToMap = windowWithPID;
  1047. }
  1048. else
  1049. {
  1050. return false;
  1051. }
  1052. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:winId];
  1053. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr, false);
  1054. [parentWindow orderWindow:NSWindowBelow
  1055. relativeTo:windowToMap];
  1056. return true;
  1057. #endif
  1058. #ifdef CARLA_OS_WIN
  1059. if (HWND const childWindow = FindWindowA(nullptr, uiTitle))
  1060. {
  1061. HWND const parentWindow = (HWND)winId;
  1062. SetWindowLongPtr(childWindow, GWLP_HWNDPARENT, (LONG_PTR)parentWindow);
  1063. if (centerUI)
  1064. {
  1065. RECT rectChild, rectParent;
  1066. if (GetWindowRect(childWindow, &rectChild) && GetWindowRect(parentWindow, &rectParent))
  1067. {
  1068. SetWindowPos(childWindow, parentWindow,
  1069. rectParent.left + (rectChild.right-rectChild.left)/2,
  1070. rectParent.top + (rectChild.bottom-rectChild.top)/2,
  1071. 0, 0, SWP_NOSIZE);
  1072. }
  1073. }
  1074. carla_stdout("Match found using window name");
  1075. return true;
  1076. }
  1077. return false;
  1078. #endif
  1079. // fallback, may be unused
  1080. return true;
  1081. (void)pid; (void)centerUI;
  1082. }
  1083. #endif // BUILD_BRIDGE_ALTERNATIVE_ARCH
  1084. // -----------------------------------------------------
  1085. #ifdef HAVE_X11
  1086. CarlaPluginUI* CarlaPluginUI::newX11(Callback* cb, uintptr_t parentId, bool isResizable)
  1087. {
  1088. return new X11PluginUI(cb, parentId, isResizable);
  1089. }
  1090. #endif
  1091. #ifdef CARLA_OS_MAC
  1092. CarlaPluginUI* CarlaPluginUI::newCocoa(Callback* cb, uintptr_t parentId, bool isResizable)
  1093. {
  1094. return new CocoaPluginUI(cb, parentId, isResizable);
  1095. }
  1096. #endif
  1097. #ifdef CARLA_OS_WIN
  1098. CarlaPluginUI* CarlaPluginUI::newWindows(Callback* cb, uintptr_t parentId, bool isResizable)
  1099. {
  1100. return new WindowsPluginUI(cb, parentId, isResizable);
  1101. }
  1102. #endif
  1103. // -----------------------------------------------------