kwin Library API Documentation

workspace.h

00001 /*****************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
00006 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
00007 
00008 You can Freely distribute this program under the GNU General Public
00009 License. See the file "COPYING" for the exact licensing terms.
00010 ******************************************************************/
00011 
00012 #ifndef KWIN_WORKSPACE_H
00013 #define KWIN_WORKSPACE_H
00014 
00015 #include <qtimer.h>
00016 #include <kshortcut.h>
00017 #include <qcursor.h>
00018 #include <netwm.h>
00019 
00020 #include "KWinInterface.h"
00021 #include "utils.h"
00022 #include "kdecoration.h"
00023 #include "sm.h"
00024 
00025 #include <X11/Xlib.h>
00026 
00027 class QPopupMenu;
00028 class KConfig;
00029 class KGlobalAccel;
00030 class KStartupInfo;
00031 class KStartupInfoData;
00032 
00033 namespace KWinInternal
00034 {
00035 
00036 class Client;
00037 class TabBox;
00038 class PopupInfo;
00039 class RootInfo;
00040 class PluginMgr;
00041 class Placement;
00042 
00043 class SystemTrayWindow
00044     {
00045     public:
00046         SystemTrayWindow()
00047             : win(0),winFor(0)
00048             {}
00049         SystemTrayWindow( WId w )
00050             : win(w),winFor(0)
00051             {}
00052         SystemTrayWindow( WId w, WId wf  )
00053             : win(w),winFor(wf)
00054             {}
00055 
00056         bool operator==( const SystemTrayWindow& other )
00057             { return win == other.win; }
00058         WId win;
00059         WId winFor;
00060     };
00061 
00062 typedef QValueList<SystemTrayWindow> SystemTrayWindowList;
00063 
00064 class Workspace : public QObject, public KWinInterface, public KDecorationDefines
00065     {
00066     Q_OBJECT
00067     public:
00068         Workspace( bool restore = FALSE );
00069         virtual ~Workspace();
00070 
00071         static Workspace * self() { return _self; }
00072 
00073         bool workspaceEvent( XEvent * );
00074 
00075         KDecoration* createDecoration( KDecorationBridge* bridge );
00076 
00077         bool hasClient( const Client * );
00078 
00079         template< typename T > Client* findClient( T predicate );
00080         template< typename T1, typename T2 > void forEachClient( T1 procedure, T2 predicate );
00081         template< typename T > void forEachClient( T procedure );
00082 
00083         Group* findGroup( Window leader ) const;
00084         void addGroup( Group* group, allowed_t );
00085         void removeGroup( Group* group, allowed_t );
00086         Group* findClientLeaderGroup( const Client* c ) const;
00087 
00088         QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const;
00089         QRect clientArea( clientAreaOption, const Client* c ) const;
00090 
00094         void killWindowId( Window window);
00095 
00096         void killWindow() { slotKillWindow(); }
00097 
00098         WId rootWin() const;
00099 
00100         bool initializing() const;
00101 
00106         Client* activeClient() const;
00107         // Client that was activated, but it's not yet really activeClient(), because
00108         // we didn't process yet the matching FocusIn event. Used mostly in focus
00109         // stealing prevention code.
00110         Client* mostRecentlyActivatedClient() const;
00111 
00112         void setActiveClient( Client*, allowed_t );
00113         void activateClient( Client*, bool force = FALSE  );
00114         void requestFocus( Client* c, bool force = FALSE );
00115         bool allowClientActivation( const Client* c, Time time = -1U, bool focus_in = false,
00116             bool session_active = false );
00117         void restoreFocus();
00118         void gotFocusIn( const Client* );
00119         bool fakeRequestedActivity( Client* c );
00120         void unfakeActivity( Client* c );
00121         void activateNextClient( Client* c );
00122         bool focusChangeEnabled() { return block_focus == 0; }
00123 
00124         void updateColormap();
00125 
00129         void setClientIsMoving( Client *c );
00130 
00131         void place( Client *c, QRect& area );
00132         void placeSmart( Client* c, const QRect& area );
00133 
00134         QPoint adjustClientPosition( Client* c, QPoint pos );
00135         void raiseClient( Client* c );
00136         void lowerClient( Client* c );
00137         void raiseClientRequest( Client* c );
00138         void lowerClientRequest( Client* c );
00139         void restackClientUnderActive( Client* );
00140         void updateClientLayer( Client* c );
00141         void raiseOrLowerClient( Client * );
00142         void reconfigure();
00143 
00144         void clientHidden( Client*  );
00145         void clientAttentionChanged( Client* c, bool set );
00146 
00147         void clientMoved(const QPoint &pos, Time time);
00148 
00152         int currentDesktop() const;
00156         int numberOfDesktops() const;
00157         void setNumberOfDesktops( int n );
00158 
00159         QWidget* desktopWidget();
00160 
00161     // for TabBox
00162         Client* nextFocusChainClient(Client*) const;
00163         Client* previousFocusChainClient(Client*) const;
00164         Client* nextStaticClient(Client*) const;
00165         Client* previousStaticClient(Client*) const;
00166         int nextDesktopFocusChain( int iDesktop ) const;
00167         int previousDesktopFocusChain( int iDesktop ) const;
00168 
00173         const ClientList& stackingOrder() const;
00174 
00175         ClientList ensureStackingOrder( const ClientList& clients ) const;
00176 
00177         Client* topClientOnDesktop( int desktop, bool unconstrained = false ) const;
00178         Client* findDesktop( bool topmost, int desktop ) const;
00179         void sendClientToDesktop( Client* c, int desktop, bool dont_activate );
00180 
00181     // KDE4 remove me - and it's also in the DCOP interface :(
00182         void showWindowMenuAt( unsigned long id, int x, int y );
00183 
00188         void showWindowMenu( int x, int y, Client* cl );
00189         void showWindowMenu( QPoint pos, Client* cl );
00190 
00191         void updateMinimizedOfTransients( Client* );
00192         void updateOnAllDesktopsOfTransients( Client* );
00193         void checkTransients( Window w );
00194 
00195         void performWindowOperation( Client* c, WindowOperation op );
00196 
00197         void storeSession( KConfig* config, SMSavePhase phase );
00198 
00199         SessionInfo* takeSessionInfo( Client* );
00200 
00201 
00202     // dcop interface
00203         void cascadeDesktop();
00204         void unclutterDesktop();
00205         void doNotManage(QString);
00206         bool setCurrentDesktop( int new_desktop );
00207         void nextDesktop();
00208         void previousDesktop();
00209         void circulateDesktopApplications();
00210 
00211         QString desktopName( int desk ) const;
00212         void setDesktopLayout(int o, int x, int y);
00213 
00214         bool isNotManaged( const QString& title );  // ### setter or getter ?
00215 
00216         void sendPingToWindow( Window w, Time timestamp ); // called from Client::pingWindow()
00217 
00218     // only called from Client::destroyClient() or Client::releaseWindow()
00219         void removeClient( Client*, allowed_t );
00220 
00221         bool checkStartupNotification( Window w, KStartupInfoData& data );
00222 
00223         void focusToNull(); // SELI public?
00224 
00225         void sessionSaveStarted();
00226         void sessionSaveDone();
00227         void setWasUserInteraction();
00228         bool sessionSaving() const;
00229 
00230         bool managingTopMenus() const;
00231         int topMenuHeight() const;
00232 
00233         int packPositionLeft( const Client* cl, int oldx, bool left_edge ) const;
00234         int packPositionRight( const Client* cl, int oldx, bool right_edge ) const;
00235         int packPositionUp( const Client* cl, int oldy, bool top_edge ) const;
00236         int packPositionDown( const Client* cl, int oldy, bool bottom_edge ) const;
00237 
00238     public slots:
00239         void refresh();
00240     // keybindings
00241         void slotSwitchDesktopNext();
00242         void slotSwitchDesktopPrevious();
00243         void slotSwitchDesktopRight();
00244         void slotSwitchDesktopLeft();
00245         void slotSwitchDesktopUp();
00246         void slotSwitchDesktopDown();
00247 
00248         void slotSwitchToDesktop( int );
00249     //void slotSwitchToWindow( int );
00250         void slotWindowToDesktop( int );
00251     //void slotWindowToListPosition( int );
00252 
00253         void slotWindowMaximize();
00254         void slotWindowMaximizeVertical();
00255         void slotWindowMaximizeHorizontal();
00256         void slotWindowMinimize();
00257         void slotWindowShade();
00258         void slotWindowRaise();
00259         void slotWindowLower();
00260         void slotWindowRaiseOrLower();
00261         void slotActivateAttentionWindow();
00262         void slotWindowPackLeft();
00263         void slotWindowPackRight();
00264         void slotWindowPackUp();
00265         void slotWindowPackDown();
00266         void slotWindowGrowHorizontal();
00267         void slotWindowGrowVertical();
00268         void slotWindowShrinkHorizontal();
00269         void slotWindowShrinkVertical();
00270 
00271         void slotWalkThroughDesktops();
00272         void slotWalkBackThroughDesktops();
00273         void slotWalkThroughDesktopList();
00274         void slotWalkBackThroughDesktopList();
00275         void slotWalkThroughWindows();
00276         void slotWalkBackThroughWindows();
00277 
00278         void slotWindowOperations();
00279         void slotWindowClose();
00280         void slotWindowMove();
00281         void slotWindowResize();
00282         void slotWindowAbove();
00283         void slotWindowBelow();
00284         void slotWindowOnAllDesktops();
00285         void slotWindowFullScreen();
00286         void slotWindowNoBorder();
00287 
00288         void slotWindowToNextDesktop();
00289         void slotWindowToPreviousDesktop();
00290 
00291         void slotMouseEmulation();
00292 
00293         void slotSettingsChanged( int category );
00294 
00295         void slotReconfigure();
00296 
00297         void slotKillWindow();
00298 
00299         void slotGrabWindow();
00300         void slotGrabDesktop();
00301 
00302         void updateClientArea();
00303 
00304     private slots:
00305         void desktopPopupAboutToShow();
00306         void clientPopupAboutToShow();
00307         void sendToDesktop( int );
00308         void clientPopupActivated( int );
00309         void configureWM();
00310         void desktopResized();
00311         void slotUpdateToolWindows();
00312         void lostTopMenuSelection();
00313         void lostTopMenuOwner();
00314 
00315     protected:
00316         bool keyPressMouseEmulation( XKeyEvent& ev );
00317         bool netCheck( XEvent* e );
00318 
00319     private:
00320         void init();
00321         void initShortcuts();
00322         void readShortcuts();
00323         void initDesktopPopup();
00324 
00325         bool startKDEWalkThroughWindows();
00326         bool startWalkThroughDesktops( int mode ); // TabBox::Mode::DesktopMode | DesktopListMode
00327         bool startWalkThroughDesktops();
00328         bool startWalkThroughDesktopList();
00329         void KDEWalkThroughWindows( bool forward );
00330         void CDEWalkThroughWindows( bool forward );
00331         void walkThroughDesktops( bool forward );
00332         void KDEOneStepThroughWindows( bool forward );
00333         void oneStepThroughDesktops( bool forward, int mode ); // TabBox::Mode::DesktopMode | DesktopListMode
00334         void oneStepThroughDesktops( bool forward );
00335         void oneStepThroughDesktopList( bool forward );
00336 
00337         void updateStackingOrder( bool propagate_new_clients = false );
00338         void propagateClients( bool propagate_new_clients ); // called only from updateStackingOrder
00339         ClientList constrainedStackingOrder();
00340         void raiseClientWithinApplication( Client* c );
00341         void lowerClientWithinApplication( Client* c );
00342         bool allowFullClientRaising( const Client* c );
00343         bool keepTransientAbove( const Client* mainwindow, const Client* transient );
00344         void blockStackingUpdates( bool block );
00345         void updateCurrentTopMenu();
00346         void addTopMenu( Client* c );
00347         void removeTopMenu( Client* c );
00348         void setupTopMenuHandling();
00349         void updateTopMenuGeometry( Client* c = NULL );
00350         void updateToolWindows( bool also_hide );
00351 
00352     // this is the right way to create a new client
00353         Client* createClient( Window w, bool is_mapped );
00354         void addClient( Client* c, allowed_t );
00355 
00356         Window findSpecialEventWindow( XEvent* e );
00357 
00358         void randomPlacement(Client* c);
00359         void smartPlacement(Client* c);
00360         void cascadePlacement(Client* c, bool re_init = false);
00361 
00362         bool addSystemTrayWin( WId w );
00363         bool removeSystemTrayWin( WId w, bool check );
00364         void propagateSystemTrayWins();
00365         SystemTrayWindow findSystemTrayWin( WId w );
00366 
00367     // desktop names and number of desktops
00368         void loadDesktopSettings();
00369         void saveDesktopSettings();
00370 
00371     // mouse emulation
00372         WId getMouseEmulationWindow();
00373         enum MouseEmulation { EmuPress, EmuRelease, EmuMove };
00374         unsigned int sendFakedMouseEvent( QPoint pos, WId win, MouseEmulation type, int button, unsigned int state ); // returns the new state
00375 
00376         void tabBoxKeyPress( const KKeyNative& keyX );
00377         void tabBoxKeyRelease( const XKeyEvent& ev );
00378 
00379     // electric borders
00380         void createBorderWindows();
00381         void destroyBorderWindows();
00382         void electricBorder(XEvent * e);
00383         void raiseElectricBorders();
00384 
00385     // ------------------
00386     
00387         void helperDialog( const QString& message, const Client* c );
00388 
00389         void calcDesktopLayout(int &x, int &y);
00390 
00391         QPopupMenu* clientPopup();
00392 
00393         void updateClientArea( bool force );
00394 
00395         SystemTrayWindowList systemTrayWins;
00396 
00397         int current_desktop;
00398         int number_of_desktops;
00399         QMemArray<int> desktop_focus_chain;
00400 
00401         Client* popup_client;
00402 
00403         void loadSessionInfo();
00404 
00405         QWidget* desktop_widget;
00406 
00407         QPtrList<SessionInfo> session;
00408         QPtrList<SessionInfo> fakeSession;
00409         void loadFakeSessionInfo();
00410         void storeFakeSessionInfo( Client* c );
00411         void writeFakeSessionInfo();
00412         static const char* windowTypeToTxt( NET::WindowType type );
00413         static NET::WindowType txtToWindowType( const char* txt );
00414         static bool sessionInfoWindowTypeMatch( Client* c, SessionInfo* info );
00415 
00416         Client* active_client;
00417         Client* last_active_client;
00418         Client* most_recently_raised; // used _only_ by raiseOrLowerClient()
00419         Client* movingClient;
00420 
00421         ClientList clients;
00422         ClientList desktops;
00423 
00424         ClientList unconstrained_stacking_order;
00425         ClientList stacking_order;
00426         ClientList focus_chain;
00427         ClientList should_get_focus; // last is most recent
00428         ClientList attention_chain;
00429 
00430         GroupList groups;
00431 
00432         bool was_user_interaction;
00433         bool session_saving;
00434         int session_active_client;
00435         int session_desktop;
00436 
00437         bool control_grab;
00438         bool tab_grab;
00439     //KKeyNative walkThroughDesktopsKeycode, walkBackThroughDesktopsKeycode;
00440     //KKeyNative walkThroughDesktopListKeycode, walkBackThroughDesktopListKeycode;
00441     //KKeyNative walkThroughWindowsKeycode, walkBackThroughWindowsKeycode;
00442         KShortcut cutWalkThroughDesktops, cutWalkThroughDesktopsReverse;
00443         KShortcut cutWalkThroughDesktopList, cutWalkThroughDesktopListReverse;
00444         KShortcut cutWalkThroughWindows, cutWalkThroughWindowsReverse;
00445         bool mouse_emulation;
00446         unsigned int mouse_emulation_state;
00447         WId mouse_emulation_window;
00448         int block_focus;
00449 
00450         TabBox* tab_box;
00451         PopupInfo* popupinfo;
00452 
00453         QPopupMenu *popup;
00454         QPopupMenu *advanced_popup;
00455         QPopupMenu *desk_popup;
00456         int desk_popup_index;
00457 
00458         KGlobalAccel *keys;
00459         WId root;
00460 
00461         PluginMgr *mgr;
00462 
00463         RootInfo *rootInfo;
00464         QWidget* supportWindow;
00465 
00466     // swallowing
00467         QStringList doNotManageList;
00468 
00469     // colormap handling
00470         Colormap default_colormap;
00471         Colormap installed_colormap;
00472 
00473     // Timer to collect requests for 'reconfigure'
00474         QTimer reconfigureTimer;
00475 
00476         QTimer updateToolWindowsTimer;
00477 
00478         static Workspace *_self;
00479 
00480         bool workspaceInit;
00481 
00482         KStartupInfo* startup;
00483 
00484         bool electric_have_borders;
00485         int electric_current_border;
00486         WId electric_top_border;
00487         WId electric_bottom_border;
00488         WId electric_left_border;
00489         WId electric_right_border;
00490         int electricLeft;
00491         int electricRight;
00492         int electricTop;
00493         int electricBottom;
00494         Time electric_time_first;
00495         Time electric_time_last;
00496         QPoint electric_push_point;
00497 
00498         Qt::Orientation layoutOrientation;
00499         int layoutX;
00500         int layoutY;
00501 
00502         Placement *initPositioning;
00503 
00504         QRect* workarea; //  array of workareas for virtual desktops
00505 
00506         bool managing_topmenus;
00507         KSelectionOwner* topmenu_selection;
00508         KSelectionWatcher* topmenu_watcher;
00509         ClientList topmenus; // doesn't own them
00510         mutable int topmenu_height;
00511         QWidget* topmenu_space;
00512 
00513         int set_active_client_recursion;
00514         int block_stacking_updates; // when >0, stacking updates are temporarily disabled
00515         bool blocked_propagating_new_clients; // propagate also new clients after enabling stacking updates?
00516         friend class StackingUpdatesBlocker;
00517     };
00518 
00519 // helper for Workspace::blockStackingUpdates() being called in pairs (true/false)
00520 class StackingUpdatesBlocker
00521     {
00522     public:
00523         StackingUpdatesBlocker( Workspace* w )
00524             : ws( w ) { ws->blockStackingUpdates( true ); }
00525         ~StackingUpdatesBlocker()
00526             { ws->blockStackingUpdates( false ); }
00527     private:
00528         Workspace* ws;
00529     };
00530 
00531 // NET WM Protocol handler class
00532 class RootInfo : public NETRootInfo2
00533     {
00534     private:
00535         typedef KWinInternal::Client Client;  // because of NET::Client
00536     public:
00537         RootInfo( Workspace* ws, Display *dpy, Window w, const char *name, unsigned long pr[], int pr_num, int scr= -1);
00538     protected:
00539         virtual void changeNumberOfDesktops(int n);
00540         virtual void changeCurrentDesktop(int d);
00541 //    virtual void changeActiveWindow(Window w); the extended version is used
00542         virtual void changeActiveWindow(Window w,NET::RequestSource src, Time timestamp, Window active_window);
00543         virtual void closeWindow(Window w);
00544         virtual void moveResize(Window w, int x_root, int y_root, unsigned long direction);
00545         virtual void moveResizeWindow(Window w, int flags, int x, int y, int width, int height );
00546         virtual void gotPing(Window w, Time timestamp);
00547         virtual void restackWindow(Window w, Window above, int detail);
00548     private:
00549         Workspace* workspace;
00550     };
00551 
00552 
00553 inline WId Workspace::rootWin() const
00554     {
00555     return root;
00556     }
00557 
00558 inline bool Workspace::initializing() const
00559     {
00560     return workspaceInit;
00561     }
00562 
00563 inline Client* Workspace::activeClient() const
00564     {
00565     return active_client;
00566     }
00567 
00568 inline Client* Workspace::mostRecentlyActivatedClient() const
00569     {
00570     return should_get_focus.count() > 0 ? should_get_focus.last() : active_client;
00571     }
00572 
00573 inline int Workspace::currentDesktop() const
00574     {
00575     return current_desktop;
00576     }
00577 
00578 inline int Workspace::numberOfDesktops() const
00579     {
00580     return number_of_desktops;
00581     }
00582 
00583 inline void Workspace::addGroup( Group* group, allowed_t )
00584     {
00585     groups.append( group );
00586     }
00587 
00588 inline void Workspace::removeGroup( Group* group, allowed_t )
00589     {
00590     groups.remove( group );
00591     }
00592 
00593 inline const ClientList& Workspace::stackingOrder() const
00594     {
00595 // TODO    Q_ASSERT( block_stacking_updates == 0 );
00596     return stacking_order;
00597     }
00598 
00599 inline void Workspace::showWindowMenu(QPoint pos, Client* cl)
00600     {
00601     showWindowMenu(pos.x(), pos.y(), cl);
00602     }
00603 
00604 inline
00605 void Workspace::setWasUserInteraction()
00606     {
00607     was_user_interaction = true;
00608     }
00609 
00610 inline
00611 bool Workspace::managingTopMenus() const
00612     {
00613     return managing_topmenus;
00614     }
00615 
00616 inline void Workspace::sessionSaveStarted()
00617     {
00618     session_saving = true;
00619     }
00620 
00621 inline void Workspace::sessionSaveDone()
00622     {
00623     session_saving = false;
00624     }
00625 
00626 inline bool Workspace::sessionSaving() const
00627     {
00628     return session_saving;
00629     }
00630 
00631 template< typename T >
00632 inline Client* Workspace::findClient( T predicate )
00633     {
00634     if( Client* ret = findClientInList( clients, predicate ))
00635         return ret;
00636     if( Client* ret = findClientInList( desktops, predicate ))
00637         return ret;
00638     return NULL;
00639     }
00640 
00641 template< typename T1, typename T2 >
00642 inline void Workspace::forEachClient( T1 procedure, T2 predicate )
00643     {
00644     for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it)
00645         if ( predicate( const_cast< const Client* >( *it)))
00646             procedure( *it );
00647     for ( ClientList::ConstIterator it = desktops.begin(); it != desktops.end(); ++it)
00648         if ( predicate( const_cast< const Client* >( *it)))
00649             procedure( *it );
00650     }
00651 
00652 template< typename T >
00653 inline void Workspace::forEachClient( T procedure )
00654     {
00655     return forEachClient( procedure, TruePredicate());
00656     }
00657 
00658 KWIN_COMPARE_PREDICATE( ClientMatchPredicate, const Client*, cl == value );
00659 inline bool Workspace::hasClient( const Client* c )
00660     {
00661     return findClient( ClientMatchPredicate( c ));
00662     }
00663 
00664 } // namespace
00665 
00666 #endif
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 5 04:41:15 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003