File: oxygenblurhelper.h

package info (click to toggle)
oxygen 4%3A5.20.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,660 kB
  • sloc: cpp: 21,511; python: 39; sh: 14; makefile: 7
file content (168 lines) | stat: -rw-r--r-- 4,834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef oxygenblurhelper_h
#define oxygenblurhelper_h

//////////////////////////////////////////////////////////////////////////////
// oxygenblurhelper.h
// handle regions passed to kwin for blurring
// -------------------
//
// Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// Loosely inspired (and largely rewritten) from BeSpin style
// Copyright (C) 2007 Thomas Luebking <thomas.luebking@web.de>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////

#include "oxygenstylehelper.h"
#include "oxygen.h"

#include <QBasicTimer>
#include <QHash>
#include <QObject>
#include <QSet>
#include <QTimerEvent>

#include <QDockWidget>
#include <QMenu>
#include <QRegion>
#include <QToolBar>

#if OXYGEN_HAVE_X11
#include <xcb/xcb.h>
#endif

namespace Oxygen
{
    class BlurHelper: public QObject
    {

        Q_OBJECT

        public:

        //* constructor
        BlurHelper( QObject*, StyleHelper& );

        //* enable state
        void setEnabled( bool value )
        { _enabled = value; }

        //* enabled
        bool enabled( void ) const
        { return _enabled; }

        //* register widget
        void registerWidget( QWidget* );

        //* register widget
        void unregisterWidget( QWidget* );

        //* event filter
        bool eventFilter( QObject*, QEvent* ) override;

        protected:

        //* timer event
        /** used to perform delayed blur region update of pending widgets */
        void timerEvent( QTimerEvent* event ) override
        {

            if( event->timerId() == _timer.timerId() )
            {
                _timer.stop();
                update();
            } else QObject::timerEvent( event );

        }

        private Q_SLOTS:

        //* wiget destroyed
        void widgetDestroyed( QObject* object )
        { _widgets.remove( object ); }

        private:

        //* install event filter to object, in a unique way
        void addEventFilter( QObject* object )
        {
            object->removeEventFilter( this );
            object->installEventFilter( this );
        }

        //* get list of blur-behind regions matching a given widget
        QRegion blurRegion( QWidget* ) const;

        //* trim blur region to remove unnecessary areas (recursive)
        void trimBlurRegion( QWidget*, QWidget*, QRegion& ) const;

        //* update blur region for all pending widgets
        void update( void )
        {

            foreach( const WidgetPointer& widget, _pendingWidgets )
            { if( widget ) update( widget.data() ); }

            _pendingWidgets.clear();

        }

        //* update blur regions for given widget
        void update( QWidget* ) const;

        //* clear blur regions for given widget
        void clear( QWidget* ) const;

        //* returns true if a given widget is opaque
        bool isOpaque( const QWidget* widget ) const;

        //* true if widget is a transparent window
        /** some additional checks are performed to make sure stuff like plasma tooltips
        don't get their blur region overwritten */
        bool isTransparent( const QWidget* widget ) const;

        //* helper
        StyleHelper& _helper;

        //* enability
        bool _enabled;

        //* list of widgets for which blur region must be updated
        using WidgetPointer = WeakPointer<QWidget>;
        using WidgetSet = QHash<QWidget*, WidgetPointer>;
        WidgetSet _pendingWidgets;

        //* set of registered widgets
        QSet<const QObject*> _widgets;

        //* delayed update timer
        QBasicTimer _timer;

        #if OXYGEN_HAVE_X11
        //* blur atom
        xcb_atom_t _blurAtom;
        xcb_atom_t _opaqueAtom;
        #endif

    };

}

#endif