summaryrefslogtreecommitdiff
path: root/src/locker.h
blob: 806d16a915580c436ebef61a2082559f57aa7f8e (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * Compiz locker plugin
 *
 * locker.cpp
 *
 * Copyright (c) 2010 Canonical Ltd.
 *
 * This program 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 3
 * of the License, or (at your option) any later version.
 *
 * This program 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.
 *
 */

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

#include "locker_options.h"

#include <X11/extensions/scrnsaver.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 LockTrigger
{
public:
    LockTrigger () {}
    virtual ~LockTrigger () {}

    virtual void unlocked () = 0;

    static LockTrigger *
    Default ();

    static void
    SetDefault (LockTrigger *);
};

class XScreenSaverTrigger :
    public LockTrigger
{
public:

    XScreenSaverTrigger (Display *, Window root, unsigned int timeout);
    ~XScreenSaverTrigger ();

    bool usable ();
    void processEvent (XEvent *);
    void unlocked ();

private:

    Display      *dpy;
    Window       root;

    int timeout;
    int interval;
    int preferBlanking;
    int allowExposures;

    int          eventBase;
    int          eventBit;
};

/* Not exactly reliable */
class TimerTrigger :
    public LockTrigger
{
public:

    TimerTrigger (unsigned int timeout);

    void processEvent (XEvent *);
    bool check ();
    void unlocked ();

private:

    CompTimer    mTimer;
    unsigned int mTimeout;
    bool         mLocked;
};

class Lockable
{
public:

    Lockable () {}
    virtual ~Lockable () {}

    virtual bool lock () = 0;
    virtual bool unlock () = 0;
    virtual bool wake () = 0;

    static void
    SetDefault (Lockable *);

    static Lockable *
    Default ();

protected:

    LockerLockWindow     *mLockerWindow;
    LockerLockBackground *mLockerBackground;
    LockTrigger          *mTrigger;
};



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

    LockerScreen (CompScreen *);
    ~LockerScreen ();

    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;
};

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 ();
};