diff options
Diffstat (limited to 'kpager')
-rw-r--r-- | kpager/Makefile.am | 22 | ||||
-rw-r--r-- | kpager/TODO | 1 | ||||
-rw-r--r-- | kpager/config.cpp | 180 | ||||
-rw-r--r-- | kpager/config.h | 78 | ||||
-rw-r--r-- | kpager/desktop.cpp | 688 | ||||
-rw-r--r-- | kpager/desktop.h | 130 | ||||
-rw-r--r-- | kpager/hi16-app-kpager.png | bin | 0 -> 288 bytes | |||
-rw-r--r-- | kpager/hi22-app-kpager.png | bin | 0 -> 1059 bytes | |||
-rw-r--r-- | kpager/hi32-app-kpager.png | bin | 0 -> 784 bytes | |||
-rw-r--r-- | kpager/hi48-app-kpager.png | bin | 0 -> 1081 bytes | |||
-rw-r--r-- | kpager/kpager.cpp | 674 | ||||
-rw-r--r-- | kpager/kpager.desktop | 106 | ||||
-rw-r--r-- | kpager/kpager.h | 139 | ||||
-rw-r--r-- | kpager/kpagerIface.h | 22 | ||||
-rw-r--r-- | kpager/main.cpp | 107 | ||||
-rw-r--r-- | kpager/uninstall.desktop | 2 | ||||
-rw-r--r-- | kpager/windowdrag.cpp | 60 | ||||
-rw-r--r-- | kpager/windowdrag.h | 41 |
18 files changed, 2250 insertions, 0 deletions
diff --git a/kpager/Makefile.am b/kpager/Makefile.am new file mode 100644 index 000000000..d33d8852e --- /dev/null +++ b/kpager/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES= $(all_includes) + +bin_PROGRAMS = kpager + +kpager_SOURCES = desktop.cpp kpager.cpp config.cpp windowdrag.cpp \ + kpagerIface.skel main.cpp + +kpager_METASOURCES = AUTO +kpager_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +kpager_LDADD = $(LIB_KDEUI) + +KDE_ICON = kpager + +xdg_apps_DATA = kpager.desktop + +install-data-local: uninstall.desktop + $(mkinstalldirs) $(DESTDIR)$(kde_appsdir)/Utilities + $(INSTALL_DATA) $(srcdir)/uninstall.desktop $(DESTDIR)$(kde_appsdir)/Utilities/kpager.desktop + +messages: + $(XGETTEXT) *.cpp *.h -o $(podir)/kpager.pot diff --git a/kpager/TODO b/kpager/TODO new file mode 100644 index 000000000..9794e7fc1 --- /dev/null +++ b/kpager/TODO @@ -0,0 +1 @@ +Mantain the aspect ratio diff --git a/kpager/config.cpp b/kpager/config.cpp new file mode 100644 index 000000000..60aa85f2a --- /dev/null +++ b/kpager/config.cpp @@ -0,0 +1,180 @@ +/************************************************************************** + + config.cpp - KPager config dialog + Copyright (C) 2000 Antonio Larrosa Jimenez + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ + +#include <qcheckbox.h> +#include <qradiobutton.h> +#include <qbuttongroup.h> +#include <qwidget.h> +#include <qvbox.h> +#include <qhbox.h> +#include <qlayout.h> + +#include <kdialogbase.h> +#include <klocale.h> +#include <kconfig.h> +#include <kseparator.h> +#include <kapplication.h> +#include <kdebug.h> + +#include "config.h" +#include "config.moc" +#include "desktop.h" +#include "kpager.h" + + +KPagerConfigDialog::KPagerConfigDialog (QWidget *parent) + : KDialogBase ( parent, "configdialog", true, i18n("Configuration"), Ok|Cancel, Ok, true ) +{ + QVBox *box = new QVBox( this ); + m_chkWindowDragging=new QCheckBox(i18n("Enable window dragging"),box,0); + (void ) new KSeparator( box ); + connect(m_chkWindowDragging, SIGNAL(toggled(bool)), this, SLOT(enableWindowDragging(bool))); + + QHBox *page = new QHBox( box ); + QVBox *lpage = new QVBox( page ); + setMainWidget(box); + + m_chkShowName=new QCheckBox(i18n("Show name"),lpage,0); + connect(m_chkShowName, SIGNAL(toggled(bool)), this, SLOT(setShowName(bool))); + m_chkShowNumber=new QCheckBox(i18n("Show number"),lpage,0); + connect(m_chkShowNumber, SIGNAL(toggled(bool)), this, SLOT(setShowNumber(bool))); + m_chkShowBackground=new QCheckBox(i18n("Show background"),lpage,0); + connect(m_chkShowBackground, SIGNAL(toggled(bool)), this, SLOT(setShowBackground(bool))); + m_chkShowWindows=new QCheckBox(i18n("Show windows"),lpage,0); + connect(m_chkShowWindows, SIGNAL(toggled(bool)), this, SLOT(setShowWindows(bool))); + + m_grpWindowDrawMode=new QButtonGroup(i18n("Type of Window"),page); + m_grpWindowDrawMode->setExclusive(true); + QVBoxLayout *vbox = new QVBoxLayout(m_grpWindowDrawMode, KDialog::marginHint(), + KDialog::spacingHint()); + vbox->addSpacing(fontMetrics().lineSpacing()); + vbox->addWidget(new QRadioButton(i18n("Plain"),m_grpWindowDrawMode)); + vbox->addWidget(new QRadioButton(i18n("Icon"),m_grpWindowDrawMode)); + + QRadioButton *rbpix = new QRadioButton(i18n("Pixmap"),m_grpWindowDrawMode); +// rbpix->setEnabled(false); + vbox->addWidget(rbpix); + + connect(m_grpWindowDrawMode, SIGNAL(clicked(int)), this, SLOT(setWindowDrawMode(int))); + + m_grpLayoutType=new QButtonGroup(i18n("Layout"),page); + m_grpLayoutType->setExclusive(true); + vbox = new QVBoxLayout(m_grpLayoutType, KDialog::marginHint(), KDialog::spacingHint()); + vbox->addSpacing(fontMetrics().lineSpacing()); + vbox->addWidget(new QRadioButton(i18n("Classical"),m_grpLayoutType)); + vbox->addWidget(new QRadioButton(i18n("Horizontal"),m_grpLayoutType)); + vbox->addWidget(new QRadioButton(i18n("Vertical"),m_grpLayoutType)); + + connect(m_grpLayoutType, SIGNAL(clicked(int)), this, SLOT(setLayout(int))); + connect(this,SIGNAL(okClicked()),this,SLOT(slotOk())); + loadConfiguration(); + setMinimumSize(360, 160); +} + +void KPagerConfigDialog::setShowName(bool show) +{ + m_tmpShowName=show; +} + +void KPagerConfigDialog::setShowNumber(bool show) +{ + m_tmpShowNumber=show; +} + +void KPagerConfigDialog::setShowBackground(bool show) +{ + m_tmpShowBackground=show; +} + +void KPagerConfigDialog::setShowWindows(bool show) +{ + m_tmpShowWindows=show; +} + +void KPagerConfigDialog::enableWindowDragging(bool enable) +{ + m_tmpWindowDragging = enable; +} + +void KPagerConfigDialog::setWindowDrawMode(int type) +{ + m_tmpWindowDrawMode=type; +} + +void KPagerConfigDialog::setLayout(int layout) +{ + m_tmpLayoutType=layout; +} + +void KPagerConfigDialog::loadConfiguration() +{ + m_chkShowName->setChecked(m_showName); + m_chkShowNumber->setChecked(m_showNumber); + m_chkShowBackground->setChecked(m_showBackground); + m_chkShowWindows->setChecked(m_showWindows); + m_grpWindowDrawMode->setButton(m_windowDrawMode); + m_grpLayoutType->setButton(m_layoutType); + m_chkWindowDragging->setChecked( m_windowDragging ); + m_tmpShowName=m_showName; + m_tmpShowNumber=m_showNumber; + m_tmpShowBackground=m_showBackground; + m_tmpShowWindows=m_showWindows; + m_tmpWindowDrawMode=m_windowDrawMode; + m_tmpLayoutType=m_layoutType; + m_tmpWindowDragging=m_windowDragging; +} + +void KPagerConfigDialog::initConfiguration(void) +{ + KConfig *cfg= kapp->config(); + cfg->setGroup("KPager"); + + m_windowDrawMode=cfg->readNumEntry("windowDrawMode", Desktop::c_defWindowDrawMode); + m_showName=cfg->readBoolEntry("showName", Desktop::c_defShowName); + m_showNumber=cfg->readBoolEntry("showNumber", Desktop::c_defShowNumber); + m_showBackground=cfg->readBoolEntry("showBackground", Desktop::c_defShowBackground); + m_showWindows=cfg->readBoolEntry("showWindows", Desktop::c_defShowWindows); + m_layoutType=cfg->readNumEntry("layoutType", KPager::c_defLayout); + m_windowDragging=cfg->readBoolEntry("windowDragging", true ); +} + +void KPagerConfigDialog::slotOk() +{ + m_showName=m_tmpShowName; + m_showNumber=m_tmpShowNumber; + m_showBackground=m_tmpShowBackground; + m_showWindows=m_tmpShowWindows; + m_windowDrawMode=m_tmpWindowDrawMode; + m_layoutType=m_tmpLayoutType; + m_windowDragging=m_tmpWindowDragging; + accept(); +} + +bool KPagerConfigDialog::m_showName=Desktop::c_defShowName; +bool KPagerConfigDialog::m_showNumber=Desktop::c_defShowNumber; +bool KPagerConfigDialog::m_showBackground=Desktop::c_defShowBackground; +bool KPagerConfigDialog::m_showWindows=Desktop::c_defShowWindows; +bool KPagerConfigDialog::m_windowDragging=Desktop::c_defWindowDragging; +int KPagerConfigDialog::m_windowDrawMode=Desktop::c_defWindowDrawMode; +int KPagerConfigDialog::m_layoutType=KPager::c_defLayout; + diff --git a/kpager/config.h b/kpager/config.h new file mode 100644 index 000000000..153e025f9 --- /dev/null +++ b/kpager/config.h @@ -0,0 +1,78 @@ +/************************************************************************** + + config.h - KPager config dialog + Copyright (C) 2000 Antonio Larrosa Jimenez + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ +#ifndef __KPCONFIG_H +#define __KPCONFIG_H + +#include <kdialogbase.h> + +class QCheckBox; +class QButtonGroup; + +class KPagerConfigDialog : public KDialogBase +{ + Q_OBJECT + +public: + KPagerConfigDialog(QWidget *parent); + +public slots: + void setShowName(bool show); + void setShowNumber(bool show); + void setShowBackground(bool show); + void setShowWindows(bool show); + + void setWindowDrawMode(int mode); + void setLayout(int layout); + + void enableWindowDragging(bool); + + void loadConfiguration(); + void slotOk(); +public: + static void initConfiguration(void); + static bool m_showName; + static bool m_showNumber; + static bool m_showBackground; + static bool m_showWindows; + static int m_windowDrawMode; + static int m_layoutType; + static bool m_windowDragging; + +protected: + QCheckBox *m_chkShowName; + QCheckBox *m_chkShowNumber; + QCheckBox *m_chkShowBackground; + QCheckBox *m_chkShowWindows; + QButtonGroup *m_grpWindowDrawMode; + QButtonGroup *m_grpLayoutType; + QCheckBox* m_chkWindowDragging; + bool m_tmpShowName; + bool m_tmpShowNumber; + bool m_tmpShowBackground; + bool m_tmpShowWindows; + int m_tmpWindowDrawMode; + int m_tmpLayoutType; + bool m_tmpWindowDragging; +}; + +#endif diff --git a/kpager/desktop.cpp b/kpager/desktop.cpp new file mode 100644 index 000000000..1ecfcca43 --- /dev/null +++ b/kpager/desktop.cpp @@ -0,0 +1,688 @@ +/************************************************************************** + + desktop.cpp - KPager's desktop + Copyright (C) 2000 Antonio Larrosa Jimenez + Matthias Ettrich + Matthias Elter + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ + +#include "kpager.h" + +#include <dcopobject.h> +#include <dcopclient.h> +#include <kdatastream.h> +#include <kapplication.h> +#include <kglobalsettings.h> +#include <kwinmodule.h> +#include <kwin.h> +#include <kconfig.h> +#include <kglobal.h> +#include <kdebug.h> +#include <ksharedpixmap.h> +#include <kpixmapio.h> +#include <kpopupmenu.h> +#include <netwm.h> +#include <qcstring.h> +#include <qpixmap.h> +#include <qpainter.h> +#include <qdrawutil.h> +#include <qpoint.h> + +#include "desktop.h" +#include "config.h" +#include "windowdrag.h" + +Desktop::Desktop( int desk, QString desktopName, QWidget *parent, const char *name): QWidget(parent,name) +{ + m_desk = desk; + m_name = desktopName; + m_bgSmallPixmap=0L; + m_bgCommonSmallPixmap=0L; + m_bgPixmap = 0L; + m_bgDirty=true; + m_grabWindows=false; + setAcceptDrops(TRUE); + setBackgroundMode(NoBackground); + + if (m_desk==1) Desktop::m_windowPixmaps.setAutoDelete(true); + KConfig *cfg= KGlobal::config(); + m_transparentMode=static_cast<WindowTransparentMode> + (cfg->readNumEntry("windowTransparentMode", c_defWindowTransparentMode)); + resize(67, 50); +} + +Desktop::~Desktop() +{ + delete m_bgPixmap; + delete m_bgSmallPixmap; +} + +void Desktop::mouseMoveEvent( QMouseEvent *ev ) +{ + if ( !KPagerConfigDialog::m_windowDragging ) + return; + if ( (ev->state() & LeftButton) == 0 ) + return; + QPoint p( ev->pos() - pressPos ); + if ( p.manhattanLength() >= qApp->startDragDistance() ) + startDrag( pressPos ); +} + +void Desktop::mousePressEvent( QMouseEvent * ev) +{ + bool showWindows= KPagerConfigDialog::m_showWindows; + if (ev->button()==LeftButton){ + pressPos = ev->pos(); + } + else if ((ev->button()==MidButton)&&(showWindows)) + startDrag(ev->pos()); + else if (ev->button()==RightButton) { + QPoint pos; + KWin::WindowInfo *info = windowAtPosition(ev->pos(), &pos); + if ( info && showWindows ) + pager()->showPopupMenu(info->win(), mapToGlobal(ev->pos())); + else + pager()->showPopupMenu(0, mapToGlobal(ev->pos())); + } +} + +void Desktop::mouseReleaseEvent( QMouseEvent *ev ) +{ +/** Note that mouseReleaseEvent is not called when releasing the mouse + to drop a window in this desktop */ + if (ev->button()==LeftButton) + { + bool showWindows= KPagerConfigDialog::m_showWindows; + QPoint pos; + KWin::setCurrentDesktop(m_desk); + if (showWindows) + { + KWin::WindowInfo *info = windowAtPosition(ev->pos(), &pos); + if (info) + { + KWin::forceActiveWindow(info->win()); + + // if ( static_cast<WindowDrawMode>( KPagerConfigDialog::m_windowDrawMode ) == Pixmap ) + // m_windowPixmapsDirty.replace(info->win,true); + } + } + } +} + +KWin::WindowInfo *Desktop::windowAtPosition(const QPoint &p, QPoint *internalpos) +{ + QRect r; + const QValueList<WId> &list(pager()->kwin()->stackingOrder()); + if (list.count() <= 0) + return 0L; + + for (QValueList<WId>::ConstIterator it = list.fromLast(); ; --it) + { + KWin::WindowInfo* info = pager()->info( *it ); + if (shouldPaintWindow(info)) + { + r=info->geometry(); + convertRectS2P(r); + if (r.contains(p)) + { + if (internalpos) + { + internalpos->setX(p.x()-r.x()); + internalpos->setY(p.y()-r.y()); + } + return info; + } + } + + if (it == list.begin()) + break; + } + return 0L; +} + +void Desktop::convertRectS2P(QRect &r) +{ + QRect tmp(r); + r.setRect(deskX()+tmp.x()*deskWidth()/kapp->desktop()->width(), + deskY()+tmp.y()*deskHeight()/kapp->desktop()->height(), + tmp.width()*deskWidth()/kapp->desktop()->width(), + tmp.height()*deskHeight()/kapp->desktop()->height()); +} + +void Desktop::convertCoordP2S(int &x, int &y) +{ + x=(x-deskX())*(kapp->desktop()->width())/deskWidth(); + y=(y-deskY())*(kapp->desktop()->height())/deskHeight(); +} + +QPixmap scalePixmap(const QPixmap &pixmap, int width, int height) +{ + if (pixmap.width()>100) + { + KPixmapIO io; + QImage img(io.convertToImage(pixmap)); + return io.convertToPixmap(img.smoothScale(width,height)); + } + + QImage img(pixmap.convertToImage().smoothScale(width,height)); + QPixmap pix; + pix.convertFromImage(img); + + return pix; +} + +QPixmap fastScalePixmap(const QPixmap &pixmap, int width, int height) +{ + QWMatrix m; + m.scale(width/(double)pixmap.width(), + height/(double)pixmap.height()); + return pixmap.xForm(m); +} + +void Desktop::loadBgPixmap(void) +{ +// if (!m_bgDirty) return; + DCOPClient *client = kapp->dcopClient(); + if (!client->isAttached()) + client->attach(); + QByteArray data, data2, replyData; + QCString replyType; + if (client->call("kdesktop", "KBackgroundIface", "isCommon()", + data, replyType, replyData)) + { + QDataStream reply(replyData, IO_ReadOnly); + if (replyType == "bool") { + reply >> m_isCommon; + } + } + if ( m_isCommon && m_desk!=1 ) return; + +/* + QDataStream args2( data2, IO_WriteOnly ); + args2 << m_desk-1 << 0 << 0 << -1 << -1 << 200 << 150 ; + if (client->call("kdesktop", "KBackgroundIface", + "wallpaper(int,int,int,int,int,int,int)", data2, replyType, replyData)) + { + QDataStream reply(replyData, IO_ReadOnly); + if (replyType == "QPixmap") { + QPixmap pixmap; + reply >> pixmap; + if (!pixmap.isNull()) + { + kdDebug() << "getting small bg through dcop\n"; + if (m_isCommon) + { + if (m_bgSmallPixmap) { delete m_bgSmallPixmap; m_bgSmallPixmap=0L; } + + if (!m_bgCommonSmallPixmap) m_bgCommonSmallPixmap=new QPixmap(pixmap); + else *m_bgCommonSmallPixmap=pixmap; + } + else + { + if (m_bgCommonSmallPixmap) + { + delete m_bgCommonSmallPixmap; + m_bgCommonSmallPixmap=0L; + } + + if (!m_bgSmallPixmap) m_bgSmallPixmap=new QPixmap(pixmap); + else *m_bgSmallPixmap=pixmap; + } + return; + } + } + } + kdDebug() << "getting whole bg through shpixmap\n"; + */ + + QDataStream args( data, IO_WriteOnly ); + args << 1; + client->send( "kdesktop", "KBackgroundIface", "setExport(int)", data ); + + if (!m_bgPixmap) + { + m_bgPixmap = new KSharedPixmap; + connect(m_bgPixmap, SIGNAL(done(bool)), SLOT(backgroundLoaded(bool))); + } + + m_bgPixmap->loadFromShared(QString("DESKTOP%1").arg(m_isCommon?1:m_desk)); + +} + +void Desktop::paintWindow(QPainter &p, const KWin::WindowInfo *info, bool onDesktop) +{ + switch (static_cast<WindowDrawMode>(KPagerConfigDialog::m_windowDrawMode ) ) + { + case (Plain) : paintWindowPlain (p, info, onDesktop);break; + case (Icon) : paintWindowIcon (p, info, onDesktop);break; + case (Pixmap) : paintWindowPixmap(p, info, onDesktop);break; + } +} + +QPixmap *Desktop::paintNewWindow(const KWin::WindowInfo *info) +{ + QRect r = info->frameGeometry(); + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + r = QRect( r.x() * width() / dw, 2 + r.y() * height() / dh, + r.width() * width() / dw, r.height() * height() / dh ); + r.moveTopLeft(QPoint(0,0)); + + + QPixmap *pixmap=new QPixmap(r.width(),r.height()); + QPainter p; + + p.begin(pixmap); + p.setFont(font()); + p.fillRect( r, colorGroup().brush(QColorGroup::Dark)); + paintWindow(p, info, false); + p.end(); + + return pixmap; +} + +void Desktop::startDrag(const QPoint &p) +{ + QPoint dragpos; + KWin::WindowInfo *info=windowAtPosition(p,&dragpos); + if ( (!info)/* || (info->state & NET::Max)*/ ) return; + + QPixmap *pixmap=paintNewWindow(info); + + int deltax=dragpos.x(); + int deltay=dragpos.y(); + PagerWindowDrag *wdrag= new PagerWindowDrag( info->win(), deltax, deltay, + m_desk, this); + wdrag->setPixmap( *pixmap, QPoint( deltax, deltay) ); + delete pixmap; + wdrag->dragCopy(); + +} + +void Desktop::dragEnterEvent(QDragEnterEvent *ev) +{ + if (PagerWindowDrag::canDecode( ev )) ev->accept(); +} + +void Desktop::dragMoveEvent(QDragMoveEvent *) +{ + // TODO Moving the window while dragging would be cool, wouldn't it ? + // Matthias: No, is way to slow on low end machines. + // Antonio:Ok, I'll make it configurable after 2.0 (it would add a string) +} + +void Desktop::dropEvent(QDropEvent *ev) +{ + WId win=0; + int deltax,deltay; + int origdesk; + if (!PagerWindowDrag::decode(ev,win,deltax,deltay,origdesk)) return; + + int x=ev->pos().x()-deltax; + int y=ev->pos().y()-deltay; + /* + * x and y now contain the position (in local coordinates) which + * has the origin of the window + */ + convertCoordP2S(x,y); + +// kdDebug() << "moving window " << win << "d from " << origdesk << " to " << m_desk << endl; +// NETWinInfo NETinfo( qt_xdisplay(), win, qt_xrootwin(), NET::Client | NET::WMDesktop); + + if (m_desk==0) + { + /* + * The next line moves the window to the active desktop. This is done + * because in other case, kwm raises the window when it's in a semi + * changed state and doesn't work well with kpager. Let's see how well + * KWin behaves. + * if (activedesktop!=KWM::desktop(w)) + * KWM::moveToDesktop(w,activedesktop); + */ +// KWin::setState(win, NET::Sticky); + KWin::setOnAllDesktops(win, true); + } + else + { + if (origdesk==0) KWin::setOnAllDesktops(win, false); + + KWin::WindowInfo *info = pager()->info(win); + if (!info->onAllDesktops()) + KWin::setOnDesktop(win, m_desk); + } + + XMoveWindow(x11Display(), win, x, y ); +} + +bool Desktop::shouldPaintWindow( KWin::WindowInfo *info ) +{ + if (!info) + return false; + +// if (info->mappingState != NET::Visible) +// return false; + + NET::WindowType type = info->windowType( NET::NormalMask | NET::DesktopMask + | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask + | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask ); + if (type == NET::Desktop || type == NET::Dock + || type == NET::TopMenu) + return false; + + if (!info->isOnDesktop(m_desk)) + return false; + + if (info->state() & NET::SkipPager + || info->state() & NET::Shaded ) + return false; + + if (info->win() == pager()->winId()) + return false; + + if ( info->isMinimized() ) + return false; + + return true; +} + +void Desktop::paintFrame(bool active) +{ + QPainter p(this); + + if ( active ) + p.setPen(yellow); + else + p.setPen(QColorGroup::Base); + p.drawRect(rect()); + p.end(); +} + +void Desktop::paintEvent( QPaintEvent * ) +{ + QPixmap pixmap(width(),height()); + QPainter p; + + p.begin(&pixmap); +// p.setFont(font()); +// p.fillRect(rect(), colorGroup().brush(QColorGroup::Dark)); +// p.setPen(Qt::black); +// p.drawRect(rect()); + + if (KPagerConfigDialog::m_showBackground ) + { + if ( ( !m_isCommon && !m_bgSmallPixmap ) + || (m_isCommon && !m_bgCommonSmallPixmap) ) + loadBgPixmap(); + + if ( ( !m_isCommon && m_bgSmallPixmap && !m_bgSmallPixmap->isNull() ) + || ( m_isCommon && + m_bgCommonSmallPixmap && !m_bgCommonSmallPixmap->isNull() ) ) + { + QPixmap tmp; + if ( m_isCommon ) + tmp=fastScalePixmap(*m_bgCommonSmallPixmap, width(),height()); + else + tmp=fastScalePixmap(*m_bgSmallPixmap, width(),height()); + + p.drawPixmap(0,0,tmp); + } + else pixmap.fill(Qt::gray); + } + else + p.fillRect(rect(), colorGroup().brush(QColorGroup::Mid)); + + // set in/active pen + if (isCurrent()) + p.setPen(yellow); + else + p.setPen(QColorGroup::Base); + + // paint number & name + bool sname=KPagerConfigDialog::m_showName; + bool snumber=KPagerConfigDialog::m_showNumber; + if ( sname || snumber ) { + QString txt; + + // set font + if (sname) { + QFont f(KGlobalSettings::generalFont().family(), 10, QFont::Bold); + p.setFont(f); + } + else { + QFont f(KGlobalSettings::generalFont().family(), 12, QFont::Bold); + p.setFont(f); + } + + // draw text + if ( sname && snumber ) + txt=QString("%1. %2").arg(m_desk).arg(pager()->kwin()->desktopName( m_desk )); + else if ( sname ) + txt=pager()->kwin()->desktopName( m_desk ); + else if ( snumber ) + txt=QString::number( m_desk ); + p.drawText(2, 0, width()-4, height(), AlignCenter, txt ); + } + + // paint windows + if ( KPagerConfigDialog::m_showWindows ) { + QValueList<WId>::ConstIterator it; + for ( it = pager()->kwin()->stackingOrder().begin(); + it != pager()->kwin()->stackingOrder().end(); ++it ) { + + KWin::WindowInfo* info = pager()->info( *it ); + + if (shouldPaintWindow(info)) + paintWindow(p,info); + } + } + + // paint border rectangle + p.drawRect(rect()); + p.end(); + + // blit pixmap to widget + p.begin(this); + p.drawPixmap(0,0,pixmap); + p.end(); + + m_grabWindows=false; +} + +void Desktop::paintWindowPlain(QPainter &p, const KWin::WindowInfo *info, bool onDesktop) +{ + QRect r = info->frameGeometry(); + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + r = QRect( r.x() * width() / dw, 2 + r.y() * height() / dh, + r.width() * width() / dw, r.height() * height() / dh ); + if ( !onDesktop ) + r.moveTopLeft(QPoint(0,0)); + + bool isActive=(pager()->kwin()->activeWindow() == info->win()); + + QBrush brush; + + if ( isActive ) brush=colorGroup().brush( QColorGroup::Highlight ); + else brush=colorGroup().brush( QColorGroup::Button ); + + if ( m_transparentMode==AllWindows + || (m_transparentMode==MaximizedWindows && ( info->state() & NET::Max )) ) + brush.setStyle(QBrush::Dense4Pattern); + + if ( isActive ) + { + qDrawShadeRect( &p, r, colorGroup(), false, 1, 0, &brush ); + } + else + { + p.fillRect( r, brush ); + qDrawShadeRect( &p, r, colorGroup(), true, 1, 0 ); + } + +} + + +void Desktop::paintWindowIcon(QPainter &p, const KWin::WindowInfo *info, bool onDesktop) +{ + QRect r = info->frameGeometry(); + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + r = QRect( r.x() * width() / dw, 2 + r.y() * height() / dh, + r.width() * width() / dw, r.height() * height() / dh ); + QPixmap icon=KWin::icon( info->win(), int(r.width()*0.8), + int(r.height()*0.8), true); + + NET::WindowType type = info->windowType( NET::NormalMask | NET::DesktopMask + | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask + | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask ); + if ( icon.isNull() || type!=NET::Override ) + paintWindowPlain(p,info,onDesktop); + + if ( !onDesktop ) + r.moveTopLeft(QPoint(0,0)); + + p.drawPixmap( r.topLeft()+ QPoint(int(r.width()*0.1),int(r.height()*0.1)), + icon ); + +} + +void Desktop::paintWindowPixmap(QPainter &p, const KWin::WindowInfo *info, + bool onDesktop) +{ + const int knDefaultPixmapWd = 100; + const int knDefaultPixmapHg = 75; + QRect rSmall, r = info->frameGeometry(); + + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + rSmall = QRect( r.x() * width() / dw, 2 + r.y() * height() / dh, + r.width() * width() / dw, r.height() * height() / dh ); + + QPixmap *pixmap=m_windowPixmaps[info->win()]; + bool isDirty=m_windowPixmapsDirty[info->win()]; + if ( !pixmap || isDirty || m_grabWindows ) + { + if ( isCurrent() ) + { + QPixmap tmp=QPixmap::grabWindow(info->win(), + 0,0,r.width(),r.height()); + if (!tmp.isNull() && tmp.width() > 0 && tmp.height() > 0) + { + tmp.setOptimization(QPixmap::BestOptim); + int nWd, nHg; + if (rSmall.width() > knDefaultPixmapWd || rSmall.height() > knDefaultPixmapHg) + { + nWd = knDefaultPixmapWd; + nHg = knDefaultPixmapHg; + } + else + { + nWd = rSmall.width(); + nHg = rSmall.height(); + } + pixmap=new QPixmap(fastScalePixmap(tmp, nWd, nHg)); + m_windowPixmaps.replace(info->win(),pixmap); + m_windowPixmapsDirty.replace(info->win(),false); + } + } + + // It was impossible to get the pixmap, let's fallback to the icon mode. + if ( !pixmap || pixmap->isNull() ) + { + paintWindowIcon(p, info, onDesktop); + return; + } + + } + + if ( !onDesktop ) + rSmall.moveTopLeft(QPoint(0,0)); + + if (rSmall.width() != pixmap->width() || rSmall.height() != pixmap->height()) + { + QPixmap pixmapSmall(fastScalePixmap(*pixmap,rSmall.width(),rSmall.height())); + p.drawPixmap( rSmall.topLeft(), pixmapSmall ); + } + else + { + p.drawPixmap( rSmall.topLeft(), *pixmap); + } + +} + +KPager *Desktop::pager() const +{ + return reinterpret_cast<KPager *>(parent()); +} + +bool Desktop::isCurrent() const +{ + return pager()->kwin()->currentDesktop()==m_desk; +} + +void Desktop::backgroundLoaded(bool b) +{ + if (b) + { + if (m_isCommon) + { + if (m_bgSmallPixmap) { delete m_bgSmallPixmap; m_bgSmallPixmap=0L ; }; + + if (!m_bgCommonSmallPixmap) m_bgCommonSmallPixmap=new QPixmap; + *m_bgCommonSmallPixmap=scalePixmap(*m_bgPixmap,200,150); + } + else + { + if (m_bgCommonSmallPixmap) { delete m_bgCommonSmallPixmap; + m_bgCommonSmallPixmap=0L ; }; + + if (!m_bgSmallPixmap) m_bgSmallPixmap=new QPixmap; + *m_bgSmallPixmap=fastScalePixmap(*m_bgPixmap,200,150); + } + delete m_bgPixmap; + m_bgPixmap=0L; + + + if (m_isCommon) pager()->redrawDesktops(); + else update(); + } else kdDebug() << "Error getting the background\n"; +} + +QSize Desktop::sizeHint() const +{ + return QSize(67,50); +} + +QPixmap *Desktop::m_bgCommonSmallPixmap=0L; +bool Desktop::m_isCommon=false; +QIntDict<QPixmap> Desktop::m_windowPixmaps; +QMap<int,bool> Desktop::m_windowPixmapsDirty; + +// Default Configuration ------------------------------------------------- + +const bool Desktop::c_defShowName=false; +const bool Desktop::c_defShowNumber=false; +const bool Desktop::c_defShowWindows=true; +const bool Desktop::c_defShowBackground=true; +const bool Desktop::c_defWindowDragging=true; +const Desktop::WindowDrawMode Desktop::c_defWindowDrawMode=Desktop::Icon; +const Desktop::WindowTransparentMode + Desktop::c_defWindowTransparentMode=Desktop::AllWindows; +#include "desktop.moc" diff --git a/kpager/desktop.h b/kpager/desktop.h new file mode 100644 index 000000000..acdf4f517 --- /dev/null +++ b/kpager/desktop.h @@ -0,0 +1,130 @@ +/************************************************************************** + + desktop.h - KPager's desktop + Copyright (C) 2000 Antonio Larrosa Jimenez + Matthias Ettrich + Matthias Elter + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ +#ifndef __DESKTOP_H +#define __DESKTOP_H + +#include <qwidget.h> +#include <qintdict.h> +#include <kwin.h> + +class KSharedPixmap; +class KPopupMenu; + +class QPainter; +class QPoint; + +class Desktop : public QWidget +{ + Q_OBJECT + +public: + Desktop( int desk, QString desktopName, QWidget *parent=0, + const char *name=0); + ~Desktop(); + + int id() const { return m_desk; }; + bool isCurrent() const; + +// int widthForHeight(int height) const; +// int heightForWidth(int width) const; + + static const bool c_defShowName; + static const bool c_defShowNumber; + static const bool c_defShowBackground; + static const bool c_defShowWindows; + static const bool c_defWindowDragging; + enum WindowDrawMode { Plain=0, Icon=1, Pixmap=2 }; + enum WindowTransparentMode { NoWindows=0, MaximizedWindows=1, AllWindows=2}; + static const WindowDrawMode c_defWindowDrawMode; + static const WindowTransparentMode c_defWindowTransparentMode; + + virtual int deskX() const { return 0; }; + virtual int deskY() const { return 0; }; + virtual int deskWidth() const { return width(); }; + virtual int deskHeight() const { return height(); }; + + void startDrag(const QPoint &point); + void dragEnterEvent(QDragEnterEvent *ev); + void dragMoveEvent(QDragMoveEvent *); + void dropEvent(QDropEvent *ev); + void convertRectS2P(QRect &r); + void convertCoordP2S(int &x, int &y); + + static void removeCachedPixmap(int nWin) { m_windowPixmaps.remove(nWin); }; + + QSize sizeHint() const; + + /** + * active is a bool that specifies if the frame is the active + * one or not (so that it's painted highlighted or not) + */ + void paintFrame(bool active); + + bool m_grabWindows; +public slots: + void backgroundLoaded(bool b); + + void loadBgPixmap(); + +protected: + void mousePressEvent( QMouseEvent *ev ); + void mouseMoveEvent( QMouseEvent *ev ); + void mouseReleaseEvent( QMouseEvent *ev ); + + void paintEvent( QPaintEvent *ev ); + + KWin::WindowInfo *windowAtPosition (const QPoint &p, QPoint *internalpos); + + bool shouldPaintWindow( KWin::WindowInfo *info ); + + int m_desk; + QString m_name; + KSharedPixmap *m_bgPixmap; + bool m_bgDirty; + QPixmap *m_bgSmallPixmap; + static QPixmap *m_bgCommonSmallPixmap; + static bool m_isCommon; + static QIntDict<QPixmap> m_windowPixmaps; + static QMap<int,bool> m_windowPixmapsDirty; + WindowTransparentMode m_transparentMode; + + QPixmap *paintNewWindow(const KWin::WindowInfo *info); + + void paintWindow(QPainter &p, const KWin::WindowInfo *info, + bool onDesktop=true); + void paintWindowPlain(QPainter &p, const KWin::WindowInfo *info, + bool onDesktop=true); + void paintWindowIcon(QPainter &p, const KWin::WindowInfo *info, + bool onDesktop=true); + void paintWindowPixmap(QPainter &p, const KWin::WindowInfo *info, + bool onDesktop=true); + +private: + class KPager* pager() const; + QPoint pressPos; + +}; + +#endif diff --git a/kpager/hi16-app-kpager.png b/kpager/hi16-app-kpager.png Binary files differnew file mode 100644 index 000000000..b58c33643 --- /dev/null +++ b/kpager/hi16-app-kpager.png diff --git a/kpager/hi22-app-kpager.png b/kpager/hi22-app-kpager.png Binary files differnew file mode 100644 index 000000000..f549d927b --- /dev/null +++ b/kpager/hi22-app-kpager.png diff --git a/kpager/hi32-app-kpager.png b/kpager/hi32-app-kpager.png Binary files differnew file mode 100644 index 000000000..00e5c0c26 --- /dev/null +++ b/kpager/hi32-app-kpager.png diff --git a/kpager/hi48-app-kpager.png b/kpager/hi48-app-kpager.png Binary files differnew file mode 100644 index 000000000..529954009 --- /dev/null +++ b/kpager/hi48-app-kpager.png diff --git a/kpager/kpager.cpp b/kpager/kpager.cpp new file mode 100644 index 000000000..b405e633b --- /dev/null +++ b/kpager/kpager.cpp @@ -0,0 +1,674 @@ +/************************************************************************** + + kpager.cpp - KPager's main window + Copyright (C) 2000 Antonio Larrosa Jimenez + Matthias Ettrich + Matthias Elter + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ + +/* + * There is a features that is only configurable by manually editing the + * config file due to the translation freeze . The key is + * windowTransparentMode and the values are : + * 0 = Never + * 1 = Only maximized windows are painted transparent + * 2 = Every window is painted transparent (default) + * + */ + +#include "config.h" +#include "kpager.h" + +#include <qintdict.h> +#include <qptrlist.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qtimer.h> + +#include <kapplication.h> +#include <kglobalsettings.h> +#include <kaction.h> +#include <kstdaction.h> +#include <kglobal.h> +#include <kconfig.h> +#include <kdebug.h> +#include <klocale.h> +#include <kwin.h> +#include <kwinmodule.h> +#include <netwm.h> +#include "desktop.h" +#include <qpopupmenu.h> +#include <kpopupmenu.h> +#include <kiconloader.h> +#include <assert.h> + +KPagerMainWindow::KPagerMainWindow(QWidget *parent, const char *name) + : DCOPObject("KPagerIface"), KMainWindow(parent, name) +{ + m_reallyClose=false; + + m_pPager = new KPager(this, 0); + setCentralWidget(m_pPager); + + KConfig *cfg = kapp->config(); + cfg->setGroup("KPager"); + + // Update the last used geometry + int w = cfg->readNumEntry(m_pPager->lWidth(),-1); + int h = cfg->readNumEntry(m_pPager->lHeight(),-1); + if (w > 0 && h > 0) + resize(w,h); + else + resize(m_pPager->sizeHint()); + // resize(cfg->readNumEntry(lWidth(),200),cfg->readNumEntry(lHeight(),90)); + + int xpos=cfg->readNumEntry("xPos",-1); + int ypos=cfg->readNumEntry("yPos",-1); + if (xpos > 0 && ypos > 0) + move(xpos,ypos); + else + { +// NETRootInfo ri( qt_xdisplay(), NET::WorkArea ); +// NETRect rect=ri.workArea(1); +// move(rect.pos.x+rect.size.width-m_pPager->width(), +// rect.pos.y+rect.size.height-m_pPager->height()); +// antonio:The above lines don't work. I should look at them when I have +// more time + move(kapp->desktop()->width()-m_pPager->sizeHint().width()-5,kapp->desktop()->height()-m_pPager->sizeHint().height()-25); + } + + // Set the wm flags to this window + KWin::setState( winId(), NET::StaysOnTop | NET::SkipTaskbar | NET::Sticky | NET::SkipPager ); + KWin::setOnAllDesktops( winId(), true); + if ( KWin::windowInfo( winId(), NET::WMWindowType, 0 ).windowType(NET::Normal) == NET::Normal ) + { + KWin::setType( winId(), NET::Utility ); + } + + XWMHints *hints = XGetWMHints(x11Display(), winId()); + if( hints == NULL ) + hints = XAllocWMHints(); + hints->input = false; + hints->flags |= InputHint; + XSetWMHints(x11Display(), winId(), hints); + XFree(reinterpret_cast<char *>(hints)); + + timeout=new QTimer(this,"timeoutToQuit"); + connect(timeout,SIGNAL(timeout()),this, SLOT(reallyClose())); +} + +KPagerMainWindow::~KPagerMainWindow() +{ +} + +extern bool closed_by_sm; + +bool KPagerMainWindow::queryClose() +{ + KConfig *cfg=KGlobal::config(); + + cfg->setGroup("KPager"); + cfg->writeEntry("layoutType", static_cast<int>(m_pPager->m_layoutType)); + cfg->writeEntry(m_pPager->lWidth(),width()); + cfg->writeEntry(m_pPager->lHeight(),height()); + cfg->writeEntry("xPos",x()); + cfg->writeEntry("yPos",y()); + cfg->sync(); + + kdDebug() << "queryCLose " << m_reallyClose << " " << closed_by_sm << endl; + if (m_reallyClose || closed_by_sm) return true; + + hide(); + timeout->start(10 /*minutes*/ *60000, true); + + return false; +} + +void KPagerMainWindow::showEvent( QShowEvent *ev ) +{ + timeout->stop(); + KMainWindow::showEvent(ev); +} + +void KPagerMainWindow::reallyClose() +{ + m_reallyClose=true; + close(); +} + +void KPagerMainWindow::showAt(int x, int y) +{ + // Just in case we lost the sticky bit... (as when a window is hidden) + KWin::setOnAllDesktops( winId(), true); + + if (x>kapp->desktop()->width()/2) // Right + x-=m_pPager->width()+5; + if (y>kapp->desktop()->height()/2) // Bottom + y-=m_pPager->height()+25; + move(x,y); + show(); +} + +void KPagerMainWindow::toggleShow(int x, int y) +{ + if (isVisible()) + { + hide(); + timeout->start(10 /*minutes*/ *60000, true); + } + else + showAt(x,y); +} + +KPager::KPager(KPagerMainWindow *parent, const char *name) + : QFrame (parent, name, WStyle_Customize | WStyle_NoBorder | WStyle_Tool) + , m_layout(0) + , m_mnu(0) + , m_smnu(0) + , m_dmnu(0) +{ + m_windows.setAutoDelete(true); // delete windows info after removal + + setBackgroundColor( black ); + m_winmodule=new KWinModule(this); + m_currentDesktop=m_winmodule->currentDesktop(); + + m_grabWinTimer=new QTimer(this,"grabWinTimer"); + connect(m_grabWinTimer, SIGNAL(timeout()), this, SLOT(slotGrabWindows())); + + KPagerConfigDialog::initConfiguration(); + + KConfig *cfg = kapp->config(); + cfg->setGroup("KPager"); + m_showStickyOption=cfg->readBoolEntry("ShowStickyOption",false); + + int numberOfDesktops=m_winmodule->numberOfDesktops(); + for (int i=0;i<numberOfDesktops;i++) + { + Desktop *dsk=new Desktop(i+1,m_winmodule->desktopName(i),this); + m_desktops.append(dsk); + } + + m_layoutType=static_cast<enum KPager::LayoutTypes>( KPagerConfigDialog::m_layoutType ); + + connect( m_winmodule, SIGNAL( activeWindowChanged(WId)), + SLOT(slotActiveWindowChanged(WId))); + connect( m_winmodule, SIGNAL( windowAdded(WId) ), + SLOT( slotWindowAdded(WId) ) ); + connect( m_winmodule, SIGNAL( windowRemoved(WId) ), + SLOT( slotWindowRemoved(WId) ) ); + connect( m_winmodule, SIGNAL( windowChanged(WId,unsigned int) ), + SLOT( slotWindowChanged(WId,unsigned int) ) ); + connect( m_winmodule, SIGNAL( stackingOrderChanged() ), + SLOT( slotStackingOrderChanged() ) ); + connect( m_winmodule, SIGNAL( desktopNamesChanged() ), + SLOT( slotDesktopNamesChanged() ) ); + connect( m_winmodule, SIGNAL( numberOfDesktopsChanged(int) ), + SLOT( slotNumberOfDesktopsChanged(int) ) ); + connect( m_winmodule, SIGNAL( currentDesktopChanged(int)), + SLOT( slotCurrentDesktopChanged(int) ) ); + connect(kapp, SIGNAL(backgroundChanged(int)), + SLOT(slotBackgroundChanged(int))); + + QFont defFont(KGlobalSettings::generalFont().family(), 10, QFont::Bold); + defFont = cfg->readFontEntry("Font", &defFont); + setFont(defFont); + + m_prefs_action = KStdAction::preferences(this, SLOT(configureDialog()), parent->actionCollection()); + m_quit_action = KStdAction::quit(kapp, SLOT(quit()), parent->actionCollection()); + + updateLayout(); +} + +KPager::~KPager() +{ + +} + +const QString KPager::lWidth() +{ + switch (m_layoutType) { + case (Classical) : return "layoutClassicalWidth";break; + case (Horizontal) : return "layoutHorizontalWidth";break; + case (Vertical) : return "layoutVerticalWidth";break; + }; + return "Width"; +} + +const QString KPager::lHeight() +{ + switch (m_layoutType) { + case (Classical) : return "layoutClassicalHeight";break; + case (Horizontal) : return "layoutHorizontalHeight";break; + case (Vertical) : return "layoutVerticalHeight";break; + }; + return "Height"; +} + +void KPager::updateLayout() +{ + int w=m_desktops[0]->width(); + int h=m_desktops[0]->height(); + + delete m_layout; + + switch (m_layoutType) + { + case (Classical) : m_layout=new QGridLayout(this, 2, 0); break; + case (Horizontal) : m_layout=new QGridLayout(this, 0, 1); break; + case (Vertical) : m_layout=new QGridLayout(this, 1, 0); break; + }; + + QValueList <Desktop *>::Iterator it; + int i,j; + i=j=0; + int ndesks=0; + int halfdesks = (m_desktops.count() + 1) / 2; + for( it = m_desktops.begin(); it != m_desktops.end(); ++it ) + { + m_layout->addWidget(*it,i,j); + ndesks++; + switch (m_layoutType) + { + case (Classical) : i= ndesks / halfdesks; j = ndesks % halfdesks; break; + case (Horizontal) : j++; break; + case (Vertical) : i++; break; + }; + } + + m_layout->activate(); + updateGeometry(); + + switch (m_layoutType) + { + case (Classical) : resize(w*(ndesks/2+(ndesks%2)),h*2);break; + case (Horizontal) : resize(w*ndesks,h);break; + case (Vertical) : resize(w, h*ndesks);break; + }; + +} + +void KPager::showPopupMenu( WId wid, QPoint pos) +{ + if (wid <= 0) { + if(!m_smnu) { + m_smnu = new QPopupMenu(this); + m_prefs_action->plug(m_smnu); + m_quit_action->plug(m_smnu); + } + m_smnu->popup(pos); + } + else { + m_winfo = KWin::windowInfo(wid); + + if (!m_mnu) { + m_mnu = new KPopupMenu(this); + + m_mnu->insertTitle( QString::fromUtf8("KPager"), 1); + m_mnu->setCheckable(true); + connect(m_mnu, SIGNAL(aboutToShow()), SLOT(clientPopupAboutToShow())); + connect(m_mnu, SIGNAL(activated(int)), SLOT(clientPopupActivated(int))); + + m_dmnu = new QPopupMenu(m_mnu); + m_dmnu->setCheckable(true); + connect(m_dmnu, SIGNAL(aboutToShow()), SLOT(desktopPopupAboutToShow())); + connect(m_dmnu, SIGNAL(activated(int)), SLOT(sendToDesktop(int))); + + m_mnu->insertItem( i18n("Mi&nimize"), IconifyOp ); + m_mnu->insertItem( i18n("Ma&ximize"), MaximizeOp ); + if (m_showStickyOption) + m_mnu->insertItem( QString("&Sticky"), StickyOp ); // Add translation + m_mnu->insertSeparator(); + + m_mnu->insertItem(i18n("&To Desktop"), m_dmnu ); + m_mnu->insertSeparator(); + + m_mnu->insertItem(SmallIcon("fileclose"),i18n("&Close"), CloseOp); + + m_mnu->insertSeparator(); + m_prefs_action->plug(m_mnu); + m_quit_action->plug(m_mnu); + } + m_mnu->popup(pos); + } +} + +void KPager::configureDialog() +{ + KPagerConfigDialog *dialog= new KPagerConfigDialog(this); + if (dialog->exec()) + { + m_layoutType=static_cast<enum KPager::LayoutTypes>(KPagerConfigDialog::m_layoutType); + KConfig *cfg=KGlobal::config(); + int nWd = (parent() ? ((QWidget *)parent())->width() : width()); + int nHg = (parent() ? ((QWidget *)parent())->width() : width()); + + cfg->setGroup("KPager"); + + cfg->writeEntry(lWidth(),nWd); + cfg->writeEntry(lHeight(),nHg); + cfg->writeEntry("windowDrawMode",KPagerConfigDialog::m_windowDrawMode); + cfg->writeEntry("layoutType",KPagerConfigDialog::m_layoutType); + cfg->writeEntry("showNumber",KPagerConfigDialog::m_showNumber); + cfg->writeEntry("showName",KPagerConfigDialog::m_showName); + cfg->writeEntry("showWindows",KPagerConfigDialog::m_showWindows); + cfg->writeEntry("showBackground",KPagerConfigDialog::m_showBackground); + cfg->writeEntry("windowDragging",KPagerConfigDialog::m_windowDragging); + + updateLayout(); + for( QValueList <Desktop *>::Iterator it = m_desktops.begin(); it != m_desktops.end(); ++it ) + (*it)->repaint(); + } +} + +KWin::WindowInfo* KPager::info( WId win ) +{ + KWin::WindowInfo* info = m_windows[win]; + if (!info ) + { + info = new KWin::WindowInfo( KWin::windowInfo( win ) ); + if( !info->valid() || info->desktop() == 0 ) + { + delete info; + return NULL; // window no longer valid + } + m_windows.insert( (long) win, info ); + } + return info; +} + +void KPager::slotActiveWindowChanged( WId win ) +{ + KWin::WindowInfo* inf1 = info( m_activeWin ); + KWin::WindowInfo* inf2 = info( win ); + m_activeWin = win; + + // update window pixmap + // in case of active desktop change it will be updated anyway by timer +// if (!m_grabWinTimer->isActive()) +// Desktop::removeCachedPixmap(win); + + for ( int i=1; i <= (int) m_desktops.count(); ++i) + { + if ( (inf1 && inf1->isOnDesktop(i)) + || (inf2 && inf2->isOnDesktop(i) ) ) + m_desktops[i-1]->repaint(false); + } +} + +void KPager::slotWindowAdded( WId win) +{ + KWin::WindowInfo* inf = info( win ); + if (!inf) + return; // never should be here + + for ( int i=1; i <= (int) m_desktops.count(); ++i) + { + if ( inf->isOnDesktop( i )) + m_desktops[i-1]->repaint(false); + } +} + +void KPager::slotWindowRemoved( WId win ) +{ + KWin::WindowInfo* inf = m_windows[win]; + if (inf) + { + bool onAllDesktops = inf->onAllDesktops(); + int desktop = inf->desktop(); + m_windows.remove( (long)win ); + Desktop::removeCachedPixmap(win); + for (int i = 1; i <= (int) m_desktops.count(); ++i) + { + if (onAllDesktops || desktop == i) + m_desktops[i-1]->repaint(false); + } + } +} + +void KPager::slotWindowChanged( WId win , unsigned int prop) +{ + bool repaint=false; + + KWin::WindowInfo* inf = m_windows[win]; + if (!inf) + { + inf=info(win); + prop=0; // info already calls KWin::info, so there's no need + // to update anything else. + repaint=true; + }; + + bool onAllDesktops = inf ? inf->onAllDesktops() : false; + int desktop = inf ? inf->desktop() : 0; + + if (prop) + { + m_windows.remove( (long) win ); + inf = info( win ); + } + + if((prop & ~( NET::WMName | NET::WMVisibleName )) != 0 ) + repaint = true; + + if (repaint) + for ( int i=1; i <= (int) m_desktops.count(); ++i) + { + if ((inf && (inf->isOnDesktop(i))) + || onAllDesktops || desktop == i ) + { + m_desktops[i-1]->repaint(false); + } + } +// redrawDesktops(); +} + +void KPager::slotStackingOrderChanged() +{ + m_desktops[m_currentDesktop-1]->m_grabWindows=true; + for ( int i=1; i <= (int) m_desktops.count(); ++i) + { + m_desktops[i-1]->repaint(false); + } +// repaint(true); +} + +void KPager::slotDesktopNamesChanged() +{ + for ( int i=1; i <= (int) m_desktops.count(); ++i) + { + QToolTip::remove(m_desktops[i-1]); + QToolTip::add(m_desktops[i-1], kwin()->desktopName(i)); + } + + update(); + emit updateLayout(); +} + +void KPager::slotNumberOfDesktopsChanged(int ndesktops) +{ + unsigned int nDesktops=static_cast<unsigned int>(ndesktops); + if (nDesktops<m_desktops.count()) + { + QValueList <Desktop *>::Iterator it; + for ( int i=m_desktops.count()-nDesktops; i > 0; i--) + { + it = m_desktops.fromLast(); + delete (*it); + m_desktops.remove(it); + } + + emit updateLayout(); + } + else if (nDesktops>m_desktops.count()) + { + int i,j; + i=j=m_desktops.count(); + switch (m_layoutType) + { + case (Classical) : i%=2;j/=2; break; + case (Horizontal) : i=0; break; + case (Vertical) : j=0; break; + } + + for (unsigned int d=m_desktops.count()+1;d<=nDesktops; d++) + { + Desktop *dsk=new Desktop(d,kwin()->desktopName(d-1),this); + m_desktops.append(dsk); + dsk->show(); + } + + emit updateLayout(); + } +} + + +void KPager::slotCurrentDesktopChanged(int desk) +{ + if (m_currentDesktop==desk) return; + m_desktops[m_currentDesktop-1]->paintFrame( false ); + m_desktops[m_currentDesktop-1]->update(); + m_desktops[desk-1]->paintFrame( true ); + m_desktops[desk-1]->update(); +// m_desktops[m_currentDesktop-1]->repaint(); +// m_desktops[desk-1]->repaint(); + + m_currentDesktop=desk; + + if (m_grabWinTimer->isActive()) m_grabWinTimer->stop(); + + if ( static_cast<Desktop::WindowDrawMode>( KPagerConfigDialog::m_windowDrawMode ) == Desktop::Pixmap ) + m_grabWinTimer->start(1000,true); +} + +void KPager::slotBackgroundChanged(int desk) +{ + m_desktops[desk-1]->loadBgPixmap(); +} + +void KPager::sendToDesktop(int desk) +{ + if (desk == 0) + KWin::setOnAllDesktops(m_winfo.win(), true); + else { + KWin::setOnDesktop(m_winfo.win(), desk); + } +} + +void KPager::clientPopupAboutToShow() +{ + if (!m_mnu) return; + + m_mnu->changeTitle(1,KWin::icon(m_winfo.win(),16,16,true), m_winfo.name()); + m_mnu->setItemChecked(IconifyOp, m_winfo.isMinimized()); + m_mnu->setItemChecked(MaximizeOp, m_winfo.state() & NET::Max); + if (m_showStickyOption) // Add translation + m_mnu->changeItem(StickyOp, + (m_winfo.onAllDesktops()) ? QString("Un&sticky"):QString("&Sticky")); +} + +void KPager::desktopPopupAboutToShow() +{ + if (!m_dmnu) return; + + m_dmnu->clear(); + m_dmnu->insertItem( i18n("&All Desktops"), 0 ); + m_dmnu->insertSeparator(); + + if (m_winfo.onAllDesktops()) + m_dmnu->setItemChecked( 0, true ); + + int id; + for ( int i = 1; i <= m_winmodule->numberOfDesktops(); i++ ) { + id = m_dmnu->insertItem( QString("&")+QString::number(i )+QString(" ") + + m_winmodule->desktopName(i), i ); + if ( m_winfo.desktop() == i ) + m_dmnu->setItemChecked( id, TRUE ); + } +} + +void KPager::clientPopupActivated( int id ) +{ + switch ( id ) { + case MaximizeOp: + if ( (m_winfo.state() & NET::Max) == 0 ) { + NETWinInfo ni( qt_xdisplay(), m_winfo.win(), qt_xrootwin(), 0); + ni.setState( NET::Max, NET::Max ); + } else { + NETWinInfo ni( qt_xdisplay(), m_winfo.win(), qt_xrootwin(), 0); + ni.setState( 0, NET::Max ); + } + break; + case IconifyOp: + if ( !m_winfo.isMinimized() ) { + KWin::iconifyWindow( m_winfo.win()); + } else { + KWin::forceActiveWindow( m_winfo.win() ); + } + break; + case StickyOp: + if ( m_winfo.onAllDesktops() ) { + KWin::setOnAllDesktops(m_winfo.win(), false); + } else { + KWin::setOnAllDesktops(m_winfo.win(), true); + } + break; + case CloseOp: { + NETRootInfo ri( qt_xdisplay(), 0 ); + ri.closeWindowRequest( m_winfo.win() ); + } break; + default: + break; + } +} + +void KPager::redrawDesktops() +{ + QValueList <Desktop *>::Iterator it; + for( it = m_desktops.begin(); it != m_desktops.end(); ++it ) + (*it)->repaint(); +} + +void KPager::slotGrabWindows() +{ + m_desktops[m_currentDesktop-1]->m_grabWindows=true; + m_desktops[m_currentDesktop-1]->repaint(); +} + +QSize KPager::sizeHint() const +{ + int n=m_desktops.count(); + int w=-1,h=-1; + + QSize size=m_desktops[0]->sizeHint(); + int wDsk=size.width(); + int hDsk=size.height(); + switch (m_layoutType) + { + case (Classical) : w=wDsk*(n/2+(n%2)); h=hDsk*2;break; + case (Horizontal) : w=wDsk*n; h=hDsk;break; + case (Vertical) : w=wDsk; h=hDsk*n;break; + }; + return QSize(w,h); +} + +const KPager::LayoutTypes KPager::c_defLayout=KPager::Horizontal; + +#include "kpager.moc" diff --git a/kpager/kpager.desktop b/kpager/kpager.desktop new file mode 100644 index 000000000..79e4632d5 --- /dev/null +++ b/kpager/kpager.desktop @@ -0,0 +1,106 @@ +[Desktop Entry] +Name=KPager +Name[cy]=KSwnyn +Name[eo]=Paĝilo +Name[hi]=के-पेजर +Name[ko]=호출기 +Name[lo]=ຕົວຮງກພື້ນທີ່ທຳງານ - K +Name[lv]=KPeidžers +Name[mk]=КПејџер +Name[ne]=के पेजर +Name[nso]=KSephetli +Name[pa]=ਕੇਪੇਜਰ +Name[ro]=Paginator +Name[rw]=K-Paja +Name[sv]=Kpager +Name[te]=కెపేజర్ +Name[tg]=KПейҷер +Name[th]=เปลี่ยนพื้นที่ทำงาน +Name[tr]=KDE Sayfalayıcı +Name[ven]=Pheidzha ya K +Name[wa]=KPådjeu +GenericName=Desktop Pager +GenericName[af]=Werkskerm Boodskapper +GenericName[ar]=Pager لسطح المكتب +GenericName[be]=Пэйджар для працоўнага стала +GenericName[bg]=Пейджър на работните плотове +GenericName[bn]=ডেস্কটপ পেজার +GenericName[br]=Pajenner ar Burev +GenericName[bs]=Promjena radne površine +GenericName[ca]=Paginador de l'escriptori +GenericName[cs]=Přepínač ploch +GenericName[csb]=Przestôwnik pùltów +GenericName[cy]=Swnyn Penbwrdd +GenericName[da]=desktop-skifter +GenericName[de]=Umschalten zwischen Arbeitsflächen +GenericName[el]=Αλλαγή Επιφάνειας Εργασίας +GenericName[eo]=Tabula paĝilo +GenericName[es]=Paginador del escritorio +GenericName[et]=Töölaua peiler +GenericName[eu]=Mahaigaineko orrialdekatzailea +GenericName[fa]=پیجوی رومیزی +GenericName[fi]=Työpöydänvaihtotyökalu +GenericName[fr]=Gestionnaire de bureaux virtuels +GenericName[fy]=Buroblêdpager +GenericName[ga]=Brabhsálaí na nDeasc +GenericName[gl]=Paxinador do Escritório +GenericName[he]=מנהל חלונות +GenericName[hi]=डेस्कटॉप पेजर +GenericName[hr]=Pager na radnoj površini +GenericName[hu]=Asztalváltó +GenericName[is]=Skjáborðflettir +GenericName[it]=Gestione dei desktop virtuali +GenericName[ja]=デスクトップページャー +GenericName[ka]=სამუშაო დაფათა გადამრთველი +GenericName[kk]=Виртуалды үстелдер ақтарғышы +GenericName[lo]=ແວ້ນຂະຫຍາຍພື້ນທີ່ທຳງານ +GenericName[lt]=Darbastalio puslapiuotojas +GenericName[lv]=Darbvirsmas Peidžers +GenericName[mk]=Пејџер на раб. површина +GenericName[mn]=Ажлын тавцан хоорондын сэлгүүр +GenericName[ms]=Penghalaman Desktop +GenericName[mt]=Desktops multipli +GenericName[nb]=Skrivebordsbytter +GenericName[nds]=Schriefdisch-Ümschalter +GenericName[ne]=डेस्कटप पेजर +GenericName[nl]=Bureaubladpager +GenericName[nn]=Skrivebordsbytar +GenericName[nso]=Sephetli sa Desktop +GenericName[pa]=ਡੈਸਕਟਾਪ ਪੇਜਰ +GenericName[pl]=Przełącznik pulpitów +GenericName[pt]=Paginador do Ecrã +GenericName[pt_BR]=Pager de Área de Trabalho +GenericName[ro]=Paginator de ecran +GenericName[ru]=Переключатель рабочих столов +GenericName[rw]=Paja y'Ibiro +GenericName[se]=Čállinbeavde molssuhanprográmma +GenericName[sk]=Pager pracovnej plochy +GenericName[sl]=Namizni pager +GenericName[sr]=Пејџер радне површине +GenericName[sr@Latn]=Pejdžer radne površine +GenericName[ss]=Sivulikhasi se-desktop +GenericName[sv]=Skrivbordsväljare +GenericName[ta]=மேல்மேசை பேஜர் +GenericName[te]=రంగస్థల పేజర్ +GenericName[tg]=Pager-и мизи корӣ +GenericName[th]=เรียกพื้นที่หน้าจอน +GenericName[tr]=Masaüstü Sayfalayıcı +GenericName[tt]=Östäl Bitçese +GenericName[uk]=Прогортач стільниць +GenericName[uz]=Ish stolining peyjeri +GenericName[uz@cyrillic]=Иш столининг пейжери +GenericName[ven]=Pheidzha ya Desikithopo +GenericName[vi]=Pager Màn hình nền +GenericName[wa]=Pådjeu do scribanne +GenericName[zh_CN]=桌面分页器 +GenericName[zh_TW]=桌面呼叫器 +GenericName[zu]=I-Pager ye-Desktop + +Icon=kpager +Type=Application +Exec=kpager +DocPath=kpager/index.html +Terminal=false +X-KDE-StartupNotify=false +X-DCOP-ServiceType=Unique +Categories=Qt;KDE;Utility;X-KDE-Utilities-Desktop; diff --git a/kpager/kpager.h b/kpager/kpager.h new file mode 100644 index 000000000..9fe67942c --- /dev/null +++ b/kpager/kpager.h @@ -0,0 +1,139 @@ +/************************************************************************** + + kpager.h - KPager's main window + Copyright (C) 2000 Antonio Larrosa Jimenez + Matthias Ettrich + Matthias Elter + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ +#ifndef __KPAGER_H +#define __KPAGER_H + +#include <qwidget.h> +#include <qintdict.h> +#include <kmainwindow.h> +#include <kwin.h> +#include "kpagerIface.h" + +class KPager; +class QPopupMenu; + +class KPagerMainWindow : public KMainWindow, public virtual KPagerIface +{ + Q_OBJECT + +public: + KPagerMainWindow(QWidget *parent=0, const char *name=0); + ~KPagerMainWindow(); + + virtual void showAt(int x, int y); + virtual void toggleShow(int x, int y); + +public slots: + virtual void reallyClose(); + +protected: + bool queryClose(); + void showEvent(QShowEvent *ev); + + KPager *m_pPager; + class QTimer *timeout; + bool m_reallyClose; +}; + +class KPager : public QFrame +{ + Q_OBJECT + + friend class KPagerMainWindow; + +public: + KPager(KPagerMainWindow *parent=0, const char *name=0); + ~KPager(); + + class KWinModule *kwin() const { return m_winmodule; }; + void updateLayout(); + + void redrawDesktops(); + + void showPopupMenu( WId wid, QPoint pos); + + KWin::WindowInfo* info( WId win ); + + QSize sizeHint() const; + + enum LayoutTypes { Classical=0, Horizontal, Vertical }; + +public slots: + void configureDialog(); + + void slotActiveWindowChanged( WId win ); + void slotWindowAdded( WId ); + void slotWindowRemoved( WId ); + void slotWindowChanged( WId, unsigned int ); + void slotStackingOrderChanged(); + void slotDesktopNamesChanged(); + void slotNumberOfDesktopsChanged(int ndesktops); + void slotCurrentDesktopChanged(int); + + void slotGrabWindows(); + +protected slots: + void slotBackgroundChanged(int); + void clientPopupAboutToShow(); + void clientPopupActivated(int); + void desktopPopupAboutToShow(); + void sendToDesktop(int desk); + +protected: + enum WindowOperation { + MaximizeOp = 100, + IconifyOp, + StickyOp, + CloseOp + }; + +protected: + KWinModule *m_winmodule; + QValueList<class Desktop *> m_desktops; + + QIntDict<KWin::WindowInfo> m_windows; + WId m_activeWin; + + const QString lWidth(); + const QString lHeight(); + + LayoutTypes m_layoutType; + + class QGridLayout *m_layout; + KPopupMenu *m_mnu; + QPopupMenu *m_smnu, *m_dmnu; + KAction *m_quit_action; + KAction *m_prefs_action; + KWin::WindowInfo m_winfo; + bool m_showStickyOption; // To be removed after the message freeze + + QTimer *m_grabWinTimer; + int m_currentDesktop; + +public: + static const LayoutTypes c_defLayout; +}; + +#endif diff --git a/kpager/kpagerIface.h b/kpager/kpagerIface.h new file mode 100644 index 000000000..5288a21f3 --- /dev/null +++ b/kpager/kpagerIface.h @@ -0,0 +1,22 @@ +#ifndef _KPAGERIFACE_H_ +#define _KPAGERIFACE_H_ + +#include <dcopobject.h> + +class KPagerIface : virtual public DCOPObject +{ + K_DCOP + +k_dcop: +/** + * If it's closed, open the window at the specified location + */ + virtual void showAt(int x, int y)=0; + +/** + * Toggles the show/hide state of kpager + */ + virtual void toggleShow(int x, int y)=0; +}; +#endif + diff --git a/kpager/main.cpp b/kpager/main.cpp new file mode 100644 index 000000000..cf943f4f0 --- /dev/null +++ b/kpager/main.cpp @@ -0,0 +1,107 @@ +/************************************************************************** + + main.cpp - The main function for KPager + Copyright (C) 1998-2000 Antonio Larrosa Jimenez + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +***************************************************************************/ + +#include <kuniqueapplication.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kaboutdata.h> +#include <qcolor.h> +#include <kdebug.h> +#include <stdlib.h> +#include <qsessionmanager.h> + +#include "kpager.h" + +static KCmdLineOptions pagerOpts[] = +{ + { "hidden", I18N_NOOP("Create pager but keep the window hidden"), 0 }, + KCmdLineLastOption +}; + +bool closed_by_sm = false; + +class KPagerApplication : public KUniqueApplication +{ +public: + KPagerApplication() : KUniqueApplication() {} + + void commitData(QSessionManager& sm) { + if (mainWidget()->isHidden()) { + sm.setRestartHint( QSessionManager::RestartNever ); + return; + } + closed_by_sm = true; + KUniqueApplication::commitData( sm ); + closed_by_sm = false; + } + + int newInstance() { + mainWidget()->show(); + return 0; + } + +}; + +int main(int argc, char **argv) +{ + KAboutData *aboutdata = new KAboutData("kpager", "KPager", "1.5", + I18N_NOOP("Desktop Overview"), KAboutData::License_GPL, + "(C) 1998-2002, Antonio Larrosa Jimenez","", + "http://developer.kde.org/~larrosa/kpager.html"); + + aboutdata->addAuthor("Antonio Larrosa Jimenez", + I18N_NOOP("Original Developer/Maintainer"),"larrosa@kde.org", + "http://developer.kde.org/~larrosa/index.html"); + aboutdata->addAuthor("Matthias Elter", + I18N_NOOP("Developer"),"elter@kde.org", ""); + aboutdata->addAuthor("Matthias Ettrich", + I18N_NOOP("Developer"),"ettrich@kde.org", ""); + + KCmdLineArgs::init(argc, argv, aboutdata); + KCmdLineArgs::addCmdLineOptions(pagerOpts); + KUniqueApplication::addCmdLineOptions(); + + if (!KUniqueApplication::start()) + { + kdError() << "kpager is already running!" << endl; + return 0; + } + + + KApplication * app = new KPagerApplication; + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + KPagerMainWindow *kpager = new KPagerMainWindow(0,"KPager"); + kpager->setPlainCaption( i18n("Desktop Pager") ); + + + app->setMainWidget(kpager); + if (!args->isSet("hidden")) kpager->show(); + else kpager->hide(); + + int ret = app->exec(); + + delete app; + return ret; +} + diff --git a/kpager/uninstall.desktop b/kpager/uninstall.desktop new file mode 100644 index 000000000..e1e3e1732 --- /dev/null +++ b/kpager/uninstall.desktop @@ -0,0 +1,2 @@ +[Desktop Entry] +Hidden=true diff --git a/kpager/windowdrag.cpp b/kpager/windowdrag.cpp new file mode 100644 index 000000000..2f9c59cbd --- /dev/null +++ b/kpager/windowdrag.cpp @@ -0,0 +1,60 @@ +/************************************************************************* + + windowdrag.cpp - The windowDrag object, used to drag windows across + desktops + + Copyright (C) 1998,99,2000 Antonio Larrosa Jimenez <larrosa@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +*************************************************************************/ + +#include "windowdrag.h" + +PagerWindowDrag::PagerWindowDrag(WId w,int deltax,int deltay, int origdesk,QWidget *parent) + : QStoredDrag("application/x-kpager",parent,"windowdrag") +{ + QString tmp; + tmp.sprintf("%d %d %d %d", static_cast<int>(w), deltax, deltay, origdesk); + QByteArray data; + data.setRawData(tmp.latin1(),tmp.length()+1); + + setEncodedData(data); + data.resetRawData(tmp.latin1(),tmp.length()+1); +} + +PagerWindowDrag::~PagerWindowDrag() +{ +} + +bool PagerWindowDrag::canDecode (QDragMoveEvent *e) +{ + return e->provides("application/x-kpager"); +} + +bool PagerWindowDrag::decode( QDropEvent *e, WId &w,int &deltax,int &deltay,int &origdesk) +{ + QByteArray data=e->data("application/x-kpager"); + if (data.size()) + { + char *tmp=data.data(); + sscanf(tmp,"%lu %d %d %d", &w, &deltax, &deltay, &origdesk); + e->accept(); + return TRUE; + } + return FALSE; +} diff --git a/kpager/windowdrag.h b/kpager/windowdrag.h new file mode 100644 index 000000000..d1886ba68 --- /dev/null +++ b/kpager/windowdrag.h @@ -0,0 +1,41 @@ +/************************************************************************* + + windowdrag.h - The windowDrag object, used to drag windows across + desktops + Copyright (C) 1998,99,2000 Antonio Larrosa Jimenez + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Send comments and bug fixes to larrosa@kde.org + +*************************************************************************/ +#ifndef WINDOWDRAG_H +#define WINDOWDRAG_H + +#include <qdragobject.h> +#include <X11/Xlib.h> + +class PagerWindowDrag : public QStoredDrag +{ +public: + PagerWindowDrag(WId w,int deltax,int deltay,int origdesk,QWidget *parent); + virtual ~PagerWindowDrag(); + + static bool canDecode( QDragMoveEvent *e); + static bool decode ( QDropEvent *e, WId &w,int &deltax,int &deltay,int &origdesk); + +}; + +#endif |