2017-07-26 09:25:56 +03: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/>.
*/
# include "infoview.h"
2018-12-02 03:05:52 +03:00
// local
2019-04-10 18:10:53 +03:00
# include <config-latte.h>
2018-12-02 02:29:18 +03:00
# include "wm/abstractwindowinterface.h"
2018-12-06 13:15:58 +03:00
# include "view/panelshadows_p.h"
2017-07-26 09:25:56 +03:00
2018-12-02 03:05:52 +03:00
// Qt
2017-07-26 09:25:56 +03:00
# include <QQuickItem>
# include <QQmlContext>
# include <QQmlEngine>
# include <QScreen>
2018-12-02 03:05:52 +03:00
// KDE
2017-07-26 09:25:56 +03:00
# include <KLocalizedContext>
# include <KDeclarative/KDeclarative>
2017-07-26 10:21:37 +03:00
# include <KWindowSystem>
2017-07-26 09:25:56 +03:00
# include <KWayland/Client/plasmashell.h>
# include <KWayland/Client/surface.h>
2018-12-02 03:05:52 +03:00
// Plasma
# include <Plasma/Package>
2017-07-26 09:25:56 +03:00
namespace Latte {
2018-12-06 15:35:34 +03:00
InfoView : : InfoView ( Latte : : Corona * corona , QString message , QScreen * screen , QWindow * parent )
2017-07-26 09:25:56 +03:00
: QQuickView ( parent ) ,
m_corona ( corona ) ,
m_message ( message ) ,
m_screen ( screen )
{
2020-03-21 14:06:03 +03:00
m_id = QString : : number ( qrand ( ) % 1000 ) ;
setTitle ( validTitle ( ) ) ;
2017-07-26 09:25:56 +03:00
setupWaylandIntegration ( ) ;
setResizeMode ( QQuickView : : SizeViewToRootObject ) ;
setColor ( QColor ( Qt : : transparent ) ) ;
2017-07-26 10:21:37 +03:00
setDefaultAlphaBuffer ( true ) ;
2017-07-26 09:25:56 +03:00
setIcon ( qGuiApp - > windowIcon ( ) ) ;
setScreen ( screen ) ;
setFlags ( wFlags ( ) ) ;
2020-03-21 14:06:03 +03:00
if ( KWindowSystem : : isPlatformX11 ( ) ) {
m_trackedWindowId = winId ( ) ;
m_corona - > wm ( ) - > registerIgnoredWindow ( m_trackedWindowId ) ;
} else {
connect ( m_corona - > wm ( ) , & WindowSystem : : AbstractWindowInterface : : latteWindowAdded , this , & InfoView : : updateWaylandId ) ;
}
2017-07-26 09:25:56 +03:00
init ( ) ;
}
InfoView : : ~ InfoView ( )
{
2017-08-01 00:37:37 +03:00
PanelShadows : : self ( ) - > removeWindow ( this ) ;
2017-07-26 09:25:56 +03:00
qDebug ( ) < < " InfoView deleting ... " ;
if ( m_shellSurface ) {
delete m_shellSurface ;
m_shellSurface = nullptr ;
}
}
void InfoView : : init ( )
{
2017-07-26 10:21:37 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " infoWindow " ) , this ) ;
2017-07-26 09:25:56 +03:00
KDeclarative : : KDeclarative kdeclarative ;
kdeclarative . setDeclarativeEngine ( engine ( ) ) ;
kdeclarative . setTranslationDomain ( QStringLiteral ( " latte-dock " ) ) ;
2019-04-10 18:10:53 +03:00
# if KF5_VERSION_MINOR >= 45
2019-04-10 02:09:25 +03:00
kdeclarative . setupContext ( ) ;
kdeclarative . setupEngine ( engine ( ) ) ;
2019-04-10 18:10:53 +03:00
# else
kdeclarative . setupBindings ( ) ;
# endif
2017-07-26 09:25:56 +03:00
auto source = QUrl : : fromLocalFile ( m_corona - > kPackage ( ) . filePath ( " infoviewui " ) ) ;
setSource ( source ) ;
2017-07-26 10:21:37 +03:00
2017-07-26 09:25:56 +03:00
rootObject ( ) - > setProperty ( " message " , m_message ) ;
syncGeometry ( ) ;
}
2020-03-21 14:06:03 +03:00
QString InfoView : : validTitle ( ) const
{
return " #layoutinfowindow# " + m_id ;
}
2017-07-26 10:21:37 +03:00
Plasma : : FrameSvg : : EnabledBorders InfoView : : enabledBorders ( ) const
{
return m_borders ;
}
2017-07-26 09:25:56 +03:00
inline Qt : : WindowFlags InfoView : : wFlags ( ) const
{
return ( flags ( ) | Qt : : FramelessWindowHint | Qt : : WindowStaysOnTopHint ) & ~ Qt : : WindowDoesNotAcceptFocus ;
}
void InfoView : : syncGeometry ( )
{
2017-07-26 10:21:37 +03:00
const QSize size ( rootObject ( ) - > width ( ) , rootObject ( ) - > height ( ) ) ;
2017-07-26 09:25:56 +03:00
const auto sGeometry = screen ( ) - > geometry ( ) ;
2017-07-26 10:21:37 +03:00
setMaximumSize ( size ) ;
setMinimumSize ( size ) ;
resize ( size ) ;
2017-07-26 09:25:56 +03:00
2017-07-26 10:21:37 +03:00
QPoint position { sGeometry . center ( ) . x ( ) - size . width ( ) / 2 , sGeometry . center ( ) . y ( ) - size . height ( ) / 2 } ;
2017-07-26 09:25:56 +03:00
setPosition ( position ) ;
if ( m_shellSurface ) {
m_shellSurface - > setPosition ( position ) ;
2017-07-26 10:21:37 +03:00
}
2017-07-26 09:25:56 +03:00
}
void InfoView : : showEvent ( QShowEvent * ev )
{
QQuickWindow : : showEvent ( ev ) ;
2019-12-26 17:53:37 +03:00
m_corona - > wm ( ) - > setViewExtraFlags ( this ) ;
2017-07-26 09:25:56 +03:00
setFlags ( wFlags ( ) ) ;
2018-03-02 00:53:28 +03:00
m_corona - > wm ( ) - > enableBlurBehind ( * this ) ;
2017-07-26 09:25:56 +03:00
syncGeometry ( ) ;
QTimer : : singleShot ( 400 , this , & InfoView : : syncGeometry ) ;
2017-08-01 00:37:37 +03:00
PanelShadows : : self ( ) - > addWindow ( this ) ;
PanelShadows : : self ( ) - > setEnabledBorders ( this , m_borders ) ;
2017-07-26 09:25:56 +03:00
}
2020-03-21 14:06:03 +03:00
void InfoView : : updateWaylandId ( )
{
Latte : : WindowSystem : : WindowId newId = m_corona - > wm ( ) - > winIdFor ( " latte-dock " , validTitle ( ) ) ;
if ( m_trackedWindowId ! = newId ) {
if ( ! m_trackedWindowId . isNull ( ) ) {
m_corona - > wm ( ) - > unregisterIgnoredWindow ( m_trackedWindowId ) ;
}
m_trackedWindowId = newId ;
m_corona - > wm ( ) - > registerIgnoredWindow ( m_trackedWindowId ) ;
}
}
2017-07-26 09:25:56 +03:00
void InfoView : : setupWaylandIntegration ( )
{
if ( m_shellSurface ) {
// already setup
return ;
}
if ( m_corona ) {
using namespace KWayland : : Client ;
2018-12-06 15:35:34 +03:00
PlasmaShell * interface = m_corona - > waylandCoronaInterface ( ) ;
2017-07-26 09:25:56 +03:00
if ( ! interface ) {
return ;
}
Surface * s = Surface : : fromWindow ( this ) ;
if ( ! s ) {
return ;
}
qDebug ( ) < < " wayland dock window surface was created... " ;
m_shellSurface = interface - > createSurface ( s , this ) ;
2019-12-26 17:53:37 +03:00
m_corona - > wm ( ) - > setViewExtraFlags ( m_shellSurface ) ;
2017-07-26 09:25:56 +03:00
}
}
bool InfoView : : event ( QEvent * e )
{
if ( e - > type ( ) = = QEvent : : PlatformSurface ) {
if ( auto pe = dynamic_cast < QPlatformSurfaceEvent * > ( e ) ) {
switch ( pe - > surfaceEventType ( ) ) {
case QPlatformSurfaceEvent : : SurfaceCreated :
if ( m_shellSurface ) {
break ;
}
setupWaylandIntegration ( ) ;
break ;
case QPlatformSurfaceEvent : : SurfaceAboutToBeDestroyed :
if ( m_shellSurface ) {
delete m_shellSurface ;
m_shellSurface = nullptr ;
}
PanelShadows : : self ( ) - > removeWindow ( this ) ;
break ;
}
}
}
2017-07-26 10:21:37 +03:00
return QQuickWindow : : event ( e ) ;
2017-07-26 09:25:56 +03:00
}
2018-01-15 01:29:11 +03:00
void InfoView : : setOnActivities ( QStringList activities )
{
KWindowSystem : : setOnActivities ( winId ( ) , activities ) ;
}
2017-07-26 09:25:56 +03:00
}
// kate: indent-mode cstyle; indent-width 4; replace-tabs on;