[KDE/Mac] Qt4/KDE4 issue with persistent window size across restarts on OS X 10.9

René J.V. Bertin rjvbertin at gmail.com
Fri Feb 13 19:11:08 UTC 2015


Hello (again)

I've come up with the draft below, additionally letting a QEvent::Move do d->setSizeDirty() as on MS Windows. It now works (almost?) as one would expect on OS X.
I did try to set autoSaveSettings=true in KMainWindowPrivate::init(), but that caused a crash in Kate (somewhere in KConfig) when I started it so I backtracked on that one; I didn't notice any difference in the behaviour of other applications because of it.

#elif defined(Q_OS_MAC)

void KMainWindow::restoreWindowSize( const KConfigGroup & _cg )
{

    QString geometryKey = QString::fromLatin1("geometry");
    QByteArray geometry = _cg.readEntry( geometryKey, QByteArray() );
    kDebug(200) << "restoreWindowSize():" << geometryKey << "=" << geometry;
    if (!restoreGeometry( QByteArray::fromBase64(geometry) )) {
        // try first if there data has been stored using the X11-like approach from earlier kdelibs versions.
        // This code is copied from restoreWindowSize() below.
        int scnum = QApplication::desktop()->screenNumber(window());
        QRect desk = QApplication::desktop()->screenGeometry(scnum);
        const QSize size( _cg.readEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ),
                    _cg.readEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ) );
        if ( !size.isEmpty() ) {
            kDebug(200) << "restoreWindowSize(): falling back to legacy saved state" << size;
            if (size.width() > desk.width() || size.height() > desk.height()) {
                setWindowState( Qt::WindowMaximized );
            }
            else {
                resize( size );
            }
        }
        else {
            // if first time run, centre window
            kDebug(200) << "restoreWindowSize(): moving the window to the screen centre of" << desk;
            move( (desk.width()-width())/2, (desk.height()-height())/2 );
        }
    }
}

void KMainWindow::saveWindowSize( const KConfigGroup & _cg ) const
{
    QString geometryKey = QString::fromLatin1("geometry");
    QByteArray geometry = saveGeometry();
    kDebug(200) << "saveWindowSize():" << geometryKey << "=" << geometry;
    KConfigGroup cg(_cg);
    cg.writeEntry( geometryKey, geometry.toBase64() );
}

#else // Q_WS_X11 and select others.
void KMainWindow::saveWindowSize( const KConfigGroup & _cg ) const



More information about the kde-mac mailing list