add more spacing
[personal-kdebase.git] / workspace / kwin / workspace.h
blob1157689d805dc0b96e03e19bf42584d57b5b78c3
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #ifndef KWIN_WORKSPACE_H
23 #define KWIN_WORKSPACE_H
25 #include <QTimer>
26 #include <QVector>
27 #include <kshortcut.h>
28 #include <QCursor>
29 #include <netwm.h>
30 #include <kxmessages.h>
31 #include <QDateTime>
32 #include <kmanagerselection.h>
34 #include "plugins.h"
35 #include "utils.h"
36 #include "kdecoration.h"
37 #include "kdecorationfactory.h"
38 #include "sm.h"
40 #include <X11/Xlib.h>
42 // TODO: Cleanup the order of things in this .h file
44 class QMenu;
45 class KConfig;
46 class KActionCollection;
47 class KStartupInfo;
48 class KStartupInfoId;
49 class KStartupInfoData;
50 class QSlider;
51 class QPushButton;
53 namespace KWin
56 class Client;
57 class TabBox;
58 class PopupInfo;
59 class RootInfo;
60 class PluginMgr;
61 class Placement;
62 class Rules;
63 class WindowRules;
65 class Workspace : public QObject, public KDecorationDefines
67 Q_OBJECT
68 public:
69 Workspace( bool restore = false );
70 virtual ~Workspace();
72 static Workspace* self() { return _self; }
74 bool workspaceEvent( XEvent* );
75 bool workspaceEvent( QEvent* );
77 KDecoration* createDecoration( KDecorationBridge* bridge );
79 bool hasClient( const Client* );
81 template<typename T> Client* findClient( T predicate ) const;
82 template<typename T1, typename T2> void forEachClient( T1 procedure, T2 predicate );
83 template<typename T> void forEachClient( T procedure );
84 template<typename T> Unmanaged* findUnmanaged( T predicate ) const;
85 template<typename T1, typename T2> void forEachUnmanaged( T1 procedure, T2 predicate );
86 template<typename T> void forEachUnmanaged( T procedure );
88 QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const;
89 QRect clientArea( clientAreaOption, const Client* c ) const;
90 QRect clientArea( clientAreaOption, int screen, int desktop ) const;
92 /**
93 * @internal
95 void killWindowId( Window window);
97 void killWindow()
98 { slotKillWindow(); }
100 bool initializing() const;
103 * Returns the active client, i.e. the client that has the focus (or None
104 * if no client has the focus)
106 Client* activeClient() const;
108 * Client that was activated, but it's not yet really activeClient(), because
109 * we didn't process yet the matching FocusIn event. Used mostly in focus
110 * stealing prevention code.
112 Client* mostRecentlyActivatedClient() const;
114 void activateClient( Client*, bool force = false );
115 void requestFocus( Client* c, bool force = false );
116 void takeActivity( Client* c, int flags, bool handled ); // Flags are ActivityFlags
117 void handleTakeActivity( Client* c, Time timestamp, int flags ); // Flags are ActivityFlags
118 bool allowClientActivation( const Client* c, Time time = -1U, bool focus_in = false,
119 bool ignore_desktop = false );
120 void restoreFocus();
121 void gotFocusIn( const Client* );
122 void setShouldGetFocus( Client* );
123 bool fakeRequestedActivity( Client* c );
124 void unfakeActivity( Client* c );
125 bool activateNextClient( Client* c );
126 bool focusChangeEnabled()
127 { return block_focus == 0; }
129 void updateColormap();
132 * Indicates that the client c is being moved around by the user.
134 void setClientIsMoving( Client* c );
136 void place( Client* c, QRect& area );
137 void placeSmart( Client* c, const QRect& area );
139 QPoint adjustClientPosition( Client* c, QPoint pos, bool unrestricted );
140 QRect adjustClientSize( Client* c, QRect moveResizeGeom, int mode );
141 void raiseClient( Client* c, bool nogroup = false );
142 void lowerClient( Client* c, bool nogroup = false );
143 void raiseClientRequest( Client* c, NET::RequestSource src, Time timestamp );
144 void lowerClientRequest( Client* c, NET::RequestSource src, Time timestamp );
145 void restackClientUnderActive( Client* );
146 void updateClientLayer( Client* c );
147 void raiseOrLowerClient( Client* );
148 void restoreSessionStackingOrder( Client* c );
149 void updateStackingOrder( bool propagate_new_clients = false );
150 void forceRestacking();
152 void clientHidden( Client* );
153 void clientAttentionChanged( Client* c, bool set );
155 void checkElectricBorder(const QPoint& pos, Time time);
156 void reserveElectricBorder( ElectricBorder border );
157 void unreserveElectricBorder( ElectricBorder border );
158 void reserveElectricBorderSwitching( bool reserve );
161 * Returns the current virtual desktop of this workspace
163 int currentDesktop() const;
165 * Returns the number of virtual desktops of this workspace
167 int numberOfDesktops() const;
168 void setNumberOfDesktops( int n );
169 void calcDesktopLayout( int* x, int* y, Qt::Orientation* orientation ) const;
170 int desktopToRight( int desktop, bool wrap ) const;
171 int desktopToLeft( int desktop, bool wrap ) const;
172 int desktopUp( int desktop, bool wrap ) const;
173 int desktopDown( int desktop, bool wrap ) const;
175 int activeScreen() const;
176 int numScreens() const;
177 void checkActiveScreen( const Client* c );
178 void setActiveScreenMouse( const QPoint& mousepos );
179 QRect screenGeometry( int screen ) const;
180 int screenNumber( const QPoint& pos ) const;
182 // Tab box
183 Client* currentTabBoxClient() const;
184 ClientList currentTabBoxClientList() const;
185 int currentTabBoxDesktop() const;
186 QList<int> currentTabBoxDesktopList() const;
187 void setTabBoxClient( Client* );
188 void setTabBoxDesktop( int );
189 Client* nextClientFocusChain( Client* ) const;
190 Client* previousClientFocusChain( Client* ) const;
191 Client* nextClientStatic( Client* ) const;
192 Client* previousClientStatic( Client* ) const;
193 int nextDesktopFocusChain( int iDesktop ) const;
194 int previousDesktopFocusChain( int iDesktop ) const;
195 int nextDesktopStatic( int iDesktop ) const;
196 int previousDesktopStatic( int iDesktop ) const;
197 void refTabBox();
198 void unrefTabBox();
199 void closeTabBox();
202 * Returns the list of clients sorted in stacking order, with topmost client
203 * at the last position
205 const ClientList& stackingOrder() const;
206 ToplevelList xStackingOrder() const;
207 ClientList ensureStackingOrder( const ClientList& clients ) const;
209 Client* topClientOnDesktop( int desktop, int screen, bool unconstrained = false,
210 bool only_normal = true ) const;
211 Client* findDesktop( bool topmost, int desktop ) const;
212 void sendClientToDesktop( Client* c, int desktop, bool dont_activate );
213 void windowToPreviousDesktop( Client* c );
214 void windowToNextDesktop( Client* c );
215 void sendClientToScreen( Client* c, int screen );
217 // KDE4 remove me - And it's also in the DCOP interface :(
218 void showWindowMenuAt( unsigned long id, int x, int y );
220 void loadEffect( const QString& name );
221 void toggleEffect( const QString& name );
222 void reconfigureEffect( const QString& name );
223 void unloadEffect( const QString& name );
225 QStringList loadedEffects() const;
226 QStringList listOfEffects() const;
230 * Shows the menu operations menu for the client and makes it active if
231 * it's not already.
233 void showWindowMenu( const QRect& pos, Client* cl );
235 * Backwards compatibility.
237 void showWindowMenu( int x, int y, Client* cl );
238 void showWindowMenu( QPoint pos, Client* cl );
240 void updateMinimizedOfTransients( Client* );
241 void updateOnAllDesktopsOfTransients( Client* );
242 void checkTransients( Window w );
244 void performWindowOperation( Client* c, WindowOperation op );
246 void storeSession( KConfig* config, SMSavePhase phase );
248 SessionInfo* takeSessionInfo( Client* );
249 WindowRules findWindowRules( const Client*, bool );
250 void rulesUpdated();
251 void discardUsedWindowRules( Client* c, bool withdraw );
252 void disableRulesUpdates( bool disable );
253 bool rulesUpdatesDisabled() const;
255 bool hasDecorationShadows() const;
256 QList< QList<QImage> > decorationShadowTextures();
257 int decorationShadowTextureList( ShadowType type ) const;
258 QList<QRect> decorationShadowQuads( ShadowType type, QSize size ) const;
259 double decorationShadowOpacity( ShadowType type ) const;
260 double decorationShadowBrightness( ShadowType type ) const;
261 double decorationShadowSaturation( ShadowType type ) const;
263 // D-Bus interface
264 void cascadeDesktop();
265 void unclutterDesktop();
266 void doNotManage( const QString& );
267 QList<int> decorationSupportedColors() const;
268 bool setCurrentDesktop( int new_desktop );
269 void nextDesktop();
270 void previousDesktop();
271 void circulateDesktopApplications();
272 bool compositingActive();
273 bool waitForCompositingSetup();
275 void setCurrentScreen( int new_screen );
277 QString desktopName( int desk ) const;
278 void updateDesktopLayout();
279 void setShowingDesktop( bool showing );
280 void resetShowingDesktop( bool keep_hidden );
281 bool showingDesktop() const;
283 bool isNotManaged( const QString& title ); // TODO: Setter or getter?
285 void sendPingToWindow( Window w, Time timestamp ); // Called from Client::pingWindow()
286 void sendTakeActivity( Client* c, Time timestamp, long flags ); // Called from Client::takeActivity()
288 void removeClient( Client*, allowed_t ); // Only called from Client::destroyClient() or Client::releaseWindow()
289 void setActiveClient( Client*, allowed_t );
290 Group* findGroup( Window leader ) const;
291 void addGroup( Group* group, allowed_t );
292 void removeGroup( Group* group, allowed_t );
293 Group* findClientLeaderGroup( const Client* c ) const;
295 void removeUnmanaged( Unmanaged*, allowed_t ); // Only called from Unmanaged::release()
296 void removeDeleted( Deleted*, allowed_t );
297 void addDeleted( Deleted*, allowed_t );
299 bool checkStartupNotification( Window w, KStartupInfoId& id, KStartupInfoData& data );
301 void focusToNull(); // SELI TODO: Public?
302 enum FocusChainChange
304 FocusChainMakeFirst,
305 FocusChainMakeLast,
306 FocusChainUpdate
308 void updateFocusChains( Client* c, FocusChainChange change );
310 bool forcedGlobalMouseGrab() const;
311 void clientShortcutUpdated( Client* c );
312 bool shortcutAvailable( const KShortcut& cut, Client* ignore = NULL ) const;
313 bool globalShortcutsDisabled() const;
314 void disableGlobalShortcuts( bool disable );
315 void disableGlobalShortcutsForClient( bool disable );
316 QPoint cursorPos() const;
318 void sessionSaveStarted();
319 void sessionSaveDone();
320 void setWasUserInteraction();
321 bool wasUserInteraction() const;
322 bool sessionSaving() const;
324 bool managingTopMenus() const;
325 int topMenuHeight() const;
326 void updateCurrentTopMenu();
328 int packPositionLeft( const Client* cl, int oldx, bool left_edge ) const;
329 int packPositionRight( const Client* cl, int oldx, bool right_edge ) const;
330 int packPositionUp( const Client* cl, int oldy, bool top_edge ) const;
331 int packPositionDown( const Client* cl, int oldy, bool bottom_edge ) const;
333 static QStringList configModules(bool controlCenter);
335 void cancelDelayFocus();
336 void requestDelayFocus( Client* );
337 void updateFocusMousePosition( const QPoint& pos );
338 QPoint focusMousePosition() const;
340 void toggleTopDockShadows(bool on);
342 // when adding repaints caused by a window, you probably want to use
343 // either Toplevel::addRepaint() or Toplevel::addWorkspaceRepaint()
344 void addRepaint( const QRect& r );
345 void addRepaint( const QRegion& r );
346 void addRepaint( int x, int y, int w, int h );
347 /// Creates XComposite overlay window, call initOverlay() afterwards
348 bool createOverlay();
349 /// Init overlay and the destination window in it
350 void setupOverlay( Window window );
351 void showOverlay();
352 void hideOverlay(); // hides and resets overlay window
353 void setOverlayShape( const QRegion& reg );
354 /// Destroys XComposite overlay window
355 void destroyOverlay();
356 Window overlayWindow();
357 void checkUnredirect( bool force = false );
358 void checkCompositeTimer();
360 public slots:
361 void addRepaintFull();
362 void refresh();
364 // Keybindings
365 void slotSwitchDesktopNext();
366 void slotSwitchDesktopPrevious();
367 void slotSwitchDesktopRight();
368 void slotSwitchDesktopLeft();
369 void slotSwitchDesktopUp();
370 void slotSwitchDesktopDown();
372 void slotSwitchToDesktop( int );
373 void slotSwitchToDesktop1() { return slotSwitchToDesktop( 1 ); }
374 void slotSwitchToDesktop2() { return slotSwitchToDesktop( 2 ); }
375 void slotSwitchToDesktop3() { return slotSwitchToDesktop( 3 ); }
376 void slotSwitchToDesktop4() { return slotSwitchToDesktop( 4 ); }
377 void slotSwitchToDesktop5() { return slotSwitchToDesktop( 5 ); }
378 void slotSwitchToDesktop6() { return slotSwitchToDesktop( 6 ); }
379 void slotSwitchToDesktop7() { return slotSwitchToDesktop( 7 ); }
380 void slotSwitchToDesktop8() { return slotSwitchToDesktop( 8 ); }
381 void slotSwitchToDesktop9() { return slotSwitchToDesktop( 9 ); }
382 void slotSwitchToDesktop10() { return slotSwitchToDesktop( 10 ); }
383 void slotSwitchToDesktop11() { return slotSwitchToDesktop( 11 ); }
384 void slotSwitchToDesktop12() { return slotSwitchToDesktop( 12 ); }
385 void slotSwitchToDesktop13() { return slotSwitchToDesktop( 13 ); }
386 void slotSwitchToDesktop14() { return slotSwitchToDesktop( 14 ); }
387 void slotSwitchToDesktop15() { return slotSwitchToDesktop( 15 ); }
388 void slotSwitchToDesktop16() { return slotSwitchToDesktop( 16 ); }
389 void slotSwitchToDesktop17() { return slotSwitchToDesktop( 17 ); }
390 void slotSwitchToDesktop18() { return slotSwitchToDesktop( 18 ); }
391 void slotSwitchToDesktop19() { return slotSwitchToDesktop( 19 ); }
392 void slotSwitchToDesktop20() { return slotSwitchToDesktop( 20 ); }
393 //void slotSwitchToWindow( int );
394 void slotWindowToDesktop( int );
395 void slotWindowToDesktop1() { return slotWindowToDesktop( 1 ); }
396 void slotWindowToDesktop2() { return slotWindowToDesktop( 2 ); }
397 void slotWindowToDesktop3() { return slotWindowToDesktop( 3 ); }
398 void slotWindowToDesktop4() { return slotWindowToDesktop( 4 ); }
399 void slotWindowToDesktop5() { return slotWindowToDesktop( 5 ); }
400 void slotWindowToDesktop6() { return slotWindowToDesktop( 6 ); }
401 void slotWindowToDesktop7() { return slotWindowToDesktop( 7 ); }
402 void slotWindowToDesktop8() { return slotWindowToDesktop( 8 ); }
403 void slotWindowToDesktop9() { return slotWindowToDesktop( 9 ); }
404 void slotWindowToDesktop10() { return slotWindowToDesktop( 10 ); }
405 void slotWindowToDesktop11() { return slotWindowToDesktop( 11 ); }
406 void slotWindowToDesktop12() { return slotWindowToDesktop( 12 ); }
407 void slotWindowToDesktop13() { return slotWindowToDesktop( 13 ); }
408 void slotWindowToDesktop14() { return slotWindowToDesktop( 14 ); }
409 void slotWindowToDesktop15() { return slotWindowToDesktop( 15 ); }
410 void slotWindowToDesktop16() { return slotWindowToDesktop( 16 ); }
411 void slotWindowToDesktop17() { return slotWindowToDesktop( 17 ); }
412 void slotWindowToDesktop18() { return slotWindowToDesktop( 18 ); }
413 void slotWindowToDesktop19() { return slotWindowToDesktop( 19 ); }
414 void slotWindowToDesktop20() { return slotWindowToDesktop( 20 ); }
415 //void slotWindowToListPosition( int );
416 void slotSwitchToScreen( int );
417 void slotSwitchToScreen0() { return slotSwitchToScreen( 0 ); }
418 void slotSwitchToScreen1() { return slotSwitchToScreen( 1 ); }
419 void slotSwitchToScreen2() { return slotSwitchToScreen( 2 ); }
420 void slotSwitchToScreen3() { return slotSwitchToScreen( 3 ); }
421 void slotSwitchToScreen4() { return slotSwitchToScreen( 4 ); }
422 void slotSwitchToScreen5() { return slotSwitchToScreen( 5 ); }
423 void slotSwitchToScreen6() { return slotSwitchToScreen( 6 ); }
424 void slotSwitchToScreen7() { return slotSwitchToScreen( 7 ); }
425 void slotWindowToScreen( int );
426 void slotWindowToScreen0() { return slotWindowToScreen( 0 ); }
427 void slotWindowToScreen1() { return slotWindowToScreen( 1 ); }
428 void slotWindowToScreen2() { return slotWindowToScreen( 2 ); }
429 void slotWindowToScreen3() { return slotWindowToScreen( 3 ); }
430 void slotWindowToScreen4() { return slotWindowToScreen( 4 ); }
431 void slotWindowToScreen5() { return slotWindowToScreen( 5 ); }
432 void slotWindowToScreen6() { return slotWindowToScreen( 6 ); }
433 void slotWindowToScreen7() { return slotWindowToScreen( 7 ); }
434 void slotSwitchToNextScreen();
435 void slotWindowToNextScreen();
437 void slotWindowMaximize();
438 void slotWindowMaximizeVertical();
439 void slotWindowMaximizeHorizontal();
440 void slotWindowMinimize();
441 void slotWindowShade();
442 void slotWindowRaise();
443 void slotWindowLower();
444 void slotWindowRaiseOrLower();
445 void slotActivateAttentionWindow();
446 void slotWindowPackLeft();
447 void slotWindowPackRight();
448 void slotWindowPackUp();
449 void slotWindowPackDown();
450 void slotWindowGrowHorizontal();
451 void slotWindowGrowVertical();
452 void slotWindowShrinkHorizontal();
453 void slotWindowShrinkVertical();
455 void slotWalkThroughDesktops();
456 void slotWalkBackThroughDesktops();
457 void slotWalkThroughDesktopList();
458 void slotWalkBackThroughDesktopList();
459 void slotWalkThroughWindows();
460 void slotWalkBackThroughWindows();
462 void slotWindowOperations();
463 void slotWindowClose();
464 void slotWindowMove();
465 void slotWindowResize();
466 void slotWindowAbove();
467 void slotWindowBelow();
468 void slotWindowOnAllDesktops();
469 void slotWindowFullScreen();
470 void slotWindowNoBorder();
472 void slotWindowToNextDesktop();
473 void slotWindowToPreviousDesktop();
474 void slotWindowToDesktopRight();
475 void slotWindowToDesktopLeft();
476 void slotWindowToDesktopUp();
477 void slotWindowToDesktopDown();
479 void slotMouseEmulation();
480 void slotDisableGlobalShortcuts();
482 void slotSettingsChanged( int category );
484 void reconfigure();
485 void slotReconfigure();
486 void slotReinitCompositing();
488 void slotKillWindow();
490 void slotGrabWindow();
491 void slotGrabDesktop();
493 void slotSetupWindowShortcut();
494 void setupWindowShortcutDone( bool );
495 void slotToggleCompositing();
497 void updateClientArea();
498 void suspendCompositing();
499 void suspendCompositing( bool suspend );
501 private slots:
502 void desktopPopupAboutToShow();
503 void clientPopupAboutToShow();
504 void slotSendToDesktop( QAction* );
505 void clientPopupActivated( QAction* );
506 void configureWM();
507 void desktopResized();
508 void slotUpdateToolWindows();
509 void lostTopMenuSelection();
510 void lostTopMenuOwner();
511 void delayFocus();
512 void gotTemporaryRulesMessage( const QString& );
513 void cleanupTemporaryRules();
514 void writeWindowRules();
515 void slotBlockShortcuts(int data);
516 void slotReloadConfig();
517 void setPopupClientOpacity( QAction* action );
518 void setupCompositing();
519 void performCompositing();
520 void lostCMSelection();
521 void updateElectricBorders();
522 void resetCursorPosTime();
523 void delayedCheckUnredirect();
525 protected:
526 bool keyPressMouseEmulation( XKeyEvent& ev );
528 private:
529 void init();
530 void initShortcuts();
531 void readShortcuts();
532 void initDesktopPopup();
533 void discardPopup();
534 void setupWindowShortcut( Client* c );
535 void checkCursorPos();
537 bool startKDEWalkThroughWindows();
538 bool startWalkThroughDesktops( TabBoxMode mode ); // TabBoxDesktopMode | TabBoxDesktopListMode
539 bool startWalkThroughDesktops();
540 bool startWalkThroughDesktopList();
541 void KDEWalkThroughWindows( bool forward );
542 void CDEWalkThroughWindows( bool forward );
543 void walkThroughDesktops( bool forward );
544 void KDEOneStepThroughWindows( bool forward );
545 void oneStepThroughDesktops( bool forward, TabBoxMode mode ); // TabBoxDesktopMode | TabBoxDesktopListMode
546 void oneStepThroughDesktops( bool forward );
547 void oneStepThroughDesktopList( bool forward );
548 bool establishTabBoxGrab();
549 void removeTabBoxGrab();
551 void propagateClients( bool propagate_new_clients ); // Called only from updateStackingOrder
552 ClientList constrainedStackingOrder();
553 void raiseClientWithinApplication( Client* c );
554 void lowerClientWithinApplication( Client* c );
555 bool allowFullClientRaising( const Client* c, Time timestamp );
556 bool keepTransientAbove( const Client* mainwindow, const Client* transient );
557 void blockStackingUpdates( bool block );
558 void addTopMenu( Client* c );
559 void removeTopMenu( Client* c );
560 void setupTopMenuHandling();
561 void updateTopMenuGeometry( Client* c = NULL );
562 void updateToolWindows( bool also_hide );
564 /// This is the right way to create a new client
565 Client* createClient( Window w, bool is_mapped );
566 void addClient( Client* c, allowed_t );
567 Unmanaged* createUnmanaged( Window w );
568 void addUnmanaged( Unmanaged* c, allowed_t );
570 Window findSpecialEventWindow( XEvent* e );
572 void randomPlacement( Client* c );
573 void smartPlacement( Client* c );
574 void cascadePlacement( Client* c, bool re_init = false );
576 // Desktop names and number of desktops
577 void loadDesktopSettings();
578 void saveDesktopSettings();
580 // Mouse emulation
581 WId getMouseEmulationWindow();
582 enum MouseEmulation { EmuPress, EmuRelease, EmuMove };
583 unsigned int sendFakedMouseEvent( const QPoint& pos, WId win, MouseEmulation type, int button, unsigned int state ); // returns the new state
585 void tabBoxKeyPress( int key );
586 void tabBoxKeyRelease( const XKeyEvent& ev );
588 // Electric borders
589 void destroyElectricBorders();
590 bool electricBorderEvent(XEvent * e);
591 void electricBorderSwitchDesktop( ElectricBorder border, const QPoint& pos );
593 //---------------------------------------------------------------------
595 void helperDialog( const QString& message, const Client* c );
597 QMenu* clientPopup();
598 void closeActivePopup();
600 void updateClientArea( bool force );
602 void finishCompositing();
603 bool windowRepaintsPending() const;
604 void setCompositeTimer();
605 void checkCompositePaintTime( int msec );
607 int current_desktop;
608 int number_of_desktops;
609 QVector<int> desktop_focus_chain;
611 QWidget* active_popup;
612 Client* active_popup_client;
614 void loadSessionInfo();
615 void loadWindowRules();
616 void editWindowRules( Client* c, bool whole_app );
618 QList<SessionInfo*> session;
619 QList<Rules*> rules;
620 KXMessages temporaryRulesMessages;
621 QTimer rulesUpdatedTimer;
622 bool rules_updates_disabled;
623 static const char* windowTypeToTxt( NET::WindowType type );
624 static NET::WindowType txtToWindowType( const char* txt );
625 static bool sessionInfoWindowTypeMatch( Client* c, SessionInfo* info );
627 Client* active_client;
628 Client* last_active_client;
629 Client* most_recently_raised; // Used ONLY by raiseOrLowerClient()
630 Client* movingClient;
631 Client* pending_take_activity;
632 int active_screen;
634 // Delay(ed) window focus timer and client
635 QTimer* delayFocusTimer;
636 Client* delayfocus_client;
637 QPoint focusMousePos;
639 ClientList clients;
640 ClientList desktops;
641 UnmanagedList unmanaged;
642 DeletedList deleted;
644 ClientList unconstrained_stacking_order; // Topmost last
645 ClientList stacking_order; // Topmost last
646 bool force_restacking;
647 mutable ToplevelList x_stacking; // From XQueryTree()
648 mutable bool x_stacking_dirty;
649 QVector< ClientList > focus_chain; // Currently ative last
650 ClientList global_focus_chain; // This one is only for things like tabbox's MRU
651 ClientList should_get_focus; // Last is most recent
652 ClientList attention_chain;
654 bool showing_desktop;
655 ClientList showing_desktop_clients;
656 int block_showing_desktop;
658 GroupList groups;
660 bool was_user_interaction;
661 bool session_saving;
662 int session_active_client;
663 int session_desktop;
665 bool control_grab;
666 bool tab_grab;
667 //KKeyNative walkThroughDesktopsKeycode, walkBackThroughDesktopsKeycode;
668 //KKeyNative walkThroughDesktopListKeycode, walkBackThroughDesktopListKeycode;
669 //KKeyNative walkThroughWindowsKeycode, walkBackThroughWindowsKeycode;
670 KShortcut cutWalkThroughDesktops, cutWalkThroughDesktopsReverse;
671 KShortcut cutWalkThroughDesktopList, cutWalkThroughDesktopListReverse;
672 KShortcut cutWalkThroughWindows, cutWalkThroughWindowsReverse;
673 bool mouse_emulation;
674 unsigned int mouse_emulation_state;
675 WId mouse_emulation_window;
676 int block_focus;
678 TabBox* tab_box;
679 PopupInfo* popupinfo;
681 QMenu* popup;
682 QMenu* advanced_popup;
683 QMenu* trans_popup;
684 QMenu* desk_popup;
686 void modalActionsSwitch( bool enabled );
688 KActionCollection* keys;
689 KActionCollection* client_keys;
690 QAction* mResizeOpAction;
691 QAction* mMoveOpAction;
692 QAction* mMaximizeOpAction;
693 QAction* mShadeOpAction;
694 QAction* mKeepAboveOpAction;
695 QAction* mKeepBelowOpAction;
696 QAction* mFullScreenOpAction;
697 QAction* mNoBorderOpAction;
698 QAction* mMinimizeOpAction;
699 QAction* mCloseOpAction;
700 ShortcutDialog* client_keys_dialog;
701 Client* client_keys_client;
702 KActionCollection* disable_shortcuts_keys;
703 bool global_shortcuts_disabled;
704 bool global_shortcuts_disabled_for_client;
706 PluginMgr* mgr;
708 RootInfo* rootInfo;
709 QWidget* supportWindow;
711 // Swallowing
712 QStringList doNotManageList;
714 // Colormap handling
715 Colormap default_colormap;
716 Colormap installed_colormap;
718 // Timer to collect requests for 'reconfigure'
719 QTimer reconfigureTimer;
721 QTimer updateToolWindowsTimer;
723 static Workspace* _self;
725 bool workspaceInit;
727 KStartupInfo* startup;
729 ElectricBorder electric_current_border;
730 Window electric_windows[ELECTRIC_COUNT];
731 int electricLeft;
732 int electricRight;
733 int electricTop;
734 int electricBottom;
735 Time electric_time_first;
736 Time electric_time_last;
737 QPoint electric_push_point;
738 int electric_reserved[ELECTRIC_COUNT]; // Corners/edges used by something
740 Qt::Orientation layoutOrientation;
741 int layoutX;
742 int layoutY;
744 Placement* initPositioning;
746 QVector<QRect> workarea; // Array of workareas for virtual desktops
747 QVector< QVector<QRect> > screenarea; // Array of workareas per xinerama screen for all virtual desktops
749 bool managing_topmenus;
750 KSelectionOwner* topmenu_selection;
751 KSelectionWatcher* topmenu_watcher;
752 ClientList topmenus; // Doesn't own them
753 mutable int topmenu_height;
754 QWidget* topmenu_space;
756 int set_active_client_recursion;
757 int block_stacking_updates; // When > 0, stacking updates are temporarily disabled
758 bool blocked_propagating_new_clients; // Propagate also new clients after enabling stacking updates?
759 Window null_focus_window;
760 bool forced_global_mouse_grab;
761 friend class StackingUpdatesBlocker;
763 KSelectionOwner* cm_selection;
764 bool compositingSuspended;
765 QTimer compositeTimer;
766 QTime lastCompositePaint;
767 QTime nextPaintReference;
768 int compositeRate;
769 QRegion repaints_region;
770 Window overlay; // XComposite overlay window
771 bool overlay_visible;
772 bool overlay_shown; // For showOverlay()
773 QRegion overlay_shape;
774 QSlider* transSlider;
775 QPushButton* transButton;
776 QTimer unredirectTimer;
777 bool forceUnredirectCheck;
778 QList< int > composite_paint_times;
780 private:
781 friend bool performTransiencyCheck();
785 * Helper for Workspace::blockStackingUpdates() being called in pairs (True/false)
787 class StackingUpdatesBlocker
789 public:
790 StackingUpdatesBlocker( Workspace* w )
791 : ws( w ) { ws->blockStackingUpdates( true ); }
792 ~StackingUpdatesBlocker()
793 { ws->blockStackingUpdates( false ); }
795 private:
796 Workspace* ws;
800 * NET WM Protocol handler class
802 class RootInfo : public NETRootInfo
804 private:
805 typedef KWin::Client Client; // Because of NET::Client
807 public:
808 RootInfo( Workspace* ws, Display* dpy, Window w, const char* name, unsigned long pr[],
809 int pr_num, int scr= -1 );
811 protected:
812 virtual void changeNumberOfDesktops( int n );
813 virtual void changeCurrentDesktop( int d );
814 virtual void changeActiveWindow( Window w,NET::RequestSource src, Time timestamp, Window active_window );
815 virtual void closeWindow( Window w );
816 virtual void moveResize( Window w, int x_root, int y_root, unsigned long direction );
817 virtual void moveResizeWindow( Window w, int flags, int x, int y, int width, int height );
818 virtual void gotPing( Window w, Time timestamp );
819 virtual void restackWindow( Window w, RequestSource source, Window above, int detail, Time timestamp );
820 virtual void gotTakeActivity( Window w, Time timestamp, long flags );
821 virtual void changeShowingDesktop( bool showing );
823 private:
824 Workspace* workspace;
828 inline bool Workspace::initializing() const
830 return workspaceInit;
833 inline Client* Workspace::activeClient() const
835 return active_client;
838 inline Client* Workspace::mostRecentlyActivatedClient() const
840 return should_get_focus.count() > 0 ? should_get_focus.last() : active_client;
843 inline int Workspace::currentDesktop() const
845 return current_desktop;
848 inline int Workspace::numberOfDesktops() const
850 return number_of_desktops;
853 inline void Workspace::addGroup( Group* group, allowed_t )
855 groups.append( group );
858 inline void Workspace::removeGroup( Group* group, allowed_t )
860 groups.removeAll( group );
863 inline const ClientList& Workspace::stackingOrder() const
865 // TODO: Q_ASSERT( block_stacking_updates == 0 );
866 return stacking_order;
869 inline void Workspace::showWindowMenu( QPoint pos, Client* cl )
871 showWindowMenu( QRect( pos, pos ), cl );
874 inline void Workspace::showWindowMenu( int x, int y, Client* cl )
876 showWindowMenu( QRect( QPoint( x, y ), QPoint( x, y )), cl );
879 inline void Workspace::setWasUserInteraction()
881 was_user_interaction = true;
884 inline bool Workspace::wasUserInteraction() const
886 return was_user_interaction;
889 inline bool Workspace::managingTopMenus() const
891 return managing_topmenus;
894 inline void Workspace::sessionSaveStarted()
896 session_saving = true;
899 inline void Workspace::sessionSaveDone()
901 session_saving = false;
904 inline bool Workspace::sessionSaving() const
906 return session_saving;
909 inline bool Workspace::forcedGlobalMouseGrab() const
911 return forced_global_mouse_grab;
914 inline bool Workspace::showingDesktop() const
916 return showing_desktop;
919 inline bool Workspace::globalShortcutsDisabled() const
921 return global_shortcuts_disabled || global_shortcuts_disabled_for_client;
924 inline Window Workspace::overlayWindow()
926 return overlay;
929 inline bool Workspace::rulesUpdatesDisabled() const
931 return rules_updates_disabled;
934 inline void Workspace::forceRestacking()
936 force_restacking = true;
937 StackingUpdatesBlocker blocker( this ); // Do restacking if not blocked
940 inline void Workspace::updateFocusMousePosition( const QPoint& pos )
942 focusMousePos = pos;
945 inline QPoint Workspace::focusMousePosition() const
947 return focusMousePos;
950 template< typename T >
951 inline Client* Workspace::findClient( T predicate ) const
953 if( Client* ret = findClientInList( clients, predicate ))
954 return ret;
955 if( Client* ret = findClientInList( desktops, predicate ))
956 return ret;
957 return NULL;
960 template< typename T1, typename T2 >
961 inline void Workspace::forEachClient( T1 procedure, T2 predicate )
963 for( ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it )
964 if( predicate( const_cast<const Client*>( *it )))
965 procedure( *it );
966 for( ClientList::ConstIterator it = desktops.constBegin(); it != desktops.constEnd(); ++it )
967 if( predicate( const_cast<const Client*>( *it )))
968 procedure( *it );
971 template< typename T >
972 inline void Workspace::forEachClient( T procedure )
974 return forEachClient( procedure, TruePredicate() );
977 template< typename T >
978 inline Unmanaged* Workspace::findUnmanaged( T predicate ) const
980 return findUnmanagedInList( unmanaged, predicate );
983 template< typename T1, typename T2 >
984 inline void Workspace::forEachUnmanaged( T1 procedure, T2 predicate )
986 for( UnmanagedList::ConstIterator it = unmanaged.constBegin(); it != unmanaged.constEnd(); ++it )
987 if( predicate( const_cast<const Unmanaged*>( *it )))
988 procedure( *it );
991 template< typename T >
992 inline void Workspace::forEachUnmanaged( T procedure )
994 return forEachUnmanaged( procedure, TruePredicate() );
997 KWIN_COMPARE_PREDICATE( ClientMatchPredicate, Client, const Client*, cl == value );
999 inline bool Workspace::hasClient( const Client* c )
1001 return findClient( ClientMatchPredicate( c ));
1004 inline void Workspace::checkCompositeTimer()
1006 if( !compositeTimer.isActive() )
1007 setCompositeTimer();
1010 inline bool Workspace::hasDecorationShadows() const
1012 return mgr->factory()->supports( AbilityCompositingShadow );
1015 inline QList< QList<QImage> > Workspace::decorationShadowTextures()
1017 if( KDecorationFactoryUnstable* factory = dynamic_cast<KDecorationFactoryUnstable*>( mgr->factory() ))
1018 return factory->shadowTextures();
1019 return QList< QList<QImage> >();
1022 inline int Workspace::decorationShadowTextureList( ShadowType type ) const
1024 if( KDecorationFactoryUnstable* factory = dynamic_cast<KDecorationFactoryUnstable*>( mgr->factory() ))
1025 return factory->shadowTextureList( type );
1026 return -1;
1029 inline QList<QRect> Workspace::decorationShadowQuads( ShadowType type, QSize size ) const
1031 if( KDecorationFactoryUnstable* factory = dynamic_cast<KDecorationFactoryUnstable*>( mgr->factory() ))
1032 return factory->shadowQuads( type, size );
1033 return QList<QRect>();
1036 inline double Workspace::decorationShadowOpacity( ShadowType type ) const
1038 if( KDecorationFactoryUnstable* factory = dynamic_cast<KDecorationFactoryUnstable*>( mgr->factory() ))
1039 return factory->shadowOpacity( type );
1040 return 1.0;
1043 inline double Workspace::decorationShadowBrightness( ShadowType type ) const
1045 if( KDecorationFactoryUnstable* factory = dynamic_cast<KDecorationFactoryUnstable*>( mgr->factory() ))
1046 return factory->shadowBrightness( type );
1047 return 1.0;
1050 inline double Workspace::decorationShadowSaturation( ShadowType type ) const
1052 if( KDecorationFactoryUnstable* factory = dynamic_cast< KDecorationFactoryUnstable*>( mgr->factory() ))
1053 return factory->shadowSaturation( type );
1054 return 1.0;
1057 } // namespace
1059 #endif