From 55845ab4df57bd8f8d33f6959e91c66e6fb50829 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 6 Sep 2012 11:39:42 +0200 Subject: [PATCH] X11: Restore windows on correct virtual desktops - this will not be used for first application window, to prevent starting application and no window being opened on current desktop = applies only for other restored windows (2nd, 3rd, ...) --- CHANGELOG | 1 + src/lib/app/mainapplication.cpp | 2 - src/lib/app/qupzilla.cpp | 93 ++++++++++++++++++++++++++++++++- src/lib/app/qupzilla.h | 10 ++++ 4 files changed, 102 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ca28d6791..03349e4e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,7 @@ Version 1.3.5 * new option to show loading progress in address bar * new option to hide close button on tabs * new option to start new instance with --no-remote option + * X11: restore windows on correct virtual desktops * fixed visibility of navigation bar in fullscreen * fixed bad position of add tab button when there is a lot of tabs * fixed gui with RTL languages diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index d64d60323..a37d802f6 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -233,7 +233,6 @@ MainApplication::MainApplication(int &argc, char** argv) translateApp(); QupZilla* qupzilla = new QupZilla(Qz::BW_FirstAppWindow, startUrl); - qupzilla->show(); m_mainWindows.append(qupzilla); connect(qupzilla, SIGNAL(message(Qz::AppMessageType, bool)), this, SLOT(sendMessages(Qz::AppMessageType, bool))); @@ -542,7 +541,6 @@ QupZilla* MainApplication::makeNewWindow(Qz::BrowserWindow type, const QUrl &sta QupZilla* newWindow = new QupZilla(type, startUrl); m_mainWindows.append(newWindow); - newWindow->show(); return newWindow; } diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index e1191a291..a6ea9686a 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -80,6 +80,12 @@ #include #include +#ifdef Q_WS_X11 +#include +#include +#include +#endif + const QString QupZilla::VERSION = "1.3.1"; const QString QupZilla::BUILDTIME = __DATE__" "__TIME__; const QString QupZilla::AUTHOR = "David Rosca"; @@ -181,6 +187,8 @@ void QupZilla::postLaunch() break; } + show(); + if (!m_startingUrl.isEmpty()) { startUrl = QUrl::fromUserInput(m_startingUrl.toString()); addTab = true; @@ -1382,7 +1390,7 @@ void QupZilla::addDeleteOnCloseWidget(QWidget* widget) void QupZilla::restoreWindowState(const RestoreManager::WindowData &d) { - QMainWindow::restoreState(d.windowState); + restoreState(d.windowState); m_tabWidget->restoreState(d.tabsState, d.currentTab); } @@ -1827,10 +1835,91 @@ bool QupZilla::quitApp() settings.endGroup(); } - QTimer::singleShot(0, mApp, SLOT(quitApplication())); + mApp->quitApplication(); return true; } +QByteArray QupZilla::saveState(int version) const +{ +#ifdef Q_WS_X11 + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly); + + stream << QMainWindow::saveState(version); + stream << getCurrentVirtualDesktop(); + + return data; +#else + return QMainWindow::saveState(version); +#endif +} + +bool QupZilla::restoreState(const QByteArray &state, int version) +{ +#ifdef Q_WS_X11 + QByteArray windowState; + int desktopId = -1; + + QDataStream stream(state); + stream >> windowState; + stream >> desktopId; + + moveToVirtualDesktop(desktopId); + + return QMainWindow::restoreState(windowState, version); +#else + return QMainWindow::saveState(version); +#endif +} + +#ifdef Q_WS_X11 +int QupZilla::getCurrentVirtualDesktop() const +{ + Display* display = QX11Info::display(); + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long bytes; + unsigned long* data; + + Atom net_wm_desktop = XInternAtom(display, "_NET_WM_DESKTOP", False); + if (net_wm_desktop == None) { + return -1; + } + + int status = XGetWindowProperty(display, winId(), net_wm_desktop, 0, 1, + False, XA_CARDINAL, &actual_type, &actual_format, + &nitems, &bytes, (unsigned char**) &data); + + if (status != Success || data == NULL) { + return -1; + } + + int desktop = *data; + XFree(data); + + return desktop; +} + +void QupZilla::moveToVirtualDesktop(int desktopId) +{ + // Don't move when window is already visible or it is first app window + if (desktopId < 0 || isVisible() || m_startBehaviour == Qz::BW_FirstAppWindow) { + return; + } + + Display* display = QX11Info::display(); + + Atom net_wm_desktop = XInternAtom(display, "_NET_WM_DESKTOP", False); + if (net_wm_desktop == None) { + return; + } + + XChangeProperty(display, winId(), net_wm_desktop, XA_CARDINAL, + 32, PropModeReplace, (unsigned char*) &desktopId, 1L); +} +#endif + #ifdef Q_OS_WIN bool QupZilla::winEvent(MSG* message, long* result) { diff --git a/src/lib/app/qupzilla.h b/src/lib/app/qupzilla.h index d11aec887..9d27d73cb 100644 --- a/src/lib/app/qupzilla.h +++ b/src/lib/app/qupzilla.h @@ -81,9 +81,13 @@ public: SideBar* addSideBar(); virtual QMenuBar* menuBar() const; + QByteArray saveState(int version = 0) const; + bool restoreState(const QByteArray &state, int version = 0); + TabbedWebView* weView() const; TabbedWebView* weView(int index) const; LocationBar* locationBar() const; + inline TabWidget* tabWidget() { return m_tabWidget; } inline BookmarksToolbar* bookmarksToolbar() { return m_bookmarksToolbar; } inline StatusBarMessage* statusBarMessage() { return m_statusBarMessage; } @@ -201,11 +205,17 @@ private: void setupMenu(); void disconnectObjects(); + #ifdef Q_OS_WIN bool winEvent(MSG* message, long* result); bool eventFilter(QObject* object, QEvent* event); #endif +#ifdef Q_WS_X11 + int getCurrentVirtualDesktop() const; + void moveToVirtualDesktop(int desktopId); +#endif + bool m_historyMenuChanged; bool m_bookmarksMenuChanged; bool m_isClosing;