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.

122 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. /*
  51. for (NSView* subview in [(NSView*)winId subviews])
  52. {
  53. // [subview setFrame:NSMakeRect(0, 0, width, height)];
  54. d_stdout("found subview");
  55. return Size<uint>(subview.frame.size.width, subview.frame.size.height);
  56. }
  57. */
  58. #elif defined(DISTRHO_OS_WINDOWS)
  59. #else
  60. if (::Display* const display = XOpenDisplay(nullptr))
  61. {
  62. if (const ::Window childWindow = getChildWindow(display, (::Window)winId))
  63. {
  64. d_stdout("found child window");
  65. XWindowAttributes attrs;
  66. memset(&attrs, 0, sizeof(attrs));
  67. XSizeHints sizeHints;
  68. memset(&sizeHints, 0, sizeof(sizeHints));
  69. int width = 0;
  70. int height = 0;
  71. if (XGetWindowAttributes(display, childWindow, &attrs))
  72. {
  73. width = attrs.width;
  74. height = attrs.height;
  75. }
  76. else if (XGetNormalHints(display, childWindow, &sizeHints))
  77. {
  78. if (sizeHints.flags & PSize)
  79. {
  80. width = sizeHints.width;
  81. height = sizeHints.height;
  82. }
  83. else if (sizeHints.flags & PBaseSize)
  84. {
  85. width = sizeHints.base_width;
  86. height = sizeHints.base_height;
  87. }
  88. }
  89. d_stdout("child window bounds %u %u", width, height);
  90. if (width > 1 && height > 1)
  91. {
  92. // XMoveWindow(display, (::Window)winId, 0, 40);
  93. // XResizeWindow(display, (::Window)winId, width, height);
  94. // XMoveWindow(display, childWindow, 0, 40);
  95. // XMoveResizeWindow(display, childWindow, 0, 40, width, height);
  96. return Size<uint>(static_cast<uint>(width), static_cast<uint>(height));
  97. }
  98. }
  99. XCloseDisplay(display);
  100. }
  101. #endif
  102. return Size<uint>(0, 0);
  103. }
  104. END_NAMESPACE_DGL