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.

111 lines
3.0KB

  1. /*
  2. * Carla Interposer for X11 Window Mapping
  3. * Copyright (C) 2014-2017 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. struct ScopedLibOpen {
  21. void* handle;
  22. ScopedLibOpen()
  23. : handle(dlopen("libjack.so.0", RTLD_NOW|RTLD_LOCAL)) {}
  24. ~ScopedLibOpen()
  25. {
  26. if (handle != nullptr)
  27. dlclose(handle);
  28. }
  29. };
  30. // -----------------------------------------------------------------------
  31. // Function typedefs
  32. typedef int (*XMapWindowFunc)(Display*, Window);
  33. typedef int (*XUnmapWindowFunc)(Display*, Window);
  34. // -----------------------------------------------------------------------
  35. // Global counter so we only map the first (hopefully main) window
  36. static int sMapWindowCounter = 0;
  37. // -----------------------------------------------------------------------
  38. // Calling the real functions
  39. static int real_XMapWindow(Display* display, Window w)
  40. {
  41. static const XMapWindowFunc func = (XMapWindowFunc)::dlsym(RTLD_NEXT, "XMapWindow");
  42. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  43. return func(display, w);
  44. }
  45. static int real_XUnmapWindow(Display* display, Window w)
  46. {
  47. static const XUnmapWindowFunc func = (XUnmapWindowFunc)::dlsym(RTLD_NEXT, "XUnmapWindow");
  48. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  49. return func(display, w);
  50. }
  51. // -----------------------------------------------------------------------
  52. // Our custom functions
  53. CARLA_EXPORT
  54. int XMapWindow(Display* display, Window w)
  55. {
  56. carla_stdout("------------------------------- XMapWindow called");
  57. for (;;)
  58. {
  59. if (++sMapWindowCounter != 1)
  60. break;
  61. static const ScopedLibOpen slo;
  62. if (const char* const winIdStr = std::getenv("CARLA_FRONTEND_WIN_ID"))
  63. {
  64. CARLA_SAFE_ASSERT_BREAK(winIdStr[0] != '\0');
  65. const long long winIdLL(std::strtoll(winIdStr, nullptr, 16));
  66. CARLA_SAFE_ASSERT_BREAK(winIdLL > 0);
  67. const Window winId(static_cast<Window>(winIdLL));
  68. XSetTransientForHint(display, w, static_cast<Window>(winId));
  69. carla_stdout("Transient hint correctly applied before mapping window");
  70. }
  71. break;
  72. }
  73. return real_XMapWindow(display, w);
  74. }
  75. CARLA_EXPORT
  76. int XUnmapWindow(Display* display, Window w)
  77. {
  78. carla_stdout("------------------------------- XUnmapWindow called");
  79. --sMapWindowCounter;
  80. return real_XUnmapWindow(display, w);
  81. }
  82. // -----------------------------------------------------------------------