summaryrefslogtreecommitdiff
path: root/tile.h
blob: 5ed6faa38bf0550334c4b86ee9d2142c16957f91 (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
/**
 *
 * Compiz tile plugin
 *
 * tile.c
 *
 * Copyright (c) 2006 Atie H. <atie.at.matrix@gmail.com>
 * Copyright (c) 2006 Michal Fojtik <pichalsi(at)gmail.com>
 * Copyright (c) 2007 Danny Baumann <maniac@beryl-project.org>
 *
 * Rewritten by:
 * Copyright (c) 2008 Sam Spilsbury <smspillaz@gmail.com>
 *
 * 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 2
 * 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.
 *
 * TODO
 *	- change vertical and horizontal tiling to similar behavior as Left
 *	- fix bugs
 *	- make vertical and horizontal maximization be saved when tiling
 *
 **/

#include <core/core.h>
#include <core/privatehandler.h>

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

#include "tile_options.h"

#include <cmath>

#define WIN_REAL_X(w) (w->x () - w->input ().left)
#define WIN_REAL_Y(w) (w->y () - w->input ().top)

#define WIN_REAL_W(w) (w->width () + (w->input ().left + w->input ().right))
#define WIN_REAL_H(w) (w->height () + (w->input ().top + w->input ().bottom))

class Tiler;

class TileScreen :
    public PrivateHandler <TileScreen, CompScreen>,
    public TileOptions,
    public ScreenInterface,
    public CompositeScreenInterface,
    public GLScreenInterface
{
    public:

	typedef enum
	{
	    Normal = 0,
	    In,
	    Tiled,
	    Out
	} State;

	typedef enum
	{
	    Restore = 0,
	    Square,
	    Even,
	    Horizontal,
	    Vertical,
	    Expand,
	    Organic,
	    Cascade
	} TileType;

    public:

	TileScreen (CompScreen *screen);

	CompositeScreen *cScreen;
	GLScreen *gScreen;

	State state;
	int time;

	/* Tiling queue */

	std::list <Tiler *> tilers;
	CompRect nextPosition;
	TileType type;

	void
	preparePaint (int);

	/* finsih */

	bool
	glPaintOutput (const GLScreenPaintAttrib &attrib,
		       const GLMatrix	         &transform,
		       CompRegion                &region,
		       CompOutput                *output,
		       unsigned int              mask);
#if 0
	bool
	glPaintScreen (CompOutput   *outputs,
		       int          numOutputs,
		       unsigned int mask); //for ensuring fullscreen output;
#endif
	void
	donePaint ();

	/* Tiling modes */

	void
	restoreTile (CompWindowExtents &border,
		     XRectangle &workArea,
		     int        count);

	void
	squareTile (CompWindowExtents &border,
		    XRectangle &workArea,
		    int        count);

	void
	horizontalTile (CompWindowExtents &border,
			XRectangle &workArea,
			int        count);

	void
	verticalTile (CompWindowExtents &border,
		      XRectangle &workArea,
		      int        count);

	void
	evenTile (CompWindowExtents &border,
		  XRectangle &workArea,
		  int        count);

	void
	expandTile (CompWindowExtents &border,
		    XRectangle &workArea,
		    int        count);

	void
	organicTile (CompWindowExtents &border,
		     XRectangle &workArea,
		     int        count);

	void
	cascadeTile (CompWindowExtents &border,
		     XRectangle &workArea,
		     int        count);

	/* Actions */

	bool
	applyTiling (CompAction           *action,
		     CompAction::State    state,
		     CompOption::Vector   options,
		     TileType 		  type);
};

#define TILE_SCREEN(s)							       \
    TileScreen *ts = TileScreen::get (s);

class Tiler
{
    public:

	Tiler ();

    public:

	typedef enum
	{
	    NotTiled = 0,
	    WaitingForTile,
	    WaitingForRestore,
	    Tiled
	} State;

    public:

	State state;

	bool maximized;
	int  savedMaxState;

	CompRect saved;
	CompRect previous;
	CompRect current;

	bool
	configure (CompWindow *,
		   TileScreen::TileType);

	void
	save (CompWindow *);
};

class TileWindow :
    public PrivateHandler <TileWindow, CompWindow>,
    public WindowInterface,
    public GLWindowInterface
{
    public:

	TileWindow (CompWindow *window);
	~TileWindow ();

	CompWindow *window;
	GLWindow *gWindow;

	bool animate;

	int outlineColor[3];
	int time;

	bool alreadyResized;
	bool needConfigure;

	Tiler *tiler;

	void
	resizeNotify (int, int, int, int);

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

	void
	constrainMinMax (int        width,
		 	 int        height,
		 	 int        &newWidth,
		 	 int        &newHeight);

	bool
	placeWin (int          x,
		  int          y,
		  unsigned int width,
		  unsigned int height);

	bool is ();
};

#define TILE_WINDOW(w)							       \
    TileWindow *tw = TileWindow::get (w);

class TilePluginVTable :
    public CompPlugin::VTableForScreenAndWindow <TileScreen, TileWindow>
{
    public:

	bool init ();

	PLUGIN_OPTION_HELPER (TileScreen);
};