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.

128 lines
3.3KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2019 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaUtils.h"
  18. #include "CarlaUtils.hpp"
  19. #if defined(CARLA_OS_MAC) && !defined(CARLA_PLUGIN_EXPORT)
  20. # import <Cocoa/Cocoa.h>
  21. #endif
  22. #ifdef HAVE_X11
  23. # include <X11/Xlib.h>
  24. #endif
  25. namespace CB = CarlaBackend;
  26. // -------------------------------------------------------------------------------------------------------------------
  27. int carla_cocoa_get_window(void* nsViewPtr)
  28. {
  29. CARLA_SAFE_ASSERT_RETURN(nsViewPtr != nullptr, 0);
  30. #if defined(CARLA_OS_MAC) && !defined(CARLA_PLUGIN_EXPORT)
  31. NSView* const nsView = (NSView*)nsViewPtr;
  32. return [[nsView window] windowNumber];
  33. #else
  34. return 0;
  35. #endif
  36. }
  37. void carla_cocoa_set_transient_window_for(void* nsViewChildPtr, void* nsViewParentPtr)
  38. {
  39. CARLA_SAFE_ASSERT_RETURN(nsViewChildPtr != nullptr,);
  40. CARLA_SAFE_ASSERT_RETURN(nsViewParentPtr != nullptr,);
  41. #if defined(CARLA_OS_MAC) && !defined(CARLA_PLUGIN_EXPORT)
  42. NSView* const nsViewChild = (NSView*)nsViewChildPtr;
  43. NSView* const nsViewParent = (NSView*)nsViewParentPtr;
  44. [[nsViewParent window] addChildWindow:[nsViewChild window]
  45. ordered:NSWindowAbove];
  46. #endif
  47. }
  48. void carla_x11_reparent_window(uintptr_t winId1, uintptr_t winId2)
  49. {
  50. CARLA_SAFE_ASSERT_RETURN(winId1 != 0,);
  51. CARLA_SAFE_ASSERT_RETURN(winId2 != 0,);
  52. #ifdef HAVE_X11
  53. if (::Display* const disp = XOpenDisplay(nullptr))
  54. {
  55. XReparentWindow(disp, winId1, winId2, 0, 0);
  56. XMapWindow(disp, winId1);
  57. XCloseDisplay(disp);
  58. }
  59. #endif
  60. }
  61. void carla_x11_move_window(uintptr_t winId, int x, int y)
  62. {
  63. CARLA_SAFE_ASSERT_RETURN(winId != 0,);
  64. #ifdef HAVE_X11
  65. if (::Display* const disp = XOpenDisplay(nullptr))
  66. {
  67. XMoveWindow(disp, winId, x, y);
  68. XCloseDisplay(disp);
  69. }
  70. #else
  71. // unused
  72. return; (void)x; (void)y;
  73. #endif
  74. }
  75. int* carla_x11_get_window_pos(uintptr_t winId)
  76. {
  77. static int pos[4];
  78. if (winId == 0)
  79. {
  80. pos[0] = 0;
  81. pos[1] = 0;
  82. pos[2] = 0;
  83. pos[3] = 0;
  84. }
  85. #ifdef HAVE_X11
  86. else if (::Display* const disp = XOpenDisplay(nullptr))
  87. {
  88. int x, y;
  89. Window child;
  90. XWindowAttributes xwa;
  91. XTranslateCoordinates(disp, winId, XRootWindow(disp, 0), 0, 0, &x, &y, &child);
  92. XGetWindowAttributes(disp, winId, &xwa);
  93. XCloseDisplay(disp);
  94. pos[0] = x - xwa.x;
  95. pos[1] = y - xwa.y;
  96. pos[2] = xwa.x;
  97. pos[3] = xwa.y;
  98. }
  99. #endif
  100. else
  101. {
  102. pos[0] = 0;
  103. pos[1] = 0;
  104. pos[2] = 0;
  105. pos[3] = 0;
  106. }
  107. return pos;
  108. }
  109. // -------------------------------------------------------------------------------------------------------------------