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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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[2];
  57. if (winId == 0)
  58. {
  59. pos[0] = 0;
  60. pos[1] = 0;
  61. }
  62. #ifdef HAVE_X11
  63. else if (::Display* const disp = XOpenDisplay(nullptr))
  64. {
  65. int x, y;
  66. Window child;
  67. XWindowAttributes xwa;
  68. XTranslateCoordinates(disp, winId, XRootWindow(disp, 0), 0, 0, &x, &y, &child);
  69. XGetWindowAttributes(disp, winId, &xwa);
  70. XCloseDisplay(disp);
  71. pos[0] = x - xwa.x;
  72. pos[1] = y - xwa.y;
  73. }
  74. #endif
  75. else
  76. {
  77. pos[0] = 0;
  78. pos[1] = 0;
  79. }
  80. return pos;
  81. }
  82. int carla_cocoa_get_window(void* nsViewPtr)
  83. {
  84. CARLA_SAFE_ASSERT_RETURN(nsViewPtr != nullptr, 0);
  85. #ifdef CARLA_OS_MAC
  86. NSView* const nsView = (NSView*)nsViewPtr;
  87. return [[nsView window] windowNumber];
  88. #else
  89. return 0;
  90. #endif
  91. }
  92. // -------------------------------------------------------------------------------------------------------------------