00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "workspace.h"
00015
00016 #include <kapplication.h>
00017 #include <kstartupinfo.h>
00018 #include <fixx11h.h>
00019 #include <kconfig.h>
00020 #include <kglobal.h>
00021 #include <qpopupmenu.h>
00022 #include <klocale.h>
00023 #include <qregexp.h>
00024 #include <qpainter.h>
00025 #include <qbitmap.h>
00026 #include <qclipboard.h>
00027 #include <kmenubar.h>
00028 #include <kprocess.h>
00029 #include <kglobalaccel.h>
00030
00031 #include "plugins.h"
00032 #include "client.h"
00033 #include "popupinfo.h"
00034 #include "tabbox.h"
00035 #include "atoms.h"
00036 #include "placement.h"
00037 #include "notifications.h"
00038 #include "group.h"
00039 #include "rules.h"
00040
00041 #include <X11/extensions/shape.h>
00042 #include <X11/keysym.h>
00043 #include <X11/keysymdef.h>
00044 #include <X11/cursorfont.h>
00045
00046 extern Time qt_x_time;
00047
00048 namespace KWinInternal
00049 {
00050
00051 extern int screen_number;
00052
00053 Workspace *Workspace::_self = 0;
00054
00055
00056
00057
00058
00059
00060
00061
00062 Workspace::Workspace( bool restore )
00063 : DCOPObject ("KWinInterface"),
00064 QObject (0, "workspace"),
00065 current_desktop (0),
00066 number_of_desktops(0),
00067 popup_client (0),
00068 desktop_widget (0),
00069 temporaryRulesMessages( "_KDE_NET_WM_TEMPORARY_RULES", NULL, false ),
00070 active_client (0),
00071 last_active_client (0),
00072 most_recently_raised (0),
00073 movingClient(0),
00074 pending_take_activity ( NULL ),
00075 delayfocus_client (0),
00076 was_user_interaction (false),
00077 session_saving (false),
00078 control_grab (false),
00079 tab_grab (false),
00080 mouse_emulation (false),
00081 block_focus (0),
00082 tab_box (0),
00083 popupinfo (0),
00084 popup (0),
00085 advanced_popup (0),
00086 desk_popup (0),
00087 desk_popup_index (0),
00088 keys (0),
00089 root (0),
00090 workspaceInit (true),
00091 startup(0), electric_have_borders(false),
00092 electric_current_border(0),
00093 electric_top_border(None),
00094 electric_bottom_border(None),
00095 electric_left_border(None),
00096 electric_right_border(None),
00097 layoutOrientation(Qt::Vertical),
00098 layoutX(-1),
00099 layoutY(2),
00100 workarea(NULL),
00101 screenarea(NULL),
00102 topmenu_selection( NULL ),
00103 topmenu_watcher( NULL ),
00104 topmenu_height( 0 ),
00105 managing_topmenus( false ),
00106 topmenu_space( NULL ),
00107 set_active_client_recursion( 0 ),
00108 block_stacking_updates( 0 ),
00109 forced_global_mouse_grab( false )
00110 {
00111 _self = this;
00112 mgr = new PluginMgr;
00113 root = qt_xrootwin();
00114 default_colormap = DefaultColormap(qt_xdisplay(), qt_xscreen() );
00115 installed_colormap = default_colormap;
00116 session.setAutoDelete( TRUE );
00117
00118 connect( &temporaryRulesMessages, SIGNAL( gotMessage( const QString& )),
00119 this, SLOT( gotTemporaryRulesMessage( const QString& )));
00120 connect( &rulesUpdatedTimer, SIGNAL( timeout()), this, SLOT( writeWindowRules()));
00121
00122 updateXTime();
00123
00124 delayFocusTimer = 0;
00125
00126 electric_time_first = qt_x_time;
00127 electric_time_last = qt_x_time;
00128
00129 if ( restore )
00130 loadSessionInfo();
00131
00132 loadWindowRules();
00133
00134 (void) QApplication::desktop();
00135
00136 desktop_widget =
00137 new QWidget(
00138 0,
00139 "desktop_widget",
00140 Qt::WType_Desktop | Qt::WPaintUnclipped
00141 );
00142
00143 kapp->setGlobalMouseTracking( true );
00144
00145 startup = new KStartupInfo(
00146 KStartupInfo::DisableKWinModule | KStartupInfo::AnnounceSilenceChanges, this );
00147
00148
00149 XSelectInput(qt_xdisplay(), root,
00150 KeyPressMask |
00151 PropertyChangeMask |
00152 ColormapChangeMask |
00153 SubstructureRedirectMask |
00154 SubstructureNotifyMask |
00155 FocusChangeMask
00156 );
00157
00158 Shape::init();
00159
00160
00161 long data = 1;
00162
00163 XChangeProperty(
00164 qt_xdisplay(),
00165 qt_xrootwin(),
00166 atoms->kwin_running,
00167 atoms->kwin_running,
00168 32,
00169 PropModeAppend,
00170 (unsigned char*) &data,
00171 1
00172 );
00173
00174 initShortcuts();
00175 tab_box = new TabBox( this );
00176 popupinfo = new PopupInfo( );
00177
00178 init();
00179
00180 #if (QT_VERSION-0 >= 0x030200) // XRANDR support
00181 connect( kapp->desktop(), SIGNAL( resized( int )), SLOT( desktopResized()));
00182 #endif
00183 }
00184
00185
00186 void Workspace::init()
00187 {
00188 checkElectricBorders();
00189
00190 supportWindow = new QWidget;
00191 XLowerWindow( qt_xdisplay(), supportWindow->winId());
00192
00193 XSetWindowAttributes attr;
00194 attr.override_redirect = 1;
00195 null_focus_window = XCreateWindow( qt_xdisplay(), qt_xrootwin(), -1,-1, 1, 1, 0, CopyFromParent,
00196 InputOnly, CopyFromParent, CWOverrideRedirect, &attr );
00197 XMapWindow(qt_xdisplay(), null_focus_window);
00198
00199 unsigned long protocols[ 5 ] =
00200 {
00201 NET::Supported |
00202 NET::SupportingWMCheck |
00203 NET::ClientList |
00204 NET::ClientListStacking |
00205 NET::DesktopGeometry |
00206 NET::NumberOfDesktops |
00207 NET::CurrentDesktop |
00208 NET::ActiveWindow |
00209 NET::WorkArea |
00210 NET::CloseWindow |
00211 NET::DesktopNames |
00212 NET::KDESystemTrayWindows |
00213 NET::WMName |
00214 NET::WMVisibleName |
00215 NET::WMDesktop |
00216 NET::WMWindowType |
00217 NET::WMState |
00218 NET::WMStrut |
00219 NET::WMIconGeometry |
00220 NET::WMIcon |
00221 NET::WMPid |
00222 NET::WMMoveResize |
00223 NET::WMKDESystemTrayWinFor |
00224 NET::WMKDEFrameStrut |
00225 NET::WMPing
00226 ,
00227 NET::NormalMask |
00228 NET::DesktopMask |
00229 NET::DockMask |
00230 NET::ToolbarMask |
00231 NET::MenuMask |
00232 NET::DialogMask |
00233 NET::OverrideMask |
00234 NET::TopMenuMask |
00235 NET::UtilityMask |
00236 NET::SplashMask |
00237 0
00238 ,
00239 NET::Modal |
00240
00241 NET::MaxVert |
00242 NET::MaxHoriz |
00243 NET::Shaded |
00244 NET::SkipTaskbar |
00245 NET::KeepAbove |
00246
00247 NET::SkipPager |
00248 NET::Hidden |
00249 NET::FullScreen |
00250 NET::KeepBelow |
00251 NET::DemandsAttention |
00252 0
00253 ,
00254 NET::WM2UserTime |
00255 NET::WM2StartupId |
00256 NET::WM2AllowedActions |
00257 NET::WM2RestackWindow |
00258 NET::WM2MoveResizeWindow |
00259 NET::WM2ExtendedStrut |
00260 NET::WM2KDETemporaryRules |
00261 0
00262 ,
00263 NET::ActionMove |
00264 NET::ActionResize |
00265 NET::ActionMinimize |
00266 NET::ActionShade |
00267
00268 NET::ActionMaxVert |
00269 NET::ActionMaxHoriz |
00270 NET::ActionFullScreen |
00271 NET::ActionChangeDesktop |
00272 NET::ActionClose |
00273 0
00274 ,
00275 };
00276
00277 rootInfo = new RootInfo( this, qt_xdisplay(), supportWindow->winId(), "KWin",
00278 protocols, 5, qt_xscreen() );
00279
00280 loadDesktopSettings();
00281
00282 NETRootInfo client_info( qt_xdisplay(), NET::ActiveWindow | NET::CurrentDesktop );
00283 int initial_desktop;
00284 if( !kapp->isSessionRestored())
00285 initial_desktop = client_info.currentDesktop();
00286 else
00287 {
00288 KConfigGroupSaver saver( kapp->sessionConfig(), "Session" );
00289 initial_desktop = kapp->sessionConfig()->readNumEntry( "desktop", 1 );
00290 }
00291 if( !setCurrentDesktop( initial_desktop ))
00292 setCurrentDesktop( 1 );
00293
00294
00295 initPositioning = new Placement(this);
00296
00297 connect(&reconfigureTimer, SIGNAL(timeout()), this,
00298 SLOT(slotReconfigure()));
00299 connect( &updateToolWindowsTimer, SIGNAL( timeout()), this, SLOT( slotUpdateToolWindows()));
00300
00301 connect(kapp, SIGNAL(appearanceChanged()), this,
00302 SLOT(slotReconfigure()));
00303 connect(kapp, SIGNAL(settingsChanged(int)), this,
00304 SLOT(slotSettingsChanged(int)));
00305
00306 active_client = NULL;
00307 rootInfo->setActiveWindow( None );
00308 focusToNull();
00309 if( !kapp->isSessionRestored())
00310 ++block_focus;
00311
00312 char nm[ 100 ];
00313 sprintf( nm, "_KDE_TOPMENU_OWNER_S%d", DefaultScreen( qt_xdisplay()));
00314 Atom topmenu_atom = XInternAtom( qt_xdisplay(), nm, False );
00315 topmenu_selection = new KSelectionOwner( topmenu_atom );
00316 topmenu_watcher = new KSelectionWatcher( topmenu_atom );
00317
00318
00319 {
00320 StackingUpdatesBlocker blocker( this );
00321
00322 if( options->topMenuEnabled() && topmenu_selection->claim( false ))
00323 setupTopMenuHandling();
00324 else
00325 lostTopMenuSelection();
00326
00327 unsigned int i, nwins;
00328 Window root_return, parent_return, *wins;
00329 XQueryTree(qt_xdisplay(), root, &root_return, &parent_return, &wins, &nwins);
00330 for (i = 0; i < nwins; i++)
00331 {
00332 XWindowAttributes attr;
00333 XGetWindowAttributes(qt_xdisplay(), wins[i], &attr);
00334 if (attr.override_redirect )
00335 continue;
00336 if( topmenu_space && topmenu_space->winId() == wins[ i ] )
00337 continue;
00338 if (attr.map_state != IsUnmapped)
00339 {
00340 if ( addSystemTrayWin( wins[i] ) )
00341 continue;
00342 Client* c = createClient( wins[i], true );
00343 if ( c != NULL && root != qt_xrootwin() )
00344 {
00345
00346 XReparentWindow( qt_xdisplay(), c->frameId(), root, 0, 0 );
00347 c->move(0,0);
00348 }
00349 }
00350 }
00351 if ( wins )
00352 XFree((void *) wins);
00353
00354 updateStackingOrder( true );
00355
00356 updateClientArea();
00357 raiseElectricBorders();
00358
00359
00360 NETPoint* viewports = new NETPoint[ number_of_desktops ];
00361 rootInfo->setDesktopViewport( number_of_desktops, *viewports );
00362 delete[] viewports;
00363 QRect geom = QApplication::desktop()->geometry();
00364 NETSize desktop_geometry;
00365 desktop_geometry.width = geom.width();
00366 desktop_geometry.height = geom.height();
00367
00368 rootInfo->setDesktopGeometry( -1, desktop_geometry );
00369
00370 }
00371
00372 Client* new_active_client = NULL;
00373 if( !kapp->isSessionRestored())
00374 {
00375 --block_focus;
00376 new_active_client = findClient( WindowMatchPredicate( client_info.activeWindow()));
00377 }
00378 if( new_active_client == NULL
00379 && activeClient() == NULL && should_get_focus.count() == 0 )
00380 {
00381 if( new_active_client == NULL )
00382 new_active_client = topClientOnDesktop( currentDesktop());
00383 if( new_active_client == NULL && !desktops.isEmpty() )
00384 new_active_client = findDesktop( true, currentDesktop());
00385 }
00386 if( new_active_client != NULL )
00387 activateClient( new_active_client );
00388
00389
00390
00391 workspaceInit = false;
00392
00393 }
00394
00395 Workspace::~Workspace()
00396 {
00397 blockStackingUpdates( true );
00398
00399
00400 for( ClientList::ConstIterator it = stacking_order.begin();
00401 it != stacking_order.end();
00402 ++it )
00403 {
00404
00405 (*it)->releaseWindow( true );
00406
00407 }
00408 delete desktop_widget;
00409 delete tab_box;
00410 delete popupinfo;
00411 delete popup;
00412 if ( root == qt_xrootwin() )
00413 XDeleteProperty(qt_xdisplay(), qt_xrootwin(), atoms->kwin_running);
00414
00415 writeWindowRules();
00416 KGlobal::config()->sync();
00417
00418 delete rootInfo;
00419 delete supportWindow;
00420 delete mgr;
00421 delete[] workarea;
00422 delete[] screenarea;
00423 delete startup;
00424 delete initPositioning;
00425 delete topmenu_watcher;
00426 delete topmenu_selection;
00427 delete topmenu_space;
00428 while( !rules.isEmpty())
00429 {
00430 delete rules.front();
00431 rules.pop_front();
00432 }
00433 XDestroyWindow( qt_xdisplay(), null_focus_window );
00434
00435 _self = 0;
00436 }
00437
00438 Client* Workspace::createClient( Window w, bool is_mapped )
00439 {
00440 StackingUpdatesBlocker blocker( this );
00441 Client* c = new Client( this );
00442 if( !c->manage( w, is_mapped ))
00443 {
00444 Client::deleteClient( c, Allowed );
00445 return NULL;
00446 }
00447 addClient( c, Allowed );
00448 return c;
00449 }
00450
00451 void Workspace::addClient( Client* c, allowed_t )
00452 {
00453 Group* grp = findGroup( c->window());
00454 if( grp != NULL )
00455 grp->gotLeader( c );
00456
00457 if ( c->isDesktop() )
00458 {
00459 desktops.append( c );
00460 if( active_client == NULL && should_get_focus.isEmpty() && c->isOnCurrentDesktop())
00461 requestFocus( c );
00462 }
00463 else
00464 {
00465 if ( c->wantsTabFocus() && !focus_chain.contains( c ))
00466 focus_chain.append( c );
00467 clients.append( c );
00468 }
00469 if( !unconstrained_stacking_order.contains( c ))
00470 unconstrained_stacking_order.append( c );
00471 if( !stacking_order.contains( c ))
00472 stacking_order.append( c );
00473 if( c->isTopMenu())
00474 addTopMenu( c );
00475 updateClientArea();
00476 updateClientLayer( c );
00477 if( c->isDesktop())
00478 {
00479 raiseClient( c );
00480
00481 if( activeClient() == NULL && should_get_focus.count() == 0 )
00482 activateClient( findDesktop( true, currentDesktop()));
00483 }
00484 checkTransients( c->window());
00485 updateStackingOrder( true );
00486 if( c->isUtility() || c->isMenu() || c->isToolbar())
00487 updateToolWindows( true );
00488 }
00489
00490
00491
00492
00493 void Workspace::removeClient( Client* c, allowed_t )
00494 {
00495 if (c == active_client && popup)
00496 popup->close();
00497 if( c == popup_client )
00498 popup_client = 0;
00499
00500 if( c->isDialog())
00501 Notify::raise( Notify::TransDelete );
00502 if( c->isNormalWindow())
00503 Notify::raise( Notify::Delete );
00504
00505 Q_ASSERT( clients.contains( c ) || desktops.contains( c ));
00506 clients.remove( c );
00507 desktops.remove( c );
00508 unconstrained_stacking_order.remove( c );
00509 stacking_order.remove( c );
00510 focus_chain.remove( c );
00511 attention_chain.remove( c );
00512 if( c->isTopMenu())
00513 removeTopMenu( c );
00514 Group* group = findGroup( c->window());
00515 if( group != NULL )
00516 group->lostLeader();
00517
00518 if ( c == most_recently_raised )
00519 most_recently_raised = 0;
00520 should_get_focus.remove( c );
00521 Q_ASSERT( c != active_client );
00522 if ( c == last_active_client )
00523 last_active_client = 0;
00524 if( c == pending_take_activity )
00525 pending_take_activity = NULL;
00526 if( c == delayfocus_client )
00527 cancelDelayFocus();
00528
00529 updateStackingOrder( true );
00530
00531 if (tab_grab)
00532 tab_box->repaint();
00533
00534 updateClientArea();
00535 }
00536
00537 void Workspace::updateCurrentTopMenu()
00538 {
00539 if( !managingTopMenus())
00540 return;
00541
00542 Client* menubar = 0;
00543 bool block_desktop_menubar = false;
00544 if( active_client )
00545 {
00546
00547 Client* menu_client = active_client;
00548 for(;;)
00549 {
00550 if( menu_client->isFullScreen())
00551 block_desktop_menubar = true;
00552 for( ClientList::ConstIterator it = menu_client->transients().begin();
00553 it != menu_client->transients().end();
00554 ++it )
00555 if( (*it)->isTopMenu())
00556 {
00557 menubar = *it;
00558 break;
00559 }
00560 if( menubar != NULL || !menu_client->isTransient())
00561 break;
00562 if( menu_client->isModal() || menu_client->transientFor() == NULL )
00563 break;
00564 menu_client = menu_client->transientFor();
00565 }
00566 if( !menubar )
00567 {
00568 for( ClientList::ConstIterator it = active_client->group()->members().begin();
00569 it != active_client->group()->members().end();
00570 ++it )
00571 if( (*it)->isTopMenu())
00572 {
00573 menubar = *it;
00574 break;
00575 }
00576 }
00577 }
00578 if( !menubar && !block_desktop_menubar && options->desktopTopMenu())
00579 {
00580
00581 Client* desktop = findDesktop( true, currentDesktop());
00582 if( desktop != NULL )
00583 {
00584 for( ClientList::ConstIterator it = desktop->transients().begin();
00585 it != desktop->transients().end();
00586 ++it )
00587 if( (*it)->isTopMenu())
00588 {
00589 menubar = *it;
00590 break;
00591 }
00592 }
00593
00594
00595
00596 if( menubar == NULL )
00597 {
00598 for( ClientList::ConstIterator it = topmenus.begin();
00599 it != topmenus.end();
00600 ++it )
00601 if( (*it)->wasOriginallyGroupTransient())
00602 {
00603 menubar = *it;
00604 break;
00605 }
00606 }
00607 }
00608
00609
00610 if ( menubar )
00611 {
00612 if( active_client && !menubar->isOnDesktop( active_client->desktop()))
00613 menubar->setDesktop( active_client->desktop());
00614 menubar->hideClient( false );
00615 topmenu_space->hide();
00616
00617
00618
00619 unconstrained_stacking_order.remove( menubar );
00620 unconstrained_stacking_order.append( menubar );
00621 }
00622 else if( !block_desktop_menubar )
00623 {
00624 topmenu_space->show();
00625 }
00626
00627
00628 for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it)
00629 {
00630 if( (*it)->isTopMenu() && (*it) != menubar )
00631 (*it)->hideClient( true );
00632 }
00633 }
00634
00635
00636 void Workspace::updateToolWindows( bool also_hide )
00637 {
00638
00639 const Group* group = NULL;
00640 const Client* client = active_client;
00641
00642
00643 while( client != NULL )
00644 {
00645 if( !client->isTransient())
00646 break;
00647 if( client->groupTransient())
00648 {
00649 group = client->group();
00650 break;
00651 }
00652 client = client->transientFor();
00653 }
00654
00655
00656
00657
00658 ClientList to_show, to_hide;
00659 for( ClientList::ConstIterator it = stacking_order.begin();
00660 it != stacking_order.end();
00661 ++it )
00662 {
00663 if( (*it)->isUtility() || (*it)->isMenu() || (*it)->isToolbar())
00664 {
00665 bool show = true;
00666 if( !(*it)->isTransient())
00667 {
00668 if( (*it)->group()->members().count() == 1 )
00669 show = true;
00670 else if( client != NULL && (*it)->group() == client->group())
00671 show = true;
00672 else
00673 show = false;
00674 }
00675 else
00676 {
00677 if( group != NULL && (*it)->group() == group )
00678 show = true;
00679 else if( client != NULL && client->hasTransient( (*it), true ))
00680 show = true;
00681 else
00682 show = false;
00683 }
00684 if( !show && also_hide )
00685 {
00686 const ClientList mainclients = (*it)->mainClients();
00687
00688
00689 if( mainclients.isEmpty())
00690 show = true;
00691 for( ClientList::ConstIterator it2 = mainclients.begin();
00692 it2 != mainclients.end();
00693 ++it2 )
00694 {
00695 if( (*it2)->isSpecialWindow())
00696 show = true;
00697 }
00698 if( !show )
00699 to_hide.append( *it );
00700 }
00701 if( show )
00702 to_show.append( *it );
00703 }
00704 }
00705 for( ClientList::ConstIterator it = to_show.fromLast();
00706 it != to_show.end();
00707 --it )
00708
00709 (*it)->hideClient( false );
00710 if( also_hide )
00711 {
00712 for( ClientList::ConstIterator it = to_hide.begin();
00713 it != to_hide.end();
00714 ++it )
00715 (*it)->hideClient( true );
00716 updateToolWindowsTimer.stop();
00717 }
00718 else
00719 {
00720 updateToolWindowsTimer.start( 50, true );
00721 }
00722 }
00723
00724 void Workspace::slotUpdateToolWindows()
00725 {
00726 updateToolWindows( true );
00727 }
00728
00732 void Workspace::updateColormap()
00733 {
00734 Colormap cmap = default_colormap;
00735 if ( activeClient() && activeClient()->colormap() != None )
00736 cmap = activeClient()->colormap();
00737 if ( cmap != installed_colormap )
00738 {
00739 XInstallColormap(qt_xdisplay(), cmap );
00740 installed_colormap = cmap;
00741 }
00742 }
00743
00744 void Workspace::reconfigure()
00745 {
00746 reconfigureTimer.start(200, true);
00747 }
00748
00749
00750 void Workspace::slotSettingsChanged(int category)
00751 {
00752 kdDebug(1212) << "Workspace::slotSettingsChanged()" << endl;
00753 if( category == (int) KApplication::SETTINGS_SHORTCUTS )
00754 readShortcuts();
00755 }
00756
00760 KWIN_PROCEDURE( CheckBorderSizesProcedure, cl->checkBorderSizes() );
00761 KWIN_PROCEDURE( ResetupRulesProcedure, cl->setupWindowRules( true ) );
00762
00763 void Workspace::slotReconfigure()
00764 {
00765 kdDebug(1212) << "Workspace::slotReconfigure()" << endl;
00766 reconfigureTimer.stop();
00767
00768 KGlobal::config()->reparseConfiguration();
00769 unsigned long changed = options->updateSettings();
00770 tab_box->reconfigure();
00771 popupinfo->reconfigure();
00772 readShortcuts();
00773 forEachClient( CheckIgnoreFocusStealingProcedure());
00774
00775 if( mgr->reset( changed ))
00776 {
00777 #if 0 // This actually seems to make things worse now
00778 QWidget curtain;
00779 curtain.setBackgroundMode( NoBackground );
00780 curtain.setGeometry( QApplication::desktop()->geometry() );
00781 curtain.show();
00782 #endif
00783 for( ClientList::ConstIterator it = clients.begin();
00784 it != clients.end();
00785 ++it )
00786 {
00787 (*it)->updateDecoration( true, true );
00788 }
00789 mgr->destroyPreviousPlugin();
00790 }
00791 else
00792 {
00793 forEachClient( CheckBorderSizesProcedure());
00794 }
00795
00796 checkElectricBorders();
00797
00798 if( options->topMenuEnabled() && !managingTopMenus())
00799 {
00800 if( topmenu_selection->claim( false ))
00801 setupTopMenuHandling();
00802 else
00803 lostTopMenuSelection();
00804 }
00805 else if( !options->topMenuEnabled() && managingTopMenus())
00806 {
00807 topmenu_selection->release();
00808 lostTopMenuSelection();
00809 }
00810 topmenu_height = 0;
00811 if( managingTopMenus())
00812 {
00813 updateTopMenuGeometry();
00814 updateCurrentTopMenu();
00815 }
00816
00817 loadWindowRules();
00818 forEachClient( ResetupRulesProcedure());
00819 }
00820
00821 void Workspace::loadDesktopSettings()
00822 {
00823 KConfig* c = KGlobal::config();
00824 QCString groupname;
00825 if (screen_number == 0)
00826 groupname = "Desktops";
00827 else
00828 groupname.sprintf("Desktops-screen-%d", screen_number);
00829 KConfigGroupSaver saver(c,groupname);
00830
00831 int n = c->readNumEntry("Number", 4);
00832 number_of_desktops = n;
00833 delete workarea;
00834 workarea = new QRect[ n + 1 ];
00835 delete screenarea;
00836 screenarea = NULL;
00837 rootInfo->setNumberOfDesktops( number_of_desktops );
00838 desktop_focus_chain.resize( n );
00839 for(int i = 1; i <= n; i++)
00840 {
00841 QString s = c->readEntry(QString("Name_%1").arg(i),
00842 i18n("Desktop %1").arg(i));
00843 rootInfo->setDesktopName( i, s.utf8().data() );
00844 desktop_focus_chain[i-1] = i;
00845 }
00846 }
00847
00848 void Workspace::saveDesktopSettings()
00849 {
00850 KConfig* c = KGlobal::config();
00851 QCString groupname;
00852 if (screen_number == 0)
00853 groupname = "Desktops";
00854 else
00855 groupname.sprintf("Desktops-screen-%d", screen_number);
00856 KConfigGroupSaver saver(c,groupname);
00857
00858 c->writeEntry("Number", number_of_desktops );
00859 for(int i = 1; i <= number_of_desktops; i++)
00860 {
00861 QString s = desktopName( i );
00862 QString defaultvalue = i18n("Desktop %1").arg(i);
00863 if ( s.isEmpty() )
00864 {
00865 s = defaultvalue;
00866 rootInfo->setDesktopName( i, s.utf8().data() );
00867 }
00868
00869 if (s != defaultvalue)
00870 {
00871 c->writeEntry( QString("Name_%1").arg(i), s );
00872 }
00873 else
00874 {
00875 QString currentvalue = c->readEntry(QString("Name_%1").arg(i));
00876 if (currentvalue != defaultvalue)
00877 c->writeEntry( QString("Name_%1").arg(i), "" );
00878 }
00879 }
00880 }
00881
00882 QStringList Workspace::configModules(bool controlCenter)
00883 {
00884 QStringList args;
00885 args << "kde-kwindecoration.desktop";
00886 if (controlCenter)
00887 args << "kde-kwinoptions.desktop";
00888 else if (kapp->authorizeControlModule("kde-kwinoptions.desktop"))
00889 args << "kwinactions" << "kwinfocus" << "kwinmoving" << "kwinadvanced" << "kwinrules";
00890 return args;
00891 }
00892
00893 void Workspace::configureWM()
00894 {
00895 KApplication::kdeinitExec( "kcmshell", configModules(false) );
00896 }
00897
00901 void Workspace::doNotManage( QString title )
00902 {
00903 doNotManageList.append( title );
00904 }
00905
00909 bool Workspace::isNotManaged( const QString& title )
00910 {
00911 for ( QStringList::Iterator it = doNotManageList.begin(); it != doNotManageList.end(); ++it )
00912 {
00913 QRegExp r( (*it) );
00914 if (r.search(title) != -1)
00915 {
00916 doNotManageList.remove( it );
00917 return TRUE;
00918 }
00919 }
00920 return FALSE;
00921 }
00922
00926 void Workspace::refresh()
00927 {
00928 QWidget w;
00929 w.setGeometry( QApplication::desktop()->geometry() );
00930 w.show();
00931 w.hide();
00932 QApplication::flushX();
00933 }
00934
00942 class ObscuringWindows
00943 {
00944 public:
00945 ~ObscuringWindows();
00946 void create( Client* c );
00947 private:
00948 QValueList<Window> obscuring_windows;
00949 static QValueList<Window>* cached;
00950 static unsigned int max_cache_size;
00951 };
00952
00953 QValueList<Window>* ObscuringWindows::cached = 0;
00954 unsigned int ObscuringWindows::max_cache_size = 0;
00955
00956 void ObscuringWindows::create( Client* c )
00957 {
00958 if( cached == 0 )
00959 cached = new QValueList<Window>;
00960 Window obs_win;
00961 XWindowChanges chngs;
00962 int mask = CWSibling | CWStackMode;
00963 if( cached->count() > 0 )
00964 {
00965 cached->remove( obs_win = cached->first());
00966 chngs.x = c->x();
00967 chngs.y = c->y();
00968 chngs.width = c->width();
00969 chngs.height = c->height();
00970 mask |= CWX | CWY | CWWidth | CWHeight;
00971 }
00972 else
00973 {
00974 XSetWindowAttributes a;
00975 a.background_pixmap = None;
00976 a.override_redirect = True;
00977 obs_win = XCreateWindow( qt_xdisplay(), qt_xrootwin(), c->x(), c->y(),
00978 c->width(), c->height(), 0, CopyFromParent, InputOutput,
00979 CopyFromParent, CWBackPixmap | CWOverrideRedirect, &a );
00980 }
00981 chngs.sibling = c->frameId();
00982 chngs.stack_mode = Below;
00983 XConfigureWindow( qt_xdisplay(), obs_win, mask, &chngs );
00984 XMapWindow( qt_xdisplay(), obs_win );
00985 obscuring_windows.append( obs_win );
00986 }
00987
00988 ObscuringWindows::~ObscuringWindows()
00989 {
00990 max_cache_size = QMAX( max_cache_size, obscuring_windows.count() + 4 ) - 1;
00991 for( QValueList<Window>::ConstIterator it = obscuring_windows.begin();
00992 it != obscuring_windows.end();
00993 ++it )
00994 {
00995 XUnmapWindow( qt_xdisplay(), *it );
00996 if( cached->count() < max_cache_size )
00997 cached->prepend( *it );
00998 else
00999 XDestroyWindow( qt_xdisplay(), *it );
01000 }
01001 }
01002
01003
01010 bool Workspace::setCurrentDesktop( int new_desktop )
01011 {
01012 if (new_desktop < 1 || new_desktop > number_of_desktops )
01013 return false;
01014
01015 if( popup )
01016 popup->close();
01017 ++block_focus;
01018
01019 StackingUpdatesBlocker blocker( this );
01020
01021 if (new_desktop != current_desktop)
01022 {
01023
01024
01025
01026
01027 Notify::raise((Notify::Event) (Notify::DesktopChange+new_desktop));
01028
01029 ObscuringWindows obs_wins;
01030
01031 int old_desktop = current_desktop;
01032 current_desktop = new_desktop;
01033
01034 for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it)
01035 if ( !(*it)->isOnDesktop( new_desktop ) && (*it) != movingClient )
01036 {
01037 if( (*it)->isShown( true ) && (*it)->isOnDesktop( old_desktop ))
01038 obs_wins.create( *it );
01039 (*it)->virtualDesktopChange();
01040 }
01041
01042 rootInfo->setCurrentDesktop( current_desktop );
01043
01044 if( movingClient && !movingClient->isOnDesktop( new_desktop ))
01045 movingClient->setDesktop( new_desktop );
01046
01047 for ( ClientList::ConstIterator it = stacking_order.fromLast(); it != stacking_order.end(); --it)
01048 if ( (*it)->isOnDesktop( new_desktop ) )
01049 (*it)->virtualDesktopChange();
01050 }
01051
01052
01053 --block_focus;
01054 Client* c = 0;
01055
01056 if ( options->focusPolicyIsReasonable())
01057 {
01058
01059
01060 if ( focus_chain.contains( active_client ) && active_client->isShown( true )
01061 && active_client->isOnCurrentDesktop())
01062 {
01063 c = active_client;
01064 }
01065
01066 if ( !c )
01067 {
01068 for( ClientList::ConstIterator it = focus_chain.fromLast(); it != focus_chain.end(); --it)
01069 {
01070 if ( (*it)->isShown( false ) && !(*it)->isOnAllDesktops() && (*it)->isOnCurrentDesktop())
01071 {
01072 c = *it;
01073 break;
01074 }
01075 }
01076 }
01077
01078 if ( !c )
01079 {
01080 for( ClientList::ConstIterator it = focus_chain.fromLast(); it != focus_chain.end(); --it)
01081 {
01082 if ( (*it)->isShown( false ) && (*it)->isOnCurrentDesktop())
01083 {
01084 c = *it;
01085 break;
01086 }
01087 }
01088 }
01089 }
01090
01091
01092
01093
01094 else if( active_client && active_client->isShown( true ) && active_client->isOnCurrentDesktop())
01095 c= active_client;
01096
01097 if( c != active_client )
01098 setActiveClient( NULL, Allowed );
01099
01100 if ( c )
01101 requestFocus( c );
01102 else
01103 focusToNull();
01104
01105 if( !desktops.isEmpty() )
01106 {
01107 Window w_tmp;
01108 int i_tmp;
01109 XGetInputFocus( qt_xdisplay(), &w_tmp, &i_tmp );
01110 if( w_tmp == null_focus_window )
01111 requestFocus( findDesktop( true, currentDesktop()));
01112 }
01113
01114 updateCurrentTopMenu();
01115
01116
01117
01118
01119
01120
01121 for( int i = desktop_focus_chain.find( current_desktop ); i > 0; i-- )
01122 desktop_focus_chain[i] = desktop_focus_chain[i-1];
01123 desktop_focus_chain[0] = current_desktop;
01124
01125
01126
01127
01128
01129 return true;
01130 }
01131
01132 void Workspace::nextDesktop()
01133 {
01134 int desktop = currentDesktop() + 1;
01135 setCurrentDesktop(desktop > numberOfDesktops() ? 1 : desktop);
01136 popupinfo->showInfo( desktopName(currentDesktop()) );
01137 }
01138
01139 void Workspace::previousDesktop()
01140 {
01141 int desktop = currentDesktop() - 1;
01142 setCurrentDesktop(desktop > 0 ? desktop : numberOfDesktops());
01143 popupinfo->showInfo( desktopName(currentDesktop()) );
01144 }
01145
01149 void Workspace::setNumberOfDesktops( int n )
01150 {
01151 if ( n == number_of_desktops )
01152 return;
01153 int old_number_of_desktops = number_of_desktops;
01154 number_of_desktops = n;
01155
01156 if( currentDesktop() > numberOfDesktops())
01157 setCurrentDesktop( numberOfDesktops());
01158
01159
01160
01161 if( old_number_of_desktops < number_of_desktops )
01162 {
01163 rootInfo->setNumberOfDesktops( number_of_desktops );
01164 NETPoint* viewports = new NETPoint[ number_of_desktops ];
01165 rootInfo->setDesktopViewport( number_of_desktops, *viewports );
01166 delete[] viewports;
01167 updateClientArea( true );
01168 }
01169
01170
01171
01172 if( old_number_of_desktops > number_of_desktops )
01173 {
01174 for( ClientList::ConstIterator it = clients.begin();
01175 it != clients.end();
01176 ++it)
01177 {
01178 if( !(*it)->isOnAllDesktops() && (*it)->desktop() > numberOfDesktops())
01179 sendClientToDesktop( *it, numberOfDesktops(), true );
01180 }
01181 }
01182 if( old_number_of_desktops > number_of_desktops )
01183 {
01184 rootInfo->setNumberOfDesktops( number_of_desktops );
01185 NETPoint* viewports = new NETPoint[ number_of_desktops ];
01186 rootInfo->setDesktopViewport( number_of_desktops, *viewports );
01187 delete[] viewports;
01188 updateClientArea( true );
01189 }
01190
01191 saveDesktopSettings();
01192
01193
01194 desktop_focus_chain.resize( n );
01195 for( int i = 0; i < (int)desktop_focus_chain.size(); i++ )
01196 desktop_focus_chain[i] = i+1;
01197 }
01198
01204 void Workspace::sendClientToDesktop( Client* c, int desk, bool dont_activate )
01205 {
01206 bool was_on_desktop = c->isOnDesktop( desk ) || c->isOnAllDesktops();
01207 c->setDesktop( desk );
01208 if ( c->desktop() != desk )
01209 return;
01210 desk = c->desktop();
01211
01212 if ( c->isOnDesktop( currentDesktop() ) )
01213 {
01214 if ( c->wantsTabFocus() && options->focusPolicyIsReasonable()
01215 && !was_on_desktop
01216 && !dont_activate )
01217 requestFocus( c );
01218 else
01219 restackClientUnderActive( c );
01220 }
01221 else
01222 {
01223 raiseClient( c );
01224 focus_chain.remove( c );
01225 if ( c->wantsTabFocus() )
01226 focus_chain.append( c );
01227 }
01228
01229 ClientList transients_stacking_order = ensureStackingOrder( c->transients());
01230 for( ClientList::ConstIterator it = transients_stacking_order.begin();
01231 it != transients_stacking_order.end();
01232 ++it )
01233 sendClientToDesktop( *it, desk, dont_activate );
01234 updateClientArea();
01235 }
01236
01237 void Workspace::setDesktopLayout(int o, int x, int y)
01238 {
01239 layoutOrientation = (Qt::Orientation) o;
01240 layoutX = x;
01241 layoutY = y;
01242 }
01243
01244 void Workspace::calcDesktopLayout(int &x, int &y)
01245 {
01246 x = layoutX;
01247 y = layoutY;
01248 if ((x == -1) && (y > 0))
01249 x = (numberOfDesktops()+y-1) / y;
01250 else if ((y == -1) && (x > 0))
01251 y = (numberOfDesktops()+x-1) / x;
01252
01253 if (x == -1)
01254 x = 1;
01255 if (y == -1)
01256 y = 1;
01257 }
01258
01263 bool Workspace::addSystemTrayWin( WId w )
01264 {
01265 if ( systemTrayWins.contains( w ) )
01266 return TRUE;
01267
01268 NETWinInfo ni( qt_xdisplay(), w, root, NET::WMKDESystemTrayWinFor );
01269 WId trayWinFor = ni.kdeSystemTrayWinFor();
01270 if ( !trayWinFor )
01271 return FALSE;
01272 systemTrayWins.append( SystemTrayWindow( w, trayWinFor ) );
01273 XSelectInput( qt_xdisplay(), w,
01274 StructureNotifyMask
01275 );
01276 XAddToSaveSet( qt_xdisplay(), w );
01277 propagateSystemTrayWins();
01278 return TRUE;
01279 }
01280
01285 bool Workspace::removeSystemTrayWin( WId w, bool check )
01286 {
01287 if ( !systemTrayWins.contains( w ) )
01288 return FALSE;
01289 if( check )
01290 {
01291
01292
01293
01294
01295
01296
01297
01298 int num_props;
01299 Atom* props = XListProperties( qt_xdisplay(), w, &num_props );
01300 if( props != NULL )
01301 {
01302 for( int i = 0;
01303 i < num_props;
01304 ++i )
01305 if( props[ i ] == atoms->kde_system_tray_embedding )
01306 {
01307 XFree( props );
01308 return false;
01309 }
01310 XFree( props );
01311 }
01312 }
01313 systemTrayWins.remove( w );
01314 propagateSystemTrayWins();
01315 return TRUE;
01316 }
01317
01318
01322 void Workspace::propagateSystemTrayWins()
01323 {
01324 Window *cl = new Window[ systemTrayWins.count()];
01325
01326 int i = 0;
01327 for ( SystemTrayWindowList::ConstIterator it = systemTrayWins.begin(); it != systemTrayWins.end(); ++it )
01328 {
01329 cl[i++] = (*it).win;
01330 }
01331
01332 rootInfo->setKDESystemTrayWindows( cl, i );
01333 delete [] cl;
01334 }
01335
01336
01337 void Workspace::killWindowId( Window window_to_kill )
01338 {
01339 if( window_to_kill == None )
01340 return;
01341 Window window = window_to_kill;
01342 Client* client = NULL;
01343 for(;;)
01344 {
01345 client = findClient( FrameIdMatchPredicate( window ));
01346 if( client != NULL )
01347 break;
01348 Window parent, root;
01349 Window* children;
01350 unsigned int children_count;
01351 XQueryTree( qt_xdisplay(), window, &root, &parent, &children, &children_count );
01352 if( children != NULL )
01353 XFree( children );
01354 if( window == root )
01355 break;
01356 window = parent;
01357 }
01358 if( client != NULL )
01359 client->killWindow();
01360 else
01361 XKillClient( qt_xdisplay(), window_to_kill );
01362 }
01363
01364
01365 void Workspace::sendPingToWindow( Window window, Time timestamp )
01366 {
01367 rootInfo->sendPing( window, timestamp );
01368 }
01369
01370 void Workspace::sendTakeActivity( Client* c, Time timestamp, long flags )
01371 {
01372 rootInfo->takeActivity( c->window(), timestamp, flags );
01373 pending_take_activity = c;
01374 }
01375
01376
01380 void Workspace::slotGrabWindow()
01381 {
01382 if ( active_client )
01383 {
01384 QPixmap snapshot = QPixmap::grabWindow( active_client->frameId() );
01385
01386
01387 if( Shape::available())
01388 {
01389
01390 int count, order;
01391 XRectangle* rects = XShapeGetRectangles( qt_xdisplay(), active_client->frameId(),
01392 ShapeBounding, &count, &order);
01393
01394
01395
01396
01397 if (rects)
01398 {
01399
01400 QRegion contents;
01401 for (int pos = 0; pos < count; pos++)
01402 contents += QRegion(rects[pos].x, rects[pos].y,
01403 rects[pos].width, rects[pos].height);
01404 XFree(rects);
01405
01406
01407 QRegion bbox(0, 0, snapshot.width(), snapshot.height());
01408
01409
01410 QRegion maskedAway = bbox - contents;
01411 QMemArray<QRect> maskedAwayRects = maskedAway.rects();
01412
01413
01414 QBitmap mask( snapshot.width(), snapshot.height());
01415 QPainter p(&mask);
01416 p.fillRect(0, 0, mask.width(), mask.height(), Qt::color1);
01417 for (uint pos = 0; pos < maskedAwayRects.count(); pos++)
01418 p.fillRect(maskedAwayRects[pos], Qt::color0);
01419 p.end();
01420 snapshot.setMask(mask);
01421 }
01422 }
01423
01424 QClipboard *cb = QApplication::clipboard();
01425 cb->setPixmap( snapshot );
01426 }
01427 else
01428 slotGrabDesktop();
01429 }
01430
01434 void Workspace::slotGrabDesktop()
01435 {
01436 QPixmap p = QPixmap::grabWindow( qt_xrootwin() );
01437 QClipboard *cb = QApplication::clipboard();
01438 cb->setPixmap( p );
01439 }
01440
01441
01445 void Workspace::slotMouseEmulation()
01446 {
01447
01448 if ( mouse_emulation )
01449 {
01450 XUngrabKeyboard(qt_xdisplay(), qt_x_time);
01451 mouse_emulation = FALSE;
01452 return;
01453 }
01454
01455 if ( XGrabKeyboard(qt_xdisplay(),
01456 root, FALSE,
01457 GrabModeAsync, GrabModeAsync,
01458 qt_x_time) == GrabSuccess )
01459 {
01460 mouse_emulation = TRUE;
01461 mouse_emulation_state = 0;
01462 mouse_emulation_window = 0;
01463 }
01464 }
01465
01472 WId Workspace::getMouseEmulationWindow()
01473 {
01474 Window root;
01475 Window child = qt_xrootwin();
01476 int root_x, root_y, lx, ly;
01477 uint state;
01478 Window w;
01479 Client * c = 0;
01480 do
01481 {
01482 w = child;
01483 if (!c)
01484 c = findClient( FrameIdMatchPredicate( w ));
01485 XQueryPointer( qt_xdisplay(), w, &root, &child,
01486 &root_x, &root_y, &lx, &ly, &state );
01487 } while ( child != None && child != w );
01488
01489 if ( c && !c->isActive() )
01490 activateClient( c );
01491 return (WId) w;
01492 }
01493
01497 unsigned int Workspace::sendFakedMouseEvent( QPoint pos, WId w, MouseEmulation type, int button, unsigned int state )
01498 {
01499 if ( !w )
01500 return state;
01501 QWidget* widget = QWidget::find( w );
01502 if ( (!widget || widget->inherits("QToolButton") ) && !findClient( WindowMatchPredicate( w )) )
01503 {
01504 int x, y;
01505 Window xw;
01506 XTranslateCoordinates( qt_xdisplay(), qt_xrootwin(), w, pos.x(), pos.y(), &x, &y, &xw );
01507 if ( type == EmuMove )
01508 {
01509 XMotionEvent e;
01510 e.type = MotionNotify;
01511 e.window = w;
01512 e.root = qt_xrootwin();
01513 e.subwindow = w;
01514 e.time = qt_x_time;
01515 e.x = x;
01516 e.y = y;
01517 e.x_root = pos.x();
01518 e.y_root = pos.y();
01519 e.state = state;
01520 e.is_hint = NotifyNormal;
01521 XSendEvent( qt_xdisplay(), w, TRUE, ButtonMotionMask, (XEvent*)&e );
01522 }
01523 else
01524 {
01525 XButtonEvent e;
01526 e.type = type == EmuRelease ? ButtonRelease : ButtonPress;
01527 e.window = w;
01528 e.root = qt_xrootwin();
01529 e.subwindow = w;
01530 e.time = qt_x_time;
01531 e.x = x;
01532 e.y = y;
01533 e.x_root = pos.x();
01534 e.y_root = pos.y();
01535 e.state = state;
01536 e.button = button;
01537 XSendEvent( qt_xdisplay(), w, TRUE, ButtonPressMask, (XEvent*)&e );
01538
01539 if ( type == EmuPress )
01540 {
01541 switch ( button )
01542 {
01543 case 2:
01544 state |= Button2Mask;
01545 break;
01546 case 3:
01547 state |= Button3Mask;
01548 break;
01549 default:
01550 state |= Button1Mask;
01551 break;
01552 }
01553 }
01554 else
01555 {
01556 switch ( button )
01557 {
01558 case 2:
01559 state &= ~Button2Mask;
01560 break;
01561 case 3:
01562 state &= ~Button3Mask;
01563 break;
01564 default:
01565 state &= ~Button1Mask;
01566 break;
01567 }
01568 }
01569 }
01570 }
01571 return state;
01572 }
01573
01577 bool Workspace::keyPressMouseEmulation( XKeyEvent& ev )
01578 {
01579 if ( root != qt_xrootwin() )
01580 return FALSE;
01581 int kc = XKeycodeToKeysym(qt_xdisplay(), ev.keycode, 0);
01582 int km = ev.state & (ControlMask | Mod1Mask | ShiftMask);
01583
01584 bool is_control = km & ControlMask;
01585 bool is_alt = km & Mod1Mask;
01586 bool is_shift = km & ShiftMask;
01587 int delta = is_control?1:is_alt?32:8;
01588 QPoint pos = QCursor::pos();
01589
01590 switch ( kc )
01591 {
01592 case XK_Left:
01593 case XK_KP_Left:
01594 pos.rx() -= delta;
01595 break;
01596 case XK_Right:
01597 case XK_KP_Right:
01598 pos.rx() += delta;
01599 break;
01600 case XK_Up:
01601 case XK_KP_Up:
01602 pos.ry() -= delta;
01603 break;
01604 case XK_Down:
01605 case XK_KP_Down:
01606 pos.ry() += delta;
01607 break;
01608 case XK_F1:
01609 if ( !mouse_emulation_state )
01610 mouse_emulation_window = getMouseEmulationWindow();
01611 if ( (mouse_emulation_state & Button1Mask) == 0 )
01612 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuPress, Button1, mouse_emulation_state );
01613 if ( !is_shift )
01614 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button1, mouse_emulation_state );
01615 break;
01616 case XK_F2:
01617 if ( !mouse_emulation_state )
01618 mouse_emulation_window = getMouseEmulationWindow();
01619 if ( (mouse_emulation_state & Button2Mask) == 0 )
01620 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuPress, Button2, mouse_emulation_state );
01621 if ( !is_shift )
01622 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button2, mouse_emulation_state );
01623 break;
01624 case XK_F3:
01625 if ( !mouse_emulation_state )
01626 mouse_emulation_window = getMouseEmulationWindow();
01627 if ( (mouse_emulation_state & Button3Mask) == 0 )
01628 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuPress, Button3, mouse_emulation_state );
01629 if ( !is_shift )
01630 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button3, mouse_emulation_state );
01631 break;
01632 case XK_Return:
01633 case XK_space:
01634 case XK_KP_Enter:
01635 case XK_KP_Space:
01636 {
01637 if ( !mouse_emulation_state )
01638 {
01639
01640 mouse_emulation_window = getMouseEmulationWindow();
01641 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuPress, Button1, mouse_emulation_state );
01642 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button1, mouse_emulation_state );
01643 }
01644 else
01645 {
01646 if ( mouse_emulation_state & Button1Mask )
01647 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button1, mouse_emulation_state );
01648 if ( mouse_emulation_state & Button2Mask )
01649 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button2, mouse_emulation_state );
01650 if ( mouse_emulation_state & Button3Mask )
01651 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuRelease, Button3, mouse_emulation_state );
01652 }
01653 }
01654
01655 case XK_Escape:
01656 XUngrabKeyboard(qt_xdisplay(), qt_x_time);
01657 mouse_emulation = FALSE;
01658 return TRUE;
01659 default:
01660 return FALSE;
01661 }
01662
01663 QCursor::setPos( pos );
01664 if ( mouse_emulation_state )
01665 mouse_emulation_state = sendFakedMouseEvent( pos, mouse_emulation_window, EmuMove, 0, mouse_emulation_state );
01666 return TRUE;
01667
01668 }
01669
01675 QWidget* Workspace::desktopWidget()
01676 {
01677 return desktop_widget;
01678 }
01679
01680
01681 void Workspace::delayFocus()
01682 {
01683 requestFocus( delayfocus_client );
01684 cancelDelayFocus();
01685 }
01686
01687 void Workspace::requestDelayFocus( Client* c )
01688 {
01689 delayfocus_client = c;
01690 delete delayFocusTimer;
01691 delayFocusTimer = new QTimer( this );
01692 connect( delayFocusTimer, SIGNAL( timeout() ), this, SLOT( delayFocus() ) );
01693 delayFocusTimer->start( options->delayFocusInterval, TRUE );
01694 }
01695
01696 void Workspace::cancelDelayFocus()
01697 {
01698 delete delayFocusTimer;
01699 delayFocusTimer = 0;
01700 }
01701
01702
01703
01704
01705
01706
01707
01708
01709 void Workspace::checkElectricBorders( bool force )
01710 {
01711 if( force )
01712 destroyBorderWindows();
01713
01714 electric_current_border = 0;
01715
01716 QRect r = QApplication::desktop()->geometry();
01717 electricTop = r.top();
01718 electricBottom = r.bottom();
01719 electricLeft = r.left();
01720 electricRight = r.right();
01721
01722 if (options->electricBorders() == Options::ElectricAlways)
01723 createBorderWindows();
01724 else
01725 destroyBorderWindows();
01726 }
01727
01728 void Workspace::createBorderWindows()
01729 {
01730 if ( electric_have_borders )
01731 return;
01732
01733 electric_have_borders = true;
01734
01735 QRect r = QApplication::desktop()->geometry();
01736 XSetWindowAttributes attributes;
01737 unsigned long valuemask;
01738 attributes.override_redirect = True;
01739 attributes.event_mask = (EnterWindowMask | LeaveWindowMask |
01740 VisibilityChangeMask);
01741 valuemask= (CWOverrideRedirect | CWEventMask | CWCursor );
01742 attributes.cursor = XCreateFontCursor(qt_xdisplay(),
01743 XC_sb_up_arrow);
01744 electric_top_border = XCreateWindow (qt_xdisplay(), qt_xrootwin(),
01745 0,0,
01746 r.width(),1,
01747 0,
01748 CopyFromParent, InputOnly,
01749 CopyFromParent,
01750 valuemask, &attributes);
01751 XMapWindow(qt_xdisplay(), electric_top_border);
01752
01753 attributes.cursor = XCreateFontCursor(qt_xdisplay(),
01754 XC_sb_down_arrow);
01755 electric_bottom_border = XCreateWindow (qt_xdisplay(), qt_xrootwin(),
01756 0,r.height()-1,
01757 r.width(),1,
01758 0,
01759 CopyFromParent, InputOnly,
01760 CopyFromParent,
01761 valuemask, &attributes);
01762 XMapWindow(qt_xdisplay(), electric_bottom_border);
01763
01764 attributes.cursor = XCreateFontCursor(qt_xdisplay(),
01765 XC_sb_left_arrow);
01766 electric_left_border = XCreateWindow (qt_xdisplay(), qt_xrootwin(),
01767 0,0,
01768 1,r.height(),
01769 0,
01770 CopyFromParent, InputOnly,
01771 CopyFromParent,
01772 valuemask, &attributes);
01773 XMapWindow(qt_xdisplay(), electric_left_border);
01774
01775 attributes.cursor = XCreateFontCursor(qt_xdisplay(),
01776 XC_sb_right_arrow);
01777 electric_right_border = XCreateWindow (qt_xdisplay(), qt_xrootwin(),
01778 r.width()-1,0,
01779 1,r.height(),
01780 0,
01781 CopyFromParent, InputOnly,
01782 CopyFromParent,
01783 valuemask, &attributes);
01784 XMapWindow(qt_xdisplay(), electric_right_border);
01785 }
01786
01787
01788
01789
01790
01791
01792
01793 void Workspace::destroyBorderWindows()
01794 {
01795 if( !electric_have_borders)
01796 return;
01797
01798 electric_have_borders = false;
01799
01800 if(electric_top_border)
01801 XDestroyWindow(qt_xdisplay(),electric_top_border);
01802 if(electric_bottom_border)
01803 XDestroyWindow(qt_xdisplay(),electric_bottom_border);
01804 if(electric_left_border)
01805 XDestroyWindow(qt_xdisplay(),electric_left_border);
01806 if(electric_right_border)
01807 XDestroyWindow(qt_xdisplay(),electric_right_border);
01808
01809 electric_top_border = None;
01810 electric_bottom_border = None;
01811 electric_left_border = None;
01812 electric_right_border = None;
01813 }
01814
01815 void Workspace::clientMoved(const QPoint &pos, Time now)
01816 {
01817 if (options->electricBorders() == Options::ElectricDisabled)
01818 return;
01819
01820 if ((pos.x() != electricLeft) &&
01821 (pos.x() != electricRight) &&
01822 (pos.y() != electricTop) &&
01823 (pos.y() != electricBottom))
01824 return;
01825
01826 Time treshold_set = options->electricBorderDelay();
01827 Time treshold_reset = 250;
01828 int distance_reset = 10;
01829
01830 int border = 0;
01831 if (pos.x() == electricLeft)
01832 border = 1;
01833 else if (pos.x() == electricRight)
01834 border = 2;
01835 else if (pos.y() == electricTop)
01836 border = 3;
01837 else if (pos.y() == electricBottom)
01838 border = 4;
01839
01840 if ((electric_current_border == border) &&
01841 (timestampDiff(electric_time_last, now) < treshold_reset) &&
01842 ((pos-electric_push_point).manhattanLength() < distance_reset))
01843 {
01844 electric_time_last = now;
01845
01846 if (timestampDiff(electric_time_first, now) > treshold_set)
01847 {
01848 electric_current_border = 0;
01849
01850 QRect r = QApplication::desktop()->geometry();
01851 int offset;
01852
01853 int desk_before = currentDesktop();
01854 switch(border)
01855 {
01856 case 1:
01857 slotSwitchDesktopLeft();
01858 if (currentDesktop() != desk_before)
01859 {
01860 offset = r.width() / 5;
01861 QCursor::setPos(r.width() - offset, pos.y());
01862 }
01863 break;
01864
01865 case 2:
01866 slotSwitchDesktopRight();
01867 if (currentDesktop() != desk_before)
01868 {
01869 offset = r.width() / 5;
01870 QCursor::setPos(offset, pos.y());
01871 }
01872 break;
01873
01874 case 3:
01875 slotSwitchDesktopUp();
01876 if (currentDesktop() != desk_before)
01877 {
01878 offset = r.height() / 5;
01879 QCursor::setPos(pos.x(), r.height() - offset);
01880 }
01881 break;
01882
01883 case 4:
01884 slotSwitchDesktopDown();
01885 if (currentDesktop() != desk_before)
01886 {
01887 offset = r.height() / 5;
01888 QCursor::setPos(pos.x(), offset);
01889 }
01890 break;
01891 }
01892 return;
01893 }
01894 }
01895 else
01896 {
01897 electric_current_border = border;
01898 electric_time_first = now;
01899 electric_time_last = now;
01900 electric_push_point = pos;
01901 }
01902
01903 int mouse_warp = 1;
01904
01905
01906 switch( border)
01907 {
01908 case 1: QCursor::setPos(pos.x()+mouse_warp, pos.y()); break;
01909 case 2: QCursor::setPos(pos.x()-mouse_warp, pos.y()); break;
01910 case 3: QCursor::setPos(pos.x(), pos.y()+mouse_warp); break;
01911 case 4: QCursor::setPos(pos.x(), pos.y()-mouse_warp); break;
01912 }
01913 }
01914
01915
01916
01917 void Workspace::electricBorder(XEvent *e)
01918 {
01919 Time now = e->xcrossing.time;
01920 QPoint p(e->xcrossing.x_root, e->xcrossing.y_root);
01921
01922 clientMoved(p, now);
01923 }
01924
01925
01926
01927
01928 void Workspace::raiseElectricBorders()
01929 {
01930
01931 if(electric_have_borders)
01932 {
01933 XRaiseWindow(qt_xdisplay(), electric_top_border);
01934 XRaiseWindow(qt_xdisplay(), electric_left_border);
01935 XRaiseWindow(qt_xdisplay(), electric_bottom_border);
01936 XRaiseWindow(qt_xdisplay(), electric_right_border);
01937 }
01938 }
01939
01940 void Workspace::addTopMenu( Client* c )
01941 {
01942 assert( c->isTopMenu());
01943 assert( !topmenus.contains( c ));
01944 topmenus.append( c );
01945 if( managingTopMenus())
01946 {
01947 int minsize = c->minSize().height();
01948 if( minsize > topMenuHeight())
01949 {
01950 topmenu_height = minsize;
01951 updateTopMenuGeometry();
01952 }
01953 updateTopMenuGeometry( c );
01954 updateCurrentTopMenu();
01955 }
01956
01957 }
01958
01959 void Workspace::removeTopMenu( Client* c )
01960 {
01961
01962
01963 assert( c->isTopMenu());
01964 assert( topmenus.contains( c ));
01965 topmenus.remove( c );
01966 updateCurrentTopMenu();
01967
01968 }
01969
01970 void Workspace::lostTopMenuSelection()
01971 {
01972
01973
01974 disconnect( topmenu_watcher, SIGNAL( lostOwner()), this, SLOT( lostTopMenuOwner()));
01975 connect( topmenu_watcher, SIGNAL( lostOwner()), this, SLOT( lostTopMenuOwner()));
01976 if( !managing_topmenus )
01977 return;
01978 connect( topmenu_watcher, SIGNAL( lostOwner()), this, SLOT( lostTopMenuOwner()));
01979 disconnect( topmenu_selection, SIGNAL( lostOwnership()), this, SLOT( lostTopMenuSelection()));
01980 managing_topmenus = false;
01981 delete topmenu_space;
01982 topmenu_space = NULL;
01983 updateClientArea();
01984 for( ClientList::ConstIterator it = topmenus.begin();
01985 it != topmenus.end();
01986 ++it )
01987 (*it)->checkWorkspacePosition();
01988 }
01989
01990 void Workspace::lostTopMenuOwner()
01991 {
01992 if( !options->topMenuEnabled())
01993 return;
01994
01995 if( !topmenu_selection->claim( false ))
01996 {
01997
01998 return;
01999 }
02000
02001 setupTopMenuHandling();
02002 }
02003
02004 void Workspace::setupTopMenuHandling()
02005 {
02006 if( managing_topmenus )
02007 return;
02008 connect( topmenu_selection, SIGNAL( lostOwnership()), this, SLOT( lostTopMenuSelection()));
02009 disconnect( topmenu_watcher, SIGNAL( lostOwner()), this, SLOT( lostTopMenuOwner()));
02010 managing_topmenus = true;
02011 topmenu_space = new QWidget;
02012 Window stack[ 2 ];
02013 stack[ 0 ] = supportWindow->winId();
02014 stack[ 1 ] = topmenu_space->winId();
02015 XRestackWindows(qt_xdisplay(), stack, 2);
02016 updateTopMenuGeometry();
02017 topmenu_space->show();
02018 updateClientArea();
02019 updateCurrentTopMenu();
02020 }
02021
02022 int Workspace::topMenuHeight() const
02023 {
02024 if( topmenu_height == 0 )
02025 {
02026 KMenuBar tmpmenu;
02027 tmpmenu.insertItem( "dummy" );
02028 topmenu_height = tmpmenu.sizeHint().height();
02029 }
02030 return topmenu_height;
02031 }
02032
02033 KDecoration* Workspace::createDecoration( KDecorationBridge* bridge )
02034 {
02035 return mgr->createDecoration( bridge );
02036 }
02037
02038 QString Workspace::desktopName( int desk ) const
02039 {
02040 return QString::fromUtf8( rootInfo->desktopName( desk ) );
02041 }
02042
02043 bool Workspace::checkStartupNotification( Window w, KStartupInfoId& id, KStartupInfoData& data )
02044 {
02045 return startup->checkStartup( w, id, data ) == KStartupInfo::Match;
02046 }
02047
02052 void Workspace::focusToNull()
02053 {
02054 XSetInputFocus(qt_xdisplay(), null_focus_window, RevertToPointerRoot, qt_x_time );
02055 }
02056
02057 void Workspace::helperDialog( const QString& message, const Client* c )
02058 {
02059 QStringList args;
02060 QString type;
02061 if( message == "noborderaltf3" )
02062 {
02063 QString shortcut = QString( "%1 (%2)" ).arg( keys->label( "Window Operations Menu" ))
02064 .arg( keys->shortcut( "Window Operations Menu" ).seq( 0 ).toString());
02065 args << "--msgbox" <<
02066 i18n( "You have selected to show a window without its border.\n"
02067 "Without the border, you will not be able to enable the border "
02068 "again using the mouse: use the window operations menu instead, "
02069 "activated using the %1 keyboard shortcut." )
02070 .arg( shortcut );
02071 type = "altf3warning";
02072 }
02073 else if( message == "fullscreenaltf3" )
02074 {
02075 QString shortcut = QString( "%1 (%2)" ).arg( keys->label( "Window Operations Menu" ))
02076 .arg( keys->shortcut( "Window Operations Menu" ).seq( 0 ).toString());
02077 args << "--msgbox" <<
02078 i18n( "You have selected to show a window in fullscreen mode.\n"
02079 "If the application itself does not have an option to turn the fullscreen "
02080 "mode off you will not be able to disable it "
02081 "again using the mouse: use the window operations menu instead, "
02082 "activated using the %1 keyboard shortcut." )
02083 .arg( shortcut );
02084 type = "altf3warning";
02085 }
02086 else
02087 assert( false );
02088 KProcess proc;
02089 proc << "kdialog" << args;
02090 if( !type.isEmpty())
02091 {
02092 KConfig cfg( "kwin_dialogsrc" );
02093 cfg.setGroup( "Notification Messages" );
02094 if( !cfg.readBoolEntry( type, true ))
02095 return;
02096 proc << "--dontagain" << "kwin_dialogsrc:" + type;
02097 }
02098 if( c != NULL )
02099 proc << "--embed" << QString::number( c->window());
02100 proc.start( KProcess::DontCare );
02101 }
02102
02103 }
02104
02105 #include "workspace.moc"