Example #1
0
void Application::desktopManager(bool enabled) {
  // TODO: turn on or turn off desktpo management (desktop icons & wallpaper)
  qDebug("desktopManager: %d", enabled);
  QDesktopWidget* desktopWidget = desktop();
  if(enabled) {
    if(!enableDesktopManager_) {
      installNativeEventFilter(this);
      Q_FOREACH(QScreen* screen, screens()) {
        connect(screen, &QScreen::virtualGeometryChanged, this, &Application::onVirtualGeometryChanged);
        connect(screen, &QObject::destroyed, this, &Application::onScreenDestroyed);
      }
      connect(this, &QApplication::screenAdded, this, &Application::onScreenAdded);
      connect(desktopWidget, SIGNAL(resized(int)), SLOT(onScreenResized(int)));
      connect(desktopWidget, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));

      // NOTE: there are two modes
      // When virtual desktop is used (all screens are combined to form a large virtual desktop),
      // we only create one DesktopWindow. Otherwise, we create one for each screen.
      if(desktopWidget->isVirtualDesktop()) {
        DesktopWindow* window = createDesktopWindow(-1);
        desktopWindows_.push_back(window);
      }
      else {
        int n = desktopWidget->numScreens();
        desktopWindows_.reserve(n);
        for(int i = 0; i < n; ++i) {
          DesktopWindow* window = createDesktopWindow(i);
          desktopWindows_.push_back(window);
        }
      }
    }
Example #2
0
ObjKsTheme::ObjKsTheme( const QString& theme )
  :mActiveTheme (theme), mThemeDir("/"), mThemeConfig (0L), mThemePrefix( "Themes/" ), d(0)
{
  // Get Xinerama config.
  KConfig *config = kapp->config();
  config->setGroup( "Xinerama" );
  QDesktopWidget *desktop = kapp->desktop();
  mXineramaScreen = config->readNumEntry("KSplashScreen", desktop->primaryScreen());

  // For Xinerama, let's put the mouse on the first head.  Otherwise it could appear anywhere!
  if (desktop->isVirtualDesktop() && mXineramaScreen != -2)
  {
    QRect rect = desktop->screenGeometry( mXineramaScreen );
    if (!rect.contains(QCursor::pos()))
      QCursor::setPos(rect.center());
  }

  // Does the active theme exist?
  if( !loadThemeRc( mActiveTheme, false ) )
    if( !loadLocalConfig( mActiveTheme, false ) )
      if( !loadThemeRc( "Default", false ) )
        loadLocalConfig( "Default", true ); //force: we need some defaults
  loadCmdLineArgs(KCmdLineArgs::parsedArgs());
  mThemePrefix += ( mActiveTheme + "/" );
}
Example #3
0
void UIMachineViewNormal::normalizeGeometry(bool bAdjustPosition)
{
#ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1
    QWidget *pTopLevelWidget = window();

    /* Make no normalizeGeometry in case we are in manual resize mode or main window is maximized: */
    if (pTopLevelWidget->isMaximized())
        return;

    /* Calculate client window offsets: */
    QRect frameGeo = pTopLevelWidget->frameGeometry();
    QRect geo = pTopLevelWidget->geometry();
    int dl = geo.left() - frameGeo.left();
    int dt = geo.top() - frameGeo.top();
    int dr = frameGeo.right() - geo.right();
    int db = frameGeo.bottom() - geo.bottom();

    /* Get the best size w/o scroll bars: */
    QSize s = pTopLevelWidget->sizeHint();

    /* Resize the frame to fit the contents: */
    s -= pTopLevelWidget->size();
    frameGeo.setRight(frameGeo.right() + s.width());
    frameGeo.setBottom(frameGeo.bottom() + s.height());

    if (bAdjustPosition)
    {
        QRegion availableGeo;
        QDesktopWidget *dwt = QApplication::desktop();
        if (dwt->isVirtualDesktop())
            /* Compose complex available region */
            for (int i = 0; i < dwt->numScreens(); ++ i)
                availableGeo += dwt->availableGeometry(i);
        else
            /* Get just a simple available rectangle */
            availableGeo = dwt->availableGeometry(pTopLevelWidget->pos());

        frameGeo = VBoxGlobal::normalizeGeometry(frameGeo, availableGeo, vboxGlobal().vmRenderMode() != SDLMode /* can resize? */);
    }

#if 0
    /* Center the frame on the desktop: */
    frameGeo.moveCenter(availableGeo.center());
#endif

    /* Finally, set the frame geometry */
    pTopLevelWidget->setGeometry(frameGeo.left() + dl, frameGeo.top() + dt, frameGeo.width() - dl - dr, frameGeo.height() - dt - db);

#else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
    Q_UNUSED(bAdjustPosition);
#endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
}
void MediaSourceDesktop::getVideoDevices(VideoDevices &pVList)
{
    static bool tFirstCall = true;
    VideoDeviceDescriptor tDevice;

    #ifdef MSD_DEBUG_PACKETS
        tFirstCall = true;
    #endif

    if (tFirstCall)
        LOG(LOG_VERBOSE, "Enumerating hardware..");

    //#############################
    //### screen segment
    //#############################
    tDevice.Name = MEDIA_SOURCE_DESKTOP;
    tDevice.Card = "segment";
	#ifdef APPLE
    	tDevice.Desc = "OSX Cocoa based screen segment capturing";
	#else
		tDevice.Desc = "Qt based screen segment capturing";
	#endif
	if (tFirstCall)
        LOG(LOG_VERBOSE, "Found video device: %s (card: %s)", tDevice.Name.c_str(), tDevice.Card.c_str());
    pVList.push_back(tDevice);


    QDesktopWidget *tDesktop = QApplication::desktop();
    if (tDesktop != NULL)
    {
        if (tFirstCall)
        {
            LOG(LOG_VERBOSE, "Desktop found..");
            LOG(LOG_VERBOSE, "  ..resolution: %d * %d", tDesktop->width(), tDesktop->height());
            LOG(LOG_VERBOSE, "  ..screens: %d", tDesktop->numScreens());
            LOG(LOG_VERBOSE, "  ..virtualized: %d", tDesktop->isVirtualDesktop());
        }

        for (int i = 0; i < tDesktop->numScreens(); i++)
        {
            QWidget *tScreen = tDesktop->screen(i);
            if (tFirstCall)
            {
                LOG(LOG_VERBOSE, "  ..screen %d: resolution=%d*%d, available resolution=%d*%d, position=(%d, %d)", i, tDesktop->screenGeometry(i).width(), tDesktop->screenGeometry(i).height(), tDesktop->availableGeometry(i).width(), tDesktop->availableGeometry(i).height(), tDesktop->screenGeometry(i).x(), tDesktop->screenGeometry(i).y());
            }
        }
    }

    tFirstCall = false;
}
Example #5
0
QRect KGlobalSettings::desktopGeometry(const QPoint& point)
{
    QDesktopWidget *dw = QApplication::desktop();

    if (dw->isVirtualDesktop()) {
        KConfigGroup group(KGlobal::config(), "Windows");
        if (group.readBoolEntry("XineramaEnabled", true) &&
            group.readBoolEntry("XineramaPlacementEnabled", true)) {
            return dw->screenGeometry(dw->screenNumber(point));
        } else {
            return dw->geometry();
        }
    } else {
        return dw->geometry();
    }
}
void RegionGrabber::initGrabber()
{
  pixmap = QPixmap::grabWindow( qt_xrootwin() );
  setPaletteBackgroundPixmap( pixmap );

  QDesktopWidget desktopWidget;
  QRect desktopSize;
  if ( desktopWidget.isVirtualDesktop() )
    desktopSize = desktopWidget.geometry();
  else
    desktopSize = desktopWidget.screenGeometry( qt_xrootwin() );

  setGeometry( desktopSize );
  showFullScreen();

  QApplication::setOverrideCursor( crossCursor );
}
Example #7
0
QRect KGlobalSettings::splashScreenDesktopGeometry()
{
    QDesktopWidget *dw = QApplication::desktop();

    if (dw->isVirtualDesktop()) {
        KConfigGroup group(KGlobal::config(), "Windows");
        int scr = group.readNumEntry("Unmanaged", -3);
        if (group.readBoolEntry("XineramaEnabled", true) && scr != -2) {
            if (scr == -3)
                scr = dw->screenNumber(QCursor::pos());
            return dw->screenGeometry(scr);
        } else {
            return dw->geometry();
        }
    } else {
        return dw->geometry();
    }
}
Example #8
0
static QRect screenRect( QWidget *w, int screen )
{
  QDesktopWidget *desktop = QApplication::desktop();
  KConfig gc("kdeglobals", false, false);
  gc.setGroup("Windows");
  if (desktop->isVirtualDesktop() &&
      gc.readBoolEntry("XineramaEnabled", true) &&
      gc.readBoolEntry("XineramaPlacementEnabled", true)) {
    if ( screen < 0 || screen >= desktop->numScreens() ) {
      if ( screen == -1 ) {
        screen = desktop->primaryScreen();
      } else if ( screen == -3 ) {
        screen = desktop->screenNumber( QCursor::pos() );
      } else {
        screen = desktop->screenNumber( w );
      }
    }
    return desktop->availableGeometry(screen);
  } else {
    return desktop->geometry();
  }
}
Example #9
0
/*! \mainpage X11 Info for Razor-qt.
 * This tool allows to gather various useful X11/screen information.
 * Sometimes it would be useful to attach output of this command line
 * application to the bugreport.
 *
 * \note This program is not useful for end-users. It's a helper
 *       for Razor development.
 */
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    qDebug() << "Razor-qt (" << RAZOR_VERSION << ") environment summary\n";

#ifdef Q_WS_X11
    // collect QX11
    qDebug() << "* X11 Information";
    QX11Info x11;
    qDebug() << "X11 display:\t\t" << x11.display();
    qDebug() << "X11 colormap:\t\t" << x11.colormap();
    qDebug() << "X11 depth:\t\t" << x11.depth();
    qDebug() << "X11 composite:\t\t" << x11.isCompositingManagerRunning();
    qDebug() << "X11 ScreenCount:\t" << ScreenCount(QX11Info::display());
    qDebug() << "";
#endif

    qDebug() << "* QDesktopWidget Information";
    QDesktopWidget *dw = QApplication::desktop();
    qDebug() << "QD virtual desktop:\t" << dw->isVirtualDesktop();
    qDebug() << "QD primary screen:\t" << dw->primaryScreen();
    qDebug() << "QD screen count:\t" << dw->screenCount();
    qDebug() << "** QD screens";
    for (int i = 0; i < dw->screenCount(); ++i)
    {
        qDebug() << "\tScreen" << i << "availableGeometry:\t" << dw->availableGeometry(i);
        qDebug() << "\tScreen" << i << "screenGeometry:\t" << dw->screenGeometry(i);
        qDebug() << "";
    }
    
    qDebug() << "* XfitMan information";
    qDebug() << "getActiveDesktop:\t" << xfitMan().getActiveDesktop();
    qDebug() << "getNumDesktop:\t" << xfitMan().getNumDesktop();

    return 0;
}
Example #10
0
void CMainWindow::centerWindow()
{
    int screen = 0;
    QWidget *w = window();
    QDesktopWidget *desktop = QApplication::desktop();
    if (w) {
        screen = desktop->screenNumber(w);
    } else if (desktop->isVirtualDesktop()) {
        screen = desktop->screenNumber(QCursor::pos());
    } else {
        screen = desktop->screenNumber(this);
    }
    QRect rect(desktop->availableGeometry(screen));
        int h = 80*rect.height()/100;
    QSize nw(135*h/100,h);
    if (nw.width()<1000) nw.setWidth(80*rect.width()/100);
    resize(nw);
    move(rect.width()/2 - frameGeometry().width()/2,
         rect.height()/2 - frameGeometry().height()/2);

    QList<int> sz;
    sz << nw.width()/4 << 3*nw.width()/4;
    ui->splitter->setSizes(sz);
}
Example #11
0
// QListView does item layout in a very inflexible way, so let's do our custom layout again.
// FIXME: this is very inefficient, but due to the design flaw of QListView, this is currently the only workaround.
void DesktopWindow::relayoutItems() {
    displayNames_.clear();
    loadItemPositions(); // something may have changed
    // qDebug("relayoutItems()");
    if(relayoutTimer_) {
        // this slot might be called from the timer, so we cannot delete it directly here.
        relayoutTimer_->deleteLater();
        relayoutTimer_ = nullptr;
    }

    QDesktopWidget* desktop = qApp->desktop();
    int screen = 0;
    int row = 0;
    int rowCount = proxyModel_->rowCount();

    auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
    auto itemSize = delegate->itemSize();

    for(;;) {
        if(desktop->isVirtualDesktop()) {
            if(screen >= desktop->numScreens()) {
                break;
            }
        }
        else {
            screen = screenNum_;
        }
        QRect workArea = desktop->availableGeometry(screen);
        workArea.adjust(12, 12, -12, -12); // add a 12 pixel margin to the work area
        // qDebug() << "workArea" << screen <<  workArea;
        // FIXME: we use an internal class declared in a private header here, which is pretty bad.
        QPoint pos = workArea.topLeft();
        for(; row < rowCount; ++row) {
            QModelIndex index = proxyModel_->index(row, 0);
            int itemWidth = delegate->sizeHint(listView_->getViewOptions(), index).width();
            auto file = proxyModel_->fileInfoFromIndex(index);
            // remember display names of desktop entries and shortcuts
            if(file->isDesktopEntry() || file->isShortcut()) {
                displayNames_[index] = file->displayName();
            }
            auto name = file->name();
            auto find_it = customItemPos_.find(name);
            if(find_it != customItemPos_.cend()) { // the item has a custom position
                QPoint customPos = find_it->second;
                // center the contents vertically
                listView_->setPositionForIndex(customPos + QPoint((itemSize.width() - itemWidth) / 2, 0), index);
                // qDebug() << "set custom pos:" << name << row << index << customPos;
                continue;
            }
            // check if the current pos is alredy occupied by a custom item
            bool used = false;
            for(auto it = customItemPos_.cbegin(); it != customItemPos_.cend(); ++it) {
                QPoint customPos = it->second;
                if(QRect(customPos, itemSize).contains(pos)) {
                    used = true;
                    break;
                }
            }
            if(used) { // go to next pos
                --row;
            }
            else {
                // center the contents vertically
                listView_->setPositionForIndex(pos + QPoint((itemSize.width() - itemWidth) / 2, 0), index);
                // qDebug() << "set pos" << name << row << index << pos;
            }
            // move to next cell in the column
            pos.setY(pos.y() + itemSize.height() + listView_->spacing());
            if(pos.y() + itemSize.height() > workArea.bottom() + 1) {
                // if the next position may exceed the bottom of work area, go to the top of next column
                pos.setX(pos.x() + itemSize.width() + listView_->spacing());
                pos.setY(workArea.top());

                // check if the new column exceeds the right margin of work area
                if(pos.x() + itemSize.width() > workArea.right() + 1) {
                    if(desktop->isVirtualDesktop()) {
                        // in virtual desktop mode, go to next screen
                        ++screen;
                        break;
                    }
                }
            }
        }
        if(row >= rowCount) {
            break;
        }
    }

    if(!listView_->updatesEnabled()) {
        listView_->setUpdatesEnabled(true);
    }
}
Example #12
0
DesktopWindow::DesktopWindow(int screenNum):
    View(Fm::FolderView::IconMode),
    proxyModel_(nullptr),
    model_(nullptr),
    wallpaperMode_(WallpaperNone),
    slideShowInterval_(0),
    wallpaperTimer_(nullptr),
    wallpaperRandomize_(false),
    fileLauncher_(nullptr),
    showWmMenu_(false),
    screenNum_(screenNum),
    relayoutTimer_(nullptr) {

    QDesktopWidget* desktopWidget = QApplication::desktop();
    setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_X11NetWmWindowTypeDesktop);
    setAttribute(Qt::WA_DeleteOnClose);

    // set our custom file launcher
    View::setFileLauncher(&fileLauncher_);

    listView_ = static_cast<Fm::FolderViewListView*>(childView());
    listView_->setMovement(QListView::Snap);
    listView_->setResizeMode(QListView::Adjust);
    listView_->setFlow(QListView::TopToBottom);

    // This is to workaround Qt bug 54384 which affects Qt >= 5.6
    // https://bugreports.qt.io/browse/QTBUG-54384
    // Setting a QPixmap larger then the screen resolution to desktop's QPalette won't work.
    // So we make the viewport transparent by preventing its backround from being filled automatically.
    // Then we paint desktop's background ourselves by using its paint event handling method.
    listView_->viewport()->setAutoFillBackground(false);

    // NOTE: When XRnadR is in use, the all screens are actually combined to form a
    // large virtual desktop and only one DesktopWindow needs to be created and screenNum is -1.
    // In some older multihead setups, such as xinerama, every physical screen
    // is treated as a separate desktop so many instances of DesktopWindow may be created.
    // In this case we only want to show desktop icons on the primary screen.
    if(desktopWidget->isVirtualDesktop() || screenNum_ == desktopWidget->primaryScreen()) {
        loadItemPositions();
        Settings& settings = static_cast<Application* >(qApp)->settings();

        auto desktopPath = Fm::FilePath::fromLocalPath(XdgDir::readDesktopDir().toStdString().c_str());
        model_ = Fm::CachedFolderModel::modelFromPath(desktopPath);
        folder_ = model_->folder();

        proxyModel_ = new Fm::ProxyFolderModel();
        proxyModel_->setSourceModel(model_);
        proxyModel_->setShowThumbnails(settings.showThumbnails());
        proxyModel_->sort(settings.desktopSortColumn(), settings.desktopSortOrder());
        proxyModel_->setFolderFirst(settings.desktopSortFolderFirst());
        setModel(proxyModel_);

        connect(proxyModel_, &Fm::ProxyFolderModel::rowsInserted, this, &DesktopWindow::onRowsInserted);
        connect(proxyModel_, &Fm::ProxyFolderModel::rowsAboutToBeRemoved, this, &DesktopWindow::onRowsAboutToBeRemoved);
        connect(proxyModel_, &Fm::ProxyFolderModel::layoutChanged, this, &DesktopWindow::onLayoutChanged);
        connect(proxyModel_, &Fm::ProxyFolderModel::sortFilterChanged, this, &DesktopWindow::onModelSortFilterChanged);
        connect(proxyModel_, &Fm::ProxyFolderModel::dataChanged, this, &DesktopWindow::onDataChanged);
        connect(listView_, &QListView::indexesMoved, this, &DesktopWindow::onIndexesMoved);
    }

    // remove frame
    listView_->setFrameShape(QFrame::NoFrame);
    // inhibit scrollbars FIXME: this should be optional in the future
    listView_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    listView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    connect(this, &DesktopWindow::openDirRequested, this, &DesktopWindow::onOpenDirRequested);

    listView_->installEventFilter(this);
    listView_->viewport()->installEventFilter(this);

    // setup shortcuts
    QShortcut* shortcut;
    shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_X), this); // cut
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onCutActivated);

    shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C), this); // copy
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onCopyActivated);

    shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this); // paste
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onPasteActivated);

    shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A), this); // select all
    connect(shortcut, &QShortcut::activated, this, &FolderView::selectAll);

    shortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this); // delete
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onDeleteActivated);

    shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this); // rename
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onRenameActivated);

    shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F2), this); // bulk rename
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onBulkRenameActivated);

    shortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_Return), this); // properties
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onFilePropertiesActivated);

    shortcut = new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Delete), this); // force delete
    connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onDeleteActivated);
}
Example #13
0
/*
 * From koffice/libs/pigment/colorprofiles/KoLcmsColorProfileContainer.cpp
 * Copyright (C) 2000 Matthias Elter <*****@*****.**>
 *                2001 John Califf
 *                2004 Boudewijn Rempt <*****@*****.**>
 *  Copyright (C) 2007 Thomas Zander <*****@*****.**>
 *  Copyright (C) 2007 Adrian Page <*****@*****.**>IccProfile IccSettingsPriv::profileForScreen(QWidget *widget)
*/
IccProfile IccSettings::IccSettingsPriv::profileFromWindowSystem(QWidget* widget)
{
#ifdef Q_WS_X11

    Qt::HANDLE appRootWindow;
    QString atomName;

    QDesktopWidget* desktop = QApplication::desktop();
    int screenNumber        = desktop->screenNumber(widget);

    IccProfile profile;
    {
        QMutexLocker lock(&mutex);

        if (screenProfiles.contains(screenNumber))
        {
            return screenProfiles.value(screenNumber);
        }
    }

    if (desktop->isVirtualDesktop())
    {
        appRootWindow = QX11Info::appRootWindow(QX11Info::appScreen());
        atomName      = QString("_ICC_PROFILE_%1").arg(screenNumber);
    }
    else
    {
        appRootWindow = QX11Info::appRootWindow(screenNumber);
        atomName      = "_ICC_PROFILE";
    }

    Atom          type;
    int           format;
    unsigned long nitems;
    unsigned long bytes_after;
    quint8*       str;

    static Atom icc_atom = XInternAtom( QX11Info::display(), atomName.toLatin1(), True );

    if  ( icc_atom != None &&
          XGetWindowProperty(QX11Info::display(),
                             appRootWindow,
                             icc_atom,
                             0,
                             INT_MAX,
                             False,
                             XA_CARDINAL,
                             &type,
                             &format,
                             &nitems,
                             &bytes_after,
                             (unsigned char**) &str) == Success &&
          nitems
        )
    {
        QByteArray bytes = QByteArray::fromRawData((char*)str, (quint32)nitems);

        if (!bytes.isEmpty())
        {
            profile = bytes;
        }

        kDebug() << "Found X.org XICC monitor profile" << profile.description();
    }

    /*
        else
        {
            kDebug() << "No X.org XICC profile installed for screen" << screenNumber;
        }
    */
    // insert to cache even if null
    {
        QMutexLocker lock(&mutex);
        screenProfiles.insert(screenNumber, profile);
    }
    return profile;

#elif defined Q_WS_WIN
    //TODO
#elif defined Q_WS_MAC
    //TODO
#endif

    return IccProfile();
}
Example #14
0
// QListView does item layout in a very inflexible way, so let's do our custom layout again.
// FIXME: this is very inefficient, but due to the design flaw of QListView, this is currently the only workaround.
void DesktopWindow::relayoutItems() {
  loadItemPositions(); // something may have changed
  // qDebug("relayoutItems()");
  if(relayoutTimer_) {
    // this slot might be called from the timer, so we cannot delete it directly here.
    relayoutTimer_->deleteLater();
    relayoutTimer_ = NULL;
  }

  QDesktopWidget* desktop = qApp->desktop();
  int screen = 0;
  int row = 0;
  int rowCount = proxyModel_->rowCount();
  for(;;) {
    if(desktop->isVirtualDesktop()) {
      if(screen >= desktop->numScreens())
        break;
    }else {
      screen = screenNum_;
    }
    QRect workArea = desktop->availableGeometry(screen);
    workArea.adjust(12, 12, -12, -12); // add a 12 pixel margin to the work area
    // qDebug() << "workArea" << screen <<  workArea;
    // FIXME: we use an internal class declared in a private header here, which is pretty bad.
    QSize grid = listView_->gridSize();
    QPoint pos = workArea.topLeft();
    for(; row < rowCount; ++row) {
      QModelIndex index = proxyModel_->index(row, 0);
      int itemWidth = delegate_->sizeHint(listView_->getViewOptions(), index).width();
      FmFileInfo* file = proxyModel_->fileInfoFromIndex(index);
      QByteArray name = fm_file_info_get_name(file);
      QHash<QByteArray, QPoint>::iterator it = customItemPos_.find(name);
      if(it != customItemPos_.end()) { // the item has a custom position
        QPoint customPos = *it;
        // center the contents vertically
        listView_->setPositionForIndex(customPos + QPoint((grid.width() - itemWidth) / 2, 0), index);
        // qDebug() << "set custom pos:" << name << row << index << customPos;
        continue;
      }
      // check if the current pos is alredy occupied by a custom item
      bool used = false;
      for(it = customItemPos_.begin(); it != customItemPos_.end(); ++it) {
        QPoint customPos = *it;
        if(QRect(customPos, grid).contains(pos)) {
          used = true;
          break;
        }
      }
      if(used) { // go to next pos
        --row;
      }
      else {
        // center the contents vertically
        listView_->setPositionForIndex(pos + QPoint((grid.width() - itemWidth) / 2, 0), index);
        // qDebug() << "set pos" << name << row << index << pos;
      }
      // move to next cell in the column
      pos.setY(pos.y() + grid.height() + listView_->spacing());
      if(pos.y() + grid.height() > workArea.bottom() + 1) {
        // if the next position may exceed the bottom of work area, go to the top of next column
        pos.setX(pos.x() + grid.width() + listView_->spacing());
        pos.setY(workArea.top());

        // check if the new column exceeds the right margin of work area
        if(pos.x() + grid.width() > workArea.right() + 1) {
          if(desktop->isVirtualDesktop()) {
            // in virtual desktop mode, go to next screen
            ++screen;
            break;
          }
        }
      }
    }
    if(row >= rowCount)
      break;
  }
}
Example #15
0
DesktopWindow::DesktopWindow(int screenNum):
  View(Fm::FolderView::IconMode),
  proxyModel_(NULL),
  model_(NULL),
  folder_(NULL),
  wallpaperMode_(WallpaperNone),
  fileLauncher_(NULL),
  showWmMenu_(false),
  screenNum_(screenNum),
  relayoutTimer_(NULL) {

  QDesktopWidget* desktopWidget = QApplication::desktop();
  setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
  setAttribute(Qt::WA_X11NetWmWindowTypeDesktop);
  setAttribute(Qt::WA_DeleteOnClose);

  // set our custom file launcher
  View::setFileLauncher(&fileLauncher_);

  listView_ = static_cast<Fm::FolderViewListView*>(childView());
  listView_->setMovement(QListView::Snap);
  listView_->setResizeMode(QListView::Adjust);
  listView_->setFlow(QListView::TopToBottom);

  // NOTE: When XRnadR is in use, the all screens are actually combined to form a
  // large virtual desktop and only one DesktopWindow needs to be created and screenNum is -1.
  // In some older multihead setups, such as xinerama, every physical screen
  // is treated as a separate desktop so many instances of DesktopWindow may be created.
  // In this case we only want to show desktop icons on the primary screen.
  if(desktopWidget->isVirtualDesktop() || screenNum_ == desktopWidget->primaryScreen()) {
    loadItemPositions();
    Settings& settings = static_cast<Application* >(qApp)->settings();

    model_ = Fm::CachedFolderModel::modelFromPath(fm_path_get_desktop());
    folder_ = reinterpret_cast<FmFolder*>(g_object_ref(model_->folder()));

    proxyModel_ = new Fm::ProxyFolderModel();
    proxyModel_->setSourceModel(model_);
    proxyModel_->setShowThumbnails(settings.showThumbnails());
    proxyModel_->sort(settings.desktopSortColumn(), settings.desktopSortOrder());
    proxyModel_->setFolderFirst(settings.desktopSortFolderFirst());
    setModel(proxyModel_);

    connect(proxyModel_, &Fm::ProxyFolderModel::rowsInserted, this, &DesktopWindow::onRowsInserted);
    connect(proxyModel_, &Fm::ProxyFolderModel::rowsAboutToBeRemoved, this, &DesktopWindow::onRowsAboutToBeRemoved);
    connect(proxyModel_, &Fm::ProxyFolderModel::layoutChanged, this, &DesktopWindow::onLayoutChanged);
    connect(proxyModel_, &Fm::ProxyFolderModel::sortFilterChanged, this, &DesktopWindow::onModelSortFilterChanged);
    connect(listView_, &QListView::indexesMoved, this, &DesktopWindow::onIndexesMoved);
  }

  // set our own delegate
  delegate_ = new DesktopItemDelegate(listView_);
  listView_->setItemDelegateForColumn(Fm::FolderModel::ColumnFileName, delegate_);

  // remove frame
  listView_->setFrameShape(QFrame::NoFrame);
  // inhibit scrollbars FIXME: this should be optional in the future
  listView_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  listView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

  connect(this, &DesktopWindow::openDirRequested, this, &DesktopWindow::onOpenDirRequested);

  listView_->installEventFilter(this);

  // setup shortcuts
  QShortcut* shortcut;
  shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_X), this); // cut
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onCutActivated);

  shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C), this); // copy
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onCopyActivated);

  shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this); // paste
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onPasteActivated);

  shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A), this); // select all
  connect(shortcut, &QShortcut::activated, listView_, &QListView::selectAll);

  shortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this); // delete
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onDeleteActivated);

  shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this); // rename
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onRenameActivated);

  shortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_Return), this); // rename
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onFilePropertiesActivated);

  shortcut = new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Delete), this); // force delete
  connect(shortcut, &QShortcut::activated, this, &DesktopWindow::onDeleteActivated);
}
Example #16
0
const QRect XfitMan::availableGeometry(int screen) const
{
    QDesktopWidget *d = QApplication::desktop();

    if (screen < 0 || screen >= d->screenCount())
        screen = d->primaryScreen();

    QRect available = d->screenGeometry(screen);

    // Iterate over all the client windows and subtract from the available
    // area the space they reserved on the edges (struts).
    // Note: _NET_WORKAREA is not reliable as it exposes only one
    // rectangular area spanning all screens.
    Display *display = QX11Info::display();
    int x11Screen = d->isVirtualDesktop() ? DefaultScreen(display) : screen;

    Atom ret;
    int format, status;
    uchar* data = 0;
    ulong nitems, after;

    status = XGetWindowProperty(display, QX11Info::appRootWindow(x11Screen),
                                atom("_NET_CLIENT_LIST"), 0L, ~0L, False, XA_WINDOW,
                                &ret, &format, &nitems, &after, &data);

    if (status == Success && ret == XA_WINDOW && format == 32 && nitems)
    {
        const QRect desktopGeometry = d->rect();

        Window* xids = (Window*) data;
        for (quint32 i = 0; i < nitems; ++i)
        {
            ulong nitems2;
            uchar* data2 = 0;
            status = XGetWindowProperty(display, xids[i],
                                        atom("_NET_WM_STRUT_PARTIAL"), 0, 12, False, XA_CARDINAL,
                                        &ret, &format, &nitems2, &after, &data2);

            if (status == Success && ret == XA_CARDINAL && format == 32 && nitems2 == 12)
            {
                ulong* struts = (ulong*) data2;

                QRect left(desktopGeometry.x(),
                           desktopGeometry.y() + struts[4],
                           struts[0],
                           struts[5] - struts[4]);
                if (available.intersects(left))
                    available.setX(left.width());

                QRect right(desktopGeometry.x() + desktopGeometry.width() - struts[1],
                            desktopGeometry.y() + struts[6],
                            struts[1],
                            struts[7] - struts[6]);
                if (available.intersects(right))
                    available.setWidth(right.x() - available.x());

                QRect top(desktopGeometry.x() + struts[8],
                          desktopGeometry.y(),
                          struts[9] - struts[8],
                          struts[2]);
                if (available.intersects(top))
                    available.setY(top.height());

                QRect bottom(desktopGeometry.x() + struts[10],
                             desktopGeometry.y() + desktopGeometry.height() - struts[3],
                             struts[11] - struts[10],
                             struts[3]);
                if (available.intersects(bottom))
                    available.setHeight(bottom.y() - available.y());
            }
            if (data2)
                XFree(data2);
        }
    }
    if (data)
        XFree(data);

    return available;
}
Example #17
0
bool KXKBApp::settingsRead()
{
    kxkbConfig.load(KxkbConfig::LOAD_ACTIVE_OPTIONS);

    if(kxkbConfig.m_enableXkbOptions)
    {
        kdDebug() << "Setting XKB options " << kxkbConfig.m_options << endl;
        if(!m_extension->setXkbOptions(kxkbConfig.m_options, kxkbConfig.m_resetOldOptions))
        {
            kdDebug() << "Setting XKB options failed!" << endl;
        }
    }

    if(kxkbConfig.m_useKxkb == false)
    {
        kapp->quit();
        return false;
    }

    m_prevWinId = X11Helper::UNKNOWN_WINDOW_ID;

    if(kxkbConfig.m_switchingPolicy == SWITCH_POLICY_GLOBAL)
    {
        delete kWinModule;
        kWinModule = NULL;
    }
    else
    {
        QDesktopWidget desktopWidget;
        if(desktopWidget.numScreens() > 1 && desktopWidget.isVirtualDesktop() == false)
        {
            kdWarning() << "With non-virtual desktop only global switching policy supported on non-primary screens" << endl;
            // TODO: find out how to handle that
        }

        if(kWinModule == NULL)
        {
            kWinModule = new KWinModule(0, KWinModule::INFO_DESKTOP);
            connect(kWinModule, SIGNAL(activeWindowChanged(WId)), SLOT(windowChanged(WId)));
        }
        m_prevWinId = kWinModule->activeWindow();
        kdDebug() << "Active window " << m_prevWinId << endl;
    }

    m_layoutOwnerMap->reset();
    m_layoutOwnerMap->setCurrentWindow(m_prevWinId);

    if(m_rules == NULL)
        m_rules = new XkbRules(false);

    for(int ii = 0; ii < (int)kxkbConfig.m_layouts.count(); ii++)
    {
        LayoutUnit &layoutUnit = kxkbConfig.m_layouts[ii];
        layoutUnit.defaultGroup = m_rules->getDefaultGroup(layoutUnit.layout, layoutUnit.includeGroup);
        kdDebug() << "default group for " << layoutUnit.toPair() << " is " << layoutUnit.defaultGroup << endl;
    }

    m_currentLayout = kxkbConfig.getDefaultLayout();

    if(kxkbConfig.m_layouts.count() == 1)
    {
        QString layoutName = m_currentLayout.layout;
        QString variantName = m_currentLayout.variant;
        QString includeName = m_currentLayout.includeGroup;
        int group = m_currentLayout.defaultGroup;

        if(!m_extension->setLayout(kxkbConfig.m_model, layoutName, variantName, includeName, false) || !m_extension->setGroup(group))
        {
            kdDebug() << "Error switching to single layout " << m_currentLayout.toPair() << endl;
            // TODO: alert user
        }

        if(kxkbConfig.m_showSingle == false)
        {
            kapp->quit();
            return false;
        }
    }
    else
    {
        //		initPrecompiledLayouts();
    }

    initTray();

    KGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals
    keys->readSettings();
    keys->updateConnections();

    return true;
}