select proper client for shortcuts and guard pointer

REVIEW: 103998
remotes/origin/Plasma/5.0
Thomas Lübking 14 years ago
parent 7e7846adce
commit 2123fb8dbd
  1. 189
      useractions.cpp

@ -419,10 +419,8 @@ void Workspace::initDesktopPopup()
desk_popup = new QMenu(popup); desk_popup = new QMenu(popup);
desk_popup->setFont(KGlobalSettings::menuFont()); desk_popup->setFont(KGlobalSettings::menuFont());
connect(desk_popup, SIGNAL(triggered(QAction*)), connect(desk_popup, SIGNAL(triggered(QAction*)), SLOT(slotSendToDesktop(QAction*)));
this, SLOT(slotSendToDesktop(QAction*))); connect(desk_popup, SIGNAL(aboutToShow()), SLOT(desktopPopupAboutToShow()));
connect(desk_popup, SIGNAL(aboutToShow()),
this, SLOT(desktopPopupAboutToShow()));
QAction *action = desk_popup->menuAction(); QAction *action = desk_popup->menuAction();
// set it as the first item // set it as the first item
@ -627,6 +625,8 @@ void Workspace::clientPopupActivated(QAction *action)
WindowOperation op = static_cast< WindowOperation >(action->data().toInt()); WindowOperation op = static_cast< WindowOperation >(action->data().toInt());
Client* c = active_popup_client ? active_popup_client : active_client; Client* c = active_popup_client ? active_popup_client : active_client;
if (!c)
return;
QString type; QString type;
switch(op) { switch(op) {
case FullScreenOp: case FullScreenOp:
@ -1130,17 +1130,18 @@ void Workspace::slotSwitchToDesktop()
setCurrentDesktop(i); setCurrentDesktop(i);
} }
#define USABLE_ACTIVE_CLIENT (!active_client || (active_client->isDesktop() || active_client->isDock()))
void Workspace::slotWindowToDesktop() void Workspace::slotWindowToDesktop()
{ {
const int i = senderValue(sender()); if (USABLE_ACTIVE_CLIENT) {
if (i < 1) const int i = senderValue(sender());
return; if (i < 1)
Client* c = active_popup_client ? active_popup_client : active_client; return;
if (i >= 1 && i <= numberOfDesktops() && c
&& !c->isDesktop() if (i >= 1 && i <= numberOfDesktops())
&& !c->isDock()) sendClientToDesktop(active_client, i, true);
sendClientToDesktop(c, i, true); }
} }
void Workspace::slotSwitchToScreen() void Workspace::slotSwitchToScreen()
@ -1157,25 +1158,20 @@ void Workspace::slotSwitchToNextScreen()
void Workspace::slotWindowToScreen() void Workspace::slotWindowToScreen()
{ {
const int i = senderValue(sender()); if (USABLE_ACTIVE_CLIENT) {
if (i < 0) const int i = senderValue(sender());
return; if (i < 0)
Client* c = active_popup_client ? active_popup_client : active_client; return;
if (i >= 0 && i <= numScreens() && c if (i >= 0 && i <= numScreens()) {
&& !c->isDesktop() sendClientToScreen(active_client, i);
&& !c->isDock()) { }
sendClientToScreen(c, i);
} }
} }
void Workspace::slotWindowToNextScreen() void Workspace::slotWindowToNextScreen()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c sendClientToScreen(active_client, (active_client->screen() + 1) % numScreens());
&& !c->isDesktop()
&& !c->isDock()) {
sendClientToScreen(c, (c->screen() + 1) % numScreens());
}
} }
/*! /*!
@ -1183,9 +1179,8 @@ void Workspace::slotWindowToNextScreen()
*/ */
void Workspace::slotWindowMaximize() void Workspace::slotWindowMaximize()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::MaximizeOp);
performWindowOperation(c, Options::MaximizeOp);
} }
/*! /*!
@ -1193,9 +1188,8 @@ void Workspace::slotWindowMaximize()
*/ */
void Workspace::slotWindowMaximizeVertical() void Workspace::slotWindowMaximizeVertical()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::VMaximizeOp);
performWindowOperation(c, Options::VMaximizeOp);
} }
/*! /*!
@ -1203,9 +1197,8 @@ void Workspace::slotWindowMaximizeVertical()
*/ */
void Workspace::slotWindowMaximizeHorizontal() void Workspace::slotWindowMaximizeHorizontal()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::HMaximizeOp);
performWindowOperation(c, Options::HMaximizeOp);
} }
@ -1214,8 +1207,8 @@ void Workspace::slotWindowMaximizeHorizontal()
*/ */
void Workspace::slotWindowMinimize() void Workspace::slotWindowMinimize()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
performWindowOperation(c, Options::MinimizeOp); performWindowOperation(active_client, Options::MinimizeOp);
} }
/*! /*!
@ -1223,8 +1216,8 @@ void Workspace::slotWindowMinimize()
*/ */
void Workspace::slotWindowShade() void Workspace::slotWindowShade()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
performWindowOperation(c, Options::ShadeOp); performWindowOperation(active_client, Options::ShadeOp);
} }
/*! /*!
@ -1232,9 +1225,8 @@ void Workspace::slotWindowShade()
*/ */
void Workspace::slotWindowRaise() void Workspace::slotWindowRaise()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) raiseClient(active_client);
raiseClient(c);
} }
/*! /*!
@ -1242,12 +1234,12 @@ void Workspace::slotWindowRaise()
*/ */
void Workspace::slotWindowLower() void Workspace::slotWindowLower()
{ {
if ((Client* c = active_popup_client ? active_popup_client : active_client)) { if (USABLE_ACTIVE_CLIENT) {
lowerClient(c); lowerClient(active_client);
// As this most likely makes the window no longer visible change the // As this most likely makes the window no longer visible change the
// keyboard focus to the next available window. // keyboard focus to the next available window.
//activateNextClient( c ); // Doesn't work when we lower a child window //activateNextClient( c ); // Doesn't work when we lower a child window
if (c->isActive()) if (active_client->isActive())
activateClient(topClientOnDesktop(currentDesktop(), -1)); activateClient(topClientOnDesktop(currentDesktop(), -1));
} }
} }
@ -1257,50 +1249,43 @@ void Workspace::slotWindowLower()
*/ */
void Workspace::slotWindowRaiseOrLower() void Workspace::slotWindowRaiseOrLower()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) raiseOrLowerClient(active_client);
raiseOrLowerClient(c);
} }
void Workspace::slotWindowOnAllDesktops() void Workspace::slotWindowOnAllDesktops()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) active_client->setOnAllDesktops(!active_client->isOnAllDesktops());
c->setOnAllDesktops(!c->isOnAllDesktops());
} }
void Workspace::slotWindowFullScreen() void Workspace::slotWindowFullScreen()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::FullScreenOp);
performWindowOperation(c, Options::FullScreenOp);
} }
void Workspace::slotWindowNoBorder() void Workspace::slotWindowNoBorder()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::NoBorderOp);
performWindowOperation(c, Options::NoBorderOp);
} }
void Workspace::slotWindowAbove() void Workspace::slotWindowAbove()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::KeepAboveOp);
performWindowOperation(c, Options::KeepAboveOp);
} }
void Workspace::slotWindowBelow() void Workspace::slotWindowBelow()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::KeepBelowOp);
performWindowOperation(c, Options::KeepBelowOp);
} }
void Workspace::slotSetupWindowShortcut() void Workspace::slotSetupWindowShortcut()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
if (c) performWindowOperation(active_client, Options::SetupWindowShortcutOp);
performWindowOperation(c, Options::SetupWindowShortcutOp);
} }
/*! /*!
@ -1316,7 +1301,8 @@ void Workspace::slotToggleShowDesktop()
*/ */
void Workspace::slotWindowToNextDesktop() void Workspace::slotWindowToNextDesktop()
{ {
windowToNextDesktop(active_popup_client ? active_popup_client : active_client); if (USABLE_ACTIVE_CLIENT)
windowToNextDesktop(active_client);
} }
void Workspace::windowToNextDesktop(Client* c) void Workspace::windowToNextDesktop(Client* c)
@ -1337,7 +1323,8 @@ void Workspace::windowToNextDesktop(Client* c)
*/ */
void Workspace::slotWindowToPreviousDesktop() void Workspace::slotWindowToPreviousDesktop()
{ {
windowToPreviousDesktop(active_popup_client ? active_popup_client : active_client); if (USABLE_ACTIVE_CLIENT)
windowToPreviousDesktop(active_client);
} }
void Workspace::windowToPreviousDesktop(Client* c) void Workspace::windowToPreviousDesktop(Client* c)
@ -1355,13 +1342,12 @@ void Workspace::windowToPreviousDesktop(Client* c)
void Workspace::slotWindowToDesktopRight() void Workspace::slotWindowToDesktopRight()
{ {
int d = desktopToRight(currentDesktop(), options->rollOverDesktops); if (USABLE_ACTIVE_CLIENT) {
if (d == currentDesktop()) int d = desktopToRight(currentDesktop(), options->rollOverDesktops);
return; if (d == currentDesktop())
Client* c = active_popup_client ? active_popup_client : active_client; return;
if (c && !c->isDesktop()
&& !c->isDock()) { setClientIsMoving(active_client);
setClientIsMoving(c);
setCurrentDesktop(d); setCurrentDesktop(d);
setClientIsMoving(NULL); setClientIsMoving(NULL);
} }
@ -1369,13 +1355,12 @@ void Workspace::slotWindowToDesktopRight()
void Workspace::slotWindowToDesktopLeft() void Workspace::slotWindowToDesktopLeft()
{ {
int d = desktopToLeft(currentDesktop(), options->rollOverDesktops); if (USABLE_ACTIVE_CLIENT) {
if (d == currentDesktop()) int d = desktopToLeft(currentDesktop(), options->rollOverDesktops);
return; if (d == currentDesktop())
Client* c = active_popup_client ? active_popup_client : active_client; return;
if (c && !c->isDesktop()
&& !c->isDock()) { setClientIsMoving(active_client);
setClientIsMoving(c);
setCurrentDesktop(d); setCurrentDesktop(d);
setClientIsMoving(NULL); setClientIsMoving(NULL);
} }
@ -1383,13 +1368,12 @@ void Workspace::slotWindowToDesktopLeft()
void Workspace::slotWindowToDesktopUp() void Workspace::slotWindowToDesktopUp()
{ {
int d = desktopAbove(currentDesktop(), options->rollOverDesktops); if (USABLE_ACTIVE_CLIENT) {
if (d == currentDesktop()) int d = desktopAbove(currentDesktop(), options->rollOverDesktops);
return; if (d == currentDesktop())
Client* c = active_popup_client ? active_popup_client : active_client; return;
if (c && !c->isDesktop()
&& !c->isDock()) { setClientIsMoving(active_client);
setClientIsMoving(c);
setCurrentDesktop(d); setCurrentDesktop(d);
setClientIsMoving(NULL); setClientIsMoving(NULL);
} }
@ -1397,13 +1381,12 @@ void Workspace::slotWindowToDesktopUp()
void Workspace::slotWindowToDesktopDown() void Workspace::slotWindowToDesktopDown()
{ {
int d = desktopBelow(currentDesktop(), options->rollOverDesktops); if (USABLE_ACTIVE_CLIENT) {
if (d == currentDesktop()) int d = desktopBelow(currentDesktop(), options->rollOverDesktops);
return; if (d == currentDesktop())
Client* c = active_popup_client ? active_popup_client : active_client; return;
if (c && !c->isDesktop()
&& !c->isDock()) { setClientIsMoving(active_client);
setClientIsMoving(c);
setCurrentDesktop(d); setCurrentDesktop(d);
setClientIsMoving(NULL); setClientIsMoving(NULL);
} }
@ -1634,8 +1617,8 @@ void Workspace::slotWindowClose()
// TODO: why? // TODO: why?
// if ( tab_box->isVisible()) // if ( tab_box->isVisible())
// return; // return;
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
performWindowOperation(c, Options::CloseOp); performWindowOperation(active_client, Options::CloseOp);
} }
/*! /*!
@ -1643,8 +1626,8 @@ void Workspace::slotWindowClose()
*/ */
void Workspace::slotWindowMove() void Workspace::slotWindowMove()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
performWindowOperation(c, Options::UnrestrictedMoveOp); performWindowOperation(active_client, Options::UnrestrictedMoveOp);
} }
/*! /*!
@ -1652,10 +1635,12 @@ void Workspace::slotWindowMove()
*/ */
void Workspace::slotWindowResize() void Workspace::slotWindowResize()
{ {
Client* c = active_popup_client ? active_popup_client : active_client; if (USABLE_ACTIVE_CLIENT)
performWindowOperation(c, Options::UnrestrictedResizeOp); performWindowOperation(active_client, Options::UnrestrictedResizeOp);
} }
#undef USABLE_ACTIVE_CLIENT
void Client::setShortcut(const QString& _cut) void Client::setShortcut(const QString& _cut)
{ {
QString cut = rules()->checkShortcut(_cut); QString cut = rules()->checkShortcut(_cut);

Loading…
Cancel
Save