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.

120 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. XWindowAttributes attrs;
  64. memset(&attrs, 0, sizeof(attrs));
  65. XSizeHints sizeHints;
  66. memset(&sizeHints, 0, sizeof(sizeHints));
  67. int width = 0;
  68. int height = 0;
  69. if (XGetWindowAttributes(display, childWindow, &attrs))
  70. {
  71. width = attrs.width;
  72. height = attrs.height;
  73. }
  74. else if (XGetNormalHints(display, childWindow, &sizeHints))
  75. {
  76. if (sizeHints.flags & PSize)
  77. {
  78. width = sizeHints.width;
  79. height = sizeHints.height;
  80. }
  81. else if (sizeHints.flags & PBaseSize)
  82. {
  83. width = sizeHints.base_width;
  84. height = sizeHints.base_height;
  85. }
  86. }
  87. d_stdout("child window bounds %u %u", width, height);
  88. if (width > 1 && height > 1)
  89. {
  90. // XMoveWindow(display, (::Window)winId, 0, 40);
  91. // XResizeWindow(display, (::Window)winId, width, height);
  92. // XMoveWindow(display, childWindow, 0, 40);
  93. // XMoveResizeWindow(display, childWindow, 0, 40, width, height);
  94. return Size<uint>(static_cast<uint>(width), static_cast<uint>(height));
  95. }
  96. }
  97. XCloseDisplay(display);
  98. }
  99. #endif
  100. return Size<uint>(0, 0);
  101. }
  102. END_NAMESPACE_DGL