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.

juce_linux_XEmbedComponent.cpp 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. ::Window juce_createKeyProxyWindow (ComponentPeer*);
  21. void juce_deleteKeyProxyWindow (::Window);
  22. //==============================================================================
  23. enum
  24. {
  25. maxXEmbedVersionToSupport = 0
  26. };
  27. enum
  28. {
  29. XEMBED_MAPPED = (1<<0)
  30. };
  31. enum
  32. {
  33. XEMBED_EMBEDDED_NOTIFY = 0,
  34. XEMBED_WINDOW_ACTIVATE = 1,
  35. XEMBED_WINDOW_DEACTIVATE = 2,
  36. XEMBED_REQUEST_FOCUS = 3,
  37. XEMBED_FOCUS_IN = 4,
  38. XEMBED_FOCUS_OUT = 5,
  39. XEMBED_FOCUS_NEXT = 6,
  40. XEMBED_FOCUS_PREV = 7,
  41. XEMBED_MODALITY_ON = 10,
  42. XEMBED_MODALITY_OFF = 11,
  43. XEMBED_REGISTER_ACCELERATOR = 12,
  44. XEMBED_UNREGISTER_ACCELERATOR = 13,
  45. XEMBED_ACTIVATE_ACCELERATOR = 14
  46. };
  47. enum
  48. {
  49. XEMBED_FOCUS_CURRENT = 0,
  50. XEMBED_FOCUS_FIRST = 1,
  51. XEMBED_FOCUS_LAST = 2
  52. };
  53. //==============================================================================
  54. class XEmbedComponent::Pimpl : private ComponentListener
  55. {
  56. public:
  57. //==============================================================================
  58. struct SharedKeyWindow : public ReferenceCountedObject
  59. {
  60. SharedKeyWindow (ComponentPeer* peerToUse)
  61. : keyPeer (peerToUse),
  62. keyProxy (juce_createKeyProxyWindow (keyPeer))
  63. {}
  64. ~SharedKeyWindow()
  65. {
  66. juce_deleteKeyProxyWindow (keyProxy);
  67. auto& keyWindows = getKeyWindows();
  68. keyWindows.remove (keyPeer);
  69. }
  70. using Ptr = ReferenceCountedObjectPtr<SharedKeyWindow>;
  71. //==============================================================================
  72. Window getHandle() { return keyProxy; }
  73. static Window getCurrentFocusWindow (ComponentPeer* peerToLookFor)
  74. {
  75. auto& keyWindows = getKeyWindows();
  76. if (peerToLookFor != nullptr)
  77. if (auto* foundKeyWindow = keyWindows[peerToLookFor])
  78. return foundKeyWindow->keyProxy;
  79. return {};
  80. }
  81. static SharedKeyWindow::Ptr getKeyWindowForPeer (ComponentPeer* peerToLookFor)
  82. {
  83. jassert (peerToLookFor != nullptr);
  84. auto& keyWindows = getKeyWindows();
  85. auto foundKeyWindow = keyWindows[peerToLookFor];
  86. if (foundKeyWindow == nullptr)
  87. {
  88. foundKeyWindow = new SharedKeyWindow (peerToLookFor);
  89. keyWindows.set (peerToLookFor, foundKeyWindow);
  90. }
  91. return foundKeyWindow;
  92. }
  93. private:
  94. //==============================================================================
  95. ComponentPeer* keyPeer;
  96. Window keyProxy;
  97. static HashMap<ComponentPeer*, SharedKeyWindow*>& getKeyWindows()
  98. {
  99. // store a weak reference to the shared key windows
  100. static HashMap<ComponentPeer*, SharedKeyWindow*> keyWindows;
  101. return keyWindows;
  102. }
  103. };
  104. public:
  105. //==============================================================================
  106. Pimpl (XEmbedComponent& parent, Window x11Window,
  107. bool wantsKeyboardFocus, bool isClientInitiated, bool shouldAllowResize)
  108. : owner (parent),
  109. infoAtom (XWindowSystem::getInstance()->getAtoms().XembedInfo),
  110. messageTypeAtom (XWindowSystem::getInstance()->getAtoms().XembedMsgType),
  111. clientInitiated (isClientInitiated),
  112. wantsFocus (wantsKeyboardFocus),
  113. allowResize (shouldAllowResize)
  114. {
  115. getWidgets().add (this);
  116. createHostWindow();
  117. if (clientInitiated)
  118. setClient (x11Window, true);
  119. owner.setWantsKeyboardFocus (wantsFocus);
  120. owner.addComponentListener (this);
  121. }
  122. ~Pimpl() override
  123. {
  124. owner.removeComponentListener (this);
  125. setClient (0, true);
  126. if (host != 0)
  127. {
  128. auto dpy = getDisplay();
  129. X11Symbols::getInstance()->xDestroyWindow (dpy, host);
  130. X11Symbols::getInstance()->xSync (dpy, false);
  131. auto mask = NoEventMask | KeyPressMask | KeyReleaseMask
  132. | EnterWindowMask | LeaveWindowMask | PointerMotionMask
  133. | KeymapStateMask | ExposureMask | StructureNotifyMask
  134. | FocusChangeMask;
  135. XEvent event;
  136. while (X11Symbols::getInstance()->xCheckWindowEvent (dpy, host, mask, &event) == True)
  137. {}
  138. host = 0;
  139. }
  140. getWidgets().removeAllInstancesOf (this);
  141. }
  142. //==============================================================================
  143. void setClient (Window xembedClient, bool shouldReparent)
  144. {
  145. removeClient();
  146. if (xembedClient != 0)
  147. {
  148. auto dpy = getDisplay();
  149. client = xembedClient;
  150. // if the client has initiated the component then keep the clients size
  151. // otherwise the client should use the host's window' size
  152. if (clientInitiated)
  153. {
  154. configureNotify();
  155. }
  156. else
  157. {
  158. auto newBounds = getX11BoundsFromJuce();
  159. X11Symbols::getInstance()->xResizeWindow (dpy, client, static_cast<unsigned int> (newBounds.getWidth()),
  160. static_cast<unsigned int> (newBounds.getHeight()));
  161. }
  162. auto eventMask = StructureNotifyMask | PropertyChangeMask | FocusChangeMask;
  163. XWindowAttributes clientAttr;
  164. X11Symbols::getInstance()->xGetWindowAttributes (dpy, client, &clientAttr);
  165. if ((eventMask & clientAttr.your_event_mask) != eventMask)
  166. X11Symbols::getInstance()->xSelectInput (dpy, client, clientAttr.your_event_mask | eventMask);
  167. getXEmbedMappedFlag();
  168. if (shouldReparent)
  169. X11Symbols::getInstance()->xReparentWindow (dpy, client, host, 0, 0);
  170. if (supportsXembed)
  171. sendXEmbedEvent (CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0, (long) host, xembedVersion);
  172. updateMapping();
  173. }
  174. }
  175. void focusGained (FocusChangeType changeType)
  176. {
  177. if (client != 0 && supportsXembed && wantsFocus)
  178. {
  179. updateKeyFocus();
  180. sendXEmbedEvent (CurrentTime, XEMBED_FOCUS_IN,
  181. (changeType == focusChangedByTabKey ? XEMBED_FOCUS_FIRST : XEMBED_FOCUS_CURRENT));
  182. }
  183. }
  184. void focusLost (FocusChangeType)
  185. {
  186. if (client != 0 && supportsXembed && wantsFocus)
  187. {
  188. sendXEmbedEvent (CurrentTime, XEMBED_FOCUS_OUT);
  189. updateKeyFocus();
  190. }
  191. }
  192. void broughtToFront()
  193. {
  194. if (client != 0 && supportsXembed)
  195. sendXEmbedEvent (CurrentTime, XEMBED_WINDOW_ACTIVATE);
  196. }
  197. unsigned long getHostWindowID()
  198. {
  199. // You are using the client initiated version of the protocol. You cannot
  200. // retrieve the window id of the host. Please read the documentation for
  201. // the XEmebedComponent class.
  202. jassert (! clientInitiated);
  203. return host;
  204. }
  205. void updateEmbeddedBounds()
  206. {
  207. componentMovedOrResized (owner, true, true);
  208. }
  209. private:
  210. //==============================================================================
  211. XEmbedComponent& owner;
  212. Window client = 0, host = 0;
  213. Atom infoAtom, messageTypeAtom;
  214. bool clientInitiated;
  215. bool wantsFocus = false;
  216. bool allowResize = false;
  217. bool supportsXembed = false;
  218. bool hasBeenMapped = false;
  219. int xembedVersion = maxXEmbedVersionToSupport;
  220. ComponentPeer* lastPeer = nullptr;
  221. SharedKeyWindow::Ptr keyWindow;
  222. //==============================================================================
  223. void componentParentHierarchyChanged (Component&) override { peerChanged (owner.getPeer()); }
  224. void componentMovedOrResized (Component&, bool, bool) override
  225. {
  226. if (host != 0 && lastPeer != nullptr)
  227. {
  228. auto dpy = getDisplay();
  229. auto newBounds = getX11BoundsFromJuce();
  230. XWindowAttributes attr;
  231. if (X11Symbols::getInstance()->xGetWindowAttributes (dpy, host, &attr))
  232. {
  233. Rectangle<int> currentBounds (attr.x, attr.y, attr.width, attr.height);
  234. if (currentBounds != newBounds)
  235. {
  236. X11Symbols::getInstance()->xMoveResizeWindow (dpy, host, newBounds.getX(), newBounds.getY(),
  237. static_cast<unsigned int> (newBounds.getWidth()),
  238. static_cast<unsigned int> (newBounds.getHeight()));
  239. }
  240. }
  241. if (client != 0 && X11Symbols::getInstance()->xGetWindowAttributes (dpy, client, &attr))
  242. {
  243. Rectangle<int> currentBounds (attr.x, attr.y, attr.width, attr.height);
  244. if ((currentBounds.getWidth() != newBounds.getWidth()
  245. || currentBounds.getHeight() != newBounds.getHeight()))
  246. {
  247. X11Symbols::getInstance()->xMoveResizeWindow (dpy, client, 0, 0,
  248. static_cast<unsigned int> (newBounds.getWidth()),
  249. static_cast<unsigned int> (newBounds.getHeight()));
  250. }
  251. }
  252. }
  253. }
  254. //==============================================================================
  255. void createHostWindow()
  256. {
  257. auto dpy = getDisplay();
  258. int defaultScreen = X11Symbols::getInstance()->xDefaultScreen (dpy);
  259. Window root = X11Symbols::getInstance()->xRootWindow (dpy, defaultScreen);
  260. XSetWindowAttributes swa;
  261. swa.border_pixel = 0;
  262. swa.background_pixmap = None;
  263. swa.override_redirect = True;
  264. swa.event_mask = SubstructureNotifyMask | StructureNotifyMask | FocusChangeMask;
  265. host = X11Symbols::getInstance()->xCreateWindow (dpy, root, 0, 0, 1, 1, 0, CopyFromParent,
  266. InputOutput, CopyFromParent,
  267. CWEventMask | CWBorderPixel | CWBackPixmap | CWOverrideRedirect,
  268. &swa);
  269. }
  270. void removeClient()
  271. {
  272. if (client != 0)
  273. {
  274. auto dpy = getDisplay();
  275. X11Symbols::getInstance()->xSelectInput (dpy, client, 0);
  276. keyWindow = nullptr;
  277. int defaultScreen = X11Symbols::getInstance()->xDefaultScreen (dpy);
  278. Window root = X11Symbols::getInstance()->xRootWindow (dpy, defaultScreen);
  279. if (hasBeenMapped)
  280. {
  281. X11Symbols::getInstance()->xUnmapWindow (dpy, client);
  282. hasBeenMapped = false;
  283. }
  284. X11Symbols::getInstance()->xReparentWindow (dpy, client, root, 0, 0);
  285. client = 0;
  286. X11Symbols::getInstance()->xSync (dpy, False);
  287. }
  288. }
  289. void updateMapping()
  290. {
  291. if (client != 0)
  292. {
  293. const bool shouldBeMapped = getXEmbedMappedFlag();
  294. if (shouldBeMapped != hasBeenMapped)
  295. {
  296. hasBeenMapped = shouldBeMapped;
  297. if (shouldBeMapped)
  298. X11Symbols::getInstance()->xMapWindow (getDisplay(), client);
  299. else
  300. X11Symbols::getInstance()->xUnmapWindow (getDisplay(), client);
  301. }
  302. }
  303. }
  304. Window getParentX11Window()
  305. {
  306. if (auto* peer = owner.getPeer())
  307. return reinterpret_cast<Window> (peer->getNativeHandle());
  308. return {};
  309. }
  310. Display* getDisplay() { return XWindowSystem::getInstance()->getDisplay(); }
  311. //==============================================================================
  312. bool getXEmbedMappedFlag()
  313. {
  314. XWindowSystemUtilities::GetXProperty embedInfo (getDisplay(), client, infoAtom, 0, 2, false, infoAtom);
  315. if (embedInfo.success && embedInfo.actualFormat == 32
  316. && embedInfo.numItems >= 2 && embedInfo.data != nullptr)
  317. {
  318. long version;
  319. memcpy (&version, embedInfo.data, sizeof (long));
  320. supportsXembed = true;
  321. xembedVersion = jmin ((int) maxXEmbedVersionToSupport, (int) version);
  322. long flags;
  323. memcpy (&flags, embedInfo.data + sizeof (long), sizeof (long));
  324. return ((flags & XEMBED_MAPPED) != 0);
  325. }
  326. else
  327. {
  328. supportsXembed = false;
  329. xembedVersion = maxXEmbedVersionToSupport;
  330. }
  331. return true;
  332. }
  333. //==============================================================================
  334. void propertyChanged (const Atom& a)
  335. {
  336. if (a == infoAtom)
  337. updateMapping();
  338. }
  339. void configureNotify()
  340. {
  341. XWindowAttributes attr;
  342. auto dpy = getDisplay();
  343. if (X11Symbols::getInstance()->xGetWindowAttributes (dpy, client, &attr))
  344. {
  345. XWindowAttributes hostAttr;
  346. if (X11Symbols::getInstance()->xGetWindowAttributes (dpy, host, &hostAttr))
  347. if (attr.width != hostAttr.width || attr.height != hostAttr.height)
  348. X11Symbols::getInstance()->xResizeWindow (dpy, host, (unsigned int) attr.width, (unsigned int) attr.height);
  349. // as the client window is not on any screen yet, we need to guess
  350. // on which screen it might appear to get a scaling factor :-(
  351. auto& displays = Desktop::getInstance().getDisplays();
  352. auto* peer = owner.getPeer();
  353. const double scale = (peer != nullptr ? peer->getPlatformScaleFactor()
  354. : displays.getPrimaryDisplay()->scale);
  355. Point<int> topLeftInPeer
  356. = (peer != nullptr ? peer->getComponent().getLocalPoint (&owner, Point<int> (0, 0))
  357. : owner.getBounds().getTopLeft());
  358. Rectangle<int> newBounds (topLeftInPeer.getX(), topLeftInPeer.getY(),
  359. static_cast<int> (static_cast<double> (attr.width) / scale),
  360. static_cast<int> (static_cast<double> (attr.height) / scale));
  361. if (peer != nullptr)
  362. newBounds = owner.getLocalArea (&peer->getComponent(), newBounds);
  363. jassert (newBounds.getX() == 0 && newBounds.getY() == 0);
  364. if (newBounds != owner.getLocalBounds())
  365. owner.setSize (newBounds.getWidth(), newBounds.getHeight());
  366. }
  367. }
  368. void peerChanged (ComponentPeer* newPeer)
  369. {
  370. if (newPeer != lastPeer)
  371. {
  372. if (lastPeer != nullptr)
  373. keyWindow = nullptr;
  374. auto dpy = getDisplay();
  375. Window rootWindow = X11Symbols::getInstance()->xRootWindow (dpy, DefaultScreen (dpy));
  376. Rectangle<int> newBounds = getX11BoundsFromJuce();
  377. if (newPeer == nullptr)
  378. X11Symbols::getInstance()->xUnmapWindow (dpy, host);
  379. Window newParent = (newPeer != nullptr ? getParentX11Window() : rootWindow);
  380. X11Symbols::getInstance()->xReparentWindow (dpy, host, newParent, newBounds.getX(), newBounds.getY());
  381. lastPeer = newPeer;
  382. if (newPeer != nullptr)
  383. {
  384. if (wantsFocus)
  385. {
  386. keyWindow = SharedKeyWindow::getKeyWindowForPeer (newPeer);
  387. updateKeyFocus();
  388. }
  389. componentMovedOrResized (owner, true, true);
  390. X11Symbols::getInstance()->xMapWindow (dpy, host);
  391. broughtToFront();
  392. }
  393. }
  394. }
  395. void updateKeyFocus()
  396. {
  397. if (lastPeer != nullptr && lastPeer->isFocused())
  398. X11Symbols::getInstance()->xSetInputFocus (getDisplay(), getCurrentFocusWindow (lastPeer), RevertToParent, CurrentTime);
  399. }
  400. //==============================================================================
  401. void handleXembedCmd (const ::Time& /*xTime*/, long opcode, long /*detail*/, long /*data1*/, long /*data2*/)
  402. {
  403. switch (opcode)
  404. {
  405. case XEMBED_REQUEST_FOCUS:
  406. if (wantsFocus)
  407. owner.grabKeyboardFocus();
  408. break;
  409. case XEMBED_FOCUS_NEXT:
  410. if (wantsFocus)
  411. owner.moveKeyboardFocusToSibling (true);
  412. break;
  413. case XEMBED_FOCUS_PREV:
  414. if (wantsFocus)
  415. owner.moveKeyboardFocusToSibling (false);
  416. break;
  417. default:
  418. break;
  419. }
  420. }
  421. bool handleX11Event (const XEvent& e)
  422. {
  423. if (e.xany.window == client && client != 0)
  424. {
  425. switch (e.type)
  426. {
  427. case PropertyNotify:
  428. propertyChanged (e.xproperty.atom);
  429. return true;
  430. case ConfigureNotify:
  431. if (allowResize)
  432. configureNotify();
  433. else
  434. MessageManager::callAsync ([this] {componentMovedOrResized (owner, true, true);});
  435. return true;
  436. default:
  437. break;
  438. }
  439. }
  440. else if (e.xany.window == host && host != 0)
  441. {
  442. switch (e.type)
  443. {
  444. case ReparentNotify:
  445. if (e.xreparent.parent == host && e.xreparent.window != client)
  446. {
  447. setClient (e.xreparent.window, false);
  448. return true;
  449. }
  450. break;
  451. case CreateNotify:
  452. if (e.xcreatewindow.parent != e.xcreatewindow.window && e.xcreatewindow.parent == host && e.xcreatewindow.window != client)
  453. {
  454. setClient (e.xcreatewindow.window, false);
  455. return true;
  456. }
  457. break;
  458. case GravityNotify:
  459. componentMovedOrResized (owner, true, true);
  460. return true;
  461. case ClientMessage:
  462. if (e.xclient.message_type == messageTypeAtom && e.xclient.format == 32)
  463. {
  464. handleXembedCmd ((::Time) e.xclient.data.l[0], e.xclient.data.l[1],
  465. e.xclient.data.l[2], e.xclient.data.l[3],
  466. e.xclient.data.l[4]);
  467. return true;
  468. }
  469. break;
  470. default:
  471. break;
  472. }
  473. }
  474. return false;
  475. }
  476. void sendXEmbedEvent (const ::Time& xTime, long opcode,
  477. long opcodeMinor = 0, long data1 = 0, long data2 = 0)
  478. {
  479. XClientMessageEvent msg;
  480. auto dpy = getDisplay();
  481. ::memset (&msg, 0, sizeof (XClientMessageEvent));
  482. msg.window = client;
  483. msg.type = ClientMessage;
  484. msg.message_type = messageTypeAtom;
  485. msg.format = 32;
  486. msg.data.l[0] = (long) xTime;
  487. msg.data.l[1] = opcode;
  488. msg.data.l[2] = opcodeMinor;
  489. msg.data.l[3] = data1;
  490. msg.data.l[4] = data2;
  491. X11Symbols::getInstance()->xSendEvent (dpy, client, False, NoEventMask, (XEvent*) &msg);
  492. X11Symbols::getInstance()->xSync (dpy, False);
  493. }
  494. Rectangle<int> getX11BoundsFromJuce()
  495. {
  496. if (auto* peer = owner.getPeer())
  497. {
  498. auto r = peer->getComponent().getLocalArea (&owner, owner.getLocalBounds());
  499. return r * peer->getPlatformScaleFactor() * peer->getComponent().getDesktopScaleFactor();
  500. }
  501. return owner.getLocalBounds();
  502. }
  503. //==============================================================================
  504. friend bool juce::juce_handleXEmbedEvent (ComponentPeer*, void*);
  505. friend unsigned long juce::juce_getCurrentFocusWindow (ComponentPeer*);
  506. static Array<Pimpl*>& getWidgets()
  507. {
  508. static Array<Pimpl*> i;
  509. return i;
  510. }
  511. static bool dispatchX11Event (ComponentPeer* p, const XEvent* eventArg)
  512. {
  513. if (eventArg != nullptr)
  514. {
  515. auto& e = *eventArg;
  516. if (auto w = e.xany.window)
  517. for (auto* widget : getWidgets())
  518. if (w == widget->host || w == widget->client)
  519. return widget->handleX11Event (e);
  520. }
  521. else
  522. {
  523. for (auto* widget : getWidgets())
  524. if (widget->owner.getPeer() == p)
  525. widget->peerChanged (nullptr);
  526. }
  527. return false;
  528. }
  529. static Window getCurrentFocusWindow (ComponentPeer* p)
  530. {
  531. if (p != nullptr)
  532. {
  533. for (auto* widget : getWidgets())
  534. if (widget->owner.getPeer() == p && widget->owner.hasKeyboardFocus (false))
  535. return widget->client;
  536. }
  537. return SharedKeyWindow::getCurrentFocusWindow (p);
  538. }
  539. };
  540. //==============================================================================
  541. XEmbedComponent::XEmbedComponent (bool wantsKeyboardFocus, bool allowForeignWidgetToResizeComponent)
  542. : pimpl (new Pimpl (*this, 0, wantsKeyboardFocus, false, allowForeignWidgetToResizeComponent))
  543. {
  544. setOpaque (true);
  545. }
  546. XEmbedComponent::XEmbedComponent (unsigned long wID, bool wantsKeyboardFocus, bool allowForeignWidgetToResizeComponent)
  547. : pimpl (new Pimpl (*this, wID, wantsKeyboardFocus, true, allowForeignWidgetToResizeComponent))
  548. {
  549. setOpaque (true);
  550. }
  551. XEmbedComponent::~XEmbedComponent() {}
  552. void XEmbedComponent::paint (Graphics& g)
  553. {
  554. g.fillAll (Colours::lightgrey);
  555. }
  556. void XEmbedComponent::focusGained (FocusChangeType changeType) { pimpl->focusGained (changeType); }
  557. void XEmbedComponent::focusLost (FocusChangeType changeType) { pimpl->focusLost (changeType); }
  558. void XEmbedComponent::broughtToFront() { pimpl->broughtToFront(); }
  559. unsigned long XEmbedComponent::getHostWindowID() { return pimpl->getHostWindowID(); }
  560. void XEmbedComponent::removeClient() { pimpl->setClient (0, true); }
  561. void XEmbedComponent::updateEmbeddedBounds() { pimpl->updateEmbeddedBounds(); }
  562. //==============================================================================
  563. bool juce_handleXEmbedEvent (ComponentPeer* p, void* e)
  564. {
  565. return XEmbedComponent::Pimpl::dispatchX11Event (p, reinterpret_cast<const XEvent*> (e));
  566. }
  567. unsigned long juce_getCurrentFocusWindow (ComponentPeer* peer)
  568. {
  569. return (unsigned long) XEmbedComponent::Pimpl::getCurrentFocusWindow (peer);
  570. }
  571. } // namespace juce