예제 #1
0
static
QPixmap grabWindow( HWND hWnd, QString *title=0, QString *windowClass=0 )
{
    RECT windowRect;
    GetWindowRect(hWnd, &windowRect);
    int w = windowRect.right - windowRect.left;
    int h = windowRect.bottom - windowRect.top;
    HDC targetDC = GetWindowDC(hWnd);
    HDC hDC = CreateCompatibleDC(targetDC);
    HBITMAP tempPict = CreateCompatibleBitmap(targetDC, w, h);
    HGDIOBJ oldPict = SelectObject(hDC, tempPict);
    BitBlt(hDC, 0, 0, w, h, targetDC, 0, 0, SRCCOPY);
    tempPict = (HBITMAP) SelectObject(hDC, oldPict);
    QPixmap pm = QPixmap::fromWinHBITMAP(tempPict);

    DeleteDC(hDC);
    ReleaseDC(hWnd, targetDC);

    KWindowInfo winInfo( findRealWindow(hWnd), NET::WMVisibleName, NET::WM2WindowClass );
    if ( title ) {
        (*title) = winInfo.visibleName();
    }

    if ( windowClass ) {
        (*windowClass) = winInfo.windowClassName();
    }
    return pm;
}
예제 #2
0
void servercontroller::saveSessionConfig()
{
    QDictIterator<KSircProcess> ksp(proc_list);
    for (; ksp.current(); ++ksp ) {
	ChannelSessionInfoList channels;

	QDictIterator<KSircMessageReceiver> ksm(ksp.current()->getWindowList());
	for (; ksm.current(); ++ksm )
	    if(ksm.currentKey()[0] != '!') { // Ignore !ksm's (system created)
		ChannelSessionInfo sessionInfo;

		sessionInfo.name = ksm.currentKey();
		sessionInfo.port = ksp.current()->serverPort();
		KSircTopLevel *topLev = dynamic_cast<KSircTopLevel *>( ksm.current() );
		if ( topLev && topLev->isTopLevel() ) {
#ifdef Q_WS_X11
		    NETWinInfo winInfo( qt_xdisplay(), topLev->winId(), qt_xrootwin(), NET::WMDesktop );
		    sessionInfo.desktop = winInfo.desktop();
#endif
		}

		channels << sessionInfo;
	    }

	if ( !channels.isEmpty() )
	    m_sessionConfig[ ksp.currentKey() ] = channels;
    }
}
예제 #3
0
// Disconnect client from server and record winner status for him and his
// opponent, if there was a game between'em
void Server::disconnectClientAndRecord(
    ClientsIterator client,
    bool winnerStatus
)
{
    if( client == clients_.end() )
        return;

    if(
        client->status == Client::ST_MAKING_STEP ||
        client->status == Client::ST_WAITING_STEP
    )
    {
        Client& winner = winnerStatus
            ? client.value()
            : client->playingWith.value();
        Client& looser = !winnerStatus
            ? client.value()
            : client->playingWith.value();

        recordSessionStatistic(
            winner.login,
            looser.login
        );

        PlayerStats stat = stats_.getStat(winner.login);
        QString winInfo("win: winRate: ");
        winInfo.append(QString::number(stat.roundsWon));
        winInfo.append(" loseRate: ");
        winInfo.append(QString::number(stat.roundsLost));

        stat = stats_.getStat(looser.login);
        QString loseInfo("lose: winRate: ");
        loseInfo.append(QString::number(stat.roundsWon));
        loseInfo.append(" loseRate: ");
        loseInfo.append(QString::number(stat.roundsLost));

        winner.send(winInfo);
        looser.send(loseInfo);
    }

    if( client->playingWith != clients_.end() )
        disconnectClient( client->playingWith );

    disconnectClient( client );
}
예제 #4
0
static
QPixmap grabWindow( Window child, int x, int y, uint w, uint h, uint border,
            QString *title=0, QString *windowClass=0 )
{
    QPixmap pm( QPixmap::grabWindow( QX11Info::appRootWindow(), x, y, w, h ) );

    KWindowInfo winInfo( findRealWindow(child), NET::WMVisibleName, NET::WM2WindowClass );

    if ( title ) {
        (*title) = winInfo.visibleName();
    }

    if ( windowClass ) {
        (*windowClass) = winInfo.windowClassName();
    }

#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
    int tmp1, tmp2;
    //Check whether the extension is available
    if ( XShapeQueryExtension( QX11Info::display(), &tmp1, &tmp2 ) ) {
    QBitmap mask( w, h );
    //As the first step, get the mask from XShape.
    int count, order;
    XRectangle* rects = XShapeGetRectangles( QX11Info::display(), child,
                         ShapeBounding, &count, &order );
    //The ShapeBounding region is the outermost shape of the window;
    //ShapeBounding - ShapeClipping is defined to be the border.
    //Since the border area is part of the window, we use bounding
    // to limit our work region
    if (rects) {
        //Create a QRegion from the rectangles describing the bounding mask.
        QRegion contents;
        for ( int pos = 0; pos < count; pos++ )
        contents += QRegion( rects[pos].x, rects[pos].y,
                     rects[pos].width, rects[pos].height );
        XFree( rects );

        //Create the bounding box.
        QRegion bbox( 0, 0, w, h );

        if( border > 0 ) {
            contents.translate( border, border );
            contents += QRegion( 0, 0, border, h );
            contents += QRegion( 0, 0, w, border );
            contents += QRegion( 0, h - border, w, border );
            contents += QRegion( w - border, 0, border, h );
        }

        //Get the masked away area.
        QRegion maskedAway = bbox - contents;
        QVector<QRect> maskedAwayRects = maskedAway.rects();

        //Construct a bitmap mask from the rectangles
        QPainter p(&mask);
        p.fillRect(0, 0, w, h, Qt::color1);
        for (int pos = 0; pos < maskedAwayRects.count(); pos++)
            p.fillRect(maskedAwayRects[pos], Qt::color0);
        p.end();

        pm.setMask(mask);
    }
    }
#endif // HAVE_X11_EXTENSIONS_SHAPE_H

    return pm;
}
예제 #5
0
void servercontroller::readGlobalProperties(KConfig *ksc)
{
    QString group = ksc->group();

    // ksc == K Session Config

    // KMainWindow silently disables our menubar, when we quit in a docked
    // state, so we have to force showing it here.
    menuBar()->show();

    // commented in for testing...
    ksc->setGroup( "KSircSession" );
    QMap<QString,QString> keyMap = ksc->entryMap( ksc->group() );
    QMap<QString,QString>::Iterator it = keyMap.begin();

    while(it != keyMap.end()) {
	QString server = it.key();
	QString port = KConfigGroup( ksc, "KSircSessionPort" ).readEntry( server );
	//	debug("%s", it.key().latin1());
        KSircServer kss(server, port);
	new_ksircprocess( kss ); // sets up proc_list
	QStringList channels = ksc->readListEntry( server );

	QStringList desktops = KConfigGroup( ksc, "KSircSessionDesktopNumbers" ).readListEntry( server );

	for(uint i = 0; i < channels.count(); i++){

	    QString channel = channels[ i ];

	    proc_list[ server ]->new_toplevel( KSircChannel(server, channel), true );

	    KSircTopLevel *topLevel = dynamic_cast<KSircTopLevel *>( proc_list[ server ]->getWindowList()[ channel ] );
	    if ( !topLevel || !topLevel->isTopLevel() )
		continue;

	    QStringList::ConstIterator desktopNumberIt = desktops.at( i );
	    if ( desktopNumberIt == desktops.end() )
		continue;

	    int desktop = ( *desktopNumberIt ).toInt();
	    if ( desktop == -1 )
		continue;
#ifdef Q_WS_X11
	    NETWinInfo winInfo( qt_xdisplay(), topLevel->winId(), qt_xrootwin(), NET::WMDesktop );
	    winInfo.setDesktop( desktop );
#endif
	}
	++it;
    }

    QRect geom;

//    ksc->setGroup("ServerController");
//    bool docked = ksc->readBoolEntry("Docked", FALSE);
//    if ( !docked )
    //      show();
    if(ksopts->runDocked == false)
        show();

    geom = ksc->readRectEntry("Size");
    if(! geom.isEmpty())
    	setGeometry(geom);

    ksc->setGroup(group);
}