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.

Windows.cpp 2.7KB

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