Browse Source

Center external windows when shown, if possible

tags/1.9.4
falkTX 10 years ago
parent
commit
06f2cfe679
3 changed files with 32 additions and 4 deletions
  1. +1
    -1
      source/Makefile.deps
  2. +1
    -1
      source/backend/Makefile
  3. +30
    -2
      source/utils/CarlaPluginUI.cpp

+ 1
- 1
source/Makefile.deps View File

@@ -166,6 +166,6 @@ VST3_PLUGIN_CPP = $(CWD)/backend/plugin/Vst3Plugin.cpp $
# backend/standalone # backend/standalone


CARLA_STANDALONE_CPP_DEPS = $(CARLA_HOST_H) $(CARLA_MIDI_H) $(CARLA_NATIVE_H) $(CARLA_ENGINE_HPP) $(CARLA_PLUGIN_HPP) $(CARLA_BACKEND_UTILS_HPP) $(CARLA_OSC_UTILS_HPP) CARLA_STANDALONE_CPP_DEPS = $(CARLA_HOST_H) $(CARLA_MIDI_H) $(CARLA_NATIVE_H) $(CARLA_ENGINE_HPP) $(CARLA_PLUGIN_HPP) $(CARLA_BACKEND_UTILS_HPP) $(CARLA_OSC_UTILS_HPP)
CARLA_STANDALONE_CPP = $(CWD)/backend/standalone/CarlaStandalone.cpp $(CARLA_STANDALONE_CPP_DEPS) $(CARLA_PLUGIN_UI_CPP) $(CARLA_DSSI_UTILS_CPP) $(CARLA_STATE_UTILS_CPP)
CARLA_STANDALONE_CPP = $(CWD)/backend/CarlaStandalone.cpp $(CARLA_STANDALONE_CPP_DEPS) $(CARLA_PLUGIN_UI_CPP) $(CARLA_DSSI_UTILS_CPP) $(CARLA_STATE_UTILS_CPP)


# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------

+ 1
- 1
source/backend/Makefile View File

@@ -101,7 +101,7 @@ doxygen: CarlaBackend.doxygen


# -------------------------------------------------------------- # --------------------------------------------------------------


CarlaStandalone.cpp.o: CarlaStandalone.cpp $(CARLA_STANDALONE_CPP_DEPS)
CarlaStandalone.cpp.o: $(CARLA_STANDALONE_CPP)
$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@


# -------------------------------------------------------------- # --------------------------------------------------------------


+ 30
- 2
source/utils/CarlaPluginUI.cpp View File

@@ -328,6 +328,8 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons
const ScopedDisplay sd; const ScopedDisplay sd;
CARLA_SAFE_ASSERT_RETURN(sd.display != nullptr, true); CARLA_SAFE_ASSERT_RETURN(sd.display != nullptr, true);


const Window rootWindow(DefaultRootWindow(sd.display));

const Atom _ncl = XInternAtom(sd.display, "_NET_CLIENT_LIST" , False); const Atom _ncl = XInternAtom(sd.display, "_NET_CLIENT_LIST" , False);
const Atom _nwn = XInternAtom(sd.display, "_NET_WM_NAME", False); const Atom _nwn = XInternAtom(sd.display, "_NET_WM_NAME", False);
const Atom _nwp = XInternAtom(sd.display, "_NET_WM_PID", False); const Atom _nwp = XInternAtom(sd.display, "_NET_WM_PID", False);
@@ -338,7 +340,7 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons
ulong numWindows, bytesAfter; ulong numWindows, bytesAfter;
uchar* data = nullptr; uchar* data = nullptr;


int status = XGetWindowProperty(sd.display, DefaultRootWindow(sd.display), _ncl, 0L, (~0L), False, AnyPropertyType, &actualType, &actualFormat, &numWindows, &bytesAfter, &data);
int status = XGetWindowProperty(sd.display, rootWindow, _ncl, 0L, (~0L), False, AnyPropertyType, &actualType, &actualFormat, &numWindows, &bytesAfter, &data);


CARLA_SAFE_ASSERT_RETURN(data != nullptr, true); CARLA_SAFE_ASSERT_RETURN(data != nullptr, true);
const ScopedFreeData sfd(data); const ScopedFreeData sfd(data);
@@ -440,7 +442,33 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons
const Atom _nwi = XInternAtom(sd.display, "_NET_WM_ICON", False); const Atom _nwi = XInternAtom(sd.display, "_NET_WM_ICON", False);
XChangeProperty(sd.display, lastGoodWindow, _nwi, XA_CARDINAL, 32, PropModeReplace, (const uchar*)sCarlaX11Icon, sCarlaX11IconSize); XChangeProperty(sd.display, lastGoodWindow, _nwi, XA_CARDINAL, 32, PropModeReplace, (const uchar*)sCarlaX11Icon, sCarlaX11IconSize);


XSetTransientForHint(sd.display, lastGoodWindow, (Window)winId);
const Window hostWinId((Window)winId);

XSetTransientForHint(sd.display, lastGoodWindow, hostWinId);

// center the plugin UI
{
int hostX, hostY, pluginX, pluginY;
uint hostWidth, hostHeight, pluginWidth, pluginHeight, border, depth;
Window retWindow;

if (XGetGeometry(sd.display, hostWinId, &retWindow, &hostX, &hostY, &hostWidth, &hostHeight, &border, &depth) != 0 &&
XGetGeometry(sd.display, lastGoodWindow, &retWindow, &pluginX, &pluginY, &pluginWidth, &pluginHeight, &border, &depth) != 0)
{
if (XTranslateCoordinates(sd.display, hostWinId, rootWindow, hostX, hostY, &hostX, &hostY, &retWindow) == True &&
XTranslateCoordinates(sd.display, lastGoodWindow, rootWindow, pluginX, pluginY, &pluginX, &pluginY, &retWindow) == True)
{
const int newX = hostX + int(hostWidth/2 - pluginWidth/2);
const int newY = hostY + int(hostHeight/2 - pluginHeight/2);

XMoveWindow(sd.display, lastGoodWindow, newX, newY);
}
}
}

// focusing the host UI and then the plugin UI forces the WM to repaint the plugin window icon
XRaiseWindow(sd.display, hostWinId);
XSetInputFocus(sd.display, hostWinId, RevertToPointerRoot, CurrentTime);


XRaiseWindow(sd.display, lastGoodWindow); XRaiseWindow(sd.display, lastGoodWindow);
XSetInputFocus(sd.display, lastGoodWindow, RevertToPointerRoot, CurrentTime); XSetInputFocus(sd.display, lastGoodWindow, RevertToPointerRoot, CurrentTime);


Loading…
Cancel
Save