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.

91 lines
2.8KB

  1. /*
  2. * Carla Interposer for X11 Window Mapping
  3. * Copyright (C) 2014-2015 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 (*XMapWindowFunc)(Display*, Window);
  23. typedef int (*XUnmapWindowFunc)(Display*, Window);
  24. // -----------------------------------------------------------------------
  25. // Global counter so we only map the first (hopefully main) window
  26. static int sMapWindowCounter = 0;
  27. // -----------------------------------------------------------------------
  28. // Calling the real functions
  29. static int real_XMapWindow(Display* display, Window w)
  30. {
  31. static const XMapWindowFunc func = (XMapWindowFunc)::dlsym(RTLD_NEXT, "XMapWindow");
  32. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  33. return func(display, w);
  34. }
  35. static int real_XUnmapWindow(Display* display, Window w)
  36. {
  37. static const XUnmapWindowFunc func = (XUnmapWindowFunc)::dlsym(RTLD_NEXT, "XUnmapWindow");
  38. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  39. return func(display, w);
  40. }
  41. // -----------------------------------------------------------------------
  42. // Our custom functions
  43. CARLA_EXPORT
  44. int XMapWindow(Display* display, Window w)
  45. {
  46. carla_stdout("------------------------------- XMapWindow called");
  47. if (++sMapWindowCounter != 1)
  48. return real_XMapWindow(display, w);
  49. if (const char* const winIdStr = std::getenv("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID"))
  50. {
  51. CARLA_SAFE_ASSERT_RETURN(winIdStr[0] != '\0', real_XMapWindow(display, w));
  52. const long long winIdLL(std::strtoll(winIdStr, nullptr, 16));
  53. CARLA_SAFE_ASSERT_RETURN(winIdLL > 0, real_XMapWindow(display, w));
  54. const Window winId(static_cast<Window>(winIdLL));
  55. XSetTransientForHint(display, w, static_cast<Window>(winId));
  56. carla_stdout("Transient hint correctly applied before mapping window");
  57. }
  58. return real_XMapWindow(display, w);
  59. }
  60. CARLA_EXPORT
  61. int XUnmapWindow(Display* display, Window w)
  62. {
  63. carla_stdout("------------------------------- XUnmapWindow called");
  64. --sMapWindowCounter;
  65. return real_XUnmapWindow(display, w);
  66. }
  67. // -----------------------------------------------------------------------