67 if (m_host || !host || !delegate) {
71 m_delegate.reset(delegate);
72 m_winIdChangeEventFilter = std::make_unique<WinIdChangeEventFilter>(host,
this);
74 m_windowHandle = m_delegate->hostWindow(m_host);
77 m_windowEventFilter = std::make_unique<WindowEventFilter>(m_windowHandle,
this);
144 *
button = WindowAgentBase::Unknown;
145 for (
int i = WindowAgentBase::WindowIcon; i <= WindowAgentBase::Close; ++i) {
146 auto currentButton = m_systemButtons[i];
147 if (!currentButton || !m_delegate->isVisible(currentButton) || !m_delegate->isEnabled(currentButton)) {
150 if (m_delegate->mapGeometryToScene(currentButton).contains(pos)) {
158bool WindowContext::isInTitleBarDraggableArea(
const QPoint &pos)
const
164 if (!m_delegate->isVisible(m_titleBar) || !m_delegate->isEnabled(m_titleBar)) {
169 QRect windowRect = {QPoint(0, 0), m_windowHandle->size()};
170 QRect titleBarRect = m_delegate->mapGeometryToScene(m_titleBar);
171 if (!titleBarRect.intersects(windowRect)) {
177 if (!titleBarRect.contains(pos)) {
181 for (
int i = WindowAgentBase::WindowIcon; i <= WindowAgentBase::Close; ++i) {
182 auto currentButton = m_systemButtons[i];
183 if (currentButton && m_delegate->isVisible(currentButton) && m_delegate->isEnabled(currentButton) &&
184 m_delegate->mapGeometryToScene(currentButton).contains(pos)) {
189 for (
auto widget : m_hitTestVisibleItems) {
190 if (widget && m_delegate->isVisible(widget) && m_delegate->isEnabled(widget) &&
191 m_delegate->mapGeometryToScene(widget).contains(pos)) {
195 if (!m_captionClassNameList.isEmpty()) {
196 if (
auto widget = m_delegate->childAt(m_titleBar, pos)) {
197 if (!isCaptionClassName(widget->metaObject()->className())) {
235void WindowContext::virtual_hook(
int id,
void *data)
238 case CentralizeHook: {
242 QRect screenGeometry = m_windowHandle->screen()->geometry();
243 int x = (screenGeometry.width() - m_windowHandle->width()) / 2;
244 int y = (screenGeometry.height() - m_windowHandle->height()) / 2;
246 pos += screenGeometry.topLeft();
247 m_windowHandle->setPosition(pos);
251 case RaiseWindowHook: {
255 m_delegate->setWindowVisible(m_host,
true);
256 Qt::WindowStates state = m_delegate->getWindowState(m_host);
257 if (state & Qt::WindowMinimized) {
258 m_delegate->setWindowState(m_host, state & ~Qt::WindowMinimized);
260 m_delegate->bringWindowToTop(m_host);
264 case DefaultColorsHook: {
265 auto &map = *
static_cast<QMap<QString, QColor> *
>(data);
267 map.insert(QStringLiteral(
"activeLight"),
kSampleColorSet.activeLight);
269 map.insert(QStringLiteral(
"inactiveLight"),
kSampleColorSet.inactiveLight);
270 map.insert(QStringLiteral(
"inactiveDark"),
kSampleColorSet.inactiveDark);
284void WindowContext::notifyWinIdChange()
286 auto oldWindow = m_windowHandle;
287 m_windowHandle = m_delegate->hostWindow(m_host);
288 if (oldWindow == m_windowHandle)
290 m_windowEventFilter.reset();
292 if (m_windowHandle) {
293 m_windowEventFilter = std::make_unique<WindowEventFilter>(m_windowHandle,
this);
296 auto attributes = m_windowAttributes;
297 m_windowAttributes.clear();
298 for (
auto it = attributes.begin(); it != attributes.end(); ++it) {
299 if (!windowAttributeChanged(it.key(), it.value(), {})) {
302 m_windowAttributes.insert(it.key(), it.value());
312bool WindowContext::setWindowAttribute(
const QString &key,
const QVariant &attribute)
314 auto it = m_windowAttributes.find(key);
315 if (it == m_windowAttributes.end()) {
316 if (!attribute.isValid()) {
319 if (!m_windowHandle || !windowAttributeChanged(key, attribute, {})) {
322 m_windowAttributes.insert(key, attribute);
326 if (it.value() == attribute)
328 if (!m_windowHandle || !windowAttributeChanged(key, attribute, it.value())) {
332 if (attribute.isValid()) {
333 it.value() = attribute;
335 m_windowAttributes.erase(it);