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.

119 lines
3.5KB

  1. /*
  2. * DISTRHO Ildaeil Plugin
  3. * Copyright (C) 2021 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 LICENSE file.
  16. */
  17. #include "src/DistrhoDefines.h"
  18. #if defined(DISTRHO_OS_HAIKU)
  19. #elif defined(DISTRHO_OS_MAC)
  20. # import <Cocoa/Cocoa.h>
  21. #elif defined(DISTRHO_OS_WINDOWS)
  22. #else
  23. # include <X11/Xlib.h>
  24. # include <X11/Xutil.h>
  25. #endif
  26. #include "SizeUtils.hpp"
  27. START_NAMESPACE_DGL
  28. #if defined(DISTRHO_OS_HAIKU)
  29. #elif defined(DISTRHO_OS_MAC)
  30. #elif defined(DISTRHO_OS_WINDOWS)
  31. #else
  32. static ::Window getChildWindow(::Display* const display, const ::Window ourWindow)
  33. {
  34. ::Window rootWindow, parentWindow, ret = 0;
  35. ::Window* childWindows = nullptr;
  36. uint numChildren = 0;
  37. XQueryTree(display, ourWindow, &rootWindow, &parentWindow, &childWindows, &numChildren);
  38. if (numChildren > 0 && childWindows != nullptr)
  39. {
  40. ret = childWindows[0];
  41. XFree(childWindows);
  42. }
  43. return ret;
  44. }
  45. #endif
  46. Size<uint> getChildWindowSize(const uintptr_t winId)
  47. {
  48. #if defined(DISTRHO_OS_HAIKU)
  49. #elif defined(DISTRHO_OS_MAC)
  50. for (NSView* subview in [(NSView*)winId subviews])
  51. {
  52. // [subview setFrame:NSMakeRect(0, 0, width, height)];
  53. d_stdout("found subview");
  54. return Size<uint>(subview.frame.size.width, subview.frame.size.height);
  55. }
  56. #elif defined(DISTRHO_OS_WINDOWS)
  57. #else
  58. if (::Display* const display = XOpenDisplay(nullptr))
  59. {
  60. if (const ::Window childWindow = getChildWindow(display, (::Window)winId))
  61. {
  62. d_stdout("found child window");
  63. XSizeHints sizeHints;
  64. memset(&sizeHints, 0, sizeof(sizeHints));
  65. if (XGetNormalHints(display, childWindow, &sizeHints))
  66. {
  67. int width = 0;
  68. int height = 0;
  69. if (sizeHints.flags & PSize)
  70. {
  71. width = sizeHints.width;
  72. height = sizeHints.height;
  73. }
  74. else if (sizeHints.flags & PBaseSize)
  75. {
  76. width = sizeHints.base_width;
  77. height = sizeHints.base_height;
  78. }
  79. else if (sizeHints.flags & PMinSize)
  80. {
  81. width = sizeHints.min_width;
  82. height = sizeHints.min_height;
  83. }
  84. d_stdout("child window bounds %u %u", width, height);
  85. if (width > 1 && height > 1)
  86. {
  87. // XMoveWindow(display, (::Window)winId, 0, 40);
  88. // XResizeWindow(display, (::Window)winId, width, height);
  89. // XMoveWindow(display, childWindow, 0, 40);
  90. // XMoveResizeWindow(display, childWindow, 0, 40, width, height);
  91. return Size<uint>(static_cast<uint>(width), static_cast<uint>(height));
  92. }
  93. }
  94. else
  95. d_stdout("child window without bounds");
  96. }
  97. XCloseDisplay(display);
  98. }
  99. #endif
  100. return Size<uint>(0, 0);
  101. }
  102. END_NAMESPACE_DGL