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 2.8KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. for (;;)
  48. {
  49. if (++sMapWindowCounter != 1)
  50. break;
  51. if (const char* const winIdStr = std::getenv("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID"))
  52. {
  53. CARLA_SAFE_ASSERT_BREAK(winIdStr[0] != '\0');
  54. const long long winIdLL(std::strtoll(winIdStr, nullptr, 16));
  55. CARLA_SAFE_ASSERT_BREAK(winIdLL > 0);
  56. const Window winId(static_cast<Window>(winIdLL));
  57. XSetTransientForHint(display, w, static_cast<Window>(winId));
  58. carla_stdout("Transient hint correctly applied before mapping window");
  59. }
  60. break;
  61. }
  62. return real_XMapWindow(display, w);
  63. }
  64. CARLA_EXPORT
  65. int XUnmapWindow(Display* display, Window w)
  66. {
  67. carla_stdout("------------------------------- XUnmapWindow called");
  68. --sMapWindowCounter;
  69. return real_XUnmapWindow(display, w);
  70. }
  71. // -----------------------------------------------------------------------