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>
7
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program. If not, see <http://www.gnu.org/licenses/>.
21
*********************************************************************/
23
//#define QT_CLEAN_NAMESPACE
27
#include "tabbox/clientmodel.h"
28
#include "tabbox/desktopmodel.h"
29
#include "tabbox/tabboxconfig.h"
33
#include "workspace.h"
38
#include <KActionCollection>
40
#include <KConfigGroup>
43
#include <kkeyserver.h>
46
#include <X11/keysym.h>
47
#include <X11/keysymdef.h>
50
// specify externals before namespace
55
extern QPixmap* kwin_get_menu_pix_hack();
60
TabBoxHandlerImpl::TabBoxHandlerImpl()
65
TabBoxHandlerImpl::~TabBoxHandlerImpl()
69
int TabBoxHandlerImpl::activeScreen() const
71
return Workspace::self()->activeScreen();
74
int TabBoxHandlerImpl::currentDesktop() const
76
return Workspace::self()->currentDesktop();
79
QString TabBoxHandlerImpl::desktopName(TabBoxClient* client) const
81
if (TabBoxClientImpl* c = static_cast< TabBoxClientImpl* >(client)) {
82
if (!c->client()->isOnAllDesktops())
83
return Workspace::self()->desktopName(c->client()->desktop());
85
return Workspace::self()->desktopName(Workspace::self()->currentDesktop());
88
QString TabBoxHandlerImpl::desktopName(int desktop) const
90
return Workspace::self()->desktopName(desktop);
93
TabBoxClient* TabBoxHandlerImpl::nextClientFocusChain(TabBoxClient* client) const
95
if (TabBoxClientImpl* c = static_cast< TabBoxClientImpl* >(client)) {
96
Client* next = Workspace::self()->nextClientFocusChain(c->client());
98
return next->tabBoxClient();
103
int TabBoxHandlerImpl::nextDesktopFocusChain(int desktop) const
105
return Workspace::self()->nextDesktopFocusChain(desktop);
108
int TabBoxHandlerImpl::numberOfDesktops() const
110
return Workspace::self()->numberOfDesktops();
113
TabBoxClient* TabBoxHandlerImpl::activeClient() const
115
if (Workspace::self()->activeClient())
116
return Workspace::self()->activeClient()->tabBoxClient();
121
TabBoxClient* TabBoxHandlerImpl::clientToAddToList(TabBoxClient* client, int desktop, bool allDesktops) const
123
Workspace* workspace = Workspace::self();
125
Client* current = (static_cast< TabBoxClientImpl* >(client))->client();
126
bool addClient = false;
127
bool applications = (config().clientListMode() == TabBoxConfig::AllDesktopsApplicationList ||
128
config().clientListMode() == TabBoxConfig::CurrentDesktopApplicationList);
132
addClient = current->isOnDesktop(desktop);
133
addClient = addClient && current->isOnCurrentActivity();
134
addClient = addClient && current->wantsTabFocus() && !current->skipSwitcher();
136
// don't add windows that have modal dialogs
137
Client* modal = current->findModal();
138
if (modal == NULL || modal == current)
140
else if (!clientList().contains(modal->tabBoxClient()))
145
if (ret && applications) {
146
// check if the list already contains an entry of this application
147
foreach (TabBoxClient * tabBoxClient, clientList()) {
148
if (TabBoxClientImpl* c = dynamic_cast< TabBoxClientImpl* >(tabBoxClient)) {
149
if (c->client()->resourceClass() == ret->resourceClass()) {
157
if (options->separateScreenFocus && options->xineramaEnabled) {
158
if (current->screen() != workspace->activeScreen())
162
return ret->tabBoxClient();
167
TabBoxClientList TabBoxHandlerImpl::stackingOrder() const
169
ClientList stacking = Workspace::self()->stackingOrder();
170
TabBoxClientList ret;
171
foreach (const Client * client, stacking) {
172
ret.append(client->tabBoxClient());
177
void TabBoxHandlerImpl::raiseClient(TabBoxClient* c) const
179
Workspace::self()->raiseClient(static_cast<TabBoxClientImpl*>(c)->client());
182
void TabBoxHandlerImpl::restack(TabBoxClient *c, TabBoxClient *under)
184
Workspace::self()->restack(static_cast<TabBoxClientImpl*>(c)->client(),
185
static_cast<TabBoxClientImpl*>(under)->client());
189
TabBoxClient* TabBoxHandlerImpl::desktopClient() const
191
foreach (const Client * client, Workspace::self()->stackingOrder()) {
192
if (client->isDesktop() && client->isOnCurrentDesktop() && client->screen() == Workspace::self()->activeScreen()) {
193
return client->tabBoxClient();
199
void TabBoxHandlerImpl::showOutline(const QRect &outline)
201
Workspace::self()->outline()->show(outline);
204
void TabBoxHandlerImpl::hideOutline()
206
Workspace::self()->outline()->hide();
209
QVector< Window > TabBoxHandlerImpl::outlineWindowIds() const
211
return Workspace::self()->outline()->windowIds();
215
/*********************************************************
217
*********************************************************/
219
TabBoxClientImpl::TabBoxClientImpl()
224
TabBoxClientImpl::~TabBoxClientImpl()
228
QString TabBoxClientImpl::caption() const
230
if (m_client->isDesktop())
231
return i18nc("Special entry in alt+tab list for minimizing all windows",
233
return m_client->caption();
236
QPixmap TabBoxClientImpl::icon(const QSize& size) const
238
return m_client->icon(size);
241
WId TabBoxClientImpl::window() const
243
return m_client->window();
246
bool TabBoxClientImpl::isMinimized() const
248
return m_client->isMinimized();
251
int TabBoxClientImpl::x() const
253
return m_client->x();
256
int TabBoxClientImpl::y() const
258
return m_client->y();
261
int TabBoxClientImpl::width() const
263
return m_client->width();
266
int TabBoxClientImpl::height() const
268
return m_client->height();
272
/*********************************************************
274
*********************************************************/
275
TabBox::TabBox(Workspace *ws)
278
, display_refcount(0)
281
m_defaultConfig = TabBoxConfig();
282
m_defaultConfig.setTabBoxMode(TabBoxConfig::ClientTabBox);
283
m_defaultConfig.setClientListMode(TabBoxConfig::CurrentDesktopClientList);
284
m_defaultConfig.setClientSwitchingMode(TabBoxConfig::FocusChainSwitching);
285
m_defaultConfig.setLayout(TabBoxConfig::VerticalLayout);
287
m_alternativeConfig = TabBoxConfig();
288
m_alternativeConfig.setTabBoxMode(TabBoxConfig::ClientTabBox);
289
m_alternativeConfig.setClientListMode(TabBoxConfig::AllDesktopsClientList);
290
m_alternativeConfig.setClientSwitchingMode(TabBoxConfig::FocusChainSwitching);
291
m_alternativeConfig.setLayout(TabBoxConfig::VerticalLayout);
293
m_desktopConfig = TabBoxConfig();
294
m_desktopConfig.setTabBoxMode(TabBoxConfig::DesktopTabBox);
295
m_desktopConfig.setShowTabBox(true);
296
m_desktopConfig.setShowDesktop(false);
297
m_desktopConfig.setDesktopSwitchingMode(TabBoxConfig::MostRecentlyUsedDesktopSwitching);
298
m_desktopConfig.setLayout(TabBoxConfig::VerticalLayout);
300
m_desktopListConfig = TabBoxConfig();
301
m_desktopListConfig.setTabBoxMode(TabBoxConfig::DesktopTabBox);
302
m_desktopListConfig.setShowTabBox(true);
303
m_desktopListConfig.setShowDesktop(false);
304
m_desktopListConfig.setDesktopSwitchingMode(TabBoxConfig::StaticDesktopSwitching);
305
m_desktopListConfig.setLayout(TabBoxConfig::VerticalLayout);
306
m_tabBox = new TabBoxHandlerImpl();
307
m_tabBox->setConfig(m_defaultConfig);
310
m_tabBoxMode = TabBoxDesktopMode; // init variables
312
connect(&delayedShowTimer, SIGNAL(timeout()), this, SLOT(show()));
321
Sets the current mode to \a mode, either TabBoxDesktopListMode or TabBoxWindowsMode
325
void TabBox::setMode(TabBoxMode mode)
329
case TabBoxWindowsMode:
330
m_tabBox->setConfig(m_defaultConfig);
332
case TabBoxWindowsAlternativeMode:
333
m_tabBox->setConfig(m_alternativeConfig);
335
case TabBoxDesktopMode:
336
m_tabBox->setConfig(m_desktopConfig);
338
case TabBoxDesktopListMode:
339
m_tabBox->setConfig(m_desktopListConfig);
345
Resets the tab box to display the active client in TabBoxWindowsMode, or the
346
current desktop in TabBoxDesktopListMode
348
void TabBox::reset(bool partial_reset)
350
switch(m_tabBox->config().tabBoxMode()) {
351
case TabBoxConfig::ClientTabBox:
352
m_tabBox->createModel(partial_reset);
353
if (!partial_reset) {
354
if (workspace()->activeClient())
355
setCurrentClient(workspace()->activeClient());
356
// it's possible that the active client is not part of the model
357
// in that case the index is invalid
358
if (!m_index.isValid())
359
setCurrentIndex(m_tabBox->first());
361
if (!m_index.isValid() || !m_tabBox->client(m_index))
362
setCurrentIndex(m_tabBox->first());
365
case TabBoxConfig::DesktopTabBox:
366
m_tabBox->createModel();
369
setCurrentDesktop(workspace()->currentDesktop());
373
emit tabBoxUpdated();
377
Shows the next or previous item, depending on \a next
379
void TabBox::nextPrev(bool next)
381
setCurrentIndex(m_tabBox->nextPrev(next), false);
382
emit tabBoxUpdated();
387
Returns the currently displayed client ( only works in TabBoxWindowsMode ).
388
Returns 0 if no client is displayed.
390
Client* TabBox::currentClient()
392
if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(m_index))) {
393
if (!workspace()->hasClient(client->client()))
395
return client->client();
401
Returns the list of clients potentially displayed ( only works in
403
Returns an empty list if no clients are available.
405
ClientList TabBox::currentClientList()
407
TabBoxClientList list = m_tabBox->clientList();
409
foreach (const TabBoxClient * client, list) {
410
if (const TabBoxClientImpl* c = static_cast< const TabBoxClientImpl* >(client))
411
ret.append(c->client());
418
Returns the currently displayed virtual desktop ( only works in
419
TabBoxDesktopListMode )
420
Returns -1 if no desktop is displayed.
422
int TabBox::currentDesktop()
424
return m_tabBox->desktop(m_index);
429
Returns the list of desktops potentially displayed ( only works in
430
TabBoxDesktopListMode )
431
Returns an empty list if no are available.
433
QList< int > TabBox::currentDesktopList()
435
return m_tabBox->desktopList();
440
Change the currently selected client, and notify the effects.
442
\sa setCurrentDesktop()
444
void TabBox::setCurrentClient(Client* newClient)
446
setCurrentIndex(m_tabBox->index(newClient->tabBoxClient()));
450
Change the currently selected desktop, and notify the effects.
452
\sa setCurrentClient()
454
void TabBox::setCurrentDesktop(int newDesktop)
456
setCurrentIndex(m_tabBox->desktopIndex(newDesktop));
459
void TabBox::TabBox::setCurrentIndex(QModelIndex index, bool notifyEffects)
461
if (!index.isValid())
464
m_tabBox->setCurrentIndex(index);
466
emit tabBoxUpdated();
471
Notify effects that the tab box is being shown, and only display the
472
default tab box QFrame if no effect has referenced the tab box.
476
emit tabBoxAdded(m_tabBoxMode);
488
Notify effects that the tab box is being hidden.
490
void TabBox::hide(bool abort)
492
delayedShowTimer.stop();
499
kDebug(1212) << "Tab box was not properly closed by an effect";
500
m_index = QModelIndex();
501
m_tabBox->hide(abort);
502
QApplication::syncX();
504
while (XCheckTypedEvent(display(), EnterNotify, &otherEvent))
510
Decrease the reference count. Only when the reference count is 0 will
511
the default tab box be shown.
513
void TabBox::unrefDisplay()
518
void TabBox::reconfigure()
520
KSharedConfigPtr c(KGlobal::config());
521
KConfigGroup config = c->group("TabBox");
523
loadConfig(c->group("TabBox"), m_defaultConfig);
524
loadConfig(c->group("TabBoxAlternative"), m_alternativeConfig);
526
m_tabBox->setConfig(m_defaultConfig);
528
m_delayShow = config.readEntry<bool>("ShowDelay", true);
529
m_delayShowTime = config.readEntry<int>("DelayTime", 90);
532
void TabBox::loadConfig(const KConfigGroup& config, TabBoxConfig& tabBoxConfig)
534
tabBoxConfig.setClientListMode(TabBoxConfig::ClientListMode(
535
config.readEntry<int>("ListMode", TabBoxConfig::defaultListMode())));
536
tabBoxConfig.setClientSwitchingMode(TabBoxConfig::ClientSwitchingMode(
537
config.readEntry<int>("SwitchingMode", TabBoxConfig::defaultSwitchingMode())));
538
tabBoxConfig.setLayout(TabBoxConfig::LayoutMode(
539
config.readEntry<int>("LayoutMode", TabBoxConfig::defaultLayoutMode())));
540
tabBoxConfig.setSelectedItemViewPosition(TabBoxConfig::SelectedItemViewPosition(
541
config.readEntry<int>("SelectedItem", TabBoxConfig::defaultSelectedItemViewPosition())));
543
tabBoxConfig.setShowOutline(config.readEntry<bool>("ShowOutline",
544
TabBoxConfig::defaultShowOutline()));
545
tabBoxConfig.setShowTabBox(config.readEntry<bool>("ShowTabBox",
546
TabBoxConfig::defaultShowTabBox()));
547
tabBoxConfig.setHighlightWindows(config.readEntry<bool>("HighlightWindows",
548
TabBoxConfig::defaultHighlightWindow()));
549
tabBoxConfig.setShowDesktop(config.readEntry<bool>("ShowDesktop",
550
TabBoxConfig::defaultShowDesktop()));
552
tabBoxConfig.setMinWidth(config.readEntry<int>("MinWidth",
553
TabBoxConfig::defaultMinWidth()));
554
tabBoxConfig.setMinHeight(config.readEntry<int>("MinHeight",
555
TabBoxConfig::defaultMinHeight()));
557
tabBoxConfig.setLayoutName(config.readEntry<QString>("LayoutName", TabBoxConfig::defaultLayoutName()));
558
tabBoxConfig.setSelectedItemLayoutName(config.readEntry<QString>("SelectedLayoutName", TabBoxConfig::defaultSelectedItemLayoutName()));
562
Rikkus: please document! (Matthias)
564
Ok, here's the docs :)
566
You call delayedShow() instead of show() directly.
568
If the 'ShowDelay' setting is false, show() is simply called.
570
Otherwise, we start a timer for the delay given in the settings and only
571
do a show() when it times out.
573
This means that you can alt-tab between windows and you don't see the
574
tab box immediately. Not only does this make alt-tabbing faster, it gives
575
less 'flicker' to the eyes. You don't need to see the tab box if you're
576
just quickly switching between 2 or 3 windows. It seems to work quite
579
void TabBox::delayedShow()
581
if (isDisplayed() || delayedShowTimer.isActive())
582
// already called show - no need to call it twice
585
if (!m_delayShowTime) {
590
delayedShowTimer.setSingleShot(true);
591
delayedShowTimer.start(m_delayShowTime);
595
void TabBox::handleMouseEvent(XEvent* e)
597
XAllowEvents(display(), AsyncPointer, xTime());
598
if (!m_isShown && isDisplayed()) {
599
// tabbox has been replaced, check effects
600
if (effects && static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(e))
603
if (e->type != ButtonPress)
605
QPoint pos(e->xbutton.x_root, e->xbutton.y_root);
607
if ((!m_isShown && isDisplayed())
608
|| (!m_tabBox->containsPos(pos) &&
609
(e->xbutton.button == Button1 || e->xbutton.button == Button2 || e->xbutton.button == Button3))) {
610
workspace()->closeTabBox(); // click outside closes tab
615
if (e->xbutton.button == Button1 || e->xbutton.button == Button2 || e->xbutton.button == Button3) {
616
index = m_tabBox->indexAt(pos);
617
if (e->xbutton.button == Button2 && index.isValid()) {
618
if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(index))) {
619
if (workspace()->hasClient(client->client())) {
620
client->client()->closeWindow();
627
index = m_tabBox->nextPrev(e->xbutton.button == Button5);
631
setCurrentIndex(index);
634
void TabBox::TabBox::grabbedKeyEvent(QKeyEvent* event)
636
emit tabBoxKeyEvent(event);
637
if (!m_isShown && isDisplayed()) {
638
// tabbox has been replaced, check effects
641
setCurrentIndex(m_tabBox->grabbedKeyEvent(event));
644
} // namespace TabBox
647
//*******************************
649
//*******************************
653
Handles alt-tab / control-tab
657
bool areKeySymXsDepressed(bool bAll, const uint keySyms[], int nKeySyms)
661
kDebug(125) << "areKeySymXsDepressed: " << (bAll ? "all of " : "any of ") << nKeySyms;
663
XQueryKeymap(display(), keymap);
665
for (int iKeySym = 0; iKeySym < nKeySyms; iKeySym++) {
666
uint keySymX = keySyms[ iKeySym ];
667
uchar keyCodeX = XKeysymToKeycode(display(), keySymX);
668
int i = keyCodeX / 8;
669
char mask = 1 << (keyCodeX - (i * 8));
671
// Abort if bad index value,
672
if (i < 0 || i >= 32)
675
kDebug(125) << iKeySym << ": keySymX=0x" << QString::number(keySymX, 16)
676
<< " i=" << i << " mask=0x" << QString::number(mask, 16)
677
<< " keymap[i]=0x" << QString::number(keymap[i], 16) << endl;
679
// If ALL keys passed need to be depressed,
681
if ((keymap[i] & mask) == 0)
684
// If we are looking for ANY key press, and this key is depressed,
685
if (keymap[i] & mask)
690
// If we were looking for ANY key press, then none was found, return false,
691
// If we were looking for ALL key presses, then all were found, return true.
695
static bool areModKeysDepressed(const QKeySequence& seq)
701
int mod = seq[seq.count()-1] & Qt::KeyboardModifierMask;
703
if (mod & Qt::SHIFT) {
704
rgKeySyms[nKeySyms++] = XK_Shift_L;
705
rgKeySyms[nKeySyms++] = XK_Shift_R;
707
if (mod & Qt::CTRL) {
708
rgKeySyms[nKeySyms++] = XK_Control_L;
709
rgKeySyms[nKeySyms++] = XK_Control_R;
712
rgKeySyms[nKeySyms++] = XK_Alt_L;
713
rgKeySyms[nKeySyms++] = XK_Alt_R;
715
if (mod & Qt::META) {
716
// It would take some code to determine whether the Win key
717
// is associated with Super or Meta, so check for both.
718
// See bug #140023 for details.
719
rgKeySyms[nKeySyms++] = XK_Super_L;
720
rgKeySyms[nKeySyms++] = XK_Super_R;
721
rgKeySyms[nKeySyms++] = XK_Meta_L;
722
rgKeySyms[nKeySyms++] = XK_Meta_R;
725
return areKeySymXsDepressed(false, rgKeySyms, nKeySyms);
728
static bool areModKeysDepressed(const KShortcut& cut)
730
if (areModKeysDepressed(cut.primary()) || areModKeysDepressed(cut.alternate()))
736
void Workspace::navigatingThroughWindows(bool forward, const KShortcut& shortcut, TabBoxMode mode)
738
if (tab_grab || control_grab)
740
if (!options->focusPolicyIsReasonable()) {
741
//ungrabXKeyboard(); // need that because of accelerator raw mode
742
// CDE style raise / lower
743
CDEWalkThroughWindows(forward);
745
if (areModKeysDepressed(shortcut)) {
746
if (startKDEWalkThroughWindows(mode))
747
KDEWalkThroughWindows(forward);
749
// if the shortcut has no modifiers, don't show the tabbox,
750
// don't grab, but simply go to the next window
751
KDEOneStepThroughWindows(forward, mode);
755
void Workspace::slotWalkThroughWindows()
757
navigatingThroughWindows(true, cutWalkThroughWindows, TabBoxWindowsMode);
760
void Workspace::slotWalkBackThroughWindows()
762
navigatingThroughWindows(false, cutWalkThroughWindowsReverse, TabBoxWindowsMode);
765
void Workspace::slotWalkThroughWindowsAlternative()
767
navigatingThroughWindows(true, cutWalkThroughWindowsAlternative, TabBoxWindowsAlternativeMode);
770
void Workspace::slotWalkBackThroughWindowsAlternative()
772
navigatingThroughWindows(false, cutWalkThroughWindowsAlternativeReverse, TabBoxWindowsAlternativeMode);
775
void Workspace::slotWalkThroughDesktops()
777
if (tab_grab || control_grab)
779
if (areModKeysDepressed(cutWalkThroughDesktops)) {
780
if (startWalkThroughDesktops())
781
walkThroughDesktops(true);
783
oneStepThroughDesktops(true);
787
void Workspace::slotWalkBackThroughDesktops()
789
if (tab_grab || control_grab)
791
if (areModKeysDepressed(cutWalkThroughDesktopsReverse)) {
792
if (startWalkThroughDesktops())
793
walkThroughDesktops(false);
795
oneStepThroughDesktops(false);
799
void Workspace::slotWalkThroughDesktopList()
801
if (tab_grab || control_grab)
803
if (areModKeysDepressed(cutWalkThroughDesktopList)) {
804
if (startWalkThroughDesktopList())
805
walkThroughDesktops(true);
807
oneStepThroughDesktopList(true);
811
void Workspace::slotWalkBackThroughDesktopList()
813
if (tab_grab || control_grab)
815
if (areModKeysDepressed(cutWalkThroughDesktopListReverse)) {
816
if (startWalkThroughDesktopList())
817
walkThroughDesktops(false);
819
oneStepThroughDesktopList(false);
823
void Workspace::slotWalkThroughDesktopsKeyChanged(const QKeySequence& seq)
825
cutWalkThroughDesktops = KShortcut(seq);
828
void Workspace::slotWalkBackThroughDesktopsKeyChanged(const QKeySequence& seq)
830
cutWalkThroughDesktopsReverse = KShortcut(seq);
833
void Workspace::slotWalkThroughDesktopListKeyChanged(const QKeySequence& seq)
835
cutWalkThroughDesktopList = KShortcut(seq);
838
void Workspace::slotWalkBackThroughDesktopListKeyChanged(const QKeySequence& seq)
840
cutWalkThroughDesktopListReverse = KShortcut(seq);
843
void Workspace::slotWalkThroughWindowsKeyChanged(const QKeySequence& seq)
845
cutWalkThroughWindows = KShortcut(seq);
848
void Workspace::slotWalkBackThroughWindowsKeyChanged(const QKeySequence& seq)
850
cutWalkThroughWindowsReverse = KShortcut(seq);
853
void Workspace::slotMoveToTabLeftKeyChanged(const QKeySequence& seq)
855
cutWalkThroughGroupWindows = KShortcut(seq);
857
void Workspace::slotMoveToTabRightKeyChanged(const QKeySequence& seq)
859
cutWalkThroughGroupWindowsReverse = KShortcut(seq);
862
void Workspace::slotWalkThroughWindowsAlternativeKeyChanged(const QKeySequence& seq)
864
cutWalkThroughWindowsAlternative = KShortcut(seq);
867
void Workspace::slotWalkBackThroughWindowsAlternativeKeyChanged(const QKeySequence& seq)
869
cutWalkThroughWindowsAlternativeReverse = KShortcut(seq);
872
void Workspace::modalActionsSwitch(bool enabled)
874
QList<KActionCollection*> collections;
875
collections.append(keys);
876
collections.append(disable_shortcuts_keys);
877
collections.append(client_keys);
878
foreach (KActionCollection * collection, collections)
879
foreach (QAction * action, collection->actions())
880
action->setEnabled(enabled);
883
bool Workspace::startKDEWalkThroughWindows(TabBoxMode mode)
885
if (!establishTabBoxGrab())
888
modalActionsSwitch(false);
889
tab_box->setMode(mode);
894
bool Workspace::startWalkThroughDesktops(TabBoxMode mode)
896
if (!establishTabBoxGrab())
899
modalActionsSwitch(false);
900
tab_box->setMode(mode);
905
bool Workspace::startWalkThroughDesktops()
907
return startWalkThroughDesktops(TabBoxDesktopMode);
910
bool Workspace::startWalkThroughDesktopList()
912
return startWalkThroughDesktops(TabBoxDesktopListMode);
915
void Workspace::KDEWalkThroughWindows(bool forward)
917
tab_box->nextPrev(forward);
918
tab_box->delayedShow();
921
void Workspace::walkThroughDesktops(bool forward)
923
tab_box->nextPrev(forward);
924
tab_box->delayedShow();
927
void Workspace::CDEWalkThroughWindows(bool forward)
930
// this function find the first suitable client for unreasonable focus
931
// policies - the topmost one, with some exceptions (can't be keepabove/below,
932
// otherwise it gets stuck on them)
933
Q_ASSERT(block_stacking_updates == 0);
934
for (int i = stacking_order.size() - 1;
937
Client* it = stacking_order.at(i);
938
if (it->isOnCurrentActivity() && it->isOnCurrentDesktop() && !it->isSpecialWindow()
939
&& it->isShown(false) && it->wantsTabFocus()
940
&& !it->keepAbove() && !it->keepBelow()) {
946
bool options_traverse_all;
948
KConfigGroup group(KGlobal::config(), "TabBox");
949
options_traverse_all = group.readEntry("TraverseAll", false);
952
Client* firstClient = 0;
954
nc = forward ? nextClientStatic(nc) : previousClientStatic(nc);
956
// When we see our first client for the second time,
957
// it's time to stop.
959
} else if (nc == firstClient) {
960
// No candidates found.
964
} while (nc && nc != c &&
965
((!options_traverse_all && !nc->isOnDesktop(currentDesktop())) ||
966
nc->isMinimized() || !nc->wantsTabFocus() || nc->keepAbove() || nc->keepBelow() || !nc->isOnCurrentActivity()));
970
if (options->focusPolicyIsReasonable()) {
972
if (nc->isShade() && options->shadeHover)
973
nc->setShade(ShadeActivated);
975
if (!nc->isOnDesktop(currentDesktop()))
976
setCurrentDesktop(nc->desktop());
982
void Workspace::KDEOneStepThroughWindows(bool forward, TabBoxMode mode)
984
tab_box->setMode(mode);
986
tab_box->nextPrev(forward);
987
if (Client* c = tab_box->currentClient()) {
989
if (c->isShade() && options->shadeHover)
990
c->setShade(ShadeActivated);
994
void Workspace::oneStepThroughDesktops(bool forward, TabBoxMode mode)
996
tab_box->setMode(mode);
998
tab_box->nextPrev(forward);
999
if (tab_box->currentDesktop() != -1)
1000
setCurrentDesktop(tab_box->currentDesktop());
1003
void Workspace::oneStepThroughDesktops(bool forward)
1005
oneStepThroughDesktops(forward, TabBoxDesktopMode);
1008
void Workspace::oneStepThroughDesktopList(bool forward)
1010
oneStepThroughDesktops(forward, TabBoxDesktopListMode);
1014
Handles holding alt-tab / control-tab
1016
void Workspace::tabBoxKeyPress(int keyQt)
1018
bool forward = false;
1019
bool backward = false;
1022
KShortcut forwardShortcut;
1023
KShortcut backwardShortcut;
1024
if (tab_box->mode() == TabBoxWindowsMode) {
1025
forwardShortcut = cutWalkThroughWindows;
1026
backwardShortcut = cutWalkThroughWindowsReverse;
1028
forwardShortcut = cutWalkThroughWindowsAlternative;
1029
backwardShortcut = cutWalkThroughWindowsAlternativeReverse;
1031
forward = forwardShortcut.contains(keyQt);
1032
backward = backwardShortcut.contains(keyQt);
1033
if (forward || backward) {
1034
kDebug(125) << "== " << forwardShortcut.toString()
1035
<< " or " << backwardShortcut.toString() << endl;
1036
KDEWalkThroughWindows(forward);
1038
} else if (control_grab) {
1039
forward = cutWalkThroughDesktops.contains(keyQt) ||
1040
cutWalkThroughDesktopList.contains(keyQt);
1041
backward = cutWalkThroughDesktopsReverse.contains(keyQt) ||
1042
cutWalkThroughDesktopListReverse.contains(keyQt);
1043
if (forward || backward)
1044
walkThroughDesktops(forward);
1047
if (control_grab || tab_grab) {
1048
if (((keyQt & ~Qt::KeyboardModifierMask) == Qt::Key_Escape)
1049
&& !(forward || backward)) {
1050
// if Escape is part of the shortcut, don't cancel
1052
} else if (!(forward || backward)) {
1053
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, keyQt & ~Qt::KeyboardModifierMask, Qt::NoModifier);
1054
tab_box->grabbedKeyEvent(event);
1059
void Workspace::refTabBox()
1062
tab_box->refDisplay();
1065
void Workspace::unrefTabBox()
1068
tab_box->unrefDisplay();
1071
void Workspace::closeTabBox(bool abort)
1074
tab_box->hide(abort);
1075
modalActionsSwitch(true);
1077
control_grab = false;
1081
Handles alt-tab / control-tab releasing
1083
void Workspace::tabBoxKeyRelease(const XKeyEvent& ev)
1085
unsigned int mk = ev.state &
1086
(KKeyServer::modXShift() |
1087
KKeyServer::modXCtrl() |
1088
KKeyServer::modXAlt() |
1089
KKeyServer::modXMeta());
1090
// ev.state is state before the key release, so just checking mk being 0 isn't enough
1091
// using XQueryPointer() also doesn't seem to work well, so the check that all
1092
// modifiers are released: only one modifier is active and the currently released
1093
// key is this modifier - if yes, release the grab
1095
for (int i = ShiftMapIndex;
1098
if ((mk & (1 << i)) != 0) {
1103
bool release = false;
1104
if (mod_index == -1)
1107
XModifierKeymap* xmk = XGetModifierMapping(display());
1108
for (int i = 0; i < xmk->max_keypermod; i++)
1109
if (xmk->modifiermap[xmk->max_keypermod * mod_index + i]
1112
XFreeModifiermap(xmk);
1117
bool old_control_grab = control_grab;
1118
Client* c = tab_box->currentClient();
1120
control_grab = old_control_grab;
1123
if (c->isShade() && options->shadeHover)
1124
c->setShade(ShadeActivated);
1126
setShowingDesktop(!showingDesktop());
1130
bool old_tab_grab = tab_grab;
1131
int desktop = tab_box->currentDesktop();
1133
tab_grab = old_tab_grab;
1134
if (desktop != -1) {
1135
setCurrentDesktop(desktop);
1141
int Workspace::nextDesktopFocusChain(int iDesktop) const
1143
int i = desktop_focus_chain.indexOf(iDesktop);
1144
if (i >= 0 && i + 1 < (int)desktop_focus_chain.size())
1145
return desktop_focus_chain[i+1];
1146
else if (desktop_focus_chain.size() > 0)
1147
return desktop_focus_chain[ 0 ];
1152
int Workspace::previousDesktopFocusChain(int iDesktop) const
1154
int i = desktop_focus_chain.indexOf(iDesktop);
1156
return desktop_focus_chain[i-1];
1157
else if (desktop_focus_chain.size() > 0)
1158
return desktop_focus_chain[desktop_focus_chain.size()-1];
1160
return numberOfDesktops();
1163
int Workspace::nextDesktopStatic(int iDesktop) const
1166
if (i > numberOfDesktops())
1171
int Workspace::previousDesktopStatic(int iDesktop) const
1175
i = numberOfDesktops();
1180
auxiliary functions to travers all clients according to the focus
1181
order. Useful for kwms Alt-tab feature.
1183
Client* Workspace::nextClientFocusChain(Client* c) const
1185
if (global_focus_chain.isEmpty())
1187
int pos = global_focus_chain.indexOf(c);
1189
return global_focus_chain.last();
1191
return global_focus_chain.last();
1193
return global_focus_chain[ pos ];
1197
auxiliary functions to travers all clients according to the focus
1198
order. Useful for kwms Alt-tab feature.
1200
Client* Workspace::previousClientFocusChain(Client* c) const
1202
if (global_focus_chain.isEmpty())
1204
int pos = global_focus_chain.indexOf(c);
1206
return global_focus_chain.first();
1208
if (pos == global_focus_chain.count())
1209
return global_focus_chain.first();
1210
return global_focus_chain[ pos ];
1214
auxiliary functions to travers all clients according to the static
1215
order. Useful for the CDE-style Alt-tab feature.
1217
Client* Workspace::nextClientStatic(Client* c) const
1219
if (!c || clients.isEmpty())
1221
int pos = clients.indexOf(c);
1223
return clients.first();
1225
if (pos == clients.count())
1226
return clients.first();
1227
return clients[ pos ];
1230
auxiliary functions to travers all clients according to the static
1231
order. Useful for the CDE-style Alt-tab feature.
1233
Client* Workspace::previousClientStatic(Client* c) const
1235
if (!c || clients.isEmpty())
1237
int pos = clients.indexOf(c);
1239
return clients.last();
1241
return clients.last();
1243
return clients[ pos ];
1246
Client* Workspace::currentTabBoxClient() const
1250
return tab_box->currentClient();
1253
ClientList Workspace::currentTabBoxClientList() const
1256
return ClientList();
1257
return tab_box->currentClientList();
1260
int Workspace::currentTabBoxDesktop() const
1264
return tab_box->currentDesktop();
1267
QList< int > Workspace::currentTabBoxDesktopList() const
1270
return QList< int >();
1271
return tab_box->currentDesktopList();
1274
void Workspace::setTabBoxClient(Client* c)
1277
tab_box->setCurrentClient(c);
1280
void Workspace::setTabBoxDesktop(int iDesktop)
1283
tab_box->setCurrentDesktop(iDesktop);
1286
bool Workspace::establishTabBoxGrab()
1288
if (!grabXKeyboard())
1290
// Don't try to establish a global mouse grab using XGrabPointer, as that would prevent
1291
// using Alt+Tab while DND (#44972). However force passive grabs on all windows
1292
// in order to catch MouseRelease events and close the tabbox (#67416).
1293
// All clients already have passive grabs in their wrapper windows, so check only
1294
// the active client, which may not have it.
1295
assert(!forced_global_mouse_grab);
1296
forced_global_mouse_grab = true;
1297
if (active_client != NULL)
1298
active_client->updateMouseGrab();
1302
void Workspace::removeTabBoxGrab()
1305
assert(forced_global_mouse_grab);
1306
forced_global_mouse_grab = false;
1307
if (active_client != NULL)
1308
active_client->updateMouseGrab();
1313
#include "tabbox.moc"