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.

interposer-x11.cpp 4.0KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Carla Interposer for X11 Window Mapping
  3. * Copyright (C) 2014-2022 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.hpp"
  18. #include <dlfcn.h>
  19. #include <X11/Xlib.h>
  20. // --------------------------------------------------------------------------------------------------------------------
  21. // Function typedefs
  22. typedef int (*XWindowFunc)(Display*, Window);
  23. // --------------------------------------------------------------------------------------------------------------------
  24. // Calling the real functions
  25. static int real_XMapWindow(Display* display, Window window)
  26. {
  27. static const XWindowFunc func = (XWindowFunc)::dlsym(RTLD_NEXT, "XMapWindow");
  28. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  29. return func(display, window);
  30. }
  31. static int real_XMapRaised(Display* display, Window window)
  32. {
  33. static const XWindowFunc func = (XWindowFunc)::dlsym(RTLD_NEXT, "XMapRaised");
  34. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  35. return func(display, window);
  36. }
  37. static int real_XMapSubwindows(Display* display, Window window)
  38. {
  39. static const XWindowFunc func = (XWindowFunc)::dlsym(RTLD_NEXT, "XMapSubwindows");
  40. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  41. return func(display, window);
  42. }
  43. static int real_XUnmapWindow(Display* display, Window window)
  44. {
  45. static const XWindowFunc func = (XWindowFunc)::dlsym(RTLD_NEXT, "XUnmapWindow");
  46. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  47. return func(display, window);
  48. }
  49. // --------------------------------------------------------------------------------------------------------------------
  50. // Custom carla window handling
  51. static int carlaWindowMap(Display* const display, const Window window, const int fallbackFnType)
  52. {
  53. for (;;)
  54. {
  55. if (const char* const winIdStr = std::getenv("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID"))
  56. {
  57. CARLA_SAFE_ASSERT_BREAK(winIdStr[0] != '\0');
  58. const long long winIdLL(std::strtoll(winIdStr, nullptr, 16));
  59. CARLA_SAFE_ASSERT_BREAK(winIdLL > 0);
  60. const Window winId(static_cast<Window>(winIdLL));
  61. XSetTransientForHint(display, window, static_cast<Window>(winId));
  62. carla_stdout("Transient hint correctly applied before mapping window");
  63. }
  64. break;
  65. }
  66. switch (fallbackFnType)
  67. {
  68. case 1:
  69. return real_XMapWindow(display, window);
  70. case 2:
  71. return real_XMapRaised(display, window);
  72. case 3:
  73. return real_XMapSubwindows(display, window);
  74. default:
  75. return 0;
  76. }
  77. }
  78. // --------------------------------------------------------------------------------------------------------------------
  79. // Our custom X11 functions
  80. CARLA_PLUGIN_EXPORT
  81. int XMapWindow(Display* display, Window window)
  82. {
  83. carla_debug("XMapWindow(%p, %lu)", display, window);
  84. return carlaWindowMap(display, window, 1);
  85. }
  86. CARLA_PLUGIN_EXPORT
  87. int XMapRaised(Display* display, Window window)
  88. {
  89. carla_debug("XMapRaised(%p, %lu)", display, window);
  90. return carlaWindowMap(display, window, 2);
  91. }
  92. CARLA_PLUGIN_EXPORT
  93. int XMapSubwindows(Display* display, Window window)
  94. {
  95. carla_debug("XMapSubwindows(%p, %lu)", display, window);
  96. return carlaWindowMap(display, window, 3);
  97. }
  98. CARLA_PLUGIN_EXPORT
  99. int XUnmapWindow(Display* display, Window window)
  100. {
  101. carla_debug("XUnmapWindow(%p, %lu)", display, window);
  102. return real_XUnmapWindow(display, window);
  103. }
  104. // --------------------------------------------------------------------------------------------------------------------