From 3e43789786e19e0020f1a97d43dba4c3830c72dd Mon Sep 17 00:00:00 2001 From: Alexander Kellett Date: Mon, 1 Apr 2002 02:54:00 +0000 Subject: [PATCH] "wmaker-like" popup messages on desktop switch. svn path=/trunk/kdebase/kwin/; revision=146349 --- Makefile.am | 2 +- popupinfo.cpp | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++ popupinfo.h | 87 ++++++++++++++++++++++ workspace.cpp | 13 +++- workspace.h | 2 + 5 files changed, 297 insertions(+), 3 deletions(-) create mode 100644 popupinfo.cpp create mode 100644 popupinfo.h diff --git a/Makefile.am b/Makefile.am index ca3114d5f0..31281ee2ae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ lib_LTLIBRARIES = kwin.la # workspace.cpp has to be first in order not to break --enable-final kwin_la_SOURCES = workspace.cpp atoms.cpp client.cpp main.cpp \ tabbox.cpp options.cpp plugins.cpp events.cpp KWinInterface.skel \ - killwindow.cpp kwinbutton.cpp + popupinfo.cpp killwindow.cpp kwinbutton.cpp kwin_la_LIBADD = $(LIB_KDEUI) $(LIBXINERAMA) kwin_la_LDFLAGS = $(all_libraries) -module -avoid-version diff --git a/popupinfo.cpp b/popupinfo.cpp new file mode 100644 index 0000000000..88a43eaf3b --- /dev/null +++ b/popupinfo.cpp @@ -0,0 +1,196 @@ +/***************************************************************** +kwin - the KDE window manager + +Copyright (C) 1999, 2000 Matthias Ettrich +******************************************************************/ +//#define QT_CLEAN_NAMESPACE +#include "popupinfo.h" +#include "workspace.h" +#include "client.h" +#include +#include +#include +#include +#undef Bool // f**king X11 +#include +#include +#include +#include +#include +#include +#include +#include + +// specify externals before namespace + +extern QPixmap* kwin_get_menu_pix_hack(); + +using namespace KWinInternal; + +PopupInfo::PopupInfo( Workspace *ws, const char *name ) + : QWidget( 0, name, WStyle_Customize | WStyle_NoBorder ) +{ + no_tasks = i18n("*** No Tasks ***"); + m = DesktopMode; // init variables + wspace = ws; + reconfigure(); + reset(); + connect(&delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide())); +} + +PopupInfo::~PopupInfo() +{ +} + + +/*! + Sets the current mode to \a mode, either DesktopListMode or WindowsMode + + \sa mode() + */ +void PopupInfo::setMode( Mode mode ) +{ + m = mode; +} + + +/*! + Resets the tab box to display the active client in WindowsMode, or the + current desktop in DesktopListMode + */ +void PopupInfo::reset() +{ + QFont f = font(); + f.setBold( TRUE ); + f.setPointSize( 14 ); + setFont( f ); + + wmax = 0; + + desk = workspace()->currentDesktop(); + + QDesktopWidget* desktop = qApp->desktop(); + int screen = desktop->screenNumber( QCursor::pos() ); + QRect r = desktop->screenGeometry(screen); + + int w = QMIN( QMAX( wmax + 20, r.width()/3 ), r.width() ); + setGeometry( (r.width()-w)/2 + r.x(), + r.height()/2-fontMetrics().height()*2-10 + r.y(), + w, fontMetrics().height()*2 + 20 ); + + wmax = QMIN( wmax, width() - 12 ); +} + + +/*! + Returns the currently displayed client ( only works in WindowsMode ). + Returns 0 if no client is displayed. + */ +Client* PopupInfo::currentClient() +{ + if ( mode() != WindowsMode ) + return 0; + if (!workspace()->hasClient( client )) + return 0; + return client; +} + +/*! + Returns the currently displayed virtual desktop ( only works in + DesktopListMode ) + Returns -1 if no desktop is displayed. + */ +int PopupInfo::currentDesktop() +{ + if ( mode() == DesktopListMode || mode() == DesktopMode ) + return desk; + else + return -1; +} + + +/*! + Reimplemented to raise the tab box as well + */ +void PopupInfo::showEvent( QShowEvent* ) +{ +} + + +/*! + hide the icon box if necessary + */ +void PopupInfo::hideEvent( QHideEvent* ) +{ +} + + +/*! + Paints the tab box + */ +void PopupInfo::paintEvent( QPaintEvent* ) +{ + QPainter p( this ); +#if QT_VERSION < 300 + style().drawPanel( &p, 0, 0, width(), height(), colorGroup(), FALSE ); + style().drawPanel( &p, 4, 4, width()-8, height()-8, colorGroup(), TRUE ); +#else + style().drawPrimitive( QStyle::PE_Panel, &p, QRect( 0, 0, width(), height() ), + colorGroup(), QStyle::Style_Default ); + style().drawPrimitive( QStyle::PE_Panel, &p, QRect( 4, 4, width()-8, height()-8 ), + colorGroup(), QStyle::Style_Sunken ); +#endif + paintContents(); +} + + +/*! + Paints the contents of the tab box. Used in paintEvent() and + whenever the contents changes. + */ +void PopupInfo::paintContents() +{ + QPixmap* menu_pix = kwin_get_menu_pix_hack(); + QPainter p( this ); + QRect r( 6, 6, width()-12, height()-32 ); + p.fillRect( r, colorGroup().brush( QColorGroup::Background ) ); + + p.drawText( r, AlignCenter, workspace()->desktopName(desk) ); + int x = (width() - workspace()->numberOfDesktops() * 20 )/2; + int y = height() - 16; + QFont f( font() ); + f.setPointSize( 12 ); + f.setBold( FALSE ); + p.setFont(f ); +} + +void PopupInfo::hide() +{ + delayedHideTimer.stop(); + QWidget::hide(); + QApplication::syncX(); + XEvent otherEvent; + while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) ) + ; +} + + +void PopupInfo::reconfigure() +{ + KConfig * c(KGlobal::config()); + c->setGroup("PopupInfo"); + m_show = c->readNumEntry("Show", false); + m_delayTime = c->readNumEntry("DelayTime", 250); +} + +void PopupInfo::showInfo() +{ + if (m_show) { + reset(); + show(); + raise(); + delayedHideTimer.start(m_delayTime, true); + } +} + +#include "popupinfo.moc" diff --git a/popupinfo.h b/popupinfo.h new file mode 100644 index 0000000000..e617c352ff --- /dev/null +++ b/popupinfo.h @@ -0,0 +1,87 @@ +/***************************************************************** +kwin - the KDE window manager + +Copyright (C) 1999, 2000 Matthias Ettrich +******************************************************************/ +#ifndef POPUPINFO_H +#define POPUPINFO_H +#include +#include +#include + +class QLabel; + +namespace KWinInternal { + +class Workspace; +class Client; +typedef QValueList ClientList; + +class PopupInfo : public QWidget +{ + Q_OBJECT +public: + PopupInfo( Workspace *ws, const char *name=0 ); + ~PopupInfo(); + + Client* currentClient(); + int currentDesktop(); + + // DesktopMode and WindowsMode are based on the order in which the desktop + // or window were viewed. + // DesktopListMode lists them in the order created. + enum Mode { DesktopMode, DesktopListMode, WindowsMode }; + void setMode( Mode mode ); + Mode mode() const; + + void reset(); + void hide(); + void showInfo(); + + Workspace* workspace() const; + + void reconfigure(); + +protected: + void paintEvent( QPaintEvent* ); + void showEvent( QShowEvent* ); + void hideEvent( QHideEvent* ); + void paintContents(); + +private: + Client* client; + Mode m; + Workspace* wspace; + ClientList clients; + int desk; + QLabel* icon; + int wmax; + QTimer delayedHideTimer; + QString no_tasks; + bool options_traverse_all; + int m_delayTime; + bool m_show; +}; + + +/*! + Returns the tab box' workspace + */ +inline Workspace* PopupInfo::workspace() const +{ + return wspace; +} + +/*! + Returns the current mode, either DesktopListMode or WindowsMode + + \sa setMode() + */ +inline PopupInfo::Mode PopupInfo::mode() const +{ + return m; +} + +}; + +#endif diff --git a/workspace.cpp b/workspace.cpp index 33401ba79d..7539d0092e 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -28,6 +28,7 @@ Copyright (C) 1999, 2000 Matthias Ettrich #include "workspace.h" #include "client.h" #include "tabbox.h" +#include "popupinfo.h" #include "atoms.h" #include "plugins.h" #include "events.h" @@ -272,6 +273,7 @@ Workspace::Workspace( bool restore ) mouse_emulation (false), focus_change (true), tab_box (0), + popupinfo (0), popup (0), desk_popup (0), keys (0), @@ -331,6 +333,7 @@ Workspace::Workspace( bool restore ) initShortcuts(); tab_box = new TabBox( this ); + popupinfo = new PopupInfo( this ); init(); @@ -456,6 +459,7 @@ Workspace::~Workspace() } delete desktop_widget; delete tab_box; + delete popupinfo; delete popup; if ( root == qt_xrootwin() ) XDeleteProperty(qt_xdisplay(), qt_xrootwin(), atoms->kwin_running); @@ -2022,6 +2026,7 @@ void Workspace::slotReconfigure() KGlobal::config()->reparseConfiguration(); options->reload(); tab_box->reconfigure(); + popupinfo->reconfigure(); readShortcuts(); mgr->updatePlugin(); @@ -2194,6 +2199,9 @@ void Workspace::raiseClient( Client* c ) if ( tab_box->isVisible() ) tab_box->raise(); + if ( popupinfo->isVisible() ) + popupinfo->raise(); + raiseElectricBorders(); } @@ -2862,7 +2870,8 @@ void Workspace::slotSwitchDesktopDown(){ void Workspace::slotSwitchToDesktop( int i ) { - setCurrentDesktop( i ); + popupinfo->showInfo(); + setCurrentDesktop( i ); } @@ -3182,7 +3191,7 @@ void Workspace::slotWindowOperations() */ void Workspace::slotWindowClose() { - if ( tab_box->isVisible() ) + if ( tab_box->isVisible() || popupinfo->isVisible() ) return; performWindowOperation( popup_client, Options::CloseOp ); } diff --git a/workspace.h b/workspace.h index 22b738626b..b3256b4b02 100644 --- a/workspace.h +++ b/workspace.h @@ -28,6 +28,7 @@ namespace KWinInternal { class Client; class TabBox; +class PopupInfo; class RootInfo; class PluginMgr; @@ -403,6 +404,7 @@ private: bool focus_change; TabBox* tab_box; + PopupInfo* popupinfo; QPopupMenu *popup; QPopupMenu *desk_popup;