1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-26 23:21:37 +03:00

move window funcionality to lastactivewindow

This commit is contained in:
Michail Vourlakos 2019-06-01 10:55:03 +03:00
parent a03655f176
commit 342d4a1a00
8 changed files with 71 additions and 67 deletions

View File

@ -44,6 +44,10 @@ WindowsTracker::WindowsTracker(Latte::View *parent)
init();
m_wm->windowsTracker()->addView(m_latteView);
connect(lastActiveWindow(), &WindowSystem::Tracker::LastActiveWindow::draggingStarted,
this, &WindowsTracker::activeWindowDraggingStarted);
emit lastActiveWindowChanged();
}
@ -161,47 +165,5 @@ void WindowsTracker::setWindowOnActivities(QWindow &window, const QStringList &a
m_wm->setWindowOnActivities(window, activities);
}
void WindowsTracker::requestToggleMaximizeForActiveWindow()
{
Latte::WindowSystem::Tracker::LastActiveWindow *actInfo = m_wm->windowsTracker()->lastActiveWindow(m_latteView);
//active window can be toggled only when it is in the same screen
if (actInfo && !actInfo->geometry().isNull() && m_latteView->screenGeometry().contains(actInfo->geometry().center())) {
m_wm->requestToggleMaximized(actInfo->winId());
}
}
void WindowsTracker::requestMoveActiveWindow(int localX, int localY)
{
Latte::WindowSystem::Tracker::LastActiveWindow *actInfo = m_wm->windowsTracker()->lastActiveWindow(m_latteView);
//active window can be dragged only when it is in the same screen
if (actInfo && !actInfo->geometry().isNull() && m_latteView->screenGeometry().contains(actInfo->geometry().center())) {
QPoint globalPoint{m_latteView->x() + localX, m_latteView->y() + localY};
m_wm->requestMoveWindow(actInfo->winId(), globalPoint);
//! This timer is needed because otherwise the mouse position
//! in the dragged window changes to TopLeft corner
QTimer::singleShot(250, this, [&]() {
m_wm->releaseMouseEventFor(m_latteView->winId());
});
emit activeWindowDraggingStarted();
}
}
bool WindowsTracker::activeWindowCanBeDragged()
{
Latte::WindowSystem::Tracker::LastActiveWindow *actInfo = m_wm->windowsTracker()->lastActiveWindow(m_latteView);
//active window can be dragged only when it is in the same screen
if (actInfo && !actInfo->geometry().isNull() && m_latteView->screenGeometry().contains(actInfo->geometry().center())) {
return m_wm->windowCanBeDragged(actInfo->winId());
}
return false;
}
}
}

View File

@ -88,11 +88,6 @@ signals:
void lastActiveWindowChanged();
public slots:
Q_INVOKABLE void requestToggleMaximizeForActiveWindow();
Q_INVOKABLE void requestMoveActiveWindow(int localX, int localY);
Q_INVOKABLE bool activeWindowCanBeDragged();
private:
void init();

View File

@ -24,19 +24,24 @@
#include "windows.h"
#include "../abstractwindowinterface.h"
#include "../tasktools.h"
#include "../../view/view.h"
#include "../../view/visibilitymanager.h"
// Qt
#include <QDebug>
#include <QPoint>
#include <QTimer>
namespace Latte {
namespace WindowSystem {
namespace Tracker {
LastActiveWindow::LastActiveWindow(TrackedInfo *parent)
: QObject(parent),
m_windowsTracker(parent->wm()->windowsTracker()),
m_wm(parent->wm())
LastActiveWindow::LastActiveWindow(TrackedInfo *trackedInfo)
: QObject(trackedInfo),
m_trackedInfo(trackedInfo),
m_windowsTracker(trackedInfo->wm()->windowsTracker()),
m_wm(trackedInfo->wm())
{
}
@ -246,6 +251,32 @@ void LastActiveWindow::setInformation(const WindowInfoWrap &info)
}
//! FUNCTIONALITY
void LastActiveWindow::requestToggleMaximize()
{
m_wm->requestToggleMaximized(m_winId);
}
void LastActiveWindow::requestMove(int localX, int localY)
{
QPoint globalPoint{m_trackedInfo->view()->x() + localX, m_trackedInfo->view()->y() + localY};
m_wm->requestMoveWindow(m_winId, globalPoint);
//! This timer is needed because otherwise the mouse position
//! in the dragged window changes to TopLeft corner
QTimer::singleShot(250, this, [&]() {
m_wm->releaseMouseEventFor(m_trackedInfo->view()->winId());
});
emit draggingStarted();
}
bool LastActiveWindow::canBeDragged()
{
return m_wm->windowCanBeDragged(m_winId);
}
}
}
}

View File

@ -22,12 +22,14 @@
// local
#include "../windowinfowrap.h"
#include "../abstractwindowinterface.h"
// Qt
#include <QObject>
#include <QRect>
namespace Latte {
class View;
namespace WindowSystem {
class AbstractWindowInterface;
namespace Tracker {
@ -36,9 +38,6 @@ class Windows;
}
}
}
/*
, m_hasSkipTaskbar(false)
*/
namespace Latte {
namespace WindowSystem {
@ -63,7 +62,7 @@ class LastActiveWindow : public QObject {
Q_PROPERTY(QVariant winId READ winId NOTIFY winIdChanged)
public:
LastActiveWindow(TrackedInfo *parent);
LastActiveWindow(TrackedInfo *trackedInfo);
~LastActiveWindow() override;
bool isActive() const;
@ -84,7 +83,14 @@ public:
void setInformation(const WindowInfoWrap &info);
public slots:
Q_INVOKABLE void requestToggleMaximize();
Q_INVOKABLE void requestMove(int localX, int localY);
Q_INVOKABLE bool canBeDragged();
signals:
void draggingStarted();
void iconChanged();
void isActiveChanged();
void isMinimizedChanged();
@ -134,9 +140,9 @@ private:
QVariant m_winId;
TrackedInfo *m_trackedInfo{nullptr};
AbstractWindowInterface *m_wm{nullptr};
Tracker::Windows *m_windowsTracker{nullptr};
};
}

View File

@ -22,15 +22,17 @@
//local
#include "windows.h"
#include "../schemecolors.h"
#include "../../view/view.h"
namespace Latte {
namespace WindowSystem {
namespace Tracker {
TrackedInfo::TrackedInfo(Tracker::Windows *parent)
: QObject(parent),
m_wm(parent->wm())
TrackedInfo::TrackedInfo(Tracker::Windows *tracker, Latte::View *view)
: QObject(tracker) ,
m_wm(tracker->wm()),
m_view(view)
{
m_lastActiveWindow = new LastActiveWindow(this);
@ -179,6 +181,11 @@ void TrackedInfo::setTouchingWindowScheme(SchemeColors *scheme)
m_touchingWindowScheme = scheme;
}
Latte::View *TrackedInfo::view()
{
return m_view;
}
AbstractWindowInterface *TrackedInfo::wm()
{
return m_wm;

View File

@ -29,6 +29,7 @@
#include <QRect>
namespace Latte {
class View;
namespace WindowSystem {
class SchemeColors;
namespace Tracker {
@ -48,7 +49,7 @@ class TrackedInfo : public QObject {
Q_PROPERTY(Latte::WindowSystem::Tracker::LastActiveWindow *activeWindow READ lastActiveWindow NOTIFY lastActiveWindowChanged)
public:
TrackedInfo(Tracker::Windows *parent);
TrackedInfo(Tracker::Windows *tracker, Latte::View *view);
~TrackedInfo() override;
bool enabled() const;
@ -80,6 +81,7 @@ public:
SchemeColors *touchingWindowScheme() const;
void setTouchingWindowScheme(SchemeColors *scheme);
Latte::View *view();
AbstractWindowInterface *wm();
signals:
@ -95,6 +97,7 @@ private:
QRect m_availableScreenGeometry;
Latte::View *m_view{nullptr};
LastActiveWindow *m_lastActiveWindow{nullptr};
SchemeColors *m_activeWindowScheme{nullptr};

View File

@ -130,7 +130,7 @@ void Windows::addView(Latte::View *view)
return;
}
m_views[view] = new TrackedInfo(this);
m_views[view] = new TrackedInfo(this, view);
updateAvailableScreenGeometries();
updateHints(view);

View File

@ -69,7 +69,7 @@ Loader {
return;
}
if (latteView.windowsTracker.activeWindowCanBeDragged()) {
if (latteView.windowsTracker.lastActiveWindow.canBeDragged()) {
lastPressX = mouse.x;
lastPressY = mouse.y;
dragWindowTimer.start();
@ -92,7 +92,7 @@ Loader {
var tryDrag = mainArea.pressed && (stepX>threshold || stepY>threshold);
if ( tryDrag && latteView.windowsTracker.activeWindowCanBeDragged()) {
if ( tryDrag && latteView.windowsTracker.lastActiveWindow.canBeDragged()) {
dragWindowTimer.stop();
activateDragging();
}
@ -105,7 +105,7 @@ Loader {
dragWindowTimer.stop();
restoreGrabberTimer.stop();
latteView.windowsTracker.requestToggleMaximizeForActiveWindow();
latteView.windowsTracker.lastActiveWindow.requestToggleMaximize();
//tasksModel.requestToggleMaximized(tasksModel.activeTask);
}
@ -170,7 +170,7 @@ Loader {
function activateDragging(){
latteView.disableGrabItemBehavior();
latteView.windowsTracker.requestMoveActiveWindow(mainArea.mouseX, mainArea.mouseY);
latteView.windowsTracker.lastActiveWindow.requestMove(mainArea.mouseX, mainArea.mouseY);
restoreGrabberTimer.start();
}
@ -179,7 +179,7 @@ Loader {
id: dragWindowTimer
interval: 500
onTriggered: {
if (mainArea.pressed && latteView.windowsTracker.activeWindowCanBeDragged()) {
if (mainArea.pressed && latteView.windowsTracker.lastActiveWindow.canBeDragged()) {
mainArea.activateDragging();
}
}