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
2018-12-06 12:15:58 +02:00
# include "view.h"
2018-02-03 11:34:13 +02:00
2018-12-02 02:05:52 +02:00
// local
2018-12-02 00:53:40 +02:00
# include "contextmenu.h"
2018-11-30 21:33:46 +02:00
# include "effects.h"
2018-11-29 21:30:00 +02:00
# include "positioner.h"
2017-03-18 13:21:17 +02:00
# include "visibilitymanager.h"
2018-12-09 00:06:14 +02:00
# include "settings/primaryconfigview.h"
2019-04-01 23:50:25 +03:00
# include "settings/secondaryconfigview.h"
2019-06-20 17:42:49 +03:00
# include "../indicator/factory.h"
2018-12-06 14:35:34 +02:00
# include "../lattecorona.h"
2019-04-06 02:00:37 +03:00
# include "../layout/genericlayout.h"
2019-05-09 17:12:57 +03:00
# include "../layouts/manager.h"
2018-12-13 20:03:14 +02:00
# include "../plasma/extended/theme.h"
2018-02-03 11:34:13 +02:00
# include "../screenpool.h"
2018-12-02 01:21:34 +02:00
# include "../settings/universalsettings.h"
2019-02-03 00:10:07 +02:00
# include "../shortcuts/globalshortcuts.h"
# include "../shortcuts/shortcutstracker.h"
2018-12-07 18:55:35 +02:00
# include "../../liblatte2/extras.h"
2016-12-30 16:22:28 -05:00
2018-12-02 02:05:52 +02:00
// Qt
2016-12-30 16:22:28 -05:00
# include <QAction>
2019-04-14 13:25:16 +03:00
# include <QMouseEvent>
2016-12-30 16:22:28 -05:00
# 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
2018-12-02 02:05:52 +02:00
// KDe
2016-12-30 16:22:28 -05:00
# include <KActionCollection>
2018-01-14 09:39:31 +02:00
# include <KActivities/Consumer>
2018-12-02 02:05:52 +02:00
# include <KWayland/Client/plasmashell.h>
# include <KWayland/Client/surface.h>
2018-12-01 15:46:49 +02:00
# include <KWindowSystem>
2018-12-02 02:05:52 +02:00
// Plasma
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
namespace Latte {
2018-12-06 15:34:04 +02:00
//! both alwaysVisible and byPassWM are passed through corona because
//! during the view window creation containment hasn't been set, but these variables
2017-03-18 23:32:27 +02:00
//! are needed in order for window flags to be set correctly
2018-12-06 15:34:04 +02:00
View : : View ( Plasma : : Corona * corona , QScreen * targetScreen , bool byPassWM )
2017-01-03 15:33:30 +02:00
: PlasmaQuick : : ContainmentView ( corona ) ,
2018-12-06 11:37:14 +02:00
m_contextMenu ( new ViewPart : : ContextMenu ( this ) ) ,
2019-07-15 14:53:40 +03:00
m_effects ( new ViewPart : : Effects ( this ) )
2019-07-13 14:51:26 +03:00
{
2019-07-15 14:53:40 +03:00
//! needs to be created after Effects because it catches some of its signals
//! and avoid a crash from View::winId() at the same time
m_positioner = new ViewPart : : Positioner ( this ) ;
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 ) ) ;
2019-07-16 14:06:26 +03:00
setDefaultAlphaBuffer ( true ) ;
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
2019-03-23 17:49:09 +02:00
| Qt : : WindowStaysOnTopHint
| Qt : : NoDropShadowWindowHint
| Qt : : WindowDoesNotAcceptFocus ;
2017-04-09 13:42:39 -05:00
2018-12-06 15:34:04 +02:00
if ( byPassWM ) {
2017-04-09 13:42:39 -05:00
setFlags ( flags | Qt : : BypassWindowManagerHint ) ;
2018-12-06 15:34:04 +02:00
} else {
setFlags ( flags ) ;
2017-03-08 21:00:09 +02:00
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( targetScreen )
2018-11-29 21:30:00 +02:00
m_positioner - > setScreenToFollow ( targetScreen ) ;
2016-12-30 16:22:28 -05:00
else
2018-11-29 21:30:00 +02:00
m_positioner - > setScreenToFollow ( qGuiApp - > primaryScreen ( ) ) ;
2017-01-16 14:07:49 -05:00
2018-12-06 12:15:58 +02:00
connect ( this , & View : : containmentChanged
2019-03-23 17:49:09 +02:00
, this , [ & , byPassWM ] ( ) {
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... " ;
2018-09-04 19:38:54 +03:00
//! First load default values from file
restoreConfig ( ) ;
//! Afterwards override that values in case during creation something different is needed
2018-12-06 15:34:04 +02:00
setByPassWM ( byPassWM ) ;
2017-07-29 23:07:00 +03:00
2018-09-04 19:38:54 +03:00
//! Check the screen assigned to this dock
2017-02-27 00:53:27 +02:00
reconsiderScreen ( ) ;
2017-01-16 14:07:49 -05:00
2019-02-07 20:24:52 +02:00
//! needs to be created before visibility creation because visibility uses it
if ( ! m_windowsTracker ) {
m_windowsTracker = new ViewPart : : WindowsTracker ( this ) ;
2019-03-23 17:49:09 +02:00
emit windowsTrackerChanged ( ) ;
2019-02-07 20:24:52 +02:00
}
2016-12-30 16:22:28 -05:00
if ( ! m_visibility ) {
2018-12-09 00:29:35 +02:00
m_visibility = new ViewPart : : VisibilityManager ( this ) ;
2018-02-25 20:00:23 +02:00
2018-12-09 00:29:35 +02:00
connect ( m_visibility , & ViewPart : : VisibilityManager : : isHiddenChanged , this , [ & ] ( ) {
2018-02-25 20:00:23 +02:00
if ( m_visibility - > isHidden ( ) ) {
deactivateApplets ( ) ;
}
} ) ;
2019-03-23 17:49:09 +02:00
emit visibilityChanged ( ) ;
}
if ( ! m_indicator ) {
m_indicator = new ViewPart : : Indicator ( this ) ;
emit indicatorChanged ( ) ;
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
2019-04-12 18:55:45 +03:00
m_corona = qobject_cast < Latte : : Corona * > ( this - > corona ( ) ) ;
2017-01-16 14:07:49 -05:00
2019-04-12 18:55:45 +03:00
if ( m_corona ) {
connect ( m_corona , & Latte : : Corona : : viewLocationChanged , this , & View : : dockLocationChanged ) ;
2017-01-22 13:29:40 +02:00
}
2016-12-30 16:22:28 -05:00
}
2018-12-06 12:15:58 +02:00
View : : ~ View ( )
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
2019-05-08 23:42:06 +03:00
//! clear Layout connections
2019-05-07 22:06:00 +03:00
m_visibleHackTimer1 . stop ( ) ;
m_visibleHackTimer2 . stop ( ) ;
2019-05-08 23:42:06 +03:00
for ( auto & c : connectionsLayout ) {
2019-05-07 22:06:00 +03:00
disconnect ( c ) ;
}
//! unload indicators
2019-04-05 17:16:40 +03:00
if ( m_indicator ) {
m_indicator - > unloadIndicators ( ) ;
}
2019-04-12 18:55:45 +03:00
disconnect ( m_corona , & Latte : : Corona : : availableScreenRectChangedFrom , this , & View : : availableScreenRectChangedFrom ) ;
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-01-05 17:48:27 +02:00
qDebug ( ) < < " dock view deleting... " ;
2017-01-22 00:40:16 +02:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dock " ) , nullptr ) ;
2019-05-09 17:12:57 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " layoutsManager " ) , nullptr ) ;
2019-02-03 00:10:07 +02:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " shortcutsEngine " ) , nullptr ) ;
2018-12-01 21:58:45 +02:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " themeExtended " ) , nullptr ) ;
rootContext ( ) - > setContextProperty ( QStringLiteral ( " universalSettings " ) , 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
2018-12-06 12:15:58 +02:00
//! latteView is deleted. A crash for this example is the following:
2017-03-13 20:58:31 +02:00
//! 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 ) {
2019-07-15 15:48:36 +03:00
m_configView - > deleteLater ( ) ;
2018-01-18 21:21:32 +02:00
}
2018-12-02 00:53:40 +02:00
if ( m_contextMenu ) {
delete m_contextMenu ;
2018-02-03 15:00:44 +02:00
}
2019-01-01 11:19:44 +02:00
//needs to be deleted before Effects because it catches some of its signals
2018-11-29 21:30:00 +02:00
if ( m_positioner ) {
delete m_positioner ;
}
2018-11-30 21:33:46 +02:00
if ( m_effects ) {
delete m_effects ;
}
2019-04-05 17:16:40 +03:00
if ( m_indicator ) {
delete m_indicator ;
}
2019-02-07 19:15:25 +02:00
if ( m_visibility ) {
2018-11-30 21:33:46 +02:00
delete m_visibility ;
2019-02-07 19:15:25 +02:00
}
2019-02-07 20:24:52 +02:00
if ( m_windowsTracker ) {
delete m_windowsTracker ;
}
2016-12-30 16:22:28 -05:00
}
2018-12-06 12:15:58 +02:00
void View : : init ( )
2016-12-30 16:22:28 -05:00
{
2018-12-06 12:15:58 +02:00
connect ( this , & QQuickWindow : : xChanged , this , & View : : xChanged ) ;
2019-04-23 10:41:35 +03:00
connect ( this , & QQuickWindow : : xChanged , this , & View : : updateAbsoluteGeometry ) ;
2018-12-06 12:15:58 +02:00
connect ( this , & QQuickWindow : : yChanged , this , & View : : yChanged ) ;
2019-04-23 10:41:35 +03:00
connect ( this , & QQuickWindow : : yChanged , this , & View : : updateAbsoluteGeometry ) ;
2018-12-06 12:15:58 +02:00
connect ( this , & QQuickWindow : : widthChanged , this , & View : : widthChanged ) ;
2019-04-23 10:41:35 +03:00
connect ( this , & QQuickWindow : : widthChanged , this , & View : : updateAbsoluteGeometry ) ;
2018-12-06 12:15:58 +02:00
connect ( this , & QQuickWindow : : heightChanged , this , & View : : heightChanged ) ;
2019-04-23 10:41:35 +03:00
connect ( this , & QQuickWindow : : heightChanged , this , & View : : updateAbsoluteGeometry ) ;
2017-06-21 22:42:09 +03:00
2019-04-12 18:55:45 +03:00
connect ( m_corona , & Latte : : Corona : : availableScreenRectChangedFrom , this , & View : : availableScreenRectChangedFrom ) ;
2017-06-21 22:42:09 +03:00
2018-12-06 15:34:04 +02:00
connect ( this , & View : : byPassWMChanged , this , & View : : saveConfig ) ;
2018-12-06 12:15:58 +02:00
connect ( this , & View : : isPreferredForShortcutsChanged , this , & View : : saveConfig ) ;
2019-02-11 16:49:10 +02:00
connect ( this , & View : : onPrimaryChanged , this , & View : : saveConfig ) ;
connect ( this , & View : : typeChanged , this , & View : : saveConfig ) ;
2018-01-04 21:27:55 +02:00
2019-04-12 18:55:45 +03:00
connect ( this , & View : : normalThicknessChanged , this , [ & ] ( ) {
emit m_corona - > availableScreenRectChangedFrom ( this ) ;
} ) ;
2017-12-10 19:54:13 +02:00
2019-04-12 18:55:45 +03:00
connect ( m_effects , & ViewPart : : Effects : : innerShadowChanged , this , [ & ] ( ) {
emit m_corona - > availableScreenRectChangedFrom ( this ) ;
} ) ;
2018-12-06 12:15:58 +02:00
connect ( m_positioner , & ViewPart : : Positioner : : onHideWindowsForSlidingOut , this , & View : : hideWindowsForSlidingOut ) ;
connect ( m_positioner , & ViewPart : : Positioner : : screenGeometryChanged , this , & View : : screenGeometryChanged ) ;
2019-04-12 18:55:45 +03:00
connect ( m_positioner , & ViewPart : : Positioner : : windowSizeChanged , this , [ & ] ( ) {
emit m_corona - > availableScreenRectChangedFrom ( this ) ;
} ) ;
2018-12-06 12:15:58 +02:00
connect ( m_contextMenu , & ViewPart : : ContextMenu : : menuChanged , this , & View : : contextMenuIsShownChanged ) ;
2018-02-03 15:00:44 +02:00
2019-06-20 17:42:49 +03:00
connect ( m_corona - > indicatorFactory ( ) , & Latte : : Indicator : : Factory : : pluginsUpdated , this , & View : : reloadSource ) ;
//! View sends this signal in order to avoid crashes from ViewPart::Indicator when the view is recreated
connect ( m_corona - > indicatorFactory ( ) , & Latte : : Indicator : : Factory : : customPluginsChanged , this , & View : : customPluginsChanged ) ;
connect ( m_corona , & Latte : : Corona : : availableScreenRectChanged , this , & View : : availableScreenRectChangedForViewParts ) ;
2017-12-10 19:54:13 +02:00
///!!!!!
2018-12-08 18:35:32 +02:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " latteView " ) , this ) ;
2017-03-18 13:21:17 +02:00
2019-04-12 18:55:45 +03:00
if ( m_corona ) {
2019-05-09 17:12:57 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " layoutsManager " ) , m_corona - > layoutsManager ( ) ) ;
2019-04-12 18:55:45 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " shortcutsEngine " ) , m_corona - > globalShortcuts ( ) - > shortcutsTracker ( ) ) ;
rootContext ( ) - > setContextProperty ( QStringLiteral ( " themeExtended " ) , m_corona - > themeExtended ( ) ) ;
rootContext ( ) - > setContextProperty ( QStringLiteral ( " universalSettings " ) , m_corona - > universalSettings ( ) ) ;
2017-03-18 13:21:17 +02:00
}
2016-12-30 16:25:27 -05:00
setSource ( corona ( ) - > kPackage ( ) . filePath ( " lattedockui " ) ) ;
2018-11-29 21:30:00 +02:00
m_positioner - > syncGeometry ( ) ;
2017-06-20 23:13:38 +03:00
2017-01-12 20:04:27 +02:00
qDebug ( ) < < " SOURCE: " < < source ( ) ;
2016-12-30 16:22:28 -05:00
}
2019-06-20 17:42:49 +03:00
void View : : reloadSource ( )
{
if ( m_layout & & containment ( ) ) {
if ( settingsWindowIsShown ( ) ) {
m_configView - > deleteLater ( ) ;
}
engine ( ) - > clearComponentCache ( ) ;
m_layout - > recreateView ( containment ( ) , settingsWindowIsShown ( ) ) ;
}
}
2018-12-06 12:15:58 +02:00
bool View : : inDelete ( ) const
2018-01-21 11:34:18 +02:00
{
2018-11-29 21:30:00 +02:00
return m_inDelete ;
2018-01-04 21:27:55 +02:00
}
2017-12-10 19:54:13 +02:00
2018-12-06 12:15:58 +02:00
void View : : disconnectSensitiveSignals ( )
2018-01-11 21:11:46 +02:00
{
2019-04-12 18:55:45 +03:00
disconnect ( m_corona , & Latte : : Corona : : availableScreenRectChangedFrom , this , & View : : availableScreenRectChangedFrom ) ;
2019-05-08 23:42:06 +03:00
setLayout ( nullptr ) ;
2018-01-11 21:11:46 +02:00
2019-02-07 19:15:25 +02:00
if ( m_windowsTracker ) {
2019-06-08 17:36:14 +03:00
// m_windowsTracker->setEnabled(false);
2018-01-11 21:11:46 +02:00
}
}
2019-04-12 18:55:45 +03:00
void View : : availableScreenRectChangedFrom ( View * origin )
2017-06-21 22:42:09 +03:00
{
2019-04-12 18:55:45 +03:00
if ( m_inDelete | | origin = = this )
2017-06-21 23:34:40 +03:00
return ;
2018-11-29 21:30:00 +02:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
m_positioner - > syncGeometry ( ) ;
}
2019-04-12 18:55:45 +03:00
2017-06-21 22:42:09 +03:00
}
2018-12-06 12:15:58 +02:00
void View : : setupWaylandIntegration ( )
2017-04-25 19:18:49 +03:00
{
2017-06-15 16:56:55 -05:00
if ( m_shellSurface )
2017-04-25 19:18:49 +03:00
return ;
2018-12-06 14:35:34 +02:00
if ( Latte : : Corona * c = qobject_cast < Latte : : Corona * > ( corona ( ) ) ) {
2018-03-01 00:52:05 +02:00
using namespace KWayland : : Client ;
2018-12-06 14:35:34 +02:00
PlasmaShell * interface { c - > waylandCoronaInterface ( ) } ;
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
}
}
2018-12-06 12:15:58 +02:00
KWayland : : Client : : PlasmaShellSurface * View : : surface ( )
2018-03-28 20:39:52 +03:00
{
return m_shellSurface ;
}
2017-03-02 18:07:29 +02:00
//! the main function which decides if this dock is at the
//! correct screen
2018-12-06 12:15:58 +02:00
void View : : reconsiderScreen ( )
2017-02-26 02:43:41 +02:00
{
2018-11-29 21:30:00 +02:00
m_positioner - > reconsiderScreen ( ) ;
2016-12-30 16:22:28 -05:00
}
2018-12-06 15:57:20 +02:00
void View : : copyView ( )
2017-06-05 23:52:49 +03:00
{
2019-05-08 23:42:06 +03:00
m_layout - > copyView ( containment ( ) ) ;
2017-06-05 23:52:49 +03:00
}
2018-12-06 15:57:20 +02:00
void View : : removeView ( )
2016-12-30 16:22:28 -05:00
{
2019-05-08 23:42:06 +03:00
if ( m_layout & & m_layout - > viewsCount ( ) > 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 ( ) ;
}
}
}
2018-12-06 12:15:58 +02:00
bool View : : settingsWindowIsShown ( )
2018-01-18 21:21:32 +02:00
{
2018-12-09 00:06:14 +02:00
auto configView = qobject_cast < ViewPart : : PrimaryConfigView * > ( 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
}
2018-12-06 12:15:58 +02:00
void View : : showSettingsWindow ( )
2017-11-19 14:51:15 +02:00
{
2018-12-26 17:33:59 +02:00
if ( ! settingsWindowIsShown ( ) ) {
emit m_visibility - > mustBeShown ( ) ;
showConfigurationInterface ( containment ( ) ) ;
applyActivitiesToWindows ( ) ;
}
2017-11-19 14:51:15 +02:00
}
2019-03-08 23:43:08 +02:00
PlasmaQuick : : ConfigView * View : : configView ( )
{
return m_configView ;
}
2018-12-06 12:15:58 +02:00
void View : : 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 ( ) ) {
2019-07-15 19:39:21 +03:00
m_configView - > hide ( ) ;
2016-12-30 16:22:28 -05:00
} else {
2019-07-15 19:39:21 +03:00
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 ) {
2019-07-15 19:39:21 +03:00
m_configView - > show ( ) ;
2019-07-15 15:48:36 +03:00
2019-03-09 20:19:26 +02:00
if ( KWindowSystem : : isPlatformX11 ( ) ) {
m_configView - > requestActivate ( ) ;
}
2016-12-30 16:22:28 -05:00
return ;
} else {
2019-07-15 19:39:21 +03:00
m_configView - > hide ( ) ;
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-12-09 00:06:14 +02:00
m_configView = new ViewPart : : PrimaryConfigView ( 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 ) {
2019-07-15 19:39:21 +03:00
m_configView - > 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
2019-01-01 11:19:44 +02:00
//created in order to give the containment's layouts the time to
2017-01-11 16:33:10 +02:00
//calculate the window's height
2019-07-15 15:48:36 +03:00
QTimer : : singleShot ( 150 , [ this ] ( ) {
if ( m_configView ) {
2019-07-15 19:39:21 +03:00
m_configView - > show ( ) ;
2019-07-15 15:48:36 +03:00
}
} ) ;
2017-01-11 16:29:11 +02:00
}
2016-12-30 16:22:28 -05:00
}
2018-12-06 12:15:58 +02:00
QRect View : : localGeometry ( ) const
2017-03-09 15:49:24 +02:00
{
return m_localGeometry ;
}
2018-12-06 12:15:58 +02:00
void View : : 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 ( ) ;
2019-04-23 10:41:35 +03:00
updateAbsoluteGeometry ( ) ;
2016-12-30 19:26:48 -05:00
}
2019-04-23 10:41:35 +03:00
void View : : updateAbsoluteGeometry ( 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
2019-01-01 11:19:44 +02:00
//! remember exactly the reason, something related to right edge in
2017-06-20 17:28:55 +03:00
//! 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 ( )
2019-03-23 17:49:09 +02:00
, m_localGeometry . width ( ) , m_localGeometry . height ( ) } ;
2017-02-10 22:12:17 -05:00
2019-04-23 10:41:35 +03:00
if ( m_absoluteGeometry = = absGeometry & & ! bypassChecks ) {
2017-01-12 18:55:43 -05:00
return ;
2019-04-23 10:41:35 +03:00
}
2017-01-16 14:07:49 -05:00
2019-04-23 10:41:35 +03:00
if ( m_absoluteGeometry ! = absGeometry ) {
m_absoluteGeometry = absGeometry ;
emit absoluteGeometryChanged ( m_absoluteGeometry ) ;
}
2017-12-24 20:54:45 +02:00
//! this is needed in order to update correctly the screenGeometries
2018-12-07 18:55:35 +02:00
if ( visibility ( ) & & corona ( ) & & visibility ( ) - > mode ( ) = = Types : : AlwaysVisible ) {
2019-04-23 10:41:35 +03:00
//! main use of BYPASSCKECKS is from Positioner when the view changes screens
2019-04-12 18:55:45 +03:00
emit m_corona - > availableScreenRectChangedFrom ( this ) ;
emit m_corona - > availableScreenRegionChangedFrom ( this ) ;
2017-12-24 20:54:45 +02:00
}
2016-12-30 19:26:48 -05:00
}
2018-12-06 12:15:58 +02:00
void View : : statusChanged ( Plasma : : Types : : ItemStatus status )
2017-01-14 01:59:25 +02:00
{
2017-02-18 10:28:40 +02:00
if ( containment ( ) ) {
if ( containment ( ) - > status ( ) > = Plasma : : Types : : NeedsAttentionStatus & &
2019-03-23 17:49:09 +02:00
containment ( ) - > status ( ) ! = Plasma : : Types : : HiddenStatus ) {
2017-08-09 03:41:45 +03:00
setBlockHiding ( true ) ;
2019-01-11 20:09:46 +02:00
} else if ( ! containment ( ) - > isUserConfiguring ( ) ) {
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
}
}
2019-02-11 16:49:10 +02:00
Types : : ViewType View : : type ( ) const
{
return m_type ;
}
void View : : setType ( Types : : ViewType type )
{
if ( m_type = = type ) {
return ;
}
m_type = type ;
emit typeChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
bool View : : alternativesIsShown ( ) const
2017-08-09 03:33:03 +03:00
{
return m_alternativesIsShown ;
}
2018-12-06 12:15:58 +02:00
void View : : setAlternativesIsShown ( bool show )
2017-08-09 03:33:03 +03:00
{
if ( m_alternativesIsShown = = show ) {
return ;
}
m_alternativesIsShown = show ;
setBlockHiding ( show ) ;
emit alternativesIsShownChanged ( ) ;
}
2019-05-17 21:28:39 +03:00
bool View : : containsDrag ( ) const
{
return m_containsDrag ;
}
void View : : setContainsDrag ( bool contains )
{
if ( m_containsDrag = = contains ) {
return ;
}
m_containsDrag = contains ;
emit containsDragChanged ( ) ;
}
2019-03-08 16:14:34 +02:00
bool View : : containsMouse ( ) const
{
return m_containsMouse ;
}
2018-12-06 12:15:58 +02:00
bool View : : contextMenuIsShown ( ) const
2017-07-27 18:24:31 +03:00
{
2018-12-02 00:53:40 +02:00
if ( ! m_contextMenu ) {
2018-02-03 15:00:44 +02:00
return false ;
}
2018-12-02 00:53:40 +02:00
return m_contextMenu - > menu ( ) ;
2017-07-27 18:24:31 +03:00
}
2018-12-06 12:15:58 +02:00
int View : : currentThickness ( ) const
2016-12-30 16:22:28 -05:00
{
2017-01-12 18:55:43 -05:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
2018-12-01 00:52:05 +02:00
return m_effects - > mask ( ) . isNull ( ) ? width ( ) : m_effects - > mask ( ) . width ( ) - m_effects - > innerShadow ( ) ;
2016-12-30 16:22:28 -05:00
} else {
2018-12-01 00:52:05 +02:00
return m_effects - > mask ( ) . isNull ( ) ? height ( ) : m_effects - > mask ( ) . height ( ) - m_effects - > innerShadow ( ) ;
2016-12-30 16:22:28 -05:00
}
}
2018-12-06 12:15:58 +02:00
int View : : normalThickness ( ) const
2017-01-27 20:31:41 +02:00
{
return m_normalThickness ;
}
2018-12-06 12:15:58 +02:00
void View : : setNormalThickness ( int thickness )
2017-01-27 20:31:41 +02:00
{
if ( m_normalThickness = = thickness ) {
return ;
}
m_normalThickness = thickness ;
emit normalThicknessChanged ( ) ;
}
2018-12-06 15:34:04 +02:00
bool View : : byPassWM ( ) const
2017-03-18 23:32:27 +02:00
{
2018-12-06 15:34:04 +02:00
return m_byPassWM ;
2017-03-18 23:32:27 +02:00
}
2018-12-06 15:34:04 +02:00
void View : : setByPassWM ( bool bypass )
2017-03-18 23:32:27 +02:00
{
2018-12-06 15:34:04 +02:00
if ( m_byPassWM = = bypass ) {
2017-03-18 23:32:27 +02:00
return ;
}
2018-12-06 15:34:04 +02:00
m_byPassWM = bypass ;
emit byPassWMChanged ( ) ;
2017-03-18 23:32:27 +02:00
}
2018-12-06 12:15:58 +02:00
bool View : : 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
}
2018-12-06 12:15:58 +02:00
void View : : 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:06:29 +03:00
emit behaveAsPlasmaPanelChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
bool View : : inEditMode ( ) const
2018-02-12 16:11:33 +02:00
{
return m_inEditMode ;
}
2018-12-06 12:15:58 +02:00
void View : : setInEditMode ( bool edit )
2018-02-12 16:11:33 +02:00
{
if ( m_inEditMode = = edit ) {
return ;
}
m_inEditMode = edit ;
emit inEditModeChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
bool View : : isPreferredForShortcuts ( ) const
2018-09-22 20:21:57 +03:00
{
return m_isPreferredForShortcuts ;
}
2018-12-06 12:15:58 +02:00
void View : : setIsPreferredForShortcuts ( bool preferred )
2018-09-22 20:21:57 +03:00
{
if ( m_isPreferredForShortcuts = = preferred ) {
return ;
}
m_isPreferredForShortcuts = preferred ;
emit isPreferredForShortcutsChanged ( ) ;
2019-05-08 23:42:06 +03:00
if ( m_isPreferredForShortcuts & & m_layout ) {
emit m_layout - > preferredViewForShortcutsChanged ( this ) ;
2018-09-22 20:21:57 +03:00
}
}
2019-03-23 17:49:09 +02:00
bool View : : latteTasksArePresent ( ) const
{
return m_latteTasksArePresent ;
}
void View : : setLatteTasksArePresent ( bool present )
{
if ( m_latteTasksArePresent = = present ) {
return ;
}
m_latteTasksArePresent = present ;
emit latteTasksArePresentChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
void View : : preferredViewForShortcutsChangedSlot ( Latte : : View * view )
2018-09-22 20:21:57 +03:00
{
if ( view ! = this ) {
setIsPreferredForShortcuts ( false ) ;
}
}
2018-02-12 16:11:33 +02:00
2018-12-06 12:15:58 +02:00
bool View : : onPrimary ( ) const
2017-02-27 00:53:27 +02:00
{
return m_onPrimary ;
}
2018-12-06 12:15:58 +02:00
void View : : setOnPrimary ( bool flag )
2017-02-27 00:53:27 +02:00
{
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 ( ) ;
}
2018-12-06 12:15:58 +02:00
float View : : maxLength ( ) const
2017-01-31 21:25:00 +02:00
{
return m_maxLength ;
}
2018-12-06 12:15:58 +02:00
void View : : setMaxLength ( float length )
2017-01-31 21:25:00 +02:00
{
if ( m_maxLength = = length ) {
return ;
}
m_maxLength = length ;
emit maxLengthChanged ( ) ;
}
2019-03-06 20:10:36 +02:00
int View : : editThickness ( ) const
{
return m_editThickness ;
}
void View : : setEditThickness ( int thickness )
{
if ( m_editThickness = = thickness ) {
return ;
}
m_editThickness = thickness ;
emit editThicknessChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
int View : : maxThickness ( ) const
2016-12-30 16:22:28 -05:00
{
return m_maxThickness ;
}
2018-12-06 12:15:58 +02:00
void View : : 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 ;
emit maxThicknessChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
int View : : alignment ( ) const
2017-02-04 16:41:12 +02:00
{
2017-02-10 22:12:17 -05:00
return m_alignment ;
2017-02-04 16:41:12 +02:00
}
2018-12-06 12:15:58 +02:00
void View : : setAlignment ( int alignment )
2017-02-04 16:41:12 +02:00
{
2018-12-07 18:55:35 +02:00
Types : : Alignment align = static_cast < Types : : 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 ( ) ;
}
2019-04-23 10:41:35 +03:00
QRect View : : absoluteGeometry ( ) const
2017-02-10 22:12:17 -05:00
{
2019-04-23 10:41:35 +03:00
return m_absoluteGeometry ;
2017-02-10 22:12:17 -05:00
}
2018-12-06 12:15:58 +02:00
QRect View : : screenGeometry ( ) const
2017-02-26 15:49:50 +02:00
{
if ( this - > screen ( ) ) {
QRect geom = this - > screen ( ) - > geometry ( ) ;
return geom ;
}
return QRect ( ) ;
}
2018-12-06 12:15:58 +02:00
int View : : offset ( ) const
2017-04-09 01:06:48 +03:00
{
return m_offset ;
}
2018-12-06 12:15:58 +02:00
void View : : setOffset ( int offset )
2017-04-09 01:06:48 +03:00
{
if ( m_offset = = offset ) {
return ;
}
m_offset = offset ;
emit offsetChanged ( ) ;
}
2018-12-06 12:15:58 +02:00
int View : : fontPixelSize ( ) const
2018-02-17 19:02:06 +02:00
{
return m_fontPixelSize ;
}
2018-12-06 12:15:58 +02:00
void View : : setFontPixelSize ( int size )
2018-02-17 19:02:06 +02:00
{
if ( m_fontPixelSize = = size ) {
return ;
}
m_fontPixelSize = size ;
emit fontPixelSizeChanged ( ) ;
}
2019-06-08 01:38:27 +03:00
bool View : : isOnAllActivities ( ) const
{
return m_activities . isEmpty ( ) | | m_activities [ 0 ] = = " 0 " ;
}
bool View : : isOnActivity ( const QString & activity ) const
{
return isOnAllActivities ( ) | | m_activities . contains ( activity ) ;
}
QStringList View : : activities ( ) const
{
return m_activities ;
}
2018-12-06 12:15:58 +02:00
void View : : applyActivitiesToWindows ( )
2018-01-21 11:53:15 +02:00
{
2019-05-08 23:42:06 +03:00
if ( m_visibility & & m_layout ) {
2019-06-08 01:38:27 +03:00
m_windowsTracker - > setWindowOnActivities ( * this , m_activities ) ;
2018-01-21 11:53:15 +02:00
if ( m_configView ) {
2019-06-08 01:38:27 +03:00
m_windowsTracker - > setWindowOnActivities ( * m_configView , m_activities ) ;
2018-01-21 11:53:15 +02:00
2018-12-09 00:06:14 +02:00
auto configView = qobject_cast < ViewPart : : PrimaryConfigView * > ( m_configView ) ;
2018-02-09 19:22:04 +02:00
if ( configView & & configView - > secondaryWindow ( ) ) {
2019-06-08 01:38:27 +03:00
m_windowsTracker - > setWindowOnActivities ( * configView - > secondaryWindow ( ) , m_activities ) ;
2018-02-09 19:22:04 +02:00
}
2018-01-21 11:53:15 +02:00
}
2018-03-28 20:39:52 +03:00
if ( m_visibility - > supportsKWinEdges ( ) ) {
2019-06-08 01:38:27 +03:00
m_visibility - > applyActivitiesToHiddenWindows ( m_activities ) ;
2018-03-28 20:39:52 +03:00
}
2018-01-21 11:53:15 +02:00
}
}
2019-05-08 23:42:06 +03:00
Layout : : GenericLayout * View : : layout ( ) const
2018-01-10 22:55:19 +02:00
{
2019-05-08 23:42:06 +03:00
return m_layout ;
2018-01-10 22:55:19 +02:00
}
2019-05-08 23:42:06 +03:00
void View : : setLayout ( Layout : : GenericLayout * layout )
2018-01-10 22:55:19 +02:00
{
2019-05-08 23:42:06 +03:00
if ( m_layout = = layout ) {
2018-01-10 22:55:19 +02:00
return ;
}
2018-01-20 00:34:55 +02:00
// clear mode
2019-05-08 23:42:06 +03:00
for ( auto & c : connectionsLayout ) {
2018-01-20 00:34:55 +02:00
disconnect ( c ) ;
}
2019-05-08 23:42:06 +03:00
m_layout = layout ;
2018-01-13 12:55:13 +02:00
2019-05-08 23:42:06 +03:00
if ( m_layout ) {
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( containment ( ) , & Plasma : : Applet : : destroyedChanged , m_layout , & Layout : : GenericLayout : : destroyedChanged ) ;
connectionsLayout < < connect ( containment ( ) , & Plasma : : Applet : : locationChanged , m_corona , & Latte : : Corona : : viewLocationChanged ) ;
connectionsLayout < < connect ( containment ( ) , & Plasma : : Containment : : appletAlternativesRequested , m_corona , & Latte : : Corona : : showAlternativesForApplet , Qt : : QueuedConnection ) ;
if ( m_corona - > layoutsManager ( ) - > memoryUsage ( ) = = Types : : MultipleLayouts ) {
connectionsLayout < < connect ( containment ( ) , & Plasma : : Containment : : appletCreated , m_layout , & Layout : : GenericLayout : : appletCreated ) ;
}
connectionsLayout < < connect ( m_positioner , & Latte : : ViewPart : : Positioner : : edgeChanged , m_layout , & Layout : : GenericLayout : : viewEdgeChanged ) ;
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 ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout & & m_visibility ) {
2019-06-08 01:38:27 +03:00
m_activities = m_layout - > appliedActivities ( ) ;
qDebug ( ) < < " DOCK VIEW FROM LAYOUT ::: " < < m_layout - > name ( ) < < " - activities: " < < m_activities ;
2018-01-21 11:53:15 +02:00
applyActivitiesToWindows ( ) ;
2018-01-14 17:30:29 +02:00
emit activitiesChanged ( ) ;
}
} ) ;
2018-09-22 20:21:57 +03:00
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( m_layout , & Layout : : GenericLayout : : preferredViewForShortcutsChanged , this , & View : : preferredViewForShortcutsChangedSlot ) ;
2019-05-25 17:40:29 +03:00
connectionsLayout < < connect ( m_layout , & Layout : : GenericLayout : : lastConfigViewForChanged , this , & View : : configViewCreatedFor ) ;
2018-01-14 09:39:31 +02:00
2019-04-08 18:57:32 +03:00
Latte : : Corona * latteCorona = qobject_cast < Latte : : Corona * > ( this - > corona ( ) ) ;
2018-01-14 09:39:31 +02:00
2019-05-09 17:12:57 +03:00
if ( latteCorona - > layoutsManager ( ) - > memoryUsage ( ) = = Types : : MultipleLayouts ) {
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( latteCorona - > activitiesConsumer ( ) , & KActivities : : Consumer : : runningActivitiesChanged , this , [ & ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout & & m_visibility ) {
2019-06-08 01:38:27 +03:00
m_activities = m_layout - > appliedActivities ( ) ;
2019-05-08 23:42:06 +03:00
qDebug ( ) < < " DOCK VIEW FROM LAYOUT (runningActivitiesChanged) ::: " < < m_layout - > name ( )
2019-06-08 01:38:27 +03:00
< < " - activities: " < < m_activities ;
2019-04-08 18:57:32 +03:00
applyActivitiesToWindows ( ) ;
emit activitiesChanged ( ) ;
}
} ) ;
2018-01-14 09:39:31 +02:00
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( m_layout , & Layout : : GenericLayout : : activitiesChanged , this , [ & ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout ) {
2019-06-08 01:38:27 +03:00
m_activities = m_layout - > appliedActivities ( ) ;
2019-04-08 18:57:32 +03:00
applyActivitiesToWindows ( ) ;
emit activitiesChanged ( ) ;
}
} ) ;
2018-01-14 12:22:45 +02:00
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( latteCorona - > layoutsManager ( ) , & Layouts : : Manager : : layoutsChanged , this , [ & ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout ) {
2019-06-08 01:38:27 +03:00
m_activities = m_layout - > appliedActivities ( ) ;
2019-04-08 18:57:32 +03:00
applyActivitiesToWindows ( ) ;
emit activitiesChanged ( ) ;
}
} ) ;
2018-01-15 19:44:00 +02:00
2019-05-07 22:06:00 +03:00
//! BEGIN OF KWIN HACK
//! IMPORTANT ::: Fixing KWin Faulty Behavior that KWin hides ALL Views when an Activity stops
//! with no reason!!
2019-05-14 17:12:36 +03:00
m_visibleHackTimer1 . setInterval ( 400 ) ;
m_visibleHackTimer2 . setInterval ( 2500 ) ;
2019-05-07 22:06:00 +03:00
m_visibleHackTimer1 . setSingleShot ( true ) ;
m_visibleHackTimer2 . setSingleShot ( true ) ;
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( this , & QWindow : : visibleChanged , this , [ & ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout & & ! inDelete ( ) & ! isVisible ( ) ) {
2019-05-07 22:06:00 +03:00
m_visibleHackTimer1 . start ( ) ;
m_visibleHackTimer2 . start ( ) ;
2019-04-08 18:57:32 +03:00
}
} ) ;
2019-05-07 22:06:00 +03:00
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( & m_visibleHackTimer1 , & QTimer : : timeout , this , [ & ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout & & ! inDelete ( ) & ! isVisible ( ) ) {
2019-07-15 19:39:21 +03:00
show ( ) ;
2019-05-07 22:06:00 +03:00
applyActivitiesToWindows ( ) ;
2019-05-14 17:12:36 +03:00
//qDebug() << "View:: Enforce reshow from timer 1...";
2019-05-07 22:06:00 +03:00
emit activitiesChanged ( ) ;
2019-07-16 13:23:20 +03:00
emit forcedShown ( ) ;
2019-05-14 17:12:36 +03:00
} else {
//qDebug() << "View:: No needed reshow from timer 1...";
2019-05-07 22:06:00 +03:00
}
} ) ;
2019-05-09 23:45:52 +03:00
connectionsLayout < < connect ( & m_visibleHackTimer2 , & QTimer : : timeout , this , [ & ] ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout & & ! inDelete ( ) & & ! isVisible ( ) ) {
2019-07-15 19:39:21 +03:00
show ( ) ;
2019-05-07 22:06:00 +03:00
applyActivitiesToWindows ( ) ;
2019-05-14 17:12:36 +03:00
//qDebug() << "View:: Enforce reshow from timer 2...";
2019-05-07 22:06:00 +03:00
emit activitiesChanged ( ) ;
2019-07-16 13:23:20 +03:00
emit forcedShown ( ) ;
2019-05-14 17:12:36 +03:00
} else {
//qDebug() << "View:: No needed reshow from timer 2...";
2019-05-07 22:06:00 +03:00
}
} ) ;
//! END OF KWIN HACK
2019-04-08 18:57:32 +03:00
}
2018-01-13 12:55:13 +02:00
2019-05-08 23:42:06 +03:00
emit layoutChanged ( ) ;
2019-06-08 01:38:27 +03:00
} else {
m_activities . clear ( ) ;
2019-04-08 18:57:32 +03:00
}
2018-01-10 22:55:19 +02:00
}
2018-12-06 12:15:58 +02:00
void View : : moveToLayout ( QString layoutName )
2018-01-21 11:34:18 +02:00
{
2019-05-08 23:42:06 +03:00
if ( ! m_layout ) {
2018-01-21 11:34:18 +02:00
return ;
}
2019-05-08 23:42:06 +03:00
QList < Plasma : : Containment * > containments = m_layout - > unassignFromLayout ( this ) ;
2018-01-21 11:34:18 +02:00
2018-12-06 14:35:34 +02:00
Latte : : Corona * latteCorona = qobject_cast < Latte : : Corona * > ( this - > corona ( ) ) ;
2018-01-21 11:34:18 +02:00
2018-12-06 14:35:34 +02:00
if ( latteCorona & & containments . size ( ) > 0 ) {
2019-05-11 09:23:14 +03:00
Layout : : GenericLayout * newLayout = latteCorona - > layoutsManager ( ) - > synchronizer ( ) - > layout ( layoutName ) ;
2018-01-21 11:34:18 +02:00
if ( newLayout ) {
newLayout - > assignToLayout ( this , containments ) ;
}
}
}
2018-12-06 12:15:58 +02:00
void View : : setBlockHiding ( bool block )
2017-08-09 03:33:03 +03:00
{
if ( ! block ) {
2018-12-09 00:06:14 +02:00
auto * configView = qobject_cast < ViewPart : : PrimaryConfigView * > ( m_configView ) ;
2017-08-09 03:33:03 +03:00
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
}
}
2019-05-25 17:40:29 +03:00
void View : : configViewCreatedFor ( Latte : : View * view )
2019-03-09 14:24:52 +02:00
{
2019-05-25 17:40:29 +03:00
if ( view ! = this & & m_configView ) {
2019-03-09 14:24:52 +02:00
//! for each layout only one dock should show its configuration windows
//! otherwise we could reach a point that because a settings window
//! is below another Latte View its options are not reachable
2019-03-09 19:56:57 +02:00
auto configDialog = qobject_cast < ViewPart : : PrimaryConfigView * > ( m_configView ) ;
if ( configDialog ) {
configDialog - > hideConfigWindow ( ) ;
}
2019-03-09 14:24:52 +02:00
}
}
2018-12-06 12:15:58 +02:00
void View : : hideWindowsForSlidingOut ( )
2018-12-01 00:13:11 +02:00
{
setBlockHiding ( false ) ;
if ( m_configView ) {
2018-12-09 00:06:14 +02:00
auto configDialog = qobject_cast < ViewPart : : PrimaryConfigView * > ( m_configView ) ;
2018-12-01 00:13:11 +02:00
if ( configDialog ) {
configDialog - > hideConfigWindow ( ) ;
}
}
}
2017-04-11 12:10:54 +03:00
//! remove latte tasks plasmoid
2018-12-06 12:15:58 +02:00
void View : : removeTasksPlasmoid ( )
2017-04-11 12:10:54 +03:00
{
if ( ! tasksPresent ( ) | | ! containment ( ) ) {
return ;
}
2019-04-04 23:55:44 +03:00
for ( const Plasma : : Applet * applet : containment ( ) - > applets ( ) ) {
2017-04-11 12:10:54 +03:00
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
2018-12-06 12:15:58 +02:00
bool View : : tasksPresent ( )
2017-01-02 22:26:10 +02:00
{
2017-03-05 16:30:50 +02:00
if ( ! this - > containment ( ) ) {
return false ;
}
2019-04-04 23:55:44 +03:00
for ( const 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-06-11 18:06:03 +03:00
//!check if the plasmoid with _name_ exists in the midedata
2018-12-06 12:15:58 +02:00
bool View : : mimeContainsPlasmoid ( QMimeData * mimeData , QString name )
2017-06-11 18:06:03 +03:00
{
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 ) ;
2019-04-04 23:55:44 +03:00
for ( const QString & appletName : appletNames ) {
2017-06-11 18:06:03 +03:00
if ( appletName = = name )
return true ;
}
}
return false ;
}
2018-12-06 12:15:58 +02:00
ViewPart : : Effects * View : : effects ( ) const
2018-11-30 21:33:46 +02:00
{
return m_effects ;
}
2019-03-23 17:49:09 +02:00
ViewPart : : Indicator * View : : indicator ( ) const
{
return m_indicator ;
}
2018-12-06 12:15:58 +02:00
ViewPart : : Positioner * View : : positioner ( ) const
2018-11-29 21:30:00 +02:00
{
return m_positioner ;
}
2017-06-11 18:06:03 +03:00
2018-12-09 00:29:35 +02:00
ViewPart : : VisibilityManager * View : : visibility ( ) const
2016-12-30 16:22:28 -05:00
{
return m_visibility ;
}
2019-02-07 19:15:25 +02:00
ViewPart : : WindowsTracker * View : : windowsTracker ( ) const
{
return m_windowsTracker ;
}
2018-12-06 12:15:58 +02:00
bool View : : event ( QEvent * e )
2019-04-14 13:25:16 +03: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 ( ) ) {
2019-03-23 17:49:09 +02:00
case QEvent : : Enter :
m_containsMouse = true ;
2019-03-09 23:08:24 +02:00
2019-04-01 23:50:25 +03:00
if ( m_configView ) {
2019-03-23 17:49:09 +02:00
ViewPart : : PrimaryConfigView * primaryConfigView = qobject_cast < ViewPart : : PrimaryConfigView * > ( m_configView ) ;
2019-03-09 23:08:24 +02:00
2019-03-23 17:49:09 +02:00
if ( primaryConfigView ) {
if ( primaryConfigView - > secondaryWindow ( ) ) {
2019-04-01 23:50:25 +03:00
ViewPart : : SecondaryConfigView * secConfigView = qobject_cast < ViewPart : : SecondaryConfigView * > ( primaryConfigView - > secondaryWindow ( ) ) ;
if ( secConfigView ) {
secConfigView - > requestActivate ( ) ;
}
2019-03-09 23:08:24 +02:00
}
2019-03-23 17:49:09 +02:00
primaryConfigView - > requestActivate ( ) ;
2019-03-09 00:11:39 +02:00
}
2019-03-23 17:49:09 +02:00
}
break ;
case QEvent : : Leave :
m_containsMouse = false ;
2019-05-17 21:49:31 +03:00
setContainsDrag ( false ) ;
2019-03-23 17:49:09 +02:00
engine ( ) - > trimComponentCache ( ) ;
break ;
2019-05-17 21:28:39 +03:00
case QEvent : : DragEnter :
setContainsDrag ( true ) ;
break ;
case QEvent : : DragLeave :
2019-05-25 14:46:19 +03:00
case QEvent : : Drop :
2019-05-17 21:28:39 +03:00
setContainsDrag ( false ) ;
break ;
2019-04-14 13:25:16 +03:00
case QEvent : : MouseButtonPress :
if ( auto mouseEvent = dynamic_cast < QMouseEvent * > ( e ) ) {
2019-04-17 20:17:28 +03:00
emit mousePressed ( mouseEvent - > pos ( ) , mouseEvent - > button ( ) ) ;
2019-04-14 13:25:16 +03:00
}
break ;
case QEvent : : MouseButtonRelease :
if ( auto mouseEvent = dynamic_cast < QMouseEvent * > ( e ) ) {
2019-04-17 20:17:28 +03:00
emit mouseReleased ( mouseEvent - > pos ( ) , mouseEvent - > button ( ) ) ;
2019-04-14 13:25:16 +03:00
}
break ;
2019-05-16 23:20:51 +03:00
/* case QEvent::DragMove:
qDebug ( ) < < " DRAG MOVING>>>>>> " ;
break ; */
2019-03-23 17:49:09 +02:00
case QEvent : : PlatformSurface :
if ( auto pe = dynamic_cast < QPlatformSurfaceEvent * > ( e ) ) {
switch ( pe - > surfaceEventType ( ) ) {
case QPlatformSurfaceEvent : : SurfaceCreated :
setupWaylandIntegration ( ) ;
if ( m_shellSurface ) {
m_positioner - > syncGeometry ( ) ;
m_effects - > updateShadows ( ) ;
2017-06-21 23:34:40 +03:00
}
2019-03-23 17:49:09 +02:00
break ;
case QPlatformSurfaceEvent : : SurfaceAboutToBeDestroyed :
if ( m_shellSurface ) {
delete m_shellSurface ;
m_shellSurface = nullptr ;
qDebug ( ) < < " WAYLAND dock window surface was deleted... " ;
m_effects - > clearShadows ( ) ;
}
break ;
2017-04-25 19:18:49 +03:00
}
2019-03-23 17:49:09 +02:00
}
2017-04-25 19:18:49 +03:00
2019-03-23 17:49:09 +02:00
break ;
2017-04-25 19:18:49 +03:00
2019-05-11 16:06:53 +03:00
case QEvent : : Show :
m_corona - > wm ( ) - > setViewExtraFlags ( * this ) ;
break ;
2019-03-23 17:49:09 +02:00
default :
break ;
2017-06-21 23:34:40 +03:00
}
2017-04-25 19:18:49 +03:00
}
2019-05-01 17:39:52 +03:00
return ContainmentView : : event ( e ) ;
2016-12-30 16:22:28 -05:00
}
2018-12-06 12:15:58 +02:00
void View : : deactivateApplets ( )
2017-03-20 20:40:27 +02:00
{
if ( ! containment ( ) ) {
return ;
}
2019-04-04 23:55:44 +03:00
for ( const auto applet : containment ( ) - > applets ( ) ) {
2017-03-20 20:40:27 +02:00
PlasmaQuick : : AppletQuickItem * ai = applet - > property ( " _plasma_graphicObject " ) . value < PlasmaQuick : : AppletQuickItem * > ( ) ;
if ( ai ) {
ai - > setExpanded ( false ) ;
}
}
}
2018-12-06 12:15:58 +02:00
void View : : toggleAppletExpanded ( const int id )
2017-05-16 23:08:13 +03:00
{
if ( ! containment ( ) ) {
return ;
}
2019-04-04 23:55:44 +03:00
for ( const auto applet : containment ( ) - > applets ( ) ) {
2017-05-16 23:08:13 +03:00
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
}
}
}
}
2018-12-06 12:15:58 +02:00
QVariantList View : : containmentActions ( )
2017-01-02 12:02:35 +02:00
{
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
2019-04-04 23:55:44 +03:00
for ( QAction * ac : plugin - > contextualActions ( ) ) {
2017-01-02 12:02:35 +02:00
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
2018-12-06 12:15:58 +02:00
void View : : disableGrabItemBehavior ( )
2018-10-27 20:50:49 +03:00
{
setMouseGrabEnabled ( false ) ;
}
2018-12-06 12:15:58 +02:00
void View : : restoreGrabItemBehavior ( )
2018-10-27 20:50:49 +03:00
{
if ( mouseGrabberItem ( ) ) {
mouseGrabberItem ( ) - > ungrabMouse ( ) ;
}
}
2017-01-12 18:55:43 -05:00
2019-02-06 18:15:59 +02:00
bool View : : isHighestPriorityView ( ) {
2019-05-08 23:42:06 +03:00
if ( m_layout ) {
return this = = m_layout - > highestPriorityView ( ) ;
2019-02-06 18:15:59 +02:00
}
2019-02-07 09:38:01 +02:00
2019-02-06 18:15:59 +02:00
return false ;
}
2017-01-03 15:33:30 +02:00
//!BEGIN overriding context menus behavior
2018-12-06 12:15:58 +02:00
void View : : mousePressEvent ( QMouseEvent * event )
2017-01-03 15:33:30 +02:00
{
2018-12-02 00:53:40 +02:00
bool result = m_contextMenu - > 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-02-27 00:53:27 +02:00
//!BEGIN configuration functions
2018-12-06 12:15:58 +02:00
void View : : saveConfig ( )
2017-02-27 00:53:27 +02:00
{
if ( ! this - > containment ( ) )
return ;
auto config = this - > containment ( ) - > config ( ) ;
2018-09-04 19:38:54 +03:00
config . writeEntry ( " onPrimary " , onPrimary ( ) ) ;
2018-12-06 15:34:04 +02:00
config . writeEntry ( " byPassWM " , byPassWM ( ) ) ;
2018-09-22 20:21:57 +03:00
config . writeEntry ( " isPreferredForShortcuts " , isPreferredForShortcuts ( ) ) ;
2019-02-11 16:49:10 +02:00
config . writeEntry ( " viewType " , ( int ) m_type ) ;
2017-07-29 23:07:00 +03:00
config . sync ( ) ;
2017-02-27 00:53:27 +02:00
}
2018-12-06 12:15:58 +02:00
void View : : restoreConfig ( )
2017-02-27 00:53:27 +02:00
{
if ( ! this - > containment ( ) )
return ;
auto config = this - > containment ( ) - > config ( ) ;
2018-09-04 19:38:54 +03:00
m_onPrimary = config . readEntry ( " onPrimary " , true ) ;
2018-12-06 15:34:04 +02:00
m_byPassWM = config . readEntry ( " byPassWM " , false ) ;
2018-09-22 20:21:57 +03:00
m_isPreferredForShortcuts = config . readEntry ( " isPreferredForShortcuts " , false ) ;
2018-09-04 19:38:54 +03:00
//! Send changed signals at the end in order to be sure that saveConfig
//! wont rewrite default/invalid values
emit onPrimaryChanged ( ) ;
2018-12-06 15:34:04 +02:00
emit byPassWMChanged ( ) ;
2017-02-27 00:53:27 +02:00
}
//!END configuration functions
2016-12-30 16:22:28 -05:00
}
//!END namespace