2016-12-30 16:22:28 -05:00
/*
2017-01-02 17:05:30 -05:00
* Copyright 2016 Smith AR < audoban @ openmailbox . org >
* Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2016-12-30 16:22:28 -05:00
2016-12-30 16:25:27 -05:00
# include "dockview.h"
2018-02-03 11:34:13 +02:00
2016-12-30 16:25:27 -05:00
# include "dockconfigview.h"
2018-02-03 15:00:44 +02:00
# include "dockmenumanager.h"
2018-02-03 11:34:13 +02:00
2017-01-31 21:25:00 +02:00
# include "panelshadows_p.h"
2017-03-18 13:21:17 +02:00
# include "visibilitymanager.h"
2018-02-03 11:34:13 +02:00
# include "../dockcorona.h"
# include "../layout.h"
# include "../layoutmanager.h"
# include "../screenpool.h"
# include "../universalsettings.h"
# include "../../liblattedock/extras.h"
2016-12-30 16:22:28 -05:00
# include <QAction>
# include <QQmlContext>
# include <QQmlEngine>
# include <QQmlProperty>
# include <QQuickItem>
2017-01-03 15:33:30 +02:00
# include <QMenu>
2016-12-30 16:22:28 -05:00
# include <QMetaEnum>
2017-05-17 09:19:32 +03:00
# include <QVersionNumber>
2016-12-30 16:22:28 -05:00
# include <KActionCollection>
2017-01-03 15:33:30 +02:00
# include <KAuthorized>
2016-12-30 16:22:28 -05:00
# include <KLocalizedContext>
2017-01-03 15:33:30 +02:00
# include <KLocalizedString>
2017-03-04 12:49:48 +02:00
# include <KWindowEffects>
2017-03-12 20:18:18 +02:00
# include <KWindowSystem>
2017-01-03 15:33:30 +02:00
2018-01-14 09:39:31 +02:00
# include <KActivities/Consumer>
2017-01-03 15:33:30 +02:00
# include <Plasma/Containment>
# include <Plasma/ContainmentActions>
# include <PlasmaQuick/AppletQuickItem>
2016-12-30 16:22:28 -05:00
2017-04-25 19:18:49 +03:00
# include <KWayland/Client/plasmashell.h>
# include <KWayland/Client/surface.h>
2016-12-30 16:22:28 -05:00
namespace Latte {
2017-03-18 23:32:27 +02:00
//! both alwaysVisible and dockWinBehavior are passed through corona because
//! during the dock window creation containment hasnt been set, but these variables
//! are needed in order for window flags to be set correctly
2017-04-09 13:42:39 -05:00
DockView : : DockView ( Plasma : : Corona * corona , QScreen * targetScreen , bool dockWindowBehavior )
2017-01-03 15:33:30 +02:00
: PlasmaQuick : : ContainmentView ( corona ) ,
2018-02-03 15:00:44 +02:00
m_menuManager ( new DockMenuManager ( this ) )
2017-02-27 02:36:30 -05:00
{
2016-12-30 16:22:28 -05:00
setTitle ( corona - > kPackage ( ) . metadata ( ) . name ( ) ) ;
2017-03-11 20:36:43 +02:00
setIcon ( qGuiApp - > windowIcon ( ) ) ;
2016-12-30 16:22:28 -05:00
setResizeMode ( QuickViewSharedEngine : : SizeRootObjectToView ) ;
2017-03-12 20:18:18 +02:00
setColor ( QColor ( Qt : : transparent ) ) ;
2016-12-30 16:22:28 -05:00
setClearBeforeRendering ( true ) ;
2017-03-08 21:00:09 +02:00
2017-04-09 13:42:39 -05:00
const auto flags = Qt : : FramelessWindowHint
2017-04-11 12:10:54 +03:00
| Qt : : WindowStaysOnTopHint
| Qt : : NoDropShadowWindowHint
| Qt : : WindowDoesNotAcceptFocus ;
2017-04-09 13:42:39 -05:00
if ( dockWindowBehavior ) {
setFlags ( flags ) ;
2017-03-08 21:00:09 +02:00
} else {
2017-04-09 13:42:39 -05:00
setFlags ( flags | Qt : : BypassWindowManagerHint ) ;
2017-03-08 21:00:09 +02:00
}
2017-01-16 14:07:49 -05:00
2017-03-29 14:32:32 +03:00
KWindowSystem : : setOnAllDesktops ( winId ( ) , true ) ;
2016-12-30 16:22:28 -05:00
if ( targetScreen )
2017-02-25 15:29:05 +02:00
setScreenToFollow ( targetScreen ) ;
2016-12-30 16:22:28 -05:00
else
2017-02-25 15:29:05 +02:00
setScreenToFollow ( qGuiApp - > primaryScreen ( ) ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:25:27 -05:00
connect ( this , & DockView : : containmentChanged
2017-07-29 23:07:00 +03:00
, this , [ & , dockWindowBehavior ] ( ) {
2017-06-25 16:42:19 +03:00
qDebug ( ) < < " dock view c++ containment changed 1... " ;
2017-02-12 10:02:01 +02:00
if ( ! this - > containment ( ) )
2016-12-30 16:22:28 -05:00
return ;
2017-02-27 00:53:27 +02:00
2017-06-25 16:42:19 +03:00
qDebug ( ) < < " dock view c++ containment changed 2... " ;
2017-07-29 23:07:00 +03:00
setDockWinBehavior ( dockWindowBehavior ) ;
2017-02-27 00:53:27 +02:00
restoreConfig ( ) ;
reconsiderScreen ( ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! m_visibility ) {
m_visibility = new VisibilityManager ( this ) ;
2018-02-25 20:00:23 +02:00
connect ( m_visibility , & VisibilityManager : : isHiddenChanged , this , [ & ] ( ) {
if ( m_visibility - > isHidden ( ) ) {
deactivateApplets ( ) ;
}
} ) ;
2016-12-30 16:22:28 -05:00
}
2017-01-16 14:07:49 -05:00
2017-02-12 10:02:01 +02:00
connect ( this - > containment ( ) , SIGNAL ( statusChanged ( Plasma : : Types : : ItemStatus ) ) , SLOT ( statusChanged ( Plasma : : Types : : ItemStatus ) ) ) ;
2016-12-30 16:22:28 -05:00
} , Qt : : DirectConnection ) ;
2018-01-10 19:48:23 +02:00
2017-01-16 13:24:46 -05:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
2017-01-16 14:07:49 -05:00
2017-01-22 13:29:40 +02:00
if ( dockCorona ) {
2017-01-16 13:24:46 -05:00
connect ( dockCorona , & DockCorona : : docksCountChanged , this , & DockView : : docksCountChanged ) ;
2017-06-12 00:40:45 +03:00
connect ( this , & DockView : : docksCountChanged , this , & DockView : : totalDocksCountChanged ) ;
2017-01-22 13:29:40 +02:00
connect ( dockCorona , & DockCorona : : dockLocationChanged , this , & DockView : : dockLocationChanged ) ;
2017-02-27 23:21:14 +02:00
connect ( dockCorona , & DockCorona : : dockLocationChanged , this , [ & ] ( ) {
2017-03-02 18:07:29 +02:00
//! check if an edge has been freed for a primary dock
//! from another screen
2017-03-01 16:59:04 +02:00
if ( m_onPrimary ) {
2017-02-27 23:21:14 +02:00
m_screenSyncTimer . start ( ) ;
}
} ) ;
2017-01-22 13:29:40 +02:00
}
2017-02-26 19:15:20 +02:00
m_screenSyncTimer . setSingleShot ( true ) ;
2017-03-01 20:49:21 +02:00
m_screenSyncTimer . setInterval ( 2000 ) ;
2017-02-26 19:15:20 +02:00
connect ( & m_screenSyncTimer , & QTimer : : timeout , this , & DockView : : reconsiderScreen ) ;
2016-12-30 16:22:28 -05:00
}
2016-12-30 16:25:27 -05:00
DockView : : ~ DockView ( )
2016-12-30 16:22:28 -05:00
{
2017-06-21 23:34:40 +03:00
m_inDelete = true ;
2018-03-01 01:31:17 +02:00
2017-06-21 22:42:09 +03:00
disconnect ( corona ( ) , & Plasma : : Corona : : availableScreenRectChanged , this , & DockView : : availableScreenRectChanged ) ;
2017-06-21 23:34:40 +03:00
disconnect ( containment ( ) , SIGNAL ( statusChanged ( Plasma : : Types : : ItemStatus ) ) , this , SLOT ( statusChanged ( Plasma : : Types : : ItemStatus ) ) ) ;
2017-06-21 22:42:09 +03:00
2017-02-27 23:24:13 +02:00
m_screenSyncTimer . stop ( ) ;
2017-03-18 01:53:44 +02:00
2017-01-05 17:48:27 +02:00
qDebug ( ) < < " dock view deleting... " ;
2017-01-22 00:40:16 +02:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dock " ) , nullptr ) ;
2017-01-16 14:07:49 -05:00
2017-03-13 20:58:31 +02:00
//! this disconnect does not free up connections correctly when
//! dockView is deleted. A crash for this example is the following:
//! switch to Alternative Session and disable compositing,
//! the signal creating the crash was probably from deleted
//! windows.
//! this->disconnect();
2017-01-17 20:09:43 +02:00
2018-01-18 21:21:32 +02:00
if ( m_configView ) {
2017-06-21 17:14:13 +03:00
m_configView - > setVisible ( false ) ; //hide();
2018-01-18 21:21:32 +02:00
}
2018-02-03 15:00:44 +02:00
if ( m_menuManager ) {
m_menuManager - > deleteLater ( ) ;
}
2017-03-12 12:05:02 -05:00
if ( m_visibility )
delete m_visibility ;
2016-12-30 16:22:28 -05:00
}
2016-12-30 16:25:27 -05:00
void DockView : : init ( )
2016-12-30 16:22:28 -05:00
{
2017-02-25 15:29:05 +02:00
connect ( this , & QQuickWindow : : screenChanged , this , & DockView : : screenChanged ) ;
2017-06-12 00:52:17 +03:00
connect ( this , & QQuickWindow : : screenChanged , this , & DockView : : docksCountChanged ) ;
2017-02-26 15:49:50 +02:00
connect ( qGuiApp , & QGuiApplication : : screenAdded , this , & DockView : : screenChanged ) ;
connect ( qGuiApp , & QGuiApplication : : primaryScreenChanged , this , & DockView : : screenChanged ) ;
2017-02-08 20:48:46 +02:00
connect ( this , & DockView : : screenGeometryChanged , this , & DockView : : syncGeometry ) ;
2017-02-26 15:49:50 +02:00
connect ( this , & QQuickWindow : : xChanged , this , & DockView : : xChanged ) ;
2017-03-08 21:00:09 +02:00
connect ( this , & QQuickWindow : : xChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-02-26 15:49:50 +02:00
connect ( this , & QQuickWindow : : yChanged , this , & DockView : : yChanged ) ;
2017-03-08 21:00:09 +02:00
connect ( this , & QQuickWindow : : yChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-01-12 18:55:43 -05:00
connect ( this , & QQuickWindow : : widthChanged , this , & DockView : : widthChanged ) ;
2017-03-08 21:00:09 +02:00
connect ( this , & QQuickWindow : : widthChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-01-12 18:55:43 -05:00
connect ( this , & QQuickWindow : : heightChanged , this , & DockView : : heightChanged ) ;
2017-03-08 21:00:09 +02:00
connect ( this , & QQuickWindow : : heightChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-06-21 22:42:09 +03:00
connect ( corona ( ) , & Plasma : : Corona : : availableScreenRectChanged , this , & DockView : : availableScreenRectChanged ) ;
2017-05-07 15:06:29 +03:00
connect ( this , & DockView : : behaveAsPlasmaPanelChanged , this , & DockView : : syncGeometry ) ;
2017-05-18 15:27:57 +03:00
connect ( this , & DockView : : drawShadowsChanged , this , & DockView : : syncGeometry ) ;
2017-01-31 21:25:00 +02:00
connect ( this , & DockView : : maxLengthChanged , this , & DockView : : syncGeometry ) ;
2017-04-09 01:06:48 +03:00
connect ( this , & DockView : : offsetChanged , this , & DockView : : syncGeometry ) ;
2017-02-04 16:41:12 +02:00
connect ( this , & DockView : : alignmentChanged , this , & DockView : : updateEnabledBorders ) ;
2017-03-18 23:32:27 +02:00
connect ( this , & DockView : : dockWinBehaviorChanged , this , & DockView : : saveConfig ) ;
2017-02-27 00:53:27 +02:00
connect ( this , & DockView : : onPrimaryChanged , this , & DockView : : saveConfig ) ;
2018-01-04 21:27:55 +02:00
2017-01-13 01:27:26 -05:00
connect ( this , & DockView : : locationChanged , this , [ & ] ( ) {
updateFormFactor ( ) ;
syncGeometry ( ) ;
} ) ;
2017-06-19 00:30:07 +03:00
connect ( this , & DockView : : dockTransparencyChanged , this , & DockView : : updateEffects ) ;
2017-03-17 16:58:57 +02:00
connect ( this , & DockView : : drawEffectsChanged , this , & DockView : : updateEffects ) ;
connect ( this , & DockView : : effectsAreaChanged , this , & DockView : : updateEffects ) ;
2018-01-05 20:13:43 +02:00
connect ( & m_theme , & Plasma : : Theme : : themeChanged , this , & DockView : : themeChanged ) ;
2017-05-07 19:24:08 +03:00
connect ( this , & DockView : : normalThicknessChanged , this , [ & ] ( ) {
if ( m_behaveAsPlasmaPanel ) {
syncGeometry ( ) ;
}
} ) ;
2017-03-05 16:38:17 +02:00
connect ( this , SIGNAL ( normalThicknessChanged ( ) ) , corona ( ) , SIGNAL ( availableScreenRectChanged ( ) ) ) ;
connect ( this , SIGNAL ( shadowChanged ( ) ) , corona ( ) , SIGNAL ( availableScreenRectChanged ( ) ) ) ;
2017-12-10 19:54:13 +02:00
2018-02-03 15:00:44 +02:00
connect ( m_menuManager , & DockMenuManager : : contextMenuChanged , this , & DockView : : contextMenuIsShownChanged ) ;
2017-12-10 19:54:13 +02:00
initSignalingForLocationChangeSliding ( ) ;
///!!!!!
2017-01-12 18:55:43 -05:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dock " ) , this ) ;
2017-03-18 13:21:17 +02:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
if ( dockCorona ) {
2017-07-03 19:04:37 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " universalSettings " ) , dockCorona - > universalSettings ( ) ) ;
rootContext ( ) - > setContextProperty ( QStringLiteral ( " layoutManager " ) , dockCorona - > layoutManager ( ) ) ;
2017-03-18 13:21:17 +02:00
}
2016-12-30 16:25:27 -05:00
setSource ( corona ( ) - > kPackage ( ) . filePath ( " lattedockui " ) ) ;
2017-06-20 23:13:38 +03:00
// setVisible(true);
2017-01-12 20:04:27 +02:00
syncGeometry ( ) ;
2017-06-20 23:13:38 +03:00
if ( ! KWindowSystem : : isPlatformWayland ( ) ) {
setVisible ( true ) ;
}
2017-01-12 20:04:27 +02:00
qDebug ( ) < < " SOURCE: " < < source ( ) ;
2016-12-30 16:22:28 -05:00
}
2018-01-21 11:34:18 +02:00
void DockView : : hideWindowsForSlidingOut ( )
2017-12-10 19:54:13 +02:00
{
2018-01-21 11:34:18 +02:00
setBlockHiding ( false ) ;
2017-12-10 19:54:13 +02:00
2018-01-21 11:34:18 +02:00
if ( m_configView ) {
auto configDialog = qobject_cast < DockConfigView * > ( m_configView ) ;
2017-12-10 19:54:13 +02:00
2018-01-21 11:34:18 +02:00
if ( configDialog ) {
configDialog - > hideConfigWindow ( ) ;
2017-12-10 19:54:13 +02:00
}
2018-01-21 11:34:18 +02:00
}
}
void DockView : : initSignalingForLocationChangeSliding ( )
{
//! signals to handle the sliding-in/out during location changes
connect ( this , & DockView : : hideDockDuringLocationChangeStarted , this , [ & ] ( ) {
hideWindowsForSlidingOut ( ) ;
2017-12-10 19:54:13 +02:00
} ) ;
2018-01-04 21:27:55 +02:00
connect ( this , & DockView : : locationChanged , this , [ & ] ( ) {
if ( m_goToLocation ! = Plasma : : Types : : Floating ) {
m_goToLocation = Plasma : : Types : : Floating ;
QTimer : : singleShot ( 100 , [ this ] ( ) {
setBlockAnimations ( false ) ;
emit showDockAfterLocationChangeFinished ( ) ;
showSettingsWindow ( ) ;
} ) ;
}
} ) ;
//! signals to handle the sliding-in/out during screen changes
connect ( this , & DockView : : hideDockDuringScreenChangeStarted , this , [ & ] ( ) {
2018-01-21 11:34:18 +02:00
hideWindowsForSlidingOut ( ) ;
2017-12-10 19:54:13 +02:00
} ) ;
2018-01-04 21:27:55 +02:00
connect ( this , & DockView : : currentScreenChanged , this , [ & ] ( ) {
if ( m_goToScreen ) {
m_goToScreen = nullptr ;
2017-12-10 19:54:13 +02:00
QTimer : : singleShot ( 100 , [ this ] ( ) {
setBlockAnimations ( false ) ;
2018-01-04 21:27:55 +02:00
emit showDockAfterScreenChangeFinished ( ) ;
2017-12-10 19:54:13 +02:00
showSettingsWindow ( ) ;
} ) ;
}
} ) ;
2018-01-21 11:34:18 +02:00
//! signals to handle the sliding-in/out during moving to another layout
connect ( this , & DockView : : hideDockDuringMovingToLayoutStarted , this , [ & ] ( ) {
hideWindowsForSlidingOut ( ) ;
} ) ;
connect ( this , & DockView : : managedLayoutChanged , this , [ & ] ( ) {
if ( ! m_moveToLayout . isEmpty ( ) & & m_managedLayout ) {
m_moveToLayout = " " ;
QTimer : : singleShot ( 100 , [ this ] ( ) {
setBlockAnimations ( false ) ;
emit showDockAfterMovingToLayoutFinished ( ) ;
showSettingsWindow ( ) ;
} ) ;
}
} ) ;
2018-01-04 21:27:55 +02:00
//! ---- both cases ---- !//
//! this is used for both location and screen change cases, this signal
//! is send when the sliding-out animation has finished
connect ( this , & DockView : : hideDockDuringLocationChangeFinished , this , [ & ] ( ) {
setBlockAnimations ( true ) ;
if ( m_goToLocation ! = Plasma : : Types : : Floating ) {
setLocation ( m_goToLocation ) ;
} else if ( m_goToScreen ) {
setScreenToFollow ( m_goToScreen ) ;
2018-01-21 11:34:18 +02:00
} else if ( ! m_moveToLayout . isEmpty ( ) ) {
moveToLayout ( m_moveToLayout ) ;
2018-01-04 21:27:55 +02:00
}
} ) ;
}
2017-12-10 19:54:13 +02:00
2018-01-11 21:11:46 +02:00
void DockView : : disconnectSensitiveSignals ( )
{
disconnect ( corona ( ) , & Plasma : : Corona : : availableScreenRectChanged , this , & DockView : : availableScreenRectChanged ) ;
2018-01-14 09:39:31 +02:00
setManagedLayout ( nullptr ) ;
2018-01-11 21:11:46 +02:00
if ( visibility ( ) ) {
visibility ( ) - > setEnabledDynamicBackground ( false ) ;
}
}
2017-06-21 22:42:09 +03:00
void DockView : : availableScreenRectChanged ( )
{
2017-06-21 23:34:40 +03:00
if ( m_inDelete )
return ;
2017-06-21 22:42:09 +03:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical )
syncGeometry ( ) ;
}
2017-04-25 19:18:49 +03:00
void DockView : : setupWaylandIntegration ( )
{
2017-06-15 16:56:55 -05:00
if ( m_shellSurface )
2017-04-25 19:18:49 +03:00
return ;
if ( DockCorona * c = qobject_cast < DockCorona * > ( corona ( ) ) ) {
2018-03-01 00:52:05 +02:00
using namespace KWayland : : Client ;
2017-06-15 16:56:55 -05:00
PlasmaShell * interface { c - > waylandDockCoronaInterface ( ) } ;
2017-04-25 19:18:49 +03:00
2017-06-15 16:56:55 -05:00
if ( ! interface )
2017-04-25 19:18:49 +03:00
return ;
2017-06-15 16:56:55 -05:00
Surface * s { Surface : : fromWindow ( this ) } ;
2017-04-25 19:18:49 +03:00
2017-06-15 16:56:55 -05:00
if ( ! s )
2017-04-25 19:18:49 +03:00
return ;
m_shellSurface = interface - > createSurface ( s , this ) ;
2018-03-01 01:31:17 +02:00
qDebug ( ) < < " WAYLAND dock window surface was created... " ;
2017-04-26 17:46:04 +03:00
m_shellSurface - > setSkipTaskbar ( true ) ;
2017-06-29 17:00:55 -05:00
m_shellSurface - > setRole ( PlasmaShellSurface : : Role : : Panel ) ;
2017-06-20 16:58:25 -05:00
m_shellSurface - > setPanelBehavior ( PlasmaShellSurface : : PanelBehavior : : WindowsGoBelow ) ;
2017-04-25 19:18:49 +03:00
}
}
2017-02-27 19:46:10 +02:00
bool DockView : : setCurrentScreen ( const QString id )
2017-02-25 15:29:05 +02:00
{
2017-02-27 19:46:10 +02:00
QScreen * nextScreen { qGuiApp - > primaryScreen ( ) } ;
2017-02-25 15:29:05 +02:00
2017-02-27 19:46:10 +02:00
if ( id ! = " primary " ) {
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr & & scr - > name ( ) = = id ) {
nextScreen = scr ;
break ;
}
}
}
2017-02-27 20:27:32 +02:00
if ( m_screenToFollow = = nextScreen ) {
return true ;
}
2017-02-27 19:46:10 +02:00
if ( nextScreen ) {
2018-01-31 20:38:22 +02:00
if ( m_managedLayout ) {
auto freeEdges = m_managedLayout - > freeEdges ( nextScreen ) ;
2017-02-27 19:46:10 +02:00
if ( ! freeEdges . contains ( location ( ) ) ) {
return false ;
} else {
2018-01-04 21:27:55 +02:00
m_goToScreen = nextScreen ;
//! asynchronous call in order to not crash from configwindow
//! deletion from sliding out animation
QTimer : : singleShot ( 100 , [ this ] ( ) {
emit hideDockDuringScreenChangeStarted ( ) ;
} ) ;
2017-02-27 19:46:10 +02:00
}
2017-02-25 15:29:05 +02:00
}
}
2017-02-27 20:27:32 +02:00
return true ;
2017-02-25 15:29:05 +02:00
}
2017-03-02 18:07:29 +02:00
//! this function updates the dock's associated screen.
//! updateScreenId = true, update also the m_screenToFollowId
//! updateScreenId = false, do not update the m_screenToFollowId
//! that way an explicit dock can be shown in another screen when
//! there isnt a tasks dock running in the system and for that
//! dock its first origin screen is stored and that way when
//! that screen is reconnected the dock will return to its original
//! place
2017-03-01 16:59:04 +02:00
void DockView : : setScreenToFollow ( QScreen * screen , bool updateScreenId )
2017-02-25 15:29:05 +02:00
{
if ( ! screen | | m_screenToFollow = = screen ) {
return ;
}
m_screenToFollow = screen ;
2017-03-01 16:59:04 +02:00
if ( updateScreenId ) {
m_screenToFollowId = screen - > name ( ) ;
}
2017-02-25 15:29:05 +02:00
qDebug ( ) < < " adapting to screen... " ;
setScreen ( screen ) ;
2017-02-12 10:02:01 +02:00
if ( this - > containment ( ) )
this - > containment ( ) - > reactToScreenChange ( ) ;
2017-01-16 14:07:49 -05:00
2017-08-01 00:55:49 +03:00
connect ( screen , & QScreen : : geometryChanged , this , & DockView : : screenGeometryChanged ) ;
2017-01-12 20:04:27 +02:00
syncGeometry ( ) ;
2017-04-29 19:42:26 +03:00
updateAbsDockGeometry ( true ) ;
2017-03-09 16:49:51 +02:00
emit screenGeometryChanged ( ) ;
2018-01-04 21:27:55 +02:00
emit currentScreenChanged ( ) ;
2016-12-30 16:22:28 -05:00
}
2017-03-02 18:07:29 +02:00
//! the main function which decides if this dock is at the
//! correct screen
2017-02-26 02:43:41 +02:00
void DockView : : reconsiderScreen ( )
{
qDebug ( ) < < " Delayer " ;
2017-02-27 12:44:51 +02:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
qDebug ( ) < < " D, found screen: " < < scr - > name ( ) ;
2017-02-26 02:43:41 +02:00
}
2017-03-01 16:59:04 +02:00
bool screenExists { false } ;
2017-03-01 21:03:51 +02:00
2017-03-02 18:07:29 +02:00
//!check if the associated screen is running
2017-03-01 21:03:51 +02:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
2017-06-30 11:26:54 +03:00
if ( m_screenToFollowId = = scr - > name ( )
2017-07-03 10:55:52 +03:00
| | ( onPrimary ( ) & & scr = = qGuiApp - > primaryScreen ( ) ) ) {
2017-03-01 16:59:04 +02:00
screenExists = true ;
2017-06-30 11:26:54 +03:00
}
2017-03-01 16:59:04 +02:00
}
2017-02-27 23:06:03 +02:00
2017-03-01 21:03:51 +02:00
qDebug ( ) < < " dock screen exists ::: " < < screenExists ;
2017-03-01 16:59:04 +02:00
2018-01-31 20:17:50 +02:00
int docksWithTasks = m_managedLayout ? m_managedLayout - > noDocksWithTasks ( ) : 0 ;
2017-03-02 18:07:29 +02:00
//! 1.a primary dock must be always on the primary screen
//! 2.the last tasks dock must also always on the primary screen
//! even though it has been configured as an explicit
2018-01-31 20:17:50 +02:00
if ( ( m_onPrimary | | ( tasksPresent ( ) & & docksWithTasks = = 1 & & ! screenExists ) )
2017-06-30 11:26:54 +03:00
& & ( m_screenToFollowId ! = qGuiApp - > primaryScreen ( ) - > name ( )
2017-07-03 10:55:52 +03:00
| | m_screenToFollow ! = qGuiApp - > primaryScreen ( ) ) ) {
2018-01-31 19:34:19 +02:00
using Plasma : : Types ;
QList < Types : : Location > edges { Types : : BottomEdge , Types : : LeftEdge ,
Types : : TopEdge , Types : : RightEdge } ;
edges = m_managedLayout ? m_managedLayout - > freeEdges ( qGuiApp - > primaryScreen ( ) ) : edges ;
2017-02-27 23:06:03 +02:00
//change to primary screen only if the specific edge is free
2017-06-30 11:26:54 +03:00
qDebug ( ) < < " updating the primary screen for dock... " ;
2018-01-31 19:34:19 +02:00
qDebug ( ) < < " available primary screen edges: " < < edges ;
2017-06-30 11:26:54 +03:00
qDebug ( ) < < " dock location: " < < location ( ) ;
2018-01-31 19:34:19 +02:00
if ( edges . contains ( location ( ) ) ) {
2017-03-02 18:07:29 +02:00
//! case 2
2018-01-31 20:17:50 +02:00
if ( ! m_onPrimary & & ! screenExists & & tasksPresent ( ) & & ( docksWithTasks = = 1 ) ) {
2017-06-30 11:26:54 +03:00
qDebug ( ) < < " reached case 2 of updating dock primary screen... " ;
2017-03-01 16:59:04 +02:00
setScreenToFollow ( qGuiApp - > primaryScreen ( ) , false ) ;
} else {
2017-03-02 18:07:29 +02:00
//! case 1
2017-06-30 11:26:54 +03:00
qDebug ( ) < < " reached case 1 of updating dock primary screen... " ;
2017-03-01 16:59:04 +02:00
setScreenToFollow ( qGuiApp - > primaryScreen ( ) ) ;
}
2017-02-27 23:06:03 +02:00
syncGeometry ( ) ;
}
2017-07-03 10:55:52 +03:00
} else if ( ! m_onPrimary ) {
2017-03-02 18:07:29 +02:00
//! 3.an explicit dock must be always on the correct associated screen
//! there are cases that window manager misplaces the dock, this function
//! ensures that this dock will return at its correct screen
2017-02-27 12:44:51 +02:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr & & scr - > name ( ) = = m_screenToFollowId ) {
2017-06-30 11:26:54 +03:00
qDebug ( ) < < " updating the explicit screen for dock... " ;
2017-02-27 00:53:27 +02:00
setScreenToFollow ( scr ) ;
syncGeometry ( ) ;
2017-06-30 11:26:54 +03:00
break ;
2017-02-27 00:53:27 +02:00
}
2017-02-26 02:43:41 +02:00
}
}
emit docksCountChanged ( ) ;
}
2017-02-25 15:29:05 +02:00
void DockView : : screenChanged ( QScreen * scr )
{
2017-02-26 19:15:20 +02:00
m_screenSyncTimer . start ( ) ;
2017-04-29 19:42:26 +03:00
//! this is needed in order to update the struts on screen change
//! and even though the geometry has been set correctly the offsets
//! of the screen must be updated to the new ones
if ( m_visibility & & m_visibility - > mode ( ) = = Latte : : Dock : : AlwaysVisible ) {
updateAbsDockGeometry ( true ) ;
}
2017-02-25 15:29:05 +02:00
}
2016-12-30 16:25:27 -05:00
void DockView : : addNewDock ( )
2016-12-30 16:22:28 -05:00
{
2017-01-16 13:24:46 -05:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
2017-01-16 14:07:49 -05:00
2017-01-16 13:24:46 -05:00
if ( dockCorona ) {
dockCorona - > loadDefaultLayout ( ) ;
2016-12-30 16:22:28 -05:00
}
}
2017-06-05 23:52:49 +03:00
void DockView : : copyDock ( )
{
2018-01-11 20:34:16 +02:00
m_managedLayout - > copyDock ( containment ( ) ) ;
2017-06-05 23:52:49 +03:00
}
2016-12-30 16:25:27 -05:00
void DockView : : removeDock ( )
2016-12-30 16:22:28 -05:00
{
2017-06-20 17:57:58 +03:00
if ( totalDocksCount ( ) > 1 ) {
2017-02-12 10:02:01 +02:00
QAction * removeAct = this - > containment ( ) - > actions ( ) - > action ( QStringLiteral ( " remove " ) ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( removeAct ) {
removeAct - > trigger ( ) ;
}
}
}
2016-12-30 16:25:27 -05:00
QQmlListProperty < QScreen > DockView : : screens ( )
2016-12-30 16:22:28 -05:00
{
return QQmlListProperty < QScreen > ( this , nullptr , & countScreens , & atScreens ) ;
}
2016-12-30 16:25:27 -05:00
int DockView : : countScreens ( QQmlListProperty < QScreen > * property )
2016-12-30 16:22:28 -05:00
{
Q_UNUSED ( property )
return qGuiApp - > screens ( ) . count ( ) ;
}
2016-12-30 16:25:27 -05:00
QScreen * DockView : : atScreens ( QQmlListProperty < QScreen > * property , int index )
2016-12-30 16:22:28 -05:00
{
Q_UNUSED ( property )
return qGuiApp - > screens ( ) . at ( index ) ;
}
2017-02-25 15:29:05 +02:00
QString DockView : : currentScreen ( ) const
{
2017-02-26 02:43:41 +02:00
return m_screenToFollowId ;
2017-02-25 15:29:05 +02:00
}
2018-02-09 19:22:04 +02:00
bool DockView : : settingsWindowIsShown ( )
2018-01-18 21:21:32 +02:00
{
2018-02-09 19:22:04 +02:00
auto configView = qobject_cast < DockConfigView * > ( m_configView ) ;
2018-01-18 21:21:32 +02:00
2018-02-09 19:22:04 +02:00
return ( configView ! = nullptr ) ;
2018-01-18 21:21:32 +02:00
}
2017-11-19 14:51:15 +02:00
void DockView : : showSettingsWindow ( )
{
showConfigurationInterface ( containment ( ) ) ;
2018-02-19 18:10:54 +02:00
applyActivitiesToWindows ( ) ;
2017-11-19 14:51:15 +02:00
}
2016-12-30 16:25:27 -05:00
void DockView : : showConfigurationInterface ( Plasma : : Applet * applet )
2016-12-30 16:22:28 -05:00
{
if ( ! applet | | ! applet - > containment ( ) )
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
Plasma : : Containment * c = qobject_cast < Plasma : : Containment * > ( applet ) ;
2017-01-16 14:07:49 -05:00
2018-02-09 19:22:04 +02:00
if ( m_configView & & c & & c - > isContainment ( ) & & c = = this - > containment ( ) ) {
if ( m_configView - > isVisible ( ) ) {
m_configView - > setVisible ( false ) ;
//m_configView->hide();
2016-12-30 16:22:28 -05:00
} else {
2018-02-09 19:22:04 +02:00
m_configView - > setVisible ( true ) ;
//m_configView->show();
2016-12-30 16:22:28 -05:00
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
return ;
2018-02-09 19:22:04 +02:00
} else if ( m_configView ) {
if ( m_configView - > applet ( ) = = applet ) {
m_configView - > setVisible ( true ) ;
//m_configView->show();
m_configView - > requestActivate ( ) ;
2016-12-30 16:22:28 -05:00
return ;
} else {
2018-02-09 19:22:04 +02:00
m_configView - > setVisible ( false ) ;
//m_configView->hide();
m_configView - > deleteLater ( ) ;
2016-12-30 16:22:28 -05:00
}
}
2017-01-16 14:07:49 -05:00
2017-01-11 16:29:11 +02:00
bool delayConfigView = false ;
2017-01-16 14:07:49 -05:00
2017-02-12 10:02:01 +02:00
if ( c & & containment ( ) & & c - > isContainment ( ) & & c - > id ( ) = = this - > containment ( ) - > id ( ) ) {
2018-02-09 19:22:04 +02:00
m_configView = new DockConfigView ( c , this ) ;
2017-01-11 16:29:11 +02:00
delayConfigView = true ;
2016-12-30 16:22:28 -05:00
} else {
2018-02-09 19:22:04 +02:00
m_configView = new PlasmaQuick : : ConfigView ( applet ) ;
2016-12-30 16:22:28 -05:00
}
2017-01-16 14:07:49 -05:00
2018-02-09 19:22:04 +02:00
m_configView . data ( ) - > init ( ) ;
2017-01-16 14:07:49 -05:00
2017-01-11 16:29:11 +02:00
if ( ! delayConfigView ) {
2018-02-09 19:22:04 +02:00
m_configView - > setVisible ( true ) ;
2017-06-21 17:14:13 +03:00
//m_configView.data()->show();
2017-01-11 16:29:11 +02:00
} else {
2017-01-11 16:33:10 +02:00
//add a timer for showing the configuration window the first time it is
//created in order to give the containmnent's layouts the time to
//calculate the window's height
2017-06-21 17:14:13 +03:00
if ( ! KWindowSystem : : isPlatformWayland ( ) ) {
2018-02-09 19:22:04 +02:00
QTimer : : singleShot ( 150 , m_configView , SLOT ( show ( ) ) ) ;
2017-06-21 17:14:13 +03:00
} else {
2018-02-09 19:22:04 +02:00
QTimer : : singleShot ( 150 , [ this ] ( ) {
m_configView - > setVisible ( true ) ;
2017-06-21 17:14:13 +03:00
} ) ;
}
2017-01-11 16:29:11 +02:00
}
2016-12-30 16:22:28 -05:00
}
2017-03-02 22:10:26 +02:00
//! this is used mainly from vertical panels in order to
//! to get the maximum geometry that can be used from the dock
//! based on their alignment type and the location dock
QRect DockView : : maximumNormalGeometry ( )
{
int xPos = 0 ;
int yPos = 0 ;
int maxHeight = maxLength ( ) * screen ( ) - > geometry ( ) . height ( ) ;
int maxWidth = normalThickness ( ) ;
QRect maxGeometry ;
maxGeometry . setRect ( 0 , 0 , maxWidth , maxHeight ) ;
switch ( location ( ) ) {
case Plasma : : Types : : LeftEdge :
xPos = screen ( ) - > geometry ( ) . x ( ) ;
switch ( alignment ( ) ) {
case Latte : : Dock : : Top :
yPos = screen ( ) - > geometry ( ) . y ( ) ;
break ;
case Latte : : Dock : : Center :
case Latte : : Dock : : Justify :
yPos = qMax ( screen ( ) - > geometry ( ) . center ( ) . y ( ) - maxHeight / 2 , screen ( ) - > geometry ( ) . y ( ) ) ;
break ;
case Latte : : Dock : : Bottom :
yPos = screen ( ) - > geometry ( ) . bottom ( ) - maxHeight + 1 ;
break ;
}
maxGeometry . setRect ( xPos , yPos , maxWidth , maxHeight ) ;
break ;
case Plasma : : Types : : RightEdge :
xPos = screen ( ) - > geometry ( ) . right ( ) - maxWidth + 1 ;
switch ( alignment ( ) ) {
case Latte : : Dock : : Top :
yPos = screen ( ) - > geometry ( ) . y ( ) ;
break ;
case Latte : : Dock : : Center :
case Latte : : Dock : : Justify :
yPos = qMax ( screen ( ) - > geometry ( ) . center ( ) . y ( ) - maxHeight / 2 , screen ( ) - > geometry ( ) . y ( ) ) ;
break ;
case Latte : : Dock : : Bottom :
yPos = screen ( ) - > geometry ( ) . bottom ( ) - maxHeight + 1 ;
break ;
}
maxGeometry . setRect ( xPos , yPos , maxWidth , maxHeight ) ;
break ;
2017-10-21 10:21:40 +03:00
default :
//! bypass clang warnings
break ;
2017-03-02 22:10:26 +02:00
}
2017-03-18 20:08:56 +02:00
//! this is needed in order to preserve that the top dock will be above
//! the others in case flag bypasswindowmanagerhint hasnt be set,
//! such a case is the AlwaysVisible mode
if ( location ( ) = = Plasma : : Types : : TopEdge ) {
KWindowSystem : : setState ( winId ( ) , NET : : KeepAbove ) ;
} else {
KWindowSystem : : clearState ( winId ( ) , NET : : KeepAbove ) ;
}
2017-03-02 22:10:26 +02:00
return maxGeometry ;
}
2017-03-03 17:35:37 +02:00
void DockView : : resizeWindow ( QRect availableScreenRect )
2016-12-30 16:22:28 -05:00
{
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
2017-03-02 22:10:26 +02:00
//qDebug() << "MAXIMUM RECT :: " << maximumRect << " - AVAILABLE RECT :: " << availableRect;
2017-03-03 17:35:37 +02:00
QSize size { maxThickness ( ) , availableScreenRect . height ( ) } ;
2017-01-31 21:25:00 +02:00
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel ) {
2017-01-31 21:25:00 +02:00
size . setWidth ( normalThickness ( ) ) ;
2017-03-03 17:35:37 +02:00
size . setHeight ( static_cast < int > ( maxLength ( ) * availableScreenRect . height ( ) ) ) ;
2017-01-31 21:25:00 +02:00
}
2016-12-30 16:22:28 -05:00
setMinimumSize ( size ) ;
setMaximumSize ( size ) ;
resize ( size ) ;
} else {
2017-02-13 18:53:54 +02:00
QSize screenSize = this - > screen ( ) - > size ( ) ;
2017-01-31 21:25:00 +02:00
QSize size { screenSize . width ( ) , maxThickness ( ) } ;
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel ) {
2017-02-05 20:55:41 -05:00
size . setWidth ( static_cast < int > ( maxLength ( ) * screenSize . width ( ) ) ) ;
2017-01-31 21:25:00 +02:00
size . setHeight ( normalThickness ( ) ) ;
}
2016-12-30 16:22:28 -05:00
setMinimumSize ( size ) ;
setMaximumSize ( size ) ;
resize ( size ) ;
2017-02-10 22:12:17 -05:00
if ( corona ( ) )
emit corona ( ) - > availableScreenRectChanged ( ) ;
2016-12-30 16:22:28 -05:00
}
}
2017-03-09 15:49:24 +02:00
QRect DockView : : localGeometry ( ) const
{
return m_localGeometry ;
}
void DockView : : setLocalGeometry ( const QRect & geometry )
2016-12-30 19:26:48 -05:00
{
2017-03-08 21:00:09 +02:00
if ( m_localGeometry = = geometry ) {
return ;
}
m_localGeometry = geometry ;
2017-03-09 15:49:24 +02:00
emit localGeometryChanged ( ) ;
2017-03-08 21:00:09 +02:00
updateAbsDockGeometry ( ) ;
2016-12-30 19:26:48 -05:00
}
2017-04-29 19:42:26 +03:00
void DockView : : updateAbsDockGeometry ( bool bypassChecks )
2016-12-30 19:26:48 -05:00
{
2017-06-20 17:28:55 +03:00
//! there was a -1 in height and width here. The reason of this
//! if I remember correctly was related to multi-screen but I cant
//! remember exactly the reason, something related to rigth edge in
//! multi screen environment. BUT this was breaking the entire AlwaysVisible
//! experience with struts. Removing them in order to restore correct
//! behavior and keeping this comment in order to check for
//! multi-screen breakage
2017-03-08 21:00:09 +02:00
QRect absGeometry { x ( ) + m_localGeometry . x ( ) , y ( ) + m_localGeometry . y ( )
2017-06-20 17:28:55 +03:00
, m_localGeometry . width ( ) , m_localGeometry . height ( ) } ;
2017-02-10 22:12:17 -05:00
2017-04-29 19:42:26 +03:00
if ( m_absGeometry = = absGeometry & & ! bypassChecks )
2017-01-12 18:55:43 -05:00
return ;
2017-01-16 14:07:49 -05:00
2017-02-10 22:12:17 -05:00
m_absGeometry = absGeometry ;
syncGeometry ( ) ;
emit absGeometryChanged ( m_absGeometry ) ;
2017-12-24 20:54:45 +02:00
//! this is needed in order to update correctly the screenGeometries
if ( visibility ( ) & & corona ( ) & & visibility ( ) - > mode ( ) = = Dock : : AlwaysVisible ) {
emit corona ( ) - > availableScreenRectChanged ( ) ;
emit corona ( ) - > availableScreenRegionChanged ( ) ;
}
2016-12-30 19:26:48 -05:00
}
2017-03-03 17:35:37 +02:00
void DockView : : updatePosition ( QRect availableScreenRect )
2016-12-30 16:22:28 -05:00
{
2017-08-02 12:13:16 +03:00
QRect screenGeometry { availableScreenRect } ;
2016-12-30 16:22:28 -05:00
QPoint position ;
position = { 0 , 0 } ;
2017-04-09 01:59:21 +03:00
2017-02-10 23:55:25 -05:00
const auto length = [ & ] ( int length ) - > int {
2017-04-09 01:59:21 +03:00
float offs = static_cast < float > ( offset ( ) ) ;
return static_cast < int > ( length * ( ( 1 - maxLength ( ) ) / 2 ) + length * ( offs / 100 ) ) ;
2017-02-10 23:55:25 -05:00
} ;
2017-01-31 21:25:00 +02:00
int cleanThickness = normalThickness ( ) - shadow ( ) ;
2016-12-30 16:22:28 -05:00
switch ( location ( ) ) {
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : TopEdge :
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel ) {
2017-02-27 12:44:51 +02:00
position = { screenGeometry . x ( ) + length ( screenGeometry . width ( ) ) , screenGeometry . y ( ) } ;
} else {
position = { screenGeometry . x ( ) , screenGeometry . y ( ) } ;
}
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : BottomEdge :
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel ) {
2017-02-27 12:44:51 +02:00
position = { screenGeometry . x ( ) + length ( screenGeometry . width ( ) ) ,
screenGeometry . y ( ) + screenGeometry . height ( ) - cleanThickness
} ;
} else {
position = { screenGeometry . x ( ) , screenGeometry . y ( ) + screenGeometry . height ( ) - height ( ) } ;
}
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : RightEdge :
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel & & ! mask ( ) . isNull ( ) ) {
2017-03-03 17:35:37 +02:00
position = { availableScreenRect . right ( ) - cleanThickness + 1 ,
availableScreenRect . y ( ) + length ( availableScreenRect . height ( ) )
2017-02-27 12:44:51 +02:00
} ;
} else {
2017-03-03 17:35:37 +02:00
position = { availableScreenRect . right ( ) - width ( ) + 1 , availableScreenRect . y ( ) } ;
2017-02-27 12:44:51 +02:00
}
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : LeftEdge :
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel & & ! mask ( ) . isNull ( ) ) {
2017-03-03 17:35:37 +02:00
position = { availableScreenRect . x ( ) , availableScreenRect . y ( ) + length ( availableScreenRect . height ( ) ) } ;
2017-02-27 12:44:51 +02:00
} else {
2017-03-03 17:35:37 +02:00
position = { availableScreenRect . x ( ) , availableScreenRect . y ( ) } ;
2017-02-27 12:44:51 +02:00
}
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
default :
qWarning ( ) < < " wrong location, couldn't update the panel position "
< < location ( ) ;
2016-12-30 16:22:28 -05:00
}
2017-01-16 14:07:49 -05:00
2017-01-12 18:55:43 -05:00
setPosition ( position ) ;
2017-04-25 19:18:49 +03:00
if ( m_shellSurface ) {
m_shellSurface - > setPosition ( position ) ;
}
2016-12-30 16:22:28 -05:00
}
2017-01-12 20:04:27 +02:00
inline void DockView : : syncGeometry ( )
{
2017-02-13 18:53:54 +02:00
if ( ! ( this - > screen ( ) & & this - > containment ( ) ) )
2017-02-10 22:12:17 -05:00
return ;
2017-02-26 02:43:41 +02:00
bool found { false } ;
2017-02-27 12:44:51 +02:00
2017-03-02 18:07:29 +02:00
//! before updating the positioning and geometry of the dock
//! we make sure that the dock is at the correct screen
2017-02-26 02:43:41 +02:00
if ( this - > screen ( ) ! = m_screenToFollow ) {
2018-03-07 10:29:19 -07:00
qDebug ( ) < < " Sync Geometry screens inconsistent!!!! " ;
2017-02-26 19:15:20 +02:00
m_screenSyncTimer . start ( ) ;
2017-02-26 02:43:41 +02:00
} else {
found = true ;
2017-02-24 21:24:12 +02:00
}
2017-03-02 18:07:29 +02:00
//! if the dock isnt at the correct screen the calculations
//! are not executed
2017-02-26 02:43:41 +02:00
if ( found ) {
2017-03-03 17:35:37 +02:00
//! compute the free screen rectangle for vertical panels only once
//! this way the costly QRegion computations are calculated only once
//! instead of two times (both inside the resizeWindow and the updatePosition)
QRegion freeRegion ; ;
QRect maximumRect ;
2017-08-02 12:13:16 +03:00
QRect availableScreenRect { this - > screen ( ) - > geometry ( ) } ;
2017-03-03 17:35:37 +02:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
2018-01-13 21:10:58 +02:00
QString layoutName = m_managedLayout ? m_managedLayout - > name ( ) : QString ( ) ;
auto dockCorona = qobject_cast < DockCorona * > ( corona ( ) ) ;
2018-01-31 19:34:19 +02:00
int fixedScreen = onPrimary ( ) ? dockCorona - > screenPool ( ) - > primaryScreenId ( ) : this - > containment ( ) - > screen ( ) ;
freeRegion = dockCorona - > availableScreenRegionWithCriteria ( fixedScreen , layoutName ) ;
2017-03-03 17:35:37 +02:00
maximumRect = maximumNormalGeometry ( ) ;
2017-03-07 18:29:37 +02:00
QRegion availableRegion = freeRegion . intersected ( maximumRect ) ;
2017-03-03 17:35:37 +02:00
availableScreenRect = freeRegion . intersected ( maximumRect ) . boundingRect ( ) ;
2017-03-07 18:29:37 +02:00
float area = 0 ;
//! it is used to choose which or the availableRegion rectangles will
//! be the one representing dock geometry
for ( int i = 0 ; i < availableRegion . rectCount ( ) ; + + i ) {
QRect rect = availableRegion . rects ( ) . at ( i ) ;
//! the area of each rectangle in calculated in squares of 50x50
//! this is a way to avoid enourmous numbers for area value
float tempArea = ( float ) ( rect . width ( ) * rect . height ( ) ) / 2500 ;
if ( tempArea > area ) {
availableScreenRect = rect ;
area = tempArea ;
}
}
2017-05-07 15:06:29 +03:00
if ( availableRegion . rectCount ( ) > 1 & & m_behaveAsPlasmaPanel )
2017-03-07 18:29:37 +02:00
m_forceDrawCenteredBorders = true ;
else
m_forceDrawCenteredBorders = false ;
} else {
m_forceDrawCenteredBorders = false ;
2017-03-03 17:35:37 +02:00
}
2017-02-26 02:43:41 +02:00
updateEnabledBorders ( ) ;
2017-03-03 17:35:37 +02:00
resizeWindow ( availableScreenRect ) ;
updatePosition ( availableScreenRect ) ;
2017-02-26 02:43:41 +02:00
}
2017-02-27 12:44:51 +02:00
2017-01-28 19:34:03 +02:00
// qDebug() << "dock geometry:" << qRectToStr(geometry());
2017-01-12 20:04:27 +02:00
}
2017-01-14 01:59:25 +02:00
void DockView : : statusChanged ( Plasma : : Types : : ItemStatus status )
{
2017-02-18 10:28:40 +02:00
if ( containment ( ) ) {
if ( containment ( ) - > status ( ) > = Plasma : : Types : : NeedsAttentionStatus & &
2017-02-27 12:44:51 +02:00
containment ( ) - > status ( ) ! = Plasma : : Types : : HiddenStatus ) {
2017-08-09 03:41:45 +03:00
setBlockHiding ( true ) ;
2017-02-18 10:28:40 +02:00
} else {
2017-08-09 03:41:45 +03:00
setBlockHiding ( false ) ;
2017-02-18 10:28:40 +02:00
}
2017-01-14 01:59:25 +02:00
}
}
2017-08-09 03:33:03 +03:00
bool DockView : : alternativesIsShown ( ) const
{
return m_alternativesIsShown ;
}
void DockView : : setAlternativesIsShown ( bool show )
{
if ( m_alternativesIsShown = = show ) {
return ;
}
m_alternativesIsShown = show ;
setBlockHiding ( show ) ;
emit alternativesIsShownChanged ( ) ;
}
2017-07-27 18:24:31 +03:00
bool DockView : : contextMenuIsShown ( ) const
{
2018-02-03 15:00:44 +02:00
if ( ! m_menuManager ) {
return false ;
}
return m_menuManager - > contextMenu ( ) ;
2017-07-27 18:24:31 +03:00
}
2016-12-30 16:25:27 -05:00
int DockView : : currentThickness ( ) const
2016-12-30 16:22:28 -05:00
{
2017-01-12 18:55:43 -05:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
2017-01-13 16:51:56 +02:00
return m_maskArea . isNull ( ) ? width ( ) : m_maskArea . width ( ) - m_shadow ;
2016-12-30 16:22:28 -05:00
} else {
2017-01-13 16:51:56 +02:00
return m_maskArea . isNull ( ) ? height ( ) : m_maskArea . height ( ) - m_shadow ;
2016-12-30 16:22:28 -05:00
}
}
2017-01-27 20:31:41 +02:00
int DockView : : normalThickness ( ) const
{
return m_normalThickness ;
}
void DockView : : setNormalThickness ( int thickness )
{
if ( m_normalThickness = = thickness ) {
return ;
}
m_normalThickness = thickness ;
emit normalThicknessChanged ( ) ;
}
2017-01-05 00:28:25 +02:00
int DockView : : docksCount ( ) const
{
2018-01-31 20:45:55 +02:00
if ( ! m_managedLayout ) {
2017-06-12 00:40:45 +03:00
return 0 ;
2018-01-31 20:45:55 +02:00
}
2017-06-12 00:40:45 +03:00
2018-01-31 20:45:55 +02:00
return m_managedLayout - > docksCount ( screen ( ) ) ;
2017-06-12 00:40:45 +03:00
}
int DockView : : totalDocksCount ( ) const
{
2018-01-31 20:45:55 +02:00
if ( ! m_managedLayout ) {
2017-01-15 23:59:15 +02:00
return 0 ;
2018-01-31 20:45:55 +02:00
}
2017-01-16 14:07:49 -05:00
2018-01-31 20:45:55 +02:00
return m_managedLayout - > docksCount ( ) ;
2017-03-03 17:23:37 +02:00
}
int DockView : : docksWithTasks ( )
{
2018-01-31 20:28:42 +02:00
if ( ! m_managedLayout )
2017-03-03 17:23:37 +02:00
return 0 ;
2018-01-31 20:17:50 +02:00
return m_managedLayout - > noDocksWithTasks ( ) ;
2017-01-05 00:28:25 +02:00
}
2017-01-12 18:55:43 -05:00
void DockView : : updateFormFactor ( )
2016-12-30 16:22:28 -05:00
{
2017-02-12 10:02:01 +02:00
if ( ! this - > containment ( ) )
2017-01-12 18:55:43 -05:00
return ;
2017-01-16 14:07:49 -05:00
2017-01-12 18:55:43 -05:00
switch ( location ( ) ) {
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : TopEdge :
case Plasma : : Types : : BottomEdge :
this - > containment ( ) - > setFormFactor ( Plasma : : Types : : Horizontal ) ;
break ;
case Plasma : : Types : : LeftEdge :
case Plasma : : Types : : RightEdge :
this - > containment ( ) - > setFormFactor ( Plasma : : Types : : Vertical ) ;
break ;
default :
qWarning ( ) < < " wrong location, couldn't update the panel position " < < location ( ) ;
2017-01-12 18:55:43 -05:00
}
}
2016-12-30 16:22:28 -05:00
2017-03-18 23:32:27 +02:00
bool DockView : : dockWinBehavior ( ) const
{
return m_dockWinBehavior ;
}
void DockView : : setDockWinBehavior ( bool dock )
{
if ( m_dockWinBehavior = = dock ) {
return ;
}
m_dockWinBehavior = dock ;
emit dockWinBehaviorChanged ( ) ;
}
2017-05-07 15:06:29 +03:00
bool DockView : : behaveAsPlasmaPanel ( ) const
2017-01-31 21:25:00 +02:00
{
2017-05-07 15:06:29 +03:00
return m_behaveAsPlasmaPanel ;
2017-01-31 21:25:00 +02:00
}
2017-05-07 15:06:29 +03:00
void DockView : : setBehaveAsPlasmaPanel ( bool behavior )
2017-01-31 21:25:00 +02:00
{
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel = = behavior ) {
2017-01-31 21:25:00 +02:00
return ;
}
2017-05-07 15:06:29 +03:00
m_behaveAsPlasmaPanel = behavior ;
2017-01-31 21:25:00 +02:00
2017-05-07 15:18:14 +03:00
if ( m_behaveAsPlasmaPanel & & m_drawShadows ) {
2017-01-31 21:25:00 +02:00
PanelShadows : : self ( ) - > addWindow ( this , enabledBorders ( ) ) ;
} else {
PanelShadows : : self ( ) - > removeWindow ( this ) ;
2017-05-18 01:23:15 +03:00
// m_enabledBorders = Plasma::FrameSvg::AllBorders;
// emit enabledBordersChanged();
2017-01-31 21:25:00 +02:00
}
2017-03-17 16:58:57 +02:00
updateEffects ( ) ;
2017-05-07 15:06:29 +03:00
emit behaveAsPlasmaPanelChanged ( ) ;
}
bool DockView : : drawShadows ( ) const
{
return m_drawShadows ;
}
void DockView : : setDrawShadows ( bool draw )
{
if ( m_drawShadows = = draw ) {
return ;
}
m_drawShadows = draw ;
2017-05-07 15:18:14 +03:00
if ( m_behaveAsPlasmaPanel & & m_drawShadows ) {
PanelShadows : : self ( ) - > addWindow ( this , enabledBorders ( ) ) ;
} else {
PanelShadows : : self ( ) - > removeWindow ( this ) ;
2017-05-18 01:23:15 +03:00
//m_enabledBorders = Plasma::FrameSvg::AllBorders;
//emit enabledBordersChanged();
2017-05-07 15:18:14 +03:00
}
2017-01-31 21:25:00 +02:00
emit drawShadowsChanged ( ) ;
}
2017-03-17 16:58:57 +02:00
bool DockView : : drawEffects ( ) const
{
2017-03-17 23:59:50 +02:00
return m_drawEffects ;
2017-03-17 16:58:57 +02:00
}
void DockView : : setDrawEffects ( bool draw )
{
if ( m_drawEffects = = draw ) {
return ;
}
m_drawEffects = draw ;
emit drawEffectsChanged ( ) ;
}
2018-02-12 16:11:33 +02:00
bool DockView : : inEditMode ( ) const
{
return m_inEditMode ;
}
void DockView : : setInEditMode ( bool edit )
{
if ( m_inEditMode = = edit ) {
return ;
}
m_inEditMode = edit ;
emit inEditModeChanged ( ) ;
}
2017-02-27 00:53:27 +02:00
bool DockView : : onPrimary ( ) const
{
return m_onPrimary ;
}
void DockView : : setOnPrimary ( bool flag )
{
2017-02-27 12:44:51 +02:00
if ( m_onPrimary = = flag ) {
2017-02-27 00:53:27 +02:00
return ;
}
m_onPrimary = flag ;
emit onPrimaryChanged ( ) ;
}
2017-01-31 21:25:00 +02:00
float DockView : : maxLength ( ) const
{
return m_maxLength ;
}
void DockView : : setMaxLength ( float length )
{
if ( m_maxLength = = length ) {
return ;
}
m_maxLength = length ;
emit maxLengthChanged ( ) ;
}
2016-12-30 16:25:27 -05:00
int DockView : : maxThickness ( ) const
2016-12-30 16:22:28 -05:00
{
return m_maxThickness ;
}
2016-12-30 16:25:27 -05:00
void DockView : : setMaxThickness ( int thickness )
2016-12-30 16:22:28 -05:00
{
if ( m_maxThickness = = thickness )
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_maxThickness = thickness ;
2017-01-12 20:04:27 +02:00
syncGeometry ( ) ;
2016-12-30 16:22:28 -05:00
emit maxThicknessChanged ( ) ;
}
2017-02-04 16:41:12 +02:00
int DockView : : alignment ( ) const
{
2017-02-10 22:12:17 -05:00
return m_alignment ;
2017-02-04 16:41:12 +02:00
}
void DockView : : setAlignment ( int alignment )
{
2017-02-10 22:12:17 -05:00
Dock : : Alignment align = static_cast < Dock : : Alignment > ( alignment ) ;
2017-02-04 16:41:12 +02:00
2017-02-10 22:12:17 -05:00
if ( m_alignment = = alignment ) {
2017-02-04 16:41:12 +02:00
return ;
}
m_alignment = align ;
emit alignmentChanged ( ) ;
}
2017-12-10 19:54:13 +02:00
bool DockView : : blockAnimations ( ) const
{
return m_blockAnimations ;
}
void DockView : : setBlockAnimations ( bool block )
{
if ( m_blockAnimations = = block ) {
return ;
}
m_blockAnimations = block ;
emit blockAnimationsChanged ( ) ;
}
2018-03-06 22:54:37 +02:00
bool DockView : : colorizerSupport ( ) const
{
return m_colorizerSupport ;
}
void DockView : : setColorizerSupport ( bool support )
{
if ( m_colorizerSupport = = support ) {
return ;
}
m_colorizerSupport = support ;
emit colorizerSupportChanged ( ) ;
}
2016-12-30 16:25:27 -05:00
QRect DockView : : maskArea ( ) const
2016-12-30 16:22:28 -05:00
{
return m_maskArea ;
}
2016-12-30 16:25:27 -05:00
void DockView : : setMaskArea ( QRect area )
2016-12-30 16:22:28 -05:00
{
2017-01-12 18:55:43 -05:00
if ( m_maskArea = = area )
2016-12-30 16:22:28 -05:00
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_maskArea = area ;
2017-03-12 20:18:18 +02:00
if ( KWindowSystem : : compositingActive ( ) ) {
2017-06-04 19:06:45 +03:00
if ( m_behaveAsPlasmaPanel ) {
setMask ( QRect ( ) ) ;
} else {
setMask ( m_maskArea ) ;
}
2017-03-12 20:18:18 +02:00
} else {
//! this is used when compositing is disabled and provides
//! the correct way for the mask to be painted in order for
//! rounded corners to be shown correctly
2017-12-11 15:21:25 +02:00
//! the enabledBorders check was added because there was cases
//! that the mask region wasnt calculated correctly after location changes
if ( ! m_background | | m_background - > enabledBorders ( ) ! = enabledBorders ( ) ) {
2017-03-12 20:18:18 +02:00
m_background = new Plasma : : FrameSvg ( this ) ;
2017-03-17 16:58:57 +02:00
}
if ( m_background - > imagePath ( ) ! = " opaque/dialogs/background " ) {
2017-03-12 20:18:18 +02:00
m_background - > setImagePath ( QStringLiteral ( " opaque/dialogs/background " ) ) ;
}
m_background - > setEnabledBorders ( enabledBorders ( ) ) ;
m_background - > resizeFrame ( area . size ( ) ) ;
QRegion fixedMask = m_background - > mask ( ) ;
2017-03-21 20:58:01 +02:00
fixedMask . translate ( m_maskArea . x ( ) , m_maskArea . y ( ) ) ;
//! fix for KF5.32 that return empty QRegion's for the mask
if ( fixedMask . isEmpty ( ) ) {
fixedMask = QRegion ( m_maskArea ) ;
}
2017-03-12 20:18:18 +02:00
setMask ( fixedMask ) ;
}
2018-01-14 09:39:31 +02:00
// qDebug() << "dock mask set:" << m_maskArea;
2016-12-30 16:22:28 -05:00
emit maskAreaChanged ( ) ;
}
2017-03-17 16:58:57 +02:00
QRect DockView : : effectsArea ( ) const
{
return m_effectsArea ;
}
void DockView : : setEffectsArea ( QRect area )
{
if ( m_effectsArea = = area ) {
return ;
}
m_effectsArea = area ;
emit effectsAreaChanged ( ) ;
}
2017-02-10 22:12:17 -05:00
QRect DockView : : absGeometry ( ) const
{
return m_absGeometry ;
}
2017-02-26 15:49:50 +02:00
QRect DockView : : screenGeometry ( ) const
{
if ( this - > screen ( ) ) {
QRect geom = this - > screen ( ) - > geometry ( ) ;
return geom ;
}
return QRect ( ) ;
}
2017-04-09 01:06:48 +03:00
int DockView : : offset ( ) const
{
return m_offset ;
}
void DockView : : setOffset ( int offset )
{
if ( m_offset = = offset ) {
return ;
}
m_offset = offset ;
emit offsetChanged ( ) ;
}
2017-06-19 00:30:07 +03:00
int DockView : : dockTransparency ( ) const
{
return m_dockTransparency ;
}
void DockView : : setDockTransparency ( int transparency )
{
if ( m_dockTransparency = = transparency ) {
return ;
}
m_dockTransparency = transparency ;
emit dockTransparencyChanged ( ) ;
}
2017-01-13 16:51:56 +02:00
int DockView : : shadow ( ) const
{
return m_shadow ;
}
void DockView : : setShadow ( int shadow )
{
2017-01-16 13:24:46 -05:00
if ( m_shadow = = shadow )
2017-01-13 16:51:56 +02:00
return ;
2017-01-16 14:07:49 -05:00
2017-01-13 16:51:56 +02:00
m_shadow = shadow ;
2017-01-31 21:25:00 +02:00
2017-05-07 15:06:29 +03:00
if ( m_behaveAsPlasmaPanel ) {
2017-01-31 21:25:00 +02:00
syncGeometry ( ) ;
}
2017-01-13 16:51:56 +02:00
emit shadowChanged ( ) ;
}
2018-02-17 19:02:06 +02:00
int DockView : : fontPixelSize ( ) const
{
return m_fontPixelSize ;
}
void DockView : : setFontPixelSize ( int size )
{
if ( m_fontPixelSize = = size ) {
return ;
}
m_fontPixelSize = size ;
emit fontPixelSizeChanged ( ) ;
}
2018-01-21 11:53:15 +02:00
void DockView : : applyActivitiesToWindows ( )
{
if ( m_visibility ) {
QStringList activities = m_managedLayout - > appliedActivities ( ) ;
m_visibility - > setWindowOnActivities ( * this , activities ) ;
if ( m_configView ) {
m_visibility - > setWindowOnActivities ( * m_configView , activities ) ;
2018-02-09 19:22:04 +02:00
auto configView = qobject_cast < DockConfigView * > ( m_configView ) ;
if ( configView & & configView - > secondaryWindow ( ) ) {
m_visibility - > setWindowOnActivities ( * configView - > secondaryWindow ( ) , activities ) ;
}
2018-01-21 11:53:15 +02:00
}
}
}
2018-01-10 22:55:19 +02:00
Layout * DockView : : managedLayout ( ) const
{
return m_managedLayout ;
}
void DockView : : setManagedLayout ( Layout * layout )
{
if ( m_managedLayout = = layout ) {
return ;
}
2018-01-20 00:34:55 +02:00
// clear mode
for ( auto & c : connectionsManagedLayout ) {
disconnect ( c ) ;
}
2018-01-10 22:55:19 +02:00
m_managedLayout = layout ;
2018-01-13 12:55:13 +02:00
2018-01-14 09:39:31 +02:00
if ( m_managedLayout ) {
2018-01-14 17:30:29 +02:00
//! Sometimes the activity isnt completely ready, by adding a delay
//! we try to catch up
QTimer : : singleShot ( 100 , [ this ] ( ) {
if ( m_managedLayout ) {
qDebug ( ) < < " DOCK VIEW FROM LAYOUT ::: " < < m_managedLayout - > name ( ) < < " - activities: " < < m_managedLayout - > appliedActivities ( ) ;
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-14 17:30:29 +02:00
emit activitiesChanged ( ) ;
}
} ) ;
2018-01-14 09:39:31 +02:00
}
DockCorona * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
if ( dockCorona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
2018-01-20 00:34:55 +02:00
connectionsManagedLayout [ 0 ] = connect ( dockCorona - > activitiesConsumer ( ) , & KActivities : : Consumer : : runningActivitiesChanged , this , [ & ] ( ) {
2018-01-14 09:39:31 +02:00
if ( m_managedLayout ) {
2018-01-14 17:30:29 +02:00
qDebug ( ) < < " DOCK VIEW FROM LAYOUT (runningActivitiesChanged) ::: " < < m_managedLayout - > name ( )
< < " - activities: " < < m_managedLayout - > appliedActivities ( ) ;
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-14 13:21:11 +02:00
emit activitiesChanged ( ) ;
2018-01-14 09:39:31 +02:00
}
} ) ;
2018-01-20 00:34:55 +02:00
connectionsManagedLayout [ 1 ] = connect ( m_managedLayout , & Layout : : activitiesChanged , this , [ & ] ( ) {
2018-01-14 13:21:11 +02:00
if ( m_managedLayout ) {
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-14 13:21:11 +02:00
emit activitiesChanged ( ) ;
}
} ) ;
2018-01-14 12:22:45 +02:00
2018-01-20 00:34:55 +02:00
connectionsManagedLayout [ 2 ] = connect ( dockCorona - > layoutManager ( ) , & LayoutManager : : layoutsChanged , this , [ & ] ( ) {
2018-01-15 19:44:00 +02:00
if ( m_managedLayout ) {
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-15 19:44:00 +02:00
emit activitiesChanged ( ) ;
}
} ) ;
2018-01-14 09:39:31 +02:00
//!IMPORTANT!!! ::: This fixes a bug when closing an Activity all docks from all Activities are
//! disappearing! With this they reappear!!!
2018-01-20 00:34:55 +02:00
connectionsManagedLayout [ 3 ] = connect ( this , & QWindow : : visibleChanged , this , [ & ] ( ) {
2018-01-14 09:39:31 +02:00
if ( ! isVisible ( ) & & m_managedLayout ) {
2018-01-14 17:30:29 +02:00
QTimer : : singleShot ( 100 , [ this ] ( ) {
2018-01-15 00:34:44 +02:00
if ( m_managedLayout & & containment ( ) & & ! containment ( ) - > destroyed ( ) ) {
2018-01-14 12:22:45 +02:00
setVisible ( true ) ;
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-15 00:34:44 +02:00
emit activitiesChanged ( ) ;
2018-01-14 09:39:31 +02:00
}
} ) ;
2018-01-14 17:30:29 +02:00
QTimer : : singleShot ( 1500 , [ this ] ( ) {
2018-01-15 00:34:44 +02:00
if ( m_managedLayout & & containment ( ) & & ! containment ( ) - > destroyed ( ) ) {
2018-01-14 17:30:29 +02:00
setVisible ( true ) ;
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-15 00:34:44 +02:00
emit activitiesChanged ( ) ;
2018-01-14 17:30:29 +02:00
}
} ) ;
2018-01-14 09:39:31 +02:00
}
} ) ;
}
2018-01-13 12:55:13 +02:00
2018-01-10 22:55:19 +02:00
emit managedLayoutChanged ( ) ;
}
2018-01-21 11:34:18 +02:00
void DockView : : moveToLayout ( QString layoutName )
{
if ( ! m_managedLayout ) {
return ;
}
QList < Plasma : : Containment * > containments = m_managedLayout - > unassignFromLayout ( this ) ;
DockCorona * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
if ( dockCorona & & containments . size ( ) > 0 ) {
Layout * newLayout = dockCorona - > layoutManager ( ) - > activeLayout ( layoutName ) ;
if ( newLayout ) {
newLayout - > assignToLayout ( this , containments ) ;
}
}
}
2018-02-12 20:19:46 +02:00
bool DockView : : inLocationChangeAnimation ( )
{
return ( ( m_goToLocation ! = Plasma : : Types : : Floating ) | | ( m_moveToLayout ! = " " ) | | m_goToScreen ) ;
}
2017-12-10 19:54:13 +02:00
void DockView : : hideDockDuringLocationChange ( int goToLocation )
{
m_goToLocation = static_cast < Plasma : : Types : : Location > ( goToLocation ) ;
2018-01-04 19:06:05 +02:00
emit hideDockDuringLocationChangeStarted ( ) ;
2017-12-10 19:54:13 +02:00
}
2018-01-21 11:34:18 +02:00
void DockView : : hideDockDuringMovingToLayout ( QString layoutName )
{
m_moveToLayout = layoutName ;
emit hideDockDuringMovingToLayoutStarted ( ) ;
}
2017-12-10 19:54:13 +02:00
2017-08-09 03:33:03 +03:00
void DockView : : setBlockHiding ( bool block )
{
if ( ! block ) {
auto * configView = qobject_cast < DockConfigView * > ( m_configView ) ;
2017-08-09 14:48:54 +03:00
if ( m_alternativesIsShown | | ( configView & & configView - > sticker ( ) & & configView - > isVisible ( ) ) ) {
2017-08-09 03:33:03 +03:00
return ;
}
2017-08-09 04:52:42 +03:00
if ( m_visibility ) {
m_visibility - > setBlockHiding ( false ) ;
}
2017-08-09 03:33:03 +03:00
} else {
2017-08-09 04:52:42 +03:00
if ( m_visibility ) {
m_visibility - > setBlockHiding ( true ) ;
}
2017-08-09 03:33:03 +03:00
}
}
2017-03-17 16:58:57 +02:00
void DockView : : updateEffects ( )
2017-03-04 12:49:48 +02:00
{
2018-02-27 00:23:08 +02:00
//! CRASH: Dont update effects under wayland
//! because they arent supported yet
if ( KWindowSystem : : isPlatformWayland ( ) ) {
return ;
}
2017-05-07 15:06:29 +03:00
if ( ! m_behaveAsPlasmaPanel ) {
2017-03-17 16:58:57 +02:00
if ( m_drawEffects & & ! m_effectsArea . isNull ( ) & & ! m_effectsArea . isEmpty ( ) ) {
//! this is used when compositing is disabled and provides
//! the correct way for the mask to be painted in order for
//! rounded corners to be shown correctly
if ( ! m_background ) {
m_background = new Plasma : : FrameSvg ( this ) ;
}
if ( m_background - > imagePath ( ) ! = " widgets/panel-background " ) {
m_background - > setImagePath ( QStringLiteral ( " widgets/panel-background " ) ) ;
}
m_background - > setEnabledBorders ( enabledBorders ( ) ) ;
m_background - > resizeFrame ( m_effectsArea . size ( ) ) ;
QRegion fixedMask = m_background - > mask ( ) ;
fixedMask . translate ( m_effectsArea . x ( ) , m_effectsArea . y ( ) ) ;
2017-03-21 20:58:01 +02:00
//! fix for KF5.32 that return empty QRegion's for the mask
if ( fixedMask . isEmpty ( ) ) {
fixedMask = QRegion ( m_effectsArea ) ;
}
2017-03-17 16:58:57 +02:00
KWindowEffects : : enableBlurBehind ( winId ( ) , true , fixedMask ) ;
2017-06-18 13:29:40 +03:00
2017-06-19 00:30:07 +03:00
bool drawBackgroundEffect = m_theme . backgroundContrastEnabled ( ) & & ( m_dockTransparency = = 100 ) ;
2017-06-18 13:29:40 +03:00
//based on Breeze Dark theme behavior the enableBackgroundContrast even though it does accept
//a QRegion it uses only the first rect. The bug was that for Breeze Dark there was a line
//at the dock bottom that was distinguishing it from other themes
2017-06-19 00:30:07 +03:00
KWindowEffects : : enableBackgroundContrast ( winId ( ) , drawBackgroundEffect ,
2017-03-17 16:58:57 +02:00
m_theme . backgroundContrast ( ) ,
m_theme . backgroundIntensity ( ) ,
m_theme . backgroundSaturation ( ) ,
2017-06-18 13:29:40 +03:00
fixedMask . boundingRect ( ) ) ;
2017-03-17 16:58:57 +02:00
} else {
KWindowEffects : : enableBlurBehind ( winId ( ) , false ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , false ) ;
}
2017-05-07 15:06:29 +03:00
} else if ( m_behaveAsPlasmaPanel & & m_drawEffects ) {
2017-03-04 12:49:48 +02:00
KWindowEffects : : enableBlurBehind ( winId ( ) , true ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , m_theme . backgroundContrastEnabled ( ) ,
m_theme . backgroundContrast ( ) ,
m_theme . backgroundIntensity ( ) ,
m_theme . backgroundSaturation ( ) ) ;
2017-03-17 16:58:57 +02:00
} else {
KWindowEffects : : enableBlurBehind ( winId ( ) , false ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , false ) ;
2017-03-04 12:49:48 +02:00
}
}
2017-04-11 12:10:54 +03:00
//! remove latte tasks plasmoid
void DockView : : removeTasksPlasmoid ( )
{
if ( ! tasksPresent ( ) | | ! containment ( ) ) {
return ;
}
foreach ( Plasma : : Applet * applet , containment ( ) - > applets ( ) ) {
KPluginMetaData meta = applet - > kPackage ( ) . metadata ( ) ;
if ( meta . pluginId ( ) = = " org.kde.latte.plasmoid " ) {
QAction * closeApplet = applet - > actions ( ) - > action ( QStringLiteral ( " remove " ) ) ;
if ( closeApplet ) {
closeApplet - > trigger ( ) ;
//! remove only the first found
return ;
}
}
}
}
2017-03-02 18:07:29 +02:00
//! check if the tasks plasmoid exist in the dock
2017-01-02 22:26:10 +02:00
bool DockView : : tasksPresent ( )
{
2017-03-05 16:30:50 +02:00
if ( ! this - > containment ( ) ) {
return false ;
}
2017-02-12 10:02:01 +02:00
foreach ( Plasma : : Applet * applet , this - > containment ( ) - > applets ( ) ) {
2017-07-28 17:04:09 +03:00
const auto & provides = KPluginMetaData : : readStringList ( applet - > pluginMetaData ( ) . rawData ( ) , QStringLiteral ( " X-Plasma-Provides " ) ) ;
2017-01-16 14:07:49 -05:00
2017-07-28 17:04:09 +03:00
if ( provides . contains ( QLatin1String ( " org.kde.plasma.multitasking " ) ) ) {
2017-01-02 22:26:10 +02:00
return true ;
2017-07-28 17:04:09 +03:00
}
2017-01-02 22:26:10 +02:00
}
2017-01-16 14:07:49 -05:00
2017-01-02 22:26:10 +02:00
return false ;
}
2017-07-28 17:08:55 +03:00
//! check if the tasks plasmoid exist in the dock
bool DockView : : latteTasksPresent ( )
{
if ( ! this - > containment ( ) ) {
return false ;
}
foreach ( Plasma : : Applet * applet , this - > containment ( ) - > applets ( ) ) {
KPluginMetaData metadata = applet - > pluginMetaData ( ) ;
if ( metadata . pluginId ( ) = = " org.kde.latte.plasmoid " ) {
return true ;
}
}
return false ;
}
2017-06-11 18:06:03 +03:00
//!check if the plasmoid with _name_ exists in the midedata
bool DockView : : mimeContainsPlasmoid ( QMimeData * mimeData , QString name )
{
if ( ! mimeData ) {
return false ;
}
if ( mimeData - > hasFormat ( QStringLiteral ( " text/x-plasmoidservicename " ) ) ) {
QString data = mimeData - > data ( QStringLiteral ( " text/x-plasmoidservicename " ) ) ;
const QStringList appletNames = data . split ( ' \n ' , QString : : SkipEmptyParts ) ;
foreach ( const QString & appletName , appletNames ) {
if ( appletName = = name )
return true ;
}
}
return false ;
}
2017-02-12 01:59:09 +02:00
VisibilityManager * DockView : : visibility ( ) const
2016-12-30 16:22:28 -05:00
{
return m_visibility ;
}
2016-12-30 16:25:27 -05:00
bool DockView : : event ( QEvent * e )
2016-12-30 16:22:28 -05:00
{
2017-06-21 23:34:40 +03:00
if ( ! m_inDelete ) {
emit eventTriggered ( e ) ;
2017-01-31 21:25:00 +02:00
2017-06-21 23:34:40 +03:00
switch ( e - > type ( ) ) {
2018-01-28 12:49:35 +02:00
case QEvent : : Leave :
engine ( ) - > trimComponentCache ( ) ;
break ;
2017-06-21 23:34:40 +03:00
case QEvent : : PlatformSurface :
if ( auto pe = dynamic_cast < QPlatformSurfaceEvent * > ( e ) ) {
switch ( pe - > surfaceEventType ( ) ) {
case QPlatformSurfaceEvent : : SurfaceCreated :
setupWaylandIntegration ( ) ;
2017-04-25 19:18:49 +03:00
2017-06-21 23:34:40 +03:00
if ( m_shellSurface ) {
syncGeometry ( ) ;
2017-04-25 19:18:49 +03:00
2017-06-21 23:34:40 +03:00
if ( m_drawShadows ) {
PanelShadows : : self ( ) - > addWindow ( this , enabledBorders ( ) ) ;
}
2017-04-25 19:18:49 +03:00
}
2017-06-21 23:34:40 +03:00
break ;
2017-04-25 19:18:49 +03:00
2017-06-21 23:34:40 +03:00
case QPlatformSurfaceEvent : : SurfaceAboutToBeDestroyed :
2017-06-22 02:26:08 +03:00
if ( m_shellSurface ) {
delete m_shellSurface ;
m_shellSurface = nullptr ;
2018-03-01 01:31:17 +02:00
qDebug ( ) < < " WAYLAND dock window surface was deleted... " ;
2017-06-22 02:26:08 +03:00
PanelShadows : : self ( ) - > removeWindow ( this ) ;
}
2017-06-21 23:34:40 +03:00
break ;
}
2017-04-25 19:18:49 +03:00
}
2017-06-21 23:34:40 +03:00
break ;
2017-04-25 19:18:49 +03:00
2017-06-21 23:34:40 +03:00
default :
break ;
}
2017-06-23 01:35:10 +03:00
return ContainmentView : : event ( e ) ;
2017-04-25 19:18:49 +03:00
}
2017-06-23 01:35:10 +03:00
return false ;
2016-12-30 16:22:28 -05:00
}
2016-12-30 16:25:27 -05:00
QList < int > DockView : : freeEdges ( ) const
2016-12-30 16:22:28 -05:00
{
2018-01-31 20:38:22 +02:00
if ( ! m_managedLayout ) {
2017-01-17 20:09:43 +02:00
const QList < int > emptyEdges ;
return emptyEdges ;
}
2018-01-31 20:38:22 +02:00
const auto edges = m_managedLayout - > freeEdges ( screen ( ) ) ;
2016-12-30 16:22:28 -05:00
QList < int > edgesInt ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
foreach ( Plasma : : Types : : Location edge , edges ) {
2016-12-30 19:26:48 -05:00
edgesInt . append ( static_cast < int > ( edge ) ) ;
2016-12-30 16:22:28 -05:00
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
return edgesInt ;
}
2017-03-20 20:40:27 +02:00
void DockView : : deactivateApplets ( )
{
if ( ! containment ( ) ) {
return ;
}
foreach ( auto applet , containment ( ) - > applets ( ) ) {
PlasmaQuick : : AppletQuickItem * ai = applet - > property ( " _plasma_graphicObject " ) . value < PlasmaQuick : : AppletQuickItem * > ( ) ;
if ( ai ) {
ai - > setExpanded ( false ) ;
}
}
}
2017-05-16 23:08:13 +03:00
void DockView : : toggleAppletExpanded ( const int id )
{
if ( ! containment ( ) ) {
return ;
}
foreach ( auto applet , containment ( ) - > applets ( ) ) {
if ( applet - > id ( ) = = id ) {
PlasmaQuick : : AppletQuickItem * ai = applet - > property ( " _plasma_graphicObject " ) . value < PlasmaQuick : : AppletQuickItem * > ( ) ;
if ( ai ) {
2017-12-02 19:52:43 +02:00
if ( ! ai - > isActivationTogglesExpanded ( ) ) {
ai - > setActivationTogglesExpanded ( true ) ;
}
emit applet - > activated ( ) ;
2017-05-16 23:08:13 +03:00
}
}
}
}
2017-01-02 12:02:35 +02:00
QVariantList DockView : : containmentActions ( )
{
QVariantList actions ;
/*if (containment()->corona()->immutability() != Plasma::Types::Mutable) {
return actions ;
} */
//FIXME: the trigger string it should be better to be supported this way
//const QString trigger = Plasma::ContainmentActions::eventToString(event);
const QString trigger = " RightButton;NoModifier " ;
2017-02-12 10:02:01 +02:00
Plasma : : ContainmentActions * plugin = this - > containment ( ) - > containmentActions ( ) . value ( trigger ) ;
2017-01-16 14:07:49 -05:00
2017-01-02 12:02:35 +02:00
if ( ! plugin ) {
return actions ;
}
2017-01-16 14:07:49 -05:00
2017-02-12 10:02:01 +02:00
if ( plugin - > containment ( ) ! = this - > containment ( ) ) {
plugin - > setContainment ( this - > containment ( ) ) ;
2017-01-02 12:02:35 +02:00
// now configure it
2017-02-12 10:02:01 +02:00
KConfigGroup cfg ( this - > containment ( ) - > corona ( ) - > config ( ) , " ActionPlugins " ) ;
cfg = KConfigGroup ( & cfg , QString : : number ( this - > containment ( ) - > containmentType ( ) ) ) ;
2017-01-02 12:02:35 +02:00
KConfigGroup pluginConfig = KConfigGroup ( & cfg , trigger ) ;
plugin - > restore ( pluginConfig ) ;
}
2017-01-16 14:07:49 -05:00
2017-01-02 12:02:35 +02:00
foreach ( QAction * ac , plugin - > contextualActions ( ) ) {
actions < < QVariant : : fromValue < QAction * > ( ac ) ;
}
2017-01-16 14:07:49 -05:00
2017-01-02 12:02:35 +02:00
return actions ;
}
2017-01-12 18:55:43 -05:00
2017-01-03 15:33:30 +02:00
//!BEGIN overriding context menus behavior
void DockView : : mousePressEvent ( QMouseEvent * event )
{
2018-02-03 15:00:44 +02:00
bool result = m_menuManager - > mousePressEvent ( event ) ;
2017-07-27 18:24:31 +03:00
emit contextMenuIsShownChanged ( ) ;
2018-01-17 16:45:29 +02:00
2018-02-03 15:00:44 +02:00
if ( result ) {
PlasmaQuick : : ContainmentView : : mousePressEvent ( event ) ;
2017-01-27 20:03:24 +02:00
}
}
2017-01-03 15:33:30 +02:00
//!END overriding context menus behavior
2017-01-02 12:02:35 +02:00
2017-01-31 21:25:00 +02:00
//!BEGIN draw panel shadows outside the dock window
Plasma : : FrameSvg : : EnabledBorders DockView : : enabledBorders ( ) const
{
return m_enabledBorders ;
}
void DockView : : updateEnabledBorders ( )
{
2017-02-08 20:48:46 +02:00
if ( ! this - > screen ( ) ) {
2017-01-31 21:25:00 +02:00
return ;
}
Plasma : : FrameSvg : : EnabledBorders borders = Plasma : : FrameSvg : : AllBorders ;
2017-02-04 16:41:12 +02:00
switch ( location ( ) ) {
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : TopEdge :
borders & = ~ Plasma : : FrameSvg : : TopBorder ;
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : LeftEdge :
borders & = ~ Plasma : : FrameSvg : : LeftBorder ;
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : RightEdge :
borders & = ~ Plasma : : FrameSvg : : RightBorder ;
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
case Plasma : : Types : : BottomEdge :
borders & = ~ Plasma : : FrameSvg : : BottomBorder ;
break ;
2017-01-31 21:25:00 +02:00
2017-02-27 12:44:51 +02:00
default :
break ;
2017-02-04 16:41:12 +02:00
}
2017-01-31 21:25:00 +02:00
2017-02-04 16:41:12 +02:00
if ( ( location ( ) = = Plasma : : Types : : LeftEdge | | location ( ) = = Plasma : : Types : : RightEdge ) ) {
2017-03-07 18:29:37 +02:00
if ( maxLength ( ) = = 1 & & m_alignment = = Dock : : Justify & & ! m_forceDrawCenteredBorders ) {
2017-02-04 16:41:12 +02:00
borders & = ~ Plasma : : FrameSvg : : TopBorder ;
borders & = ~ Plasma : : FrameSvg : : BottomBorder ;
2017-01-31 21:25:00 +02:00
}
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Top & & ! m_forceDrawCenteredBorders & & m_offset = = 0 ) {
2017-01-31 21:25:00 +02:00
borders & = ~ Plasma : : FrameSvg : : TopBorder ;
}
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Bottom & & ! m_forceDrawCenteredBorders & & m_offset = = 0 ) {
2017-01-31 21:25:00 +02:00
borders & = ~ Plasma : : FrameSvg : : BottomBorder ;
}
}
2017-02-04 16:41:12 +02:00
if ( location ( ) = = Plasma : : Types : : TopEdge | | location ( ) = = Plasma : : Types : : BottomEdge ) {
if ( maxLength ( ) = = 1 & & m_alignment = = Dock : : Justify ) {
borders & = ~ Plasma : : FrameSvg : : LeftBorder ;
borders & = ~ Plasma : : FrameSvg : : RightBorder ;
}
2017-01-31 21:25:00 +02:00
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Left & & m_offset = = 0 ) {
2017-02-04 16:41:12 +02:00
borders & = ~ Plasma : : FrameSvg : : LeftBorder ;
}
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Right & & m_offset = = 0 ) {
2017-02-04 16:41:12 +02:00
borders & = ~ Plasma : : FrameSvg : : RightBorder ;
}
}
2017-01-31 21:25:00 +02:00
2017-02-04 16:41:12 +02:00
if ( m_enabledBorders ! = borders ) {
2017-01-31 21:25:00 +02:00
m_enabledBorders = borders ;
emit enabledBordersChanged ( ) ;
}
2017-02-04 16:41:12 +02:00
2017-05-07 15:18:14 +03:00
if ( ! m_behaveAsPlasmaPanel | | ! m_drawShadows ) {
2017-02-04 16:41:12 +02:00
PanelShadows : : self ( ) - > removeWindow ( this ) ;
} else {
PanelShadows : : self ( ) - > setEnabledBorders ( this , borders ) ;
}
2017-01-31 21:25:00 +02:00
}
//!END draw panel shadows outside the dock window
2017-02-27 00:53:27 +02:00
//!BEGIN configuration functions
void DockView : : saveConfig ( )
{
if ( ! this - > containment ( ) )
return ;
auto config = this - > containment ( ) - > config ( ) ;
config . writeEntry ( " onPrimary " , m_onPrimary ) ;
2017-03-18 23:32:27 +02:00
config . writeEntry ( " dockWindowBehavior " , m_dockWinBehavior ) ;
2017-07-29 23:07:00 +03:00
config . sync ( ) ;
2017-02-27 00:53:27 +02:00
}
void DockView : : restoreConfig ( )
{
if ( ! this - > containment ( ) )
return ;
auto config = this - > containment ( ) - > config ( ) ;
setOnPrimary ( config . readEntry ( " onPrimary " , true ) ) ;
2017-04-22 12:37:11 +03:00
setDockWinBehavior ( config . readEntry ( " dockWindowBehavior " , true ) ) ;
2017-02-27 00:53:27 +02:00
}
//!END configuration functions
2016-12-30 16:22:28 -05:00
}
//!END namespace