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

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