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

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // -----------------------------------------------------------------------
  21. // Function typedefs
  22. typedef int (*XMapWindowFunc)(Display*, Window);
  23. typedef int (*XUnmapWindowFunc)(Display*, Window);
  24. // -----------------------------------------------------------------------
  25. // Current mapped window
  26. static Window sCurrentlyMappedWindow = 0;
  27. // -----------------------------------------------------------------------
  28. // Calling the real functions
  29. static int real_XMapWindow(Display* display, Window window)
  30. {
  31. static const XMapWindowFunc func = (XMapWindowFunc)::dlsym(RTLD_NEXT, "XMapWindow");
  32. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  33. return func(display, window);
  34. }
  35. static int real_XUnmapWindow(Display* display, Window window)
  36. {
  37. static const XUnmapWindowFunc func = (XUnmapWindowFunc)::dlsym(RTLD_NEXT, "XUnmapWindow");
  38. CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0);
  39. return func(display, window);
  40. }
  41. // -----------------------------------------------------------------------
  42. // Our custom functions
  43. CARLA_EXPORT
  44. int XMapWindow(Display* display, Window window)
  45. {
  46. for (;;)
  47. {
  48. #if 0
  49. if (sCurrentlyMappedWindow != 0)
  50. break;
  51. Atom atom;
  52. int atomFormat;
  53. unsigned char* atomPtrs;
  54. unsigned long numItems, ignored;
  55. const Atom wmWindowType = XInternAtom(display, "_NET_WM_WINDOW_TYPE", True);
  56. if (XGetWindowProperty(display, window, wmWindowType, 0, ~0L, False, AnyPropertyType,
  57. &atom, &atomFormat, &numItems, &ignored, &atomPtrs) == Success)
  58. {
  59. const Atom* const atomValues = (const Atom*)atomPtrs;
  60. for (ulong i=0; i<numItems; ++i)
  61. {
  62. const char* const atomValue(XGetAtomName(display, atomValues[i]));
  63. CARLA_SAFE_ASSERT_CONTINUE(atomValue != nullptr && atomValue[0] != '\0');
  64. if (std::strcmp(atomValue, "_NET_WM_WINDOW_TYPE_NORMAL") == 0)
  65. {
  66. sCurrentlyMappedWindow = window;
  67. break;
  68. }
  69. }
  70. }
  71. #endif
  72. if (sCurrentlyMappedWindow == 0)
  73. sCurrentlyMappedWindow = window;
  74. if (const char* const winIdStr = std::getenv("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID"))
  75. {
  76. CARLA_SAFE_ASSERT_BREAK(winIdStr[0] != '\0');
  77. const long long winIdLL(std::strtoll(winIdStr, nullptr, 16));
  78. CARLA_SAFE_ASSERT_BREAK(winIdLL > 0);
  79. const Window winId(static_cast<Window>(winIdLL));
  80. XSetTransientForHint(display, window, static_cast<Window>(winId));
  81. carla_stdout("Transient hint correctly applied before mapping window");
  82. }
  83. break;
  84. }
  85. return real_XMapWindow(display, window);
  86. }
  87. CARLA_EXPORT
  88. int XUnmapWindow(Display* display, Window window)
  89. {
  90. if (sCurrentlyMappedWindow == window)
  91. sCurrentlyMappedWindow = 0;
  92. return real_XUnmapWindow(display, window);
  93. }
  94. // -----------------------------------------------------------------------