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.

115 lines
2.8KB

  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_x11_reparent_window(uintptr_t winId1, uintptr_t winId2)
  38. {
  39. CARLA_SAFE_ASSERT_RETURN(winId1 != 0,);
  40. CARLA_SAFE_ASSERT_RETURN(winId2 != 0,);
  41. #ifdef HAVE_X11
  42. if (::Display* const disp = XOpenDisplay(nullptr))
  43. {
  44. XReparentWindow(disp, winId1, winId2, 0, 0);
  45. XMapWindow(disp, winId1);
  46. XCloseDisplay(disp);
  47. }
  48. #endif
  49. }
  50. void carla_x11_move_window(uintptr_t winId, int x, int y)
  51. {
  52. CARLA_SAFE_ASSERT_RETURN(winId != 0,);
  53. #ifdef HAVE_X11
  54. if (::Display* const disp = XOpenDisplay(nullptr))
  55. {
  56. XMoveWindow(disp, winId, x, y);
  57. XCloseDisplay(disp);
  58. }
  59. #else
  60. // unused
  61. return; (void)x; (void)y;
  62. #endif
  63. }
  64. int* carla_x11_get_window_pos(uintptr_t winId)
  65. {
  66. static int pos[4];
  67. if (winId == 0)
  68. {
  69. pos[0] = 0;
  70. pos[1] = 0;
  71. pos[2] = 0;
  72. pos[3] = 0;
  73. }
  74. #ifdef HAVE_X11
  75. else if (::Display* const disp = XOpenDisplay(nullptr))
  76. {
  77. int x, y;
  78. Window child;
  79. XWindowAttributes xwa;
  80. XTranslateCoordinates(disp, winId, XRootWindow(disp, 0), 0, 0, &x, &y, &child);
  81. XGetWindowAttributes(disp, winId, &xwa);
  82. XCloseDisplay(disp);
  83. pos[0] = x - xwa.x;
  84. pos[1] = y - xwa.y;
  85. pos[2] = xwa.x;
  86. pos[3] = xwa.y;
  87. }
  88. #endif
  89. else
  90. {
  91. pos[0] = 0;
  92. pos[1] = 0;
  93. pos[2] = 0;
  94. pos[3] = 0;
  95. }
  96. return pos;
  97. }
  98. // -------------------------------------------------------------------------------------------------------------------