helloSystem / Filer

A file manager that can also render the desktop
GNU General Public License v2.0
31 stars 9 forks source link

Support custom window backgrounds #127

Open probonopd opened 3 years ago

probonopd commented 3 years ago

https://github.com/al45tair/ds_store/blob/master/doc/index.rst

Typically developers set an attractive background on their disk images, increase the icon size and font size and often include a link to the /Applications folder.

On the Mac, this kind of information is stored in .DS_Store files, which can be parsed, e.g., using the https://github.com/al45tair/ds_store tool written in Python.

probonopd commented 1 year ago

The Mac is using .DS_Store files to save properties of the window including icon size and position. Unfortunately that format is largely undocumented but has been reverse engineered to some extent, see https://metacpan.org/dist/Mac-Finder-DSStore/view/DSStoreFormat.pod. Seems rather complex and not all of it is understood. helloSystem is using a combination of extended attributes in the file system, and (optionally) .DirInfo files.

Trying to simplify things, we should possibly do something similar for backgrounds and just make filer use background files if present, similar to how it uses .DirIcon and .VolumeIcon.icns already. In Firefox 106.0.dmg, the file in question is stored in .background/background.png; however this is not standardized because on macOS, .DS_Store tells macOS where to load this from. Skype-8.89.0.403.dmg, for example, uses .hidden/background.tiff. Argh!

Inserting the following in void MainWindow::updateUIForCurrentPage() above updateViewMenuForCurrentPage(); almost works as intended:

    // Apply background
    qDebug() << "probono: tabPage->viewMode():" << tabPage->viewMode();
    // FIXME: This always seems to return 1, which is Fm::FolderView::IconMode
    if (tabPage->viewMode() == Fm::FolderView::IconMode || tabPage->viewMode() == Fm::FolderView::ThumbnailMode) {
        QString backgroundFile = tabPage->pathName() + "/.background/background.png";
        qDebug() << "probono: check for background:" << backgroundFile;
        if (QFile::exists(backgroundFile)) {
            QString ss = "background-image:url(" + backgroundFile +")";
            // qDebug() << "probono: ss:" << ss;
            tabPage->setStyleSheet(ss);
        }
    }

But:

# Skype
FreeBSD% strings '.DS_Store' | grep -i Background | grep ^/ 
/.background/background.png

# Firefox
FreeBSD% strings '.DS_Store' | grep -i Background | grep ^/ 
/.hidden/background.tiff