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.

1398 lines
42KB

  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. - (id) initWithContentRect:(NSRect)contentRect
  375. styleMask:(unsigned int)aStyle
  376. backing:(NSBackingStoreType)bufferingType
  377. defer:(BOOL)flag;
  378. - (BOOL) canBecomeKeyWindow;
  379. - (BOOL) canBecomeMainWindow;
  380. @end
  381. @implementation CarlaPluginWindow
  382. - (id)initWithContentRect:(NSRect)contentRect
  383. styleMask:(unsigned int)aStyle
  384. backing:(NSBackingStoreType)bufferingType
  385. defer:(BOOL)flag
  386. {
  387. NSWindow* result = [super initWithContentRect:contentRect
  388. styleMask:aStyle
  389. backing:bufferingType
  390. defer:flag];
  391. [result setAcceptsMouseMovedEvents:YES];
  392. return (CarlaPluginWindow*)result;
  393. // unused
  394. (void)flag;
  395. }
  396. - (BOOL)canBecomeKeyWindow
  397. {
  398. return YES;
  399. }
  400. - (BOOL)canBecomeMainWindow
  401. {
  402. return NO;
  403. }
  404. @end
  405. @interface CarlaPluginWindowDelegate : NSObject<NSWindowDelegate>
  406. {
  407. CarlaPluginUI::Callback* callback;
  408. CarlaPluginWindow* window;
  409. }
  410. - (instancetype)initWithWindowAndCallback:(CarlaPluginWindow*)window
  411. callback:(CarlaPluginUI::Callback*)callback2;
  412. - (BOOL)windowShouldClose:(id)sender;
  413. @end
  414. @implementation CarlaPluginWindowDelegate
  415. - (instancetype)initWithWindowAndCallback:(CarlaPluginWindow*)window2
  416. callback:(CarlaPluginUI::Callback*)callback2
  417. {
  418. if ((self = [super init]))
  419. {
  420. callback = callback2;
  421. window = window2;
  422. }
  423. return self;
  424. }
  425. - (BOOL)windowShouldClose:(id)sender
  426. {
  427. if (callback != nil)
  428. callback->handlePluginUIClosed();
  429. return NO;
  430. // unused
  431. (void)sender;
  432. }
  433. @end
  434. @interface CarlaPluginView : NSView
  435. - (void)resizeWithOldSuperviewSize:(NSSize)oldSize;
  436. @end
  437. @implementation CarlaPluginView
  438. - (void)resizeWithOldSuperviewSize:(NSSize)oldSize
  439. {
  440. [super resizeWithOldSuperviewSize:oldSize];
  441. /*
  442. for (NSView* subview in [self subviews])
  443. {
  444. [subview setFrame:NSMakeRect(0, 0, oldSize.width, oldSize.height)];
  445. break;
  446. }
  447. */
  448. }
  449. @end
  450. class CocoaPluginUI : public CarlaPluginUI
  451. {
  452. public:
  453. CocoaPluginUI(Callback* const callback, const uintptr_t parentId, const bool isResizable) noexcept
  454. : CarlaPluginUI(callback, isResizable),
  455. fView(nullptr),
  456. fParentWindow(nullptr),
  457. fWindow(nullptr)
  458. {
  459. carla_debug("CocoaPluginUI::CocoaPluginUI(%p, " P_UINTPTR, "%s)", callback, parentId, bool2str(isResizable));
  460. const CarlaBackend::AutoNSAutoreleasePool arp;
  461. [NSApplication sharedApplication];
  462. fView = [[CarlaPluginView new]retain];
  463. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,)
  464. uint style = NSClosableWindowMask | NSTitledWindowMask;
  465. /*
  466. if (isResizable)
  467. style |= NSResizableWindowMask;
  468. */
  469. const NSRect frame = NSMakeRect(0, 0, 100, 100);
  470. fWindow = [[[CarlaPluginWindow alloc]
  471. initWithContentRect:frame
  472. styleMask:style
  473. backing:NSBackingStoreBuffered
  474. defer:NO
  475. ] retain];
  476. if (fWindow == nullptr)
  477. {
  478. [fView release];
  479. fView = nullptr;
  480. return;
  481. }
  482. ((NSWindow*)fWindow).delegate = [[[CarlaPluginWindowDelegate alloc]
  483. initWithWindowAndCallback:fWindow
  484. callback:callback] retain];
  485. // if (! isResizable)
  486. {
  487. [fView setAutoresizingMask:NSViewNotSizable];
  488. [[fWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
  489. }
  490. [fWindow setContentView:fView];
  491. [fWindow makeFirstResponder:fView];
  492. [fView setHidden:NO];
  493. if (parentId != 0)
  494. setTransientWinId(parentId);
  495. }
  496. ~CocoaPluginUI() override
  497. {
  498. carla_debug("CocoaPluginUI::~CocoaPluginUI()");
  499. if (fView == nullptr)
  500. return;
  501. [fView setHidden:YES];
  502. [fView removeFromSuperview];
  503. [fWindow close];
  504. [fView release];
  505. [fWindow release];
  506. }
  507. void show() override
  508. {
  509. carla_debug("CocoaPluginUI::show()");
  510. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);
  511. if (fParentWindow != nullptr)
  512. {
  513. [fParentWindow addChildWindow:fWindow
  514. ordered:NSWindowAbove];
  515. }
  516. else
  517. {
  518. [fWindow setIsVisible:YES];
  519. }
  520. }
  521. void hide() override
  522. {
  523. carla_debug("CocoaPluginUI::hide()");
  524. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);
  525. [fWindow setIsVisible:NO];
  526. if (fParentWindow != nullptr)
  527. [fParentWindow removeChildWindow:fWindow];
  528. }
  529. void idle() override
  530. {
  531. // carla_debug("CocoaPluginUI::idle()");
  532. }
  533. void focus() override
  534. {
  535. carla_debug("CocoaPluginUI::focus()");
  536. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  537. [fWindow makeKeyAndOrderFront:fWindow];
  538. [fWindow orderFrontRegardless];
  539. [NSApp activateIgnoringOtherApps:YES];
  540. }
  541. void setSize(const uint width, const uint height, const bool forceUpdate) override
  542. {
  543. carla_debug("CocoaPluginUI::setSize(%u, %u, %s)", width, height, bool2str(forceUpdate));
  544. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  545. CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);
  546. [fView setFrame:NSMakeRect(0, 0, width, height)];
  547. for (NSView* subview in [fView subviews])
  548. {
  549. [subview setFrame:NSMakeRect(0, 0, width, height)];
  550. break;
  551. }
  552. const NSSize size = NSMakeSize(width, height);
  553. [fWindow setContentSize:size];
  554. /*
  555. if (fIsResizable)
  556. {
  557. [fWindow setContentMinSize:NSMakeSize(1, 1)];
  558. [fWindow setContentMaxSize:NSMakeSize(99999, 99999)];
  559. }
  560. else
  561. {
  562. [fWindow setContentMinSize:size];
  563. [fWindow setContentMaxSize:size];
  564. }
  565. */
  566. if (forceUpdate)
  567. {
  568. // FIXME, not enough
  569. [fView setNeedsDisplay:YES];
  570. }
  571. }
  572. void setTitle(const char* const title) override
  573. {
  574. carla_debug("CocoaPluginUI::setTitle(\"%s\")", title);
  575. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  576. NSString* titleString = [[NSString alloc]
  577. initWithBytes:title
  578. length:strlen(title)
  579. encoding:NSUTF8StringEncoding];
  580. [fWindow setTitle:titleString];
  581. }
  582. void setTransientWinId(const uintptr_t winId) override
  583. {
  584. carla_debug("CocoaPluginUI::setTransientWinId(" P_UINTPTR ")", winId);
  585. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  586. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:winId];
  587. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);
  588. fParentWindow = parentWindow;
  589. if ([fWindow isVisible])
  590. [fParentWindow addChildWindow:fWindow
  591. ordered:NSWindowAbove];
  592. }
  593. void setChildWindow(void* const childWindow) override
  594. {
  595. carla_debug("CocoaPluginUI::setChildWindow(%p)", childWindow);
  596. CARLA_SAFE_ASSERT_RETURN(childWindow != nullptr,);
  597. NSView* const view = (NSView*)childWindow;
  598. const NSRect frame = [view frame];
  599. [fWindow setContentSize:frame.size];
  600. [fView setFrame:frame];
  601. [fView setNeedsDisplay:YES];
  602. }
  603. void* getPtr() const noexcept override
  604. {
  605. carla_debug("CocoaPluginUI::getPtr()");
  606. return (void*)fView;
  607. }
  608. void* getDisplay() const noexcept
  609. {
  610. carla_debug("CocoaPluginUI::getDisplay()");
  611. return (void*)fWindow;
  612. }
  613. private:
  614. NSView* fView;
  615. NSWindow* fParentWindow;
  616. CarlaPluginWindow* fWindow;
  617. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CocoaPluginUI)
  618. };
  619. #endif // CARLA_OS_MAC
  620. // ---------------------------------------------------------------------------------------------------------------------
  621. // Windows
  622. #ifdef CARLA_OS_WIN
  623. #define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50)
  624. static LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  625. class WindowsPluginUI : public CarlaPluginUI
  626. {
  627. public:
  628. WindowsPluginUI(Callback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
  629. : CarlaPluginUI(cb, isResizable),
  630. fWindow(nullptr),
  631. fChildWindow(nullptr),
  632. fParentWindow(nullptr),
  633. fIsVisible(false),
  634. fFirstShow(true)
  635. {
  636. // FIXME
  637. static int wc_count = 0;
  638. char classNameBuf[32];
  639. std::srand((std::time(nullptr)));
  640. std::snprintf(classNameBuf, 32, "CarlaWin-%d-%d", ++wc_count, std::rand());
  641. classNameBuf[31] = '\0';
  642. const HINSTANCE hInstance = water::getCurrentModuleInstanceHandle();
  643. carla_zeroStruct(fWindowClass);
  644. fWindowClass.style = CS_OWNDC;
  645. fWindowClass.lpfnWndProc = wndProc;
  646. fWindowClass.hInstance = hInstance;
  647. fWindowClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
  648. fWindowClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
  649. fWindowClass.lpszClassName = strdup(classNameBuf);
  650. if (!RegisterClass(&fWindowClass)) {
  651. free((void*)fWindowClass.lpszClassName);
  652. return;
  653. }
  654. int winFlags = WS_POPUPWINDOW | WS_CAPTION;
  655. if (isResizable)
  656. {
  657. // not supported right now
  658. // winFlags |= WS_SIZEBOX;
  659. }
  660. #ifdef BUILDING_CARLA_FOR_WINE
  661. const uint winType = WS_EX_DLGMODALFRAME;
  662. const HWND parent = nullptr;
  663. #else
  664. const uint winType = WS_EX_TOOLWINDOW;
  665. const HWND parent = (HWND)parentId;
  666. #endif
  667. fWindow = CreateWindowEx(winType,
  668. classNameBuf, "Carla Plugin UI", winFlags,
  669. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  670. parent, nullptr,
  671. hInstance, nullptr);
  672. if (fWindow == nullptr) {
  673. const DWORD errorCode = ::GetLastError();
  674. carla_stderr2("CreateWindowEx failed with error code 0x%x, class name was '%s'",
  675. errorCode, fWindowClass.lpszClassName);
  676. UnregisterClass(fWindowClass.lpszClassName, nullptr);
  677. free((void*)fWindowClass.lpszClassName);
  678. return;
  679. }
  680. SetWindowLongPtr(fWindow, GWLP_USERDATA, (LONG_PTR)this);
  681. #ifndef BUILDING_CARLA_FOR_WINE
  682. if (parentId != 0)
  683. setTransientWinId(parentId);
  684. #endif
  685. return;
  686. // maybe unused
  687. (void)parentId;
  688. }
  689. ~WindowsPluginUI() override
  690. {
  691. CARLA_SAFE_ASSERT(! fIsVisible);
  692. if (fWindow != 0)
  693. {
  694. if (fIsVisible)
  695. ShowWindow(fWindow, SW_HIDE);
  696. DestroyWindow(fWindow);
  697. fWindow = 0;
  698. }
  699. // FIXME
  700. UnregisterClass(fWindowClass.lpszClassName, nullptr);
  701. free((void*)fWindowClass.lpszClassName);
  702. }
  703. void show() override
  704. {
  705. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  706. if (fFirstShow)
  707. {
  708. fFirstShow = false;
  709. RECT rectChild, rectParent;
  710. if (fParentWindow != nullptr &&
  711. GetWindowRect(fWindow, &rectChild) &&
  712. GetWindowRect(fParentWindow, &rectParent))
  713. {
  714. SetWindowPos(fWindow, fParentWindow,
  715. rectParent.left + (rectChild.right-rectChild.left)/2,
  716. rectParent.top + (rectChild.bottom-rectChild.top)/2,
  717. 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
  718. }
  719. else
  720. {
  721. ShowWindow(fWindow, SW_SHOWNORMAL);
  722. }
  723. }
  724. else
  725. {
  726. ShowWindow(fWindow, SW_RESTORE);
  727. }
  728. fIsVisible = true;
  729. UpdateWindow(fWindow);
  730. }
  731. void hide() override
  732. {
  733. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  734. ShowWindow(fWindow, SW_HIDE);
  735. fIsVisible = false;
  736. UpdateWindow(fWindow);
  737. }
  738. void idle() override
  739. {
  740. if (fIsIdling || fWindow == nullptr)
  741. return;
  742. MSG msg;
  743. fIsIdling = true;
  744. while (::PeekMessage(&msg, fWindow, 0, 0, PM_REMOVE))
  745. {
  746. switch (msg.message)
  747. {
  748. case WM_QUIT:
  749. case PUGL_LOCAL_CLOSE_MSG:
  750. fIsVisible = false;
  751. CARLA_SAFE_ASSERT_BREAK(fCallback != nullptr);
  752. fCallback->handlePluginUIClosed();
  753. break;
  754. }
  755. DispatchMessageA(&msg);
  756. }
  757. fIsIdling = false;
  758. }
  759. LRESULT checkAndHandleMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  760. {
  761. if (fWindow == hwnd)
  762. {
  763. switch (message)
  764. {
  765. case WM_QUIT:
  766. case PUGL_LOCAL_CLOSE_MSG:
  767. fIsVisible = false;
  768. CARLA_SAFE_ASSERT_BREAK(fCallback != nullptr);
  769. fCallback->handlePluginUIClosed();
  770. break;
  771. }
  772. }
  773. return DefWindowProcA(hwnd, message, wParam, lParam);
  774. }
  775. void focus() override
  776. {
  777. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  778. SetForegroundWindow(fWindow);
  779. SetActiveWindow(fWindow);
  780. SetFocus(fWindow);
  781. }
  782. void setSize(const uint width, const uint height, const bool forceUpdate) override
  783. {
  784. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  785. const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fIsResizable ? WS_SIZEBOX : 0x0);
  786. RECT wr = { 0, 0, static_cast<long>(width), static_cast<long>(height) };
  787. AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST);
  788. SetWindowPos(fWindow, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top,
  789. SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
  790. if (forceUpdate)
  791. UpdateWindow(fWindow);
  792. }
  793. void setTitle(const char* const title) override
  794. {
  795. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  796. SetWindowTextA(fWindow, title);
  797. }
  798. void setTransientWinId(const uintptr_t winId) override
  799. {
  800. CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
  801. fParentWindow = (HWND)winId;
  802. SetWindowLongPtr(fWindow, GWLP_HWNDPARENT, (LONG_PTR)winId);
  803. }
  804. void setChildWindow(void* const winId) override
  805. {
  806. CARLA_SAFE_ASSERT_RETURN(winId != nullptr,);
  807. fChildWindow = (HWND)fChildWindow;
  808. }
  809. void* getPtr() const noexcept override
  810. {
  811. return (void*)fWindow;
  812. }
  813. void* getDisplay() const noexcept
  814. {
  815. return nullptr;
  816. }
  817. private:
  818. HWND fWindow;
  819. HWND fChildWindow;
  820. HWND fParentWindow;
  821. WNDCLASS fWindowClass;
  822. bool fIsVisible;
  823. bool fFirstShow;
  824. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WindowsPluginUI)
  825. };
  826. LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  827. {
  828. switch (message)
  829. {
  830. case WM_CLOSE:
  831. PostMessage(hwnd, PUGL_LOCAL_CLOSE_MSG, wParam, lParam);
  832. return 0;
  833. #if 0
  834. case WM_CREATE:
  835. PostMessage(hwnd, WM_SHOWWINDOW, TRUE, 0);
  836. return 0;
  837. case WM_DESTROY:
  838. return 0;
  839. #endif
  840. default:
  841. if (WindowsPluginUI* const ui = (WindowsPluginUI*)GetWindowLongPtr(hwnd, GWLP_USERDATA))
  842. return ui->checkAndHandleMessage(hwnd, message, wParam, lParam);
  843. return DefWindowProcA(hwnd, message, wParam, lParam);
  844. }
  845. }
  846. #endif // CARLA_OS_WIN
  847. // -----------------------------------------------------
  848. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  849. bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* const uiTitle, const uintptr_t winId, const bool centerUI)
  850. {
  851. CARLA_SAFE_ASSERT_RETURN(uiTitle != nullptr && uiTitle[0] != '\0', true);
  852. CARLA_SAFE_ASSERT_RETURN(winId != 0, true);
  853. #if defined(HAVE_X11)
  854. struct ScopedDisplay {
  855. Display* display;
  856. ScopedDisplay() : display(XOpenDisplay(nullptr)) {}
  857. ~ScopedDisplay() { if (display!=nullptr) XCloseDisplay(display); }
  858. // c++ compat stuff
  859. CARLA_PREVENT_HEAP_ALLOCATION
  860. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisplay)
  861. };
  862. struct ScopedFreeData {
  863. union {
  864. char* data;
  865. uchar* udata;
  866. };
  867. ScopedFreeData(char* d) : data(d) {}
  868. ScopedFreeData(uchar* d) : udata(d) {}
  869. ~ScopedFreeData() { XFree(data); }
  870. // c++ compat stuff
  871. CARLA_PREVENT_HEAP_ALLOCATION
  872. CARLA_DECLARE_NON_COPY_CLASS(ScopedFreeData)
  873. };
  874. const ScopedDisplay sd;
  875. CARLA_SAFE_ASSERT_RETURN(sd.display != nullptr, true);
  876. const Window rootWindow(DefaultRootWindow(sd.display));
  877. const Atom _ncl = XInternAtom(sd.display, "_NET_CLIENT_LIST" , False);
  878. const Atom _nwn = XInternAtom(sd.display, "_NET_WM_NAME", False);
  879. const Atom _nwp = XInternAtom(sd.display, "_NET_WM_PID", False);
  880. const Atom utf8 = XInternAtom(sd.display, "UTF8_STRING", True);
  881. Atom actualType;
  882. int actualFormat;
  883. ulong numWindows, bytesAfter;
  884. uchar* data = nullptr;
  885. int status = XGetWindowProperty(sd.display, rootWindow, _ncl, 0L, (~0L), False, AnyPropertyType, &actualType, &actualFormat, &numWindows, &bytesAfter, &data);
  886. CARLA_SAFE_ASSERT_RETURN(data != nullptr, true);
  887. const ScopedFreeData sfd(data);
  888. CARLA_SAFE_ASSERT_RETURN(status == Success, true);
  889. CARLA_SAFE_ASSERT_RETURN(actualFormat == 32, true);
  890. CARLA_SAFE_ASSERT_RETURN(numWindows != 0, true);
  891. Window* windows = (Window*)data;
  892. Window lastGoodWindowPID = 0, lastGoodWindowNameSimple = 0, lastGoodWindowNameUTF8 = 0;
  893. for (ulong i = 0; i < numWindows; i++)
  894. {
  895. const Window window(windows[i]);
  896. CARLA_SAFE_ASSERT_CONTINUE(window != 0);
  897. // ------------------------------------------------
  898. // try using pid
  899. if (pid != 0)
  900. {
  901. ulong pidSize;
  902. uchar* pidData = nullptr;
  903. status = XGetWindowProperty(sd.display, window, _nwp, 0L, (~0L), False, XA_CARDINAL, &actualType, &actualFormat, &pidSize, &bytesAfter, &pidData);
  904. if (pidData != nullptr)
  905. {
  906. const ScopedFreeData sfd2(pidData);
  907. CARLA_SAFE_ASSERT_CONTINUE(status == Success);
  908. CARLA_SAFE_ASSERT_CONTINUE(pidSize != 0);
  909. if (*(ulong*)pidData == static_cast<ulong>(pid))
  910. lastGoodWindowPID = window;
  911. }
  912. }
  913. // ------------------------------------------------
  914. // try using name (UTF-8)
  915. ulong nameSize;
  916. uchar* nameData = nullptr;
  917. status = XGetWindowProperty(sd.display, window, _nwn, 0L, (~0L), False, utf8, &actualType, &actualFormat, &nameSize, &bytesAfter, &nameData);
  918. if (nameData != nullptr)
  919. {
  920. const ScopedFreeData sfd2(nameData);
  921. CARLA_SAFE_ASSERT_CONTINUE(status == Success);
  922. if (nameSize != 0 && std::strstr((const char*)nameData, uiTitle) != nullptr)
  923. lastGoodWindowNameUTF8 = window;
  924. }
  925. // ------------------------------------------------
  926. // try using name (simple)
  927. char* wmName = nullptr;
  928. status = XFetchName(sd.display, window, &wmName);
  929. if (wmName != nullptr)
  930. {
  931. const ScopedFreeData sfd2(wmName);
  932. CARLA_SAFE_ASSERT_CONTINUE(status != 0);
  933. if (std::strstr(wmName, uiTitle) != nullptr)
  934. lastGoodWindowNameSimple = window;
  935. }
  936. }
  937. if (lastGoodWindowPID == 0 && lastGoodWindowNameSimple == 0 && lastGoodWindowNameUTF8 == 0)
  938. return false;
  939. Window windowToMap;
  940. if (lastGoodWindowPID != 0)
  941. {
  942. if (lastGoodWindowPID == lastGoodWindowNameSimple && lastGoodWindowPID == lastGoodWindowNameUTF8)
  943. {
  944. carla_stdout("Match found using pid, simple and UTF-8 name all at once, nice!");
  945. windowToMap = lastGoodWindowPID;
  946. }
  947. else if (lastGoodWindowPID == lastGoodWindowNameUTF8)
  948. {
  949. carla_stdout("Match found using pid and UTF-8 name");
  950. windowToMap = lastGoodWindowPID;
  951. }
  952. else if (lastGoodWindowPID == lastGoodWindowNameSimple)
  953. {
  954. carla_stdout("Match found using pid and simple name");
  955. windowToMap = lastGoodWindowPID;
  956. }
  957. else if (lastGoodWindowNameUTF8 != 0)
  958. {
  959. if (lastGoodWindowNameUTF8 == lastGoodWindowNameSimple)
  960. {
  961. carla_stdout("Match found using simple and UTF-8 name (ignoring pid)");
  962. windowToMap = lastGoodWindowNameUTF8;
  963. }
  964. else
  965. {
  966. carla_stdout("Match found using UTF-8 name (ignoring pid)");
  967. windowToMap = lastGoodWindowNameUTF8;
  968. }
  969. }
  970. else
  971. {
  972. carla_stdout("Match found using pid");
  973. windowToMap = lastGoodWindowPID;
  974. }
  975. }
  976. else if (lastGoodWindowNameUTF8 != 0)
  977. {
  978. if (lastGoodWindowNameUTF8 == lastGoodWindowNameSimple)
  979. {
  980. carla_stdout("Match found using simple and UTF-8 name");
  981. windowToMap = lastGoodWindowNameUTF8;
  982. }
  983. else
  984. {
  985. carla_stdout("Match found using UTF-8 name");
  986. windowToMap = lastGoodWindowNameUTF8;
  987. }
  988. }
  989. else
  990. {
  991. carla_stdout("Match found using simple name");
  992. windowToMap = lastGoodWindowNameSimple;
  993. }
  994. const Atom _nwt = XInternAtom(sd.display ,"_NET_WM_STATE", False);
  995. const Atom _nws[2] = {
  996. XInternAtom(sd.display, "_NET_WM_STATE_SKIP_TASKBAR", False),
  997. XInternAtom(sd.display, "_NET_WM_STATE_SKIP_PAGER", False)
  998. };
  999. XChangeProperty(sd.display, windowToMap, _nwt, XA_ATOM, 32, PropModeAppend, (const uchar*)_nws, 2);
  1000. const Atom _nwi = XInternAtom(sd.display, "_NET_WM_ICON", False);
  1001. XChangeProperty(sd.display, windowToMap, _nwi, XA_CARDINAL, 32, PropModeReplace, (const uchar*)sCarlaX11Icon, sCarlaX11IconSize);
  1002. const Window hostWinId((Window)winId);
  1003. XSetTransientForHint(sd.display, windowToMap, hostWinId);
  1004. if (centerUI && false /* moving the window after being shown isn't pretty... */)
  1005. {
  1006. int hostX, hostY, pluginX, pluginY;
  1007. uint hostWidth, hostHeight, pluginWidth, pluginHeight, border, depth;
  1008. Window retWindow;
  1009. if (XGetGeometry(sd.display, hostWinId, &retWindow, &hostX, &hostY, &hostWidth, &hostHeight, &border, &depth) != 0 &&
  1010. XGetGeometry(sd.display, windowToMap, &retWindow, &pluginX, &pluginY, &pluginWidth, &pluginHeight, &border, &depth) != 0)
  1011. {
  1012. if (XTranslateCoordinates(sd.display, hostWinId, rootWindow, hostX, hostY, &hostX, &hostY, &retWindow) == True &&
  1013. XTranslateCoordinates(sd.display, windowToMap, rootWindow, pluginX, pluginY, &pluginX, &pluginY, &retWindow) == True)
  1014. {
  1015. const int newX = hostX + int(hostWidth/2 - pluginWidth/2);
  1016. const int newY = hostY + int(hostHeight/2 - pluginHeight/2);
  1017. XMoveWindow(sd.display, windowToMap, newX, newY);
  1018. }
  1019. }
  1020. }
  1021. // focusing the host UI and then the plugin UI forces the WM to repaint the plugin window icon
  1022. XRaiseWindow(sd.display, hostWinId);
  1023. XSetInputFocus(sd.display, hostWinId, RevertToPointerRoot, CurrentTime);
  1024. XRaiseWindow(sd.display, windowToMap);
  1025. XSetInputFocus(sd.display, windowToMap, RevertToPointerRoot, CurrentTime);
  1026. XFlush(sd.display);
  1027. return true;
  1028. #endif
  1029. #ifdef CARLA_OS_MAC
  1030. uint const hints = kCGWindowListOptionOnScreenOnly|kCGWindowListExcludeDesktopElements;
  1031. CFArrayRef const windowListRef = CGWindowListCopyWindowInfo(hints, kCGNullWindowID);
  1032. const NSArray* const windowList = (const NSArray*)windowListRef;
  1033. int windowToMap, windowWithPID = 0, windowWithNameAndPID = 0;
  1034. const NSDictionary* entry;
  1035. for (entry in windowList)
  1036. {
  1037. // FIXME: is this needed? is old version safe?
  1038. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1039. if ([entry[(id)kCGWindowSharingState] intValue] == kCGWindowSharingNone)
  1040. continue;
  1041. NSString* const windowName = entry[(id)kCGWindowName];
  1042. int const windowNumber = [entry[(id)kCGWindowNumber] intValue];
  1043. uintptr_t const windowPID = [entry[(id)kCGWindowOwnerPID] intValue];
  1044. #else
  1045. if ([[entry objectForKey:(id)kCGWindowSharingState] intValue] == kCGWindowSharingNone)
  1046. continue;
  1047. NSString* const windowName = [entry objectForKey:(id)kCGWindowName];
  1048. int const windowNumber = [[entry objectForKey:(id)kCGWindowNumber] intValue];
  1049. uintptr_t const windowPID = [[entry objectForKey:(id)kCGWindowOwnerPID] intValue];
  1050. #endif
  1051. if (windowPID != pid)
  1052. continue;
  1053. windowWithPID = windowNumber;
  1054. if (windowName != nullptr && std::strcmp([windowName UTF8String], uiTitle) == 0)
  1055. windowWithNameAndPID = windowNumber;
  1056. }
  1057. CFRelease(windowListRef);
  1058. if (windowWithNameAndPID != 0)
  1059. {
  1060. carla_stdout("Match found using pid and name");
  1061. windowToMap = windowWithNameAndPID;
  1062. }
  1063. else if (windowWithPID != 0)
  1064. {
  1065. carla_stdout("Match found using pid");
  1066. windowToMap = windowWithPID;
  1067. }
  1068. else
  1069. {
  1070. return false;
  1071. }
  1072. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:winId];
  1073. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr, false);
  1074. [parentWindow orderWindow:NSWindowBelow
  1075. relativeTo:windowToMap];
  1076. return true;
  1077. #endif
  1078. #ifdef CARLA_OS_WIN
  1079. if (HWND const childWindow = FindWindowA(nullptr, uiTitle))
  1080. {
  1081. HWND const parentWindow = (HWND)winId;
  1082. SetWindowLongPtr(childWindow, GWLP_HWNDPARENT, (LONG_PTR)parentWindow);
  1083. if (centerUI)
  1084. {
  1085. RECT rectChild, rectParent;
  1086. if (GetWindowRect(childWindow, &rectChild) && GetWindowRect(parentWindow, &rectParent))
  1087. {
  1088. SetWindowPos(childWindow, parentWindow,
  1089. rectParent.left + (rectChild.right-rectChild.left)/2,
  1090. rectParent.top + (rectChild.bottom-rectChild.top)/2,
  1091. 0, 0, SWP_NOSIZE);
  1092. }
  1093. }
  1094. carla_stdout("Match found using window name");
  1095. return true;
  1096. }
  1097. return false;
  1098. #endif
  1099. // fallback, may be unused
  1100. return true;
  1101. (void)pid; (void)centerUI;
  1102. }
  1103. #endif // BUILD_BRIDGE_ALTERNATIVE_ARCH
  1104. // -----------------------------------------------------
  1105. #ifdef HAVE_X11
  1106. CarlaPluginUI* CarlaPluginUI::newX11(Callback* cb, uintptr_t parentId, bool isResizable)
  1107. {
  1108. return new X11PluginUI(cb, parentId, isResizable);
  1109. }
  1110. #endif
  1111. #ifdef CARLA_OS_MAC
  1112. CarlaPluginUI* CarlaPluginUI::newCocoa(Callback* cb, uintptr_t parentId, bool isResizable)
  1113. {
  1114. return new CocoaPluginUI(cb, parentId, isResizable);
  1115. }
  1116. #endif
  1117. #ifdef CARLA_OS_WIN
  1118. CarlaPluginUI* CarlaPluginUI::newWindows(Callback* cb, uintptr_t parentId, bool isResizable)
  1119. {
  1120. return new WindowsPluginUI(cb, parentId, isResizable);
  1121. }
  1122. #endif
  1123. // -----------------------------------------------------