12 #ifndef KWIN_WORKSPACE_H
13 #define KWIN_WORKSPACE_H
16 #include <tqvaluevector.h>
17 #include <tdeshortcut.h>
20 #include <kxmessages.h>
22 #include "KWinInterface.h"
24 #include "kdecoration.h"
32 class TDEShortcutDialog;
34 class TDEStartupInfoId;
35 class TDEStartupInfoData;
40 namespace KWinInternal
52 class SystemTrayWindow
58 SystemTrayWindow( WId w )
61 SystemTrayWindow( WId w, WId wf )
65 bool operator==(
const SystemTrayWindow& other )
66 {
return win == other.win; }
71 typedef TQValueList<SystemTrayWindow> SystemTrayWindowList;
73 class Workspace :
public TQObject,
public KWinInterface,
public KDecorationDefines
77 Workspace(
bool restore = FALSE );
80 static Workspace *
self() {
return _self; }
82 bool workspaceEvent( XEvent * );
84 KDecoration* createDecoration( KDecorationBridge* bridge );
86 bool hasClient(
const Client * );
88 template<
typename T > Client* findClient( T predicate );
89 template<
typename T1,
typename T2 >
void forEachClient( T1 procedure, T2 predicate );
90 template<
typename T >
void forEachClient( T procedure );
92 TQRect clientArea( clientAreaOption,
const TQPoint& p,
int desktop )
const;
93 TQRect clientArea( clientAreaOption,
const Client* c )
const;
94 TQRect clientArea( clientAreaOption,
int screen,
int desktop )
const;
99 void killWindowId( Window window );
100 void suspendWindowId( Window window );
101 void resumeWindowId( Window window );
102 bool isResumeableWindowID( Window window );
104 void killWindow() { slotKillWindow(); }
105 void suspendWindow() { slotSuspendWindow(); }
106 void resumeWindow() { slotResumeWindow(); }
110 bool initializing()
const;
116 Client* activeClient()
const;
120 Client* mostRecentlyActivatedClient()
const;
122 void activateClient( Client*,
bool force = FALSE );
123 void requestFocus( Client* c,
bool force = FALSE );
124 void takeActivity( Client* c,
int flags,
bool handled );
125 void handleTakeActivity( Client* c, Time timestamp,
int flags );
126 bool allowClientActivation(
const Client* c, Time time = -1U,
bool focus_in =
false );
128 void gotFocusIn(
const Client* );
129 void setShouldGetFocus( Client* );
130 bool fakeRequestedActivity( Client* c );
131 void unfakeActivity( Client* c );
132 bool activateNextClient( Client* c );
133 bool focusChangeEnabled() {
return block_focus == 0; }
135 void updateColormap();
140 void setClientIsMoving( Client *c );
142 void place( Client *c, TQRect& area );
143 void placeSmart( Client* c,
const TQRect& area );
145 TQPoint adjustClientPosition( Client* c, TQPoint pos );
146 TQRect adjustClientSize( Client* c, TQRect moveResizeGeom,
int mode );
147 void raiseClient( Client* c );
148 void lowerClient( Client* c );
149 void raiseClientRequest( Client* c, NET::RequestSource src, Time timestamp );
150 void lowerClientRequest( Client* c, NET::RequestSource src, Time timestamp );
151 void restackClientUnderActive( Client* );
152 void updateClientLayer( Client* c );
153 void raiseOrLowerClient( Client * );
156 void clientHidden( Client* );
157 void clientAttentionChanged( Client* c,
bool set );
159 void clientMoved(
const TQPoint &pos, Time time);
164 int currentDesktop()
const;
168 int numberOfDesktops()
const;
169 void setNumberOfDesktops(
int n );
171 int activeScreen()
const;
172 int numScreens()
const;
173 void checkActiveScreen(
const Client* c );
174 void setActiveScreenMouse( TQPoint mousepos );
175 TQRect screenGeometry(
int screen )
const;
176 int screenNumber( TQPoint pos )
const;
178 TQWidget* desktopWidget();
181 Client* nextFocusChainClient(Client*)
const;
182 Client* previousFocusChainClient(Client*)
const;
183 Client* nextStaticClient(Client*)
const;
184 Client* previousStaticClient(Client*)
const;
185 int nextDesktopFocusChain(
int iDesktop )
const;
186 int previousDesktopFocusChain(
int iDesktop )
const;
193 const ClientList& stackingOrder()
const;
195 ClientList ensureStackingOrder(
const ClientList& clients )
const;
197 Client* topClientOnDesktop(
int desktop,
bool unconstrained =
false,
bool only_normal =
true )
const;
198 Client* findDesktop(
bool topmost,
int desktop )
const;
199 void sendClientToDesktop( Client* c,
int desktop,
bool dont_activate );
200 void windowToPreviousDesktop( Client* c );
201 void windowToNextDesktop( Client* c );
202 void sendClientToScreen( Client* c,
int screen );
205 void showWindowMenuAt(
unsigned long id,
int x,
int y );
206 void kDestopResized();
212 void showWindowMenu(
const TQRect &pos, Client* cl );
216 void showWindowMenu(
int x,
int y, Client* cl );
217 void showWindowMenu( TQPoint pos, Client* cl );
219 void updateMinimizedOfTransients( Client* );
220 void updateOnAllDesktopsOfTransients( Client* );
221 void checkTransients( Window w );
223 void performWindowOperation( Client* c, WindowOperation op );
225 void storeSession( TDEConfig* config, SMSavePhase phase );
227 SessionInfo* takeSessionInfo( Client* );
228 WindowRules findWindowRules(
const Client*,
bool );
230 void discardUsedWindowRules( Client* c,
bool withdraw );
231 void disableRulesUpdates(
bool disable );
232 bool rulesUpdatesDisabled()
const;
235 void cascadeDesktop();
236 void unclutterDesktop();
237 void doNotManage(TQString);
238 bool setCurrentDesktop(
int new_desktop );
239 void updateOverlappingShadows(WId window);
240 void setShadowed(WId window,
bool shadowed);
242 void previousDesktop();
243 void circulateDesktopApplications();
244 void setCurrentScreen(
int new_screen );
246 TQString desktopName(
int desk )
const;
247 virtual void setDesktopLayout(
int ,
int ,
int );
248 void updateDesktopLayout();
249 void setShowingDesktop(
bool showing );
250 void resetShowingDesktop(
bool keep_hidden );
251 bool showingDesktop()
const;
253 bool isNotManaged(
const TQString& title );
255 void sendPingToWindow( Window w, Time timestamp );
256 void sendTakeActivity( Client* c, Time timestamp,
long flags );
258 bool kompmgrIsRunning();
259 void setOpacity(
unsigned long winId,
unsigned int opacityPercent);
260 void setShadowSize(
unsigned long winId,
unsigned int shadowSizePercent);
261 void setUnshadowed(
unsigned long winId);
264 void removeClient( Client*, allowed_t );
265 void setActiveClient( Client*, allowed_t );
266 Group* findGroup( Window leader )
const;
267 void addGroup( Group* group, allowed_t );
268 void removeGroup( Group* group, allowed_t );
269 Group* findClientLeaderGroup(
const Client* c )
const;
271 bool checkStartupNotification( Window w, TDEStartupInfoId&
id, TDEStartupInfoData& data );
274 enum FocusChainChange { FocusChainMakeFirst, FocusChainMakeLast, FocusChainUpdate };
275 void updateFocusChains( Client* c, FocusChainChange change );
277 bool forcedGlobalMouseGrab()
const;
278 void clientShortcutUpdated( Client* c );
279 bool shortcutAvailable(
const TDEShortcut& cut, Client* ignore = NULL )
const;
280 bool globalShortcutsDisabled()
const;
281 void disableGlobalShortcuts(
bool disable );
282 void disableGlobalShortcutsForClient(
bool disable );
284 void sessionSaveStarted();
285 void sessionSaveDone();
286 void setWasUserInteraction();
287 bool wasUserInteraction()
const;
288 bool sessionSaving()
const;
290 bool managingTopMenus()
const;
291 int topMenuHeight()
const;
292 void updateCurrentTopMenu();
294 int packPositionLeft(
const Client* cl,
int oldx,
bool left_edge )
const;
295 int packPositionRight(
const Client* cl,
int oldx,
bool right_edge )
const;
296 int packPositionUp(
const Client* cl,
int oldy,
bool top_edge )
const;
297 int packPositionDown(
const Client* cl,
int oldy,
bool bottom_edge )
const;
299 static TQStringList configModules(
bool controlCenter);
301 void cancelDelayFocus();
302 void requestDelayFocus( Client* );
303 void updateFocusMousePosition(
const TQPoint& pos );
304 TQPoint focusMousePosition()
const;
306 void toggleTopDockShadows(
bool on);
311 void slotSwitchDesktopNext();
312 void slotSwitchDesktopPrevious();
313 void slotSwitchDesktopRight();
314 void slotSwitchDesktopLeft();
315 void slotSwitchDesktopUp();
316 void slotSwitchDesktopDown();
318 void slotSwitchToDesktop(
int );
320 void slotWindowToDesktop(
int );
322 void slotSwitchToScreen(
int );
323 void slotWindowToScreen(
int );
324 void slotSwitchToNextScreen();
325 void slotWindowToNextScreen();
327 void slotWindowMaximize();
328 void slotWindowMaximizeVertical();
329 void slotWindowMaximizeHorizontal();
330 void slotWindowMinimize();
331 void slotWindowShade();
332 void slotWindowRaise();
333 void slotWindowLower();
334 void slotWindowRaiseOrLower();
335 void slotActivateAttentionWindow();
336 void slotWindowPackLeft();
337 void slotWindowPackRight();
338 void slotWindowPackUp();
339 void slotWindowPackDown();
340 void slotWindowGrowHorizontal();
341 void slotWindowGrowVertical();
342 void slotWindowShrinkHorizontal();
343 void slotWindowShrinkVertical();
345 void slotWalkThroughDesktops();
346 void slotWalkBackThroughDesktops();
347 void slotWalkThroughApps();
348 void slotWalkBackThroughApps();
350 void slotWalkThroughDesktopList();
351 void slotWalkBackThroughDesktopList();
352 void slotWalkThroughWindows();
353 void slotWalkBackThroughWindows();
355 void slotWindowOperations();
356 void slotWindowClose();
357 void slotWindowMove();
358 void slotWindowResize();
359 void slotWindowAbove();
360 void slotWindowBelow();
361 void slotWindowOnAllDesktops();
362 void slotWindowFullScreen();
363 void slotWindowNoBorder();
365 void slotWindowToNextDesktop();
366 void slotWindowToPreviousDesktop();
367 void slotWindowToDesktopRight();
368 void slotWindowToDesktopLeft();
369 void slotWindowToDesktopUp();
370 void slotWindowToDesktopDown();
372 void slotMouseEmulation();
373 void slotDisableGlobalShortcuts();
375 void slotSettingsChanged(
int category );
377 void slotReconfigure();
379 void slotKillWindow();
380 void slotSuspendWindow();
381 void slotResumeWindow();
383 void slotGrabWindow();
384 void slotGrabDesktop();
386 void slotSetupWindowShortcut();
387 void setupWindowShortcutDone(
bool );
389 void updateClientArea();
395 void desktopPopupAboutToShow();
396 void clientPopupAboutToShow();
397 void slotSendToDesktop(
int );
398 void clientPopupActivated(
int );
400 void desktopResized();
401 void slotUpdateToolWindows();
402 void lostTopMenuSelection();
403 void lostTopMenuOwner();
405 void gotTemporaryRulesMessage(
const TQString& );
406 void cleanupTemporaryRules();
407 void writeWindowRules();
408 void kipcMessage(
int id,
int data );
410 void setPopupClientOpacity(
int v);
411 void resetClientOpacity();
412 void setTransButtonText(
int value);
413 void unblockKompmgrRestart();
414 void restartKompmgr( TDEProcess *proc );
415 void handleKompmgrOutput( TDEProcess *proc,
char *buffer,
int buflen);
417 void kompmgrReloadSettings();
421 bool keyPressMouseEmulation( XKeyEvent& ev );
425 void initShortcuts();
426 void readShortcuts();
427 void initDesktopPopup();
428 void setupWindowShortcut( Client* c );
430 bool startKDEWalkThroughWindows();
431 bool startWalkThroughDesktops(
int mode );
432 bool startWalkThroughDesktops();
433 bool startWalkThroughDesktopList();
434 void KDEWalkThroughWindows(
bool forward );
435 void CDEWalkThroughWindows(
bool forward );
436 void walkThroughDesktops(
bool forward );
437 void KDEOneStepThroughWindows(
bool forward );
438 void oneStepThroughDesktops(
bool forward,
int mode );
439 void oneStepThroughDesktops(
bool forward );
440 void oneStepThroughDesktopList(
bool forward );
441 bool establishTabBoxGrab();
442 void removeTabBoxGrab();
443 int desktopToRight(
int desktop )
const;
444 int desktopToLeft(
int desktop )
const;
445 int desktopUp(
int desktop )
const;
446 int desktopDown(
int desktop )
const;
448 void updateStackingOrder(
bool propagate_new_clients =
false );
449 void propagateClients(
bool propagate_new_clients );
450 ClientList constrainedStackingOrder();
451 void raiseClientWithinApplication( Client* c );
452 void lowerClientWithinApplication( Client* c );
453 bool allowFullClientRaising(
const Client* c, Time timestamp );
454 bool keepTransientAbove(
const Client* mainwindow,
const Client*
transient );
455 void blockStackingUpdates(
bool block );
456 void addTopMenu( Client* c );
457 void removeTopMenu( Client* c );
458 void setupTopMenuHandling();
459 void updateTopMenuGeometry( Client* c = NULL );
460 void updateToolWindows(
bool also_hide );
463 Client* createClient( Window w,
bool is_mapped );
464 void addClient( Client* c, allowed_t );
466 Window findSpecialEventWindow( XEvent* e );
468 void randomPlacement(Client* c);
469 void smartPlacement(Client* c);
470 void cascadePlacement(Client* c,
bool re_init =
false);
472 bool addSystemTrayWin( WId w );
473 bool removeSystemTrayWin( WId w,
bool check );
474 void propagateSystemTrayWins();
475 SystemTrayWindow findSystemTrayWin( WId w );
478 void loadDesktopSettings();
479 void saveDesktopSettings();
482 WId getMouseEmulationWindow();
483 enum MouseEmulation { EmuPress, EmuRelease, EmuMove };
484 unsigned int sendFakedMouseEvent( TQPoint pos, WId win, MouseEmulation type,
int button,
unsigned int state );
486 void tabBoxKeyPress(
const KKeyNative& keyX );
487 void tabBoxKeyRelease(
const XKeyEvent& ev );
490 void checkElectricBorders(
bool force =
false );
491 void createBorderWindows();
492 void destroyBorderWindows();
493 bool electricBorder(XEvent * e);
494 void raiseElectricBorders();
498 void helperDialog(
const TQString& message,
const Client* c );
500 void calcDesktopLayout(
int &x,
int &y)
const;
502 TQPopupMenu* clientPopup();
503 void closeActivePopup();
505 void updateClientArea(
bool force );
507 SystemTrayWindowList systemTrayWins;
510 int number_of_desktops;
511 TQMemArray<int> desktop_focus_chain;
514 TQWidget* active_popup;
515 Client* active_popup_client;
517 TQWidget* desktop_widget;
519 void loadSessionInfo();
520 void loadWindowRules();
521 void editWindowRules( Client* c,
bool whole_app );
523 TQPtrList<SessionInfo> session;
524 TQValueList<Rules*> rules;
525 KXMessages temporaryRulesMessages;
526 TQTimer rulesUpdatedTimer;
527 bool rules_updates_disabled;
528 static const char* windowTypeToTxt( NET::WindowType type );
529 static NET::WindowType txtToWindowType(
const char* txt );
530 static bool sessionInfoWindowTypeMatch( Client* c, SessionInfo* info );
532 Client* active_client;
533 Client* last_active_client;
534 Client* next_active_client;
535 Client* most_recently_raised;
536 Client* movingClient;
537 Client* pending_take_activity;
540 TQTimer* delayFocusTimer;
541 Client* delayfocus_client;
542 TQPoint focusMousePos;
547 ClientList unconstrained_stacking_order;
548 ClientList stacking_order;
549 TQValueVector< ClientList > focus_chain;
550 ClientList global_focus_chain;
551 ClientList should_get_focus;
552 ClientList attention_chain;
554 bool showing_desktop;
555 ClientList showing_desktop_clients;
556 int block_showing_desktop;
560 bool was_user_interaction;
562 int session_active_client;
570 TDEShortcut cutWalkThroughDesktops, cutWalkThroughDesktopsReverse;
571 TDEShortcut cutWalkThroughDesktopList, cutWalkThroughDesktopListReverse;
572 TDEShortcut cutWalkThroughWindows, cutWalkThroughWindowsReverse;
573 TDEShortcut cutWalkThroughApps, cutWalkThroughAppsReverse;
574 bool mouse_emulation;
575 unsigned int mouse_emulation_state;
576 WId mouse_emulation_window;
580 PopupInfo* popupinfo;
583 TQPopupMenu *advanced_popup;
584 TQPopupMenu *desk_popup;
585 int desk_popup_index;
587 TDEGlobalAccel *keys;
588 TDEGlobalAccel *client_keys;
589 ShortcutDialog* client_keys_dialog;
590 Client* client_keys_client;
591 TDEGlobalAccel *disable_shortcuts_keys;
592 bool global_shortcuts_disabled;
593 bool global_shortcuts_disabled_for_client;
600 TQWidget* supportWindow;
603 TQStringList doNotManageList;
606 Colormap default_colormap;
607 Colormap installed_colormap;
610 TQTimer reconfigureTimer;
612 TQTimer updateToolWindowsTimer;
614 static Workspace *_self;
618 TDEStartupInfo* startup;
620 bool electric_have_borders;
621 int electric_current_border;
622 WId electric_top_border;
623 WId electric_bottom_border;
624 WId electric_left_border;
625 WId electric_right_border;
630 Time electric_time_first;
631 Time electric_time_last;
632 TQPoint electric_push_point;
634 Qt::Orientation layoutOrientation;
638 Placement *initPositioning;
643 bool managing_topmenus;
644 TDESelectionOwner* topmenu_selection;
645 TDESelectionWatcher* topmenu_watcher;
647 mutable int topmenu_height;
648 TQWidget* topmenu_space;
650 int set_active_client_recursion;
651 int block_stacking_updates;
652 bool blocked_propagating_new_clients;
653 Window null_focus_window;
654 bool forced_global_mouse_grab;
655 friend class StackingUpdatesBlocker;
659 TQSlider *transSlider;
660 TQPushButton *transButton;
668 void kompmgrStarted();
669 void kompmgrStopped();
672 friend bool performTransiencyCheck();
676 class StackingUpdatesBlocker
679 StackingUpdatesBlocker( Workspace* w )
680 : ws( w ) { ws->blockStackingUpdates(
true ); }
681 ~StackingUpdatesBlocker()
682 { ws->blockStackingUpdates(
false ); }
688 class RootInfo :
public NETRootInfo4
693 RootInfo( Workspace* ws, Display *dpy, Window w,
const char *name,
unsigned long pr[],
int pr_num,
int scr= -1);
695 virtual void changeNumberOfDesktops(
int n);
696 virtual void changeCurrentDesktop(
int d);
698 virtual void changeActiveWindow(Window w,NET::RequestSource src, Time timestamp, Window active_window);
699 virtual void closeWindow(Window w);
700 virtual void moveResize(Window w,
int x_root,
int y_root,
unsigned long direction);
701 virtual void moveResizeWindow(Window w,
int flags,
int x,
int y,
int width,
int height );
702 virtual void gotPing(Window w, Time timestamp);
703 virtual void restackWindow(Window w, RequestSource source, Window above,
int detail, Time timestamp);
704 virtual void gotTakeActivity(Window w, Time timestamp,
long flags );
705 virtual void changeShowingDesktop(
bool showing );
707 Workspace* workspace;
711 inline WId Workspace::rootWin()
const
716 inline bool Workspace::initializing()
const
718 return workspaceInit;
721 inline Client* Workspace::activeClient()
const
731 return next_active_client != NULL ? next_active_client : active_client;
734 inline Client* Workspace::mostRecentlyActivatedClient()
const
736 return should_get_focus.count() > 0 ? should_get_focus.last() : active_client;
739 inline int Workspace::currentDesktop()
const
741 return current_desktop;
744 inline int Workspace::numberOfDesktops()
const
746 return number_of_desktops;
749 inline void Workspace::addGroup( Group* group, allowed_t )
751 groups.append( group );
754 inline void Workspace::removeGroup( Group* group, allowed_t )
756 groups.remove( group );
759 inline const ClientList& Workspace::stackingOrder()
const
762 return stacking_order;
765 inline void Workspace::showWindowMenu(TQPoint pos, Client* cl)
767 showWindowMenu(TQRect(pos, pos), cl);
770 inline void Workspace::showWindowMenu(
int x,
int y, Client* cl)
772 showWindowMenu(TQRect(TQPoint(x, y), TQPoint(x, y)), cl);
776 void Workspace::setWasUserInteraction()
778 was_user_interaction =
true;
782 bool Workspace::wasUserInteraction()
const
784 return was_user_interaction;
788 bool Workspace::managingTopMenus()
const
790 return managing_topmenus;
793 inline void Workspace::sessionSaveStarted()
795 session_saving =
true;
798 inline void Workspace::sessionSaveDone()
800 session_saving =
false;
803 inline bool Workspace::sessionSaving()
const
805 return session_saving;
808 inline bool Workspace::forcedGlobalMouseGrab()
const
810 return forced_global_mouse_grab;
813 inline bool Workspace::showingDesktop()
const
815 return showing_desktop;
818 inline bool Workspace::globalShortcutsDisabled()
const
820 return global_shortcuts_disabled || global_shortcuts_disabled_for_client;
824 bool Workspace::rulesUpdatesDisabled()
const
826 return rules_updates_disabled;
830 void Workspace::updateFocusMousePosition(
const TQPoint& pos )
836 TQPoint Workspace::focusMousePosition()
const
838 return focusMousePos;
841 template<
typename T >
842 inline Client* Workspace::findClient( T predicate )
844 if( Client* ret = findClientInList( clients, predicate ))
846 if( Client* ret = findClientInList( desktops, predicate ))
851 template<
typename T1,
typename T2 >
852 inline void Workspace::forEachClient( T1 procedure, T2 predicate )
854 for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it)
855 if ( predicate( const_cast< const Client* >( *it)))
857 for ( ClientList::ConstIterator it = desktops.begin(); it != desktops.end(); ++it)
858 if ( predicate( const_cast< const Client* >( *it)))
862 template<
typename T >
863 inline void Workspace::forEachClient( T procedure )
865 return forEachClient( procedure, TruePredicate());
868 KWIN_COMPARE_PREDICATE( ClientMatchPredicate,
const Client*, cl == value );
869 inline bool Workspace::hasClient(
const Client* c )
871 return findClient( ClientMatchPredicate( c ));