Enable mouse wheel navigation in flipswitch and coverswitch effects
BUG: 244439 FIXED-IN: 4.10 REVIEW: 105040
This commit is contained in:
parent
7f61428480
commit
e685e0f6e0
4 changed files with 131 additions and 60 deletions
|
@ -912,47 +912,62 @@ void CoverSwitchEffect::windowInputMouseEvent(Window w, QEvent* e)
|
|||
// we don't want click events during animations
|
||||
if (animation)
|
||||
return;
|
||||
QPoint pos = static_cast< QMouseEvent* >(e)->pos();
|
||||
QMouseEvent* event = static_cast< QMouseEvent* >(e);
|
||||
|
||||
// determine if a window has been clicked
|
||||
// not interested in events above a fullscreen window (ignoring panel size)
|
||||
if (pos.y() < (area.height()*scaleFactor - area.height()) * 0.5f *(1.0f / scaleFactor))
|
||||
return;
|
||||
switch (event->button()) {
|
||||
case Qt::XButton1: // wheel up
|
||||
selectPreviousWindow();
|
||||
break;
|
||||
case Qt::XButton2: // wheel down
|
||||
selectNextWindow();
|
||||
break;
|
||||
case Qt::LeftButton:
|
||||
case Qt::RightButton:
|
||||
case Qt::MidButton:
|
||||
default:
|
||||
QPoint pos = event->pos();
|
||||
|
||||
// if there is no selected window (that is no window at all) we cannot click it
|
||||
if (!selected_window)
|
||||
return;
|
||||
|
||||
if (pos.x() < (area.width()*scaleFactor - selected_window->width()) * 0.5f *(1.0f / scaleFactor)) {
|
||||
float availableSize = (area.width() * scaleFactor - area.width()) * 0.5f * (1.0f / scaleFactor);
|
||||
for (int i = 0; i < leftWindows.count(); i++) {
|
||||
int windowPos = availableSize / leftWindows.count() * i;
|
||||
if (pos.x() < windowPos)
|
||||
continue;
|
||||
if (i + 1 < leftWindows.count()) {
|
||||
if (pos.x() > availableSize / leftWindows.count()*(i + 1))
|
||||
continue;
|
||||
}
|
||||
|
||||
effects->setTabBoxWindow(leftWindows[i]);
|
||||
// determine if a window has been clicked
|
||||
// not interested in events above a fullscreen window (ignoring panel size)
|
||||
if (pos.y() < (area.height()*scaleFactor - area.height()) * 0.5f *(1.0f / scaleFactor))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos.x() > area.width() - (area.width()*scaleFactor - selected_window->width()) * 0.5f *(1.0f / scaleFactor)) {
|
||||
float availableSize = (area.width() * scaleFactor - area.width()) * 0.5f * (1.0f / scaleFactor);
|
||||
for (int i = 0; i < rightWindows.count(); i++) {
|
||||
int windowPos = area.width() - availableSize / rightWindows.count() * i;
|
||||
if (pos.x() > windowPos)
|
||||
continue;
|
||||
if (i + 1 < rightWindows.count()) {
|
||||
if (pos.x() < area.width() - availableSize / rightWindows.count()*(i + 1))
|
||||
continue;
|
||||
}
|
||||
|
||||
effects->setTabBoxWindow(rightWindows[i]);
|
||||
// if there is no selected window (that is no window at all) we cannot click it
|
||||
if (!selected_window)
|
||||
return;
|
||||
|
||||
if (pos.x() < (area.width()*scaleFactor - selected_window->width()) * 0.5f *(1.0f / scaleFactor)) {
|
||||
float availableSize = (area.width() * scaleFactor - area.width()) * 0.5f * (1.0f / scaleFactor);
|
||||
for (int i = 0; i < leftWindows.count(); i++) {
|
||||
int windowPos = availableSize / leftWindows.count() * i;
|
||||
if (pos.x() < windowPos)
|
||||
continue;
|
||||
if (i + 1 < leftWindows.count()) {
|
||||
if (pos.x() > availableSize / leftWindows.count()*(i + 1))
|
||||
continue;
|
||||
}
|
||||
|
||||
effects->setTabBoxWindow(leftWindows[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos.x() > area.width() - (area.width()*scaleFactor - selected_window->width()) * 0.5f *(1.0f / scaleFactor)) {
|
||||
float availableSize = (area.width() * scaleFactor - area.width()) * 0.5f * (1.0f / scaleFactor);
|
||||
for (int i = 0; i < rightWindows.count(); i++) {
|
||||
int windowPos = area.width() - availableSize / rightWindows.count() * i;
|
||||
if (pos.x() > windowPos)
|
||||
continue;
|
||||
if (i + 1 < rightWindows.count()) {
|
||||
if (pos.x() < area.width() - availableSize / rightWindows.count()*(i + 1))
|
||||
continue;
|
||||
}
|
||||
|
||||
effects->setTabBoxWindow(rightWindows[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1009,24 +1024,33 @@ void CoverSwitchEffect::updateCaption()
|
|||
|
||||
void CoverSwitchEffect::slotTabBoxKeyEvent(QKeyEvent *event)
|
||||
{
|
||||
if (!mActivated || !selected_window) {
|
||||
return;
|
||||
}
|
||||
const int index = effects->currentTabBoxWindowList().indexOf(selected_window);
|
||||
int newIndex = index;
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Left:
|
||||
newIndex = (index - 1);
|
||||
selectPreviousWindow();
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
newIndex = (index + 1);
|
||||
selectNextWindow();
|
||||
break;
|
||||
default:
|
||||
// nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CoverSwitchEffect::selectNextOrPreviousWindow(bool forward)
|
||||
{
|
||||
if (!mActivated || !selected_window) {
|
||||
return;
|
||||
}
|
||||
const int index = effects->currentTabBoxWindowList().indexOf(selected_window);
|
||||
int newIndex = index;
|
||||
if (forward) {
|
||||
++newIndex;
|
||||
} else {
|
||||
--newIndex;
|
||||
}
|
||||
if (newIndex == effects->currentTabBoxWindowList().size()) {
|
||||
newIndex = 0;
|
||||
} else if (newIndex < 0) {
|
||||
|
|
|
@ -65,6 +65,9 @@ private:
|
|||
void paintWindowCover(EffectWindow* w, bool reflectedWindow, WindowPaintData& data);
|
||||
void paintFrontWindow(EffectWindow* frontWindow, int width, int leftWindows, int rightWindows, bool reflectedWindow);
|
||||
void paintWindows(const EffectWindowList& windows, bool left, bool reflectedWindows, EffectWindow* additionalWindow = NULL);
|
||||
void selectNextOrPreviousWindow(bool forward);
|
||||
inline void selectNextWindow() { selectNextOrPreviousWindow(true); }
|
||||
inline void selectPreviousWindow() { selectNextOrPreviousWindow(false); }
|
||||
void abort();
|
||||
/**
|
||||
* Updates the caption of the caption frame.
|
||||
|
|
|
@ -641,6 +641,7 @@ void FlipSwitchEffect::setActive(bool activate, FlipSwitchMode mode)
|
|||
switch(m_mode) {
|
||||
case TabboxMode:
|
||||
m_selectedWindow = effects->currentTabBoxWindow();
|
||||
m_input = effects->createFullScreenInputWindow(this, Qt::ArrowCursor);
|
||||
break;
|
||||
case CurrentDesktopMode:
|
||||
m_selectedWindow = effects->activeWindow();
|
||||
|
@ -687,8 +688,7 @@ void FlipSwitchEffect::setActive(bool activate, FlipSwitchMode mode)
|
|||
}
|
||||
} else
|
||||
m_startStopTimeLine.setCurveShape(QTimeLine::EaseInOutCurve);
|
||||
if (mode != TabboxMode)
|
||||
effects->destroyInputWindow(m_input);
|
||||
effects->destroyInputWindow(m_input);
|
||||
if (m_hasKeyboardGrab) {
|
||||
effects->ungrabKeyboard();
|
||||
m_hasKeyboardGrab = false;
|
||||
|
@ -835,6 +835,29 @@ void FlipSwitchEffect::adjustWindowMultiScreen(const KWin::EffectWindow* w, Wind
|
|||
}
|
||||
}
|
||||
|
||||
void FlipSwitchEffect::selectNextOrPreviousWindow(bool forward)
|
||||
{
|
||||
if (!m_active || !m_selectedWindow) {
|
||||
return;
|
||||
}
|
||||
const int index = effects->currentTabBoxWindowList().indexOf(m_selectedWindow);
|
||||
int newIndex = index;
|
||||
if (forward) {
|
||||
++newIndex;
|
||||
} else {
|
||||
--newIndex;
|
||||
}
|
||||
if (newIndex == effects->currentTabBoxWindowList().size()) {
|
||||
newIndex = 0;
|
||||
} else if (newIndex < 0) {
|
||||
newIndex = effects->currentTabBoxWindowList().size() -1;
|
||||
}
|
||||
if (index == newIndex) {
|
||||
return;
|
||||
}
|
||||
effects->setTabBoxWindow(effects->currentTabBoxWindowList().at(newIndex));
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************
|
||||
// Keyboard handling
|
||||
|
@ -937,35 +960,21 @@ void FlipSwitchEffect::grabbedKeyboardEvent(QKeyEvent* e)
|
|||
|
||||
void FlipSwitchEffect::slotTabBoxKeyEvent(QKeyEvent *event)
|
||||
{
|
||||
if (!m_active || !m_selectedWindow) {
|
||||
return;
|
||||
}
|
||||
const int index = effects->currentTabBoxWindowList().indexOf(m_selectedWindow);
|
||||
int newIndex = index;
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Left:
|
||||
newIndex = (index - 1);
|
||||
selectPreviousWindow();
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Right:
|
||||
newIndex = (index + 1);
|
||||
selectNextWindow();
|
||||
break;
|
||||
default:
|
||||
// nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newIndex == effects->currentTabBoxWindowList().size()) {
|
||||
newIndex = 0;
|
||||
} else if (newIndex < 0) {
|
||||
newIndex = effects->currentTabBoxWindowList().size() -1;
|
||||
}
|
||||
if (index == newIndex) {
|
||||
return;
|
||||
}
|
||||
effects->setTabBoxWindow(effects->currentTabBoxWindowList().at(newIndex));
|
||||
}
|
||||
|
||||
bool FlipSwitchEffect::isActive() const
|
||||
|
@ -989,6 +998,37 @@ void FlipSwitchEffect::updateCaption()
|
|||
}
|
||||
}
|
||||
|
||||
//*************************************************************
|
||||
// Mouse handling
|
||||
//*************************************************************
|
||||
|
||||
void FlipSwitchEffect::windowInputMouseEvent(Window w, QEvent* e)
|
||||
{
|
||||
assert(w == m_input);
|
||||
Q_UNUSED(w);
|
||||
if (e->type() != QEvent::MouseButtonPress)
|
||||
return;
|
||||
// we don't want click events during animations
|
||||
if (m_animation)
|
||||
return;
|
||||
QMouseEvent* event = static_cast< QMouseEvent* >(e);
|
||||
|
||||
switch (event->button()) {
|
||||
case Qt::XButton1: // wheel up
|
||||
selectPreviousWindow();
|
||||
break;
|
||||
case Qt::XButton2: // wheel down
|
||||
selectNextWindow();
|
||||
break;
|
||||
case Qt::LeftButton:
|
||||
case Qt::RightButton:
|
||||
case Qt::MidButton:
|
||||
default:
|
||||
// TODO: Change window on mouse button click
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************
|
||||
// Item Info
|
||||
//*************************************************************
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
|
||||
virtual bool borderActivated(ElectricBorder border);
|
||||
virtual void grabbedKeyboardEvent(QKeyEvent* e);
|
||||
virtual void windowInputMouseEvent(Window w, QEvent* e);
|
||||
virtual bool isActive() const;
|
||||
|
||||
static bool supported();
|
||||
|
@ -77,6 +78,9 @@ private:
|
|||
bool isSelectableWindow(EffectWindow *w) const;
|
||||
void scheduleAnimation(const SwitchingDirection& direction, int distance = 1);
|
||||
void adjustWindowMultiScreen(const EffectWindow *w, WindowPaintData& data);
|
||||
void selectNextOrPreviousWindow(bool forward);
|
||||
inline void selectNextWindow() { selectNextOrPreviousWindow(true); }
|
||||
inline void selectPreviousWindow() { selectNextOrPreviousWindow(false); }
|
||||
/**
|
||||
* Updates the caption of the caption frame.
|
||||
* Taking care of rewording the desktop client.
|
||||
|
|
Loading…
Reference in a new issue