summaryrefslogtreecommitdiff
path: root/src/locker.h
blob: 5a1374c2484e63583bbadc1105c1b3f9ee562928 (plain)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* Compiz locker plugin
 * Copyright (c) Canonical Ltd
 * GPLv3
 */

#include <core/core.h>
#include <composite/composite.h>
#include <opengl/opengl.h>

#include "locker_options.h"

class LockerLockWindow :
    public CompRect
{
public:

    LockerLockWindow () {}
    virtual ~LockerLockWindow () {};

    virtual void hide () = 0;
    virtual void show () = 0;
    virtual bool visible () = 0;
    virtual void paint (const GLMatrix &transform) = 0;
    virtual bool needsGrab () = 0;
    virtual bool handleKeyPress (XKeyEvent *xk) { return false; };
    virtual bool handleButtonPress (XButtonEvent *xb) { return false; };
    virtual bool handleKeyRelease (XKeyEvent *xk) { return false; };
    virtual bool handleButtonRelease (XButtonEvent *xb) { return false; };
    virtual bool handleMotion (XMotionEvent *xm) { return false; };


    virtual CompRegion & damage () = 0;

    static void
    SetDefault (LockerLockWindow *);

    static LockerLockWindow *
    Default ();
};

class SimpleLockerWindow :
    public LockerLockWindow
{
public:
    void hide ();
    void show ();
    bool visible ();
    void paint (const GLMatrix &transform);
    bool needsGrab () { return true; }

    bool handleKeyPress (XKeyEvent *xk);
    bool handleKeyRelease (XKeyEvent *xk);
    bool handleButtonPress (XButtonEvent *xb);
    bool handleButtonRelease (XButtonEvent *xb);
    bool handleMotion (XMotionEvent *xm);

    CompRegion & damage ();

private:
    bool mShowing;
    CompRegion mDamage;
};

class LockerLockBackground :
    public CompRect
{
public:

    LockerLockBackground () {}
    virtual ~LockerLockBackground () {};

    virtual void hide () = 0;
    virtual void show () = 0;
    virtual bool visible () = 0;
    virtual void paint (const GLMatrix &transform) = 0;
    virtual CompRegion & damage () = 0;

    static void
    SetDefault (LockerLockBackground *);

    static LockerLockBackground *
    Default ();
};

class SimpleLockerBackground :
    public LockerLockBackground
{
public:
    void hide ();
    void show ();
    bool visible ();
    void paint (const GLMatrix &transform);

    CompRegion & damage ();

private:
    bool mShowing;
    CompRegion mDamage;
};

class LockerScreen :
    public PluginClassHandler <LockerScreen, CompScreen>,
    public ScreenInterface,
    public CompositeScreenInterface,
    public GLScreenInterface,
    public LockerOptions
{
public:

    LockerScreen (CompScreen *);

    CompositeScreen *cScreen;
    GLScreen	*gScreen;

    typedef enum
    {
	AnimationStateIdle = 0,
	AnimationStateLocking = 1,
	AnimationStateUnlocking = 2,
	AnimationStateLocked = 3
    } AnimationState;

public:

    void preparePaint (int);
    bool glPaintOutput (const GLScreenPaintAttrib &attrib,
			const GLMatrix	      &transform,
			const CompRegion	      &region,
			CompOutput                *output,
			unsigned int	      mask);
    void donePaint ();

    bool lock ();
    bool unlock ();
    bool wake ();

    void handleEvent (XEvent *);

private:

    /* Normalized */
    float  	       mAnimationProgress;
    CompWindowList mAnimatedWindows;
    AnimationState mAnimationState;

    CompTimer      mWaitTimer;

    CompScreen::GrabHandle mGrabIndex;

    SimpleLockerWindow *mSLW;
    SimpleLockerBackground *mSLB;
};

class LockerWindow :
    public PluginClassHandler <LockerWindow, CompWindow>,
    public WindowInterface,
    public CompositeWindowInterface,
    public GLWindowInterface
{
public:

    LockerWindow (CompWindow *);

    CompWindow	*window;
    CompositeWindow *cWindow;
    GLWindow	*gWindow;

public:

    bool glPaint (const GLWindowPaintAttrib	&attrib,
		  const GLMatrix		&transform,
		  const CompRegion		&region,
		  unsigned int		mask);

    bool isLockerWindow ();
    bool isAnimatedWindow ();

    void setAnimationProgress (float animProgress) { mAnimationProgress = animProgress; };

private:

    /* Normalized */
    float mAnimationProgress;
};

class LockerPluginVTable :
    public CompPlugin::VTableForScreenAndWindow <LockerScreen, LockerWindow>
{
public:

    bool init ();
};