📄 qwidget_x11.cpp
字号:
void QWidgetPrivate::dirtyWidget_sys(const QRegion &rgn){ Q_Q(QWidget); if (!rgn.isEmpty()) { dirtyOnScreen += rgn; QApplication::postEvent(q, new QEvent(QEvent::UpdateRequest), Qt::LowEventPriority); }}void QWidgetPrivate::cleanWidget_sys(const QRegion& rgn){ dirtyOnScreen -= rgn;}void QWidget::setWindowState(Qt::WindowStates newstate){ Q_D(QWidget); bool needShow = false; Qt::WindowStates oldstate = windowState(); if (oldstate == newstate) return; if (isWindow()) { // Ensure the initial size is valid, since we store it as normalGeometry below. if (!testAttribute(Qt::WA_Resized) && !isVisible()) adjustSize(); QTLWExtra *top = d->topData(); if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) { if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)) && X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT))) { if ((newstate & Qt::WindowMaximized) && !(oldstate & Qt::WindowFullScreen)) top->normalGeometry = geometry(); qt_change_net_wm_state(this, (newstate & Qt::WindowMaximized), ATOM(_NET_WM_STATE_MAXIMIZED_HORZ), ATOM(_NET_WM_STATE_MAXIMIZED_VERT)); } else if (! (newstate & Qt::WindowFullScreen)) { if (newstate & Qt::WindowMaximized) { // save original geometry const QRect normalGeometry = geometry(); if (isVisible()) { data->fstrut_dirty = true; const QRect maxRect = QApplication::desktop()->availableGeometry(this); const QRect r = top->normalGeometry; const QRect fs = d->frameStrut(); setGeometry(maxRect.x() + fs.left(), maxRect.y() + fs.top(), maxRect.width() - fs.left() - fs.right(), maxRect.height() - fs.top() - fs.bottom()); top->normalGeometry = r; } if (top->normalGeometry.width() < 0) top->normalGeometry = normalGeometry; } else { // restore original geometry setGeometry(top->normalGeometry); } } } if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) { if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) { if (newstate & Qt::WindowFullScreen) { top->normalGeometry = geometry(); top->fullScreenOffset = d->frameStrut().topLeft(); } qt_change_net_wm_state(this, (newstate & Qt::WindowFullScreen), ATOM(_NET_WM_STATE_FULLSCREEN)); } else { needShow = isVisible(); if (newstate & Qt::WindowFullScreen) { data->fstrut_dirty = true; const QRect normalGeometry = geometry(); const QPoint fullScreenOffset = d->frameStrut().topLeft(); top->savedFlags = windowFlags(); setParent(0, Qt::Window | Qt::FramelessWindowHint); const QRect r = top->normalGeometry; setGeometry(qApp->desktop()->screenGeometry(this)); top->normalGeometry = r; if (top->normalGeometry.width() < 0) { top->normalGeometry = normalGeometry; top->fullScreenOffset = fullScreenOffset; } } else { setParent(0, top->savedFlags); if (newstate & Qt::WindowMaximized) { // from fullscreen to maximized data->fstrut_dirty = true; const QRect maxRect = QApplication::desktop()->availableGeometry(this); const QRect r = top->normalGeometry; const QRect fs = d->frameStrut(); setGeometry(maxRect.x() + fs.left(), maxRect.y() + fs.top(), maxRect.width() - fs.left() - fs.right(), maxRect.height() - fs.top() - fs.bottom()); top->normalGeometry = r; } else { // restore original geometry setGeometry(top->normalGeometry.adjusted(-top->fullScreenOffset.x(), -top->fullScreenOffset.y(), -top->fullScreenOffset.x(), -top->fullScreenOffset.y())); } } } } createWinId(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) { if (isVisible()) { if (newstate & Qt::WindowMinimized) { XEvent e; e.xclient.type = ClientMessage; e.xclient.message_type = ATOM(WM_CHANGE_STATE); e.xclient.display = X11->display; e.xclient.window = data->winid; e.xclient.format = 32; e.xclient.data.l[0] = IconicState; e.xclient.data.l[1] = 0; e.xclient.data.l[2] = 0; e.xclient.data.l[3] = 0; e.xclient.data.l[4] = 0; XSendEvent(X11->display, RootWindow(X11->display,d->xinfo.screen()), False, (SubstructureNotifyMask|SubstructureRedirectMask), &e); } else { setAttribute(Qt::WA_Mapped); XMapWindow(X11->display, internalWinId()); } } needShow = false; } } data->window_state = newstate; if (needShow) show(); if (newstate & Qt::WindowActive) activateWindow(); QWindowStateChangeEvent e(oldstate); QApplication::sendEvent(this, &e);}/*! \internal Platform-specific part of QWidget::show().*/void QWidgetPrivate::show_sys(){ Q_Q(QWidget); Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); if (q->isWindow()) { XWMHints *h = XGetWMHints(X11->display, q->internalWinId()); XWMHints wm_hints; bool got_hints = h != 0; if (!got_hints) { h = &wm_hints; h->flags = 0; } h->initial_state = q->isMinimized() ? IconicState : NormalState; h->flags |= StateHint; XSetWMHints(X11->display, q->internalWinId(), h); if (got_hints) XFree((char *)h); // update WM_NORMAL_HINTS do_size_hints(q, extra); // udpate WM_TRANSIENT_FOR if (isTransient(q)) { QWidget *p = q->parentWidget(); if (p) p = p->window(); if (p) { // transient for window XSetTransientForHint(X11->display, q->internalWinId(), p->internalWinId()); } else { // transient for group XSetTransientForHint(X11->display, q->internalWinId(), X11->wm_client_leader); } } // update _MOTIF_WM_HINTS QtMWMHints mwmhints = GetMWMHints(X11->display, q->internalWinId()); if (data.window_modality != Qt::NonModal) { switch (data.window_modality) { case Qt::WindowModal: mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL; break; case Qt::ApplicationModal: default: mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL; break; } mwmhints.flags |= MWM_HINTS_INPUT_MODE; } else { mwmhints.input_mode = MWM_INPUT_MODELESS; mwmhints.flags &= ~MWM_HINTS_INPUT_MODE; } if (q->minimumSize() == q->maximumSize()) { // fixed size, remove the resize handle (since mwm/dtwm // isn't smart enough to do it itself) mwmhints.flags |= MWM_HINTS_FUNCTIONS; if (mwmhints.functions == MWM_FUNC_ALL) { mwmhints.functions = (MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE); } else { mwmhints.functions &= ~MWM_FUNC_RESIZE; } mwmhints.flags |= MWM_HINTS_DECORATIONS; if (mwmhints.decorations == MWM_DECOR_ALL) { mwmhints.decorations = (MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE); } else { mwmhints.decorations &= ~MWM_DECOR_RESIZEH; } } SetMWMHints(X11->display, q->internalWinId(), mwmhints); // update _NET_WM_STATE QVector<Atom> netWmState = getNetWmState(q); Qt::WindowFlags flags = q->windowFlags(); if (flags & Qt::WindowStaysOnTopHint) { netWmState.append(ATOM(_NET_WM_STATE_ABOVE)); netWmState.append(ATOM(_NET_WM_STATE_STAYS_ON_TOP)); } if (q->isFullScreen()) { netWmState.append(ATOM(_NET_WM_STATE_FULLSCREEN)); } if (q->isMaximized()) { netWmState.append(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)); netWmState.append(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)); } if (data.window_modality != Qt::NonModal) { netWmState.append(ATOM(_NET_WM_STATE_MODAL)); } if (!netWmState.isEmpty()) { XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_STATE), XA_ATOM, 32, PropModeReplace, (unsigned char *) netWmState.data(), netWmState.size()); } else { XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_STATE)); } // set _NET_WM_USER_TIME if (X11->userTime != CurrentTime) { XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_USER_TIME), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &X11->userTime, 1); } if (!topData()->embedded && (topData()->validWMState || topData()->waitingForMapNotify) && !q->isMinimized()) { X11->deferred_map.append(q); return; } if (q->isMaximized() && !q->isFullScreen() && !(X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)) && X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)))) { XMapWindow(X11->display, q->internalWinId()); data.fstrut_dirty = true; qt_x11_wait_for_window_manager(q); // if the wm was not smart enough to adjust our size, do that manually QRect maxRect = QApplication::desktop()->availableGeometry(q); QTLWExtra *top = topData(); QRect normalRect = top->normalGeometry; const QRect fs = frameStrut(); q->setGeometry(maxRect.x() + fs.left(), maxRect.y() + fs.top(), maxRect.width() - fs.left() - fs.right(), maxRect.height() - fs.top() - fs.bottom()); // restore the original normalGeometry top->normalGeometry = normalRect; // internalSetGeometry() clears the maximized flag... make sure we set it back data.window_state = data.window_state | Qt::WindowMaximized; q->setAttribute(Qt::WA_Mapped); return; } if (q->isFullScreen() && !X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) { XMapWindow(X11->display, q->internalWinId()); qt_x11_wait_for_window_manager(q); q->setAttribute(Qt::WA_Mapped); return; } } invalidateBuffer(q->rect()); if (q->testAttribute(Qt::WA_OutsideWSRange)) return; q->setAttribute(Qt::WA_Mapped); if (q->isWindow()) topData()->waitingForMapNotify = 1; if (!q->isWindow() && (!q->autoFillBackground() || q->palette().brush(q->backgroundRole()).style() == Qt::LinearGradientPattern)) { XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), XNone); XMapWindow(X11->display, q->internalWinId()); updateSystemBackground(); return; } XMapWindow(X11->display, q->internalWinId()); // Freedesktop.org Startup Notification if (X11->startupId && q->isWindow()) { QByteArray message("remove: ID="); message.append(X11->startupId); sendStartupMessage(message.constData()); X11->startupId = 0; }}/*! \internal Platform-specific part of QWidget::show().*/void QWidgetPrivate::sendStartupMessage(const char *message) const{ Q_Q(const QWidget); if (!message) return; XEvent xevent; xevent.xclient.type = ClientMessage; xevent.xclient.message_type = ATOM(_NET_STARTUP_INFO_BEGIN); xevent.xclient.display = X11->display; xevent.xclient.window = q->internalWin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -