Verified Commit ef7affd1 authored by snooxx's avatar snooxx
Browse files

Restore grabbing taskbar and multiple screens

39f712a2 also prevented KMag from showing the taskbar in a single-screen
setup as well as content on secondary screens in a multi-screen setup,
because `screen()->availableGeometry()->width()` is not a suitable
replacement for `QApplication::desktop()->width()`.

Qt provides a multitude of options, even when not using deprecated
functions the original commit tried to port away from:
`availableGeometry()`, `availableVirtualGeometry()`, `virtualGeometry()`
and `geometry()`. To include all screens, the `virtual*` variants are
needed, while on single screens the `available*` variants do not include
the area covered by the taskbar. Therefore for the purpose of KMag,
which should show everything, `virtualGeometry()` is the correct
function to use, switching to the more specific `virtualSize()` when
applicable.

In addition, in `KMagZoomView::mouseMoveEvent` we can eliminate one
extra unneeded variable inside a block, hiding the identically
functioning variable of the same name outside that block.

Test Plan:
  - Taskbar shows on single screen-screen setup.
  - All screens in a multi-screen setup can be magnified, gaps between
    screens are correctly shown with black bars.
  - Cursor position is correct everywhere.
  - HiDPI mode works too.
  - Note 1: KMag currently only supports X11.
  - Note 2: Testing was only performed with Qt5.
  - Note 3: Choose "Mouse Mode", since "Window Mode" has been partially
    broken way back in 095196f3 already and "Screen Edge Mode" from
    1884b51a as a replacement for the questionable "Screen Mode" has
    never been forward-ported to the Qt4 branch created before that
    commit.
parent ec406590
Pipeline #151703 skipped
......@@ -627,8 +627,7 @@ void KmagApp::slotToggleRefresh()
void KmagApp::slotModeWholeScreen()
{
m_zoomView->followMouse(false);
const QRect screenGeometry = m_zoomView->screen()->availableGeometry();
m_zoomView->setSelRectPos(QRect (0, 0, screenGeometry.width(), screenGeometry.height()));
m_zoomView->setSelRectPos(screen()->virtualGeometry());
m_zoomView->showSelRect(false);
m_zoomView->setFitToWindow (false);
m_modeFollowMouse->setChecked(false);
......
......@@ -261,11 +261,11 @@ void KMagSelWin::setSelRect (const QRect &_selRect)
selRect.setLeft (0);
if (selRect.top() < 0)
selRect.setTop (0);
const QRect screenGeometry = screen()->availableGeometry();
if (selRect.right() > screenGeometry.width())
selRect.setRight (screenGeometry.width());
if (selRect.bottom() > screenGeometry.height())
selRect.setBottom (screenGeometry.height());
const QSize screenSize = screen()->virtualSize();
if (selRect.right() > screenSize.width())
selRect.setRight (screenSize.width());
if (selRect.bottom() > screenSize.height())
selRect.setBottom (screenSize.height());
setGeometry (
selRect.left() - getFrameSize(),
......
......@@ -641,7 +641,7 @@ void KMagZoomView::mouseReleaseEvent(QMouseEvent *e)
*/
void KMagZoomView::mouseMoveEvent(QMouseEvent *e)
{
const QRect screenGeometry = screen()->availableGeometry();
const QSize screenSize = screen()->virtualSize();
if(m_mouseMode == ResizeSelection) {
// In resize selection mode
// set the current mouse position as the bottom, right corner
......@@ -657,21 +657,20 @@ void KMagZoomView::mouseMoveEvent(QMouseEvent *e)
// make sure the mouse position is not taking the grab window outside
// the display
const QRect screenGeometry = screen()->availableGeometry();
if(newCenter.x() < m_selRect.width()/2) {
// set X to the minimum possible X
newCenter.setX(m_selRect.width()/2);
} else if(newCenter.x() >= screenGeometry.width()-m_selRect.width()/2) {
} else if(newCenter.x() >= screenSize.width()-m_selRect.width()/2) {
// set X to the maximum possible X
newCenter.setX(screenGeometry.width()-m_selRect.width()/2-1);
newCenter.setX(screenSize.width()-m_selRect.width()/2-1);
}
if(newCenter.y() < m_selRect.height()/2) {
// set Y to the minimum possible Y
newCenter.setY(m_selRect.height()/2);
} else if(newCenter.y() >= screenGeometry.height()-m_selRect.height()/2) {
} else if(newCenter.y() >= screenSize.height()-m_selRect.height()/2) {
// set Y to the maximum possible Y
newCenter.setY(screenGeometry.height()-m_selRect.height()/2-1);
newCenter.setY(screenSize.height()-m_selRect.height()/2-1);
}
// move to the new center
m_selRect.moveCenter(newCenter);
......@@ -692,17 +691,17 @@ void KMagZoomView::mouseMoveEvent(QMouseEvent *e)
if(newCenter.x() < m_selRect.width()/2) {
// set X to the minimum possible X
newCenter.setX(m_selRect.width()/2);
} else if(newCenter.x() >= screenGeometry.width()-m_selRect.width()/2) {
} else if(newCenter.x() >= screenSize.width()-m_selRect.width()/2) {
// set X to the maximum possible X
newCenter.setX(screenGeometry.width()-m_selRect.width()/2-1);
newCenter.setX(screenSize.width()-m_selRect.width()/2-1);
}
if(newCenter.y() < m_selRect.height()/2) {
// set Y to the minimum possible Y
newCenter.setY(m_selRect.height()/2);
} else if(newCenter.y() >= screenGeometry.height()-m_selRect.height()/2) {
} else if(newCenter.y() >= screenSize.height()-m_selRect.height()/2) {
// set Y to the maximum possible Y
newCenter.setY(screenGeometry.height()-m_selRect.height()/2-1);
newCenter.setY(screenSize.height()-m_selRect.height()/2-1);
}
// move to the new center
......@@ -753,9 +752,9 @@ void KMagZoomView::keyPressEvent(QKeyEvent *e)
{
if (e->modifiers() & Qt::ControlModifier)
{
const QRect screenGeometry = screen()->availableGeometry();
if (m_selRect.right()+offset >= screenGeometry.width())
m_selRect.setRight (screenGeometry.width()-1);
const QSize screenSize = screen()->virtualSize();
if (m_selRect.right()+offset >= screenSize.width())
m_selRect.setRight (screenSize.width()-1);
else
m_selRect.setRight (m_selRect.right()+offset);
}
......@@ -769,9 +768,9 @@ void KMagZoomView::keyPressEvent(QKeyEvent *e)
}
else if (m_followMouse == false)
{
const QRect screenGeometry = screen()->availableGeometry();
if (m_selRect.right()+offset >= screenGeometry.width())
m_selRect.moveTopRight (QPoint (screenGeometry.width()-1, m_selRect.top()));
const QSize screenSize = screen()->virtualSize();
if (m_selRect.right()+offset >= screenSize.width())
m_selRect.moveTopRight (QPoint (screenSize.width()-1, m_selRect.top()));
else
m_selRect.translate (offset,0);
}
......@@ -807,9 +806,9 @@ void KMagZoomView::keyPressEvent(QKeyEvent *e)
{
if (e->modifiers() & Qt::ControlModifier)
{
const QRect screenGeometry = screen()->availableGeometry();
if (m_selRect.bottom()+offset >= screenGeometry.height())
m_selRect.setBottom (screenGeometry.height()-1);
const QSize screenSize = screen()->virtualSize();
if (m_selRect.bottom()+offset >= screenSize.height())
m_selRect.setBottom (screenSize.height()-1);
else
m_selRect.setBottom (m_selRect.bottom()+offset);
}
......@@ -823,9 +822,9 @@ void KMagZoomView::keyPressEvent(QKeyEvent *e)
}
else if (m_followMouse == false)
{
const QRect screenGeometry = screen()->availableGeometry();
if (m_selRect.bottom()+offset >= screenGeometry.height())
m_selRect.moveBottomLeft (QPoint (m_selRect.left(), screenGeometry.height()-1));
const QSize screenSize = screen()->virtualSize();
if (m_selRect.bottom()+offset >= screenSize.height())
m_selRect.moveBottomLeft (QPoint (m_selRect.left(), screenSize.height()-1));
else
m_selRect.translate (0, offset);
}
......@@ -877,22 +876,22 @@ void KMagZoomView::fitToWindow()
m_selRect.setWidth(newWidth);
m_selRect.setHeight(newHeight);
const QRect screenGeometry = screen()->availableGeometry();
const QSize screenSize = screen()->virtualSize();
// make sure the selection window does not go outside of the display
if(currCenter.x() < m_selRect.width()/2) {
// set X to the minimum possible X
currCenter.setX(m_selRect.width()/2);
} else if(currCenter.x() >= screenGeometry.width()-m_selRect.width()/2) {
} else if(currCenter.x() >= screenSize.width()-m_selRect.width()/2) {
// set X to the maximum possible X
currCenter.setX(screenGeometry.width()-m_selRect.width()/2-1);
currCenter.setX(screenSize.width()-m_selRect.width()/2-1);
}
if(currCenter.y() < m_selRect.height()/2) {
// set Y to the minimum possible Y
currCenter.setY(m_selRect.height()/2);
} else if(currCenter.y() >= screenGeometry.height()-m_selRect.height()/2) {
} else if(currCenter.y() >= screenSize.height()-m_selRect.height()/2) {
// set Y to the maximum possible Y
currCenter.setY(screenGeometry.height()-m_selRect.height()/2-1);
currCenter.setY(screenSize.height()-m_selRect.height()/2-1);
}
m_selRect.moveCenter(currCenter);
......@@ -940,21 +939,21 @@ void KMagZoomView::grabFrame()
// make sure the mouse position is not taking the grab window outside
// the display
const QRect screenGeometry = screen()->availableGeometry();
const QSize screenSize = screen()->virtualSize();
if(newCenter.x() < m_selRect.width()/2) {
// set X to the minimum possible X
newCenter.setX(m_selRect.width()/2);
} else if(newCenter.x() >= screenGeometry.width()-m_selRect.width()/2) {
} else if(newCenter.x() >= screenSize.width()-m_selRect.width()/2) {
// set X to the maximum possible X
newCenter.setX(screenGeometry.width()-m_selRect.width()/2-1);
newCenter.setX(screenSize.width()-m_selRect.width()/2-1);
}
if(newCenter.y() < m_selRect.height()/2) {
// set Y to the minimum possible Y
newCenter.setY(m_selRect.height()/2);
} else if(newCenter.y() >= screenGeometry.height()-m_selRect.height()/2) {
} else if(newCenter.y() >= screenSize.height()-m_selRect.height()/2) {
// set Y to the maximum possible Y
newCenter.setY(screenGeometry.height()-m_selRect.height()/2-1);
newCenter.setY(screenSize.height()-m_selRect.height()/2-1);
}
// move to the new center
m_selRect.moveCenter(newCenter);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment