~canonical-dx-team/unity/unity.fix-ql-losing-focus

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
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/* Compiz unity plugin
 * unity.h
 *
 * Copyright (c) 2008 Sam Spilsbury <smspillaz@gmail.com>
 * 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.
 *
 * Your own copyright notice would go above. You are free to choose whatever
 * licence you want, just take note that some compiz code is GPL and you will
 * not be able to re-use it if you want to use a different licence.
 */

#ifndef UNITYSHELL_H
#define UNITYSHELL_H

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

#include "unityshell_options.h"

#include "Introspectable.h"
#include "Launcher.h"
#include "LauncherController.h"
#include "PanelView.h"
#include "PlacesController.h"
#include "DebugDBusInterface.h"
#include <Nux/WindowThread.h>
#include <sigc++/sigc++.h>

/* base screen class */
class UnityScreen :
    public Introspectable,
    public sigc::trackable,
    public ScreenInterface,
    public CompositeScreenInterface,
    public GLScreenInterface,
    public PluginClassHandler <UnityScreen, CompScreen>,
    public UnityshellOptions
{

    public:

	/* Init */
	UnityScreen (CompScreen *s);

	/* Cleanup */
	~UnityScreen ();

	/* We store these  to avoid unecessary calls to ::get */
	CompScreen      *screen;
	CompositeScreen *cScreen;
        GLScreen        *gScreen;

	/* prepares nux for drawing */
	void
	nuxPrologue ();

	/* pops nux draw stack */
	void
	nuxEpilogue ();

	/* nux draw wrapper */
	void paintDisplay (const CompRegion 	&region);

	/* paint on top of all windows if we could not find a window
	 * to paint underneath */
	bool glPaintOutput (const GLScreenPaintAttrib &,
			    const GLMatrix &,
			    const CompRegion &,
		       	    CompOutput *,
			    unsigned int);

	/* paint in the special case that the output is transformed */
	void glPaintTransformedOutput (const GLScreenPaintAttrib &,
		       		       const GLMatrix &,
				       const CompRegion &,
		       		       CompOutput *,
				       unsigned int);

	/* Pop our InputOutput windows from the paint list */
	const CompWindowList & getWindowPaintList ();

	/* handle X11 events */
	void handleEvent (XEvent *);
	
	bool
	showLauncherKeyInitiate (CompAction *action, CompAction::State state,
                             CompOption::Vector &options);

	bool
	showLauncherKeyTerminate (CompAction *action, CompAction::State state,
                              CompOption::Vector &options);

  bool
  showPanelFirstMenuKeyInitiate (CompAction         *action,
                                 CompAction::State   state,
                                 CompOption::Vector &options);
  bool
  showPanelFirstMenuKeyTerminate (CompAction         *action,
                                  CompAction::State   state,
                                  CompOption::Vector &options);
  bool
  setKeyboardFocusKeyInitiate (CompAction*         action,
                               CompAction::State   state,
                               CompOption::Vector& options);

	/* handle option changes and change settings inside of the
	 * panel and dock views */
	void optionChanged (CompOption *, Options num);
	
	/* Handle changes in the number of workspaces by showing the switcher
     * or not showing the switcher */
	bool setOptionForPlugin(const char *plugin, const char *name, 
                            CompOption::Value &v);

	/* init plugin actions for screen */
	bool initPluginForScreen (CompPlugin *p);

  void NeedsRelayout ();

    protected:

	const gchar* GetName ();

	void AddProperties (GVariantBuilder *builder);

    private:

	static gboolean
	initPluginActions (gpointer data);

	static void
	initLauncher (nux::NThread* thread, void* InitData);

	void
	damageNuxRegions();

	void
	onRedrawRequested ();

	void Relayout ();

	static gboolean
	RelayoutTimeout (gpointer data);

	static void
	launcherWindowConfigureCallback(int WindowWidth, int WindowHeight, nux::Geometry& geo, void* user_data);

	static void
	panelWindowConfigureCallback(int WindowWidth, int WindowHeight, nux::Geometry& geo, void* user_data);

	static void
	initUnity(nux::NThread* thread, void* InitData);

	static gboolean
	strutHackTimeout (gpointer data);

  static void
  OnStartKeyNav (GVariant* data, void* value);

  static void
  OnExitKeyNav (GVariant* data, void* value);

  void
  startLauncherKeyNav ();

  void
  restartLauncherKeyNav ();

  static void
  OnQuicklistStartKeyNav (GVariant* data, void* value);

  static void
  OnQuicklistEndKeyNav (GVariant* data, void* value);

  static void
  OnLauncherStartKeyNav (GVariant* data, void* value);

  static void
  OnLauncherEndKeyNav (GVariant* data, void* value);

	Launcher               *launcher;
	LauncherController     *controller;
	PanelView              *panelView;
	PlacesController 			 *placesController;
	nux::WindowThread      *wt;
	nux::BaseWindow        *launcherWindow;
	nux::BaseWindow        *panelWindow;
	nux::Geometry           lastTooltipArea;
	DebugDBusInterface 		 *debugger;
  bool                   needsRelayout;

  /* keyboard-nav mode */
  CompWindow* newFocusedWindow;
  CompWindow* lastFocusedWindow;

	/* handle paint order */
	bool	  doShellRepaint;
	bool    allowWindowPaint;
	bool    damaged;
	CompWindowList _withRemovedNuxWindows;

  GdkRectangle _primary_monitor;

	friend class UnityWindow;
};

class UnityWindow :
    public WindowInterface,
    public GLWindowInterface,
    public PluginClassHandler <UnityWindow, CompWindow>
{

    public:

        /* Constructors, destructors etc */
	UnityWindow (CompWindow *);
	~UnityWindow ();

	CompWindow      *window;
	GLWindow	*gWindow;

	/* basic window draw function */
	bool
	glDraw (const GLMatrix 	&matrix,
	        GLFragment::Attrib &attrib,
	        const CompRegion 	&region,
	        unsigned int	mask);

	void windowNotify (CompWindowNotify n);

  void moveNotify (int x, int y, bool immediate);

  void resizeNotify (int x, int y, int w, int h);
  
  void stateChangeNotify (unsigned int lastState);
};

#define EX_SCREEN (screen) \
UnityScreen *es = UnityScreen::get (screen);

#define EX_WINDOW (window) \
UnityWindow *ew = UnityWindow::get (window);

/* Your vTable class is some basic info about the plugin that core uses.
 */

class UnityPluginVTable :
    public CompPlugin::VTableForScreenAndWindow<UnityScreen, UnityWindow>
{
    public:

	/* kickstart initialization */
	bool init ();
};

#endif // UNITYSHELL_H